Omniscia DAFI Audit

NetworkDemand Code Style Findings

NetworkDemand Code Style Findings

NDD-01C: Convoluted Code

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:

contracts/network
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

Description:

The linked variables contain no visibility specifier explicitly set.

Example:

contracts/network
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

Description:

The token variable is assigned to only once during the contract's constructor.

Example:

contracts/network
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.