Skip to content

Commit

Permalink
mv: assert functions
Browse files Browse the repository at this point in the history
  • Loading branch information
notJoon committed Dec 18, 2024
1 parent 689a21d commit 9d4992e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
24 changes: 1 addition & 23 deletions position/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,7 @@ func Reposition(
oldTickLower := position.tickLower
oldTickUpper := position.tickUpper

if !(position.isClear()) {
panic(addDetailToError(
errNotClear,
ufmt.Sprintf("position(%d) isn't clear(liquidity:%s, tokensOwed0:%s, tokensOwed1:%s)", tokenId, position.liquidity.ToString(), position.tokensOwed0.ToString(), position.tokensOwed1.ToString()),
))
}
checkPositionHasClear(position)

token0, token1, _ := splitOf(position.poolKey)
// check if gnot pool
Expand Down Expand Up @@ -950,14 +945,6 @@ func isAuthorizedForToken(tokenId uint64) {
}
}

func verifyTokenIdAndOwnership(tokenId uint64) {
assertTokenExists(tokenId)

owner := gnft.OwnerOf(tokenIdFrom(tokenId))
caller := std.PrevRealm().Addr()
assertCallerIsOwner(tokenId, owner, caller)
}

func calculateLiquidityToRemove(positionLiquidity *u256.Uint, liquidityRatio uint64) *u256.Uint {
liquidityToRemove := new(u256.Uint).Mul(positionLiquidity, u256.NewUint(liquidityRatio))
liquidityToRemove = new(u256.Uint).Div(liquidityToRemove, u256.NewUint(100))
Expand All @@ -968,15 +955,6 @@ func calculateLiquidityToRemove(positionLiquidity *u256.Uint, liquidityRatio uin
return liquidityToRemove
}

func verifyBurnedAmounts(burnedAmount0, burnedAmount1, amount0Min, amount1Min *u256.Uint) {
if !(burnedAmount0.Gte(amount0Min) && burnedAmount1.Gte(amount1Min)) {
panic(addDetailToError(
errSlippage,
ufmt.Sprintf("burnedAmount0(%s) >= amount0Min(%s) && burnedAmount1(%s) >= amount1Min(%s)", burnedAmount0.ToString(), amount0Min.ToString(), burnedAmount1.ToString(), amount1Min.ToString()),
))
}
}

func handleUnwrap(pToken0, pToken1 string, unwrapResult bool, userOldWugnotBalance uint64, to std.Address) {
if (pToken0 == consts.WRAPPED_WUGNOT || pToken1 == consts.WRAPPED_WUGNOT) && unwrapResult {
userNewWugnotBalance := wugnot.BalanceOf(a2u(to))
Expand Down
17 changes: 17 additions & 0 deletions position/utils.gno
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ func assertOnlyValidAddressWith(prevAddr, otherAddr std.Address) {
}
}

func verifyTokenIdAndOwnership(tokenId uint64) {
assertTokenExists(tokenId)

owner := gnft.OwnerOf(tokenIdFrom(tokenId))
caller := std.PrevRealm().Addr()
assertCallerIsOwner(tokenId, owner, caller)
}

func verifyBurnedAmounts(burnedAmount0, burnedAmount1, amount0Min, amount1Min *u256.Uint) {
if !(burnedAmount0.Gte(amount0Min) && burnedAmount1.Gte(amount1Min)) {
panic(addDetailToError(
errSlippage,
ufmt.Sprintf("burnedAmount0(%s) >= amount0Min(%s) && burnedAmount1(%s) >= amount1Min(%s)", burnedAmount0.ToString(), amount0Min.ToString(), burnedAmount1.ToString(), amount1Min.ToString()),
))
}
}

// region: helper

func GetOrigPkgAddr() std.Address {
Expand Down

0 comments on commit 9d4992e

Please sign in to comment.