mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-11 21:49:26 +00:00
only create the pool when adding liquidity first time
This commit is contained in:
@@ -378,31 +378,6 @@ pub mod pallet {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pallet::genesis_config]
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
|
|
||||||
pub struct GenesisConfig<T: Config> {
|
|
||||||
/// Pools to create at launch.
|
|
||||||
pub pools: Vec<Coin>,
|
|
||||||
/// field just to have T.
|
|
||||||
pub _ignore: PhantomData<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Config> Default for GenesisConfig<T> {
|
|
||||||
fn default() -> Self {
|
|
||||||
GenesisConfig { pools: Default::default(), _ignore: Default::default() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pallet::genesis_build]
|
|
||||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
|
||||||
fn build(&self) {
|
|
||||||
// create the pools
|
|
||||||
for coin in &self.pools {
|
|
||||||
Pallet::<T>::create_pool(*coin).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pallet::error]
|
#[pallet::error]
|
||||||
pub enum Error<T> {
|
pub enum Error<T> {
|
||||||
/// Provided coins are equal.
|
/// Provided coins are equal.
|
||||||
@@ -515,19 +490,15 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// Once a pool is created, someone may [`Pallet::add_liquidity`] to it.
|
/// Once a pool is created, someone may [`Pallet::add_liquidity`] to it.
|
||||||
pub(crate) fn create_pool(coin: Coin) -> DispatchResult {
|
pub(crate) fn create_pool(coin: Coin) -> DispatchResult {
|
||||||
ensure!(coin != Coin::Serai, Error::<T>::EqualCoins);
|
// get pool_id
|
||||||
|
let pool_id = Self::get_pool_id(coin, Coin::Serai)?;
|
||||||
// prepare pool_id
|
|
||||||
let pool_id = Self::get_pool_id(coin, Coin::Serai).unwrap();
|
|
||||||
ensure!(!Pools::<T>::contains_key(pool_id), Error::<T>::PoolExists);
|
ensure!(!Pools::<T>::contains_key(pool_id), Error::<T>::PoolExists);
|
||||||
|
|
||||||
let pool_account = Self::get_pool_account(pool_id);
|
let pool_account = Self::get_pool_account(pool_id);
|
||||||
frame_system::Pallet::<T>::inc_providers(&pool_account);
|
frame_system::Pallet::<T>::inc_providers(&pool_account);
|
||||||
|
|
||||||
Pools::<T>::insert(pool_id, ());
|
Pools::<T>::insert(pool_id, ());
|
||||||
|
|
||||||
Self::deposit_event(Event::PoolCreated { pool_id, pool_account });
|
Self::deposit_event(Event::PoolCreated { pool_id, pool_account });
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,11 +537,14 @@ pub mod pallet {
|
|||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let sender = ensure_signed(origin)?;
|
let sender = ensure_signed(origin)?;
|
||||||
ensure!((sri_desired > 0) && (coin_desired > 0), Error::<T>::WrongDesiredAmount);
|
ensure!((sri_desired > 0) && (coin_desired > 0), Error::<T>::WrongDesiredAmount);
|
||||||
ensure!(coin != Coin::Serai, Error::<T>::EqualCoins);
|
|
||||||
|
|
||||||
let pool_id = Self::get_pool_id(coin, Coin::Serai).unwrap();
|
let pool_id = Self::get_pool_id(coin, Coin::Serai)?;
|
||||||
|
|
||||||
Pools::<T>::get(pool_id).as_ref().ok_or(Error::<T>::PoolNotFound)?;
|
// create the pool if it doesn't exist. We can just attempt to do that because our checks
|
||||||
|
// far enough to allow that.
|
||||||
|
if Pools::<T>::get(pool_id).is_none() {
|
||||||
|
Self::create_pool(coin)?;
|
||||||
|
}
|
||||||
let pool_account = Self::get_pool_account(pool_id);
|
let pool_account = Self::get_pool_account(pool_id);
|
||||||
|
|
||||||
let sri_reserve = Self::get_balance(&pool_account, Coin::Serai);
|
let sri_reserve = Self::get_balance(&pool_account, Coin::Serai);
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ use sc_service::ChainType;
|
|||||||
|
|
||||||
use serai_runtime::{
|
use serai_runtime::{
|
||||||
primitives::*, WASM_BINARY, BABE_GENESIS_EPOCH_CONFIG, RuntimeGenesisConfig, SystemConfig,
|
primitives::*, WASM_BINARY, BABE_GENESIS_EPOCH_CONFIG, RuntimeGenesisConfig, SystemConfig,
|
||||||
CoinsConfig, DexConfig, ValidatorSetsConfig, SignalsConfig, BabeConfig, GrandpaConfig,
|
CoinsConfig, ValidatorSetsConfig, SignalsConfig, BabeConfig, GrandpaConfig, EmissionsConfig,
|
||||||
EmissionsConfig, GenesisLiquidityConfig,
|
GenesisLiquidityConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;
|
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;
|
||||||
@@ -44,11 +44,6 @@ fn devnet_genesis(
|
|||||||
_ignore: Default::default(),
|
_ignore: Default::default(),
|
||||||
},
|
},
|
||||||
|
|
||||||
dex: DexConfig {
|
|
||||||
pools: vec![Coin::Bitcoin, Coin::Ether, Coin::Dai, Coin::Monero],
|
|
||||||
_ignore: Default::default(),
|
|
||||||
},
|
|
||||||
|
|
||||||
validator_sets: ValidatorSetsConfig {
|
validator_sets: ValidatorSetsConfig {
|
||||||
networks: serai_runtime::primitives::NETWORKS
|
networks: serai_runtime::primitives::NETWORKS
|
||||||
.iter()
|
.iter()
|
||||||
@@ -100,11 +95,6 @@ fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> Runtime
|
|||||||
_ignore: Default::default(),
|
_ignore: Default::default(),
|
||||||
},
|
},
|
||||||
|
|
||||||
dex: DexConfig {
|
|
||||||
pools: vec![Coin::Bitcoin, Coin::Ether, Coin::Dai, Coin::Monero],
|
|
||||||
_ignore: Default::default(),
|
|
||||||
},
|
|
||||||
|
|
||||||
validator_sets: ValidatorSetsConfig {
|
validator_sets: ValidatorSetsConfig {
|
||||||
networks: serai_runtime::primitives::NETWORKS
|
networks: serai_runtime::primitives::NETWORKS
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
Reference in New Issue
Block a user