Skip to content

Commit

Permalink
feat: send cw20 tokens to astro incentives contract
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Jan 12, 2024
1 parent f22c16b commit 9dbb361
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
10 changes: 10 additions & 0 deletions contracts/alliance-lp-hub/src/astro_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ pub enum ExecuteAstroMsg {
Deposit { recipient: Option<String> },
}

#[cw_serde]
/// Cw20 hook message template
pub enum Cw20Msg {
Deposit {
recipient: Option<String>,
},
/// Besides this enum variant is redundant we keep this for backward compatibility with old pair contracts
DepositFor(String),
}


#[cw_serde]
#[derive(QueryResponses)]
Expand Down
26 changes: 21 additions & 5 deletions contracts/alliance-lp-hub/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
state::{
ASSET_REWARD_RATE, BALANCES, CONFIG, TEMP_BALANCE,
TOTAL_BALANCES, UNCLAIMED_REWARDS, USER_ASSET_REWARD_RATE, VALIDATORS, WHITELIST,
}, astro_models::{QueryAstroMsg, RewardInfo, ExecuteAstroMsg},
}, astro_models::{QueryAstroMsg, RewardInfo, ExecuteAstroMsg, Cw20Msg},
};
use crate::state::UNALLOCATED_REWARDS;

Expand Down Expand Up @@ -180,7 +180,7 @@ fn stake(

// Query astro incentives
let astro_incentives: Vec<RewardInfo> = deps.querier.query_wasm_smart(
config.astro_incentives_addr,
config.astro_incentives_addr.to_string(),
&QueryAstroMsg::RewardInfo{
lp_token: received_asset.info.to_string(),
},
Expand All @@ -194,7 +194,7 @@ fn stake(
]);

if !astro_incentives.is_empty() {
let msg = match received_asset.info {
let msg = match received_asset.info.clone() {
AssetInfo::Native(native_asset) => {
// If the asset is native, we need to send it to the astro incentives contract
// using the ExecuteAstroMsg::Deposit message
Expand All @@ -205,22 +205,38 @@ fn stake(
})?,
funds: vec![CwCoin {
denom: native_asset,
amount: received_asset.amount,
amount: received_asset.amount.clone(),
}],
});
msg
}
AssetInfo::Cw20(cw20_contract_addr) => {
// If the asset is a cw20 token, we need to send it to the astro incentives contract
// using the ExecuteAstroMsg::Receive message
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: cw20_contract_addr.to_string(),
msg: to_json_binary(&Cw20ExecuteMsg::Send {
contract: config.astro_incentives_addr.to_string(),
amount: received_asset.amount.clone(),
msg: to_json_binary(&Cw20ReceiveMsg {
sender: env.contract.address.to_string(),
amount: received_asset.amount.clone(),
msg: to_json_binary(&Cw20Msg::Deposit {
recipient: None,
})?,
})?,
})?,
funds: vec![],
});
msg

},
_ => {
return Err(ContractError::AssetNotWhitelisted(received_asset.info.to_string()));
}
};

res.add_message(msg);
res = res.add_message(msg);
}

BALANCES.update(
Expand Down

0 comments on commit 9dbb361

Please sign in to comment.