From 705de7c228bd99a12dc02d848989c7a8a5036a69 Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Tue, 26 Mar 2024 16:32:26 +0300 Subject: [PATCH 1/2] pass reward tokens info instead of querying for pcl lockdrop --- contracts/lockdrop-pcl/src/contract.rs | 24 +++++++++---------- .../astroport_periphery/src/lockdrop_pcl.rs | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/contracts/lockdrop-pcl/src/contract.rs b/contracts/lockdrop-pcl/src/contract.rs index 4581dab1..c40ad036 100644 --- a/contracts/lockdrop-pcl/src/contract.rs +++ b/contracts/lockdrop-pcl/src/contract.rs @@ -190,6 +190,7 @@ fn _handle_callback( user_address, duration, withdraw_lp_stake, + reward_tokens, } => callback_withdraw_user_rewards_for_lockup_optional_withdraw( deps, env, @@ -197,6 +198,7 @@ fn _handle_callback( user_address, duration, withdraw_lp_stake, + reward_tokens, ), CallbackMsg::FinishLockupMigrationCallback { pool_type, @@ -485,6 +487,7 @@ pub fn handle_claim_rewards_and_unlock_for_lockup( }, )?; + let mut reward_tokens: Vec = vec![]; if pending_rewards_response .iter() .any(|asset| !asset.amount.is_zero()) @@ -492,6 +495,8 @@ pub fn handle_claim_rewards_and_unlock_for_lockup( let prev_pending_rewards_balances: Vec = pending_rewards_response .iter() .map(|asset| { + reward_tokens.push(asset.info.clone()); + let balance = asset .info .query_pool(&deps.querier, env.contract.address.clone()) @@ -527,6 +532,7 @@ pub fn handle_claim_rewards_and_unlock_for_lockup( user_address, duration, withdraw_lp_stake, + reward_tokens, } .to_cosmos_msg(&env)?, ); @@ -658,6 +664,7 @@ pub fn callback_withdraw_user_rewards_for_lockup_optional_withdraw( user_address: Addr, duration: u64, withdraw_lp_stake: bool, + reward_tokens: Vec, ) -> StdResult { let config = CONFIG.load(deps.storage)?; let mut pool_info = ASSET_POOLS.load(deps.storage, pool_type)?; @@ -699,17 +706,10 @@ pub fn callback_withdraw_user_rewards_for_lockup_optional_withdraw( let mut pending_reward_assets: Vec = vec![]; // If this LP token is getting incentives // Calculate claimable staking rewards for this lockup - let pending_rewards: Vec = deps.querier.query_wasm_smart( - incentives, - &IncentivesQueryMsg::PendingRewards { - lp_token: astroport_lp_token.to_string(), - user: env.contract.address.to_string(), - }, - )?; - for reward in pending_rewards { + for reward_token in reward_tokens { let incentives_rewards_per_share = pool_info .incentives_rewards_per_share - .load(&reward.info) + .load(&reward_token) .unwrap_or_default(); if incentives_rewards_per_share.is_zero() { continue; @@ -720,20 +720,20 @@ pub fn callback_withdraw_user_rewards_for_lockup_optional_withdraw( .to_uint_floor(); let debt = lockup_info .incentives_debt - .load(&reward.info) + .load(&reward_token) .unwrap_or_default(); let pending_reward = total_lockup_rewards.checked_sub(debt)?; if !pending_reward.is_zero() { pending_reward_assets.push(Asset { - info: reward.info.clone(), + info: reward_token.clone(), amount: pending_reward, }); } lockup_info .incentives_debt - .update(&reward.info, total_lockup_rewards.checked_sub(debt)?)?; + .update(&reward_token, total_lockup_rewards.checked_sub(debt)?)?; } // If this is a void transaction (no state change), then return error. diff --git a/packages/astroport_periphery/src/lockdrop_pcl.rs b/packages/astroport_periphery/src/lockdrop_pcl.rs index 72def852..6b9fd83f 100644 --- a/packages/astroport_periphery/src/lockdrop_pcl.rs +++ b/packages/astroport_periphery/src/lockdrop_pcl.rs @@ -183,6 +183,7 @@ pub enum CallbackMsg { user_address: Addr, duration: u64, withdraw_lp_stake: bool, + reward_tokens: Vec, }, /// Completes the liquidity migration process by making all necessary state updates for the lockup /// position. From 2aadccf455caad4ac4df2835d14683929f74c34b Mon Sep 17 00:00:00 2001 From: sotnikov-s Date: Fri, 29 Mar 2024 17:52:01 +0300 Subject: [PATCH 2/2] add missing reward_tokens param description --- contracts/lockdrop-pcl/src/contract.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/lockdrop-pcl/src/contract.rs b/contracts/lockdrop-pcl/src/contract.rs index c40ad036..72510f80 100644 --- a/contracts/lockdrop-pcl/src/contract.rs +++ b/contracts/lockdrop-pcl/src/contract.rs @@ -657,6 +657,8 @@ pub fn update_pool_on_dual_rewards_claim( /// * **duration** is a vector of type [`u64`]. Duration of the lockup for which rewards have been claimed / position unlocked. /// /// * **withdraw_lp_stake** is an object of type [`bool`]. Boolean value indicating if the ASTRO LP Tokens are to be sent to the user or not. +/// +/// * **reward_tokens** is vector of [`AssetInfo`]. A list of assets to calculate claimable staking rewards for. pub fn callback_withdraw_user_rewards_for_lockup_optional_withdraw( deps: DepsMut, env: Env,