Omniscia Moby Audit
OlpManager Code Style Findings
OlpManager Code Style Findings
OMR-01C: Deprecated Revert Pattern
Type | Severity | Location |
---|---|---|
Standard Conformity | OlpManager.sol:L118, L128 |
Description:
The referenced revert
statements will yield a textual description of the error which is an abandoned practice.
Example:
118if (inPrivateMode) { revert("OlpManager: action not enabled"); }
Recommendation:
We advise custom error
declarations to be introduced to the OlpManager
and consequently utilized in place of the referenced messages, optimizing the code's gas cost as well as legibility.
Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
A dedicated ActionNotEnabled
error declaration has been introduced that is correspondingly yielded by the revert
statements referenced, addressing this exhibit.
OMR-02C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | OlpManager.sol:L171, L330 |
Description:
The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require
checks or if-else
constructs.
Example:
168if (positionValue > aum) {169 aum = 0;170} else {171 aum = aum - positionValue;172}
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):
All referenced arithmetic operations have been wrapped in an unchecked
code block safely, optimizing their gas cost whilst retaining their security guarantees via preceding conditionals.
OMR-03C: Loop Iterator Optimizations
Type | Severity | Location |
---|---|---|
Gas Optimization | OlpManager.sol:L190, L266 |
Description:
The linked for
loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X
).
Example:
190for (uint256 i = 0; i < whitelistedTokens.length; i++) {
Recommendation:
We advise the increment / decrement operations to be performed in an unchecked
code block as the last statement within each for
loop to optimize their execution cost.
Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
The referenced loop iterator increment statements have been relocated at the end of each respective for
loop's body and have been unwrapped in an unchecked
code block, optimizing their gas cost.
OMR-04C: Redundant Code Repetition
Type | Severity | Location |
---|---|---|
Gas Optimization | OlpManager.sol:L193-L208, L219-L239 |
Description:
The referenced code blocks will be repeated across OlpManager::getTotalOlpAssetUsd
and OlpManager::getOlpAssetUsd
.
Example:
180// get total pool, pending mp, pending rp, reserved, utilized, available, deposited amounts of olp asset (regardless of token)181function getTotalOlpAssetUsd(bool _maximise) public override view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256) {182 uint256 totalPoolUsd = 0;183 uint256 totalPendingMpUsd = 0;184 uint256 totalPendingRpUsd = 0;185 uint256 totalReservedUsd = 0;186 uint256 totalUtilizedUsd = 0;187 188 address[] memory whitelistedTokens = vaultUtils.getWhitelistedTokens();189
190 for (uint256 i = 0; i < whitelistedTokens.length; i++) {191 address token = whitelistedTokens[i];192
193 uint256 price = vaultPriceFeed.getSpotPrice(token, _maximise);194 uint256 decimal = vault.tokenDecimals(token);195
196 (197 uint256 poolAmounts,198 uint256 pendingMpAmounts,199 uint256 pendingRpAmounts,200 uint256 reservedAmounts,201 uint256 utilizedAmounts,,202 ) = getOlpAssetAmounts(whitelistedTokens[i]);203
204 totalPoolUsd += (poolAmounts * price) / (10 ** decimal);205 totalPendingMpUsd += (pendingMpAmounts * price) / (10 ** decimal);206 totalPendingRpUsd += (pendingRpAmounts * price) / (10 ** decimal);207 totalReservedUsd += (reservedAmounts * price) / (10 ** decimal);208 totalUtilizedUsd += (utilizedAmounts * price) / (10 ** decimal);209 }210
211 uint256 totalAvailableUsd = totalPoolUsd - totalPendingMpUsd - totalPendingRpUsd - totalReservedUsd;212 uint256 totalDepositedUsd = totalAvailableUsd + totalUtilizedUsd;213
214 return (totalPoolUsd, totalPendingMpUsd, totalPendingRpUsd, totalReservedUsd, totalUtilizedUsd, totalAvailableUsd, totalDepositedUsd);215}216
217// get pool, pending mp, pending rp, reserved, utilized, available, deposited usd of token in olp218function getOlpAssetUsd(address _token, bool _maximise) public override view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256) {219 (220 uint256 poolAmounts,221 uint256 pendingMpAmounts,222 uint256 pendingRpAmounts,223 uint256 reservedAmounts,224 uint256 utilizedAmounts,,225 ) = getOlpAssetAmounts(_token);226
227 uint256 price = vaultPriceFeed.getSpotPrice(_token, _maximise);228 uint256 decimal = vault.tokenDecimals(_token);229 230 uint256 poolUsd = (poolAmounts * price) / (10 ** decimal);231 uint256 pendingMpUsd = (pendingMpAmounts * price) / (10 ** decimal);232 uint256 pendingRpUsd = (pendingRpAmounts * price) / (10 ** decimal);233 uint256 reservedUsd = (reservedAmounts * price) / (10 ** decimal);234 uint256 utilizedUsd = (utilizedAmounts * price) / (10 ** decimal);235
236 uint256 availableUsd = poolUsd - pendingMpUsd - pendingRpUsd - reservedUsd;237 uint256 depositedUsd = availableUsd + utilizedUsd;238 239 return (poolUsd, pendingMpUsd, pendingRpUsd, reservedUsd, utilizedUsd, availableUsd, depositedUsd);240}
Recommendation:
We advise them to be relocated to an internal
function that is underscore-prefixed (_
), optimizing the bytecode size as well as legibility of the codebase.
Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
The code has been refactored permitting both functions to rely on an internal OlpManager::_getOlpAssetUsd
function, optimizing the code's maintainability as well as bytecode size.
OMR-05C: Redundant Parenthesis Statements
Type | Severity | Location |
---|---|---|
Code Style | OlpManager.sol:L319, L330 |
Description:
The referenced statements are redundantly wrapped in parenthesis' (()
).
Example:
319require((lastAddedAt[_account] + cooldownDuration) <= block.timestamp, "OlpManager: cooldown duration not yet passed");
Recommendation:
We advise them to be safely omitted, increasing the legibility of the codebase.
Alleviation (a8720219a6a97e10b8d9c6a70c6345747f0fdcb3):
The redundant parenthesis in the referenced statements have been safely omitted.