Skip to content

Commit

Permalink
Add serde impl for Asset
Browse files Browse the repository at this point in the history
squash

Add back chain::Asset serde impls (Needed for GenesisConfig `dust_limits`)

squash

squash

squash
  • Loading branch information
AlastairHolmes committed Feb 6, 2024
1 parent 991ae21 commit a82ff8e
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 230 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/lib/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ impl QueryApi {
let block_hash =
block_hash.unwrap_or_else(|| self.state_chain_client.latest_finalized_block().hash);

futures::future::join_all(Asset::all().iter().map(|asset| async {
futures::future::join_all(Asset::all().map(|asset| async move {
Ok((
*asset,
asset,
self.state_chain_client
.storage_double_map_entry::<pallet_cf_lp::FreeBalances<state_chain_runtime::Runtime>>(
block_hash,
&self.state_chain_client.account_id(),
asset,
&asset,
)
.await?
.unwrap_or_default(),
Expand Down
7 changes: 2 additions & 5 deletions state-chain/custom-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,11 +1163,8 @@ where

fn cf_supported_assets(&self) -> RpcResult<HashMap<ForeignChain, Vec<Asset>>> {
let mut chain_to_asset: HashMap<ForeignChain, Vec<Asset>> = HashMap::new();
Asset::all().iter().for_each(|asset| {
chain_to_asset
.entry((*asset).into())
.and_modify(|asset_vec| asset_vec.push(*asset))
.or_insert(vec![*asset]);
Asset::all().for_each(|asset| {
chain_to_asset.entry((asset).into()).or_default().push(asset);
});
Ok(chain_to_asset)
}
Expand Down
12 changes: 6 additions & 6 deletions state-chain/pallets/cf-swapping/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,10 +1846,10 @@ fn swap_broker_fee_calculated_correctly() {
const AMOUNT: AssetAmount = 100000;

// calculate broker fees for each asset available
Asset::all().iter().for_each(|asset| {
Asset::all().for_each(|asset| {
let total_fees: u128 =
fees.iter().fold(0, |total_fees: u128, fee_bps: &BasisPoints| {
swap_with_custom_broker_fee(*asset, Asset::Usdc, AMOUNT, *fee_bps);
swap_with_custom_broker_fee(asset, Asset::Usdc, AMOUNT, *fee_bps);
total_fees +
Permill::from_parts(*fee_bps as u32 * BASIS_POINTS_PER_MILLION) * AMOUNT
});
Expand Down Expand Up @@ -1896,17 +1896,17 @@ fn swap_broker_fee_subtracted_from_swap_amount() {

let combinations = amounts.iter().cartesian_product(fees);
let mut swap_id = 1;
Asset::all().iter().for_each(|asset| {
Asset::all().for_each(|asset| {
let mut total_fees = 0;
combinations.clone().for_each(|(amount, broker_fee)| {
swap_with_custom_broker_fee(*asset, Asset::Flip, *amount, broker_fee);
swap_with_custom_broker_fee(asset, Asset::Flip, *amount, broker_fee);
let broker_commission =
Permill::from_parts(broker_fee as u32 * BASIS_POINTS_PER_MILLION) * *amount;
total_fees += broker_commission;
assert_eq!(EarnedBrokerFees::<Test>::get(ALICE, *asset), total_fees);
assert_eq!(EarnedBrokerFees::<Test>::get(ALICE, asset), total_fees);
swap_scheduled_event_witnessed(
swap_id,
*asset,
asset,
*amount,
Asset::Flip,
broker_commission,
Expand Down
5 changes: 5 additions & 0 deletions state-chain/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ ethabi = { default-features = false, version = '18.0' }
strum = { default-features = false, version = '0.24' }
strum_macros = { default-features = false, version = '0.24' }
sp-core = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.1+3", default_features = false }
lazy_format = "2.0"

cf-utilities = { package = 'utilities', path = '../../utilities', default-features = false }

frame-support = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.1+3", default-features = false }
sp-std = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.1+3", default-features = false }
Expand All @@ -29,11 +32,13 @@ scale-info = { version = "2.5.0", default-features = false, features = [
[dev-dependencies]
sp-runtime = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.1+3" }
sp-core = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.1+3" }
serde_json = "1.0"

[features]
default = ['std']
std = [
'sp-core/std',
'cf-utilities/std',
'codec/std',
'ethabi/std',
'frame-support/std',
Expand Down
Loading

0 comments on commit a82ff8e

Please sign in to comment.