账户
0x83...41ff
0x83...41FF

0x83...41FF

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.8.17+commit.8df45f5f
语言
Solidity
合同源代码
文件 1 的 4:Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
合同源代码
文件 2 的 4:IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount
    ) external returns (bool);
}
合同源代码
文件 3 的 4:MultiDistributor.sol
// SPDX-License-Identifier: ISC
pragma solidity ^0.8.13;
pragma abicoder v2;

import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {Ownable} from "lib/openzeppelin-contracts/contracts/access/Ownable.sol";

/**
 * @title Token Distributor contract.
 * @dev   Whitelisted addresses can create batched claims for tokens.
 *        Contract owner can approve / remove these claims.
 *
 * @author Lyra
 */

contract MultiDistributor is Ownable {
  // Details for a specific batchId
  struct Batch {
    IERC20 token;
    bool approved;
  }

  // Batch Ids
  uint nextId = 1;

  mapping(address => bool) public whitelisted; // whitelisted addresses approved for creating claims
  mapping(uint => Batch) public batchApprovals; // batchId -> Batch details
  mapping(uint => mapping(address => uint)) public amountToClaim; // batchId -> User -> amount
  mapping(address => mapping(IERC20 => uint)) public totalClaimed; // User -> Token -> Amount claimed

  /////////////////////
  //   Constructor   //
  /////////////////////

  constructor() Ownable() {}

  //////////////////////////////
  //   Owner-only Functions   //
  //////////////////////////////

  /**
   * @notice Setter to whitelist an address to create claims.
   *
   * @param _user The address to be added or removed.
   * @param _whitelist Boolean on whether the address is being added or removed.
   */
  function setWhitelistAddress(address _user, bool _whitelist) external onlyOwner {
    whitelisted[_user] = _whitelist;
    emit WhitelistAddressSet(_user, _whitelist);
  }

  /**
   * @notice Allows owner to approve or unapprove batchIds.
   *
   * @param batchIds The list of batchIds to approve or unapprove
   * @param approve Bool on whether the ids are being approved or not
   */
  function approveClaims(uint[] memory batchIds, bool approve) external onlyOwner {
    for (uint i = 0; i < batchIds.length; i++) {
      batchApprovals[batchIds[i]].approved = approve;

      emit ClaimApproved(batchIds[i]);
    }
  }

  //////////////////////////////////
  //   Whitelist-only Functions   //
  //////////////////////////////////

  /**
   * @notice Allows whitelisted addresses to create a batch of new claims.
   *
   * @param tokenAmounts List of token amounts to add for the batch
   * @param users List of user addresses that correspond to the tokenAmounts
   * @param token The reward token
   * @param epochTimestamp The timestamp for the epoch
   * @param tag Data relating to the claim
   */
  function addToClaims(
    uint[] memory tokenAmounts,
    address[] memory users,
    IERC20 token,
    uint epochTimestamp,
    string memory tag
  ) external {
    if (whitelisted[msg.sender] != true) revert MD_NotWhitelisted(msg.sender);
    if (tokenAmounts.length != users.length) revert MD_InvalidArrayLength(tokenAmounts.length, users.length);

    for (uint i = 0; i < users.length; i++) {
      amountToClaim[nextId][users[i]] += tokenAmounts[i];
      emit ClaimAdded(token, users[i], tokenAmounts[i], nextId, epochTimestamp, tag);
    }
    batchApprovals[nextId++].token = token;
  }

  ////////////////////////////
  //   External Functions   //
  ////////////////////////////

  /**
   * @notice Allows user to redeem a list of batchIds.
   * @dev Users can only claim their own rewards.
   * @param claimList List of batchIds to claim
   */
  function claim(uint[] memory claimList) external {
    for (uint i = 0; i < claimList.length; i++) {
      uint batchId = claimList[i];
      if (batchApprovals[batchId].approved != true) revert MD_BatchNotApproved(batchId);

      uint balanceToClaim = amountToClaim[batchId][msg.sender];
      if (balanceToClaim == 0) {
        continue;
      }

      amountToClaim[batchId][msg.sender] = 0;
      totalClaimed[msg.sender][batchApprovals[batchId].token] += balanceToClaim;
      batchApprovals[batchId].token.transfer(msg.sender, balanceToClaim);

      emit Claimed(batchApprovals[batchId].token, msg.sender, batchId, balanceToClaim);
    }
  }

  /**
   * @notice Returns the claimable amount of a a specific token for an address.
   * @param batchIds The list of batchIds to claim
   * @param user The addresses claimable amount
   * @param token The claimable amount for this token
   */
  function getClaimableAmountForUser(uint[] memory batchIds, address user, IERC20 token)
    external
    view
    returns (uint amount)
  {
    for (uint i = 0; i < batchIds.length; i++) {
      uint balanceToClaim = amountToClaim[batchIds[i]][user];

      if (
        balanceToClaim > 0 && batchApprovals[batchIds[i]].approved == true && batchApprovals[batchIds[i]].token == token
      ) {
        amount += balanceToClaim;
      }
    }
  }

  /**
   * @notice Returns the claimable ids for an address.
   * @param batchIds The list of batchIds to check
   * @param user The addresses claimable amount
   */
  function getClaimableIdsForUser(uint[] memory batchIds, address user)
    external
    view
    returns (uint[] memory claimableIds)
  {
    uint count;
    claimableIds = new uint[](batchIds.length);
    for (uint i = 0; i < batchIds.length; i++) {
      if (amountToClaim[batchIds[i]][user] > 0 && batchApprovals[batchIds[i]].approved == true) {
        claimableIds[count++] = batchIds[i];
      }
    }
  }

  ////////////
  // Events //
  ////////////

  event WhitelistAddressSet(address user, bool whitelisted);

  event Claimed(IERC20 indexed rewardToken, address indexed claimer, uint indexed batchId, uint amount);

  event ClaimAdded(
    IERC20 rewardToken,
    address indexed claimer,
    uint amount,
    uint indexed batchId,
    uint indexed epochTimestamp,
    string tag
  );

  event ClaimApproved(uint indexed batchId);

  ////////////
  // Errors //
  ////////////

  error MD_NotWhitelisted(address user);
  error MD_InvalidArrayLength(uint tokenLength, uint userLength);
  error MD_BatchNotApproved(uint batchId);
}
合同源代码
文件 4 的 4:Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
设置
{
  "compilationTarget": {
    "src/contracts/token/MultiDistributor.sol": "MultiDistributor"
  },
  "evmVersion": "london",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 10000
  },
  "remappings": [
    ":ds-test/=lib/forge-std/lib/ds-test/src/",
    ":forge-std/=lib/forge-std/src/",
    ":openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}
ABI
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"batchId","type":"uint256"}],"name":"MD_BatchNotApproved","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenLength","type":"uint256"},{"internalType":"uint256","name":"userLength","type":"uint256"}],"name":"MD_InvalidArrayLength","type":"error"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"MD_NotWhitelisted","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"address","name":"claimer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"batchId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"epochTimestamp","type":"uint256"},{"indexed":false,"internalType":"string","name":"tag","type":"string"}],"name":"ClaimAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"batchId","type":"uint256"}],"name":"ClaimApproved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"address","name":"claimer","type":"address"},{"indexed":true,"internalType":"uint256","name":"batchId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Claimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bool","name":"whitelisted","type":"bool"}],"name":"WhitelistAddressSet","type":"event"},{"inputs":[{"internalType":"uint256[]","name":"tokenAmounts","type":"uint256[]"},{"internalType":"address[]","name":"users","type":"address[]"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"epochTimestamp","type":"uint256"},{"internalType":"string","name":"tag","type":"string"}],"name":"addToClaims","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"amountToClaim","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"batchIds","type":"uint256[]"},{"internalType":"bool","name":"approve","type":"bool"}],"name":"approveClaims","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"batchApprovals","outputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"claimList","type":"uint256[]"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"batchIds","type":"uint256[]"},{"internalType":"address","name":"user","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"getClaimableAmountForUser","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"batchIds","type":"uint256[]"},{"internalType":"address","name":"user","type":"address"}],"name":"getClaimableIdsForUser","outputs":[{"internalType":"uint256[]","name":"claimableIds","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"bool","name":"_whitelist","type":"bool"}],"name":"setWhitelistAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"contract IERC20","name":"","type":"address"}],"name":"totalClaimed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]