Omniscia Steer Protocol Audit

FlatPosition3 Code Style Findings

FlatPosition3 Code Style Findings

FP3-01C: Optimization of Conditional Evaluations

Description:

The referenced conditional evaluations are sub-optimal and result in redundant overlapping conditions being evaluated.

Example:

src/FlatPosition3.sol
48// Determine the ratios to use the maximum amount of token0 and token1
49uint256 ratio0 = (amount0Wanted > 0 && token0Desired > 0) ? (token0Desired * 1e18) / amount0Wanted : 0;
50uint256 ratio1 = (amount1Wanted > 0 && token1Desired > 0) ? (token1Desired * 1e18) / amount1Wanted : 0;
51
52// Use the smaller ratio to ensure we stay within token limits
53uint256 minRatio =
54 ratio0 > 0 && ratio1 > 0 ? (ratio0 < ratio1 ? ratio0 : ratio1) : (ratio0 > 0 ? ratio0 : ratio1);

Recommendation:

We advise the ratio0, ratio1, and minRatio variables to be declared at the beginning of this code block.

Afterward, we advise the ratio0 and ratio1 assignments to be performed in a dedicated conditional block rather than using a ternary condition.

This permits the ratio0 assignment to also assign the minRatio without any extra condition, and the ratio1 assignment to assign the minRatio if minRatio > ratio1 || minRatio == 0.

Alleviation:

The Steer Protocol team evaluated this exhibit but opted to acknowledge it in the current iteration of the codebase.

FP3-02C: Recalculation of Square Root Ratios at Ticks

Description:

The referenced operations will re-calculate the lowerTick and upperTick square root ratio encoded price points redundantly.

Example:

src/FlatPosition3.sol
40// Calculate the amount of liquidity to mint using proportional amounts of token0 and token1
41(uint256 amount0Wanted, uint256 amount1Wanted) = LiquidityAmounts.getAmountsForLiquidity(
42 sqrtPriceX96,
43 TickMath.getSqrtRatioAtTick(lowerTick),
44 TickMath.getSqrtRatioAtTick(upperTick),
45 uint128(1e18) // Use full liquidity precision
46);
47
48// Determine the ratios to use the maximum amount of token0 and token1
49uint256 ratio0 = (amount0Wanted > 0 && token0Desired > 0) ? (token0Desired * 1e18) / amount0Wanted : 0;
50uint256 ratio1 = (amount1Wanted > 0 && token1Desired > 0) ? (token1Desired * 1e18) / amount1Wanted : 0;
51
52// Use the smaller ratio to ensure we stay within token limits
53uint256 minRatio =
54 ratio0 > 0 && ratio1 > 0 ? (ratio0 < ratio1 ? ratio0 : ratio1) : (ratio0 > 0 ? ratio0 : ratio1);
55
56// Adjust the total token amounts and calculate final liquidity
57total0 = (amount0Wanted * minRatio) / 1e18;
58total1 = (amount1Wanted * minRatio) / 1e18;
59
60liquidity[0] = LiquidityAmounts.getLiquidityForAmounts(
61 sqrtPriceX96, TickMath.getSqrtRatioAtTick(lowerTick), TickMath.getSqrtRatioAtTick(upperTick), total0, total1
62);

Recommendation:

We advise the calculations to be performed once and stored to local variables that are consequently re-used, optimizing the code's gas cost.

Alleviation:

The square root ratio calculations were cached and optimized as advised.

FP3-03C: Repetitive Value Literal

Description:

The linked value literal is repeated across the codebase multiple times.

Example:

src/FlatPosition3.sol
45uint128(1e18) // Use full liquidity precision

Recommendation:

We advise it to be set to a constant variable instead, optimizing the legibility of the codebase.

In case the constant has already been declared, we advise it to be properly re-used across the code.

Alleviation:

The referenced value literal 1e18 has been properly relocated to a contract-level constant declaration labelled PRECISION, optimizing the code's legibility.