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

Implement pallet-assets-freezer #3951

Merged
merged 35 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8f10c26
Initial commit
pandres95 Mar 27, 2024
ec47019
feat(pallet-assets-freezer): implement inspection of freezes
pandres95 Apr 2, 2024
74d7217
feat(pallet-assets-freezer): implement MutateFreeze
pandres95 Apr 2, 2024
5c6ea2b
fix(pallet-assets-freezer): import Get trait from sp_runtime
pandres95 Apr 2, 2024
6dced55
fix(pallet-assets-freezer): clippy issues with "runtime-benchmarks" f…
pandres95 Apr 2, 2024
fc6cdfe
chore(pallet-assets-freezer): join impls in a single file
pandres95 Apr 2, 2024
59509c8
fixup(pallet-assets-freezer): remove env_logger — not needed anymore
pandres95 Apr 2, 2024
57eb005
chore(pallet-assets-freezer): remove last pieces of boilerplate code
pandres95 Apr 2, 2024
57ae481
change(pallet-assets-freezer): apply requested changes
pandres95 Apr 3, 2024
fd01a96
fix(pallet-assets-freezer): fmt
pandres95 Apr 3, 2024
8b0de59
change(prdoc): add pr doc for 3951
pandres95 Apr 3, 2024
70cd92d
change(pallet-assets-freezer): apply requested changes
pandres95 Apr 4, 2024
e3229b3
fix: revert unwanted formatting changes
pandres95 Apr 4, 2024
09066c6
change(pallet-assets-freezer): uniform tests interface
pandres95 Apr 4, 2024
2f79e19
change(pallet-assets-freezer): test integration with `pallet-assets`
pandres95 Apr 4, 2024
7e275e0
setup `pallet-assets-freezer` on testnet asset-hub runtimes
pandres95 Apr 5, 2024
c3a6664
fix: propagate features from asset-hubs towards pallet-assets-freezer…
pandres95 Apr 5, 2024
8582bfa
fix: toml format in cargo for `asset-hub-rococo`/`asset-hub-westend`
pandres95 Apr 5, 2024
2bbb05c
apply requested changes
pandres95 Apr 5, 2024
1b66082
".git/.scripts/commands/fmt/fmt.sh"
Apr 5, 2024
05d8861
fix: lint
pandres95 Apr 5, 2024
2018b53
Merge branch 'pandres95--pallet-assets-freezer' of https://github.com…
pandres95 Apr 5, 2024
e395e22
apply requested changes
pandres95 Apr 8, 2024
30199b3
Merge branch 'master' into pandres95--pallet-assets-freezer
liamaharon Apr 9, 2024
c4fabeb
apply requested changes
pandres95 Apr 9, 2024
c9f8573
Merge branch 'master' into pandres95--pallet-assets-freezer
liamaharon Apr 10, 2024
64a8de1
change(pallet-assets-freezer): address review comments
pandres95 Apr 10, 2024
f4abe0d
change(pallet-assets-freezer): rename type aliases for direct type re…
pandres95 Apr 11, 2024
0f76c41
change(pallet-assets-freezer): turn trait impl doc comments into dev …
pandres95 Apr 11, 2024
2b17fbb
change(pallet-assets-freezer): use RuntimeFreezeReason as freeze iden…
pandres95 Apr 11, 2024
b9be439
change(cumuls/parachains/runtimes/assets): adjust config of `pallet-a…
pandres95 Apr 11, 2024
bfe872b
minor(pallet-assets-freezer): update docs
pandres95 Apr 12, 2024
73ba9c6
Merge branch 'master' into pandres95--pallet-assets-freezer
pandres95 Jun 17, 2024
955ef2c
Merge branch 'master' into pandres95--pallet-assets-freezer
pandres95 Jun 17, 2024
5cee625
change(umbrella): add dependency to pallet-assets-freezer
pandres95 Jun 18, 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
19 changes: 19 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 @@ -293,6 +293,7 @@ members = [
"substrate/frame/asset-conversion",
"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 @@ -26,6 +26,7 @@ frame-try-runtime = { path = "../../../../../substrate/frame/try-runtime", defau
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 @@ -121,6 +122,7 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"frame-system/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 @@ -155,6 +157,7 @@ try-runtime = [
"frame-try-runtime/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 @@ -203,6 +206,7 @@ std = [
"log/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 @@ -265,7 +265,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 @@ -275,6 +275,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 @@ -303,14 +310,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 @@ -398,7 +412,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 @@ -408,6 +422,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 @@ -931,6 +952,9 @@ construct_runtime!(
NftFractionalization: pallet_nft_fractionalization = 54,
PoolAssets: pallet_assets::<Instance3> = 55,
AssetConversion: pallet_asset_conversion = 56,
AssetsFreezer: pallet_assets_freezer::<Instance1> = 57,
pandres95 marked this conversation as resolved.
Show resolved Hide resolved
ForeignAssetsFreezer: pallet_assets_freezer::<Instance2> = 58,
PoolAssetsFreezer: pallet_assets_freezer::<Instance3> = 59,

#[cfg(feature = "state-trie-version-1")]
StateTrieMigration: pallet_state_trie_migration = 70,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ frame-try-runtime = { path = "../../../../../substrate/frame/try-runtime", defau
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 @@ -112,6 +113,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"hex-literal",
"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 @@ -144,6 +146,7 @@ try-runtime = [
"frame-try-runtime/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 @@ -191,6 +194,7 @@ std = [
"log/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 @@ -248,7 +248,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 @@ -258,6 +258,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 @@ -285,14 +292,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 @@ -377,7 +391,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 @@ -387,6 +401,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 @@ -906,6 +927,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,
}
);

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
Loading