diff --git a/api/bin/chainflip-lp-api/src/main.rs b/api/bin/chainflip-lp-api/src/main.rs index 16283a7c6c..c864344d50 100644 --- a/api/bin/chainflip-lp-api/src/main.rs +++ b/api/bin/chainflip-lp-api/src/main.rs @@ -1,3 +1,4 @@ +use crate::rpc_types::CloseOrderJson; use anyhow::anyhow; use cf_primitives::{BasisPoints, BlockNumber, EgressId}; use cf_utilities::{ @@ -49,6 +50,7 @@ use tracing::log; pub mod rpc_types { use super::*; use anyhow::anyhow; + use cf_primitives::chains::assets::any; use cf_utilities::rpc::NumberOrHex; use chainflip_api::{lp::PoolPairsMap, queries::SwapChannelInfo}; use serde::{Deserialize, Serialize}; @@ -97,6 +99,26 @@ pub mod rpc_types { pub bitcoin: Vec>, pub polkadot: Vec>, } + + #[derive(Copy, Clone, Debug, Serialize, Deserialize)] + #[serde(untagged)] + pub enum CloseOrderJson { + Limit { base_asset: any::Asset, quote_asset: any::Asset, side: Side, id: OrderIdJson }, + Range { base_asset: any::Asset, quote_asset: any::Asset, id: OrderIdJson }, + } + + impl TryFrom for CloseOrder { + type Error = anyhow::Error; + + fn try_from(value: CloseOrderJson) -> Result { + Ok(match value { + CloseOrderJson::Limit { base_asset, quote_asset, side, id } => + CloseOrder::Limit { base_asset, quote_asset, side, id: id.try_into()? }, + CloseOrderJson::Range { base_asset, quote_asset, id } => + CloseOrder::Range { base_asset, quote_asset, id: id.try_into()? }, + }) + } + } } #[rpc(server, client, namespace = "lp")] @@ -213,7 +235,7 @@ pub trait Rpc { #[method(name = "cancel_orders_batch")] async fn cancel_orders_batch( &self, - orders: BoundedVec>, + orders: BoundedVec>, wait_for: Option, ) -> RpcResult>>; } @@ -601,13 +623,21 @@ impl RpcServer for RpcServerImpl { async fn cancel_orders_batch( &self, - orders: BoundedVec>, + orders: BoundedVec>, wait_for: Option, ) -> RpcResult>> { Ok(self .api .lp_api() - .cancel_orders_batch(orders, wait_for.unwrap_or_default()) + .cancel_orders_batch( + orders + .into_iter() + .map(TryInto::try_into) + .collect::, _>>()? + .try_into() + .expect("Impossible to fail, given the same MAX_ORDERS_DELETE"), + wait_for.unwrap_or_default(), + ) .await?) } }