Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Created November 3, 2022 00:51
Show Gist options
  • Save z0r0z/3d0786b1390ff470af6175538705003d to your computer and use it in GitHub Desktop.
Save z0r0z/3d0786b1390ff470af6175538705003d to your computer and use it in GitHub Desktop.
based on zora pumpkin spice
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
/// @dev The ETH transfer has failed.
error ETHTransferFailed();
/// @dev Sends `amount` (in wei) ETH to `to`.
/// Reverts upon failure.
function safeTransferETH(address to, uint256 amount) {
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)
}
}
}
contract Escrow {
address public owner;
address public claimer;
error OnlyOwner();
error OnlyClaimer();
event Claimed(uint256 balance);
event ClaimerChanged(address oldClaimer, address newClaimer);
event Received(uint256 amount);
constructor(address _owner, address _claimer) payable {
owner = _owner;
claimer = _claimer;
}
function claim(address recipient) public payable returns (bool) {
if (msg.sender != claimer) revert OnlyClaimer();
emit Claimed(address(this).balance);
return safeTransferETH(recipient, address(this).balance);
}
function setClaimer(address _claimer) public payable {
if (msg.sender != owner) revert OnlyOwner();
claimer = _claimer;
}
receive() external payable {
emit Received(msg.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment