账户
0x3c...66ae
0x3C...66aE

0x3C...66aE

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.8.25+commit.b61c2a91
语言
Solidity
合同源代码
文件 1 的 1:KingdomAirdrop.sol
// File: contracts/IVotingEscrow.sol


pragma solidity ^0.8.0;

interface IVotingEscrow {
    struct Point {
        int128 bias;
        int128 slope; // # -dweight / dt
        uint256 ts;
        uint256 blk; // block
    }

    struct LockedBalance {
        int128 amount;
        uint256 end;
    }

    function token() external view returns (address);

    function team() external returns (address);

    function epoch() external view returns (uint256);

    function point_history(uint256 loc) external view returns (Point memory);

    function user_point_history(uint256 tokenId, uint256 loc)
        external
        view
        returns (Point memory);

    function user_point_epoch(uint256 tokenId) external view returns (uint256);

    function ownerOf(uint256) external view returns (address);

    function isApprovedOrOwner(address, uint256) external view returns (bool);

    function transferFrom(
        address,
        address,
        uint256
    ) external;

    function voting(uint256 tokenId) external;

    function abstain(uint256 tokenId) external;

    function attach(uint256 tokenId) external;

    function detach(uint256 tokenId) external;

    function checkpoint() external;

    function depositFor(uint256 tokenId, uint256 value) external;

    function createLockFor(
        uint256,
        uint256,
        address
    ) external returns (uint256);

    function balanceOfNFT(uint256) external view returns (uint256);

    function balanceOfNFTAt(uint256, uint256) external view returns (uint256);

    function totalSupply() external view returns (uint256);

    function locked__end(uint256) external view returns (uint256);

    function balanceOf(address) external view returns (uint256);

    function tokenOfOwnerByIndex(address, uint256)
        external
        view
        returns (uint256);

    function locked(uint256) external view returns (LockedBalance memory);

    function isDelegate(address _operator, uint256 _tokenId)
        external
        view
        returns (bool);

    function increase_unlock_time(uint256 _tokenId, uint256 _lock_duration)
        external;
}

// File: @openzeppelin/contracts/token/ERC20/IERC20.sol


// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

// File: @openzeppelin/contracts/interfaces/IERC20.sol


// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity ^0.8.20;


// File: contracts/KingdomAirdrop.sol


pragma solidity ^0.8.20;



error Started();
error NotStarted();
error NotAuthorized();
error Claimed();
error NoAllocation();
error NotPaused();
error Paused();
error Invalid();
error NotComplete();

contract KingdomAirdrop {
    address public owner;

    IVotingEscrow public votingEscrow;
    IERC20 public emissionsToken;

    mapping(address => uint256) allocation;
    mapping(address => bool) claimed;

    bool public paused;

    uint256 public start;
    uint256 public end;
    uint256 public constant MAXTIME = 126144000;
    uint256 public constant MAX_TOKEN = 1_000_000 * 1e18;

    event ClaimAirdrop(address _user, uint256 _amount);

    modifier onlyAuth() {
        if (msg.sender != owner) revert NotAuthorized();
        _;
    }

    constructor(
        IERC20 _emissionsToken,
        IVotingEscrow _votingEscrow,
        address _owner
    ) {
        emissionsToken = _emissionsToken;
        votingEscrow = _votingEscrow;
        owner = _owner;
        paused = true;

        emissionsToken.approve(address(_votingEscrow), type(uint256).max);
    }

    ///@notice claim your airdrop
    function claim() external {
        if (start <= 0) revert NotStarted();
        if (claimed[msg.sender]) revert Claimed();
        if (allocation[msg.sender] <= 0) revert NoAllocation();
        uint256 _alloc = allocation[msg.sender];
        allocation[msg.sender] = 0;
        claimed[msg.sender] = true;
        votingEscrow.createLockFor(_alloc, MAXTIME, msg.sender);
        emit ClaimAirdrop(msg.sender, _alloc);
    }

    ///@notice start the airdrop process
    ///@param _unixLength is the length in seconds for the airdrop period to last
    function enableAirdrop(uint256 _unixLength) external onlyAuth {
        if (emissionsToken.balanceOf(address(this)) < MAX_TOKEN)
            revert Invalid();
        if (!paused) revert NotPaused();
        paused = false;
        start = block.timestamp;
        end = start + _unixLength;
    }

    ///@notice burn the remaining emissionsToken not claimed for the Airdrop, and end the airdrop
    function endAirdrop() external onlyAuth {
        if (paused) revert Paused();
        if (block.timestamp < end) revert NotComplete();
        paused = true;
        emissionsToken.transfer(owner, emissionsToken.balanceOf(address(this)));
    }

    ///@notice fill in the airdrop mappings
    function populateMapping(
        address[] calldata wallets,
        uint256[] calldata _allocations
    ) external onlyAuth {
        if (wallets.length != _allocations.length) revert Invalid();
        for (uint256 i = 0; i < wallets.length; ++i) {
            allocation[wallets[i]] += _allocations[i];
        }
    }

    function checkDistribution(address wallet) public view returns (uint256) {
        return (allocation[wallet]);
    }
}
设置
{
  "compilationTarget": {
    "KingdomAirdrop.sol": "KingdomAirdrop"
  },
  "evmVersion": "paris",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"inputs":[{"internalType":"contract IERC20","name":"_emissionsToken","type":"address"},{"internalType":"contract IVotingEscrow","name":"_votingEscrow","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"Claimed","type":"error"},{"inputs":[],"name":"Invalid","type":"error"},{"inputs":[],"name":"NoAllocation","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"NotComplete","type":"error"},{"inputs":[],"name":"NotPaused","type":"error"},{"inputs":[],"name":"NotStarted","type":"error"},{"inputs":[],"name":"Paused","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_user","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"ClaimAirdrop","type":"event"},{"inputs":[],"name":"MAXTIME","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_TOKEN","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"wallet","type":"address"}],"name":"checkDistribution","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emissionsToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_unixLength","type":"uint256"}],"name":"enableAirdrop","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"end","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"endAirdrop","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"wallets","type":"address[]"},{"internalType":"uint256[]","name":"_allocations","type":"uint256[]"}],"name":"populateMapping","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"start","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"votingEscrow","outputs":[{"internalType":"contract IVotingEscrow","name":"","type":"address"}],"stateMutability":"view","type":"function"}]