Omniscia Metavisor Audit

MetavisorManagedVault Code Style Findings

MetavisorManagedVault Code Style Findings

MMV-01C: Inefficient Invocations of Getter Function

TypeSeverityLocation
Gas OptimizationMetavisorManagedVault.sol:L313, L314, L330, L333, L335

Description:

The weth getter function of the MetavisorRegistry contract is invoked repeatedly across the MetavisorManagedVault codebase.

Example:

contracts/vaults/MetavisorManagedVault.sol
306function _transferSend(
307 IERC20MetadataUpgradeable token,
308 address recipient,
309 uint256 amount,
310 bool _asEth
311) internal {
312 if (amount > 0) {
313 if (_asEth && address(token) == address(metavisorRegistry.weth())) {
314 metavisorRegistry.weth().withdraw(amount);
315 payable(recipient).transfer(amount);
316 } else {
317 token.transfer(recipient, amount);
318 }
319 }
320}
321
322function _transferReceive(
323 IERC20MetadataUpgradeable token,
324 address from,
325 address recipient,
326 uint256 amount
327) internal {
328 if (amount > 0) {
329 if (
330 address(token) == address(metavisorRegistry.weth()) &&
331 address(this).balance >= amount
332 ) {
333 metavisorRegistry.weth().deposit{ value: address(this).balance }();
334 if (recipient != address(this)) {
335 metavisorRegistry.weth().transfer(recipient, amount);
336 }
337 } else {
338 token.transferFrom(from, recipient, amount);
339 }
340 }
341}

Recommendation:

We advise its value to be queried once and stored to a contract-level variable that is consequently utilized, optimizing the code's gas cost. As an additional optimization, the code could make use of immutable variables to further optimize the read-access gas cost of its configurational parameters.

Alleviation:

The weth member has been introduced to the MetavisorBaseVault implementation which is consequently used in all referenced lines of the exhibit within MetavisorManagedVault, optimizing the codebase.