creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/persistent/external-positions/ExternalPositionProxy.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\n\n/*\n    This file is part of the Enzyme Protocol.\n    (c) Enzyme Council <council@enzyme.finance>\n    For the full license information, please view the LICENSE\n    file that was distributed with this source code.\n*/\n\npragma solidity 0.6.12;\n\nimport \"../vault/interfaces/IExternalPositionVault.sol\";\nimport \"./IExternalPosition.sol\";\nimport \"./IExternalPositionProxy.sol\";\n\n/// @title ExternalPositionProxy Contract\n/// @author Enzyme Council <security@enzyme.finance>\n/// @notice A proxy for all external positions, modified from EIP-1822\ncontract ExternalPositionProxy is IExternalPositionProxy {\n    uint256 private immutable EXTERNAL_POSITION_TYPE;\n    address private immutable VAULT_PROXY;\n\n    /// @dev Needed to receive ETH on external positions\n    receive() external payable {}\n\n    constructor(\n        address _vaultProxy,\n        uint256 _typeId,\n        address _constructLib,\n        bytes memory _constructData\n    ) public {\n        VAULT_PROXY = _vaultProxy;\n        EXTERNAL_POSITION_TYPE = _typeId;\n\n        (bool success, bytes memory returnData) = _constructLib.delegatecall(_constructData);\n\n        require(success, string(returnData));\n    }\n\n    // solhint-disable-next-line no-complex-fallback\n    fallback() external payable {\n        address contractLogic = IExternalPositionVault(getVaultProxy())\n            .getExternalPositionLibForType(getExternalPositionType());\n        assembly {\n            calldatacopy(0x0, 0x0, calldatasize())\n            let success := delegatecall(\n                sub(gas(), 10000),\n                contractLogic,\n                0x0,\n                calldatasize(),\n                0,\n                0\n            )\n            let retSz := returndatasize()\n            returndatacopy(0, 0, retSz)\n            switch success\n                case 0 {\n                    revert(0, retSz)\n                }\n                default {\n                    return(0, retSz)\n                }\n        }\n    }\n\n    /// @notice Delegates call to IExternalPosition.receiveCallFromVault\n    /// @param _data The bytes data variable to be decoded at the External Position\n    function receiveCallFromVault(bytes calldata _data) external {\n        require(\n            msg.sender == getVaultProxy(),\n            \"receiveCallFromVault: Only the vault can make this call\"\n        );\n        address contractLogic = IExternalPositionVault(getVaultProxy())\n            .getExternalPositionLibForType(getExternalPositionType());\n        (bool success, bytes memory returnData) = contractLogic.delegatecall(\n            abi.encodeWithSelector(IExternalPosition.receiveCallFromVault.selector, _data)\n        );\n\n        require(success, string(returnData));\n    }\n\n    ///////////////////\n    // STATE GETTERS //\n    ///////////////////\n\n    /// @notice Gets the `EXTERNAL_POSITION_TYPE` variable\n    /// @return externalPositionType_ The `EXTERNAL_POSITION_TYPE` variable value\n    function getExternalPositionType()\n        public\n        view\n        override\n        returns (uint256 externalPositionType_)\n    {\n        return EXTERNAL_POSITION_TYPE;\n    }\n\n    /// @notice Gets the `VAULT_PROXY` variable\n    /// @return vaultProxy_ The `VAULT_PROXY` variable value\n    function getVaultProxy() public view override returns (address vaultProxy_) {\n        return VAULT_PROXY;\n    }\n}\n"
      },
      "contracts/persistent/vault/interfaces/IExternalPositionVault.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\n\n/*\n    This file is part of the Enzyme Protocol.\n\n    (c) Enzyme Council <council@enzyme.finance>\n\n    For the full license information, please view the LICENSE\n    file that was distributed with this source code.\n*/\n\npragma solidity 0.6.12;\n\n/// @title IExternalPositionVault interface\n/// @author Enzyme Council <security@enzyme.finance>\n/// Provides an interface to get the externalPositionLib for a given type from the Vault\ninterface IExternalPositionVault {\n    function getExternalPositionLibForType(uint256) external view returns (address);\n}\n"
      },
      "contracts/persistent/external-positions/IExternalPosition.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\n\n/*\n    This file is part of the Enzyme Protocol.\n    (c) Enzyme Council <council@enzyme.finance>\n    For the full license information, please view the LICENSE\n    file that was distributed with this source code.\n*/\n\npragma solidity 0.6.12;\n\n/// @title IExternalPosition Contract\n/// @author Enzyme Council <security@enzyme.finance>\ninterface IExternalPosition {\n    function getDebtAssets() external returns (address[] memory, uint256[] memory);\n\n    function getManagedAssets() external returns (address[] memory, uint256[] memory);\n\n    function init(bytes memory) external;\n\n    function receiveCallFromVault(bytes memory) external;\n}\n"
      },
      "contracts/persistent/external-positions/IExternalPositionProxy.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\n\n/*\n    This file is part of the Enzyme Protocol.\n    (c) Enzyme Council <council@enzyme.finance>\n    For the full license information, please view the LICENSE\n    file that was distributed with this source code.\n*/\n\npragma solidity 0.6.12;\n\n/// @title IExternalPositionProxy interface\n/// @author Enzyme Council <security@enzyme.finance>\n/// @notice An interface for publicly accessible functions on the ExternalPositionProxy\ninterface IExternalPositionProxy {\n    function getExternalPositionType() external view returns (uint256);\n\n    function getVaultProxy() external view returns (address);\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200,
        "details": {
          "yul": false
        }
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "metadata": {
        "useLiteralContent": true
      },
      "libraries": {}
    }
  }}