Skip to content

Commit

Permalink
GSW-431 feat: return pool detail in FindBestPool()
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Oct 16, 2023
1 parent 5730d00 commit d8051ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions pool/_TEST_pool_router_test.gnoa
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pool

import (
"encoding/gjson"
"std"
"testing"

Expand Down Expand Up @@ -90,43 +91,47 @@ func TestPositionMint3000(t *testing.T) {
}

func TestFindBestPoolTruePositive(t *testing.T) {
bestPath := FindBestPool(
bestPoolPathDetail := FindBestPool(
"foo", // tokenA
"bar", // tokenB
true, // zeroForOne
500, // amountSpecified
)
shouldEQ(t, bestPath, "bar_foo_500")
jsonStr := gjson.Parse(bestPoolPathDetail)
shouldEQ(t, jsonStr.Get("response.data.token0_balance").Int(), 5987)
}

func TestFindBestPoolTrueNegative(t *testing.T) {
bestPath := FindBestPool(
bestPoolPathDetail := FindBestPool(
"foo", // tokenA
"bar", // tokenB
true, // zeroForOne
-5000, // amountSpecified
)
shouldEQ(t, bestPath, "bar_foo_500")
jsonStr := gjson.Parse(bestPoolPathDetail)
shouldEQ(t, jsonStr.Get("response.data.token0_balance").Int(), 5987)
}

func TestFindBestPoolFalsePositive(t *testing.T) {
bestPath := FindBestPool(
bestPoolPathDetail := FindBestPool(
"foo", // tokenA
"bar", // tokenB
false, // zeroForOne
50, // amountSpecified
)
shouldEQ(t, bestPath, "bar_foo_3000")
jsonStr := gjson.Parse(bestPoolPathDetail)
shouldEQ(t, jsonStr.Get("response.data.token0_balance").Int(), 79)
}

func TestFindBestPoolFalseNegative(t *testing.T) {
bestPath := FindBestPool(
bestPoolPathDetail := FindBestPool(
"foo", // tokenA
"bar", // tokenB
false, // zeroForOne
-1234, // amountSpecified
)
shouldEQ(t, bestPath, "bar_foo_500")
jsonStr := gjson.Parse(bestPoolPathDetail)
shouldEQ(t, jsonStr.Get("response.data.token0_balance").Int(), 5987)
}

func TestFindBestPoolWrong(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pool/pool_router.gno
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func FindBestPool(
}

if zeroForOne == true { // if token0 is being sold to buy token1, then we want to find the pool with the largest tick (more token1 can be bought)
return poolWithTick[maxTick]
return ApiGetPool(poolWithTick[maxTick])

} else { // if token1 is being sold to buy token0, then we want to find the pool with the smallest tick (more token0 can be bought)
return poolWithTick[minTick]
return ApiGetPool(poolWithTick[minTick])
}
}

Expand Down

0 comments on commit d8051ee

Please sign in to comment.