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

Asset Conversion: Pool Account ID derivation with additional Pallet ID seed #3250

Merged
merged 52 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
21d1df4
account id converter with pallet id salt
muharem Feb 2, 2024
ebbad9f
migration for pool account
muharem Feb 2, 2024
1e2a925
refund trait and impl
muharem Feb 7, 2024
a45b298
drop super trait for reset team trait
muharem Feb 7, 2024
d8f7b4e
account id types
muharem Feb 8, 2024
1d30b89
fungibles
muharem Feb 8, 2024
cb3b79d
migration
muharem Feb 8, 2024
9f2c71a
setup migration for asset hubs
muharem Feb 8, 2024
f9a0edc
doc fixes
muharem Feb 8, 2024
61245e3
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Feb 8, 2024
6fce4bf
prdoc
muharem Feb 8, 2024
2321031
try runtime imports
muharem Feb 8, 2024
3d3e5b3
change account id format for logs
muharem Feb 8, 2024
ff19ff1
import
muharem Feb 8, 2024
4dd4334
rename deposit fn to deposit_held
muharem Feb 8, 2024
3537f90
migration adjustments
muharem Feb 9, 2024
0eee02e
migration asserts reduce to zero instead success
muharem Feb 9, 2024
11e3004
correct doc
muharem Feb 9, 2024
03363c8
balance for destroying asset cannot be increased/decreased
muharem Feb 12, 2024
58f0a66
migration
muharem Feb 12, 2024
d14b412
make migration idempotent
muharem Feb 12, 2024
10713ad
Merge branch 'master' into muharem-asset-conversion-pool-account
muharem Feb 12, 2024
979ae0c
asset conversion ops pallet
muharem Feb 16, 2024
3be3789
Revert "balance for destroying asset cannot be increased/decreased"
muharem Feb 16, 2024
f3ea112
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Feb 16, 2024
086198c
todos and unused import
muharem Feb 16, 2024
0e12b1f
clippy fix: remove clone
muharem Feb 16, 2024
6deee7f
format fixes
muharem Feb 17, 2024
c21ca3b
Merge branch 'master' into muharem-asset-conversion-pool-account
muharem Feb 20, 2024
4d4db89
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Feb 26, 2024
02a38f0
review fixes
muharem Feb 26, 2024
66b7573
test
muharem Feb 26, 2024
30b9a39
transfer total balance
muharem Feb 26, 2024
5f65481
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Mar 13, 2024
414205c
review fixes
muharem Mar 13, 2024
9f3acde
style fixes
muharem Mar 18, 2024
4300625
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Mar 18, 2024
4f2b973
Merge branch 'master' into muharem-asset-conversion-pool-account
muharem Mar 20, 2024
05e639d
Merge branch 'master' into muharem-asset-conversion-pool-account
muharem Mar 24, 2024
c8cda18
Merge remote-tracking branch 'origin/master' into muharem-asset-conve…
muharem Apr 13, 2024
b756f5f
folder for weights
muharem Apr 13, 2024
71c09ee
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Apr 13, 2024
41b9f9e
weights
muharem Apr 13, 2024
8ce6f7c
update reset team trait
muharem Apr 15, 2024
9247584
update refund trait
muharem Apr 15, 2024
6915afe
remove unused imports
muharem Apr 15, 2024
7398696
Revert "update refund trait"
muharem Apr 15, 2024
7bfd1ff
Revert "remove unused imports"
muharem Apr 15, 2024
7a579a9
update doc
muharem Apr 15, 2024
fba27bf
update pr doc and use default configs for pallets in test env
muharem Apr 16, 2024
82b0aca
update docs
muharem Apr 16, 2024
496e2d7
move reset team trait to roles module
muharem Apr 16, 2024
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
25 changes: 25 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ members = [
"substrate/frame",
"substrate/frame/alliance",
"substrate/frame/asset-conversion",
"substrate/frame/asset-conversion/ops",
"substrate/frame/asset-rate",
"substrate/frame/assets",
"substrate/frame/atomic-swap",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ frame-system-rpc-runtime-api = { path = "../../../../../substrate/frame/system/r
frame-try-runtime = { path = "../../../../../substrate/frame/try-runtime", default-features = false, optional = true }
pallet-asset-conversion-tx-payment = { path = "../../../../../substrate/frame/transaction-payment/asset-conversion-tx-payment", default-features = false }
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false }
pallet-asset-conversion-ops = { path = "../../../../../substrate/frame/asset-conversion/ops", default-features = false }
pallet-asset-conversion = { path = "../../../../../substrate/frame/asset-conversion", default-features = false }
pallet-aura = { path = "../../../../../substrate/frame/aura", default-features = false }
pallet-authorship = { path = "../../../../../substrate/frame/authorship", default-features = false }
Expand Down Expand Up @@ -120,6 +121,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-asset-conversion-ops/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
Expand Down Expand Up @@ -153,6 +155,7 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"pallet-asset-conversion-ops/try-runtime",
"pallet-asset-conversion-tx-payment/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-assets/try-runtime",
Expand Down Expand Up @@ -201,6 +204,7 @@ std = [
"frame-system/std",
"frame-try-runtime?/std",
"log/std",
"pallet-asset-conversion-ops/std",
"pallet-asset-conversion-tx-payment/std",
"pallet-asset-conversion/std",
"pallet-assets/std",
Expand Down
31 changes: 29 additions & 2 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,24 @@ pub type NativeAndAssets = fungible::UnionOf<
AccountId,
>;

pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter<
AssetConversionPalletId,
(xcm::v3::Location, xcm::v3::Location),
>;

impl pallet_asset_conversion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type HigherPrecisionBalance = sp_core::U256;
type AssetKind = xcm::v3::Location;
type Assets = NativeAndAssets;
type PoolId = (Self::AssetKind, Self::AssetKind);
type PoolLocator =
pallet_asset_conversion::WithFirstAsset<TokenLocationV3, AccountId, Self::AssetKind>;
type PoolLocator = pallet_asset_conversion::WithFirstAsset<
TokenLocationV3,
AccountId,
Self::AssetKind,
PoolIdToAccountId,
>;
type PoolAssetId = u32;
type PoolAssets = PoolAssets;
type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
Expand All @@ -362,6 +371,18 @@ impl pallet_asset_conversion::Config for Runtime {
>;
}

impl pallet_asset_conversion_ops::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PriorAccountIdConverter = pallet_asset_conversion::AccountIdConverterNoSeed<
<Runtime as pallet_asset_conversion::Config>::PoolId,
>;
type AssetsRefund = <Runtime as pallet_asset_conversion::Config>::Assets;
type PoolAssetsRefund = <Runtime as pallet_asset_conversion::Config>::PoolAssets;
type PoolAssetsTeam = <Runtime as pallet_asset_conversion::Config>::PoolAssets;
type DepositAsset = Balances;
type WeightInfo = weights::pallet_asset_conversion_ops::WeightInfo<Runtime>;
}

parameter_types! {
// we just reuse the same deposits
pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get();
Expand Down Expand Up @@ -934,6 +955,10 @@ construct_runtime!(

#[cfg(feature = "state-trie-version-1")]
StateTrieMigration: pallet_state_trie_migration = 70,

// TODO: the pallet instance should be removed once all pools have migrated
// to the new account IDs.
AssetConversionMigration: pallet_asset_conversion_ops = 200,
}
);

Expand Down Expand Up @@ -961,6 +986,7 @@ pub type SignedExtra = (
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// Migrations to apply on runtime upgrade.
#[allow(deprecated)]
pub type Migrations = (
pallet_collator_selection::migration::v1::MigrateToV1<Runtime>,
InitStorageVersions,
Expand Down Expand Up @@ -1054,6 +1080,7 @@ mod benches {
[cumulus_pallet_parachain_system, ParachainSystem]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_xcm_bridge_hub_router, ToWestend]
[pallet_asset_conversion_ops, AssetConversionMigration]
// XCM
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
// NOTE: Make sure you point to the individual modules below.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod cumulus_pallet_xcmp_queue;
pub mod extrinsic_weights;
pub mod frame_system;
pub mod pallet_asset_conversion;
pub mod pallet_asset_conversion_ops;
pub mod pallet_assets_foreign;
pub mod pallet_assets_local;
pub mod pallet_assets_pool;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

//! Autogenerated weights for `pallet_asset_conversion_ops`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `cob`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-rococo-dev")`, DB CACHE: 1024

// Executed Command:
// ./target/debug/polkadot-parachain
// benchmark
// pallet
// --chain=asset-hub-rococo-dev
// --steps=10
// --repeat=2
// --pallet=pallet-asset-conversion-ops
// --extrinsic=*
// --wasm-execution=compiled
// --heap-pages=4096
// --output=./cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;

/// Weight functions for `pallet_asset_conversion_ops`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_asset_conversion_ops::WeightInfo for WeightInfo<T> {
/// Storage: `AssetConversion::Pools` (r:1 w:0)
/// Proof: `AssetConversion::Pools` (`max_values`: None, `max_size`: Some(1224), added: 3699, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Account` (r:2 w:2)
/// Proof: `ForeignAssets::Account` (`max_values`: None, `max_size`: Some(732), added: 3207, mode: `MaxEncodedLen`)
/// Storage: `PoolAssets::Account` (r:2 w:2)
/// Proof: `PoolAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `PoolAssets::Asset` (r:1 w:1)
/// Proof: `PoolAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Asset` (r:1 w:1)
/// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`)
fn migrate_to_new_account() -> Weight {
// Proof Size summary in bytes:
// Measured: `1105`
// Estimated: `7404`
// Minimum execution time: 2_323_000_000 picoseconds.
Weight::from_parts(2_404_000_000, 0)
.saturating_add(Weight::from_parts(0, 7404))
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(8))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ frame-system = { path = "../../../../../substrate/frame/system", default-feature
frame-system-benchmarking = { path = "../../../../../substrate/frame/system/benchmarking", default-features = false, optional = true }
frame-system-rpc-runtime-api = { path = "../../../../../substrate/frame/system/rpc/runtime-api", default-features = false }
frame-try-runtime = { path = "../../../../../substrate/frame/try-runtime", default-features = false, optional = true }
pallet-asset-conversion-ops = { path = "../../../../../substrate/frame/asset-conversion/ops", default-features = false }
pallet-asset-conversion-tx-payment = { path = "../../../../../substrate/frame/transaction-payment/asset-conversion-tx-payment", default-features = false }
pallet-assets = { path = "../../../../../substrate/frame/assets", default-features = false }
pallet-asset-conversion = { path = "../../../../../substrate/frame/asset-conversion", default-features = false }
Expand Down Expand Up @@ -111,6 +112,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"pallet-asset-conversion-ops/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
Expand Down Expand Up @@ -142,6 +144,7 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame-try-runtime/try-runtime",
"pallet-asset-conversion-ops/try-runtime",
"pallet-asset-conversion-tx-payment/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-assets/try-runtime",
Expand Down Expand Up @@ -189,6 +192,7 @@ std = [
"frame-system/std",
"frame-try-runtime?/std",
"log/std",
"pallet-asset-conversion-ops/std",
"pallet-asset-conversion-tx-payment/std",
"pallet-asset-conversion/std",
"pallet-assets/std",
Expand Down
30 changes: 28 additions & 2 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,24 @@ pub type NativeAndAssets = fungible::UnionOf<
AccountId,
>;

pub type PoolIdToAccountId = pallet_asset_conversion::AccountIdConverter<
AssetConversionPalletId,
(xcm::v3::Location, xcm::v3::Location),
>;

impl pallet_asset_conversion::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type HigherPrecisionBalance = sp_core::U256;
type AssetKind = xcm::v3::Location;
type Assets = NativeAndAssets;
type PoolId = (Self::AssetKind, Self::AssetKind);
type PoolLocator =
pallet_asset_conversion::WithFirstAsset<WestendLocationV3, AccountId, Self::AssetKind>;
type PoolLocator = pallet_asset_conversion::WithFirstAsset<
WestendLocationV3,
AccountId,
Self::AssetKind,
PoolIdToAccountId,
>;
type PoolAssetId = u32;
type PoolAssets = PoolAssets;
type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
Expand All @@ -344,6 +353,18 @@ impl pallet_asset_conversion::Config for Runtime {
>;
}

impl pallet_asset_conversion_ops::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PriorAccountIdConverter = pallet_asset_conversion::AccountIdConverterNoSeed<
<Runtime as pallet_asset_conversion::Config>::PoolId,
>;
type AssetsRefund = <Runtime as pallet_asset_conversion::Config>::Assets;
type PoolAssetsRefund = <Runtime as pallet_asset_conversion::Config>::PoolAssets;
type PoolAssetsTeam = <Runtime as pallet_asset_conversion::Config>::PoolAssets;
type DepositAsset = Balances;
type WeightInfo = weights::pallet_asset_conversion_ops::WeightInfo<Runtime>;
}

parameter_types! {
// we just reuse the same deposits
pub const ForeignAssetsAssetDeposit: Balance = AssetDeposit::get();
Expand Down Expand Up @@ -906,6 +927,10 @@ construct_runtime!(
NftFractionalization: pallet_nft_fractionalization = 54,
PoolAssets: pallet_assets::<Instance3> = 55,
AssetConversion: pallet_asset_conversion = 56,

// TODO: the pallet instance should be removed once all pools have migrated
// to the new account IDs.
AssetConversionMigration: pallet_asset_conversion_ops = 200,
}
);

Expand Down Expand Up @@ -1085,6 +1110,7 @@ mod benches {
[cumulus_pallet_parachain_system, ParachainSystem]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_xcm_bridge_hub_router, ToRococo]
[pallet_asset_conversion_ops, AssetConversionMigration]
// XCM
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
// NOTE: Make sure you point to the individual modules below.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod cumulus_pallet_xcmp_queue;
pub mod extrinsic_weights;
pub mod frame_system;
pub mod pallet_asset_conversion;
pub mod pallet_asset_conversion_ops;
pub mod pallet_assets_foreign;
pub mod pallet_assets_local;
pub mod pallet_assets_pool;
Expand Down
Loading
Loading