Skip to content

Commit

Permalink
refactor: remove copied astroport messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pacmanifold committed May 1, 2024
1 parent fe78331 commit 2155779
Showing 1 changed file with 8 additions and 39 deletions.
47 changes: 8 additions & 39 deletions cw-dex-astroport/src/staking.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Staking/rewards traits implementations for Astroport
use apollo_cw_asset::{AssetInfo, AssetList};
use apollo_utils::assets::separate_natives_and_cw20s;
use astroport::asset::{Asset as AstroAsset};
use cosmwasm_schema::{cw_serde, QueryResponses};
use astroport::asset::Asset as AstroAsset;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{
coins, to_json_binary, Addr, CosmosMsg, Deps, Empty, Env, Event, QuerierWrapper, QueryRequest,
Response, Uint128, WasmMsg, WasmQuery,
Expand All @@ -19,46 +19,15 @@ pub struct AstroportStaking {
pub incentives: Addr,
}

#[cw_serde]
pub enum AstroportV5IncentivesExecuteMsg {
/// 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<String> },
/// 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<String>,
},
}

/// We copied this in because versioning on Astroport is a mess and it's easier to simply copy it in.
/// These incentive related structs come from here: https://github.com/astroport-fi/hidden_astroport_core/blob/main/packages/astroport/src/incentives.rs#L92
/// This will be released as Astroport V5 at some point in the future

#[cw_serde]
#[derive(QueryResponses)]
pub enum AstroportV5IncentivesQueryMsg {
/// PendingToken returns the amount of rewards that can be claimed by an
/// account that deposited a specific LP token in a generator
#[returns(Vec<AstroAsset>)]
PendingRewards { lp_token: String, user: String },
}

impl Staking for AstroportStaking {}

impl Stake for AstroportStaking {
fn stake(&self, _deps: Deps, _env: &Env, amount: Uint128) -> Result<Response, CwDexError> {
let stake_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: self.incentives.to_string(),
msg: to_json_binary(&AstroportV5IncentivesExecuteMsg::Deposit { recipient: None })?,
msg: to_json_binary(&astroport_v3::incentives::ExecuteMsg::Deposit {
recipient: None,
})?,
funds: coins(amount.into(), self.lp_token.to_string()),
});

Expand All @@ -85,7 +54,7 @@ impl Rewards for AstroportStaking {

let claim_rewards_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: self.incentives.to_string(),
msg: to_json_binary(&AstroportV5IncentivesExecuteMsg::ClaimRewards {
msg: to_json_binary(&astroport_v3::incentives::ExecuteMsg::ClaimRewards {
lp_tokens: vec![self.lp_token.to_string()],
})?,
funds: vec![],
Expand Down Expand Up @@ -137,7 +106,7 @@ impl Rewards for AstroportStaking {
let pending_rewards: Vec<AstroAsset> = querier
.query::<Vec<AstroAsset>>(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: self.incentives.to_string(),
msg: to_json_binary(&AstroportV5IncentivesQueryMsg::PendingRewards {
msg: to_json_binary(&astroport_v3::incentives::QueryMsg::PendingRewards {
lp_token: self.lp_token.to_string(),
user: user.to_string(),
})?,
Expand All @@ -154,7 +123,7 @@ impl Unstake for AstroportStaking {
fn unstake(&self, _deps: Deps, _env: &Env, amount: Uint128) -> Result<Response, CwDexError> {
let unstake_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: self.incentives.to_string(),
msg: to_json_binary(&AstroportV5IncentivesExecuteMsg::Withdraw {
msg: to_json_binary(&astroport_v3::incentives::ExecuteMsg::Withdraw {
lp_token: self.lp_token.to_string(),
amount,
})?,
Expand Down

0 comments on commit 2155779

Please sign in to comment.