Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xDBbC63DbCD67eD4c020699494fF965821e700C91
Balance 0 ETH
Nonce 1
Code Size 6925 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6925 bytes
0x608060405234801561000f575f5ffd5b50600436106100f3575f3560e01c806379ba509711610095578063e30c397811610064578063e30c39781461025b578063ea25e17614610279578063f2fde38b14610295578063f364c90c146102b1576100f3565b806379ba5097146101e75780638393f8dc146101f15780638da5cb5b1461020d578063a27e09781461022b576100f3565b806351bedf69116100d157806351bedf69146101615780635737619814610191578063715018a6146101ad57806371c5ecb1146101b7576100f3565b80632e7a923f146100f7578063323bf9f0146101135780634f67717d14610131575b5f5ffd5b610111600480360381019061010c9190610f07565b6102e1565b005b61011b610485565b6040516101289190610fd1565b60405180910390f35b61014b60048036038101906101469190610fea565b6104a9565b604051610158919061102f565b60405180910390f35b61017b60048036038101906101769190610fea565b6104c6565b6040516101889190611057565b60405180910390f35b6101ab60048036038101906101a691906110ab565b6104db565b005b6101b56105f1565b005b6101d160048036038101906101cc9190610fea565b610604565b6040516101de91906110f8565b60405180910390f35b6101ef610619565b005b61020b600480360381019061020691906111c7565b6106a7565b005b6102156107b6565b60405161022291906112ba565b60405180910390f35b61024560048036038101906102409190610fea565b6107dd565b6040516102529190611057565b60405180910390f35b6102636107f7565b60405161027091906112ba565b60405180910390f35b610293600480360381019061028e9190611328565b61081f565b005b6102af60048036038101906102aa91906113ac565b610839565b005b6102cb60048036038101906102c691906113d7565b6108e5565b6040516102d8919061102f565b60405180910390f35b6102e96108f8565b5f830361032b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103229061146f565b60405180910390fd5b5f5f1b820361036f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610366906114d7565b60405180910390fd5b5f60035f8581526020019081526020015f205490508082116103c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103bd90611565565b60405180910390fd5b60045f8581526020019081526020015f205f9054906101000a900460ff1615610424576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161041b906115f3565b60405180910390fd5b8260025f8681526020019081526020015f20819055508160035f8681526020019081526020015f20819055508183857f117773526ed334678c3b137c3b7e17faca97e28ed9a5e8859bd3a9f8f7a599b260405160405180910390a450505050565b7f0000000000000000000000008e729198d1c59b82bd6bba579310c40d740a11c281565b6004602052805f5260405f205f915054906101000a900460ff1681565b6003602052805f5260405f205f915090505481565b6104e36108f8565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610551576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105489061165b565b60405180910390fd5b7f0000000000000000000000008e729198d1c59b82bd6bba579310c40d740a11c273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb83836040518363ffffffff1660e01b81526004016105ac929190611679565b6020604051808303815f875af11580156105c8573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105ec91906116ca565b505050565b6105f96108f8565b6106025f61097f565b565b6002602052805f5260405f205f915090505481565b5f6106226109af565b90508073ffffffffffffffffffffffffffffffffffffffff166106436107f7565b73ffffffffffffffffffffffffffffffffffffffff161461069b57806040517f118cdaa700000000000000000000000000000000000000000000000000000000815260040161069291906112ba565b60405180910390fd5b6106a48161097f565b50565b5f3390505f89899050905087879050811480156106c657508585905081145b80156106d457508383905081145b610713576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161070a9061173f565b60405180910390fd5b5f5f90505b818110156107a95761079c8b8b838181106107365761073561175d565b5b905060200201358a8a848181106107505761074f61175d565b5b90506020020135858a8a8681811061076b5761076a61175d565b5b905060200201358989878181106107855761078461175d565b5b90506020028101906107979190611796565b6109b6565b8080600101915050610718565b5050505050505050505050565b5f5f5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b5f60035f8381526020019081526020015f20549050919050565b5f60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b5f3390506108318686838787876109b6565b505050505050565b6108416108f8565b8060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508073ffffffffffffffffffffffffffffffffffffffff166108a06107b6565b73ffffffffffffffffffffffffffffffffffffffff167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b5f6108f08383610c7a565b905092915050565b6109006109af565b73ffffffffffffffffffffffffffffffffffffffff1661091e6107b6565b73ffffffffffffffffffffffffffffffffffffffff161461097d576109416109af565b6040517f118cdaa700000000000000000000000000000000000000000000000000000000815260040161097491906112ba565b60405180910390fd5b565b60015f6101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556109ac81610cda565b50565b5f33905090565b5f60025f8881526020019081526020015f205490505f5f1b8103610a0f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0690611842565b60405180910390fd5b610a198787610c7a565b15610a59576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a50906118aa565b60405180910390fd5b5f87878787604051602001610a71949392919061192d565b604051602081830303815290604052805190602001209050610ad48484808060200260200160405190810160405280939291908181526020018383602002808284375f81840152601f19601f820116905080830192505050505050508383610d9b565b610b13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b0a906119c4565b60405180910390fd5b610b1d8888610db1565b600160045f8a81526020019081526020015f205f6101000a81548160ff0219169083151502179055507f0000000000000000000000008e729198d1c59b82bd6bba579310c40d740a11c273ffffffffffffffffffffffffffffffffffffffff1663a9059cbb87876040518363ffffffff1660e01b8152600401610ba1929190611679565b6020604051808303815f875af1158015610bbd573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610be191906116ca565b610c20576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c1790611a2c565b60405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff1687897fb94bf7f9302edf52a596286915a69b4b0685574cffdedd0712e3c62f2550f0ba88604051610c689190611057565b60405180910390a45050505050505050565b5f5f61010083610c8a9190611a77565b90505f61010084610c9b9190611aa7565b90505f60055f8781526020019081526020015f205f8481526020019081526020015f205490505f826001901b9050808183161494505050505092915050565b5f5f5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050815f5f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b5f82610da78584610e0a565b1490509392505050565b5f61010082610dc09190611a77565b90505f61010083610dd19190611aa7565b9050806001901b60055f8681526020019081526020015f205f8481526020019081526020015f205f828254179250508190555050505050565b5f5f8290505f5f90505b8451811015610e5057610e4182868381518110610e3457610e3361175d565b5b6020026020010151610e5b565b91508080600101915050610e14565b508091505092915050565b5f818310610e7257610e6d8284610e85565b610e7d565b610e7c8383610e85565b5b905092915050565b5f825f528160205260405f20905092915050565b5f5ffd5b5f5ffd5b5f819050919050565b610eb381610ea1565b8114610ebd575f5ffd5b50565b5f81359050610ece81610eaa565b92915050565b5f819050919050565b610ee681610ed4565b8114610ef0575f5ffd5b50565b5f81359050610f0181610edd565b92915050565b5f5f5f60608486031215610f1e57610f1d610e99565b5b5f610f2b86828701610ec0565b9350506020610f3c86828701610ef3565b9250506040610f4d86828701610ec0565b9150509250925092565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f819050919050565b5f610f99610f94610f8f84610f57565b610f76565b610f57565b9050919050565b5f610faa82610f7f565b9050919050565b5f610fbb82610fa0565b9050919050565b610fcb81610fb1565b82525050565b5f602082019050610fe45f830184610fc2565b92915050565b5f60208284031215610fff57610ffe610e99565b5b5f61100c84828501610ec0565b91505092915050565b5f8115159050919050565b61102981611015565b82525050565b5f6020820190506110425f830184611020565b92915050565b61105181610ea1565b82525050565b5f60208201905061106a5f830184611048565b92915050565b5f61107a82610f57565b9050919050565b61108a81611070565b8114611094575f5ffd5b50565b5f813590506110a581611081565b92915050565b5f5f604083850312156110c1576110c0610e99565b5b5f6110ce85828601611097565b92505060206110df85828601610ec0565b9150509250929050565b6110f281610ed4565b82525050565b5f60208201905061110b5f8301846110e9565b92915050565b5f5ffd5b5f5ffd5b5f5ffd5b5f5f83601f84011261113257611131611111565b5b8235905067ffffffffffffffff81111561114f5761114e611115565b5b60208301915083602082028301111561116b5761116a611119565b5b9250929050565b5f5f83601f84011261118757611186611111565b5b8235905067ffffffffffffffff8111156111a4576111a3611115565b5b6020830191508360208202830111156111c0576111bf611119565b5b9250929050565b5f5f5f5f5f5f5f5f6080898b0312156111e3576111e2610e99565b5b5f89013567ffffffffffffffff811115611200576111ff610e9d565b5b61120c8b828c0161111d565b9850985050602089013567ffffffffffffffff81111561122f5761122e610e9d565b5b61123b8b828c0161111d565b9650965050604089013567ffffffffffffffff81111561125e5761125d610e9d565b5b61126a8b828c0161111d565b9450945050606089013567ffffffffffffffff81111561128d5761128c610e9d565b5b6112998b828c01611172565b92509250509295985092959890939650565b6112b481611070565b82525050565b5f6020820190506112cd5f8301846112ab565b92915050565b5f5f83601f8401126112e8576112e7611111565b5b8235905067ffffffffffffffff81111561130557611304611115565b5b60208301915083602082028301111561132157611320611119565b5b9250929050565b5f5f5f5f5f6080868803121561134157611340610e99565b5b5f61134e88828901610ec0565b955050602061135f88828901610ec0565b945050604061137088828901610ec0565b935050606086013567ffffffffffffffff81111561139157611390610e9d565b5b61139d888289016112d3565b92509250509295509295909350565b5f602082840312156113c1576113c0610e99565b5b5f6113ce84828501611097565b91505092915050565b5f5f604083850312156113ed576113ec610e99565b5b5f6113fa85828601610ec0565b925050602061140b85828601610ec0565b9150509250929050565b5f82825260208201905092915050565b7f70726f706f73616c4964207a65726f00000000000000000000000000000000005f82015250565b5f611459600f83611415565b915061146482611425565b602082019050919050565b5f6020820190508181035f8301526114868161144d565b9050919050565b7f526f6f742063616e6e6f74206265207a65726f000000000000000000000000005f82015250565b5f6114c1601383611415565b91506114cc8261148d565b602082019050919050565b5f6020820190508181035f8301526114ee816114b5565b9050919050565b7f56657273696f6e206d7573742062652067726561746572207468616e206375725f8201527f72656e7400000000000000000000000000000000000000000000000000000000602082015250565b5f61154f602483611415565b915061155a826114f5565b604082019050919050565b5f6020820190508181035f83015261157c81611543565b9050919050565b7f43616e6e6f74206f766572777269746520726f6f7420616674657220636c61695f8201527f6d732068617665206265656e206d616465000000000000000000000000000000602082015250565b5f6115dd603183611415565b91506115e882611583565b604082019050919050565b5f6020820190508181035f83015261160a816115d1565b9050919050565b7f5a65726f206164647265737300000000000000000000000000000000000000005f82015250565b5f611645600c83611415565b915061165082611611565b602082019050919050565b5f6020820190508181035f83015261167281611639565b9050919050565b5f60408201905061168c5f8301856112ab565b6116996020830184611048565b9392505050565b6116a981611015565b81146116b3575f5ffd5b50565b5f815190506116c4816116a0565b92915050565b5f602082840312156116df576116de610e99565b5b5f6116ec848285016116b6565b91505092915050565b7f4c656e677468206d69736d6174636800000000000000000000000000000000005f82015250565b5f611729600f83611415565b9150611734826116f5565b602082019050919050565b5f6020820190508181035f8301526117568161171d565b9050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f5ffd5b5f5ffd5b5f5ffd5b5f5f833560016020038436030381126117b2576117b161178a565b5b80840192508235915067ffffffffffffffff8211156117d4576117d361178e565b5b6020830192506020820236038313156117f0576117ef611792565b5b509250929050565b7f526f6f74206e6f742073657400000000000000000000000000000000000000005f82015250565b5f61182c600c83611415565b9150611837826117f8565b602082019050919050565b5f6020820190508181035f83015261185981611820565b9050919050565b7f416c726561647920636c61696d656400000000000000000000000000000000005f82015250565b5f611894600f83611415565b915061189f82611860565b602082019050919050565b5f6020820190508181035f8301526118c181611888565b9050919050565b5f819050919050565b6118e26118dd82610ea1565b6118c8565b82525050565b5f8160601b9050919050565b5f6118fe826118e8565b9050919050565b5f61190f826118f4565b9050919050565b61192761192282611070565b611905565b82525050565b5f61193882876118d1565b60208201915061194882866118d1565b6020820191506119588285611916565b60148201915061196882846118d1565b60208201915081905095945050505050565b7f496e76616c69642070726f6f66000000000000000000000000000000000000005f82015250565b5f6119ae600d83611415565b91506119b98261197a565b602082019050919050565b5f6020820190508181035f8301526119db816119a2565b9050919050565b7f414c5641207472616e73666572206661696c65640000000000000000000000005f82015250565b5f611a16601483611415565b9150611a21826119e2565b602082019050919050565b5f6020820190508181035f830152611a4381611a0a565b9050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f611a8182610ea1565b9150611a8c83610ea1565b925082611a9c57611a9b611a4a565b5b828204905092915050565b5f611ab182610ea1565b9150611abc83610ea1565b925082611acc57611acb611a4a565b5b82820690509291505056fea2646970667358221220f5b78a22937729e7295a798c3f8e51f6103cbb7ca18eee80298ecd0eb4e8d99d64736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: cancun Optimization: No
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../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.
 *
 * The initial owner is set to the address provided by the deployer. 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;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

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

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @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 {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling 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 {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _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);
    }
}
Ownable2Step.sol 67 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

import {Ownable} from "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * This extension of the {Ownable} contract includes a two-step mechanism to transfer
 * ownership, where the new owner must call {acceptOwnership} in order to replace the
 * old one. This can help prevent common mistakes, such as transfers of ownership to
 * incorrect accounts, or to contracts that are unable to interact with the
 * permission system.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

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

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

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     *
     * Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
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);
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
Hashes.sol 31 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/Hashes.sol)

pragma solidity ^0.8.20;

/**
 * @dev Library of standard hash functions.
 *
 * _Available since v5.1._
 */
library Hashes {
    /**
     * @dev Commutative Keccak256 hash of a sorted pair of bytes32. Frequently used when working with merkle proofs.
     *
     * NOTE: Equivalent to the `standardNodeHash` in our https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
     */
    function commutativeKeccak256(bytes32 a, bytes32 b) internal pure returns (bytes32) {
        return a < b ? efficientKeccak256(a, b) : efficientKeccak256(b, a);
    }

    /**
     * @dev Implementation of keccak256(abi.encode(a, b)) that doesn't allocate or expand memory.
     */
    function efficientKeccak256(bytes32 a, bytes32 b) internal pure returns (bytes32 value) {
        assembly ("memory-safe") {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}
MerkleProof.sol 514 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/MerkleProof.sol)
// This file was procedurally generated from scripts/generate/templates/MerkleProof.js.

pragma solidity ^0.8.20;

import {Hashes} from "./Hashes.sol";

/**
 * @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.
 *
 * IMPORTANT: Consider memory side-effects when using custom hashing functions
 * that access memory in an unsafe way.
 *
 * NOTE: This library supports proof verification for merkle trees built using
 * custom _commutative_ hashing functions (i.e. `H(a, b) == H(b, a)`). Proving
 * leaf inclusion in trees built using non-commutative hashing functions requires
 * additional logic that is not supported by this library.
 */
library MerkleProof {
    /**
     *@dev The multiproof provided is not valid.
     */
    error MerkleProofInvalidMultiproof();

    /**
     * @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.
     *
     * This version handles proofs in memory with the default hashing function.
     */
    function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
        return processProof(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 leaves & pre-images are assumed to be sorted.
     *
     * This version handles proofs in memory with the default hashing function.
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = Hashes.commutativeKeccak256(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @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.
     *
     * This version handles proofs in memory with a custom hashing function.
     */
    function verify(
        bytes32[] memory proof,
        bytes32 root,
        bytes32 leaf,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bool) {
        return processProof(proof, leaf, hasher) == 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 leaves & pre-images are assumed to be sorted.
     *
     * This version handles proofs in memory with a custom hashing function.
     */
    function processProof(
        bytes32[] memory proof,
        bytes32 leaf,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = hasher(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @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.
     *
     * This version handles proofs in calldata with the default hashing function.
     */
    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 leaves & pre-images are assumed to be sorted.
     *
     * This version handles proofs in calldata with the default hashing function.
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = Hashes.commutativeKeccak256(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @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.
     *
     * This version handles proofs in calldata with a custom hashing function.
     */
    function verifyCalldata(
        bytes32[] calldata proof,
        bytes32 root,
        bytes32 leaf,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bool) {
        return processProofCalldata(proof, leaf, hasher) == 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 leaves & pre-images are assumed to be sorted.
     *
     * This version handles proofs in calldata with a custom hashing function.
     */
    function processProofCalldata(
        bytes32[] calldata proof,
        bytes32 leaf,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = hasher(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}.
     *
     * This version handles multiproofs in memory with the default hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
     * The `leaves` must be validated independently. See {processMultiProof}.
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(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.
     *
     * This version handles multiproofs in memory with the default hashing function.
     *
     * 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).
     *
     * NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
     * and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
     * validating the leaves elsewhere.
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuilds 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 proofFlagsLen = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proof.length != proofFlagsLen + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // 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[](proofFlagsLen);
        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 from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < proofFlagsLen; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = Hashes.commutativeKeccak256(a, b);
        }

        if (proofFlagsLen > 0) {
            if (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @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}.
     *
     * This version handles multiproofs in memory with a custom hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
     * The `leaves` must be validated independently. See {processMultiProof}.
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bool) {
        return processMultiProof(proof, proofFlags, leaves, hasher) == 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.
     *
     * This version handles multiproofs in memory with a custom hashing function.
     *
     * 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).
     *
     * NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
     * and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
     * validating the leaves elsewhere.
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bytes32 merkleRoot) {
        // This function rebuilds 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 proofFlagsLen = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proof.length != proofFlagsLen + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // 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[](proofFlagsLen);
        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 from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < proofFlagsLen; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = hasher(a, b);
        }

        if (proofFlagsLen > 0) {
            if (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @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}.
     *
     * This version handles multiproofs in calldata with the default hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
     * The `leaves` must be validated independently. See {processMultiProofCalldata}.
     */
    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.
     *
     * This version handles multiproofs in calldata with the default hashing function.
     *
     * 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).
     *
     * NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
     * and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
     * validating the leaves elsewhere.
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuilds 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 proofFlagsLen = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proof.length != proofFlagsLen + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // 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[](proofFlagsLen);
        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 from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < proofFlagsLen; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = Hashes.commutativeKeccak256(a, b);
        }

        if (proofFlagsLen > 0) {
            if (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @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}.
     *
     * This version handles multiproofs in calldata with a custom hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
     * The `leaves` must be validated independently. See {processMultiProofCalldata}.
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves, hasher) == 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.
     *
     * This version handles multiproofs in calldata with a custom hashing function.
     *
     * 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).
     *
     * NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
     * and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
     * validating the leaves elsewhere.
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bytes32 merkleRoot) {
        // This function rebuilds 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 proofFlagsLen = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proof.length != proofFlagsLen + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // 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[](proofFlagsLen);
        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 from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < proofFlagsLen; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = hasher(a, b);
        }

        if (proofFlagsLen > 0) {
            if (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }
}
gaugeweightclaims.sol 201 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

/**
 * @title Gauge Weight Claims
 * @notice Distributes ALVA rewards for gauge weight voting.
 *
 * Off-chain, for each proposalId (e.g. a week), you compute a Merkle tree of leaves:
 *   leaf = keccak256(abi.encodePacked(proposalId, index, account, amount));
 *
 * - proposalId: uint256 identifying a specific epoch / week.
 * - index:      uint256 unique per leaf within that proposal.
 * - account:    address that should receive the tokens.
 * - amount:     uint256 amount of tokens assigned to that account for that proposal.
 */
contract GaugeWeightClaims is Ownable2Step {
    IERC20 public immutable ALVA;

    // proposalId => merkleRoot
    mapping(uint256 => bytes32) public merkleRoots;

    // proposalId => root version (increments each time root is set, starts at 0)
    mapping(uint256 => uint256) public rootVersions;

    // proposalId => whether any claims have been made (prevents root overwriting)
    mapping(uint256 => bool) public hasClaims;

    // proposalId => (wordIndex => bitmask) for claimed indices
    mapping(uint256 => mapping(uint256 => uint256)) private claimedBitMap;

    event MerkleRootSet(uint256 indexed proposalId, bytes32 indexed merkleRoot, uint256 indexed version);
    event Claimed(
        uint256 indexed proposalId,
        uint256 indexed index,
        address indexed account,
        uint256 amount
    );

    constructor(address _ALVA, address initialOwner) Ownable(initialOwner) {
        require(_ALVA != address(0), "ALVA zero address");
        ALVA = IERC20(_ALVA);
    }

    // ---------------- Admin functions ---------------- //

    /**
     * @notice Set or update merkle root for a proposal.
     * @param proposalId The proposal ID
     * @param merkleRoot The merkle root to set
     * @param version Must be greater than current version. Prevents overwriting with older roots.
     * @dev Once claims have been made for a proposal, the root cannot be changed.
     *      Version must always increment to prevent setting an older root.
     */
    /**
     * @notice Set or update merkle root for a proposal.
     * @param proposalId The proposal ID
     * @param merkleRoot The merkle root to set
     * @param version Must be greater than current version. Prevents overwriting with older roots.
     * @dev Once claims have been made for a proposal, the root cannot be changed.
     *      Version must always increment to prevent setting an older root.
     */
    function setMerkleRoot(
        uint256 proposalId,
        bytes32 merkleRoot,
        uint256 version
    ) external onlyOwner {
        require(proposalId != 0, "proposalId zero");
        require(merkleRoot != bytes32(0), "Root cannot be zero");
        
        uint256 currentVersion = rootVersions[proposalId];
        require(version > currentVersion, "Version must be greater than current");
        
        // Prevent overwriting if any claims have been made for this proposal
        require(!hasClaims[proposalId], "Cannot overwrite root after claims have been made");
        
        merkleRoots[proposalId] = merkleRoot;
        rootVersions[proposalId] = version;
        emit MerkleRootSet(proposalId, merkleRoot, version);
    }
    
    /**
     * @notice Get the current root version for a proposal
     * @param proposalId The proposal ID
     * @return The current version number (0 if never set)
     */
    function getRootVersion(uint256 proposalId) external view returns (uint256) {
        return rootVersions[proposalId];
    }

    function rescueTokens(address to, uint256 amount) external onlyOwner {
        require(to != address(0), "Zero address");
        ALVA.transfer(to, amount);
    }

    // ---------------- Claim tracking ---------------- //

    function _isClaimed(
        uint256 proposalId,
        uint256 index
    ) internal view returns (bool) {
        uint256 wordIndex = index / 256;
        uint256 bitIndex = index % 256;
        uint256 word = claimedBitMap[proposalId][wordIndex];
        uint256 mask = (1 << bitIndex);
        return word & mask == mask;
    }

    function isClaimed(
        uint256 proposalId,
        uint256 index
    ) external view returns (bool) {
        return _isClaimed(proposalId, index);
    }

    function _setClaimed(uint256 proposalId, uint256 index) internal {
        uint256 wordIndex = index / 256;
        uint256 bitIndex = index % 256;
        claimedBitMap[proposalId][wordIndex] |= (1 << bitIndex);
    }

    // ---------------- Internal claim core ---------------- //

    function _claim(
        uint256 proposalId,
        uint256 index,
        address account,
        uint256 amount,
        bytes32[] calldata merkleProof
    ) internal {
        bytes32 root = merkleRoots[proposalId];
        require(root != bytes32(0), "Root not set");
        require(!_isClaimed(proposalId, index), "Already claimed");

        bytes32 node = keccak256(
            abi.encodePacked(proposalId, index, account, amount)
        );

        require(MerkleProof.verify(merkleProof, root, node), "Invalid proof");

        _setClaimed(proposalId, index);
        
        // Mark that claims have been made for this proposal (prevents root overwriting)
        hasClaims[proposalId] = true;

        require(ALVA.transfer(account, amount), "ALVA transfer failed");

        emit Claimed(proposalId, index, account, amount);
    }

    // ---------------- Public single-claim ---------------- //

    function claim(
        uint256 proposalId,
        uint256 index,
        uint256 amount,
        bytes32[] calldata merkleProof
    ) external {
        address account = msg.sender;
        _claim(proposalId, index, account, amount, merkleProof);
    }

    // ---------------- Public batch-claim ---------------- //

    /**
     * @notice Batch claim for multiple proposals / weeks.
     *         Reverts entirely if ANY individual claim would revert.
     *
     * Frontend should only include entries where isClaimed(...) == false.
     * All claims must be for msg.sender.
     */
    function batchClaim(
        uint256[] calldata proposalIds,
        uint256[] calldata indices,
        uint256[] calldata amounts,
        bytes32[][] calldata merkleProofs
    ) external {
        address account = msg.sender;
        uint256 len = proposalIds.length;
        require(
            len == indices.length &&
                len == amounts.length &&
                len == merkleProofs.length,
            "Length mismatch"
        );

        for (uint256 i = 0; i < len; i++) {
            _claim(
                proposalIds[i],
                indices[i],
                account,
                amounts[i],
                merkleProofs[i]
            );
        }
    }
}

Read Contract

ALVA 0x323bf9f0 → address
getRootVersion 0xa27e0978 → uint256
hasClaims 0x4f67717d → bool
isClaimed 0xf364c90c → bool
merkleRoots 0x71c5ecb1 → bytes32
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
rootVersions 0x51bedf69 → uint256

Write Contract 7 functions

These functions modify contract state and require a wallet transaction to execute.

acceptOwnership 0x79ba5097
No parameters
batchClaim 0x8393f8dc
uint256[] proposalIds
uint256[] indices
uint256[] amounts
bytes32[][] merkleProofs
claim 0xea25e176
uint256 proposalId
uint256 index
uint256 amount
bytes32[] merkleProof
renounceOwnership 0x715018a6
No parameters
rescueTokens 0x57376198
address to
uint256 amount
setMerkleRoot 0x2e7a923f
uint256 proposalId
bytes32 merkleRoot
uint256 version
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

No transactions found for this address