pfc_steak/hub.rs
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
use std::str::FromStr;
use cosmwasm_std::{
to_json_binary, Addr, Binary, Coin, CosmosMsg, Decimal, Empty, StdResult, Uint128, WasmMsg,
};
use cw20::Cw20ReceiveMsg;
use cw20_base::msg::InstantiateMarketingInfo as Cw20InstantiateMarketingInfo;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub enum Cw20HookMsg {
Distribute {},
Transfer {},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub enum EnterpriseCw20HookMsg {
Distribute {},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InstantiateMsg {
/// Code ID of the CW20 token contract
pub cw20_code_id: u64,
/// Account who can call certain privileged functions
pub owner: String,
/// Name of the liquid staking token
pub name: String,
/// Symbol of the liquid staking token
pub symbol: String,
/// Number of decimals of the liquid staking token
pub decimals: u8,
/// How often the unbonding queue is to be executed, in seconds
pub epoch_period: u64,
/// The staking module's unbonding time, in seconds
pub unbond_period: u64,
/// Initial set of validators who will receive the delegations
pub validators: Vec<String>,
/// denomination of coins to steak (uXXXX)
pub denom: String,
/// type of fee account
pub fee_account_type: String,
/// Fee Account to send fees too
pub fee_account: String,
/// Fee "1.00 = 100%"
pub fee_amount: Decimal,
/// Max Fee "1.00 = 100%"
pub max_fee_amount: Decimal,
/// label for the CW20 token we create
pub label: Option<String>,
/// Marketing info for the CW20 we create
pub marketing: Option<Cw20InstantiateMarketingInfo>,
pub dust_collector: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
/// Implements the Cw20 receiver interface
Receive(Cw20ReceiveMsg),
/// Bond specified amount of Luna
Bond {
receiver: Option<String>,
exec_msg: Option<Binary>,
},
/// Bond specified amount of Luna, just minting it directly (cw-20 version only)
BondEx {
receiver: Option<String>,
},
/// Withdraw Luna that have finished unbonding in previous batches
WithdrawUnbonded {
receiver: Option<String>,
},
/// Withdraw Luna that has finished unbonding in previous batches, for given address
WithdrawUnbondedAdmin {
address: String,
},
/// Add a validator to the whitelist; callable by the owner
AddValidator {
validator: String,
},
/// Remove a validator from the whitelist; callable by the owner
RemoveValidator {
validator: String,
},
/// Remove a validator from the whitelist; callable by the owner. Does not undelegate. use for
/// typos
RemoveValidatorEx {
validator: String,
},
/// Pause a validator from accepting new delegations
PauseValidator {
validator: String,
},
/// Unpause a validator from accepting new delegations
UnPauseValidator {
validator: String,
},
/// Transfer ownership to another account; will not take effect unless the new owner accepts
TransferOwnership {
new_owner: String,
},
/// Accept an ownership transfer
AcceptOwnership {},
/// Claim staking rewards, swap all for Luna, and restake
Harvest {},
/// Use redelegations to balance the amounts of Luna delegated to validators
Rebalance {
minimum: Uint128,
},
/// redelegate stake from one validator to another
Redelegate {
validator_from: String,
validator_to: String,
},
/// Update Luna amounts in unbonding batches to reflect any slashing or rounding errors
Reconcile {},
/// Submit the current pending batch of unbonding requests to be unbonded
SubmitBatch {},
/// Set unbond period
SetUnbondPeriod {
unbond_period: u64,
},
/// Transfer Fee collection account to another account
TransferFeeAccount {
fee_account_type: String,
new_fee_account: String,
},
/// Update fee collection amount
UpdateFee {
new_fee: Decimal,
},
/// Callbacks; can only be invoked by the contract itself
Callback(CallbackMsg),
// Set The Duster.
SetDustCollector {
dust_collector: Option<String>,
},
/// Collect the Dust
CollectDust {
max_tokens: u32,
},
/// Return the Dust in shiny 'base denom'
ReturnDenom {},
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ReceiveMsg {
/// Submit an unbonding request to the current unbonding queue; automatically invokes `unbond`
/// if `epoch_time` has elapsed since when the last unbonding queue was executed.
QueueUnbond {
receiver: Option<String>,
},
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum CallbackMsg {
/// Following the swaps, stake the Luna acquired to the whitelisted validators
Reinvest {},
}
impl CallbackMsg {
pub fn into_cosmos_msg(&self, contract_addr: &Addr) -> StdResult<CosmosMsg> {
Ok(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: contract_addr.to_string(),
msg: to_json_binary(&ExecuteMsg::Callback(self.clone()))?,
funds: vec![],
}))
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
/// The contract's configurations. Response: `ConfigResponse`
Config {},
/// The contract's current state. Response: `StateResponse`
State {},
/// The current batch on unbonding requests pending submission. Response: `PendingBatch`
PendingBatch {},
/// Query an individual batch that has previously been submitted for unbonding but have not yet
/// fully withdrawn. Response: `Batch`
PreviousBatch(u64),
/// Enumerate all previous batches that have previously been submitted for unbonding but have
/// not yet fully withdrawn. Response: `Vec<Batch>`
PreviousBatches {
start_after: Option<u64>,
limit: Option<u32>,
},
/// Enumerate all outstanding unbonding requests in a given batch. Response:
/// `Vec<UnbondRequestsResponseByBatchItem>`
UnbondRequestsByBatch {
id: u64,
start_after: Option<String>,
limit: Option<u32>,
},
/// Enumerate all outstanding unbonding requests from given a user. Response:
/// `Vec<UnbondRequestsByUserResponseItem>`
UnbondRequestsByUser {
user: String,
start_after: Option<u64>,
limit: Option<u32>,
},
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
pub struct ConfigResponse {
/// Account who can call certain privileged functions
pub owner: String,
/// Pending ownership transfer, awaiting acceptance by the new owner
pub new_owner: Option<String>,
/// Address of the Steak token
pub steak_token: String,
/// How often the unbonding queue is to be executed, in seconds
pub epoch_period: u64,
/// The staking module's unbonding time, in seconds
pub unbond_period: u64,
/// denomination of coins to steak (uXXXX)
pub denom: String,
/// type of account to send the fees too
pub fee_type: String,
/// Fee Account to send fees too
pub fee_account: String,
/// Fee "1.00 = 100%"
pub fee_rate: Decimal,
/// Max Fee "1.00 = 100%"
pub max_fee_rate: Decimal,
/// Set of validators who will receive the delegations
pub validators: Vec<String>,
pub paused_validators: Vec<String>,
pub dust_collector: Option<String>,
pub token_factory: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
pub struct StateResponse {
/// Total supply to the Steak token
pub total_usteak: Uint128,
/// Total amount of native staked
pub total_native: Uint128,
/// The exchange rate between usteak and native, in terms of native per usteak
pub exchange_rate: Decimal,
/// Staking rewards currently held by the contract that are ready to be reinvested
pub unlocked_coins: Vec<Coin>,
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
pub struct PendingBatch {
/// ID of this batch
pub id: u64,
/// Total amount of `usteak` to be burned in this batch
pub usteak_to_burn: Uint128,
/// Estimated time when this batch will be submitted for unbonding
pub est_unbond_start_time: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
pub struct Batch {
/// ID of this batch
pub id: u64,
/// Whether this batch has already been reconciled
pub reconciled: bool,
/// Total amount of shares remaining this batch. Each `usteak` burned = 1 share
pub total_shares: Uint128,
/// Amount of `denom` in this batch that have not been claimed
pub amount_unclaimed: Uint128,
/// Estimated time when this batch will finish unbonding
pub est_unbond_end_time: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
pub struct UnbondRequest {
/// ID of the batch
pub id: u64,
/// The user's address
pub user: Addr,
/// The user's share in the batch
pub shares: Uint128,
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
pub struct UnbondRequestsByBatchResponseItem {
/// The user's address
pub user: String,
/// The user's share in the batch
pub shares: Uint128,
}
impl From<UnbondRequest> for UnbondRequestsByBatchResponseItem {
fn from(s: UnbondRequest) -> Self {
Self {
user: s.user.into(),
shares: s.shares,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
pub struct UnbondRequestsByUserResponseItem {
/// ID of the batch
pub id: u64,
/// The user's share in the batch
pub shares: Uint128,
}
impl From<UnbondRequest> for UnbondRequestsByUserResponseItem {
fn from(s: UnbondRequest) -> Self {
Self {
id: s.id,
shares: s.shares,
}
}
}
pub type MigrateMsg = Empty;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Copy, JsonSchema)]
pub enum FeeType {
Wallet,
FeeSplit,
}
impl FromStr for FeeType {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Wallet" => Ok(FeeType::Wallet),
"FeeSplit" => Ok(FeeType::FeeSplit),
_ => Err(()),
}
}
}
impl ToString for FeeType {
fn to_string(&self) -> String {
match &self {
FeeType::Wallet => String::from("Wallet"),
FeeType::FeeSplit => String::from("FeeSplit"),
}
}
}