Skip to content

Instantly share code, notes, and snippets.

@m1guelpf
Created May 23, 2022 18:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m1guelpf/6d09b85d70a1dfd00d394b2acf789eeb to your computer and use it in GitHub Desktop.
Save m1guelpf/6d09b85d70a1dfd00d394b2acf789eeb to your computer and use it in GitHub Desktop.
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