diff --git a/Cargo.lock b/Cargo.lock index 432affd11..4b4c525d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -530,6 +530,7 @@ dependencies = [ "multiversx-sc-modules", "multiversx-sc-scenario", "num-bigint", + "original_owner_helper", "pair", "pausable", "permissions-hub", @@ -588,6 +589,7 @@ dependencies = [ "multiversx-sc-modules", "multiversx-sc-scenario", "num-bigint", + "original_owner_helper", "pair", "pausable", "permissions-hub", @@ -772,6 +774,7 @@ dependencies = [ "multiversx-sc-modules", "multiversx-sc-scenario", "num-bigint", + "original_owner_helper", "pausable", "permissions-hub", "permissions_hub_module", @@ -1373,6 +1376,14 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "original_owner_helper" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", +] + [[package]] name = "pair" version = "0.0.0" diff --git a/common/modules/original_owner_helper/Cargo.toml b/common/modules/original_owner_helper/Cargo.toml new file mode 100644 index 000000000..21fa393dc --- /dev/null +++ b/common/modules/original_owner_helper/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "original_owner_helper" +version = "0.0.0" +authors = ["MultiversX "] +edition = "2021" + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "=0.53.2" +features = ["esdt-token-payment-legacy-decode"] + +[dependencies.common_structs] +path = "../../common_structs" diff --git a/common/modules/original_owner_helper/src/lib.rs b/common/modules/original_owner_helper/src/lib.rs new file mode 100644 index 000000000..3f5126929 --- /dev/null +++ b/common/modules/original_owner_helper/src/lib.rs @@ -0,0 +1,62 @@ +#![no_std] + +multiversx_sc::imports!(); + +use common_structs::{FarmToken, PaymentsVec}; + +#[multiversx_sc::module] +pub trait OriginalOwnerHelperModule { + fn check_and_return_original_owner + TopDecode>( + &self, + payments: &PaymentsVec, + farm_token_mapper: &NonFungibleTokenMapper, + ) -> ManagedAddress { + let mut original_owner = ManagedAddress::zero(); + for payment in payments.iter() { + let attributes: T = farm_token_mapper.get_token_attributes(payment.token_nonce); + let payment_original_owner = attributes.get_original_owner(); + + if original_owner.is_zero() { + original_owner = payment_original_owner; + } else { + require!( + original_owner == payment_original_owner, + "All position must have the same original owner" + ); + } + } + + require!( + !original_owner.is_zero(), + "Original owner could not be identified" + ); + + original_owner + } + + fn check_additional_payments_original_owner + TopDecode>( + &self, + user: &ManagedAddress, + payments: &PaymentsVec, + farm_token_mapper: &NonFungibleTokenMapper, + ) { + if payments.len() == 1 { + return; + } + + let farm_token_id = farm_token_mapper.get_token_id(); + for payment in payments.into_iter() { + if payment.token_identifier != farm_token_id { + continue; + } + + let attributes: T = farm_token_mapper.get_token_attributes(payment.token_nonce); + let payment_original_owner = attributes.get_original_owner(); + + require!( + user == &payment_original_owner, + "Provided address is not the same as the original owner" + ); + } + } +} diff --git a/common/modules/utils/src/lib.rs b/common/modules/utils/src/lib.rs index 861061b28..990b88329 100644 --- a/common/modules/utils/src/lib.rs +++ b/common/modules/utils/src/lib.rs @@ -2,7 +2,7 @@ multiversx_sc::imports!(); -use common_structs::{FarmToken, PaymentAttributesPair, PaymentsVec}; +use common_structs::{PaymentAttributesPair, PaymentsVec}; use fixed_supply_token::FixedSupplyToken; use mergeable::Mergeable; @@ -116,60 +116,6 @@ pub trait UtilsModule { } } - fn check_and_return_original_owner + TopDecode>( - &self, - payments: &PaymentsVec, - farm_token_mapper: &NonFungibleTokenMapper, - ) -> ManagedAddress { - let mut original_owner = ManagedAddress::zero(); - for payment in payments.iter() { - let attributes: T = farm_token_mapper.get_token_attributes(payment.token_nonce); - let payment_original_owner = attributes.get_original_owner(); - - if original_owner.is_zero() { - original_owner = payment_original_owner; - } else { - require!( - original_owner == payment_original_owner, - "All position must have the same original owner" - ); - } - } - - require!( - !original_owner.is_zero(), - "Original owner could not be identified" - ); - - original_owner - } - - fn check_additional_payments_original_owner + TopDecode>( - &self, - user: &ManagedAddress, - payments: &PaymentsVec, - farm_token_mapper: &NonFungibleTokenMapper, - ) { - if payments.len() == 1 { - return; - } - - let farm_token_id = farm_token_mapper.get_token_id(); - for payment in payments.into_iter() { - if payment.token_identifier != farm_token_id { - continue; - } - - let attributes: T = farm_token_mapper.get_token_attributes(payment.token_nonce); - let payment_original_owner = attributes.get_original_owner(); - - require!( - user == &payment_original_owner, - "Provided address is not the same as the original owner" - ); - } - } - fn require_valid_token_id(&self, token_id: &TokenIdentifier) { require!(token_id.is_valid_esdt_identifier(), "Invalid token ID"); } diff --git a/dex/farm-with-locked-rewards/Cargo.toml b/dex/farm-with-locked-rewards/Cargo.toml index 3a5a753e1..d39dd6ed1 100644 --- a/dex/farm-with-locked-rewards/Cargo.toml +++ b/dex/farm-with-locked-rewards/Cargo.toml @@ -44,6 +44,9 @@ path = "../../common/modules/permissions_module" [dependencies.permissions_hub_module] path = "../../common/modules/permissions_hub_module" +[dependencies.original_owner_helper] +path = "../../common/modules/original_owner_helper" + [dependencies.sc_whitelist_module] path = "../../common/modules/sc_whitelist_module" diff --git a/dex/farm-with-locked-rewards/src/external_interaction.rs b/dex/farm-with-locked-rewards/src/external_interaction.rs index 77445dbe3..be29004f0 100644 --- a/dex/farm-with-locked-rewards/src/external_interaction.rs +++ b/dex/farm-with-locked-rewards/src/external_interaction.rs @@ -17,6 +17,7 @@ pub trait ExternalInteractionsModule: + pausable::PausableModule + permissions_module::PermissionsModule + permissions_hub_module::PermissionsHubModule + + original_owner_helper::OriginalOwnerHelperModule + sc_whitelist_module::SCWhitelistModule + events::EventsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 0de59d77e..69b5dc4a1 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -30,6 +30,7 @@ pub trait Farm: + pausable::PausableModule + permissions_module::PermissionsModule + permissions_hub_module::PermissionsHubModule + + original_owner_helper::OriginalOwnerHelperModule + sc_whitelist_module::SCWhitelistModule + events::EventsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index 2e5098f9b..1ec1e747a 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -136,6 +136,7 @@ dependencies = [ "mergeable", "multiversx-sc", "multiversx-sc-modules", + "original_owner_helper", "pair", "pausable", "permissions-hub", @@ -183,6 +184,7 @@ dependencies = [ "mergeable", "multiversx-sc", "multiversx-sc-modules", + "original_owner_helper", "pausable", "permissions-hub", "permissions_hub_module", @@ -403,6 +405,14 @@ dependencies = [ "autocfg", ] +[[package]] +name = "original_owner_helper" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", +] + [[package]] name = "pair" version = "0.0.0" diff --git a/dex/farm/Cargo.toml b/dex/farm/Cargo.toml index 12cb0ffa0..b91a99066 100644 --- a/dex/farm/Cargo.toml +++ b/dex/farm/Cargo.toml @@ -41,6 +41,9 @@ path = "../../common/modules/permissions_module" [dependencies.permissions_hub_module] path = "../../common/modules/permissions_hub_module" +[dependencies.original_owner_helper] +path = "../../common/modules/original_owner_helper" + [dependencies.sc_whitelist_module] path = "../../common/modules/sc_whitelist_module" diff --git a/dex/farm/src/external_interaction.rs b/dex/farm/src/external_interaction.rs index d840b4e19..0af8fe5a5 100644 --- a/dex/farm/src/external_interaction.rs +++ b/dex/farm/src/external_interaction.rs @@ -16,6 +16,7 @@ pub trait ExternalInteractionsModule: + pausable::PausableModule + permissions_module::PermissionsModule + permissions_hub_module::PermissionsHubModule + + original_owner_helper::OriginalOwnerHelperModule + sc_whitelist_module::SCWhitelistModule + events::EventsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index acaca9b0b..5eb7ea834 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -31,6 +31,7 @@ pub trait Farm: + pausable::PausableModule + permissions_module::PermissionsModule + permissions_hub_module::PermissionsHubModule + + original_owner_helper::OriginalOwnerHelperModule + sc_whitelist_module::SCWhitelistModule + events::EventsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule diff --git a/dex/farm/wasm/Cargo.lock b/dex/farm/wasm/Cargo.lock index a080bf9ba..c85e89764 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/wasm/Cargo.lock @@ -136,6 +136,7 @@ dependencies = [ "mergeable", "multiversx-sc", "multiversx-sc-modules", + "original_owner_helper", "pair", "pausable", "permissions-hub", @@ -371,6 +372,14 @@ dependencies = [ "autocfg", ] +[[package]] +name = "original_owner_helper" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", +] + [[package]] name = "pair" version = "0.0.0" diff --git a/farm-staking/farm-staking/Cargo.toml b/farm-staking/farm-staking/Cargo.toml index b99ae9927..51876247b 100644 --- a/farm-staking/farm-staking/Cargo.toml +++ b/farm-staking/farm-staking/Cargo.toml @@ -56,6 +56,9 @@ path = "../../common/modules/permissions_module" [dependencies.permissions_hub_module] path = "../../common/modules/permissions_hub_module" +[dependencies.original_owner_helper] +path = "../../common/modules/original_owner_helper" + [dependencies.sc_whitelist_module] path = "../../common/modules/sc_whitelist_module" diff --git a/farm-staking/farm-staking/src/external_interaction.rs b/farm-staking/farm-staking/src/external_interaction.rs index ab450a4b3..1ece48d9a 100644 --- a/farm-staking/farm-staking/src/external_interaction.rs +++ b/farm-staking/farm-staking/src/external_interaction.rs @@ -20,6 +20,7 @@ pub trait ExternalInteractionsModule: + pausable::PausableModule + permissions_module::PermissionsModule + permissions_hub_module::PermissionsHubModule + + original_owner_helper::OriginalOwnerHelperModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index 3907e38ce..4cf1c3ebf 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -37,6 +37,7 @@ pub trait FarmStaking: + pausable::PausableModule + permissions_module::PermissionsModule + permissions_hub_module::PermissionsHubModule + + original_owner_helper::OriginalOwnerHelperModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule diff --git a/farm-staking/farm-staking/wasm/Cargo.lock b/farm-staking/farm-staking/wasm/Cargo.lock index e0155a29d..7da9c7389 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/wasm/Cargo.lock @@ -136,6 +136,7 @@ dependencies = [ "mergeable", "multiversx-sc", "multiversx-sc-modules", + "original_owner_helper", "pair", "pausable", "permissions-hub", @@ -183,6 +184,7 @@ dependencies = [ "mergeable", "multiversx-sc", "multiversx-sc-modules", + "original_owner_helper", "pair", "pausable", "permissions-hub", @@ -404,6 +406,14 @@ dependencies = [ "autocfg", ] +[[package]] +name = "original_owner_helper" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", +] + [[package]] name = "pair" version = "0.0.0"