diff --git a/Cargo.lock b/Cargo.lock index 43e7acf34..3b7a33332 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -763,6 +763,7 @@ version = "0.0.0" dependencies = [ "common_errors", "common_structs", + "energy-factory", "multiversx-sc", "multiversx-sc-modules", "multiversx-sc-scenario", @@ -2352,9 +2353,13 @@ name = "proxy-dex-legacy" version = "0.0.0" dependencies = [ "common_structs", + "energy-factory", + "energy-query", "factory-legacy", + "farm-v13-locked-rewards", "multiversx-sc", "multiversx-sc-scenario", + "pair", "token_merge_helper", ] diff --git a/legacy-contracts/factory-legacy/Cargo.toml b/legacy-contracts/factory-legacy/Cargo.toml index bff8b6fa4..f1dee1bb8 100644 --- a/legacy-contracts/factory-legacy/Cargo.toml +++ b/legacy-contracts/factory-legacy/Cargo.toml @@ -24,4 +24,7 @@ path = "../../common/common_structs" path = "../../common/common_errors" [dependencies.token_merge_helper] -path = "../../common/modules/token_merge_helper" \ No newline at end of file +path = "../../common/modules/token_merge_helper" + +[dependencies.energy-factory] +path = "../../locked-asset/energy-factory" \ No newline at end of file diff --git a/legacy-contracts/factory-legacy/src/migration.rs b/legacy-contracts/factory-legacy/src/migration.rs index 393f82a59..653b93aa0 100644 --- a/legacy-contracts/factory-legacy/src/migration.rs +++ b/legacy-contracts/factory-legacy/src/migration.rs @@ -1,23 +1,7 @@ multiversx_sc::imports!(); use common_structs::UnlockEpochAmountPairs; - -mod energy_factory_proxy { - use common_structs::UnlockEpochAmountPairs; - - multiversx_sc::imports!(); - - #[multiversx_sc::proxy] - pub trait EnergyFactoryProxy { - #[endpoint(updateEnergyAfterOldTokenUnlock)] - fn update_energy_after_old_token_unlock( - &self, - original_caller: ManagedAddress, - initial_epoch_amount_pairs: UnlockEpochAmountPairs, - final_epoch_amount_pairs: UnlockEpochAmountPairs, - ); - } -} +use energy_factory::migration::ProxyTrait as _; #[multiversx_sc::module] pub trait LockedTokenMigrationModule: @@ -54,7 +38,7 @@ pub trait LockedTokenMigrationModule: fn new_factory_proxy_builder( &self, sc_address: ManagedAddress, - ) -> energy_factory_proxy::Proxy; + ) -> energy_factory::Proxy; #[storage_mapper("newFactoryAddress")] fn new_factory_address(&self) -> SingleValueMapper; diff --git a/legacy-contracts/factory-legacy/wasm/Cargo.lock b/legacy-contracts/factory-legacy/wasm/Cargo.lock index 50cc43b0b..84827ca96 100644 --- a/legacy-contracts/factory-legacy/wasm/Cargo.lock +++ b/legacy-contracts/factory-legacy/wasm/Cargo.lock @@ -44,12 +44,29 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +[[package]] +name = "energy-factory" +version = "0.0.0" +dependencies = [ + "common_structs", + "legacy_token_decode_module", + "math", + "mergeable", + "multiversx-sc", + "multiversx-sc-modules", + "sc_whitelist_module", + "simple-lock", + "unwrappable", + "utils", +] + [[package]] name = "factory-legacy" version = "0.0.0" dependencies = [ "common_errors", "common_structs", + "energy-factory", "multiversx-sc", "multiversx-sc-modules", "token_merge_helper", @@ -82,6 +99,15 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[package]] +name = "legacy_token_decode_module" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "utils", +] + [[package]] name = "math" version = "0.0.0" @@ -210,6 +236,23 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "sc_whitelist_module" +version = "0.0.0" +dependencies = [ + "common_errors", + "multiversx-sc", +] + +[[package]] +name = "simple-lock" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "multiversx-sc-modules", +] + [[package]] name = "smallvec" version = "1.13.2" @@ -253,3 +296,13 @@ version = "0.0.0" dependencies = [ "multiversx-sc", ] + +[[package]] +name = "utils" +version = "0.0.0" +dependencies = [ + "common_structs", + "fixed-supply-token", + "mergeable", + "multiversx-sc", +] diff --git a/legacy-contracts/farm-v12/src/lib.rs b/legacy-contracts/farm-v12/src/lib.rs index 2623c773f..c126c2135 100644 --- a/legacy-contracts/farm-v12/src/lib.rs +++ b/legacy-contracts/farm-v12/src/lib.rs @@ -22,7 +22,7 @@ pub trait FarmV12 { #[payable("*")] #[endpoint(acceptFee)] fn accept_fee(&self, _token_in: TokenIdentifier, _amount: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(calculateRewardsForGivenPosition)] @@ -31,12 +31,12 @@ pub trait FarmV12 { _amount: BigUint, _attributes_raw: ManagedBuffer, ) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(end_produce_rewards_as_owner)] fn end_produce_rewards_as_owner(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -45,167 +45,167 @@ pub trait FarmV12 { &self, _opt_accept_funds_func: OptionalValue, ) -> ExitFarmResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getBurnedTokenAmount)] fn burned_tokens(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getCurrentBlockFee)] fn current_block_fee_storage(&self) -> Option<(Nonce, BigUint)> { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getDivisionSafetyConstant)] fn division_safety_constant(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmTokenId)] fn farm_token_id(&self) -> TokenIdentifier { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmTokenSupply)] fn get_farm_token_supply(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmingTokenId)] fn farming_token_id(&self) -> TokenIdentifier { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmingTokenReserve)] fn farming_token_reserve(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getLastErrorMessage)] fn last_error_message(&self) -> ManagedBuffer { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getLastRewardBlockNonce)] fn last_reward_block_nonce(&self) -> Nonce { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getLockedAssetFactoryManagedAddress)] fn locked_asset_factory_address(&self) -> ManagedAddress { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getLockedRewardAprMuliplier)] fn locked_rewards_apr_multiplier(&self) -> u8 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getMinimumFarmingEpoch)] fn minimum_farming_epoch(&self) -> u8 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getOwner)] fn owner(&self) -> ManagedAddress { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getPairContractManagedAddress)] fn pair_contract_address(&self) -> ManagedAddress { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getPenaltyPercent)] fn penalty_percent(&self) -> u64 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getPerBlockRewardAmount)] fn per_block_reward_amount(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getRewardPerShare)] fn reward_per_share(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getRewardReserve)] fn reward_reserve(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getRewardTokenId)] fn reward_token_id(&self) -> TokenIdentifier { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getRouterManagedAddress)] fn router_address(&self) -> ManagedAddress { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getState)] fn state(&self) -> State { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getTransferExecGasLimit)] fn transfer_exec_gas_limit(&self) -> u64 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getUndistributedFees)] fn undistributed_fee_storage(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(pause)] fn pause(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(resume)] fn resume(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(setPerBlockRewardAmount)] fn set_per_block_reward_amount(&self, _per_block_amount: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(setTransferRoleFarmToken)] fn set_transfer_role_farm_token(&self, _opt_address: OptionalValue) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(set_locked_rewards_apr_multiplier)] fn set_locked_rewards_apr_multiplier(&self, _muliplier: u8) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(set_minimum_farming_epochs)] fn set_minimum_farming_epochs(&self, _epochs: u8) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(set_penalty_percent)] fn set_penalty_percent(&self, _percent: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(set_transfer_exec_gas_limit)] fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(start_produce_rewards)] fn start_produce_rewards(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } } diff --git a/legacy-contracts/farm-v13-custom-rewards/src/lib.rs b/legacy-contracts/farm-v13-custom-rewards/src/lib.rs index 81a4d4e5a..4708be991 100644 --- a/legacy-contracts/farm-v13-custom-rewards/src/lib.rs +++ b/legacy-contracts/farm-v13-custom-rewards/src/lib.rs @@ -34,7 +34,7 @@ pub trait FarmV13LockedRewards { #[only_owner] #[endpoint(addAddressToWhitelist)] fn add_address_to_whitelist(&self, _address: ManagedAddress) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(calculateRewardsForGivenPosition)] @@ -43,7 +43,7 @@ pub trait FarmV13LockedRewards { _amount: BigUint, _attributes: FarmTokenAttributes, ) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -52,19 +52,19 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> ClaimRewardsResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[payable("*")] #[endpoint(depositRewards)] fn deposit_rewards(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(end_produce_rewards)] fn end_produce_rewards(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -73,7 +73,7 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> EnterFarmResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -82,97 +82,97 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> ExitFarmResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getBlockForEndRewards)] fn block_for_end_rewards(&self) -> u64 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getBurnGasLimit)] fn burn_gas_limit(&self) -> u64 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getDivisionSafetyConstant)] fn division_safety_constant(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmTokenId)] fn farm_token_id(&self) -> TokenIdentifier { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmTokenSupply)] fn farm_token_supply(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmingTokenId)] fn farming_token_id(&self) -> TokenIdentifier { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getLastErrorMessage)] fn last_error_message(&self) -> ManagedBuffer { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getLastRewardBlockNonce)] fn last_reward_block_nonce(&self) -> Nonce { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getMinimumFarmingEpoch)] fn minimum_farming_epochs(&self) -> u8 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getOwner)] fn owner(&self) -> ManagedAddress { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getPenaltyPercent)] fn penalty_percent(&self) -> u64 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getPerBlockRewardAmount)] fn per_block_reward_amount(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getRewardPerShare)] fn reward_per_share(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getRewardReserve)] fn reward_reserve(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getRewardTokenId)] fn reward_token_id(&self) -> TokenIdentifier { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getState)] fn state(&self) -> State { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getTransferExecGasLimit)] fn transfer_exec_gas_limit(&self) -> u64 { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getWhitelist)] fn whitelist(&self) -> UnorderedSetMapper { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -181,12 +181,12 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> EsdtTokenPayment { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(pause)] fn pause(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("EGLD")] @@ -197,58 +197,58 @@ pub trait FarmV13LockedRewards { _token_ticker: ManagedBuffer, _num_decimals: usize, ) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(removeAddressFromWhitelist)] fn remove_address_from_whitelist(&self, _address: ManagedAddress) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(resume)] fn resume(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(setBlockForEndRewards)] fn set_block_for_end_rewards(&self, _block_end: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(setLocalRolesFarmToken)] fn set_local_roles_farm_token(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(setPerBlockRewardAmount)] fn set_per_block_reward_amount(&self, _per_block_amount: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(set_burn_gas_limit)] fn set_burn_gas_limit(&self, _gas_limit: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(set_minimum_farming_epochs)] fn set_minimum_farming_epochs(&self, _epochs: u8) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(set_penalty_percent)] fn set_penalty_percent(&self, _percent: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(set_transfer_exec_gas_limit)] fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(startProduceRewards)] fn start_produce_rewards(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } } diff --git a/legacy-contracts/farm-v13-locked-rewards/src/lib.rs b/legacy-contracts/farm-v13-locked-rewards/src/lib.rs index 7dc899f89..abd6f7bb8 100644 --- a/legacy-contracts/farm-v13-locked-rewards/src/lib.rs +++ b/legacy-contracts/farm-v13-locked-rewards/src/lib.rs @@ -4,7 +4,7 @@ use multiversx_sc::derive_imports::*; use multiversx_sc::imports::*; type Nonce = u64; -type ExitFarmResultType = +pub type ExitFarmResultType = MultiValue2, EsdtTokenPayment>; #[derive(TopEncode, TopDecode, PartialEq, TypeAbi)] @@ -73,7 +73,7 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> ExitFarmResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -82,7 +82,7 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> EsdtTokenPayment { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(calculateRewardsForGivenPosition)] @@ -91,71 +91,71 @@ pub trait FarmV13LockedRewards { _amount: BigUint, _attributes: FarmTokenAttributes, ) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn end_produce_rewards(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(setPerBlockRewardAmount)] fn set_per_block_rewards(&self, _per_block_amount: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn set_penalty_percent(&self, _percent: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn set_minimum_farming_epochs(&self, _epochs: u8) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn set_burn_gas_limit(&self, _gas_limit: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(setRpsAndStartRewards)] fn set_rps_and_start_rewards(&self, _rps: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn pause(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn resume(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(startProduceRewards)] fn start_produce_rewards_as_owner(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(setFarmTokenSupply)] fn set_farm_token_supply(&self, _supply: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] @@ -167,7 +167,7 @@ pub trait FarmV13LockedRewards { _new_farm_address: ManagedAddress, _new_farm_with_lock_address: ManagedAddress, ) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] @@ -179,13 +179,13 @@ pub trait FarmV13LockedRewards { _token_ticker: ManagedBuffer, _num_decimals: usize, ) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(setLocalRolesFarmToken)] fn set_local_roles_farm_token(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -195,7 +195,7 @@ pub trait FarmV13LockedRewards { _old_attrs: FarmTokenAttributesV1_2, _orig_caller: ManagedAddress, ) -> EsdtTokenPayment { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmMigrationConfiguration)] diff --git a/legacy-contracts/farm-v13/src/lib.rs b/legacy-contracts/farm-v13/src/lib.rs index 204a3cfb1..047d6923a 100644 --- a/legacy-contracts/farm-v13/src/lib.rs +++ b/legacy-contracts/farm-v13/src/lib.rs @@ -77,7 +77,7 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> EnterFarmResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -86,7 +86,7 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> ExitFarmResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -95,7 +95,7 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> ClaimRewardsResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -104,7 +104,7 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> CompoundRewardsResultType { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -113,7 +113,7 @@ pub trait FarmV13LockedRewards { &self, _opt_accept_funds_func: OptionalValue, ) -> EsdtTokenPayment { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(calculateRewardsForGivenPosition)] @@ -122,66 +122,66 @@ pub trait FarmV13LockedRewards { _amount: BigUint, _attributes: FarmTokenAttributes, ) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn end_produce_rewards(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(setPerBlockRewardAmount)] fn set_per_block_rewards(&self, _per_block_amount: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn set_penalty_percent(&self, _percent: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn set_minimum_farming_epochs(&self, _epochs: u8) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn set_burn_gas_limit(&self, _gas_limit: u64) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn pause(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint] fn resume(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(startProduceRewards)] fn start_produce_rewards_as_owner(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } - + #[only_owner] #[endpoint(setFarmTokenSupply)] fn set_farm_token_supply(&self, _supply: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] @@ -193,7 +193,7 @@ pub trait FarmV13LockedRewards { _new_farm_address: ManagedAddress, _new_farm_with_lock_address: ManagedAddress, ) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] @@ -205,18 +205,18 @@ pub trait FarmV13LockedRewards { _token_ticker: ManagedBuffer, _num_decimals: usize, ) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(setLocalRolesFarmToken)] fn set_local_roles_farm_token(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[endpoint(setRpsAndStartRewards)] fn set_rps_and_start_rewards(&self, _rps: BigUint) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] @@ -226,7 +226,7 @@ pub trait FarmV13LockedRewards { _old_attrs: FarmTokenAttributesV1_2, _orig_caller: ManagedAddress, ) -> EsdtTokenPayment { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getFarmMigrationConfiguration)] diff --git a/legacy-contracts/price-discovery-v1/src/lib.rs b/legacy-contracts/price-discovery-v1/src/lib.rs index 1f4852e54..065cfecec 100644 --- a/legacy-contracts/price-discovery-v1/src/lib.rs +++ b/legacy-contracts/price-discovery-v1/src/lib.rs @@ -20,29 +20,29 @@ pub trait PriceDiscoveryV1 { #[payable("*")] #[endpoint] fn deposit(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] #[endpoint] fn withdraw(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] #[endpoint] fn redeem(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getCurrentPrice)] fn calculate_price(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getCurrentPhase)] fn get_current_phase(&self) -> Phase { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] @@ -54,13 +54,13 @@ pub trait PriceDiscoveryV1 { _token_ticker: ManagedBuffer, _nr_decimals: usize, ) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(createInitialRedeemTokens)] fn create_initial_redeem_tokens(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getLaunchedTokenId)] diff --git a/legacy-contracts/price-discovery-v2/src/lib.rs b/legacy-contracts/price-discovery-v2/src/lib.rs index 77563ae78..cf63515a3 100644 --- a/legacy-contracts/price-discovery-v2/src/lib.rs +++ b/legacy-contracts/price-discovery-v2/src/lib.rs @@ -20,29 +20,29 @@ pub trait PriceDiscoveryV2 { #[payable("*")] #[endpoint] fn deposit(&self) -> EsdtTokenPayment { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] #[endpoint] fn withdraw(&self) -> EgldOrEsdtTokenPayment { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[payable("*")] #[endpoint] fn redeem(&self) -> EgldOrEsdtTokenPayment { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getCurrentPrice)] fn calculate_price(&self) -> BigUint { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getCurrentPhase)] fn get_current_phase(&self) -> Phase { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] @@ -54,13 +54,13 @@ pub trait PriceDiscoveryV2 { _token_ticker: ManagedBuffer, _nr_decimals: usize, ) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[only_owner] #[endpoint(createInitialRedeemTokens)] fn create_initial_redeem_tokens(&self) { - sc_panic!("This is a legacy contract, should not be interacted with"); + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); } #[view(getLaunchedTokenId)] diff --git a/legacy-contracts/proxy-dex-legacy/Cargo.toml b/legacy-contracts/proxy-dex-legacy/Cargo.toml index d91ce9636..0443092ed 100644 --- a/legacy-contracts/proxy-dex-legacy/Cargo.toml +++ b/legacy-contracts/proxy-dex-legacy/Cargo.toml @@ -22,3 +22,15 @@ path = "../../common/modules/token_merge_helper" [dependencies.factory-legacy] path = "../factory-legacy" + +[dependencies.energy-factory] +path = "../../locked-asset/energy-factory" + +[dependencies.energy-query] +path = "../../energy-integration/common-modules/energy-query" + +[dependencies.farm-v13-locked-rewards] +path = "../farm-v13-locked-rewards" + +[dependencies.pair] +path = "../../dex/pair" \ No newline at end of file diff --git a/legacy-contracts/proxy-dex-legacy/src/energy.rs b/legacy-contracts/proxy-dex-legacy/src/energy.rs deleted file mode 100644 index 651bbf544..000000000 --- a/legacy-contracts/proxy-dex-legacy/src/energy.rs +++ /dev/null @@ -1,109 +0,0 @@ -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -use common_structs::Epoch; - -#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, Clone, PartialEq, Debug)] -pub struct Energy { - amount: BigInt, - last_update_epoch: Epoch, - total_locked_tokens: BigUint, -} - -impl Default for Energy { - fn default() -> Self { - Self { - amount: BigInt::zero(), - last_update_epoch: 0, - total_locked_tokens: BigUint::zero(), - } - } -} - -impl Energy { - #[inline] - pub fn new( - amount: BigInt, - last_update_epoch: Epoch, - total_locked_tokens: BigUint, - ) -> Self { - Energy { - amount, - last_update_epoch, - total_locked_tokens, - } - } - - pub fn new_zero_energy(current_epoch: Epoch) -> Self { - Self::new(BigInt::zero(), current_epoch, BigUint::zero()) - } - - fn add(&mut self, future_epoch: Epoch, current_epoch: Epoch, amount_per_epoch: &BigUint) { - if current_epoch >= future_epoch { - return; - } - - let epochs_diff = future_epoch - current_epoch; - let energy_added = amount_per_epoch * epochs_diff; - self.amount += BigInt::from(energy_added); - } - - fn subtract(&mut self, past_epoch: Epoch, current_epoch: Epoch, amount_per_epoch: &BigUint) { - if past_epoch >= current_epoch { - return; - } - - let epoch_diff = current_epoch - past_epoch; - let energy_decrease = amount_per_epoch * epoch_diff; - self.amount -= BigInt::from(energy_decrease); - } - - pub fn deplete(&mut self, current_epoch: Epoch) { - if self.last_update_epoch == current_epoch { - return; - } - - if self.total_locked_tokens > 0 { - self.subtract( - self.last_update_epoch, - current_epoch, - &self.total_locked_tokens.clone(), - ); - } - - self.last_update_epoch = current_epoch; - } - - pub fn refund_after_token_unlock( - &mut self, - unlock_amount: &BigUint, - unlock_epoch: Epoch, - current_epoch: Epoch, - ) { - self.add(current_epoch, unlock_epoch, unlock_amount); - self.total_locked_tokens -= unlock_amount; - } - - pub fn deplete_after_early_unlock( - &mut self, - unlock_amount: &BigUint, - unlock_epoch: Epoch, - current_epoch: Epoch, - ) { - self.subtract(current_epoch, unlock_epoch, unlock_amount); - self.total_locked_tokens -= unlock_amount; - } - - pub fn update_after_unlock_any( - &mut self, - unlock_amount: &BigUint, - unlock_epoch: Epoch, - current_epoch: Epoch, - ) { - if unlock_epoch < current_epoch { - self.refund_after_token_unlock(unlock_amount, unlock_epoch, current_epoch); - } else { - self.deplete_after_early_unlock(unlock_amount, unlock_epoch, current_epoch); - } - } -} diff --git a/legacy-contracts/proxy-dex-legacy/src/energy_update.rs b/legacy-contracts/proxy-dex-legacy/src/energy_update.rs index e1bb7725a..880cce46b 100644 --- a/legacy-contracts/proxy-dex-legacy/src/energy_update.rs +++ b/legacy-contracts/proxy-dex-legacy/src/energy_update.rs @@ -2,44 +2,18 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use common_structs::LockedAssetTokenAttributesEx; +use energy_factory::{energy::Energy, locked_token_transfer::ProxyTrait as _}; use factory_legacy::attr_ex_helper; -use crate::{energy::Energy, proxy_common}; +use crate::proxy_common; static LEGACY_LOCKED_TOKEN_ID_STORAGE_KEY: &[u8] = b"legacyLockedTokenId"; -static USER_ENERGY_STORAGE_KEY: &[u8] = b"userEnergy"; static EXTENDED_ATTRIBUTES_ACTIVATION_NONCE_KEY: &[u8] = b"extended_attributes_activation_nonce"; -mod energy_factory_proxy { - multiversx_sc::imports!(); - use crate::energy_update::Energy; - - #[multiversx_sc::proxy] - pub trait LockedTokenTransferModule { - #[endpoint(setUserEnergyAfterLockedTokenTransfer)] - fn set_user_energy_after_locked_token_transfer( - &self, - user: ManagedAddress, - energy: Energy, - ); - } -} - #[multiversx_sc::module] pub trait EnergyUpdateModule: - proxy_common::ProxyCommonModule + attr_ex_helper::AttrExHelper + proxy_common::ProxyCommonModule + attr_ex_helper::AttrExHelper + energy_query::EnergyQueryModule { - #[only_owner] - #[endpoint(setEnergyFactoryAddress)] - fn set_energy_factory_address(&self, sc_address: ManagedAddress) { - require!( - self.blockchain().is_smart_contract(&sc_address), - "Invalid address" - ); - - self.energy_factory_address().set(&sc_address); - } - fn deduct_energy_from_user( &self, user: &ManagedAddress, @@ -82,33 +56,6 @@ pub trait EnergyUpdateModule: .execute_on_dest_context(); } - fn get_energy_entry(&self, user: &ManagedAddress) -> Energy { - let current_epoch = self.blockchain().get_block_epoch(); - if self.energy_factory_address().is_empty() { - return Energy::new_zero_energy(current_epoch); - } - - let energy_buffer: ManagedBuffer = self.read_storage_from_energy_factory(user); - if !energy_buffer.is_empty() { - let mut user_energy: Energy = Energy::top_decode(energy_buffer) - .unwrap_or_else(|_| sc_panic!("Failed decoding result from energy factory")); - user_energy.deplete(current_epoch); - - user_energy - } else { - Energy::new_zero_energy(current_epoch) - } - } - - fn read_storage_from_energy_factory(&self, user: &ManagedAddress) -> T { - let energy_factory_address = self.energy_factory_address().get(); - let mut key_buffer = ManagedBuffer::new_from_bytes(USER_ENERGY_STORAGE_KEY); - key_buffer.append(user.as_managed_buffer()); - - self.storage_raw() - .read_from_address(&energy_factory_address, key_buffer) - } - fn get_legacy_locked_token_id(&self, energy_factory_addr: &ManagedAddress) -> TokenIdentifier { self.storage_raw().read_from_address( energy_factory_addr, @@ -125,12 +72,5 @@ pub trait EnergyUpdateModule: } #[proxy] - fn energy_factory_proxy( - &self, - sc_address: ManagedAddress, - ) -> energy_factory_proxy::Proxy; - - #[view(getEnergyFactoryAddress)] - #[storage_mapper("energyFactoryAddress")] - fn energy_factory_address(&self) -> SingleValueMapper; + fn energy_factory_proxy(&self, sc_address: ManagedAddress) -> energy_factory::Proxy; } diff --git a/legacy-contracts/proxy-dex-legacy/src/lib.rs b/legacy-contracts/proxy-dex-legacy/src/lib.rs index e62a10190..d5034c31d 100644 --- a/legacy-contracts/proxy-dex-legacy/src/lib.rs +++ b/legacy-contracts/proxy-dex-legacy/src/lib.rs @@ -3,10 +3,8 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -mod energy; mod energy_update; mod events; -pub mod migration_from_v1_2; pub mod proxy_common; pub mod proxy_farm; mod proxy_pair; @@ -22,9 +20,9 @@ pub trait ProxyDexImpl: + token_merge_helper::TokenMergeHelperModule + events::EventsModule + energy_update::EnergyUpdateModule - + migration_from_v1_2::MigrationModule + transfer_role::TransferRoleModule + attr_ex_helper::AttrExHelper + + energy_query::EnergyQueryModule { #[init] fn init(&self) {} diff --git a/legacy-contracts/proxy-dex-legacy/src/migration_from_v1_2.rs b/legacy-contracts/proxy-dex-legacy/src/migration_from_v1_2.rs deleted file mode 100644 index 871e42259..000000000 --- a/legacy-contracts/proxy-dex-legacy/src/migration_from_v1_2.rs +++ /dev/null @@ -1,116 +0,0 @@ -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -use common_structs::RawResultWrapper; -use common_structs::RawResultsType; -use factory_legacy::attr_ex_helper; - -use super::events; -use super::proxy_common; -use super::proxy_pair; -use crate::energy_update; -use crate::proxy_common::WrappedFarmTokenAttributes; -use crate::proxy_farm; - -mod farm_v1_2_contract_proxy { - multiversx_sc::imports!(); - - #[multiversx_sc::proxy] - pub trait Farm { - #[payable("*")] - #[endpoint(migrateToNewFarm)] - fn migrate_to_new_farm( - &self, - orig_caller: ManagedAddress, - ) -> MultiValue2, EsdtTokenPayment>; - } -} - -#[multiversx_sc::module] -pub trait MigrationModule: - proxy_farm::ProxyFarmModule - + proxy_common::ProxyCommonModule - + proxy_pair::ProxyPairModule - + token_merge_helper::TokenMergeHelperModule - + events::EventsModule - + energy_update::EnergyUpdateModule - + attr_ex_helper::AttrExHelper -{ - #[payable("*")] - #[endpoint(migrateV1_2Position)] - fn migrate_v1_2_position(&self, farm_address: ManagedAddress) { - self.require_is_intermediated_farm(&farm_address); - self.require_wrapped_farm_token_id_not_empty(); - self.require_wrapped_lp_token_id_not_empty(); - - let (payment_token_id, payment_token_nonce, payment_amount) = - self.call_value().single_esdt().into_tuple(); - let wrapped_farm_token = self.wrapped_farm_token_id().get(); - require!( - payment_token_id == wrapped_farm_token, - "Should only be used with wrapped farm tokens" - ); - require!(payment_amount != 0u64, "Payment amount cannot be zero"); - - // The actual work starts here - let wrapped_farm_token_attrs = - self.get_wrapped_farm_token_attributes(&payment_token_id, payment_token_nonce); - let farm_token_id = wrapped_farm_token_attrs.farm_token_id.clone(); - let farm_token_nonce = wrapped_farm_token_attrs.farm_token_nonce; - let farm_amount = payment_amount.clone(); - - // Get the new farm position from the new contract. - let raw_results: RawResultsType = self - .farm_v1_2_contract_proxy(farm_address) - .migrate_to_new_farm(self.blockchain().get_sc_address()) - .with_esdt_transfer((farm_token_id, farm_token_nonce, farm_amount)) - .execute_on_dest_context(); - - let mut results_wrapper = RawResultWrapper::new(raw_results); - results_wrapper.trim_results_front(2); - - let new_pos: EsdtTokenPayment = results_wrapper.decode_next_result(); - let reward: EsdtTokenPayment = results_wrapper.decode_next_result(); - - // Burn the old proxy farm position - self.send() - .esdt_local_burn(&payment_token_id, payment_token_nonce, &payment_amount); - - // Create a new proxy farm position based on the new farm position. - let new_attrs = WrappedFarmTokenAttributes { - farm_token_id: new_pos.token_identifier.clone(), - farm_token_nonce: new_pos.token_nonce, - farm_token_amount: new_pos.amount.clone(), - farming_token_id: wrapped_farm_token_attrs.farming_token_id, - farming_token_nonce: wrapped_farm_token_attrs.farming_token_nonce, - farming_token_amount: self.rule_of_three_non_zero_result( - &payment_amount, - &wrapped_farm_token_attrs.farm_token_amount, - &wrapped_farm_token_attrs.farming_token_amount, - ), - }; - let new_nonce = - self.send() - .esdt_nft_create_compact(&wrapped_farm_token, &new_pos.amount, &new_attrs); - - let mut payments = ManagedVec::new(); - payments.push(EsdtTokenPayment::new( - wrapped_farm_token, - new_nonce, - new_pos.amount, - )); - - if reward.amount != 0u64 { - payments.push(reward); - } - - let caller = self.blockchain().get_caller(); - self.send().direct_multi(&caller, &payments); - } - - #[proxy] - fn farm_v1_2_contract_proxy( - &self, - to: ManagedAddress, - ) -> farm_v1_2_contract_proxy::Proxy; -} diff --git a/legacy-contracts/proxy-dex-legacy/src/proxy_farm.rs b/legacy-contracts/proxy-dex-legacy/src/proxy_farm.rs index d875c5486..faa105228 100644 --- a/legacy-contracts/proxy-dex-legacy/src/proxy_farm.rs +++ b/legacy-contracts/proxy-dex-legacy/src/proxy_farm.rs @@ -14,19 +14,7 @@ use super::events; use super::proxy_common; use super::proxy_pair; -type ExitFarmResultType = - MultiValue2, EsdtTokenPayment>; - -mod farm_proxy { - multiversx_sc::imports!(); - - #[multiversx_sc::proxy] - pub trait FarmProxy { - #[payable("*")] - #[endpoint(exitFarm)] - fn exit_farm(&self) -> super::ExitFarmResultType; - } -} +use farm_v13_locked_rewards::ExitFarmResultType; #[derive(ManagedVecItem, Clone)] pub struct WrappedFarmToken { @@ -42,6 +30,7 @@ pub trait ProxyFarmModule: + events::EventsModule + energy_update::EnergyUpdateModule + attr_ex_helper::AttrExHelper + + energy_query::EnergyQueryModule { #[only_owner] #[endpoint(addFarmToIntermediate)] @@ -130,7 +119,7 @@ pub trait ProxyFarmModule: ) -> ExitFarmResultType { let raw_results: RawResultsType = self .farm_contract_proxy(farm_address.clone()) - .exit_farm() + .exit_farm(OptionalValue::::None) .with_esdt_transfer((farm_token_id.clone(), farm_token_nonce, amount.clone())) .execute_on_dest_context(); @@ -155,5 +144,5 @@ pub trait ProxyFarmModule: } #[proxy] - fn farm_contract_proxy(&self, to: ManagedAddress) -> farm_proxy::Proxy; + fn farm_contract_proxy(&self, to: ManagedAddress) -> farm_v13_locked_rewards::Proxy; } diff --git a/legacy-contracts/proxy-dex-legacy/src/proxy_pair.rs b/legacy-contracts/proxy-dex-legacy/src/proxy_pair.rs index c8ec2607c..279343cf4 100644 --- a/legacy-contracts/proxy-dex-legacy/src/proxy_pair.rs +++ b/legacy-contracts/proxy-dex-legacy/src/proxy_pair.rs @@ -7,6 +7,9 @@ multiversx_sc::derive_imports!(); use common_structs::{RawResultWrapper, RawResultsType}; use factory_legacy::attr_ex_helper; +use pair::config::ProxyTrait as _; +use pair::pair_actions::common_result_types::RemoveLiquidityResultType; +use pair::pair_actions::remove_liq::ProxyTrait as _; use crate::energy_update; use crate::proxy_common::WrappedLpTokenAttributes; @@ -14,27 +17,6 @@ use crate::proxy_common::WrappedLpTokenAttributes; use super::events; use super::proxy_common; -type RemoveLiquidityResultType = - MultiValue2, EsdtTokenPayment>; - -mod pair_proxy { - multiversx_sc::imports!(); - - #[multiversx_sc::proxy] - pub trait PairProxy { - #[payable("*")] - #[endpoint(removeLiquidity)] - fn remove_liquidity( - &self, - first_token_amount_min: BigUint, - second_token_amount_min: BigUint, - ) -> super::RemoveLiquidityResultType; - - #[view(getLpTokenIdentifier)] - fn get_lp_token_identifier(&self) -> TokenIdentifier; - } -} - #[derive(ManagedVecItem, Clone)] pub struct WrappedLpToken { pub token_amount: EsdtTokenPayment, @@ -48,6 +30,7 @@ pub trait ProxyPairModule: + events::EventsModule + energy_update::EnergyUpdateModule + attr_ex_helper::AttrExHelper + + energy_query::EnergyQueryModule { #[only_owner] #[endpoint(addPairToIntermediate)] @@ -216,5 +199,5 @@ pub trait ProxyPairModule: } #[proxy] - fn pair_contract_proxy(&self, to: ManagedAddress) -> pair_proxy::Proxy; + fn pair_contract_proxy(&self, to: ManagedAddress) -> pair::Proxy; } diff --git a/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock index df92fe170..063bdc08a 100644 --- a/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock +++ b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock @@ -20,6 +20,13 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "common-types" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "common_errors" version = "0.0.0" @@ -38,23 +45,79 @@ dependencies = [ "unwrappable", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "endian-type" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +[[package]] +name = "energy-factory" +version = "0.0.0" +dependencies = [ + "common_structs", + "legacy_token_decode_module", + "math", + "mergeable", + "multiversx-sc", + "multiversx-sc-modules", + "sc_whitelist_module", + "simple-lock", + "unwrappable", + "utils", +] + +[[package]] +name = "energy-query" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", +] + [[package]] name = "factory-legacy" version = "0.0.0" dependencies = [ "common_errors", "common_structs", + "energy-factory", "multiversx-sc", "multiversx-sc-modules", "token_merge_helper", ] +[[package]] +name = "farm-v13-locked-rewards" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "fees-collector" +version = "0.0.0" +dependencies = [ + "common-types", + "common_errors", + "energy-factory", + "energy-query", + "locking_module", + "multiversx-sc", + "multiversx-sc-modules", + "sc_whitelist_module", + "simple-lock", + "utils", + "week-timekeeping", + "weekly-rewards-splitting", +] + [[package]] name = "fixed-supply-token" version = "0.0.0" @@ -74,6 +137,33 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "legacy_token_decode_module" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "utils", +] + +[[package]] +name = "locking_module" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", + "simple-lock", +] + [[package]] name = "math" version = "0.0.0" @@ -174,6 +264,39 @@ dependencies = [ "autocfg", ] +[[package]] +name = "pair" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "fees-collector", + "itertools", + "multiversx-sc", + "pausable", + "permissions_module", + "simple-lock", + "token_send", + "utils", +] + +[[package]] +name = "pausable" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "permissions_module", +] + +[[package]] +name = "permissions_module" +version = "0.0.0" +dependencies = [ + "bitflags", + "common_errors", + "multiversx-sc", +] + [[package]] name = "proc-macro2" version = "1.0.82" @@ -188,8 +311,12 @@ name = "proxy-dex-legacy" version = "0.0.0" dependencies = [ "common_structs", + "energy-factory", + "energy-query", "factory-legacy", + "farm-v13-locked-rewards", "multiversx-sc", + "pair", "token_merge_helper", ] @@ -220,6 +347,23 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "sc_whitelist_module" +version = "0.0.0" +dependencies = [ + "common_errors", + "multiversx-sc", +] + +[[package]] +name = "simple-lock" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "multiversx-sc-modules", +] + [[package]] name = "smallvec" version = "1.13.2" @@ -245,6 +389,15 @@ dependencies = [ "multiversx-sc", ] +[[package]] +name = "token_send" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "multiversx-sc", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -263,3 +416,33 @@ version = "0.0.0" dependencies = [ "multiversx-sc", ] + +[[package]] +name = "utils" +version = "0.0.0" +dependencies = [ + "common_structs", + "fixed-supply-token", + "mergeable", + "multiversx-sc", +] + +[[package]] +name = "week-timekeeping" +version = "0.0.0" +dependencies = [ + "common-types", + "multiversx-sc", +] + +[[package]] +name = "weekly-rewards-splitting" +version = "0.0.0" +dependencies = [ + "common-types", + "energy-query", + "math", + "multiversx-sc", + "unwrappable", + "week-timekeeping", +] diff --git a/legacy-contracts/proxy-dex-legacy/wasm/src/lib.rs b/legacy-contracts/proxy-dex-legacy/wasm/src/lib.rs index 5d418f971..bc4c8d085 100644 --- a/legacy-contracts/proxy-dex-legacy/wasm/src/lib.rs +++ b/legacy-contracts/proxy-dex-legacy/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 20 +// Endpoints: 19 // Async Callback (empty): 1 -// Total number of exported functions: 22 +// Total number of exported functions: 21 #![no_std] @@ -30,14 +30,13 @@ multiversx_sc_wasm_adapter::endpoints! { addFarmToIntermediate => add_farm_to_intermediate removeIntermediatedFarm => remove_intermediated_farm exitFarmProxy => exit_farm_proxy - setEnergyFactoryAddress => set_energy_factory_address - getEnergyFactoryAddress => energy_factory_address - migrateV1_2Position => migrate_v1_2_position setTransferRoleLockedLpToken => set_transfer_role_locked_lp_token unsetTransferRoleLockedLpToken => unset_transfer_role_locked_lp_token setTransferRoleLockedFarmToken => set_transfer_role_locked_farm_token unsetTransferRoleLockedFarmToken => unset_transfer_role_locked_farm_token getExtendedAttributesActivationNonce => extended_attributes_activation_nonce + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) }