Omniscia Bluejay Finance Audit

BaseBondDepository Code Style Findings

BaseBondDepository Code Style Findings

BBD-01C: Redundant Entry Variable

Description:

The Bond structure contains a redundant id member that is assigned as the value of the key within the mapping.

Example:

packages/contracts/contracts/BaseBondDepository.sol
17bonds[bondId] = Bond({
18 id: bondId,
19 principal: payout,
20 vestingPeriod: vestingPeriod,
21 purchased: block.timestamp,
22 lastRedeemed: block.timestamp
23});

Recommendation:

We advise the member to be omitted as access to the Bond struct's members guarantees that its ID will be available in memory.

Alleviation:

The id of the Bond has been safely omitted from the codebase as advised.

BBD-02C: Sub-Optimal mapping Lookups

Description:

Each time a mapping entry is accessed via a key a keccak256 instruction is performed internally to calculate the offset the data entry exists in. This calculation can be cached to significantly optimize the gas cost of the function.

Example:

packages/contracts/contracts/BaseBondDepository.sol
14// Internal functions
15function _mint(address to, uint256 payout) internal returns (uint256 bondId) {
16 bondId = ++bondsCount;
17 bonds[bondId] = Bond({
18 id: bondId,
19 principal: payout,
20 vestingPeriod: vestingPeriod,
21 purchased: block.timestamp,
22 lastRedeemed: block.timestamp
23 });
24 bondOwners[bondId] = to;
25 ownedBondsIndex[to][bondId] = ownedBonds[to].length;
26 ownedBonds[to].push(bondId);
27}

Recommendation:

We advise this to be done so by replacing all duplicate mapping entry lookups (i.e. ownedBonds[to] appearing twice in the first linked instance) with a single local variable declaration declared as storage (i.e. uint256[] storage userBonds = ownedBonds[to];). This will significantly optimize the codebase's gas cost.

Alleviation:

The mapping lookups have been adjusted as advised via optimal usage of local storage declarations.