Skip to content

Commit

Permalink
more migration remove
Browse files Browse the repository at this point in the history
  • Loading branch information
dorin-iancu committed Feb 20, 2024
1 parent 3dcbb2e commit a4fe8ad
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 69 deletions.
26 changes: 0 additions & 26 deletions common/modules/farm/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,6 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio
}
}

fn try_set_farm_position_migration_nonce(
&self,
farm_token_mapper: NonFungibleTokenMapper<Self::Api>,
) {
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();
let current_nonce = self
.blockchain()
.get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier);
current_nonce + DEFAULT_FARM_POSITION_MIGRATION_NONCE
} 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<TokenIdentifier>;
Expand Down Expand Up @@ -120,8 +98,4 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio
&self,
user: &ManagedAddress,
) -> SingleValueMapper<UserTotalFarmPosition<Self::Api>>;

#[view(getFarmPositionMigrationNonce)]
#[storage_mapper("farm_position_migration_nonce")]
fn farm_position_migration_nonce(&self) -> SingleValueMapper<Nonce>;
}
6 changes: 1 addition & 5 deletions dex/farm-concentrated-liq/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ pub trait Farm:
}

#[endpoint]
fn upgrade(&self) {
// Farm position migration code
let farm_token_mapper = self.farm_token();
self.try_set_farm_position_migration_nonce(farm_token_mapper);
}
fn upgrade(&self) {}

#[payable("*")]
#[endpoint(enterFarm)]
Expand Down
18 changes: 5 additions & 13 deletions dex/farm-with-locked-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,18 @@ pub trait Farm:
admins,
);

self.penalty_percent().set_if_empty(DEFAULT_PENALTY_PERCENT);
self.penalty_percent().set(DEFAULT_PENALTY_PERCENT);
self.minimum_farming_epochs()
.set_if_empty(DEFAULT_MINUMUM_FARMING_EPOCHS);
self.burn_gas_limit().set_if_empty(DEFAULT_BURN_GAS_LIMIT);
.set(DEFAULT_MINUMUM_FARMING_EPOCHS);
self.burn_gas_limit().set(DEFAULT_BURN_GAS_LIMIT);
self.pair_contract_address().set(&pair_contract_address);

let current_epoch = self.blockchain().get_block_epoch();
self.first_week_start_epoch().set_if_empty(current_epoch);

// Farm position migration code
let farm_token_mapper = self.farm_token();
self.try_set_farm_position_migration_nonce(farm_token_mapper);
self.first_week_start_epoch().set(current_epoch);
}

#[endpoint]
fn upgrade(&self) {
// Farm position migration code
let farm_token_mapper = self.farm_token();
self.try_set_farm_position_migration_nonce(farm_token_mapper);
}
fn upgrade(&self) {}

#[payable("*")]
#[endpoint(enterFarm)]
Expand Down
18 changes: 5 additions & 13 deletions dex/farm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,18 @@ pub trait Farm:
admins,
);

self.penalty_percent().set_if_empty(DEFAULT_PENALTY_PERCENT);
self.penalty_percent().set(DEFAULT_PENALTY_PERCENT);
self.minimum_farming_epochs()
.set_if_empty(DEFAULT_MINUMUM_FARMING_EPOCHS);
self.burn_gas_limit().set_if_empty(DEFAULT_BURN_GAS_LIMIT);
.set(DEFAULT_MINUMUM_FARMING_EPOCHS);
self.burn_gas_limit().set(DEFAULT_BURN_GAS_LIMIT);
self.pair_contract_address().set(&pair_contract_address);

let current_epoch = self.blockchain().get_block_epoch();
self.first_week_start_epoch().set_if_empty(current_epoch);

// Farm position migration code
let farm_token_mapper = self.farm_token();
self.try_set_farm_position_migration_nonce(farm_token_mapper);
self.first_week_start_epoch().set(current_epoch);
}

#[endpoint]
fn upgrade(&self) {
// Farm position migration code
let farm_token_mapper = self.farm_token();
self.try_set_farm_position_migration_nonce(farm_token_mapper);
}
fn upgrade(&self) {}

#[payable("*")]
#[endpoint(enterFarm)]
Expand Down
16 changes: 4 additions & 12 deletions farm-staking/farm-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,17 @@ pub trait FarmStaking:
);

require!(max_apr > 0u64, "Invalid max APR percentage");
self.max_annual_percentage_rewards().set_if_empty(&max_apr);
self.max_annual_percentage_rewards().set(&max_apr);

require!(
min_unbond_epochs <= MAX_MIN_UNBOND_EPOCHS,
"Invalid min unbond epochs"
);
self.min_unbond_epochs().set_if_empty(min_unbond_epochs);

// Farm position migration code
let farm_token_mapper = self.farm_token();
self.try_set_farm_position_migration_nonce(farm_token_mapper);
self.min_unbond_epochs().set(min_unbond_epochs);
}

#[endpoint]
fn upgrade(&self) {
// Farm position migration code
let farm_token_mapper = self.farm_token();
self.try_set_farm_position_migration_nonce(farm_token_mapper);
}
fn upgrade(&self) {}

#[payable("*")]
#[endpoint(mergeFarmTokens)]
Expand All @@ -121,7 +113,7 @@ pub trait FarmStaking:

(merged_farm_token, boosted_rewards_payment).into()
}

#[view(calculateRewardsForGivenPosition)]
fn calculate_rewards_for_given_position(
&self,
Expand Down

0 comments on commit a4fe8ad

Please sign in to comment.