Skip to content

Commit

Permalink
Implement pallet-assets-freezer (#3951)
Browse files Browse the repository at this point in the history
Closes #3342

cc/ @liamaharon

TODO:

- [x] Improve docs.
- [x] Define public interface (See #3342).
  In case we define public calls to the pallet implementation:
  - Implement public calls.
  - Benchmarks.
  
polkadot address: 12gMhxHw8QjEwLQvnqsmMVY1z5gFa54vND74aMUbhhwN6mJR

---------

Co-authored-by: command-bot <>
Co-authored-by: Liam Aharon <[email protected]>
  • Loading branch information
pandres95 and liamaharon authored Jun 21, 2024
1 parent d18d362 commit a477bd0
Show file tree
Hide file tree
Showing 18 changed files with 994 additions and 22 deletions.
20 changes: 20 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 @@ -306,6 +306,7 @@ members = [
"substrate/frame/asset-conversion/ops",
"substrate/frame/asset-rate",
"substrate/frame/assets",
"substrate/frame/assets-freezer",
"substrate/frame/atomic-swap",
"substrate/frame/aura",
"substrate/frame/authority-discovery",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pallet-asset-conversion-tx-payment = { path = "../../../../../substrate/frame/tr
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-assets-freezer = { path = "../../../../../substrate/frame/assets-freezer", default-features = false }
pallet-aura = { path = "../../../../../substrate/frame/aura", default-features = false }
pallet-authorship = { path = "../../../../../substrate/frame/authorship", default-features = false }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
Expand Down Expand Up @@ -116,6 +117,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-asset-conversion-ops/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets-freezer/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
Expand Down Expand Up @@ -151,6 +153,7 @@ try-runtime = [
"pallet-asset-conversion-ops/try-runtime",
"pallet-asset-conversion-tx-payment/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-assets-freezer/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
Expand Down Expand Up @@ -200,6 +203,7 @@ std = [
"pallet-asset-conversion-ops/std",
"pallet-asset-conversion-tx-payment/std",
"pallet-asset-conversion/std",
"pallet-assets-freezer/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand Down
30 changes: 27 additions & 3 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Freezer = ();
type Freezer = AssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_local::WeightInfo<Runtime>;
type CallbackHandle = ();
Expand All @@ -267,6 +267,13 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type BenchmarkHelper = ();
}

// Allow Freezes for the `Assets` pallet
pub type AssetsFreezerInstance = pallet_assets_freezer::Instance1;
impl pallet_assets_freezer::Config<AssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
Expand Down Expand Up @@ -295,14 +302,21 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type MetadataDepositPerByte = ConstU128<0>;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = ConstU32<50>;
type Freezer = ();
type Freezer = PoolAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_pool::WeightInfo<Runtime>;
type CallbackHandle = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

// Allow Freezes for the `PoolAssets` pallet
pub type PoolAssetsFreezerInstance = pallet_assets_freezer::Instance3;
impl pallet_assets_freezer::Config<PoolAssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

/// Union fungibles implementation for `Assets` and `ForeignAssets`.
pub type LocalAndForeignAssets = fungibles::UnionOf<
Assets,
Expand Down Expand Up @@ -411,7 +425,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
type ApprovalDeposit = ForeignAssetsApprovalDeposit;
type StringLimit = ForeignAssetsAssetsStringLimit;
type Freezer = ();
type Freezer = ForeignAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_foreign::WeightInfo<Runtime>;
type CallbackHandle = ();
Expand All @@ -421,6 +435,13 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
}

// Allow Freezes for the `ForeignAssets` pallet
pub type ForeignAssetsFreezerInstance = pallet_assets_freezer::Instance2;
impl pallet_assets_freezer::Config<ForeignAssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = deposit(1, 88);
Expand Down Expand Up @@ -953,6 +974,9 @@ construct_runtime!(
NftFractionalization: pallet_nft_fractionalization = 54,
PoolAssets: pallet_assets::<Instance3> = 55,
AssetConversion: pallet_asset_conversion = 56,
AssetsFreezer: pallet_assets_freezer::<Instance1> = 57,
ForeignAssetsFreezer: pallet_assets_freezer::<Instance2> = 58,
PoolAssetsFreezer: pallet_assets_freezer::<Instance3> = 59,

// TODO: the pallet instance should be removed once all pools have migrated
// to the new account IDs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pallet-asset-conversion-ops = { path = "../../../../../substrate/frame/asset-con
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 }
pallet-assets-freezer = { path = "../../../../../substrate/frame/assets-freezer", default-features = false }
pallet-aura = { path = "../../../../../substrate/frame/aura", default-features = false }
pallet-authorship = { path = "../../../../../substrate/frame/authorship", default-features = false }
pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false }
Expand Down Expand Up @@ -115,6 +116,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-asset-conversion-ops/runtime-benchmarks",
"pallet-asset-conversion/runtime-benchmarks",
"pallet-assets-freezer/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
Expand Down Expand Up @@ -150,6 +152,7 @@ try-runtime = [
"pallet-asset-conversion-ops/try-runtime",
"pallet-asset-conversion-tx-payment/try-runtime",
"pallet-asset-conversion/try-runtime",
"pallet-assets-freezer/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
Expand Down Expand Up @@ -200,6 +203,7 @@ std = [
"pallet-asset-conversion-ops/std",
"pallet-asset-conversion-tx-payment/std",
"pallet-asset-conversion/std",
"pallet-assets-freezer/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand Down
30 changes: 27 additions & 3 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = AssetsStringLimit;
type Freezer = ();
type Freezer = AssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_local::WeightInfo<Runtime>;
type CallbackHandle = ();
Expand All @@ -265,6 +265,13 @@ impl pallet_assets::Config<TrustBackedAssetsInstance> for Runtime {
type BenchmarkHelper = ();
}

// Allow Freezes for the `Assets` pallet
pub type AssetsFreezerInstance = pallet_assets_freezer::Instance1;
impl pallet_assets_freezer::Config<AssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
Expand Down Expand Up @@ -292,14 +299,21 @@ impl pallet_assets::Config<PoolAssetsInstance> for Runtime {
type MetadataDepositPerByte = ConstU128<0>;
type ApprovalDeposit = ConstU128<0>;
type StringLimit = ConstU32<50>;
type Freezer = ();
type Freezer = PoolAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_pool::WeightInfo<Runtime>;
type CallbackHandle = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

// Allow Freezes for the `PoolAssets` pallet
pub type PoolAssetsFreezerInstance = pallet_assets_freezer::Instance3;
impl pallet_assets_freezer::Config<PoolAssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

/// Union fungibles implementation for `Assets` and `ForeignAssets`.
pub type LocalAndForeignAssets = fungibles::UnionOf<
Assets,
Expand Down Expand Up @@ -405,7 +419,7 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type MetadataDepositPerByte = ForeignAssetsMetadataDepositPerByte;
type ApprovalDeposit = ForeignAssetsApprovalDeposit;
type StringLimit = ForeignAssetsAssetsStringLimit;
type Freezer = ();
type Freezer = ForeignAssetsFreezer;
type Extra = ();
type WeightInfo = weights::pallet_assets_foreign::WeightInfo<Runtime>;
type CallbackHandle = ();
Expand All @@ -415,6 +429,13 @@ impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
type BenchmarkHelper = xcm_config::XcmBenchmarkHelper;
}

// Allow Freezes for the `ForeignAssets` pallet
pub type ForeignAssetsFreezerInstance = pallet_assets_freezer::Instance2;
impl pallet_assets_freezer::Config<ForeignAssetsFreezerInstance> for Runtime {
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = deposit(1, 88);
Expand Down Expand Up @@ -943,6 +964,9 @@ construct_runtime!(
NftFractionalization: pallet_nft_fractionalization = 54,
PoolAssets: pallet_assets::<Instance3> = 55,
AssetConversion: pallet_asset_conversion = 56,
AssetsFreezer: pallet_assets_freezer::<Instance1> = 57,
ForeignAssetsFreezer: pallet_assets_freezer::<Instance2> = 58,
PoolAssetsFreezer: pallet_assets_freezer::<Instance3> = 59,

StateTrieMigration: pallet_state_trie_migration = 70,

Expand Down
30 changes: 30 additions & 0 deletions prdoc/pr_3951.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Pallet Assets Freezer

doc:
- audience: Runtime Dev
description: |
This pallet is an extension of `pallet-assets`, supporting
freezes similar to `pallet-balances`.
To use this pallet, set `Freezer` of `pallet-assets` Config to the according instance of
`pallet-assets-freezer`.
- audience: Runtime User
description: |
The storage of this pallet contains a Vecs of account freezes. Applications UIs and Developer
Tools might benefit from observing it.

crates:
- name: frame-support
bump: minor
- name: pallet-assets-freezer
bump: major
- name: pallet-assets
bump: patch
- name: pallet-balances
bump: patch
- name: asset-hub-rococo-runtime
bump: minor
- name: asset-hub-westend-runtime
bump: minor
61 changes: 61 additions & 0 deletions substrate/frame/assets-freezer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[package]
name = "pallet-assets-freezer"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license = "MIT-0"
homepage = "https://substrate.io"
repository.workspace = true
description = "Provides freezing features to `pallet-assets`"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
log = { workspace = true }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
frame-benchmarking = { path = "../benchmarking", default-features = false, optional = true }
frame-support = { path = "../support", default-features = false }
frame-system = { path = "../system", default-features = false }
pallet-assets = { path = "../assets", default-features = false }
sp-runtime = { path = "../../primitives/runtime", default-features = false }

[dev-dependencies]
sp-io = { path = "../../primitives/io", default-features = false }
sp-core = { path = "../../primitives/core", default-features = false }
pallet-balances = { path = "../balances", default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-assets/std",
"pallet-balances/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
Loading

0 comments on commit a477bd0

Please sign in to comment.