From d0e6454f95f8e4897e495e9f4011c516a6cfd889 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Tue, 21 Jun 2022 21:00:47 +1200 Subject: [PATCH] Liquidation penalty now goes to OnFeeDeposit, and the same amount of debit is added to the Treasury. When liquidation is complete, the debit should be fully paid off. Updated tests accordingly. --- modules/cdp-engine/src/lib.rs | 8 +- modules/cdp-engine/src/tests.rs | 89 +++++++++++++++++-- modules/fees/src/lib.rs | 14 +-- modules/fees/src/mock.rs | 2 + modules/fees/src/tests.rs | 63 ++++++++++++- modules/homa/src/tests.rs | 2 +- primitives/src/lib.rs | 17 ++-- runtime/integration-tests/src/honzon.rs | 20 +++-- .../mandala/src/benchmarking/cdp_engine.rs | 21 ++++- runtime/mandala/src/benchmarking/fees.rs | 3 +- 10 files changed, 203 insertions(+), 36 deletions(-) diff --git a/modules/cdp-engine/src/lib.rs b/modules/cdp-engine/src/lib.rs index 14f9e09e16..5d7f302c37 100644 --- a/modules/cdp-engine/src/lib.rs +++ b/modules/cdp-engine/src/lib.rs @@ -1155,6 +1155,13 @@ impl Pallet { let liquidation_penalty = Self::get_liquidation_penalty(currency_id)?; let target_stable_amount = liquidation_penalty.saturating_mul_acc_int(bad_debt_value); + let debt_penalty = liquidation_penalty.saturating_mul_int(bad_debt_value); + let stable_currency_id = T::GetStableCurrencyId::get(); + + // Deposit penalty to OnFeeDeposit and add the debt to the treasury. + T::OnFeeDeposit::on_fee_deposit(IncomeSource::HonzonLiquidationFee, stable_currency_id, debt_penalty)?; + ::CDPTreasury::on_system_debit(debt_penalty)?; + match currency_id { CurrencyId::DexShare(dex_share_0, dex_share_1) => { let token_0: CurrencyId = dex_share_0.into(); @@ -1165,7 +1172,6 @@ impl Pallet { ::CDPTreasury::remove_liquidity_for_lp_collateral(currency_id, collateral)?; // if these's stable - let stable_currency_id = T::GetStableCurrencyId::get(); if token_0 == stable_currency_id || token_1 == stable_currency_id { let (existing_stable, need_handle_currency, handle_amount) = if token_0 == stable_currency_id { (amount_0, token_1, amount_1) diff --git a/modules/cdp-engine/src/tests.rs b/modules/cdp-engine/src/tests.rs index cc2d3d5f6f..2e4972c67c 100644 --- a/modules/cdp-engine/src/tests.rs +++ b/modules/cdp-engine/src/tests.rs @@ -23,8 +23,8 @@ use super::*; use frame_support::{assert_noop, assert_ok}; use mock::{Call as MockCall, Event, *}; -use module_fees::PoolPercent; use orml_traits::MultiCurrency; +use primitives::PoolPercent; use sp_core::offchain::{testing, OffchainDbExt, OffchainWorkerExt, TransactionPoolExt}; use sp_io::offchain; use sp_runtime::{ @@ -68,6 +68,14 @@ fn setup_fees_distribution() { rate: Rate::one(), }], )); + assert_ok!(Fees::set_income_fee( + Origin::root(), + IncomeSource::HonzonLiquidationFee, + vec![PoolPercent { + pool: BOB, + rate: Rate::one(), + }], + )); } #[test] @@ -819,6 +827,7 @@ fn remain_debit_value_too_small_check() { #[test] fn liquidate_unsafe_cdp_by_collateral_auction() { ExtBuilder::default().build().execute_with(|| { + setup_fees_distribution(); System::set_block_number(1); assert_ok!(CDPEngineModule::set_collateral_params( Origin::signed(1), @@ -831,6 +840,7 @@ fn liquidate_unsafe_cdp_by_collateral_auction() { )); setup_default_collateral(AUSD); assert_ok!(CDPEngineModule::adjust_position(&ALICE, BTC, 100, 500)); + assert_eq!(Currencies::free_balance(BTC, &ALICE), 900); assert_eq!(Currencies::free_balance(AUSD, &ALICE), 50); assert_eq!(LoansModule::positions(BTC, ALICE).debit, 500); @@ -848,8 +858,10 @@ fn liquidate_unsafe_cdp_by_collateral_auction() { Change::NoChange, Change::NoChange, )); - assert_ok!(CDPEngineModule::liquidate_unsafe_cdp(ALICE, BTC)); + assert_eq!(CDPTreasuryModule::debit_pool(), 0); + assert_eq!(Currencies::free_balance(AUSD, &ALICE), 50); + assert_ok!(CDPEngineModule::liquidate_unsafe_cdp(ALICE, BTC)); System::assert_last_event(Event::CDPEngineModule(crate::Event::LiquidateUnsafeCDP { collateral_type: BTC, owner: ALICE, @@ -857,7 +869,10 @@ fn liquidate_unsafe_cdp_by_collateral_auction() { bad_debt_value: 50, target_amount: 60, })); - assert_eq!(CDPTreasuryModule::debit_pool(), 50); + // 50 debt + 10 penalty + assert_eq!(CDPTreasuryModule::debit_pool(), 60); + assert_eq!(Currencies::free_balance(AUSD, &BOB), 10); + assert_eq!(Currencies::free_balance(BTC, &ALICE), 900); assert_eq!(Currencies::free_balance(AUSD, &ALICE), 50); assert_eq!(LoansModule::positions(BTC, ALICE).debit, 0); @@ -874,6 +889,7 @@ fn liquidate_unsafe_cdp_by_collateral_auction() { #[test] fn liquidate_unsafe_cdp_by_collateral_auction_when_limited_by_slippage() { ExtBuilder::default().build().execute_with(|| { + setup_fees_distribution(); System::set_block_number(1); assert_ok!(CDPEngineModule::set_collateral_params( Origin::signed(1), @@ -932,7 +948,7 @@ fn liquidate_unsafe_cdp_by_collateral_auction_when_limited_by_slippage() { })); assert_eq!(DEXModule::get_liquidity_pool(BTC, AUSD), (100, 121)); - assert_eq!(CDPTreasuryModule::debit_pool(), 50); + assert_eq!(CDPTreasuryModule::debit_pool(), 60); assert_eq!(Currencies::free_balance(BTC, &ALICE), 900); assert_eq!(Currencies::free_balance(AUSD, &ALICE), 50); assert_eq!(LoansModule::positions(BTC, ALICE).debit, 0); @@ -943,6 +959,7 @@ fn liquidate_unsafe_cdp_by_collateral_auction_when_limited_by_slippage() { #[test] fn liquidate_unsafe_cdp_by_swap() { ExtBuilder::default().build().execute_with(|| { + setup_fees_distribution(); System::set_block_number(1); assert_ok!(CDPEngineModule::set_collateral_params( Origin::signed(1), @@ -992,7 +1009,7 @@ fn liquidate_unsafe_cdp_by_swap() { })); assert_eq!(DEXModule::get_liquidity_pool(BTC, AUSD), (199, 61)); - assert_eq!(CDPTreasuryModule::debit_pool(), 50); + assert_eq!(CDPTreasuryModule::debit_pool(), 60); assert_eq!(Currencies::free_balance(BTC, &ALICE), 901); assert_eq!(Currencies::free_balance(AUSD, &ALICE), 50); assert_eq!(LoansModule::positions(BTC, ALICE).debit, 0); @@ -1003,6 +1020,7 @@ fn liquidate_unsafe_cdp_by_swap() { #[test] fn liquidate_unsafe_cdp_of_lp_ausd_dot_and_swap_dot() { ExtBuilder::default().build().execute_with(|| { + setup_fees_distribution(); System::set_block_number(1); assert_ok!(CDPEngineModule::set_collateral_params( Origin::signed(1), @@ -1082,7 +1100,7 @@ fn liquidate_unsafe_cdp_of_lp_ausd_dot_and_swap_dot() { assert_eq!(LoansModule::positions(LP_AUSD_DOT, ALICE).debit, 0); assert_eq!(LoansModule::positions(LP_AUSD_DOT, ALICE).collateral, 0); assert_eq!(Currencies::free_balance(LP_AUSD_DOT, &LoansModule::account_id()), 0); - assert_eq!(CDPTreasuryModule::debit_pool(), 500); + assert_eq!(CDPTreasuryModule::debit_pool(), 600); assert_eq!(Currencies::free_balance(AUSD, &CDPTreasuryModule::account_id()), 600); assert_eq!(Currencies::free_balance(DOT, &CDPTreasuryModule::account_id()), 0); assert_eq!( @@ -1096,6 +1114,7 @@ fn liquidate_unsafe_cdp_of_lp_ausd_dot_and_swap_dot() { #[test] fn liquidate_unsafe_cdp_of_lp_ausd_dot_and_ausd_take_whole_target() { ExtBuilder::default().build().execute_with(|| { + setup_fees_distribution(); System::set_block_number(1); assert_ok!(CDPEngineModule::set_collateral_params( Origin::signed(1), @@ -1175,7 +1194,7 @@ fn liquidate_unsafe_cdp_of_lp_ausd_dot_and_ausd_take_whole_target() { assert_eq!(LoansModule::positions(LP_AUSD_DOT, ALICE).debit, 0); assert_eq!(LoansModule::positions(LP_AUSD_DOT, ALICE).collateral, 0); assert_eq!(Currencies::free_balance(LP_AUSD_DOT, &LoansModule::account_id()), 0); - assert_eq!(CDPTreasuryModule::debit_pool(), 200); + assert_eq!(CDPTreasuryModule::debit_pool(), 240); assert_eq!(Currencies::free_balance(AUSD, &CDPTreasuryModule::account_id()), 240); assert_eq!(Currencies::free_balance(DOT, &CDPTreasuryModule::account_id()), 0); assert_eq!( @@ -1189,6 +1208,7 @@ fn liquidate_unsafe_cdp_of_lp_ausd_dot_and_ausd_take_whole_target() { #[test] fn liquidate_unsafe_cdp_of_lp_ausd_dot_and_create_dot_auction() { ExtBuilder::default().build().execute_with(|| { + setup_fees_distribution(); System::set_block_number(1); assert_ok!(CDPEngineModule::set_collateral_params( Origin::signed(1), @@ -1268,7 +1288,7 @@ fn liquidate_unsafe_cdp_of_lp_ausd_dot_and_create_dot_auction() { assert_eq!(LoansModule::positions(LP_AUSD_DOT, ALICE).debit, 0); assert_eq!(LoansModule::positions(LP_AUSD_DOT, ALICE).collateral, 0); assert_eq!(Currencies::free_balance(LP_AUSD_DOT, &LoansModule::account_id()), 0); - assert_eq!(CDPTreasuryModule::debit_pool(), 500); + assert_eq!(CDPTreasuryModule::debit_pool(), 600); assert_eq!(Currencies::free_balance(AUSD, &CDPTreasuryModule::account_id()), 500); assert_eq!(Currencies::free_balance(DOT, &CDPTreasuryModule::account_id()), 25); assert_eq!( @@ -1644,6 +1664,7 @@ fn offchain_worker_works_cdp() { ext.register_extension(OffchainDbExt::new(offchain)); ext.execute_with(|| { + setup_fees_distribution(); // number of currencies allowed as collateral (cycles through all of them) setup_default_collateral(BTC); setup_default_collateral(LP_AUSD_DOT); @@ -1729,6 +1750,7 @@ fn offchain_worker_iteration_limit_works() { ext.register_extension(OffchainDbExt::new(offchain.clone())); ext.execute_with(|| { + setup_fees_distribution(); System::set_block_number(1); // sets max iterations value to 1 offchain.local_storage_set(StorageKind::PERSISTENT, OFFCHAIN_WORKER_MAX_ITERATIONS, &1u32.encode()); @@ -1950,3 +1972,54 @@ fn accumulated_interest_goes_to_on_fee_deposit() { ); }); } + +#[test] +fn liquidation_fee_goes_to_on_fee_deposit() { + ExtBuilder::default().build().execute_with(|| { + setup_fees_distribution(); + + assert_ok!(CDPEngineModule::set_collateral_params( + Origin::signed(1), + BTC, + Change::NewValue(Some(Rate::zero())), + Change::NewValue(Some(Ratio::saturating_from_rational(2, 1))), + Change::NewValue(Some(Rate::one())), + Change::NewValue(Some(Ratio::saturating_from_rational(2, 1))), + Change::NewValue(10000), + )); + assert_ok!(CDPEngineModule::adjust_position(&ALICE, BTC, 100, 500)); + + // Alice: -100 collateral. +50 from debit + assert_eq!(Currencies::free_balance(BTC, &ALICE), 900); + assert_eq!(Currencies::free_balance(AUSD, &ALICE), 50); + // Bob's initial balance + assert_eq!(Currencies::free_balance(BTC, &BOB), 1000); + assert_eq!(Currencies::free_balance(AUSD, &BOB), 0); + // Treasury had no debt from before + assert_eq!(CDPTreasuryModule::get_debit_pool(), 0); + assert_eq!( + LoansModule::positions(BTC, &ALICE), + Position { + collateral: 100, + debit: 500, + } + ); + MockPriceSource::set_price(BTC, Some(Price::saturating_from_rational(1, 10))); + assert_ok!(CDPEngineModule::liquidate_unsafe_cdp(ALICE, BTC)); + + // Treasury Debit: 50 from confiscation and +50 from penalty + assert_eq!(CDPTreasuryModule::get_debit_pool(), 100); + + assert_eq!(Currencies::free_balance(BTC, &ALICE), 900); + assert_eq!(Currencies::free_balance(AUSD, &ALICE), 50); + assert_eq!( + LoansModule::positions(BTC, &ALICE), + Position { + collateral: 0, + debit: 0, + } + ); + assert_eq!(Currencies::free_balance(BTC, &BOB), 1000); + assert_eq!(Currencies::free_balance(AUSD, &BOB), 50); + }); +} diff --git a/modules/fees/src/lib.rs b/modules/fees/src/lib.rs index 8064f0ab2d..35ec2f3da8 100644 --- a/modules/fees/src/lib.rs +++ b/modules/fees/src/lib.rs @@ -29,7 +29,7 @@ use frame_support::{ }; use frame_system::pallet_prelude::*; use orml_traits::MultiCurrency; -use primitives::{Balance, CurrencyId, IncomeSource}; +use primitives::{Balance, CurrencyId, IncomeSource, PoolPercent}; use sp_runtime::{ traits::{One, Saturating, Zero}, FixedPointNumber, FixedU128, @@ -40,11 +40,8 @@ use support::{DEXManager, OnFeeDeposit, SwapLimit}; mod mock; mod tests; pub mod weights; -pub use weights::WeightInfo; - -#[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; use sp_runtime::traits::UniqueSaturatedInto; +pub use weights::WeightInfo; pub type NegativeImbalanceOf = <::Currency as Currency<::AccountId>>::NegativeImbalance; @@ -55,13 +52,6 @@ pub type Treasuries = Vec<( Vec<(::AccountId, u32)>, )>; -#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct PoolPercent { - pub pool: AccountId, - pub rate: FixedU128, -} - /// helper method to create `PoolPercent` list by tuple. pub fn build_pool_percents(list: Vec<(AccountId, u32)>) -> Vec> { list.iter() diff --git a/modules/fees/src/mock.rs b/modules/fees/src/mock.rs index b6e547e64e..4dba4f353c 100644 --- a/modules/fees/src/mock.rs +++ b/modules/fees/src/mock.rs @@ -38,6 +38,8 @@ use sp_runtime::traits::AccountIdConversion; use support::mocks::MockAddressMapping; pub const ALICE: AccountId = AccountId::new([1u8; 32]); +pub const BOB: AccountId = AccountId::new([2u8; 32]); +pub const CHARLIE: AccountId = AccountId::new([3u8; 32]); pub const AUSD: CurrencyId = CurrencyId::Token(TokenSymbol::AUSD); pub const ACA: CurrencyId = CurrencyId::Token(TokenSymbol::ACA); pub const DOT: CurrencyId = CurrencyId::Token(TokenSymbol::DOT); diff --git a/modules/fees/src/tests.rs b/modules/fees/src/tests.rs index 6833924abb..6693053b1c 100644 --- a/modules/fees/src/tests.rs +++ b/modules/fees/src/tests.rs @@ -25,7 +25,8 @@ use crate::mock::*; use frame_support::traits::{ExistenceRequirement, WithdrawReasons}; use frame_support::{assert_noop, assert_ok}; use mock::{Event, ExtBuilder, Origin, Runtime, System}; -use primitives::AccountId; +use primitives::{AccountId, PoolPercent}; +use support::Rate; #[test] fn set_income_fee_works() { @@ -215,6 +216,19 @@ fn on_fee_deposit_works() { .balances(vec![(ALICE, ACA, 10000), (ALICE, DOT, 10000)]) .build() .execute_with(|| { + assert_ok!(Fees::do_set_treasury_rate( + IncomeSource::TxFee, + vec![ + PoolPercent { + pool: NetworkTreasuryPool::get(), + rate: Rate::saturating_from_rational(8, 10) + }, + PoolPercent { + pool: CollatorsRewardPool::get(), + rate: Rate::saturating_from_rational(2, 10) + }, + ] + )); // Native token tests // FeeToTreasuryPool based on pre-configured treasury pool percentage. assert_ok!(Pallet::::on_fee_deposit(IncomeSource::TxFee, ACA, 10000)); @@ -406,3 +420,50 @@ fn distribution_incentive_threshold_works() { })); }); } + +#[test] +fn independent_pools_on_fee_deposit_works() { + ExtBuilder::default().build().execute_with(|| { + // Register payout destination for multiple pools + assert_ok!(Fees::do_set_treasury_rate( + IncomeSource::TxFee, + vec![PoolPercent { + pool: ALICE, + rate: Rate::one() + },] + )); + assert_ok!(Fees::do_set_treasury_rate( + IncomeSource::XcmFee, + vec![PoolPercent { + pool: BOB, + rate: Rate::one() + },] + )); + assert_ok!(Fees::do_set_treasury_rate( + IncomeSource::HonzonStabilityFee, + vec![PoolPercent { + pool: CHARLIE, + rate: Rate::one() + },] + )); + + assert_ok!(Pallet::::on_fee_deposit(IncomeSource::TxFee, ACA, 1000)); + assert_eq!(Currencies::free_balance(ACA, &ALICE), 1000); + assert_eq!(Currencies::free_balance(ACA, &BOB), 0); + assert_eq!(Currencies::free_balance(ACA, &CHARLIE), 0); + + assert_ok!(Pallet::::on_fee_deposit(IncomeSource::XcmFee, ACA, 1000)); + assert_eq!(Currencies::free_balance(ACA, &ALICE), 1000); + assert_eq!(Currencies::free_balance(ACA, &BOB), 1000); + assert_eq!(Currencies::free_balance(ACA, &CHARLIE), 0); + + assert_ok!(Pallet::::on_fee_deposit( + IncomeSource::HonzonStabilityFee, + ACA, + 1000 + )); + assert_eq!(Currencies::free_balance(ACA, &ALICE), 1000); + assert_eq!(Currencies::free_balance(ACA, &BOB), 1000); + assert_eq!(Currencies::free_balance(ACA, &CHARLIE), 1000); + }); +} diff --git a/modules/homa/src/tests.rs b/modules/homa/src/tests.rs index e2a6c9b1b9..cb47596834 100644 --- a/modules/homa/src/tests.rs +++ b/modules/homa/src/tests.rs @@ -22,8 +22,8 @@ use super::*; use frame_support::{assert_noop, assert_ok}; use mock::{Event, *}; -use module_fees::PoolPercent; use orml_traits::MultiCurrency; +use primitives::PoolPercent; use sp_runtime::{traits::BadOrigin, FixedPointNumber}; fn setup_fees_distribution() { diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 240371fb9e..bc07a43323 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -192,6 +192,13 @@ pub enum ReserveIdentifier { Count, } +pub type CashYieldIndex = u128; + +/// Convert any type that implements Into into byte representation ([u8, 32]) +pub fn to_bytes>(value: T) -> [u8; 32] { + Into::<[u8; 32]>::into(value.into()) +} + #[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, MaxEncodedLen, TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum IncomeSource { @@ -203,9 +210,9 @@ pub enum IncomeSource { HomaStakingRewardFee, } -pub type CashYieldIndex = u128; - -/// Convert any type that implements Into into byte representation ([u8, 32]) -pub fn to_bytes>(value: T) -> [u8; 32] { - Into::<[u8; 32]>::into(value.into()) +#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +pub struct PoolPercent { + pub pool: AccountId, + pub rate: FixedU128, } diff --git a/runtime/integration-tests/src/honzon.rs b/runtime/integration-tests/src/honzon.rs index 8a6a1e9021..37a0b97023 100644 --- a/runtime/integration-tests/src/honzon.rs +++ b/runtime/integration-tests/src/honzon.rs @@ -17,8 +17,7 @@ // along with this program. If not, see . use crate::setup::*; -use module_fees::PoolPercent; -use primitives::IncomeSource; +use primitives::{IncomeSource, PoolPercent}; use sp_runtime::traits::One; fn setup_default_collateral(currency_id: CurrencyId) { @@ -42,6 +41,14 @@ fn setup_fees_distribution() { rate: Rate::one(), }], )); + assert_ok!(Fees::set_income_fee( + Origin::root(), + IncomeSource::HonzonLiquidationFee, + vec![PoolPercent { + pool: CdpTreasury::account_id(), + rate: Rate::one(), + }], + )); } #[test] @@ -143,6 +150,7 @@ fn liquidate_cdp() { .build() .execute_with(|| { set_oracle_price(vec![(RELAY_CHAIN_CURRENCY, Price::saturating_from_rational(10000, 1))]); // 10000 usd + setup_fees_distribution(); assert_ok!(Dex::add_liquidity( Origin::signed(AccountId::from(BOB)), @@ -229,7 +237,8 @@ fn liquidate_cdp() { 0 ); assert!(AuctionManager::collateral_auctions(0).is_some()); - assert_eq!(CdpTreasury::debit_pool(), 250_000 * dollar(USD_CURRENCY)); + // 250_000 debit + (20%) 50_000 penalty + assert_eq!(CdpTreasury::debit_pool(), 300_000 * dollar(USD_CURRENCY)); assert_ok!(CdpEngine::liquidate_unsafe_cdp( AccountId::from(BOB), @@ -254,7 +263,8 @@ fn liquidate_cdp() { Loans::positions(RELAY_CHAIN_CURRENCY, AccountId::from(BOB)).collateral, 0 ); - assert_eq!(CdpTreasury::debit_pool(), 255_000 * dollar(USD_CURRENCY)); + // 300_000 + 5000 debit + (20%) 1000 penalty + assert_eq!(CdpTreasury::debit_pool(), 306_000 * dollar(USD_CURRENCY)); assert!(CdpTreasury::surplus_pool() >= 5_000 * dollar(USD_CURRENCY)); }); } @@ -270,7 +280,7 @@ fn test_honzon_module() { .build() .execute_with(|| { set_oracle_price(vec![(RELAY_CHAIN_CURRENCY, Price::saturating_from_rational(1, 1))]); - + setup_fees_distribution(); assert_ok!(CdpEngine::set_collateral_params( Origin::root(), RELAY_CHAIN_CURRENCY, diff --git a/runtime/mandala/src/benchmarking/cdp_engine.rs b/runtime/mandala/src/benchmarking/cdp_engine.rs index 6c4559a6b7..48e174b4ea 100644 --- a/runtime/mandala/src/benchmarking/cdp_engine.rs +++ b/runtime/mandala/src/benchmarking/cdp_engine.rs @@ -18,7 +18,7 @@ use crate::{ AccountId, Address, Amount, Balance, CdpEngine, CdpTreasury, CurrencyId, DefaultDebitExchangeRate, Dex, - EmergencyShutdown, ExistentialDeposits, GetLiquidCurrencyId, GetNativeCurrencyId, GetStableCurrencyId, + EmergencyShutdown, ExistentialDeposits, Fees, GetLiquidCurrencyId, GetNativeCurrencyId, GetStableCurrencyId, GetStakingCurrencyId, MinimumDebitValue, NativeTokenExistentialDeposit, Price, Rate, Ratio, Runtime, Timestamp, MILLISECS_PER_BLOCK, }; @@ -33,6 +33,7 @@ use frame_system::RawOrigin; use module_support::DEXManager; use orml_benchmarking::runtime_benchmarks; use orml_traits::{Change, GetByKey}; +use primitives::{IncomeSource, PoolPercent}; use sp_runtime::{ traits::{AccountIdLookup, One, StaticLookup, UniqueSaturatedInto}, FixedPointNumber, @@ -156,6 +157,15 @@ runtime_benchmarks! { let collateral_value = 2 * min_debit_value; let collateral_amount = Price::saturating_from_rational(dollar(STAKING), dollar(STABLECOIN)).saturating_mul_int(collateral_value); + let _ = Fees::set_income_fee( + RawOrigin::Root.into(), + IncomeSource::HonzonLiquidationFee, + vec![PoolPercent { + pool: owner.clone(), + rate: Rate::one(), + }], + ); + // set balance set_balance(STAKING, &owner, collateral_amount + ExistentialDeposits::get(&STAKING)); @@ -204,6 +214,15 @@ runtime_benchmarks! { let collateral_amount = Price::saturating_from_rational(dollar(LIQUID), dollar(STABLECOIN)).saturating_mul_int(collateral_value); let collateral_price = Price::one(); // 1 USD + let _ = Fees::set_income_fee( + RawOrigin::Root.into(), + IncomeSource::HonzonLiquidationFee, + vec![PoolPercent { + pool: owner.clone(), + rate: Rate::one(), + }], + ); + set_balance(LIQUID, &owner, (10 * collateral_amount) + ExistentialDeposits::get(&LIQUID)); inject_liquidity(funder.clone(), LIQUID, STAKING, 10_000 * dollar(LIQUID), 10_000 * dollar(STAKING))?; inject_liquidity(funder, STAKING, STABLECOIN, 10_000 * dollar(STAKING), 10_000 * dollar(STABLECOIN))?; diff --git a/runtime/mandala/src/benchmarking/fees.rs b/runtime/mandala/src/benchmarking/fees.rs index b98491dd83..a2c6f48018 100644 --- a/runtime/mandala/src/benchmarking/fees.rs +++ b/runtime/mandala/src/benchmarking/fees.rs @@ -18,10 +18,9 @@ use crate::{Event, Fees, GetNativeCurrencyId, Origin, Runtime, System}; use frame_system::RawOrigin; -use module_fees::PoolPercent; use module_support::OnFeeDeposit; use orml_benchmarking::runtime_benchmarks; -use primitives::{AccountId, Balance, CurrencyId, IncomeSource}; +use primitives::{AccountId, Balance, CurrencyId, IncomeSource, PoolPercent}; use sp_runtime::{FixedPointNumber, FixedU128}; use sp_std::prelude::*;