diff --git a/modules/transaction-payment/src/mock.rs b/modules/transaction-payment/src/mock.rs index ff95f31a31..633ddf8801 100644 --- a/modules/transaction-payment/src/mock.rs +++ b/modules/transaction-payment/src/mock.rs @@ -234,7 +234,7 @@ impl PriceProvider for MockPriceSource { parameter_types! { // DO NOT CHANGE THIS VALUE, AS IT EFFECT THE TESTCASES. pub const FeePoolSize: Balance = 10_000; - pub const SwapBalanceThreshold: Balance = 20; + pub const SwapThreshold: Balance = 20; pub const TransactionPaymentPalletId: PalletId = PalletId(*b"aca/fees"); pub const TreasuryPalletId: PalletId = PalletId(*b"aca/trsy"); pub KaruraTreasuryAccount: AccountId = TreasuryPalletId::get().into_account(); @@ -304,21 +304,6 @@ construct_runtime!( } ); -pub struct MockTransactionPaymentUpgrade; - -impl frame_support::traits::OnRuntimeUpgrade for MockTransactionPaymentUpgrade { - fn on_runtime_upgrade() -> Weight { - for asset in FeePoolExchangeTokens::get() { - let _ = >::initialize_pool( - asset, - FeePoolSize::get(), - SwapBalanceThreshold::get(), - ); - } - 0 - } -} - pub struct ExtBuilder { balances: Vec<(AccountId, CurrencyId, Balance)>, base_weight: u64, diff --git a/modules/transaction-payment/src/tests.rs b/modules/transaction-payment/src/tests.rs index d1afd1e02d..410a1f3a52 100644 --- a/modules/transaction-payment/src/tests.rs +++ b/modules/transaction-payment/src/tests.rs @@ -21,8 +21,6 @@ #![cfg(test)] use super::*; -use crate::mock::MockTransactionPaymentUpgrade; -use frame_support::traits::OnRuntimeUpgrade; use frame_support::{ assert_noop, assert_ok, parameter_types, weights::{DispatchClass, DispatchInfo, Pays}, @@ -118,7 +116,10 @@ fn do_runtime_upgrade_and_init_balance() { false )); - MockTransactionPaymentUpgrade::on_runtime_upgrade(); + for asset in crate::mock::FeePoolExchangeTokens::get() { + let _ = Pallet::::initialize_pool(asset, FeePoolSize::get(), crate::mock::SwapThreshold::get()); + } + // MockTransactionPaymentUpgrade::on_runtime_upgrade(); vec![AUSD, DOT].iter().for_each(|token| { let ed = (>::minimum_balance(token.clone())).unique_saturated_into(); diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index ac642c964b..5f8a898b5a 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1099,13 +1099,6 @@ impl module_transaction_pause::Config for Runtime { parameter_types! { // Sort by fee charge order pub DefaultFeeSwapPathList: Vec> = vec![vec![AUSD, DOT, ACA], vec![DOT, ACA], vec![LDOT, DOT, ACA]]; - // Initial fee pool size. one extrinsic=0.0025 ACA, one block=100 extrinsics. - // 20 blocks trigger an swap, so total balance=0.0025*100*20=5 ACA - pub FeePoolSize: Balance = 5 * dollar(ACA); - // one extrinsic fee=0.0025ACA, one block=100 extrinsics, threshold=0.25+0.1=0.35ACA - pub SwapBalanceThreshold: Balance = Ratio::saturating_from_rational(35, 100).saturating_mul_int(dollar(ACA)); - // tokens used as fee charge. the token should have corresponding dex swap pool enabled. - pub FeePoolExchangeTokens: Vec = vec![AUSD, DOT]; } type NegativeImbalance = >::NegativeImbalance; @@ -1878,33 +1871,8 @@ pub type SignedPayload = generic::SignedPayload; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Executive: handles dispatch to the various modules. -pub type Executive = frame_executive::Executive< - Runtime, - Block, - frame_system::ChainContext, - Runtime, - AllPallets, - TransactionPaymentUpgrade, ->; - -pub struct TransactionPaymentUpgrade; -impl frame_support::traits::OnRuntimeUpgrade for TransactionPaymentUpgrade { - fn on_runtime_upgrade() -> Weight { - let initial_rates = FeePoolExchangeTokens::get(); - if initial_rates.is_empty() { - 0 - } else { - for asset in initial_rates { - let _ = >::initialize_pool( - asset, - FeePoolSize::get(), - SwapBalanceThreshold::get(), - ); - } - ::BlockWeights::get().max_block - } - } -} +pub type Executive = + frame_executive::Executive, Runtime, AllPallets, ()>; #[cfg(not(feature = "disable-runtime-api"))] impl_runtime_apis! { diff --git a/runtime/integration-tests/src/payment.rs b/runtime/integration-tests/src/payment.rs index 749f7cee02..a29f4a51cd 100644 --- a/runtime/integration-tests/src/payment.rs +++ b/runtime/integration-tests/src/payment.rs @@ -17,11 +17,9 @@ // along with this program. If not, see . use crate::setup::*; -use frame_support::traits::OnRuntimeUpgrade; use frame_support::weights::{DispatchClass, DispatchInfo, Pays, Weight}; use karura_runtime::{ - FeePoolSize, KarPerSecondAsBased, KaruraTreasuryAccount, KsmPerSecond, NativeTokenExistentialDeposit, - TransactionPaymentPalletId, + KarPerSecondAsBased, KaruraTreasuryAccount, KsmPerSecond, NativeTokenExistentialDeposit, TransactionPaymentPalletId, }; use module_transaction_payment::TransactionFeePoolTrader; use sp_runtime::traits::SignedExtension; @@ -32,9 +30,20 @@ use sp_runtime::{ use xcm_builder::FixedRateOfFungible; use xcm_executor::{traits::*, Assets, Config}; +#[cfg(feature = "with-karura-runtime")] +fn init_charge_fee_pool() { + for asset in InitialTokenFeePool::get() { + let _ = >::initialize_pool( + asset.0, + asset.1, + SwapBalanceThreshold::get(), + ); + } +} + #[cfg(feature = "with-karura-runtime")] #[test] -fn runtime_upgrade_initial_pool_works() { +fn initial_charge_fee_pool_works() { ExtBuilder::default() .balances(vec![ (AccountId::from(ALICE), KAR, 100000 * dollar(KAR)), @@ -50,7 +59,7 @@ fn runtime_upgrade_initial_pool_works() { let pool_size = FeePoolSize::get(); // upgrade takes no effect - MockRuntimeUpgrade::on_runtime_upgrade(); + init_charge_fee_pool(); assert_eq!(Currencies::free_balance(KAR, &treasury_account), ed); assert_eq!(Currencies::free_balance(KAR, &fee_account1), 0); @@ -92,7 +101,7 @@ fn runtime_upgrade_initial_pool_works() { 0, false )); - MockRuntimeUpgrade::on_runtime_upgrade(); + init_charge_fee_pool(); assert_eq!(Currencies::free_balance(KAR, &treasury_account), ed + pool_size); vec![KSM, KUSD].iter().for_each(|token| { let ed = @@ -209,7 +218,7 @@ fn trader_works() { 0, false )); - MockRuntimeUpgrade::on_runtime_upgrade(); + init_charge_fee_pool(); assert_eq!(Currencies::free_balance(KAR, &treasury_account), ed); assert_eq!(Currencies::free_balance(KAR, &fee_account1), pool_size); assert_eq!(Currencies::free_balance(KSM, &fee_account1), ksm_ed); @@ -272,7 +281,7 @@ fn charge_transaction_payment_and_threshold_works() { 0, false )); - MockRuntimeUpgrade::on_runtime_upgrade(); + init_charge_fee_pool(); assert_eq!(Currencies::free_balance(KAR, &treasury_account), native_ed); assert_eq!(Currencies::free_balance(KAR, &sub_account1), pool_size); assert_eq!(Currencies::free_balance(KSM, &sub_account1), ksm_ed); @@ -368,8 +377,8 @@ fn charge_transaction_payment_and_threshold_works() { let kar1 = Currencies::free_balance(KAR, &sub_account1); let ksm1 = Currencies::free_balance(KSM, &sub_account1); assert_eq!(ksm_ed + ksm_exchange_rate.saturating_mul_int(fee), ksm1); - assert_eq!(kar1 > kar2, true); - assert_eq!(ksm2 > ksm1, true); + assert!(kar1 > kar2); + assert!(ksm2 > ksm1); // next tx use the new rate to calculate the fee to be transfer. let new_rate: Ratio = module_transaction_payment::Pallet::::token_exchange_rate(KSM).unwrap(); @@ -386,41 +395,3 @@ fn charge_transaction_payment_and_threshold_works() { assert_eq!(new_rate.saturating_mul_int(fee), ksm2 - ksm1); }); } - -#[cfg(feature = "with-acala-runtime")] -#[test] -fn acala_dex_disable_works() { - use acala_runtime::{ - AcalaTreasuryAccount, FeePoolSize, NativeTokenExistentialDeposit, TransactionPaymentPalletId, - TransactionPaymentUpgrade, - }; - - ExtBuilder::default().build().execute_with(|| { - let treasury_account = AcalaTreasuryAccount::get(); - let fee_account1: AccountId = TransactionPaymentPalletId::get().into_sub_account(DOT); - let fee_account2: AccountId = TransactionPaymentPalletId::get().into_sub_account(AUSD); - let ed = NativeTokenExistentialDeposit::get(); - let pool_size = FeePoolSize::get(); - - assert_ok!(Currencies::update_balance( - Origin::root(), - MultiAddress::Id(treasury_account.clone()), - ACA, - pool_size.saturating_mul(3).unique_saturated_into(), - )); - assert_eq!(Currencies::free_balance(ACA, &treasury_account), ed + pool_size * 3); - vec![DOT, AUSD].iter().for_each(|token| { - let ed = (>::minimum_balance(token.clone())).unique_saturated_into(); - assert_ok!(Currencies::update_balance( - Origin::root(), - MultiAddress::Id(treasury_account.clone()), - token.clone(), - ed, - )); - }); - - TransactionPaymentUpgrade::on_runtime_upgrade(); - assert_eq!(Currencies::free_balance(ACA, &fee_account1), 0); - assert_eq!(Currencies::free_balance(ACA, &fee_account2), 0); - }); -} diff --git a/runtime/integration-tests/src/setup.rs b/runtime/integration-tests/src/setup.rs index 9a9923a7f3..d11cac3798 100644 --- a/runtime/integration-tests/src/setup.rs +++ b/runtime/integration-tests/src/setup.rs @@ -72,24 +72,23 @@ mod mandala_imports { pub use karura_imports::*; #[cfg(feature = "with-karura-runtime")] mod karura_imports { - pub use frame_support::parameter_types; - use frame_support::weights::Weight; + pub use frame_support::{parameter_types, weights::Weight}; pub use karura_runtime::{ constants::parachains, create_x2_parachain_multilocation, get_all_module_accounts, AcalaOracle, AccountId, AssetRegistry, AuctionManager, Authority, AuthoritysOriginId, Balance, Balances, BlockNumber, Call, CdpEngine, CdpTreasury, CreateClassDeposit, CreateTokenDeposit, Currencies, CurrencyId, CurrencyIdConvert, DataDepositPerByte, DefaultExchangeRate, Dex, EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, - FeePoolSize, FinancialCouncil, Get, GetNativeCurrencyId, Homa, HomaXcm, Honzon, IdleScheduler, KarPerSecond, + FinancialCouncil, Get, GetNativeCurrencyId, Homa, HomaXcm, Honzon, IdleScheduler, KarPerSecond, KaruraFoundationAccounts, KsmPerSecond, KusamaBondingDuration, KusdPerSecond, Loans, MaxTipsOfPriority, MinimumDebitValue, MultiLocation, NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, OriginCaller, ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, ProxyType, Ratio, - RelayChainBlockNumberProvider, Runtime, Scheduler, Session, SessionManager, SevenDays, SwapBalanceThreshold, - System, Timestamp, TipPerWeightStep, TokenSymbol, Tokens, TreasuryPalletId, Utility, Vesting, XTokens, - XcmConfig, XcmExecutor, EVM, NFT, + RelayChainBlockNumberProvider, Runtime, Scheduler, Session, SessionManager, SevenDays, System, Timestamp, + TipPerWeightStep, TokenSymbol, Tokens, TreasuryPalletId, Utility, Vesting, XTokens, XcmConfig, XcmExecutor, + EVM, NFT, }; pub use primitives::TradingPair; pub use runtime_common::{calculate_asset_ratio, cent, dollar, millicent, KAR, KSM, KUSD, LKSM}; - pub use sp_runtime::traits::AccountIdConversion; + pub use sp_runtime::{traits::AccountIdConversion, FixedPointNumber}; parameter_types! { pub EnabledTradingPairs: Vec = vec![ @@ -111,26 +110,19 @@ mod karura_imports { ); parameter_types! { - pub TokenExchangeRates: Vec<(CurrencyId, Balance)> = vec![ + // Initial fee pool size. one extrinsic=0.0025 KAR, one block=100 extrinsics. + // 20 blocks trigger an swap, so total balance=0.0025*100*20=5 KAR + pub FeePoolSize: Balance = 5 * dollar(KAR); + // one extrinsic fee=0.0025KAR, one block=100 extrinsics, threshold=0.25+0.1=0.35KAR + pub SwapBalanceThreshold: Balance = Ratio::saturating_from_rational(35, 100).saturating_mul_int(dollar(KAR)); + // tokens used as fee charge. the token should have corresponding dex swap pool enabled. + pub InitialTokenFeePool: Vec<(CurrencyId, Balance)> = vec![ (KSM, FeePoolSize::get()), (KUSD, FeePoolSize::get()), + // this one is to simulate not enough native asset so wouldn't take effect (LKSM, NativeTokenExistentialDeposit::get() - 1), ]; } - - pub struct MockRuntimeUpgrade; - impl frame_support::traits::OnRuntimeUpgrade for MockRuntimeUpgrade { - fn on_runtime_upgrade() -> Weight { - for asset in TokenExchangeRates::get() { - let _ = >::initialize_pool( - asset.0, - asset.1, - SwapBalanceThreshold::get(), - ); - } - 0 - } - } } #[cfg(feature = "with-acala-runtime")] diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index a67b817525..91f396cf1a 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1116,13 +1116,6 @@ parameter_types! { vec![LKSM, KSM, KAR], vec![BNC, KUSD, KSM, KAR], ]; - // Initial fee pool size. one extrinsic=0.0025 KAR, one block=100 extrinsics. - // 20 blocks trigger an swap, so total balance=0.0025*100*20=5 KAR - pub FeePoolSize: Balance = 5 * dollar(KAR); - // one extrinsic fee=0.0025KAR, one block=100 extrinsics, threshold=0.25+0.1=0.35KAR - pub SwapBalanceThreshold: Balance = Ratio::saturating_from_rational(35, 100).saturating_mul_int(dollar(KAR)); - // tokens used as fee charge. the token should have corresponding dex swap pool enabled. - pub FeePoolExchangeTokens: Vec = vec![KUSD, KSM, LKSM, BNC]; } type NegativeImbalance = >::NegativeImbalance; @@ -1997,33 +1990,8 @@ pub type SignedPayload = generic::SignedPayload; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Executive: handles dispatch to the various modules. -pub type Executive = frame_executive::Executive< - Runtime, - Block, - frame_system::ChainContext, - Runtime, - AllPallets, - TransactionPaymentUpgrade, ->; - -pub struct TransactionPaymentUpgrade; -impl frame_support::traits::OnRuntimeUpgrade for TransactionPaymentUpgrade { - fn on_runtime_upgrade() -> Weight { - let initial_rates = FeePoolExchangeTokens::get(); - if initial_rates.is_empty() { - 0 - } else { - for asset in initial_rates { - let _ = >::initialize_pool( - asset, - FeePoolSize::get(), - SwapBalanceThreshold::get(), - ); - } - ::BlockWeights::get().max_block - } - } -} +pub type Executive = + frame_executive::Executive, Runtime, AllPallets, ()>; #[cfg(not(feature = "disable-runtime-api"))] impl_runtime_apis! { diff --git a/runtime/mandala/src/benchmarking/transaction_payment.rs b/runtime/mandala/src/benchmarking/transaction_payment.rs index e0219318f5..e831da627d 100644 --- a/runtime/mandala/src/benchmarking/transaction_payment.rs +++ b/runtime/mandala/src/benchmarking/transaction_payment.rs @@ -18,8 +18,8 @@ use super::utils::set_balance; use crate::{ - dollar, AccountId, Balance, Currencies, CurrencyId, Dex, Event, FeePoolSize, GetNativeCurrencyId, - GetStableCurrencyId, NativeTokenExistentialDeposit, Origin, Runtime, System, TransactionPayment, TreasuryPalletId, + dollar, AccountId, Balance, Currencies, CurrencyId, Dex, Event, GetNativeCurrencyId, GetStableCurrencyId, + NativeTokenExistentialDeposit, Origin, Runtime, System, TransactionPayment, TreasuryPalletId, }; use frame_benchmarking::{account, whitelisted_caller}; use frame_support::traits::OnFinalize; @@ -91,7 +91,7 @@ runtime_benchmarks! { let sub_account: AccountId = ::PalletId::get().into_sub_account(STABLECOIN); let native_ed: Balance = >::minimum_balance(NATIVECOIN); let stable_ed: Balance = >::minimum_balance(STABLECOIN); - let pool_size: Balance = FeePoolSize::get(); + let pool_size: Balance = native_ed * 50; let swap_threshold: Balance = native_ed * 2; let path = vec![STABLECOIN, NATIVECOIN]; diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index a37eea1b87..0c4bee4614 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1119,13 +1119,6 @@ impl module_transaction_pause::Config for Runtime { parameter_types! { // Sort by fee charge order pub DefaultFeeSwapPathList: Vec> = vec![vec![AUSD, ACA], vec![AUSD, LDOT, ACA], vec![AUSD, DOT, ACA], vec![AUSD, RENBTC, ACA]]; - // Initial fee pool size. one extrinsic=0.0025 ACA, one block=100 extrinsics. - // 20 blocks trigger an swap, so total balance=0.0025*100*20=5 ACA - pub FeePoolSize: Balance = 5 * dollar(ACA); - // one extrinsic fee=0.0025ACA, one block=100 extrinsics, threshold=0.25+0.1=0.35ACA - pub SwapBalanceThreshold: Balance = Ratio::saturating_from_rational(35, 100).saturating_mul_int(dollar(ACA)); - // tokens used as fee charge. the token should have corresponding dex swap pool enabled. - pub FeePoolExchangeTokens: Vec = vec![DOT]; } type NegativeImbalance = >::NegativeImbalance; @@ -1997,33 +1990,8 @@ pub type SignedPayload = generic::SignedPayload; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Executive: handles dispatch to the various modules. -pub type Executive = frame_executive::Executive< - Runtime, - Block, - frame_system::ChainContext, - Runtime, - AllPallets, - TransactionPaymentUpgrade, ->; - -pub struct TransactionPaymentUpgrade; -impl frame_support::traits::OnRuntimeUpgrade for TransactionPaymentUpgrade { - fn on_runtime_upgrade() -> Weight { - let initial_rates = FeePoolExchangeTokens::get(); - if initial_rates.is_empty() { - 0 - } else { - for asset in initial_rates { - let _ = >::initialize_pool( - asset, - FeePoolSize::get(), - SwapBalanceThreshold::get(), - ); - } - ::BlockWeights::get().max_block - } - } -} +pub type Executive = + frame_executive::Executive, Runtime, AllPallets, ()>; construct_runtime! { pub enum Runtime where