Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion porteer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ benchmarks! {
assert_eq!(LastHeartBeat::<T>::get(), now);
}
set_xcm_fee_params {
let fee_params = XcmFeeParams { hop1: 1u32.into(), hop2: 2u32.into(), hop3: 3u32.into() };
let fee_params = XcmFeeParams { local_equivalent_sum: 6u32.into(), hop1: 1u32.into(), hop2: 2u32.into(), hop3: 3u32.into() };
}: _(RawOrigin::Root, fee_params)
verify {
assert_eq!(XcmFeeConfig::<T>::get(), fee_params);
Expand Down
18 changes: 18 additions & 0 deletions porteer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,17 @@ pub mod pallet {
/// or
/// 2. AHP -> AHK -> IK
pub struct XcmFeeParams<Balance> {
/// to be paid by the `port_tokens` caller to cover all subsequent fees
#[codec(compact)]
pub local_equivalent_sum: Balance,
/// fees to be paid by sovereign account for source side Asset Hub execution involving swapping to KSM/DOT [TEER]
#[codec(compact)]
pub hop1: Balance,
/// fees to be paid by sovereign account for destination side Asset Hub execution involving swapping to DOT/KSM [KSM/DOT]
#[codec(compact)]
pub hop2: Balance,
/// fees to be paid by sovereign account for destination side Integritee execution involving swapping to TEER [DOT/KSM]
#[codec(compact)]
pub hop3: Balance,
}

Expand Down Expand Up @@ -148,6 +157,7 @@ pub mod pallet {
Location = Self::Location,
>;

type FeeCollectorAccount: Get<AccountIdOf<Self>>;
/// The location representation used by this pallet.
type Location: Parameter + Member + MaybeSerializeDeserialize + Debug + Ord + MaxEncodedLen;

Expand Down Expand Up @@ -381,6 +391,14 @@ pub mod pallet {
return Err(Error::<T>::WatchdogHeartbeatIsTooOld.into());
};

let user_fee = Self::xcm_fee_config().local_equivalent_sum;
<T::Fungible as fungible::Mutate<_>>::transfer(
&signer,
&T::FeeCollectorAccount::get(),
user_fee,
Preservation::Preserve,
)?;

<T::Fungible as fungible::Mutate<_>>::burn_from(
&signer,
amount,
Expand Down
2 changes: 2 additions & 0 deletions porteer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl pallet_balances::Config for Test {

ord_parameter_types! {
pub const Alice: AccountId = AccountId::new(hex2array!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"));
pub const Ferdie: AccountId = AccountId::new(hex2array!("1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c"));
}

parameter_types! {
Expand All @@ -106,6 +107,7 @@ impl crate::Config for Test {
EitherOfDiverse<EnsureSignedBy<Alice, AccountId32>, EnsureRoot<AccountId32>>;
type PortTokensToDestination = MockPortTokens;
type ForwardPortedTokensToDestinations = MockPortTokens;
type FeeCollectorAccount = Ferdie;
type Location = TestLocation;
type Fungible = Balances;
#[cfg(feature = "runtime-benchmarks")]
Expand Down
32 changes: 31 additions & 1 deletion porteer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn set_xcm_fee_params_works() {

assert_eq!(XcmFeeConfig::<Test>::get(), XcmFeeParams::default());

let new_fee_params = XcmFeeParams { hop1: 1, hop2: 2, hop3: 3 };
let new_fee_params = XcmFeeParams { local_equivalent_sum: 6, hop1: 1, hop2: 2, hop3: 3 };
assert_ok!(Porteer::set_xcm_fee_params(
RuntimeOrigin::signed(alice.clone()),
new_fee_params
Expand Down Expand Up @@ -259,6 +259,36 @@ fn port_tokens_works_at_timeout_threshold() {
})
}

#[test]
fn port_tokens_charges_fees_if_port_possible() {
new_test_ext().execute_with(|| {
let alice = Keyring::Alice.to_account_id();
let bob = Keyring::Bob.to_account_id();
let ferdie = Keyring::Ferdie.to_account_id();
let bob_free: BalanceOf<Test> = 15_000_000_000_000u128;
<Test as pallet::Config>::Fungible::make_free_balance_be(&bob, bob_free);
<Test as pallet::Config>::Fungible::make_free_balance_be(&ferdie, 0);

assert_eq!(XcmFeeConfig::<Test>::get(), XcmFeeParams::default());

let new_fee_params =
XcmFeeParams { local_equivalent_sum: 600_000_000_000, hop1: 1, hop2: 2, hop3: 3 };
assert_ok!(Porteer::set_xcm_fee_params(
RuntimeOrigin::signed(alice.clone()),
new_fee_params
));

let port_amount: BalanceOf<Test> = 10_000_000_000_000u128;

assert_ok!(Porteer::port_tokens(RuntimeOrigin::signed(bob.clone()), port_amount, None));
assert_eq!(
Balances::free_balance(bob),
bob_free - port_amount - new_fee_params.local_equivalent_sum
);
assert_eq!(Balances::free_balance(ferdie), new_fee_params.local_equivalent_sum);
})
}

#[test]
fn port_tokens_system_test_works() {
// This test tests the whole logic:
Expand Down
Loading