creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/Avocado.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.18;\n\n/// @title   IAvocado\n/// @notice  interface to access internal vars on-chain\ninterface IAvocado {\n    function _avoImpl() external view returns (address);\n\n    function _data() external view returns (uint256);\n\n    function _owner() external view returns (address);\n}\n\n/// @title      Avocado\n/// @notice     Proxy for Avocados as deployed by the AvoFactory.\n///             Basic Proxy with fallback to delegate and address for implementation contract at storage 0x0\n//\n// @dev        If this contract changes then the deployment addresses for new Avocados through factory change too!!\n//             Relayers might want to pass in version as new param then to forward to the correct factory\ncontract Avocado {\n    /// @notice flexible immutable data slot.\n    /// first 20 bytes: address owner\n    /// next 4 bytes: uint32 index\n    /// next 1 byte: uint8 type\n    /// next 9 bytes: used flexible for use-cases found in the future\n    uint256 internal immutable _data;\n\n    /// @notice address of the Avocado logic / implementation contract. IMPORTANT: SAME STORAGE SLOT AS FOR PROXY\n    //\n    // @dev    _avoImpl MUST ALWAYS be the first declared variable here in the proxy and in the logic contract\n    //         when upgrading, the storage at memory address 0x0 is upgraded (first slot).\n    //         To reduce deployment costs this variable is internal but can still be retrieved with\n    //         _avoImpl(), see code and comments in fallback below\n    address internal _avoImpl;\n\n    /// @notice   sets _avoImpl & immutable _data, fetching it from msg.sender.\n    //\n    // @dev      those values are not input params to not influence the deterministic Create2 address!\n    constructor() {\n        // \"\\x8c\\x65\\x73\\x89\" is hardcoded bytes of function selector for transientDeployData()\n        (, bytes memory deployData_) = msg.sender.staticcall(bytes(\"\\x8c\\x65\\x73\\x89\"));\n\n        address impl_;\n        uint256 data_;\n        assembly {\n            // cast first 20 bytes to version address (_avoImpl)\n            impl_ := mload(add(deployData_, 0x20))\n\n            // cast bytes in position 0x40 to uint256 data; deployData_ plus 0x40 due to padding\n            data_ := mload(add(deployData_, 0x40))\n        }\n\n        _data = data_;\n        _avoImpl = impl_;\n    }\n\n    /// @notice Delegates the current call to `_avoImpl` unless one of the view methods is called:\n    ///         `_avoImpl()` returns the address for `_avoImpl`, `_owner()` returns the first\n    ///         20 bytes of `_data`, `_data()` returns `_data`.\n    //\n    // @dev    Mostly based on OpenZeppelin Proxy.sol\n    // logic contract must not implement a function `_avoImpl()`, `_owner()` or  `_data()`\n    // as they will not be callable due to collision\n    fallback() external payable {\n        uint256 data_ = _data;\n        assembly {\n            let functionSelector_ := calldataload(0)\n\n            // 0xb2bdfa7b = function selector for _owner()\n            if eq(functionSelector_, 0xb2bdfa7b00000000000000000000000000000000000000000000000000000000) {\n                // store address owner at memory address 0x0, loading only last 20 bytes through the & mask\n                mstore(0, and(data_, 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff))\n                return(0, 0x20) // send 32 bytes of memory slot 0 as return value\n            }\n\n            // 0x68beab3f = function selector for _data()\n            if eq(functionSelector_, 0x68beab3f00000000000000000000000000000000000000000000000000000000) {\n                mstore(0, data_) // store uint256 _data at memory address 0x0\n                return(0, 0x20) // send 32 bytes of memory slot 0 as return value\n            }\n\n            // load address avoImpl_ from storage\n            let avoImpl_ := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)\n\n            // first 4 bytes of calldata specify which function to call.\n            // if those first 4 bytes == 874095c6 (function selector for _avoImpl()) then we return the _avoImpl address\n            // The value is right padded to 32-bytes with 0s\n            if eq(functionSelector_, 0x874095c600000000000000000000000000000000000000000000000000000000) {\n                mstore(0, avoImpl_) // store address avoImpl_ at memory address 0x0\n                return(0, 0x20) // send 32 bytes of memory slot 0 as return value\n            }\n\n            // @dev code below is taken from OpenZeppelin Proxy.sol _delegate function\n\n            // Copy msg.data. We take full control of memory in this inline assembly\n            // block because it will not return to Solidity code. We overwrite the\n            // Solidity scratch pad at memory position 0.\n            calldatacopy(0, 0, calldatasize())\n\n            // Call the implementation.\n            // out and outsize are 0 because we don't know the size yet.\n            let result := delegatecall(gas(), avoImpl_, 0, calldatasize(), 0, 0)\n\n            // Copy the returned data.\n            returndatacopy(0, 0, returndatasize())\n\n            switch result\n            // delegatecall returns 0 on error.\n            case 0 {\n                revert(0, returndatasize())\n            }\n            default {\n                return(0, returndatasize())\n            }\n        }\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 10000000
      },
      "libraries": {},
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      }
    }
  }}