Skip to content

Commit

Permalink
nit comment and rename XRPL_ZERO_TRANSFER_RATE
Browse files Browse the repository at this point in the history
  • Loading branch information
keyleu committed Dec 15, 2023
1 parent 6831cca commit 8f2f65a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions contract/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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)?;

Expand Down
2 changes: 1 addition & 1 deletion contract/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
},
},
Expand Down

0 comments on commit 8f2f65a

Please sign in to comment.