use cosmwasm_schema::QueryResponses;
use cosmwasm_std::{Addr, Uint128};
use cw20::Cw20ReceiveMsg;
use cw_storage_plus::{Item, Map};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
pub mod state {
use super::*;
pub const CONFIG: Item<Config> = Item::new("config");
pub const STATE: Item<State> = Item::new("state");
pub const ALLOCATIONS: Map<&Addr, AllocationInfo> = Map::new("vested_allocations");
#[cosmwasm_schema::cw_serde]
pub struct Config {
pub owner: Addr,
pub refund_recipient: Addr,
pub token: Addr,
pub default_unlock_schedule: Schedule,
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
pub struct State {
pub total_deposited: Uint128,
pub remaining_tokens: Uint128,
}
impl Default for State {
fn default() -> Self {
State {
total_deposited: Uint128::zero(),
remaining_tokens: Uint128::zero(),
}
}
}
}
#[cosmwasm_schema::cw_serde]
pub struct InstantiateMsg {
pub owner: String,
pub refund_recipient: String,
pub token: String,
pub default_unlock_schedule: Schedule,
}
#[cosmwasm_schema::cw_serde]
#[cfg_attr(feature = "boot", derive(boot_core::ExecuteFns))]
pub enum ExecuteMsg {
TransferOwnership { new_owner: String },
Receive(Cw20ReceiveMsg),
Withdraw {},
Terminate { user_address: String },
}
#[cosmwasm_schema::cw_serde]
pub enum ReceiveMsg {
CreateAllocations {
allocations: Vec<(String, AllocationInfo)>,
},
}
#[cosmwasm_schema::cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(ConfigResponse)]
Config {},
#[returns(StateResponse)]
State {},
#[returns(AllocationResponse)]
Allocation { account: String },
#[returns(SimulateWithdrawResponse)]
SimulateWithdraw {
account: String,
timestamp: Option<u64>,
},
}
pub type ConfigResponse = InstantiateMsg;
pub type AllocationResponse = AllocationInfo;
#[cosmwasm_schema::cw_serde]
pub struct StateResponse {
pub total_deposited: Uint128,
pub remaining_tokens: Uint128,
}
#[cosmwasm_schema::cw_serde]
pub struct SimulateWithdrawResponse {
pub total_tokens_locked: Uint128,
pub total_tokens_unlocked: Uint128,
pub total_tokens_vested: Uint128,
pub withdrawn_amount: Uint128,
pub withdrawable_amount: Uint128,
}
#[cosmwasm_schema::cw_serde]
pub struct AllocationInfo {
pub total_amount: Uint128,
pub withdrawn_amount: Uint128,
pub vest_schedule: Schedule,
pub unlock_schedule: Option<Schedule>,
pub canceled: bool,
}
#[cosmwasm_schema::cw_serde]
pub struct Schedule {
pub start_time: u64,
pub cliff: u64,
pub duration: u64,
}
impl Schedule {
pub fn zero() -> Schedule {
Schedule {
start_time: 0u64,
cliff: 0u64,
duration: 0u64,
}
}
}