Skip to content

Commit

Permalink
Merge pull request #41 from Metaquity-Network/feature/add-pallet-vesting
Browse files Browse the repository at this point in the history
Add `pallet-vesting`
  • Loading branch information
khssnv authored Dec 20, 2023
2 parents 8296aac + 4df9bd8 commit c7bc68f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 4 deletions.
2 changes: 2 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 @@ -63,6 +63,7 @@ pallet-transaction-payment-rpc = { version = "26.0.0" }
pallet-transaction-payment-rpc-runtime-api = { version = "24.0.0", default-features = false }
pallet-treasury = { version = "23.0.0", default-features = false}
pallet-utility = { version = "24.0.0", default-features = false }
pallet-vesting = { version = "24.0.0", default-features = false }
sc-basic-authorship = { version = "0.30.0" }
sc-chain-spec = { version = "23.0.0" }
sc-cli = { version = "0.32.0" }
Expand Down
2 changes: 2 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ pub mod devnet {
},
transaction_payment: Default::default(),
treasury: Default::default(),
vesting: Default::default(),
}
}
}
Expand Down Expand Up @@ -463,6 +464,7 @@ pub mod mainnet {
},
transaction_payment: Default::default(),
treasury: Default::default(),
vesting: Default::default(),
}
}
}
4 changes: 4 additions & 0 deletions runtime/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pallet-transaction-payment = { workspace = true, default-features = false }
pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = false }
pallet-treasury = { workspace = true, default-features = false }
pallet-utility = { workspace = true, default-features = false }
pallet-vesting = { workspace = true, default-features = false }
sp-api = { workspace = true, default-features = false }
sp-block-builder = { workspace = true, default-features = false }
sp-consensus-aura = { workspace = true, default-features = false }
Expand Down Expand Up @@ -126,6 +127,7 @@ std = [
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-utility/std",
"pallet-vesting/std",
"pallet-xcm/std",
"parachain-info/std",
"parity-scale-codec/std",
Expand Down Expand Up @@ -171,6 +173,7 @@ runtime-benchmarks = [
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand Down Expand Up @@ -203,6 +206,7 @@ try-runtime = [
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
]
23 changes: 21 additions & 2 deletions runtime/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use frame_support::{
parameter_types,
traits::{
fungible::HoldConsideration, AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, ConstU8,
EitherOfDiverse, Everything, LinearStoragePrice,
EitherOfDiverse, Everything, LinearStoragePrice, WithdrawReasons,
},
weights::{ConstantMultiplier, Weight},
BoundedVec, PalletId,
Expand All @@ -48,7 +48,7 @@ pub use runtime_common::{
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Percent, Permill};
pub use sp_runtime::{traits::ConvertInto, MultiAddress, Perbill, Percent, Permill};
use xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};

#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -739,6 +739,23 @@ impl pallet_treasury::Config for Runtime {
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
}

parameter_types! {
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
}

impl pallet_vesting::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = ConstU128<{ 1 * MQTY }>;
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Runtime>;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
// `VestingInfo` encode length is 36bytes. 28 schedules gets encoded as 1009 bytes, which is the
// highest number of schedules that encodes less than 2^10.
const MAX_VESTING_SCHEDULES: u32 = 28;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub struct Runtime {
Expand All @@ -759,6 +776,7 @@ construct_runtime!(
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 12,
Treasury: pallet_treasury = 13,
Vesting: pallet_vesting = 14,

// Governance
Sudo: pallet_sudo = 15,
Expand Down Expand Up @@ -801,6 +819,7 @@ mod benches {
[pallet_utility, Utility]
[pallet_nfts, Nfts]
[pallet_nft_fractionalization, NftFractionalization]
[pallet_vesting, Vesting]
[cumulus_pallet_xcmp_queue, XcmpQueue]
// SBP-M1 review: add missing pallets: benchmarks should be re-run on reference hardware based on how they are configured/used by your runtime
// TODO (@khssnv): consider reference hardware and re-run benchmarks
Expand Down
4 changes: 4 additions & 0 deletions runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pallet-transaction-payment = { workspace = true, default-features = false }
pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = false }
pallet-treasury = { workspace = true, default-features = false }
pallet-utility = { workspace = true, default-features = false }
pallet-vesting = { workspace = true, default-features = false }
sp-api = { workspace = true, default-features = false }
sp-block-builder = { workspace = true, default-features = false }
sp-consensus-aura = { workspace = true, default-features = false }
Expand Down Expand Up @@ -126,6 +127,7 @@ std = [
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-utility/std",
"pallet-vesting/std",
"pallet-xcm/std",
"parachain-info/std",
"parity-scale-codec/std",
Expand Down Expand Up @@ -171,6 +173,7 @@ runtime-benchmarks = [
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand Down Expand Up @@ -203,6 +206,7 @@ try-runtime = [
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
]
24 changes: 22 additions & 2 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use frame_support::{
parameter_types,
traits::{
fungible::HoldConsideration, AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, ConstU8,
EitherOfDiverse, Everything, LinearStoragePrice,
EitherOfDiverse, Everything, LinearStoragePrice, WithdrawReasons,
},
weights::{ConstantMultiplier, Weight},
BoundedVec, PalletId,
Expand All @@ -48,7 +48,7 @@ pub use runtime_common::{
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Percent, Permill};
pub use sp_runtime::{traits::ConvertInto, MultiAddress, Perbill, Percent, Permill};
use xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin};

#[cfg(any(feature = "std", test))]
Expand Down Expand Up @@ -739,7 +739,25 @@ impl pallet_treasury::Config for Runtime {
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
}

parameter_types! {
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
}

impl pallet_vesting::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = ConstU128<{ 1 * MQTY }>;
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Runtime>;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
// `VestingInfo` encode length is 36bytes. 28 schedules gets encoded as 1009 bytes, which is the
// highest number of schedules that encodes less than 2^10.
const MAX_VESTING_SCHEDULES: u32 = 28;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
// add pallet vesting
construct_runtime!(
pub struct Runtime {
// System support stuff.
Expand All @@ -759,6 +777,7 @@ construct_runtime!(
TransactionPayment: pallet_transaction_payment = 11,
Assets: pallet_assets = 12,
Treasury: pallet_treasury = 13,
Vesting: pallet_vesting = 14,

// Governance
Sudo: pallet_sudo = 15,
Expand Down Expand Up @@ -802,6 +821,7 @@ mod benches {
[pallet_utility, Utility]
[pallet_nfts, Nfts]
[pallet_nft_fractionalization, NftFractionalization]
[pallet_vesting, Vesting]
[cumulus_pallet_xcmp_queue, XcmpQueue]
// SBP-M1 review: add missing pallets: benchmarks should be re-run on reference hardware based on how they are configured/used by your runtime
// TODO (@khssnv): consider reference hardware and re-run benchmarks
Expand Down

0 comments on commit c7bc68f

Please sign in to comment.