Skip to content

Commit

Permalink
Add calamari-vesting pallet (#221)
Browse files Browse the repository at this point in the history
* Add manta-vesting pallet

Co-authored-by: stechu <[email protected]>
Co-authored-by: ghzlatarev <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2021
1 parent 0273415 commit b3f646d
Show file tree
Hide file tree
Showing 15 changed files with 1,360 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/generate_calamari_weights_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ jobs:
id: pallet_balances
name: pallet_balances
iterations: 20
-
extrinsic:
id: '*'
name: calamari_vesting
pallet:
id: calamari_vesting
name: calamari_vesting
iterations: 20
-
extrinsic:
id: '*'
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

## Pending

## v3.1.0
### Breaking changes

### Features
- [\#221](https://github.com/Manta-Network/Manta/pull/221) Add calamari-vesting pallet.
- [\#263](https://github.com/Manta-Network/Manta/pull/263) Calamari/Manta docker image and integration tests.
- [\#265](https://github.com/Manta-Network/Manta/pull/265) Integrate pallet-tx-pause in Manta/Calamari giving SUDO the ability to rapidly halt further execution of any extrinsic in the runtime.

### Improvements
- Bump spec version to 3100
- [\#260](https://github.com/Manta-Network/Manta/pull/260) Update weight for `pallet_democracy`/`pallet_collective`/`pallet_membership`/`pallet_scheduler`/`pallet_balances`/`calamari-vesting`.
- [\#270](https://github.com/Manta-Network/Manta/pull/270) Whitelist `frame_system` calls and integrate custom `multisig` weights in Manta/Calamari runtimes.
- [\#279](https://github.com/Manta-Network/Manta/pull/279) CI improvements and custom weights for `pallet_session`, `pallet_timestamp`, `frame_system`.

### Bug fixes

Expand Down
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.

5 changes: 3 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ polkadot-primitives = { git = 'https://github.com/paritytech/polkadot.git', bran
polkadot-service = { git = 'https://github.com/paritytech/polkadot.git', branch = "release-v0.9.12" }

# Self dependencies
calamari-runtime = { path = '../runtime/calamari'}
manta-runtime = { path = '../runtime/manta'}
calamari-runtime = { path = '../runtime/calamari' }
manta-runtime = { path = '../runtime/manta' }
manta-primitives = { path = '../runtime/primitives' }

[build-dependencies]
substrate-build-script-utils = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.12" }

[features]
runtime-benchmarks = [
'calamari-runtime/runtime-benchmarks',
'polkadot-service/runtime-benchmarks',
'manta-runtime/runtime-benchmarks',
]
4 changes: 1 addition & 3 deletions node/src/chain_specs/manta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,5 @@ pub fn manta_testnet_config(id: ParaId) -> Result<MantaChainSpec, String> {
}

pub fn manta_config() -> Result<MantaChainSpec, String> {
MantaChainSpec::from_json_bytes(
&include_bytes!("../../../genesis/manta-genesis.json")[..],
)
MantaChainSpec::from_json_bytes(&include_bytes!("../../../genesis/manta-genesis.json")[..])
}
44 changes: 44 additions & 0 deletions pallets/vesting/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
authors = ['Manta Network']
name = "calamari-vesting"
version = '3.1.0'
edition = "2018"
homepage = 'https://manta.network'
license = 'GPL-3.0'
repository = 'https://github.com/Manta-Network/Manta/'

[dependencies]
codec = { package = "parity-scale-codec", version = "2.3.1", default-features = false, features = ["derive"] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.12", optional = true }
pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.12", optional = true }
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.12", optional = true }
frame-support = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.12" }
frame-system = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.12" }
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.12" }
sp-std = { git = 'https://github.com/paritytech/substrate.git', default-features = false, branch = "polkadot-v0.9.12" }

[dev-dependencies]
chrono = "0.4"
pallet-balances = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.12" }
pallet-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.12" }
sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.12" }
sp-io = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.12" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
]
runtime-benchmarks = [
"frame-benchmarking",
'frame-support/runtime-benchmarks',
'frame-system/runtime-benchmarks',
"pallet-timestamp/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
]
132 changes: 132 additions & 0 deletions pallets/vesting/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright 2020-2021 Manta Network.
// This file is part of Manta.
//
// Manta is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Manta is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Manta. If not, see <http://www.gnu.org/licenses/>.

#![cfg(feature = "runtime-benchmarks")]

extern crate alloc;

use super::*;
#[allow(unused_imports)]
use crate::Pallet as CalamariVesting;
use core::{convert::TryInto, ops::Div, time::Duration};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use sp_runtime::{traits::AtLeast32BitUnsigned, SaturatedConversion};

const SEED: u32 = 0;
// existential deposit multiplier
const ED_MULTIPLIER: u32 = 100;

fn assert_has_event<T: Config>(generic_event: <T as Config>::Event) {
frame_system::Pallet::<T>::assert_has_event(generic_event.into());
}

fn init_setup<
T: Config + pallet_timestamp::Config<Moment = u64> + pallet_balances::Config<I>,
I: 'static,
>(
caller: &T::AccountId,
) where
<T as pallet_balances::Config>::Balance: TryFrom<u128>,
T: pallet_balances::Config,
{
let now = Duration::from_secs(1636329600 - 1)
.as_millis()
.saturated_into::<u64>()
+ 1;
pallet_timestamp::Pallet::<T>::set_timestamp(now);

let existential_deposit = <T as pallet_balances::Config<I>>::ExistentialDeposit::get();
let amount = existential_deposit.saturating_mul(ED_MULTIPLIER.into());
let source_caller = T::Lookup::unlookup(caller.clone());
let _ = pallet_balances::Pallet::<T, I>::make_free_balance_be(&caller, amount);

assert_ok!(pallet_balances::Pallet::<T, I>::set_balance(
RawOrigin::Root.into(),
source_caller,
amount,
amount
));
assert_eq!(
pallet_balances::Pallet::<T, I>::free_balance(caller),
amount
);
}

benchmarks! {
where_clause {
where
T: Config + pallet_timestamp::Config<Moment = u64> + pallet_balances::Config,
BalanceOf<T>: AtLeast32BitUnsigned,
<T as pallet_balances::Config>::Balance: From<u128>,
}

update_vesting_schedule {
let new_schedule = BoundedVec::try_from(
crate::Pallet::<T>::vesting_schedule()
.iter()
.map(|(_, s)| s + 1)
.collect::<sp_std::vec::Vec<u64>>(),
)
.unwrap_or_default();
}: _(RawOrigin::Root, new_schedule.clone())
verify {
assert_has_event::<T>(Event::VestingScheduleUpdated(new_schedule).into());
}

vest {
let caller: T::AccountId = whitelisted_caller();
let recipient: T::AccountId = account("receiver", 0, SEED);
let source_recipient = T::Lookup::unlookup(recipient.clone());

init_setup::<T, ()>(&caller);
let existential_deposit = <T as pallet_balances::Config<()>>::ExistentialDeposit::get();
let unvested = existential_deposit.saturating_mul(ED_MULTIPLIER.div(10u32).into()).saturated_into::<u128>().try_into().ok().unwrap();
assert_ok!(crate::Pallet::<T>::vested_transfer(RawOrigin::Signed(caller.clone()).into(), source_recipient, unvested));
assert!(crate::Pallet::<T>::vesting_balance(&recipient).is_some());

let now = Duration::from_secs(1660694400)
.as_millis()
.saturated_into::<u64>()
+ 1;
pallet_timestamp::Pallet::<T>::set_timestamp(now);
}: _(RawOrigin::Signed(recipient.clone()))
verify {
assert_has_event::<T>(Event::VestingCompleted(recipient).into());
}

vested_transfer {
let caller: T::AccountId = whitelisted_caller();
init_setup::<T, ()>(&caller);
let existential_deposit = <T as pallet_balances::Config<()>>::ExistentialDeposit::get();
let unvested = existential_deposit.saturating_mul(ED_MULTIPLIER.div(10u32).into()).saturated_into::<u128>().try_into().ok().unwrap();
let recipient: T::AccountId = account("receiver", 0, SEED);
let source_recipient = T::Lookup::unlookup(recipient.clone());
}: _(RawOrigin::Signed(caller.clone()), source_recipient, unvested)
verify {
assert_eq!(crate::Pallet::<T>::vesting_balance(&recipient), Some(unvested));
assert_has_event::<T>(Event::VestingUpdated(recipient, unvested).into());
}
}

impl_benchmark_test_suite!(
CalamariVesting,
crate::mock::ExtBuilder::default()
.existential_deposit(1)
.build(),
crate::mock::Test,
);
Loading

0 comments on commit b3f646d

Please sign in to comment.