cw20_staking/
msg.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Binary, Coin, Decimal, Uint128};
5use cw20::Expiration;
6pub use cw_controllers::ClaimsResponse;
7use cw_utils::Duration;
8
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
10pub struct InstantiateMsg {
11    /// name of the derivative token
12    pub name: String,
13    /// symbol / ticker of the derivative token
14    pub symbol: String,
15    /// decimal places of the derivative token (for UI)
16    pub decimals: u8,
17
18    /// This is the validator that all tokens will be bonded to
19    pub validator: String,
20    /// This is the unbonding period of the native staking module
21    /// We need this to only allow claims to be redeemed after the money has arrived
22    pub unbonding_period: Duration,
23
24    /// this is how much the owner takes as a cut when someone unbonds
25    pub exit_tax: Decimal,
26    /// This is the minimum amount we will pull out to reinvest, as well as a minimum
27    /// that can be unbonded (to avoid needless staking tx)
28    pub min_withdrawal: Uint128,
29}
30
31#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
32#[serde(rename_all = "snake_case")]
33pub enum ExecuteMsg {
34    /// Bond will bond all staking tokens sent with the message and release derivative tokens
35    Bond {},
36    /// Unbond will "burn" the given amount of derivative tokens and send the unbonded
37    /// staking tokens to the message sender (after exit tax is deducted)
38    Unbond { amount: Uint128 },
39    /// Claim is used to claim your native tokens that you previously "unbonded"
40    /// after the chain-defined waiting period (eg. 3 weeks)
41    Claim {},
42    /// Reinvest will check for all accumulated rewards, withdraw them, and
43    /// re-bond them to the same validator. Anyone can call this, which updates
44    /// the value of the token (how much under custody).
45    Reinvest {},
46    /// _BondAllTokens can only be called by the contract itself, after all rewards have been
47    /// withdrawn. This is an example of using "callbacks" in message flows.
48    /// This can only be invoked by the contract itself as a return from Reinvest
49    _BondAllTokens {},
50
51    /// Implements CW20. Transfer is a base message to move tokens to another account without triggering actions
52    Transfer { recipient: String, amount: Uint128 },
53    /// Implements CW20. Burn is a base message to destroy tokens forever
54    Burn { amount: Uint128 },
55    /// Implements CW20.  Send is a base message to transfer tokens to a contract and trigger an action
56    /// on the receiving contract.
57    Send {
58        contract: String,
59        amount: Uint128,
60        msg: Binary,
61    },
62    /// Implements CW20 "approval" extension. Allows spender to access an additional amount tokens
63    /// from the owner's (env.sender) account. If expires is Some(), overwrites current allowance
64    /// expiration with this one.
65    IncreaseAllowance {
66        spender: String,
67        amount: Uint128,
68        expires: Option<Expiration>,
69    },
70    /// Implements CW20 "approval" extension. Lowers the spender's access of tokens
71    /// from the owner's (env.sender) account by amount. If expires is Some(), overwrites current
72    /// allowance expiration with this one.
73    DecreaseAllowance {
74        spender: String,
75        amount: Uint128,
76        expires: Option<Expiration>,
77    },
78    /// Implements CW20 "approval" extension. Transfers amount tokens from owner -> recipient
79    /// if `env.sender` has sufficient pre-approval.
80    TransferFrom {
81        owner: String,
82        recipient: String,
83        amount: Uint128,
84    },
85    /// Implements CW20 "approval" extension. Sends amount tokens from owner -> contract
86    /// if `env.sender` has sufficient pre-approval.
87    SendFrom {
88        owner: String,
89        contract: String,
90        amount: Uint128,
91        msg: Binary,
92    },
93    /// Implements CW20 "approval" extension. Destroys tokens forever
94    BurnFrom { owner: String, amount: Uint128 },
95}
96
97#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
98#[serde(rename_all = "snake_case")]
99pub enum QueryMsg {
100    /// Claims shows the number of tokens this address can access when they are done unbonding
101    Claims { address: String },
102    /// Investment shows metadata on the staking info of the contract
103    Investment {},
104
105    /// Implements CW20. Returns the current balance of the given address, 0 if unset.
106    Balance { address: String },
107    /// Implements CW20. Returns metadata on the contract - name, decimals, supply, etc.
108    TokenInfo {},
109    /// Implements CW20 "allowance" extension.
110    /// Returns how much spender can use from owner account, 0 if unset.
111    Allowance { owner: String, spender: String },
112}
113
114#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
115pub struct InvestmentResponse {
116    pub token_supply: Uint128,
117    pub staked_tokens: Coin,
118    // ratio of staked_tokens / token_supply (or how many native tokens that one derivative token is nominally worth)
119    pub nominal_value: Decimal,
120
121    /// owner created the contract and takes a cut
122    pub owner: String,
123    /// this is how much the owner takes as a cut when someone unbonds
124    pub exit_tax: Decimal,
125    /// All tokens are bonded to this validator
126    pub validator: String,
127    /// This is the minimum amount we will pull out to reinvest, as well as a minimum
128    /// that can be unbonded (to avoid needless staking tx)
129    pub min_withdrawal: Uint128,
130}