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-vesting #7404

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e6edb06
feat(frame): introduce `pallet-assets-vesting`
pandres95 Jan 30, 2025
1efe964
feat(pallet-assets-vesting): start adding equivalent tests from `pall…
pandres95 Jan 31, 2025
648c663
Merge branch 'master' into pallet-assets-vesting
pandres95 Jan 31, 2025
478b259
fix(pallet-assets-vesting): fmt
pandres95 Feb 10, 2025
4eef9ff
feat(pallet-assets-vesting): add tests for `vested_transfer`
pandres95 Feb 10, 2025
400c353
feat(pallet-assets-vesting): add tests for `force_vested_transfer`
pandres95 Feb 10, 2025
ce554d2
chore(pallet-assets-vesting): modularize tests / remove repeated refe…
pandres95 Feb 10, 2025
2b468c0
chore(pallet-assets-vesting): add tests for `merge_schedules`
pandres95 Feb 10, 2025
fc2e23d
chore(pallet-assets-vesting): add tests for `genesis_config`
pandres95 Feb 10, 2025
ec58622
chore(pallet-assets-vesting): add tests for `vesting_info`
pandres95 Feb 10, 2025
434a99e
feat(pallet-assets-vesting): migrate misc tests from `pallet-vesting`
pandres95 Feb 10, 2025
768e77b
feat(pallet-assets-vesting): add benchmarkings for `pallet-assets-ves…
pandres95 Feb 12, 2025
4ff51b7
Merge branch 'master' into pallet-assets-vesting
pandres95 Feb 12, 2025
42866a2
fix(pallet-assets-vesting): missing license headers
pandres95 Feb 12, 2025
5b21df1
fix(pallet-assets-vesting): format Cargo.toml
pandres95 Feb 12, 2025
8b127dc
fix(pallet-assets-vesting): make clippy happy
pandres95 Feb 12, 2025
05b7583
fix(polkadot-sdk): update umbrella
pandres95 Feb 12, 2025
16b1b9d
chore: add PRDoc
pandres95 Feb 12, 2025
31b8299
fix: make CI happy
pandres95 Feb 12, 2025
e620f9d
fix(pallet-assets-vesting): fully reference `TestExternalities` on `b…
pandres95 Feb 12, 2025
1250c2e
fix(pallet-assets-vesting): missing import to `Vec`
pandres95 Feb 12, 2025
71a1c69
fix(pallet-assets-vesting): fmt
pandres95 Feb 12, 2025
8675f7d
fix(pallet-assets-vesting): invalid `assert_ok` in `benchmarking`
pandres95 Feb 12, 2025
d5fa351
fix(pallet-assets-vesting): clippy
pandres95 Feb 12, 2025
66e3103
feat(cumulus/parachains): add vesting for Assets and ForeignAssets in…
pandres95 Feb 12, 2025
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
16 changes: 16 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ members = [
"substrate/frame/asset-rewards",
"substrate/frame/assets",
"substrate/frame/assets-freezer",
"substrate/frame/assets-vesting",
"substrate/frame/atomic-swap",
"substrate/frame/aura",
"substrate/frame/authority-discovery",
Expand Down Expand Up @@ -899,6 +900,7 @@ pallet-asset-rewards = { path = "substrate/frame/asset-rewards", default-feature
pallet-asset-tx-payment = { path = "substrate/frame/transaction-payment/asset-tx-payment", default-features = false }
pallet-assets = { path = "substrate/frame/assets", default-features = false }
pallet-assets-freezer = { path = "substrate/frame/assets-freezer", default-features = false }
pallet-assets-vesting = { path = "substrate/frame/assets-vesting", default-features = false }
pallet-atomic-swap = { default-features = false, path = "substrate/frame/atomic-swap" }
pallet-aura = { path = "substrate/frame/aura", default-features = false }
pallet-authority-discovery = { path = "substrate/frame/authority-discovery", default-features = false }
Expand Down
10 changes: 9 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pallet-asset-conversion-tx-payment = { workspace = true }
pallet-asset-rewards = { workspace = true }
pallet-assets = { workspace = true }
pallet-assets-freezer = { workspace = true }
pallet-assets-vesting = { workspace = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
Expand Down Expand Up @@ -63,7 +64,11 @@ sp-version = { workspace = true }
sp-weights = { workspace = true }

# num-traits feature needed for dex integer sq root:
primitive-types = { features = ["codec", "num-traits", "scale-info"], workspace = true }
primitive-types = { features = [
"codec",
"num-traits",
"scale-info",
], workspace = true }

# Polkadot
pallet-xcm = { workspace = true }
Expand Down Expand Up @@ -126,6 +131,7 @@ runtime-benchmarks = [
"pallet-asset-conversion/runtime-benchmarks",
"pallet-asset-rewards/runtime-benchmarks",
"pallet-assets-freezer/runtime-benchmarks",
"pallet-assets-vesting/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
Expand Down Expand Up @@ -166,6 +172,7 @@ try-runtime = [
"pallet-asset-conversion/try-runtime",
"pallet-asset-rewards/try-runtime",
"pallet-assets-freezer/try-runtime",
"pallet-assets-vesting/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
Expand Down Expand Up @@ -217,6 +224,7 @@ std = [
"pallet-asset-conversion/std",
"pallet-asset-rewards/std",
"pallet-assets-freezer/std",
"pallet-assets-vesting/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand Down
51 changes: 50 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ use xcm_runtime_apis::{

#[cfg(feature = "runtime-benchmarks")]
use frame_support::traits::PalletInfoAccess;

use sp_runtime::traits::ConvertInto;
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};

impl_opaque_keys! {
Expand Down Expand Up @@ -290,6 +290,25 @@ impl pallet_assets_freezer::Config<AssetsFreezerInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const TrustBackedMinVestedTransfer: Balance = 100 * CENTS;
}

pub type TrustBackedAssetsVestingInstance = pallet_assets_vesting::Instance1;

impl pallet_assets_vesting::Config<TrustBackedAssetsVestingInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForceOrigin = EnsureRoot<AccountId>;
type Assets = Assets;
type Freezer = AssetsFreezer;
type BlockNumberToBalance = ConvertInto;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = ();
type MinVestedTransfer = TrustBackedMinVestedTransfer;
type BlockNumberProvider = System;
const MAX_VESTING_SCHEDULES: u32 = 28;
}

parameter_types! {
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
Expand Down Expand Up @@ -511,6 +530,25 @@ impl pallet_assets_freezer::Config<ForeignAssetsFreezerInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const ForeignMinVestedTransfer: Balance = 1;
}

pub type ForeignAssetsVestingInstance = pallet_assets_vesting::Instance2;

impl pallet_assets_vesting::Config<ForeignAssetsVestingInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForceOrigin = EnsureRoot<AccountId>;
type Assets = ForeignAssets;
type Freezer = ForeignAssetsFreezer;
type BlockNumberToBalance = ConvertInto;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = ();
type MinVestedTransfer = ForeignMinVestedTransfer;
type BlockNumberProvider = System;
const MAX_VESTING_SCHEDULES: u32 = 28;
}

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 @@ -1107,6 +1145,9 @@ construct_runtime!(
ForeignAssetsFreezer: pallet_assets_freezer::<Instance2> = 58,
PoolAssetsFreezer: pallet_assets_freezer::<Instance3> = 59,

AssetsVesting: pallet_assets_vesting::<Instance1> = 80,
ForeignAssetsVesting: pallet_assets_vesting::<Instance2> = 81,

AssetRewards: pallet_asset_rewards = 60,

// TODO: the pallet instance should be removed once all pools have migrated
Expand Down Expand Up @@ -1299,6 +1340,8 @@ mod benches {
[pallet_assets, Local]
[pallet_assets, Foreign]
[pallet_assets, Pool]
[pallet_assets_vesting, LocalVesting]
[pallet_assets_vesting, ForeignVesting]
[pallet_asset_conversion, AssetConversion]
[pallet_asset_rewards, AssetRewards]
[pallet_asset_conversion_tx_payment, AssetTxPayment]
Expand Down Expand Up @@ -1670,6 +1713,9 @@ impl_runtime_apis! {
type Foreign = pallet_assets::Pallet::<Runtime, ForeignAssetsInstance>;
type Pool = pallet_assets::Pallet::<Runtime, PoolAssetsInstance>;

type LocalVesting = pallet_assets::Pallet::<Runtime, TrustBackedAssetsVestingInstance>;
type ForeignVesting = pallet_assets::Pallet::<Runtime, ForeignAssetsVestingInstance>;

type ToWestend = XcmBridgeHubRouterBench<Runtime, ToWestendXcmRouterInstance>;

let mut list = Vec::<BenchmarkList>::new();
Expand Down Expand Up @@ -1975,6 +2021,9 @@ impl_runtime_apis! {
type Foreign = pallet_assets::Pallet::<Runtime, ForeignAssetsInstance>;
type Pool = pallet_assets::Pallet::<Runtime, PoolAssetsInstance>;

type LocalVesting = pallet_assets::Pallet::<Runtime, TrustBackedAssetsVestingInstance>;
type ForeignVesting = pallet_assets::Pallet::<Runtime, ForeignAssetsVestingInstance>;

type ToWestend = XcmBridgeHubRouterBench<Runtime, ToWestendXcmRouterInstance>;

use frame_support::traits::WhitelistedStorageKeys;
Expand Down
10 changes: 9 additions & 1 deletion cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pallet-asset-conversion-tx-payment = { workspace = true }
pallet-asset-rewards = { workspace = true }
pallet-assets = { workspace = true }
pallet-assets-freezer = { workspace = true }
pallet-assets-vesting = { workspace = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
Expand Down Expand Up @@ -66,7 +67,11 @@ sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }

# num-traits feature needed for dex integer sq root:
primitive-types = { features = ["codec", "num-traits", "scale-info"], workspace = true }
primitive-types = { features = [
"codec",
"num-traits",
"scale-info",
], workspace = true }

# Polkadot
pallet-xcm = { workspace = true }
Expand Down Expand Up @@ -130,6 +135,7 @@ runtime-benchmarks = [
"pallet-asset-conversion/runtime-benchmarks",
"pallet-asset-rewards/runtime-benchmarks",
"pallet-assets-freezer/runtime-benchmarks",
"pallet-assets-vesting/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
Expand Down Expand Up @@ -173,6 +179,7 @@ try-runtime = [
"pallet-asset-conversion/try-runtime",
"pallet-asset-rewards/try-runtime",
"pallet-assets-freezer/try-runtime",
"pallet-assets-vesting/try-runtime",
"pallet-assets/try-runtime",
"pallet-aura/try-runtime",
"pallet-authorship/try-runtime",
Expand Down Expand Up @@ -227,6 +234,7 @@ std = [
"pallet-asset-conversion/std",
"pallet-asset-rewards/std",
"pallet-assets-freezer/std",
"pallet-assets-vesting/std",
"pallet-assets/std",
"pallet-aura/std",
"pallet-authorship/std",
Expand Down
53 changes: 51 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 @@ -105,7 +105,7 @@ use xcm::{

#[cfg(feature = "runtime-benchmarks")]
use frame_support::traits::PalletInfoAccess;

use sp_runtime::traits::ConvertInto;
#[cfg(feature = "runtime-benchmarks")]
use xcm::latest::prelude::{
Asset, Assets as XcmAssets, Fungible, Here, InteriorLocation, Junction, Junction::*, Location,
Expand Down Expand Up @@ -294,6 +294,25 @@ impl pallet_assets_freezer::Config<AssetsFreezerInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const TrustBackedMinVestedTransfer: Balance = 100 * CENTS;
}

pub type TrustBackedAssetsVestingInstance = pallet_assets_vesting::Instance1;

impl pallet_assets_vesting::Config<TrustBackedAssetsVestingInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForceOrigin = EnsureRoot<AccountId>;
type Assets = Assets;
type Freezer = AssetsFreezer;
type BlockNumberToBalance = ConvertInto;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = ();
type MinVestedTransfer = TrustBackedMinVestedTransfer;
type BlockNumberProvider = System;
const MAX_VESTING_SCHEDULES: u32 = 28;
}

parameter_types! {
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub const LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
Expand Down Expand Up @@ -563,6 +582,25 @@ impl pallet_assets_freezer::Config<ForeignAssetsFreezerInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
}

parameter_types! {
pub const ForeignMinVestedTransfer: Balance = 1;
}

pub type ForeignAssetsVestingInstance = pallet_assets_vesting::Instance2;

impl pallet_assets_vesting::Config<ForeignAssetsVestingInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForceOrigin = EnsureRoot<AccountId>;
type Assets = ForeignAssets;
type Freezer = ForeignAssetsFreezer;
type BlockNumberToBalance = ConvertInto;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = ();
type MinVestedTransfer = ForeignMinVestedTransfer;
type BlockNumberProvider = System;
const MAX_VESTING_SCHEDULES: u32 = 28;
}

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 @@ -1168,6 +1206,10 @@ construct_runtime!(
AssetsFreezer: pallet_assets_freezer::<Instance1> = 57,
ForeignAssetsFreezer: pallet_assets_freezer::<Instance2> = 58,
PoolAssetsFreezer: pallet_assets_freezer::<Instance3> = 59,

AssetsVesting: pallet_assets_vesting::<Instance1> = 80,
ForeignAssetsVesting: pallet_assets_vesting::<Instance2> = 81,

Revive: pallet_revive = 60,

AssetRewards: pallet_asset_rewards = 61,
Expand Down Expand Up @@ -1446,8 +1488,9 @@ mod benches {
[frame_system, SystemBench::<Runtime>]
[frame_system_extensions, SystemExtensionsBench::<Runtime>]
[pallet_assets, Local]
[pallet_assets, Foreign]
[pallet_assets, Pool]
[pallet_assets_vesting, LocalVesting]
[pallet_assets_vesting, ForeignVesting]
[pallet_asset_conversion, AssetConversion]
[pallet_asset_rewards, AssetRewards]
[pallet_asset_conversion_tx_payment, AssetTxPayment]
Expand Down Expand Up @@ -1866,6 +1909,9 @@ impl_runtime_apis! {
type Foreign = pallet_assets::Pallet::<Runtime, ForeignAssetsInstance>;
type Pool = pallet_assets::Pallet::<Runtime, PoolAssetsInstance>;

type LocalVesting = pallet_assets::Pallet::<Runtime, TrustBackedAssetsVestingInstance>;
type ForeignVesting = pallet_assets::Pallet::<Runtime, ForeignAssetsVestingInstance>;

type ToRococo = XcmBridgeHubRouterBench<Runtime, ToRococoXcmRouterInstance>;

let mut list = Vec::<BenchmarkList>::new();
Expand Down Expand Up @@ -2171,6 +2217,9 @@ impl_runtime_apis! {
type Foreign = pallet_assets::Pallet::<Runtime, ForeignAssetsInstance>;
type Pool = pallet_assets::Pallet::<Runtime, PoolAssetsInstance>;

type LocalVesting = pallet_assets::Pallet::<Runtime, TrustBackedAssetsVestingInstance>;
type ForeignVesting = pallet_assets::Pallet::<Runtime, ForeignAssetsVestingInstance>;

type ToRococo = XcmBridgeHubRouterBench<Runtime, ToRococoXcmRouterInstance>;

use frame_support::traits::WhitelistedStorageKeys;
Expand Down
16 changes: 16 additions & 0 deletions prdoc/pr_7404.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: Bridges small nits/improvements
doc:
- audience: Runtime Dev
description: |
This Pull Request introduces `pallet-assets-vesting`, allowing runtimes to add vesting schedules to assets.
crates:
- name: asset-hub-rococo-runtime
bump: minor
- name: asset-hub-westend-runtime
bump: minor
- name: frame-support
bump: minor
- name: pallet-assets-vesting
bump: major
- name: polkadot-sdk
bump: minor
Loading
Loading