-
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.
Merge pull request #19 from renegade-fi/joey/hot-wallet-create
funds-manager: Add endpoint to create new hot wallets
- Loading branch information
Showing
12 changed files
with
245 additions
and
57 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
43 changes: 43 additions & 0 deletions
43
funds-manager/funds-manager-server/src/custody_client/hot_wallets.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,43 @@ | ||
//! Handlers for managing hot wallets | ||
//! | ||
//! We store funds in hot wallets to prevent excessive in/out-flow from | ||
//! Fireblocks | ||
|
||
use ethers::{ | ||
signers::{LocalWallet, Signer}, | ||
utils::hex::ToHexExt, | ||
}; | ||
use rand::thread_rng; | ||
use tracing::info; | ||
|
||
use super::CustodyClient; | ||
use crate::{error::FundsManagerError, helpers::create_secrets_manager_entry_with_description}; | ||
|
||
impl CustodyClient { | ||
/// Create a new hot wallet | ||
/// | ||
/// Returns the Arbitrum address of the hot wallet | ||
pub async fn create_hot_wallet(&self, vault: String) -> Result<String, FundsManagerError> { | ||
// Generate a new Ethereum keypair | ||
let wallet = LocalWallet::new(&mut thread_rng()); | ||
let address = wallet.address().encode_hex(); | ||
let private_key = wallet.signer().to_bytes(); | ||
|
||
// Store the private key in Secrets Manager | ||
let secret_name = format!("hot-wallet-{}", address); | ||
let secret_value = hex::encode(private_key); | ||
let description = format!("Hot wallet for vault: {vault}"); | ||
create_secrets_manager_entry_with_description( | ||
&secret_name, | ||
&secret_value, | ||
&self.aws_config, | ||
&description, | ||
) | ||
.await?; | ||
|
||
// Insert the wallet metadata into the database | ||
self.insert_hot_wallet(&address, &vault, &secret_name).await?; | ||
info!("Created hot wallet with address: {} for vault: {}", address, vault); | ||
Ok(address) | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
funds-manager/funds-manager-server/src/custody_client/queries.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,29 @@ | ||
//! Queries for managing custody data | ||
|
||
use diesel_async::RunQueryDsl; | ||
use renegade_util::err_str; | ||
|
||
use crate::db::models::HotWallet; | ||
use crate::db::schema::hot_wallets; | ||
use crate::error::FundsManagerError; | ||
use crate::CustodyClient; | ||
|
||
impl CustodyClient { | ||
/// Insert a new hot wallet into the database | ||
pub async fn insert_hot_wallet( | ||
&self, | ||
address: &str, | ||
vault: &str, | ||
secret_id: &str, | ||
) -> Result<(), FundsManagerError> { | ||
let mut conn = self.get_db_conn().await?; | ||
let entry = HotWallet::new(secret_id.to_string(), vault.to_string(), address.to_string()); | ||
diesel::insert_into(hot_wallets::table) | ||
.values(entry) | ||
.execute(&mut conn) | ||
.await | ||
.map_err(err_str!(FundsManagerError::Db))?; | ||
|
||
Ok(()) | ||
} | ||
} |
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
Oops, something went wrong.