false
true
0

Contract Address Details

0x267b0DE19A3cf105940cd4bDEB69Ef797B226b6d

Contract Name
YieldVault
Creator
0x038db8–b803f1 at 0xd6328d–1f7cd7
Balance
0 tPLS
Tokens
Fetching tokens...
Transactions
Fetching transactions...
Transfers
Fetching transfers...
Gas Used
Fetching gas used...
Last Balance Update
26048725
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
YieldVault




Optimization enabled
false
Compiler version
v0.8.20+commit.a1b79de6




EVM Version




Verified at
2026-11-21T17:11:34.842524Z

Constructor Arguments

000000000000000000000000726f6d4ed3b7842ba27e54ed7f198269bc0b2558000000000000000000000000e84a941fe9da6eb049aed191e3d780f5e7b8f3ab000000000000000000000000ea7e02c247418107a97f430538148d23e98160c2

Arg [0] (address) : 0x726f6d4ed3b7842ba27e54ed7f198269bc0b2558
Arg [1] (address) : 0xe84a941fe9da6eb049aed191e3d780f5e7b8f3ab
Arg [2] (address) : 0xea7e02c247418107a97f430538148d23e98160c2

              

contracts/core/YieldVault.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/// @title IBidToken
/// @notice The one thing the vault needs from the BID auction token: the
///         "have you activated your account?" flag. A wallet only earns the
///         flag by spending BID (BidToken.depositBids), so staking and daily
///         revenue are gated to real participants.
interface IBidToken {
    function checkStakingStatus(address user) external view returns (bool);
}

/// @title ICommissionTree
/// @notice The upline/MLM engine. On every stake the vault pings it so it can
///         mint/allocate the 10% / 5% / 2% BBA sponsor commissions — or route
///         them to the company rotator when the staker has no sponsor.
interface ICommissionTree {
    function distributeStakingCommissions(address staker, uint256 stakedAmount) external;
}

/// @title YieldVault
/// @notice Two jobs in one contract for the Blockbids ecosystem on PulseChain:
///         1. The BBA staking vault — users lock BBA here and the commission
///            tree pays their upline.
///         2. A Web2-hybrid "claim terminal" — it holds native PLS (routed in
///            from BBACoin tax swaps + the treasury) and lets stakers claim
///            their daily revenue share against a Merkle root the backend
///            publishes each epoch.
/// @dev The daily 16.5% revenue math (90-day expiries, $500 minimums, ad
///      verifications) is impossible on-chain, so the backend computes each
///      day's allocations off-chain and the admin posts only the Merkle root.
contract YieldVault is AccessControl, ReentrancyGuard {
    using SafeERC20 for IERC20;

    // --- Immutable-ish wiring ---

    IERC20 public bbaToken;              // the token users stake
    IBidToken public bidToken;           // source of checkStakingStatus()
    ICommissionTree public commissionTree; // upline payout engine

    // --- Staking state ---

    mapping(address => uint256) public stakedBalance;
    uint256 public totalStaked; // sum of all stakes; protects users from rescueERC20

    // each stake re-locks the whole balance
    uint256 public constant MAX_LOCK_DURATION = 365 days;
    uint256 public lockDuration = 30 days;
    mapping(address => uint256) public unlockTime;

    // --- Daily revenue (Merkle) state ---

    uint256 public currentEpoch;
    mapping(uint256 => bytes32) public epochRoot;
    // PLS still owed per epoch, rescueNative can't touch it
    mapping(uint256 => uint256) public epochUnclaimed;
    uint256 public totalReserved;
    uint256 public constant CLAIM_WINDOW = 90 days;
    mapping(uint256 => uint256) public epochPostedAt;
    // epoch => user => already pulled this epoch's allocation?
    mapping(uint256 => mapping(address => bool)) public hasClaimed;

    // --- Events ---

    event Staked(address indexed user, uint256 amount);
    event Unstaked(address indexed user, uint256 amount);
    event DailyRootUpdated(uint256 indexed epoch, bytes32 newRoot, uint256 epochTotal);
    event RevenueClaimed(uint256 indexed epoch, address indexed user, uint256 amount);
    event EpochExpired(uint256 indexed epoch, uint256 released);
    event BbaTokenUpdated(address indexed previous, address indexed current);
    event BidTokenUpdated(address indexed previous, address indexed current);
    event CommissionTreeUpdated(address indexed previous, address indexed current);
    event LockDurationUpdated(uint256 newDuration);
    event ERC20Rescued(address indexed token, address indexed to, uint256 amount);
    event NativeRescued(address indexed to, uint256 amount);

    constructor(
        address _bbaToken,
        address _bidToken,
        address _commissionTree
    ) {
        require(_bbaToken != address(0), "Vault: bba is zero");
        require(_bidToken != address(0), "Vault: bid is zero");
        require(_commissionTree != address(0), "Vault: tree is zero");

        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);

        bbaToken = IERC20(_bbaToken);
        bidToken = IBidToken(_bidToken);
        commissionTree = ICommissionTree(_commissionTree);
    }

    // ============================================================
    //                     STAKING (BBA)
    // ============================================================

    /// @notice Lock `amount` BBA in the vault and trigger upline commissions.
    /// @dev Requires the caller to have activated staking by spending BID.
    ///      Caller must approve(this, amount) on the BBA token first.
    function stake(uint256 amount) external nonReentrant {
        require(amount > 0, "Vault: amount is zero");
        require(bidToken.checkStakingStatus(msg.sender), "Vault: not activated");

        // Effects first (CEI): book the stake before any external call.
        stakedBalance[msg.sender] += amount;
        totalStaked += amount;
        unlockTime[msg.sender] = block.timestamp + lockDuration;

        // Pull the BBA. SafeERC20 reverts on a lying/false-returning token.
        bbaToken.safeTransferFrom(msg.sender, address(this), amount);

        // CRITICAL HOOK: pay the sponsor tree. Left un-caught on purpose — if
        // commissions can't be booked the whole stake reverts rather than
        // silently shorting the upline.
        commissionTree.distributeStakingCommissions(msg.sender, amount);

        emit Staked(msg.sender, amount);
    }

    /// @notice Withdraw `amount` of previously staked BBA.
    /// @dev No activation check, but the stake must be past its lock. Unstaking
    ///      does not claw back paid commissions.
    function unstake(uint256 amount) external nonReentrant {
        require(amount > 0, "Vault: amount is zero");
        require(stakedBalance[msg.sender] >= amount, "Vault: insufficient stake");
        require(block.timestamp >= unlockTime[msg.sender], "Vault: stake locked");

        stakedBalance[msg.sender] -= amount;
        totalStaked -= amount;

        bbaToken.safeTransfer(msg.sender, amount);

        emit Unstaked(msg.sender, amount);
    }

    // ============================================================
    //              DAILY REVENUE CLAIM (native PLS)
    // ============================================================

    /// @notice Publish a new day's allocation root and reserve its PLS.
    /// @param epochTotal Sum of every allocation in the root; the vault must
    ///                   already hold it on top of earlier unclaimed epochs.
    function updateDailyRoot(bytes32 newRoot, uint256 epochTotal)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(newRoot != bytes32(0), "Vault: root is zero");
        require(
            address(this).balance >= totalReserved + epochTotal,
            "Vault: underfunded epoch"
        );

        currentEpoch += 1;
        epochRoot[currentEpoch] = newRoot;
        epochUnclaimed[currentEpoch] = epochTotal;
        epochPostedAt[currentEpoch] = block.timestamp;
        totalReserved += epochTotal;

        emit DailyRootUpdated(currentEpoch, newRoot, epochTotal);
    }

    /// @notice Claim your allocated PLS for any published epoch not yet claimed.
    /// @param epoch       The epoch whose root holds the allocation.
    /// @param amount      PLS (wei) the backend allocated to msg.sender.
    /// @param merkleProof Proof against epochRoot[epoch].
    /// @dev OpenZeppelin standard-merkle-tree leaf: double keccak256 over
    ///      abi.encode(chainId, vault, epoch, account, amount). The backend must
    ///      build it with ["uint256","address","uint256","address","uint256"].
    function claimDailyRevenue(
        uint256 epoch,
        uint256 amount,
        bytes32[] calldata merkleProof
    ) external nonReentrant {
        require(epoch != 0 && epoch <= currentEpoch, "Vault: bad epoch");
        require(block.timestamp < epochPostedAt[epoch] + CLAIM_WINDOW, "Vault: epoch expired");
        require(bidToken.checkStakingStatus(msg.sender), "Vault: not activated");
        require(!hasClaimed[epoch][msg.sender], "Vault: already claimed");

        bytes32 leaf = keccak256(
            bytes.concat(
                keccak256(
                    abi.encode(block.chainid, address(this), epoch, msg.sender, amount)
                )
            )
        );
        require(
            MerkleProof.verify(merkleProof, epochRoot[epoch], leaf),
            "Vault: bad proof"
        );
        // a bad root can't pay out more than was reserved for it
        require(amount <= epochUnclaimed[epoch], "Vault: exceeds epoch total");

        // Effects before the value transfer (CEI + nonReentrant).
        hasClaimed[epoch][msg.sender] = true;
        epochUnclaimed[epoch] -= amount;
        totalReserved -= amount;

        (bool ok, ) = payable(msg.sender).call{value: amount}("");
        require(ok, "Vault: PLS transfer failed");

        emit RevenueClaimed(epoch, msg.sender, amount);
    }

    /// @notice Release an epoch's unclaimed PLS once its claim window has
    ///         closed, making it surplus again. Anyone can call it.
    function expireEpoch(uint256 epoch) external {
        require(epoch != 0 && epoch <= currentEpoch, "Vault: bad epoch");
        require(block.timestamp >= epochPostedAt[epoch] + CLAIM_WINDOW, "Vault: epoch still open");

        uint256 released = epochUnclaimed[epoch];
        require(released > 0, "Vault: nothing to release");

        epochUnclaimed[epoch] = 0;
        totalReserved -= released;

        emit EpochExpired(epoch, released);
    }

    // ============================================================
    //                   FUNDING & SAFETY
    // ============================================================

    /// @notice Passively receive native PLS — BBACoin tax swaps land here, and
    ///         so does treasury top-up for the daily revenue pool.
    receive() external payable {}

    /// @notice Rescue ERC20s sent here by mistake.
    /// @dev For the staking token we only let the admin pull the surplus above
    ///      totalStaked, so this can never be used to drain users' stakes.
    function rescueERC20(address token, address to, uint256 amount)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(to != address(0), "Vault: to is zero");
        if (token == address(bbaToken)) {
            uint256 surplus = bbaToken.balanceOf(address(this)) - totalStaked;
            require(amount <= surplus, "Vault: exceeds BBA surplus");
        }
        IERC20(token).safeTransfer(to, amount);
        emit ERC20Rescued(token, to, amount);
    }

    /// @notice Withdraw native PLS above what published epochs still owe.
    function rescueNative(address to, uint256 amount)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(to != address(0), "Vault: to is zero");
        require(
            amount <= address(this).balance - totalReserved,
            "Vault: exceeds PLS surplus"
        );
        (bool ok, ) = payable(to).call{value: amount}("");
        require(ok, "Vault: PLS transfer failed");
        emit NativeRescued(to, amount);
    }

    // ============================================================
    //                        ADMIN WIRING
    // ============================================================

    /// @notice Applies to future stakes only; existing unlock times are kept.
    function setLockDuration(uint256 _duration)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(_duration <= MAX_LOCK_DURATION, "Vault: lock too long");
        lockDuration = _duration;
        emit LockDurationUpdated(_duration);
    }

    function setBbaToken(address _bbaToken)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(_bbaToken != address(0), "Vault: bba is zero");
        require(totalStaked == 0, "Vault: stakes outstanding");
        emit BbaTokenUpdated(address(bbaToken), _bbaToken);
        bbaToken = IERC20(_bbaToken);
    }

    function setBidToken(address _bidToken)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(_bidToken != address(0), "Vault: bid is zero");
        emit BidTokenUpdated(address(bidToken), _bidToken);
        bidToken = IBidToken(_bidToken);
    }

    function setCommissionTree(address _commissionTree)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(_commissionTree != address(0), "Vault: tree is zero");
        emit CommissionTreeUpdated(address(commissionTree), _commissionTree);
        commissionTree = ICommissionTree(_commissionTree);
    }
}
        

contracts/core/BidToken.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import {IBBACoin} from "../interfaces/IBBACoin.sol";

/// @title BidToken
/// @notice Blockbids' $1-pegged auction token (BID). Spending BID routes the
///         revenue to the treasury, mints BBA to the bidder, and flips the
///         wallet's staking flag on — the "Value Loop".
contract BidToken is ERC20, AccessControl, ReentrancyGuard {
    // --- Roles ---

    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); // fiat/web2 bridge

    // --- State ---

    address public bbaTokenAddress; // the BBACoin contract we mint rewards on
    address public auctionTreasury; // where spent BID lands (recycled revenue)
    uint256 public bbaMintRate; // BBA minted per 1 BID spent, scaled by 1e18
    uint256 public minActivationAmount = 1e18; // smallest single deposit that unlocks staking

    // "your bids activate staking and farming" — set once a wallet deposits bids
    mapping(address => bool) private _isStakingActivated;

    // --- Events ---

    event BidDeposited(address indexed user, uint256 amount, uint256 bbaRewarded);
    event BbaTokenAddressUpdated(address indexed previous, address indexed current);
    event AuctionTreasuryUpdated(address indexed previous, address indexed current);
    event BbaMintRateUpdated(uint256 newRate);
    event MinActivationAmountUpdated(uint256 newAmount);

    constructor(
        address _bbaTokenAddress,
        address _auctionTreasury,
        uint256 _bbaMintRate
    ) ERC20("Blockbids", "BID") {
        require(_bbaTokenAddress != address(0), "BID: bba is zero");
        require(_auctionTreasury != address(0), "BID: treasury is zero");

        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);

        bbaTokenAddress = _bbaTokenAddress;
        auctionTreasury = _auctionTreasury;
        bbaMintRate = _bbaMintRate;
    }

    // --- Value Loop ---

    /// @notice Spend BID: route it to the treasury, mint BBA back, and unlock
    ///         staking if the deposit is at least minActivationAmount.
    /// @dev User must hold `bidAmount` BID. No approval needed — these are the
    ///      caller's own tokens, so we move them with the internal _transfer
    ///      instead of the spec's transferFrom (which would require a pointless
    ///      self-approval and, called internally, reverts on a zero self-allowance).
    function depositBids(uint256 bidAmount) external nonReentrant {
        require(bidAmount > 0, "BID: amount is zero");

        // revenue routing (recycling): user -> treasury
        _transfer(msg.sender, auctionTreasury, bidAmount);

        uint256 bbaReward = (bidAmount * bbaMintRate) / (10 ** decimals());
        // clamp to the cap so bids still settle
        uint256 remaining = IBBACoin(bbaTokenAddress).mintableRemaining();
        if (bbaReward > remaining) {
            bbaReward = remaining;
        }

        // effects before the external call (CEI); nonReentrant guards it too
        if (bidAmount >= minActivationAmount) {
            _isStakingActivated[msg.sender] = true;
        }

        if (bbaReward > 0) {
            IBBACoin(bbaTokenAddress).mint(msg.sender, bbaReward);
        }

        emit BidDeposited(msg.sender, bidAmount, bbaReward);
    }

    // --- Fiat gateway ---

    /// @notice Mint BID to a buyer once their fiat/USDC payment clears off-chain.
    function mintBid(address to, uint256 amount) external onlyRole(MINTER_ROLE) {
        _mint(to, amount);
    }

    // --- Reads ---

    /// @notice Master key for YieldVault: has this wallet ever deposited bids?
    function checkStakingStatus(address user) external view returns (bool) {
        return _isStakingActivated[user];
    }

    // --- Admin ---

    function setBbaMintRate(uint256 _newRate)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        bbaMintRate = _newRate;
        emit BbaMintRateUpdated(_newRate);
    }

    function setMinActivationAmount(uint256 _amount)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(_amount > 0, "BID: amount is zero");
        minActivationAmount = _amount;
        emit MinActivationAmountUpdated(_amount);
    }

    function setAuctionTreasury(address _newTreasury)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(_newTreasury != address(0), "BID: treasury is zero");
        emit AuctionTreasuryUpdated(auctionTreasury, _newTreasury);
        auctionTreasury = _newTreasury;
    }

    function setBbaTokenAddress(address _bbaAddress)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        require(_bbaAddress != address(0), "BID: bba is zero");
        emit BbaTokenAddressUpdated(bbaTokenAddress, _bbaAddress);
        bbaTokenAddress = _bbaAddress;
    }
}
          

@openzeppelin/contracts/interfaces/draft-IERC6093.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (interfaces/draft-IERC6093.sol)

pragma solidity >=0.8.4;

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-721.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
          

@openzeppelin/contracts/utils/introspection/ERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
          

contracts/core/QuarterlyBurner.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";

import {IBBACoin} from "../interfaces/IBBACoin.sol";

/// @title QuarterlyBurner
/// @notice Lightweight autonomous timelock: once every 90 days, anyone can
///         call `executeBurn` to burn exactly 3.69% of BBA's current
///         total supply out of the treasury. The contract enforces its
///         own cadence on-chain, so no off-chain scheduler or admin trigger
///         is required.
/// @dev Needs `BURNER_ROLE` on BBACoin, and the treasury must keep BBACoin
///      approved for at least the next burn amount - see BBACoin.burnSupply's
///      two-key (role + allowance) gating. If the treasury is under-approved
///      or under-funded when a quarter rolls over, `executeBurn` simply
///      reverts and can be retried once the treasury is topped up; the 90-day
///      clock does not advance on a revert.
contract QuarterlyBurner is AccessControl {
    // --- State ---

    IBBACoin public bbaToken;

    uint256 public constant BURN_INTERVAL = 90 days;
    uint256 public constant BURN_RATE_BPS = 369; // 3.69%
    uint256 private constant BPS_DENOMINATOR = 10000;

    // 0 at deployment, so the first burn is available immediately; every
    // burn after that is locked out until BURN_INTERVAL has elapsed.
    uint256 public lastBurnTimestamp;

    // --- Events ---

    event BbaTokenUpdated(address indexed previous, address indexed current);
    event QuarterlyBurnExecuted(
        uint256 indexed timestamp,
        uint256 totalSupply,
        uint256 amountBurned
    );

    constructor(address _bbaToken) {
        require(_bbaToken != address(0), "Burner: token is zero");
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
        bbaToken = IBBACoin(_bbaToken);
    }

    // --- Execution ---

    /// @notice Burn 3.69% of BBA's current total supply. Permissionless,
    ///         but only once every 90 days.
    function executeBurn() external {
        require(
            block.timestamp >= lastBurnTimestamp + BURN_INTERVAL,
            "Burner: too soon"
        );

        // Effects before the external call, so the window can't be re-entered.
        lastBurnTimestamp = block.timestamp;

        uint256 supply = bbaToken.totalSupply();
        uint256 burnAmount = previewBurn();
        require(burnAmount > 0, "Burner: nothing to burn");

        bbaToken.burnSupply(burnAmount);

        emit QuarterlyBurnExecuted(block.timestamp, supply, burnAmount);
    }

    // --- Views ---

    /// @notice What executeBurn would burn right now; the treasury needs at
    ///         least this much balance and allowance.
    function previewBurn() public view returns (uint256) {
        return (bbaToken.totalSupply() * BURN_RATE_BPS) / BPS_DENOMINATOR;
    }

    /// @notice Timestamp at which the next `executeBurn` call will succeed.
    function nextBurnAvailableAt() external view returns (uint256) {
        return lastBurnTimestamp + BURN_INTERVAL;
    }

    // --- Admin ---

    function setBbaToken(address _bbaToken) external onlyRole(DEFAULT_ADMIN_ROLE) {
        require(_bbaToken != address(0), "Burner: token is zero");
        emit BbaTokenUpdated(address(bbaToken), _bbaToken);
        bbaToken = IBBACoin(_bbaToken);
    }
}
          

@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

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

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
          

@openzeppelin/contracts/interfaces/IERC1363.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
          

@openzeppelin/contracts/interfaces/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";
          

@openzeppelin/contracts/access/AccessControl.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.6.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /// @inheritdoc ERC165
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
          

@openzeppelin/contracts/utils/Context.sol

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

@openzeppelin/contracts/utils/cryptography/Hashes.sol

// 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)
        }
    }
}
          

@openzeppelin/contracts/utils/StorageSlot.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC-1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {SlotDerivation}.
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct Int256Slot {
        int256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Int256Slot` with member `value` located at `slot`.
     */
    function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns a `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }
}
          

@openzeppelin/contracts/access/IAccessControl.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/IAccessControl.sol)

pragma solidity >=0.8.4;

/**
 * @dev External interface of AccessControl declared to support ERC-165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted to signal this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
     * Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}
          

@openzeppelin/contracts/token/ERC20/ERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC-20
 * applications.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * Both values are immutable: they can only be set once during construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /// @inheritdoc IERC20
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /// @inheritdoc IERC20
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /// @inheritdoc IERC20
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Skips emitting an {Approval} event indicating an allowance update. This is not
     * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation sets the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the `transferFrom` operation can force the flag to
     * true using the following override:
     *
     * ```solidity
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner`'s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance < type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}
          

contracts/interfaces/IBBACoin.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @title IBBACoin
/// @notice Minimal interface the rest of the ecosystem needs against BBACoin:
///         BidToken mints BBA rewards, QuarterlyBurner reads supply and burns
///         it out of the treasury.
interface IBBACoin is IERC20 {
    function mint(address to, uint256 amount) external;
    function mintableRemaining() external view returns (uint256);
    function burnSupply(uint256 amount) external;
}
          

@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        if (!_safeTransfer(token, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        if (!_safeTransferFrom(token, from, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _safeTransfer(token, to, value, false);
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _safeTransferFrom(token, from, to, value, false);
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        if (!_safeApprove(token, spender, value, false)) {
            if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
            if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity `token.transfer(to, value)` call, relaxing the requirement on the return value: the
     * return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.transfer.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }

    /**
     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, relaxing the requirement on the return
     * value: the return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param from The sender of the tokens
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value,
        bool bubble
    ) private returns (bool success) {
        bytes4 selector = IERC20.transferFrom.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(from, shr(96, not(0))))
            mstore(0x24, and(to, shr(96, not(0))))
            mstore(0x44, value)
            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
            mstore(0x60, 0)
        }
    }

    /**
     * @dev Imitates a Solidity `token.approve(spender, value)` call, relaxing the requirement on the return value:
     * the return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param spender The spender of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.approve.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(spender, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }
}
          

@openzeppelin/contracts/utils/cryptography/MerkleProof.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.6.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();
        }

        if (proofFlagsLen > 0) {
            // 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 (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();
        }

        if (proofFlagsLen > 0) {
            // 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 (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();
        }

        if (proofFlagsLen > 0) {
            // 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 (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();
        }

        if (proofFlagsLen > 0) {
            // 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 (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }
}
          

@openzeppelin/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
          

@openzeppelin/contracts/interfaces/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";
          

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

// 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);
}
          

@openzeppelin/contracts/utils/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 *
 * IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced
 * by the {ReentrancyGuardTransient} variant in v6.0.
 *
 * @custom:stateless
 */
abstract contract ReentrancyGuard {
    using StorageSlot for bytes32;

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant REENTRANCY_GUARD_STORAGE =
        0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

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

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
    }

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

    /**
     * @dev A `view` only version of {nonReentrant}. Use to block view functions
     * from being called, preventing reading from inconsistent contract state.
     *
     * CAUTION: This is a "view" modifier and does not change the reentrancy
     * status. Use it only on view functions. For payable or non-payable functions,
     * use the standard {nonReentrant} modifier instead.
     */
    modifier nonReentrantView() {
        _nonReentrantBeforeView();
        _;
    }

    function _nonReentrantBeforeView() private view {
        if (_reentrancyGuardEntered()) {
            revert ReentrancyGuardReentrantCall();
        }
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        _nonReentrantBeforeView();

        // Any calls to nonReentrant after this point will fail
        _reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;
    }

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;
    }

    function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
        return REENTRANCY_GUARD_STORAGE;
    }
}
          

Compiler Settings

{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata"],"":["ast"]}},"optimizer":{"runs":200,"enabled":true},"evmVersion":"paris"}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_bbaToken","internalType":"address"},{"type":"address","name":"_bidToken","internalType":"address"},{"type":"address","name":"_commissionTree","internalType":"address"}]},{"type":"error","name":"AccessControlBadConfirmation","inputs":[]},{"type":"error","name":"AccessControlUnauthorizedAccount","inputs":[{"type":"address","name":"account","internalType":"address"},{"type":"bytes32","name":"neededRole","internalType":"bytes32"}]},{"type":"error","name":"ReentrancyGuardReentrantCall","inputs":[]},{"type":"error","name":"SafeERC20FailedOperation","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"event","name":"BbaTokenUpdated","inputs":[{"type":"address","name":"previous","internalType":"address","indexed":true},{"type":"address","name":"current","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"BidTokenUpdated","inputs":[{"type":"address","name":"previous","internalType":"address","indexed":true},{"type":"address","name":"current","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"CommissionTreeUpdated","inputs":[{"type":"address","name":"previous","internalType":"address","indexed":true},{"type":"address","name":"current","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"DailyRootUpdated","inputs":[{"type":"uint256","name":"epoch","internalType":"uint256","indexed":true},{"type":"bytes32","name":"newRoot","internalType":"bytes32","indexed":false},{"type":"uint256","name":"epochTotal","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"ERC20Rescued","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"EpochExpired","inputs":[{"type":"uint256","name":"epoch","internalType":"uint256","indexed":true},{"type":"uint256","name":"released","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"LockDurationUpdated","inputs":[{"type":"uint256","name":"newDuration","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"NativeRescued","inputs":[{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RevenueClaimed","inputs":[{"type":"uint256","name":"epoch","internalType":"uint256","indexed":true},{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Staked","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Unstaked","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"CLAIM_WINDOW","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"MAX_LOCK_DURATION","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC20"}],"name":"bbaToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IBidToken"}],"name":"bidToken","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"claimDailyRevenue","inputs":[{"type":"uint256","name":"epoch","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"bytes32[]","name":"merkleProof","internalType":"bytes32[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ICommissionTree"}],"name":"commissionTree","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"currentEpoch","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"epochPostedAt","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"epochRoot","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"epochUnclaimed","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"expireEpoch","inputs":[{"type":"uint256","name":"epoch","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasClaimed","inputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lockDuration","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"callerConfirmation","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"rescueERC20","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"rescueNative","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setBbaToken","inputs":[{"type":"address","name":"_bbaToken","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setBidToken","inputs":[{"type":"address","name":"_bidToken","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCommissionTree","inputs":[{"type":"address","name":"_commissionTree","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLockDuration","inputs":[{"type":"uint256","name":"_duration","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"stake","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"stakedBalance","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalReserved","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalStaked","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"unlockTime","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unstake","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateDailyRoot","inputs":[{"type":"bytes32","name":"newRoot","internalType":"bytes32"},{"type":"uint256","name":"epochTotal","internalType":"uint256"}]},{"type":"receive","stateMutability":"payable"}]
              

Contract Creation Code

0x608060405262278d006006553480156200001857600080fd5b5060405162002162380380620021628339810160408190526200003b9162000272565b60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00556001600160a01b038316620000b05760405162461bcd60e51b81526020600482015260126024820152715661756c743a20626261206973207a65726f60701b60448201526064015b60405180910390fd5b6001600160a01b038216620000fd5760405162461bcd60e51b81526020600482015260126024820152715661756c743a20626964206973207a65726f60701b6044820152606401620000a7565b6001600160a01b038116620001555760405162461bcd60e51b815260206004820152601360248201527f5661756c743a2074726565206973207a65726f000000000000000000000000006044820152606401620000a7565b62000162600033620001a6565b50600180546001600160a01b039485166001600160a01b031991821617909155600280549385169382169390931790925560038054919093169116179055620002bc565b6000828152602081815260408083206001600160a01b038516845290915281205460ff166200024b576000838152602081815260408083206001600160a01b03861684529091529020805460ff19166001179055620002023390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016200024f565b5060005b92915050565b80516001600160a01b03811681146200026d57600080fd5b919050565b6000806000606084860312156200028857600080fd5b620002938462000255565b9250620002a36020850162000255565b9150620002b36040850162000255565b90509250925092565b611e9680620002cc6000396000f3fe6080604052600436106101f25760003560e01c8063873f6f9e1161010d578063b2118a8d116100a0578063dfafd4fd1161006f578063dfafd4fd146105cb578063e02068e114610603578063f6ac848814610623578063f72701fe14610643578063fbe93b781461066357600080fd5b8063b2118a8d14610555578063b997d4dd14610575578063c71b0e1c14610595578063d547741f146105ab57600080fd5b80639f34fc80116100dc5780639f34fc80146104e9578063a217fddf14610500578063a6683c6514610515578063a694fc3a1461053557600080fd5b8063873f6f9e146104415780638925fd121461047c5780638c6b0dea146104a957806391d14854146104c957600080fd5b806336568abe11610185578063602172671161015457806360217267146103bb57806376671808146103e857806376b467b7146103fe578063817b1cd21461042b57600080fd5b806336568abe146103435780634eb665af146103635780634f1bfc9e14610383578063501ee1261461039b57600080fd5b80631ba7573d116101c15780631ba7573d146102a6578063248a9ca3146102d35780632e17de78146103035780632f2ff15d1461032357600080fd5b806301ffc9a7146101fe57806304554443146102335780631291f79d14610257578063171c6e261461027957600080fd5b366101f957005b600080fd5b34801561020a57600080fd5b5061021e610219366004611be9565b610683565b60405190151581526020015b60405180910390f35b34801561023f57600080fd5b5061024960065481565b60405190815260200161022a565b34801561026357600080fd5b50610277610272366004611c2f565b6106ba565b005b34801561028557600080fd5b50610249610294366004611c59565b600c6020526000908152604090205481565b3480156102b257600080fd5b506102496102c1366004611c59565b600a6020526000908152604090205481565b3480156102df57600080fd5b506102496102ee366004611c59565b60009081526020819052604090206001015490565b34801561030f57600080fd5b5061027761031e366004611c59565b61085c565b34801561032f57600080fd5b5061027761033e366004611c72565b610a04565b34801561034f57600080fd5b5061027761035e366004611c72565b610a2f565b34801561036f57600080fd5b5061027761037e366004611c59565b610a67565b34801561038f57600080fd5b506102496301e1338081565b3480156103a757600080fd5b506102776103b6366004611c9e565b610af9565b3480156103c757600080fd5b506102496103d6366004611c9e565b60046020526000908152604090205481565b3480156103f457600080fd5b5061024960085481565b34801561040a57600080fd5b50610249610419366004611c9e565b60076020526000908152604090205481565b34801561043757600080fd5b5061024960055481565b34801561044d57600080fd5b5061021e61045c366004611c72565b600d60209081526000928352604080842090915290825290205460ff1681565b34801561048857600080fd5b50610249610497366004611c59565b60096020526000908152604090205481565b3480156104b557600080fd5b506102776104c4366004611cb9565b610bac565b3480156104d557600080fd5b5061021e6104e4366004611c72565b611005565b3480156104f557600080fd5b506102496276a70081565b34801561050c57600080fd5b50610249600081565b34801561052157600080fd5b50610277610530366004611c9e565b61102e565b34801561054157600080fd5b50610277610550366004611c59565b611131565b34801561056157600080fd5b50610277610570366004611d3c565b61133d565b34801561058157600080fd5b50610277610590366004611c9e565b6114de565b3480156105a157600080fd5b50610249600b5481565b3480156105b757600080fd5b506102776105c6366004611c72565b611592565b3480156105d757600080fd5b506002546105eb906001600160a01b031681565b6040516001600160a01b03909116815260200161022a565b34801561060f57600080fd5b506003546105eb906001600160a01b031681565b34801561062f57600080fd5b5061027761063e366004611c59565b6115b7565b34801561064f57600080fd5b5061027761065e366004611d78565b611730565b34801561066f57600080fd5b506001546105eb906001600160a01b031681565b60006001600160e01b03198216637965db0b60e01b14806106b457506301ffc9a760e01b6001600160e01b03198316145b92915050565b60006106c58161187f565b6001600160a01b0383166107145760405162461bcd60e51b81526020600482015260116024820152705661756c743a20746f206973207a65726f60781b60448201526064015b60405180910390fd5b600b546107219047611db0565b8211156107705760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a206578636565647320504c5320737572706c7573000000000000604482015260640161070b565b6000836001600160a01b03168360405160006040518083038185875af1925050503d80600081146107bd576040519150601f19603f3d011682016040523d82523d6000602084013e6107c2565b606091505b50509050806108135760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a20504c53207472616e73666572206661696c6564000000000000604482015260640161070b565b836001600160a01b03167fe3eb98b7fe2a0c1d490b92af73eeae611e9b00ab3c3f70b20bd7bb43f67a0f438460405161084e91815260200190565b60405180910390a250505050565b610864611889565b600081116108ac5760405162461bcd60e51b81526020600482015260156024820152745661756c743a20616d6f756e74206973207a65726f60581b604482015260640161070b565b3360009081526004602052604090205481111561090b5760405162461bcd60e51b815260206004820152601960248201527f5661756c743a20696e73756666696369656e74207374616b6500000000000000604482015260640161070b565b336000908152600760205260409020544210156109605760405162461bcd60e51b815260206004820152601360248201527215985d5b1d0e881cdd185ad9481b1bd8dad959606a1b604482015260640161070b565b336000908152600460205260408120805483929061097f908490611db0565b9250508190555080600560008282546109989190611db0565b90915550506001546109b4906001600160a01b031633836118a5565b60405181815233907f0f5bb82176feb1b5e747e28471aa92156a04d9f3ab9f45f28e2d704232b93f75906020015b60405180910390a2610a016001600080516020611e4183398151915255565b50565b600082815260208190526040902060010154610a1f8161187f565b610a2983836118da565b50505050565b6001600160a01b0381163314610a585760405163334bd91960e11b815260040160405180910390fd5b610a62828261196c565b505050565b6000610a728161187f565b6301e13380821115610abd5760405162461bcd60e51b81526020600482015260146024820152735661756c743a206c6f636b20746f6f206c6f6e6760601b604482015260640161070b565b60068290556040518281527f3e062f634a950eae456fa5f8fb53a4f59f55039983bd73df7a34a313b75443d49060200160405180910390a15050565b6000610b048161187f565b6001600160a01b038216610b4f5760405162461bcd60e51b81526020600482015260126024820152715661756c743a20626964206973207a65726f60701b604482015260640161070b565b6002546040516001600160a01b038085169216907f3d95ddbd62e70d2b2604c43cb7a4f582291d1d790e813f0ea997adc4a13d3ca990600090a350600280546001600160a01b0319166001600160a01b0392909216919091179055565b610bb4611889565b8315801590610bc557506008548411155b610c045760405162461bcd60e51b815260206004820152601060248201526f0acc2ead8e87440c4c2c840cae0dec6d60831b604482015260640161070b565b6000848152600c6020526040902054610c21906276a70090611dc3565b4210610c665760405162461bcd60e51b815260206004820152601460248201527315985d5b1d0e88195c1bd8da08195e1c1a5c995960621b604482015260640161070b565b600254604051633e02810f60e01b81523360048201526001600160a01b0390911690633e02810f90602401602060405180830381865afa158015610cae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd29190611dd6565b610d155760405162461bcd60e51b815260206004820152601460248201527315985d5b1d0e881b9bdd081858dd1a5d985d195960621b604482015260640161070b565b6000848152600d6020908152604080832033845290915290205460ff1615610d785760405162461bcd60e51b815260206004820152601660248201527515985d5b1d0e88185b1c9958591e4818db185a5b595960521b604482015260640161070b565b6040805146602082015230918101919091526060810185905233608082015260a0810184905260009060c00160408051601f1981840301815282825280516020918201209083015201604051602081830303815290604052805190602001209050610e2483838080602002602001604051908101604052809392919081815260200183836020028082843760009201829052508a81526009602052604090205492508591506119d79050565b610e635760405162461bcd60e51b815260206004820152601060248201526f2b30bab63a1d103130b210383937b7b360811b604482015260640161070b565b6000858152600a6020526040902054841115610ec15760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a20657863656564732065706f636820746f74616c000000000000604482015260640161070b565b6000858152600d602090815260408083203384528252808320805460ff19166001179055878352600a90915281208054869290610eff908490611db0565b9250508190555083600b6000828254610f189190611db0565b9091555050604051600090339086908381818185875af1925050503d8060008114610f5f576040519150601f19603f3d011682016040523d82523d6000602084013e610f64565b606091505b5050905080610fb55760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a20504c53207472616e73666572206661696c6564000000000000604482015260640161070b565b604051858152339087907fb9e8470097faa00e83252475f2ee4b69007b0bb2405268ebec248676998a21b39060200160405180910390a35050610a296001600080516020611e4183398151915255565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60006110398161187f565b6001600160a01b0382166110845760405162461bcd60e51b81526020600482015260126024820152715661756c743a20626261206973207a65726f60701b604482015260640161070b565b600554156110d45760405162461bcd60e51b815260206004820152601960248201527f5661756c743a207374616b6573206f75747374616e64696e6700000000000000604482015260640161070b565b6001546040516001600160a01b038085169216907fbf98f1ee7301f79fde742c95d928a6cee1cb5b1145b8b630ae0013c7fe508ac490600090a350600180546001600160a01b0319166001600160a01b0392909216919091179055565b611139611889565b600081116111815760405162461bcd60e51b81526020600482015260156024820152745661756c743a20616d6f756e74206973207a65726f60581b604482015260640161070b565b600254604051633e02810f60e01b81523360048201526001600160a01b0390911690633e02810f90602401602060405180830381865afa1580156111c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ed9190611dd6565b6112305760405162461bcd60e51b815260206004820152601460248201527315985d5b1d0e881b9bdd081858dd1a5d985d195960621b604482015260640161070b565b336000908152600460205260408120805483929061124f908490611dc3565b9250508190555080600560008282546112689190611dc3565b909155505060065461127a9042611dc3565b336000818152600760205260409020919091556001546112a7916001600160a01b039091169030846119ed565b6003546040516375e4513160e11b8152336004820152602481018390526001600160a01b039091169063ebc8a26290604401600060405180830381600087803b1580156112f357600080fd5b505af1158015611307573d6000803e3d6000fd5b50506040518381523392507f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d91506020016109e2565b60006113488161187f565b6001600160a01b0383166113925760405162461bcd60e51b81526020600482015260116024820152705661756c743a20746f206973207a65726f60781b604482015260640161070b565b6001546001600160a01b0390811690851603611477576005546001546040516370a0823160e01b8152306004820152600092916001600160a01b0316906370a0823190602401602060405180830381865afa1580156113f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114199190611df8565b6114239190611db0565b9050808311156114755760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a20657863656564732042424120737572706c7573000000000000604482015260640161070b565b505b61148b6001600160a01b03851684846118a5565b826001600160a01b0316846001600160a01b03167f8bbfbb5d7fcacf6fc74005cdede0635561638507f576c95f7f294c22141be2e5846040516114d091815260200190565b60405180910390a350505050565b60006114e98161187f565b6001600160a01b0382166115355760405162461bcd60e51b81526020600482015260136024820152725661756c743a2074726565206973207a65726f60681b604482015260640161070b565b6003546040516001600160a01b038085169216907f939f6e7ad69bb30fa12cff123013a784ddc4c97df163f88ae40f6d3ee468c26590600090a350600380546001600160a01b0319166001600160a01b0392909216919091179055565b6000828152602081905260409020600101546115ad8161187f565b610a29838361196c565b80158015906115c857506008548111155b6116075760405162461bcd60e51b815260206004820152601060248201526f0acc2ead8e87440c4c2c840cae0dec6d60831b604482015260640161070b565b6000818152600c6020526040902054611624906276a70090611dc3565b4210156116735760405162461bcd60e51b815260206004820152601760248201527f5661756c743a2065706f6368207374696c6c206f70656e000000000000000000604482015260640161070b565b6000818152600a6020526040902054806116cf5760405162461bcd60e51b815260206004820152601960248201527f5661756c743a206e6f7468696e6720746f2072656c6561736500000000000000604482015260640161070b565b6000828152600a60205260408120819055600b80548392906116f2908490611db0565b909155505060405181815282907f8007930b6abf1152af6b6be889431704b742c5ce10536629325e8ee97c9606d19060200160405180910390a25050565b600061173b8161187f565b8261177e5760405162461bcd60e51b81526020600482015260136024820152725661756c743a20726f6f74206973207a65726f60681b604482015260640161070b565b81600b5461178c9190611dc3565b4710156117db5760405162461bcd60e51b815260206004820152601860248201527f5661756c743a20756e64657266756e6465642065706f63680000000000000000604482015260640161070b565b6001600860008282546117ee9190611dc3565b909155505060088054600090815260096020908152604080832087905583548352600a825280832086905592548252600c9052908120429055600b8054849290611839908490611dc3565b909155505060085460408051858152602081018590527fff973aeb41f10cade7d8d4089848d0b109e4be3dd3d7a0a842c714246a070ea4910160405180910390a2505050565b610a018133611a23565b611891611a60565b6002600080516020611e4183398151915255565b6118b28383836001611a92565b610a6257604051635274afe760e01b81526001600160a01b038416600482015260240161070b565b60006118e68383611005565b611964576000838152602081815260408083206001600160a01b03861684529091529020805460ff1916600117905561191c3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016106b4565b5060006106b4565b60006119788383611005565b15611964576000838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45060016106b4565b6000826119e48584611af8565b14949350505050565b6119fb848484846001611b45565b610a2957604051635274afe760e01b81526001600160a01b038516600482015260240161070b565b611a2d8282611005565b611a5c5760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161070b565b5050565b600080516020611e4183398151915254600203611a9057604051633ee5aeb560e01b815260040160405180910390fd5b565b60405163a9059cbb60e01b60008181526001600160a01b038616600452602485905291602083604481808b5af192506001600051148316611aec578383151615611adf573d6000823e3d81fd5b6000873b113d1516831692505b60405250949350505050565b600081815b8451811015611b3d57611b2982868381518110611b1c57611b1c611e11565b6020026020010151611bb7565b915080611b3581611e27565b915050611afd565b509392505050565b6040516323b872dd60e01b60008181526001600160a01b038781166004528616602452604485905291602083606481808c5af192506001600051148316611ba5578383151615611b98573d6000823e3d81fd5b6000883b113d1516831692505b60405250600060605295945050505050565b6000818310611bd3576000828152602084905260409020611be2565b60008381526020839052604090205b9392505050565b600060208284031215611bfb57600080fd5b81356001600160e01b031981168114611be257600080fd5b80356001600160a01b0381168114611c2a57600080fd5b919050565b60008060408385031215611c4257600080fd5b611c4b83611c13565b946020939093013593505050565b600060208284031215611c6b57600080fd5b5035919050565b60008060408385031215611c8557600080fd5b82359150611c9560208401611c13565b90509250929050565b600060208284031215611cb057600080fd5b611be282611c13565b60008060008060608587031215611ccf57600080fd5b8435935060208501359250604085013567ffffffffffffffff80821115611cf557600080fd5b818701915087601f830112611d0957600080fd5b813581811115611d1857600080fd5b8860208260051b8501011115611d2d57600080fd5b95989497505060200194505050565b600080600060608486031215611d5157600080fd5b611d5a84611c13565b9250611d6860208501611c13565b9150604084013590509250925092565b60008060408385031215611d8b57600080fd5b50508035926020909101359150565b634e487b7160e01b600052601160045260246000fd5b818103818111156106b4576106b4611d9a565b808201808211156106b4576106b4611d9a565b600060208284031215611de857600080fd5b81518015158114611be257600080fd5b600060208284031215611e0a57600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b600060018201611e3957611e39611d9a565b506001019056fe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220ac9fa1514890dbeb9510d17063cbbf8f3a2baf9612d3cf7b4c1473ce6c61354e64736f6c63430008140033000000000000000000000000726f6d4ed3b7842ba27e54ed7f198269bc0b2558000000000000000000000000e84a941fe9da6eb049aed191e3d780f5e7b8f3ab000000000000000000000000ea7e02c247418107a97f430538148d23e98160c2

Deployed ByteCode

0x6080604052600436106101f25760003560e01c8063873f6f9e1161010d578063b2118a8d116100a0578063dfafd4fd1161006f578063dfafd4fd146105cb578063e02068e114610603578063f6ac848814610623578063f72701fe14610643578063fbe93b781461066357600080fd5b8063b2118a8d14610555578063b997d4dd14610575578063c71b0e1c14610595578063d547741f146105ab57600080fd5b80639f34fc80116100dc5780639f34fc80146104e9578063a217fddf14610500578063a6683c6514610515578063a694fc3a1461053557600080fd5b8063873f6f9e146104415780638925fd121461047c5780638c6b0dea146104a957806391d14854146104c957600080fd5b806336568abe11610185578063602172671161015457806360217267146103bb57806376671808146103e857806376b467b7146103fe578063817b1cd21461042b57600080fd5b806336568abe146103435780634eb665af146103635780634f1bfc9e14610383578063501ee1261461039b57600080fd5b80631ba7573d116101c15780631ba7573d146102a6578063248a9ca3146102d35780632e17de78146103035780632f2ff15d1461032357600080fd5b806301ffc9a7146101fe57806304554443146102335780631291f79d14610257578063171c6e261461027957600080fd5b366101f957005b600080fd5b34801561020a57600080fd5b5061021e610219366004611be9565b610683565b60405190151581526020015b60405180910390f35b34801561023f57600080fd5b5061024960065481565b60405190815260200161022a565b34801561026357600080fd5b50610277610272366004611c2f565b6106ba565b005b34801561028557600080fd5b50610249610294366004611c59565b600c6020526000908152604090205481565b3480156102b257600080fd5b506102496102c1366004611c59565b600a6020526000908152604090205481565b3480156102df57600080fd5b506102496102ee366004611c59565b60009081526020819052604090206001015490565b34801561030f57600080fd5b5061027761031e366004611c59565b61085c565b34801561032f57600080fd5b5061027761033e366004611c72565b610a04565b34801561034f57600080fd5b5061027761035e366004611c72565b610a2f565b34801561036f57600080fd5b5061027761037e366004611c59565b610a67565b34801561038f57600080fd5b506102496301e1338081565b3480156103a757600080fd5b506102776103b6366004611c9e565b610af9565b3480156103c757600080fd5b506102496103d6366004611c9e565b60046020526000908152604090205481565b3480156103f457600080fd5b5061024960085481565b34801561040a57600080fd5b50610249610419366004611c9e565b60076020526000908152604090205481565b34801561043757600080fd5b5061024960055481565b34801561044d57600080fd5b5061021e61045c366004611c72565b600d60209081526000928352604080842090915290825290205460ff1681565b34801561048857600080fd5b50610249610497366004611c59565b60096020526000908152604090205481565b3480156104b557600080fd5b506102776104c4366004611cb9565b610bac565b3480156104d557600080fd5b5061021e6104e4366004611c72565b611005565b3480156104f557600080fd5b506102496276a70081565b34801561050c57600080fd5b50610249600081565b34801561052157600080fd5b50610277610530366004611c9e565b61102e565b34801561054157600080fd5b50610277610550366004611c59565b611131565b34801561056157600080fd5b50610277610570366004611d3c565b61133d565b34801561058157600080fd5b50610277610590366004611c9e565b6114de565b3480156105a157600080fd5b50610249600b5481565b3480156105b757600080fd5b506102776105c6366004611c72565b611592565b3480156105d757600080fd5b506002546105eb906001600160a01b031681565b6040516001600160a01b03909116815260200161022a565b34801561060f57600080fd5b506003546105eb906001600160a01b031681565b34801561062f57600080fd5b5061027761063e366004611c59565b6115b7565b34801561064f57600080fd5b5061027761065e366004611d78565b611730565b34801561066f57600080fd5b506001546105eb906001600160a01b031681565b60006001600160e01b03198216637965db0b60e01b14806106b457506301ffc9a760e01b6001600160e01b03198316145b92915050565b60006106c58161187f565b6001600160a01b0383166107145760405162461bcd60e51b81526020600482015260116024820152705661756c743a20746f206973207a65726f60781b60448201526064015b60405180910390fd5b600b546107219047611db0565b8211156107705760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a206578636565647320504c5320737572706c7573000000000000604482015260640161070b565b6000836001600160a01b03168360405160006040518083038185875af1925050503d80600081146107bd576040519150601f19603f3d011682016040523d82523d6000602084013e6107c2565b606091505b50509050806108135760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a20504c53207472616e73666572206661696c6564000000000000604482015260640161070b565b836001600160a01b03167fe3eb98b7fe2a0c1d490b92af73eeae611e9b00ab3c3f70b20bd7bb43f67a0f438460405161084e91815260200190565b60405180910390a250505050565b610864611889565b600081116108ac5760405162461bcd60e51b81526020600482015260156024820152745661756c743a20616d6f756e74206973207a65726f60581b604482015260640161070b565b3360009081526004602052604090205481111561090b5760405162461bcd60e51b815260206004820152601960248201527f5661756c743a20696e73756666696369656e74207374616b6500000000000000604482015260640161070b565b336000908152600760205260409020544210156109605760405162461bcd60e51b815260206004820152601360248201527215985d5b1d0e881cdd185ad9481b1bd8dad959606a1b604482015260640161070b565b336000908152600460205260408120805483929061097f908490611db0565b9250508190555080600560008282546109989190611db0565b90915550506001546109b4906001600160a01b031633836118a5565b60405181815233907f0f5bb82176feb1b5e747e28471aa92156a04d9f3ab9f45f28e2d704232b93f75906020015b60405180910390a2610a016001600080516020611e4183398151915255565b50565b600082815260208190526040902060010154610a1f8161187f565b610a2983836118da565b50505050565b6001600160a01b0381163314610a585760405163334bd91960e11b815260040160405180910390fd5b610a62828261196c565b505050565b6000610a728161187f565b6301e13380821115610abd5760405162461bcd60e51b81526020600482015260146024820152735661756c743a206c6f636b20746f6f206c6f6e6760601b604482015260640161070b565b60068290556040518281527f3e062f634a950eae456fa5f8fb53a4f59f55039983bd73df7a34a313b75443d49060200160405180910390a15050565b6000610b048161187f565b6001600160a01b038216610b4f5760405162461bcd60e51b81526020600482015260126024820152715661756c743a20626964206973207a65726f60701b604482015260640161070b565b6002546040516001600160a01b038085169216907f3d95ddbd62e70d2b2604c43cb7a4f582291d1d790e813f0ea997adc4a13d3ca990600090a350600280546001600160a01b0319166001600160a01b0392909216919091179055565b610bb4611889565b8315801590610bc557506008548411155b610c045760405162461bcd60e51b815260206004820152601060248201526f0acc2ead8e87440c4c2c840cae0dec6d60831b604482015260640161070b565b6000848152600c6020526040902054610c21906276a70090611dc3565b4210610c665760405162461bcd60e51b815260206004820152601460248201527315985d5b1d0e88195c1bd8da08195e1c1a5c995960621b604482015260640161070b565b600254604051633e02810f60e01b81523360048201526001600160a01b0390911690633e02810f90602401602060405180830381865afa158015610cae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd29190611dd6565b610d155760405162461bcd60e51b815260206004820152601460248201527315985d5b1d0e881b9bdd081858dd1a5d985d195960621b604482015260640161070b565b6000848152600d6020908152604080832033845290915290205460ff1615610d785760405162461bcd60e51b815260206004820152601660248201527515985d5b1d0e88185b1c9958591e4818db185a5b595960521b604482015260640161070b565b6040805146602082015230918101919091526060810185905233608082015260a0810184905260009060c00160408051601f1981840301815282825280516020918201209083015201604051602081830303815290604052805190602001209050610e2483838080602002602001604051908101604052809392919081815260200183836020028082843760009201829052508a81526009602052604090205492508591506119d79050565b610e635760405162461bcd60e51b815260206004820152601060248201526f2b30bab63a1d103130b210383937b7b360811b604482015260640161070b565b6000858152600a6020526040902054841115610ec15760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a20657863656564732065706f636820746f74616c000000000000604482015260640161070b565b6000858152600d602090815260408083203384528252808320805460ff19166001179055878352600a90915281208054869290610eff908490611db0565b9250508190555083600b6000828254610f189190611db0565b9091555050604051600090339086908381818185875af1925050503d8060008114610f5f576040519150601f19603f3d011682016040523d82523d6000602084013e610f64565b606091505b5050905080610fb55760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a20504c53207472616e73666572206661696c6564000000000000604482015260640161070b565b604051858152339087907fb9e8470097faa00e83252475f2ee4b69007b0bb2405268ebec248676998a21b39060200160405180910390a35050610a296001600080516020611e4183398151915255565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60006110398161187f565b6001600160a01b0382166110845760405162461bcd60e51b81526020600482015260126024820152715661756c743a20626261206973207a65726f60701b604482015260640161070b565b600554156110d45760405162461bcd60e51b815260206004820152601960248201527f5661756c743a207374616b6573206f75747374616e64696e6700000000000000604482015260640161070b565b6001546040516001600160a01b038085169216907fbf98f1ee7301f79fde742c95d928a6cee1cb5b1145b8b630ae0013c7fe508ac490600090a350600180546001600160a01b0319166001600160a01b0392909216919091179055565b611139611889565b600081116111815760405162461bcd60e51b81526020600482015260156024820152745661756c743a20616d6f756e74206973207a65726f60581b604482015260640161070b565b600254604051633e02810f60e01b81523360048201526001600160a01b0390911690633e02810f90602401602060405180830381865afa1580156111c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ed9190611dd6565b6112305760405162461bcd60e51b815260206004820152601460248201527315985d5b1d0e881b9bdd081858dd1a5d985d195960621b604482015260640161070b565b336000908152600460205260408120805483929061124f908490611dc3565b9250508190555080600560008282546112689190611dc3565b909155505060065461127a9042611dc3565b336000818152600760205260409020919091556001546112a7916001600160a01b039091169030846119ed565b6003546040516375e4513160e11b8152336004820152602481018390526001600160a01b039091169063ebc8a26290604401600060405180830381600087803b1580156112f357600080fd5b505af1158015611307573d6000803e3d6000fd5b50506040518381523392507f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d91506020016109e2565b60006113488161187f565b6001600160a01b0383166113925760405162461bcd60e51b81526020600482015260116024820152705661756c743a20746f206973207a65726f60781b604482015260640161070b565b6001546001600160a01b0390811690851603611477576005546001546040516370a0823160e01b8152306004820152600092916001600160a01b0316906370a0823190602401602060405180830381865afa1580156113f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114199190611df8565b6114239190611db0565b9050808311156114755760405162461bcd60e51b815260206004820152601a60248201527f5661756c743a20657863656564732042424120737572706c7573000000000000604482015260640161070b565b505b61148b6001600160a01b03851684846118a5565b826001600160a01b0316846001600160a01b03167f8bbfbb5d7fcacf6fc74005cdede0635561638507f576c95f7f294c22141be2e5846040516114d091815260200190565b60405180910390a350505050565b60006114e98161187f565b6001600160a01b0382166115355760405162461bcd60e51b81526020600482015260136024820152725661756c743a2074726565206973207a65726f60681b604482015260640161070b565b6003546040516001600160a01b038085169216907f939f6e7ad69bb30fa12cff123013a784ddc4c97df163f88ae40f6d3ee468c26590600090a350600380546001600160a01b0319166001600160a01b0392909216919091179055565b6000828152602081905260409020600101546115ad8161187f565b610a29838361196c565b80158015906115c857506008548111155b6116075760405162461bcd60e51b815260206004820152601060248201526f0acc2ead8e87440c4c2c840cae0dec6d60831b604482015260640161070b565b6000818152600c6020526040902054611624906276a70090611dc3565b4210156116735760405162461bcd60e51b815260206004820152601760248201527f5661756c743a2065706f6368207374696c6c206f70656e000000000000000000604482015260640161070b565b6000818152600a6020526040902054806116cf5760405162461bcd60e51b815260206004820152601960248201527f5661756c743a206e6f7468696e6720746f2072656c6561736500000000000000604482015260640161070b565b6000828152600a60205260408120819055600b80548392906116f2908490611db0565b909155505060405181815282907f8007930b6abf1152af6b6be889431704b742c5ce10536629325e8ee97c9606d19060200160405180910390a25050565b600061173b8161187f565b8261177e5760405162461bcd60e51b81526020600482015260136024820152725661756c743a20726f6f74206973207a65726f60681b604482015260640161070b565b81600b5461178c9190611dc3565b4710156117db5760405162461bcd60e51b815260206004820152601860248201527f5661756c743a20756e64657266756e6465642065706f63680000000000000000604482015260640161070b565b6001600860008282546117ee9190611dc3565b909155505060088054600090815260096020908152604080832087905583548352600a825280832086905592548252600c9052908120429055600b8054849290611839908490611dc3565b909155505060085460408051858152602081018590527fff973aeb41f10cade7d8d4089848d0b109e4be3dd3d7a0a842c714246a070ea4910160405180910390a2505050565b610a018133611a23565b611891611a60565b6002600080516020611e4183398151915255565b6118b28383836001611a92565b610a6257604051635274afe760e01b81526001600160a01b038416600482015260240161070b565b60006118e68383611005565b611964576000838152602081815260408083206001600160a01b03861684529091529020805460ff1916600117905561191c3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016106b4565b5060006106b4565b60006119788383611005565b15611964576000838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45060016106b4565b6000826119e48584611af8565b14949350505050565b6119fb848484846001611b45565b610a2957604051635274afe760e01b81526001600160a01b038516600482015260240161070b565b611a2d8282611005565b611a5c5760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161070b565b5050565b600080516020611e4183398151915254600203611a9057604051633ee5aeb560e01b815260040160405180910390fd5b565b60405163a9059cbb60e01b60008181526001600160a01b038616600452602485905291602083604481808b5af192506001600051148316611aec578383151615611adf573d6000823e3d81fd5b6000873b113d1516831692505b60405250949350505050565b600081815b8451811015611b3d57611b2982868381518110611b1c57611b1c611e11565b6020026020010151611bb7565b915080611b3581611e27565b915050611afd565b509392505050565b6040516323b872dd60e01b60008181526001600160a01b038781166004528616602452604485905291602083606481808c5af192506001600051148316611ba5578383151615611b98573d6000823e3d81fd5b6000883b113d1516831692505b60405250600060605295945050505050565b6000818310611bd3576000828152602084905260409020611be2565b60008381526020839052604090205b9392505050565b600060208284031215611bfb57600080fd5b81356001600160e01b031981168114611be257600080fd5b80356001600160a01b0381168114611c2a57600080fd5b919050565b60008060408385031215611c4257600080fd5b611c4b83611c13565b946020939093013593505050565b600060208284031215611c6b57600080fd5b5035919050565b60008060408385031215611c8557600080fd5b82359150611c9560208401611c13565b90509250929050565b600060208284031215611cb057600080fd5b611be282611c13565b60008060008060608587031215611ccf57600080fd5b8435935060208501359250604085013567ffffffffffffffff80821115611cf557600080fd5b818701915087601f830112611d0957600080fd5b813581811115611d1857600080fd5b8860208260051b8501011115611d2d57600080fd5b95989497505060200194505050565b600080600060608486031215611d5157600080fd5b611d5a84611c13565b9250611d6860208501611c13565b9150604084013590509250925092565b60008060408385031215611d8b57600080fd5b50508035926020909101359150565b634e487b7160e01b600052601160045260246000fd5b818103818111156106b4576106b4611d9a565b808201808211156106b4576106b4611d9a565b600060208284031215611de857600080fd5b81518015158114611be257600080fd5b600060208284031215611e0a57600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b600060018201611e3957611e39611d9a565b506001019056fe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220ac9fa1514890dbeb9510d17063cbbf8f3a2baf9612d3cf7b4c1473ce6c61354e64736f6c63430008140033