Skip to content

Commit

Permalink
Switching from pallet configs to macros, Part 1 (#1255)
Browse files Browse the repository at this point in the history
* Switching from pallet configs to macros, Part 1

* Alphabetical order
  • Loading branch information
shlavik authored Oct 29, 2024
1 parent 1b15da2 commit 9d4174b
Show file tree
Hide file tree
Showing 44 changed files with 529 additions and 829 deletions.
198 changes: 179 additions & 19 deletions common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ pub fn charlie() -> AccountId32 {
/// Mock of pallet `assets::Config`.
#[macro_export]
macro_rules! mock_assets_config {
($runtime:ty) => {
parameter_types! {
($runtime:ty, $asset_regulator:ty) => {
frame_support::parameter_types! {
pub GetBuyBackAccountId: AccountId = AccountId32::from([23; 32]);
pub GetBuyBackSupplyAssets: Vec<AssetId> = vec![];
pub const GetBuyBackPercentage: u8 = 0;
Expand All @@ -233,7 +233,23 @@ macro_rules! mock_assets_config {
type Currency = currencies::Pallet<$runtime>;
type GetTotalBalance = ();
type WeightInfo = ();
type AssetRegulator = permissions::Pallet<$runtime>;
type AssetRegulator = $asset_regulator;
}
};
($runtime:ty) => {
mock_assets_config!($runtime, permissions::Pallet<$runtime>);
};
}

/// Mock of pallet `extended_assets::Config`.
#[macro_export]
macro_rules! mock_extended_assets_config {
($runtime:ty) => {
impl extended_assets::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type AssetInfoProvider = assets::Pallet<$runtime>;
type MaxRegulatedAssetsPerSBT = ConstU32<10000>;
type WeightInfo = ();
}
};
}
Expand All @@ -242,7 +258,7 @@ macro_rules! mock_assets_config {
#[macro_export]
macro_rules! mock_pallet_balances_config {
($runtime:ty) => {
parameter_types! {
frame_support::parameter_types! {
pub const ExistentialDeposit: u128 = 0;
}
impl pallet_balances::Config for $runtime {
Expand Down Expand Up @@ -331,17 +347,6 @@ macro_rules! mock_permissions_config {
/// Mock of pallet `technical::Config`.
#[macro_export]
macro_rules! mock_technical_config {
($runtime:ty) => {
impl technical::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type TechAssetId = TechAssetId;
type TechAccountId = TechAccountId;
type Trigger = ();
type Condition = ();
type SwapAction = ();
type AssetInfoProvider = assets::Pallet<$runtime>;
}
};
($runtime:ty, $swap_action:ty) => {
impl technical::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
Expand All @@ -353,13 +358,16 @@ macro_rules! mock_technical_config {
type AssetInfoProvider = assets::Pallet<$runtime>;
}
};
($runtime:ty) => {
mock_technical_config!($runtime, ());
};
}

/// Mock of pallet `tokens::Config`.
#[macro_export]
macro_rules! mock_tokens_config {
($runtime:ty) => {
parameter_types! {
frame_support::parameter_types! {
pub const MaxLocks: u32 = 1;
}
impl tokens::Config for $runtime {
Expand All @@ -378,15 +386,35 @@ macro_rules! mock_tokens_config {
};
}

/// Mock of pallet `orml_tokens::Config`.
#[macro_export]
macro_rules! mock_orml_tokens_config {
($runtime:ty) => {
impl orml_tokens::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type Balance = Balance;
type Amount = Amount;
type CurrencyId = <$runtime as assets::Config>::AssetId;
type WeightInfo = ();
type ExistentialDeposits = ExistentialDeposits;
type CurrencyHooks = ();
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = ();
type DustRemovalWhitelist = Everything;
}
};
}

/// Mock of pallet `pallet_timestamp::Config`.
#[macro_export]
macro_rules! mock_pallet_timestamp_config {
($runtime:ty) => {
parameter_types! {
frame_support::parameter_types! {
pub const MinimumPeriod: u64 = 5;
}
impl pallet_timestamp::Config for $runtime {
type Moment = Moment;
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
Expand All @@ -398,7 +426,7 @@ macro_rules! mock_pallet_timestamp_config {
#[macro_export]
macro_rules! mock_vested_rewards_config {
($runtime:ty) => {
parameter_types! {
frame_support::parameter_types! {
pub const MaxVestingSchedules: u32 = 0;
pub const MinVestedTransfer: Balance = 0;
}
Expand All @@ -417,3 +445,135 @@ macro_rules! mock_vested_rewards_config {
}
};
}

/// Mock of pallet `dex_manager::Config`.
#[macro_export]
macro_rules! mock_dex_manager_config {
($runtime:ty) => {
impl dex_manager::Config for $runtime {}
};
}

/// Mock of pallet `trading_pair::Config`.
#[macro_export]
macro_rules! mock_trading_pair_config {
($runtime:ty) => {
impl trading_pair::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type EnsureDEXManager = dex_manager::Pallet<$runtime>;
type DexInfoProvider = dex_manager::Pallet<$runtime>;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<$runtime>;
}
};
}

/// Mock of pallet `price_tools::Config`.
#[macro_export]
macro_rules! mock_price_tools_config {
($runtime:ty) => {
impl price_tools::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type LiquidityProxy = ();
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type WeightInfo = price_tools::weights::SubstrateWeight<Runtime>;
}
};
}

/// Mock of pallet `band::Config`.
#[macro_export]
macro_rules! mock_band_config {
($runtime:ty, $on_new_symbol_relayed_hook:ty, $on_symbol_disabled_hook:ty) => {
frame_support::parameter_types! {
pub const GetBandRateStalePeriod: u64 = 60*5*1000; // 5 minutes
pub const GetBandRateStaleBlockPeriod: u64 = 600;
}
impl band::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type Symbol = common::SymbolName;
type WeightInfo = ();
type OnNewSymbolsRelayedHook = $on_new_symbol_relayed_hook;
type OnSymbolDisabledHook = $on_symbol_disabled_hook;
type GetBandRateStalePeriod = GetBandRateStalePeriod;
type GetBandRateStaleBlockPeriod = GetBandRateStaleBlockPeriod;
type MaxRelaySymbols = frame_support::traits::ConstU32<100>;
type Time = Timestamp;
}
};
($runtime:ty, $on_symbol_disabled_hook:ty) => {
mock_band_config!(
$runtime,
oracle_proxy::Pallet<Runtime>,
$on_symbol_disabled_hook
);
};
($runtime:ty) => {
mock_band_config!($runtime, oracle_proxy::Pallet<Runtime>, ());
};
}

/// Mock of pallet `oracle_proxy::Config`.
#[macro_export]
macro_rules! mock_oracle_proxy_config {
($runtime:ty, $band_chain_oracle:ty) => {
impl oracle_proxy::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type BandChainOracle = $band_chain_oracle;
type Symbol = <Runtime as band::Config>::Symbol;
type WeightInfo = ();
}
};
($runtime:ty) => {
mock_oracle_proxy_config!($runtime, band::Pallet<Runtime>);
};
}

/// Mock of pallet `dex_api::Config`.
#[macro_export]
macro_rules! mock_dex_api_config {
(
$runtime:ty,
$mcbc_pool:ty,
$xyk_pool:ty,
$xst_pool:ty,
$mock_liquidity_source:ty,
$mock_liquidity_source2:ty,
$mock_liquidity_source3:ty,
$mock_liquidity_source4:ty
) => {
impl dex_api::Config for $runtime {
type RuntimeEvent = RuntimeEvent;
type MulticollateralBondingCurvePool = $mcbc_pool;
type XYKPool = $xyk_pool;
type XSTPool = $xst_pool;
type MockLiquiditySource = $mock_liquidity_source;
type MockLiquiditySource2 = $mock_liquidity_source2;
type MockLiquiditySource3 = $mock_liquidity_source3;
type MockLiquiditySource4 = $mock_liquidity_source4;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type OrderBook = ();
type WeightInfo = ();
}
};
(
$runtime:ty,
$mcbc_pool:ty,
$xyk_pool:ty,
$xst_pool:ty
) => {
mock_dex_api_config!($runtime, $mcbc_pool, $xyk_pool, $xst_pool, (), (), (), ());
};
($runtime:ty) => {
mock_dex_api_config!(
$runtime,
multicollateral_bonding_curve_pool::Pallet<$runtime>,
pool_xyk::Pallet<Runtime>,
(),
(),
(),
(),
()
);
};
}
64 changes: 13 additions & 51 deletions pallets/apollo-platform/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use {
common::{
balance, fixed, hash,
mock::{ExistentialDeposits, GetTradingPairRestrictedFlag},
mock_assets_config, mock_common_config, mock_currencies_config, mock_frame_system_config,
mock_pallet_balances_config, mock_technical_config, mock_tokens_config,
mock_assets_config, mock_common_config, mock_currencies_config, mock_dex_api_config,
mock_dex_manager_config, mock_frame_system_config, mock_pallet_balances_config,
mock_pallet_timestamp_config, mock_permissions_config, mock_price_tools_config,
mock_technical_config, mock_tokens_config, mock_trading_pair_config,
mock_vested_rewards_config,
prelude::{Balance, SwapOutcome},
AssetId32, AssetName, AssetSymbol, BalancePrecision, ContentSource,
Expand Down Expand Up @@ -33,7 +35,6 @@ use {

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;
type Moment = u64;

pub type AccountId = AccountId32;
pub type BlockNumber = u64;
Expand Down Expand Up @@ -90,13 +91,19 @@ construct_runtime! {

pub type MockExtrinsic = TestXt<RuntimeCall, ()>;

mock_pallet_balances_config!(Runtime);
mock_assets_config!(Runtime);
mock_common_config!(Runtime);
mock_currencies_config!(Runtime);
mock_dex_api_config!(Runtime);
mock_dex_manager_config!(Runtime);
mock_frame_system_config!(Runtime);
mock_pallet_balances_config!(Runtime);
mock_pallet_timestamp_config!(Runtime);
mock_permissions_config!(Runtime);
mock_price_tools_config!(Runtime);
mock_technical_config!(Runtime, pool_xyk::PolySwapAction<DEXId, AssetId, AccountId, TechAccountId>);
mock_common_config!(Runtime);
mock_tokens_config!(Runtime);
mock_assets_config!(Runtime);
mock_trading_pair_config!(Runtime);
mock_vested_rewards_config!(Runtime);

impl<LocalCall> SendTransactionTypes<LocalCall> for Runtime
Expand All @@ -119,23 +126,20 @@ parameter_types! {
pub const GetBurnUpdateFrequency: BlockNumber = 14400;
pub GetParliamentAccountId: AccountId = AccountId32::from([100; 32]);
pub GetPswapDistributionAccountId: AccountId = AccountId32::from([101; 32]);
pub const MinimumPeriod: u64 = 5;
}

parameter_types! {
pub const GetNumSamples: usize = 40;
pub const GetBaseAssetId: AssetId = APOLLO_ASSET_ID;
pub const GetBuyBackAssetId: AssetId = VXOR;
pub GetLiquidityProxyTechAccountId: TechAccountId = {

TechAccountId::from_generic_pair(
liquidity_proxy::TECH_ACCOUNT_PREFIX.to_vec(),
liquidity_proxy::TECH_ACCOUNT_MAIN.to_vec(),
)
};
pub GetLiquidityProxyAccountId: AccountId = {
let tech_account_id = GetLiquidityProxyTechAccountId::get();

technical::Pallet::<Runtime>::tech_account_id_to_account_id(&tech_account_id)
.expect("Failed to get ordinary account id for technical account id.")
};
Expand Down Expand Up @@ -180,28 +184,6 @@ impl ceres_liquidity_locker::Config for Runtime {
type WeightInfo = ();
}

impl dex_api::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MockLiquiditySource = ();
type MockLiquiditySource2 = ();
type MockLiquiditySource3 = ();
type MockLiquiditySource4 = ();
type MulticollateralBondingCurvePool = ();
type XYKPool = pool_xyk::Pallet<Runtime>;
type XSTPool = ();
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type OrderBook = ();
type WeightInfo = ();
}

impl trading_pair::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type WeightInfo = ();
type AssetInfoProvider = assets::Pallet<Runtime>;
}

impl multicollateral_bonding_curve_pool::Config for Runtime {
const RETRY_DISTRIBUTION_FREQUENCY: BlockNumber = 1000;
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -267,26 +249,6 @@ impl pswap_distribution::Config for Runtime {
type AssetInfoProvider = assets::Pallet<Runtime>;
}

impl pallet_timestamp::Config for Runtime {
type Moment = Moment;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}

impl dex_manager::Config for Runtime {}

impl permissions::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

impl price_tools::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type LiquidityProxy = LiquidityProxy;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type WeightInfo = price_tools::weights::SubstrateWeight<Runtime>;
}

pub struct MockPriceTools;

impl PriceToolsProvider<AssetId> for MockPriceTools {
Expand Down
Loading

0 comments on commit 9d4174b

Please sign in to comment.