-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from 3 commits
1bffe80
b04110d
111eae4
acb967a
3337aec
b8998db
6095c59
e89f3f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ use cf_primitives::{AccountRole, Asset, BasisPoints, ChannelId, SemVer}; | |
use futures::FutureExt; | ||
use pallet_cf_governance::ExecutionMode; | ||
use pallet_cf_validator::MAX_LENGTH_FOR_VANITY_NAME; | ||
use serde::Serialize; | ||
use serde::{Deserialize, Serialize}; | ||
use sp_consensus_aura::sr25519::AuthorityId as AuraId; | ||
use sp_consensus_grandpa::AuthorityId as GrandpaId; | ||
pub use sp_core::crypto::AccountId32; | ||
|
@@ -304,6 +304,11 @@ pub struct SwapDepositAddress { | |
pub channel_id: ChannelId, | ||
pub source_chain_expiry_block: <AnyChain as cf_chains::Chain>::ChainBlockNumber, | ||
} | ||
#[derive(Serialize, Deserialize)] | ||
pub struct WithdrawFeesDetail { | ||
pub tx_hash: H256, | ||
pub egress_id: (ForeignChain, u64), | ||
} | ||
|
||
#[async_trait] | ||
pub trait BrokerApi: SignedExtrinsicApi { | ||
|
@@ -356,6 +361,42 @@ pub trait BrokerApi: SignedExtrinsicApi { | |
bail!("No SwapDepositAddressReady event was found"); | ||
} | ||
} | ||
async fn withdraw_fees( | ||
&self, | ||
asset: Asset, | ||
destination_address: EncodedAddress, | ||
) -> Result<WithdrawFeesDetail> { | ||
let (tx_hash, events, ..) = self | ||
.submit_signed_extrinsic(RuntimeCall::from(pallet_cf_swapping::Call::withdraw { | ||
asset, | ||
destination_address, | ||
})) | ||
.await | ||
.until_in_block() | ||
.await | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.")?; | ||
|
||
if let Some(state_chain_runtime::RuntimeEvent::Swapping( | ||
pallet_cf_swapping::Event::WithdrawalRequested { | ||
egress_amount: _, | ||
egress_fee: _, | ||
destination_address: _, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not return all of the information? All of this is interesting to the broker. |
||
egress_id, | ||
}, | ||
)) = events.iter().find(|event| { | ||
matches!( | ||
event, | ||
state_chain_runtime::RuntimeEvent::Swapping( | ||
pallet_cf_swapping::Event::WithdrawalRequested { .. } | ||
) | ||
) | ||
}) { | ||
Ok(WithdrawFeesDetail { tx_hash, egress_id: *egress_id }) | ||
} else { | ||
bail!("No WithdrawalRequested event was found"); | ||
} | ||
// Ok(tx_hash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: stale comment |
||
} | ||
} | ||
|
||
/// Sanitize the given address (hex or base58) and turn it into a EncodedAddress of the given | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and implement Display for WithdrawalDetails.