Open code423n4 opened 2 years ago
_cliffReleaseTimestamp > 0 is not really needed here:
_cliffReleaseTimestamp > 0
require( _cliffReleaseTimestamp > 0 && _cliffAmount > 0 && _cliffReleaseTimestamp <= _startTimestamp )
because _startTimestamp was validated before:
_startTimestamp
require(_startTimestamp > 0, "INVALID_START_TIMESTAMP");
No need to initialize to default values:
uint112 public numTokensReservedForVesting = 0;
This is the first assignment to vestAmt:
vestAmt
if(_referenceTs >= _claim.cliffReleaseTimestamp) { vestAmt += _claim.cliffAmount; }
can save a bit of gas by replacing += with just =.
+=
=
Can use unchecked maths here and everywhere else where overflow/underflow is not possible:
unchecked
if(_referenceTs > _claim.startTimestamp) { uint40 currentVestingDurationSecs = _referenceTs - _claim.startTimestamp;
The duration is re-calculated every time the _baseVestedAmount is queried:
_baseVestedAmount
uint40 finalVestingDurationSecs = _claim.endTimestamp - _claim.startTimestamp;
even though nor start, nor end timestamps do not change. Wouldn't it be better to store the duration in the Claim struct then?
Claim
Repeated access of storage usrClaim.amountWithdrawn variable:
usrClaim.amountWithdrawn
require(allowance > usrClaim.amountWithdrawn, "NOTHING_TO_WITHDRAW"); ... uint112 amountRemaining = allowance - usrClaim.amountWithdrawn;
Can just directly assign usrClaim.amountWithdrawn = allowance:
usrClaim.amountWithdrawn = allowance
uint112 allowance = vestedAmount(_msgSender(), uint40(block.timestamp)); ... uint112 amountRemaining = allowance - usrClaim.amountWithdrawn; ... usrClaim.amountWithdrawn += amountRemaining;
_cliffReleaseTimestamp > 0
is not really needed here:because
_startTimestamp
was validated before:No need to initialize to default values:
This is the first assignment to
vestAmt
:can save a bit of gas by replacing
+=
with just=
.Can use
unchecked
maths here and everywhere else where overflow/underflow is not possible:The duration is re-calculated every time the
_baseVestedAmount
is queried:even though nor start, nor end timestamps do not change. Wouldn't it be better to store the duration in the
Claim
struct then?Repeated access of storage
usrClaim.amountWithdrawn
variable:Can just directly assign
usrClaim.amountWithdrawn = allowance
: