Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: update pool on deposit #85

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions contracts/lockdrop-pcl/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ pub fn handle_migrate_xyk_liquidity(
},
)?;

let mut cosmos_msgs: Vec<CosmosMsg<Empty>> = vec![];
// provide the transferred liquidity to the PCL pool
let mut cosmos_msgs: Vec<CosmosMsg<Empty>> = vec![CosmosMsg::Wasm(WasmMsg::Execute {
cosmos_msgs.push(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: astroport_pool.to_string(),
funds: info.funds.clone(),
msg: to_json_binary(&ProvideLiquidity {
Expand All @@ -390,7 +391,46 @@ pub fn handle_migrate_xyk_liquidity(
auto_stake: Some(true),
receiver: None,
})?,
})];
}));

let incentives = &config.incentives;

// QUERY :: Check if there are any pending staking rewards
let pending_rewards_response: StdResult<Vec<Asset>> = deps.querier.query_wasm_smart(
incentives,
&IncentivesQueryMsg::PendingRewards {
lp_token: pool_info.lp_token.to_string(),
user: env.contract.address.to_string(),
},
);

// the incentives contract claims rewards on LP Deposit: https://github.com/astroport-fi/astroport-core/blob/514d83331da3232111c5c590fd8086ef62025ca9/contracts/tokenomics/incentives/src/execute.rs#L190
// thus we need update pool info after the deposit otherwise there will be unaccounted rewards on PCL lockdrop during users migration
if let Ok(pending_rewards) = pending_rewards_response {
let prev_pending_rewards_balances: Vec<Asset> = pending_rewards
.iter()
.map(|asset| {
let balance = asset
.info
.query_pool(&deps.querier, env.contract.address.clone())
.unwrap_or_default();

Asset {
info: asset.info.clone(),
amount: balance,
}
})
.collect();

cosmos_msgs.push(
CallbackMsg::UpdatePoolOnDualRewardsClaim {
pool_type: pool_type.into(),
prev_reward_balances: prev_pending_rewards_balances,
}
.to_cosmos_msg(&env)?,
);
}

// invoke callback that creates a lockup entry for the provided liquidity
cosmos_msgs.push(
CallbackMsg::FinishLockupMigrationCallback {
Expand Down
Loading