1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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,
}
}
}