Skip to content

Commit

Permalink
fix: use U256 return value for asset volume (chainflip-io#4986)
Browse files Browse the repository at this point in the history
* fix: remove `context` from api results

* fix: use U256 return value for asset volume

* clippy
  • Loading branch information
dandanlen authored Jun 21, 2024
1 parent f0bc4ea commit fb221f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
2 changes: 1 addition & 1 deletion api/bin/chainflip-broker-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl From<chainflip_api::SwapDepositAddress> for BrokerSwapDepositAddress {
issued_block: value.issued_block,
channel_id: value.channel_id,
source_chain_expiry_block: NumberOrHex::from(value.source_chain_expiry_block),
channel_opening_fee: U256::from(value.channel_opening_fee),
channel_opening_fee: value.channel_opening_fee,
}
}
}
Expand Down
47 changes: 14 additions & 33 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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;
use sp_core::{ed25519::Public as EdPublic, sr25519::Public as SrPublic, Bytes, Pair, H256};
use sp_core::{ed25519::Public as EdPublic, sr25519::Public as SrPublic, Bytes, Pair, H256, U256};
pub use state_chain_runtime::chainflip::BlockUpdate;
use state_chain_runtime::{opaque::SessionKeys, RuntimeCall};
use zeroize::Zeroize;
Expand Down Expand Up @@ -71,11 +71,7 @@ impl<
> AuctionPhaseApi for StateChainClient<SignedExtrinsicClient, BaseRpcClient<RawRpcClient>>
{
async fn is_auction_phase(&self) -> Result<bool> {
self.base_rpc_client
.raw_rpc_client
.cf_is_auction_phase(None)
.await
.context("Error RPC query: is_auction_phase")
Ok(self.base_rpc_client.raw_rpc_client.cf_is_auction_phase(None).await?)
}
}

Expand Down Expand Up @@ -170,22 +166,18 @@ pub trait ValidatorApi: SimpleSubmissionApi {
async fn register_account(&self) -> Result<H256> {
self.simple_submission_with_dry_run(pallet_cf_validator::Call::register_as_validator {})
.await
.context("Could not register as validator")
}
async fn deregister_account(&self) -> Result<H256> {
self.simple_submission_with_dry_run(pallet_cf_validator::Call::deregister_as_validator {})
.await
.context("Could not de-register as validator")
}
async fn stop_bidding(&self) -> Result<H256> {
self.simple_submission_with_dry_run(pallet_cf_validator::Call::stop_bidding {})
.await
.context("Could not stop bidding")
}
async fn start_bidding(&self) -> Result<H256> {
self.simple_submission_with_dry_run(pallet_cf_validator::Call::start_bidding {})
.await
.context("Could not start bidding")
}
}

Expand Down Expand Up @@ -238,19 +230,13 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
AccountRole::Unregistered => bail!("Cannot register account role {:?}", role),
};

let (tx_hash, ..) = self
.submit_signed_extrinsic_with_dry_run(call)
.await?
.until_in_block()
.await
.context("Could not register account role for account")?;
let (tx_hash, ..) =
self.submit_signed_extrinsic_with_dry_run(call).await?.until_in_block().await?;
Ok(tx_hash)
}

async fn rotate_session_keys(&self) -> Result<H256> {
let raw_keys = RotateSessionKeysApi::rotate_session_keys(self)
.await
.context("Could not rotate session keys.")?;
let raw_keys = RotateSessionKeysApi::rotate_session_keys(self).await?;

let aura_key: [u8; 32] = raw_keys[0..32].try_into().unwrap();
let grandpa_key: [u8; 32] = raw_keys[32..64].try_into().unwrap();
Expand Down Expand Up @@ -279,8 +265,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
})
.await
.until_in_block()
.await
.context("Could not set vanity name for your account")?;
.await?;
println!("Vanity name set at tx {tx_hash:#x}.");
Ok(())
}
Expand All @@ -296,8 +281,7 @@ pub trait GovernanceApi: SignedExtrinsicApi {
})
.await
.until_in_block()
.await
.context("Failed to submit rotation governance proposal")?;
.await?;

println!("If you're the governance dictator, the rotation will begin soon.");

Expand All @@ -310,15 +294,15 @@ pub struct SwapDepositAddress {
pub issued_block: state_chain_runtime::BlockNumber,
pub channel_id: ChannelId,
pub source_chain_expiry_block: <AnyChain as cf_chains::Chain>::ChainBlockNumber,
pub channel_opening_fee: u128,
pub channel_opening_fee: U256,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct WithdrawFeesDetail {
pub tx_hash: H256,
pub egress_id: (ForeignChain, u64),
pub egress_amount: u128,
pub egress_fee: u128,
pub egress_amount: U256,
pub egress_fee: U256,
pub destination_address: String,
}

Expand Down Expand Up @@ -402,7 +386,7 @@ pub trait BrokerApi: SignedExtrinsicApi + Sized + Send + Sync + 'static {
issued_block: header.number,
channel_id: *channel_id,
source_chain_expiry_block: *source_chain_expiry_block,
channel_opening_fee: *channel_opening_fee,
channel_opening_fee: (*channel_opening_fee).into(),
})
} else {
bail!("No SwapDepositAddressReady event was found");
Expand All @@ -420,8 +404,7 @@ pub trait BrokerApi: SignedExtrinsicApi + Sized + Send + Sync + 'static {
}))
.await
.until_in_block()
.await
.context("Request to withdraw broker fee for ${asset} failed.")?;
.await?;

if let Some(state_chain_runtime::RuntimeEvent::Swapping(
pallet_cf_swapping::Event::WithdrawalRequested {
Expand All @@ -442,8 +425,8 @@ pub trait BrokerApi: SignedExtrinsicApi + Sized + Send + Sync + 'static {
Ok(WithdrawFeesDetail {
tx_hash,
egress_id: *egress_id,
egress_amount: *egress_amount,
egress_fee: *egress_fee,
egress_amount: (*egress_amount).into(),
egress_fee: (*egress_fee).into(),
destination_address: destination_address.to_string(),
})
} else {
Expand All @@ -453,12 +436,10 @@ pub trait BrokerApi: SignedExtrinsicApi + Sized + Send + Sync + 'static {
async fn register_account(&self) -> Result<H256> {
self.simple_submission_with_dry_run(pallet_cf_swapping::Call::register_as_broker {})
.await
.context("Could not register as broker")
}
async fn deregister_account(&self) -> Result<H256> {
self.simple_submission_with_dry_run(pallet_cf_swapping::Call::deregister_as_broker {})
.await
.context("Could not de-register as broker")
}
}

Expand Down
10 changes: 3 additions & 7 deletions api/lib/src/lp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::SimpleSubmissionApi;
use anyhow::{bail, Context, Result};
use anyhow::{bail, Result};
use async_trait::async_trait;
pub use cf_amm::{
common::{Amount, PoolPairsMap, Side, Tick},
Expand Down Expand Up @@ -172,8 +172,7 @@ pub trait LpApi: SignedExtrinsicApi + Sized + Send + Sync + 'static {
))
.await
.until_in_block()
.await
.context("Registration for Liquidity Refund Address failed.")?;
.await?;
Ok(tx_hash)
}

Expand Down Expand Up @@ -273,8 +272,7 @@ pub trait LpApi: SignedExtrinsicApi + Sized + Send + Sync + 'static {
}))
.await
.until_in_block()
.await
.context("Unable to transfer asset.")?;
.await?;
Ok(tx_hash)
}

Expand Down Expand Up @@ -408,12 +406,10 @@ pub trait LpApi: SignedExtrinsicApi + Sized + Send + Sync + 'static {
async fn register_account(&self) -> Result<H256> {
self.simple_submission_with_dry_run(pallet_cf_lp::Call::register_lp_account {})
.await
.context("Could not register liquidity provider")
}

async fn deregister_account(&self) -> Result<H256> {
self.simple_submission_with_dry_run(pallet_cf_lp::Call::deregister_lp_account {})
.await
.context("Could not de-register liquidity provider")
}
}

0 comments on commit fb221f4

Please sign in to comment.