Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions common/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ pub trait TradingPairSourceManager<DEXId, AssetId> {
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<bool, DispatchError>;

fn register_pair(
dex_id: DEXId,
base_asset_id: AssetId,
target_asset_id: AssetId,
) -> Result<(), DispatchError>;
}

impl<DEXId, AssetId> TradingPairSourceManager<DEXId, AssetId> for () {
Expand Down Expand Up @@ -157,6 +169,22 @@ impl<DEXId, AssetId> TradingPairSourceManager<DEXId, AssetId> for () {
) -> DispatchResult {
Err(DispatchError::CannotLookup)
}

fn is_trading_pair_enabled(
_dex_id: &DEXId,
_base_asset_id: &AssetId,
_target_asset_id: &AssetId,
) -> Result<bool, DispatchError> {
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.
Expand Down Expand Up @@ -216,6 +244,24 @@ pub trait LiquiditySource<TargetId, AccountId, AssetId, Amount, Error> {
fn check_rewards_weight() -> Weight;
}

/// Implements trading pairs LockedLiquiditySources storage
pub trait LockedLiquiditySourcesManager<LiquiditySourceType> {
fn get() -> Vec<LiquiditySourceType>;
fn set(liquidity_source_types: Vec<LiquiditySourceType>) -> ();
fn append(liquidity_source_type: LiquiditySourceType) -> ();
}

/// Implements trading pair EnabledSources storage
pub trait EnabledSourcesManager<DEXId, AssetId> {
fn mutate_remove(dex_id: &DEXId, base_asset_id: &AssetId, target_asset_id: &AssetId) -> ();
}

impl<DEXId, AssetId> EnabledSourcesManager<DEXId, AssetId> 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*
Expand Down
1 change: 0 additions & 1 deletion pallets/ceres-governance-platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 4 additions & 8 deletions pallets/ceres-governance-platform/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ construct_runtime! {
Currencies: currencies::{Pallet, Call, Storage},
Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},
DexManager: dex_manager::{Pallet, Call, Config<T>, Storage},
TradingPair: trading_pair::{Pallet, Call, Config<T>, Storage, Event<T>},
Permissions: permissions::{Pallet, Call, Config<T>, Storage, Event<T>},
Technical: technical::{Pallet, Call, Config<T>, Storage, Event<T>},
PoolXYK: pool_xyk::{Pallet, Call, Storage, Event<T>},
Expand Down Expand Up @@ -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<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type WeightInfo = ();
}

impl demeter_farming_platform::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type DemeterAssetId = ();
Expand All @@ -170,6 +162,10 @@ impl pool_xyk::Config for Runtime {
pool_xyk::WithdrawLiquidityAction<AssetId, AccountId, TechAccountId>;
type PolySwapAction = pool_xyk::PolySwapAction<AssetId, AccountId, TechAccountId>;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type TradingPairSourceManager = ();
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type EnsureTradingPairExists = ();
type EnabledSourcesManager = ();
type GetFee = GetXykFee;
type OnPoolCreated = PswapDistribution;
type OnPoolReservesChanged = ();
Expand Down
16 changes: 10 additions & 6 deletions pallets/ceres-launchpad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand All @@ -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<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

type TradingPairSourceManager: TradingPairSourceManager<Self::DEXId, Self::AssetId>;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}

type Assets<T> = assets::Pallet<T>;
pub type Timestamp<T> = timestamp::Pallet<T>;
type TradingPair<T> = trading_pair::Pallet<T>;
type PoolXYK<T> = pool_xyk::Pallet<T>;
type CeresLiquidityLocker<T> = ceres_liquidity_locker::Pallet<T>;
type TokenLocker<T> = ceres_token_locker::Pallet<T>;
Expand Down Expand Up @@ -399,8 +400,12 @@ pub mod pallet {
};

ensure!(
!TradingPair::<T>::is_trading_pair_enabled(&dex_id, &base_asset, &asset_id)
.unwrap_or(true),
!<T as Config>::TradingPairSourceManager::is_trading_pair_enabled(
&dex_id,
&base_asset,
&asset_id
)
.unwrap_or(true),
Error::<T>::CantCreateILOForListedToken
);

Expand Down Expand Up @@ -733,8 +738,7 @@ pub mod pallet {
DEXId::PolkaswapXSTUSD.into()
};
// Register trading pair
TradingPair::<T>::register(
RawOrigin::Signed(pallet_account.clone()).into(),
<T as Config>::TradingPairSourceManager::register_pair(
dex_id,
ilo_info.base_asset,
asset_id,
Expand Down
6 changes: 6 additions & 0 deletions pallets/ceres-launchpad/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>;
type WeightInfo = ();
}

Expand Down Expand Up @@ -182,6 +183,10 @@ impl pool_xyk::Config for Runtime {
pool_xyk::WithdrawLiquidityAction<AssetId, AccountId, TechAccountId>;
type PolySwapAction = pool_xyk::PolySwapAction<AssetId, AccountId, TechAccountId>;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type EnsureTradingPairExists = trading_pair::Pallet<Runtime>;
type EnabledSourcesManager = trading_pair::Pallet<Runtime>;
type GetFee = GetXykFee;
type OnPoolCreated = PswapDistribution;
type OnPoolReservesChanged = ();
Expand All @@ -197,6 +202,7 @@ impl multicollateral_bonding_curve_pool::Config for Runtime {
type EnsureTradingPairExists = trading_pair::Pallet<Runtime>;
type PriceToolsPallet = ();
type VestedRewardsPallet = VestedRewards;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type BuyBackHandler = ();
type BuyBackTBCDPercent = GetTBCBuyBackTBCDPercent;
type WeightInfo = ();
Expand Down
19 changes: 7 additions & 12 deletions pallets/ceres-liquidity-locker/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<T: Config>(ceres_liquidity_locker::Pallet<T>);
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;

Expand All @@ -42,8 +44,6 @@ pub fn AUTHORITY<T: frame_system::Config>() -> T::AccountId {
fn setup_benchmark_assets_only<T: Config>() -> Result<(), &'static str> {
let owner = alice::<T>();
frame_system::Pallet::<T>::inc_providers(&owner);
let owner_origin: <T as frame_system::Config>::RuntimeOrigin =
RawOrigin::Signed(owner.clone()).into();
let ceres_asset_id = common::AssetId32::from_bytes(hex!(
"008bcfd2387d3fc453333557eecb0efe59fcba128769b2feefdd306e98e66440"
));
Expand Down Expand Up @@ -85,13 +85,8 @@ fn setup_benchmark_assets_only<T: Config>() -> Result<(), &'static str> {
None,
);

TradingPair::<T>::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::<T>::mint_to(&XOR.into(), &owner.clone(), &owner.clone(), balance!(50000))?;
Assets::<T>::mint_to(
Expand Down
5 changes: 5 additions & 0 deletions pallets/ceres-liquidity-locker/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl dex_api::Config for Runtime {
type MulticollateralBondingCurvePool = ();
type XYKPool = pool_xyk::Pallet<Runtime>;
type XSTPool = ();
type DexInfoProvider = dex_manager::Pallet<Runtime>;

#[cfg(feature = "ready-to-test")] // order-book
type OrderBook = ();
Expand Down Expand Up @@ -220,6 +221,10 @@ impl pool_xyk::Config for Runtime {
pool_xyk::WithdrawLiquidityAction<AssetId, AccountId, TechAccountId>;
type PolySwapAction = pool_xyk::PolySwapAction<AssetId, AccountId, TechAccountId>;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type EnsureTradingPairExists = trading_pair::Pallet<Runtime>;
type EnabledSourcesManager = trading_pair::Pallet<Runtime>;
type GetFee = GetXykFee;
type OnPoolCreated = PswapDistribution;
type OnPoolReservesChanged = ();
Expand Down
4 changes: 4 additions & 0 deletions pallets/ceres-liquidity-locker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ impl pool_xyk::Config for Runtime {
pool_xyk::WithdrawLiquidityAction<AssetId, AccountId, TechAccountId>;
type PolySwapAction = pool_xyk::PolySwapAction<AssetId, AccountId, TechAccountId>;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type TradingPairSourceManager = trading_pair::Pallet<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type EnsureTradingPairExists = trading_pair::Pallet<Runtime>;
type EnabledSourcesManager = trading_pair::Pallet<Runtime>;
type GetFee = GetFee;
type OnPoolCreated = PswapDistribution;
type OnPoolReservesChanged = ();
Expand Down
1 change: 0 additions & 1 deletion pallets/ceres-token-locker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
12 changes: 4 additions & 8 deletions pallets/ceres-token-locker/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ construct_runtime! {
Currencies: currencies::{Pallet, Call, Storage},
Balances: pallet_balances::{Pallet, Call, Storage, Event<T>},
DexManager: dex_manager::{Pallet, Call, Config<T>, Storage},
TradingPair: trading_pair::{Pallet, Call, Config<T>, Storage, Event<T>},
Permissions: permissions::{Pallet, Call, Config<T>, Storage, Event<T>},
Technical: technical::{Pallet, Call, Config<T>, Storage, Event<T>},
PoolXYK: pool_xyk::{Pallet, Call, Storage, Event<T>},
Expand Down Expand Up @@ -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<Runtime>;
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type WeightInfo = ();
}

impl demeter_farming_platform::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type DemeterAssetId = ();
Expand All @@ -168,6 +160,10 @@ impl pool_xyk::Config for Runtime {
pool_xyk::WithdrawLiquidityAction<AssetId, AccountId, TechAccountId>;
type PolySwapAction = pool_xyk::PolySwapAction<AssetId, AccountId, TechAccountId>;
type EnsureDEXManager = dex_manager::Pallet<Runtime>;
type TradingPairSourceManager = ();
type DexInfoProvider = dex_manager::Pallet<Runtime>;
type EnsureTradingPairExists = ();
type EnabledSourcesManager = ();
type GetFee = GetXykFee;
type OnPoolCreated = PswapDistribution;
type OnPoolReservesChanged = ();
Expand Down
Loading