Omniscia DAFI Audit
NetworkDemand Code Style Findings
NetworkDemand Code Style Findings
NDD-01C: Convoluted Code
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | [NetworkDemand.sol:L23](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L23), [L51](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L51), [L54](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L54), [L66-L82](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L66-L82) |
Description:
The NetworkDemand
contract system utilizes two fractions to calculate the "weight" of each metric (price and TVL) for a particular token. This is done by accessing a mapping
for those two values.
Example:
66function setPriceFraction(uint8 _floor, uint8 _ceiling) external onlyWhitelist{67 Fraction memory priceFraction = Fraction(_floor,_ceiling);68 fractions["PRICE_FRACTION"] = priceFraction;69}70
71function getPriceFraction() public view returns(Fraction memory) {72 return fractions["PRICE_FRACTION"];73}74
75function setTVLFraction(uint8 _floor, uint8 _ceiling) external onlyWhitelist{76 Fraction memory priceFraction = Fraction(_floor,_ceiling);77 fractions["TVL_FRACTION"] = priceFraction;78}79
80function getTVLFraction() public view returns(Fraction memory) {81 return fractions["TVL_FRACTION"];82}
Recommendation:
We advise two contract level declared Fraction
variables to be utilized instead of the mapping
declaration as the mapping
declaration redundantly convolutes the codebase and wastes more gas to access given that it performs a keccak256
operation on the mapping
key argument.
Alleviation:
The fraction system was dropped entirely in favor of a percentage system which is more legible and maintainable.
NDD-02C: Inexistent Visibility Specifiers
Type | Severity | Location |
---|---|---|
Code Style | Informational | [NetworkDemand.sol:L15](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L15), [L20](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L20), [L21](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L21) |
Description:
The linked variables contain no visibility specifier explicitly set.
Example:
15IERC20 token;16
17uint private targetPrice;18uint private targetTVL;19
20IPriceFeeds priceFeeds;21ITVLFeeds tvlFeeds;
Recommendation:
We advise one to be set for each variable as currently the compiler assigns a visibility specifier automatically which can cause compilation discrepancies should the default visibility change.
Alleviation:
Visibility specifiers were properly introduced for all variables.
NDD-03C: Variable Mutability Specifier
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | [NetworkDemand.sol:L15](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L15), [L38](https://github.com/DAFIProtocol/dDAFI/blob/d08c795cdf3455616f403d1468e02ec234ab01ef/contracts/network demand/NetworkDemand.sol#L38) |
Description:
The token
variable is assigned to only once during the contract's constructor
.
Example:
37constructor(IERC20 _token, IPriceFeeds _priceFeeds, ITVLFeeds _tvlFeeds) Ownable(){38 token = _token;39 priceFeeds = _priceFeeds;40 tvlFeeds = _tvlFeeds;41}
Recommendation:
We advise it to be set as immutable
greatly optimizing the contract's gas cost.
Alleviation:
The immutable
attribute was properly specified for the linked variable.