Skip to content

Commit 31ba262

Browse files
authored
Add Vesting to Asset Hubs (#269)
Adds the Vesting pallet to the Asset Hub runtimes, as a few people have requested this feature, and in general the Asset Hubs should provide more balances/asset-related features than the Relay Chain.
1 parent 5cd9e70 commit 31ba262

10 files changed

Lines changed: 596 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Changelog for the runtimes governed by the Polkadot Fellowship.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## Unreleased
8+
9+
- Add `pallet-vesting` to Asset Hubs ([polkadot-fellows/runtimes#269](https://github.com/polkadot-fellows/runtimes/pull/269))
10+
711
## [1.2.1] 09.04.2024
812

913
### Changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pallet-transaction-payment = { workspace = true }
4949
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
5050
pallet-uniques = { workspace = true }
5151
pallet-utility = { workspace = true }
52+
pallet-vesting = { workspace = true }
5253
sp-api = { workspace = true }
5354
sp-block-builder = { workspace = true }
5455
sp-consensus-aura = { workspace = true }
@@ -138,6 +139,7 @@ runtime-benchmarks = [
138139
"pallet-timestamp/runtime-benchmarks",
139140
"pallet-uniques/runtime-benchmarks",
140141
"pallet-utility/runtime-benchmarks",
142+
"pallet-vesting/runtime-benchmarks",
141143
"pallet-xcm-benchmarks/runtime-benchmarks",
142144
"pallet-xcm-bridge-hub-router/runtime-benchmarks",
143145
"pallet-xcm/runtime-benchmarks",
@@ -178,6 +180,7 @@ try-runtime = [
178180
"pallet-transaction-payment/try-runtime",
179181
"pallet-uniques/try-runtime",
180182
"pallet-utility/try-runtime",
183+
"pallet-vesting/try-runtime",
181184
"pallet-xcm-bridge-hub-router/try-runtime",
182185
"pallet-xcm/try-runtime",
183186
"parachain-info/try-runtime",
@@ -229,6 +232,7 @@ std = [
229232
"pallet-transaction-payment/std",
230233
"pallet-uniques/std",
231234
"pallet-utility/std",
235+
"pallet-vesting/std",
232236
"pallet-xcm-benchmarks?/std",
233237
"pallet-xcm-bridge-hub-router/std",
234238
"pallet-xcm/std",

system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ use sp_api::impl_runtime_apis;
3939
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
4040
use sp_runtime::{
4141
create_runtime_str, generic, impl_opaque_keys,
42-
traits::{AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Verify},
42+
traits::{
43+
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto, Verify,
44+
},
4345
transaction_validity::{TransactionSource, TransactionValidity},
4446
ApplyExtrinsicResult, Perbill, Permill,
4547
};
@@ -58,7 +60,7 @@ use frame_support::{
5860
traits::{
5961
fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool,
6062
ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter,
61-
TransformOrigin,
63+
TransformOrigin, WithdrawReasons,
6264
},
6365
weights::{ConstantMultiplier, Weight},
6466
BoundedVec, PalletId,
@@ -229,6 +231,26 @@ impl pallet_balances::Config for Runtime {
229231
type MaxFreezes = ConstU32<0>;
230232
}
231233

234+
parameter_types! {
235+
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
236+
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
237+
}
238+
239+
impl pallet_vesting::Config for Runtime {
240+
type RuntimeEvent = RuntimeEvent;
241+
type Currency = Balances;
242+
type BlockNumberToBalance = ConvertInto;
243+
type MinVestedTransfer = ExistentialDeposit;
244+
type WeightInfo = weights::pallet_vesting::WeightInfo<Runtime>;
245+
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
246+
/// Note for wallets and implementers: This means that vesting schedules are evaluated with the
247+
/// block number of the Relay Chain, not the parachain. This is because with Coretime and Async
248+
/// Backing, parachain block numbers may not be a good proxy for time. Vesting schedules should
249+
/// be set accordingly.
250+
type BlockNumberProvider = cumulus_pallet_parachain_system::RelaychainDataProvider<Runtime>;
251+
const MAX_VESTING_SCHEDULES: u32 = 28;
252+
}
253+
232254
parameter_types! {
233255
/// Relay Chain `TransactionByteFee` / 10
234256
pub const TransactionByteFee: Balance = system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE;
@@ -507,7 +529,10 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
507529
RuntimeCall::Assets { .. } |
508530
RuntimeCall::NftFractionalization { .. } |
509531
RuntimeCall::Nfts { .. } |
510-
RuntimeCall::Uniques { .. }
532+
RuntimeCall::Uniques { .. } |
533+
// We allow calling `vest` and merging vesting schedules, but obviously not
534+
// vested transfers.
535+
RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. })
511536
),
512537
ProxyType::CancelProxy => matches!(
513538
c,
@@ -934,6 +959,7 @@ construct_runtime!(
934959
Balances: pallet_balances = 10,
935960
TransactionPayment: pallet_transaction_payment = 11,
936961
AssetTxPayment: pallet_asset_conversion_tx_payment = 13,
962+
Vesting: pallet_vesting = 14,
937963

938964
// Collator support. the order of these 5 are important and shall not change.
939965
Authorship: pallet_authorship = 20,
@@ -1029,6 +1055,7 @@ mod benches {
10291055
[pallet_session, SessionBench::<Runtime>]
10301056
[pallet_uniques, Uniques]
10311057
[pallet_utility, Utility]
1058+
[pallet_vesting, Vesting]
10321059
[pallet_timestamp, Timestamp]
10331060
[pallet_collator_selection, CollatorSelection]
10341061
[cumulus_pallet_parachain_system, ParachainSystem]

system-parachains/asset-hubs/asset-hub-kusama/src/weights/mod.rs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)