From 9877aaee697cc17c8935112e26ad0a58fd595353 Mon Sep 17 00:00:00 2001 From: Charlie Little Date: Fri, 27 Oct 2023 22:41:13 -0500 Subject: [PATCH 1/2] Add fee_info function --- wasm/src/lib.rs | 15 +++++++++++++++ wasm/src/types.rs | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 8b2e1d78..3de1147f 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -493,6 +493,21 @@ pub async fn capacity_limit() -> Result { .await?) } +#[wasm_bindgen(js_name = feeInfo)] +pub async fn fee_info() -> Result { + Ok(app_client() + .query(|app: InnerApp| { + let building = app.bitcoin.checkpoints.building()?; + let est_miner_fee = + building.fee_rate * app.bitcoin.checkpoints.active_sigset()?.est_witness_vsize(); + Ok(FeeInfo { + bridgeFeeRate: 0.015, + minerFeeRate: est_miner_fee, + }) + }) + .await?) +} + #[wasm_bindgen(js_name = depositsEnabled)] pub async fn deposits_enabled() -> Result { Ok(app_client() diff --git a/wasm/src/types.rs b/wasm/src/types.rs index da6a6661..251f6444 100644 --- a/wasm/src/types.rs +++ b/wasm/src/types.rs @@ -8,6 +8,12 @@ pub struct DepositAddress { pub expiration: u64, } +#[wasm_bindgen(getter_with_clone)] +pub struct FeeInfo { + pub minerFeeRate: u64, + pub bridgeFeeRate: f32, +} + #[wasm_bindgen(getter_with_clone)] pub struct ValidatorQueryInfo { pub jailed: bool, From bb778bc61abd179908aa1d4eba9783603ae6fe21 Mon Sep 17 00:00:00 2001 From: Charlie Little Date: Wed, 14 Feb 2024 15:18:03 -0600 Subject: [PATCH 2/2] Update est_miner_fee calculation --- wasm/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 45ec7563..6c704f4f 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -497,11 +497,17 @@ pub async fn capacity_limit() -> Result { #[wasm_bindgen(js_name = feeInfo)] pub async fn fee_info() -> Result { + let user_fee_factor = app_client() + .query(|app: InnerApp| Ok(app.bitcoin.checkpoints.config.user_fee_factor)) + .await?; + Ok(app_client() .query(|app: InnerApp| { let building = app.bitcoin.checkpoints.building()?; - let est_miner_fee = - building.fee_rate * app.bitcoin.checkpoints.active_sigset()?.est_witness_vsize(); + let est_miner_fee = building.fee_rate + * app.bitcoin.checkpoints.active_sigset()?.est_witness_vsize() + * user_fee_factor + / 10_000; Ok(FeeInfo { bridgeFeeRate: 0.015, minerFeeRate: est_miner_fee,