Skip to content

refactor: addressing audit - #235

Merged
kupermind merged 54 commits into
pol_testingfrom
pol_testing2
Oct 24, 2025
Merged

refactor: addressing audit#235
kupermind merged 54 commits into
pol_testingfrom
pol_testing2

Conversation

@kupermind

Copy link
Copy Markdown
Contributor
  • Addressing audit.

@kupermind
kupermind requested review from 77ph and mariapiamo October 13, 2025 17:00

@77ph 77ph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function _increaseLiquidity

        (aMin[0], aMin[1]) =
            LiquidityAmounts.getAmountsForLiquidity(sqrtPriceX96, sqrtAB[0], sqrtAB[1], liquidity);
        aMin[0] = inputAmounts[0] * (MAX_BPS - maxSlippage) / MAX_BPS;
        aMin[1] = inputAmounts[1] * (MAX_BPS - maxSlippage) / MAX_BPS;

to

        uint256[] memory aMin = new uint256[](2);
        (aMin[0], aMin[1]) =
            LiquidityAmounts.getAmountsForLiquidity(sqrtPriceX96, sqrtAB[0], sqrtAB[1], liquidity);
        aMin[0] = aMin[0] * (MAX_BPS - maxSlippage) / MAX_BPS;
        aMin[1] = aMin[1] * (MAX_BPS - maxSlippage) / MAX_BPS;

@77ph 77ph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double check

function _roundDownToSpacing(int24 tick, int24 spacing) internal pure returns (int24) {
    int24 r = tick % spacing;
    return r == 0 ? tick : (tick - r);
}
function _roundUpToSpacing(int24 tick, int24 spacing) internal pure returns (int24) {
    int24 r = tick % spacing;
    return r == 0 ? tick : (tick - r + spacing);
}

for negative int
Example: tick = -7, spacing = 10
Maybe

function _roundDownToSpacing(int24 tick, int24 spacing) internal pure returns (int24) {
    int24 r = tick % spacing;
    return r == 0 ? tick : (r > 0 ? tick - r : tick - (r + spacing));
}

function _roundUpToSpacing(int24 tick, int24 spacing) internal pure returns (int24) {
    int24 r = tick % spacing;
    return r == 0 ? tick : (r > 0 ? tick + (spacing - r) : tick - r);
}

@77ph 77ph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hiMinMax[0] = _roundUpToSpacing(ct + 1, tickSpacing);
if (hiMinMax[0] <= loHiBest[0]) hiMinMax[0] = loHiBest[0] + tickSpacing;

hiMinMax[1] = _roundDownToSpacing(TickMath.MAX_TICK, tickSpacing);
if (hiMinMax[1] <= hiMinMax[0]) hiMinMax[1] = hiMinMax[0] + tickSpacing; // <--- triple check out of MAX_TICK

@77ph 77ph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        // Snap to spacing + safety margins
        int24 minSafe = _roundUpToSpacing(TickMath.MIN_TICK, tickSpacing);
        minSafe += SAFETY_STEPS * tickSpacing;
        int24 maxSafe = _roundDownToSpacing(TickMath.MAX_TICK, tickSpacing);
        minSafe -= SAFETY_STEPS * tickSpacing;

double minSafe (typo)

77ph

This comment was marked as outdated.

@77ph 77ph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    function optimizeLiquidityAmounts(
...
    ) external pure returns (int24[] memory loHi, uint128 liquidity, uint256[] memory amountsDesired) {
-> amountsDesired = initialAmounts; --> double check copy array-to-array

@kupermind
kupermind merged commit 5564d75 into pol_testing Oct 24, 2025
2 checks passed
@kupermind
kupermind deleted the pol_testing2 branch October 24, 2025 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants