Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zqhxuyuan committed Feb 28, 2022
1 parent 69acc52 commit 662981c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
26 changes: 13 additions & 13 deletions xtokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,10 @@ pub mod module {
}
}

// In case that fee reserve != asset reserve, there are two xcm sent from sender.
// first xcm sent to fee reserve chain which route to dest chain. second xcm directly
// sent to dest chain. the fee amount in fee asset is split into two parts.
// 1. fee asset sent to fee reserve chain = fee_amount - min_xcm_fee
// In case that fee reserve != asset reserve, there are two xcm sent from
// sender. first xcm sent to fee reserve chain which route to dest chain. second
// xcm directly sent to dest chain. the fee amount in fee asset is split into
// two parts. 1. fee asset sent to fee reserve chain = fee_amount - min_xcm_fee
// 2. fee asset sent to dest reserve chain = min_xcm_fee
// the first part + second part = fee amount in fee asset
let fee_reserve = fee.reserve();
Expand Down Expand Up @@ -528,9 +528,9 @@ pub mod module {
// First xcm sent to fee reserve chain and routed to dest chain.
// The `SelfLocation` current is (1, Parachain(id)) refer to sender parachain.
// we use `SelfLocation` to fund fee to sender's parachain sovereign account on
// destination chain, which asset is originated from sender account on sender chain.
// This means if user setup too much fee, the fee is not returned to user, instead
// deposit to sibling parachain sovereign account on dest chain.
// destination chain, which asset is originated from sender account on sender
// chain. This means if user setup too much fee, the fee is not returned to
// user, instead deposit to sibling parachain sovereign account on dest chain.
// Notice: if parachain set `SelfLocation` to (0, Here), it'll be error!
Self::send_xcm(
origin_location.clone(),
Expand All @@ -543,12 +543,12 @@ pub mod module {
)?;

// Second xcm send to dest chain.
// Current not ensure xcm order delivery. if second xcm is first executed before first
// xcm, then second xcm may failed because of sibling parachain account don't have enough
// fee to withdraw, but we can pre-fund some amount to sibling parachain sovereign
// account to fix this case. as first xcm executed later on, the sibling
// sovereign parachain account get top up. and next transaction will succeed even though
// second xcm is executed before first xcm.
// Current not ensure xcm order delivery. if second xcm is first executed before
// first xcm, then second xcm may failed because of sibling parachain account
// don't have enough fee to withdraw, but we can pre-fund some amount to sibling
// parachain sovereign account to fix this case. as first xcm executed later on,
// the sibling sovereign parachain account get top up. and next transaction will
// succeed even though second xcm is executed before first xcm.
Self::send_xcm(
origin_location,
assets_to_dest,
Expand Down
9 changes: 3 additions & 6 deletions xtokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_works() {
RelayBalances::free_balance(&para_a_account())
);
assert_eq!(
fee_amount - dest_weight*2,
fee_amount - dest_weight * 2,
RelayBalances::free_balance(&para_b_account())
);
});
Expand Down Expand Up @@ -752,18 +752,15 @@ fn sending_sibling_asset_to_reserve_sibling_with_relay_fee_not_enough() {
RelayBalances::free_balance(&para_a_account())
);
assert_eq!(
fee_amount - dest_weight*2,
fee_amount - dest_weight * 2,
RelayBalances::free_balance(&para_b_account())
);
});

ParaB::execute_with(|| {
// after first xcm succeed, sibling_a amount = 159-120=39
// second xcm failed, so sibling_a amount stay same.
assert_eq!(
39,
ParaTokens::free_balance(CurrencyId::R, &sibling_a_account())
);
assert_eq!(39, ParaTokens::free_balance(CurrencyId::R, &sibling_a_account()));

// second xcm failed, so recipient account don't receive any token of B and R.
assert_eq!(0, ParaTokens::free_balance(CurrencyId::B, &BOB));
Expand Down

0 comments on commit 662981c

Please sign in to comment.