diff --git a/position/position.gno b/position/position.gno index 1d37bfff..34a04027 100644 --- a/position/position.gno +++ b/position/position.gno @@ -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 @@ -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)) @@ -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)) diff --git a/position/utils.gno b/position/utils.gno index c91bf346..bd26ea90 100644 --- a/position/utils.gno +++ b/position/utils.gno @@ -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 {