Skip to content

Commit

Permalink
1196 orml vesting functionality (#1208)
Browse files Browse the repository at this point in the history
* add orml vesting functionality

* implement it for multicurrencies

* use enum for implementing new VestingSchedulesVariant in future

* add tests

* add benchmarks
  • Loading branch information
ZlayaMorda authored Sep 30, 2024
1 parent d3eb7aa commit 250a13a
Show file tree
Hide file tree
Showing 17 changed files with 1,512 additions and 112 deletions.
28 changes: 27 additions & 1 deletion common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ macro_rules! mock_technical_config {
#[macro_export]
macro_rules! mock_tokens_config {
($runtime:ty) => {
parameter_types! {
pub const MaxLocks: u32 = 1;
}
impl tokens::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
Expand All @@ -367,7 +370,7 @@ macro_rules! mock_tokens_config {
type WeightInfo = ();
type ExistentialDeposits = ExistentialDeposits;
type CurrencyHooks = ();
type MaxLocks = ();
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = ();
type DustRemovalWhitelist = Everything;
Expand All @@ -390,3 +393,26 @@ macro_rules! mock_pallet_timestamp_config {
}
};
}

/// Mock of pallet `vested-rewards::Config`
#[macro_export]
macro_rules! mock_vested_rewards_config {
($runtime:ty) => {
parameter_types! {
pub const MaxVestingSchedules: u32 = 0;
pub const MinVestedTransfer: Balance = 0;
}
impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = 14400;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
type MaxVestingSchedules = MaxVestingSchedules;
type Currency = Tokens;
type MinVestedTransfer = MinVestedTransfer;
}
};
}
12 changes: 2 additions & 10 deletions pallets/apollo-platform/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use common::mock_vested_rewards_config;
use {
crate as apollo_platform,
common::{
Expand Down Expand Up @@ -96,6 +97,7 @@ mock_technical_config!(Runtime, pool_xyk::PolySwapAction<DEXId, AssetId, Account
mock_common_config!(Runtime);
mock_tokens_config!(Runtime);
mock_assets_config!(Runtime);
mock_vested_rewards_config!(Runtime);

impl<LocalCall> SendTransactionTypes<LocalCall> for Runtime
where
Expand Down Expand Up @@ -192,16 +194,6 @@ impl dex_api::Config for Runtime {
type WeightInfo = ();
}

impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = 14400;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
}

impl trading_pair::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
Expand Down
16 changes: 4 additions & 12 deletions pallets/ceres-launchpad/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ pub use common::TechPurpose::*;
use common::{
balance, fixed, hash, mock_assets_config, mock_common_config, mock_currencies_config,
mock_frame_system_config, mock_pallet_balances_config, mock_technical_config,
mock_tokens_config, AssetName, AssetSymbol, BalancePrecision, ContentSource, DEXId, DEXInfo,
Description, Fixed, CERES_ASSET_ID, PSWAP, TBCD, XOR, XST, XSTUSD,
mock_tokens_config, mock_vested_rewards_config, AssetName, AssetSymbol, BalancePrecision,
ContentSource, DEXId, DEXInfo, Description, Fixed, CERES_ASSET_ID, PSWAP, TBCD, XOR, XST,
XSTUSD,
};
use currencies::BasicCurrencyAdapter;
use frame_support::traits::{Everything, GenesisBuild, Hooks};
Expand Down Expand Up @@ -74,6 +75,7 @@ mock_frame_system_config!(Runtime);
mock_common_config!(Runtime);
mock_tokens_config!(Runtime);
mock_assets_config!(Runtime);
mock_vested_rewards_config!(Runtime);

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand Down Expand Up @@ -176,16 +178,6 @@ impl multicollateral_bonding_curve_pool::Config for Runtime {
type WeightInfo = ();
}

impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = 14400;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
}

parameter_types! {
pub const CeresAssetId: AssetId = CERES_ASSET_ID;
}
Expand Down
15 changes: 3 additions & 12 deletions pallets/demeter-farming-platform/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub use common::TechAssetId as Tas;
use common::{
balance, fixed, hash, mock_assets_config, mock_common_config, mock_currencies_config,
mock_frame_system_config, mock_pallet_balances_config, mock_technical_config,
mock_tokens_config, DEXId, DEXInfo, Fixed, CERES_ASSET_ID, DEMETER_ASSET_ID, PSWAP, TBCD, XOR,
XST,
mock_tokens_config, mock_vested_rewards_config, DEXId, DEXInfo, Fixed, CERES_ASSET_ID,
DEMETER_ASSET_ID, PSWAP, TBCD, XOR, XST,
};
use currencies::BasicCurrencyAdapter;
use frame_support::traits::{Everything, GenesisBuild};
Expand Down Expand Up @@ -69,6 +69,7 @@ mock_frame_system_config!(Runtime);
mock_common_config!(Runtime);
mock_tokens_config!(Runtime);
mock_assets_config!(Runtime);
mock_vested_rewards_config!(Runtime);

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand Down Expand Up @@ -189,16 +190,6 @@ impl multicollateral_bonding_curve_pool::Config for Runtime {
type WeightInfo = ();
}

impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = 14400;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
}

impl pswap_distribution::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
const PSWAP_BURN_PERCENT: Percent = Percent::from_percent(3);
Expand Down
15 changes: 3 additions & 12 deletions pallets/demeter-farming-platform/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub use common::TechAssetId as Tas;
use common::{
balance, fixed, hash, mock_assets_config, mock_common_config, mock_currencies_config,
mock_frame_system_config, mock_pallet_balances_config, mock_technical_config,
mock_tokens_config, DEXId, DEXInfo, Fixed, CERES_ASSET_ID, DEMETER_ASSET_ID, PSWAP, TBCD, XOR,
XST, XSTUSD,
mock_tokens_config, mock_vested_rewards_config, DEXId, DEXInfo, Fixed, CERES_ASSET_ID,
DEMETER_ASSET_ID, PSWAP, TBCD, XOR, XST, XSTUSD,
};
use currencies::BasicCurrencyAdapter;
use frame_support::traits::{Everything, GenesisBuild, Hooks};
Expand Down Expand Up @@ -67,6 +67,7 @@ mock_frame_system_config!(Runtime);
mock_common_config!(Runtime);
mock_tokens_config!(Runtime);
mock_assets_config!(Runtime);
mock_vested_rewards_config!(Runtime);

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand Down Expand Up @@ -184,16 +185,6 @@ impl multicollateral_bonding_curve_pool::Config for Runtime {
type WeightInfo = ();
}

impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = 14400;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
}

impl pswap_distribution::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
const PSWAP_BURN_PERCENT: Percent = Percent::from_percent(3);
Expand Down
15 changes: 3 additions & 12 deletions pallets/farming/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use common::prelude::Balance;
use common::{
balance, fixed, hash, mock_assets_config, mock_common_config, mock_currencies_config,
mock_frame_system_config, mock_pallet_balances_config, mock_technical_config,
mock_tokens_config, AssetName, AssetSymbol, DEXId, DEXInfo, Fixed, DEFAULT_BALANCE_PRECISION,
DOT, PSWAP, TBCD, VAL, XOR, XST, XSTUSD,
mock_tokens_config, mock_vested_rewards_config, AssetName, AssetSymbol, DEXId, DEXInfo, Fixed,
DEFAULT_BALANCE_PRECISION, DOT, PSWAP, TBCD, VAL, XOR, XST, XSTUSD,
};
use currencies::BasicCurrencyAdapter;
use frame_support::traits::{Everything, GenesisBuild, OnFinalize, OnInitialize, PrivilegeCmp};
Expand Down Expand Up @@ -162,6 +162,7 @@ mock_frame_system_config!(Runtime);
mock_common_config!(Runtime);
mock_tokens_config!(Runtime);
mock_assets_config!(Runtime);
mock_vested_rewards_config!(Runtime);

impl permissions::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -255,16 +256,6 @@ impl multicollateral_bonding_curve_pool::Config for Runtime {
type WeightInfo = ();
}

impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = BLOCKS_PER_DAY;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
}

/// Used the compare the privilege of an origin inside the scheduler.
pub struct OriginPrivilegeCmp;

Expand Down
20 changes: 6 additions & 14 deletions pallets/liquidity-proxy/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ use common::prelude::{Balance, QuoteAmount};
use common::{
balance, fixed, fixed_from_basis_points, hash, mock_assets_config, mock_common_config,
mock_currencies_config, mock_frame_system_config, mock_pallet_balances_config,
mock_technical_config, mock_tokens_config, Amount, AssetId32, AssetName, AssetSymbol,
BalancePrecision, ContentSource, DEXId, DEXInfo, Description, Fixed, FromGenericPair,
LiquidityProxyTrait, LiquiditySourceFilter, LiquiditySourceType, PriceToolsProvider,
PriceVariant, TechPurpose, DEFAULT_BALANCE_PRECISION, DOT, PSWAP, TBCD, USDT, VAL, XOR, XST,
mock_technical_config, mock_tokens_config, mock_vested_rewards_config, Amount, AssetId32,
AssetName, AssetSymbol, BalancePrecision, ContentSource, DEXId, DEXInfo, Description, Fixed,
FromGenericPair, LiquidityProxyTrait, LiquiditySourceFilter, LiquiditySourceType,
PriceToolsProvider, PriceVariant, TechPurpose, DEFAULT_BALANCE_PRECISION, DOT, PSWAP, TBCD,
USDT, VAL, XOR, XST,
};
use currencies::BasicCurrencyAdapter;
use hex_literal::hex;
Expand Down Expand Up @@ -144,6 +145,7 @@ mock_frame_system_config!(Runtime);
mock_common_config!(Runtime);
mock_tokens_config!(Runtime);
mock_assets_config!(Runtime);
mock_vested_rewards_config!(Runtime);

impl liquidity_proxy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -271,16 +273,6 @@ impl pool_xyk::Config for Runtime {
type WeightInfo = ();
}

impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = 14400;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
}

impl pallet_timestamp::Config for Runtime {
type Moment = u64;
type OnTimestampSet = ();
Expand Down
19 changes: 5 additions & 14 deletions pallets/liquidity-proxy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ use common::mock::{ExistentialDeposits, GetTradingPairRestrictedFlag};
use common::{
self, balance, fixed, fixed_from_basis_points, fixed_wrapper, hash, mock_assets_config,
mock_common_config, mock_currencies_config, mock_frame_system_config,
mock_pallet_balances_config, mock_technical_config, mock_tokens_config, Amount, AssetId32,
AssetName, AssetSymbol, DEXInfo, Fixed, FromGenericPair, GetMarketInfo, LiquiditySource,
LiquiditySourceType, RewardReason, DAI, DEFAULT_BALANCE_PRECISION, DOT, ETH, KSM, PSWAP, TBCD,
USDT, VAL, XOR, XST, XSTUSD,
mock_pallet_balances_config, mock_technical_config, mock_tokens_config,
mock_vested_rewards_config, Amount, AssetId32, AssetName, AssetSymbol, DEXInfo, Fixed,
FromGenericPair, GetMarketInfo, LiquiditySource, LiquiditySourceType, RewardReason, DAI,
DEFAULT_BALANCE_PRECISION, DOT, ETH, KSM, PSWAP, TBCD, USDT, VAL, XOR, XST, XSTUSD,
};
use currencies::BasicCurrencyAdapter;

Expand Down Expand Up @@ -175,6 +175,7 @@ mock_frame_system_config!(Runtime);
mock_common_config!(Runtime);
mock_tokens_config!(Runtime);
mock_assets_config!(Runtime);
mock_vested_rewards_config!(Runtime);

impl Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -359,16 +360,6 @@ impl multicollateral_bonding_curve_pool::Config for Runtime {
type WeightInfo = ();
}

impl vested_rewards::Config for Runtime {
const BLOCKS_PER_DAY: BlockNumberFor<Self> = 14400;
type RuntimeEvent = RuntimeEvent;
type GetMarketMakerRewardsAccountId = GetMarketMakerRewardsAccountId;
type GetBondingCurveRewardsAccountId = GetBondingCurveRewardsAccountId;
type GetFarmingRewardsAccountId = GetFarmingRewardsAccountId;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
}

pub struct ExtBuilder {
pub total_supply: Balance,
pub xyk_reserves: Vec<(DEXId, AssetId, (Balance, Balance))>,
Expand Down
2 changes: 2 additions & 0 deletions pallets/vested-rewards/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ runtime-benchmarks = [
private-net = []

try-runtime = ["frame-support/try-runtime"]

wip = []
Loading

0 comments on commit 250a13a

Please sign in to comment.