Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/pool total #442

Merged
merged 10 commits into from
Dec 18, 2024
14 changes: 9 additions & 5 deletions _deploy/r/gnoswap/consts/consts.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (

// GNOSWAP SERVICE
const (
ADMIN std.Address = "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d" // Admin
DEV_OPS std.Address = "g1mjvd83nnjee3z2g7683er55me9f09688pd4mj9" // DevOps

ADMIN std.Address = "g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d"
DEV_OPS std.Address = "g1mjvd83nnjee3z2g7683er55me9f09688pd4mj9"
TOKEN_REGISTER std.Address = "g1er355fkjksqpdtwmhf5penwa82p0rhqxkkyhk5"

TOKEN_REGISTER_NAMESPACE string = "gno.land/r/g1er355fkjksqpdtwmhf5penwa82p0rhqxkkyhk5"
Expand All @@ -21,7 +20,8 @@ const (
GNOT string = "gnot"
WRAPPED_WUGNOT string = "gno.land/r/demo/wugnot"

UGNOT_MIN_DEPOSIT_TO_WRAP uint64 = 1000 // defined in https://github.com/gnolang/gno/blob/81a88a2976ba9f2f9127ebbe7fb7d1e1f7fa4bd4/examples/gno.land/r/demo/wugnot/wugnot.gno#L19
// defined in https://github.com/gnolang/gno/blob/81a88a2976ba9f2f9127ebbe7fb7d1e1f7fa4bd4/examples/gno.land/r/demo/wugnot/wugnot.gno#L19
UGNOT_MIN_DEPOSIT_TO_WRAP uint64 = 1000
)

// CONTRACT PATH & ADDRESS
Expand Down Expand Up @@ -91,9 +91,11 @@ const (

MAX_UINT128 string = "340282366920938463463374607431768211455"
MAX_UINT160 string = "1461501637330902918203684832716283019655932542975"
MAX_INT256 string = "57896044618658097711785492504343953926634992332820282019728792003956564819968"
MAX_UINT256 string = "115792089237316195423570985008687907853269984665640564039457584007913129639935"

MAX_INT128 string = "170141183460469231731687303715884105727"
MAX_INT256 string = "57896044618658097711785492504343953926634992332820282019728792003956564819968"

// Tick Related
MIN_TICK int32 = -887272
MAX_TICK int32 = 887272
Expand All @@ -108,6 +110,8 @@ const (
Q64 string = "18446744073709551616" // 2 ** 64
Q96 string = "79228162514264337593543950336" // 2 ** 96
Q128 string = "340282366920938463463374607431768211456" // 2 ** 128

Q128_RESOLUTION uint = 128
)

// TIMESTAMP & DAY
Expand Down
9 changes: 7 additions & 2 deletions pool/errors.gno
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ var (
errTransferFailed = errors.New("[GNOSWAP-POOL-021] token transfer failed")
errInvalidTickAndTickSpacing = errors.New("[GNOSWAP-POOL-022] invalid tick and tick spacing requested")
errInvalidAddress = errors.New("[GNOSWAP-POOL-023] invalid address")
errInvalidTickRange = errors.New("[GNOSWAP-POOL-024] tickLower is greater than tickUpper")
errUnderflow = errors.New("[GNOSWAP-POOL-025] underflow") // TODO: make as common error code
errInvalidTickRange = errors.New("[GNOSWAP-POOL-024] tickLower is greater than or equal to tickUpper")
errUnderflow = errors.New("[GNOSWAP-POOL-025] underflow")
errOverFlow = errors.New("[GNOSWAP-POOL-026] overflow")
errBalanceUpdateFailed = errors.New("[GNOSWAP-POOL-027] balance update failed")
errTickLowerInvalid = errors.New("[GNOSWAP-POOL-028] tickLower is invalid")
errTickUpperInvalid = errors.New("[GNOSWAP-POOL-029] tickUpper is invalid")
errTickLowerGtTickUpper = errors.New("[GNOSWAP-POOL-030] tickLower is greater than tickUpper")
)

// addDetailToError adds detail to an error message
Expand Down
45 changes: 21 additions & 24 deletions pool/getter.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pool

// pool
func PoolGetPoolList() []string {
poolPaths := []string{}
for poolPath, _ := range pools {
Expand All @@ -11,91 +10,89 @@ func PoolGetPoolList() []string {
}

func PoolGetToken0Path(poolPath string) string {
return mustGetPool(poolPath).GetToken0Path()
return mustGetPool(poolPath).Token0Path()
}

func PoolGetToken1Path(poolPath string) string {
return mustGetPool(poolPath).GetToken1Path()
return mustGetPool(poolPath).Token1Path()
}

func PoolGetFee(poolPath string) uint32 {
return mustGetPool(poolPath).GetFee()
return mustGetPool(poolPath).Fee()
}

func PoolGetBalanceToken0(poolPath string) string {
return mustGetPool(poolPath).GetBalanceToken0().ToString()
return mustGetPool(poolPath).BalanceToken0().ToString()
}

func PoolGetBalanceToken1(poolPath string) string {
return mustGetPool(poolPath).GetBalanceToken1().ToString()
return mustGetPool(poolPath).BalanceToken1().ToString()
}

func PoolGetTickSpacing(poolPath string) int32 {
return mustGetPool(poolPath).GetTickSpacing()
return mustGetPool(poolPath).TickSpacing()
}

func PoolGetMaxLiquidityPerTick(poolPath string) string {
return mustGetPool(poolPath).GetMaxLiquidityPerTick().ToString()
return mustGetPool(poolPath).MaxLiquidityPerTick().ToString()
}

func PoolGetSlot0SqrtPriceX96(poolPath string) string {
return mustGetPool(poolPath).GetSlot0SqrtPriceX96().ToString()
return mustGetPool(poolPath).Slot0SqrtPriceX96().ToString()
}

func PoolGetSlot0Tick(poolPath string) int32 {
return mustGetPool(poolPath).GetSlot0Tick()
return mustGetPool(poolPath).Slot0Tick()
}

func PoolGetSlot0FeeProtocol(poolPath string) uint8 {
return mustGetPool(poolPath).GetSlot0FeeProtocol()
return mustGetPool(poolPath).Slot0FeeProtocol()
}

func PoolGetSlot0Unlocked(poolPath string) bool {
return mustGetPool(poolPath).GetSlot0Unlocked()
return mustGetPool(poolPath).Slot0Unlocked()
}

func PoolGetFeeGrowthGlobal0X128(poolPath string) string {
return mustGetPool(poolPath).GetFeeGrowthGlobal0X128().ToString()
return mustGetPool(poolPath).FeeGrowthGlobal0X128().ToString()
}

func PoolGetFeeGrowthGlobal1X128(poolPath string) string {
return mustGetPool(poolPath).GetFeeGrowthGlobal1X128().ToString()
return mustGetPool(poolPath).FeeGrowthGlobal1X128().ToString()
}

func PoolGetProtocolFeesToken0(poolPath string) string {
return mustGetPool(poolPath).GetProtocolFeesToken0().ToString()
return mustGetPool(poolPath).ProtocolFeesToken0().ToString()
}

func PoolGetProtocolFeesToken1(poolPath string) string {
return mustGetPool(poolPath).GetProtocolFeesToken1().ToString()
return mustGetPool(poolPath).ProtocolFeesToken1().ToString()
}

func PoolGetLiquidity(poolPath string) string {
return mustGetPool(poolPath).GetLiquidity().ToString()
return mustGetPool(poolPath).Liquidity().ToString()
}

// position
func PoolGetPositionLiquidity(poolPath, key string) string {
return mustGetPool(poolPath).GetPositionLiquidity(key).ToString()
return mustGetPool(poolPath).PositionLiquidity(key).ToString()
}

func PoolGetPositionFeeGrowthInside0LastX128(poolPath, key string) string {
return mustGetPool(poolPath).GetPositionFeeGrowthInside0LastX128(key).ToString()
return mustGetPool(poolPath).PositionFeeGrowthInside0LastX128(key).ToString()
}

func PoolGetPositionFeeGrowthInside1LastX128(poolPath, key string) string {
return mustGetPool(poolPath).GetPositionFeeGrowthInside1LastX128(key).ToString()
return mustGetPool(poolPath).PositionFeeGrowthInside1LastX128(key).ToString()
}

func PoolGetPositionTokensOwed0(poolPath, key string) string {
return mustGetPool(poolPath).GetPositionTokensOwed0(key).ToString()
return mustGetPool(poolPath).PositionTokensOwed0(key).ToString()
}

func PoolGetPositionTokensOwed1(poolPath, key string) string {
return mustGetPool(poolPath).GetPositionTokensOwed1(key).ToString()
return mustGetPool(poolPath).PositionTokensOwed1(key).ToString()
}

// tick
func PoolGetTickLiquidityGross(poolPath string, tick int32) string {
return mustGetPool(poolPath).GetTickLiquidityGross(tick).ToString()
}
Expand Down
4 changes: 2 additions & 2 deletions pool/liquidity_math.gno
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func liquidityMathAddDelta(x *u256.Uint, y *i256.Int) *u256.Uint {
if z.Gte(x) {
panic(addDetailToError(
errLiquidityCalculation,
ufmt.Sprintf("Less than Condition(z must be < x) (x: %s, y: %s, z:%s)", x.ToString(), y.ToString(), z.ToString()),
ufmt.Sprintf("Condition failed: (z must be < x) (x: %s, y: %s, z:%s)", x.ToString(), y.ToString(), z.ToString()),
))
}
} else {
z = new(u256.Uint).Add(x, y.Abs())
if z.Lt(x) {
panic(addDetailToError(
errLiquidityCalculation,
ufmt.Sprintf("Less than or Equal Condition(z must be >= x) (x: %s, y: %s, z:%s)", x.ToString(), y.ToString(), z.ToString()),
ufmt.Sprintf("Condition failed: (z must be >= x) (x: %s, y: %s, z:%s)", x.ToString(), y.ToString(), z.ToString()),
))
}
}
Expand Down
4 changes: 2 additions & 2 deletions pool/liquidity_math_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestLiquidityMathAddDelta(t *testing.T) {
},
wantPanic: addDetailToError(
errLiquidityCalculation,
ufmt.Sprintf("Less than Condition(z must be < x) (x: 0, y: -100, z:115792089237316195423570985008687907853269984665640564039457584007913129639836)")),
ufmt.Sprintf("Condition failed: (z must be < x) (x: 0, y: -100, z:115792089237316195423570985008687907853269984665640564039457584007913129639836)")),
},
{
name: "overflow panic with add delta",
Expand All @@ -53,7 +53,7 @@ func TestLiquidityMathAddDelta(t *testing.T) {
},
wantPanic: addDetailToError(
errLiquidityCalculation,
ufmt.Sprintf("Less than or Equal Condition(z must be >= x) (x: 115792089237316195423570985008687907853269984665640564039457584007913129639935, y: 100, z:99)")),
ufmt.Sprintf("Condition failed: (z must be >= x) (x: 115792089237316195423570985008687907853269984665640564039457584007913129639935, y: 100, z:99)")),
},
}

Expand Down
Loading
Loading