diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index 29bc8838c..ea4d856e0 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -7,6 +7,7 @@ use common_structs::Nonce; use pausable::State; pub const DEFAULT_NFT_DEPOSIT_MAX_LEN: usize = 10; +pub const DEFAULT_FARM_POSITION_MIGRATION_NONCE: u64 = 1; #[derive( ManagedVecItem, @@ -35,6 +36,16 @@ impl Default for UserTotalFarmPosition { #[multiversx_sc::module] pub trait ConfigModule: pausable::PausableModule + permissions_module::PermissionsModule { + + #[endpoint(allowExternalClaimBoostedRewards)] + fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { + let caller = self.blockchain().get_caller(); + let mut user_total_farm_position = self.get_user_total_farm_position(&caller); + user_total_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; + self.user_total_farm_position(&caller) + .set(user_total_farm_position); + } + #[inline] fn is_active(&self) -> bool { let state = self.state().get(); @@ -58,15 +69,24 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio token_nonce > 0 && token_nonce < farm_position_migration_nonce } - #[endpoint(allowExternalClaimBoostedRewards)] - fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { - let caller = self.blockchain().get_caller(); - let mut user_total_farm_position = self.get_user_total_farm_position(&caller); - user_total_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; - self.user_total_farm_position(&caller) - .set(user_total_farm_position); + fn try_set_farm_position_migration_nonce(&self, farm_token_mapper: NonFungibleTokenMapper) { + if !self.farm_position_migration_nonce().is_empty() { + return; + } + + let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { + let token_identifier = farm_token_mapper.get_token_id_ref(); + self.blockchain() + .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) + } else { + DEFAULT_FARM_POSITION_MIGRATION_NONCE + }; + + self.farm_position_migration_nonce() + .set(migration_farm_token_nonce); } + #[view(getFarmingTokenId)] #[storage_mapper("farming_token_id")] fn farming_token_id(&self) -> SingleValueMapper; diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 9ac50d388..27421ac16 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -77,7 +77,8 @@ pub trait Farm: self.first_week_start_epoch().set_if_empty(current_epoch); // Farm position migration code - self.try_set_farm_position_migration_nonce(); + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index bbe12a49f..968e3381d 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -239,25 +239,6 @@ pub trait BaseFunctionsModule: }); } - fn try_set_farm_position_migration_nonce(&self) { - if !self.farm_position_migration_nonce().is_empty() { - return; - } - - let farm_token_mapper = self.farm_token(); - - let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { - let token_identifier = farm_token_mapper.get_token_id_ref(); - self.blockchain() - .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) - } else { - DEFAULT_FARM_POSITION_MIGRATION_NONCE - }; - - self.farm_position_migration_nonce() - .set(migration_farm_token_nonce); - } - fn end_produce_rewards>(&self) { let mut storage = StorageCache::new(self); FC::generate_aggregated_rewards(self, &mut storage); diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index c7364b322..5a18d41e3 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -78,7 +78,8 @@ pub trait Farm: self.first_week_start_epoch().set_if_empty(current_epoch); // Farm position migration code - self.try_set_farm_position_migration_nonce(); + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index 26622a02b..5bd41cecf 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -25,8 +25,6 @@ pub mod token_attributes; pub mod unbond_farm; pub mod unstake_farm; -pub const DEFAULT_FARM_POSITION_MIGRATION_NONCE: u64 = 1; - #[multiversx_sc::contract] pub trait FarmStaking: custom_rewards::CustomRewardsModule @@ -92,7 +90,8 @@ pub trait FarmStaking: self.min_unbond_epochs().set_if_empty(min_unbond_epochs); // Farm position migration code - self.try_set_farm_position_migration_nonce(); + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] @@ -149,23 +148,4 @@ pub trait FarmStaking: "May only call this function through VM query" ); } - - fn try_set_farm_position_migration_nonce(&self) { - if !self.farm_position_migration_nonce().is_empty() { - return; - } - - let farm_token_mapper = self.farm_token(); - - let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { - let token_identifier = farm_token_mapper.get_token_id_ref(); - self.blockchain() - .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier) - } else { - DEFAULT_FARM_POSITION_MIGRATION_NONCE - }; - - self.farm_position_migration_nonce() - .set(migration_farm_token_nonce); - } }