账户
0xfd...8837
0xfD...8837

0xfD...8837

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.8.20+commit.a1b79de6
语言
Solidity
合同源代码
文件 1 的 7:ECDSA.sol
合同源代码
文件 2 的 7:LibBit.sol
合同源代码
文件 3 的 7:LibBitmap.sol
合同源代码
文件 4 的 7:Ownable.sol
合同源代码
文件 5 的 7:ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}
合同源代码
文件 6 的 7:SafeTransferLib.sol
合同源代码
文件 7 的 7:TokenClaimer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Ownable} from "https://github.com/Vectorized/solady/blob/main/src/auth/Ownable.sol";
import {SafeTransferLib} from "https://github.com/Vectorized/solady/blob/main/src/utils/SafeTransferLib.sol";
import {ECDSA} from "https://github.com/Vectorized/solady/blob/main/src/utils/ECDSA.sol";
import {Bitmap} from "https://github.com/Vectorized/solady/blob/main/src/utils/g/LibBitmap.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract TokenClaimer is Ownable, ReentrancyGuard {
    Bitmap internal _claimed;

    address public claimSigner;
    address public token;

    event Claimed(address by, address token, address to, uint256 total, uint256[] claimIndices, bytes memo, bool bonus);

    constructor(address _token, address _owner) {
        _initializeOwner(_owner);
        token = _token;
    }

    function isClaimed(uint256 claimIndex) public view returns (bool) {
        return _claimed.get(claimIndex);
    }

    function setClaimSigner(address newClaimSigner) public onlyOwner {
        claimSigner = newClaimSigner;
    }

    function claim(
        address to,
        uint256 total,
        uint256[] memory claimIndices,
        bytes memory signature,
        uint256 expiry,
        bytes memory memo
    ) public nonReentrant {
        require(block.timestamp <= expiry, "Expired");

        bytes32 hash = keccak256(abi.encode(claimIndices, msg.sender, token, to, total, expiry, memo));
        require(ECDSA.recover(hash, signature) == claimSigner, "Invalid Signature");

        for (uint256 i; i < claimIndices.length; ++i) {
            require(_claimed.toggle(claimIndices[i]), "Already Claimed");
        }

        SafeTransferLib.safeTransferFrom(token, owner(), to, total);
        emit Claimed(msg.sender, token, to, total, claimIndices, memo, false);
    }

    function claimWithBonus(
        address to,
        uint256 total,
        uint256[] memory claimIndices,
        bytes memory signature,
        uint256 expiry,
        bytes memory memo
    ) public nonReentrant {
        require(block.timestamp <= expiry, "Expired");

        bytes32 hash = keccak256(abi.encode(claimIndices, msg.sender, token, to, total, expiry, memo));
        require(ECDSA.recover(hash, signature) == claimSigner, "Invalid Signature");

        for (uint256 i; i < claimIndices.length; ++i) {
            require(_claimed.toggle(claimIndices[i]), "Already Claimed");
        }

        emit Claimed(msg.sender, token, to, total, claimIndices, memo, true);
    }
}
设置
{
  "compilationTarget": {
    "airdrop/TokenClaimer.sol": "TokenClaimer"
  },
  "evmVersion": "shanghai",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": false,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"by","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"total","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"claimIndices","type":"uint256[]"},{"indexed":false,"internalType":"bytes","name":"memo","type":"bytes"},{"indexed":false,"internalType":"bool","name":"bonus","type":"bool"}],"name":"Claimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256[]","name":"claimIndices","type":"uint256[]"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"bytes","name":"memo","type":"bytes"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256[]","name":"claimIndices","type":"uint256[]"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"bytes","name":"memo","type":"bytes"}],"name":"claimWithBonus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"claimIndex","type":"uint256"}],"name":"isClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newClaimSigner","type":"address"}],"name":"setClaimSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"}]