-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
funds-manager: fee-indexer: Add endpoint to view wallet fee balances
- Loading branch information
Showing
9 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
funds-manager/funds-manager-server/src/fee_indexer/fee_balances.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Fetch the balances of redeemed fees | ||
|
||
use crate::db::models::WalletMetadata; | ||
use crate::error::FundsManagerError; | ||
use renegade_api::types::ApiWallet; | ||
use renegade_common::types::wallet::derivation::derive_wallet_keychain; | ||
|
||
use super::Indexer; | ||
|
||
impl Indexer { | ||
/// Fetch fee balances for wallets managed by the funds manager | ||
pub async fn fetch_fee_wallets(&mut self) -> Result<Vec<ApiWallet>, FundsManagerError> { | ||
// Query the wallets and fetch from the relayer | ||
let wallet_metadata = self.get_all_wallets().await?; | ||
let mut wallets = Vec::with_capacity(wallet_metadata.len()); | ||
for meta in wallet_metadata.into_iter() { | ||
let wallet = self.fetch_wallet(meta).await?; | ||
wallets.push(wallet); | ||
} | ||
|
||
Ok(wallets) | ||
} | ||
|
||
/// Fetch a wallet given its metadata | ||
/// | ||
/// This is done by: | ||
/// 1. Fetch the wallet's key from secrets manager | ||
/// 2. Use the key to fetch the wallet from the relayer | ||
async fn fetch_wallet( | ||
&mut self, | ||
wallet_metadata: WalletMetadata, | ||
) -> Result<ApiWallet, FundsManagerError> { | ||
// Get the wallet's private key from secrets manager | ||
let eth_key = self.get_wallet_private_key(&wallet_metadata).await?; | ||
|
||
// Derive the wallet keychain | ||
let wallet_keychain = | ||
derive_wallet_keychain(ð_key, self.chain_id).map_err(FundsManagerError::custom)?; | ||
let root_key = wallet_keychain.secret_keys.sk_root.clone().expect("root key not present"); | ||
|
||
// Fetch the wallet from the relayer | ||
let wallet = self.relayer_client.get_wallet(wallet_metadata.id, &root_key).await?; | ||
Ok(wallet.wallet) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters