Omniscia Tren Finance Audit

PriceFeed Code Style Findings

PriceFeed Code Style Findings

PFD-01C: Inefficient Enum Handling

Description:

The Solidity compiler ensures that input arguments designated as enum declarations always contain a valid enum value, rendering the return 0 statement of the PriceFeed::_fetchDecimals function unreachable and the function itself slightly inefficient.

Example:

contracts/PriceFeed.sol
126function _fetchDecimals(address _oracle, ProviderType _type) internal view returns (uint8) {
127 if (ProviderType.Chainlink == _type) {
128 return ChainlinkAggregatorV3Interface(_oracle).decimals();
129 } else if (ProviderType.API3 == _type) {
130 return 18;
131 } else if (ProviderType.Pyth == _type) {
132 return 18;
133 }
134 return 0;
135}

Recommendation:

We advise the code to instead omit the return statement and replace the last else-if clause with a simple else clause, optimizing its gas cost.

Additionally, we advise other if-else-if structures in the contract to be optimized in the same regard.

Alleviation (f6f1ad0b8f24a96ade345db1dd05a1878eb0f761):

The last condition of the if-else-if block has been updated per our recommendation to an else clause, optimizing the code's gas cost.