Skip to content

Commit

Permalink
feature: Added affiliates to cf_account_info rpc (#5491)
Browse files Browse the repository at this point in the history
* 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

* chore: fixed fmt
  • Loading branch information
Janislav authored Dec 13, 2024
1 parent b8bdc87 commit f969c92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions state-chain/custom-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -259,6 +259,7 @@ pub enum RpcAccountInfo {
Broker {
flip_balance: NumberOrHex,
earned_fees: any::AssetMap<NumberOrHex>,
affiliates: Vec<(AffiliateShortId, AccountId)>,
btc_vault_deposit_address: Option<String>,
},
LiquidityProvider {
Expand Down Expand Up @@ -300,6 +301,7 @@ impl RpcAccountInfo {
.iter()
.map(|(asset, balance)| (*asset, (*balance).into())),
),
affiliates: broker_info.affiliates,
}
}

Expand Down Expand Up @@ -2185,10 +2187,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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
1 change: 1 addition & 0 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,7 @@ impl_runtime_apis! {
).collect(),
btc_vault_deposit_address: BrokerPrivateBtcChannels::<Runtime>::get(&account_id)
.map(derive_btc_vault_deposit_address),
affiliates: pallet_cf_swapping::AffiliateIdMapping::<Runtime>::iter_prefix(&account_id).collect(),
}
}

Expand Down
1 change: 1 addition & 0 deletions state-chain/runtime/src/runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub struct LiquidityProviderInfo {
pub struct BrokerInfo {
pub earned_fees: Vec<(Asset, AssetAmount)>,
pub btc_vault_deposit_address: Option<String>,
pub affiliates: Vec<(AffiliateShortId, AccountId32)>,
}

/// Struct that represents the estimated output of a Swap.
Expand Down

0 comments on commit f969c92

Please sign in to comment.