diff --git a/funds-manager/funds-manager-server/src/db/models.rs b/funds-manager/funds-manager-server/src/db/models.rs index e12b52b..953d4e4 100644 --- a/funds-manager/funds-manager-server/src/db/models.rs +++ b/funds-manager/funds-manager-server/src/db/models.rs @@ -61,7 +61,7 @@ pub struct Metadata { /// A metadata entry for a wallet managed by the indexer #[derive(Clone, Queryable, Selectable, Insertable)] -#[diesel(table_name = crate::db::schema::wallets)] +#[diesel(table_name = crate::db::schema::renegade_wallets)] #[diesel(check_for_backend(diesel::pg::Pg))] #[allow(missing_docs, clippy::missing_docs_in_private_items)] pub struct WalletMetadata { diff --git a/funds-manager/funds-manager-server/src/db/schema.rs b/funds-manager/funds-manager-server/src/db/schema.rs index af949b2..cc5c53a 100644 --- a/funds-manager/funds-manager-server/src/db/schema.rs +++ b/funds-manager/funds-manager-server/src/db/schema.rs @@ -12,6 +12,14 @@ diesel::table! { } } +diesel::table! { + hot_wallets (id) { + id -> Uuid, + secret_id -> Text, + vault -> Text, + } +} + diesel::table! { indexing_metadata (key) { key -> Text, @@ -20,11 +28,16 @@ diesel::table! { } diesel::table! { - wallets (id) { + renegade_wallets (id) { id -> Uuid, mints -> Array>, secret_id -> Text, } } -diesel::allow_tables_to_appear_in_same_query!(fees, indexing_metadata, wallets,); +diesel::allow_tables_to_appear_in_same_query!( + fees, + hot_wallets, + indexing_metadata, + renegade_wallets, +); diff --git a/funds-manager/funds-manager-server/src/fee_indexer/queries.rs b/funds-manager/funds-manager-server/src/fee_indexer/queries.rs index c05d80d..1df682e 100644 --- a/funds-manager/funds-manager-server/src/fee_indexer/queries.rs +++ b/funds-manager/funds-manager-server/src/fee_indexer/queries.rs @@ -27,7 +27,9 @@ use crate::db::schema::{ indexing_metadata::dsl::{ indexing_metadata as metadata_table, key as metadata_key, value as metadata_value, }, - wallets::dsl::{id as wallet_id_col, mints as managed_mints_col, wallets as wallet_table}, + renegade_wallets::dsl::{ + id as wallet_id_col, mints as managed_mints_col, renegade_wallets as renegade_wallet_table, + }, }; use crate::error::FundsManagerError; use crate::Indexer; @@ -214,7 +216,7 @@ impl Indexer { &mut self, wallet_id: &Uuid, ) -> Result { - wallet_table + renegade_wallet_table .filter(wallet_id_col.eq(wallet_id)) .first::(&mut self.db_conn) .await @@ -225,7 +227,7 @@ impl Indexer { pub(crate) async fn get_all_wallets( &mut self, ) -> Result, FundsManagerError> { - let wallets = wallet_table + let wallets = renegade_wallet_table .load::(&mut self.db_conn) .await .map_err(|e| FundsManagerError::db(format!("failed to load wallets: {}", e)))?; @@ -239,7 +241,7 @@ impl Indexer { &mut self, mint: &str, ) -> Result, FundsManagerError> { - let wallets: Vec = wallet_table + let wallets: Vec = renegade_wallet_table .filter(managed_mints_col.contains(vec![mint])) .load::(&mut self.db_conn) .await @@ -253,7 +255,7 @@ impl Indexer { &mut self, ) -> Result, FundsManagerError> { let n_mints = coalesce(array_length(managed_mints_col, 1 /* dim */), 0); - let wallets = wallet_table + let wallets = renegade_wallet_table .filter(n_mints.lt(MAX_BALANCES as i32)) .load::(&mut self.db_conn) .await @@ -267,7 +269,7 @@ impl Indexer { &mut self, wallet: WalletMetadata, ) -> Result<(), FundsManagerError> { - diesel::insert_into(wallet_table) + diesel::insert_into(renegade_wallet_table) .values(vec![wallet]) .execute(&mut self.db_conn) .await @@ -281,7 +283,7 @@ impl Indexer { wallet_id: &WalletIdentifier, mint: &str, ) -> Result<(), FundsManagerError> { - diesel::update(wallet_table.find(wallet_id)) + diesel::update(renegade_wallet_table.find(wallet_id)) .set(managed_mints_col.eq(array_append(managed_mints_col, mint))) .execute(&mut self.db_conn) .await diff --git a/funds-manager/migrations/2024-07-27-200942_create_hot_wallets_table/down.sql b/funds-manager/migrations/2024-07-27-200942_create_hot_wallets_table/down.sql new file mode 100644 index 0000000..d06e0fa --- /dev/null +++ b/funds-manager/migrations/2024-07-27-200942_create_hot_wallets_table/down.sql @@ -0,0 +1,3 @@ +-- Drop the hot wallets table +DROP TABLE hot_wallets; +ALTER TABLE renegade_wallets RENAME TO wallets; \ No newline at end of file diff --git a/funds-manager/migrations/2024-07-27-200942_create_hot_wallets_table/up.sql b/funds-manager/migrations/2024-07-27-200942_create_hot_wallets_table/up.sql new file mode 100644 index 0000000..a174ee8 --- /dev/null +++ b/funds-manager/migrations/2024-07-27-200942_create_hot_wallets_table/up.sql @@ -0,0 +1,9 @@ +-- Create a table for storing hot wallets +CREATE TABLE hot_wallets( + id UUID PRIMARY KEY, + secret_id TEXT NOT NULL, -- The AWS Secrets Manager secret that holds the hot wallet's key + vault TEXT NOT NULL -- The fireblocks vault that the hot wallet writes back to +); + +--- Rename the wallets table to renegade_wallets for clarity +ALTER TABLE wallets RENAME TO renegade_wallets;