Skip to content

Commit

Permalink
Merge pull request #125 from gnoswap-labs/GSW-679-fix-position-remove…
Browse files Browse the repository at this point in the history
…-liquditiy

GSW-679 fix: position liquidity
  • Loading branch information
notJoon committed Dec 13, 2023
2 parents e53ede0 + 7a5e12c commit 83b2ff3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
15 changes: 3 additions & 12 deletions position/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,12 @@ func increaseLiquidity(params IncreaseLiquidityParams) (bigint, bigint, bigint)
func DecreaseLiquidity(
tokenId uint64,
liquidity bigint,
amount0Min bigint,
amount1Min bigint,
deadline bigint,
) (bigint, bigint) {
decreaseLiquidityParams := DecreaseLiquidityParams{
tokenId: tokenId,
liquidity: liquidity,
amount0Min: amount0Min,
amount1Min: amount1Min,
deadline: deadline,
tokenId: tokenId,
liquidity: liquidity,
deadline: deadline,
}

return decreaseLiquidity(decreaseLiquidityParams)
Expand All @@ -184,9 +180,6 @@ func decreaseLiquidity(params DecreaseLiquidityParams) (bigint, bigint) {
position := positions[params.tokenId]

positionLiquidity := position.liquidity
// r3v4_xxx
// panic or remove entire liquidity(for now)
// require(positionLiquidity >= params.liquidity, ufmt.Sprintf("[POSITION] position.gno__decreaseLiquidity() || positionLiquidity(%s) >= params.liquidity(%s)", positionLiquidity, params.liquidity))
if positionLiquidity < params.liquidity {
// remove entire liquidity
params.liquidity = positionLiquidity
Expand All @@ -197,8 +190,6 @@ func decreaseLiquidity(params DecreaseLiquidityParams) (bigint, bigint) {

amount0, amount1 := p.Burn(pToken0, pToken1, pFee, position.tickLower, position.tickUpper, params.liquidity)

require(amount0 >= params.amount0Min && amount1 >= params.amount1Min, ufmt.Sprintf("[POSITION] position.gno__decreaseLiquidity() || amount0(%s) >= params.amount0Min(%s) && amount1(%s) >= params.amount1Min(%s)", amount0, params.amount0Min, amount1, params.amount1Min))

positionKey := positionKeyCompute(GetOrigPkgAddr(), position.tickLower, position.tickUpper)
feeGrowthInside0LastX128, feeGrowthInside1LastX128 := pool.PoolGetPositionFeeGrowthInside0LastX128(positionKey), pool.PoolGetPositionFeeGrowthInside1LastX128(positionKey)

Expand Down
8 changes: 3 additions & 5 deletions position/type.gno
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ type IncreaseLiquidityParams struct {
}

type DecreaseLiquidityParams struct {
tokenId uint64
liquidity bigint
amount0Min bigint
amount1Min bigint
deadline bigint
tokenId uint64
liquidity bigint
deadline bigint
}

type CollectParams struct {
Expand Down

0 comments on commit 83b2ff3

Please sign in to comment.