Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A contract that rewards its first caller after the Merge.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol";
/// @title Merge Reward
/// @author Miguel Piedrafita
/// @notice A contract that rewards its first caller after the Merge
contract MergeReward {
/// @notice Thrown when attempting to claim the reward while in POW
error StillPow();
/// @notice Thrown when the reward has already been claimed
error AlreadyClaimed();
/// @notice Whether the reward has been claimed
bool public hasClaimed;
/// @notice Claim a reward, when in POS
function claim() public {
if (hasClaimed) revert AlreadyClaimed();
if (!haveWeMergedYet()) revert StillPow();
hasClaimed = true;
SafeTransferLib.safeTransferETH(msg.sender, address(this).balance);
/// @notice Determine whether we're running in Proof of Work or Proof of Stake
/// @dev Post-merge, the DIFFICULTY opcode gets renamed to PREVRANDAO, and stores the prevRandao field from the beacon chain state.
function haveWeMergedYet() public view returns (bool) {
return block.difficulty > 2**64;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment