ETH Price: $2,055.85 (+1.88%)
 

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Register Spirit431035552026-03-08 19:00:573 days ago1772996457IN
0xF2709ceF...32b12dFb9
0 ETH0.000001540.00676738
Register Spirit430138982026-03-06 17:12:235 days ago1772817143IN
0xF2709ceF...32b12dFb9
0 ETH0.000001050.00500015
Register Spirit430138932026-03-06 17:12:135 days ago1772817133IN
0xF2709ceF...32b12dFb9
0 ETH0.000001140.00500015
Register Spirit427811502026-03-01 7:54:0711 days ago1772351647IN
0xF2709ceF...32b12dFb9
0 ETH0.000001050.00501405
Register Spirit427811352026-03-01 7:53:3711 days ago1772351617IN
0xF2709ceF...32b12dFb9
0 ETH0.000001140.00501714
Set Metadata420653732026-02-12 18:14:5327 days ago1770920093IN
0xF2709ceF...32b12dFb9
0 ETH0.000000360.00703865
Set Metadata420652602026-02-12 18:11:0727 days ago1770919867IN
0xF2709ceF...32b12dFb9
0 ETH0.000000350.00677624
Set Metadata420652592026-02-12 18:11:0527 days ago1770919865IN
0xF2709ceF...32b12dFb9
0 ETH0.000000350.00681073
Set Metadata420652582026-02-12 18:11:0327 days ago1770919863IN
0xF2709ceF...32b12dFb9
0 ETH0.000000350.00680338
Set Metadata420652572026-02-12 18:11:0127 days ago1770919861IN
0xF2709ceF...32b12dFb9
0 ETH0.000000350.00682115
Set Agent URI420651232026-02-12 18:06:3327 days ago1770919593IN
0xF2709ceF...32b12dFb9
0 ETH0.000000550.00710798
Set Metadata420644822026-02-12 17:45:1127 days ago1770918311IN
0xF2709ceF...32b12dFb9
0 ETH0.000000490.00938444
Set Metadata420644812026-02-12 17:45:0927 days ago1770918309IN
0xF2709ceF...32b12dFb9
0 ETH0.000001780.00938444
Set Metadata420644812026-02-12 17:45:0927 days ago1770918309IN
0xF2709ceF...32b12dFb9
0 ETH0.000000490.00938444
Set Metadata420644802026-02-12 17:45:0727 days ago1770918307IN
0xF2709ceF...32b12dFb9
0 ETH0.000000490.00938444
Set Metadata420644792026-02-12 17:45:0527 days ago1770918305IN
0xF2709ceF...32b12dFb9
0 ETH0.000000490.00938444
Set Metadata420644782026-02-12 17:45:0327 days ago1770918303IN
0xF2709ceF...32b12dFb9
0 ETH0.000000490.00938444
Set Metadata420644772026-02-12 17:45:0127 days ago1770918301IN
0xF2709ceF...32b12dFb9
0 ETH0.000001780.00938444
Set Metadata420644762026-02-12 17:44:5927 days ago1770918299IN
0xF2709ceF...32b12dFb9
0 ETH0.000000490.00938444
Set Metadata420644752026-02-12 17:44:5727 days ago1770918297IN
0xF2709ceF...32b12dFb9
0 ETH0.000000490.00938444
Set Metadata420644732026-02-12 17:44:5327 days ago1770918293IN
0xF2709ceF...32b12dFb9
0 ETH0.000000490.00938444
Register Spirit419786142026-02-10 18:02:5529 days ago1770746575IN
0xF2709ceF...32b12dFb9
0 ETH0.000005050.02214544
Register Spirit416984022026-02-04 6:22:3136 days ago1770186151IN
0xF2709ceF...32b12dFb9
0 ETH0.000001040.00347412
Register Spirit416984022026-02-04 6:22:3136 days ago1770186151IN
0xF2709ceF...32b12dFb9
0 ETH0.000001040.00347412
Register Spirit416983652026-02-04 6:21:1736 days ago1770186077IN
0xF2709ceF...32b12dFb9
0 ETH0.000000860.00316632
View all transactions

Parent Transaction Hash Block From To
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
SpiritRegistry

Compiler Version
v0.8.26+commit.8a97fa7a

Optimization Enabled:
Yes with 200 runs

Other Settings:
cancun EvmVersion
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import { IERC20 } from "@openzeppelin-v5/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin-v5/contracts/token/ERC20/utils/SafeERC20.sol";

import { IERC8004IdentityRegistry } from "../interfaces/registry/IERC8004IdentityRegistry.sol";
import { ISpiritRegistry } from "../interfaces/registry/ISpiritRegistry.sol";
import { ERC8004IdentityRegistry } from "./ERC8004IdentityRegistry.sol";

/**
 * @title SpiritRegistry
 * @notice Spirit Protocol's agent registry — extends ERC-8004 Identity Registry
 *         with treasury, revenue routing, and token creation primitives.
 * @dev Implements ISpiritRegistry on top of ERC8004IdentityRegistry.
 *
 *      Integration modes:
 *      1. Native: registerSpirit() creates ERC-8004 identity + Spirit economics in one call
 *      2. Attached: attachSpirit() links an external ERC-8004 agent to Spirit economics
 */
contract SpiritRegistry is ISpiritRegistry, ERC8004IdentityRegistry {
    using SafeERC20 for IERC20;

    //      ________ __                        __
    //     / ___// //_/____  _____  __________/ /______
    //     \__ \/ __/ / ___/ / / / / ___/ __  / __/ ___/
    //    ___/ / / / / /  / /_/ / /__/ /_/ / / (__  )
    //   /____/_/ /_/_/   \__,_/\___/\__,_/_/  /____/

    /// @notice Protocol treasury address
    address public immutable override protocolTreasury;

    /// @notice Spirit config per agent
    mapping(uint256 agentId => SpiritConfig config) private _spiritConfigs;

    /// @notice Revenue config per agent
    mapping(uint256 agentId => RevenueConfig config) private _revenueConfigs;

    /// @notice Whether an agent has Spirit economics attached
    mapping(uint256 agentId => bool attached) private _spiritAttached;

    /// @notice External agent references (spiritId => ExternalAgent)
    mapping(uint256 spiritId => ExternalAgent ref) private _externalAgents;

    /// @notice NOT_TREASURY error for updateTreasury access control
    error NOT_TREASURY();

    /// @notice NOT_IMPLEMENTED error for stub functions
    error NOT_IMPLEMENTED();

    /// @notice NO_ETH_SENT error
    error NO_ETH_SENT();

    /// @notice ETH_WITH_ERC20 error
    error ETH_WITH_ERC20();

    //     ______                 __                  __
    //    / ____/___  ____  _____/ /________  _______/ /_____  _____
    //   / /   / __ \/ __ \/ ___/ __/ ___/ / / / ___/ __/ __ \/ ___/
    //  / /___/ /_/ / / / (__  ) /_/ /  / /_/ / /__/ /_/ /_/ / /
    //  \____/\____/_/ /_/____/\__/_/   \__,_/\___/\__/\____/_/

    /**
     * @param protocolTreasury_ Address of the Spirit Protocol treasury
     */
    constructor(address protocolTreasury_) ERC8004IdentityRegistry("Spirit Registry", "SPIRIT-ID") {
        protocolTreasury = protocolTreasury_;
    }

    //      ______     __                        __   ______                 __  _
    //     / ____/  __/ /____  _________  ____ _/ /  / ____/_  ______  _____/ /_(_)___  ____  _____
    //    / __/ | |/_/ __/ _ \/ ___/ __ \/ __ `/ /  / /_  / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
    //   / /____>  </ /_/  __/ /  / / / / /_/ / /  / __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__  )
    //  /_____/_/|_|\__/\___/_/  /_/ /_/\__,_/_/  /_/    \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/

    /// @inheritdoc ISpiritRegistry
    function registerSpirit(
        string calldata agentURI_,
        address artist,
        address platform,
        address[] calldata, /* treasuryOwners — ignored in MVP */
        uint256 /* treasuryThreshold — ignored in MVP */
    ) external returns (uint256 agentId) {
        // Register ERC-8004 identity with artist as owner
        agentId = _register(artist, agentURI_);

        // Set agentWallet = artist (treasury) via internal call
        _setAgentWallet(agentId, artist);

        // Store Spirit config
        _spiritConfigs[agentId] = SpiritConfig({
            treasury: artist,
            childToken: address(0),
            stakingPool: address(0),
            lpPosition: address(0),
            artist: artist,
            platform: platform,
            createdAt: block.timestamp,
            hasToken: false
        });

        // Set default revenue config (25/25/25/25)
        _revenueConfigs[agentId] = RevenueConfig({
            artistBps: 2500,
            agentBps: 2500,
            platformBps: 2500,
            protocolBps: 2500
        });

        _spiritAttached[agentId] = true;

        emit SpiritRegistered(agentId, artist, artist, platform);
    }

    /// @inheritdoc ISpiritRegistry
    function attachSpirit(
        address externalRegistry,
        uint256 externalAgentId,
        address artist,
        address platform
    ) external returns (uint256 spiritId) {
        // Verify caller owns the external agent
        address externalOwner = IERC8004IdentityRegistry(externalRegistry).ownerOf(externalAgentId);
        if (externalOwner != msg.sender) revert EXTERNAL_VERIFICATION_FAILED();

        // Register a local Spirit entry for this external agent
        spiritId = _register(msg.sender, "");
        _setAgentWallet(spiritId, msg.sender);

        // Store external reference
        _externalAgents[spiritId] = ExternalAgent({
            registry: externalRegistry,
            agentId: externalAgentId
        });

        // Store Spirit config
        _spiritConfigs[spiritId] = SpiritConfig({
            treasury: msg.sender,
            childToken: address(0),
            stakingPool: address(0),
            lpPosition: address(0),
            artist: artist,
            platform: platform,
            createdAt: block.timestamp,
            hasToken: false
        });

        // Set default revenue config
        _revenueConfigs[spiritId] = RevenueConfig({
            artistBps: 2500,
            agentBps: 2500,
            platformBps: 2500,
            protocolBps: 2500
        });

        _spiritAttached[spiritId] = true;

        emit SpiritAttached(spiritId, externalRegistry, externalAgentId);
    }

    /// @inheritdoc ISpiritRegistry
    function createChildToken(
        uint256, /* agentId */
        string calldata, /* name */
        string calldata, /* symbol */
        bytes32, /* merkleRoot */
        uint160 /* initialSqrtPriceX96 */
    ) external pure {
        revert NOT_IMPLEMENTED();
    }

    /// @inheritdoc ISpiritRegistry
    function routeRevenue(uint256 agentId, address token, uint256 amount) external payable {
        if (!_spiritAttached[agentId]) revert SPIRIT_NOT_ATTACHED();

        SpiritConfig storage config = _spiritConfigs[agentId];
        RevenueConfig storage rev = _revenueConfigs[agentId];

        if (token == address(0)) {
            // ETH distribution
            if (msg.value == 0) revert NO_ETH_SENT();
            uint256 total = msg.value;
            uint256 artistAmt = (total * rev.artistBps) / 10_000;
            uint256 agentAmt = (total * rev.agentBps) / 10_000;
            uint256 platformAmt = (total * rev.platformBps) / 10_000;
            uint256 protocolAmt = total - artistAmt - agentAmt - platformAmt;

            _sendETH(config.artist, artistAmt);
            _sendETH(config.treasury, agentAmt);
            _sendETH(config.platform, platformAmt);
            _sendETH(protocolTreasury, protocolAmt);

            emit RevenueRouted(agentId, address(0), total, artistAmt, agentAmt, platformAmt, protocolAmt);
        } else {
            // ERC-20 distribution
            if (msg.value > 0) revert ETH_WITH_ERC20();
            IERC20 erc20 = IERC20(token);
            uint256 artistAmt = (amount * rev.artistBps) / 10_000;
            uint256 agentAmt = (amount * rev.agentBps) / 10_000;
            uint256 platformAmt = (amount * rev.platformBps) / 10_000;
            uint256 protocolAmt = amount - artistAmt - agentAmt - platformAmt;

            erc20.safeTransferFrom(msg.sender, config.artist, artistAmt);
            erc20.safeTransferFrom(msg.sender, config.treasury, agentAmt);
            erc20.safeTransferFrom(msg.sender, config.platform, platformAmt);
            erc20.safeTransferFrom(msg.sender, protocolTreasury, protocolAmt);

            emit RevenueRouted(agentId, token, amount, artistAmt, agentAmt, platformAmt, protocolAmt);
        }
    }

    /// @inheritdoc ISpiritRegistry
    function updateTreasury(uint256 agentId, address newTreasury) external {
        if (!_spiritAttached[agentId]) revert SPIRIT_NOT_ATTACHED();
        SpiritConfig storage config = _spiritConfigs[agentId];
        if (msg.sender != config.treasury) revert NOT_TREASURY();

        address oldTreasury = config.treasury;
        config.treasury = newTreasury;
        _setAgentWallet(agentId, newTreasury);

        emit TreasuryUpdated(agentId, oldTreasury, newTreasury);
    }

    /// @inheritdoc ISpiritRegistry
    function setRevenueConfig(uint256 agentId, RevenueConfig calldata config) external {
        _requireOwner(agentId);
        if (!_spiritAttached[agentId]) revert SPIRIT_NOT_ATTACHED();
        uint256 total = uint256(config.artistBps) + config.agentBps + config.platformBps + config.protocolBps;
        if (total != 10_000) revert INVALID_REVENUE_CONFIG();
        _revenueConfigs[agentId] = config;
    }

    //     _    ___                 ______                 __  _
    //    | |  / (_)__ _      __   / ____/_  ______  _____/ /_(_)___  ____  _____
    //    | | / / / _ \ | /| / /  / /_  / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
    //    | |/ / /  __/ |/ |/ /  / __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__  )
    //    |___/_/\___/|__/|__/  /_/    \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/

    /// @notice Override to resolve ambiguity between ISpiritRegistry and ERC8004IdentityRegistry
    function ownerOf(uint256 agentId)
        public
        view
        override(ERC8004IdentityRegistry, IERC8004IdentityRegistry)
        returns (address)
    {
        return super.ownerOf(agentId);
    }

    /// @inheritdoc ISpiritRegistry
    function getSpiritConfig(uint256 agentId) external view returns (SpiritConfig memory) {
        _requireExists(agentId);
        return _spiritConfigs[agentId];
    }

    /// @inheritdoc ISpiritRegistry
    function getRevenueConfig(uint256 agentId) external view returns (RevenueConfig memory) {
        _requireExists(agentId);
        return _revenueConfigs[agentId];
    }

    /// @inheritdoc ISpiritRegistry
    function getTreasury(uint256 agentId) external view returns (address) {
        _requireExists(agentId);
        return _spiritConfigs[agentId].treasury;
    }

    /// @inheritdoc ISpiritRegistry
    function getChildToken(uint256 agentId) external view returns (address) {
        _requireExists(agentId);
        return _spiritConfigs[agentId].childToken;
    }

    /// @inheritdoc ISpiritRegistry
    function getStakingPool(uint256 agentId) external view returns (address) {
        _requireExists(agentId);
        return _spiritConfigs[agentId].stakingPool;
    }

    /// @inheritdoc ISpiritRegistry
    function hasSpiritAttached(uint256 agentId) external view returns (bool) {
        return _spiritAttached[agentId];
    }

    /// @inheritdoc ISpiritRegistry
    function getExternalAgent(uint256 spiritId) external view returns (ExternalAgent memory) {
        _requireExists(spiritId);
        return _externalAgents[spiritId];
    }

    /// @inheritdoc ISpiritRegistry
    function defaultRevenueConfig() external pure returns (RevenueConfig memory) {
        return RevenueConfig({ artistBps: 2500, agentBps: 2500, platformBps: 2500, protocolBps: 2500 });
    }

    //      ____      __                        __
    //     /  _/___  / /____  _________  ____ _/ /
    //     / // __ \/ __/ _ \/ ___/ __ \/ __ `/ /
    //   _/ // / / / /_/  __/ /  / / / / /_/ / /
    //  /___/_/ /_/\__/\___/_/  /_/ /_/\__,_/_/

    function _sendETH(address to, uint256 amount) internal {
        if (amount == 0) return;
        (bool success,) = to.call{ value: amount }("");
        require(success, "ETH_TRANSFER_FAILED");
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 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 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 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 {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @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 {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    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.
     */
    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.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), 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 data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), 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 data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

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

/**
 * @title IERC8004IdentityRegistry
 * @notice Standard interface from ERC-8004 (Trustless AI Agents) specification
 * @dev Reference: https://github.com/ethereum/ERCs/pull/661
 *
 * ERC-8004 defines a standard way for AI agents to have on-chain identity,
 * enabling trustless interactions between agents and protocols.
 *
 * Key concepts:
 * - agentId: NFT-based unique identifier
 * - agentURI: Points to agent registration JSON (IPFS/HTTPS)
 * - agentWallet: Agent-controlled wallet (separate from owner)
 * - metadata: On-chain key-value store
 */
interface IERC8004IdentityRegistry {

    //      ________ __                        __
    //     / ___// //_/____  _____  __________/ /______
    //     \__ \/ __/ / ___/ / / / / ___/ __  / __/ ___/
    //    ___/ / / / / /  / /_/ / /__/ /_/ / / (__  )
    //   /____/_/ /_/_/   \__,_/\___/\__,_/_/  /____/

    /// @notice Metadata entry for agent registration
    struct MetadataEntry {
        string key;
        string value;
    }

    //      ______                 __
    //     / ____/   _____  ____  / /______
    //    / __/ | | / / _ \/ __ \/ __/ ___/
    //   / /___ | |/ /  __/ / / / /_(__  )
    //  /_____/ |___/\___/_/ /_/\__/____/

    /// @notice Emitted when a new agent is registered
    event Registered(
        uint256 indexed agentId,
        string agentURI,
        address indexed owner
    );

    /// @notice Emitted when agent URI is updated
    event URIUpdated(
        uint256 indexed agentId,
        string newURI,
        address indexed updatedBy
    );

    /// @notice Emitted when agent wallet is set or changed
    event AgentWalletSet(
        uint256 indexed agentId,
        address indexed oldWallet,
        address indexed newWallet
    );

    /// @notice Emitted when metadata is set
    /// @dev Note: indexedMetadataKey is indexed for efficient filtering but limited to 32 bytes.
    ///      metadataKey contains the full key string. metadataValue is bytes to support
    ///      arbitrary data encoding (implementations may use abi.encode(string) for string values).
    event MetadataSet(
        uint256 indexed agentId,
        bytes32 indexed indexedMetadataKey,
        string metadataKey,
        string metadataValue
    );

    //     ______           __                     ______
    //    / ____/_  _______/ /_____  ____ ___     / ____/_____________  __________
    //   / /   / / / / ___/ __/ __ \/ __ `__ \   / __/ / ___/ ___/ __ \/ ___/ ___/
    //  / /___/ /_/ (__  ) /_/ /_/ / / / / / /  / /___/ /  / /  / /_/ / /  (__  )
    //  \____/\__,_/____/\__/\____/_/ /_/ /_/  /_____/_/  /_/   \____/_/  /____/

    /// @notice Agent not found
    error AGENT_NOT_FOUND();

    /// @notice Caller is not the owner
    error NOT_OWNER();

    /// @notice Invalid signature
    error INVALID_SIGNATURE();

    /// @notice Deadline expired
    error DEADLINE_EXPIRED();

    //      ______     __                        __   ______                 __  _
    //     / ____/  __/ /____  _________  ____ _/ /  / ____/_  ______  _____/ /_(_)___  ____  _____
    //    / __/ | |/_/ __/ _ \/ ___/ __ \/ __ `/ /  / /_  / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
    //   / /____>  </ /_/  __/ /  / / / / /_/ / /  / __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__  )
    //  /_____/_/|_|\__/\___/_/  /_/ /_/\__,_/_/  /_/    \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/

    /**
     * @notice Register a new agent with URI and metadata
     * @param agentURI URI pointing to agent registration JSON
     * @param metadata Initial metadata entries
     * @return agentId The unique agent identifier (NFT ID)
     */
    function register(
        string calldata agentURI,
        MetadataEntry[] calldata metadata
    ) external returns (uint256 agentId);

    /**
     * @notice Register a new agent with only URI
     * @param agentURI URI pointing to agent registration JSON
     * @return agentId The unique agent identifier
     */
    function register(string calldata agentURI) external returns (uint256 agentId);

    /**
     * @notice Register a new agent with no URI (can be set later)
     * @return agentId The unique agent identifier
     */
    function register() external returns (uint256 agentId);

    /**
     * @notice Update the agent's URI
     * @dev Only callable by the agent owner
     * @param agentId The agent to update
     * @param newURI The new URI
     */
    function setAgentURI(uint256 agentId, string calldata newURI) external;

    /**
     * @notice Set the agent's operational wallet
     * @dev Requires EIP-712 signature from the new wallet to prevent hijacking
     * @param agentId The agent to update
     * @param newWallet The new wallet address
     * @param deadline Signature expiry timestamp
     * @param signature EIP-712 signature from newWallet
     */
    function setAgentWallet(
        uint256 agentId,
        address newWallet,
        uint256 deadline,
        bytes calldata signature
    ) external;

    /**
     * @notice Get metadata value for an agent
     * @param agentId The agent to query
     * @param key The metadata key
     * @return The metadata value
     */
    function getMetadata(uint256 agentId, string calldata key)
        external view returns (string memory);

    /**
     * @notice Set metadata for an agent
     * @dev Only callable by the agent owner
     * @param agentId The agent to update
     * @param key The metadata key
     * @param value The metadata value
     */
    function setMetadata(
        uint256 agentId,
        string calldata key,
        string calldata value
    ) external;

    /**
     * @notice Get the owner of an agent
     * @param agentId The agent to query
     * @return The owner address
     */
    function ownerOf(uint256 agentId) external view returns (address);

    /**
     * @notice Get the operational wallet of an agent
     * @param agentId The agent to query
     * @return The agent wallet address
     */
    function agentWalletOf(uint256 agentId) external view returns (address);

    /**
     * @notice Get the URI for an agent
     * @param agentId The agent to query
     * @return The agent URI
     */
    function agentURI(uint256 agentId) external view returns (string memory);

    /**
     * @notice Check if an agent exists
     * @param agentId The agent to check
     * @return True if the agent exists
     */
    function exists(uint256 agentId) external view returns (bool);
}

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

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

/**
 * @title ISpiritRegistry
 * @notice Spirit Protocol's agent registry, extending ERC-8004 Identity Registry
 * @dev Adds treasury, revenue routing, and token creation to standard agent identity
 *
 * Spirit extends ERC-8004 to provide the economic layer for AI agents:
 * - Treasury: Safe multisig per agent for fund management
 * - Revenue Routing: 25/25/25/25 split (Artist/Agent/Platform/Protocol)
 * - Child Tokens: Native token with staking pool
 * - LP Positions: Uniswap V4 liquidity owned by agent
 *
 * Integration modes:
 * 1. Native: Agent registers directly with Spirit (gets ERC-8004 ID + Spirit economics)
 * 2. Attached: Existing ERC-8004 agent attaches Spirit economics
 */
interface ISpiritRegistry is IERC8004IdentityRegistry {

    //      ________ __                        __
    //     / ___// //_/____  _____  __________/ /______
    //     \__ \/ __/ / ___/ / / / / ___/ __  / __/ ___/
    //    ___/ / / / / /  / /_/ / /__/ /_/ / / (__  )
    //   /____/_/ /_/_/   \__,_/\___/\__,_/_/  /____/

    /// @notice Spirit-specific configuration for an agent
    struct SpiritConfig {
        address treasury;           // Safe multisig for agent funds
        address childToken;         // Agent's token (if created)
        address stakingPool;        // GDA staking pool
        address lpPosition;         // Uniswap V4 LP NFT
        address artist;             // Creator/trainer address
        address platform;           // Platform address (Eden, etc.)
        uint256 createdAt;          // Block timestamp
        bool hasToken;              // Whether child token exists
    }

    /// @notice Revenue routing configuration
    struct RevenueConfig {
        uint16 artistBps;           // Basis points to artist (2500 = 25%)
        uint16 agentBps;            // Basis points to agent treasury
        uint16 platformBps;         // Basis points to platform
        uint16 protocolBps;         // Basis points to Spirit treasury
    }

    /// @notice External agent reference for attached mode
    struct ExternalAgent {
        address registry;           // External ERC-8004 registry
        uint256 agentId;            // Agent ID in that registry
    }

    //      ______                 __
    //     / ____/   _____  ____  / /______
    //    / __/ | | / / _ \/ __ \/ __/ ___/
    //   / /___ | |/ /  __/ / / / /_(__  )
    //  /_____/ |___/\___/_/ /_/\__/____/

    /// @notice Emitted when a Spirit agent is registered
    event SpiritRegistered(
        uint256 indexed agentId,
        address indexed treasury,
        address indexed artist,
        address platform
    );

    /// @notice Emitted when Spirit economics are attached to external agent
    event SpiritAttached(
        uint256 indexed spiritId,
        address indexed externalRegistry,
        uint256 indexed externalAgentId
    );

    /// @notice Emitted when treasury is updated
    event TreasuryUpdated(
        uint256 indexed agentId,
        address oldTreasury,
        address newTreasury
    );

    /// @notice Emitted when child token is created
    event ChildTokenCreated(
        uint256 indexed agentId,
        address indexed childToken,
        address indexed stakingPool,
        address lpPosition
    );

    /// @notice Emitted when revenue is routed
    event RevenueRouted(
        uint256 indexed agentId,
        address indexed token,
        uint256 amount,
        uint256 artistAmount,
        uint256 agentAmount,
        uint256 platformAmount,
        uint256 protocolAmount
    );

    //     ______           __                     ______
    //    / ____/_  _______/ /_____  ____ ___     / ____/_____________  __________
    //   / /   / / / / ___/ __/ __ \/ __ `__ \   / __/ / ___/ ___/ __ \/ ___/ ___/
    //  / /___/ /_/ (__  ) /_/ /_/ / / / / / /  / /___/ /  / /  / /_/ / /  (__  )
    //  \____/\__,_/____/\__/\____/_/ /_/ /_/  /_____/_/  /_/   \____/_/  /____/

    /// @notice Spirit not attached to this agent
    error SPIRIT_NOT_ATTACHED();

    /// @notice Agent already has Spirit attached
    error SPIRIT_ALREADY_ATTACHED();

    /// @notice Agent already has a token
    error TOKEN_ALREADY_EXISTS();

    /// @notice Invalid revenue configuration (must sum to 10000 bps)
    error INVALID_REVENUE_CONFIG();

    /// @notice External registry verification failed
    error EXTERNAL_VERIFICATION_FAILED();

    /// @notice Invalid treasury configuration
    error INVALID_TREASURY_CONFIG();

    //      ______     __                        __   ______                 __  _
    //     / ____/  __/ /____  _________  ____ _/ /  / ____/_  ______  _____/ /_(_)___  ____  _____
    //    / __/ | |/_/ __/ _ \/ ___/ __ \/ __ `/ /  / /_  / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
    //   / /____>  </ /_/  __/ /  / / / / /_/ / /  / __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__  )
    //  /_____/_/|_|\__/\___/_/  /_/ /_/\__,_/_/  /_/    \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/

    /**
     * @notice Register a Spirit agent (extends ERC-8004 register)
     * @dev Creates ERC-8004 identity + Spirit economics in one transaction.
     *
     *      Wallet/Treasury mapping:
     *      - ERC-8004's agentWallet is set to the treasury address
     *      - This means agentWalletOf(agentId) == getTreasury(agentId)
     *      - The treasury (Safe multisig) acts as the agent's operational wallet
     *      - Owner (artist) controls identity; treasury controls funds
     *
     *      Implementation MUST:
     *      - Deploy Safe multisig with treasuryOwners and treasuryThreshold
     *      - Call inherited setAgentWallet() to set agentWallet = treasury
     *      - Store Spirit-specific config (artist, platform, etc.)
     *
     * @param agentURI URI pointing to agent registration JSON
     * @param artist Address of the creator/trainer (becomes ERC-8004 owner)
     * @param platform Address of the platform
     * @param treasuryOwners Initial Safe multisig owners (must include artist and agent)
     * @param treasuryThreshold Safe threshold for transactions
     * @return agentId The ERC-8004 compatible agent ID
     */
    function registerSpirit(
        string calldata agentURI,
        address artist,
        address platform,
        address[] calldata treasuryOwners,
        uint256 treasuryThreshold
    ) external returns (uint256 agentId);

    /**
     * @notice Attach Spirit economics to existing ERC-8004 agent
     * @dev For agents already registered in another ERC-8004 registry.
     *      SECURITY: Caller must be the owner of the external agent.
     *      Implementation MUST verify ownership via:
     *      - IERC8004IdentityRegistry(externalRegistry).ownerOf(externalAgentId) == msg.sender
     *      This prevents unauthorized attachment to someone else's agent.
     * @param externalRegistry The ERC-8004 registry address (must implement IERC8004IdentityRegistry)
     * @param externalAgentId The agent's ID in that registry
     * @param artist Address of the creator/trainer
     * @param platform Address of the platform
     * @return spiritId Spirit's internal reference ID
     */
    function attachSpirit(
        address externalRegistry,
        uint256 externalAgentId,
        address artist,
        address platform
    ) external returns (uint256 spiritId);

    /**
     * @notice Create child token for an agent
     * @dev Only callable by agent owner, deploys token + staking pool + LP
     * @param agentId The agent to create token for
     * @param name Token name
     * @param symbol Token symbol
     * @param merkleRoot Merkle root for airstream
     * @param initialSqrtPriceX96 Initial price for Uniswap V4 pool
     */
    function createChildToken(
        uint256 agentId,
        string calldata name,
        string calldata symbol,
        bytes32 merkleRoot,
        uint160 initialSqrtPriceX96
    ) external;

    /**
     * @notice Route revenue to an agent's stakeholders
     * @dev Distributes according to RevenueConfig (default: 25/25/25/25)
     *
     *      ETH vs ERC-20 handling:
     *      - For ETH: token = address(0), amount is ignored, msg.value is distributed
     *      - For ERC-20: token = token address, msg.value MUST be 0, amount is transferred via transferFrom
     *
     *      Implementation MUST:
     *      - Revert if token == address(0) && msg.value == 0 (no ETH sent)
     *      - Revert if token != address(0) && msg.value > 0 (ETH sent with ERC-20)
     *      - For ERC-20: call transferFrom(msg.sender, ...) for each recipient
     *
     * @param agentId The agent receiving revenue
     * @param token The token being distributed (address(0) for ETH)
     * @param amount The amount to distribute (ignored for ETH, uses msg.value)
     */
    function routeRevenue(
        uint256 agentId,
        address token,
        uint256 amount
    ) external payable;

    /**
     * @notice Update treasury for an agent
     * @dev Only callable by current treasury via multisig
     * @param agentId The agent to update
     * @param newTreasury The new treasury address
     */
    function updateTreasury(
        uint256 agentId,
        address newTreasury
    ) external;

    /**
     * @notice Update revenue configuration for an agent
     * @dev Only callable by agent owner, must sum to 10000 bps
     * @param agentId The agent to update
     * @param config New revenue configuration
     */
    function setRevenueConfig(
        uint256 agentId,
        RevenueConfig calldata config
    ) external;

    //     _    ___                 ______                 __  _
    //    | |  / (_)__ _      __   / ____/_  ______  _____/ /_(_)___  ____  _____
    //    | | / / / _ \ | /| / /  / /_  / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
    //    | |/ / /  __/ |/ |/ /  / __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__  )
    //    |___/_/\___/|__/|__/  /_/    \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/

    /**
     * @notice Get Spirit-specific configuration for an agent
     * @param agentId The agent to query
     * @return Spirit configuration
     */
    function getSpiritConfig(uint256 agentId)
        external view returns (SpiritConfig memory);

    /**
     * @notice Get revenue routing configuration
     * @param agentId The agent to query
     * @return Revenue configuration
     */
    function getRevenueConfig(uint256 agentId)
        external view returns (RevenueConfig memory);

    /**
     * @notice Get agent's treasury address
     * @param agentId The agent to query
     * @return Treasury address
     */
    function getTreasury(uint256 agentId)
        external view returns (address);

    /**
     * @notice Get agent's child token (if exists)
     * @param agentId The agent to query
     * @return Child token address (address(0) if none)
     */
    function getChildToken(uint256 agentId)
        external view returns (address);

    /**
     * @notice Get agent's staking pool (if exists)
     * @param agentId The agent to query
     * @return Staking pool address (address(0) if none)
     */
    function getStakingPool(uint256 agentId)
        external view returns (address);

    /**
     * @notice Check if agent has Spirit economics attached
     * @param agentId The agent to check
     * @return True if Spirit is attached
     */
    function hasSpiritAttached(uint256 agentId)
        external view returns (bool);

    /**
     * @notice Get external agent reference (for attached mode)
     * @param spiritId Spirit's internal ID
     * @return External agent reference
     */
    function getExternalAgent(uint256 spiritId)
        external view returns (ExternalAgent memory);

    /**
     * @notice Get Spirit Protocol treasury address
     * @return Protocol treasury address
     */
    function protocolTreasury() external view returns (address);

    /**
     * @notice Get default revenue configuration
     * @return Default revenue config (25/25/25/25)
     */
    function defaultRevenueConfig() external view returns (RevenueConfig memory);
}

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

import { ERC721 } from "@openzeppelin-v5/contracts/token/ERC721/ERC721.sol";
import { ECDSA } from "@openzeppelin-v5/contracts/utils/cryptography/ECDSA.sol";
import { EIP712 } from "@openzeppelin-v5/contracts/utils/cryptography/EIP712.sol";

import { IERC8004IdentityRegistry } from "../interfaces/registry/IERC8004IdentityRegistry.sol";

/**
 * @title ERC8004IdentityRegistry
 * @notice Implementation of the ERC-8004 Identity Registry standard
 * @dev Extends ERC-721 for NFT-based agent IDs with URI, wallet, and metadata storage.
 *      Reference: https://github.com/ethereum/ERCs/pull/661
 */
contract ERC8004IdentityRegistry is IERC8004IdentityRegistry, ERC721, EIP712 {
    using ECDSA for bytes32;

    //      ________ __                        __
    //     / ___// //_/____  _____  __________/ /______
    //     \__ \/ __/ / ___/ / / / / ___/ __  / __/ ___/
    //    ___/ / / / / /  / /_/ / /__/ /_/ / / (__  )
    //   /____/_/ /_/_/   \__,_/\___/\__,_/_/  /____/

    /// @notice EIP-712 typehash for setAgentWallet signature verification
    bytes32 public constant AGENT_WALLET_TYPEHASH =
        keccak256("SetAgentWallet(uint256 agentId,address newWallet,uint256 deadline)");

    /// @notice Auto-incrementing agent ID counter (starts at 1)
    uint256 private _nextAgentId = 1;

    /// @notice Agent URI storage
    mapping(uint256 agentId => string uri) private _agentURIs;

    /// @notice Agent wallet storage
    mapping(uint256 agentId => address wallet) private _agentWallets;

    /// @notice On-chain metadata key-value store
    mapping(uint256 agentId => mapping(string key => string value)) private _metadata;

    //     ______                 __                  __
    //    / ____/___  ____  _____/ /________  _______/ /_____  _____
    //   / /   / __ \/ __ \/ ___/ __/ ___/ / / / ___/ __/ __ \/ ___/
    //  / /___/ /_/ / / / (__  ) /_/ /  / /_/ / /__/ /_/ /_/ / /
    //  \____/\____/_/ /_/____/\__/_/   \__,_/\___/\__/\____/_/

    constructor(string memory name, string memory symbol) ERC721(name, symbol) EIP712(name, "1") { }

    /// @notice Returns the EIP-712 domain separator
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32) {
        return _domainSeparatorV4();
    }

    //      ______     __                        __   ______                 __  _
    //     / ____/  __/ /____  _________  ____ _/ /  / ____/_  ______  _____/ /_(_)___  ____  _____
    //    / __/ | |/_/ __/ _ \/ ___/ __ \/ __ `/ /  / /_  / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
    //   / /____>  </ /_/  __/ /  / / / / /_/ / /  / __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__  )
    //  /_____/_/|_|\__/\___/_/  /_/ /_/\__,_/_/  /_/    \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/

    /// @inheritdoc IERC8004IdentityRegistry
    function register(string calldata agentURI_, MetadataEntry[] calldata metadata_)
        external
        returns (uint256 agentId)
    {
        agentId = _register(msg.sender, agentURI_);
        for (uint256 i; i < metadata_.length; ++i) {
            _setMetadata(agentId, metadata_[i].key, metadata_[i].value);
        }
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function register(string calldata agentURI_) external returns (uint256 agentId) {
        agentId = _register(msg.sender, agentURI_);
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function register() external returns (uint256 agentId) {
        agentId = _register(msg.sender, "");
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function setAgentURI(uint256 agentId, string calldata newURI) external {
        _requireOwner(agentId);
        _agentURIs[agentId] = newURI;
        emit URIUpdated(agentId, newURI, msg.sender);
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function setAgentWallet(uint256 agentId, address newWallet, uint256 deadline, bytes calldata signature) external {
        _requireOwner(agentId);
        if (block.timestamp > deadline) revert DEADLINE_EXPIRED();

        bytes32 structHash = keccak256(abi.encode(AGENT_WALLET_TYPEHASH, agentId, newWallet, deadline));
        bytes32 digest = _hashTypedDataV4(structHash);
        address recovered = digest.recover(signature);
        if (recovered != newWallet) revert INVALID_SIGNATURE();

        _setAgentWallet(agentId, newWallet);
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function setMetadata(uint256 agentId, string calldata key, string calldata value) external {
        _requireOwner(agentId);
        _setMetadata(agentId, key, value);
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function getMetadata(uint256 agentId, string calldata key) external view returns (string memory) {
        _requireExists(agentId);
        return _metadata[agentId][key];
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function ownerOf(uint256 agentId) public view virtual override(ERC721, IERC8004IdentityRegistry) returns (address) {
        return super.ownerOf(agentId);
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function agentWalletOf(uint256 agentId) external view returns (address) {
        _requireExists(agentId);
        return _agentWallets[agentId];
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function agentURI(uint256 agentId) external view returns (string memory) {
        _requireExists(agentId);
        return _agentURIs[agentId];
    }

    /// @inheritdoc IERC8004IdentityRegistry
    function exists(uint256 agentId) external view returns (bool) {
        return _ownerOf(agentId) != address(0);
    }

    //      ____      __                        __   ______                 __  _
    //     /  _/___  / /____  _________  ____ _/ /  / ____/_  ______  _____/ /_(_)___  ____  _____
    //     / // __ \/ __/ _ \/ ___/ __ \/ __ `/ /  / /_  / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
    //   _/ // / / / /_/  __/ /  / / / / /_/ / /  / __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__  )
    //  /___/_/ /_/\__/\___/_/  /_/ /_/\__,_/_/  /_/    \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/

    /**
     * @notice Internal registration logic
     * @param owner_ The address that will own the agent NFT
     * @param agentURI_ Initial URI for the agent
     * @return agentId The newly minted agent ID
     */
    function _register(address owner_, string memory agentURI_) internal returns (uint256 agentId) {
        agentId = _nextAgentId++;
        _mint(owner_, agentId);
        if (bytes(agentURI_).length > 0) {
            _agentURIs[agentId] = agentURI_;
        }
        emit Registered(agentId, agentURI_, owner_);
    }

    /**
     * @notice Internal agent wallet setter (no signature required)
     * @param agentId The agent to update
     * @param newWallet The new wallet address
     */
    function _setAgentWallet(uint256 agentId, address newWallet) internal {
        address oldWallet = _agentWallets[agentId];
        _agentWallets[agentId] = newWallet;
        emit AgentWalletSet(agentId, oldWallet, newWallet);
    }

    /**
     * @notice Internal metadata setter
     * @param agentId The agent to update
     * @param key Metadata key
     * @param value Metadata value
     */
    function _setMetadata(uint256 agentId, string memory key, string memory value) internal {
        _metadata[agentId][key] = value;
        emit MetadataSet(agentId, keccak256(bytes(key)), key, value);
    }

    /**
     * @notice Require that agentId exists
     */
    function _requireExists(uint256 agentId) internal view {
        if (_ownerOf(agentId) == address(0)) revert AGENT_NOT_FOUND();
    }

    /**
     * @notice Require that msg.sender is the owner of agentId
     */
    function _requireOwner(uint256 agentId) internal view {
        if (ownerOf(agentId) != msg.sender) revert NOT_OWNER();
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

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

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

File 9 of 25 : ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.20;

import {IERC721} from "./IERC721.sol";
import {IERC721Receiver} from "./IERC721Receiver.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {Strings} from "../../utils/Strings.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {IERC721Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    mapping(uint256 tokenId => address) private _owners;

    mapping(address owner => uint256) private _balances;

    mapping(uint256 tokenId => address) private _tokenApprovals;

    mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual returns (uint256) {
        if (owner == address(0)) {
            revert ERC721InvalidOwner(address(0));
        }
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual returns (address) {
        return _requireOwned(tokenId);
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
        _requireOwned(tokenId);

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overridden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual {
        _approve(to, tokenId, _msgSender());
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual returns (address) {
        _requireOwned(tokenId);

        return _getApproved(tokenId);
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(address from, address to, uint256 tokenId) public virtual {
        if (to == address(0)) {
            revert ERC721InvalidReceiver(address(0));
        }
        // Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
        // (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
        address previousOwner = _update(to, tokenId, _msgSender());
        if (previousOwner != from) {
            revert ERC721IncorrectOwner(from, tokenId, previousOwner);
        }
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) public {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
        transferFrom(from, to, tokenId);
        _checkOnERC721Received(from, to, tokenId, data);
    }

    /**
     * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
     *
     * IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
     * core ERC721 logic MUST be matched with the use of {_increaseBalance} to keep balances
     * consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
     * `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
     */
    function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
        return _owners[tokenId];
    }

    /**
     * @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
     */
    function _getApproved(uint256 tokenId) internal view virtual returns (address) {
        return _tokenApprovals[tokenId];
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
     * particular (ignoring whether it is owned by `owner`).
     *
     * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
     * assumption.
     */
    function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
        return
            spender != address(0) &&
            (owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
    }

    /**
     * @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
     * Reverts if `spender` does not have approval from the provided `owner` for the given token or for all its assets
     * the `spender` for the specific `tokenId`.
     *
     * WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
     * assumption.
     */
    function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
        if (!_isAuthorized(owner, spender, tokenId)) {
            if (owner == address(0)) {
                revert ERC721NonexistentToken(tokenId);
            } else {
                revert ERC721InsufficientApproval(spender, tokenId);
            }
        }
    }

    /**
     * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
     *
     * NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
     * a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
     *
     * WARNING: Increasing an account's balance using this function tends to be paired with an override of the
     * {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
     * remain consistent with one another.
     */
    function _increaseBalance(address account, uint128 value) internal virtual {
        unchecked {
            _balances[account] += value;
        }
    }

    /**
     * @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
     * (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
     *
     * The `auth` argument is optional. If the value passed is non 0, then this function will check that
     * `auth` is either the owner of the token, or approved to operate on the token (by the owner).
     *
     * Emits a {Transfer} event.
     *
     * NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
     */
    function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
        address from = _ownerOf(tokenId);

        // Perform (optional) operator check
        if (auth != address(0)) {
            _checkAuthorized(from, auth, tokenId);
        }

        // Execute the update
        if (from != address(0)) {
            // Clear approval. No need to re-authorize or emit the Approval event
            _approve(address(0), tokenId, address(0), false);

            unchecked {
                _balances[from] -= 1;
            }
        }

        if (to != address(0)) {
            unchecked {
                _balances[to] += 1;
            }
        }

        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        return from;
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal {
        if (to == address(0)) {
            revert ERC721InvalidReceiver(address(0));
        }
        address previousOwner = _update(to, tokenId, address(0));
        if (previousOwner != address(0)) {
            revert ERC721InvalidSender(address(0));
        }
    }

    /**
     * @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
        _mint(to, tokenId);
        _checkOnERC721Received(address(0), to, tokenId, data);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     * This is an internal function that does not check if the sender is authorized to operate on the token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal {
        address previousOwner = _update(address(0), tokenId, address(0));
        if (previousOwner == address(0)) {
            revert ERC721NonexistentToken(tokenId);
        }
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(address from, address to, uint256 tokenId) internal {
        if (to == address(0)) {
            revert ERC721InvalidReceiver(address(0));
        }
        address previousOwner = _update(to, tokenId, address(0));
        if (previousOwner == address(0)) {
            revert ERC721NonexistentToken(tokenId);
        } else if (previousOwner != from) {
            revert ERC721IncorrectOwner(from, tokenId, previousOwner);
        }
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
     * are aware of the ERC721 standard to prevent tokens from being forever locked.
     *
     * `data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is like {safeTransferFrom} in the sense that it invokes
     * {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `tokenId` token must exist and be owned by `from`.
     * - `to` cannot be the zero address.
     * - `from` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(address from, address to, uint256 tokenId) internal {
        _safeTransfer(from, to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
        _transfer(from, to, tokenId);
        _checkOnERC721Received(from, to, tokenId, data);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
     * either the owner of the token, or approved to operate on all tokens held by this owner.
     *
     * Emits an {Approval} event.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address to, uint256 tokenId, address auth) internal {
        _approve(to, tokenId, auth, true);
    }

    /**
     * @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
     * emitted in the context of transfers.
     */
    function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
        // Avoid reading the owner unless necessary
        if (emitEvent || auth != address(0)) {
            address owner = _requireOwned(tokenId);

            // We do not use _isAuthorized because single-token approvals should not be able to call approve
            if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
                revert ERC721InvalidApprover(auth);
            }

            if (emitEvent) {
                emit Approval(owner, to, tokenId);
            }
        }

        _tokenApprovals[tokenId] = to;
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Requirements:
     * - operator can't be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
        if (operator == address(0)) {
            revert ERC721InvalidOperator(operator);
        }
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
     * Returns the owner.
     *
     * Overrides to ownership logic should be done to {_ownerOf}.
     */
    function _requireOwned(uint256 tokenId) internal view returns (address) {
        address owner = _ownerOf(tokenId);
        if (owner == address(0)) {
            revert ERC721NonexistentToken(tokenId);
        }
        return owner;
    }

    /**
     * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target address. This will revert if the
     * recipient doesn't accept the token transfer. The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param data bytes optional data to send along with the call
     */
    function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private {
        if (to.code.length > 0) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
                if (retval != IERC721Receiver.onERC721Received.selector) {
                    revert ERC721InvalidReceiver(to);
                }
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert ERC721InvalidReceiver(to);
                } else {
                    /// @solidity memory-safe-assembly
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            uint8 v = uint8((uint256(vs) >> 255) + 27);
            return tryRecover(hash, v, r, s);
        }
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS, s);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.20;

import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
 * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
 * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
 * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
 * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
 * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
 *
 * @custom:oz-upgrades-unsafe-allow state-variable-immutable
 */
abstract contract EIP712 is IERC5267 {
    using ShortStrings for *;

    bytes32 private constant TYPE_HASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    bytes32 private immutable _hashedName;
    bytes32 private immutable _hashedVersion;

    ShortString private immutable _name;
    ShortString private immutable _version;
    string private _nameFallback;
    string private _versionFallback;

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        _name = name.toShortStringWithFallback(_nameFallback);
        _version = version.toShortStringWithFallback(_versionFallback);
        _hashedName = keccak256(bytes(name));
        _hashedVersion = keccak256(bytes(version));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
    }

    /**
     * @dev See {IERC-5267}.
     */
    function eip712Domain()
        public
        view
        virtual
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        )
    {
        return (
            hex"0f", // 01111
            _EIP712Name(),
            _EIP712Version(),
            block.chainid,
            address(this),
            bytes32(0),
            new uint256[](0)
        );
    }

    /**
     * @dev The name parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _name which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Name() internal view returns (string memory) {
        return _name.toStringWithFallback(_nameFallback);
    }

    /**
     * @dev The version parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _version which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Version() internal view returns (string memory) {
        return _version.toStringWithFallback(_versionFallback);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
     *   {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 13 of 25 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.20;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be
     * reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

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

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

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant HEX_DIGITS = "0123456789abcdef";
    uint8 private constant ADDRESS_LENGTH = 20;

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        uint256 localValue = value;
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = HEX_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
     * representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.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 ERC165 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 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 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 ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * 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 ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
 *
 * The library provides methods for generating a hash of a message that conforms to the
 * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
 * specifications.
 */
library MessageHashUtils {
    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing a bytes32 `messageHash` with
     * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
     * keccak256, although any bytes32 value can be safely used because the final digest will
     * be re-hashed.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
            mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
            digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing an arbitrary `message` with
     * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
        return
            keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x00` (data with intended validator).
     *
     * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
     * `validator` address. Then hashing the result.
     *
     * See {ECDSA-recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
     *
     * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
     * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
     *
     * See {ECDSA-recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            digest := keccak256(ptr, 0x42)
        }
    }
}

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

pragma solidity ^0.8.20;

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

// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
// | length  | 0x                                                              BB |
type ShortString is bytes32;

/**
 * @dev This library provides functions to convert short memory strings
 * into a `ShortString` type that can be used as an immutable variable.
 *
 * Strings of arbitrary length can be optimized using this library if
 * they are short enough (up to 31 bytes) by packing them with their
 * length (1 byte) in a single EVM word (32 bytes). Additionally, a
 * fallback mechanism can be used for every other case.
 *
 * Usage example:
 *
 * ```solidity
 * contract Named {
 *     using ShortStrings for *;
 *
 *     ShortString private immutable _name;
 *     string private _nameFallback;
 *
 *     constructor(string memory contractName) {
 *         _name = contractName.toShortStringWithFallback(_nameFallback);
 *     }
 *
 *     function name() external view returns (string memory) {
 *         return _name.toStringWithFallback(_nameFallback);
 *     }
 * }
 * ```
 */
library ShortStrings {
    // Used as an identifier for strings longer than 31 bytes.
    bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;

    error StringTooLong(string str);
    error InvalidShortString();

    /**
     * @dev Encode a string of at most 31 chars into a `ShortString`.
     *
     * This will trigger a `StringTooLong` error is the input string is too long.
     */
    function toShortString(string memory str) internal pure returns (ShortString) {
        bytes memory bstr = bytes(str);
        if (bstr.length > 31) {
            revert StringTooLong(str);
        }
        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
    }

    /**
     * @dev Decode a `ShortString` back to a "normal" string.
     */
    function toString(ShortString sstr) internal pure returns (string memory) {
        uint256 len = byteLength(sstr);
        // using `new string(len)` would work locally but is not memory safe.
        string memory str = new string(32);
        /// @solidity memory-safe-assembly
        assembly {
            mstore(str, len)
            mstore(add(str, 0x20), sstr)
        }
        return str;
    }

    /**
     * @dev Return the length of a `ShortString`.
     */
    function byteLength(ShortString sstr) internal pure returns (uint256) {
        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
        if (result > 31) {
            revert InvalidShortString();
        }
        return result;
    }

    /**
     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
     */
    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
        if (bytes(value).length < 32) {
            return toShortString(value);
        } else {
            StorageSlot.getStringSlot(store).value = value;
            return ShortString.wrap(FALLBACK_SENTINEL);
        }
    }

    /**
     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     */
    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return toString(value);
        } else {
            return store;
        }
    }

    /**
     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using
     * {setWithFallback}.
     *
     * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
     */
    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return byteLength(value);
        } else {
            return bytes(store).length;
        }
    }
}

File 21 of 25 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.20;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * 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[EIP 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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.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 ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     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;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 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) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

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

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

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

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            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) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            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) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

Settings
{
  "remappings": [
    "@superfluid-finance/ethereum-contracts/=lib/superfluid-protocol-monorepo/packages/ethereum-contracts/",
    "@superfluid-finance/solidity-semantic-money/=lib/superfluid-protocol-monorepo/packages/solidity-semantic-money/",
    "@superfluid-finance/automation-contracts/=lib/superfluid-protocol-monorepo/packages/automation-contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts-v4/contracts/",
    "@openzeppelin-v5/contracts/=lib/openzeppelin-contracts-v5/contracts/",
    "@uniswap/v4-core/=lib/uniswap-v4-core/",
    "@uniswap/v4-periphery/=lib/uniswap-v4-periphery/",
    "@ensdomains/=lib/uniswap-v4-core/node_modules/@ensdomains/",
    "ds-test/=lib/openzeppelin-contracts-v5/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-v5/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/uniswap-v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "forge-std/=lib/forge-std/src/",
    "hardhat/=lib/uniswap-v4-core/node_modules/hardhat/",
    "openzeppelin-contracts-v4/=lib/openzeppelin-contracts-v4/",
    "openzeppelin-contracts-v5/=lib/openzeppelin-contracts-v5/",
    "openzeppelin-contracts/=lib/uniswap-v4-core/lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts-v4/contracts/",
    "permit2/=lib/uniswap-v4-periphery/lib/permit2/",
    "solmate/=lib/uniswap-v4-core/lib/solmate/",
    "superfluid-protocol-monorepo/=lib/superfluid-protocol-monorepo/packages/solidity-semantic-money/src/",
    "uniswap-v4-core/=lib/uniswap-v4-core/src/",
    "uniswap-v4-periphery/=lib/uniswap-v4-periphery/",
    "v4-core/=lib/uniswap-v4-periphery/lib/v4-core/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"protocolTreasury_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AGENT_NOT_FOUND","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"DEADLINE_EXPIRED","type":"error"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721IncorrectOwner","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721InsufficientApproval","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC721InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"name":"ERC721InvalidOperator","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721InvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC721InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC721InvalidSender","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721NonexistentToken","type":"error"},{"inputs":[],"name":"ETH_WITH_ERC20","type":"error"},{"inputs":[],"name":"EXTERNAL_VERIFICATION_FAILED","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"INVALID_REVENUE_CONFIG","type":"error"},{"inputs":[],"name":"INVALID_SIGNATURE","type":"error"},{"inputs":[],"name":"INVALID_TREASURY_CONFIG","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[],"name":"NOT_IMPLEMENTED","type":"error"},{"inputs":[],"name":"NOT_OWNER","type":"error"},{"inputs":[],"name":"NOT_TREASURY","type":"error"},{"inputs":[],"name":"NO_ETH_SENT","type":"error"},{"inputs":[],"name":"SPIRIT_ALREADY_ATTACHED","type":"error"},{"inputs":[],"name":"SPIRIT_NOT_ATTACHED","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"inputs":[],"name":"TOKEN_ALREADY_EXISTS","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"agentId","type":"uint256"},{"indexed":true,"internalType":"address","name":"oldWallet","type":"address"},{"indexed":true,"internalType":"address","name":"newWallet","type":"address"}],"name":"AgentWalletSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"agentId","type":"uint256"},{"indexed":true,"internalType":"address","name":"childToken","type":"address"},{"indexed":true,"internalType":"address","name":"stakingPool","type":"address"},{"indexed":false,"internalType":"address","name":"lpPosition","type":"address"}],"name":"ChildTokenCreated","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"agentId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"indexedMetadataKey","type":"bytes32"},{"indexed":false,"internalType":"string","name":"metadataKey","type":"string"},{"indexed":false,"internalType":"string","name":"metadataValue","type":"string"}],"name":"MetadataSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"agentId","type":"uint256"},{"indexed":false,"internalType":"string","name":"agentURI","type":"string"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"Registered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"agentId","type":"uint256"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"artistAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"agentAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"platformAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolAmount","type":"uint256"}],"name":"RevenueRouted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"spiritId","type":"uint256"},{"indexed":true,"internalType":"address","name":"externalRegistry","type":"address"},{"indexed":true,"internalType":"uint256","name":"externalAgentId","type":"uint256"}],"name":"SpiritAttached","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"agentId","type":"uint256"},{"indexed":true,"internalType":"address","name":"treasury","type":"address"},{"indexed":true,"internalType":"address","name":"artist","type":"address"},{"indexed":false,"internalType":"address","name":"platform","type":"address"}],"name":"SpiritRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"agentId","type":"uint256"},{"indexed":false,"internalType":"address","name":"oldTreasury","type":"address"},{"indexed":false,"internalType":"address","name":"newTreasury","type":"address"}],"name":"TreasuryUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"agentId","type":"uint256"},{"indexed":false,"internalType":"string","name":"newURI","type":"string"},{"indexed":true,"internalType":"address","name":"updatedBy","type":"address"}],"name":"URIUpdated","type":"event"},{"inputs":[],"name":"AGENT_WALLET_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"agentURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"agentWalletOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"externalRegistry","type":"address"},{"internalType":"uint256","name":"externalAgentId","type":"uint256"},{"internalType":"address","name":"artist","type":"address"},{"internalType":"address","name":"platform","type":"address"}],"name":"attachSpirit","outputs":[{"internalType":"uint256","name":"spiritId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"string","name":"","type":"string"},{"internalType":"string","name":"","type":"string"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint160","name":"","type":"uint160"}],"name":"createChildToken","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"defaultRevenueConfig","outputs":[{"components":[{"internalType":"uint16","name":"artistBps","type":"uint16"},{"internalType":"uint16","name":"agentBps","type":"uint16"},{"internalType":"uint16","name":"platformBps","type":"uint16"},{"internalType":"uint16","name":"protocolBps","type":"uint16"}],"internalType":"struct ISpiritRegistry.RevenueConfig","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"getChildToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"spiritId","type":"uint256"}],"name":"getExternalAgent","outputs":[{"components":[{"internalType":"address","name":"registry","type":"address"},{"internalType":"uint256","name":"agentId","type":"uint256"}],"internalType":"struct ISpiritRegistry.ExternalAgent","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"},{"internalType":"string","name":"key","type":"string"}],"name":"getMetadata","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"getRevenueConfig","outputs":[{"components":[{"internalType":"uint16","name":"artistBps","type":"uint16"},{"internalType":"uint16","name":"agentBps","type":"uint16"},{"internalType":"uint16","name":"platformBps","type":"uint16"},{"internalType":"uint16","name":"protocolBps","type":"uint16"}],"internalType":"struct ISpiritRegistry.RevenueConfig","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"getSpiritConfig","outputs":[{"components":[{"internalType":"address","name":"treasury","type":"address"},{"internalType":"address","name":"childToken","type":"address"},{"internalType":"address","name":"stakingPool","type":"address"},{"internalType":"address","name":"lpPosition","type":"address"},{"internalType":"address","name":"artist","type":"address"},{"internalType":"address","name":"platform","type":"address"},{"internalType":"uint256","name":"createdAt","type":"uint256"},{"internalType":"bool","name":"hasToken","type":"bool"}],"internalType":"struct ISpiritRegistry.SpiritConfig","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"getStakingPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"getTreasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"hasSpiritAttached","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolTreasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"register","outputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"agentURI_","type":"string"},{"components":[{"internalType":"string","name":"key","type":"string"},{"internalType":"string","name":"value","type":"string"}],"internalType":"struct IERC8004IdentityRegistry.MetadataEntry[]","name":"metadata_","type":"tuple[]"}],"name":"register","outputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"agentURI_","type":"string"}],"name":"register","outputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"agentURI_","type":"string"},{"internalType":"address","name":"artist","type":"address"},{"internalType":"address","name":"platform","type":"address"},{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"registerSpirit","outputs":[{"internalType":"uint256","name":"agentId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"routeRevenue","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"},{"internalType":"string","name":"newURI","type":"string"}],"name":"setAgentURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"},{"internalType":"address","name":"newWallet","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"setAgentWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"},{"internalType":"string","name":"key","type":"string"},{"internalType":"string","name":"value","type":"string"}],"name":"setMetadata","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"},{"components":[{"internalType":"uint16","name":"artistBps","type":"uint16"},{"internalType":"uint16","name":"agentBps","type":"uint16"},{"internalType":"uint16","name":"platformBps","type":"uint16"},{"internalType":"uint16","name":"protocolBps","type":"uint16"}],"internalType":"struct ISpiritRegistry.RevenueConfig","name":"config","type":"tuple"}],"name":"setRevenueConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"agentId","type":"uint256"},{"internalType":"address","name":"newTreasury","type":"address"}],"name":"updateTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"}]

6101806040526001600855348015610015575f80fd5b50604051614036380380614036833981016040819052610034916101f6565b6040518060400160405280600f81526020016e53706972697420526567697374727960881b8152506040518060400160405280600981526020016814d4125492550b525160ba1b81525081604051806040016040528060018152602001603160f81b8152508383815f90816100a991906102bb565b5060016100b682826102bb565b506100c69150839050600661017e565b610120526100d581600761017e565b61014052815160208084019190912060e052815190820120610100524660a05261016160e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b60805250503060c05250506001600160a01b0316610160526103cd565b5f60208351101561019957610192836101b0565b90506101aa565b816101a484826102bb565b5060ff90505b92915050565b5f80829050601f815111156101e3578260405163305a27a960e01b81526004016101da9190610375565b60405180910390fd5b80516101ee826103aa565b179392505050565b5f60208284031215610206575f80fd5b81516001600160a01b038116811461021c575f80fd5b9392505050565b634e487b7160e01b5f52604160045260245ffd5b600181811c9082168061024b57607f821691505b60208210810361026957634e487b7160e01b5f52602260045260245ffd5b50919050565b601f8211156102b657805f5260205f20601f840160051c810160208510156102945750805b601f840160051c820191505b818110156102b3575f81556001016102a0565b50505b505050565b81516001600160401b038111156102d4576102d4610223565b6102e8816102e28454610237565b8461026f565b6020601f82116001811461031a575f83156103035750848201515b5f19600385901b1c1916600184901b1784556102b3565b5f84815260208120601f198516915b828110156103495787850151825560209485019460019092019101610329565b508482101561036657868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80516020808301519190811015610269575f1960209190910360031b1b16919050565b60805160a05160c05160e05161010051610120516101405161016051613c006104365f395f81816105a5015281816113c0015261156401525f61244a01525f61241d01525f61231301525f6122eb01525f61224601525f61227001525f61229a0152613c005ff3fe60806040526004361061023e575f3560e01c8063803db96d11610134578063adcd2940116100b3578063cb4799f211610078578063cb4799f21461079b578063cdc593df146107ba578063e48a9785146107d9578063e985e9c5146107f8578063f2c298be14610817578063ff591d0f14610836575f80fd5b8063adcd2940146106dc578063b10d8c41146106fb578063b29bbe621461073e578063b88d4fde1461075d578063c87b56dd1461077c575f80fd5b806395d89b41116100f957806395d89b411461063f578063a22cb46514610653578063a2b44d7514610672578063a823778814610691578063abac8e30146106bd575f80fd5b8063803db96d1461059457806384413ec4146105c757806384b0196e146105e6578063851f5d691461060d5780638d72d0571461062c575f80fd5b80633644e515116101c057806359f9f50f1161018557806359f9f50f146104765780636352211e1461049557806370a08231146104b457806377ada3be146104d357806378396cb314610575575f80fd5b80633644e515146103cf5780633de1aaaa146103e357806342842e0e146104025780634f558e791461042157806353115e1814610457575f80fd5b80631aa3a008116102065780631aa3a0081461030e57806323b872dd14610330578063271073721461034f578063296e52181461037d5780632d1ef5ae146103b0575f80fd5b806301ffc9a71461024257806306fdde0314610276578063081812fc14610297578063095ea7b3146102ce5780630af28bd3146102ef575b5f80fd5b34801561024d575f80fd5b5061026161025c366004612f33565b610855565b60405190151581526020015b60405180910390f35b348015610281575f80fd5b5061028a6108a6565b60405161026d9190612f7c565b3480156102a2575f80fd5b506102b66102b1366004612f8e565b610935565b6040516001600160a01b03909116815260200161026d565b3480156102d9575f80fd5b506102ed6102e8366004612fb9565b61095c565b005b3480156102fa575f80fd5b506102ed610309366004613027565b61096b565b348015610319575f80fd5b506103226109d6565b60405190815260200161026d565b34801561033b575f80fd5b506102ed61034a36600461306e565b6109f4565b34801561035a575f80fd5b50610261610369366004612f8e565b5f908152600e602052604090205460ff1690565b348015610388575f80fd5b506103227f5a2b87f3673ca6856d85d54cb1a9eb690f53c4d6b0954db34c84fe6c19c80d9481565b3480156103bb575f80fd5b506102ed6103ca3660046130ac565b610a82565b3480156103da575f80fd5b50610322610ba5565b3480156103ee575f80fd5b506102b66103fd366004612f8e565b610bae565b34801561040d575f80fd5b506102ed61041c36600461306e565b610bd6565b34801561042c575f80fd5b5061026161043b366004612f8e565b5f908152600260205260409020546001600160a01b0316151590565b348015610462575f80fd5b50610322610471366004613150565b610bf5565b348015610481575f80fd5b506102ed6104903660046131ea565b610f58565b3480156104a0575f80fd5b506102b66104af366004612f8e565b610fda565b3480156104bf575f80fd5b506103226104ce366004613244565b610fe4565b3480156104de575f80fd5b5061052e604080516080810182525f80825260208201819052918101829052606081019190915250604080516080810182526109c480825260208201819052918101829052606081019190915290565b60405161026d91905f60808201905061ffff835116825261ffff602084015116602083015261ffff604084015116604083015261ffff606084015116606083015292915050565b348015610580575f80fd5b5061028a61058f366004612f8e565b611029565b34801561059f575f80fd5b506102b67f000000000000000000000000000000000000000000000000000000000000000081565b3480156105d2575f80fd5b506103226105e136600461325f565b6110cf565b3480156105f1575f80fd5b506105fa6111ff565b60405161026d97969594939291906132c9565b348015610618575f80fd5b506102b6610627366004612f8e565b611241565b6102ed61063a36600461335f565b611266565b34801561064a575f80fd5b5061028a6115f1565b34801561065e575f80fd5b506102ed61066d366004613390565b611600565b34801561067d575f80fd5b506102b661068c366004612f8e565b61160b565b34801561069c575f80fd5b506106b06106ab366004612f8e565b611633565b60405161026d91906133c7565b3480156106c8575f80fd5b506102ed6106d736600461343e565b611702565b3480156106e7575f80fd5b506102b66106f6366004612f8e565b6117e2565b348015610706575f80fd5b5061071a610715366004612f8e565b611807565b6040805182516001600160a01b03168152602092830151928101929092520161026d565b348015610749575f80fd5b50610322610758366004613473565b611855565b348015610768575f80fd5b506102ed6107773660046134d7565b611c67565b348015610787575f80fd5b5061028a610796366004612f8e565b611c7e565b3480156107a6575f80fd5b5061028a6107b5366004613027565b611cef565b3480156107c5575f80fd5b5061052e6107d4366004612f8e565b611db6565b3480156107e4575f80fd5b506102ed6107f33660046135b5565b611e3a565b348015610803575f80fd5b50610261610812366004613648565b611e53565b348015610822575f80fd5b50610322610831366004613674565b611e80565b348015610841575f80fd5b506102ed6108503660046136b2565b611ec0565b5f6001600160e01b031982166380ac58cd60e01b148061088557506001600160e01b03198216635b5e139f60e01b145b806108a057506301ffc9a760e01b6001600160e01b03198316145b92915050565b60605f80546108b4906136d5565b80601f01602080910402602001604051908101604052809291908181526020018280546108e0906136d5565b801561092b5780601f106109025761010080835404028352916020019161092b565b820191905f5260205f20905b81548152906001019060200180831161090e57829003601f168201915b5050505050905090565b5f61093f82611f96565b505f828152600460205260409020546001600160a01b03166108a0565b610967828233611fce565b5050565b61097483611fdb565b5f83815260096020526040902061098c828483613751565b50336001600160a01b0316837f3a2c7fffc2cba7582c690e3b82c453ea02a308326a98a3ad7576c606336409fb84846040516109c992919061380a565b60405180910390a3505050565b5f6109ef3360405180602001604052805f81525061200f565b905090565b6001600160a01b038216610a2257604051633250574960e11b81525f60048201526024015b60405180910390fd5b5f610a2e838333612097565b9050836001600160a01b0316816001600160a01b031614610a7c576040516364283d7b60e01b81526001600160a01b0380861660048301526024820184905282166044820152606401610a19565b50505050565b610a8b85611fdb565b82421115610aac5760405163086014a960e31b815260040160405180910390fd5b604080517f5a2b87f3673ca6856d85d54cb1a9eb690f53c4d6b0954db34c84fe6c19c80d9460208201529081018690526001600160a01b0385166060820152608081018490525f9060a0016040516020818303038152906040528051906020012090505f610b1982612189565b90505f610b5d85858080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525086939250506121b59050565b9050866001600160a01b0316816001600160a01b031614610b9157604051631468054760e31b815260040160405180910390fd5b610b9b88886121dd565b5050505050505050565b5f6109ef61223a565b5f610bb882612363565b505f908152600c60205260409020600101546001600160a01b031690565b610bf083838360405180602001604052805f815250611c67565b505050565b5f610c358689898080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061200f92505050565b9050610c4181876121dd565b604051806101000160405280876001600160a01b031681526020015f6001600160a01b031681526020015f6001600160a01b031681526020015f6001600160a01b03168152602001876001600160a01b03168152602001866001600160a01b031681526020014281526020015f1515815250600c5f8381526020019081526020015f205f820151815f015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506020820151816001015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506040820151816002015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506060820151816003015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506080820151816004015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060a0820151816005015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c0820151816006015560e0820151816007015f6101000a81548160ff02191690831515021790555090505060405180608001604052806109c461ffff1681526020016109c461ffff1681526020016109c461ffff1681526020016109c461ffff16815250600d5f8381526020019081526020015f205f820151815f015f6101000a81548161ffff021916908361ffff1602179055506020820151815f0160026101000a81548161ffff021916908361ffff1602179055506040820151815f0160046101000a81548161ffff021916908361ffff1602179055506060820151815f0160066101000a81548161ffff021916908361ffff1602179055509050506001600e5f8381526020019081526020015f205f6101000a81548160ff021916908315150217905550856001600160a01b0316866001600160a01b0316827f89722757f90cfe8ec9d33d86a87e69c841579a185b5147ba21b38f740eb0627888604051610f4591906001600160a01b0391909116815260200190565b60405180910390a4979650505050505050565b610f6185611fdb565b610fd38585858080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525050604080516020601f890181900481028201810190925287815292508791508690819084018382808284375f9201919091525061239792505050565b5050505050565b5f6108a08261240c565b5f6001600160a01b03821661100e576040516322718ad960e21b81525f6004820152602401610a19565b506001600160a01b03165f9081526003602052604090205490565b606061103482612363565b5f828152600960205260409020805461104c906136d5565b80601f0160208091040260200160405190810160405280929190818152602001828054611078906136d5565b80156110c35780601f1061109a576101008083540402835291602001916110c3565b820191905f5260205f20905b8154815290600101906020018083116110a657829003601f168201915b50505050509050919050565b5f61110f3386868080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061200f92505050565b90505f5b828110156111f6576111ee8285858481811061113157611131613838565b9050602002810190611143919061384c565b61114d908061386a565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525089925088915086905081811061119557611195613838565b90506020028101906111a7919061384c565b6111b590602081019061386a565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061239792505050565b600101611113565b50949350505050565b5f6060805f805f6060611210612416565b611218612443565b604080515f80825260208201909252600f60f81b9b939a50919850469750309650945092509050565b5f61124b82612363565b505f908152600a60205260409020546001600160a01b031690565b5f838152600e602052604090205460ff1661129457604051633897565360e11b815260040160405180910390fd5b5f838152600c60209081526040808320600d9092529091206001600160a01b03841661144257345f036112da5760405163d1b5cfef60e01b815260040160405180910390fd5b805434905f90612710906112f29061ffff16846138c0565b6112fc91906138d7565b83549091505f906127109061131b9062010000900461ffff16856138c0565b61132591906138d7565b84549091505f906127109061134690640100000000900461ffff16866138c0565b61135091906138d7565b90505f818361135f86886138f6565b61136991906138f6565b61137391906138f6565b600488015490915061138e906001600160a01b031685612470565b86546113a3906001600160a01b031684612470565b60058701546113bb906001600160a01b031683612470565b6113e57f000000000000000000000000000000000000000000000000000000000000000082612470565b604080518681526020810186905290810184905260608101839052608081018290525f908b907f8fb705d20f5abef69e7c2e6d0e82d5c49a9efb5fd40c083c802f095a8bfe00ac9060a00160405180910390a35050505050610fd3565b3415611461576040516355d8111560e01b815260040160405180910390fd5b805484905f90612710906114799061ffff16876138c0565b61148391906138d7565b83549091505f90612710906114a29062010000900461ffff16886138c0565b6114ac91906138d7565b84549091505f90612710906114cd90640100000000900461ffff16896138c0565b6114d791906138d7565b90505f81836114e6868b6138f6565b6114f091906138f6565b6114fa91906138f6565b600488015490915061151b906001600160a01b038781169133911687612510565b8654611536906001600160a01b038781169133911686612510565b6005870154611554906001600160a01b038781169133911685612510565b6115896001600160a01b038616337f000000000000000000000000000000000000000000000000000000000000000084612510565b604080518981526020810186905290810184905260608101839052608081018290526001600160a01b038a16908b907f8fb705d20f5abef69e7c2e6d0e82d5c49a9efb5fd40c083c802f095a8bfe00ac9060a00160405180910390a350505050505050505050565b6060600180546108b4906136d5565b61096733838361256a565b5f61161582612363565b505f908152600c60205260409020600201546001600160a01b031690565b60408051610100810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081019190915261167c82612363565b505f908152600c602090815260409182902082516101008101845281546001600160a01b03908116825260018301548116938201939093526002820154831693810193909352600381015482166060840152600481015482166080840152600581015490911660a0830152600681015460c08301526007015460ff16151560e082015290565b61170b82611fdb565b5f828152600e602052604090205460ff1661173957604051633897565360e11b815260040160405180910390fd5b5f61174a6080830160608401613918565b61ffff1661175e6060840160408501613918565b61ffff166117726040850160208601613918565b61ffff166117836020860186613918565b61ffff166117919190613933565b61179b9190613933565b6117a59190613933565b905080612710146117c95760405163cdb06e4560e01b815260040160405180910390fd5b5f838152600d602052604090208290610fd38282613946565b5f6117ec82612363565b505f908152600c60205260409020546001600160a01b031690565b604080518082019091525f808252602082015261182382612363565b505f908152600f6020908152604091829020825180840190935280546001600160a01b03168352600101549082015290565b6040516331a9108f60e11b8152600481018490525f9081906001600160a01b03871690636352211e90602401602060405180830381865afa15801561189c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118c091906139ef565b90506001600160a01b03811633146118eb5760405163f4d44f1d60e01b815260040160405180910390fd5b6119033360405180602001604052805f81525061200f565b915061190f82336121dd565b6040518060400160405280876001600160a01b0316815260200186815250600f5f8481526020019081526020015f205f820151815f015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060208201518160010155905050604051806101000160405280336001600160a01b031681526020015f6001600160a01b031681526020015f6001600160a01b031681526020015f6001600160a01b03168152602001856001600160a01b03168152602001846001600160a01b031681526020014281526020015f1515815250600c5f8481526020019081526020015f205f820151815f015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506020820151816001015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506040820151816002015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506060820151816003015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506080820151816004015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060a0820151816005015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c0820151816006015560e0820151816007015f6101000a81548160ff02191690831515021790555090505060405180608001604052806109c461ffff1681526020016109c461ffff1681526020016109c461ffff1681526020016109c461ffff16815250600d5f8481526020019081526020015f205f820151815f015f6101000a81548161ffff021916908361ffff1602179055506020820151815f0160026101000a81548161ffff021916908361ffff1602179055506040820151815f0160046101000a81548161ffff021916908361ffff1602179055506060820151815f0160066101000a81548161ffff021916908361ffff1602179055509050506001600e5f8481526020019081526020015f205f6101000a81548160ff02191690831515021790555084866001600160a01b0316837f99b739fa7e8e4de69922e3e97fe4891dd69c63b00e7ff3ba7391c8d20f25428260405160405180910390a450949350505050565b611c728484846109f4565b610a7c84848484612600565b6060611c8982611f96565b505f611c9f60408051602081019091525f815290565b90505f815111611cbd5760405180602001604052805f815250611ce8565b80611cc78461271f565b604051602001611cd8929190613a21565b6040516020818303038152906040525b9392505050565b6060611cfa84612363565b5f848152600b6020526040908190209051611d189085908590613a35565b90815260200160405180910390208054611d31906136d5565b80601f0160208091040260200160405190810160405280929190818152602001828054611d5d906136d5565b8015611da85780601f10611d7f57610100808354040283529160200191611da8565b820191905f5260205f20905b815481529060010190602001808311611d8b57829003601f168201915b505050505090509392505050565b604080516080810182525f808252602082018190529181018290526060810191909152611de282612363565b505f908152600d60209081526040918290208251608081018452905461ffff80821683526201000082048116938301939093526401000000008104831693820193909352660100000000000090920416606082015290565b6040516343f6e4ab60e01b815260040160405180910390fd5b6001600160a01b039182165f90815260056020908152604080832093909416825291909152205460ff1690565b5f611ce83384848080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061200f92505050565b5f828152600e602052604090205460ff16611eee57604051633897565360e11b815260040160405180910390fd5b5f828152600c6020526040902080546001600160a01b03163314611f255760405163497e715760e11b815260040160405180910390fd5b80546001600160a01b038381166001600160a01b0319831617835516611f4b84846121dd565b604080516001600160a01b0380841682528516602082015285917fb88ba391e13cea0a995109e36cb78a23220ce580445e37681253eb34ebd8d831910160405180910390a250505050565b5f818152600260205260408120546001600160a01b0316806108a057604051637e27328960e01b815260048101849052602401610a19565b610bf083838360016127ae565b33611fe582610fda565b6001600160a01b03161461200c576040516338ebc58960e11b815260040160405180910390fd5b50565b600880545f918261201f83613a44565b91905055905061202f83826128b2565b81511561204f575f81815260096020526040902061204d8382613a5c565b505b826001600160a01b0316817fca52e62c367d81bb2e328eb795f7c7ba24afb478408a26c0e201d155c449bc4a846040516120899190612f7c565b60405180910390a392915050565b5f828152600260205260408120546001600160a01b03908116908316156120c3576120c3818486612913565b6001600160a01b038116156120fd576120de5f855f806127ae565b6001600160a01b0381165f90815260036020526040902080545f190190555b6001600160a01b0385161561212b576001600160a01b0385165f908152600360205260409020805460010190555b5f8481526002602052604080822080546001600160a01b0319166001600160a01b0389811691821790925591518793918516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4949350505050565b5f6108a061219561223a565b8360405161190160f01b8152600281019290925260228201526042902090565b5f805f806121c38686612977565b9250925092506121d382826129c0565b5090949350505050565b5f828152600a602052604080822080546001600160a01b031981166001600160a01b038681169182179093559251911692839186917fc8982c1ad4646a1ed6bb40061ac7f2a6aaffef7f2e096aa9805cf705fa12933b91a4505050565b5f306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614801561229257507f000000000000000000000000000000000000000000000000000000000000000046145b156122bc57507f000000000000000000000000000000000000000000000000000000000000000090565b6109ef604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b5f818152600260205260409020546001600160a01b031661200c5760405163c277ab0b60e01b815260040160405180910390fd5b80600b5f8581526020019081526020015f20836040516123b79190613b16565b908152602001604051809103902090816123d19190613a5c565b508180519060200120837f403dd6edbea0d46f3bf2a690b98afd205834e8679b719b9d0ef2becbfb2dc2fa84846040516109c9929190613b21565b5f6108a082612a78565b60606109ef7f00000000000000000000000000000000000000000000000000000000000000006006612a82565b60606109ef7f00000000000000000000000000000000000000000000000000000000000000006007612a82565b805f0361247b575050565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f81146124c4576040519150601f19603f3d011682016040523d82523d5f602084013e6124c9565b606091505b5050905080610bf05760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b6044820152606401610a19565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610a7c908590612b2b565b6001600160a01b03821661259c57604051630b61174360e31b81526001600160a01b0383166004820152602401610a19565b6001600160a01b038381165f81815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3191016109c9565b6001600160a01b0383163b15610a7c57604051630a85bd0160e11b81526001600160a01b0384169063150b7a0290612642903390889087908790600401613b4e565b6020604051808303815f875af192505050801561267c575060408051601f3d908101601f1916820190925261267991810190613b80565b60015b6126e3573d8080156126a9576040519150601f19603f3d011682016040523d82523d5f602084013e6126ae565b606091505b5080515f036126db57604051633250574960e11b81526001600160a01b0385166004820152602401610a19565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b14610fd357604051633250574960e11b81526001600160a01b0385166004820152602401610a19565b60605f61272b83612b8c565b60010190505f816001600160401b03811115612749576127496134c3565b6040519080825280601f01601f191660200182016040528015612773576020820181803683370190505b5090508181016020015b5f19016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461277d57509392505050565b80806127c257506001600160a01b03821615155b15612883575f6127d184611f96565b90506001600160a01b038316158015906127fd5750826001600160a01b0316816001600160a01b031614155b8015612810575061280e8184611e53565b155b156128395760405163a9fbf51f60e01b81526001600160a01b0384166004820152602401610a19565b81156128815783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b50505f90815260046020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0382166128db57604051633250574960e11b81525f6004820152602401610a19565b5f6128e783835f612097565b90506001600160a01b03811615610bf0576040516339e3563760e11b81525f6004820152602401610a19565b61291e838383612c63565b610bf0576001600160a01b03831661294c57604051637e27328960e01b815260048101829052602401610a19565b60405163177e802f60e01b81526001600160a01b038316600482015260248101829052604401610a19565b5f805f83516041036129ae576020840151604085015160608601515f1a6129a088828585612cc7565b9550955095505050506129b9565b505081515f91506002905b9250925092565b5f8260038111156129d3576129d3613b9b565b036129dc575050565b60018260038111156129f0576129f0613b9b565b03612a0e5760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115612a2257612a22613b9b565b03612a435760405163fce698f760e01b815260048101829052602401610a19565b6003826003811115612a5757612a57613b9b565b03610967576040516335e2f38360e21b815260048101829052602401610a19565b5f6108a082611f96565b606060ff8314612a9c57612a9583612d8f565b90506108a0565b818054612aa8906136d5565b80601f0160208091040260200160405190810160405280929190818152602001828054612ad4906136d5565b8015612b1f5780601f10612af657610100808354040283529160200191612b1f565b820191905f5260205f20905b815481529060010190602001808311612b0257829003601f168201915b505050505090506108a0565b5f612b3f6001600160a01b03841683612dcc565b905080515f14158015612b63575080806020019051810190612b619190613baf565b155b15610bf057604051635274afe760e01b81526001600160a01b0384166004820152602401610a19565b5f8072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310612bca5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310612bf6576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310612c1457662386f26fc10000830492506010015b6305f5e1008310612c2c576305f5e100830492506008015b6127108310612c4057612710830492506004015b60648310612c52576064830492506002015b600a83106108a05760010192915050565b5f6001600160a01b03831615801590612cbf5750826001600160a01b0316846001600160a01b03161480612c9c5750612c9c8484611e53565b80612cbf57505f828152600460205260409020546001600160a01b038481169116145b949350505050565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115612d0057505f91506003905082612d85565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015612d51573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b038116612d7c57505f925060019150829050612d85565b92505f91508190505b9450945094915050565b60605f612d9b83612dd9565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b6060611ce883835f612e00565b5f60ff8216601f8111156108a057604051632cd44ac360e21b815260040160405180910390fd5b606081471015612e255760405163cd78605960e01b8152306004820152602401610a19565b5f80856001600160a01b03168486604051612e409190613b16565b5f6040518083038185875af1925050503d805f8114612e7a576040519150601f19603f3d011682016040523d82523d5f602084013e612e7f565b606091505b5091509150612e8f868383612e99565b9695505050505050565b606082612eae57612ea982612ef5565b611ce8565b8151158015612ec557506001600160a01b0384163b155b15612eee57604051639996b31560e01b81526001600160a01b0385166004820152602401610a19565b5080611ce8565b805115612f055780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160e01b03198116811461200c575f80fd5b5f60208284031215612f43575f80fd5b8135611ce881612f1e565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f611ce86020830184612f4e565b5f60208284031215612f9e575f80fd5b5035919050565b6001600160a01b038116811461200c575f80fd5b5f8060408385031215612fca575f80fd5b8235612fd581612fa5565b946020939093013593505050565b5f8083601f840112612ff3575f80fd5b5081356001600160401b03811115613009575f80fd5b602083019150836020828501011115613020575f80fd5b9250929050565b5f805f60408486031215613039575f80fd5b8335925060208401356001600160401b03811115613055575f80fd5b61306186828701612fe3565b9497909650939450505050565b5f805f60608486031215613080575f80fd5b833561308b81612fa5565b9250602084013561309b81612fa5565b929592945050506040919091013590565b5f805f805f608086880312156130c0575f80fd5b8535945060208601356130d281612fa5565b93506040860135925060608601356001600160401b038111156130f3575f80fd5b6130ff88828901612fe3565b969995985093965092949392505050565b5f8083601f840112613120575f80fd5b5081356001600160401b03811115613136575f80fd5b6020830191508360208260051b8501011115613020575f80fd5b5f805f805f805f60a0888a031215613166575f80fd5b87356001600160401b0381111561317b575f80fd5b6131878a828b01612fe3565b909850965050602088013561319b81612fa5565b945060408801356131ab81612fa5565b935060608801356001600160401b038111156131c5575f80fd5b6131d18a828b01613110565b989b979a50959894979596608090950135949350505050565b5f805f805f606086880312156131fe575f80fd5b8535945060208601356001600160401b0381111561321a575f80fd5b61322688828901612fe3565b90955093505060408601356001600160401b038111156130f3575f80fd5b5f60208284031215613254575f80fd5b8135611ce881612fa5565b5f805f8060408587031215613272575f80fd5b84356001600160401b03811115613287575f80fd5b61329387828801612fe3565b90955093505060208501356001600160401b038111156132b1575f80fd5b6132bd87828801613110565b95989497509550505050565b60ff60f81b8816815260e060208201525f6132e760e0830189612f4e565b82810360408401526132f98189612f4e565b606084018890526001600160a01b038716608085015260a0840186905283810360c0850152845180825260208087019350909101905f5b8181101561334e578351835260209384019390920191600101613330565b50909b9a5050505050505050505050565b5f805f60608486031215613371575f80fd5b83359250602084013561309b81612fa5565b801515811461200c575f80fd5b5f80604083850312156133a1575f80fd5b82356133ac81612fa5565b915060208301356133bc81613383565b809150509250929050565b81516001600160a01b03908116825260208084015182169083015260408084015182169083015260608084015182169083015260808084015182169083015260a080840151918216908301526101008201905060c083015160c083015260e083015161343760e084018215159052565b5092915050565b5f8082840360a0811215613450575f80fd5b833592506080601f1982011215613465575f80fd5b506020830190509250929050565b5f805f8060808587031215613486575f80fd5b843561349181612fa5565b93506020850135925060408501356134a881612fa5565b915060608501356134b881612fa5565b939692955090935050565b634e487b7160e01b5f52604160045260245ffd5b5f805f80608085870312156134ea575f80fd5b84356134f581612fa5565b9350602085013561350581612fa5565b92506040850135915060608501356001600160401b03811115613526575f80fd5b8501601f81018713613536575f80fd5b80356001600160401b0381111561354f5761354f6134c3565b604051601f8201601f19908116603f011681016001600160401b038111828210171561357d5761357d6134c3565b604052818152828201602001891015613594575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f805f805f805f60a0888a0312156135cb575f80fd5b8735965060208801356001600160401b038111156135e7575f80fd5b6135f38a828b01612fe3565b90975095505060408801356001600160401b03811115613611575f80fd5b61361d8a828b01612fe3565b90955093505060608801359150608088013561363881612fa5565b8091505092959891949750929550565b5f8060408385031215613659575f80fd5b823561366481612fa5565b915060208301356133bc81612fa5565b5f8060208385031215613685575f80fd5b82356001600160401b0381111561369a575f80fd5b6136a685828601612fe3565b90969095509350505050565b5f80604083850312156136c3575f80fd5b8235915060208301356133bc81612fa5565b600181811c908216806136e957607f821691505b60208210810361370757634e487b7160e01b5f52602260045260245ffd5b50919050565b601f821115610bf057805f5260205f20601f840160051c810160208510156137325750805b601f840160051c820191505b81811015610fd3575f815560010161373e565b6001600160401b03831115613768576137686134c3565b61377c8361377683546136d5565b8361370d565b5f601f8411600181146137ad575f85156137965750838201355b5f19600387901b1c1916600186901b178355610fd3565b5f83815260208120601f198716915b828110156137dc57868501358255602094850194600190920191016137bc565b50868210156137f8575f1960f88860031b161c19848701351681555b505060018560011b0183555050505050565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b634e487b7160e01b5f52603260045260245ffd5b5f8235603e19833603018112613860575f80fd5b9190910192915050565b5f808335601e1984360301811261387f575f80fd5b8301803591506001600160401b03821115613898575f80fd5b602001915036819003821315613020575f80fd5b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176108a0576108a06138ac565b5f826138f157634e487b7160e01b5f52601260045260245ffd5b500490565b818103818111156108a0576108a06138ac565b61ffff8116811461200c575f80fd5b5f60208284031215613928575f80fd5b8135611ce881613909565b808201808211156108a0576108a06138ac565b813561395181613909565b61ffff8116905081548161ffff198216178355602084013561397281613909565b63ffff00008160101b169050808363ffffffff19841617178455604085013561399a81613909565b65ffff000000008160201b168465ffffffffffff198516178317178555505050505f60608301356139ca81613909565b825467ffff000000000000191660309190911b67ffff00000000000016179091555050565b5f602082840312156139ff575f80fd5b8151611ce881612fa5565b5f81518060208401855e5f93019283525090919050565b5f612cbf613a2f8386613a0a565b84613a0a565b818382375f9101908152919050565b5f60018201613a5557613a556138ac565b5060010190565b81516001600160401b03811115613a7557613a756134c3565b613a8981613a8384546136d5565b8461370d565b6020601f821160018114613abb575f8315613aa45750848201515b5f19600385901b1c1916600184901b178455610fd3565b5f84815260208120601f198516915b82811015613aea5787850151825560209485019460019092019101613aca565b5084821015613b0757868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f611ce88284613a0a565b604081525f613b336040830185612f4e565b8281036020840152613b458185612f4e565b95945050505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190525f90612e8f90830184612f4e565b5f60208284031215613b90575f80fd5b8151611ce881612f1e565b634e487b7160e01b5f52602160045260245ffd5b5f60208284031215613bbf575f80fd5b8151611ce88161338356fea26469706673582212205c3d2e7f426fd79d896b3bb4684b096e482abcb09308027776925a0dd27752a964736f6c634300081a00330000000000000000000000005d6d8518a1d564c85ea5c41d1dc0deca70f2301c

Deployed Bytecode

0x60806040526004361061023e575f3560e01c8063803db96d11610134578063adcd2940116100b3578063cb4799f211610078578063cb4799f21461079b578063cdc593df146107ba578063e48a9785146107d9578063e985e9c5146107f8578063f2c298be14610817578063ff591d0f14610836575f80fd5b8063adcd2940146106dc578063b10d8c41146106fb578063b29bbe621461073e578063b88d4fde1461075d578063c87b56dd1461077c575f80fd5b806395d89b41116100f957806395d89b411461063f578063a22cb46514610653578063a2b44d7514610672578063a823778814610691578063abac8e30146106bd575f80fd5b8063803db96d1461059457806384413ec4146105c757806384b0196e146105e6578063851f5d691461060d5780638d72d0571461062c575f80fd5b80633644e515116101c057806359f9f50f1161018557806359f9f50f146104765780636352211e1461049557806370a08231146104b457806377ada3be146104d357806378396cb314610575575f80fd5b80633644e515146103cf5780633de1aaaa146103e357806342842e0e146104025780634f558e791461042157806353115e1814610457575f80fd5b80631aa3a008116102065780631aa3a0081461030e57806323b872dd14610330578063271073721461034f578063296e52181461037d5780632d1ef5ae146103b0575f80fd5b806301ffc9a71461024257806306fdde0314610276578063081812fc14610297578063095ea7b3146102ce5780630af28bd3146102ef575b5f80fd5b34801561024d575f80fd5b5061026161025c366004612f33565b610855565b60405190151581526020015b60405180910390f35b348015610281575f80fd5b5061028a6108a6565b60405161026d9190612f7c565b3480156102a2575f80fd5b506102b66102b1366004612f8e565b610935565b6040516001600160a01b03909116815260200161026d565b3480156102d9575f80fd5b506102ed6102e8366004612fb9565b61095c565b005b3480156102fa575f80fd5b506102ed610309366004613027565b61096b565b348015610319575f80fd5b506103226109d6565b60405190815260200161026d565b34801561033b575f80fd5b506102ed61034a36600461306e565b6109f4565b34801561035a575f80fd5b50610261610369366004612f8e565b5f908152600e602052604090205460ff1690565b348015610388575f80fd5b506103227f5a2b87f3673ca6856d85d54cb1a9eb690f53c4d6b0954db34c84fe6c19c80d9481565b3480156103bb575f80fd5b506102ed6103ca3660046130ac565b610a82565b3480156103da575f80fd5b50610322610ba5565b3480156103ee575f80fd5b506102b66103fd366004612f8e565b610bae565b34801561040d575f80fd5b506102ed61041c36600461306e565b610bd6565b34801561042c575f80fd5b5061026161043b366004612f8e565b5f908152600260205260409020546001600160a01b0316151590565b348015610462575f80fd5b50610322610471366004613150565b610bf5565b348015610481575f80fd5b506102ed6104903660046131ea565b610f58565b3480156104a0575f80fd5b506102b66104af366004612f8e565b610fda565b3480156104bf575f80fd5b506103226104ce366004613244565b610fe4565b3480156104de575f80fd5b5061052e604080516080810182525f80825260208201819052918101829052606081019190915250604080516080810182526109c480825260208201819052918101829052606081019190915290565b60405161026d91905f60808201905061ffff835116825261ffff602084015116602083015261ffff604084015116604083015261ffff606084015116606083015292915050565b348015610580575f80fd5b5061028a61058f366004612f8e565b611029565b34801561059f575f80fd5b506102b67f0000000000000000000000005d6d8518a1d564c85ea5c41d1dc0deca70f2301c81565b3480156105d2575f80fd5b506103226105e136600461325f565b6110cf565b3480156105f1575f80fd5b506105fa6111ff565b60405161026d97969594939291906132c9565b348015610618575f80fd5b506102b6610627366004612f8e565b611241565b6102ed61063a36600461335f565b611266565b34801561064a575f80fd5b5061028a6115f1565b34801561065e575f80fd5b506102ed61066d366004613390565b611600565b34801561067d575f80fd5b506102b661068c366004612f8e565b61160b565b34801561069c575f80fd5b506106b06106ab366004612f8e565b611633565b60405161026d91906133c7565b3480156106c8575f80fd5b506102ed6106d736600461343e565b611702565b3480156106e7575f80fd5b506102b66106f6366004612f8e565b6117e2565b348015610706575f80fd5b5061071a610715366004612f8e565b611807565b6040805182516001600160a01b03168152602092830151928101929092520161026d565b348015610749575f80fd5b50610322610758366004613473565b611855565b348015610768575f80fd5b506102ed6107773660046134d7565b611c67565b348015610787575f80fd5b5061028a610796366004612f8e565b611c7e565b3480156107a6575f80fd5b5061028a6107b5366004613027565b611cef565b3480156107c5575f80fd5b5061052e6107d4366004612f8e565b611db6565b3480156107e4575f80fd5b506102ed6107f33660046135b5565b611e3a565b348015610803575f80fd5b50610261610812366004613648565b611e53565b348015610822575f80fd5b50610322610831366004613674565b611e80565b348015610841575f80fd5b506102ed6108503660046136b2565b611ec0565b5f6001600160e01b031982166380ac58cd60e01b148061088557506001600160e01b03198216635b5e139f60e01b145b806108a057506301ffc9a760e01b6001600160e01b03198316145b92915050565b60605f80546108b4906136d5565b80601f01602080910402602001604051908101604052809291908181526020018280546108e0906136d5565b801561092b5780601f106109025761010080835404028352916020019161092b565b820191905f5260205f20905b81548152906001019060200180831161090e57829003601f168201915b5050505050905090565b5f61093f82611f96565b505f828152600460205260409020546001600160a01b03166108a0565b610967828233611fce565b5050565b61097483611fdb565b5f83815260096020526040902061098c828483613751565b50336001600160a01b0316837f3a2c7fffc2cba7582c690e3b82c453ea02a308326a98a3ad7576c606336409fb84846040516109c992919061380a565b60405180910390a3505050565b5f6109ef3360405180602001604052805f81525061200f565b905090565b6001600160a01b038216610a2257604051633250574960e11b81525f60048201526024015b60405180910390fd5b5f610a2e838333612097565b9050836001600160a01b0316816001600160a01b031614610a7c576040516364283d7b60e01b81526001600160a01b0380861660048301526024820184905282166044820152606401610a19565b50505050565b610a8b85611fdb565b82421115610aac5760405163086014a960e31b815260040160405180910390fd5b604080517f5a2b87f3673ca6856d85d54cb1a9eb690f53c4d6b0954db34c84fe6c19c80d9460208201529081018690526001600160a01b0385166060820152608081018490525f9060a0016040516020818303038152906040528051906020012090505f610b1982612189565b90505f610b5d85858080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525086939250506121b59050565b9050866001600160a01b0316816001600160a01b031614610b9157604051631468054760e31b815260040160405180910390fd5b610b9b88886121dd565b5050505050505050565b5f6109ef61223a565b5f610bb882612363565b505f908152600c60205260409020600101546001600160a01b031690565b610bf083838360405180602001604052805f815250611c67565b505050565b5f610c358689898080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061200f92505050565b9050610c4181876121dd565b604051806101000160405280876001600160a01b031681526020015f6001600160a01b031681526020015f6001600160a01b031681526020015f6001600160a01b03168152602001876001600160a01b03168152602001866001600160a01b031681526020014281526020015f1515815250600c5f8381526020019081526020015f205f820151815f015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506020820151816001015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506040820151816002015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506060820151816003015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506080820151816004015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060a0820151816005015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c0820151816006015560e0820151816007015f6101000a81548160ff02191690831515021790555090505060405180608001604052806109c461ffff1681526020016109c461ffff1681526020016109c461ffff1681526020016109c461ffff16815250600d5f8381526020019081526020015f205f820151815f015f6101000a81548161ffff021916908361ffff1602179055506020820151815f0160026101000a81548161ffff021916908361ffff1602179055506040820151815f0160046101000a81548161ffff021916908361ffff1602179055506060820151815f0160066101000a81548161ffff021916908361ffff1602179055509050506001600e5f8381526020019081526020015f205f6101000a81548160ff021916908315150217905550856001600160a01b0316866001600160a01b0316827f89722757f90cfe8ec9d33d86a87e69c841579a185b5147ba21b38f740eb0627888604051610f4591906001600160a01b0391909116815260200190565b60405180910390a4979650505050505050565b610f6185611fdb565b610fd38585858080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525050604080516020601f890181900481028201810190925287815292508791508690819084018382808284375f9201919091525061239792505050565b5050505050565b5f6108a08261240c565b5f6001600160a01b03821661100e576040516322718ad960e21b81525f6004820152602401610a19565b506001600160a01b03165f9081526003602052604090205490565b606061103482612363565b5f828152600960205260409020805461104c906136d5565b80601f0160208091040260200160405190810160405280929190818152602001828054611078906136d5565b80156110c35780601f1061109a576101008083540402835291602001916110c3565b820191905f5260205f20905b8154815290600101906020018083116110a657829003601f168201915b50505050509050919050565b5f61110f3386868080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061200f92505050565b90505f5b828110156111f6576111ee8285858481811061113157611131613838565b9050602002810190611143919061384c565b61114d908061386a565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525089925088915086905081811061119557611195613838565b90506020028101906111a7919061384c565b6111b590602081019061386a565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061239792505050565b600101611113565b50949350505050565b5f6060805f805f6060611210612416565b611218612443565b604080515f80825260208201909252600f60f81b9b939a50919850469750309650945092509050565b5f61124b82612363565b505f908152600a60205260409020546001600160a01b031690565b5f838152600e602052604090205460ff1661129457604051633897565360e11b815260040160405180910390fd5b5f838152600c60209081526040808320600d9092529091206001600160a01b03841661144257345f036112da5760405163d1b5cfef60e01b815260040160405180910390fd5b805434905f90612710906112f29061ffff16846138c0565b6112fc91906138d7565b83549091505f906127109061131b9062010000900461ffff16856138c0565b61132591906138d7565b84549091505f906127109061134690640100000000900461ffff16866138c0565b61135091906138d7565b90505f818361135f86886138f6565b61136991906138f6565b61137391906138f6565b600488015490915061138e906001600160a01b031685612470565b86546113a3906001600160a01b031684612470565b60058701546113bb906001600160a01b031683612470565b6113e57f0000000000000000000000005d6d8518a1d564c85ea5c41d1dc0deca70f2301c82612470565b604080518681526020810186905290810184905260608101839052608081018290525f908b907f8fb705d20f5abef69e7c2e6d0e82d5c49a9efb5fd40c083c802f095a8bfe00ac9060a00160405180910390a35050505050610fd3565b3415611461576040516355d8111560e01b815260040160405180910390fd5b805484905f90612710906114799061ffff16876138c0565b61148391906138d7565b83549091505f90612710906114a29062010000900461ffff16886138c0565b6114ac91906138d7565b84549091505f90612710906114cd90640100000000900461ffff16896138c0565b6114d791906138d7565b90505f81836114e6868b6138f6565b6114f091906138f6565b6114fa91906138f6565b600488015490915061151b906001600160a01b038781169133911687612510565b8654611536906001600160a01b038781169133911686612510565b6005870154611554906001600160a01b038781169133911685612510565b6115896001600160a01b038616337f0000000000000000000000005d6d8518a1d564c85ea5c41d1dc0deca70f2301c84612510565b604080518981526020810186905290810184905260608101839052608081018290526001600160a01b038a16908b907f8fb705d20f5abef69e7c2e6d0e82d5c49a9efb5fd40c083c802f095a8bfe00ac9060a00160405180910390a350505050505050505050565b6060600180546108b4906136d5565b61096733838361256a565b5f61161582612363565b505f908152600c60205260409020600201546001600160a01b031690565b60408051610100810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081019190915261167c82612363565b505f908152600c602090815260409182902082516101008101845281546001600160a01b03908116825260018301548116938201939093526002820154831693810193909352600381015482166060840152600481015482166080840152600581015490911660a0830152600681015460c08301526007015460ff16151560e082015290565b61170b82611fdb565b5f828152600e602052604090205460ff1661173957604051633897565360e11b815260040160405180910390fd5b5f61174a6080830160608401613918565b61ffff1661175e6060840160408501613918565b61ffff166117726040850160208601613918565b61ffff166117836020860186613918565b61ffff166117919190613933565b61179b9190613933565b6117a59190613933565b905080612710146117c95760405163cdb06e4560e01b815260040160405180910390fd5b5f838152600d602052604090208290610fd38282613946565b5f6117ec82612363565b505f908152600c60205260409020546001600160a01b031690565b604080518082019091525f808252602082015261182382612363565b505f908152600f6020908152604091829020825180840190935280546001600160a01b03168352600101549082015290565b6040516331a9108f60e11b8152600481018490525f9081906001600160a01b03871690636352211e90602401602060405180830381865afa15801561189c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118c091906139ef565b90506001600160a01b03811633146118eb5760405163f4d44f1d60e01b815260040160405180910390fd5b6119033360405180602001604052805f81525061200f565b915061190f82336121dd565b6040518060400160405280876001600160a01b0316815260200186815250600f5f8481526020019081526020015f205f820151815f015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060208201518160010155905050604051806101000160405280336001600160a01b031681526020015f6001600160a01b031681526020015f6001600160a01b031681526020015f6001600160a01b03168152602001856001600160a01b03168152602001846001600160a01b031681526020014281526020015f1515815250600c5f8481526020019081526020015f205f820151815f015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506020820151816001015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506040820151816002015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506060820151816003015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055506080820151816004015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060a0820151816005015f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c0820151816006015560e0820151816007015f6101000a81548160ff02191690831515021790555090505060405180608001604052806109c461ffff1681526020016109c461ffff1681526020016109c461ffff1681526020016109c461ffff16815250600d5f8481526020019081526020015f205f820151815f015f6101000a81548161ffff021916908361ffff1602179055506020820151815f0160026101000a81548161ffff021916908361ffff1602179055506040820151815f0160046101000a81548161ffff021916908361ffff1602179055506060820151815f0160066101000a81548161ffff021916908361ffff1602179055509050506001600e5f8481526020019081526020015f205f6101000a81548160ff02191690831515021790555084866001600160a01b0316837f99b739fa7e8e4de69922e3e97fe4891dd69c63b00e7ff3ba7391c8d20f25428260405160405180910390a450949350505050565b611c728484846109f4565b610a7c84848484612600565b6060611c8982611f96565b505f611c9f60408051602081019091525f815290565b90505f815111611cbd5760405180602001604052805f815250611ce8565b80611cc78461271f565b604051602001611cd8929190613a21565b6040516020818303038152906040525b9392505050565b6060611cfa84612363565b5f848152600b6020526040908190209051611d189085908590613a35565b90815260200160405180910390208054611d31906136d5565b80601f0160208091040260200160405190810160405280929190818152602001828054611d5d906136d5565b8015611da85780601f10611d7f57610100808354040283529160200191611da8565b820191905f5260205f20905b815481529060010190602001808311611d8b57829003601f168201915b505050505090509392505050565b604080516080810182525f808252602082018190529181018290526060810191909152611de282612363565b505f908152600d60209081526040918290208251608081018452905461ffff80821683526201000082048116938301939093526401000000008104831693820193909352660100000000000090920416606082015290565b6040516343f6e4ab60e01b815260040160405180910390fd5b6001600160a01b039182165f90815260056020908152604080832093909416825291909152205460ff1690565b5f611ce83384848080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061200f92505050565b5f828152600e602052604090205460ff16611eee57604051633897565360e11b815260040160405180910390fd5b5f828152600c6020526040902080546001600160a01b03163314611f255760405163497e715760e11b815260040160405180910390fd5b80546001600160a01b038381166001600160a01b0319831617835516611f4b84846121dd565b604080516001600160a01b0380841682528516602082015285917fb88ba391e13cea0a995109e36cb78a23220ce580445e37681253eb34ebd8d831910160405180910390a250505050565b5f818152600260205260408120546001600160a01b0316806108a057604051637e27328960e01b815260048101849052602401610a19565b610bf083838360016127ae565b33611fe582610fda565b6001600160a01b03161461200c576040516338ebc58960e11b815260040160405180910390fd5b50565b600880545f918261201f83613a44565b91905055905061202f83826128b2565b81511561204f575f81815260096020526040902061204d8382613a5c565b505b826001600160a01b0316817fca52e62c367d81bb2e328eb795f7c7ba24afb478408a26c0e201d155c449bc4a846040516120899190612f7c565b60405180910390a392915050565b5f828152600260205260408120546001600160a01b03908116908316156120c3576120c3818486612913565b6001600160a01b038116156120fd576120de5f855f806127ae565b6001600160a01b0381165f90815260036020526040902080545f190190555b6001600160a01b0385161561212b576001600160a01b0385165f908152600360205260409020805460010190555b5f8481526002602052604080822080546001600160a01b0319166001600160a01b0389811691821790925591518793918516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4949350505050565b5f6108a061219561223a565b8360405161190160f01b8152600281019290925260228201526042902090565b5f805f806121c38686612977565b9250925092506121d382826129c0565b5090949350505050565b5f828152600a602052604080822080546001600160a01b031981166001600160a01b038681169182179093559251911692839186917fc8982c1ad4646a1ed6bb40061ac7f2a6aaffef7f2e096aa9805cf705fa12933b91a4505050565b5f306001600160a01b037f000000000000000000000000f2709cef1cf4893ed78d3220864428b32b12dfb91614801561229257507f000000000000000000000000000000000000000000000000000000000000210546145b156122bc57507f11fc6e7e0c91c985549f715b0580091552087c67cad25e729f68dfb40886742490565b6109ef604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527fbfd1fd769158287ec115d502fec1ecea18e2ea1a3156bfe3bd4768d54e3dd7cb918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b5f818152600260205260409020546001600160a01b031661200c5760405163c277ab0b60e01b815260040160405180910390fd5b80600b5f8581526020019081526020015f20836040516123b79190613b16565b908152602001604051809103902090816123d19190613a5c565b508180519060200120837f403dd6edbea0d46f3bf2a690b98afd205834e8679b719b9d0ef2becbfb2dc2fa84846040516109c9929190613b21565b5f6108a082612a78565b60606109ef7f537069726974205265676973747279000000000000000000000000000000000f6006612a82565b60606109ef7f31000000000000000000000000000000000000000000000000000000000000016007612a82565b805f0361247b575050565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f81146124c4576040519150601f19603f3d011682016040523d82523d5f602084013e6124c9565b606091505b5050905080610bf05760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b6044820152606401610a19565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610a7c908590612b2b565b6001600160a01b03821661259c57604051630b61174360e31b81526001600160a01b0383166004820152602401610a19565b6001600160a01b038381165f81815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3191016109c9565b6001600160a01b0383163b15610a7c57604051630a85bd0160e11b81526001600160a01b0384169063150b7a0290612642903390889087908790600401613b4e565b6020604051808303815f875af192505050801561267c575060408051601f3d908101601f1916820190925261267991810190613b80565b60015b6126e3573d8080156126a9576040519150601f19603f3d011682016040523d82523d5f602084013e6126ae565b606091505b5080515f036126db57604051633250574960e11b81526001600160a01b0385166004820152602401610a19565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b14610fd357604051633250574960e11b81526001600160a01b0385166004820152602401610a19565b60605f61272b83612b8c565b60010190505f816001600160401b03811115612749576127496134c3565b6040519080825280601f01601f191660200182016040528015612773576020820181803683370190505b5090508181016020015b5f19016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461277d57509392505050565b80806127c257506001600160a01b03821615155b15612883575f6127d184611f96565b90506001600160a01b038316158015906127fd5750826001600160a01b0316816001600160a01b031614155b8015612810575061280e8184611e53565b155b156128395760405163a9fbf51f60e01b81526001600160a01b0384166004820152602401610a19565b81156128815783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b50505f90815260046020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b0382166128db57604051633250574960e11b81525f6004820152602401610a19565b5f6128e783835f612097565b90506001600160a01b03811615610bf0576040516339e3563760e11b81525f6004820152602401610a19565b61291e838383612c63565b610bf0576001600160a01b03831661294c57604051637e27328960e01b815260048101829052602401610a19565b60405163177e802f60e01b81526001600160a01b038316600482015260248101829052604401610a19565b5f805f83516041036129ae576020840151604085015160608601515f1a6129a088828585612cc7565b9550955095505050506129b9565b505081515f91506002905b9250925092565b5f8260038111156129d3576129d3613b9b565b036129dc575050565b60018260038111156129f0576129f0613b9b565b03612a0e5760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115612a2257612a22613b9b565b03612a435760405163fce698f760e01b815260048101829052602401610a19565b6003826003811115612a5757612a57613b9b565b03610967576040516335e2f38360e21b815260048101829052602401610a19565b5f6108a082611f96565b606060ff8314612a9c57612a9583612d8f565b90506108a0565b818054612aa8906136d5565b80601f0160208091040260200160405190810160405280929190818152602001828054612ad4906136d5565b8015612b1f5780601f10612af657610100808354040283529160200191612b1f565b820191905f5260205f20905b815481529060010190602001808311612b0257829003601f168201915b505050505090506108a0565b5f612b3f6001600160a01b03841683612dcc565b905080515f14158015612b63575080806020019051810190612b619190613baf565b155b15610bf057604051635274afe760e01b81526001600160a01b0384166004820152602401610a19565b5f8072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310612bca5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310612bf6576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310612c1457662386f26fc10000830492506010015b6305f5e1008310612c2c576305f5e100830492506008015b6127108310612c4057612710830492506004015b60648310612c52576064830492506002015b600a83106108a05760010192915050565b5f6001600160a01b03831615801590612cbf5750826001600160a01b0316846001600160a01b03161480612c9c5750612c9c8484611e53565b80612cbf57505f828152600460205260409020546001600160a01b038481169116145b949350505050565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115612d0057505f91506003905082612d85565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015612d51573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b038116612d7c57505f925060019150829050612d85565b92505f91508190505b9450945094915050565b60605f612d9b83612dd9565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b6060611ce883835f612e00565b5f60ff8216601f8111156108a057604051632cd44ac360e21b815260040160405180910390fd5b606081471015612e255760405163cd78605960e01b8152306004820152602401610a19565b5f80856001600160a01b03168486604051612e409190613b16565b5f6040518083038185875af1925050503d805f8114612e7a576040519150601f19603f3d011682016040523d82523d5f602084013e612e7f565b606091505b5091509150612e8f868383612e99565b9695505050505050565b606082612eae57612ea982612ef5565b611ce8565b8151158015612ec557506001600160a01b0384163b155b15612eee57604051639996b31560e01b81526001600160a01b0385166004820152602401610a19565b5080611ce8565b805115612f055780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6001600160e01b03198116811461200c575f80fd5b5f60208284031215612f43575f80fd5b8135611ce881612f1e565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f611ce86020830184612f4e565b5f60208284031215612f9e575f80fd5b5035919050565b6001600160a01b038116811461200c575f80fd5b5f8060408385031215612fca575f80fd5b8235612fd581612fa5565b946020939093013593505050565b5f8083601f840112612ff3575f80fd5b5081356001600160401b03811115613009575f80fd5b602083019150836020828501011115613020575f80fd5b9250929050565b5f805f60408486031215613039575f80fd5b8335925060208401356001600160401b03811115613055575f80fd5b61306186828701612fe3565b9497909650939450505050565b5f805f60608486031215613080575f80fd5b833561308b81612fa5565b9250602084013561309b81612fa5565b929592945050506040919091013590565b5f805f805f608086880312156130c0575f80fd5b8535945060208601356130d281612fa5565b93506040860135925060608601356001600160401b038111156130f3575f80fd5b6130ff88828901612fe3565b969995985093965092949392505050565b5f8083601f840112613120575f80fd5b5081356001600160401b03811115613136575f80fd5b6020830191508360208260051b8501011115613020575f80fd5b5f805f805f805f60a0888a031215613166575f80fd5b87356001600160401b0381111561317b575f80fd5b6131878a828b01612fe3565b909850965050602088013561319b81612fa5565b945060408801356131ab81612fa5565b935060608801356001600160401b038111156131c5575f80fd5b6131d18a828b01613110565b989b979a50959894979596608090950135949350505050565b5f805f805f606086880312156131fe575f80fd5b8535945060208601356001600160401b0381111561321a575f80fd5b61322688828901612fe3565b90955093505060408601356001600160401b038111156130f3575f80fd5b5f60208284031215613254575f80fd5b8135611ce881612fa5565b5f805f8060408587031215613272575f80fd5b84356001600160401b03811115613287575f80fd5b61329387828801612fe3565b90955093505060208501356001600160401b038111156132b1575f80fd5b6132bd87828801613110565b95989497509550505050565b60ff60f81b8816815260e060208201525f6132e760e0830189612f4e565b82810360408401526132f98189612f4e565b606084018890526001600160a01b038716608085015260a0840186905283810360c0850152845180825260208087019350909101905f5b8181101561334e578351835260209384019390920191600101613330565b50909b9a5050505050505050505050565b5f805f60608486031215613371575f80fd5b83359250602084013561309b81612fa5565b801515811461200c575f80fd5b5f80604083850312156133a1575f80fd5b82356133ac81612fa5565b915060208301356133bc81613383565b809150509250929050565b81516001600160a01b03908116825260208084015182169083015260408084015182169083015260608084015182169083015260808084015182169083015260a080840151918216908301526101008201905060c083015160c083015260e083015161343760e084018215159052565b5092915050565b5f8082840360a0811215613450575f80fd5b833592506080601f1982011215613465575f80fd5b506020830190509250929050565b5f805f8060808587031215613486575f80fd5b843561349181612fa5565b93506020850135925060408501356134a881612fa5565b915060608501356134b881612fa5565b939692955090935050565b634e487b7160e01b5f52604160045260245ffd5b5f805f80608085870312156134ea575f80fd5b84356134f581612fa5565b9350602085013561350581612fa5565b92506040850135915060608501356001600160401b03811115613526575f80fd5b8501601f81018713613536575f80fd5b80356001600160401b0381111561354f5761354f6134c3565b604051601f8201601f19908116603f011681016001600160401b038111828210171561357d5761357d6134c3565b604052818152828201602001891015613594575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f805f805f805f60a0888a0312156135cb575f80fd5b8735965060208801356001600160401b038111156135e7575f80fd5b6135f38a828b01612fe3565b90975095505060408801356001600160401b03811115613611575f80fd5b61361d8a828b01612fe3565b90955093505060608801359150608088013561363881612fa5565b8091505092959891949750929550565b5f8060408385031215613659575f80fd5b823561366481612fa5565b915060208301356133bc81612fa5565b5f8060208385031215613685575f80fd5b82356001600160401b0381111561369a575f80fd5b6136a685828601612fe3565b90969095509350505050565b5f80604083850312156136c3575f80fd5b8235915060208301356133bc81612fa5565b600181811c908216806136e957607f821691505b60208210810361370757634e487b7160e01b5f52602260045260245ffd5b50919050565b601f821115610bf057805f5260205f20601f840160051c810160208510156137325750805b601f840160051c820191505b81811015610fd3575f815560010161373e565b6001600160401b03831115613768576137686134c3565b61377c8361377683546136d5565b8361370d565b5f601f8411600181146137ad575f85156137965750838201355b5f19600387901b1c1916600186901b178355610fd3565b5f83815260208120601f198716915b828110156137dc57868501358255602094850194600190920191016137bc565b50868210156137f8575f1960f88860031b161c19848701351681555b505060018560011b0183555050505050565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b634e487b7160e01b5f52603260045260245ffd5b5f8235603e19833603018112613860575f80fd5b9190910192915050565b5f808335601e1984360301811261387f575f80fd5b8301803591506001600160401b03821115613898575f80fd5b602001915036819003821315613020575f80fd5b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176108a0576108a06138ac565b5f826138f157634e487b7160e01b5f52601260045260245ffd5b500490565b818103818111156108a0576108a06138ac565b61ffff8116811461200c575f80fd5b5f60208284031215613928575f80fd5b8135611ce881613909565b808201808211156108a0576108a06138ac565b813561395181613909565b61ffff8116905081548161ffff198216178355602084013561397281613909565b63ffff00008160101b169050808363ffffffff19841617178455604085013561399a81613909565b65ffff000000008160201b168465ffffffffffff198516178317178555505050505f60608301356139ca81613909565b825467ffff000000000000191660309190911b67ffff00000000000016179091555050565b5f602082840312156139ff575f80fd5b8151611ce881612fa5565b5f81518060208401855e5f93019283525090919050565b5f612cbf613a2f8386613a0a565b84613a0a565b818382375f9101908152919050565b5f60018201613a5557613a556138ac565b5060010190565b81516001600160401b03811115613a7557613a756134c3565b613a8981613a8384546136d5565b8461370d565b6020601f821160018114613abb575f8315613aa45750848201515b5f19600385901b1c1916600184901b178455610fd3565b5f84815260208120601f198516915b82811015613aea5787850151825560209485019460019092019101613aca565b5084821015613b0757868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f611ce88284613a0a565b604081525f613b336040830185612f4e565b8281036020840152613b458185612f4e565b95945050505050565b6001600160a01b03858116825284166020820152604081018390526080606082018190525f90612e8f90830184612f4e565b5f60208284031215613b90575f80fd5b8151611ce881612f1e565b634e487b7160e01b5f52602160045260245ffd5b5f60208284031215613bbf575f80fd5b8151611ce88161338356fea26469706673582212205c3d2e7f426fd79d896b3bb4684b096e482abcb09308027776925a0dd27752a964736f6c634300081a0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000005d6d8518a1d564c85ea5c41d1dc0deca70f2301c

-----Decoded View---------------
Arg [0] : protocolTreasury_ (address): 0x5D6D8518A1d564c85ea5c41d1dc0deca70F2301C

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000005d6d8518a1d564c85ea5c41d1dc0deca70f2301c


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.