-
Notifications
You must be signed in to change notification settings - Fork 46
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
[MEX-580] Add on behalf features for farm SC #967
base: rc/v3.0.2
Are you sure you want to change the base?
Conversation
Coverage SummaryTotals
FilesExpand
|
Contract comparison - from 79c6016 to a2f526f
|
#[view(getBlacklistedAddresses)] | ||
#[storage_mapper("blacklistedAddresses")] | ||
fn blacklisted_addresses(&self) -> UnorderedSetMapper<ManagedAddress>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you ever need a blacklist if all actions require user to be whitelisted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never even seen this blacklist used anywhere in the code, so I'd say just remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The blacklist is used in is_whitelisted
view. The blacklist here is design to override the user's whitelist. For example, if the users whitelist an address and that address becomes malicious in any way, we as owners would have a way to block that address generally without clearing it out of everyone's whitelists.
dex/farm/src/external_interaction.rs
Outdated
fn check_and_return_original_owner(&self) -> ManagedAddress { | ||
let payments = self.call_value().all_esdt_transfers().clone_value(); | ||
let farm_token_mapper = self.farm_token(); | ||
let mut original_owner = ManagedAddress::zero(); | ||
for payment in payments.into_iter() { | ||
let attributes: FarmTokenAttributes<Self::Api> = | ||
farm_token_mapper.get_token_attributes(payment.token_nonce); | ||
|
||
if original_owner.is_zero() { | ||
original_owner = attributes.original_owner; | ||
} else { | ||
require!( | ||
original_owner == attributes.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(&self, user: &ManagedAddress) { | ||
let payments = self.call_value().all_esdt_transfers().clone_value(); | ||
if payments.len() == 1 { | ||
return; | ||
} | ||
|
||
let farm_token_mapper = self.farm_token(); | ||
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: FarmTokenAttributes<Self::Api> = | ||
farm_token_mapper.get_token_attributes(payment.token_nonce); | ||
|
||
require!( | ||
user == &attributes.original_owner, | ||
"Provided address is not the same as the original owner" | ||
); | ||
} | ||
} | ||
|
||
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"); | ||
} | ||
|
||
#[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>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like the fact that this code is duplicated in all the contracts. You can refactor it and put it into the common/modules/farm
folder.
For check_and_return_original_owner
, take the mapper as argument, and take the attributes type as a trait parameter, i.e.
fn check_and_return_original_owner<T: FarmToken>(&self, mapper: &NonFungibleTokenMapper) -> ManagedAddress {
//
}
Add a method for fn get_original_owner(&self) -> ManagedAddress
in FarmToken
trait, since you need that field.
Also, for consistency with the other methods, have the payments as arguments instead.
Similar changes for check_additional_payments_original_owner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done what you need here, so you can copy that part: https://github.com/multiversx/mx-exchange-sc/pull/968/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated for farms and farm staking. Farm staking proxy is too custom to be handled the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, added a new PermissionsHubModule, to remove duplicated code.
(virtual_farm_token.payment, claim_result.rewards).into() | ||
} | ||
|
||
fn check_and_return_original_owner(&self, payment: &EsdtTokenPayment) -> ManagedAddress { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated code with farm, farm-staking-proxy, etc.. Can you refactor to avoid code duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated for farms and farm staking. Farm staking proxy is too custom to be handled the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, added a new PermissionsHubModule, to remove duplicated code.
Features: