Omniscia Moby Audit

ViewAggregator Code Style Findings

ViewAggregator Code Style Findings

VAR-01C: Ineffectual Usage of Safe Arithmetics

Description:

The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

contracts/ViewAggregator.sol
61if (endIndex > positionRequestKeysLength) {
62 endIndex = positionRequestKeysLength;
63}
64
65PositionQueueInfo[] memory result = new PositionQueueInfo[](endIndex - positionRequestKeysStart);

Recommendation:

Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statement to be wrapped in an unchecked code block thereby optimizing its execution cost.

Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

An unchecked code block has been introduced to the referenced arithmetic operation, optimizing it as advised.

VAR-02C: Loop Iterator Optimization

Description:

The linked for loop increments / decrements the iterator "safely" due to Solidity's built-in safe arithmetics (post-0.8.X).

Example:

contracts/ViewAggregator.sol
67for (uint256 i = positionRequestKeysStart; i < endIndex; i++) {

Recommendation:

We advise the increment / decrement operation to be performed in an unchecked code block as the last statement within the for loop to optimize its execution cost.

Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

The referenced loop iterator's increment statement has been relocated at the end of the for loop's body and has been unwrapped in an unchecked code block, optimizing its gas cost.

VAR-03C: Suboptimal Struct Declaration Styles

Description:

The linked declaration styles of the referenced structs are using index-based argument initialization.

Example:

contracts/ViewAggregator.sol
73result[i - positionRequestKeysStart] = PositionQueueInfo(i, optionTokenId, minSize, amountIn, blockTime, isOpen);

Recommendation:

We advise the key-value declaration format to be utilized instead in each instance, greatly increasing the legibility of the codebase.

Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):

The Moby team opted to instead employ a key-assignment declaration style which we consider optimal and to achieve a similar purpose to the key-value declaration style, rendering this exhibit addressed.