diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index 897ce8c8e..6aa2b48bf 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -74,6 +74,13 @@ dependencies = [ "token_send", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -488,6 +495,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index e8aa3099f..1aff7cb49 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 66 +// Endpoints: 65 // Async Callback: 1 -// Total number of exported functions: 69 +// Total number of exported functions: 68 #![no_std] @@ -71,7 +71,6 @@ multiversx_sc_wasm_adapter::endpoints! { getAccumulatedRewardsForWeek => accumulated_rewards_for_week getFarmSupplyForWeek => farm_supply_for_week getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute - getUndistributedBoostedRewards => undistributed_boosted_rewards setBoostedYieldsFactors => set_boosted_yields_factors getBoostedYieldsFactors => get_boosted_yields_factors getCurrentWeek => get_current_week diff --git a/dex/farm/tests/farm_multi_user_test.rs b/dex/farm/tests/farm_multi_user_test.rs index 03315b184..210e3b799 100644 --- a/dex/farm/tests/farm_multi_user_test.rs +++ b/dex/farm/tests/farm_multi_user_test.rs @@ -690,12 +690,14 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { farm_setup.check_error_collect_undistributed_boosted_rewards( "Current week must be higher than the week offset", + 1, + 4, ); // advance to week 6 farm_setup.b_mock.set_block_epoch(36); - farm_setup.collect_undistributed_boosted_rewards(); + farm_setup.collect_undistributed_boosted_rewards(1, 1); farm_setup.check_undistributed_boosted_rewards(1); farm_setup.check_remaining_boosted_rewards_to_distribute(1, 0); farm_setup.check_remaining_boosted_rewards_to_distribute(2, 1); @@ -704,7 +706,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { // advance to week 8 farm_setup.b_mock.set_block_epoch(50); - farm_setup.collect_undistributed_boosted_rewards(); + farm_setup.collect_undistributed_boosted_rewards(1, 3); farm_setup.check_undistributed_boosted_rewards(3); farm_setup.check_remaining_boosted_rewards_to_distribute(1, 0); @@ -966,7 +968,7 @@ fn farm_claim_with_minimum_tokens() { let remaining_boosted_yields_rewards = total_boosted_yields_rewards - first_boosted_amt - second_boosted_amt; farm_setup.check_undistributed_boosted_rewards(0); - farm_setup.collect_undistributed_boosted_rewards(); + farm_setup.collect_undistributed_boosted_rewards(1, 1); farm_setup.check_undistributed_boosted_rewards(remaining_boosted_yields_rewards); farm_setup.check_remaining_boosted_rewards_to_distribute(1, 0); farm_setup.check_remaining_boosted_rewards_to_distribute(2, 0); diff --git a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs index cb12a2a1e..b681b2166 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -24,9 +24,11 @@ use farm_boosted_yields::FarmBoostedYieldsModule; use farm_token::FarmTokenModule; use pausable::{PausableModule, State}; use sc_whitelist_module::SCWhitelistModule; -use week_timekeeping::Epoch; +use week_timekeeping::{Epoch, Week}; use weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule; +use super::single_user_farm_setup::MEX_TOKEN_ID; + pub static REWARD_TOKEN_ID: &[u8] = b"REW-123456"; pub static FARMING_TOKEN_ID: &[u8] = b"LPTOK-123456"; pub static FARM_TOKEN_ID: &[u8] = b"FARM-123456"; @@ -65,6 +67,7 @@ where pub first_user: Address, pub second_user: Address, pub third_user: Address, + pub undistributed_rew_dest: Address, pub last_farm_token_nonce: u64, pub farm_wrapper: ContractObjWrapper, FarmObjBuilder>, pub energy_factory_wrapper: @@ -91,6 +94,7 @@ where let first_user = b_mock.create_user_account(&rust_zero); let second_user = b_mock.create_user_account(&rust_zero); let third_user = b_mock.create_user_account(&rust_zero); + let undistributed_rew_dest = b_mock.create_user_account(&rust_zero); let farm_wrapper = b_mock.create_sc_account(&rust_zero, Some(&owner), farm_builder, "farm.wasm"); let energy_factory_wrapper = b_mock.create_sc_account( @@ -102,6 +106,20 @@ where let eu_wrapper = b_mock.create_sc_account(&rust_zero, Some(&owner), eu_builder, "energy update mock"); + b_mock + .execute_tx(&owner, &energy_factory_wrapper, &rust_zero, |sc| { + sc.init(); + sc.base_asset_token_id() + .set(managed_token_id!(MEX_TOKEN_ID)); + }) + .assert_ok(); + + b_mock.set_esdt_local_roles( + energy_factory_wrapper.address_ref(), + MEX_TOKEN_ID, + &[EsdtLocalRole::Mint], + ); + b_mock .execute_tx(&owner, &eu_wrapper, &rust_zero, |sc| { sc.init(); @@ -185,6 +203,7 @@ where first_user, second_user, third_user, + undistributed_rew_dest, last_farm_token_nonce: 0, farm_wrapper, energy_factory_wrapper, @@ -651,18 +670,33 @@ where .assert_ok(); } - pub fn check_error_collect_undistributed_boosted_rewards(&mut self, expected_message: &str) { + pub fn check_error_collect_undistributed_boosted_rewards( + &mut self, + expected_message: &str, + start_week: Week, + end_week: Week, + ) { + let dest_address = self.undistributed_rew_dest.clone(); self.b_mock .execute_tx(&self.owner, &self.farm_wrapper, &rust_biguint!(0), |sc| { - sc.collect_undistributed_boosted_rewards(); + sc.collect_undistributed_boosted_rewards( + start_week, + end_week, + managed_address!(&dest_address), + ); }) .assert_error(4, expected_message) } - pub fn collect_undistributed_boosted_rewards(&mut self) { + pub fn collect_undistributed_boosted_rewards(&mut self, start_week: Week, end_week: Week) { + let dest_address = self.undistributed_rew_dest.clone(); self.b_mock .execute_tx(&self.owner, &self.farm_wrapper, &rust_biguint!(0), |sc| { - sc.collect_undistributed_boosted_rewards(); + sc.collect_undistributed_boosted_rewards( + start_week, + end_week, + managed_address!(&dest_address), + ); }) .assert_ok(); } @@ -683,12 +717,11 @@ where } pub fn check_undistributed_boosted_rewards(&mut self, expected_amount: u64) { - self.b_mock - .execute_query(&self.farm_wrapper, |sc| { - let result_managed = sc.undistributed_boosted_rewards().get(); - assert_eq!(result_managed, managed_biguint!(expected_amount)); - }) - .assert_ok(); + self.b_mock.check_esdt_balance( + &self.undistributed_rew_dest, + MEX_TOKEN_ID, + &rust_biguint!(expected_amount), + ); } pub fn check_farm_token_supply(&mut self, expected_farm_token_supply: u64) { diff --git a/dex/farm/wasm/Cargo.lock b/dex/farm/wasm/Cargo.lock index c3dea8cdc..92b4a7933 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/wasm/Cargo.lock @@ -74,6 +74,13 @@ dependencies = [ "token_send", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -458,6 +465,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index 525d76239..312ed3f3b 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 63 +// Endpoints: 62 // Async Callback: 1 -// Total number of exported functions: 66 +// Total number of exported functions: 65 #![no_std] @@ -68,7 +68,6 @@ multiversx_sc_wasm_adapter::endpoints! { getAccumulatedRewardsForWeek => accumulated_rewards_for_week getFarmSupplyForWeek => farm_supply_for_week getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute - getUndistributedBoostedRewards => undistributed_boosted_rewards setBoostedYieldsFactors => set_boosted_yields_factors getBoostedYieldsFactors => get_boosted_yields_factors getCurrentWeek => get_current_week diff --git a/dex/pair/wasm-pair-full/Cargo.lock b/dex/pair/wasm-pair-full/Cargo.lock index 50c1aa77e..fe9af7730 100644 --- a/dex/pair/wasm-pair-full/Cargo.lock +++ b/dex/pair/wasm-pair-full/Cargo.lock @@ -45,6 +45,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -327,6 +334,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/dex/pair/wasm-safe-price-view/Cargo.lock b/dex/pair/wasm-safe-price-view/Cargo.lock index e71c9ac82..47b6d15f3 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.lock +++ b/dex/pair/wasm-safe-price-view/Cargo.lock @@ -45,6 +45,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -327,6 +334,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/dex/pair/wasm/Cargo.lock b/dex/pair/wasm/Cargo.lock index 1b9f258d3..22f253c6a 100644 --- a/dex/pair/wasm/Cargo.lock +++ b/dex/pair/wasm/Cargo.lock @@ -45,6 +45,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -327,6 +334,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/dex/price-discovery/wasm/Cargo.lock b/dex/price-discovery/wasm/Cargo.lock index 4fbe6c51b..62c383266 100644 --- a/dex/price-discovery/wasm/Cargo.lock +++ b/dex/price-discovery/wasm/Cargo.lock @@ -38,6 +38,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -262,6 +269,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/dex/proxy-deployer/wasm/Cargo.lock b/dex/proxy-deployer/wasm/Cargo.lock index 8d87420e6..88813977d 100644 --- a/dex/proxy-deployer/wasm/Cargo.lock +++ b/dex/proxy-deployer/wasm/Cargo.lock @@ -74,6 +74,13 @@ dependencies = [ "token_send", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -469,6 +476,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/dex/router/wasm/Cargo.lock b/dex/router/wasm/Cargo.lock index a8e9d5976..8c965d9a5 100644 --- a/dex/router/wasm/Cargo.lock +++ b/dex/router/wasm/Cargo.lock @@ -45,6 +45,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -339,6 +346,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs index 456bf60d2..e1d39978d 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs +++ b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs @@ -3,7 +3,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -pub const USER_MAX_CLAIM_WEEKS: usize = 4; +pub const USER_MAX_CLAIM_WEEKS: Week = 4; pub mod base_impl; pub mod events; diff --git a/energy-integration/energy-factory-mock/src/lib.rs b/energy-integration/energy-factory-mock/src/lib.rs index d3354e67e..2b2693b78 100644 --- a/energy-integration/energy-factory-mock/src/lib.rs +++ b/energy-integration/energy-factory-mock/src/lib.rs @@ -52,9 +52,23 @@ pub trait EnergyFactoryMock { self.user_energy(&user).set(&energy); } + #[endpoint(transferUnlockedToken)] + fn transfer_unlocked_token(&self, dest: ManagedAddress, amount: BigUint) { + require!(amount != 0, "Invalid amount"); + + let base_asset_token_id = self.base_asset_token_id().get(); + self.send() + .esdt_local_mint(&base_asset_token_id, 0, &amount); + self.send() + .direct_esdt(&dest, &base_asset_token_id, 0, &amount); + } + #[storage_mapper("userEnergy")] fn user_energy(&self, user: &ManagedAddress) -> SingleValueMapper>; #[storage_mapper("lockedTokenId")] fn locked_token(&self) -> NonFungibleTokenMapper; + + #[storage_mapper("baseAssetTokenId")] + fn base_asset_token_id(&self) -> SingleValueMapper; } diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.lock b/energy-integration/energy-factory-mock/wasm/Cargo.lock index 4e08004ac..0937f217e 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.lock +++ b/energy-integration/energy-factory-mock/wasm/Cargo.lock @@ -38,6 +38,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -253,6 +260,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/energy-integration/energy-factory-mock/wasm/src/lib.rs b/energy-integration/energy-factory-mock/wasm/src/lib.rs index 400849b5a..9af0d54c3 100644 --- a/energy-integration/energy-factory-mock/wasm/src/lib.rs +++ b/energy-integration/energy-factory-mock/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 4 +// Endpoints: 5 // Async Callback (empty): 1 -// Total number of exported functions: 6 +// Total number of exported functions: 7 #![no_std] @@ -22,6 +22,7 @@ multiversx_sc_wasm_adapter::endpoints! { getEnergyAmountForUser => get_energy_amount_for_user getEnergyEntryForUser => get_energy_entry_for_user setUserEnergyAfterLockedTokenTransfer => set_user_energy_after_locked_token_transfer + transferUnlockedToken => transfer_unlocked_token ) } diff --git a/energy-integration/energy-update/wasm/Cargo.lock b/energy-integration/energy-update/wasm/Cargo.lock index e36d78e0b..68376f8b9 100644 --- a/energy-integration/energy-update/wasm/Cargo.lock +++ b/energy-integration/energy-update/wasm/Cargo.lock @@ -74,6 +74,13 @@ dependencies = [ "token_send", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -468,6 +475,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/energy-integration/farm-boosted-yields/src/lib.rs b/energy-integration/farm-boosted-yields/src/lib.rs index 739907b2c..f3f088f96 100644 --- a/energy-integration/farm-boosted-yields/src/lib.rs +++ b/energy-integration/farm-boosted-yields/src/lib.rs @@ -30,6 +30,16 @@ impl SplitReward { } } +mod energy_factory_proxy_send_rew { + multiversx_sc::imports!(); + + #[multiversx_sc::proxy] + pub trait EnergyFactorySendRewProxy { + #[endpoint(transferUnlockedToken)] + fn transfer_unlocked_token(&self, dest: ManagedAddress, amount: BigUint); + } +} + #[multiversx_sc::module] pub trait FarmBoostedYieldsModule: boosted_yields_factors::BoostedYieldsFactorsModule @@ -44,31 +54,41 @@ pub trait FarmBoostedYieldsModule: + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + energy_query::EnergyQueryModule { + #[only_owner] #[endpoint(collectUndistributedBoostedRewards)] - fn collect_undistributed_boosted_rewards(&self) { - self.require_caller_has_admin_permissions(); - - let collect_rewards_offset = USER_MAX_CLAIM_WEEKS + 1usize; + fn collect_undistributed_boosted_rewards( + &self, + start_week: Week, + end_week: Week, + dest_address: ManagedAddress, + ) { + let collect_rewards_offset = USER_MAX_CLAIM_WEEKS + 1; let current_week = self.get_current_week(); require!( current_week > collect_rewards_offset, "Current week must be higher than the week offset" ); + require!(start_week <= end_week, "Invalid week numbers"); + require!( + end_week <= current_week - collect_rewards_offset, + "Invalid end week" + ); - let last_collect_week_mapper = self.last_undistributed_boosted_rewards_collect_week(); - let first_collect_week = last_collect_week_mapper.get() + 1; - let last_collect_week = current_week - collect_rewards_offset; - if first_collect_week > last_collect_week { - return; + let mut total_rewards = BigUint::zero(); + for week in start_week..=end_week { + let rewards_to_distribute = self.remaining_boosted_rewards_to_distribute(week).take(); + total_rewards += rewards_to_distribute; } - for week in first_collect_week..=last_collect_week { - let rewards_to_distribute = self.remaining_boosted_rewards_to_distribute(week).take(); - self.undistributed_boosted_rewards() - .update(|total_amount| *total_amount += rewards_to_distribute); + if total_rewards == 0 { + return; } - last_collect_week_mapper.set(last_collect_week); + let energy_factory = self.energy_factory_address().get(); + let _: () = self + .energy_factory_send_rew_proxy_obj(energy_factory) + .transfer_unlocked_token(dest_address, total_rewards) + .execute_on_dest_context(); } fn take_reward_slice(&self, full_reward: BigUint) -> SplitReward { @@ -150,12 +170,11 @@ pub trait FarmBoostedYieldsModule: #[storage_mapper("remainingBoostedRewardsToDistribute")] fn remaining_boosted_rewards_to_distribute(&self, week: Week) -> SingleValueMapper; - #[storage_mapper("lastUndistributedBoostedRewardsCollectWeek")] - fn last_undistributed_boosted_rewards_collect_week(&self) -> SingleValueMapper; - - #[view(getUndistributedBoostedRewards)] - #[storage_mapper("undistributedBoostedRewards")] - fn undistributed_boosted_rewards(&self) -> SingleValueMapper; + #[proxy] + fn energy_factory_send_rew_proxy_obj( + &self, + sc_address: ManagedAddress, + ) -> energy_factory_proxy_send_rew::Proxy; } pub struct FarmBoostedYieldsWrapper { diff --git a/energy-integration/fees-collector/wasm/Cargo.lock b/energy-integration/fees-collector/wasm/Cargo.lock index d962ee257..4e67ac4bf 100644 --- a/energy-integration/fees-collector/wasm/Cargo.lock +++ b/energy-integration/fees-collector/wasm/Cargo.lock @@ -45,6 +45,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -279,6 +286,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/energy-integration/governance-v2/wasm/Cargo.lock b/energy-integration/governance-v2/wasm/Cargo.lock index 5853e1198..1bc423aba 100644 --- a/energy-integration/governance-v2/wasm/Cargo.lock +++ b/energy-integration/governance-v2/wasm/Cargo.lock @@ -45,6 +45,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -299,6 +306,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.lock b/farm-staking/farm-staking-proxy/wasm/Cargo.lock index 1f79bbe16..10299c347 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.lock +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.lock @@ -74,6 +74,13 @@ dependencies = [ "token_send", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -549,6 +556,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/farm-staking/farm-staking/wasm/Cargo.lock b/farm-staking/farm-staking/wasm/Cargo.lock index 465de9d30..95d2f2a15 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/wasm/Cargo.lock @@ -74,6 +74,13 @@ dependencies = [ "token_send", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -489,6 +496,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index 9489b1d7e..7e687cca5 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 69 +// Endpoints: 68 // Async Callback: 1 -// Total number of exported functions: 72 +// Total number of exported functions: 71 #![no_std] @@ -74,7 +74,6 @@ multiversx_sc_wasm_adapter::endpoints! { getAccumulatedRewardsForWeek => accumulated_rewards_for_week getFarmSupplyForWeek => farm_supply_for_week getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute - getUndistributedBoostedRewards => undistributed_boosted_rewards setBoostedYieldsFactors => set_boosted_yields_factors getBoostedYieldsFactors => get_boosted_yields_factors getCurrentWeek => get_current_week diff --git a/legacy-contracts/factory-legacy/wasm/Cargo.lock b/legacy-contracts/factory-legacy/wasm/Cargo.lock index f9d78eed7..9a2de5fca 100644 --- a/legacy-contracts/factory-legacy/wasm/Cargo.lock +++ b/legacy-contracts/factory-legacy/wasm/Cargo.lock @@ -38,6 +38,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -249,6 +256,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock b/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock index ff771930d..64e6817aa 100644 --- a/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock +++ b/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock @@ -74,6 +74,13 @@ dependencies = [ "token_send", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -509,6 +516,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock index d45260ddb..290b6eda0 100644 --- a/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock +++ b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock @@ -45,6 +45,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "either" version = "1.13.0" @@ -360,6 +367,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/locked-asset/energy-factory/src/lib.rs b/locked-asset/energy-factory/src/lib.rs index a8cd96be4..6f076537c 100644 --- a/locked-asset/energy-factory/src/lib.rs +++ b/locked-asset/energy-factory/src/lib.rs @@ -14,6 +14,7 @@ pub mod penalty; pub mod token_merging; pub mod token_whitelist; pub mod unlock_with_penalty; +pub mod unlocked_token_transfer; pub mod unstake; pub mod virtual_lock; @@ -47,6 +48,7 @@ pub trait SimpleLockEnergy: + virtual_lock::VirtualLockModule + sc_whitelist_module::SCWhitelistModule + locked_token_transfer::LockedTokenTransferModule + + unlocked_token_transfer::UnlockedTokenTransferModule + legacy_token_decode_module::LegacyTokenDecodeModule { /// Args: @@ -82,11 +84,10 @@ pub trait SimpleLockEnergy: self.min_migrated_token_locked_period() .set(min_migrated_token_locked_period); - self.base_asset_token_id() - .set_if_empty(&base_asset_token_id); - self.legacy_locked_token_id().set_if_empty(&legacy_token_id); + self.base_asset_token_id().set(&base_asset_token_id); + self.legacy_locked_token_id().set(&legacy_token_id); self.old_locked_asset_factory_address() - .set_if_empty(&old_locked_asset_factory_address); + .set(&old_locked_asset_factory_address); self.set_paused(true); } diff --git a/locked-asset/energy-factory/src/locked_token_transfer.rs b/locked-asset/energy-factory/src/locked_token_transfer.rs index 8e9397e48..d37d6f6cd 100644 --- a/locked-asset/energy-factory/src/locked_token_transfer.rs +++ b/locked-asset/energy-factory/src/locked_token_transfer.rs @@ -15,6 +15,7 @@ pub trait LockedTokenTransferModule: let mapper = self.token_transfer_whitelist(); for sc_addr in sc_addresses { self.require_sc_address(&sc_addr); + mapper.add(&sc_addr); } } @@ -38,6 +39,7 @@ pub trait LockedTokenTransferModule: energy: Energy, ) { self.require_not_paused(); + let caller = self.blockchain().get_caller(); self.token_transfer_whitelist().require_whitelisted(&caller); diff --git a/locked-asset/energy-factory/src/unlock_with_penalty.rs b/locked-asset/energy-factory/src/unlock_with_penalty.rs index 102565ed5..d14ff3e79 100644 --- a/locked-asset/energy-factory/src/unlock_with_penalty.rs +++ b/locked-asset/energy-factory/src/unlock_with_penalty.rs @@ -10,7 +10,7 @@ use crate::{energy::Energy, lock_options::MAX_PENALTY_PERCENTAGE}; pub static TOKEN_CAN_BE_UNLOCKED_ALREADY_ERR_MSG: &[u8] = b"Token can be unlocked already"; pub struct LockReduceResult { - pub new_lock_epochs: u64, + pub new_lock_epochs: Epoch, pub unlocked_tokens: EgldOrEsdtTokenPayment, pub energy: Energy, } @@ -39,6 +39,7 @@ pub trait UnlockWithPenaltyModule: #[endpoint(unlockEarly)] fn unlock_early(&self) { self.require_not_paused(); + let caller = self.blockchain().get_caller(); let payment = self.call_value().single_esdt(); let reduce_result = self.reduce_lock_period_common(&caller, payment.clone(), None); diff --git a/locked-asset/energy-factory/src/unlocked_token_transfer.rs b/locked-asset/energy-factory/src/unlocked_token_transfer.rs new file mode 100644 index 000000000..c2269b0cd --- /dev/null +++ b/locked-asset/energy-factory/src/unlocked_token_transfer.rs @@ -0,0 +1,55 @@ +multiversx_sc::imports!(); + +#[multiversx_sc::module] +pub trait UnlockedTokenTransferModule: + utils::UtilsModule + + multiversx_sc_modules::pause::PauseModule + + crate::token_whitelist::TokenWhitelistModule +{ + #[only_owner] + #[endpoint(addToUnlockedTokenTransferWhitelist)] + fn add_to_unlocked_token_transfer_whitelist( + &self, + sc_addresses: MultiValueEncoded, + ) { + let mapper = self.unlocked_token_transfer_whitelist(); + for sc_addr in sc_addresses { + self.require_sc_address(&sc_addr); + + mapper.add(&sc_addr); + } + } + + #[only_owner] + #[endpoint(removeFromUnlockedTokenTransferWhitelist)] + fn remove_from_unlocked_token_transfer_whitelist( + &self, + sc_addresses: MultiValueEncoded, + ) { + let mapper = self.unlocked_token_transfer_whitelist(); + for sc_addr in sc_addresses { + mapper.remove(&sc_addr); + } + } + + #[endpoint(transferUnlockedToken)] + fn transfer_unlocked_token(&self, dest: ManagedAddress, amount: BigUint) { + self.require_not_paused(); + require!(amount != 0, "Invalid amount"); + + let caller = self.blockchain().get_caller(); + require!( + self.unlocked_token_transfer_whitelist().contains(&caller), + "May not call this endpoint" + ); + + let base_asset_token_id = self.base_asset_token_id().get(); + self.send() + .esdt_local_mint(&base_asset_token_id, 0, &amount); + self.send() + .direct_esdt(&dest, &base_asset_token_id, 0, &amount); + } + + #[storage_mapper("ulkTokenTransfWhitelist")] + fn unlocked_token_transfer_whitelist(&self) -> WhitelistMapper; +} diff --git a/locked-asset/energy-factory/wasm/Cargo.lock b/locked-asset/energy-factory/wasm/Cargo.lock index 93a271e50..c539f6b4b 100644 --- a/locked-asset/energy-factory/wasm/Cargo.lock +++ b/locked-asset/energy-factory/wasm/Cargo.lock @@ -38,6 +38,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -237,6 +244,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/locked-asset/energy-factory/wasm/src/lib.rs b/locked-asset/energy-factory/wasm/src/lib.rs index 181f50f1a..feff62338 100644 --- a/locked-asset/energy-factory/wasm/src/lib.rs +++ b/locked-asset/energy-factory/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 34 +// Endpoints: 37 // Async Callback: 1 -// Total number of exported functions: 37 +// Total number of exported functions: 40 #![no_std] @@ -54,6 +54,9 @@ multiversx_sc_wasm_adapter::endpoints! { addToTokenTransferWhitelist => add_to_token_transfer_whitelist removeFromTokenTransferWhitelist => remove_from_token_transfer_whitelist setUserEnergyAfterLockedTokenTransfer => set_user_energy_after_locked_token_transfer + addToUnlockedTokenTransferWhitelist => add_to_unlocked_token_transfer_whitelist + removeFromUnlockedTokenTransferWhitelist => remove_from_unlocked_token_transfer_whitelist + transferUnlockedToken => transfer_unlocked_token ) } diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.lock b/locked-asset/lkmex-transfer/wasm/Cargo.lock index d269860db..e10425062 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.lock +++ b/locked-asset/lkmex-transfer/wasm/Cargo.lock @@ -38,6 +38,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -268,6 +275,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/locked-asset/locked-token-wrapper/wasm/Cargo.lock b/locked-asset/locked-token-wrapper/wasm/Cargo.lock index 98b8ba9bc..6ee87c898 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.lock +++ b/locked-asset/locked-token-wrapper/wasm/Cargo.lock @@ -38,6 +38,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -292,6 +299,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/locked-asset/proxy_dex/wasm/Cargo.lock b/locked-asset/proxy_dex/wasm/Cargo.lock index 78557ecb7..e5731cf54 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.lock +++ b/locked-asset/proxy_dex/wasm/Cargo.lock @@ -78,7 +78,6 @@ dependencies = [ name = "disable-add-liq" version = "0.0.0" dependencies = [ - "common_structs", "multiversx-sc", ] @@ -521,6 +520,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ] diff --git a/locked-asset/simple-lock/wasm/Cargo.lock b/locked-asset/simple-lock/wasm/Cargo.lock index 45c1b2963..e24df1557 100644 --- a/locked-asset/simple-lock/wasm/Cargo.lock +++ b/locked-asset/simple-lock/wasm/Cargo.lock @@ -35,7 +35,6 @@ dependencies = [ name = "disable-add-liq" version = "0.0.0" dependencies = [ - "common_structs", "multiversx-sc", ] diff --git a/locked-asset/token-unstake/wasm/Cargo.lock b/locked-asset/token-unstake/wasm/Cargo.lock index 788eb7478..486861f02 100644 --- a/locked-asset/token-unstake/wasm/Cargo.lock +++ b/locked-asset/token-unstake/wasm/Cargo.lock @@ -45,6 +45,13 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "disable-add-liq" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -244,6 +251,7 @@ name = "simple-lock" version = "0.0.0" dependencies = [ "common_structs", + "disable-add-liq", "multiversx-sc", "multiversx-sc-modules", ]