-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathmsg.rs
More file actions
348 lines (300 loc) · 12.5 KB
/
msg.rs
File metadata and controls
348 lines (300 loc) · 12.5 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
// License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
// "Business Source License" is a trademark of MariaDB Corporation Ab.
//
// Parameters
//
// Licensor: Union.fi, Labs Inc.
// Licensed Work: All files under https://github.com/unionlabs/union's cosmwasm/lst subdirectory
// The Licensed Work is (c) 2025 Union.fi, Labs Inc.
// Change Date: Four years from the date the Licensed Work is published.
// Change License: Apache-2.0
//
//
// For information about alternative licensing arrangements for the Licensed Work,
// please contact info@union.build.
//
// Notice
//
// Business Source License 1.1
//
// Terms
//
// The Licensor hereby grants you the right to copy, modify, create derivative
// works, redistribute, and make non-production use of the Licensed Work. The
// Licensor may make an Additional Use Grant, above, permitting limited production use.
//
// Effective on the Change Date, or the fourth anniversary of the first publicly
// available distribution of a specific version of the Licensed Work under this
// License, whichever comes first, the Licensor hereby grants you rights under
// the terms of the Change License, and the rights granted in the paragraph
// above terminate.
//
// If your use of the Licensed Work does not comply with the requirements
// currently in effect as described in this License, you must purchase a
// commercial license from the Licensor, its affiliated entities, or authorized
// resellers, or you must refrain from using the Licensed Work.
//
// All copies of the original and modified Licensed Work, and derivative works
// of the Licensed Work, are subject to this License. This License applies
// separately for each version of the Licensed Work and the Change Date may vary
// for each version of the Licensed Work released by Licensor.
//
// You must conspicuously display this License on each original or modified copy
// of the Licensed Work. If you receive the Licensed Work in original or
// modified form from a third party, the terms and conditions set forth in this
// License apply to your use of that work.
//
// Any use of the Licensed Work in violation of this License will automatically
// terminate your rights under this License for the current and all other
// versions of the Licensed Work.
//
// This License does not grant you any right in any trademark or logo of
// Licensor or its affiliates (provided that you may use a trademark or logo of
// Licensor as expressly required by this License).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.
use cosmwasm_std::{Addr, Decimal, Uint128};
use serde::{Deserialize, Serialize};
use crate::types::{
BatchExpectedAmount, BatchId, PendingBatch, ProtocolFeeConfig, ReceivedBatch, SubmittedBatch,
UnstakeRequestKey,
};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct InitMsg {
pub native_token_denom: String,
#[serde(with = "::serde_utils::string")]
#[cfg_attr(feature = "schemars", schemars(with = "cosmwasm_std::Uint128"))]
pub minimum_liquid_stake_amount: u128,
/// Address of the account that delegates the tokens
/// toward the validators.
pub staker_address: Addr,
/// Protocol fee configuration.
pub protocol_fee_config: ProtocolFeeConfig,
/// Address of the LST contract.
pub lst_address: Addr,
/// Frequency (in seconds) at which the unbonding queue is executed.
#[serde(with = "::serde_utils::string")]
#[cfg_attr(feature = "schemars", schemars(with = "cosmwasm_std::Uint64"))]
pub batch_period_seconds: u64,
/// The unbonding period of the chain.
#[serde(with = "::serde_utils::string")]
#[cfg_attr(feature = "schemars", schemars(with = "cosmwasm_std::Uint64"))]
pub unbonding_period_seconds: u64,
/// Set of addresses allowed to trigger a circuit break.
pub monitors: Vec<Addr>,
pub admin: Addr,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[allow(clippy::large_enum_variant)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum ExecuteMsg {
/// Initiates the bonding process for a user.
Bond {
/// The address to mint the LST to.
mint_to_address: Addr,
/// Minimum expected amount of LST tokens to be received
/// for the operation to be considered valid.
min_mint_amount: Uint128,
},
/// Initiates the unbonding process for a user.
Unbond {
/// The amount to unstake.
amount: Uint128,
},
/// Withdraws unstaked tokens.
Withdraw {
/// The address to withdraw the funds to.
withdraw_to_address: Addr,
/// ID of the batch from which to withdraw.
batch_id: BatchId,
},
/// Processes the pending batch.
SubmitBatch {},
TransferOwnership {
/// Address of the new owner on the protocol chain.
#[cfg_attr(feature = "schemars", schemars(with = "Addr"))]
new_owner: String,
},
/// Accepts ownership transfer; callable by the new owner.
AcceptOwnership {},
/// Revokes ownership transfer; callable by the current owner.
RevokeOwnershipTransfer {},
/// Updates contract configuration; callable by the owner.
UpdateConfig {
/// Updated protocol fee configuration.
protocol_fee_config: Option<ProtocolFeeConfig>,
/// Updated list of circuit breaker monitors.
monitors: Option<Vec<Addr>>,
/// Updated unbonding batch execution frequency (in seconds).
batch_period_seconds: Option<u64>,
/// Updated unbonding period for this chain.
unbonding_period_seconds: Option<u64>,
},
/// Receives rewards from the native chain.
ReceiveRewards {},
/// Rebase the LST by claiming all current pending rewards and restaking them.
Rebase {},
/// Receives unstaked tokens from the native chain.
ReceiveUnstakedTokens {
/// ID of the batch that originated the unstake request.
batch_id: BatchId,
},
/// Stops the contract due to irregularities; callable by monitors and admin.
CircuitBreaker {},
/// Resumes the contract; callable by the admin.
ResumeContract {
/// Updated total native tokens delegated (used post-slashing).
total_bonded_native_tokens: Uint128,
/// Updated total issued liquid staked tokens.
total_issued_lst: Uint128,
/// Updated total protocol rewards.
total_reward_amount: Uint128,
},
SlashBatches {
new_amounts: Vec<BatchExpectedAmount>,
},
/// Call Staker to received unstaked tokens for specific batch
ReceiveBatch { batch_id: BatchId },
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(
feature = "schemars",
derive(schemars::JsonSchema, cosmwasm_schema::QueryResponses)
)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum QueryMsg {
/// Queries the contract configuration.
/// Returns the current `native_chain_config`, `protocol_chain_config`,
/// `protocol_fee_config`, `liquid_stake_token_denom`, and other settings.
#[cfg_attr(feature = "schemars", returns(ConfigResponse))]
Config {},
/// Queries the current accounting state of the contract.
/// Returns totals such as delegated native tokens, LST supply, and rewards.
#[cfg_attr(feature = "schemars", returns(AccountingStateResponse))]
AccountingState {},
/// Queries the information of a specific batch by its ID.
#[cfg_attr(feature = "schemars", returns(Batch))]
Batch {
/// ID of the batch to query.
batch_id: BatchId,
},
/// Queries a paginated list of all submitted batches.
#[cfg_attr(feature = "schemars", returns(BatchesResponse<IdentifiedBatch<SubmittedBatch>>))]
SubmittedBatches {
/// If provided, starts listing batches after this batch ID.
start_after: Option<BatchId>,
/// Maximum number of batches to return.
limit: Option<usize>,
},
/// Queries a paginated list of all received batches.
#[cfg_attr(feature = "schemars", returns(BatchesResponse<IdentifiedBatch<ReceivedBatch>>))]
ReceivedBatches {
/// If provided, starts listing batches after this batch ID.
start_after: Option<BatchId>,
/// Maximum number of batches to return.
limit: Option<usize>,
},
/// Queries the batches with the provided list of IDs.
#[cfg_attr(feature = "schemars", returns(BatchesResponse<IdentifiedBatch<Batch>>))]
BatchesByIds {
/// List of batch IDs to fetch.
batch_ids: Vec<BatchId>,
},
/// Queries the current batch that is pending processing (if any).
#[cfg_attr(feature = "schemars", returns(Batch))]
PendingBatch {},
/// Queries the unstake requests made by a specific staker.
#[cfg_attr(feature = "schemars", returns(Vec<crate::types::UnstakeRequest>))]
UnstakeRequestsByStaker {
/// Address of the user whose unstake requests are to be queried.
staker: Addr,
},
/// Queries all unstake requests in the contract.
#[cfg_attr(feature = "schemars", returns(Vec<crate::types::UnstakeRequest>))]
AllUnstakeRequests {
/// If provided, starts listing unstake requests after this key.
start_after: Option<UnstakeRequestKey>,
/// Maximum number of unstake requests to return.
limit: Option<usize>,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct ConfigResponse {
pub native_token_denom: String,
pub minimum_liquid_stake_amount: Uint128,
pub protocol_fee_config: ProtocolFeeConfig,
pub monitors: Vec<Addr>,
pub lst_address: Addr,
pub staker_address: Addr,
pub batch_period_seconds: u64,
pub unbonding_period_seconds: u64,
pub stopped: bool,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct AccountingStateResponse {
pub total_assets: Uint128,
pub total_shares: Uint128,
pub total_reward_amount: Uint128,
pub redemption_rate: Decimal,
pub purchase_rate: Decimal,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct OwnershipResponse {
pub pending_owner: Addr,
pub total_reward_amount: Uint128,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct BatchesResponse<B> {
pub batches: Vec<IdentifiedBatch<B>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub struct IdentifiedBatch<B> {
pub batch_id: BatchId,
pub batch: B,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case", tag = "status")]
pub enum Batch {
Pending(PendingBatch),
Submitted(SubmittedBatch),
Received(ReceivedBatch),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case", tag = "status")]
pub enum StakerExecuteMsg {
/// Stake the tokens provided along with this call.
///
/// This must only be callable by the LST hub itself.
Stake {},
/// Unstake `amount` of tokens.
///
/// This must only be callable by the LST hub itself.
Unstake { amount: Uint128 },
/// Rebase the current rewards by restaking them through the LST hub.
///
/// This must only be callable by the LST hub itself.
Rebase {},
/// Receive unstaked tokens to mark batch as received
///
/// This must only be callable by the LST hub itself.
ReceiveUnstakedTokens { batch_id: BatchId },
}