diff --git a/api/lib/src/lib.rs b/api/lib/src/lib.rs index 874c412c37..6b174b9226 100644 --- a/api/lib/src/lib.rs +++ b/api/lib/src/lib.rs @@ -360,7 +360,7 @@ pub trait BrokerApi: SignedExtrinsicApi { source_chain_expiry_block: *source_chain_expiry_block, }) } else { - panic!("SwapDepositAddressReady must have been generated"); + bail!("No SwapDepositAddressReady event was found"); } } } diff --git a/api/lib/src/lp.rs b/api/lib/src/lp.rs index f14b868d1a..1815e8a798 100644 --- a/api/lib/src/lp.rs +++ b/api/lib/src/lp.rs @@ -1,6 +1,6 @@ use std::ops::Range; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use async_trait::async_trait; pub use cf_amm::{ common::{Order, SideMap, Tick}, @@ -131,7 +131,7 @@ pub trait LpApi: SignedExtrinsicApi { .until_in_block() .await?; - Ok(events + events .into_iter() .find_map(|event| match event { state_chain_runtime::RuntimeEvent::LiquidityProvider( @@ -139,7 +139,7 @@ pub trait LpApi: SignedExtrinsicApi { ) => Some(deposit_address), _ => None, }) - .expect("DepositAddressReady must have been generated")) + .ok_or_else(|| anyhow::anyhow!("No LiquidityDepositAddressReady event was found")) } async fn withdraw_asset( @@ -148,6 +148,10 @@ pub trait LpApi: SignedExtrinsicApi { asset: Asset, destination_address: EncodedAddress, ) -> Result { + if amount == 0 { + bail!("Withdrawal amount must be greater than 0"); + } + let (_tx_hash, events, ..) = self .submit_signed_extrinsic(pallet_cf_lp::Call::withdraw_asset { amount, @@ -158,7 +162,7 @@ pub trait LpApi: SignedExtrinsicApi { .until_in_block() .await?; - Ok(events + events .into_iter() .find_map(|event| match event { state_chain_runtime::RuntimeEvent::LiquidityProvider( @@ -166,7 +170,7 @@ pub trait LpApi: SignedExtrinsicApi { ) => Some(egress_id), _ => None, }) - .expect("WithdrawalEgressScheduled must have been generated")) + .ok_or_else(|| anyhow::anyhow!("No WithdrawalEgressScheduled event was found")) } async fn update_range_order(