diff --git a/Cargo.lock b/Cargo.lock index e8ce72a9f0..d8436db6e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1644,7 +1644,6 @@ dependencies = [ "sp-runtime", "sp-std", "technical", - "trading-pair", ] [[package]] @@ -2682,7 +2681,6 @@ dependencies = [ "sp-runtime", "sp-std", "technical", - "trading-pair", ] [[package]] @@ -5143,7 +5141,6 @@ dependencies = [ "sp-runtime", "sp-std", "technical", - "trading-pair", ] [[package]] @@ -7093,7 +7090,6 @@ dependencies = [ "sp-runtime", "sp-std", "technical", - "trading-pair", ] [[package]] @@ -9145,7 +9141,6 @@ dependencies = [ "sp-runtime", "sp-std", "technical", - "trading-pair", ] [[package]] @@ -9358,7 +9353,6 @@ dependencies = [ "sp-runtime", "sp-std", "technical", - "trading-pair", ] [[package]] @@ -9441,7 +9435,6 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "trading-pair", ] [[package]] @@ -13330,7 +13323,6 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "trading-pair", "twox-hash", ] @@ -14219,7 +14211,6 @@ dependencies = [ "sp-runtime", "sp-std", "technical", - "trading-pair", ] [[package]] diff --git a/common/src/traits.rs b/common/src/traits.rs index 6840ef4e8b..95c336f7ce 100644 --- a/common/src/traits.rs +++ b/common/src/traits.rs @@ -120,6 +120,18 @@ pub trait TradingPairSourceManager { target_asset_id: &AssetId, source_type: LiquiditySourceType, ) -> DispatchResult; + + fn is_trading_pair_enabled( + dex_id: &DEXId, + base_asset_id: &AssetId, + target_asset_id: &AssetId, + ) -> Result; + + fn register_pair( + dex_id: DEXId, + base_asset_id: AssetId, + target_asset_id: AssetId, + ) -> Result<(), DispatchError>; } impl TradingPairSourceManager for () { @@ -157,6 +169,22 @@ impl TradingPairSourceManager for () { ) -> DispatchResult { Err(DispatchError::CannotLookup) } + + fn is_trading_pair_enabled( + _dex_id: &DEXId, + _base_asset_id: &AssetId, + _target_asset_id: &AssetId, + ) -> Result { + Err(DispatchError::CannotLookup) + } + + fn register_pair( + _dex_id: DEXId, + _base_asset_id: AssetId, + _target_asset_id: AssetId, + ) -> Result<(), DispatchError> { + Err(DispatchError::CannotLookup) + } } /// Indicates that particular object can be used to perform exchanges. @@ -216,6 +244,24 @@ pub trait LiquiditySource { fn check_rewards_weight() -> Weight; } +/// Implements trading pairs LockedLiquiditySources storage +pub trait LockedLiquiditySourcesManager { + fn get() -> Vec; + fn set(liquidity_source_types: Vec) -> (); + fn append(liquidity_source_type: LiquiditySourceType) -> (); +} + +/// Implements trading pair EnabledSources storage +pub trait EnabledSourcesManager { + fn mutate_remove(dex_id: &DEXId, base_asset_id: &AssetId, target_asset_id: &AssetId) -> (); +} + +impl EnabledSourcesManager for () { + fn mutate_remove(_dex_id: &DEXId, _baset_asset_id: &AssetId, _target_asset_id: &AssetId) -> () { + todo!() + } +} + /// *Hook*-like trait for oracles to capture newly relayed symbols. /// /// A struct implementing this trait can be specified in oracle pallet *Config* diff --git a/pallets/ceres-governance-platform/Cargo.toml b/pallets/ceres-governance-platform/Cargo.toml index 3cddcde275..934b1e2adc 100644 --- a/pallets/ceres-governance-platform/Cargo.toml +++ b/pallets/ceres-governance-platform/Cargo.toml @@ -25,7 +25,6 @@ sp-std = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot sp-core = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } sp-runtime = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } technical = { path = "../technical", default-features = false } -trading-pair = { path = "../trading-pair", default-features = false } permissions = { path = "../permissions", default-features = false } serde = { version = "1.0.101", optional = true, features = ["derive"] } hex-literal = "0.4.1" diff --git a/pallets/ceres-governance-platform/src/mock.rs b/pallets/ceres-governance-platform/src/mock.rs index 2404f6193a..826dac8446 100644 --- a/pallets/ceres-governance-platform/src/mock.rs +++ b/pallets/ceres-governance-platform/src/mock.rs @@ -34,7 +34,6 @@ construct_runtime! { Currencies: currencies::{Pallet, Call, Storage}, Balances: pallet_balances::{Pallet, Call, Storage, Event}, DexManager: dex_manager::{Pallet, Call, Config, Storage}, - TradingPair: trading_pair::{Pallet, Call, Config, Storage, Event}, Permissions: permissions::{Pallet, Call, Config, Storage, Event}, Technical: technical::{Pallet, Call, Config, Storage, Event}, PoolXYK: pool_xyk::{Pallet, Call, Storage, Event}, @@ -146,13 +145,6 @@ impl permissions::Config for Runtime { impl dex_manager::Config for Runtime {} -impl trading_pair::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type EnsureDEXManager = dex_manager::Pallet; - type DexInfoProvider = dex_manager::Pallet; - type WeightInfo = (); -} - impl demeter_farming_platform::Config for Runtime { type RuntimeEvent = RuntimeEvent; type DemeterAssetId = (); @@ -170,6 +162,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = (); + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = (); + type EnabledSourcesManager = (); type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/ceres-launchpad/src/lib.rs b/pallets/ceres-launchpad/src/lib.rs index 386e0dfb4e..523c152c5f 100644 --- a/pallets/ceres-launchpad/src/lib.rs +++ b/pallets/ceres-launchpad/src/lib.rs @@ -13,6 +13,7 @@ mod tests; mod benchmarking; use codec::{Decode, Encode}; +use common::TradingPairSourceManager; pub use weights::WeightInfo; #[derive(Encode, Decode, Default, PartialEq, Eq, scale_info::TypeInfo)] @@ -101,7 +102,6 @@ pub mod pallet { pub trait Config: frame_system::Config + assets::Config - + trading_pair::Config + pool_xyk::Config + ceres_liquidity_locker::Config + pswap_distribution::Config @@ -115,13 +115,14 @@ pub mod pallet { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type TradingPairSourceManager: TradingPairSourceManager; + /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } type Assets = assets::Pallet; pub type Timestamp = timestamp::Pallet; - type TradingPair = trading_pair::Pallet; type PoolXYK = pool_xyk::Pallet; type CeresLiquidityLocker = ceres_liquidity_locker::Pallet; type TokenLocker = ceres_token_locker::Pallet; @@ -399,8 +400,12 @@ pub mod pallet { }; ensure!( - !TradingPair::::is_trading_pair_enabled(&dex_id, &base_asset, &asset_id) - .unwrap_or(true), + !::TradingPairSourceManager::is_trading_pair_enabled( + &dex_id, + &base_asset, + &asset_id + ) + .unwrap_or(true), Error::::CantCreateILOForListedToken ); @@ -733,8 +738,7 @@ pub mod pallet { DEXId::PolkaswapXSTUSD.into() }; // Register trading pair - TradingPair::::register( - RawOrigin::Signed(pallet_account.clone()).into(), + ::TradingPairSourceManager::register_pair( dex_id, ilo_info.base_asset, asset_id, diff --git a/pallets/ceres-launchpad/src/mock.rs b/pallets/ceres-launchpad/src/mock.rs index 3bdb9d95b5..30ad6a82f8 100644 --- a/pallets/ceres-launchpad/src/mock.rs +++ b/pallets/ceres-launchpad/src/mock.rs @@ -116,6 +116,7 @@ impl frame_system::Config for Runtime { impl crate::Config for Runtime { const MILLISECONDS_PER_DAY: Self::Moment = 86_400_000; type RuntimeEvent = RuntimeEvent; + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = (); } @@ -182,6 +183,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); @@ -197,6 +202,7 @@ impl multicollateral_bonding_curve_pool::Config for Runtime { type EnsureTradingPairExists = trading_pair::Pallet; type PriceToolsPallet = (); type VestedRewardsPallet = VestedRewards; + type TradingPairSourceManager = trading_pair::Pallet; type BuyBackHandler = (); type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; type WeightInfo = (); diff --git a/pallets/ceres-liquidity-locker/benchmarking/src/lib.rs b/pallets/ceres-liquidity-locker/benchmarking/src/lib.rs index ed0529ec2e..c3f025dd69 100644 --- a/pallets/ceres-liquidity-locker/benchmarking/src/lib.rs +++ b/pallets/ceres-liquidity-locker/benchmarking/src/lib.rs @@ -7,7 +7,10 @@ use ceres_liquidity_locker::AccountIdOf; use codec::Decode; use common::prelude::Balance; -use common::{balance, AssetName, AssetSymbol, DEXId, DEFAULT_BALANCE_PRECISION, XOR}; +use common::{ + balance, AssetName, AssetSymbol, DEXId, TradingPairSourceManager, DEFAULT_BALANCE_PRECISION, + XOR, +}; use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; use frame_system::RawOrigin; use hex_literal::hex; @@ -17,13 +20,12 @@ use assets::Pallet as Assets; use pallet_timestamp::Pallet as Timestamp; use permissions::Pallet as Permissions; use pool_xyk::Pallet as XYKPool; -use trading_pair::Pallet as TradingPair; #[cfg(test)] mod mock; pub struct Pallet(ceres_liquidity_locker::Pallet); -pub trait Config: ceres_liquidity_locker::Config + trading_pair::Config + pool_xyk::Config {} +pub trait Config: ceres_liquidity_locker::Config + pool_xyk::Config {} pub const DEX: DEXId = DEXId::Polkaswap; @@ -42,8 +44,6 @@ pub fn AUTHORITY() -> T::AccountId { fn setup_benchmark_assets_only() -> Result<(), &'static str> { let owner = alice::(); frame_system::Pallet::::inc_providers(&owner); - let owner_origin: ::RuntimeOrigin = - RawOrigin::Signed(owner.clone()).into(); let ceres_asset_id = common::AssetId32::from_bytes(hex!( "008bcfd2387d3fc453333557eecb0efe59fcba128769b2feefdd306e98e66440" )); @@ -85,13 +85,8 @@ fn setup_benchmark_assets_only() -> Result<(), &'static str> { None, ); - TradingPair::::register( - owner_origin.clone(), - DEX.into(), - XOR.into(), - ceres_asset_id.into(), - ) - .unwrap(); + T::TradingPairSourceManager::register_pair(DEX.into(), XOR.into(), ceres_asset_id.into()) + .unwrap(); Assets::::mint_to(&XOR.into(), &owner.clone(), &owner.clone(), balance!(50000))?; Assets::::mint_to( diff --git a/pallets/ceres-liquidity-locker/benchmarking/src/mock.rs b/pallets/ceres-liquidity-locker/benchmarking/src/mock.rs index ab27e6cfb7..fdf90dd5ba 100644 --- a/pallets/ceres-liquidity-locker/benchmarking/src/mock.rs +++ b/pallets/ceres-liquidity-locker/benchmarking/src/mock.rs @@ -187,6 +187,7 @@ impl dex_api::Config for Runtime { type MulticollateralBondingCurvePool = (); type XYKPool = pool_xyk::Pallet; type XSTPool = (); + type DexInfoProvider = dex_manager::Pallet; #[cfg(feature = "ready-to-test")] // order-book type OrderBook = (); @@ -220,6 +221,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/ceres-liquidity-locker/src/mock.rs b/pallets/ceres-liquidity-locker/src/mock.rs index d5202635ae..38544f45a6 100644 --- a/pallets/ceres-liquidity-locker/src/mock.rs +++ b/pallets/ceres-liquidity-locker/src/mock.rs @@ -223,6 +223,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/ceres-token-locker/Cargo.toml b/pallets/ceres-token-locker/Cargo.toml index 9de1f36fa5..adabf90bea 100644 --- a/pallets/ceres-token-locker/Cargo.toml +++ b/pallets/ceres-token-locker/Cargo.toml @@ -41,7 +41,6 @@ dex-manager = { path = "../dex-manager" } pallet-balances = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" } pool-xyk = { path = "../pool-xyk" } pswap-distribution = { path = "../pswap-distribution" } -trading-pair = { path = "../trading-pair" } sp-io = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" } permissions = { path = "../permissions" } tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-tokens" } diff --git a/pallets/ceres-token-locker/src/mock.rs b/pallets/ceres-token-locker/src/mock.rs index 218832931f..a4093889e3 100644 --- a/pallets/ceres-token-locker/src/mock.rs +++ b/pallets/ceres-token-locker/src/mock.rs @@ -35,7 +35,6 @@ construct_runtime! { Currencies: currencies::{Pallet, Call, Storage}, Balances: pallet_balances::{Pallet, Call, Storage, Event}, DexManager: dex_manager::{Pallet, Call, Config, Storage}, - TradingPair: trading_pair::{Pallet, Call, Config, Storage, Event}, Permissions: permissions::{Pallet, Call, Config, Storage, Event}, Technical: technical::{Pallet, Call, Config, Storage, Event}, PoolXYK: pool_xyk::{Pallet, Call, Storage, Event}, @@ -144,13 +143,6 @@ impl permissions::Config for Runtime { impl dex_manager::Config for Runtime {} -impl trading_pair::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type EnsureDEXManager = dex_manager::Pallet; - type DexInfoProvider = dex_manager::Pallet; - type WeightInfo = (); -} - impl demeter_farming_platform::Config for Runtime { type RuntimeEvent = RuntimeEvent; type DemeterAssetId = (); @@ -168,6 +160,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = (); + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = (); + type EnabledSourcesManager = (); type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/demeter-farming-platform/benchmarking/src/mock.rs b/pallets/demeter-farming-platform/benchmarking/src/mock.rs index 8c3106992e..69e2bd8d79 100644 --- a/pallets/demeter-farming-platform/benchmarking/src/mock.rs +++ b/pallets/demeter-farming-platform/benchmarking/src/mock.rs @@ -176,6 +176,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); @@ -210,6 +214,7 @@ impl multicollateral_bonding_curve_pool::Config for Runtime { type EnsureTradingPairExists = trading_pair::Pallet; type PriceToolsPallet = (); type VestedRewardsPallet = VestedRewards; + type TradingPairSourceManager = trading_pair::Pallet; type BuyBackHandler = (); type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; type WeightInfo = (); diff --git a/pallets/demeter-farming-platform/src/mock.rs b/pallets/demeter-farming-platform/src/mock.rs index 432832d535..e27a5cd712 100644 --- a/pallets/demeter-farming-platform/src/mock.rs +++ b/pallets/demeter-farming-platform/src/mock.rs @@ -173,6 +173,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); @@ -207,6 +211,7 @@ impl multicollateral_bonding_curve_pool::Config for Runtime { type EnsureTradingPairExists = trading_pair::Pallet; type PriceToolsPallet = (); type VestedRewardsPallet = VestedRewards; + type TradingPairSourceManager = trading_pair::Pallet; type BuyBackHandler = (); type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; type WeightInfo = (); diff --git a/pallets/dex-api/Cargo.toml b/pallets/dex-api/Cargo.toml index ba0feb716b..b295f1f310 100644 --- a/pallets/dex-api/Cargo.toml +++ b/pallets/dex-api/Cargo.toml @@ -31,7 +31,6 @@ serde = { version = "1.0.101", optional = true, features = [ sp-arithmetic = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } sp-std = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-tokens", default-features = false } -trading-pair = { path = "../trading-pair", default-features = false } traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", package = "orml-traits", default-features = false } pallet-timestamp = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } @@ -51,7 +50,6 @@ permissions = { path = "../permissions" } pool-xyk = { path = "../pool-xyk" } pswap-distribution = { path = "../pswap-distribution" } technical = { path = "../technical" } -trading-pair = { path = "../trading-pair" } [features] default = ['std'] diff --git a/pallets/dex-api/src/lib.rs b/pallets/dex-api/src/lib.rs index 6487ffeb0a..a13bac0d1d 100644 --- a/pallets/dex-api/src/lib.rs +++ b/pallets/dex-api/src/lib.rs @@ -34,8 +34,8 @@ use common::prelude::{Balance, QuoteAmount, SwapAmount, SwapOutcome}; use common::{ - DexInfoProvider, LiquidityRegistry, LiquiditySource, LiquiditySourceFilter, LiquiditySourceId, - LiquiditySourceType, RewardReason, + DEXInfo, DexInfoProvider, LiquidityRegistry, LiquiditySource, LiquiditySourceFilter, + LiquiditySourceId, LiquiditySourceType, RewardReason, }; use frame_support::sp_runtime::DispatchError; use frame_support::weights::Weight; @@ -342,9 +342,7 @@ pub mod pallet { use frame_system::pallet_prelude::*; #[pallet::config] - pub trait Config: - frame_system::Config + common::Config + trading_pair::Config + assets::Config - { + pub trait Config: frame_system::Config + common::Config + assets::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type MockLiquiditySource: LiquiditySource< Self::DEXId, @@ -395,6 +393,7 @@ pub mod pallet { Balance, DispatchError, >; + type DexInfoProvider: DexInfoProvider>; #[cfg(feature = "ready-to-test")] // order-book type OrderBook: LiquiditySource< diff --git a/pallets/dex-api/src/mock.rs b/pallets/dex-api/src/mock.rs index 845c7cf553..5334ff3b5f 100644 --- a/pallets/dex-api/src/mock.rs +++ b/pallets/dex-api/src/mock.rs @@ -112,7 +112,6 @@ construct_runtime! { MockLiquiditySource4: mock_liquidity_source::::{Pallet, Call, Config, Storage}, Technical: technical::{Pallet, Call, Storage, Event}, DexManager: dex_manager::{Pallet, Call, Storage}, - TradingPair: trading_pair::{Pallet, Call, Storage, Event}, PoolXYK: pool_xyk::{Pallet, Call, Storage, Event}, PswapDistribution: pswap_distribution::{Pallet, Call, Storage, Event}, CeresLiquidityLocker: ceres_liquidity_locker::{Pallet, Call, Storage, Event}, @@ -160,6 +159,7 @@ impl Config for Runtime { type MulticollateralBondingCurvePool = (); type XYKPool = pool_xyk::Pallet; type XSTPool = (); + type DexInfoProvider = dex_manager::Pallet; #[cfg(feature = "ready-to-test")] // order-book type OrderBook = (); @@ -240,28 +240,28 @@ impl pallet_balances::Config for Runtime { impl mock_liquidity_source::Config for Runtime { type GetFee = GetFee; type EnsureDEXManager = dex_manager::Pallet; - type EnsureTradingPairExists = trading_pair::Pallet; + type EnsureTradingPairExists = (); type DexInfoProvider = dex_manager::Pallet; } impl mock_liquidity_source::Config for Runtime { type GetFee = GetFee; type EnsureDEXManager = dex_manager::Pallet; - type EnsureTradingPairExists = trading_pair::Pallet; + type EnsureTradingPairExists = (); type DexInfoProvider = dex_manager::Pallet; } impl mock_liquidity_source::Config for Runtime { type GetFee = GetFee; type EnsureDEXManager = dex_manager::Pallet; - type EnsureTradingPairExists = trading_pair::Pallet; + type EnsureTradingPairExists = (); type DexInfoProvider = dex_manager::Pallet; } impl mock_liquidity_source::Config for Runtime { type GetFee = GetFee; type EnsureDEXManager = dex_manager::Pallet; - type EnsureTradingPairExists = trading_pair::Pallet; + type EnsureTradingPairExists = (); type DexInfoProvider = dex_manager::Pallet; } @@ -276,13 +276,6 @@ impl technical::Config for Runtime { impl dex_manager::Config for Runtime {} -impl trading_pair::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type EnsureDEXManager = dex_manager::Pallet; - type DexInfoProvider = dex_manager::Pallet; - type WeightInfo = (); -} - impl demeter_farming_platform::Config for Runtime { type RuntimeEvent = RuntimeEvent; type DemeterAssetId = (); @@ -300,6 +293,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = (); + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = (); + type EnabledSourcesManager = (); type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/farming/src/benchmarking.rs b/pallets/farming/src/benchmarking.rs index b51297f7f5..fab86afd42 100644 --- a/pallets/farming/src/benchmarking.rs +++ b/pallets/farming/src/benchmarking.rs @@ -38,7 +38,7 @@ use frame_system::RawOrigin; use hex_literal::hex; use sp_std::prelude::*; -use common::{AssetName, AssetSymbol, DEFAULT_BALANCE_PRECISION, XOR}; +use common::{AssetName, AssetSymbol, TradingPairSourceManager, DEFAULT_BALANCE_PRECISION, XOR}; use crate::utils; @@ -73,8 +73,7 @@ fn prepare_pools(count: u32) -> (Vec, Vec) ) .unwrap(); - assert_ok!(trading_pair::Pallet::::register( - signed_origin::(asset_owner::()), + assert_ok!(::TradingPairSourceManager::register_pair( Default::default(), xor_asset.clone(), other_asset.clone(), diff --git a/pallets/farming/src/lib.rs b/pallets/farming/src/lib.rs index e136f5cf2d..9a58635193 100644 --- a/pallets/farming/src/lib.rs +++ b/pallets/farming/src/lib.rs @@ -57,7 +57,10 @@ use sp_std::collections::btree_map::{BTreeMap, Entry}; use sp_std::vec::Vec; use common::prelude::{FixedWrapper, QuoteAmount}; -use common::{balance, AccountIdOf, Balance, DexIdOf, LiquiditySource, OnPoolCreated}; +use common::{ + balance, AccountIdOf, Balance, DexIdOf, LiquiditySource, OnPoolCreated, + TradingPairSourceManager, +}; pub type WeightInfoOf = ::WeightInfo; pub use weights::WeightInfo; @@ -338,6 +341,7 @@ pub mod pallet { type SchedulerOriginCaller: From>; type Scheduler: Anon::RuntimeCall, Self::SchedulerOriginCaller>; type RewardDoublingAssets: Get>>; + type TradingPairSourceManager: TradingPairSourceManager; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } diff --git a/pallets/farming/src/mock.rs b/pallets/farming/src/mock.rs index b3ab0943db..402728ecf9 100644 --- a/pallets/farming/src/mock.rs +++ b/pallets/farming/src/mock.rs @@ -287,6 +287,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = (PswapDistribution, Farming); type OnPoolReservesChanged = (); @@ -320,6 +324,7 @@ impl multicollateral_bonding_curve_pool::Config for Runtime { type EnsureDEXManager = dex_manager::Pallet; type PriceToolsPallet = (); type VestedRewardsPallet = VestedRewards; + type TradingPairSourceManager = trading_pair::Pallet; type BuyBackHandler = (); type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; type WeightInfo = (); @@ -391,6 +396,7 @@ impl Config for Runtime { type SchedulerOriginCaller = OriginCaller; type Scheduler = Scheduler; type RewardDoublingAssets = RewardDoublingAssets; + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = (); } diff --git a/pallets/hermes-governance-platform/Cargo.toml b/pallets/hermes-governance-platform/Cargo.toml index 8e53dceb85..d13aca9dcc 100644 --- a/pallets/hermes-governance-platform/Cargo.toml +++ b/pallets/hermes-governance-platform/Cargo.toml @@ -26,7 +26,6 @@ sp-std = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot sp-core = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } sp-runtime = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } technical = { path = "../technical", default-features = false } -trading-pair = { path = "../trading-pair", default-features = false } permissions = { path = "../permissions", default-features = false } serde = { version = "1.0.101", optional = true, features = ["derive"] } hex-literal = "0.4.1" @@ -48,7 +47,6 @@ pool-xyk = { path = "../pool-xyk", default-features = false } pswap-distribution = { path = "../pswap-distribution" } technical = { path = "../technical" } dex-manager = { path = "../dex-manager" } -trading-pair = { path = "../trading-pair" } price-tools = { path = "../price-tools" } [features] @@ -60,7 +58,6 @@ std = [ "assets/std", "frame-support/std", "frame-system/std", - "trading-pair/std", "technical/std", 'serde', "sp-core/std", diff --git a/pallets/hermes-governance-platform/src/mock.rs b/pallets/hermes-governance-platform/src/mock.rs index 1f30a5d107..30d9b85993 100644 --- a/pallets/hermes-governance-platform/src/mock.rs +++ b/pallets/hermes-governance-platform/src/mock.rs @@ -37,7 +37,6 @@ construct_runtime! { Currencies: currencies::{Pallet, Call, Storage}, Balances: pallet_balances::{Pallet, Call, Storage, Event}, DexManager: dex_manager::{Pallet, Call, Config, Storage}, - TradingPair: trading_pair::{Pallet, Call, Config, Storage, Event}, Permissions: permissions::{Pallet, Call, Config, Storage, Event}, Technical: technical::{Pallet, Call, Config, Storage, Event}, PoolXYK: pool_xyk::{Pallet, Call, Storage, Event}, @@ -168,13 +167,6 @@ impl permissions::Config for Runtime { impl dex_manager::Config for Runtime {} -impl trading_pair::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type EnsureDEXManager = dex_manager::Pallet; - type DexInfoProvider = dex_manager::Pallet; - type WeightInfo = (); -} - impl demeter_farming_platform::Config for Runtime { type RuntimeEvent = RuntimeEvent; type DemeterAssetId = (); @@ -201,6 +193,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = (); + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = (); + type EnabledSourcesManager = (); type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/liquidity-proxy/benchmarking/src/lib.rs b/pallets/liquidity-proxy/benchmarking/src/lib.rs index 71190946fa..befca1cbd3 100644 --- a/pallets/liquidity-proxy/benchmarking/src/lib.rs +++ b/pallets/liquidity-proxy/benchmarking/src/lib.rs @@ -115,7 +115,7 @@ benchmarks! { } new_trivial { - let dex_info = ::DexInfoProvider::get_dex_info(&DEX.into())?; + let dex_info = ::DexInfoProvider::get_dex_info(&DEX.into())?; let from_asset: T::AssetId = XSTUSD.into(); let to_asset: T::AssetId = VAL.into(); }: { diff --git a/pallets/liquidity-proxy/benchmarking/src/mock.rs b/pallets/liquidity-proxy/benchmarking/src/mock.rs index 4e1b4e209d..d08168012d 100644 --- a/pallets/liquidity-proxy/benchmarking/src/mock.rs +++ b/pallets/liquidity-proxy/benchmarking/src/mock.rs @@ -170,6 +170,9 @@ impl liquidity_proxy::Config for Runtime { type PrimaryMarketXST = (); type SecondaryMarket = (); type VestedRewardsPallet = vested_rewards::Pallet; + type LockedLiquiditySourcesManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; type GetADARAccountId = GetADARAccountId; type ADARCommissionRatioUpdateOrigin = EnsureRoot; type MaxAdditionalDataLength = ConstU32<128>; @@ -294,6 +297,7 @@ impl dex_api::Config for Runtime { type XYKPool = pool_xyk::Pallet; type XSTPool = (); type MulticollateralBondingCurvePool = multicollateral_bonding_curve_pool::Pallet; + type DexInfoProvider = dex_manager::Pallet; #[cfg(feature = "ready-to-test")] // order-book type OrderBook = (); @@ -325,6 +329,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); @@ -493,6 +501,7 @@ impl multicollateral_bonding_curve_pool::Config for Runtime { type EnsureTradingPairExists = trading_pair::Pallet; type PriceToolsPallet = MockPriceTools; type VestedRewardsPallet = VestedRewards; + type TradingPairSourceManager = trading_pair::Pallet; type BuyBackHandler = liquidity_proxy::LiquidityProxyBuyBackHandler; type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; type WeightInfo = (); @@ -520,6 +529,7 @@ impl pswap_distribution::Config for Runtime { impl price_tools::Config for Runtime { type RuntimeEvent = RuntimeEvent; type LiquidityProxy = LiquidityProxy; + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = price_tools::weights::SubstrateWeight; } diff --git a/pallets/liquidity-proxy/src/lib.rs b/pallets/liquidity-proxy/src/lib.rs index af10d0d683..f23175dc22 100644 --- a/pallets/liquidity-proxy/src/lib.rs +++ b/pallets/liquidity-proxy/src/lib.rs @@ -46,8 +46,8 @@ use common::{ balance, fixed_wrapper, AccountIdOf, AssetInfoProvider, BuyBackHandler, DEXInfo, DexIdOf, DexInfoProvider, FilterMode, Fixed, GetMarketInfo, GetPoolReserves, LiquidityProxyTrait, LiquidityRegistry, LiquiditySource, LiquiditySourceFilter, LiquiditySourceId, - LiquiditySourceType, RewardReason, TradingPair, TradingPairSourceManager, VestedRewardsPallet, - XSTUSD, + LiquiditySourceType, LockedLiquiditySourcesManager, RewardReason, TradingPair, + TradingPairSourceManager, VestedRewardsPallet, XSTUSD, }; use fallible_iterator::FallibleIterator as _; use frame_support::dispatch::PostDispatchInfo; @@ -986,7 +986,7 @@ impl Pallet { let mut sources = T::LiquidityRegistry::list_liquidity_sources(input_asset_id, output_asset_id, filter)?; let mut total_weight = ::WeightInfo::list_liquidity_sources(); - let locked = trading_pair::LockedLiquiditySources::::get(); + let locked = T::LockedLiquiditySourcesManager::get(); sources.retain(|x| !locked.contains(&x.liquidity_source_index)); ensure!(!sources.is_empty(), Error::::UnavailableExchangePath); @@ -1106,9 +1106,7 @@ impl Pallet { .tuple_windows() .filter_map(|(from, to)| { let pair = Self::weak_sort_pair(&dex_info, *from, *to); - - // TODO: #441 use TradingPairSourceManager instead of trading-pair pallet - trading_pair::Pallet::::list_enabled_sources_for_trading_pair( + T::TradingPairSourceManager::list_enabled_sources_for_trading_pair( dex_id, &pair.base_asset_id, &pair.target_asset_id, @@ -1127,9 +1125,7 @@ impl Pallet { let sources_set = fallible_iterator::convert(path.to_vec().iter().tuple_windows().map( |(from, to)| -> Result<_, DispatchError> { let pair = Self::weak_sort_pair(&dex_info, *from, *to); - - // TODO: #441 use TradingPairSourceManager instead of trading-pair pallet - let sources = trading_pair::Pallet::::list_enabled_sources_for_trading_pair( + let sources = T::TradingPairSourceManager::list_enabled_sources_for_trading_pair( &dex_id, &pair.base_asset_id, &pair.target_asset_id, @@ -2247,11 +2243,8 @@ pub mod pallet { use frame_system::pallet_prelude::*; // TODO: #395 use AssetInfoProvider instead of assets pallet - // TODO: #441 use TradingPairSourceManager instead of trading-pair pallet #[pallet::config] - pub trait Config: - frame_system::Config + common::Config + assets::Config + trading_pair::Config - { + pub trait Config: frame_system::Config + common::Config + assets::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type LiquidityRegistry: LiquidityRegistry< Self::DEXId, @@ -2267,9 +2260,12 @@ pub mod pallet { type PrimaryMarketXST: GetMarketInfo; type SecondaryMarket: GetPoolReserves; type VestedRewardsPallet: VestedRewardsPallet; + type TradingPairSourceManager: TradingPairSourceManager; + type LockedLiquiditySourcesManager: LockedLiquiditySourcesManager; type GetADARAccountId: Get; type ADARCommissionRatioUpdateOrigin: EnsureOrigin; type MaxAdditionalDataLength: Get; + type DexInfoProvider: DexInfoProvider>; /// Weight information for the extrinsics in this Pallet. type WeightInfo: WeightInfo; } @@ -2430,7 +2426,7 @@ pub mod pallet { Error::::UnableToEnableLiquiditySource ); - let mut locked = trading_pair::LockedLiquiditySources::::get(); + let mut locked = T::LockedLiquiditySourcesManager::get(); ensure!( locked.contains(&liquidity_source), @@ -2438,7 +2434,7 @@ pub mod pallet { ); locked.retain(|x| *x != liquidity_source); - trading_pair::LockedLiquiditySources::::set(locked); + T::LockedLiquiditySourcesManager::set(locked); Self::deposit_event(Event::::LiquiditySourceEnabled(liquidity_source)); Ok(().into()) } @@ -2460,10 +2456,10 @@ pub mod pallet { Error::::UnableToDisableLiquiditySource ); ensure!( - !trading_pair::LockedLiquiditySources::::get().contains(&liquidity_source), + !T::LockedLiquiditySourcesManager::get().contains(&liquidity_source), Error::::LiquiditySourceAlreadyDisabled ); - trading_pair::LockedLiquiditySources::::append(liquidity_source); + T::LockedLiquiditySourcesManager::append(liquidity_source); Self::deposit_event(Event::::LiquiditySourceDisabled(liquidity_source)); Ok(().into()) } diff --git a/pallets/liquidity-proxy/src/mock.rs b/pallets/liquidity-proxy/src/mock.rs index ea86714f25..6812a02888 100644 --- a/pallets/liquidity-proxy/src/mock.rs +++ b/pallets/liquidity-proxy/src/mock.rs @@ -199,9 +199,13 @@ impl Config for Runtime { type PrimaryMarketXST = MockXSTPool; type SecondaryMarket = mock_liquidity_source::Pallet; type VestedRewardsPallet = vested_rewards::Pallet; + type GetADARAccountId = GetADARAccountId; type ADARCommissionRatioUpdateOrigin = EnsureRoot; type MaxAdditionalDataLength = ConstU32<128>; + type LockedLiquiditySourcesManager = trading_pair::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; } impl tokens::Config for Runtime { @@ -327,6 +331,7 @@ impl dex_api::Config for Runtime { type XYKPool = pool_xyk::Pallet; type MulticollateralBondingCurvePool = MockMCBCPool; type XSTPool = MockXSTPool; + type DexInfoProvider = dex_manager::Pallet; #[cfg(feature = "ready-to-test")] // order-book type OrderBook = (); // todo @@ -377,6 +382,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type OnPoolCreated = pswap_distribution::Pallet; type OnPoolReservesChanged = (); type GetFee = GetXykFee; @@ -406,6 +415,7 @@ impl multicollateral_bonding_curve_pool::Config for Runtime { type EnsureTradingPairExists = trading_pair::Pallet; type EnsureDEXManager = dex_manager::Pallet; type VestedRewardsPallet = VestedRewards; + type TradingPairSourceManager = trading_pair::Pallet; type PriceToolsPallet = (); type BuyBackHandler = LiquidityProxyBuyBackHandler; type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; diff --git a/pallets/mock-liquidity-source/Cargo.toml b/pallets/mock-liquidity-source/Cargo.toml index 33cba231d0..94b7bd0a0b 100644 --- a/pallets/mock-liquidity-source/Cargo.toml +++ b/pallets/mock-liquidity-source/Cargo.toml @@ -43,7 +43,6 @@ hex-literal = "0.4.1" common = { path = "../../common", features = ["test"] } dex-manager = { path = "../dex-manager" } technical = { path = "../technical" } -trading-pair = { path = "../trading-pair" } [features] default = ['std'] diff --git a/pallets/mock-liquidity-source/src/mock.rs b/pallets/mock-liquidity-source/src/mock.rs index 2e17c4c113..8a03734853 100644 --- a/pallets/mock-liquidity-source/src/mock.rs +++ b/pallets/mock-liquidity-source/src/mock.rs @@ -89,7 +89,6 @@ construct_runtime! { Balances: pallet_balances::{Pallet, Call, Storage, Event}, Permissions: permissions::{Pallet, Call, Config, Storage, Event}, DexManager: dex_manager::{Pallet, Call, Config, Storage}, - TradingPair: trading_pair::{Pallet, Call, Config, Storage, Event}, } } @@ -123,14 +122,14 @@ impl frame_system::Config for Runtime { impl Config for Runtime { type GetFee = GetFee; type EnsureDEXManager = dex_manager::Pallet; - type EnsureTradingPairExists = trading_pair::Pallet; + type EnsureTradingPairExists = (); type DexInfoProvider = dex_manager::Pallet; } impl Config for Runtime { type GetFee = GetFee; type EnsureDEXManager = dex_manager::Pallet; - type EnsureTradingPairExists = trading_pair::Pallet; + type EnsureTradingPairExists = (); type DexInfoProvider = dex_manager::Pallet; } @@ -215,13 +214,6 @@ impl permissions::Config for Runtime { impl dex_manager::Config for Runtime {} -impl trading_pair::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type EnsureDEXManager = dex_manager::Pallet; - type DexInfoProvider = dex_manager::Pallet; - type WeightInfo = (); -} - pub struct ExtBuilder { // add additional fields for other pallets genesis } diff --git a/pallets/multicollateral-bonding-curve-pool/src/benchmarking.rs b/pallets/multicollateral-bonding-curve-pool/src/benchmarking.rs index 7d4b2ae2ff..c577ec1e34 100644 --- a/pallets/multicollateral-bonding-curve-pool/src/benchmarking.rs +++ b/pallets/multicollateral-bonding-curve-pool/src/benchmarking.rs @@ -51,7 +51,6 @@ use crate::Pallet as MBCPool; use assets::Pallet as Assets; use permissions::Pallet as Permissions; use pool_xyk::Pallet as XYKPool; -use trading_pair::Pallet as TradingPair; #[cfg(not(test))] use price_tools::Pallet as PriceTools; @@ -176,8 +175,7 @@ benchmarks! { None, None ).unwrap(); - TradingPair::::register( - RawOrigin::Signed(caller.clone()).into(), + ::TradingPairSourceManager::register_pair( common::DEXId::Polkaswap.into(), XOR.into(), USDT.into() @@ -244,7 +242,7 @@ benchmarks! { None, None ).unwrap(); - TradingPair::::register(RawOrigin::Signed(caller.clone()).into(), common::DEXId::Polkaswap.into(), XOR.into(), USDT.into()).unwrap(); + ::TradingPairSourceManager::register_pair( common::DEXId::Polkaswap.into(), XOR.into(), USDT.into()).unwrap(); MBCPool::::initialize_pool(RawOrigin::Signed(caller.clone()).into(), USDT.into()).unwrap(); }: { Pallet::::set_optional_reward_multiplier( @@ -333,8 +331,7 @@ benchmarks! { None, ) .unwrap(); - TradingPair::::register( - RawOrigin::Signed(caller.clone()).into(), + ::TradingPairSourceManager::register_pair( common::DEXId::Polkaswap.into(), XOR.into(), USDT.into(), @@ -393,8 +390,7 @@ benchmarks! { balance!(50000000), ) .unwrap(); - TradingPair::::register( - RawOrigin::Signed(caller.clone()).into(), + ::TradingPairSourceManager::register_pair( common::DEXId::Polkaswap.into(), XOR.into(), USDT.into(), @@ -452,8 +448,7 @@ benchmarks! { None, None ).unwrap(); - TradingPair::::register( - RawOrigin::Signed(caller.clone()).into(), + ::TradingPairSourceManager::register_pair( common::DEXId::Polkaswap.into(), XOR.into(), USDT.into() @@ -502,8 +497,7 @@ benchmarks! { balance!(50000000), ) .unwrap(); - TradingPair::::register( - RawOrigin::Signed(caller.clone()).into(), + ::TradingPairSourceManager::register_pair( common::DEXId::Polkaswap.into(), XOR.into(), USDT.into(), diff --git a/pallets/multicollateral-bonding-curve-pool/src/lib.rs b/pallets/multicollateral-bonding-curve-pool/src/lib.rs index 3db061bd13..a48cef15e6 100644 --- a/pallets/multicollateral-bonding-curve-pool/src/lib.rs +++ b/pallets/multicollateral-bonding-curve-pool/src/lib.rs @@ -187,14 +187,12 @@ pub mod pallet { use frame_system::pallet_prelude::*; // TODO: #395 use AssetInfoProvider instead of assets pallet - // TODO: #441 use TradingPairSourceManager instead of trading-pair pallet #[pallet::config] pub trait Config: frame_system::Config + common::Config + assets::Config + technical::Config - + trading_pair::Config + pool_xyk::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -207,6 +205,7 @@ pub mod pallet { >; type PriceToolsPallet: PriceToolsPallet; type VestedRewardsPallet: VestedRewardsPallet; + type TradingPairSourceManager: TradingPairSourceManager; type BuyBackHandler: BuyBackHandler; type BuyBackTBCDPercent: Get; /// Weight information for extrinsics in this pallet. @@ -783,7 +782,7 @@ impl Pallet { ) -> DispatchResult { common::with_transaction(|| { let base_asset_id = T::GetBaseAssetId::get(); - let swapped_xor_amount = ::LiquidityProxy::exchange( + let swapped_xor_amount = T::LiquidityProxy::exchange( DEXId::Polkaswap.into(), holder, holder, @@ -873,14 +872,13 @@ impl Pallet { Error::::PoolAlreadyInitializedForPair ); T::PriceToolsPallet::register_asset(&collateral_asset_id)?; - T::EnsureTradingPairExists::ensure_trading_pair_exists( + ::EnsureTradingPairExists::ensure_trading_pair_exists( &DEXId::Polkaswap.into(), &T::GetBaseAssetId::get(), &collateral_asset_id, )?; - // TODO: #441 use TradingPairSourceManager instead of trading-pair pallet - trading_pair::Pallet::::enable_source_for_trading_pair( + ::TradingPairSourceManager::enable_source_for_trading_pair( &DEXId::Polkaswap.into(), &T::GetBaseAssetId::get(), &collateral_asset_id, @@ -1426,7 +1424,7 @@ impl Pallet { let price = if asset_id == &reference_asset_id || asset_id == &common::TBCD.into() { balance!(1) } else { - ::PriceToolsPallet::get_average_price( + ::PriceToolsPallet::get_average_price( asset_id, &reference_asset_id, price_variant, diff --git a/pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs b/pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs index 1e26622389..139917a7c0 100644 --- a/pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs +++ b/pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs @@ -1,6 +1,8 @@ +use crate::pallet; use crate::Pallet; use common::balance; use common::FromGenericPair; +use common::TradingPairSourceManager; use common::TBCD; use frame_support::traits::Get; use frame_support::traits::OnRuntimeUpgrade; @@ -72,8 +74,7 @@ where ); return ::DbWeight::get().reads(1); } - if let Err(err) = trading_pair::Pallet::::register( - frame_system::RawOrigin::Signed(assets_and_permissions_account_id).into(), + if let Err(err) = ::TradingPairSourceManager::register_pair( common::DEXId::Polkaswap.into(), common::XOR.into(), common::TBCD.into(), diff --git a/pallets/multicollateral-bonding-curve-pool/src/mock.rs b/pallets/multicollateral-bonding-curve-pool/src/mock.rs index 421bb2d321..0afe51d53e 100644 --- a/pallets/multicollateral-bonding-curve-pool/src/mock.rs +++ b/pallets/multicollateral-bonding-curve-pool/src/mock.rs @@ -203,6 +203,7 @@ impl Config for Runtime { type EnsureDEXManager = dex_manager::Pallet; type PriceToolsPallet = MockDEXApi; type VestedRewardsPallet = MockVestedRewards; + type TradingPairSourceManager = trading_pair::Pallet; type BuyBackHandler = BuyBackHandlerImpl; type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; type WeightInfo = (); @@ -362,6 +363,7 @@ impl pswap_distribution::Config for Runtime { impl price_tools::Config for Runtime { type RuntimeEvent = RuntimeEvent; type LiquidityProxy = (); + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = price_tools::weights::SubstrateWeight; } @@ -382,6 +384,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/pool-xyk/benchmarking/src/lib.rs b/pallets/pool-xyk/benchmarking/src/lib.rs index 789e791cfb..239d9ee1f5 100644 --- a/pallets/pool-xyk/benchmarking/src/lib.rs +++ b/pallets/pool-xyk/benchmarking/src/lib.rs @@ -39,7 +39,7 @@ use codec::Decode; use common::prelude::{Balance, SwapAmount}; use common::{ balance, AssetInfoProvider, AssetName, AssetSymbol, DEXId, LiquiditySource, - DEFAULT_BALANCE_PRECISION, DOT, XOR, + TradingPairSourceManager, DEFAULT_BALANCE_PRECISION, DOT, XOR, }; use frame_benchmarking::benchmarks; use frame_system::RawOrigin; @@ -50,7 +50,6 @@ use sp_std::prelude::*; use assets::Pallet as Assets; use permissions::Pallet as Permissions; use pool_xyk::Pallet as XYKPool; -use trading_pair::Pallet as TradingPair; #[cfg(test)] mod mock; @@ -68,8 +67,6 @@ fn alice() -> T::AccountId { fn setup_benchmark_assets_only() -> Result<(), &'static str> { let owner = alice::(); frame_system::Pallet::::inc_providers(&owner); - let owner_origin: ::RuntimeOrigin = - RawOrigin::Signed(owner.clone()).into(); // Grant permissions to self in case they haven't been explicitly given in genesis config let _ = Permissions::::assign_permission( @@ -109,7 +106,7 @@ fn setup_benchmark_assets_only() -> Result<(), &'static str> { ) .unwrap(); - TradingPair::::register(owner_origin.clone(), DEX.into(), XOR.into(), DOT.into()).unwrap(); + T::TradingPairSourceManager::register_pair(DEX.into(), XOR.into(), DOT.into()).unwrap(); Assets::::mint_to(&XOR.into(), &owner.clone(), &owner.clone(), balance!(50000))?; Assets::::mint_to(&DOT.into(), &owner.clone(), &owner.clone(), balance!(50000))?; diff --git a/pallets/pool-xyk/benchmarking/src/mock.rs b/pallets/pool-xyk/benchmarking/src/mock.rs index 17f3aa13e9..d3e4dc2802 100644 --- a/pallets/pool-xyk/benchmarking/src/mock.rs +++ b/pallets/pool-xyk/benchmarking/src/mock.rs @@ -216,6 +216,7 @@ impl dex_api::Config for Runtime { type MulticollateralBondingCurvePool = (); type XYKPool = pool_xyk::Pallet; type XSTPool = (); + type DexInfoProvider = dex_manager::Pallet; #[cfg(feature = "ready-to-test")] // order-book type OrderBook = (); @@ -249,6 +250,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/pool-xyk/src/lib.rs b/pallets/pool-xyk/src/lib.rs index 5ca647ea25..f337196bf9 100644 --- a/pallets/pool-xyk/src/lib.rs +++ b/pallets/pool-xyk/src/lib.rs @@ -44,9 +44,10 @@ use common::prelude::{ Balance, EnsureDEXManager, FixedWrapper, QuoteAmount, SwapAmount, SwapOutcome, }; use common::{ - fixed_wrapper, AssetInfoProvider, DexInfoProvider, EnsureTradingPairExists, GetPoolReserves, - LiquiditySource, LiquiditySourceType, ManagementMode, OnPoolReservesChanged, PoolXykPallet, - RewardReason, TechAccountId, TechPurpose, ToFeeAccount, TradingPair, TradingPairSourceManager, + fixed_wrapper, AssetInfoProvider, DEXInfo, DexInfoProvider, EnsureTradingPairExists, + GetPoolReserves, LiquiditySource, LiquiditySourceType, ManagementMode, OnPoolReservesChanged, + PoolXykPallet, RewardReason, TechAccountId, TechPurpose, ToFeeAccount, TradingPair, + TradingPairSourceManager, }; mod aliases; @@ -180,8 +181,7 @@ impl Pallet { (asset_a_pair.0, asset_b_pair.0) }; - // TODO: #441 use TradingPairSourceManager instead of trading-pair pallet - trading_pair::Pallet::::enable_source_for_trading_pair( + T::TradingPairSourceManager::enable_source_for_trading_pair( dex_id, sorted_asset_a, sorted_asset_b, @@ -242,7 +242,7 @@ impl Pallet { // can be done, check every condition for `PoolIsAlreadyInitialized`. if technical::Pallet::::ensure_tech_account_registered(&tech_acc_id).is_ok() { if technical::Pallet::::ensure_tech_account_registered(&fee_acc_id).is_ok() - && trading_pair::Pallet::::ensure_trading_pair_exists( + && T::EnsureTradingPairExists::ensure_trading_pair_exists( &dex_id, &trading_pair.base_asset_id.into(), &trading_pair.target_asset_id.into(), @@ -642,19 +642,17 @@ use sp_runtime::traits::Zero; #[frame_support::pallet] pub mod pallet { use super::*; - use common::{AccountIdOf, Fixed, GetMarketInfo, OnPoolCreated}; + use common::{AccountIdOf, EnabledSourcesManager, Fixed, GetMarketInfo, OnPoolCreated}; use frame_support::pallet_prelude::*; use frame_support::traits::StorageVersion; use frame_system::pallet_prelude::*; use orml_traits::GetByKey; // TODO: #395 use AssetInfoProvider instead of assets pallet - // TODO: #441 use TradingPairSourceManager instead of trading-pair pallet #[pallet::config] pub trait Config: frame_system::Config + technical::Config - + trading_pair::Config + ceres_liquidity_locker::Config + demeter_farming_platform::Config { @@ -676,6 +674,14 @@ pub mod pallet { + Into<::SwapAction> + From>; type EnsureDEXManager: EnsureDEXManager; + type TradingPairSourceManager: TradingPairSourceManager; + type DexInfoProvider: DexInfoProvider>; + type EnabledSourcesManager: EnabledSourcesManager; + type EnsureTradingPairExists: EnsureTradingPairExists< + Self::DEXId, + Self::AssetId, + DispatchError, + >; type XSTMarketInfo: GetMarketInfo; type GetFee: Get; type OnPoolCreated: OnPoolCreated, DEXId = DEXIdOf>; diff --git a/pallets/pool-xyk/src/migrations/v3.rs b/pallets/pool-xyk/src/migrations/v3.rs index 9f82fa179e..e0f3cd90e4 100644 --- a/pallets/pool-xyk/src/migrations/v3.rs +++ b/pallets/pool-xyk/src/migrations/v3.rs @@ -29,7 +29,7 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use crate::pallet::{Config, Pallet}; -use common::{Balance, LiquiditySourceType, ToFeeAccount, TradingPair}; +use common::{Balance, EnabledSourcesManager, ToFeeAccount}; use frame_support::pallet_prelude::{Get, StorageVersion}; use frame_support::traits::OnRuntimeUpgrade; use frame_support::weights::WeightMeter; @@ -43,7 +43,6 @@ use sp_std::prelude::Vec; use crate::{PoolProviders, Properties, Reserves, TotalIssuances, WeightInfo}; use ceres_liquidity_locker::LockerData; use demeter_farming_platform::UserInfos; -use trading_pair::EnabledSources; pub struct XYKPoolUpgrade(core::marker::PhantomData<(T, L)>); @@ -118,16 +117,11 @@ where let (_, tech_acc_id) = Pallet::::tech_account_from_dex_and_asset_pair(dex_id, base_asset, target_asset)?; - let pair = TradingPair:: { - base_asset_id: base_asset.clone(), - target_asset_id: target_asset.clone(), - }; - - EnabledSources::::mutate(&dex_id, &pair, |opt_set| { - if let Some(sources) = opt_set.as_mut() { - sources.remove(&LiquiditySourceType::XYKPool); - } - }); + T::EnabledSourcesManager::mutate_remove( + &dex_id, + &base_asset.clone(), + &target_asset.clone(), + ); Properties::::remove(base_asset, target_asset); let fee_acc_id = tech_acc_id diff --git a/pallets/pool-xyk/src/mock.rs b/pallets/pool-xyk/src/mock.rs index 22dfa5951c..e39d4a48af 100644 --- a/pallets/pool-xyk/src/mock.rs +++ b/pallets/pool-xyk/src/mock.rs @@ -337,6 +337,10 @@ impl Config for Runtime { crate::WithdrawLiquidityAction; type PolySwapAction = crate::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/pool-xyk/src/utils.rs b/pallets/pool-xyk/src/utils.rs index fb6e0b35a0..1e15e97168 100644 --- a/pallets/pool-xyk/src/utils.rs +++ b/pallets/pool-xyk/src/utils.rs @@ -32,15 +32,14 @@ use frame_support::dispatch::{DispatchError, DispatchResult}; use frame_support::{ensure, fail}; use orml_traits::GetByKey; +use crate::aliases::{AssetIdOf, TechAccountIdOf, TechAssetIdOf}; +use crate::bounds::*; +use crate::{Config, Error, Pallet, PoolProviders, TotalIssuances}; use common::prelude::{Balance, SwapAmount}; use common::{ AccountIdOf, DexInfoProvider, ToFeeAccount, ToXykTechUnitFromDEXAndTradingPair, TradingPair, }; -use crate::aliases::{AssetIdOf, TechAccountIdOf, TechAssetIdOf}; -use crate::bounds::*; -use crate::{Config, Error, Pallet, PoolProviders, TotalIssuances}; - impl Pallet { pub fn decide_is_fee_from_destination( base_asset_id: &AssetIdOf, diff --git a/pallets/price-tools/Cargo.toml b/pallets/price-tools/Cargo.toml index 0013801b85..d8455a1c01 100644 --- a/pallets/price-tools/Cargo.toml +++ b/pallets/price-tools/Cargo.toml @@ -35,7 +35,6 @@ common = { path = "../../common", default-features = false } dex-api = { path = "../dex-api", default-features = false } permissions = { path = "../permissions", default-features = false } pswap-distribution = { path = "../pswap-distribution", default-features = false } -trading-pair = { path = "../trading-pair", default-features = false } pool-xyk = { path = "../pool-xyk", default-features = false } technical = { path = "../technical", default-features = false } pallet-timestamp = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } @@ -48,7 +47,6 @@ pallet-balances = { git = "https://github.com/sora-xor/substrate.git", branch = common = { path = "../../common", features = ["test"] } dex-manager = { path = "../dex-manager" } mock-liquidity-source = { path = "../mock-liquidity-source" } -trading-pair = { path = "../trading-pair" } [features] default = ['std'] diff --git a/pallets/price-tools/src/benchmarking.rs b/pallets/price-tools/src/benchmarking.rs index 6df87805b5..af20cf9568 100644 --- a/pallets/price-tools/src/benchmarking.rs +++ b/pallets/price-tools/src/benchmarking.rs @@ -82,8 +82,12 @@ fn create_pair_with_xor( ) { assets::Pallet::::mint(origin.clone(), asset, owner, balance!(1000000)).unwrap(); - trading_pair::Pallet::::register(origin.clone(), DEXId::Polkaswap.into(), XOR.into(), asset) - .unwrap(); + ::TradingPairSourceManager::register_pair( + DEXId::Polkaswap.into(), + XOR.into(), + asset, + ) + .unwrap(); pool_xyk::Pallet::::initialize_pool( origin.clone(), diff --git a/pallets/price-tools/src/lib.rs b/pallets/price-tools/src/lib.rs index 83c719e508..857094a99d 100644 --- a/pallets/price-tools/src/lib.rs +++ b/pallets/price-tools/src/lib.rs @@ -52,6 +52,7 @@ pub mod migration; use codec::{Decode, Encode}; use common::prelude::{ Balance, Fixed, FixedWrapper, LiquiditySourceType, PriceToolsPallet, QuoteAmount, + TradingPairSourceManager, }; use common::{ balance, fixed_const, fixed_wrapper, DEXId, LiquidityProxyTrait, LiquiditySourceFilter, @@ -140,10 +141,10 @@ pub mod pallet { + common::Config + technical::Config + pool_xyk::Config - + trading_pair::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type LiquidityProxy: LiquidityProxyTrait; + type TradingPairSourceManager: TradingPairSourceManager; type WeightInfo: WeightInfo; } @@ -378,7 +379,7 @@ impl Pallet { /// Get current spot price for pub fn spot_price(asset_id: &T::AssetId) -> Result { - ::LiquidityProxy::quote( + T::LiquidityProxy::quote( DEXId::Polkaswap.into(), &XOR.into(), &asset_id, diff --git a/pallets/price-tools/src/mock.rs b/pallets/price-tools/src/mock.rs index 97238223fe..e1aa3a7a9e 100644 --- a/pallets/price-tools/src/mock.rs +++ b/pallets/price-tools/src/mock.rs @@ -107,7 +107,6 @@ construct_runtime! { { System: frame_system::{Pallet, Call, Config, Storage, Event}, DexManager: dex_manager::{Pallet, Call, Storage}, - TradingPair: trading_pair::{Pallet, Call, Storage, Event}, MockLiquiditySource: mock_liquidity_source::::{Pallet, Call, Config, Storage}, Tokens: tokens::{Pallet, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, @@ -153,13 +152,6 @@ impl frame_system::Config for Runtime { impl dex_manager::Config for Runtime {} -impl trading_pair::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type EnsureDEXManager = dex_manager::Pallet; - type DexInfoProvider = dex_manager::Pallet; - type WeightInfo = (); -} - impl mock_liquidity_source::Config for Runtime { type GetFee = (); type EnsureDEXManager = (); @@ -170,6 +162,7 @@ impl mock_liquidity_source::Config for Runtime impl Config for Runtime { type RuntimeEvent = RuntimeEvent; type LiquidityProxy = MockDEXApi; + type TradingPairSourceManager = TradingPair; type WeightInfo = (); } @@ -278,6 +271,62 @@ impl demeter_farming_platform::Config for Runtime { type WeightInfo = (); } +pub struct TradingPair; + +impl common::TradingPairSourceManager for TradingPair { + fn list_enabled_sources_for_trading_pair( + _dex_id: &DEXId, + _base_asset_id: &AssetId, + _target_asset_id: &AssetId, + ) -> Result, DispatchError> + { + Ok(Default::default()) + } + + fn is_source_enabled_for_trading_pair( + _dex_id: &DEXId, + _base_asset_id: &AssetId, + _target_asset_id: &AssetId, + _source_type: LiquiditySourceType, + ) -> Result { + Ok(false) + } + + fn enable_source_for_trading_pair( + _dex_id: &DEXId, + _base_asset_id: &AssetId, + _target_asset_id: &AssetId, + _source_type: LiquiditySourceType, + ) -> frame_support::pallet_prelude::DispatchResult { + Ok(()) + } + + fn disable_source_for_trading_pair( + _dex_id: &DEXId, + _base_asset_id: &AssetId, + _target_asset_id: &AssetId, + _source_type: LiquiditySourceType, + ) -> frame_support::pallet_prelude::DispatchResult { + Ok(()) + } + + fn is_trading_pair_enabled( + _dex_id: &DEXId, + _base_asset_id: &AssetId, + _target_asset_id: &AssetId, + ) -> Result { + Ok(false) + } + + fn register_pair( + _dex_id: DEXId, + _base_asset_id: AssetId, + _target_asset_id: AssetId, + ) -> Result<(), DispatchError> { + Ok(()) + } +} + impl pool_xyk::Config for Runtime { const MIN_XOR: Balance = balance!(0.0007); type RuntimeEvent = RuntimeEvent; @@ -288,6 +337,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = TradingPair; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = (); + type EnabledSourcesManager = (); type GetFee = GetXykFee; type OnPoolCreated = pswap_distribution::Pallet; type OnPoolReservesChanged = PriceTools; diff --git a/pallets/pswap-distribution/Cargo.toml b/pallets/pswap-distribution/Cargo.toml index b2485afa7d..0a74ea646d 100644 --- a/pallets/pswap-distribution/Cargo.toml +++ b/pallets/pswap-distribution/Cargo.toml @@ -37,7 +37,6 @@ common = { path = "../../common", default-features = false } dex-manager = { path = "../dex-manager", default-features = false } permissions = { path = "../permissions", default-features = false } technical = { path = "../technical", default-features = false } -trading-pair = { path = "../trading-pair", default-features = false } pallet-timestamp = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } [dev-dependencies] @@ -51,7 +50,6 @@ dex-manager = { path = "../dex-manager" } mock-liquidity-source = { path = "../mock-liquidity-source" } pool-xyk = { path = "../pool-xyk" } technical = { path = "../technical" } -trading-pair = { path = "../trading-pair" } [features] default = ['std'] @@ -69,7 +67,6 @@ std = [ 'sp-io/std', 'sp-std/std', 'tokens/std', - 'trading-pair/std', 'traits/std', ] diff --git a/pallets/pswap-distribution/benchmarking/src/mock.rs b/pallets/pswap-distribution/benchmarking/src/mock.rs index 39f970332e..beaf93ae05 100644 --- a/pallets/pswap-distribution/benchmarking/src/mock.rs +++ b/pallets/pswap-distribution/benchmarking/src/mock.rs @@ -295,6 +295,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/pswap-distribution/src/mock.rs b/pallets/pswap-distribution/src/mock.rs index e8fbaceb1e..bfb3cfb104 100644 --- a/pallets/pswap-distribution/src/mock.rs +++ b/pallets/pswap-distribution/src/mock.rs @@ -144,7 +144,6 @@ construct_runtime! { Balances: pallet_balances::{Pallet, Call, Config, Storage, Event}, Technical: technical::{Pallet, Call, Storage, Event}, DexManager: dex_manager::{Pallet, Call, Storage}, - TradingPair: trading_pair::{Pallet, Call, Config, Storage, Event}, PoolXYK: pool_xyk::{Pallet, Call, Storage, Event}, CeresLiquidityLocker: ceres_liquidity_locker::{Pallet, Call, Storage, Event}, DemeterFarmingPlatform: demeter_farming_platform::{Pallet, Call, Storage, Event}, @@ -279,13 +278,6 @@ impl technical::Config for Runtime { impl dex_manager::Config for Runtime {} -impl trading_pair::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type EnsureDEXManager = dex_manager::Pallet; - type DexInfoProvider = dex_manager::Pallet; - type WeightInfo = (); -} - impl demeter_farming_platform::Config for Runtime { type RuntimeEvent = RuntimeEvent; type DemeterAssetId = (); @@ -303,6 +295,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = (); + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = (); + type EnabledSourcesManager = (); type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/pallets/qa-tools/Cargo.toml b/pallets/qa-tools/Cargo.toml index 2d4211265f..88f8efbd4f 100644 --- a/pallets/qa-tools/Cargo.toml +++ b/pallets/qa-tools/Cargo.toml @@ -22,7 +22,6 @@ frame-support = { git = "https://github.com/sora-xor/substrate.git", branch = "p frame-system = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } assets = { path = "../assets", default-features = false } order-book = { path = "../../pallets/order-book", default-features = false } -trading-pair = { path = "../trading-pair", default-features = false } [dev-dependencies] framenode-chain-spec = { path = "../../node/chain_spec", features = ["test"] } diff --git a/pallets/qa-tools/src/lib.rs b/pallets/qa-tools/src/lib.rs index 67da407db2..2e2c175eea 100644 --- a/pallets/qa-tools/src/lib.rs +++ b/pallets/qa-tools/src/lib.rs @@ -58,7 +58,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + order_book::Config + trading_pair::Config { + pub trait Config: frame_system::Config + order_book::Config { type WeightInfo: WeightInfo; type AssetInfoProvider: AssetInfoProvider< Self::AssetId, diff --git a/pallets/qa-tools/src/pallets/order_book_tools.rs b/pallets/qa-tools/src/pallets/order_book_tools.rs index 8f7ad2ecd4..2829264616 100644 --- a/pallets/qa-tools/src/pallets/order_book_tools.rs +++ b/pallets/qa-tools/src/pallets/order_book_tools.rs @@ -29,7 +29,7 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use crate::Config; -use common::{balance, Balance, PriceVariant}; +use common::{balance, Balance, PriceVariant, TradingPairSourceManager}; use frame_support::pallet_prelude::*; use frame_support::traits::Time; use frame_system::pallet_prelude::*; @@ -79,12 +79,12 @@ pub fn create_multiple_empty_unchecked( .filter(|(id, _)| !>::contains_key(id)) .collect(); for (order_book_id, _) in &to_create_ids { - if !trading_pair::Pallet::::is_trading_pair_enabled( + if !T::TradingPairSourceManager::is_trading_pair_enabled( &order_book_id.dex_id, &order_book_id.quote.into(), &order_book_id.base.into(), )? { - trading_pair::Pallet::::register_pair( + T::TradingPairSourceManager::register_pair( order_book_id.dex_id, order_book_id.quote.into(), order_book_id.base.into(), diff --git a/pallets/technical/Cargo.toml b/pallets/technical/Cargo.toml index f1111346f5..2f8143430b 100644 --- a/pallets/technical/Cargo.toml +++ b/pallets/technical/Cargo.toml @@ -32,7 +32,6 @@ twox-hash = { version = "1.5.0", default-features = false } assets = { path = "../assets", default-features = false } common = { path = "../../common", default-features = false } permissions = { path = "../permissions", default-features = false, optional = true } -trading-pair = { path = "../trading-pair", default-features = false, optional = true } [dev-dependencies] sp-core = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false } @@ -62,7 +61,6 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-system/runtime-benchmarks", "frame-support/runtime-benchmarks", - "trading-pair", "permissions", "hex-literal", diff --git a/pallets/trading-pair/src/lib.rs b/pallets/trading-pair/src/lib.rs index 677b98de85..14329502af 100644 --- a/pallets/trading-pair/src/lib.rs +++ b/pallets/trading-pair/src/lib.rs @@ -37,11 +37,13 @@ extern crate alloc; use common::{ - AssetInfoProvider, DexInfoProvider, EnsureDEXManager, EnsureTradingPairExists, - LiquiditySourceType, ManagementMode, TradingPairSourceManager, + AssetInfoProvider, DexInfoProvider, EnabledSourcesManager, EnsureDEXManager, + EnsureTradingPairExists, LiquiditySourceType, LockedLiquiditySourcesManager, ManagementMode, + TradingPairSourceManager, }; use frame_support::dispatch::{DispatchError, DispatchResult}; use frame_support::ensure; +use frame_support::pallet_prelude::DispatchResultWithPostInfo; use frame_support::traits::IsType; use sp_std::collections::btree_set::BTreeSet; use sp_std::vec::Vec; @@ -75,6 +77,36 @@ impl EnsureTradingPairExists for } } +impl LockedLiquiditySourcesManager for Pallet { + fn get() -> Vec { + LockedLiquiditySources::::get() + } + fn set(liquidity_source_types: Vec) -> () { + LockedLiquiditySources::::set(liquidity_source_types) + } + fn append(liquidity_source_type: LiquiditySourceType) -> () { + LockedLiquiditySources::::append(liquidity_source_type) + } +} + +impl EnabledSourcesManager for Pallet { + fn mutate_remove( + dex_id: &T::DEXId, + base_asset_id: &T::AssetId, + target_asset_id: &T::AssetId, + ) -> () { + let pair = TradingPair:: { + base_asset_id: base_asset_id.clone(), + target_asset_id: target_asset_id.clone(), + }; + EnabledSources::::mutate(&dex_id, &pair, |opt_set| { + if let Some(sources) = opt_set.as_mut() { + sources.remove(&LiquiditySourceType::XYKPool); + } + }) + } +} + impl TradingPairSourceManager for Pallet { fn list_enabled_sources_for_trading_pair( dex_id: &T::DEXId, @@ -144,6 +176,22 @@ impl TradingPairSourceManager for Pallet { }); Ok(()) } + + fn is_trading_pair_enabled( + dex_id: &T::DEXId, + base_asset_id: &T::AssetId, + target_asset_id: &T::AssetId, + ) -> Result { + Self::is_trading_pair_enabled(dex_id, base_asset_id, target_asset_id) + } + + fn register_pair( + dex_id: T::DEXId, + base_asset_id: T::AssetId, + target_asset_id: T::AssetId, + ) -> Result<(), DispatchError> { + Self::register_pair(dex_id, base_asset_id, target_asset_id) + } } impl Pallet { diff --git a/pallets/trustless-bridge/ethereum-light-client/src/benchmarking/mod.rs b/pallets/trustless-bridge/ethereum-light-client/src/benchmarking/mod.rs index 28f7d614e8..c4f6495b3a 100644 --- a/pallets/trustless-bridge/ethereum-light-client/src/benchmarking/mod.rs +++ b/pallets/trustless-bridge/ethereum-light-client/src/benchmarking/mod.rs @@ -69,8 +69,8 @@ fn validate_dispatch(call: Call) -> Result<(), &'static str benchmarks! { where_clause { where - ::Submitter: From, - ::ImportSignature: From, + ::Submitter: From, + ::ImportSignature: From, } // Benchmark `import_header` extrinsic under worst case conditions: // * Import will set a new best block. @@ -85,7 +85,7 @@ benchmarks! { validate_unsigned_then_import_header { // We don't care about security but just about calculation time let caller_public = sp_io::crypto::sr25519_generate(123.into(), None); - let caller = ::Submitter::from(caller_public).into_account(); + let caller = ::Submitter::from(caller_public).into_account(); let descendants_until_final = T::DescendantsUntilFinalized::get(); @@ -114,7 +114,7 @@ benchmarks! { proof: header_proof, mix_nonce: header_mix_nonce, submitter: caller, - signature: ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) + signature: ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) }; }: { validate_dispatch(call)? } verify { @@ -152,7 +152,7 @@ benchmarks! { // re-insert using >::insert. import_header_not_new_finalized_with_max_prune { let caller_public = sp_io::crypto::sr25519_generate(123.into(), None); - let caller = ::Submitter::from(caller_public).into_account(); + let caller = ::Submitter::from(caller_public).into_account(); let descendants_until_final = T::DescendantsUntilFinalized::get(); @@ -187,7 +187,7 @@ benchmarks! { proof: header_proof, mix_nonce: header_mix_nonce, submitter: caller, - signature: ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) + signature: ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) }; }: { validate_dispatch(call)? } verify { @@ -221,7 +221,7 @@ benchmarks! { // * Import will prune a single old header with no siblings. import_header_new_finalized_with_single_prune { let caller_public = sp_io::crypto::sr25519_generate(123.into(), None); - let caller = ::Submitter::from(caller_public).into_account(); + let caller = ::Submitter::from(caller_public).into_account(); let descendants_until_final = T::DescendantsUntilFinalized::get(); @@ -251,7 +251,7 @@ benchmarks! { proof: header_proof, mix_nonce: header_mix_nonce, submitter: caller, - signature: ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) + signature: ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) }; }: { validate_dispatch(call)? } verify { @@ -282,7 +282,7 @@ benchmarks! { // * Import will prune a single old header with no siblings. import_header_not_new_finalized_with_single_prune { let caller_public = sp_io::crypto::sr25519_generate(123.into(), None); - let caller = ::Submitter::from(caller_public).into_account(); + let caller = ::Submitter::from(caller_public).into_account(); let descendants_until_final = T::DescendantsUntilFinalized::get(); @@ -317,7 +317,7 @@ benchmarks! { proof: header_proof, mix_nonce: header_mix_nonce, submitter: caller, - signature: ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) + signature: ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) }; }: { validate_dispatch(call)? } verify { @@ -353,7 +353,7 @@ benchmarks! { let header_mix_nonce = data::header_mix_nonce(header.compute_hash()).unwrap(); let caller_public = sp_io::crypto::sr25519_generate(123.into(), None); - let caller = ::Submitter::from(caller_public).into_account(); + let caller = ::Submitter::from(caller_public).into_account(); assert_ok!(EthereumLightClient::::import_header( RawOrigin::None.into(), @@ -362,7 +362,7 @@ benchmarks! { header_proof, header_mix_nonce, caller, - ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) + ::ImportSignature::from(digest_signature::(&caller_public, &EthNetworkConfig::Mainnet.chain_id(), &header)) )); } diff --git a/pallets/vested-rewards/Cargo.toml b/pallets/vested-rewards/Cargo.toml index 7973a9a458..9fa4cc0dd8 100644 --- a/pallets/vested-rewards/Cargo.toml +++ b/pallets/vested-rewards/Cargo.toml @@ -48,7 +48,6 @@ ceres-liquidity-locker = { path = "../ceres-liquidity-locker", default-features demeter-farming-platform = { path = "../demeter-farming-platform", default-features = false } dex-manager = { path = "../dex-manager" } permissions = { path = "../permissions" } -trading-pair = { path = "../trading-pair" } pool-xyk = { path = "../pool-xyk" } pswap-distribution = { path = "../pswap-distribution" } technical = { path = "../technical" } diff --git a/pallets/vested-rewards/src/mock.rs b/pallets/vested-rewards/src/mock.rs index bbc3a166bb..dedf5a1622 100644 --- a/pallets/vested-rewards/src/mock.rs +++ b/pallets/vested-rewards/src/mock.rs @@ -62,7 +62,6 @@ construct_runtime! { System: frame_system::{Pallet, Call, Config, Storage, Event}, Tokens: tokens::{Pallet, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, - TradingPair: trading_pair::{Pallet, Call, Storage, Event}, Currencies: currencies::{Pallet, Call, Storage}, Assets: assets::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Event}, @@ -248,13 +247,6 @@ impl assets::Config for Runtime { type WeightInfo = (); } -impl trading_pair::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type EnsureDEXManager = dex_manager::Pallet; - type DexInfoProvider = dex_manager::Pallet; - type WeightInfo = (); -} - impl technical::Config for Runtime { type RuntimeEvent = RuntimeEvent; type TechAssetId = TechAssetId; @@ -300,6 +292,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = (); + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = (); + type EnabledSourcesManager = (); type GetFee = GetXykFee; type OnPoolCreated = pswap_distribution::Pallet; type OnPoolReservesChanged = (); @@ -310,9 +306,10 @@ impl pool_xyk::Config for Runtime { impl multicollateral_bonding_curve_pool::Config for Runtime { type RuntimeEvent = RuntimeEvent; type LiquidityProxy = MockLiquidityProxy; - type EnsureTradingPairExists = trading_pair::Pallet; + type EnsureTradingPairExists = (); type EnsureDEXManager = dex_manager::Pallet; type VestedRewardsPallet = VestedRewards; + type TradingPairSourceManager = (); type PriceToolsPallet = (); type BuyBackHandler = (); type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; diff --git a/pallets/xst/benchmarking/src/mock.rs b/pallets/xst/benchmarking/src/mock.rs index ca0de09a5d..466cea0bd6 100644 --- a/pallets/xst/benchmarking/src/mock.rs +++ b/pallets/xst/benchmarking/src/mock.rs @@ -279,6 +279,7 @@ impl dex_api::Config for Runtime { type XYKPool = MockLiquiditySource; type XSTPool = XSTPool; type MulticollateralBondingCurvePool = (); + type DexInfoProvider = (); #[cfg(feature = "ready-to-test")] // order-book type OrderBook = (); @@ -347,6 +348,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); @@ -375,6 +380,7 @@ impl ceres_liquidity_locker::Config for Runtime { impl price_tools::Config for Runtime { type RuntimeEvent = RuntimeEvent; type LiquidityProxy = (); + type TradingPairSourceManager = (); type WeightInfo = (); } diff --git a/pallets/xst/src/lib.rs b/pallets/xst/src/lib.rs index 1ce041e5ed..0f94f1520f 100644 --- a/pallets/xst/src/lib.rs +++ b/pallets/xst/src/lib.rs @@ -132,11 +132,8 @@ pub mod pallet { use frame_support::{pallet_prelude::*, Parameter}; use frame_system::pallet_prelude::*; - // TODO: #441 use TradingPairSourceManager instead of trading-pair pallet #[pallet::config] - pub trait Config: - frame_system::Config + technical::Config + common::Config + trading_pair::Config - { + pub trait Config: frame_system::Config + technical::Config + common::Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// AssetId which is convertible to/from XSTUSD type GetSyntheticBaseAssetId: Get; @@ -516,7 +513,7 @@ impl Pallet { } fn enable_synthetic_trading_pair(synthetic_asset_id: T::AssetId) -> sp_runtime::DispatchResult { - if trading_pair::Pallet::::is_trading_pair_enabled( + if T::TradingPairSourceManager::is_trading_pair_enabled( &DEXId::Polkaswap.into(), &T::GetSyntheticBaseAssetId::get(), &synthetic_asset_id, @@ -524,7 +521,7 @@ impl Pallet { return Ok(()); } - trading_pair::Pallet::::register_pair( + T::TradingPairSourceManager::register_pair( DEXId::Polkaswap.into(), T::GetSyntheticBaseAssetId::get(), synthetic_asset_id, @@ -880,17 +877,16 @@ impl Pallet { /// Used for converting XST fee to XOR fn convert_fee(fee_amount: Balance) -> Result { - let output_to_base: FixedWrapper = - ::PriceToolsPallet::get_average_price( - &T::GetSyntheticBaseAssetId::get(), - &T::GetBaseAssetId::get(), - // Since `Buy` is more expensive in case if we are buying XOR - // (x XST -> y XOR; y XOR -> x' XST, x' < x), - // it seems logical to show this amount in order - // to not accidentally lie about the price. - PriceVariant::Buy, - )? - .into(); + let output_to_base: FixedWrapper = ::PriceToolsPallet::get_average_price( + &T::GetSyntheticBaseAssetId::get(), + &T::GetBaseAssetId::get(), + // Since `Buy` is more expensive in case if we are buying XOR + // (x XST -> y XOR; y XOR -> x' XST, x' < x), + // it seems logical to show this amount in order + // to not accidentally lie about the price. + PriceVariant::Buy, + )? + .into(); Ok((fee_amount * output_to_base) .try_into_balance() .map_err(|_| Error::::PriceCalculationFailed)?) diff --git a/pallets/xst/src/mock.rs b/pallets/xst/src/mock.rs index 64d90c83b7..b7d33be52a 100644 --- a/pallets/xst/src/mock.rs +++ b/pallets/xst/src/mock.rs @@ -280,6 +280,7 @@ impl dex_api::Config for Runtime { type XYKPool = MockLiquiditySource; type XSTPool = XSTPool; type MulticollateralBondingCurvePool = (); + type DexInfoProvider = (); #[cfg(feature = "ready-to-test")] // order-book type OrderBook = (); @@ -334,6 +335,7 @@ impl pswap_distribution::Config for Runtime { impl price_tools::Config for Runtime { type RuntimeEvent = RuntimeEvent; type LiquidityProxy = (); + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = price_tools::weights::SubstrateWeight; } @@ -354,6 +356,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetXykFee; type OnPoolCreated = PswapDistribution; type OnPoolReservesChanged = (); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9299076555..ac6d772d07 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1002,6 +1002,10 @@ impl pool_xyk::Config for Runtime { pool_xyk::WithdrawLiquidityAction; type PolySwapAction = pool_xyk::PolySwapAction; type EnsureDEXManager = dex_manager::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; + type DexInfoProvider = dex_manager::Pallet; + type EnsureTradingPairExists = trading_pair::Pallet; + type EnabledSourcesManager = trading_pair::Pallet; type GetFee = GetFee; type OnPoolCreated = (PswapDistribution, Farming); type OnPoolReservesChanged = PriceTools; @@ -1056,6 +1060,9 @@ impl liquidity_proxy::Config for Runtime { type SecondaryMarket = pool_xyk::Pallet; type WeightInfo = liquidity_proxy::weights::SubstrateWeight; type VestedRewardsPallet = VestedRewards; + type DexInfoProvider = dex_manager::Pallet; + type LockedLiquiditySourcesManager = trading_pair::Pallet; + type TradingPairSourceManager = trading_pair::Pallet; type GetADARAccountId = GetADARAccountId; type ADARCommissionRatioUpdateOrigin = EitherOfDiverse< pallet_collective::EnsureProportionMoreThan, @@ -1105,6 +1112,7 @@ impl dex_api::Config for Runtime { type MulticollateralBondingCurvePool = multicollateral_bonding_curve_pool::Pallet; type XYKPool = pool_xyk::Pallet; type XSTPool = xst::Pallet; + type DexInfoProvider = dex_manager::Pallet; #[cfg(feature = "ready-to-test")] // order-book type OrderBook = order_book::Pallet; @@ -1578,6 +1586,7 @@ impl farming::Config for Runtime { type SchedulerOriginCaller = OriginCaller; type Scheduler = Scheduler; type RewardDoublingAssets = FarmingRewardDoublingAssets; + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = (); } @@ -1681,6 +1690,7 @@ impl multicollateral_bonding_curve_pool::Config for Runtime { type EnsureTradingPairExists = TradingPair; type PriceToolsPallet = PriceTools; type VestedRewardsPallet = VestedRewards; + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = multicollateral_bonding_curve_pool::weights::SubstrateWeight; type BuyBackHandler = liquidity_proxy::LiquidityProxyBuyBackHandler; type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent; @@ -1741,6 +1751,7 @@ impl vested_rewards::Config for Runtime { impl price_tools::Config for Runtime { type RuntimeEvent = RuntimeEvent; type LiquidityProxy = LiquidityProxy; + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = price_tools::weights::SubstrateWeight; } @@ -1814,6 +1825,7 @@ parameter_types! { impl ceres_launchpad::Config for Runtime { const MILLISECONDS_PER_DAY: Moment = 86_400_000; type RuntimeEvent = RuntimeEvent; + type TradingPairSourceManager = trading_pair::Pallet; type WeightInfo = ceres_launchpad::weights::SubstrateWeight; }