Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose command for broker fee withdrawal #4581

Merged
merged 8 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ pub trait Rpc {
channel_metadata: Option<CcmChannelMetadata>,
boost_fee: Option<BasisPoints>,
) -> RpcResult<BrokerSwapDepositAddress>;

#[method(name = "withdraw_fee_asset", aliases = ["broker_withdrawFeeAsset"])]
async fn withdraw_fee_asset(
&self,
asset: Asset,
destination_address: String,
) -> RpcResult<String>;
}

pub struct RpcServerImpl {
Expand Down Expand Up @@ -108,6 +115,22 @@ impl RpcServer for RpcServerImpl {
.await
.map(BrokerSwapDepositAddress::from)?)
}

async fn withdraw_fee_asset(
&self,
asset: Asset,
destination_address: String,
) -> RpcResult<String> {
Ok(self
.api
.broker_api()
.withdraw_fee_asset(
asset,
clean_foreign_chain_address(asset.into(), &destination_address)?,
)
.await
.map(|tx_hash| format!("{tx_hash:#x}"))?)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, better to return the hash here and rely on Serialize rather than converting to a string explicitly.

}
}

#[derive(Parser, Debug, Clone, Default)]
Expand Down
13 changes: 13 additions & 0 deletions api/bin/chainflip-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ async fn run_cli() -> Result<()> {
.await?;
println!("Deposit Address: {address}");
},
Broker(BrokerSubcommands::WithdrawFeeAsset(params)) => {
let tx_hash = api
.broker_api()
.withdraw_fee_asset(
params.asset,
chainflip_api::clean_foreign_chain_address(
params.asset.into(),
&params.destination_address,
)?,
)
.await?;
println!("Withdrawal request successfull submitted. Tx hash: {tx_hash}");
},
LiquidityProvider(
LiquidityProviderSubcommands::RequestLiquidityDepositAddress {
asset,
Expand Down
9 changes: 8 additions & 1 deletion api/bin/chainflip-cli/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,18 @@ pub struct SwapRequestParams {
/// Commission to the booster in basis points
pub boost_fee: Option<u16>,
}

#[derive(Parser, Clone, Debug)]
pub struct WithdrawFeeAssetParams {
/// Asset to withdraw ("ETH"|"DOT")
pub asset: Asset,
/// Egress asset address to receive withdrawn funds
pub destination_address: String,
}
#[derive(clap::Subcommand, Clone, Debug)]
pub enum BrokerSubcommands {
/// Request a swap deposit address.
RequestSwapDepositAddress(SwapRequestParams),
WithdrawFeeAsset(WithdrawFeeAssetParams),
}

#[derive(clap::Subcommand, Clone, Debug)]
Expand Down
16 changes: 16 additions & 0 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,22 @@ pub trait BrokerApi: SignedExtrinsicApi {
bail!("No SwapDepositAddressReady event was found");
}
}
async fn withdraw_fee_asset(
&self,
asset: Asset,
destination_address: EncodedAddress,
) -> Result<H256> {
let (tx_hash, ..) = self
.submit_signed_extrinsic(RuntimeCall::from(pallet_cf_swapping::Call::withdraw {
asset,
destination_address,
}))
.await
.until_in_block()
.await
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we can also get the egress details, we should return these too.

.context("Request to withdraw broker fee for ${asset} failed.")?;
Ok(tx_hash)
}
}

/// Sanitize the given address (hex or base58) and turn it into a EncodedAddress of the given
Expand Down
Loading