Omniscia Myso Finance Audit

Escrow Code Style Findings

Escrow Code Style Findings

EWO-01C: Common Option Initialization Code

Description:

The Escrow::initializeRFQMatch and the Escrow::initializeMintOption functions contain common code that can be compartmentalized to an internal function.

Example:

contracts/Escrow.sol
103function initializeRFQMatch(
104 address _router,
105 address _owner,
106 address optionReceiver,
107 uint96 _exerciseFee,
108 DataTypes.RFQInitialization calldata _rfqInitialization,
109 uint256 oTokenIndex
110) external initializer {
111 optionInfo = _rfqInitialization.optionInfo;
112 optionMinted = true;
113 premiumPaid = _rfqInitialization.rfqQuote.premium;
114 _mint(optionReceiver, _rfqInitialization.optionInfo.notional);
115 // @dev: automatically set max. allowance to minimize
116 // overhead for follow-on option token swapping via router
117 _approve(optionReceiver, _router, type(uint256).max);
118 _initialize(
119 _router,
120 _owner,
121 _exerciseFee,
122 _rfqInitialization.optionInfo.underlyingToken,
123 oTokenIndex
124 );
125}
126
127function initializeMintOption(
128 address _router,
129 address _owner,
130 address optionReceiver,
131 uint96 _exerciseFee,
132 DataTypes.OptionInfo calldata _optionInfo,
133 DataTypes.OptionNaming calldata _optionNaming
134) external initializer {
135 optionInfo = _optionInfo;
136 optionMinted = true;
137 router = _router;
138 owner = _owner;
139 exerciseFee = _exerciseFee;
140
141 // @dev: initialize with custom name and symbol
142 _name = _optionNaming.name;
143 _symbol = _optionNaming.symbol;
144
145 _mint(optionReceiver, _optionInfo.notional);
146
147 // @dev: automatically set max. allowance to minimize
148 // overhead for follow-on option token swapping via router
149 _approve(optionReceiver, _router, type(uint256).max);
150
151 _decimals = IERC20Metadata(_optionInfo.underlyingToken).decimals();
152}

Recommendation:

We advise the highlighted statements to be refactored into an internal call, optimizing the bytecode size and maintainability of the codebase.

Alleviation (d9eb549dcca601db1fa91336ebe4d08fa8f2908b):

The code was optimized by bundling the option's mint as well as approval operation with the contract's optionMinted status configuration to true, optimizing the code's gas cost.

EWO-02C: Ineffectual Usage of Safe Arithmetics

Description:

The linked mathematical operation is guaranteed to be performed safely by logical inference, such as surrounding conditionals evaluated in require checks or if-else constructs.

Example:

contracts/Escrow.sol
506if (block.timestamp < _decayStartTime) {
507 currentAsk = auctionParams.relPremiumStart;
508} else if (block.timestamp < _decayStartTime + _decayDuration) {
509 uint256 _timePassed = block.timestamp - _decayStartTime;

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 (d9eb549dcc):

The optimization was solely applied to the highlighted item out of the three lines of code identified by this exhibit rendering it partially addressed.

Alleviation (af42d4effc):

The optimization has been properly applied to the borrowedUnderlyingAmounts subtraction as originally recommended, addressing this exhibit in full.