Near-One / rainbow-token-connector

ERC-20/NEP-141 Token Connector for Rainbow Bridge
62 stars 18 forks source link

Fee integration #213

Open UrAvgDeveloper opened 1 year ago

UrAvgDeveloper commented 1 year ago

Description

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

Specification:

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