Inconsistent coding conventions
Description
While the codebase generally follows good coding practices, there are some minor instances where stronger coding conventions could be applied to improve code readability, maintainability, and security.
Impact
Inconsistent coding conventions can diminish code readability and make it harder for third party integrations and future developers to understand the code.
Here are some specific instances:
The function
VestingFactory.sol -> function createVestingFromNow(address _recipient, uint40 _duration, uint256 _amount, bool _isCancellable)does not have input validation on the duration, allowing for someone to create an irrational duration period. This can lead to some unexpected results; for example, if duration is larger than the amount, the last section of thegetAccruedTokens()function inVesting.solwill always return 0.
The following if condition in
Spot.sol -> createNewStf(STfSpot calldata _stf)reverts if the token is not a base or deposit token - but uses theNoBaseTokenerror each time.
if (!isBaseToken[_stf.baseToken] || !isDepositToken[_stf.depositToken]) {
revert NoBaseToken(_stf.baseToken);
}The function
addTokenCapacity(address baseToken, address depositToken, uint96 capacity)inSpot.solrequires the capacity to be nonzero. This means the capacity can never be unset once set.
The
Trade.sol -> openSpot(...)emits an eventemit OpenSpot(spot.managerCurrentStf(msg.sender), ...)at the end. This relays the manager of thestf; however, this information is previously gathered earlier fromspot.getManagerCurrentStfInfo(msg.sender). This presents extra, unnecessary gas usage.
In
Trade.sol -> _closeSpotSwap(), before and after the call toswap.swapUniversalRouter(), the balance of thedepositTokenis measured and the difference is calculated. InsideSwap.sol -> swapUniversalRouter()the same balance measurement is happening on thereceiverparameter, which happens to bedepositToken. This difference is returned tocloseSpotSwap(). This ends up doing the balance difference calculation twice.
Recommendations
Make sure the duration has a sane maximum, preferably less than the amount.
Revert with a different reason when the given
depositTokenis not whitelisted.
Consider removing the requirement for capacity being nonzero, unless it is acceptable with no unset functionality.
Initialize the
OpenSpotevent with the existing variable (_stf.manager).
If the
swapUniversalRouteralways returns the same balance change, it can be removed from thecloseSpotSwap()function. Otherwise, the measurement can be removed from Swap.
Remediation
STFX acknowledged and resolved the issue in 043fecb3↗, 5fcfa1a4↗, and 0389c664↗.