Skip to content

Commit

Permalink
use correct expected values in go getAmountsForLiquidity tests, mir…
Browse files Browse the repository at this point in the history
…ror in rust
  • Loading branch information
eli-d committed Nov 19, 2024
1 parent ff1f7a4 commit 95f31c3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/math/concentrated-liq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestGetSqrtRatioAtTick(t *testing.T) {
}

func TestGetPriceAtSqrtRatio(t *testing.T) {
t.Fatal("unimplemented")
t.Skip("unimplemented")
}

var getAmountsForLiqTestTable = map[string]struct {
Expand Down Expand Up @@ -121,16 +121,16 @@ var getAmountsForLiqTestTable = map[string]struct {
GetSqrtRatioAtTick(new(big.Int).SetInt64(2100)), // Lower tick
GetSqrtRatioAtTick(new(big.Int).SetInt64(4080)), // Upper tick
18117952900, // Liquidity (delta)
new(big.Rat).SetInt64(842893567), // Amount0
new(big.Rat).SetInt64(842893567), // Amount1
new(big.Rat).SetInt64(843131960), // Amount0
new(big.Rat).SetInt64(894653736), // Amount1
},
"contract alex_0f08c379a without tick conversion in the go code": {
mustIntFromStr("91911338314972375132734921679"), // Current tick
mustIntFromStr("87999098777895760865233273050"), // Lower tick
mustIntFromStr("97156358459122590463153608088"), // Upper tick
18117952900, // Liquidity (delta)
new(big.Rat).SetInt64(842893567), // Amount0
new(big.Rat).SetInt64(842893567), // Amount1
new(big.Rat).SetInt64(843131960), // Amount0
new(big.Rat).SetInt64(894653736), // Amount1
},
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/seawater/src/maths/sqrt_price_math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,35 @@ mod test {
);
}

// These differ from the Go tests by +1 as we use mul_div_rounding_up here
#[test]
fn test_get_amount_1_delta_go() {
use std::str::FromStr;
assert_eq!(
get_amount_1_delta(
U256::from_str("87999098777895760865233273050").unwrap(),
U256::from_str("91911338314972375132734921679").unwrap(),
18117952900
)
.unwrap(),
I256::from_str("894653737").unwrap()
);
}

#[test]
fn test_get_amount_0_delta_go() {
use std::str::FromStr;
assert_eq!(
get_amount_0_delta(
U256::from_str("97156358459122590463153608088").unwrap(),
U256::from_str("91911338314972375132734921679").unwrap(),
18117952900
)
.unwrap(),
I256::from_str("843131961").unwrap()
);
}

#[test]
fn test_get_amount_1_delta_weird() {
use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion pkg/seawater/tests/lib-end-to-end-proptest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ proptest! {
let pool = Address::from([1_u8; 20]);
contract.ctor(msg::sender(), Address::ZERO, Address::ZERO).unwrap();
let fee = fee_of_spacing(spacing);
contract.create_pool_D650_E2_D0(
contract.create_pool_653_F_395_E(
pool,
U256::from_limbs([9433916063688681729, 246222, 0, 0]), //4542003653232976906676481
fee,
Expand Down

0 comments on commit 95f31c3

Please sign in to comment.