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.sol
will 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 theNoBaseToken
error each time.
if (!isBaseToken[_stf.baseToken] || !isDepositToken[_stf.depositToken]) {
revert NoBaseToken(_stf.baseToken);
}
The function
addTokenCapacity(address baseToken, address depositToken, uint96 capacity)
inSpot.sol
requires 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 thedepositToken
is measured and the difference is calculated. InsideSwap.sol -> swapUniversalRouter()
the same balance measurement is happening on thereceiver
parameter, 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
depositToken
is not whitelisted.
Consider removing the requirement for capacity being nonzero, unless it is acceptable with no unset functionality.
Initialize the
OpenSpot
event with the existing variable (_stf.manager
).
If the
swapUniversalRouter
always 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↗.