Skip to content

Commit

Permalink
Add vesting-manager pallet (#126)
Browse files Browse the repository at this point in the history
* enable off-chain workers for pendulum node. (#136)

* Add bootnodes to Pendulum chain specs (#104)

* enable off chain workers for pendulum node.

---------

Co-authored-by: Gonza Montiel <[email protected]>

* Free up CI disk space

* Fix typo in workflow file

* Added vesting-manager pallet

* Bump versions

---------

Co-authored-by: cr4pt0 <[email protected]>
Co-authored-by: Gonza Montiel <[email protected]>
  • Loading branch information
3 people authored Mar 3, 2023
1 parent f5837cc commit a774df1
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 4 deletions.
18 changes: 18 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 @@ -4,6 +4,8 @@ panic = "unwind"
[workspace]
members = [
"node",
"pallets/parachain-staking",
"pallets/vesting-manager",
"runtime/common",
"runtime/amplitude",
"runtime/foucoco",
Expand Down
45 changes: 45 additions & 0 deletions pallets/vesting-manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
authors = ["Pendulum"]
description = "A pallet to manage vesting schedules"
edition = "2021"
name = "vesting-manager"
version = "0.0.1"

[dependencies]
log = "0.4.17"
parity-scale-codec = {version = "3.1.5", default-features = false, features = ["derive"]}
scale-info = {version = "2.1.1", default-features = false, features = ["derive"]}
serde = {version = "1.0.142", optional = true}
sp-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false}

frame-support = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false}
frame-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false}
pallet-vesting = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false}
sp-runtime = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false}
sp-std = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false}

# benchmarking
frame-benchmarking = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37", default-features = false, optional = true}

[features]
default = ["std"]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
std = [
"frame-support/std",
"frame-system/std",
"log/std",
"parity-scale-codec/std",
"pallet-vesting/std",
"scale-info/std",
"serde",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
]
try-runtime = [
"frame-support/try-runtime",
]
51 changes: 51 additions & 0 deletions pallets/vesting-manager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;

use frame_support::traits::VestingSchedule;
use sp_runtime::traits::StaticLookup;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type VestingSchedule: VestingSchedule<Self::AccountId>;
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
VestingScheduleRemoved { who: T::AccountId, schedule_index: u32 },
}

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(10_000_000)]
pub fn remove_vesting_schedule(
origin: OriginFor<T>,
who: AccountIdLookupOf<T>,
schedule_index: u32,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
let who = T::Lookup::lookup(who)?;
T::VestingSchedule::remove_vesting_schedule(&who, schedule_index)?;

Self::deposit_event(Event::VestingScheduleRemoved { who, schedule_index });

// waive the fee
Ok(Pays::No.into())
}
}
}
4 changes: 4 additions & 0 deletions runtime/pendulum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ orml-tokens = {git = "https://github.com/open-web3-stack/open-runtime-module-lib
# KILT
parachain-staking = {path = "../../pallets/parachain-staking", default-features = false}

# Pendulum Pallets
vesting-manager = {path = "../../pallets/vesting-manager", default-features = false}

# Polkadot
pallet-xcm = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.37"}
polkadot-parachain = {git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.37"}
Expand Down Expand Up @@ -155,6 +158,7 @@ std = [
"sp-std/std",
"sp-transaction-pool/std",
"sp-version/std",
"vesting-manager/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std"
Expand Down
16 changes: 12 additions & 4 deletions runtime/pendulum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("pendulum"),
impl_name: create_runtime_str!("pendulum"),
authoring_version: 1,
spec_version: 1,
spec_version: 2,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
transaction_version: 2,
state_version: 1,
};

Expand Down Expand Up @@ -258,7 +258,8 @@ impl Contains<RuntimeCall> for BaseFilter {
RuntimeCall::Utility(_) |
RuntimeCall::Vesting(_) |
RuntimeCall::XTokens(_) |
RuntimeCall::Multisig(_) => true,
RuntimeCall::Multisig(_) |
RuntimeCall::VestingManager(_) => true,
// All pallets are allowed, but exhaustive match is defensive
// in the case of adding new pallets.
}
Expand Down Expand Up @@ -805,6 +806,11 @@ impl pallet_vesting::Config for Runtime {
const MAX_VESTING_SCHEDULES: u32 = 10;
}

impl vesting_manager::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type VestingSchedule = Vesting;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
Expand Down Expand Up @@ -854,7 +860,9 @@ construct_runtime!(
Utility: pallet_utility::{Pallet, Call, Event} = 51,
Currencies: orml_currencies::{Pallet, Call, Storage} = 52,
Tokens: orml_tokens::{Pallet, Call, Storage, Event<T>} = 53,
XTokens: orml_xtokens::{Pallet, Storage, Call, Event<T>} = 54
XTokens: orml_xtokens::{Pallet, Storage, Call, Event<T>} = 54,

VestingManager: vesting_manager::{Pallet, Call, Event<T>} = 100
}
);

Expand Down

0 comments on commit a774df1

Please sign in to comment.