From 8f2f65a914deb2b1cd63b6c4062501f68ca8113d Mon Sep 17 00:00:00 2001 From: keyne Date: Fri, 15 Dec 2023 12:13:47 +0000 Subject: [PATCH] nit comment and rename XRPL_ZERO_TRANSFER_RATE --- contract/src/contract.rs | 3 ++- contract/src/fees.rs | 6 +++--- contract/src/tests.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/contract/src/contract.rs b/contract/src/contract.rs index b82cd3ca..a8b70100 100644 --- a/contract/src/contract.rs +++ b/contract/src/contract.rs @@ -59,7 +59,8 @@ pub const XRPL_TOKENS_DECIMALS: u32 = 15; // If it is 1000000001 it means the fee will be 0.0000001% // If it is 1500000000 it means the fee will be 50% and so on. // We will use this value to calculate the fee to be applied to the amount being sent. -pub const XRPL_MIN_TRANSFER_RATE: Uint128 = Uint128::new(1000000000); +// For more info check https://xrpl.org/transfer-fees.html#technical-details +pub const XRPL_ZERO_TRANSFER_RATE: Uint128 = Uint128::new(1000000000); const XRP_CURRENCY: &str = "XRP"; const XRP_ISSUER: &str = "rrrrrrrrrrrrrrrrrrrrrhoLvTp"; diff --git a/contract/src/fees.rs b/contract/src/fees.rs index 4f3ede0e..7aa6a61e 100644 --- a/contract/src/fees.rs +++ b/contract/src/fees.rs @@ -2,7 +2,7 @@ use coreum_wasm_sdk::core::CoreumMsg; use cosmwasm_std::{coin, BankMsg, Coin, Decimal, Response, Storage, Uint128}; use crate::{ - contract::XRPL_MIN_TRANSFER_RATE, + contract::XRPL_ZERO_TRANSFER_RATE, error::ContractError, state::{CONFIG, FEES_COLLECTED}, }; @@ -32,8 +32,8 @@ pub fn amount_after_transfer_fees( // For example, if our transfer rate is 2% (1020000000), we will get 2% by doing 1020000000 - 1000000000 = 20000000 // and then dividing this by 1000000000 to get the percentage (0.02) // Afterwards we just need to apply the formula to get the amount to send (rounded down) and substract from the initial amount to get the fee that is applied. - let rate_value = rate.checked_sub(XRPL_MIN_TRANSFER_RATE)?; - let rate_percentage = Decimal::from_ratio(rate_value, XRPL_MIN_TRANSFER_RATE); + let rate_value = rate.checked_sub(XRPL_ZERO_TRANSFER_RATE)?; + let rate_percentage = Decimal::from_ratio(rate_value, XRPL_ZERO_TRANSFER_RATE); let denominator = Decimal::one().checked_add(rate_percentage)?; diff --git a/contract/src/tests.rs b/contract/src/tests.rs index 877f3b70..449dfeca 100644 --- a/contract/src/tests.rs +++ b/contract/src/tests.rs @@ -4583,7 +4583,7 @@ mod tests { tx_hash: tx_hash.to_owned(), issuer: bridge_xrpl_address.to_owned(), currency: coreum_token.xrpl_currency.to_owned(), - amount: Uint128::new(650010000000000), // 650010000000000 will convert to 650010, which after charging fees and truncating will send 350000 to the receiver + amount: Uint128::new(650010000000000), // 650010000000000 will convert to 650010, which after charging bridging fees (300000) and truncating (10) will send 350000 to the receiver recipient: Addr::unchecked(receiver.address()), }, },