Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge rc v3.3 with farm on behalf features #982

Merged
merged 8 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added OriginalOwnerHelperModule
psorinionut committed Nov 20, 2024

Verified

This commit was signed with the committer’s verified signature.
psorinionut Sorin Petreasca
commit a2f526f67a6deeb39b6f7e015820e3600c3531e0
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions common/modules/original_owner_helper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "original_owner_helper"
version = "0.0.0"
authors = ["MultiversX <[email protected]>"]
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"
62 changes: 62 additions & 0 deletions common/modules/original_owner_helper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<T: FarmToken<Self::Api> + TopDecode>(
&self,
payments: &PaymentsVec<Self::Api>,
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<T: FarmToken<Self::Api> + TopDecode>(
&self,
user: &ManagedAddress,
payments: &PaymentsVec<Self::Api>,
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"
);
}
}
}
56 changes: 1 addition & 55 deletions common/modules/utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<T: FarmToken<Self::Api> + TopDecode>(
&self,
payments: &PaymentsVec<Self::Api>,
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<T: FarmToken<Self::Api> + TopDecode>(
&self,
user: &ManagedAddress,
payments: &PaymentsVec<Self::Api>,
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");
}
3 changes: 3 additions & 0 deletions dex/farm-with-locked-rewards/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

1 change: 1 addition & 0 deletions dex/farm-with-locked-rewards/src/external_interaction.rs
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions dex/farm-with-locked-rewards/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions dex/farm-with-locked-rewards/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dex/farm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

1 change: 1 addition & 0 deletions dex/farm/src/external_interaction.rs
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions dex/farm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions dex/farm/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions farm-staking/farm-staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

1 change: 1 addition & 0 deletions farm-staking/farm-staking/src/external_interaction.rs
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions farm-staking/farm-staking/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions farm-staking/farm-staking/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.