Skip to content

Commit

Permalink
Merge pull request #191 from gnoswap-labs/GSW-908-feat-admin-can-add-…
Browse files Browse the repository at this point in the history
…remove-internal-staking-reward-pool-fix

GSW-908 feat: admin can change internal staking pool tiers
  • Loading branch information
notJoon authored Mar 13, 2024
2 parents 9abf1c7 + 5401e6b commit d233d8b
Show file tree
Hide file tree
Showing 30 changed files with 161 additions and 3,451 deletions.
2 changes: 1 addition & 1 deletion packages/big/uint256/uint256.gno
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ func (z *Uint) fromDecimal(bs string) error {
z.SetUint64(num)
} else {
base := NewUint(num)
z.UnsafeAdd(z, base.Mul(base, mult))
z.Add(z, base.Mul(base, mult))
}
// Chop off another 19 characters
if remaining > 19 {
Expand Down
16 changes: 0 additions & 16 deletions pool/_RPC_dry.gno
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,9 @@ func DrySwap(
liquidity: cache.liquidityStart,
}
}
// println("state.tick:", state.tick)
// println("IN state.sqrtPriceX96:", state.sqrtPriceX96.ToString())

// println("state.sqrtPriceX96:", state.sqrtPriceX96.ToString())
// continue swapping as long as we haven't used the entire input/output and haven't reached the price limit
for !(state.amountSpecifiedRemaining.IsZero()) && !(state.sqrtPriceX96.Eq(sqrtPriceLimitX96)) {
// println("state.amountSpecifiedRemaining:", state.amountSpecifiedRemaining.ToString())
var step StepComputations
step.sqrtPriceStartX96 = state.sqrtPriceX96

Expand Down Expand Up @@ -131,25 +127,13 @@ func DrySwap(
sqrtRatioTargetX96 = step.sqrtPriceNextX96
}

// println("state.sqrtPriceX96:", state.sqrtPriceX96.ToString())
// println("sqrtRatioTargetX96:", sqrtRatioTargetX96.ToString())
// println("state.liquidity:", state.liquidity.ToString())
// println("state.amountSpecifiedRemaining:", state.amountSpecifiedRemaining.ToString())
// println("pool.fee:", pool.fee)
state.sqrtPriceX96, step.amountIn, step.amountOut, step.feeAmount = swapMathComputeSwapStep(
state.sqrtPriceX96,
sqrtRatioTargetX96,
state.liquidity,
state.amountSpecifiedRemaining,
uint64(pool.fee),
)
if step.amountIn.ToString() == "271" {
// println("> state.sqrtPriceX96:", state.sqrtPriceX96.ToString())
// println("step.amountIn:", step.amountIn.ToString())
// println("step.amountOut:", step.amountOut.ToString())
// println("step.feeAmount:", step.feeAmount.ToString())
// panic("FIX")
}

amountInWithFee := i256.FromUint256(new(u256.Uint).Add(step.amountIn, step.feeAmount))
if exactInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestDrySwap_ZeroForOneTrue_AmountSpecified_Negative_16000(t *testing.T) {
consts.MIN_PRICE, // sqrtPriceLimitX96
)

shouldEQ(t, poolIn, "43512")
shouldEQ(t, poolIn, "43512") // r3v4_xxx: ROUNDING ERROR
shouldEQ(t, poolOut, "-16000")
}

Expand Down
Empty file.
File renamed without changes.
471 changes: 0 additions & 471 deletions pool/_TEST_pool_single_lp_test.gno_OK

This file was deleted.

81 changes: 0 additions & 81 deletions pool/_TEST_rpc_test.gno_OK

This file was deleted.

7 changes: 5 additions & 2 deletions pool/gno.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module gno.land/r/demo/pool

require (
gno.land/p/demo/u256 v0.0.0-latest
gno.land/p/demo/common v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
gno.land/r/demo/bar v0.0.0-latest
gno.land/r/demo/baz v0.0.0-latest
gno.land/r/demo/consts v0.0.0-latest
gno.land/r/demo/foo v0.0.0-latest
gno.land/r/demo/fred v0.0.0-latest
gno.land/r/demo/gns v0.0.0-latest
gno.land/r/demo/gov v0.0.0-latest
gno.land/r/demo/grc20_wrapper v0.0.0-latest
gno.land/r/demo/obl v0.0.0-latest
gno.land/r/demo/qux v0.0.0-latest
gno.land/r/demo/thud v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/demo/wugnot v0.0.0-latest
)
16 changes: 0 additions & 16 deletions pool/swap_math.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ func swapMathComputeSwapStep(
// NEGATIVE == EXACT_OUT => Estimated AmountIn
exactIn := !(amountRemaining.IsNeg()) // amountRemaining >= 0

// println()
// println("exactIn", exactIn) // f
// println("isToken1Expensive", isToken1Expensive) // t

if exactIn {
amountRemainingLessFee := u256.Zero()

Expand All @@ -47,31 +43,20 @@ func swapMathComputeSwapStep(
}
} else {
if isToken1Expensive {
// println(1)
amountOut = sqrtPriceMathGetAmount1DeltaHelper(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, false)
} else {
// println(2)
amountOut = sqrtPriceMathGetAmount0DeltaHelper(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, false)
}

if amountRemaining.Abs().Gte(amountOut) {
// println(3)
sqrtRatioNextX96 = sqrtRatioTargetX96
} else {
// println(4)
// println("sqrtRatioCurrentX96:", sqrtRatioCurrentX96.ToString())
// println("liquidity:", liquidity.ToString())
// println("amountRemaining.Abs():", amountRemaining.Abs().ToString())
// println("isToken1Expensive:", isToken1Expensive)
// println("<< SQRT")
sqrtRatioNextX96 = sqrtPriceMathGetNextSqrtPriceFromOutput(
sqrtRatioCurrentX96,
liquidity,
amountRemaining.Abs(),
isToken1Expensive,
)
// println("sqrtRatioNextX96:", sqrtRatioNextX96.ToString())
// panic("F")
}
}

Expand Down Expand Up @@ -117,6 +102,5 @@ func swapMathComputeSwapStep(
if !exactIn && !(amountOut.IsZero()) {
amountOut = amountOut.Add(amountOut, u256.NewUint(1))
}
// println()
return sqrtRatioNextX96, amountIn, amountOut, feeAmount
}
174 changes: 0 additions & 174 deletions pool/tick_bitmap_test.gno

This file was deleted.

Loading

0 comments on commit d233d8b

Please sign in to comment.