-
Notifications
You must be signed in to change notification settings - Fork 1
Reward relayer on BH for S->E transfer #162
Reward relayer on BH for S->E transfer #162
Conversation
pub(crate) fn calculate_fee( | ||
gas_used_at_most: u64, | ||
params: PricingParameters<T::Balance>, | ||
_gas_used_at_most: u64, | ||
_params: PricingParameters<T::Balance>, | ||
) -> Fee<T::Balance> { | ||
// Remote fee in ether | ||
let fee = Self::calculate_remote_fee( | ||
gas_used_at_most, | ||
params.fee_per_gas, | ||
params.rewards.remote, | ||
); | ||
|
||
// downcast to u128 | ||
let fee: u128 = fee.try_into().defensive_unwrap_or(u128::MAX); | ||
|
||
// multiply by multiplier and convert to local currency | ||
let fee = FixedU128::from_inner(fee) | ||
.saturating_mul(params.multiplier) | ||
.checked_div(¶ms.exchange_rate) | ||
.expect("exchange rate is not zero; qed") | ||
.into_inner(); | ||
|
||
// adjust fixed point to match local currency | ||
let fee = Self::convert_from_ether_decimals(fee); | ||
|
||
Fee::from((Self::calculate_local_fee(), fee)) | ||
} | ||
|
||
/// Calculate fee in remote currency for dispatching a message on Ethereum | ||
pub(crate) fn calculate_remote_fee( | ||
gas_used_at_most: u64, | ||
fee_per_gas: U256, | ||
reward: U256, | ||
) -> U256 { | ||
fee_per_gas.saturating_mul(gas_used_at_most.into()).saturating_add(reward) | ||
Fee::from((Self::calculate_local_fee(), T::Balance::zero())) |
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.
Will remove price params on chain and the remote portion of the fee.
T::Token::mint_into(&Self::account_id(), fee_amount)?; | ||
} |
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.
Mint the fee(in DOT) to pallet account of OutboundQueue.
/// Fee locked by message hash | ||
#[pallet::storage] | ||
pub type LockedFee<T: Config> = StorageMap<_, Twox64Concat, H256, u128, ValueQuery>; | ||
|
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 storage map with Fee(in DOT) locked by MessageId.
pub fn add_fees( | ||
origin: OriginFor<T>, | ||
message_id: H256, | ||
fee_amount: BalanceOf<T>, | ||
) -> DispatchResult { | ||
let who = ensure_signed(origin)?; | ||
Self::lock_fee(message_id, fee_amount, Some(who))?; | ||
Ok(()) | ||
} |
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.
Essentially just a transfer from the sender origin to the pallet account.
No description provided.