-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #994 from multiversx/rc/v3.0.2
Rc/v3.0.2
- Loading branch information
Showing
66 changed files
with
3,613 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ jobs: | |
uses: multiversx/mx-sc-actions/.github/workflows/[email protected] | ||
with: | ||
image_tag: v7.0.0 | ||
attach_to_existing_release: true | ||
attach_to_existing_release: true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#![no_std] | ||
|
||
multiversx_sc::imports!(); | ||
|
||
use common_structs::{FarmToken, PaymentsVec}; | ||
|
||
#[multiversx_sc::module] | ||
pub trait OriginalOwnerHelperModule { | ||
fn get_claim_original_owner<T: FarmToken<Self::Api> + TopDecode>( | ||
&self, | ||
farm_token_mapper: &NonFungibleTokenMapper, | ||
) -> ManagedAddress { | ||
let payments = self.call_value().all_esdt_transfers(); | ||
let farm_token_id = farm_token_mapper.get_token_id(); | ||
|
||
let mut opt_original_owner = None; | ||
for payment in payments.into_iter() { | ||
require!( | ||
payment.token_identifier == farm_token_id, | ||
"Invalid payment token" | ||
); | ||
|
||
let attributes: T = farm_token_mapper.get_token_attributes(payment.token_nonce); | ||
let payment_original_owner = attributes.get_original_owner(); | ||
|
||
require!( | ||
!payment_original_owner.is_zero(), | ||
"Cannot claim rewards on behalf of legacy positions" | ||
); | ||
|
||
match opt_original_owner { | ||
Some(ref original_owner) => { | ||
require!( | ||
*original_owner == payment_original_owner, | ||
"Original owner is not the same for all payments" | ||
); | ||
} | ||
None => opt_original_owner = Some(payment_original_owner), | ||
} | ||
} | ||
|
||
require!( | ||
opt_original_owner.is_some(), | ||
"Original owner could not be identified" | ||
); | ||
|
||
unsafe { opt_original_owner.unwrap_unchecked() } | ||
} | ||
|
||
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" | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "permissions_hub_module" | ||
version = "0.0.0" | ||
authors = ["MultiversX <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
path = "src/permissions_hub_module.rs" | ||
|
||
[dependencies.permissions-hub] | ||
path = "../../../dex/permissions-hub" | ||
|
||
[dependencies.multiversx-sc] | ||
version = "=0.53.2" | ||
features = ["esdt-token-payment-legacy-decode"] |
35 changes: 35 additions & 0 deletions
35
common/modules/permissions_hub_module/src/permissions_hub_module.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![no_std] | ||
|
||
multiversx_sc::imports!(); | ||
multiversx_sc::derive_imports!(); | ||
|
||
#[multiversx_sc::module] | ||
pub trait PermissionsHubModule { | ||
fn require_user_whitelisted(&self, user: &ManagedAddress, authorized_address: &ManagedAddress) { | ||
let permissions_hub_address = self.permissions_hub_address().get(); | ||
let is_whitelisted: bool = self | ||
.permissions_hub_proxy(permissions_hub_address) | ||
.is_whitelisted(user, authorized_address) | ||
.execute_on_dest_context(); | ||
|
||
require!( | ||
is_whitelisted, | ||
"Caller is not whitelisted by the user or is blacklisted" | ||
); | ||
} | ||
|
||
#[only_owner] | ||
#[endpoint(setPermissionsHubAddress)] | ||
fn set_permissions_hub_address(&self, address: ManagedAddress) { | ||
self.permissions_hub_address().set(&address); | ||
} | ||
|
||
#[proxy] | ||
fn permissions_hub_proxy( | ||
&self, | ||
sc_address: ManagedAddress, | ||
) -> permissions_hub::Proxy<Self::Api>; | ||
|
||
#[storage_mapper("permissionsHubAddress")] | ||
fn permissions_hub_address(&self) -> SingleValueMapper<ManagedAddress>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.