Skip to content

Commit

Permalink
fix: sonarcube warning
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Dec 16, 2024
1 parent 03e4f52 commit 2aa6c3a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
8 changes: 4 additions & 4 deletions position/_RPC_dry.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ func DryMint(
tickCurrent int32,
tickLower int32,
tickUpper int32,
_amount0Desired string,
_amount1Desired string,
amount0DesiredStr string,
amount1DesiredStr string,
) (string, string) {
// FROM: position__liquidity_management.gno
sqrtRatioX96 := common.TickMathGetSqrtRatioAtTick(tickCurrent)
sqrtLowerX96 := common.TickMathGetSqrtRatioAtTick(tickLower)
sqrtUpperX96 := common.TickMathGetSqrtRatioAtTick(tickUpper)

amount0Desired := u256.MustFromDecimal(_amount0Desired)
amount1Desired := u256.MustFromDecimal(_amount1Desired)
amount0Desired := u256.MustFromDecimal(amount0DesiredStr)
amount1Desired := u256.MustFromDecimal(amount1DesiredStr)

liquidity := common.GetLiquidityForAmounts(
sqrtRatioX96,
Expand Down
24 changes: 11 additions & 13 deletions position/errors.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ import (
)

var (
errNoPermission = errors.New("[GNOSWAP-POSITION-001] caller has no permission")
errSlippage = errors.New("[GNOSWAP-POSITION-002] slippage failed")
errWrapUnwrap = errors.New("[GNOSWAP-POSITION-003] wrap, unwrap failed")
errOutOfRange = errors.New("[GNOSWAP-POSITION-004] out of range for numeric value")
errInvalidInput = errors.New("[GNOSWAP-POSITION-005] invalid input data")
errDataNotFound = errors.New("[GNOSWAP-POSITION-006] requested data not found")
errExpired = errors.New("[GNOSWAP-POSITION-007] transaction expired")
errWugnotMinimum = errors.New("[GNOSWAP-POSITION-008] can not wrap less than minimum amount")
errNotClear = errors.New("[GNOSWAP-POSITION-009] position is not clear")
errZeroLiquidity = errors.New("[GNOSWAP-POSITION-010] zero liquidity")
errInvalidAddress = errors.New("[GNOSWAP-POSITION-011] invalid address")
errNoPermission = errors.New("[GNOSWAP-POSITION-001] caller has no permission")
errSlippage = errors.New("[GNOSWAP-POSITION-002] slippage failed")
errWrapUnwrap = errors.New("[GNOSWAP-POSITION-003] wrap, unwrap failed")
errOutOfRange = errors.New("[GNOSWAP-POSITION-004] out of range for numeric value")
errInvalidInput = errors.New("[GNOSWAP-POSITION-005] invalid input data")
errDataNotFound = errors.New("[GNOSWAP-POSITION-006] requested data not found")
errExpired = errors.New("[GNOSWAP-POSITION-007] transaction expired")
errWugnotMinimum = errors.New("[GNOSWAP-POSITION-008] can not wrap less than minimum amount")
errNotClear = errors.New("[GNOSWAP-POSITION-009] position is not clear")
errZeroLiquidity = errors.New("[GNOSWAP-POSITION-010] zero liquidity")
errPositionExist = errors.New("[GNOSWAP-POSITION-011] position with same tokenId already exists")
)

// TODO:
// addDetailToError -> newErrorWithDetail
func addDetailToError(err error, detail string) string {
finalErr := ufmt.Errorf("%s || %s", err.Error(), detail)
return finalErr.Error()
Expand Down
66 changes: 34 additions & 32 deletions position/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func Mint(
fee uint32,
tickLower int32,
tickUpper int32,
_amount0Desired string, // *u256.Uint
_amount1Desired string, // *u256.Uint
_amount0Min string, // *u256.Uint
_amount1Min string, // *u256.Uint
amount0DesiredStr string,
amount1DesiredStr string,
amount0MinStr string,
amount1MinStr string,
deadline int64,
mintTo std.Address,
caller std.Address,
Expand Down Expand Up @@ -69,16 +69,16 @@ func Mint(

if token1 < token0 {
token0, token1 = token1, token0
_amount0Desired, _amount1Desired = _amount1Desired, _amount0Desired
_amount0Min, _amount1Min = _amount1Min, _amount0Min
amount0DesiredStr, amount1DesiredStr = amount1DesiredStr, amount0DesiredStr
amount0MinStr, amount1MinStr = amount1MinStr, amount0MinStr
tickLower, tickUpper = -tickUpper, -tickLower
token0IsNative, token1IsNative = token1IsNative, token0IsNative
}

amount0Desired := u256.MustFromDecimal(_amount0Desired)
amount1Desired := u256.MustFromDecimal(_amount1Desired)
amount0Min := u256.MustFromDecimal(_amount0Min)
amount1Min := u256.MustFromDecimal(_amount1Min)
amount0Desired := u256.MustFromDecimal(amount0DesiredStr)
amount1Desired := u256.MustFromDecimal(amount1DesiredStr)
amount0Min := u256.MustFromDecimal(amount0MinStr)
amount1Min := u256.MustFromDecimal(amount1MinStr)

// one of token amount can be 0 if position is out of range
// check this condition by using DryMint()
Expand Down Expand Up @@ -210,8 +210,10 @@ func mint(params MintParams) (uint64, *u256.Uint, *u256.Uint, *u256.Uint) {
}
updated := setPosition(tokenId, position)
if updated {
// TODO:
panic("position with same tokenId already exists")
panic(addDetailToError(
errPositionExist,
ufmt.Sprintf("tokenId(%d) already exists", tokenId),
))
}

return tokenId, liquidity, amount0, amount1
Expand All @@ -222,19 +224,19 @@ func mint(params MintParams) (uint64, *u256.Uint, *u256.Uint, *u256.Uint) {
// ref: https://docs.gnoswap.io/contracts/position/position.gno#increaseliquidity
func IncreaseLiquidity(
tokenId uint64,
_amount0Desired string, // uint256
_amount1Desired string, // uint256
_amount0Min string, // uint256
_amount1Min string, // uint256
amount0DesiredStr string,
amount1DesiredStr string,
amount0MinStr string,
amount1MinStr string,
deadline int64,
) (uint64, string, string, string, string) {
common.IsHalted()
en.MintAndDistributeGns()

amount0Desired := u256.MustFromDecimal(_amount0Desired)
amount1Desired := u256.MustFromDecimal(_amount1Desired)
amount0Min := u256.MustFromDecimal(_amount0Min)
amount1Min := u256.MustFromDecimal(_amount1Min)
amount0Desired := u256.MustFromDecimal(amount0DesiredStr)
amount1Desired := u256.MustFromDecimal(amount1DesiredStr)
amount0Min := u256.MustFromDecimal(amount0MinStr)
amount1Min := u256.MustFromDecimal(amount1MinStr)
increaseLiquidityParams := IncreaseLiquidityParams{
tokenId: tokenId,
amount0Desired: amount0Desired,
Expand Down Expand Up @@ -365,8 +367,8 @@ func increaseLiquidity(params IncreaseLiquidityParams) (uint64, *u256.Uint, *u25
func DecreaseLiquidity(
tokenId uint64,
liquidityRatio uint64,
_amount0Min string, // uint256
_amount1Min string, // uint256
amount0MinStr string,
amount1MinStr string,
deadline int64,
unwrapResult bool,
) (uint64, string, string, string, string, string, string) {
Expand All @@ -381,8 +383,8 @@ func DecreaseLiquidity(
))
}

amount0Min := u256.MustFromDecimal(_amount0Min)
amount1Min := u256.MustFromDecimal(_amount1Min)
amount0Min := u256.MustFromDecimal(amount0MinStr)
amount1Min := u256.MustFromDecimal(amount1MinStr)
decreaseLiquidityParams := DecreaseLiquidityParams{
tokenId: tokenId,
liquidityRatio: liquidityRatio,
Expand Down Expand Up @@ -537,10 +539,10 @@ func Reposition(
tokenId uint64,
tickLower int32,
tickUpper int32,
_amount0Desired string, // uint256
_amount1Desired string, // uint256
_amount0Min string, // *u256.Uint
_amount1Min string, // *u256.Uint
amount0Desired string, // uint25Str6
amount1DesiredStr string, // uint256
amount0MinStr string, // *u256.Uint
amount1MinStr string, // *u256.Uint
) (uint64, string, int32, int32, string, string) {
common.IsHalted()
en.MintAndDistributeGns()
Expand Down Expand Up @@ -600,10 +602,10 @@ func Reposition(
poolKey: position.poolKey,
tickLower: tickLower,
tickUpper: tickUpper,
amount0Desired: u256.MustFromDecimal(_amount0Desired),
amount1Desired: u256.MustFromDecimal(_amount1Desired),
amount0Min: u256.MustFromDecimal(_amount0Min),
amount1Min: u256.MustFromDecimal(_amount1Min),
amount0Desired: u256.MustFromDecimal(amount0Desired)Str,
amount1Desired: u256.MustFromDecimal(amount1DesiredStr),
amount0Min: u256.MustFromDecimal(amount0MinStr),
amount1Min: u256.MustFromDecimal(amount1MinStr),
caller: std.PrevRealm().Addr(),
},
)
Expand Down

0 comments on commit 2aa6c3a

Please sign in to comment.