Skip to content

Commit

Permalink
Merge pull request #126 from gnoswap-labs/GSW-685-fix-cannot-decrease…
Browse files Browse the repository at this point in the history
…-liquidity-at-staked-position

GSW-685 fix: cannot decrease liquidity at staked position
  • Loading branch information
notJoon authored Dec 14, 2023
2 parents 83b2ff3 + 5cf925f commit 926014d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions position/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

p "gno.land/r/demo/pool"

nft "gno.land/r/demo/gnft"
"gno.land/r/demo/gnft"
)

var (
Expand Down Expand Up @@ -74,7 +74,7 @@ func mint(params MintParams) (uint64, bigint, bigint, bigint) {
tokenId := nextId
nextId++ // nextId = nextId + 1

nft.Mint(a2u(GetOrigCaller()), tid(tokenId)) // owner, tokenId
gnft.Mint(a2u(GetOrigCaller()), tid(tokenId)) // owner, tokenId

positionKey := positionKeyCompute(GetOrigPkgAddr(), params.tickLower, params.tickUpper)
feeGrowthInside0LastX128, feeGrowthInside1LastX128 := pool.PoolGetPositionFeeGrowthInside0LastX128(positionKey), pool.PoolGetPositionFeeGrowthInside1LastX128(positionKey)
Expand Down Expand Up @@ -170,7 +170,10 @@ func DecreaseLiquidity(
}

func decreaseLiquidity(params DecreaseLiquidityParams) (bigint, bigint) {
isAuthorizedForToken(params.tokenId)
// MUST BE OWNER TO DECREASE LIQUIDITY ( can not be approved address )
owner := gnft.OwnerOf(tid(params.tokenId))
require(owner == GetOrigCaller(), ufmt.Sprintf("[POSITION] position.gno__decreaseLiquidity() || only owner can decrease liquidity__owner(%s) == GetOrigCaller(%s)", owner, GetOrigCaller()))

checkDeadline(params.deadline)
require(params.liquidity >= 0, ufmt.Sprintf("[POSITION] position.gno__decreaseLiquidity() || liquidity(%d) >= 0", params.liquidity))

Expand Down Expand Up @@ -295,7 +298,7 @@ func burn(tokenId uint64) {
require(position.isClear(), ufmt.Sprintf("[POSITION] position.gno__burn() || position(tokenId:%d) isn't clear(has something)", tokenId))

delete(positions, tokenId)
nft.Burn(tid(tokenId))
gnft.Burn(tid(tokenId))
}

func isAuthorizedForToken(tokenId uint64) {
Expand Down
2 changes: 1 addition & 1 deletion position/util.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func require(condition bool, message string) {
}

func checkDeadline(deadline bigint) {
require(bigint(GetTimestamp()) <= deadline, ufmt.Sprintf("[POSITION] util.gno__checkDeadline() || transaction too old__GetTimestamp()(%d) <= deadline(%s)", GetTimestamp(), deadline))
require(bigint(GetTimestamp()) <= deadline, ufmt.Sprintf("[POSITION] util.gno__checkDeadline() || transaction too old__GetTimestamp()(%d) <= deadline(%d)", GetTimestamp(), deadline))
}

func a2u(addr std.Address) users.AddressOrName {
Expand Down

0 comments on commit 926014d

Please sign in to comment.