Skip to content

Commit

Permalink
Remove RpcAsset (and remove CLI option to specify chain)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlastairHolmes committed Feb 6, 2024
1 parent a82ff8e commit e629301
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 260 deletions.
14 changes: 6 additions & 8 deletions api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use cf_utilities::{
};
use chainflip_api::{
self, clean_foreign_chain_address,
primitives::{AccountRole, BasisPoints, BlockNumber, CcmChannelMetadata, ChannelId},
primitives::{AccountRole, Asset, BasisPoints, BlockNumber, CcmChannelMetadata, ChannelId},
settings::StateChain,
BrokerApi, OperatorApi, StateChainApi,
};
use clap::Parser;
use custom_rpc::RpcAsset;
use futures::FutureExt;
use jsonrpsee::{
core::{async_trait, RpcResult},
Expand Down Expand Up @@ -50,8 +49,8 @@ pub trait Rpc {
#[method(name = "request_swap_deposit_address", aliases = ["broker_requestSwapDepositAddress"])]
async fn request_swap_deposit_address(
&self,
source_asset: RpcAsset,
destination_asset: RpcAsset,
source_asset: Asset,
destination_asset: Asset,
destination_address: String,
broker_commission_bps: BasisPoints,
channel_metadata: Option<CcmChannelMetadata>,
Expand Down Expand Up @@ -88,19 +87,18 @@ impl RpcServer for RpcServerImpl {

async fn request_swap_deposit_address(
&self,
source_asset: RpcAsset,
destination_asset: RpcAsset,
source_asset: Asset,
destination_asset: Asset,
destination_address: String,
broker_commission_bps: BasisPoints,
channel_metadata: Option<CcmChannelMetadata>,
boost_fee: Option<BasisPoints>,
) -> RpcResult<BrokerSwapDepositAddress> {
let destination_asset = destination_asset.try_into()?;
Ok(self
.api
.broker_api()
.request_swap_deposit_address(
source_asset.try_into()?,
source_asset,
destination_asset,
clean_foreign_chain_address(destination_asset.into(), &destination_address)?,
broker_commission_bps,
Expand Down
19 changes: 4 additions & 15 deletions api/bin/chainflip-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use cf_chains::eth::Address as EthereumAddress;
use chainflip_api as api;
use chainflip_api::primitives::state_chain_runtime;
use clap::Parser;
use custom_rpc::RpcAsset;
use futures::FutureExt;
use serde::Serialize;
use std::{io::Write, path::PathBuf, sync::Arc};
Expand Down Expand Up @@ -60,17 +59,13 @@ async fn run_cli() -> Result<()> {
let api = StateChainApi::connect(scope, cli_settings.state_chain).await?;
match command_line_opts.cmd {
Broker(BrokerSubcommands::RequestSwapDepositAddress(params)) => {
let destination_asset =
RpcAsset::try_from((params.destination_asset, params.destination_chain))?
.try_into()?;
let SwapDepositAddress { address, .. } = api
.broker_api()
.request_swap_deposit_address(
RpcAsset::try_from((params.source_asset, params.source_chain))?
.try_into()?,
destination_asset,
params.source_asset,
params.destination_asset,
chainflip_api::clean_foreign_chain_address(
destination_asset.into(),
params.destination_asset.into(),
&params.destination_address,
)?,
params.broker_commission,
Expand All @@ -83,18 +78,12 @@ async fn run_cli() -> Result<()> {
LiquidityProvider(
LiquidityProviderSubcommands::RequestLiquidityDepositAddress {
asset,
chain,
boost_fee,
},
) => {
let asset = RpcAsset::try_from((asset, chain))?;
let address = api
.lp_api()
.request_liquidity_deposit_address(
asset.try_into()?,
api::WaitFor::InBlock,
boost_fee,
)
.request_liquidity_deposit_address(asset, api::WaitFor::InBlock, boost_fee)
.await?
.unwrap_details();
println!("Deposit Address: {address}");
Expand Down
6 changes: 0 additions & 6 deletions api/bin/chainflip-cli/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ pub struct SwapRequestParams {
pub broker_commission: u16,
/// Commission to the booster in basis points
pub boost_fee: Option<u16>,
/// Chain of the source asset ("Ethereum"|"Polkadot")
pub source_chain: Option<ForeignChain>,
/// Chain of the destination asset ("Ethereum"|"Polkadot")
pub destination_chain: Option<ForeignChain>,
}

#[derive(clap::Subcommand, Clone, Debug)]
Expand All @@ -93,8 +89,6 @@ pub enum LiquidityProviderSubcommands {
RequestLiquidityDepositAddress {
/// Asset to deposit ("ETH"|"DOT")
asset: Asset,
/// Chain of the deposit asset ("Ethereum"|"Polkadot")
chain: Option<ForeignChain>,
boost_fee: Option<u16>,
},
/// Register a Liquidity Refund Address for the given chain. An address must be
Expand Down
83 changes: 35 additions & 48 deletions api/bin/chainflip-lp-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ use chainflip_api::{
StorageApi, WaitFor,
};
use clap::Parser;
use custom_rpc::{
CustomApiClient, RpcAsset,
RpcAsset::{ExplicitChain, ImplicitChain},
};
use custom_rpc::CustomApiClient;
use futures::{try_join, FutureExt, StreamExt};
use jsonrpsee::{
core::{async_trait, RpcResult},
Expand Down Expand Up @@ -111,7 +108,7 @@ pub trait Rpc {
#[method(name = "liquidity_deposit")]
async fn request_liquidity_deposit_address(
&self,
asset: RpcAsset,
asset: Asset,
wait_for: Option<WaitFor>,
boost_fee: Option<BasisPoints>,
) -> RpcResult<ApiWaitForResult<String>>;
Expand All @@ -127,16 +124,16 @@ pub trait Rpc {
async fn withdraw_asset(
&self,
amount: NumberOrHex,
asset: RpcAsset,
asset: Asset,
destination_address: &str,
wait_for: Option<WaitFor>,
) -> RpcResult<ApiWaitForResult<EgressId>>;

#[method(name = "update_range_order")]
async fn update_range_order(
&self,
base_asset: RpcAsset,
quote_asset: RpcAsset,
base_asset: Asset,
quote_asset: Asset,
id: OrderIdJson,
tick_range: Option<Range<Tick>>,
size_change: IncreaseOrDecrease<RangeOrderSizeJson>,
Expand All @@ -146,8 +143,8 @@ pub trait Rpc {
#[method(name = "set_range_order")]
async fn set_range_order(
&self,
base_asset: RpcAsset,
quote_asset: RpcAsset,
base_asset: Asset,
quote_asset: Asset,
id: OrderIdJson,
tick_range: Option<Range<Tick>>,
size: RangeOrderSizeJson,
Expand All @@ -157,8 +154,8 @@ pub trait Rpc {
#[method(name = "update_limit_order")]
async fn update_limit_order(
&self,
base_asset: RpcAsset,
quote_asset: RpcAsset,
base_asset: Asset,
quote_asset: Asset,
side: Order,
id: OrderIdJson,
tick: Option<Tick>,
Expand All @@ -170,8 +167,8 @@ pub trait Rpc {
#[method(name = "set_limit_order")]
async fn set_limit_order(
&self,
base_asset: RpcAsset,
quote_asset: RpcAsset,
base_asset: Asset,
quote_asset: Asset,
side: Order,
id: OrderIdJson,
tick: Option<Tick>,
Expand Down Expand Up @@ -255,18 +252,14 @@ impl RpcServer for RpcServerImpl {
/// Returns a deposit address
async fn request_liquidity_deposit_address(
&self,
asset: RpcAsset,
asset: Asset,
wait_for: Option<WaitFor>,
boost_fee: Option<BasisPoints>,
) -> RpcResult<ApiWaitForResult<String>> {
Ok(self
.api
.lp_api()
.request_liquidity_deposit_address(
asset.try_into()?,
wait_for.unwrap_or_default(),
boost_fee,
)
.request_liquidity_deposit_address(asset, wait_for.unwrap_or_default(), boost_fee)
.await
.map(|result| result.map_details(|address| address.to_string()))?)
}
Expand All @@ -284,12 +277,10 @@ impl RpcServer for RpcServerImpl {
async fn withdraw_asset(
&self,
amount: NumberOrHex,
asset: RpcAsset,
asset: Asset,
destination_address: &str,
wait_for: Option<WaitFor>,
) -> RpcResult<ApiWaitForResult<EgressId>> {
let asset: Asset = asset.try_into()?;

let destination_address =
chainflip_api::clean_foreign_chain_address(asset.into(), destination_address)?;

Expand Down Expand Up @@ -319,23 +310,19 @@ impl RpcServer for RpcServerImpl {
.await?;

let mut lp_asset_balances: BTreeMap<ForeignChain, Vec<AssetBalance>> = BTreeMap::new();

for rpc_asset_with_amount in cf_asset_balances {
let (chain, asset) = match rpc_asset_with_amount.asset {
ImplicitChain(asset) => (asset.into(), asset),
ExplicitChain { chain, asset } => (chain, asset),
};
let asset_balance =
AssetBalance { asset, balance: rpc_asset_with_amount.amount.into() };
lp_asset_balances.entry(chain).or_insert_with(Vec::new).push(asset_balance);
for custom_rpc::AssetWithAmount { asset, amount } in cf_asset_balances {
lp_asset_balances
.entry(asset.into())
.or_insert_with(Vec::new)
.push(AssetBalance { asset, balance: amount.into() });
}
Ok(lp_asset_balances)
}

async fn update_range_order(
&self,
base_asset: RpcAsset,
quote_asset: RpcAsset,
base_asset: Asset,
quote_asset: Asset,
id: OrderIdJson,
tick_range: Option<Range<Tick>>,
size_change: IncreaseOrDecrease<RangeOrderSizeJson>,
Expand All @@ -345,8 +332,8 @@ impl RpcServer for RpcServerImpl {
.api
.lp_api()
.update_range_order(
base_asset.try_into()?,
quote_asset.try_into()?,
base_asset,
quote_asset,
id.try_into()?,
tick_range,
size_change.try_map(|size| size.try_into())?,
Expand All @@ -357,8 +344,8 @@ impl RpcServer for RpcServerImpl {

async fn set_range_order(
&self,
base_asset: RpcAsset,
quote_asset: RpcAsset,
base_asset: Asset,
quote_asset: Asset,
id: OrderIdJson,
tick_range: Option<Range<Tick>>,
size: RangeOrderSizeJson,
Expand All @@ -368,8 +355,8 @@ impl RpcServer for RpcServerImpl {
.api
.lp_api()
.set_range_order(
base_asset.try_into()?,
quote_asset.try_into()?,
base_asset,
quote_asset,
id.try_into()?,
tick_range,
size.try_into()?,
Expand All @@ -380,8 +367,8 @@ impl RpcServer for RpcServerImpl {

async fn update_limit_order(
&self,
base_asset: RpcAsset,
quote_asset: RpcAsset,
base_asset: Asset,
quote_asset: Asset,
side: Order,
id: OrderIdJson,
tick: Option<Tick>,
Expand All @@ -393,8 +380,8 @@ impl RpcServer for RpcServerImpl {
.api
.lp_api()
.update_limit_order(
base_asset.try_into()?,
quote_asset.try_into()?,
base_asset,
quote_asset,
side,
id.try_into()?,
tick,
Expand All @@ -407,8 +394,8 @@ impl RpcServer for RpcServerImpl {

async fn set_limit_order(
&self,
base_asset: RpcAsset,
quote_asset: RpcAsset,
base_asset: Asset,
quote_asset: Asset,
side: Order,
id: OrderIdJson,
tick: Option<Tick>,
Expand All @@ -420,8 +407,8 @@ impl RpcServer for RpcServerImpl {
.api
.lp_api()
.set_limit_order(
base_asset.try_into()?,
quote_asset.try_into()?,
base_asset,
quote_asset,
side,
id.try_into()?,
tick,
Expand Down
Loading

0 comments on commit e629301

Please sign in to comment.