Skip to content

Commit

Permalink
Optimize xcm interface (#1439)
Browse files Browse the repository at this point in the history
* Optimize xcm-interface pallet

* Add weights

* Add weights

* Add weights

* Optimize xcm-interface pallet
  • Loading branch information
hqwangningbo authored Sep 25, 2024
1 parent 1a87eec commit 0e8f755
Show file tree
Hide file tree
Showing 25 changed files with 665 additions and 1,091 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 20 additions & 24 deletions pallets/flexible-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub use crate::pallet::*;
use bifrost_primitives::{
currency::{VGLMR, VMANTA, WETH},
traits::XcmDestWeightAndFeeHandler,
Balance, BalanceCmp, CurrencyId, DerivativeIndex, OraclePriceProvider, Price, TryConvertFrom,
XcmOperationType, BNC, DOT, GLMR, MANTA, VBNC, VDOT,
AssetHubChainId, Balance, BalanceCmp, CurrencyId, DerivativeIndex, OraclePriceProvider, Price,
TryConvertFrom, XcmOperationType, BNC, DOT, GLMR, MANTA, VBNC, VDOT,
};
use bifrost_xcm_interface::{polkadot::RelaychainCall, traits::parachains, PolkadotXcmCall};
use bifrost_xcm_interface::calls::{PolkadotXcmCall, RelaychainCall};
use core::convert::Into;
use cumulus_primitives_core::ParaId;
use frame_support::{
Expand Down Expand Up @@ -274,28 +274,24 @@ impl<T: Config> Pallet<T> {
)),
};

let remote_call =
RelaychainCall::<BalanceOf<T>, AccountIdOf<T>, BlockNumberFor<T>>::XcmPallet(
PolkadotXcmCall::LimitedTeleportAssets(
Box::new(Location::new(0, [Parachain(parachains::Statemine::ID)]).into()),
Box::new(
Location::new(
0,
[AccountId32 {
network: None,
id: Sibling::from(T::ParachainId::get())
.into_account_truncating(),
}],
)
.into(),
),
Box::new(asset.into()),
let remote_call = RelaychainCall::XcmPallet(PolkadotXcmCall::LimitedTeleportAssets(
Box::new(Location::new(0, [Parachain(AssetHubChainId::get())]).into()),
Box::new(
Location::new(
0,
Unlimited,
),
)
.encode()
.into();
[AccountId32 {
network: None,
id: Sibling::from(T::ParachainId::get()).into_account_truncating(),
}],
)
.into(),
),
Box::new(asset.into()),
0,
Unlimited,
))
.encode()
.into();

let (require_weight_at_most, xcm_fee) =
T::XcmWeightAndFeeHandler::get_operation_weight_and_fee(
Expand Down
43 changes: 43 additions & 0 deletions pallets/flexible-fee/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,49 @@ fn correct_and_deposit_fee_should_work() {
});
}

#[test]
fn correct_and_deposit_fee_with_tip() {
new_test_ext().execute_with(|| {
basic_setup();

let corrected_fee = 5 * 10u128.pow(12);
let tip = 5 * 10u128.pow(12);

assert_eq!(Currencies::free_balance(BNC, &ALICE), 1000 * 10u128.pow(12));

let already_withdrawn = Some(PaymentInfo::Native(10 * 10u128.pow(12)));
assert_ok!(FlexibleFee::correct_and_deposit_fee(
&ALICE,
&info(),
&post_info(),
corrected_fee,
tip,
already_withdrawn
));
assert_eq!(Currencies::free_balance(BNC, &ALICE), 1005 * 10u128.pow(12));

let corrected_fee = 10 * 10u128.pow(12);
let tip = 10 * 10u128.pow(12);
assert_eq!(Currencies::free_balance(DOT, &ALICE), 1000 * 10u128.pow(10));

let already_withdrawn = Some(PaymentInfo::NonNative(
1 * 10u128.pow(10),
DOT,
FixedU128::from_inner(200_000_000_000_000_000),
FixedU128::from(5),
));
assert_ok!(FlexibleFee::correct_and_deposit_fee(
&ALICE,
&info(),
&post_info(),
corrected_fee,
tip,
already_withdrawn
));
assert_eq!(Currencies::free_balance(DOT, &ALICE), 10006 * 10u128.pow(9));
});
}

#[test]
fn get_currency_asset_id_should_work() {
new_test_ext().execute_with(|| {
Expand Down
Loading

0 comments on commit 0e8f755

Please sign in to comment.