Skip to content

Commit

Permalink
Merge pull request #85 from neutron-org/fix/update-pool-on-deposit
Browse files Browse the repository at this point in the history
Fix: update pool on deposit
  • Loading branch information
sotnikov-s authored Mar 29, 2024
2 parents e016b14 + d44ee2f commit 1028cd2
Showing 1 changed file with 42 additions and 2 deletions.
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

0 comments on commit 1028cd2

Please sign in to comment.