Skip to content

Commit

Permalink
add unchecked to optimize gas
Browse files Browse the repository at this point in the history
  • Loading branch information
ZumZoom committed Aug 23, 2021
1 parent 96fb63d commit 5d19a1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions contracts/CumulativeMerkleDrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ contract CumulativeMerkleDrop is Ownable, ICumulativeMerkleDrop {
cumulativeClaimed[account] = cumulativeAmount;

// Send the token
uint256 amount = cumulativeAmount - preclaimed;
IERC20(token).safeTransfer(account, amount);
emit Claimed(account, amount);
unchecked {
uint256 amount = cumulativeAmount - preclaimed;
IERC20(token).safeTransfer(account, amount);
emit Claimed(account, amount);
}
}

// function verify(bytes32[] calldata merkleProof, bytes32 root, bytes32 leaf) public pure returns (bool) {
Expand Down
8 changes: 5 additions & 3 deletions contracts/CumulativeMerkleDrop128.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ contract CumulativeMerkleDrop128 is Ownable, ICumulativeMerkleDrop128 {
cumulativeClaimed[account] = cumulativeAmount;

// Send the token
uint256 amount = cumulativeAmount - preclaimed;
IERC20(token).safeTransfer(account, amount);
emit Claimed(account, amount);
unchecked {
uint256 amount = cumulativeAmount - preclaimed;
IERC20(token).safeTransfer(account, amount);
emit Claimed(account, amount);
}
}

// function verify(bytes calldata proof, bytes16 root, bytes16 leaf) public pure returns (bool) {
Expand Down
8 changes: 5 additions & 3 deletions contracts/CumulativeMerkleDrop160.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ contract CumulativeMerkleDrop160 is Ownable, ICumulativeMerkleDrop160 {
cumulativeClaimed[account] = cumulativeAmount;

// Send the token
uint256 amount = cumulativeAmount - preclaimed;
IERC20(token).safeTransfer(account, amount);
emit Claimed(account, amount);
unchecked {
uint256 amount = cumulativeAmount - preclaimed;
IERC20(token).safeTransfer(account, amount);
emit Claimed(account, amount);
}
}

// function verify(bytes calldata proof, bytes20 root, bytes20 leaf) public pure returns (bool) {
Expand Down

0 comments on commit 5d19a1a

Please sign in to comment.