Skip to main content

abstract_staking_standard/
msg.rs

1#![warn(missing_docs)]
2//! # Staking Adapter
3//!
4//! `abstract::cw-staking`
5use abstract_std::{
6    adapter,
7    objects::{AnsAsset, AssetEntry},
8};
9use cosmwasm_schema::QueryResponses;
10use cosmwasm_std::Empty;
11use cw_utils::Duration;
12
13/// Name of the staking provider, used by the ANS.
14pub type ProviderName = String;
15
16/// The callback id for staking over ibc
17pub const IBC_STAKING_PROVIDER_ID: &str = "IBC_STAKING_ACTION";
18
19/// Top-level Abstract Adapter execute message. This is the message that is passed to the `execute` entrypoint of the smart-contract.
20pub type ExecuteMsg = adapter::ExecuteMsg<StakingExecuteMsg>;
21/// Top-level Abstract Adapter instantiate message. This is the message that is passed to the `instantiate` entrypoint of the smart-contract.
22pub type InstantiateMsg = adapter::InstantiateMsg<Empty>;
23/// Top-level Abstract Adapter query message. This is the message that is passed to the `query` entrypoint of the smart-contract.
24pub type QueryMsg = adapter::QueryMsg<StakingQueryMsg>;
25
26impl adapter::AdapterExecuteMsg for StakingExecuteMsg {}
27impl adapter::AdapterQueryMsg for StakingQueryMsg {}
28
29/// A request message that's sent to this staking adapter
30#[cosmwasm_schema::cw_serde]
31pub struct StakingExecuteMsg {
32    /// The name of the staking provider
33    pub provider: ProviderName,
34    /// the action to execute, see [StakingAction]
35    pub action: StakingAction,
36}
37
38/// Possible actions to perform on the staking contract
39/// All provide an asset [AnsAsset] information
40#[cosmwasm_schema::cw_serde]
41pub enum StakingAction {
42    /// Stakes/bonds a given token
43    Stake {
44        /// The ANS-resolvable asset information of the assets to stake.
45        assets: Vec<AnsAsset>,
46        /// The unbonding period for the specified stake.
47        unbonding_period: Option<Duration>,
48    },
49    /// Unstake/unbond a given token
50    Unstake {
51        /// The ANS-resolvable asset information of the assets to unstake.
52        assets: Vec<AnsAsset>,
53        /// The unbonding period for the specified stake.
54        unbonding_period: Option<Duration>,
55    },
56    /// Claim rewards for a set of staked assets.
57    ClaimRewards {
58        /// Staked assets to claim rewards for.
59        assets: Vec<AssetEntry>,
60    },
61    /// Claim matured unbonding tokens
62    Claim {
63        /// Unbonded staking assets to claim.
64        assets: Vec<AssetEntry>,
65    },
66}
67
68#[cosmwasm_schema::cw_serde]
69#[derive(QueryResponses, cw_orch::QueryFns)]
70/// Query messages for the staking adapter
71pub enum StakingQueryMsg {
72    /// Get the staking info for a given provider
73    /// Returns [`StakingInfoResponse`]
74    #[returns(StakingInfoResponse)]
75    Info {
76        /// Name of the provider
77        provider: ProviderName,
78        /// The staking tokens to query
79        staking_tokens: Vec<AssetEntry>,
80    },
81    /// Get the staked amount for a given provider, staking token, staker address and unbonding period
82    /// Returns [`StakeResponse`]
83    #[returns(StakeResponse)]
84    Staked {
85        /// Name of the provider
86        provider: ProviderName,
87        /// The staking token to query
88        stakes: Vec<AssetEntry>,
89        /// The address of the staker (contract or user)
90        staker_address: String,
91        /// The unbonding period for the specified staked position.
92        unbonding_period: Option<Duration>,
93    },
94    /// Get the unbonding entries for a given provider, staking token and staker address
95    /// Returns [`UnbondingResponse`]
96    #[returns(UnbondingResponse)]
97    Unbonding {
98        /// Name of the provider
99        provider: ProviderName,
100        /// The staking tokens to query
101        staking_tokens: Vec<AssetEntry>,
102        /// The address of the staker (contract or user)
103        staker_address: String,
104    },
105    /// Get the reward tokens for a given provider and staking token
106    /// Returns [`RewardTokensResponse`]
107    #[returns(RewardTokensResponse)]
108    RewardTokens {
109        /// Name of the provider
110        provider: ProviderName,
111        /// The staking tokens to query
112        staking_tokens: Vec<AssetEntry>,
113    },
114}
115
116use cosmwasm_std::{Addr, Uint128};
117use cw_asset::AssetInfo;
118use cw_utils::Expiration;
119
120/// Possible staking targets to support staking on cosmwasm contract or cosmos Lockup module
121#[cosmwasm_schema::cw_serde]
122#[non_exhaustive]
123pub enum StakingTarget {
124    /// Address of the staking contract (Cosmwasm)
125    Contract(Addr),
126    /// Pool id of the staking contract (Osmosis)
127    Id(u64),
128}
129
130impl StakingTarget {
131    /// Extract contract address
132    pub fn expect_contract(self) -> abstract_std::AbstractResult<Addr> {
133        match self {
134            StakingTarget::Contract(addr) => Ok(addr),
135            _ => Err(abstract_std::AbstractError::Assert(
136                "Staking target is not a contract address.".into(),
137            )),
138        }
139    }
140
141    /// Extract pool id
142    pub fn expect_id(self) -> abstract_std::AbstractResult<u64> {
143        match self {
144            StakingTarget::Id(id) => Ok(id),
145            _ => Err(abstract_std::AbstractError::Assert(
146                "Staking target is not an pool ID.".into(),
147            )),
148        }
149    }
150}
151
152impl From<u64> for StakingTarget {
153    fn from(value: u64) -> Self {
154        Self::Id(value)
155    }
156}
157
158impl From<Addr> for StakingTarget {
159    fn from(value: Addr) -> Self {
160        Self::Contract(value)
161    }
162}
163
164/// Response for the staking_info query
165#[cosmwasm_schema::cw_serde]
166pub struct StakingInfoResponse {
167    /// Contract or pool id to stake to
168    pub infos: Vec<StakingInfo>,
169}
170
171/// Info for a stakeable token
172#[cosmwasm_schema::cw_serde]
173pub struct StakingInfo {
174    /// Address or pool id to stake to
175    pub staking_target: StakingTarget,
176    /// Staking token
177    pub staking_token: AssetInfo,
178    /// Different supported unbonding periods. None if no unbonding is supported.
179    pub unbonding_periods: Option<Vec<Duration>>,
180    /// Max number of claims. None if no limit.
181    pub max_claims: Option<u32>,
182}
183
184/// Response for the staked query
185#[cosmwasm_schema::cw_serde]
186pub struct StakeResponse {
187    /// Amount of staked tokens, per token provided in query
188    pub amounts: Vec<Uint128>,
189}
190
191/// Response for the rewards query
192#[cosmwasm_schema::cw_serde]
193pub struct RewardTokensResponse {
194    /// List of reward tokens, per token provided in query
195    pub tokens: Vec<Vec<AssetInfo>>,
196}
197
198/// Response for the unbonding query
199#[cosmwasm_schema::cw_serde]
200pub struct UnbondingResponse {
201    /// List of unbonding entries, per token provided in query
202    pub claims: Vec<Vec<Claim>>,
203}
204
205/// A claim for a given amount of tokens that are unbonding.
206#[cosmwasm_schema::cw_serde]
207pub struct Claim {
208    /// Amount of tokens that are unbonding
209    pub amount: Uint128,
210    /// When the tokens can be claimed
211    pub claimable_at: Expiration,
212}