Skip to content

Commit

Permalink
Merge pull request #200 from Phoenix-Protocol-Group/187-audit-documen…
Browse files Browse the repository at this point in the history
…tation-and-naming-issues

Pool, Pool-Stable, Curve, Decimal, Phoenix: addresses small issues with documentation and naming
  • Loading branch information
ueco-jb authored Jan 18, 2024
2 parents 7c2b0ac + a130b34 commit f8a7f20
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to
## Changed

- Update soroban-sdk version from v20.0.3 to v20.1.0 ([#193])
- Fixes documentation and naming ([#200])

[#200]: https://github.com/Phoenix-Protocol-Group/phoenix-contracts/pull/200

## [0.8.0] - 2024-01-17

Expand Down
4 changes: 2 additions & 2 deletions contracts/pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
};
use decimal::Decimal;
use phoenix::{
utils::{assert_approx_ratio, StakeInitInfo, TokenInitInfo},
utils::{is_approx_ratio, StakeInitInfo, TokenInitInfo},
validate_int_parameters,
};

Expand Down Expand Up @@ -821,7 +821,7 @@ fn split_deposit_based_on_pool_ratio(
};

// If the resulting ratio is approximately equal (1%) to the target ratio, break the loop
if assert_approx_ratio(ratio, target_ratio, Decimal::percent(1)) {
if is_approx_ratio(ratio, target_ratio, Decimal::percent(1)) {
break;
}
// Update boundaries for the next iteration of the binary search
Expand Down
2 changes: 1 addition & 1 deletion contracts/pool/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ pub mod utils {
let amount_b = {
let mut amount_b = desired_a * pool_balance_b / pool_balance_a;
if amount_b > desired_b {
// If the amount is within 1% of the desired amount, we accept it
// If the amount is within the set threshold of the desired amount, we accept it
if Decimal::from_ratio(amount_b, desired_b) - Decimal::one() <= allowed_slippage {
amount_b = desired_b;
} else {
Expand Down
4 changes: 2 additions & 2 deletions contracts/pool_stable/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
};
use decimal::Decimal;
use phoenix::{
utils::{assert_approx_ratio, StakeInitInfo, TokenInitInfo},
utils::{is_approx_ratio, StakeInitInfo, TokenInitInfo},
validate_int_parameters,
};

Expand Down Expand Up @@ -756,7 +756,7 @@ fn split_deposit_based_on_pool_ratio(
};

// If the resulting ratio is approximately equal (1%) to the target ratio, break the loop
if assert_approx_ratio(ratio, target_ratio, Decimal::percent(1)) {
if is_approx_ratio(ratio, target_ratio, Decimal::percent(1)) {
break;
}
// Update boundaries for the next iteration of the binary search
Expand Down
2 changes: 1 addition & 1 deletion packages/curve/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Most of this code is taken from the wynd-utils crate, which is licensed under the Apache
// License Apache 2.0 - https://github.com/wynddao/wynd-contracts
// License Apache 2.0 - https://github.com/wynddao/wynddao/

#![no_std]

Expand Down
6 changes: 3 additions & 3 deletions packages/decimal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ impl Decimal {

/// Creates a decimal from a number of atomic units and the number
/// of decimal places. The inputs will be converted internally to form
/// a decimal with 18 decimal places. So the input 123 and 2 will create
/// the decimal 1.23.
/// a decimal with 18 decimal places. So the input 1234 and 3 will create
/// the decimal 1.234.
///
/// Using 18 decimal places is slightly more efficient than other values
/// as no internal conversion is necessary.
///
/// ## Examples
///
/// ```
/// # use decimal::Decimal;
/// use decimal::Decimal;
/// use soroban_sdk::{String, Env};
///
/// let e = Env::default();
Expand Down
8 changes: 4 additions & 4 deletions packages/phoenix/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ macro_rules! validate_int_parameters {
};
}

pub fn assert_approx_ratio(a: Decimal, b: Decimal, tolerance: Decimal) -> bool {
pub fn is_approx_ratio(a: Decimal, b: Decimal, tolerance: Decimal) -> bool {
let diff = (a - b).abs();
diff <= tolerance
}
Expand Down Expand Up @@ -104,22 +104,22 @@ mod tests {
let a = Decimal::from_ratio(100, 101);
let b = Decimal::from_ratio(100, 100);
let tolerance = Decimal::percent(3);
assert!(assert_approx_ratio(a, b, tolerance));
assert!(is_approx_ratio(a, b, tolerance));
}

#[test]
fn test_assert_approx_ratio_equal_values() {
let a = Decimal::from_ratio(100, 100);
let b = Decimal::from_ratio(100, 100);
let tolerance = Decimal::percent(3);
assert!(assert_approx_ratio(a, b, tolerance));
assert!(is_approx_ratio(a, b, tolerance));
}

#[test]
fn test_assert_approx_ratio_outside_tolerance() {
let a = Decimal::from_ratio(100, 104);
let b = Decimal::from_ratio(100, 100);
let tolerance = Decimal::percent(3);
assert!(!assert_approx_ratio(a, b, tolerance));
assert!(!is_approx_ratio(a, b, tolerance));
}
}

0 comments on commit f8a7f20

Please sign in to comment.