Skip to content

Commit

Permalink
refactor: pre declare the blockTimestamp in _claim
Browse files Browse the repository at this point in the history
chore: use named args in transfer function
chore: correct prepare artifacts interface
  • Loading branch information
andreivladbrg committed Feb 14, 2025
1 parent e76d4e6 commit 1a448b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion shell/prepare-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cp out-optimized/ISablierMerkleFactory.sol/ISablierMerkleFactory.json $interface
cp out-optimized/ISablierMerkleInstant.sol/ISablierMerkleInstant.json $interfaces
cp out-optimized/ISablierMerkleLL.sol/ISablierMerkleLL.json $interfaces
cp out-optimized/ISablierMerkleLT.sol/ISablierMerkleLT.json $interfaces
cp out-optimized/SablierMerkleVCA.sol/SablierMerkleVCA.json $interfaces
cp out-optimized/ISablierMerkleVCA.sol/ISablierMerkleVCA.json $interfaces

libraries=./artifacts/libraries
cp out-optimized/libraries/Errors.sol/Errors.json $libraries
Expand Down
12 changes: 7 additions & 5 deletions src/SablierMerkleVCA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,22 @@ contract SablierMerkleVCA is

/// @inheritdoc SablierMerkleBase
function _claim(uint256 index, address recipient, uint128 amount) internal override {
uint40 blockTimestamp = uint40(block.timestamp);

// Check: vesting start time is not in the future.
if (_vestingSchedule.start >= block.timestamp) {
if (_vestingSchedule.start >= blockTimestamp) {
revert Errors.SablierMerkleVCA_ClaimNotStarted();
}

uint128 claimableAmount;

// Calculate the claimable amount.
if (_vestingSchedule.end <= block.timestamp) {
if (_vestingSchedule.end <= blockTimestamp) {
// If the vesting period has ended, the recipient can claim the full amount.
claimableAmount = amount;
} else {
// Otherwise, calculate the claimable amount based on the elapsed time.
uint40 elapsedTime = uint40(block.timestamp) - _vestingSchedule.start;
uint40 elapsedTime = blockTimestamp - _vestingSchedule.start;
uint40 totalDuration = _vestingSchedule.end - _vestingSchedule.start;

claimableAmount = ((uint256(amount) * elapsedTime) / totalDuration).toUint128();
Expand All @@ -130,8 +132,8 @@ contract SablierMerkleVCA is
forgoneAmount += (amount - claimableAmount);
}

// Interaction: withdraw the tokens to the recipient.
TOKEN.safeTransfer(recipient, claimableAmount);
// Interaction: transfer the tokens to the recipient.
TOKEN.safeTransfer({ to: recipient, value: claimableAmount });

// Log the claim.
emit Claim(index, recipient, claimableAmount, amount);
Expand Down
2 changes: 1 addition & 1 deletion src/abstracts/SablierMerkleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ abstract contract SablierMerkleBase is
}

// Effect: transfer the tokens to the provided address.
TOKEN.safeTransfer(to, amount);
TOKEN.safeTransfer({ to: to, value: amount });

// Log the clawback.
emit Clawback(admin, to, amount);
Expand Down

0 comments on commit 1a448b2

Please sign in to comment.