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

Fee integration #213

Open
wants to merge 77 commits into
base: master
Choose a base branch
from
Open

Fee integration #213

wants to merge 77 commits into from

Conversation

UrAvgDeveloper
Copy link

@UrAvgDeveloper UrAvgDeveloper commented May 2, 2023

Description

This PR contains Fee Implementation for Deposit and Withdrawal flows for tokens transfer using Rainbow Bridge (Business requirement).

Specification:

  • Deposit and withdrawal can have separate fee percentages.
  • The fee collected is locked in the same contract that the owner could claim using the function claim_fee.
  • All the fee setters are only callable by the accounts that have the role Role::FeeSetter.
  • The fee_amount has lower and upper bounds.
  • If the the calculated fee_amount is higher than the withdraw/deposit amount then charge the full amount as a fee and don't transfer anything to the recipient.
  • The fee is set in 6 decimal precision 10% = 0.1 * 10e6 = 100_000
  • It is possible to set a particular fee for silos on deposit and withdrawal. The silo is just a NEAR account, so as a side effect, it is possible to set a specific fee to any NEAR account.
  • It is possible not just to set a particular fee for a particular token for the silo, but also a default fee for this silo.

Added public function:

// Deposit
set_deposit_fee(token: EthAddressHex, fee_percentage: U128, lower_bound: Option<U128>, upper_bound: Option<U128>);
unset_deposit_fee(&mut self, token: EthAddressHex);
set_deposit_fee_per_silo(silo_account_id: AccountId, token: Option<EthAddressHex>, fee_percentage: U128, lower_bound: Option<U128>, upper_bound: Option<U128>);
unset_deposit_fee_per_silo(silo_account_id: AccountId, token: Option<EthAddressHex>);

// Withdraw
set_withdraw_fee(token: EthAddressHex, fee_percentage: U128, lower_bound: Option<U128>, upper_bound: Option<U128>);
unset_withdraw_fee(&mut self, token: EthAddressHex);
set_withdraw_fee_per_silo(silo_account_id: AccountId, token: Option<EthAddressHex>, fee_percentage: U128, lower_bound: Option<U128>, upper_bound: Option<U128>);
unset_withdraw_fee_per_silo(silo_account_id: AccountId, token: Option<EthAddressHex>);

// Getters
get_deposit_fee(&self, token: &EthAddressHex) -> Option<Fee>
get_withdraw_fee(&self, token: &EthAddressHex) -> Option<Fee>
get_withdraw_fee_per_silo(&self, silo_account_id: AccountId, token: Option<EthAddressHex>) -> Option<Fee>
get_deposit_fee_per_silo(&self, silo_account_id: AccountId, token: Option<EthAddressHex>) -> Option<Fee>

// Claim
claim_fee(&mut self, token: AccountId, amount: Balance) -> Promise

// Calculate 
calculate_deposit_fee_amount(&self, token: &EthAddressHex, amount: U128, target: Option<AccountId>) -> U128
calculate_withdraw_fee_amount(&self, token: &EthAddressHex, amount: U128, withdrawer: &AccountId) -> U128

Migration:
The migration is needed due to the added fields deposit_fee, withdraw_fee, withdraw_fee_per_silo, deposit_fee_per_silo to the contract structure. To migrate the storage we need to call:
pub fn migrate() -> Self

bridge-token-factory/readme.md Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/readme.md Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/readme.md Outdated Show resolved Hide resolved
bridge-token-factory/readme.md Outdated Show resolved Hide resolved
bridge-token-factory/src/fee.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/fee.rs Show resolved Hide resolved
bridge-token-factory/src/fee.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/fee.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Outdated Show resolved Hide resolved
bridge-token-factory/src/lib.rs Show resolved Hide resolved
bridge-token-factory/src/lib.rs Show resolved Hide resolved
Base automatically changed from add-near-plugins to master October 5, 2023 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants