diff --git a/cw-dex-astroport/src/staking.rs b/cw-dex-astroport/src/staking.rs index f073938..3acc7c0 100644 --- a/cw-dex-astroport/src/staking.rs +++ b/cw-dex-astroport/src/staking.rs @@ -1,49 +1,66 @@ //! Staking/rewards traits implementations for Astroport - +use apollo_cw_asset::AssetList; use apollo_utils::assets::separate_natives_and_cw20s; -use cosmwasm_schema::cw_serde; +use astroport::asset::{Asset as AstroAsset, Asset}; +use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{ - to_json_binary, Addr, CosmosMsg, Deps, Empty, Env, Event, QuerierWrapper, QueryRequest, + coins, to_json_binary, Addr, CosmosMsg, Deps, Empty, Env, Event, QuerierWrapper, QueryRequest, Response, Uint128, WasmMsg, WasmQuery, }; -use cw20::Cw20ExecuteMsg; - -use apollo_cw_asset::AssetList; -use astroport::asset::Asset as AstroAsset; -use astroport_v3::incentives::{ - Cw20Msg as IncentivesCw20Msg, ExecuteMsg as IncentivesExecuteMsg, - QueryMsg as IncentivesQueryMsg, -}; - use cw_dex::traits::{Rewards, Stake, Staking, Unstake}; use cw_dex::CwDexError; /// Represents staking of tokens on Astroport #[cw_serde] pub struct AstroportStaking { - /// The address of the associated LP token contract - pub lp_token_addr: Addr, + /// The token factory denom of the associated LP token + pub lp_token_denom: String, /// The address of the astroport incentives contract pub incentives: Addr, } +#[cw_serde] +pub enum IncentivesExecuteMsg { + /// Stake LP tokens in the Generator. LP tokens staked on behalf of + /// recipient if recipient is set. Otherwise LP tokens are staked on + /// behalf of message sender. + Deposit { recipient: Option }, + /// Withdraw LP tokens from the Generator + Withdraw { + /// The LP token cw20 address or token factory denom + lp_token: String, + /// The amount to withdraw. Must not exceed total staked amount. + amount: Uint128, + }, + /// Update rewards and return it to user. + ClaimRewards { + /// The LP token cw20 address or token factory denom + lp_tokens: Vec, + }, +} + +#[cw_serde] +#[derive(QueryResponses)] +pub enum IncentivesQueryMsg { + /// PendingToken returns the amount of rewards that can be claimed by an + /// account that deposited a specific LP token in a generator + #[returns(Vec)] + PendingRewards { lp_token: String, user: String }, +} + impl Staking for AstroportStaking {} impl Stake for AstroportStaking { fn stake(&self, _deps: Deps, _env: &Env, amount: Uint128) -> Result { let stake_msg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: self.lp_token_addr.to_string(), - msg: to_json_binary(&Cw20ExecuteMsg::Send { - contract: self.incentives.to_string(), - amount, - msg: to_json_binary(&IncentivesCw20Msg::Deposit { recipient: None })?, - })?, - funds: vec![], + contract_addr: self.incentives.to_string(), + msg: to_json_binary(&IncentivesExecuteMsg::Deposit { recipient: None })?, + funds: coins(amount.into(), self.lp_token_denom.to_string()), }); let event = Event::new("apollo/cw-dex/stake") .add_attribute("type", "astroport_staking") - .add_attribute("asset", self.lp_token_addr.to_string()) + .add_attribute("asset", self.lp_token_denom.to_string()) .add_attribute("incentives contract address", self.incentives.to_string()); Ok(Response::new().add_message(stake_msg).add_event(event)) @@ -65,7 +82,7 @@ impl Rewards for AstroportStaking { let claim_rewards_msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: self.incentives.to_string(), msg: to_json_binary(&IncentivesExecuteMsg::ClaimRewards { - lp_tokens: vec![self.lp_token_addr.to_string()], + lp_tokens: vec![self.lp_token_denom.to_string()], })?, funds: vec![], }); @@ -117,7 +134,7 @@ impl Rewards for AstroportStaking { .query::>(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: self.incentives.to_string(), msg: to_json_binary(&IncentivesQueryMsg::PendingRewards { - lp_token: self.lp_token_addr.to_string(), + lp_token: self.lp_token_denom.to_string(), user: user.to_string(), })?, }))? @@ -134,7 +151,7 @@ impl Unstake for AstroportStaking { let unstake_msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: self.incentives.to_string(), msg: to_json_binary(&IncentivesExecuteMsg::Withdraw { - lp_token: self.lp_token_addr.to_string(), + lp_token: self.lp_token_denom.to_string(), amount, })?, funds: vec![], diff --git a/test-contracts/astroport-test-contract/src/contract.rs b/test-contracts/astroport-test-contract/src/contract.rs index c6608e5..3ab11b9 100644 --- a/test-contracts/astroport-test-contract/src/contract.rs +++ b/test-contracts/astroport-test-contract/src/contract.rs @@ -28,7 +28,7 @@ pub fn instantiate( STAKING.save( deps.storage, &AstroportStaking { - lp_token_addr: Addr::unchecked(msg.lp_token_addr), + lp_token_denom: msg.lp_token_denom, incentives: Addr::unchecked(msg.incentives_addr), }, )?; diff --git a/test-contracts/package/src/msg.rs b/test-contracts/package/src/msg.rs index dffec8d..d2cf1e8 100644 --- a/test-contracts/package/src/msg.rs +++ b/test-contracts/package/src/msg.rs @@ -13,7 +13,7 @@ pub struct OsmosisTestContractInstantiateMsg { #[cw_serde] pub struct AstroportContractInstantiateMsg { pub pair_addr: String, - pub lp_token_addr: String, + pub lp_token_denom: String, pub incentives_addr: String, pub astro_token: AssetInfo, pub liquidity_manager_addr: String, diff --git a/test-helpers/src/astroport.rs b/test-helpers/src/astroport.rs index 7653c01..b53a93e 100644 --- a/test-helpers/src/astroport.rs +++ b/test-helpers/src/astroport.rs @@ -296,13 +296,13 @@ pub fn instantiate_test_astroport_contract<'a, R: Runner<'a>>( pair_addr: String, incentives_addr: String, astro_token: AssetInfo, - lp_token_addr: String, + lp_token_denom: String, liquidity_manager_addr: String, signer: &SigningAccount, ) -> RunnerResult { let init_msg = AstroportContractInstantiateMsg { pair_addr, - lp_token_addr, + lp_token_denom, incentives_addr, astro_token, liquidity_manager_addr,