-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated PR for vortex distribution, making changes according to previ…
…ous review comments, and rebased on main
- Loading branch information
Showing
16 changed files
with
2,272 additions
and
408 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
[package] | ||
name = "pallet-vortex" | ||
version = "2.1.0" | ||
authors = ["Centrality Developers <[email protected]>"] | ||
edition = "2021" | ||
license = "GPL-3.0" | ||
repository = "https://github.com/futureversecom/seed" | ||
description = "Vortex distribution pallet" | ||
|
||
[dependencies] | ||
serde = { version = "1.0.136", optional = true } | ||
scale-info = { version = "2.1", default-features = false, features = ["derive"] } | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } | ||
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } | ||
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } | ||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } | ||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30", default-features = false } | ||
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30", default-features = false } | ||
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } | ||
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } | ||
pallet-staking = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.30" } | ||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.30" } | ||
|
||
seed-primitives = { path = "../../primitives", default-features = false } | ||
seed-pallet-common = { path = "../common", default-features = false } | ||
|
||
[dev-dependencies] | ||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } | ||
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } | ||
pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } | ||
pallet-assets-ext = { path = "../assets-ext" } | ||
frame-election-provider-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } | ||
pallet-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } | ||
pallet-bags-list = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } | ||
pallet-staking-reward-curve = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"seed-primitives/std", | ||
"seed-pallet-common/std", | ||
"serde", | ||
"codec/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
"sp-staking/std", | ||
"pallet-staking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/std", | ||
] | ||
try-runtime = ["frame-support/try-runtime"] | ||
runtime-benchmarks = ["frame-benchmarking"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
|
||
use crate::Pallet as Vortex; | ||
use frame_benchmarking::{account as bench_account, benchmarks, impl_benchmark_test_suite}; | ||
use frame_support::{assert_ok, BoundedVec}; | ||
use frame_system::{Pallet as System, RawOrigin}; | ||
use sp_runtime::traits::One; | ||
|
||
use crate::Pallet as VortexDistribution; | ||
|
||
/// This is a helper function to get an account. | ||
pub fn account<T: Config>(name: &'static str) -> T::AccountId { | ||
bench_account(name, 0, 0) | ||
} | ||
|
||
pub fn origin<T: Config>(acc: &T::AccountId) -> RawOrigin<T::AccountId> { | ||
RawOrigin::Signed(acc.clone()) | ||
} | ||
|
||
fn mint_asset<T: Config>(fee_vault: &T::AccountId, root_vault: &T::AccountId) -> AssetId { | ||
let asset_id = T::MultiCurrency::create(&fee_vault, None).unwrap(); | ||
// let mint_amount = Balance::from(10_000_000u32); | ||
// let mint_amount = <T as pallet_staking::Config>::CurrencyBalance::default(); | ||
let mint_amount = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
assert_ok!(T::MultiCurrency::mint_into(asset_id, &fee_vault, mint_amount.into())); | ||
assert_ok!(T::MultiCurrency::mint_into(T::NativeAssetId::get(), &root_vault, mint_amount)); | ||
assert_ok!(T::MultiCurrency::mint_into(T::VtxAssetId::get(), &root_vault, mint_amount)); | ||
asset_id | ||
} | ||
|
||
benchmarks! { | ||
create_vtx_dist { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let amount = 100u32.into(); | ||
}: _(RawOrigin::Root, vortex_dist_id, amount) | ||
verify { | ||
assert_eq!(VtxDistStatuses::<T>::get(vortex_dist_id), VtxDistStatus::Enabled); | ||
} | ||
|
||
disable_vtx_dist { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let amount = 100u32.into(); | ||
assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
}: _(RawOrigin::Root, vortex_dist_id) | ||
verify { | ||
assert_eq!(VtxDistStatuses::<T>::get(vortex_dist_id), VtxDistStatus::NotEnabled); | ||
} | ||
|
||
start_vtx_dist { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let amount = 100u32.into(); | ||
assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
}: _(RawOrigin::Root, vortex_dist_id) | ||
verify { | ||
assert_eq!(VtxDistStatuses::<T>::get(vortex_dist_id), VtxDistStatus::Paying); | ||
} | ||
|
||
set_vtx_dist_eras { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let amount = 100u32.into(); | ||
let start_era = 1u32; | ||
let end_era = 64u32; | ||
assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
}: _(RawOrigin::Root, vortex_dist_id, start_era, end_era) | ||
verify { | ||
assert_eq!(VtxDistEras::<T>::get(vortex_dist_id), (start_era, end_era)); | ||
} | ||
|
||
set_asset_prices { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let amount = 100u32.into(); | ||
let asset_id = AssetId::default(); | ||
// let balance = <T as pallet_staking::Config>::CurrencyBalance::default(); | ||
let balance = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let asset_prices = BoundedVec::try_from(vec![(asset_id, balance.into())]).unwrap(); | ||
assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
}: _(RawOrigin::Root, asset_prices, vortex_dist_id) | ||
verify { | ||
assert_eq!(AssetPrices::<T>::get(vortex_dist_id, asset_id), balance); | ||
} | ||
|
||
register_rewards { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let amount = 100u32.into(); | ||
// let origin = origin::<T>(&account::<T>("test")); | ||
let rewards = BoundedVec::try_from(vec![(account::<T>("test"), 100u32.into())]).unwrap(); | ||
assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
}: _(RawOrigin::Root, vortex_dist_id, rewards) | ||
verify { | ||
let reward = VtxDistOrderbook::<T>::get(vortex_dist_id, account::<T>("test")); | ||
assert_eq!(reward, (100u32.into(), false)); | ||
} | ||
|
||
trigger_vtx_distribution { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let root_price = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let vortex_price = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let root_vault = account::<T>("root_vault"); | ||
let fee_vault = account::<T>("fee_vault"); | ||
let amount = 100u32.into(); | ||
let asset_id = mint_asset::<T>(&fee_vault, &root_vault); | ||
assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
let balance = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let asset_prices = BoundedVec::try_from(vec![(asset_id, balance.into())]).unwrap(); | ||
assert_ok!(VortexDistribution::<T>::set_asset_prices(RawOrigin::Root.into(), asset_prices, vortex_dist_id)); | ||
}: _(RawOrigin::Root, root_price, vortex_price, root_vault.clone(), fee_vault.clone(), vortex_dist_id) | ||
verify { | ||
assert_eq!(T::MultiCurrency::balance(asset_id, &root_vault), 0u32.into()); | ||
assert_eq!(T::MultiCurrency::balance(T::NativeAssetId::get(), &root_vault), 0u32.into()); | ||
|
||
assert_eq!(T::MultiCurrency::balance(asset_id, &fee_vault), 0u32.into()); | ||
assert_eq!(T::MultiCurrency::balance(T::NativeAssetId::get(), &fee_vault), 0u32.into()); | ||
|
||
let mint_amount = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let accum_vault = Vortex::<T>::get_vault_account_accum().unwrap(); | ||
assert_eq!(T::MultiCurrency::balance(asset_id, &accum_vault), mint_amount); | ||
assert_eq!(T::MultiCurrency::balance(T::NativeAssetId::get(), &accum_vault), mint_amount); | ||
} | ||
|
||
// calc_staker_reward_points { | ||
// let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
// let root_price = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
// let vortex_price = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
// let root_vault = account::<T>("root_vault"); | ||
// let fee_vault = account::<T>("fee_vault"); | ||
// let validator_stash = account::<T>("validator"); | ||
// let amount = 100u32.into(); | ||
// let asset_id = mint_asset::<T>(&fee_vault, &root_vault); | ||
// assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
// let balance = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
// let asset_prices = vec![(asset_id, balance.into())]; | ||
// assert_ok!(VortexDistribution::<T>::set_asset_prices(RawOrigin::Root.into(), asset_prices, vortex_dist_id)); | ||
// }: _(RawOrigin::Root, validator_stash, vortex_dist_id) | ||
|
||
redeem_tokens_from_vault { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let root_price = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let vortex_price = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let root_vault = account::<T>("root_vault"); | ||
let fee_vault = account::<T>("fee_vault"); | ||
let amount = 2u32.into(); | ||
let asset_id = mint_asset::<T>(&fee_vault, &root_vault); | ||
assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
let balance = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let asset_prices = BoundedVec::try_from(vec![(asset_id, balance.into())]).unwrap(); | ||
let end_block: u32 = 500; | ||
assert_ok!(VortexDistribution::<T>::set_asset_prices(RawOrigin::Root.into(), asset_prices, vortex_dist_id)); | ||
let rewards = BoundedVec::try_from(vec![(account::<T>("test"), 2u32.into())]).unwrap(); | ||
assert_ok!(VortexDistribution::<T>::register_rewards(RawOrigin::Root.into(), vortex_dist_id, rewards)); | ||
assert_ok!(VortexDistribution::<T>::trigger_vtx_distribution(RawOrigin::Root.into(), root_price, vortex_price, root_vault, fee_vault, vortex_dist_id)); | ||
assert_ok!(VortexDistribution::<T>::start_vtx_dist(RawOrigin::Root.into(), vortex_dist_id)); | ||
System::<T>::set_block_number(end_block.into()); | ||
assert_ok!(VortexDistribution::<T>::pay_unsigned(RawOrigin::None.into(), vortex_dist_id, end_block.into())); | ||
}: _(RawOrigin::Signed(account::<T>("test")), vortex_dist_id, balance) | ||
verify { | ||
assert_eq!(T::MultiCurrency::balance(T::VtxAssetId::get(), &account::<T>("test")), balance); | ||
|
||
let ratio = Perbill::from_rational(balance, amount * 2u32.into()); | ||
let mint_amount = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let expect_balance = ratio * mint_amount; | ||
assert_eq!(T::MultiCurrency::balance(asset_id, &account::<T>("test")), expect_balance); | ||
assert_eq!(T::MultiCurrency::balance(T::NativeAssetId::get(), &account::<T>("test")), expect_balance); | ||
} | ||
|
||
pay_unsigned { | ||
let vortex_dist_id = T::VtxDistIdentifier::default(); | ||
let root_price = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let vortex_price = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let root_vault = account::<T>("root_vault"); | ||
let fee_vault = account::<T>("fee_vault"); | ||
let amount = 2u32.into(); | ||
let asset_id = mint_asset::<T>(&fee_vault, &root_vault); | ||
assert_ok!(VortexDistribution::<T>::create_vtx_dist(RawOrigin::Root.into(), vortex_dist_id, amount)); | ||
let balance = <T as pallet_staking::Config>::CurrencyBalance::one(); | ||
let asset_prices = BoundedVec::try_from(vec![(asset_id, balance.into())]).unwrap(); | ||
let end_block: u32 = 500; | ||
assert_ok!(VortexDistribution::<T>::set_asset_prices(RawOrigin::Root.into(), asset_prices, vortex_dist_id)); | ||
let rewards = BoundedVec::try_from(vec![(account::<T>("test"), 2u32.into())]).unwrap(); | ||
assert_ok!(VortexDistribution::<T>::register_rewards(RawOrigin::Root.into(), vortex_dist_id, rewards)); | ||
assert_ok!(VortexDistribution::<T>::trigger_vtx_distribution(RawOrigin::Root.into(), root_price, vortex_price, root_vault, fee_vault, vortex_dist_id)); | ||
assert_ok!(VortexDistribution::<T>::start_vtx_dist(RawOrigin::Root.into(), vortex_dist_id)); | ||
System::<T>::set_block_number(end_block.into()); | ||
// assert_ok!(VortexDistribution::<T>::pay_unsigned(RawOrigin::None.into(), vortex_dist_id, end_block.into())); | ||
}: _(RawOrigin::None, vortex_dist_id, end_block.into()) | ||
verify { | ||
assert_eq!(T::MultiCurrency::balance(T::VtxAssetId::get(), &account::<T>("test")), 2u32.into()); | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!(VortexDistribution, crate::mock::new_test_ext(), crate::mock::Test,); |
Oops, something went wrong.