#[pallet::call_index(0)]#[pallet::weight(Weight::default())]pub fn create_liquidity_pool(origin: OriginFor<T>,asset_a: AssetIdOf<T>,asset_b: AssetIdOf<T>,liquidity_token: AssetIdOf<T>,) -> DispatchResult {// ensure that the origin has been signedlet sender = ensure_signed(origin)?;let trading_pair = (asset_a, asset_b);ensure!(!LiquidityPools::<T>::contains_key(trading_pair),Error::<T>::LiquidityPoolAlreadyExists);// Create a new liquidity poollet liquidity_pool = LiquidityPool {assets: trading_pair,reserves: (Zero::zero(), Zero::zero()),total_liquidity: Zero::zero(),liquidity_token,};// Insert the new liquidity pool into the storageLiquidityPools::<T>::insert(trading_pair, liquidity_pool);// Log an event indicating that the pool was createdSelf::deposit_event(Event::LiquidityPoolCreated(sender, trading_pair));Ok(())}
Make sure to update your pallet's Error
enum to include the LiquidityPoolAlreadyExists
variant, and add
the LiquidityPoolCreated
variant to your Event enum.
No files edited in this step.