From b7a4d0cdc4fc989b9fe206eb82a0c90d7143640a Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Mon, 20 May 2024 14:40:14 -0700 Subject: [PATCH] sys-lend: add principal_balance_change datapoint --- src/bin/sys-lend.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/bin/sys-lend.rs b/src/bin/sys-lend.rs index 745e276..abc77c7 100644 --- a/src/bin/sys-lend.rs +++ b/src/bin/sys-lend.rs @@ -85,6 +85,19 @@ mod dp { .tag("token", maybe_token.name()) .field("apy_bps", apy_bps as f64) } + + pub fn principal_balance_change( + pool: &str, + address: &Pubkey, + maybe_token: Token, + ui_amount: f64, + ) -> metrics::Point { + metrics::Point::new("sys_lend::principal_balance_change") + .tag("pool", pool) + .tag("address", metrics::dp::pubkey_to_value(address)) + .tag("token", maybe_token.name()) + .field("amount", ui_amount) + } } fn is_token_supported(token: &Token, pools: &[String]) -> Result<(), Box> { @@ -615,14 +628,23 @@ async fn main() -> Result<(), Box> { required_compute_units += result.required_compute_units; amount = result.amount; - match op { + let principal_balance_change_ui_amount = match op { Operation::Deposit => { - println!("Depositing {} into {}", token.format_amount(amount), pool) + println!("Depositing {} into {}", token.format_amount(amount), pool); + token.ui_amount(amount) } Operation::Withdraw => { - println!("Withdrawing {} from {}", token.format_amount(amount), pool) + println!("Withdrawing {} from {}", token.format_amount(amount), pool); + -token.ui_amount(amount) } - } + }; + metrics::push(dp::principal_balance_change( + pool, + &address, + token, + principal_balance_change_ui_amount, + )) + .await; } apply_priority_fee(