-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.28; | ||
|
||
import {OwnerVault} from "../OwnerVault.sol"; | ||
|
||
import {SafeTransferLib} from "@solady/utils/SafeTransferLib.sol"; | ||
|
||
contract SoladySafeTransferEth is OwnerVault { | ||
function sendETHToOwner() external override onlyOwner { | ||
uint256 ethBal = address(this).balance; | ||
|
||
if(ethBal > 0) { | ||
SafeTransferLib.safeTransferETH(msg.sender, ethBal); | ||
} | ||
} | ||
} | ||
|
||
|
28 changes: 28 additions & 0 deletions
28
test/10-solady-safeTransferEth/SoladySafeTransferEthTest.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.28; | ||
|
||
import {OwnerVaultTest} from "../OwnerVaultTest.sol"; | ||
import {SoladySafeTransferEth} from "../../src/10-solady-safeTransferEth/SoladySafeTransferEth.sol"; | ||
|
||
// Optimizer ON, 10000 runs | ||
// ======================== | ||
// Pre : 14420 gas | ||
// forge test --optimizer-runs 10000 --match-contract MsgSenderNotOwnerTest --match-test test_sendETHToOwner -vvv | ||
// Post : 14368 gas (0.36% cheaper) | ||
// forge test --optimizer-runs 10000 --match-contract SoladySafeTransferEthTest --match-test test_sendETHToOwner -vvv | ||
// | ||
// Optimizer OFF | ||
// ============= | ||
// Pre : 14456 gas | ||
// forge test --match-contract MsgSenderNotOwnerTest --match-test test_sendETHToOwner -vvv | ||
// Post : 14404 gas (0.36% cheaper) | ||
// forge test --match-contract SoladySafeTransferEthTest --match-test test_sendETHToOwner -vvv | ||
// | ||
// Conclusion | ||
// ========== | ||
// Using Solady SafeTransferEth cheaper than standard Solidity using `call` | ||
contract SoladySafeTransferEthTest is OwnerVaultTest { | ||
function _createContract() internal override { | ||
ownerVault = new SoladySafeTransferEth(); | ||
} | ||
} |