Omniscia DAFI Audit

StakingDatabase Code Style Findings

StakingDatabase Code Style Findings

SDE-01C: Duplication of Code

TypeSeverityLocation
Gas OptimizationInformationalStakingDatabase.sol:L72

Description:

The addAccumulatedPoolWeight performs the exact statements of getDemandFactorLatest.

Example:

contracts/StakingDatabase.sol
70function addAccumulatedPoolWeight(uint _currentWeight) external onlyWhitelist {
71pool.currentAccumulatedWeight = pool.currentAccumulatedWeight + _currentWeight;
72pool.lastDemandFactor = demandFactorHistory[demandFactorHistory.length - 1].value;
73pool.lastUpdatedOn = block.timestamp;
74pool.currentPoolWeight = _currentWeight;
75}

Recommendation:

We advise the lastDemandFactor assignment statement to utilize the getter function and the getter function to be declared as public thereby optimizing the generated bytecode of the contract.

Alleviation:

The getDemandFactorLatest function is now properly utilized in the linked statement.

SDE-02C: Inexistent Visibility Specifiers

TypeSeverityLocation
Code StyleInformationalStakingDatabase.sol:L49, L52, L54-L63

Description:

The linked variables contain no visibility specifier explicitly set.

Example:

contracts/StakingDatabase.sol
51DemandFactor[] public demandFactorHistory;
52Pool pool;

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:

A visibility specifier was only added for one of the linked variables, namely the pool.

SDE-03C: Literal Boolean Comparison

TypeSeverityLocation
Gas OptimizationInformationalStakingDatabase.sol:L104

Description:

The addStake function performs a boolean comparison between the value of stake.exist and false.

Example:

contracts/StakingDatabase.sol
104if(stake.exist == false) {
105stake.exist = true;
106stake.createdOn = block.timestamp;
107}

Recommendation:

We advise the equality to be dropped entirely and the negation of stake.exist to be utilized instead. Furthermore, the value of exist may be dropped altogether as a non-zero createdOn value would indicate the same status.

Alleviation:

The exist member of the Stake struct no longer exists rendering this exhibit null.

SDE-04C: Redundant Function Implementation

TypeSeverityLocation
Gas OptimizationInformationalStakingDatabase.sol:L207-L209

Description:

The getEightDecimals function should not exist as it is a value that can be imported by other contracts as a constant.

Example:

contracts/StakingDatabase.sol
207function getEightDecimals() external pure returns(uint) {
208return EIGHT_DECIMALS_CONSTANT;
209}

Recommendation:

We advise it to be safely omitted to reduce the gas cost of the contract's deployment.

Alleviation:

The variable has since been removed in the latest iteration of the codebase, rendering this exhibit null.

SDE-05C: Redundant Visibility Specifier

TypeSeverityLocation
Gas OptimizationInformationalStakingDatabase.sol:L43

Description:

The EIGHT_DECIMALS_CONSTANT variable is declared as both constant and public.

Example:

contracts/StakingDatabase.sol
43uint constant public EIGHT_DECIMALS_CONSTANT = 100000000;

Recommendation:

We advise the public visibility specifier to be set to either private or internal to avoid the generation of redundant bytecode given that the variable will solely be internally utilized.

Alleviation:

The variable has since been removed in the latest iteration of the codebase, rendering this exhibit null.