Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Allow Sufficient Assets for XCM Fee Payment on Statemint #1884 #1910

Merged
merged 7 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
{
log::warn!(
target: "xcm::barrier",
target: "xcm::barriers",
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
"Unexpected ReserveAssetDeposited from the Relay Chain",
);
}
Expand Down
67 changes: 67 additions & 0 deletions parachains/runtimes/assets/statemine/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,70 @@ fn test_that_buying_ed_refund_does_not_refund() {
assert_eq!(Assets::total_supply(1), ExistentialDeposit::get());
});
}

#[test]
fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
ExtBuilder::<Runtime>::default()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
)])
.build()
.execute_with(|| {
// Create a non-sufficient asset
// We set existential deposit to be identical to the one for Balances first
assert_ok!(Assets::force_create(
RuntimeHelper::<Runtime>::root_origin(),
1,
bkontur marked this conversation as resolved.
Show resolved Hide resolved
AccountId::from(ALICE).into(),
false,
ExistentialDeposit::get()
bkontur marked this conversation as resolved.
Show resolved Hide resolved
));

// We first mint enough asset for the account to exist for assets
assert_ok!(Assets::mint(
RuntimeHelper::<Runtime>::origin_of(AccountId::from(ALICE)),
1,
AccountId::from(ALICE).into(),
ExistentialDeposit::get()
));

let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();

// Set Alice as block author, who will receive fees
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));

// We are going to buy 4e9 weight
let bought = 4_000_000_000u64;

// lets calculate amount needed
let amount_needed = WeightToFee::weight_to_fee(&Weight::from_ref_time(bought));
bkontur marked this conversation as resolved.
Show resolved Hide resolved

let asset_multilocation = MultiLocation::new(
0,
X2(
PalletInstance(
<Runtime as frame_system::Config>::PalletInfo::index::<Assets>().unwrap()
as u8,
),
GeneralIndex(1),
),
);

let asset: MultiAsset = (asset_multilocation, amount_needed).into();

// Make sure again buy_weight does return an error
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);

// Drop trader
drop(trader);

// Make sure author(Alice) has NOT received the amount
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get());

// We also need to ensure the total supply NOT increased
assert_eq!(Assets::total_supply(1), ExistentialDeposit::get());
});
}
30 changes: 27 additions & 3 deletions parachains/runtimes/assets/statemint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ use frame_support::{
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::{DenyReserveTransferToRelayChain, DenyThenTry},
xcm_config::{
AssetFeeAsExistentialDepositMultiplier, DenyReserveTransferToRelayChain, DenyThenTry,
},
};
use polkadot_parachain::primitives::Sibling;
use sp_runtime::traits::ConvertInto;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
Expand Down Expand Up @@ -172,8 +175,29 @@ impl xcm_executor::Config for XcmConfig {
RuntimeCall,
MaxInstructions,
>;
type Trader =
UsingComponents<WeightToFee, DotLocation, AccountId, Balances, ToStakingPot<Runtime>>;
type Trader = (
UsingComponents<WeightToFee, DotLocation, AccountId, Balances, ToStakingPot<Runtime>>,
cumulus_primitives_utility::TakeFirstAssetTrader<
AccountId,
AssetFeeAsExistentialDepositMultiplier<
Runtime,
WeightToFee,
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
>,
ConvertedConcreteAssetId<
AssetId,
Balance,
AsPrefixedGeneralIndex<AssetsPalletLocation, AssetId, JustTry>,
JustTry,
>,
Assets,
cumulus_primitives_utility::XcmFeesTo32ByteAccount<
FungiblesTransactor,
AccountId,
XcmAssetFeesReceiver,
>,
>,
);
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
Expand Down
Loading