You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removing the abi.encodePacked() from constant typehash encoding when the hashing is done on a single string saves minor gas and removes redundant code. See here and here.
Removing the redundant owner check in the exercise() function in the PuttyV2 contract (this is already validated in the call to transferFrom()) saves gas.
Like the point above, removing the redundant owner check in the withdraw() function in the PuttyV2 contract saves gas.
In the withdraw() function in the PuttyV2 contract, refactoring the fee stack variable to only be created if needed saves gas. This comes at the cost of a minor readability degradation though.
Here's the change:
// Before:
if ((order.isCall && isExercised) || (!order.isCall && !isExercised)) {
// send the fee to the admin/DAO if fee is greater than 0%
uint256 feeAmount = 0;
if (fee > 0) {
feeAmount = (order.strike * fee) / 1000;
ERC20(order.baseAsset).safeTransfer(owner(), feeAmount);
}
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
return;
}
// After:
if ((order.isCall && isExercised) || (!order.isCall && !isExercised)) {
// send the fee to the admin/DAO if fee is greater than 0%
if (fee > 0) {
uint256 feeAmount = (order.strike * fee) / 1000;
ERC20(order.baseAsset).safeTransfer(owner(), feeAmount);
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike - feeAmount);
} else {
ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike);
}
return;
}
The text was updated successfully, but these errors were encountered:
Gas Report
Removing the
abi.encodePacked()
from constant typehash encoding when the hashing is done on a single string saves minor gas and removes redundant code. See here and here.Removing the redundant owner check in the
exercise()
function in the PuttyV2 contract (this is already validated in the call totransferFrom()
) saves gas.Like the point above, removing the redundant owner check in the
withdraw()
function in the PuttyV2 contract saves gas.In the
withdraw()
function in the PuttyV2 contract, refactoring the fee stack variable to only be created if needed saves gas. This comes at the cost of a minor readability degradation though.Here's the change:
The text was updated successfully, but these errors were encountered: