From 896080050a4fe7e347e0b0779bb729f6bbd9d068 Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Fri, 12 Dec 2025 12:01:27 +0100 Subject: [PATCH 1/3] Makes `compute_masp_frontend_sus_fee` public --- crates/sdk/src/tx.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index 93f643562d..c6d57aec27 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -3616,8 +3616,8 @@ async fn get_masp_fee_payment_amount( }) } -// Extract the validate amount for the masp frontend sustainability fee -async fn compute_masp_frontend_sus_fee( +/// Extract the validate amount for the masp frontend sustainability fee +pub async fn compute_masp_frontend_sus_fee( context: &impl Namada, input_amount: &namada_token::DenominatedAmount, percentage: &namada_core::dec::Dec, From b6bf629d07db603b1aa8d3e521f095c4010cce50 Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Fri, 12 Dec 2025 12:05:36 +0100 Subject: [PATCH 2/3] Changelog #5001 --- .changelog/unreleased/SDK/5001-pub-frontendfee-builder.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/unreleased/SDK/5001-pub-frontendfee-builder.md diff --git a/.changelog/unreleased/SDK/5001-pub-frontendfee-builder.md b/.changelog/unreleased/SDK/5001-pub-frontendfee-builder.md new file mode 100644 index 0000000000..e034223698 --- /dev/null +++ b/.changelog/unreleased/SDK/5001-pub-frontendfee-builder.md @@ -0,0 +1,3 @@ +- The SDK now exposes the function to derive the validated amount of the + MASP frontend sustainability fee. ([\#5001](https://github.com/namada- + net/namada/pull/5001)) \ No newline at end of file From db30c308bd5d71e28b41804fcf6016be7ae1769e Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Thu, 18 Dec 2025 15:02:35 +0100 Subject: [PATCH 3/3] Rounds up the frontend fee --- crates/sdk/src/tx.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index c6d57aec27..374b26df45 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -3624,23 +3624,24 @@ pub async fn compute_masp_frontend_sus_fee( token: &Address, force: bool, ) -> Result { - let sus_fee_amt = namada_token::Amount::from_uint( - input_amount - .amount() - .raw_amount() - .checked_mul_div( - percentage.abs(), - namada_core::uint::Uint::exp10(POS_DECIMAL_PRECISION as _), + let (mut amount, remainder) = input_amount + .amount() + .raw_amount() + .checked_mul_div( + percentage.abs(), + namada_core::uint::Uint::exp10(POS_DECIMAL_PRECISION as _), + ) + .ok_or_else(|| { + Error::Other( + "Overflow in masp frontend fee computation".to_string(), ) - .ok_or_else(|| { - Error::Other( - "Overflow in masp frontend fee computation".to_string(), - ) - })? - .0, - 0, - ) - .map_err(|e| Error::Other(e.to_string()))?; + })?; + if !remainder.is_zero() { + // Round up the fee + amount += 1.into(); + } + let sus_fee_amt = namada_token::Amount::from_uint(amount, 0) + .map_err(|e| Error::Other(e.to_string()))?; // Validate the amount given validate_amount(