Skip to content

Instantly share code, notes, and snippets.

@Vectorized
Last active August 3, 2022 02:04
Show Gist options
  • Save Vectorized/f775772025904285ece1529e1869e2ff to your computer and use it in GitHub Desktop.
Save Vectorized/f775772025904285ece1529e1869e2ff to your computer and use it in GitHub Desktop.
Sprinkly Headers
// 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