Omniscia Steadefi Audit

TraderJoeYieldFarmVault Code Style Findings

TraderJoeYieldFarmVault Code Style Findings

TJY-01C: Inefficient Transfer Flow

TypeSeverityLocation
Gas OptimizationTraderJoeYieldFarmVault.sol:L179, L182

Description:

The TraderJoeYieldFarmVault::deposit function will either wrap the incoming native funds or transfer them inwards and will ultimately transfer them outwards to the target manager recipient.

Example:

contracts/vaults/trader-joe/TraderJoeYieldFarmVault.sol
165if (_isNative) {
166 require(vaultConfig.isNativeAsset, "Vault asset not native token");
167 require(_amt == msg.value, "Amt != msg.value");
168
169 token = tokenA;
170
171 IWAVAX(address(token)).deposit{ value: msg.value }();
172} else {
173 if (strategy == VaultStrategy.Neutral || strategy == VaultStrategy.Short) {
174 token = tokenB;
175 } else if (strategy == VaultStrategy.Long) {
176 token = tokenA;
177 }
178
179 token.safeTransferFrom(msg.sender, address(this), _amt);
180}
181
182token.safeTransfer(address(manager), _amt);

Recommendation:

We advise the outward transfer to be relocated after the deposit call to IWAVAX and the safeTransferFrom statement within the else branch of the if-else construct in TraderJoeYieldFarmVault::deposit to provide the manager variable as the second positional argument to the call, transferring the funds directly from the msg.sender to the manager.

Alleviation (4325253d6d):

While the exhibit appears to have been resolved albeit incorrectly in PR#167, no changes are reflected in the revised commit hash that was provided to us.

Alleviation (7c9b2b09db):

The asset transfer flows have all been made as optimal as possible, requiring a single transfer towards the manager as advised.

TJY-02C: Inexplicable Transfer of Dust

TypeSeverityLocation
Gas OptimizationTraderJoeYieldFarmVault.sol:L318-L319

Description:

The TraderJoeYieldFarmVault::_deposit execution flow when a deposit is performed will utilize the full available balance of the user when providing liquidity to the LP pair, rendering any "dust" clean-up redundant.

Example:

contracts/vaults/trader-joe/TraderJoeYieldFarmVault.sol
317// transfer dust
318tokenA.safeTransfer(msg.sender, tokenA.balanceOf(address(this)));
319tokenB.safeTransfer(msg.sender, tokenB.balanceOf(address(this)));

Recommendation:

We advise the safeTransfer functions to be omitted from this point as they are ineffectual.

Alleviation (4325253d6de0ea91c1e9fb9e01d2e7e98f3d83a9):

The inexplicable transfer of dust has been removed per our recommendation, optimizing the execution cost of TraderJoeYieldFarmVault::_deposit significantly.

TJY-03C: Repetitive Value Literal

TypeSeverityLocation
Code StyleTraderJoeYieldFarmVault.sol:L237, L330

Description:

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

Example:

contracts/vaults/trader-joe/TraderJoeYieldFarmVault.sol
237if (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.

TJY-04C: Variable Mutability Specifiers (Immutable)

TypeSeverityLocation
Gas OptimizationTraderJoeYieldFarmVault.sol:L109-L112, L117

Description:

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

Example:

contracts/vaults/trader-joe/TraderJoeYieldFarmVault.sol
96constructor (
97 string memory _name,
98 string memory _symbol,
99 VaultStrategy _strategy,
100 IERC20 _tokenA,
101 IERC20 _tokenB,
102 IChainLinkOracle _priceOracle,
103 VaultConfig memory _vaultConfig,
104 uint256 _capacityValue,
105 uint256 _mgmtFeePerSecond,
106 uint256 _perfFee,
107 address _treasury
108) ERC20(_name, _symbol) {
109 strategy = _strategy;
110 tokenA = _tokenA;
111 tokenB = _tokenB;
112 priceOracle = _priceOracle;
113 vaultConfig = _vaultConfig;
114 capacityValue = _capacityValue;
115 mgmtFeePerSecond = _mgmtFeePerSecond;
116 perfFee = _perfFee;
117 treasury = _treasury;
118 lastFeeCollected = block.timestamp;
119}

Recommendation:

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

Alleviation (4325253d6d):

Four out of the five 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.