Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet assets / upgrade to use fungible #1907

Closed
wants to merge 13 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ fn cannot_create_pool_from_pool_assets() {
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocation::get());
let mut asset_one = asset_hub_westend_runtime::xcm_config::PoolAssetsPalletLocation::get();
asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets");
let pool_owner_account_id = asset_hub_westend_runtime::AssetConversionOrigin::get();
AssetHubWestend::fund_accounts(vec![(pool_owner_account_id.clone(), 1_000_000_000)]);

AssetHubWestend::execute_with(|| {
let pool_owner_account_id = asset_hub_westend_runtime::AssetConversionOrigin::get();

assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::PoolAssets::create(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(pool_owner_account_id.clone()),
ASSET_ID.into(),
Expand Down
18 changes: 11 additions & 7 deletions cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ impl pallet_balances::Config for Runtime {
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
// We allow each account to have holds on it from:
// - `Assets`: 4 * 3 instances = 12
// - `NftFractionalization`: 1
type MaxHolds = ConstU32<1>;
type MaxHolds = ConstU32<13>;
type MaxFreezes = ConstU32<0>;
}

Expand Down Expand Up @@ -268,10 +269,11 @@ pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
type TrustBackedAssetsCall = pallet_assets::Call<Runtime, TrustBackedAssetsInstance>;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
Expand Down Expand Up @@ -304,11 +306,12 @@ ord_parameter_types! {
pub type PoolAssetsInstance = pallet_assets::Instance3;
impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type RemoveItemsLimit = ConstU32<1000>;
type AssetId = u32;
type AssetIdParameter = u32;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin =
AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, sp_runtime::AccountId32>>;
type ForceOrigin = AssetsForceOrigin;
Expand Down Expand Up @@ -376,10 +379,11 @@ parameter_types! {
pub type ForeignAssetsInstance = pallet_assets::Instance2;
impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = MultiLocationForAssetId;
type AssetIdParameter = MultiLocationForAssetId;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = ForeignCreators<
(FromSiblingParachain<parachain_info::Pallet<Runtime>>,),
ForeignCreatorsSovereignAccountOf,
Expand Down Expand Up @@ -855,13 +859,13 @@ construct_runtime!(
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 42,

// The main stage.
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>, HoldReason} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
Nfts: pallet_nfts::{Pallet, Call, Storage, Event<T>} = 52,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>} = 53,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>, HoldReason} = 53,
NftFractionalization: pallet_nft_fractionalization::{Pallet, Call, Storage, Event<T>, HoldReason} = 54,

PoolAssets: pallet_assets::<Instance3>::{Pallet, Call, Storage, Event<T>} = 55,
PoolAssets: pallet_assets::<Instance3>::{Pallet, Call, Storage, Event<T>, HoldReason} = 55,
AssetConversion: pallet_asset_conversion::{Pallet, Call, Storage, Event<T>} = 56,

#[cfg(feature = "state-trie-version-1")]
Expand Down
14 changes: 9 additions & 5 deletions cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ impl pallet_balances::Config for Runtime {
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
// We allow each account to have holds on it from:
// - `Assets`: 4 * 2 instances = 8
type MaxHolds = ConstU32<8>;
type MaxFreezes = ConstU32<0>;
}

Expand Down Expand Up @@ -276,10 +278,11 @@ pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
type TrustBackedAssetsCall = pallet_assets::Call<Runtime, TrustBackedAssetsInstance>;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
Expand Down Expand Up @@ -314,10 +317,11 @@ parameter_types! {
pub type ForeignAssetsInstance = pallet_assets::Instance2;
impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = MultiLocationForAssetId;
type AssetIdParameter = MultiLocationForAssetId;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = ForeignCreators<
(FromSiblingParachain<parachain_info::Pallet<Runtime>>,),
ForeignCreatorsSovereignAccountOf,
Expand Down Expand Up @@ -769,10 +773,10 @@ construct_runtime!(
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 42,

// The main stage.
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>, HoldReason} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
Nfts: pallet_nfts::{Pallet, Call, Storage, Event<T>} = 52,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>} = 53,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>, HoldReason} = 53,
}
);

Expand Down
18 changes: 11 additions & 7 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ impl pallet_balances::Config for Runtime {
type FreezeIdentifier = ();
// We allow each account to have holds on it from:
// - `NftFractionalization`: 1
type MaxHolds = ConstU32<1>;
// - `Assets`: 12 (3 instances)
type MaxHolds = ConstU32<13>;
type MaxFreezes = ConstU32<0>;
}

Expand Down Expand Up @@ -274,10 +275,11 @@ pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
type TrustBackedAssetsCall = pallet_assets::Call<Runtime, TrustBackedAssetsInstance>;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
Expand Down Expand Up @@ -310,11 +312,12 @@ ord_parameter_types! {
pub type PoolAssetsInstance = pallet_assets::Instance3;
impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type RemoveItemsLimit = ConstU32<1000>;
type AssetId = u32;
type AssetIdParameter = u32;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin =
AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, sp_runtime::AccountId32>>;
type ForceOrigin = AssetsForceOrigin;
Expand Down Expand Up @@ -382,10 +385,11 @@ parameter_types! {
pub type ForeignAssetsInstance = pallet_assets::Instance2;
impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = MultiLocationForAssetId;
type AssetIdParameter = MultiLocationForAssetId;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = ForeignCreators<
(FromSiblingParachain<parachain_info::Pallet<Runtime>>,),
ForeignCreatorsSovereignAccountOf,
Expand Down Expand Up @@ -932,13 +936,13 @@ construct_runtime!(
ToRococoXcmRouter: pallet_xcm_bridge_hub_router::<Instance2>::{Pallet, Storage, Call} = 44,

// The main stage.
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>, HoldReason} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
Nfts: pallet_nfts::{Pallet, Call, Storage, Event<T>} = 52,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>} = 53,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>, HoldReason} = 53,
NftFractionalization: pallet_nft_fractionalization::{Pallet, Call, Storage, Event<T>, HoldReason} = 54,

PoolAssets: pallet_assets::<Instance3>::{Pallet, Call, Storage, Event<T>} = 55,
PoolAssets: pallet_assets::<Instance3>::{Pallet, Call, Storage, Event<T>, HoldReason} = 55,
AssetConversion: pallet_asset_conversion::{Pallet, Call, Storage, Event<T>} = 56,

#[cfg(feature = "state-trie-version-1")]
Expand Down
18 changes: 11 additions & 7 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ impl pallet_balances::Config for Runtime {
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
// We allow each account to have holds on it from:
// - `Assets`: 4 * 3 instaces = 12
// - `NftFractionalization`: 1
type MaxHolds = ConstU32<1>;
type MaxHolds = ConstU32<13>;
type MaxFreezes = ConstU32<0>;
}

Expand Down Expand Up @@ -245,10 +246,11 @@ pub type TrustBackedAssetsInstance = pallet_assets::Instance1;
type TrustBackedAssetsCall = pallet_assets::Call<Runtime, TrustBackedAssetsInstance>;
impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AssetsForceOrigin;
type AssetDeposit = AssetDeposit;
Expand Down Expand Up @@ -281,11 +283,12 @@ ord_parameter_types! {
pub type PoolAssetsInstance = pallet_assets::Instance3;
impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type RemoveItemsLimit = ConstU32<1000>;
type AssetId = u32;
type AssetIdParameter = u32;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin =
AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, sp_runtime::AccountId32>>;
type ForceOrigin = AssetsForceOrigin;
Expand Down Expand Up @@ -351,10 +354,11 @@ parameter_types! {
pub type ForeignAssetsInstance = pallet_assets::Instance2;
impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = MultiLocationForAssetId;
type AssetIdParameter = MultiLocationForAssetId;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = ForeignCreators<
(FromSiblingParachain<parachain_info::Pallet<Runtime>>,),
ForeignCreatorsSovereignAccountOf,
Expand Down Expand Up @@ -831,12 +835,12 @@ construct_runtime!(
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 42,

// The main stage.
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>, HoldReason} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
Nfts: pallet_nfts::{Pallet, Call, Storage, Event<T>} = 52,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>} = 53,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>, HoldReason} = 53,
NftFractionalization: pallet_nft_fractionalization::{Pallet, Call, Storage, Event<T>, HoldReason} = 54,
PoolAssets: pallet_assets::<Instance3>::{Pallet, Call, Storage, Event<T>} = 55,
PoolAssets: pallet_assets::<Instance3>::{Pallet, Call, Storage, Event<T>, HoldReason} = 55,
AssetConversion: pallet_asset_conversion::{Pallet, Call, Storage, Event<T>} = 56,
}
);
Expand Down
7 changes: 4 additions & 3 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl pallet_balances::Config for Runtime {
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxHolds = ConstU32<4>; // assets
type MaxFreezes = ConstU32<0>;
}

Expand Down Expand Up @@ -433,10 +433,11 @@ parameter_types! {

impl pallet_assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = AssetId;
type AssetIdParameter = codec::Compact<AssetId>;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
type AssetDeposit = AssetDeposit;
Expand Down Expand Up @@ -598,7 +599,7 @@ construct_runtime!(
DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 33,

// The main stage.
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 50,
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>, HoldReason} = 50,

Sudo: pallet_sudo::{Pallet, Call, Storage, Event<T>, Config<T>} = 255,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl pallet_balances::Config for Runtime {
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxHolds = ConstU32<4>; // assets
type MaxFreezes = ConstU32<0>;
}

Expand Down Expand Up @@ -545,10 +545,11 @@ pub type AdminOrigin =

impl pallet_assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = u64;
type AssetId = AssetIdForTrustBackedAssets;
type AssetIdParameter = codec::Compact<AssetIdForTrustBackedAssets>;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = AdminOrigin;
type AssetDeposit = AssetDeposit;
Expand Down Expand Up @@ -589,7 +590,7 @@ construct_runtime! {
ParachainInfo: parachain_info::{Pallet, Storage, Config<T>} = 21,

Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>} = 31,
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>, HoldReason} = 31,

Aura: pallet_aura::{Pallet, Config<T>},
AuraExt: cumulus_pallet_aura_ext::{Pallet, Config<T>},
Expand Down
5 changes: 3 additions & 2 deletions polkadot/xcm/xcm-builder/src/tests/pay/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl pallet_balances::Config for Test {
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = RuntimeHoldReason;
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxHolds = ConstU32<4>; // assets
type MaxFreezes = ConstU32<0>;
}

Expand All @@ -92,9 +92,10 @@ parameter_types! {

impl pallet_assets::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Balance = Balance;
type AssetId = AssetIdForAssets;
type Currency = Balances;
type NativeToken = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type ForceOrigin = EnsureRoot<AccountId>;
type AssetDeposit = AssetDeposit;
Expand Down
20 changes: 20 additions & 0 deletions prdoc/pr_1907.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Schema: Parity PR Documentation Schema (prdoc)
# See doc at https://github.com/paritytech/prdoc

title: pallet assets / upgrade to use fungible

doc:
- audience: Core Dev
description: |
This updates the assets pallet to use the new fungible traits rather than the now deprecated
Currency and ReserveCurrency traits ( paritytech/substrate#12951 ).
Partial fix of #226.

migrations:
db: []

runtime: []

crates: []

host_functions: []
Loading
Loading