Last active
August 3, 2022 02:04
-
-
Save Vectorized/f775772025904285ece1529e1869e2ff to your computer and use it in GitHub Desktop.
Sprinkly Headers
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.15; | |
library SafeTransferLib { | |
/*´:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:*/ | |
/* CUSTOM ERRORS */ | |
/*.•°:°.´•˚.*°.˚:*.´•*.•°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´•*.•*/ | |
error ETHTransferFailed(); | |
/*´:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:*/ | |
/* ETH OPERATIONS */ | |
/*.•°:°.´•˚.*°.˚:*.´•*.•°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´•*.•*/ | |
function safeTransferETH(address to, uint256 amount) internal { | |
assembly { | |
// Transfer the ETH and check if it succeeded or not. | |
if iszero(call(gas(), to, amount, 0, 0, 0, 0)) { | |
// Store the function selector of `ETHTransferFailed()`. | |
mstore(0x00, 0xb12d13eb) | |
// Revert with (offset, size). | |
revert(0x1c, 0x04) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment