Source Code
Overview
S Balance
0 S
More Info
ContractCreator
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xaD379940...099218E3E The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
MerkleTree
Compiler Version
v0.8.13+commit.abaa5c0e
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import "../interfaces/IAirdropClaim.sol"; contract MerkleTree is Ownable { /// ============ Mutable storage ============ /// @notice ERC20-claimee inclusion root bytes32 public merkleRoot; /// @notice airdrop managment address public airdropClaim; /// @notice Mapping of addresses who have claimed tokens mapping(address => bool) public hasClaimed; /// ============ Errors ============ /// @notice Thrown if address has already claimed error AlreadyClaimed(address _who); /// @notice Thrown if address/amount are not part of Merkle tree error NotInMerkle(address _who, uint _amnt); /// ============ Constructor ============ /// @notice Creates a new MerkleClaimERC20 contract /// @param _airdropClaim claim manager constructor(address _airdropClaim) { airdropClaim = _airdropClaim; } /// ============ Events ============ /// @notice Emitted after a successful token claim /// @param who has right to claim /// @param to recipient of claim /// @param amount of tokens claimed event ClaimSet(address indexed who, address indexed to, uint256 amount); /// ============ Functions ============ /// @notice Allows claiming tokens if address is part of merkle tree /// @param to address of claimee /// @param amount of tokens owed to claimee /// @param proof merkle proof to prove address and amount are in tree function claim( address to, uint256 amount, bytes32[] calldata proof ) external { // Throw if address has already claimed tokens if (hasClaimed[msg.sender]) revert AlreadyClaimed(msg.sender); // Verify merkle proof, or revert if not in tree bytes32 leaf = keccak256( abi.encodePacked(keccak256(abi.encodePacked(msg.sender, amount))) ); bool isValidLeaf = MerkleProof.verify(proof, merkleRoot, leaf); if (!isValidLeaf) revert NotInMerkle(msg.sender, amount); // Set address to claimed hasClaimed[msg.sender] = true; // Mint tokens to msg.sender IAirdropClaim(airdropClaim).claim(msg.sender, amount, to); // Emit claim event emit ClaimSet(msg.sender, to, amount); } /// @notice Set Merkle Root (before starting the claim!) /// @param _merkleRoot merkle root function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner { require(_merkleRoot != bytes32(0), "root 0"); require(merkleRoot == bytes32(0), "Already initialized"); merkleRoot = _merkleRoot; } function setUserClaimed(address[] memory users) external onlyOwner { uint i = 0; for (i = 0; i < users.length; i++) { hasClaimed[users[i]] = true; } } }
// 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); } }
// 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; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/MerkleProof.sol) pragma solidity ^0.8.0; /** * @dev These functions deal with verification of Merkle Tree proofs. * * The tree and the proofs can be generated using our * https://github.com/OpenZeppelin/merkle-tree[JavaScript library]. * You will find a quickstart guide in the readme. * * WARNING: You should avoid using leaf values that are 64 bytes long prior to * hashing, or use a hash function other than keccak256 for hashing leaves. * This is because the concatenation of a sorted pair of internal nodes in * the merkle tree could be reinterpreted as a leaf value. * OpenZeppelin's JavaScript library generates merkle trees that are safe * against this attack out of the box. */ library MerkleProof { /** * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree * defined by `root`. For this, a `proof` must be provided, containing * sibling hashes on the branch from the leaf to the root of the tree. Each * pair of leaves and each pair of pre-images are assumed to be sorted. */ function verify( bytes32[] memory proof, bytes32 root, bytes32 leaf ) internal pure returns (bool) { return processProof(proof, leaf) == root; } /** * @dev Calldata version of {verify} * * _Available since v4.7._ */ function verifyCalldata( bytes32[] calldata proof, bytes32 root, bytes32 leaf ) internal pure returns (bool) { return processProofCalldata(proof, leaf) == root; } /** * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt * hash matches the root of the tree. When processing the proof, the pairs * of leafs & pre-images are assumed to be sorted. * * _Available since v4.4._ */ function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) { bytes32 computedHash = leaf; for (uint256 i = 0; i < proof.length; i++) { computedHash = _hashPair(computedHash, proof[i]); } return computedHash; } /** * @dev Calldata version of {processProof} * * _Available since v4.7._ */ function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) { bytes32 computedHash = leaf; for (uint256 i = 0; i < proof.length; i++) { computedHash = _hashPair(computedHash, proof[i]); } return computedHash; } /** * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a merkle tree defined by * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}. * * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details. * * _Available since v4.7._ */ function multiProofVerify( bytes32[] memory proof, bool[] memory proofFlags, bytes32 root, bytes32[] memory leaves ) internal pure returns (bool) { return processMultiProof(proof, proofFlags, leaves) == root; } /** * @dev Calldata version of {multiProofVerify} * * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details. * * _Available since v4.7._ */ function multiProofVerifyCalldata( bytes32[] calldata proof, bool[] calldata proofFlags, bytes32 root, bytes32[] memory leaves ) internal pure returns (bool) { return processMultiProofCalldata(proof, proofFlags, leaves) == root; } /** * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false * respectively. * * CAUTION: Not all merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer). * * _Available since v4.7._ */ function processMultiProof( bytes32[] memory proof, bool[] memory proofFlags, bytes32[] memory leaves ) internal pure returns (bytes32 merkleRoot) { // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of // the merkle tree. uint256 leavesLen = leaves.length; uint256 totalHashes = proofFlags.length; // Check proof validity. require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof"); // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop". bytes32[] memory hashes = new bytes32[](totalHashes); uint256 leafPos = 0; uint256 hashPos = 0; uint256 proofPos = 0; // At each step, we compute the next hash using two values: // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we // get the next hash. // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the // `proof` array. for (uint256 i = 0; i < totalHashes; i++) { bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; hashes[i] = _hashPair(a, b); } if (totalHashes > 0) { return hashes[totalHashes - 1]; } else if (leavesLen > 0) { return leaves[0]; } else { return proof[0]; } } /** * @dev Calldata version of {processMultiProof}. * * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details. * * _Available since v4.7._ */ function processMultiProofCalldata( bytes32[] calldata proof, bool[] calldata proofFlags, bytes32[] memory leaves ) internal pure returns (bytes32 merkleRoot) { // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of // the merkle tree. uint256 leavesLen = leaves.length; uint256 totalHashes = proofFlags.length; // Check proof validity. require(leavesLen + proof.length - 1 == totalHashes, "MerkleProof: invalid multiproof"); // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop". bytes32[] memory hashes = new bytes32[](totalHashes); uint256 leafPos = 0; uint256 hashPos = 0; uint256 proofPos = 0; // At each step, we compute the next hash using two values: // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we // get the next hash. // - depending on the flag, either another value for the "main queue" (merging branches) or an element from the // `proof` array. for (uint256 i = 0; i < totalHashes; i++) { bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]; bytes32 b = proofFlags[i] ? leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++] : proof[proofPos++]; hashes[i] = _hashPair(a, b); } if (totalHashes > 0) { return hashes[totalHashes - 1]; } else if (leavesLen > 0) { return leaves[0]; } else { return proof[0]; } } function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) { return a < b ? _efficientHash(a, b) : _efficientHash(b, a); } function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) { /// @solidity memory-safe-assembly assembly { mstore(0x00, a) mstore(0x20, b) value := keccak256(0x00, 0x40) } } }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; interface IAirdropClaim { event Claimed(address indexed who, address indexed to, uint256 amount, uint256 veShareAmount, uint256 vestingShareAmount); function claim(address who, uint amount, address to) external; }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
[{"inputs":[{"internalType":"address","name":"_airdropClaim","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_who","type":"address"}],"name":"AlreadyClaimed","type":"error"},{"inputs":[{"internalType":"address","name":"_who","type":"address"},{"internalType":"uint256","name":"_amnt","type":"uint256"}],"name":"NotInMerkle","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"who","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ClaimSet","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"},{"inputs":[],"name":"airdropClaim","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"hasClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"merkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"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":"bytes32","name":"_merkleRoot","type":"bytes32"}],"name":"setMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"users","type":"address[]"}],"name":"setUserClaimed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100935760003560e01c806373b2e80e1161006657806373b2e80e146100e45780637cb64759146101175780638da5cb5b1461012a578063b6d6ed4e1461014f578063f2fde38b1461016257600080fd5b80632eb4a7ab1461009857806338cf1b49146100b45780633d13f874146100c9578063715018a6146100dc575b600080fd5b6100a160015481565b6040519081526020015b60405180910390f35b6100c76100c2366004610640565b610175565b005b6100c76100d7366004610705565b6101e9565b6100c76103b9565b6101076100f236600461078f565b60036020526000908152604090205460ff1681565b60405190151581526020016100ab565b6100c76101253660046107aa565b6103cd565b6000546001600160a01b03165b6040516001600160a01b0390911681526020016100ab565b600254610137906001600160a01b031681565b6100c761017036600461078f565b610456565b61017d6104cf565b60005b81518110156101e5576001600360008484815181106101a1576101a16107c3565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff1916911515919091179055806101dd816107d9565b915050610180565b5050565b3360009081526003602052604090205460ff161561022157604051632058b6db60e01b81523360048201526024015b60405180910390fd5b6040516bffffffffffffffffffffffff193360601b1660208201526034810184905260009060540160408051601f198184030181528282528051602091820120908301520160405160208183030381529060405280519060200120905060006102c1848480806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250506001549150859050610529565b9050806102ea5760405163057365dd60e31b815233600482015260248101869052604401610218565b3360008181526003602052604090819020805460ff1916600117905560025490516304f4b51360e51b81526004810192909252602482018790526001600160a01b0388811660448401521690639e96a26090606401600060405180830381600087803b15801561035957600080fd5b505af115801561036d573d6000803e3d6000fd5b50506040518781526001600160a01b03891692503391507fdc2005f113f1c2ccd6bd35df2a16954f0ff4e029277b9d76ea10b0b3b29ae9649060200160405180910390a3505050505050565b6103c16104cf565b6103cb600061053f565b565b6103d56104cf565b8061040b5760405162461bcd60e51b81526020600482015260066024820152650726f6f7420360d41b6044820152606401610218565b600154156104515760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b6044820152606401610218565b600155565b61045e6104cf565b6001600160a01b0381166104c35760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610218565b6104cc8161053f565b50565b6000546001600160a01b031633146103cb5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610218565b600082610536858461058f565b14949350505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600081815b84518110156105d4576105c0828683815181106105b3576105b36107c3565b60200260200101516105dc565b9150806105cc816107d9565b915050610594565b509392505050565b60008183106105f8576000828152602084905260409020610607565b60008381526020839052604090205b9392505050565b634e487b7160e01b600052604160045260246000fd5b80356001600160a01b038116811461063b57600080fd5b919050565b6000602080838503121561065357600080fd5b823567ffffffffffffffff8082111561066b57600080fd5b818501915085601f83011261067f57600080fd5b8135818111156106915761069161060e565b8060051b604051601f19603f830116810181811085821117156106b6576106b661060e565b6040529182528482019250838101850191888311156106d457600080fd5b938501935b828510156106f9576106ea85610624565b845293850193928501926106d9565b98975050505050505050565b6000806000806060858703121561071b57600080fd5b61072485610624565b935060208501359250604085013567ffffffffffffffff8082111561074857600080fd5b818701915087601f83011261075c57600080fd5b81358181111561076b57600080fd5b8860208260051b850101111561078057600080fd5b95989497505060200194505050565b6000602082840312156107a157600080fd5b61060782610624565b6000602082840312156107bc57600080fd5b5035919050565b634e487b7160e01b600052603260045260246000fd5b6000600182016107f957634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220567ae83bb354f57edf90f934e5777df8b7694dcc3dead1cea0c013916f772cdc64736f6c634300080d0033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.