Skip to content

Commit

Permalink
Merge pull request #157 from notJoon/refactor-sqrt-price-math
Browse files Browse the repository at this point in the history
Refactor: `sqrt-price-math`
  • Loading branch information
r3v4s committed Feb 8, 2024
2 parents 24da3df + e1269a7 commit 160aa2f
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 82 deletions.
4 changes: 2 additions & 2 deletions pool/_TEST_math_logic_test.gnoa
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestDrySwap_ZeroForOneFalse_AmountSpecified_Positive_16000(t *testing.T) {
"_", // recipient
false, // zeroForOne
16000, // amountSpecified
MAX_PRICE, // sqrtPriceLimitX96
consts.MAX_PRICE, // sqrtPriceLimitX96
)

shouldEQ(t, poolOut, bigint(-43468))
Expand All @@ -112,7 +112,7 @@ func TestDrySwap_ZeroForOneFalse_AmountSpecified_Negative_16000(t *testing.T) {
"_", // recipient
false, // zeroForOne
-16000, // amountSpecified
MAX_PRICE, // sqrtPriceLimitX96
consts.MAX_PRICE, // sqrtPriceLimitX96
)
shouldEQ(t, poolOut, bigint(-16000))
shouldEQ(t, poolIn, bigint(5888))
Expand Down
2 changes: 1 addition & 1 deletion pool/_TEST_pool_native_swap_test.gnoa
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestSwapSellNative(t *testing.T) {
test1,
false,
bigint(10000),
MAX_PRICE,
consts.MAX_PRICE,
std.GetOrigCaller(),
)
shouldEQ(t, amount0, bigint(-3685))
Expand Down
4 changes: 2 additions & 2 deletions pool/_TEST_pool_single_lp_test.gnoa
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func TestSwap(t *testing.T) {
userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1)
userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1)

amount0, amount1 := Swap(barPath, fooPath, fee500, test1, false, 16000, MAX_PRICE, std.GetOrigCaller()) // give enough amount to take fees away
amount0, amount1 := Swap(barPath, fooPath, fee500, test1, false, 16000, consts.MAX_PRICE, std.GetOrigCaller()) // give enough amount to take fees away

poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr)
poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr)
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestCollectProtocol(t *testing.T) {

std.TestSetPrevRealm("gno.land/r/demo/router")
std.TestSetOrigCaller(test1)
Swap(barPath, fooPath, fee500, test1, false, 200000, MAX_SQRT_RATIO-1, std.GetOrigCaller()) // swap token0 -> token1 => fee only in token0
Swap(barPath, fooPath, fee500, test1, false, 200000, consts.MAX_SQRT_RATIO-1, std.GetOrigCaller()) // swap token0 -> token1 => fee only in token0

test1OldToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1)
test1OldToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1)
Expand Down
Loading

0 comments on commit 160aa2f

Please sign in to comment.