From c6c34319b8d5b615c64802114825a09cc1ac5798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bo=CC=88rner?= Date: Thu, 12 Dec 2024 15:55:50 +0100 Subject: [PATCH] feat: Add private channel address to account info rpc (#5489) * feature: Added channel address to cf-account-info * refactor: derive address from channel id * refactor: renamed channel_address to deposit_address * chore: renamed deposit_address -> btc_vault_deposit_address * chore: moved btc address derivation to own function * chore: improved comment * chore: refactored cf_broker_info --- state-chain/custom-rpc/src/lib.rs | 10 ++++++---- .../custom_rpc__test__broker_serialization.snap | 2 +- state-chain/runtime/src/lib.rs | 1 + state-chain/runtime/src/runtime_apis.rs | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/state-chain/custom-rpc/src/lib.rs b/state-chain/custom-rpc/src/lib.rs index 3fa8c479d8..b4cffcda4a 100644 --- a/state-chain/custom-rpc/src/lib.rs +++ b/state-chain/custom-rpc/src/lib.rs @@ -14,9 +14,9 @@ use cf_chains::{ }; use cf_primitives::{ chains::assets::any::{self, AssetMap}, - AccountRole, AffiliateShortId, Affiliates, Asset, AssetAmount, BasisPoints, BlockNumber, - BroadcastId, DcaParameters, EpochIndex, ForeignChain, NetworkEnvironment, SemVer, SwapId, - SwapRequestId, + AccountId, AccountRole, AffiliateShortId, Affiliates, Asset, AssetAmount, BasisPoints, + BlockNumber, BroadcastId, DcaParameters, EpochIndex, ForeignChain, NetworkEnvironment, SemVer, + SwapId, SwapRequestId, }; use cf_utilities::rpc::NumberOrHex; use core::ops::Range; @@ -259,6 +259,7 @@ pub enum RpcAccountInfo { Broker { flip_balance: NumberOrHex, earned_fees: any::AssetMap, + affiliates: Vec<(AffiliateShortId, AccountId)>, btc_vault_deposit_address: Option, }, LiquidityProvider { @@ -300,6 +301,7 @@ impl RpcAccountInfo { .iter() .map(|(asset, balance)| (*asset, (*balance).into())), ), + affiliates: broker_info.affiliates, } } @@ -2190,10 +2192,10 @@ mod test { btc_vault_deposit_address: Some( ScriptPubkey::Taproot([1u8; 32]).to_address(&BitcoinNetwork::Testnet), ), + affiliates: vec![(cf_primitives::AffiliateShortId(1), AccountId32::new([1; 32]))], }, 0, ); - insta::assert_snapshot!(serde_json::to_value(broker).unwrap()); } diff --git a/state-chain/custom-rpc/src/snapshots/custom_rpc__test__broker_serialization.snap b/state-chain/custom-rpc/src/snapshots/custom_rpc__test__broker_serialization.snap index 8fd0e3a6b0..1ff3c47ac8 100644 --- a/state-chain/custom-rpc/src/snapshots/custom_rpc__test__broker_serialization.snap +++ b/state-chain/custom-rpc/src/snapshots/custom_rpc__test__broker_serialization.snap @@ -3,4 +3,4 @@ source: state-chain/custom-rpc/src/lib.rs expression: "serde_json::to_value(broker).unwrap()" snapshot_kind: text --- -{"btc_vault_deposit_address":"tb1pqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqsn60vlk","earned_fees":{"Arbitrum":{"ETH":"0x0","USDC":"0x0"},"Bitcoin":{"BTC":"0x0"},"Ethereum":{"ETH":"0x0","FLIP":"0xde0b6b3a7640000","USDC":"0x0","USDT":"0x0"},"Polkadot":{"DOT":"0x0"},"Solana":{"SOL":"0x0","USDC":"0x0"}},"flip_balance":"0x0","role":"broker"} +{"affiliates":[[1,"5C62Ck4UrFPiBtoCmeSrgF7x9yv9mn38446dhCpsi2mLHiFT"]],"btc_vault_deposit_address":"tb1pqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqsn60vlk","earned_fees":{"Arbitrum":{"ETH":"0x0","USDC":"0x0"},"Bitcoin":{"BTC":"0x0"},"Ethereum":{"ETH":"0x0","FLIP":"0xde0b6b3a7640000","USDC":"0x0","USDT":"0x0"},"Polkadot":{"DOT":"0x0"},"Solana":{"SOL":"0x0","USDC":"0x0"}},"flip_balance":"0x0","role":"broker"} diff --git a/state-chain/runtime/src/lib.rs b/state-chain/runtime/src/lib.rs index 42cf26c691..fd04b53dda 100644 --- a/state-chain/runtime/src/lib.rs +++ b/state-chain/runtime/src/lib.rs @@ -1912,6 +1912,7 @@ impl_runtime_apis! { ).collect(), btc_vault_deposit_address: BrokerPrivateBtcChannels::::get(&account_id) .map(derive_btc_vault_deposit_address), + affiliates: pallet_cf_swapping::AffiliateIdMapping::::iter_prefix(&account_id).collect(), } } diff --git a/state-chain/runtime/src/runtime_apis.rs b/state-chain/runtime/src/runtime_apis.rs index e7a89ff188..b8caefcb0d 100644 --- a/state-chain/runtime/src/runtime_apis.rs +++ b/state-chain/runtime/src/runtime_apis.rs @@ -162,6 +162,7 @@ pub struct LiquidityProviderInfo { pub struct BrokerInfo { pub earned_fees: Vec<(Asset, AssetAmount)>, pub btc_vault_deposit_address: Option, + pub affiliates: Vec<(AffiliateShortId, AccountId32)>, } /// Struct that represents the estimated output of a Swap.