Omniscia Steadefi Audit

GMXPerpetualDEXLongVault Code Style Findings

GMXPerpetualDEXLongVault Code Style Findings

GMX-01C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificGMXPerpetualDEXLongVault.sol:L195

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/vaults/gmx/GMXPerpetualDEXLongVault.sol
192require(_shareAmt <= balanceOf(msg.sender), "Withdraw amt exceeds balance");
193
194// to avoid leaving dust behind
195if (balanceOf(msg.sender) - _shareAmt < (1 * SAFE_MULTIPLIER / 10)) {
196 _shareAmt = balanceOf(msg.sender);
197}

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 (4325253d6de0ea91c1e9fb9e01d2e7e98f3d83a9):

The referenced subtraction is optimally wrapped in an unchecked code block in the latest implementation of GMXPerpetualDEXLongVault.

GMX-02C: Inefficient Transfer Flow

TypeSeverityLocation
Gas OptimizationGMXPerpetualDEXLongVault.sol:L146-L147

Description:

The referenced transfer flow transmits the funds from the msg.sender to the contract itself and then to the manager.

Example:

contracts/vaults/gmx/GMXPerpetualDEXLongVault.sol
146token.safeTransferFrom(msg.sender, address(this), _amt);
147token.safeTransfer(address(manager), _amt);

Recommendation:

We advise the funds to be transmitted directly from the msg.sender to the manager by utilizing a single safeTransferFrom call with the correct arguments.

Alleviation (4325253d6de0ea91c1e9fb9e01d2e7e98f3d83a9):

The inefficient transfer flow has been remediated by directly transferring the token funds from the msg.sender to the target manager.

GMX-03C: Inexplicable Transfer of Dust

TypeSeverityLocation
Gas OptimizationGMXPerpetualDEXLongVault.sol:L261

Description:

The GMXPerpetualDEXLongManager::work execution flow when a deposit is performed will utilize the full available balance of the user when minting and staking the GLP, rendering any "dust" clean-up redundant.

Example:

contracts/vaults/gmx/GMXPerpetualDEXLongVault.sol
247manager.work(
248 ManagerAction.Deposit, /* action */
249 0, /* lpAmt */
250 borrowTokenAmt, /* borrowTokenAmt */
251 0 /* repayTokenAAmt */
252);
253
254uint256 _equityChange = (reader.assetValueWithPrice(glpPrice) - reader.debtValue()) - equityBefore;
255// calculate shares to users
256uint256 sharesToUser = valueToShares(_equityChange, equityBefore);
257
258_mint(msg.sender, sharesToUser);
259
260// transfer dust
261token.safeTransfer(msg.sender, token.balanceOf(address(this)));

Recommendation:

We advise the safeTransfer function to be omitted from this point as it is ineffectual.

Alleviation (4325253d6de0ea91c1e9fb9e01d2e7e98f3d83a9):

The transfer of "dust" has been removed per our recommendation, optimizing all GMXPerpetualDEXLongVault::_deposit operations.

GMX-04C: Repetitive Value Literal

TypeSeverityLocation
Code StyleGMXPerpetualDEXLongVault.sol:L195, L272

Description:

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

Example:

contracts/vaults/gmx/GMXPerpetualDEXLongVault.sol
195if (balanceOf(msg.sender) - _shareAmt < (1 * SAFE_MULTIPLIER / 10)) {

Recommendation:

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

Alleviation (4325253d6d):

The repetitive value literal outlined has been replaced by the 1e17 statement in each instance; the exhibit's recommendation, however, is to declare the value as a contract-level constant that is in turn utilized in the referenced statements. As such, we consider this exhibit partially alleviated.

Alleviation (7c9b2b09db):

The 1e17 value literal that resulted from the original calculation was relocated to its dedicated DUST_AMOUNT constant variable as advised, addressing this exhibit in full.

GMX-05C: Variable Mutability Specifiers (Immutable)

TypeSeverityLocation
Gas OptimizationGMXPerpetualDEXLongVault.sol:L95, L96, L101

Description:

The linked variables are assigned to only once during the contract's constructor.

Example:

contracts/vaults/gmx/GMXPerpetualDEXLongVault.sol
84constructor (
85 string memory _name,
86 string memory _symbol,
87 IERC20 _token,
88 IChainLinkOracle _priceOracle,
89 VaultConfig memory _vaultConfig,
90 uint256 _capacityValue,
91 uint256 _mgmtFeePerSecond,
92 uint256 _perfFee,
93 address _treasury
94) ERC20(_name, _symbol) {
95 token = _token;
96 priceOracle = _priceOracle;
97 vaultConfig = _vaultConfig;
98 capacityValue = _capacityValue;
99 mgmtFeePerSecond = _mgmtFeePerSecond;
100 perfFee = _perfFee;
101 treasury = _treasury;
102 lastFeeCollected = block.timestamp;
103}

Recommendation:

We advise them to be set as immutable greatly optimizing their read-access gas cost.

Alleviation (4325253d6d):

Two out of the three referenced variables were set as immutable, rendering this exhibit partially alleviated.

Alleviation (7c9b2b09db):

The last remaining member (treasury) has been set as immutable in the latest update to the codebase, rendering this exhibit fully alleviated.