├── .changeset └── config.json ├── .editorconfig ├── .env ├── .env.default ├── .eslintignore ├── .eslintrc.js ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .prettierignore ├── .prettierrc.js ├── .setup.js ├── .solhint.json ├── .travis.yml ├── .vscode └── settings.json.default ├── CHANGELOG.md ├── Diamantaire.new.sol ├── LICENSE ├── README.md ├── TODO.md ├── docs ├── README.md └── index.md ├── extendedArtifacts ├── Address.json ├── BeaconProxy.json ├── Clones.json ├── Context.json ├── Diamond.json ├── DiamondCutFacet.json ├── DiamondERC165Init.json ├── DiamondLoupeFacet.json ├── DiamondLoupeFacetWithoutSupportsInterface.json ├── EIP173Proxy.json ├── EIP173ProxyWithReceive.json ├── ERC165.json ├── ERC165Checker.json ├── ERC165Storage.json ├── ERC1967Proxy.json ├── ERC1967Upgrade.json ├── IBeacon.json ├── IDiamondCut.json ├── IDiamondLoupe.json ├── IERC165.json ├── IERC173.json ├── IERC1822Proxiable.json ├── Initializable.json ├── LibDiamond.json ├── OptimizedTransparentUpgradeableProxy.json ├── Ownable.json ├── OwnershipFacet.json ├── Proxied.json ├── Proxy.json ├── ProxyAdmin.json ├── StorageSlot.json ├── TransparentUpgradeableProxy.json ├── UUPSUpgradeable.json ├── UpgradeableBeacon.json └── UsingDiamondOwner.json ├── funding.json ├── hardhat.config.ts ├── logo.svg ├── package.json ├── pnpm-lock.yaml ├── solc_0.6 └── proxy │ └── Proxied.sol ├── solc_0.7 ├── diamond │ ├── UsingDiamondOwner.sol │ ├── interfaces │ │ └── IDiamondCut.sol │ └── libraries │ │ └── LibDiamond.sol └── proxy │ └── Proxied.sol ├── solc_0.8 ├── diamond │ ├── Diamond.sol │ ├── UsingDiamondOwner.sol │ ├── facets │ │ ├── DiamondCutFacet.sol │ │ ├── DiamondLoupeFacet.sol │ │ ├── DiamondLoupeFacetWithoutSupportsInterface.sol │ │ └── OwnershipFacet.sol │ ├── initializers │ │ └── DiamondERC165Init.sol │ ├── interfaces │ │ ├── IDiamondCut.sol │ │ ├── IDiamondLoupe.sol │ │ ├── IERC165.sol │ │ └── IERC173.sol │ └── libraries │ │ └── LibDiamond.sol ├── openzeppelin │ ├── access │ │ └── Ownable.sol │ ├── interfaces │ │ └── draft-IERC1822.sol │ ├── proxy │ │ ├── Clones.sol │ │ ├── ERC1967 │ │ │ ├── ERC1967Proxy.sol │ │ │ └── ERC1967Upgrade.sol │ │ ├── Proxy.sol │ │ ├── beacon │ │ │ ├── BeaconProxy.sol │ │ │ ├── IBeacon.sol │ │ │ └── UpgradeableBeacon.sol │ │ ├── transparent │ │ │ ├── ProxyAdmin.sol │ │ │ └── TransparentUpgradeableProxy.sol │ │ └── utils │ │ │ ├── Initializable.sol │ │ │ └── UUPSUpgradeable.sol │ └── utils │ │ ├── Address.sol │ │ ├── Context.sol │ │ ├── StorageSlot.sol │ │ └── introspection │ │ ├── ERC165.sol │ │ ├── ERC165Checker.sol │ │ ├── ERC165Storage.sol │ │ └── IERC165.sol └── proxy │ ├── EIP173Proxy.sol │ ├── EIP173ProxyWithReceive.sol │ ├── OptimizedTransparentUpgradeableProxy.sol │ ├── Proxied.sol │ └── Proxy.sol ├── src ├── DeploymentFactory.ts ├── DeploymentsManager.ts ├── decs.d.ts ├── errors.ts ├── etherscan.ts ├── globalStore.ts ├── hdpath.ts ├── helpers.ts ├── index.ts ├── internal │ ├── types.ts │ └── utils.ts ├── old_diamondbase.json ├── sourcify.ts ├── type-extensions.ts └── utils.ts ├── test ├── fixture-projects │ └── hardhat-project │ │ ├── .gitignore │ │ └── hardhat.config.ts ├── helpers.ts ├── mocha.opts └── project.test.ts ├── tsconfig.json └── types.ts /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@1.4.0/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "linked": [], 6 | "access": "restricted", 7 | "baseBranch": "main", 8 | "updateInternalDependencies": "patch", 9 | "ignore": [] 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | 11 | [*.sol] 12 | indent_size = 4 13 | 14 | 15 | [/solc_0.7/openzeppelin/**] 16 | charset = unset 17 | end_of_line = unset 18 | insert_final_newline = unset 19 | trim_trailing_whitespace = unset 20 | indent_style = unset 21 | indent_size = unset 22 | 23 | [/solc_0.7/diamond/**] 24 | charset = unset 25 | end_of_line = unset 26 | insert_final_newline = unset 27 | trim_trailing_whitespace = unset 28 | indent_style = unset 29 | indent_size = unset 30 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | TS_NODE_FILES=true -------------------------------------------------------------------------------- /.env.default: -------------------------------------------------------------------------------- 1 | TS_NODE_FILES=true -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | deployments/ 3 | artifacts/ 4 | cache/ 5 | coverage/ 6 | node_modules/ 7 | package.json 8 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: '@typescript-eslint/parser', 4 | parserOptions: { 5 | ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features 6 | sourceType: 'module', // Allows for the use of imports 7 | }, 8 | env: { 9 | commonjs: true, 10 | }, 11 | plugins: ['@typescript-eslint'], 12 | extends: [ 13 | 'eslint:recommended', 14 | 'plugin:@typescript-eslint/recommended', 15 | 'prettier', 16 | ], 17 | rules: { 18 | 'no-empty': 'off', 19 | 'no-empty-function': 'off', 20 | '@typescript-eslint/no-empty-function': 'off', 21 | }, 22 | }; 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. execute '...' 16 | 2. See error 17 | 18 | **Expected behavior** 19 | A clear and concise description of what you expected to happen. 20 | 21 | **versions** 22 | - hardhat-deploy [e.g. 0.9.14] 23 | - hardhat 24 | - nodejs 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /dist 2 | 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | 10 | node_modules/ 11 | .env* 12 | !.env*.default 13 | .vscode/* 14 | !.vscode/settings.json.default 15 | 16 | cache/ 17 | artifacts/ 18 | 19 | .yalc 20 | yalc.lock 21 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | deployments/ 3 | artifacts/ 4 | cache/ 5 | coverage/ 6 | node_modules/ 7 | package.json 8 | solc_0.7/diamond/* 9 | solc_0.7/openzeppelin/* 10 | solc_0.7/proxy/Proxy.sol 11 | .yalc/ 12 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | singleQuote: true, 3 | bracketSpacing: false, 4 | overrides: [ 5 | { 6 | files: '*.sol', 7 | options: { 8 | printWidth: 128, 9 | tabWidth: 4, 10 | singleQuote: false, 11 | explicitTypes: 'always', 12 | }, 13 | }, 14 | ], 15 | }; 16 | -------------------------------------------------------------------------------- /.setup.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const fs = require('fs'); 3 | function copyFromDefault(p) { 4 | if (!fs.existsSync(p)) { 5 | const defaultFile = `${p}.default`; 6 | if (fs.existsSync(defaultFile)) { 7 | fs.copyFileSync(`${p}.default`, p); 8 | } 9 | } 10 | } 11 | ['.env', '.vscode/settings.json'].map(copyFromDefault); 12 | -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:default", 3 | "plugins": ["prettier"], 4 | "rules": { 5 | "prettier/prettier": "error" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | cache: yarn 4 | 5 | node_js: 6 | - '14' 7 | 8 | install: 9 | - yarn 10 | 11 | script: 12 | - yarn build 13 | - yarn lint 14 | 15 | branches: 16 | only: 17 | - master 18 | -------------------------------------------------------------------------------- /.vscode/settings.json.default: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "editor.defaultFormatter": "esbenp.prettier-vscode", 4 | "editor.codeActionsOnSave": { 5 | "source.fixAll": true 6 | }, 7 | "solidity.linter": "solhint", 8 | "solidity.enableLocalNodeCompiler": false, 9 | "solidity.compileUsingRemoteVersion": "v0.7.1+commit.f4a555be", 10 | "solidity.packageDefaultDependenciesContractsDirectory": "", 11 | "solidity.enabledAsYouTypeCompilationErrorCheck": true, 12 | "solidity.validationDelay": 1500, 13 | "solidity.packageDefaultDependenciesDirectory": "node_modules", 14 | "mochaExplorer.env": { 15 | "HARDHAT_CONFIG": "hardhat.config.ts", 16 | "HARDHAT_COMPILE": "true" 17 | }, 18 | "mochaExplorer.require": ["ts-node/register/transpile-only"] 19 | } 20 | -------------------------------------------------------------------------------- /Diamantaire.new.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.1; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import "./interfaces/IDiamondCut.sol"; 6 | import "./Diamond.sol"; 7 | import "./facets/DiamondCutFacet.sol"; 8 | import "./facets/DiamondLoupeFacet.sol"; 9 | import "./facets/OwnershipFacet.sol"; 10 | 11 | contract Diamantaire { 12 | event DiamondCreated(Diamond diamond); 13 | 14 | IDiamondCut.FacetCut[] public builtinDiamondCut; 15 | 16 | constructor() { 17 | bytes4[] memory functionSelectors; 18 | 19 | // ------------------------------------------------------------------------- 20 | // adding diamondCut function 21 | // ------------------------------------------------------------------------- 22 | DiamondCutFacet diamondCutFacet = new DiamondCutFacet(); // 0x35d80a53f7be635f75152221d4d71cd4dcb07e5c 23 | 24 | functionSelectors = new bytes4[](1); 25 | functionSelectors[0] = DiamondCutFacet.diamondCut.selector; 26 | builtinDiamondCut.push(IDiamondCut.FacetCut({ 27 | facetAddress:address(diamondCutFacet), 28 | action: IDiamondCut.FacetCutAction.Add, 29 | functionSelectors: functionSelectors 30 | })); 31 | 32 | 33 | // ------------------------------------------------------------------------- 34 | // adding diamond loupe functions 35 | // ------------------------------------------------------------------------- 36 | DiamondLoupeFacet diamondLoupeFacet = new DiamondLoupeFacet(); // 0xc1bbdf9f8c0b6ae0b4d35e9a778080b691a72a3e 37 | 38 | functionSelectors = new bytes4[](5); 39 | functionSelectors[0] = DiamondLoupeFacet.facetFunctionSelectors.selector; 40 | functionSelectors[1] = DiamondLoupeFacet.facets.selector; 41 | functionSelectors[2] = DiamondLoupeFacet.facetAddress.selector; 42 | functionSelectors[3] = DiamondLoupeFacet.facetAddresses.selector; 43 | functionSelectors[4] = DiamondLoupeFacet.supportsInterface.selector; 44 | builtinDiamondCut.push(IDiamondCut.FacetCut({ 45 | facetAddress:address(diamondLoupeFacet), 46 | action: IDiamondCut.FacetCutAction.Add, 47 | functionSelectors: functionSelectors 48 | })); 49 | 50 | 51 | // ------------------------------------------------------------------------- 52 | // adding ownership functions 53 | // ------------------------------------------------------------------------- 54 | OwnershipFacet ownershipFacet = new OwnershipFacet(); // 0xcfEe10af6C7A91863c2bbDbCCA3bCB5064A447BE 55 | 56 | functionSelectors = new bytes4[](2); 57 | functionSelectors[0] = OwnershipFacet.transferOwnership.selector; 58 | functionSelectors[1] = OwnershipFacet.owner.selector; 59 | builtinDiamondCut.push(IDiamondCut.FacetCut({ 60 | facetAddress:address(ownershipFacet), 61 | action: IDiamondCut.FacetCutAction.Add, 62 | functionSelectors: functionSelectors 63 | })); 64 | } 65 | 66 | function createDiamond( 67 | address owner, 68 | IDiamondCut.FacetCut[] calldata _diamondCut, 69 | bytes calldata data, 70 | bytes32 salt 71 | ) external payable returns (Diamond diamond) { 72 | if (salt != 0x0000000000000000000000000000000000000000000000000000000000000000) { 73 | salt = keccak256(abi.encodePacked(salt, owner)); 74 | diamond = new Diamond{value: msg.value, salt: salt}( 75 | builtinDiamondCut, 76 | Diamond.DiamondArgs({owner:address(this)}) 77 | ); 78 | } else { 79 | diamond = new Diamond{value: msg.value}(builtinDiamondCut, Diamond.DiamondArgs({owner:address(this)})); 80 | } 81 | emit DiamondCreated(diamond); 82 | 83 | IDiamondCut(address(diamond)).diamondCut(_diamondCut, data.length > 0 ? address(diamond) : address(0), data); 84 | IERC173(address(diamond)).transferOwnership(owner); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ronan Sandford 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | - [ ] --pendingtx : wait | reset | false | interactive 2 | - [ ] execute conditionals : if/unless 3 | - [ ] pause option on unknown signer : check once done and repeat if needed 4 | - [ ] automine as global option 5 | 6 | - [ ] support generator from (like templates for --export ?) 7 | - [ ] library name vs : and error out if ambiguity (when using only name) 8 | - [ ] libraries : address should not need to be address, they could be names of deployments or {address} 9 | - [ ] fix error with proxy constructor, the check use the number of argument given instead of the abi 10 | - [ ] fix issue with fixture reading deployments in hardhat folder: fixture should not read 11 | - [ ] add configuration field for network based configuration ? or at least expose the chainIfNetworkConfig expansion function 12 | - [ ] ipfs-upload 13 | - [ ] add ability to specify metadata in `imports` artifacts 14 | - [ ] deployments.getByAddress(
) // getByAddressOrNull(
) 15 | - [ ] hard fail when no metadata : as this indicate the contract is actually no more part of the compilation unit, and should be discarded 16 | - [ ] exclude tag options 17 | - [ ] hre.run("deploy:before-deploy") in the runDeploy for deploymentManager 18 | - [ ] SPDX license detection regex more flexible ? 19 | - [ ] accept "auto" as allowed argument for `gasPrice` to make it compatible with `hre.network.config.gasPrice` 20 | - [ ] error on Library missing in bytecode 21 | - [ ] error when not finding --no-scripts as folder 22 | - [ ] continue even if evm_snapshot not present on fixture call 23 | - [ ] supports ENS name in namedAccounts (fetch ENS first, or only if ends with .eth or other domain?, require mainnet provider) 24 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | Hello 2 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | Hello world 2 | -------------------------------------------------------------------------------- /extendedArtifacts/Clones.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "Clones", 3 | "sourceName": "solc_0.8/openzeppelin/proxy/Clones.sol", 4 | "abi": [], 5 | "bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212207d7b5d469e9c289eeba6f37e1bcc6deb7f5b8e00d2bff8902b8a91d1669f63c464736f6c634300080a0033", 6 | "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212207d7b5d469e9c289eeba6f37e1bcc6deb7f5b8e00d2bff8902b8a91d1669f63c464736f6c634300080a0033", 7 | "linkReferences": {}, 8 | "deployedLinkReferences": {}, 9 | "devdoc": { 10 | "details": "https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for deploying minimal proxy contracts, also known as \"clones\". > To simply and cheaply clone contract functionality in an immutable way, this standard specifies > a minimal bytecode implementation that delegates all calls to a known, fixed address. The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the deterministic method. _Available since v3.4._", 11 | "kind": "dev", 12 | "methods": {}, 13 | "version": 1 14 | }, 15 | "evm": { 16 | "bytecode": { 17 | "functionDebugData": {}, 18 | "generatedSources": [], 19 | "linkReferences": {}, 20 | "opcodes": "PUSH1 0x56 PUSH1 0x37 PUSH1 0xB DUP3 DUP3 DUP3 CODECOPY DUP1 MLOAD PUSH1 0x0 BYTE PUSH1 0x73 EQ PUSH1 0x2A JUMPI PUSH4 0x4E487B71 PUSH1 0xE0 SHL PUSH1 0x0 MSTORE PUSH1 0x0 PUSH1 0x4 MSTORE PUSH1 0x24 PUSH1 0x0 REVERT JUMPDEST ADDRESS PUSH1 0x0 MSTORE PUSH1 0x73 DUP2 MSTORE8 DUP3 DUP2 RETURN INVALID PUSH20 0x0 ADDRESS EQ PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 PUSH30 0x7B5D469E9C289EEBA6F37E1BCC6DEB7F5B8E00D2BFF8902B8A91D1669F63 0xC4 PUSH5 0x736F6C6343 STOP ADDMOD EXP STOP CALLER ", 21 | "sourceMap": "740:2817:0:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;740:2817:0;;;;;;;;;;;;;;;;;" 22 | }, 23 | "deployedBytecode": { 24 | "functionDebugData": {}, 25 | "generatedSources": [], 26 | "immutableReferences": {}, 27 | "linkReferences": {}, 28 | "opcodes": "PUSH20 0x0 ADDRESS EQ PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 PUSH30 0x7B5D469E9C289EEBA6F37E1BCC6DEB7F5B8E00D2BFF8902B8A91D1669F63 0xC4 PUSH5 0x736F6C6343 STOP ADDMOD EXP STOP CALLER ", 29 | "sourceMap": "740:2817:0:-:0;;;;;;;;" 30 | }, 31 | "gasEstimates": { 32 | "creation": { 33 | "codeDepositCost": "17200", 34 | "executionCost": "103", 35 | "totalCost": "17303" 36 | }, 37 | "internal": { 38 | "clone(address)": "infinite", 39 | "cloneDeterministic(address,bytes32)": "infinite", 40 | "predictDeterministicAddress(address,bytes32)": "infinite", 41 | "predictDeterministicAddress(address,bytes32,address)": "infinite" 42 | } 43 | }, 44 | "methodIdentifiers": {} 45 | }, 46 | "metadata": "{\"compiler\":{\"version\":\"0.8.10+commit.fc410830\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"details\":\"https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for deploying minimal proxy contracts, also known as \\\"clones\\\". > To simply and cheaply clone contract functionality in an immutable way, this standard specifies > a minimal bytecode implementation that delegates all calls to a known, fixed address. The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the deterministic method. _Available since v3.4._\",\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solc_0.8/openzeppelin/proxy/Clones.sol\":\"Clones\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":999999},\"remappings\":[]},\"sources\":{\"solc_0.8/openzeppelin/proxy/Clones.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (proxy/Clones.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for\\n * deploying minimal proxy contracts, also known as \\\"clones\\\".\\n *\\n * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies\\n * > a minimal bytecode implementation that delegates all calls to a known, fixed address.\\n *\\n * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`\\n * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the\\n * deterministic method.\\n *\\n * _Available since v3.4._\\n */\\nlibrary Clones {\\n /**\\n * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\\n *\\n * This function uses the create opcode, which should never revert.\\n */\\n function clone(address implementation) internal returns (address instance) {\\n assembly {\\n let ptr := mload(0x40)\\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\\n mstore(add(ptr, 0x14), shl(0x60, implementation))\\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\\n instance := create(0, ptr, 0x37)\\n }\\n require(instance != address(0), \\\"ERC1167: create failed\\\");\\n }\\n\\n /**\\n * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\\n *\\n * This function uses the create2 opcode and a `salt` to deterministically deploy\\n * the clone. Using the same `implementation` and `salt` multiple time will revert, since\\n * the clones cannot be deployed twice at the same address.\\n */\\n function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {\\n assembly {\\n let ptr := mload(0x40)\\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\\n mstore(add(ptr, 0x14), shl(0x60, implementation))\\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\\n instance := create2(0, ptr, 0x37, salt)\\n }\\n require(instance != address(0), \\\"ERC1167: create2 failed\\\");\\n }\\n\\n /**\\n * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\\n */\\n function predictDeterministicAddress(\\n address implementation,\\n bytes32 salt,\\n address deployer\\n ) internal pure returns (address predicted) {\\n assembly {\\n let ptr := mload(0x40)\\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\\n mstore(add(ptr, 0x14), shl(0x60, implementation))\\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)\\n mstore(add(ptr, 0x38), shl(0x60, deployer))\\n mstore(add(ptr, 0x4c), salt)\\n mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))\\n predicted := keccak256(add(ptr, 0x37), 0x55)\\n }\\n }\\n\\n /**\\n * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\\n */\\n function predictDeterministicAddress(address implementation, bytes32 salt)\\n internal\\n view\\n returns (address predicted)\\n {\\n return predictDeterministicAddress(implementation, salt, address(this));\\n }\\n}\\n\",\"keccak256\":\"0x1cc0efb01cbf008b768fd7b334786a6e358809198bb7e67f1c530af4957c6a21\",\"license\":\"MIT\"}},\"version\":1}", 47 | "storageLayout": { 48 | "storage": [], 49 | "types": null 50 | }, 51 | "userdoc": { 52 | "kind": "user", 53 | "methods": {}, 54 | "version": 1 55 | }, 56 | "solcInput": "{\n \"language\": \"Solidity\",\n \"sources\": {\n \"solc_0.8/openzeppelin/proxy/Clones.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (proxy/Clones.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for\\n * deploying minimal proxy contracts, also known as \\\"clones\\\".\\n *\\n * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies\\n * > a minimal bytecode implementation that delegates all calls to a known, fixed address.\\n *\\n * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`\\n * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the\\n * deterministic method.\\n *\\n * _Available since v3.4._\\n */\\nlibrary Clones {\\n /**\\n * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\\n *\\n * This function uses the create opcode, which should never revert.\\n */\\n function clone(address implementation) internal returns (address instance) {\\n assembly {\\n let ptr := mload(0x40)\\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\\n mstore(add(ptr, 0x14), shl(0x60, implementation))\\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\\n instance := create(0, ptr, 0x37)\\n }\\n require(instance != address(0), \\\"ERC1167: create failed\\\");\\n }\\n\\n /**\\n * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\\n *\\n * This function uses the create2 opcode and a `salt` to deterministically deploy\\n * the clone. Using the same `implementation` and `salt` multiple time will revert, since\\n * the clones cannot be deployed twice at the same address.\\n */\\n function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {\\n assembly {\\n let ptr := mload(0x40)\\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\\n mstore(add(ptr, 0x14), shl(0x60, implementation))\\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\\n instance := create2(0, ptr, 0x37, salt)\\n }\\n require(instance != address(0), \\\"ERC1167: create2 failed\\\");\\n }\\n\\n /**\\n * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\\n */\\n function predictDeterministicAddress(\\n address implementation,\\n bytes32 salt,\\n address deployer\\n ) internal pure returns (address predicted) {\\n assembly {\\n let ptr := mload(0x40)\\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\\n mstore(add(ptr, 0x14), shl(0x60, implementation))\\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)\\n mstore(add(ptr, 0x38), shl(0x60, deployer))\\n mstore(add(ptr, 0x4c), salt)\\n mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))\\n predicted := keccak256(add(ptr, 0x37), 0x55)\\n }\\n }\\n\\n /**\\n * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\\n */\\n function predictDeterministicAddress(address implementation, bytes32 salt)\\n internal\\n view\\n returns (address predicted)\\n {\\n return predictDeterministicAddress(implementation, salt, address(this));\\n }\\n}\\n\"\n }\n },\n \"settings\": {\n \"optimizer\": {\n \"enabled\": true,\n \"runs\": 999999\n },\n \"outputSelection\": {\n \"*\": {\n \"*\": [\n \"abi\",\n \"evm.bytecode\",\n \"evm.deployedBytecode\",\n \"evm.methodIdentifiers\",\n \"metadata\",\n \"devdoc\",\n \"userdoc\",\n \"storageLayout\",\n \"evm.gasEstimates\"\n ],\n \"\": [\n \"ast\"\n ]\n }\n },\n \"metadata\": {\n \"useLiteralContent\": true\n }\n }\n}", 57 | "solcInputHash": "e2d945ac773b9f390b942223c790e77b" 58 | } -------------------------------------------------------------------------------- /extendedArtifacts/IERC165.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "IERC165", 3 | "sourceName": "solc_0.8/openzeppelin/utils/introspection/IERC165.sol", 4 | "abi": [ 5 | { 6 | "inputs": [ 7 | { 8 | "internalType": "bytes4", 9 | "name": "interfaceId", 10 | "type": "bytes4" 11 | } 12 | ], 13 | "name": "supportsInterface", 14 | "outputs": [ 15 | { 16 | "internalType": "bool", 17 | "name": "", 18 | "type": "bool" 19 | } 20 | ], 21 | "stateMutability": "view", 22 | "type": "function" 23 | } 24 | ], 25 | "bytecode": "0x", 26 | "deployedBytecode": "0x", 27 | "linkReferences": {}, 28 | "deployedLinkReferences": {}, 29 | "devdoc": { 30 | "details": "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}.", 31 | "kind": "dev", 32 | "methods": { 33 | "supportsInterface(bytes4)": { 34 | "details": "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." 35 | } 36 | }, 37 | "version": 1 38 | }, 39 | "evm": { 40 | "bytecode": { 41 | "functionDebugData": {}, 42 | "generatedSources": [], 43 | "linkReferences": {}, 44 | "object": "", 45 | "opcodes": "", 46 | "sourceMap": "" 47 | }, 48 | "deployedBytecode": { 49 | "functionDebugData": {}, 50 | "generatedSources": [], 51 | "immutableReferences": {}, 52 | "linkReferences": {}, 53 | "object": "", 54 | "opcodes": "", 55 | "sourceMap": "" 56 | }, 57 | "gasEstimates": null, 58 | "methodIdentifiers": { 59 | "supportsInterface(bytes4)": "01ffc9a7" 60 | } 61 | }, 62 | "metadata": "{\"compiler\":{\"version\":\"0.8.10+commit.fc410830\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"details\":\"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}.\",\"kind\":\"dev\",\"methods\":{\"supportsInterface(bytes4)\":{\"details\":\"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.\"}},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solc_0.8/openzeppelin/utils/introspection/IERC165.sol\":\"IERC165\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":999999},\"remappings\":[]},\"sources\":{\"solc_0.8/openzeppelin/utils/introspection/IERC165.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\",\"keccak256\":\"0x447a5f3ddc18419d41ff92b3773fb86471b1db25773e07f877f548918a185bf1\",\"license\":\"MIT\"}},\"version\":1}", 63 | "storageLayout": { 64 | "storage": [], 65 | "types": null 66 | }, 67 | "userdoc": { 68 | "kind": "user", 69 | "methods": {}, 70 | "version": 1 71 | }, 72 | "solcInput": "{\n \"language\": \"Solidity\",\n \"sources\": {\n \"solc_0.8/openzeppelin/utils/introspection/ERC165.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Implementation of the {IERC165} interface.\\n *\\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\\n * for the additional interface id that will be supported. For example:\\n *\\n * ```solidity\\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\\n * }\\n * ```\\n *\\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\\n */\\nabstract contract ERC165 is IERC165 {\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return interfaceId == type(IERC165).interfaceId;\\n }\\n}\\n\"\n },\n \"solc_0.8/openzeppelin/utils/introspection/IERC165.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\\n\\npragma solidity ^0.8.0;\\n\\n/**\\n * @dev Interface of the ERC165 standard, as defined in the\\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\\n *\\n * Implementers can declare support of contract interfaces, which can then be\\n * queried by others ({ERC165Checker}).\\n *\\n * For an implementation, see {ERC165}.\\n */\\ninterface IERC165 {\\n /**\\n * @dev Returns true if this contract implements the interface defined by\\n * `interfaceId`. See the corresponding\\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\\n * to learn more about how these ids are created.\\n *\\n * This function call must use less than 30 000 gas.\\n */\\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\\n}\\n\"\n },\n \"solc_0.8/openzeppelin/utils/introspection/ERC165Storage.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165Storage.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./ERC165.sol\\\";\\n\\n/**\\n * @dev Storage based implementation of the {IERC165} interface.\\n *\\n * Contracts may inherit from this and call {_registerInterface} to declare\\n * their support of an interface.\\n */\\nabstract contract ERC165Storage is ERC165 {\\n /**\\n * @dev Mapping of interface ids to whether or not it's supported.\\n */\\n mapping(bytes4 => bool) private _supportedInterfaces;\\n\\n /**\\n * @dev See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\\n return super.supportsInterface(interfaceId) || _supportedInterfaces[interfaceId];\\n }\\n\\n /**\\n * @dev Registers the contract as an implementer of the interface defined by\\n * `interfaceId`. Support of the actual ERC165 interface is automatic and\\n * registering its interface id is not required.\\n *\\n * See {IERC165-supportsInterface}.\\n *\\n * Requirements:\\n *\\n * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).\\n */\\n function _registerInterface(bytes4 interfaceId) internal virtual {\\n require(interfaceId != 0xffffffff, \\\"ERC165: invalid interface id\\\");\\n _supportedInterfaces[interfaceId] = true;\\n }\\n}\\n\"\n },\n \"solc_0.8/openzeppelin/utils/introspection/ERC165Checker.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165Checker.sol)\\n\\npragma solidity ^0.8.0;\\n\\nimport \\\"./IERC165.sol\\\";\\n\\n/**\\n * @dev Library used to query support of an interface declared via {IERC165}.\\n *\\n * Note that these functions return the actual result of the query: they do not\\n * `revert` if an interface is not supported. It is up to the caller to decide\\n * what to do in these cases.\\n */\\nlibrary ERC165Checker {\\n // As per the EIP-165 spec, no interface should ever match 0xffffffff\\n bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;\\n\\n /**\\n * @dev Returns true if `account` supports the {IERC165} interface,\\n */\\n function supportsERC165(address account) internal view returns (bool) {\\n // Any contract that implements ERC165 must explicitly indicate support of\\n // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid\\n return\\n _supportsERC165Interface(account, type(IERC165).interfaceId) &&\\n !_supportsERC165Interface(account, _INTERFACE_ID_INVALID);\\n }\\n\\n /**\\n * @dev Returns true if `account` supports the interface defined by\\n * `interfaceId`. Support for {IERC165} itself is queried automatically.\\n *\\n * See {IERC165-supportsInterface}.\\n */\\n function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {\\n // query support of both ERC165 as per the spec and support of _interfaceId\\n return supportsERC165(account) && _supportsERC165Interface(account, interfaceId);\\n }\\n\\n /**\\n * @dev Returns a boolean array where each value corresponds to the\\n * interfaces passed in and whether they're supported or not. This allows\\n * you to batch check interfaces for a contract where your expectation\\n * is that some interfaces may not be supported.\\n *\\n * See {IERC165-supportsInterface}.\\n *\\n * _Available since v3.4._\\n */\\n function getSupportedInterfaces(address account, bytes4[] memory interfaceIds)\\n internal\\n view\\n returns (bool[] memory)\\n {\\n // an array of booleans corresponding to interfaceIds and whether they're supported or not\\n bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);\\n\\n // query support of ERC165 itself\\n if (supportsERC165(account)) {\\n // query support of each interface in interfaceIds\\n for (uint256 i = 0; i < interfaceIds.length; i++) {\\n interfaceIdsSupported[i] = _supportsERC165Interface(account, interfaceIds[i]);\\n }\\n }\\n\\n return interfaceIdsSupported;\\n }\\n\\n /**\\n * @dev Returns true if `account` supports all the interfaces defined in\\n * `interfaceIds`. Support for {IERC165} itself is queried automatically.\\n *\\n * Batch-querying can lead to gas savings by skipping repeated checks for\\n * {IERC165} support.\\n *\\n * See {IERC165-supportsInterface}.\\n */\\n function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {\\n // query support of ERC165 itself\\n if (!supportsERC165(account)) {\\n return false;\\n }\\n\\n // query support of each interface in _interfaceIds\\n for (uint256 i = 0; i < interfaceIds.length; i++) {\\n if (!_supportsERC165Interface(account, interfaceIds[i])) {\\n return false;\\n }\\n }\\n\\n // all interfaces supported\\n return true;\\n }\\n\\n /**\\n * @notice Query if a contract implements an interface, does not check ERC165 support\\n * @param account The address of the contract to query for support of an interface\\n * @param interfaceId The interface identifier, as specified in ERC-165\\n * @return true if the contract at account indicates support of the interface with\\n * identifier interfaceId, false otherwise\\n * @dev Assumes that account contains a contract that supports ERC165, otherwise\\n * the behavior of this method is undefined. This precondition can be checked\\n * with {supportsERC165}.\\n * Interface identification is specified in ERC-165.\\n */\\n function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {\\n bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);\\n (bool success, bytes memory result) = account.staticcall{gas: 30000}(encodedParams);\\n if (result.length < 32) return false;\\n return success && abi.decode(result, (bool));\\n }\\n}\\n\"\n }\n },\n \"settings\": {\n \"optimizer\": {\n \"enabled\": true,\n \"runs\": 999999\n },\n \"outputSelection\": {\n \"*\": {\n \"*\": [\n \"abi\",\n \"evm.bytecode\",\n \"evm.deployedBytecode\",\n \"evm.methodIdentifiers\",\n \"metadata\",\n \"devdoc\",\n \"userdoc\",\n \"storageLayout\",\n \"evm.gasEstimates\"\n ],\n \"\": [\n \"ast\"\n ]\n }\n },\n \"metadata\": {\n \"useLiteralContent\": true\n }\n }\n}", 73 | "solcInputHash": "79de338ba05d5edc12f53c878431817f" 74 | } -------------------------------------------------------------------------------- /extendedArtifacts/Proxied.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "Proxied", 3 | "sourceName": "solc_0.8/proxy/Proxied.sol", 4 | "abi": [], 5 | "bytecode": "0x", 6 | "deployedBytecode": "0x", 7 | "linkReferences": {}, 8 | "deployedLinkReferences": {}, 9 | "devdoc": { 10 | "kind": "dev", 11 | "methods": {}, 12 | "version": 1 13 | }, 14 | "evm": { 15 | "bytecode": { 16 | "functionDebugData": {}, 17 | "generatedSources": [], 18 | "linkReferences": {}, 19 | "object": "", 20 | "opcodes": "", 21 | "sourceMap": "" 22 | }, 23 | "deployedBytecode": { 24 | "functionDebugData": {}, 25 | "generatedSources": [], 26 | "immutableReferences": {}, 27 | "linkReferences": {}, 28 | "object": "", 29 | "opcodes": "", 30 | "sourceMap": "" 31 | }, 32 | "gasEstimates": null, 33 | "methodIdentifiers": {} 34 | }, 35 | "metadata": "{\"compiler\":{\"version\":\"0.8.10+commit.fc410830\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solc_0.8/proxy/Proxied.sol\":\"Proxied\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":999999},\"remappings\":[]},\"sources\":{\"solc_0.8/proxy/Proxied.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.0;\\n\\nabstract contract Proxied {\\n /// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them\\n /// It also allows these functions to be called inside a contructor\\n /// even if the contract is meant to be used without proxy\\n modifier proxied() {\\n address proxyAdminAddress = _proxyAdmin();\\n // With hardhat-deploy proxies\\n // the proxyAdminAddress is zero only for the implementation contract\\n // if the implementation contract want to be used as a standalone/immutable contract\\n // it simply has to execute the `proxied` function\\n // This ensure the proxyAdminAddress is never zero post deployment\\n // And allow you to keep the same code for both proxied contract and immutable contract\\n if (proxyAdminAddress == address(0)) {\\n // ensure can not be called twice when used outside of proxy : no admin\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n sstore(\\n 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,\\n 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\\n )\\n }\\n } else {\\n require(msg.sender == proxyAdminAddress);\\n }\\n _;\\n }\\n\\n modifier onlyProxyAdmin() {\\n require(msg.sender == _proxyAdmin(), \\\"NOT_AUTHORIZED\\\");\\n _;\\n }\\n\\n function _proxyAdmin() internal view returns (address ownerAddress) {\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)\\n }\\n }\\n}\\n\",\"keccak256\":\"0xaaceeafeeaf0d200ca3942d8bf14c1c4f787a77f79cc87c08bb668e65acdee29\",\"license\":\"MIT\"}},\"version\":1}", 36 | "storageLayout": { 37 | "storage": [], 38 | "types": null 39 | }, 40 | "userdoc": { 41 | "kind": "user", 42 | "methods": {}, 43 | "version": 1 44 | }, 45 | "solcInput": "{\n \"language\": \"Solidity\",\n \"sources\": {\n \"solc_0.8/proxy/Proxied.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.0;\\n\\nabstract contract Proxied {\\n /// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them\\n /// It also allows these functions to be called inside a contructor\\n /// even if the contract is meant to be used without proxy\\n modifier proxied() {\\n address proxyAdminAddress = _proxyAdmin();\\n // With hardhat-deploy proxies\\n // the proxyAdminAddress is zero only for the implementation contract\\n // if the implementation contract want to be used as a standalone/immutable contract\\n // it simply has to execute the `proxied` function\\n // This ensure the proxyAdminAddress is never zero post deployment\\n // And allow you to keep the same code for both proxied contract and immutable contract\\n if (proxyAdminAddress == address(0)) {\\n // ensure can not be called twice when used outside of proxy : no admin\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n sstore(\\n 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,\\n 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\\n )\\n }\\n } else {\\n require(msg.sender == proxyAdminAddress);\\n }\\n _;\\n }\\n\\n modifier onlyProxyAdmin() {\\n require(msg.sender == _proxyAdmin(), \\\"NOT_AUTHORIZED\\\");\\n _;\\n }\\n\\n function _proxyAdmin() internal view returns (address ownerAddress) {\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)\\n }\\n }\\n}\\n\"\n }\n },\n \"settings\": {\n \"optimizer\": {\n \"enabled\": true,\n \"runs\": 999999\n },\n \"outputSelection\": {\n \"*\": {\n \"*\": [\n \"abi\",\n \"evm.bytecode\",\n \"evm.deployedBytecode\",\n \"evm.methodIdentifiers\",\n \"metadata\",\n \"devdoc\",\n \"userdoc\",\n \"storageLayout\",\n \"evm.gasEstimates\"\n ],\n \"\": [\n \"ast\"\n ]\n }\n },\n \"metadata\": {\n \"useLiteralContent\": true\n }\n }\n}", 46 | "solcInputHash": "671af58dff9d96540fbd6480e1e9a256" 47 | } -------------------------------------------------------------------------------- /extendedArtifacts/Proxy.json: -------------------------------------------------------------------------------- 1 | { 2 | "contractName": "Proxy", 3 | "sourceName": "solc_0.8/proxy/Proxy.sol", 4 | "abi": [ 5 | { 6 | "anonymous": false, 7 | "inputs": [ 8 | { 9 | "indexed": true, 10 | "internalType": "address", 11 | "name": "previousImplementation", 12 | "type": "address" 13 | }, 14 | { 15 | "indexed": true, 16 | "internalType": "address", 17 | "name": "newImplementation", 18 | "type": "address" 19 | } 20 | ], 21 | "name": "ProxyImplementationUpdated", 22 | "type": "event" 23 | }, 24 | { 25 | "stateMutability": "payable", 26 | "type": "fallback" 27 | }, 28 | { 29 | "stateMutability": "payable", 30 | "type": "receive" 31 | } 32 | ], 33 | "bytecode": "0x", 34 | "deployedBytecode": "0x", 35 | "linkReferences": {}, 36 | "deployedLinkReferences": {}, 37 | "devdoc": { 38 | "kind": "dev", 39 | "methods": {}, 40 | "version": 1 41 | }, 42 | "evm": { 43 | "bytecode": { 44 | "functionDebugData": {}, 45 | "generatedSources": [], 46 | "linkReferences": {}, 47 | "object": "", 48 | "opcodes": "", 49 | "sourceMap": "" 50 | }, 51 | "deployedBytecode": { 52 | "functionDebugData": {}, 53 | "generatedSources": [], 54 | "immutableReferences": {}, 55 | "linkReferences": {}, 56 | "object": "", 57 | "opcodes": "", 58 | "sourceMap": "" 59 | }, 60 | "gasEstimates": null, 61 | "methodIdentifiers": {} 62 | }, 63 | "metadata": "{\"compiler\":{\"version\":\"0.8.10+commit.fc410830\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousImplementation\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newImplementation\",\"type\":\"address\"}],\"name\":\"ProxyImplementationUpdated\",\"type\":\"event\"},{\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"stateMutability\":\"payable\",\"type\":\"receive\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"solc_0.8/proxy/Proxy.sol\":\"Proxy\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":999999},\"remappings\":[]},\"sources\":{\"solc_0.8/proxy/Proxy.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.0;\\n\\n// EIP-1967\\nabstract contract Proxy {\\n // /////////////////////// EVENTS ///////////////////////////////////////////////////////////////////////////\\n\\n event ProxyImplementationUpdated(address indexed previousImplementation, address indexed newImplementation);\\n\\n // ///////////////////// EXTERNAL ///////////////////////////////////////////////////////////////////////////\\n\\n receive() external payable virtual {\\n revert(\\\"ETHER_REJECTED\\\"); // explicit reject by default\\n }\\n\\n fallback() external payable {\\n _fallback();\\n }\\n\\n // ///////////////////////// INTERNAL //////////////////////////////////////////////////////////////////////\\n\\n function _fallback() internal {\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n let implementationAddress := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)\\n calldatacopy(0x0, 0x0, calldatasize())\\n let success := delegatecall(gas(), implementationAddress, 0x0, calldatasize(), 0, 0)\\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 function _setImplementation(address newImplementation, bytes memory data) internal {\\n address previousImplementation;\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n previousImplementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)\\n }\\n\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, newImplementation)\\n }\\n\\n emit ProxyImplementationUpdated(previousImplementation, newImplementation);\\n\\n if (data.length > 0) {\\n (bool success, ) = newImplementation.delegatecall(data);\\n if (!success) {\\n assembly {\\n // This assembly ensure the revert contains the exact string data\\n let returnDataSize := returndatasize()\\n returndatacopy(0, 0, returnDataSize)\\n revert(0, returnDataSize)\\n }\\n }\\n }\\n }\\n}\\n\",\"keccak256\":\"0x68c8cf1a340a53d31de8ed808bb66d64e83d50b20d80a0b2dff6aba903cebc98\",\"license\":\"MIT\"}},\"version\":1}", 64 | "storageLayout": { 65 | "storage": [], 66 | "types": null 67 | }, 68 | "userdoc": { 69 | "kind": "user", 70 | "methods": {}, 71 | "version": 1 72 | }, 73 | "solcInput": "{\n \"language\": \"Solidity\",\n \"sources\": {\n \"solc_0.8/proxy/EIP173Proxy.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.0;\\n\\nimport \\\"./Proxy.sol\\\";\\n\\ninterface ERC165 {\\n function supportsInterface(bytes4 id) external view returns (bool);\\n}\\n\\n///@notice Proxy implementing EIP173 for ownership management\\ncontract EIP173Proxy is Proxy {\\n // ////////////////////////// EVENTS ///////////////////////////////////////////////////////////////////////\\n\\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\\n\\n // /////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////////////\\n\\n constructor(\\n address implementationAddress,\\n address ownerAddress,\\n bytes memory data\\n ) payable {\\n _setOwner(ownerAddress);\\n _setImplementation(implementationAddress, data);\\n }\\n\\n // ///////////////////// EXTERNAL ///////////////////////////////////////////////////////////////////////////\\n\\n function owner() external view returns (address) {\\n return _owner();\\n }\\n\\n function supportsInterface(bytes4 id) external view returns (bool) {\\n if (id == 0x01ffc9a7 || id == 0x7f5828d0) {\\n return true;\\n }\\n if (id == 0xFFFFFFFF) {\\n return false;\\n }\\n\\n ERC165 implementation;\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n implementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)\\n }\\n\\n // Technically this is not standard compliant as ERC-165 require 30,000 gas which that call cannot ensure\\n // because it is itself inside `supportsInterface` that might only get 30,000 gas.\\n // In practise this is unlikely to be an issue.\\n try implementation.supportsInterface(id) returns (bool support) {\\n return support;\\n } catch {\\n return false;\\n }\\n }\\n\\n function transferOwnership(address newOwner) external onlyOwner {\\n _setOwner(newOwner);\\n }\\n\\n function upgradeTo(address newImplementation) external onlyOwner {\\n _setImplementation(newImplementation, \\\"\\\");\\n }\\n\\n function upgradeToAndCall(address newImplementation, bytes calldata data) external payable onlyOwner {\\n _setImplementation(newImplementation, data);\\n }\\n\\n // /////////////////////// MODIFIERS ////////////////////////////////////////////////////////////////////////\\n\\n modifier onlyOwner() {\\n require(msg.sender == _owner(), \\\"NOT_AUTHORIZED\\\");\\n _;\\n }\\n\\n // ///////////////////////// INTERNAL //////////////////////////////////////////////////////////////////////\\n\\n function _owner() internal view returns (address adminAddress) {\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n adminAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)\\n }\\n }\\n\\n function _setOwner(address newOwner) internal {\\n address previousOwner = _owner();\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n sstore(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, newOwner)\\n }\\n emit OwnershipTransferred(previousOwner, newOwner);\\n }\\n}\\n\"\n },\n \"solc_0.8/proxy/Proxy.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.0;\\n\\n// EIP-1967\\nabstract contract Proxy {\\n // /////////////////////// EVENTS ///////////////////////////////////////////////////////////////////////////\\n\\n event ProxyImplementationUpdated(address indexed previousImplementation, address indexed newImplementation);\\n\\n // ///////////////////// EXTERNAL ///////////////////////////////////////////////////////////////////////////\\n\\n receive() external payable virtual {\\n revert(\\\"ETHER_REJECTED\\\"); // explicit reject by default\\n }\\n\\n fallback() external payable {\\n _fallback();\\n }\\n\\n // ///////////////////////// INTERNAL //////////////////////////////////////////////////////////////////////\\n\\n function _fallback() internal {\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n let implementationAddress := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)\\n calldatacopy(0x0, 0x0, calldatasize())\\n let success := delegatecall(gas(), implementationAddress, 0x0, calldatasize(), 0, 0)\\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 function _setImplementation(address newImplementation, bytes memory data) internal {\\n address previousImplementation;\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n previousImplementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)\\n }\\n\\n // solhint-disable-next-line security/no-inline-assembly\\n assembly {\\n sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, newImplementation)\\n }\\n\\n emit ProxyImplementationUpdated(previousImplementation, newImplementation);\\n\\n if (data.length > 0) {\\n (bool success, ) = newImplementation.delegatecall(data);\\n if (!success) {\\n assembly {\\n // This assembly ensure the revert contains the exact string data\\n let returnDataSize := returndatasize()\\n returndatacopy(0, 0, returnDataSize)\\n revert(0, returnDataSize)\\n }\\n }\\n }\\n }\\n}\\n\"\n },\n \"solc_0.8/proxy/EIP173ProxyWithReceive.sol\": {\n \"content\": \"// SPDX-License-Identifier: MIT\\npragma solidity ^0.8.0;\\n\\nimport \\\"./EIP173Proxy.sol\\\";\\n\\n///@notice Proxy implementing EIP173 for ownership management that accept ETH via receive\\ncontract EIP173ProxyWithReceive is EIP173Proxy {\\n constructor(\\n address implementationAddress,\\n address ownerAddress,\\n bytes memory data\\n ) payable EIP173Proxy(implementationAddress, ownerAddress, data) {}\\n\\n receive() external payable override {}\\n}\\n\"\n }\n },\n \"settings\": {\n \"optimizer\": {\n \"enabled\": true,\n \"runs\": 999999\n },\n \"outputSelection\": {\n \"*\": {\n \"*\": [\n \"abi\",\n \"evm.bytecode\",\n \"evm.deployedBytecode\",\n \"evm.methodIdentifiers\",\n \"metadata\",\n \"devdoc\",\n \"userdoc\",\n \"storageLayout\",\n \"evm.gasEstimates\"\n ],\n \"\": [\n \"ast\"\n ]\n }\n },\n \"metadata\": {\n \"useLiteralContent\": true\n }\n }\n}", 74 | "solcInputHash": "4a46ee6c1a29be400c9fab1ecc28e172" 75 | } -------------------------------------------------------------------------------- /funding.json: -------------------------------------------------------------------------------- 1 | { 2 | "opRetro": { 3 | "projectId": "0x9b639cc6061e41a1d12adb39619a2fddb7005074cf965a3a6f4eabc6eea31112" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import {HardhatUserConfig, internalTask, task} from 'hardhat/config'; 2 | import { 3 | TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT, 4 | TASK_COMPILE, 5 | } from 'hardhat/builtin-tasks/task-names'; 6 | import fs from 'fs-extra'; 7 | import path from 'path'; 8 | import {Artifact, BuildInfo} from 'hardhat/types'; 9 | import murmur128 from 'murmur-128'; 10 | 11 | function addIfNotPresent(array: string[], value: string) { 12 | if (array.indexOf(value) === -1) { 13 | array.push(value); 14 | } 15 | } 16 | 17 | function setupExtraSolcSettings(settings: { 18 | metadata?: {useLiteralContent?: boolean}; 19 | outputSelection: {[key: string]: {[key: string]: string[]}}; 20 | }): void { 21 | settings.metadata = settings.metadata || {}; 22 | settings.metadata.useLiteralContent = true; 23 | 24 | if (settings.outputSelection === undefined) { 25 | settings.outputSelection = { 26 | '*': { 27 | '*': [], 28 | '': [], 29 | }, 30 | }; 31 | } 32 | if (settings.outputSelection['*'] === undefined) { 33 | settings.outputSelection['*'] = { 34 | '*': [], 35 | '': [], 36 | }; 37 | } 38 | if (settings.outputSelection['*']['*'] === undefined) { 39 | settings.outputSelection['*']['*'] = []; 40 | } 41 | if (settings.outputSelection['*'][''] === undefined) { 42 | settings.outputSelection['*'][''] = []; 43 | } 44 | 45 | addIfNotPresent(settings.outputSelection['*']['*'], 'abi'); 46 | addIfNotPresent(settings.outputSelection['*']['*'], 'evm.bytecode'); 47 | addIfNotPresent(settings.outputSelection['*']['*'], 'evm.deployedBytecode'); 48 | addIfNotPresent(settings.outputSelection['*']['*'], 'metadata'); 49 | addIfNotPresent(settings.outputSelection['*']['*'], 'devdoc'); 50 | addIfNotPresent(settings.outputSelection['*']['*'], 'userdoc'); 51 | addIfNotPresent(settings.outputSelection['*']['*'], 'storageLayout'); 52 | addIfNotPresent(settings.outputSelection['*']['*'], 'evm.methodIdentifiers'); 53 | addIfNotPresent(settings.outputSelection['*']['*'], 'evm.gasEstimates'); 54 | // addIfNotPresent(settings.outputSelection["*"][""], "ir"); 55 | // addIfNotPresent(settings.outputSelection["*"][""], "irOptimized"); 56 | // addIfNotPresent(settings.outputSelection["*"][""], "ast"); 57 | } 58 | 59 | internalTask(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction( 60 | async (_, __, runSuper) => { 61 | const input = await runSuper(); 62 | setupExtraSolcSettings(input.settings); 63 | 64 | return input; 65 | } 66 | ); 67 | 68 | task(TASK_COMPILE).setAction(async (args, hre, runSuper) => { 69 | await runSuper(args); 70 | const extendedArtifactFolderpath = 'extendedArtifacts'; 71 | fs.emptyDirSync(extendedArtifactFolderpath); 72 | const artifactPaths = await hre.artifacts.getArtifactPaths(); 73 | for (const artifactPath of artifactPaths) { 74 | const artifact: Artifact = await fs.readJSON(artifactPath); 75 | const artifactName = path.basename(artifactPath, '.json'); 76 | const artifactDBGPath = path.join( 77 | path.dirname(artifactPath), 78 | artifactName + '.dbg.json' 79 | ); 80 | const artifactDBG = await fs.readJSON(artifactDBGPath); 81 | const buildinfoPath = path.join( 82 | path.dirname(artifactDBGPath), 83 | artifactDBG.buildInfo 84 | ); 85 | const buildInfo: BuildInfo = await fs.readJSON(buildinfoPath); 86 | const output = 87 | buildInfo.output.contracts[artifact.sourceName][artifactName]; 88 | 89 | // TODO decide on ExtendedArtifact vs Artifact vs Deployment type 90 | // save space by not duplicating bytecodes 91 | if (output.evm?.bytecode?.object) { 92 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 93 | (output.evm.bytecode.object as any) = undefined; 94 | } 95 | if (output.evm?.deployedBytecode?.object) { 96 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 97 | (output.evm.deployedBytecode.object as any) = undefined; 98 | } 99 | // ----------------------------------------- 100 | 101 | const solcInput = JSON.stringify(buildInfo.input, null, ' '); 102 | const solcInputHash = Buffer.from(murmur128(solcInput)).toString('hex'); 103 | const extendedArtifact = { 104 | ...artifact, 105 | ...output, 106 | solcInput, 107 | solcInputHash, 108 | }; 109 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 110 | (extendedArtifact._format as any) = undefined; 111 | fs.writeFileSync( 112 | path.join(extendedArtifactFolderpath, artifactName + '.json'), 113 | JSON.stringify(extendedArtifact, null, ' ') 114 | ); 115 | } 116 | }); 117 | 118 | const config: HardhatUserConfig = { 119 | solidity: { 120 | version: '0.8.10', 121 | settings: { 122 | optimizer: { 123 | enabled: true, 124 | runs: 999999, 125 | }, 126 | }, 127 | }, 128 | paths: { 129 | sources: 'solc_0.8', 130 | }, 131 | }; 132 | 133 | export default config; 134 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hardhat-deploy", 3 | "version": "1.0.2", 4 | "description": "Hardhat Plugin For Replicable Deployments And Tests", 5 | "repository": "github:wighawag/hardhat-deploy", 6 | "author": "wighawag", 7 | "license": "MIT", 8 | "publishConfig": { 9 | "access": "public" 10 | }, 11 | "main": "dist/src/index.js", 12 | "types": "dist/src/index.d.ts", 13 | "keywords": [ 14 | "ethereum", 15 | "smart-contracts", 16 | "deployment", 17 | "test", 18 | "testing", 19 | "tool", 20 | "hardhat", 21 | "hardhat-deploy", 22 | "hardhat-plugin" 23 | ], 24 | "files": [ 25 | "dist/src/", 26 | "dist/types*", 27 | "dist/extendedArtifacts/", 28 | "extendedArtifacts/", 29 | "src/", 30 | "types.ts", 31 | "LICENSE", 32 | "README.md", 33 | "solc_0.6/", 34 | "solc_0.7", 35 | "solc_0.8" 36 | ], 37 | "devDependencies": { 38 | "@changesets/cli": "^2.11.1", 39 | "@types/chai": "^4.2.21", 40 | "@types/debug": "^4.1.7", 41 | "@types/fs-extra": "^9.0.12", 42 | "@types/mocha": "^9.0.0", 43 | "@types/node": "^16.6.2", 44 | "@typescript-eslint/eslint-plugin": "^4.29.2", 45 | "@typescript-eslint/parser": "^4.29.2", 46 | "chai": "^4.2.0", 47 | "dotenv": "^10.0.0", 48 | "eslint": "^7.32.0", 49 | "eslint-config-prettier": "^8.3.0", 50 | "hardhat": "^2.22.18", 51 | "mocha": "^9.1.0", 52 | "prettier": "^2.3.2", 53 | "prettier-plugin-solidity": "^1.0.0-beta.17", 54 | "solhint": "^3.3.6", 55 | "solhint-plugin-prettier": "^0.0.5", 56 | "source-map-support": "^0.5.12", 57 | "ts-node": "^10.2.1", 58 | "typescript": "^4.3.5" 59 | }, 60 | "dependencies": { 61 | "@ethersproject/abi": "^5.7.0", 62 | "@ethersproject/abstract-signer": "^5.7.0", 63 | "@ethersproject/address": "^5.7.0", 64 | "@ethersproject/bignumber": "^5.7.0", 65 | "@ethersproject/bytes": "^5.7.0", 66 | "@ethersproject/constants": "^5.7.0", 67 | "@ethersproject/contracts": "^5.7.0", 68 | "@ethersproject/providers": "^5.7.2", 69 | "@ethersproject/solidity": "^5.7.0", 70 | "@ethersproject/transactions": "^5.7.0", 71 | "@ethersproject/wallet": "^5.7.0", 72 | "@types/qs": "^6.9.7", 73 | "axios": "^0.21.1", 74 | "chalk": "^4.1.2", 75 | "chokidar": "^3.5.2", 76 | "debug": "^4.3.2", 77 | "enquirer": "^2.3.6", 78 | "ethers": "^5.7.0", 79 | "form-data": "^4.0.0", 80 | "fs-extra": "^10.0.0", 81 | "match-all": "^1.2.6", 82 | "murmur-128": "^0.2.1", 83 | "qs": "^6.9.4", 84 | "zksync-ethers": "^5.0.0" 85 | }, 86 | "scripts": { 87 | "prepare": "node ./.setup.js", 88 | "compile": "hardhat compile", 89 | "lint": "eslint \"**/*.{js,ts}\" && solhint src/**/*.sol", 90 | "lint:fix": "eslint --fix \"**/*.{js,ts}\" && solhint --fix src/**/*.sol", 91 | "format": "prettier --write \"**/*.{ts,js,sol}\"", 92 | "test": "mocha --timeout 20000 --exit", 93 | "build": "tsc", 94 | "watch": "tsc -w", 95 | "publish:next": "npm publish --tag next", 96 | "publish:release": "npm publish", 97 | "prepublishOnly": "npm run build" 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /solc_0.6/proxy/Proxied.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.6.0; 3 | 4 | abstract contract Proxied { 5 | /// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them 6 | /// It also allows these functions to be called inside a contructor 7 | /// even if the contract is meant to be used without proxy 8 | modifier proxied() { 9 | address proxyAdminAddress = _proxyAdmin(); 10 | // With hardhat-deploy proxies 11 | // the proxyAdminAddress is zero only for the implementation contract 12 | // if the implementation contract want to be used as a standalone/immutable contract 13 | // it simply has to execute the `proxied` function 14 | // This ensure the proxyAdminAddress is never zero post deployment 15 | // And allow you to keep the same code for both proxied contract and immutable contract 16 | if (proxyAdminAddress == address(0)) { 17 | // ensure can not be called twice when used outside of proxy : no admin 18 | // solhint-disable-next-line security/no-inline-assembly 19 | assembly { 20 | sstore( 21 | 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, 22 | 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 23 | ) 24 | } 25 | } else { 26 | require(msg.sender == proxyAdminAddress); 27 | } 28 | _; 29 | } 30 | 31 | modifier onlyProxyAdmin() { 32 | require(msg.sender == _proxyAdmin(), "NOT_AUTHORIZED"); 33 | _; 34 | } 35 | 36 | function _proxyAdmin() internal view returns (address ownerAddress) { 37 | // solhint-disable-next-line security/no-inline-assembly 38 | assembly { 39 | ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103) 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /solc_0.7/diamond/UsingDiamondOwner.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.0; 3 | 4 | import "./libraries/LibDiamond.sol"; 5 | 6 | contract UsingDiamondOwner { 7 | modifier onlyOwner() { 8 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 9 | require(msg.sender == ds.contractOwner, "Only owner is allowed to perform this action"); 10 | _; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /solc_0.7/diamond/interfaces/IDiamondCut.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.6; 3 | pragma experimental ABIEncoderV2; 4 | 5 | /******************************************************************************\ 6 | * Author: Nick Mudge (https://twitter.com/mudgen) 7 | * EIP-2535 Diamond Standard: https://eips.ethereum.org/EIPS/eip-2535 8 | /******************************************************************************/ 9 | 10 | interface IDiamondCut { 11 | enum FacetCutAction {Add, Replace, Remove} 12 | // Add=0, Replace=1, Remove=2 13 | 14 | struct FacetCut { 15 | address facetAddress; 16 | FacetCutAction action; 17 | bytes4[] functionSelectors; 18 | } 19 | 20 | /// @notice Add/replace/remove any number of functions and optionally execute 21 | /// a function with delegatecall 22 | /// @param _diamondCut Contains the facet addresses and function selectors 23 | /// @param _init The address of the contract or facet to execute _calldata 24 | /// @param _calldata A function call, including function selector and arguments 25 | /// _calldata is executed with delegatecall on _init 26 | function diamondCut( 27 | FacetCut[] calldata _diamondCut, 28 | address _init, 29 | bytes calldata _calldata 30 | ) external; 31 | 32 | event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); 33 | } 34 | -------------------------------------------------------------------------------- /solc_0.7/diamond/libraries/LibDiamond.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.6; 3 | pragma experimental ABIEncoderV2; 4 | 5 | /******************************************************************************\ 6 | * Author: Nick Mudge (https://twitter.com/mudgen) 7 | * EIP-2535 Diamond Standard: https://eips.ethereum.org/EIPS/eip-2535 8 | /******************************************************************************/ 9 | 10 | import "../interfaces/IDiamondCut.sol"; 11 | 12 | library LibDiamond { 13 | bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.diamond.storage"); 14 | 15 | struct FacetAddressAndPosition { 16 | address facetAddress; 17 | uint16 functionSelectorPosition; // position in facetFunctionSelectors.functionSelectors array 18 | } 19 | 20 | struct FacetFunctionSelectors { 21 | bytes4[] functionSelectors; 22 | uint16 facetAddressPosition; // position of facetAddress in facetAddresses array 23 | } 24 | 25 | struct DiamondStorage { 26 | // maps function selector to the facet address and 27 | // the position of the selector in the facetFunctionSelectors.selectors array 28 | mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition; 29 | // maps facet addresses to function selectors 30 | mapping(address => FacetFunctionSelectors) facetFunctionSelectors; 31 | // facet addresses 32 | address[] facetAddresses; 33 | // Used to query if a contract implements an interface. 34 | // Used to implement ERC-165. 35 | mapping(bytes4 => bool) supportedInterfaces; 36 | // owner of the contract 37 | address contractOwner; 38 | } 39 | 40 | function diamondStorage() internal pure returns (DiamondStorage storage ds) { 41 | bytes32 position = DIAMOND_STORAGE_POSITION; 42 | assembly { 43 | ds.slot := position 44 | } 45 | } 46 | 47 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 48 | 49 | function setContractOwner(address _newOwner) internal { 50 | DiamondStorage storage ds = diamondStorage(); 51 | address previousOwner = ds.contractOwner; 52 | ds.contractOwner = _newOwner; 53 | emit OwnershipTransferred(previousOwner, _newOwner); 54 | } 55 | 56 | function contractOwner() internal view returns (address contractOwner_) { 57 | contractOwner_ = diamondStorage().contractOwner; 58 | } 59 | 60 | function enforceIsContractOwner() internal view { 61 | require(msg.sender == diamondStorage().contractOwner, "LibDiamond: Must be contract owner"); 62 | } 63 | 64 | event DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata); 65 | 66 | // Internal function version of diamondCut 67 | function diamondCut( 68 | IDiamondCut.FacetCut[] memory _diamondCut, 69 | address _init, 70 | bytes memory _calldata 71 | ) internal { 72 | for (uint256 facetIndex; facetIndex < _diamondCut.length; facetIndex++) { 73 | IDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action; 74 | if (action == IDiamondCut.FacetCutAction.Add) { 75 | addFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); 76 | } else if (action == IDiamondCut.FacetCutAction.Replace) { 77 | replaceFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); 78 | } else if (action == IDiamondCut.FacetCutAction.Remove) { 79 | removeFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); 80 | } else { 81 | revert("LibDiamondCut: Incorrect FacetCutAction"); 82 | } 83 | } 84 | emit DiamondCut(_diamondCut, _init, _calldata); 85 | initializeDiamondCut(_init, _calldata); 86 | } 87 | 88 | function addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { 89 | require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); 90 | DiamondStorage storage ds = diamondStorage(); 91 | // uint16 selectorCount = uint16(diamondStorage().selectors.length); 92 | require(_facetAddress != address(0), "LibDiamondCut: Add facet can't be address(0)"); 93 | uint16 selectorPosition = uint16(ds.facetFunctionSelectors[_facetAddress].functionSelectors.length); 94 | // add new facet address if it does not exist 95 | if (selectorPosition == 0) { 96 | enforceHasContractCode(_facetAddress, "LibDiamondCut: New facet has no code"); 97 | ds.facetFunctionSelectors[_facetAddress].facetAddressPosition = uint16(ds.facetAddresses.length); 98 | ds.facetAddresses.push(_facetAddress); 99 | } 100 | for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { 101 | bytes4 selector = _functionSelectors[selectorIndex]; 102 | address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress; 103 | require(oldFacetAddress == address(0), "LibDiamondCut: Can't add function that already exists"); 104 | ds.facetFunctionSelectors[_facetAddress].functionSelectors.push(selector); 105 | ds.selectorToFacetAndPosition[selector].facetAddress = _facetAddress; 106 | ds.selectorToFacetAndPosition[selector].functionSelectorPosition = selectorPosition; 107 | selectorPosition++; 108 | } 109 | } 110 | 111 | function replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { 112 | require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); 113 | DiamondStorage storage ds = diamondStorage(); 114 | require(_facetAddress != address(0), "LibDiamondCut: Add facet can't be address(0)"); 115 | uint16 selectorPosition = uint16(ds.facetFunctionSelectors[_facetAddress].functionSelectors.length); 116 | // add new facet address if it does not exist 117 | if (selectorPosition == 0) { 118 | enforceHasContractCode(_facetAddress, "LibDiamondCut: New facet has no code"); 119 | ds.facetFunctionSelectors[_facetAddress].facetAddressPosition = uint16(ds.facetAddresses.length); 120 | ds.facetAddresses.push(_facetAddress); 121 | } 122 | for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { 123 | bytes4 selector = _functionSelectors[selectorIndex]; 124 | address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress; 125 | require(oldFacetAddress != _facetAddress, "LibDiamondCut: Can't replace function with same function"); 126 | removeFunction(oldFacetAddress, selector); 127 | // add function 128 | ds.selectorToFacetAndPosition[selector].functionSelectorPosition = selectorPosition; 129 | ds.facetFunctionSelectors[_facetAddress].functionSelectors.push(selector); 130 | ds.selectorToFacetAndPosition[selector].facetAddress = _facetAddress; 131 | selectorPosition++; 132 | } 133 | } 134 | 135 | function removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { 136 | require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); 137 | DiamondStorage storage ds = diamondStorage(); 138 | // if function does not exist then do nothing and return 139 | require(_facetAddress == address(0), "LibDiamondCut: Remove facet address must be address(0)"); 140 | for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { 141 | bytes4 selector = _functionSelectors[selectorIndex]; 142 | address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress; 143 | removeFunction(oldFacetAddress, selector); 144 | } 145 | } 146 | 147 | function removeFunction(address _facetAddress, bytes4 _selector) internal { 148 | DiamondStorage storage ds = diamondStorage(); 149 | require(_facetAddress != address(0), "LibDiamondCut: Can't remove function that doesn't exist"); 150 | // an immutable function is a function defined directly in a diamond 151 | require(_facetAddress != address(this), "LibDiamondCut: Can't remove immutable function"); 152 | // replace selector with last selector, then delete last selector 153 | uint256 selectorPosition = ds.selectorToFacetAndPosition[_selector].functionSelectorPosition; 154 | uint256 lastSelectorPosition = ds.facetFunctionSelectors[_facetAddress].functionSelectors.length - 1; 155 | // if not the same then replace _selector with lastSelector 156 | if (selectorPosition != lastSelectorPosition) { 157 | bytes4 lastSelector = ds.facetFunctionSelectors[_facetAddress].functionSelectors[lastSelectorPosition]; 158 | ds.facetFunctionSelectors[_facetAddress].functionSelectors[selectorPosition] = lastSelector; 159 | ds.selectorToFacetAndPosition[lastSelector].functionSelectorPosition = uint16(selectorPosition); 160 | } 161 | // delete the last selector 162 | ds.facetFunctionSelectors[_facetAddress].functionSelectors.pop(); 163 | delete ds.selectorToFacetAndPosition[_selector]; 164 | 165 | // if no more selectors for facet address then delete the facet address 166 | if (lastSelectorPosition == 0) { 167 | // replace facet address with last facet address and delete last facet address 168 | uint256 lastFacetAddressPosition = ds.facetAddresses.length - 1; 169 | uint256 facetAddressPosition = ds.facetFunctionSelectors[_facetAddress].facetAddressPosition; 170 | if (facetAddressPosition != lastFacetAddressPosition) { 171 | address lastFacetAddress = ds.facetAddresses[lastFacetAddressPosition]; 172 | ds.facetAddresses[facetAddressPosition] = lastFacetAddress; 173 | ds.facetFunctionSelectors[lastFacetAddress].facetAddressPosition = uint16(facetAddressPosition); 174 | } 175 | ds.facetAddresses.pop(); 176 | delete ds.facetFunctionSelectors[_facetAddress].facetAddressPosition; 177 | } 178 | } 179 | 180 | function initializeDiamondCut(address _init, bytes memory _calldata) internal { 181 | if (_init == address(0)) { 182 | require(_calldata.length == 0, "LibDiamondCut: _init is address(0) but_calldata is not empty"); 183 | } else { 184 | require(_calldata.length > 0, "LibDiamondCut: _calldata is empty but _init is not address(0)"); 185 | if (_init != address(this)) { 186 | enforceHasContractCode(_init, "LibDiamondCut: _init address has no code"); 187 | } 188 | (bool success, bytes memory error) = _init.delegatecall(_calldata); 189 | if (!success) { 190 | if (error.length > 0) { 191 | // bubble up the error 192 | revert(string(error)); 193 | } else { 194 | revert("LibDiamondCut: _init function reverted"); 195 | } 196 | } 197 | } 198 | } 199 | 200 | function enforceHasContractCode(address _contract, string memory _errorMessage) internal view { 201 | uint256 contractSize; 202 | assembly { 203 | contractSize := extcodesize(_contract) 204 | } 205 | require(contractSize > 0, _errorMessage); 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /solc_0.7/proxy/Proxied.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.0; 3 | 4 | abstract contract Proxied { 5 | /// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them 6 | /// It also allows these functions to be called inside a contructor 7 | /// even if the contract is meant to be used without proxy 8 | modifier proxied() { 9 | address proxyAdminAddress = _proxyAdmin(); 10 | // With hardhat-deploy proxies 11 | // the proxyAdminAddress is zero only for the implementation contract 12 | // if the implementation contract want to be used as a standalone/immutable contract 13 | // it simply has to execute the `proxied` function 14 | // This ensure the proxyAdminAddress is never zero post deployment 15 | // And allow you to keep the same code for both proxied contract and immutable contract 16 | if (proxyAdminAddress == address(0)) { 17 | // ensure can not be called twice when used outside of proxy : no admin 18 | // solhint-disable-next-line security/no-inline-assembly 19 | assembly { 20 | sstore( 21 | 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, 22 | 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 23 | ) 24 | } 25 | } else { 26 | require(msg.sender == proxyAdminAddress); 27 | } 28 | _; 29 | } 30 | 31 | modifier onlyProxyAdmin() { 32 | require(msg.sender == _proxyAdmin(), "NOT_AUTHORIZED"); 33 | _; 34 | } 35 | 36 | function _proxyAdmin() internal view returns (address ownerAddress) { 37 | // solhint-disable-next-line security/no-inline-assembly 38 | assembly { 39 | ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103) 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /solc_0.8/diamond/Diamond.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /******************************************************************************\ 5 | * Author: Nick Mudge (https://twitter.com/mudgen) 6 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 7 | * 8 | * Implementation of a diamond. 9 | /******************************************************************************/ 10 | 11 | import {LibDiamond} from "./libraries/LibDiamond.sol"; 12 | import {IDiamondCut} from "./interfaces/IDiamondCut.sol"; 13 | 14 | contract Diamond { 15 | struct Initialization { 16 | address initContract; 17 | bytes initData; 18 | } 19 | 20 | /// @notice This construct a diamond contract 21 | /// @param _contractOwner the owner of the contract. With default DiamondCutFacet, this is the sole address allowed to make further cuts. 22 | /// @param _diamondCut the list of facet to add 23 | /// @param _initializations the list of initialization pair to execute. This allow to setup a contract with multiple level of independent initialization. 24 | constructor( 25 | address _contractOwner, 26 | IDiamondCut.FacetCut[] memory _diamondCut, 27 | Initialization[] memory _initializations 28 | ) payable { 29 | if (_contractOwner != address(0)) { 30 | LibDiamond.setContractOwner(_contractOwner); 31 | } 32 | 33 | LibDiamond.diamondCut(_diamondCut, address(0), ""); 34 | 35 | for (uint256 i = 0; i < _initializations.length; i++) { 36 | LibDiamond.initializeDiamondCut(_initializations[i].initContract, _initializations[i].initData); 37 | } 38 | } 39 | 40 | // Find facet for function that is called and execute the 41 | // function if a facet is found and return any value. 42 | fallback() external payable { 43 | LibDiamond.DiamondStorage storage ds; 44 | bytes32 position = LibDiamond.DIAMOND_STORAGE_POSITION; 45 | // get diamond storage 46 | assembly { 47 | ds.slot := position 48 | } 49 | // get facet from function selector 50 | address facet = ds.selectorToFacetAndPosition[msg.sig].facetAddress; 51 | require(facet != address(0), "Diamond: Function does not exist"); 52 | // Execute external function from facet using delegatecall and return any value. 53 | assembly { 54 | // copy function selector and any arguments 55 | calldatacopy(0, 0, calldatasize()) 56 | // execute function call using the facet 57 | let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0) 58 | // get any return value 59 | returndatacopy(0, 0, returndatasize()) 60 | // return any return value or error back to the caller 61 | switch result 62 | case 0 { 63 | revert(0, returndatasize()) 64 | } 65 | default { 66 | return(0, returndatasize()) 67 | } 68 | } 69 | } 70 | 71 | receive() external payable {} 72 | } 73 | -------------------------------------------------------------------------------- /solc_0.8/diamond/UsingDiamondOwner.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./libraries/LibDiamond.sol"; 5 | 6 | contract UsingDiamondOwner { 7 | modifier onlyOwner() { 8 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 9 | require(msg.sender == ds.contractOwner, "Only owner is allowed to perform this action"); 10 | _; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /solc_0.8/diamond/facets/DiamondCutFacet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /******************************************************************************\ 5 | * Author: Nick Mudge (https://twitter.com/mudgen) 6 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 7 | /******************************************************************************/ 8 | 9 | import { IDiamondCut } from "../interfaces/IDiamondCut.sol"; 10 | import { LibDiamond } from "../libraries/LibDiamond.sol"; 11 | 12 | contract DiamondCutFacet is IDiamondCut { 13 | /// @notice Add/replace/remove any number of functions and optionally execute 14 | /// a function with delegatecall 15 | /// @param _diamondCut Contains the facet addresses and function selectors 16 | /// @param _init The address of the contract or facet to execute _calldata 17 | /// @param _calldata A function call, including function selector and arguments 18 | /// _calldata is executed with delegatecall on _init 19 | function diamondCut( 20 | FacetCut[] calldata _diamondCut, 21 | address _init, 22 | bytes calldata _calldata 23 | ) external override { 24 | LibDiamond.enforceIsContractOwner(); 25 | LibDiamond.diamondCut(_diamondCut, _init, _calldata); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /solc_0.8/diamond/facets/DiamondLoupeFacet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | /******************************************************************************\ 4 | * Author: Nick Mudge (https://twitter.com/mudgen) 5 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 6 | /******************************************************************************/ 7 | 8 | import { LibDiamond } from "../libraries/LibDiamond.sol"; 9 | import { IDiamondLoupe } from "../interfaces/IDiamondLoupe.sol"; 10 | import { IERC165 } from "../interfaces/IERC165.sol"; 11 | 12 | contract DiamondLoupeFacet is IDiamondLoupe, IERC165 { 13 | // Diamond Loupe Functions 14 | //////////////////////////////////////////////////////////////////// 15 | /// These functions are expected to be called frequently by tools. 16 | // 17 | // struct Facet { 18 | // address facetAddress; 19 | // bytes4[] functionSelectors; 20 | // } 21 | 22 | /// @notice Gets all facets and their selectors. 23 | /// @return facets_ Facet 24 | function facets() external override view returns (Facet[] memory facets_) { 25 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 26 | uint256 numFacets = ds.facetAddresses.length; 27 | facets_ = new Facet[](numFacets); 28 | for (uint256 i; i < numFacets; i++) { 29 | address facetAddress_ = ds.facetAddresses[i]; 30 | facets_[i].facetAddress = facetAddress_; 31 | facets_[i].functionSelectors = ds.facetFunctionSelectors[facetAddress_].functionSelectors; 32 | } 33 | } 34 | 35 | /// @notice Gets all the function selectors provided by a facet. 36 | /// @param _facet The facet address. 37 | /// @return facetFunctionSelectors_ 38 | function facetFunctionSelectors(address _facet) external override view returns (bytes4[] memory facetFunctionSelectors_) { 39 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 40 | facetFunctionSelectors_ = ds.facetFunctionSelectors[_facet].functionSelectors; 41 | } 42 | 43 | /// @notice Get all the facet addresses used by a diamond. 44 | /// @return facetAddresses_ 45 | function facetAddresses() external override view returns (address[] memory facetAddresses_) { 46 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 47 | facetAddresses_ = ds.facetAddresses; 48 | } 49 | 50 | /// @notice Gets the facet that supports the given selector. 51 | /// @dev If facet is not found return address(0). 52 | /// @param _functionSelector The function selector. 53 | /// @return facetAddress_ The facet address. 54 | function facetAddress(bytes4 _functionSelector) external override view returns (address facetAddress_) { 55 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 56 | facetAddress_ = ds.selectorToFacetAndPosition[_functionSelector].facetAddress; 57 | } 58 | 59 | // This implements ERC-165. 60 | function supportsInterface(bytes4 _interfaceId) external override view returns (bool) { 61 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 62 | return ds.supportedInterfaces[_interfaceId]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /solc_0.8/diamond/facets/DiamondLoupeFacetWithoutSupportsInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | /******************************************************************************\ 4 | * Author: Nick Mudge (https://twitter.com/mudgen) 5 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 6 | /******************************************************************************/ 7 | 8 | import {LibDiamond} from "../libraries/LibDiamond.sol"; 9 | import {IDiamondLoupe} from "../interfaces/IDiamondLoupe.sol"; 10 | 11 | contract DiamondLoupeFacetWithoutSupportsInterface is IDiamondLoupe { 12 | // Diamond Loupe Functions 13 | //////////////////////////////////////////////////////////////////// 14 | /// These functions are expected to be called frequently by tools. 15 | // 16 | // struct Facet { 17 | // address facetAddress; 18 | // bytes4[] functionSelectors; 19 | // } 20 | 21 | /// @notice Gets all facets and their selectors. 22 | /// @return facets_ Facet 23 | function facets() external view override returns (Facet[] memory facets_) { 24 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 25 | uint256 numFacets = ds.facetAddresses.length; 26 | facets_ = new Facet[](numFacets); 27 | for (uint256 i; i < numFacets; i++) { 28 | address facetAddress_ = ds.facetAddresses[i]; 29 | facets_[i].facetAddress = facetAddress_; 30 | facets_[i].functionSelectors = ds.facetFunctionSelectors[facetAddress_].functionSelectors; 31 | } 32 | } 33 | 34 | /// @notice Gets all the function selectors provided by a facet. 35 | /// @param _facet The facet address. 36 | /// @return facetFunctionSelectors_ 37 | function facetFunctionSelectors(address _facet) external view override returns (bytes4[] memory facetFunctionSelectors_) { 38 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 39 | facetFunctionSelectors_ = ds.facetFunctionSelectors[_facet].functionSelectors; 40 | } 41 | 42 | /// @notice Get all the facet addresses used by a diamond. 43 | /// @return facetAddresses_ 44 | function facetAddresses() external view override returns (address[] memory facetAddresses_) { 45 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 46 | facetAddresses_ = ds.facetAddresses; 47 | } 48 | 49 | /// @notice Gets the facet that supports the given selector. 50 | /// @dev If facet is not found return address(0). 51 | /// @param _functionSelector The function selector. 52 | /// @return facetAddress_ The facet address. 53 | function facetAddress(bytes4 _functionSelector) external view override returns (address facetAddress_) { 54 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 55 | facetAddress_ = ds.selectorToFacetAndPosition[_functionSelector].facetAddress; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /solc_0.8/diamond/facets/OwnershipFacet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import { LibDiamond } from "../libraries/LibDiamond.sol"; 5 | import { IERC173 } from "../interfaces/IERC173.sol"; 6 | 7 | contract OwnershipFacet is IERC173 { 8 | function transferOwnership(address _newOwner) external override { 9 | LibDiamond.enforceIsContractOwner(); 10 | LibDiamond.setContractOwner(_newOwner); 11 | } 12 | 13 | function owner() external override view returns (address owner_) { 14 | owner_ = LibDiamond.contractOwner(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /solc_0.8/diamond/initializers/DiamondERC165Init.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import {LibDiamond} from "../libraries/LibDiamond.sol"; 5 | import {IERC165} from "../interfaces/IERC165.sol"; 6 | 7 | contract DiamondERC165Init { 8 | /// @notice set or unset ERC165 using DiamondStorage.supportedInterfaces 9 | /// @param interfaceIds list of interface id to set as supported 10 | /// @param interfaceIdsToRemove list of interface id to unset as supported. 11 | /// Technically, you can remove support of ERC165 by having the IERC165 id itself being part of that array. 12 | function setERC165(bytes4[] calldata interfaceIds, bytes4[] calldata interfaceIdsToRemove) external { 13 | LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); 14 | 15 | ds.supportedInterfaces[type(IERC165).interfaceId] = true; 16 | 17 | for (uint256 i = 0; i < interfaceIds.length; i++) { 18 | ds.supportedInterfaces[interfaceIds[i]] = true; 19 | } 20 | 21 | for (uint256 i = 0; i < interfaceIdsToRemove.length; i++) { 22 | ds.supportedInterfaces[interfaceIdsToRemove[i]] = false; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /solc_0.8/diamond/interfaces/IDiamondCut.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /******************************************************************************\ 5 | * Author: Nick Mudge (https://twitter.com/mudgen) 6 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 7 | /******************************************************************************/ 8 | 9 | interface IDiamondCut { 10 | enum FacetCutAction {Add, Replace, Remove} 11 | // Add=0, Replace=1, Remove=2 12 | 13 | struct FacetCut { 14 | address facetAddress; 15 | FacetCutAction action; 16 | bytes4[] functionSelectors; 17 | } 18 | 19 | /// @notice Add/replace/remove any number of functions and optionally execute 20 | /// a function with delegatecall 21 | /// @param _diamondCut Contains the facet addresses and function selectors 22 | /// @param _init The address of the contract or facet to execute _calldata 23 | /// @param _calldata A function call, including function selector and arguments 24 | /// _calldata is executed with delegatecall on _init 25 | function diamondCut( 26 | FacetCut[] calldata _diamondCut, 27 | address _init, 28 | bytes calldata _calldata 29 | ) external; 30 | 31 | event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); 32 | } 33 | -------------------------------------------------------------------------------- /solc_0.8/diamond/interfaces/IDiamondLoupe.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /******************************************************************************\ 5 | * Author: Nick Mudge (https://twitter.com/mudgen) 6 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 7 | /******************************************************************************/ 8 | 9 | // A loupe is a small magnifying glass used to look at diamonds. 10 | // These functions look at diamonds 11 | interface IDiamondLoupe { 12 | /// These functions are expected to be called frequently 13 | /// by tools. 14 | 15 | struct Facet { 16 | address facetAddress; 17 | bytes4[] functionSelectors; 18 | } 19 | 20 | /// @notice Gets all facet addresses and their four byte function selectors. 21 | /// @return facets_ Facet 22 | function facets() external view returns (Facet[] memory facets_); 23 | 24 | /// @notice Gets all the function selectors supported by a specific facet. 25 | /// @param _facet The facet address. 26 | /// @return facetFunctionSelectors_ 27 | function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetFunctionSelectors_); 28 | 29 | /// @notice Get all the facet addresses used by a diamond. 30 | /// @return facetAddresses_ 31 | function facetAddresses() external view returns (address[] memory facetAddresses_); 32 | 33 | /// @notice Gets the facet that supports the given selector. 34 | /// @dev If facet is not found return address(0). 35 | /// @param _functionSelector The function selector. 36 | /// @return facetAddress_ The facet address. 37 | function facetAddress(bytes4 _functionSelector) external view returns (address facetAddress_); 38 | } 39 | -------------------------------------------------------------------------------- /solc_0.8/diamond/interfaces/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IERC165 { 5 | /// @notice Query if a contract implements an interface 6 | /// @param interfaceId The interface identifier, as specified in ERC-165 7 | /// @dev Interface identification is specified in ERC-165. This function 8 | /// uses less than 30,000 gas. 9 | /// @return `true` if the contract implements `interfaceID` and 10 | /// `interfaceID` is not 0xffffffff, `false` otherwise 11 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 12 | } 13 | -------------------------------------------------------------------------------- /solc_0.8/diamond/interfaces/IERC173.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /// @title ERC-173 Contract Ownership Standard 5 | /// Note: the ERC-165 identifier for this interface is 0x7f5828d0 6 | /* is ERC165 */ 7 | interface IERC173 { 8 | /// @dev This emits when ownership of a contract changes. 9 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 10 | 11 | /// @notice Get the address of the owner 12 | /// @return owner_ The address of the owner. 13 | function owner() external view returns (address owner_); 14 | 15 | /// @notice Set the address of the new owner of the contract 16 | /// @dev Set _newOwner to address(0) to renounce any ownership. 17 | /// @param _newOwner The address of the new owner of the contract 18 | function transferOwnership(address _newOwner) external; 19 | } 20 | -------------------------------------------------------------------------------- /solc_0.8/diamond/libraries/LibDiamond.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /******************************************************************************\ 5 | * Author: Nick Mudge (https://twitter.com/mudgen) 6 | * EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 7 | /******************************************************************************/ 8 | import { IDiamondCut } from "../interfaces/IDiamondCut.sol"; 9 | 10 | library LibDiamond { 11 | bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.diamond.storage"); 12 | 13 | struct FacetAddressAndPosition { 14 | address facetAddress; 15 | uint96 functionSelectorPosition; // position in facetFunctionSelectors.functionSelectors array 16 | } 17 | 18 | struct FacetFunctionSelectors { 19 | bytes4[] functionSelectors; 20 | uint256 facetAddressPosition; // position of facetAddress in facetAddresses array 21 | } 22 | 23 | struct DiamondStorage { 24 | // maps function selector to the facet address and 25 | // the position of the selector in the facetFunctionSelectors.selectors array 26 | mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition; 27 | // maps facet addresses to function selectors 28 | mapping(address => FacetFunctionSelectors) facetFunctionSelectors; 29 | // facet addresses 30 | address[] facetAddresses; 31 | // Used to query if a contract implements an interface. 32 | // Used to implement ERC-165. 33 | mapping(bytes4 => bool) supportedInterfaces; 34 | // owner of the contract 35 | address contractOwner; 36 | } 37 | 38 | function diamondStorage() internal pure returns (DiamondStorage storage ds) { 39 | bytes32 position = DIAMOND_STORAGE_POSITION; 40 | assembly { 41 | ds.slot := position 42 | } 43 | } 44 | 45 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 46 | 47 | function setContractOwner(address _newOwner) internal { 48 | DiamondStorage storage ds = diamondStorage(); 49 | address previousOwner = ds.contractOwner; 50 | ds.contractOwner = _newOwner; 51 | emit OwnershipTransferred(previousOwner, _newOwner); 52 | } 53 | 54 | function contractOwner() internal view returns (address contractOwner_) { 55 | contractOwner_ = diamondStorage().contractOwner; 56 | } 57 | 58 | function enforceIsContractOwner() internal view { 59 | require(msg.sender == diamondStorage().contractOwner, "LibDiamond: Must be contract owner"); 60 | } 61 | 62 | event DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata); 63 | 64 | // Internal function version of diamondCut 65 | function diamondCut( 66 | IDiamondCut.FacetCut[] memory _diamondCut, 67 | address _init, 68 | bytes memory _calldata 69 | ) internal { 70 | for (uint256 facetIndex; facetIndex < _diamondCut.length; facetIndex++) { 71 | IDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action; 72 | if (action == IDiamondCut.FacetCutAction.Add) { 73 | addFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); 74 | } else if (action == IDiamondCut.FacetCutAction.Replace) { 75 | replaceFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); 76 | } else if (action == IDiamondCut.FacetCutAction.Remove) { 77 | removeFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors); 78 | } else { 79 | revert("LibDiamondCut: Incorrect FacetCutAction"); 80 | } 81 | } 82 | emit DiamondCut(_diamondCut, _init, _calldata); 83 | initializeDiamondCut(_init, _calldata); 84 | } 85 | 86 | function addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { 87 | require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); 88 | DiamondStorage storage ds = diamondStorage(); 89 | require(_facetAddress != address(0), "LibDiamondCut: Add facet can't be address(0)"); 90 | uint96 selectorPosition = uint96(ds.facetFunctionSelectors[_facetAddress].functionSelectors.length); 91 | // add new facet address if it does not exist 92 | if (selectorPosition == 0) { 93 | addFacet(ds, _facetAddress); 94 | } 95 | for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { 96 | bytes4 selector = _functionSelectors[selectorIndex]; 97 | address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress; 98 | require(oldFacetAddress == address(0), "LibDiamondCut: Can't add function that already exists"); 99 | addFunction(ds, selector, selectorPosition, _facetAddress); 100 | selectorPosition++; 101 | } 102 | } 103 | 104 | function replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { 105 | require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); 106 | DiamondStorage storage ds = diamondStorage(); 107 | require(_facetAddress != address(0), "LibDiamondCut: Add facet can't be address(0)"); 108 | uint96 selectorPosition = uint96(ds.facetFunctionSelectors[_facetAddress].functionSelectors.length); 109 | // add new facet address if it does not exist 110 | if (selectorPosition == 0) { 111 | addFacet(ds, _facetAddress); 112 | } 113 | for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { 114 | bytes4 selector = _functionSelectors[selectorIndex]; 115 | address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress; 116 | require(oldFacetAddress != _facetAddress, "LibDiamondCut: Can't replace function with same function"); 117 | removeFunction(ds, oldFacetAddress, selector); 118 | addFunction(ds, selector, selectorPosition, _facetAddress); 119 | selectorPosition++; 120 | } 121 | } 122 | 123 | function removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal { 124 | require(_functionSelectors.length > 0, "LibDiamondCut: No selectors in facet to cut"); 125 | DiamondStorage storage ds = diamondStorage(); 126 | // if function does not exist then do nothing and return 127 | require(_facetAddress == address(0), "LibDiamondCut: Remove facet address must be address(0)"); 128 | for (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) { 129 | bytes4 selector = _functionSelectors[selectorIndex]; 130 | address oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress; 131 | removeFunction(ds, oldFacetAddress, selector); 132 | } 133 | } 134 | 135 | function addFacet(DiamondStorage storage ds, address _facetAddress) internal { 136 | enforceHasContractCode(_facetAddress, "LibDiamondCut: New facet has no code"); 137 | ds.facetFunctionSelectors[_facetAddress].facetAddressPosition = ds.facetAddresses.length; 138 | ds.facetAddresses.push(_facetAddress); 139 | } 140 | 141 | 142 | function addFunction(DiamondStorage storage ds, bytes4 _selector, uint96 _selectorPosition, address _facetAddress) internal { 143 | ds.selectorToFacetAndPosition[_selector].functionSelectorPosition = _selectorPosition; 144 | ds.facetFunctionSelectors[_facetAddress].functionSelectors.push(_selector); 145 | ds.selectorToFacetAndPosition[_selector].facetAddress = _facetAddress; 146 | } 147 | 148 | function removeFunction(DiamondStorage storage ds, address _facetAddress, bytes4 _selector) internal { 149 | require(_facetAddress != address(0), "LibDiamondCut: Can't remove function that doesn't exist"); 150 | // an immutable function is a function defined directly in a diamond 151 | require(_facetAddress != address(this), "LibDiamondCut: Can't remove immutable function"); 152 | // replace selector with last selector, then delete last selector 153 | uint256 selectorPosition = ds.selectorToFacetAndPosition[_selector].functionSelectorPosition; 154 | uint256 lastSelectorPosition = ds.facetFunctionSelectors[_facetAddress].functionSelectors.length - 1; 155 | // if not the same then replace _selector with lastSelector 156 | if (selectorPosition != lastSelectorPosition) { 157 | bytes4 lastSelector = ds.facetFunctionSelectors[_facetAddress].functionSelectors[lastSelectorPosition]; 158 | ds.facetFunctionSelectors[_facetAddress].functionSelectors[selectorPosition] = lastSelector; 159 | ds.selectorToFacetAndPosition[lastSelector].functionSelectorPosition = uint96(selectorPosition); 160 | } 161 | // delete the last selector 162 | ds.facetFunctionSelectors[_facetAddress].functionSelectors.pop(); 163 | delete ds.selectorToFacetAndPosition[_selector]; 164 | 165 | // if no more selectors for facet address then delete the facet address 166 | if (lastSelectorPosition == 0) { 167 | // replace facet address with last facet address and delete last facet address 168 | uint256 lastFacetAddressPosition = ds.facetAddresses.length - 1; 169 | uint256 facetAddressPosition = ds.facetFunctionSelectors[_facetAddress].facetAddressPosition; 170 | if (facetAddressPosition != lastFacetAddressPosition) { 171 | address lastFacetAddress = ds.facetAddresses[lastFacetAddressPosition]; 172 | ds.facetAddresses[facetAddressPosition] = lastFacetAddress; 173 | ds.facetFunctionSelectors[lastFacetAddress].facetAddressPosition = facetAddressPosition; 174 | } 175 | ds.facetAddresses.pop(); 176 | delete ds.facetFunctionSelectors[_facetAddress].facetAddressPosition; 177 | } 178 | } 179 | 180 | function initializeDiamondCut(address _init, bytes memory _calldata) internal { 181 | if (_init == address(0)) { 182 | require(_calldata.length == 0, "LibDiamondCut: _init is address(0) but_calldata is not empty"); 183 | } else { 184 | require(_calldata.length > 0, "LibDiamondCut: _calldata is empty but _init is not address(0)"); 185 | if (_init != address(this)) { 186 | enforceHasContractCode(_init, "LibDiamondCut: _init address has no code"); 187 | } 188 | (bool success, bytes memory error) = _init.delegatecall(_calldata); 189 | if (!success) { 190 | if (error.length > 0) { 191 | // bubble up the error 192 | revert(string(error)); 193 | } else { 194 | revert("LibDiamondCut: _init function reverted"); 195 | } 196 | } 197 | } 198 | } 199 | 200 | function enforceHasContractCode(address _contract, string memory _errorMessage) internal view { 201 | uint256 contractSize; 202 | assembly { 203 | contractSize := extcodesize(_contract) 204 | } 205 | require(contractSize > 0, _errorMessage); 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/access/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../utils/Context.sol"; 7 | 8 | /** 9 | * @dev Contract module which provides a basic access control mechanism, where 10 | * there is an account (an owner) that can be granted exclusive access to 11 | * specific functions. 12 | * 13 | * By default, the owner account will be the one that deploys the contract. This 14 | * can later be changed with {transferOwnership}. 15 | * 16 | * This module is used through inheritance. It will make available the modifier 17 | * `onlyOwner`, which can be applied to your functions to restrict their use to 18 | * the owner. 19 | */ 20 | abstract contract Ownable is Context { 21 | address private _owner; 22 | 23 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 24 | 25 | /** 26 | * @dev Initializes the contract setting the deployer as the initial owner. 27 | */ 28 | constructor (address initialOwner) { 29 | _transferOwnership(initialOwner); 30 | } 31 | 32 | /** 33 | * @dev Returns the address of the current owner. 34 | */ 35 | function owner() public view virtual returns (address) { 36 | return _owner; 37 | } 38 | 39 | /** 40 | * @dev Throws if called by any account other than the owner. 41 | */ 42 | modifier onlyOwner() { 43 | require(owner() == _msgSender(), "Ownable: caller is not the owner"); 44 | _; 45 | } 46 | 47 | /** 48 | * @dev Leaves the contract without owner. It will not be possible to call 49 | * `onlyOwner` functions anymore. Can only be called by the current owner. 50 | * 51 | * NOTE: Renouncing ownership will leave the contract without an owner, 52 | * thereby removing any functionality that is only available to the owner. 53 | */ 54 | function renounceOwnership() public virtual onlyOwner { 55 | _transferOwnership(address(0)); 56 | } 57 | 58 | /** 59 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 60 | * Can only be called by the current owner. 61 | */ 62 | function transferOwnership(address newOwner) public virtual onlyOwner { 63 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 64 | _transferOwnership(newOwner); 65 | } 66 | 67 | /** 68 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 69 | * Internal function without access restriction. 70 | */ 71 | function _transferOwnership(address newOwner) internal virtual { 72 | address oldOwner = _owner; 73 | _owner = newOwner; 74 | emit OwnershipTransferred(oldOwner, newOwner); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/interfaces/draft-IERC1822.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (interfaces/draft-IERC1822.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified 8 | * proxy whose upgrades are fully controlled by the current implementation. 9 | */ 10 | interface IERC1822Proxiable { 11 | /** 12 | * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation 13 | * address. 14 | * 15 | * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks 16 | * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this 17 | * function revert if invoked through a proxy. 18 | */ 19 | function proxiableUUID() external view returns (bytes32); 20 | } 21 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/Clones.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (proxy/Clones.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for 8 | * deploying minimal proxy contracts, also known as "clones". 9 | * 10 | * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies 11 | * > a minimal bytecode implementation that delegates all calls to a known, fixed address. 12 | * 13 | * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` 14 | * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the 15 | * deterministic method. 16 | * 17 | * _Available since v3.4._ 18 | */ 19 | library Clones { 20 | /** 21 | * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. 22 | * 23 | * This function uses the create opcode, which should never revert. 24 | */ 25 | function clone(address implementation) internal returns (address instance) { 26 | assembly { 27 | let ptr := mload(0x40) 28 | mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) 29 | mstore(add(ptr, 0x14), shl(0x60, implementation)) 30 | mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) 31 | instance := create(0, ptr, 0x37) 32 | } 33 | require(instance != address(0), "ERC1167: create failed"); 34 | } 35 | 36 | /** 37 | * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. 38 | * 39 | * This function uses the create2 opcode and a `salt` to deterministically deploy 40 | * the clone. Using the same `implementation` and `salt` multiple time will revert, since 41 | * the clones cannot be deployed twice at the same address. 42 | */ 43 | function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { 44 | assembly { 45 | let ptr := mload(0x40) 46 | mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) 47 | mstore(add(ptr, 0x14), shl(0x60, implementation)) 48 | mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) 49 | instance := create2(0, ptr, 0x37, salt) 50 | } 51 | require(instance != address(0), "ERC1167: create2 failed"); 52 | } 53 | 54 | /** 55 | * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. 56 | */ 57 | function predictDeterministicAddress( 58 | address implementation, 59 | bytes32 salt, 60 | address deployer 61 | ) internal pure returns (address predicted) { 62 | assembly { 63 | let ptr := mload(0x40) 64 | mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) 65 | mstore(add(ptr, 0x14), shl(0x60, implementation)) 66 | mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000) 67 | mstore(add(ptr, 0x38), shl(0x60, deployer)) 68 | mstore(add(ptr, 0x4c), salt) 69 | mstore(add(ptr, 0x6c), keccak256(ptr, 0x37)) 70 | predicted := keccak256(add(ptr, 0x37), 0x55) 71 | } 72 | } 73 | 74 | /** 75 | * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. 76 | */ 77 | function predictDeterministicAddress(address implementation, bytes32 salt) 78 | internal 79 | view 80 | returns (address predicted) 81 | { 82 | return predictDeterministicAddress(implementation, salt, address(this)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/ERC1967/ERC1967Proxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Proxy.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../Proxy.sol"; 7 | import "./ERC1967Upgrade.sol"; 8 | 9 | /** 10 | * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an 11 | * implementation address that can be changed. This address is stored in storage in the location specified by 12 | * https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the 13 | * implementation behind the proxy. 14 | */ 15 | contract ERC1967Proxy is Proxy, ERC1967Upgrade { 16 | /** 17 | * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`. 18 | * 19 | * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded 20 | * function call, and allows initializating the storage of the proxy like a Solidity constructor. 21 | */ 22 | constructor(address _logic, bytes memory _data) payable { 23 | assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); 24 | _upgradeToAndCall(_logic, _data, false); 25 | } 26 | 27 | /** 28 | * @dev Returns the current implementation address. 29 | */ 30 | function _implementation() internal view virtual override returns (address impl) { 31 | return ERC1967Upgrade._getImplementation(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/ERC1967/ERC1967Upgrade.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (proxy/ERC1967/ERC1967Upgrade.sol) 3 | 4 | pragma solidity ^0.8.2; 5 | 6 | import "../beacon/IBeacon.sol"; 7 | import "../../interfaces/draft-IERC1822.sol"; 8 | import "../../utils/Address.sol"; 9 | import "../../utils/StorageSlot.sol"; 10 | 11 | /** 12 | * @dev This abstract contract provides getters and event emitting update functions for 13 | * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. 14 | * 15 | * _Available since v4.1._ 16 | * 17 | * @custom:oz-upgrades-unsafe-allow delegatecall 18 | */ 19 | abstract contract ERC1967Upgrade { 20 | // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 21 | bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; 22 | 23 | /** 24 | * @dev Storage slot with the address of the current implementation. 25 | * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is 26 | * validated in the constructor. 27 | */ 28 | bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; 29 | 30 | /** 31 | * @dev Emitted when the implementation is upgraded. 32 | */ 33 | event Upgraded(address indexed implementation); 34 | 35 | /** 36 | * @dev Returns the current implementation address. 37 | */ 38 | function _getImplementation() internal view returns (address) { 39 | return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; 40 | } 41 | 42 | /** 43 | * @dev Stores a new address in the EIP1967 implementation slot. 44 | */ 45 | function _setImplementation(address newImplementation) private { 46 | require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); 47 | StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; 48 | } 49 | 50 | /** 51 | * @dev Perform implementation upgrade 52 | * 53 | * Emits an {Upgraded} event. 54 | */ 55 | function _upgradeTo(address newImplementation) internal { 56 | _setImplementation(newImplementation); 57 | emit Upgraded(newImplementation); 58 | } 59 | 60 | /** 61 | * @dev Perform implementation upgrade with additional setup call. 62 | * 63 | * Emits an {Upgraded} event. 64 | */ 65 | function _upgradeToAndCall( 66 | address newImplementation, 67 | bytes memory data, 68 | bool forceCall 69 | ) internal { 70 | _upgradeTo(newImplementation); 71 | if (data.length > 0 || forceCall) { 72 | Address.functionDelegateCall(newImplementation, data); 73 | } 74 | } 75 | 76 | /** 77 | * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. 78 | * 79 | * Emits an {Upgraded} event. 80 | */ 81 | function _upgradeToAndCallUUPS( 82 | address newImplementation, 83 | bytes memory data, 84 | bool forceCall 85 | ) internal { 86 | // Upgrades from old implementations will perform a rollback test. This test requires the new 87 | // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing 88 | // this special case will break upgrade paths from old UUPS implementation to new ones. 89 | if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) { 90 | _setImplementation(newImplementation); 91 | } else { 92 | try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) { 93 | require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID"); 94 | } catch { 95 | revert("ERC1967Upgrade: new implementation is not UUPS"); 96 | } 97 | _upgradeToAndCall(newImplementation, data, forceCall); 98 | } 99 | } 100 | 101 | /** 102 | * @dev Storage slot with the admin of the contract. 103 | * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is 104 | * validated in the constructor. 105 | */ 106 | bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; 107 | 108 | /** 109 | * @dev Emitted when the admin account has changed. 110 | */ 111 | event AdminChanged(address previousAdmin, address newAdmin); 112 | 113 | /** 114 | * @dev Returns the current admin. 115 | */ 116 | function _getAdmin() internal view virtual returns (address) { 117 | return StorageSlot.getAddressSlot(_ADMIN_SLOT).value; 118 | } 119 | 120 | /** 121 | * @dev Stores a new address in the EIP1967 admin slot. 122 | */ 123 | function _setAdmin(address newAdmin) private { 124 | require(newAdmin != address(0), "ERC1967: new admin is the zero address"); 125 | StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin; 126 | } 127 | 128 | /** 129 | * @dev Changes the admin of the proxy. 130 | * 131 | * Emits an {AdminChanged} event. 132 | */ 133 | function _changeAdmin(address newAdmin) internal { 134 | emit AdminChanged(_getAdmin(), newAdmin); 135 | _setAdmin(newAdmin); 136 | } 137 | 138 | /** 139 | * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. 140 | * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. 141 | */ 142 | bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; 143 | 144 | /** 145 | * @dev Emitted when the beacon is upgraded. 146 | */ 147 | event BeaconUpgraded(address indexed beacon); 148 | 149 | /** 150 | * @dev Returns the current beacon. 151 | */ 152 | function _getBeacon() internal view returns (address) { 153 | return StorageSlot.getAddressSlot(_BEACON_SLOT).value; 154 | } 155 | 156 | /** 157 | * @dev Stores a new beacon in the EIP1967 beacon slot. 158 | */ 159 | function _setBeacon(address newBeacon) private { 160 | require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract"); 161 | require(Address.isContract(IBeacon(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract"); 162 | StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon; 163 | } 164 | 165 | /** 166 | * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does 167 | * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). 168 | * 169 | * Emits a {BeaconUpgraded} event. 170 | */ 171 | function _upgradeBeaconToAndCall( 172 | address newBeacon, 173 | bytes memory data, 174 | bool forceCall 175 | ) internal { 176 | _setBeacon(newBeacon); 177 | emit BeaconUpgraded(newBeacon); 178 | if (data.length > 0 || forceCall) { 179 | Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/Proxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (proxy/Proxy.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM 8 | * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to 9 | * be specified by overriding the virtual {_implementation} function. 10 | * 11 | * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a 12 | * different contract through the {_delegate} function. 13 | * 14 | * The success and return data of the delegated call will be returned back to the caller of the proxy. 15 | */ 16 | abstract contract Proxy { 17 | /** 18 | * @dev Delegates the current call to `implementation`. 19 | * 20 | * This function does not return to its internal call site, it will return directly to the external caller. 21 | */ 22 | function _delegate(address implementation) internal virtual { 23 | assembly { 24 | // Copy msg.data. We take full control of memory in this inline assembly 25 | // block because it will not return to Solidity code. We overwrite the 26 | // Solidity scratch pad at memory position 0. 27 | calldatacopy(0, 0, calldatasize()) 28 | 29 | // Call the implementation. 30 | // out and outsize are 0 because we don't know the size yet. 31 | let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) 32 | 33 | // Copy the returned data. 34 | returndatacopy(0, 0, returndatasize()) 35 | 36 | switch result 37 | // delegatecall returns 0 on error. 38 | case 0 { 39 | revert(0, returndatasize()) 40 | } 41 | default { 42 | return(0, returndatasize()) 43 | } 44 | } 45 | } 46 | 47 | /** 48 | * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function 49 | * and {_fallback} should delegate. 50 | */ 51 | function _implementation() internal view virtual returns (address); 52 | 53 | /** 54 | * @dev Delegates the current call to the address returned by `_implementation()`. 55 | * 56 | * This function does not return to its internall call site, it will return directly to the external caller. 57 | */ 58 | function _fallback() internal virtual { 59 | _beforeFallback(); 60 | _delegate(_implementation()); 61 | } 62 | 63 | /** 64 | * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other 65 | * function in the contract matches the call data. 66 | */ 67 | fallback() external payable virtual { 68 | _fallback(); 69 | } 70 | 71 | /** 72 | * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data 73 | * is empty. 74 | */ 75 | receive() external payable virtual { 76 | _fallback(); 77 | } 78 | 79 | /** 80 | * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback` 81 | * call, or as part of the Solidity `fallback` or `receive` functions. 82 | * 83 | * If overriden should call `super._beforeFallback()`. 84 | */ 85 | function _beforeFallback() internal virtual {} 86 | } 87 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/beacon/BeaconProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (proxy/beacon/BeaconProxy.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IBeacon.sol"; 7 | import "../Proxy.sol"; 8 | import "../ERC1967/ERC1967Upgrade.sol"; 9 | 10 | /** 11 | * @dev This contract implements a proxy that gets the implementation address for each call from a {UpgradeableBeacon}. 12 | * 13 | * The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't 14 | * conflict with the storage layout of the implementation behind the proxy. 15 | * 16 | * _Available since v3.4._ 17 | */ 18 | contract BeaconProxy is Proxy, ERC1967Upgrade { 19 | /** 20 | * @dev Initializes the proxy with `beacon`. 21 | * 22 | * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This 23 | * will typically be an encoded function call, and allows initializating the storage of the proxy like a Solidity 24 | * constructor. 25 | * 26 | * Requirements: 27 | * 28 | * - `beacon` must be a contract with the interface {IBeacon}. 29 | */ 30 | constructor(address beacon, bytes memory data) payable { 31 | assert(_BEACON_SLOT == bytes32(uint256(keccak256("eip1967.proxy.beacon")) - 1)); 32 | _upgradeBeaconToAndCall(beacon, data, false); 33 | } 34 | 35 | /** 36 | * @dev Returns the current beacon address. 37 | */ 38 | function _beacon() internal view virtual returns (address) { 39 | return _getBeacon(); 40 | } 41 | 42 | /** 43 | * @dev Returns the current implementation address of the associated beacon. 44 | */ 45 | function _implementation() internal view virtual override returns (address) { 46 | return IBeacon(_getBeacon()).implementation(); 47 | } 48 | 49 | /** 50 | * @dev Changes the proxy to use a new beacon. Deprecated: see {_upgradeBeaconToAndCall}. 51 | * 52 | * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. 53 | * 54 | * Requirements: 55 | * 56 | * - `beacon` must be a contract. 57 | * - The implementation returned by `beacon` must be a contract. 58 | */ 59 | function _setBeacon(address beacon, bytes memory data) internal virtual { 60 | _upgradeBeaconToAndCall(beacon, data, false); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/beacon/IBeacon.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev This is the interface that {BeaconProxy} expects of its beacon. 8 | */ 9 | interface IBeacon { 10 | /** 11 | * @dev Must return an address that can be used as a delegate call target. 12 | * 13 | * {BeaconProxy} will check that this address is a contract. 14 | */ 15 | function implementation() external view returns (address); 16 | } 17 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/beacon/UpgradeableBeacon.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (proxy/beacon/UpgradeableBeacon.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IBeacon.sol"; 7 | import "../../access/Ownable.sol"; 8 | import "../../utils/Address.sol"; 9 | 10 | /** 11 | * @dev This contract is used in conjunction with one or more instances of {BeaconProxy} to determine their 12 | * implementation contract, which is where they will delegate all function calls. 13 | * 14 | * An owner is able to change the implementation the beacon points to, thus upgrading the proxies that use this beacon. 15 | */ 16 | contract UpgradeableBeacon is IBeacon, Ownable { 17 | address private _implementation; 18 | 19 | /** 20 | * @dev Emitted when the implementation returned by the beacon is changed. 21 | */ 22 | event Upgraded(address indexed implementation); 23 | 24 | /** 25 | * @dev Sets the address of the initial implementation, and the deployer account as the owner who can upgrade the 26 | * beacon. 27 | */ 28 | 29 | constructor(address implementation_, address initialOwner) Ownable(initialOwner) { 30 | _setImplementation(implementation_); 31 | } 32 | 33 | /** 34 | * @dev Returns the current implementation address. 35 | */ 36 | function implementation() public view virtual override returns (address) { 37 | return _implementation; 38 | } 39 | 40 | /** 41 | * @dev Upgrades the beacon to a new implementation. 42 | * 43 | * Emits an {Upgraded} event. 44 | * 45 | * Requirements: 46 | * 47 | * - msg.sender must be the owner of the contract. 48 | * - `newImplementation` must be a contract. 49 | */ 50 | function upgradeTo(address newImplementation) public virtual onlyOwner { 51 | _setImplementation(newImplementation); 52 | emit Upgraded(newImplementation); 53 | } 54 | 55 | /** 56 | * @dev Sets the implementation contract address for this beacon 57 | * 58 | * Requirements: 59 | * 60 | * - `newImplementation` must be a contract. 61 | */ 62 | function _setImplementation(address newImplementation) private { 63 | require(Address.isContract(newImplementation), "UpgradeableBeacon: implementation is not a contract"); 64 | _implementation = newImplementation; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/transparent/ProxyAdmin.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (proxy/transparent/ProxyAdmin.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./TransparentUpgradeableProxy.sol"; 7 | import "../../access/Ownable.sol"; 8 | 9 | /** 10 | * @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an 11 | * explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}. 12 | */ 13 | contract ProxyAdmin is Ownable { 14 | 15 | constructor (address initialOwner) Ownable(initialOwner) {} 16 | 17 | /** 18 | * @dev Returns the current implementation of `proxy`. 19 | * 20 | * Requirements: 21 | * 22 | * - This contract must be the admin of `proxy`. 23 | */ 24 | function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) { 25 | // We need to manually run the static call since the getter cannot be flagged as view 26 | // bytes4(keccak256("implementation()")) == 0x5c60da1b 27 | (bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b"); 28 | require(success); 29 | return abi.decode(returndata, (address)); 30 | } 31 | 32 | /** 33 | * @dev Returns the current admin of `proxy`. 34 | * 35 | * Requirements: 36 | * 37 | * - This contract must be the admin of `proxy`. 38 | */ 39 | function getProxyAdmin(TransparentUpgradeableProxy proxy) public view virtual returns (address) { 40 | // We need to manually run the static call since the getter cannot be flagged as view 41 | // bytes4(keccak256("admin()")) == 0xf851a440 42 | (bool success, bytes memory returndata) = address(proxy).staticcall(hex"f851a440"); 43 | require(success); 44 | return abi.decode(returndata, (address)); 45 | } 46 | 47 | /** 48 | * @dev Changes the admin of `proxy` to `newAdmin`. 49 | * 50 | * Requirements: 51 | * 52 | * - This contract must be the current admin of `proxy`. 53 | */ 54 | function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner { 55 | proxy.changeAdmin(newAdmin); 56 | } 57 | 58 | /** 59 | * @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}. 60 | * 61 | * Requirements: 62 | * 63 | * - This contract must be the admin of `proxy`. 64 | */ 65 | function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner { 66 | proxy.upgradeTo(implementation); 67 | } 68 | 69 | /** 70 | * @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See 71 | * {TransparentUpgradeableProxy-upgradeToAndCall}. 72 | * 73 | * Requirements: 74 | * 75 | * - This contract must be the admin of `proxy`. 76 | */ 77 | function upgradeAndCall( 78 | TransparentUpgradeableProxy proxy, 79 | address implementation, 80 | bytes memory data 81 | ) public payable virtual onlyOwner { 82 | proxy.upgradeToAndCall{value: msg.value}(implementation, data); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/transparent/TransparentUpgradeableProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (proxy/transparent/TransparentUpgradeableProxy.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC1967/ERC1967Proxy.sol"; 7 | 8 | /** 9 | * @dev This contract implements a proxy that is upgradeable by an admin. 10 | * 11 | * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector 12 | * clashing], which can potentially be used in an attack, this contract uses the 13 | * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two 14 | * things that go hand in hand: 15 | * 16 | * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if 17 | * that call matches one of the admin functions exposed by the proxy itself. 18 | * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the 19 | * implementation. If the admin tries to call a function on the implementation it will fail with an error that says 20 | * "admin cannot fallback to proxy target". 21 | * 22 | * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing 23 | * the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due 24 | * to sudden errors when trying to call a function from the proxy implementation. 25 | * 26 | * Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, 27 | * you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy. 28 | */ 29 | contract TransparentUpgradeableProxy is ERC1967Proxy { 30 | /** 31 | * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and 32 | * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}. 33 | */ 34 | constructor( 35 | address _logic, 36 | address admin_, 37 | bytes memory _data 38 | ) payable ERC1967Proxy(_logic, _data) { 39 | assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1)); 40 | _changeAdmin(admin_); 41 | } 42 | 43 | /** 44 | * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin. 45 | */ 46 | modifier ifAdmin() { 47 | if (msg.sender == _getAdmin()) { 48 | _; 49 | } else { 50 | _fallback(); 51 | } 52 | } 53 | 54 | /** 55 | * @dev Returns the current admin. 56 | * 57 | * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}. 58 | * 59 | * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the 60 | * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. 61 | * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` 62 | */ 63 | function admin() external ifAdmin returns (address admin_) { 64 | admin_ = _getAdmin(); 65 | } 66 | 67 | /** 68 | * @dev Returns the current implementation. 69 | * 70 | * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}. 71 | * 72 | * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the 73 | * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. 74 | * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` 75 | */ 76 | function implementation() external ifAdmin returns (address implementation_) { 77 | implementation_ = _implementation(); 78 | } 79 | 80 | /** 81 | * @dev Changes the admin of the proxy. 82 | * 83 | * Emits an {AdminChanged} event. 84 | * 85 | * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}. 86 | */ 87 | function changeAdmin(address newAdmin) external virtual ifAdmin { 88 | _changeAdmin(newAdmin); 89 | } 90 | 91 | /** 92 | * @dev Upgrade the implementation of the proxy. 93 | * 94 | * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}. 95 | */ 96 | function upgradeTo(address newImplementation) external ifAdmin { 97 | _upgradeToAndCall(newImplementation, bytes(""), false); 98 | } 99 | 100 | /** 101 | * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified 102 | * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the 103 | * proxied contract. 104 | * 105 | * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}. 106 | */ 107 | function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { 108 | _upgradeToAndCall(newImplementation, data, true); 109 | } 110 | 111 | /** 112 | * @dev Returns the current admin. 113 | */ 114 | function _admin() internal view virtual returns (address) { 115 | return _getAdmin(); 116 | } 117 | 118 | /** 119 | * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}. 120 | */ 121 | function _beforeFallback() internal virtual override { 122 | require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target"); 123 | super._beforeFallback(); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/utils/Initializable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (proxy/utils/Initializable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../../utils/Address.sol"; 7 | 8 | /** 9 | * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed 10 | * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an 11 | * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer 12 | * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. 13 | * 14 | * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as 15 | * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. 16 | * 17 | * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure 18 | * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. 19 | * 20 | * [CAUTION] 21 | * ==== 22 | * Avoid leaving a contract uninitialized. 23 | * 24 | * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation 25 | * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the 26 | * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed: 27 | * 28 | * [.hljs-theme-light.nopadding] 29 | * ``` 30 | * /// @custom:oz-upgrades-unsafe-allow constructor 31 | * constructor() initializer {} 32 | * ``` 33 | * ==== 34 | */ 35 | abstract contract Initializable { 36 | /** 37 | * @dev Indicates that the contract has been initialized. 38 | */ 39 | bool private _initialized; 40 | 41 | /** 42 | * @dev Indicates that the contract is in the process of being initialized. 43 | */ 44 | bool private _initializing; 45 | 46 | /** 47 | * @dev Modifier to protect an initializer function from being invoked twice. 48 | */ 49 | modifier initializer() { 50 | // If the contract is initializing we ignore whether _initialized is set in order to support multiple 51 | // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the 52 | // contract may have been reentered. 53 | require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized"); 54 | 55 | bool isTopLevelCall = !_initializing; 56 | if (isTopLevelCall) { 57 | _initializing = true; 58 | _initialized = true; 59 | } 60 | 61 | _; 62 | 63 | if (isTopLevelCall) { 64 | _initializing = false; 65 | } 66 | } 67 | 68 | /** 69 | * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the 70 | * {initializer} modifier, directly or indirectly. 71 | */ 72 | modifier onlyInitializing() { 73 | require(_initializing, "Initializable: contract is not initializing"); 74 | _; 75 | } 76 | 77 | function _isConstructor() private view returns (bool) { 78 | return !Address.isContract(address(this)); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/proxy/utils/UUPSUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (proxy/utils/UUPSUpgradeable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../../interfaces/draft-IERC1822.sol"; 7 | import "../ERC1967/ERC1967Upgrade.sol"; 8 | 9 | /** 10 | * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an 11 | * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. 12 | * 13 | * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is 14 | * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing 15 | * `UUPSUpgradeable` with a custom implementation of upgrades. 16 | * 17 | * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. 18 | * 19 | * _Available since v4.1._ 20 | */ 21 | abstract contract UUPSUpgradeable is IERC1822Proxiable, ERC1967Upgrade { 22 | /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment 23 | address private immutable __self = address(this); 24 | 25 | /** 26 | * @dev Check that the execution is being performed through a delegatecall call and that the execution context is 27 | * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case 28 | * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a 29 | * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to 30 | * fail. 31 | */ 32 | modifier onlyProxy() { 33 | require(address(this) != __self, "Function must be called through delegatecall"); 34 | require(_getImplementation() == __self, "Function must be called through active proxy"); 35 | _; 36 | } 37 | 38 | /** 39 | * @dev Check that the execution is not being performed through a delegate call. This allows a function to be 40 | * callable on the implementing contract but not through proxies. 41 | */ 42 | modifier notDelegated() { 43 | require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall"); 44 | _; 45 | } 46 | 47 | /** 48 | * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the 49 | * implementation. It is used to validate that the this implementation remains valid after an upgrade. 50 | * 51 | * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks 52 | * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this 53 | * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier. 54 | */ 55 | function proxiableUUID() external view virtual override notDelegated returns (bytes32) { 56 | return _IMPLEMENTATION_SLOT; 57 | } 58 | 59 | /** 60 | * @dev Upgrade the implementation of the proxy to `newImplementation`. 61 | * 62 | * Calls {_authorizeUpgrade}. 63 | * 64 | * Emits an {Upgraded} event. 65 | */ 66 | function upgradeTo(address newImplementation) external virtual onlyProxy { 67 | _authorizeUpgrade(newImplementation); 68 | _upgradeToAndCallUUPS(newImplementation, new bytes(0), false); 69 | } 70 | 71 | /** 72 | * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call 73 | * encoded in `data`. 74 | * 75 | * Calls {_authorizeUpgrade}. 76 | * 77 | * Emits an {Upgraded} event. 78 | */ 79 | function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy { 80 | _authorizeUpgrade(newImplementation); 81 | _upgradeToAndCallUUPS(newImplementation, data, true); 82 | } 83 | 84 | /** 85 | * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by 86 | * {upgradeTo} and {upgradeToAndCall}. 87 | * 88 | * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. 89 | * 90 | * ```solidity 91 | * function _authorizeUpgrade(address) internal override onlyOwner {} 92 | * ``` 93 | */ 94 | function _authorizeUpgrade(address newImplementation) internal virtual; 95 | } 96 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/utils/Address.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.5.0-rc.0) (utils/Address.sol) 3 | 4 | pragma solidity ^0.8.1; 5 | 6 | /** 7 | * @dev Collection of functions related to the address type 8 | */ 9 | library Address { 10 | /** 11 | * @dev Returns true if `account` is a contract. 12 | * 13 | * [IMPORTANT] 14 | * ==== 15 | * It is unsafe to assume that an address for which this function returns 16 | * false is an externally-owned account (EOA) and not a contract. 17 | * 18 | * Among others, `isContract` will return false for the following 19 | * types of addresses: 20 | * 21 | * - an externally-owned account 22 | * - a contract in construction 23 | * - an address where a contract will be created 24 | * - an address where a contract lived, but was destroyed 25 | * ==== 26 | * 27 | * [IMPORTANT] 28 | * ==== 29 | * You shouldn't rely on `isContract` to protect against flash loan attacks! 30 | * 31 | * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets 32 | * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract 33 | * constructor. 34 | * ==== 35 | */ 36 | function isContract(address account) internal view returns (bool) { 37 | // This method relies on extcodesize/address.code.length, which returns 0 38 | // for contracts in construction, since the code is only stored at the end 39 | // of the constructor execution. 40 | 41 | return account.code.length > 0; 42 | } 43 | 44 | /** 45 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 46 | * `recipient`, forwarding all available gas and reverting on errors. 47 | * 48 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 49 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 50 | * imposed by `transfer`, making them unable to receive funds via 51 | * `transfer`. {sendValue} removes this limitation. 52 | * 53 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 54 | * 55 | * IMPORTANT: because control is transferred to `recipient`, care must be 56 | * taken to not create reentrancy vulnerabilities. Consider using 57 | * {ReentrancyGuard} or the 58 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 59 | */ 60 | function sendValue(address payable recipient, uint256 amount) internal { 61 | require(address(this).balance >= amount, "Address: insufficient balance"); 62 | 63 | (bool success, ) = recipient.call{value: amount}(""); 64 | require(success, "Address: unable to send value, recipient may have reverted"); 65 | } 66 | 67 | /** 68 | * @dev Performs a Solidity function call using a low level `call`. A 69 | * plain `call` is an unsafe replacement for a function call: use this 70 | * function instead. 71 | * 72 | * If `target` reverts with a revert reason, it is bubbled up by this 73 | * function (like regular Solidity function calls). 74 | * 75 | * Returns the raw returned data. To convert to the expected return value, 76 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 77 | * 78 | * Requirements: 79 | * 80 | * - `target` must be a contract. 81 | * - calling `target` with `data` must not revert. 82 | * 83 | * _Available since v3.1._ 84 | */ 85 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 86 | return functionCall(target, data, "Address: low-level call failed"); 87 | } 88 | 89 | /** 90 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 91 | * `errorMessage` as a fallback revert reason when `target` reverts. 92 | * 93 | * _Available since v3.1._ 94 | */ 95 | function functionCall( 96 | address target, 97 | bytes memory data, 98 | string memory errorMessage 99 | ) internal returns (bytes memory) { 100 | return functionCallWithValue(target, data, 0, errorMessage); 101 | } 102 | 103 | /** 104 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 105 | * but also transferring `value` wei to `target`. 106 | * 107 | * Requirements: 108 | * 109 | * - the calling contract must have an ETH balance of at least `value`. 110 | * - the called Solidity function must be `payable`. 111 | * 112 | * _Available since v3.1._ 113 | */ 114 | function functionCallWithValue( 115 | address target, 116 | bytes memory data, 117 | uint256 value 118 | ) internal returns (bytes memory) { 119 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 120 | } 121 | 122 | /** 123 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 124 | * with `errorMessage` as a fallback revert reason when `target` reverts. 125 | * 126 | * _Available since v3.1._ 127 | */ 128 | function functionCallWithValue( 129 | address target, 130 | bytes memory data, 131 | uint256 value, 132 | string memory errorMessage 133 | ) internal returns (bytes memory) { 134 | require(address(this).balance >= value, "Address: insufficient balance for call"); 135 | require(isContract(target), "Address: call to non-contract"); 136 | 137 | (bool success, bytes memory returndata) = target.call{value: value}(data); 138 | return verifyCallResult(success, returndata, errorMessage); 139 | } 140 | 141 | /** 142 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 143 | * but performing a static call. 144 | * 145 | * _Available since v3.3._ 146 | */ 147 | function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { 148 | return functionStaticCall(target, data, "Address: low-level static call failed"); 149 | } 150 | 151 | /** 152 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 153 | * but performing a static call. 154 | * 155 | * _Available since v3.3._ 156 | */ 157 | function functionStaticCall( 158 | address target, 159 | bytes memory data, 160 | string memory errorMessage 161 | ) internal view returns (bytes memory) { 162 | require(isContract(target), "Address: static call to non-contract"); 163 | 164 | (bool success, bytes memory returndata) = target.staticcall(data); 165 | return verifyCallResult(success, returndata, errorMessage); 166 | } 167 | 168 | /** 169 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 170 | * but performing a delegate call. 171 | * 172 | * _Available since v3.4._ 173 | */ 174 | function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { 175 | return functionDelegateCall(target, data, "Address: low-level delegate call failed"); 176 | } 177 | 178 | /** 179 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 180 | * but performing a delegate call. 181 | * 182 | * _Available since v3.4._ 183 | */ 184 | function functionDelegateCall( 185 | address target, 186 | bytes memory data, 187 | string memory errorMessage 188 | ) internal returns (bytes memory) { 189 | require(isContract(target), "Address: delegate call to non-contract"); 190 | 191 | (bool success, bytes memory returndata) = target.delegatecall(data); 192 | return verifyCallResult(success, returndata, errorMessage); 193 | } 194 | 195 | /** 196 | * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the 197 | * revert reason using the provided one. 198 | * 199 | * _Available since v4.3._ 200 | */ 201 | function verifyCallResult( 202 | bool success, 203 | bytes memory returndata, 204 | string memory errorMessage 205 | ) internal pure returns (bytes memory) { 206 | if (success) { 207 | return returndata; 208 | } else { 209 | // Look for revert reason and bubble it up if present 210 | if (returndata.length > 0) { 211 | // The easiest way to bubble the revert reason is using memory via assembly 212 | 213 | assembly { 214 | let returndata_size := mload(returndata) 215 | revert(add(32, returndata), returndata_size) 216 | } 217 | } else { 218 | revert(errorMessage); 219 | } 220 | } 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/utils/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Provides information about the current execution context, including the 8 | * sender of the transaction and its data. While these are generally available 9 | * via msg.sender and msg.data, they should not be accessed in such a direct 10 | * manner, since when dealing with meta-transactions the account sending and 11 | * paying for execution may not be the actual sender (as far as an application 12 | * is concerned). 13 | * 14 | * This contract is only required for intermediate, library-like contracts. 15 | */ 16 | abstract contract Context { 17 | function _msgSender() internal view virtual returns (address) { 18 | return msg.sender; 19 | } 20 | 21 | function _msgData() internal view virtual returns (bytes calldata) { 22 | return msg.data; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/utils/StorageSlot.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Library for reading and writing primitive types to specific storage slots. 8 | * 9 | * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. 10 | * This library helps with reading and writing to such slots without the need for inline assembly. 11 | * 12 | * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. 13 | * 14 | * Example usage to set ERC1967 implementation slot: 15 | * ``` 16 | * contract ERC1967 { 17 | * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; 18 | * 19 | * function _getImplementation() internal view returns (address) { 20 | * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; 21 | * } 22 | * 23 | * function _setImplementation(address newImplementation) internal { 24 | * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); 25 | * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; 26 | * } 27 | * } 28 | * ``` 29 | * 30 | * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._ 31 | */ 32 | library StorageSlot { 33 | struct AddressSlot { 34 | address value; 35 | } 36 | 37 | struct BooleanSlot { 38 | bool value; 39 | } 40 | 41 | struct Bytes32Slot { 42 | bytes32 value; 43 | } 44 | 45 | struct Uint256Slot { 46 | uint256 value; 47 | } 48 | 49 | /** 50 | * @dev Returns an `AddressSlot` with member `value` located at `slot`. 51 | */ 52 | function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { 53 | assembly { 54 | r.slot := slot 55 | } 56 | } 57 | 58 | /** 59 | * @dev Returns an `BooleanSlot` with member `value` located at `slot`. 60 | */ 61 | function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { 62 | assembly { 63 | r.slot := slot 64 | } 65 | } 66 | 67 | /** 68 | * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. 69 | */ 70 | function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { 71 | assembly { 72 | r.slot := slot 73 | } 74 | } 75 | 76 | /** 77 | * @dev Returns an `Uint256Slot` with member `value` located at `slot`. 78 | */ 79 | function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { 80 | assembly { 81 | r.slot := slot 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/utils/introspection/ERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IERC165.sol"; 7 | 8 | /** 9 | * @dev Implementation of the {IERC165} interface. 10 | * 11 | * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check 12 | * for the additional interface id that will be supported. For example: 13 | * 14 | * ```solidity 15 | * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 16 | * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); 17 | * } 18 | * ``` 19 | * 20 | * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. 21 | */ 22 | abstract contract ERC165 is IERC165 { 23 | /** 24 | * @dev See {IERC165-supportsInterface}. 25 | */ 26 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 27 | return interfaceId == type(IERC165).interfaceId; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/utils/introspection/ERC165Checker.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165Checker.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IERC165.sol"; 7 | 8 | /** 9 | * @dev Library used to query support of an interface declared via {IERC165}. 10 | * 11 | * Note that these functions return the actual result of the query: they do not 12 | * `revert` if an interface is not supported. It is up to the caller to decide 13 | * what to do in these cases. 14 | */ 15 | library ERC165Checker { 16 | // As per the EIP-165 spec, no interface should ever match 0xffffffff 17 | bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; 18 | 19 | /** 20 | * @dev Returns true if `account` supports the {IERC165} interface, 21 | */ 22 | function supportsERC165(address account) internal view returns (bool) { 23 | // Any contract that implements ERC165 must explicitly indicate support of 24 | // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid 25 | return 26 | _supportsERC165Interface(account, type(IERC165).interfaceId) && 27 | !_supportsERC165Interface(account, _INTERFACE_ID_INVALID); 28 | } 29 | 30 | /** 31 | * @dev Returns true if `account` supports the interface defined by 32 | * `interfaceId`. Support for {IERC165} itself is queried automatically. 33 | * 34 | * See {IERC165-supportsInterface}. 35 | */ 36 | function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { 37 | // query support of both ERC165 as per the spec and support of _interfaceId 38 | return supportsERC165(account) && _supportsERC165Interface(account, interfaceId); 39 | } 40 | 41 | /** 42 | * @dev Returns a boolean array where each value corresponds to the 43 | * interfaces passed in and whether they're supported or not. This allows 44 | * you to batch check interfaces for a contract where your expectation 45 | * is that some interfaces may not be supported. 46 | * 47 | * See {IERC165-supportsInterface}. 48 | * 49 | * _Available since v3.4._ 50 | */ 51 | function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) 52 | internal 53 | view 54 | returns (bool[] memory) 55 | { 56 | // an array of booleans corresponding to interfaceIds and whether they're supported or not 57 | bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length); 58 | 59 | // query support of ERC165 itself 60 | if (supportsERC165(account)) { 61 | // query support of each interface in interfaceIds 62 | for (uint256 i = 0; i < interfaceIds.length; i++) { 63 | interfaceIdsSupported[i] = _supportsERC165Interface(account, interfaceIds[i]); 64 | } 65 | } 66 | 67 | return interfaceIdsSupported; 68 | } 69 | 70 | /** 71 | * @dev Returns true if `account` supports all the interfaces defined in 72 | * `interfaceIds`. Support for {IERC165} itself is queried automatically. 73 | * 74 | * Batch-querying can lead to gas savings by skipping repeated checks for 75 | * {IERC165} support. 76 | * 77 | * See {IERC165-supportsInterface}. 78 | */ 79 | function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { 80 | // query support of ERC165 itself 81 | if (!supportsERC165(account)) { 82 | return false; 83 | } 84 | 85 | // query support of each interface in _interfaceIds 86 | for (uint256 i = 0; i < interfaceIds.length; i++) { 87 | if (!_supportsERC165Interface(account, interfaceIds[i])) { 88 | return false; 89 | } 90 | } 91 | 92 | // all interfaces supported 93 | return true; 94 | } 95 | 96 | /** 97 | * @notice Query if a contract implements an interface, does not check ERC165 support 98 | * @param account The address of the contract to query for support of an interface 99 | * @param interfaceId The interface identifier, as specified in ERC-165 100 | * @return true if the contract at account indicates support of the interface with 101 | * identifier interfaceId, false otherwise 102 | * @dev Assumes that account contains a contract that supports ERC165, otherwise 103 | * the behavior of this method is undefined. This precondition can be checked 104 | * with {supportsERC165}. 105 | * Interface identification is specified in ERC-165. 106 | */ 107 | function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { 108 | bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId); 109 | (bool success, bytes memory result) = account.staticcall{gas: 30000}(encodedParams); 110 | if (result.length < 32) return false; 111 | return success && abi.decode(result, (bool)); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/utils/introspection/ERC165Storage.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165Storage.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./ERC165.sol"; 7 | 8 | /** 9 | * @dev Storage based implementation of the {IERC165} interface. 10 | * 11 | * Contracts may inherit from this and call {_registerInterface} to declare 12 | * their support of an interface. 13 | */ 14 | abstract contract ERC165Storage is ERC165 { 15 | /** 16 | * @dev Mapping of interface ids to whether or not it's supported. 17 | */ 18 | mapping(bytes4 => bool) private _supportedInterfaces; 19 | 20 | /** 21 | * @dev See {IERC165-supportsInterface}. 22 | */ 23 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 24 | return super.supportsInterface(interfaceId) || _supportedInterfaces[interfaceId]; 25 | } 26 | 27 | /** 28 | * @dev Registers the contract as an implementer of the interface defined by 29 | * `interfaceId`. Support of the actual ERC165 interface is automatic and 30 | * registering its interface id is not required. 31 | * 32 | * See {IERC165-supportsInterface}. 33 | * 34 | * Requirements: 35 | * 36 | * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`). 37 | */ 38 | function _registerInterface(bytes4 interfaceId) internal virtual { 39 | require(interfaceId != 0xffffffff, "ERC165: invalid interface id"); 40 | _supportedInterfaces[interfaceId] = true; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /solc_0.8/openzeppelin/utils/introspection/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC165 standard, as defined in the 8 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 9 | * 10 | * Implementers can declare support of contract interfaces, which can then be 11 | * queried by others ({ERC165Checker}). 12 | * 13 | * For an implementation, see {ERC165}. 14 | */ 15 | interface IERC165 { 16 | /** 17 | * @dev Returns true if this contract implements the interface defined by 18 | * `interfaceId`. See the corresponding 19 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 20 | * to learn more about how these ids are created. 21 | * 22 | * This function call must use less than 30 000 gas. 23 | */ 24 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 25 | } 26 | -------------------------------------------------------------------------------- /solc_0.8/proxy/EIP173Proxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./Proxy.sol"; 5 | 6 | interface ERC165 { 7 | function supportsInterface(bytes4 id) external view returns (bool); 8 | } 9 | 10 | ///@notice Proxy implementing EIP173 for ownership management 11 | contract EIP173Proxy is Proxy { 12 | // ////////////////////////// EVENTS /////////////////////////////////////////////////////////////////////// 13 | 14 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 15 | 16 | // /////////////////////// CONSTRUCTOR ////////////////////////////////////////////////////////////////////// 17 | 18 | constructor( 19 | address implementationAddress, 20 | address ownerAddress, 21 | bytes memory data 22 | ) payable { 23 | _setOwner(ownerAddress); 24 | _setImplementation(implementationAddress, data); 25 | } 26 | 27 | // ///////////////////// EXTERNAL /////////////////////////////////////////////////////////////////////////// 28 | 29 | function owner() external view returns (address) { 30 | return _owner(); 31 | } 32 | 33 | function supportsInterface(bytes4 id) external view returns (bool) { 34 | if (id == 0x01ffc9a7 || id == 0x7f5828d0) { 35 | return true; 36 | } 37 | if (id == 0xFFFFFFFF) { 38 | return false; 39 | } 40 | 41 | ERC165 implementation; 42 | // solhint-disable-next-line security/no-inline-assembly 43 | assembly { 44 | implementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc) 45 | } 46 | 47 | // Technically this is not standard compliant as ERC-165 require 30,000 gas which that call cannot ensure 48 | // because it is itself inside `supportsInterface` that might only get 30,000 gas. 49 | // In practise this is unlikely to be an issue. 50 | try implementation.supportsInterface(id) returns (bool support) { 51 | return support; 52 | } catch { 53 | return false; 54 | } 55 | } 56 | 57 | function transferOwnership(address newOwner) external onlyOwner { 58 | _setOwner(newOwner); 59 | } 60 | 61 | function upgradeTo(address newImplementation) external onlyOwner { 62 | _setImplementation(newImplementation, ""); 63 | } 64 | 65 | function upgradeToAndCall(address newImplementation, bytes calldata data) external payable onlyOwner { 66 | _setImplementation(newImplementation, data); 67 | } 68 | 69 | // /////////////////////// MODIFIERS //////////////////////////////////////////////////////////////////////// 70 | 71 | modifier onlyOwner() { 72 | require(msg.sender == _owner(), "NOT_AUTHORIZED"); 73 | _; 74 | } 75 | 76 | // ///////////////////////// INTERNAL ////////////////////////////////////////////////////////////////////// 77 | 78 | function _owner() internal view returns (address adminAddress) { 79 | // solhint-disable-next-line security/no-inline-assembly 80 | assembly { 81 | adminAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103) 82 | } 83 | } 84 | 85 | function _setOwner(address newOwner) internal { 86 | address previousOwner = _owner(); 87 | // solhint-disable-next-line security/no-inline-assembly 88 | assembly { 89 | sstore(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, newOwner) 90 | } 91 | emit OwnershipTransferred(previousOwner, newOwner); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /solc_0.8/proxy/EIP173ProxyWithReceive.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./EIP173Proxy.sol"; 5 | 6 | ///@notice Proxy implementing EIP173 for ownership management that accept ETH via receive 7 | contract EIP173ProxyWithReceive is EIP173Proxy { 8 | constructor( 9 | address implementationAddress, 10 | address ownerAddress, 11 | bytes memory data 12 | ) payable EIP173Proxy(implementationAddress, ownerAddress, data) {} 13 | 14 | receive() external payable override {} 15 | } 16 | -------------------------------------------------------------------------------- /solc_0.8/proxy/OptimizedTransparentUpgradeableProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (proxy/transparent/TransparentUpgradeableProxy.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../openzeppelin/proxy/ERC1967/ERC1967Proxy.sol"; 7 | 8 | /** 9 | * @dev This contract implements a proxy that is upgradeable by an admin. 10 | * 11 | * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector 12 | * clashing], which can potentially be used in an attack, this contract uses the 13 | * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two 14 | * things that go hand in hand: 15 | * 16 | * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if 17 | * that call matches one of the admin functions exposed by the proxy itself. 18 | * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the 19 | * implementation. If the admin tries to call a function on the implementation it will fail with an error that says 20 | * "admin cannot fallback to proxy target". 21 | * 22 | * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing 23 | * the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due 24 | * to sudden errors when trying to call a function from the proxy implementation. 25 | * 26 | * Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, 27 | * you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy. 28 | */ 29 | contract OptimizedTransparentUpgradeableProxy is ERC1967Proxy { 30 | address internal immutable _ADMIN; 31 | 32 | /** 33 | * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and 34 | * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}. 35 | */ 36 | constructor( 37 | address _logic, 38 | address admin_, 39 | bytes memory _data 40 | ) payable ERC1967Proxy(_logic, _data) { 41 | assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1)); 42 | _ADMIN = admin_; 43 | 44 | // still store it to work with EIP-1967 45 | bytes32 slot = _ADMIN_SLOT; 46 | // solhint-disable-next-line no-inline-assembly 47 | assembly { 48 | sstore(slot, admin_) 49 | } 50 | emit AdminChanged(address(0), admin_); 51 | } 52 | 53 | /** 54 | * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin. 55 | */ 56 | modifier ifAdmin() { 57 | if (msg.sender == _getAdmin()) { 58 | _; 59 | } else { 60 | _fallback(); 61 | } 62 | } 63 | 64 | /** 65 | * @dev Returns the current admin. 66 | * 67 | * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}. 68 | * 69 | * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the 70 | * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. 71 | * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` 72 | */ 73 | function admin() external ifAdmin returns (address admin_) { 74 | admin_ = _getAdmin(); 75 | } 76 | 77 | /** 78 | * @dev Returns the current implementation. 79 | * 80 | * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}. 81 | * 82 | * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the 83 | * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. 84 | * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` 85 | */ 86 | function implementation() external ifAdmin returns (address implementation_) { 87 | implementation_ = _implementation(); 88 | } 89 | 90 | /** 91 | * @dev Upgrade the implementation of the proxy. 92 | * 93 | * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}. 94 | */ 95 | function upgradeTo(address newImplementation) external ifAdmin { 96 | _upgradeToAndCall(newImplementation, bytes(""), false); 97 | } 98 | 99 | /** 100 | * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified 101 | * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the 102 | * proxied contract. 103 | * 104 | * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}. 105 | */ 106 | function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { 107 | _upgradeToAndCall(newImplementation, data, true); 108 | } 109 | 110 | /** 111 | * @dev Returns the current admin. 112 | */ 113 | function _admin() internal view virtual returns (address) { 114 | return _getAdmin(); 115 | } 116 | 117 | /** 118 | * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}. 119 | */ 120 | function _beforeFallback() internal virtual override { 121 | require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target"); 122 | super._beforeFallback(); 123 | } 124 | 125 | function _getAdmin() internal view virtual override returns (address) { 126 | return _ADMIN; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /solc_0.8/proxy/Proxied.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | abstract contract Proxied { 5 | /// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them 6 | /// It also allows these functions to be called inside a contructor 7 | /// even if the contract is meant to be used without proxy 8 | modifier proxied() { 9 | address proxyAdminAddress = _proxyAdmin(); 10 | // With hardhat-deploy proxies 11 | // the proxyAdminAddress is zero only for the implementation contract 12 | // if the implementation contract want to be used as a standalone/immutable contract 13 | // it simply has to execute the `proxied` function 14 | // This ensure the proxyAdminAddress is never zero post deployment 15 | // And allow you to keep the same code for both proxied contract and immutable contract 16 | if (proxyAdminAddress == address(0)) { 17 | // ensure can not be called twice when used outside of proxy : no admin 18 | // solhint-disable-next-line security/no-inline-assembly 19 | assembly { 20 | sstore( 21 | 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, 22 | 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 23 | ) 24 | } 25 | } else { 26 | require(msg.sender == proxyAdminAddress); 27 | } 28 | _; 29 | } 30 | 31 | modifier onlyProxyAdmin() { 32 | require(msg.sender == _proxyAdmin(), "NOT_AUTHORIZED"); 33 | _; 34 | } 35 | 36 | function _proxyAdmin() internal view returns (address ownerAddress) { 37 | // solhint-disable-next-line security/no-inline-assembly 38 | assembly { 39 | ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103) 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /solc_0.8/proxy/Proxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | // EIP-1967 5 | abstract contract Proxy { 6 | // /////////////////////// EVENTS /////////////////////////////////////////////////////////////////////////// 7 | 8 | event ProxyImplementationUpdated(address indexed previousImplementation, address indexed newImplementation); 9 | 10 | // ///////////////////// EXTERNAL /////////////////////////////////////////////////////////////////////////// 11 | 12 | receive() external payable virtual { 13 | revert("ETHER_REJECTED"); // explicit reject by default 14 | } 15 | 16 | fallback() external payable { 17 | _fallback(); 18 | } 19 | 20 | // ///////////////////////// INTERNAL ////////////////////////////////////////////////////////////////////// 21 | 22 | function _fallback() internal { 23 | // solhint-disable-next-line security/no-inline-assembly 24 | assembly { 25 | let implementationAddress := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc) 26 | calldatacopy(0x0, 0x0, calldatasize()) 27 | let success := delegatecall(gas(), implementationAddress, 0x0, calldatasize(), 0, 0) 28 | let retSz := returndatasize() 29 | returndatacopy(0, 0, retSz) 30 | switch success 31 | case 0 { 32 | revert(0, retSz) 33 | } 34 | default { 35 | return(0, retSz) 36 | } 37 | } 38 | } 39 | 40 | function _setImplementation(address newImplementation, bytes memory data) internal { 41 | address previousImplementation; 42 | // solhint-disable-next-line security/no-inline-assembly 43 | assembly { 44 | previousImplementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc) 45 | } 46 | 47 | // solhint-disable-next-line security/no-inline-assembly 48 | assembly { 49 | sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, newImplementation) 50 | } 51 | 52 | emit ProxyImplementationUpdated(previousImplementation, newImplementation); 53 | 54 | if (data.length > 0) { 55 | (bool success, ) = newImplementation.delegatecall(data); 56 | if (!success) { 57 | assembly { 58 | // This assembly ensure the revert contains the exact string data 59 | let returnDataSize := returndatasize() 60 | returndatacopy(0, 0, returnDataSize) 61 | revert(0, returnDataSize) 62 | } 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/DeploymentFactory.ts: -------------------------------------------------------------------------------- 1 | import { 2 | TransactionReceipt, 3 | TransactionRequest, 4 | TransactionResponse, 5 | } from '@ethersproject/providers'; 6 | import { ContractFactory, PayableOverrides, Signer, ethers } from 'ethers'; 7 | import { Artifact } from 'hardhat/types'; 8 | import * as zk from 'zksync-ethers'; 9 | import { Address, Deployment, DeployOptions, ExtendedArtifact } from '../types'; 10 | import { getAddress } from '@ethersproject/address'; 11 | import { keccak256 as solidityKeccak256 } from '@ethersproject/solidity'; 12 | import { hexConcat } from '@ethersproject/bytes'; 13 | 14 | export class DeploymentFactory { 15 | private factory: ContractFactory; 16 | private artifact: Artifact | ExtendedArtifact; 17 | private isZkSync: boolean; 18 | private getArtifact: (name: string) => Promise; 19 | private overrides: PayableOverrides; 20 | private args: any[]; 21 | constructor( 22 | getArtifact: (name: string) => Promise, 23 | artifact: Artifact | ExtendedArtifact, 24 | args: any[], 25 | network: any, 26 | ethersSigner?: Signer | zk.Signer, 27 | overrides: PayableOverrides = {} 28 | ) { 29 | this.overrides = overrides; 30 | this.getArtifact = getArtifact; 31 | this.isZkSync = network.zksync; 32 | this.artifact = artifact; 33 | if (this.isZkSync) { 34 | this.factory = new zk.ContractFactory( 35 | artifact.abi, 36 | artifact.bytecode, 37 | ethersSigner as zk.Signer 38 | ); 39 | } else { 40 | this.factory = new ContractFactory( 41 | artifact.abi, 42 | artifact.bytecode, 43 | ethersSigner 44 | ); 45 | } 46 | const numArguments = this.factory.interface.deploy.inputs.length; 47 | if (args.length !== numArguments) { 48 | throw new Error( 49 | `expected ${numArguments} constructor arguments, got ${args.length}` 50 | ); 51 | } 52 | this.args = args; 53 | } 54 | 55 | public async extractFactoryDeps(artifact: any): Promise { 56 | const visited = new Set(); 57 | visited.add(`${artifact.sourceName}:${artifact.contractName}`); 58 | return await this._extractFactoryDepsRecursive(artifact, visited); 59 | } 60 | 61 | private async _extractFactoryDepsRecursive( 62 | artifact: any, 63 | visited: Set 64 | ): Promise { 65 | // Load all the dependency bytecodes. 66 | // We transform it into an array of bytecodes. 67 | const factoryDeps: string[] = []; 68 | for (const dependencyHash in artifact.factoryDeps) { 69 | if (!dependencyHash) continue; 70 | const dependencyContract = artifact.factoryDeps[dependencyHash]; 71 | if (!visited.has(dependencyContract)) { 72 | const dependencyArtifact = await this.getArtifact(dependencyContract); 73 | factoryDeps.push(dependencyArtifact.bytecode); 74 | visited.add(dependencyContract); 75 | const transitiveDeps = await this._extractFactoryDepsRecursive( 76 | dependencyArtifact, 77 | visited 78 | ); 79 | factoryDeps.push(...transitiveDeps); 80 | } 81 | } 82 | return factoryDeps; 83 | } 84 | 85 | public async getDeployTransaction(): Promise { 86 | let overrides = this.overrides; 87 | if (this.isZkSync) { 88 | const factoryDeps = await this.extractFactoryDeps(this.artifact); 89 | 90 | const { customData, ..._overrides } = overrides ?? {}; 91 | overrides = { 92 | ..._overrides, 93 | customData: { 94 | ...customData, 95 | factoryDeps, 96 | feeToken: zk.utils.ETH_ADDRESS, 97 | }, 98 | }; 99 | } 100 | 101 | return this.factory.getDeployTransaction(...this.args, overrides); 102 | } 103 | 104 | private async calculateEvmCreate2Address( 105 | create2DeployerAddress: Address, 106 | salt: string 107 | ): Promise
{ 108 | const deploymentTx = await this.getDeployTransaction(); 109 | if (typeof deploymentTx.data !== 'string') 110 | throw Error('unsigned tx data as bytes not supported'); 111 | return getAddress( 112 | '0x' + 113 | solidityKeccak256( 114 | ['bytes'], 115 | [ 116 | `0xff${create2DeployerAddress.slice(2)}${salt.slice( 117 | 2 118 | )}${solidityKeccak256(['bytes'], [deploymentTx.data]).slice(2)}`, 119 | ] 120 | ).slice(-40) 121 | ); 122 | } 123 | 124 | private async calculateZkCreate2Address( 125 | create2DeployerAddress: Address, 126 | salt: string 127 | ): Promise
{ 128 | const bytecodeHash = zk.utils.hashBytecode(this.artifact.bytecode); 129 | const constructor = this.factory.interface.encodeDeploy(this.args); 130 | return zk.utils.create2Address( 131 | create2DeployerAddress, 132 | bytecodeHash, 133 | salt, 134 | constructor 135 | ); 136 | } 137 | 138 | public async getCreate2Address( 139 | create2DeployerAddress: Address, 140 | create2Salt: string 141 | ): Promise
{ 142 | if (this.isZkSync) 143 | return await this.calculateZkCreate2Address( 144 | create2DeployerAddress, 145 | create2Salt 146 | ); 147 | return await this.calculateEvmCreate2Address( 148 | create2DeployerAddress, 149 | create2Salt 150 | ); 151 | } 152 | 153 | public async compareDeploymentTransaction( 154 | transaction: TransactionResponse, 155 | deployment: Deployment 156 | ): Promise { 157 | const newTransaction = await this.getDeployTransaction(); 158 | const newData = newTransaction.data?.toString(); 159 | if (this.isZkSync) { 160 | const currentFlattened = hexConcat(deployment.factoryDeps || []); 161 | const newFlattened = hexConcat(newTransaction.customData?.factoryDeps); 162 | 163 | return transaction.data !== newData || currentFlattened != newFlattened; 164 | } else { 165 | return transaction.data !== newData; 166 | } 167 | } 168 | 169 | getDeployedAddress( 170 | receipt: TransactionReceipt, 171 | options: DeployOptions, 172 | create2Address: string | undefined 173 | ): string { 174 | if (options.deterministicDeployment && create2Address) { 175 | return create2Address; 176 | } 177 | 178 | if (this.isZkSync) { 179 | const deployedAddresses = zk.utils 180 | .getDeployedContracts(receipt) 181 | .map((info) => info.deployedAddress); 182 | 183 | return deployedAddresses[deployedAddresses.length - 1]; 184 | } 185 | 186 | return receipt.contractAddress; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/decs.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'match-all'; 2 | -------------------------------------------------------------------------------- /src/errors.ts: -------------------------------------------------------------------------------- 1 | import {BigNumber} from '@ethersproject/bignumber'; 2 | import {bnReplacer} from './internal/utils'; 3 | 4 | export class UnknownSignerError extends Error { 5 | constructor( 6 | public data: { 7 | from: string; 8 | to?: string; 9 | data?: string; 10 | value?: string | BigNumber; 11 | contract?: {name: string; method: string; args: unknown[]}; 12 | } 13 | ) { 14 | super( 15 | `Unknown Signer for account: ${ 16 | data.from 17 | } Trying to execute the following::\n ${JSON.stringify( 18 | data, 19 | bnReplacer, 20 | ' ' 21 | )}` 22 | ); 23 | Error.captureStackTrace(this, UnknownSignerError); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/globalStore.ts: -------------------------------------------------------------------------------- 1 | import {Network} from 'hardhat/types'; 2 | 3 | // used a fallback as some plugin might override network fields, see for example : https://github.com/sc-forks/solidity-coverage/issues/624 4 | export const store: { 5 | networks: {[name: string]: Network}; 6 | } = { 7 | networks: {}, 8 | }; 9 | -------------------------------------------------------------------------------- /src/hdpath.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ 2 | import chalk from 'chalk'; 3 | 4 | function logError(...args: any[]) { 5 | console.log(chalk.red(...args)); 6 | } 7 | 8 | export function getDerivationPath(chainId: number): string | undefined { 9 | let coinType; 10 | 11 | switch (chainId) { 12 | case 1: 13 | case 2020 /* Ronin Mainnet */: 14 | case 2021 /* Ronin Testnet */: 15 | coinType = '60'; 16 | break; 17 | case 3: 18 | case 4: 19 | case 5: 20 | coinType = '1'; 21 | break; 22 | default: 23 | logError(`Network with chainId: ${chainId} not supported.`); 24 | return undefined; 25 | } 26 | 27 | const derivationPath = `m/44'/${coinType}'/0'/0`; 28 | return derivationPath; 29 | } 30 | -------------------------------------------------------------------------------- /src/internal/types.ts: -------------------------------------------------------------------------------- 1 | import {Artifact} from 'hardhat/types'; 2 | 3 | import { 4 | Deployment, 5 | FixtureFunc, 6 | DeploymentSubmission, 7 | ExtendedArtifact, 8 | } from '../../types'; 9 | 10 | export interface PartialExtension { 11 | readDotFile(name: string): Promise; 12 | saveDotFile(name: string, content: string): Promise; 13 | deleteDotFile(name: string): Promise; 14 | 15 | save(name: string, deployment: DeploymentSubmission): Promise; 16 | delete(name: string): Promise; 17 | 18 | get(name: string): Promise; 19 | getOrNull(name: string): Promise; 20 | getDeploymentsFromAddress(address: string): Promise; 21 | all(): Promise<{[name: string]: Deployment}>; 22 | getExtendedArtifact(name: string): Promise; 23 | getArtifact(name: string): Promise; 24 | run( 25 | tags?: string | string[], 26 | options?: { 27 | resetMemory?: boolean; 28 | deletePreviousDeployments?: boolean; 29 | writeDeploymentsToFiles?: boolean; 30 | export?: string; 31 | exportAll?: string; 32 | } 33 | ): Promise<{[name: string]: Deployment}>; 34 | fixture( 35 | tags?: string | string[], 36 | options?: {fallbackToGlobal?: boolean; keepExistingDeployments?: boolean} 37 | ): Promise<{[name: string]: Deployment}>; 38 | createFixture( 39 | func: FixtureFunc, 40 | id?: string 41 | ): (options?: O) => Promise; 42 | log(...args: unknown[]): void; 43 | 44 | getNetworkName(): string; 45 | getGasUsed(): number; 46 | } 47 | -------------------------------------------------------------------------------- /src/internal/utils.ts: -------------------------------------------------------------------------------- 1 | export function bnReplacer(k: string, v: any): any { 2 | if (typeof v === 'bigint') { 3 | return v.toString(); 4 | } 5 | return v; 6 | } 7 | -------------------------------------------------------------------------------- /src/sourcify.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ 2 | import axios from 'axios'; 3 | import FormData from 'form-data'; 4 | import {HardhatRuntimeEnvironment} from 'hardhat/types'; 5 | import chalk from 'chalk'; 6 | import fs from 'fs-extra'; 7 | import path from 'path'; 8 | import {Readable} from 'stream'; 9 | 10 | function log(...args: any[]) { 11 | console.log(...args); 12 | } 13 | 14 | function logError(...args: any[]) { 15 | console.log(chalk.red(...args)); 16 | } 17 | 18 | function logInfo(...args: any[]) { 19 | console.log(chalk.yellow(...args)); 20 | } 21 | 22 | function logSuccess(...args: any[]) { 23 | console.log(chalk.green(...args)); 24 | } 25 | 26 | function ensureTrailingSlash(s: string): string { 27 | const lastChar = s.substr(-1); 28 | if (lastChar != '/') { 29 | s = s + '/'; 30 | } 31 | return s; 32 | } 33 | 34 | // const defaultEndpoint = 'https://server.verificationstaging.shardlabs.io/'; 35 | const defaultEndpoint = 'https://sourcify.dev/server/'; 36 | 37 | export async function submitSourcesToSourcify( 38 | hre: HardhatRuntimeEnvironment, 39 | config?: { 40 | endpoint?: string; 41 | contractName?: string; 42 | writeFailingMetadata?: boolean; 43 | } 44 | ): Promise { 45 | config = config || {}; 46 | const chainId = await hre.getChainId(); 47 | const all = await hre.deployments.all(); 48 | const url = config.endpoint 49 | ? ensureTrailingSlash(config.endpoint) 50 | : defaultEndpoint; 51 | 52 | async function submit(name: string) { 53 | const deployment = all[name]; 54 | const {address, metadata: metadataString} = deployment; 55 | 56 | try { 57 | const checkResponse = await axios.get( 58 | `${url}checkByAddresses?addresses=${address.toLowerCase()}&chainIds=${chainId}` 59 | ); 60 | const {data: checkData} = checkResponse; 61 | if (checkData[0].status === 'perfect') { 62 | log(`already verified: ${name} (${address}), skipping.`); 63 | return; 64 | } 65 | } catch (e) { 66 | logError( 67 | ((e as any).response && JSON.stringify((e as any).response.data)) || e 68 | ); 69 | } 70 | 71 | if (!metadataString) { 72 | logError( 73 | `Contract ${name} was deployed without saving metadata. Cannot submit to sourcify, skipping.` 74 | ); 75 | return; 76 | } 77 | 78 | logInfo(`verifying ${name} (${address} on chain ${chainId}) ...`); 79 | 80 | const formData = new FormData(); 81 | formData.append('address', address); 82 | formData.append('chain', chainId); 83 | 84 | const fileStream = new Readable(); 85 | fileStream.push(metadataString); 86 | fileStream.push(null); 87 | formData.append('files', fileStream, 'metadata.json'); 88 | 89 | try { 90 | const submissionResponse = await axios.post(url, formData, { 91 | headers: formData.getHeaders(), 92 | }); 93 | if (submissionResponse.data.result[0].status === 'perfect') { 94 | logSuccess(` => contract ${name} is now verified`); 95 | } else { 96 | logError(` => contract ${name} is not verified`); 97 | } 98 | } catch (e) { 99 | if (config && config.writeFailingMetadata) { 100 | const failingMetadataFolder = path.join('failing_metadata', chainId); 101 | fs.ensureDirSync(failingMetadataFolder); 102 | fs.writeFileSync( 103 | path.join(failingMetadataFolder, `${name}_at_${address}.json`), 104 | metadataString 105 | ); 106 | } 107 | logError( 108 | ((e as any).response && JSON.stringify((e as any).response.data)) || e 109 | ); 110 | } 111 | } 112 | 113 | if (config.contractName) { 114 | await submit(config.contractName); 115 | } else { 116 | for (const name of Object.keys(all)) { 117 | await submit(name); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/type-extensions.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ 2 | import 'hardhat/types/runtime'; 3 | import 'hardhat/types/config'; 4 | import { 5 | Address, 6 | DeploymentsExtension, 7 | DeterministicDeploymentInfo, 8 | } from '../types'; 9 | import {EthereumProvider} from 'hardhat/types'; 10 | 11 | declare module 'hardhat/types/config' { 12 | interface HardhatUserConfig { 13 | namedAccounts?: { 14 | [name: string]: 15 | | string 16 | | number 17 | | {[network: string]: null | number | string}; 18 | }; 19 | deterministicDeployment?: 20 | | { 21 | [network: string]: DeterministicDeploymentInfo; 22 | } 23 | | ((network: string) => DeterministicDeploymentInfo | undefined); 24 | external?: { 25 | deployments?: { 26 | [networkName: string]: string[]; 27 | }; 28 | contracts?: { 29 | artifacts: string | string[]; 30 | deploy?: string; 31 | }[]; 32 | }; 33 | verify?: {etherscan?: {apiKey?: string}}; 34 | } 35 | 36 | interface HardhatConfig { 37 | namedAccounts: { 38 | [name: string]: 39 | | string 40 | | number 41 | | {[network: string]: null | number | string}; 42 | }; 43 | deterministicDeployment?: 44 | | { 45 | [network: string]: DeterministicDeploymentInfo; 46 | } 47 | | ((network: string) => DeterministicDeploymentInfo | undefined); 48 | external?: { 49 | deployments?: { 50 | [networkName: string]: string[]; 51 | }; 52 | contracts?: { 53 | artifacts: string[]; 54 | deploy?: string; 55 | }[]; 56 | }; 57 | verify: {etherscan?: {apiKey?: string}}; 58 | } 59 | 60 | interface HardhatNetworkUserConfig { 61 | live?: boolean; 62 | saveDeployments?: boolean; 63 | tags?: string[]; 64 | deploy?: string | string[]; 65 | companionNetworks?: {[name: string]: string}; 66 | verify?: {etherscan?: {apiKey?: string; apiUrl?: string}}; 67 | zksync?: boolean; 68 | autoImpersonate?: boolean; 69 | } 70 | 71 | interface HttpNetworkUserConfig { 72 | live?: boolean; 73 | saveDeployments?: boolean; 74 | tags?: string[]; 75 | deploy?: string | string[]; 76 | companionNetworks?: {[name: string]: string}; 77 | verify?: {etherscan?: {apiKey?: string; apiUrl?: string}}; 78 | zksync?: boolean; 79 | autoImpersonate?: boolean; 80 | } 81 | 82 | interface ProjectPathsUserConfig { 83 | deploy?: string | string[]; 84 | deployments?: string; 85 | imports?: string; 86 | } 87 | 88 | interface HardhatNetworkConfig { 89 | live: boolean; 90 | saveDeployments: boolean; 91 | tags: string[]; 92 | deploy?: string[]; 93 | companionNetworks: {[name: string]: string}; 94 | verify?: {etherscan?: {apiKey?: string; apiUrl?: string}}; 95 | zksync?: boolean; 96 | autoImpersonate?: boolean; 97 | } 98 | 99 | interface HttpNetworkConfig { 100 | live: boolean; 101 | saveDeployments: boolean; 102 | tags: string[]; 103 | deploy?: string[]; 104 | companionNetworks: {[name: string]: string}; 105 | verify?: {etherscan?: {apiKey?: string; apiUrl?: string}}; 106 | zksync?: boolean; 107 | autoImpersonate?: boolean; 108 | } 109 | 110 | interface ProjectPathsConfig { 111 | deploy: string[]; 112 | deployments: string; 113 | imports: string; 114 | } 115 | } 116 | 117 | declare module 'hardhat/types/runtime' { 118 | interface HardhatRuntimeEnvironment { 119 | deployments: DeploymentsExtension; 120 | getNamedAccounts: () => Promise<{ 121 | [name: string]: Address; 122 | }>; 123 | getUnnamedAccounts: () => Promise; 124 | getChainId(): Promise; 125 | companionNetworks: { 126 | [name: string]: { 127 | deployments: DeploymentsExtension; 128 | getNamedAccounts: () => Promise<{ 129 | [name: string]: Address; 130 | }>; 131 | getUnnamedAccounts: () => Promise; 132 | getChainId(): Promise; 133 | provider: EthereumProvider; 134 | }; 135 | }; 136 | } 137 | 138 | interface Network { 139 | live: boolean; 140 | saveDeployments: boolean; 141 | tags: Record; 142 | deploy: string[]; 143 | companionNetworks: {[name: string]: string}; 144 | verify?: {etherscan?: {apiKey?: string; apiUrl?: string}}; 145 | zksync?: boolean; 146 | autoImpersonate?: boolean; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /test/fixture-projects/hardhat-project/.gitignore: -------------------------------------------------------------------------------- 1 | cache/ 2 | artifacts/ 3 | -------------------------------------------------------------------------------- /test/fixture-projects/hardhat-project/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | // We load the plugin here. 2 | import '../../../src/index'; 3 | 4 | import {HardhatUserConfig} from 'hardhat/types'; 5 | 6 | const config: HardhatUserConfig = { 7 | solidity: { 8 | version: '0.7.3', 9 | }, 10 | defaultNetwork: 'hardhat', 11 | }; 12 | 13 | export default config; 14 | -------------------------------------------------------------------------------- /test/helpers.ts: -------------------------------------------------------------------------------- 1 | import {resetHardhatContext} from 'hardhat/plugins-testing'; 2 | import {HardhatRuntimeEnvironment} from 'hardhat/types'; 3 | import path from 'path'; 4 | 5 | declare module 'mocha' { 6 | interface Context { 7 | env: HardhatRuntimeEnvironment; 8 | } 9 | } 10 | 11 | export function useEnvironment( 12 | fixtureProjectName: string, 13 | networkName = 'localhost' 14 | ): void { 15 | beforeEach('Loading hardhat environment', function () { 16 | process.chdir(path.join(__dirname, 'fixture-projects', fixtureProjectName)); 17 | process.env.HARDHAT_NETWORK = networkName; 18 | 19 | this.env = require('hardhat'); 20 | }); 21 | 22 | afterEach('Resetting hardhat', function () { 23 | resetHardhatContext(); 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require dotenv/config 2 | --require ts-node/register 3 | --require source-map-support/register 4 | --recursive test/**/*.test.ts 5 | -------------------------------------------------------------------------------- /test/project.test.ts: -------------------------------------------------------------------------------- 1 | import {assert} from 'chai'; 2 | 3 | import {useEnvironment} from './helpers'; 4 | 5 | describe('hardhat-deploy hre extension', function () { 6 | useEnvironment('hardhat-project', 'hardhat'); 7 | it('It should add the deployments field', function () { 8 | assert.isNotNull(this.env.deployments); 9 | }); 10 | 11 | it('The getChainId should give the correct chainId', async function () { 12 | assert.equal(await this.env.getChainId(), '31337'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2017", 4 | "module": "commonjs", 5 | "lib": ["es2020"], 6 | "declaration": true, 7 | "declarationMap": true, 8 | "sourceMap": true, 9 | "outDir": "./dist", 10 | "strict": true, 11 | "rootDirs": ["./src", "./test"], 12 | "esModuleInterop": true, 13 | "resolveJsonModule": true, 14 | "skipLibCheck": true 15 | }, 16 | "exclude": ["dist", "node_modules"], 17 | "include": ["./test", "./src", "types.ts"] 18 | } 19 | -------------------------------------------------------------------------------- /types.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ 2 | import 'hardhat/types/runtime'; 3 | import 'hardhat/types/config'; 4 | import { 5 | LinkReferences, 6 | Artifact, 7 | HardhatRuntimeEnvironment, 8 | } from 'hardhat/types'; 9 | import type {BigNumber} from '@ethersproject/bignumber'; 10 | import {Signer} from '@ethersproject/abstract-signer'; 11 | 12 | export type ExtendedArtifact = { 13 | abi: any[]; 14 | bytecode: string; // "0x"-prefixed hex string 15 | deployedBytecode?: string; // "0x"-prefixed hex string 16 | metadata?: string; 17 | linkReferences?: LinkReferences; 18 | deployedLinkReferences?: LinkReferences; 19 | solcInput?: string; 20 | solcInputHash?: string; 21 | userdoc?: any; 22 | devdoc?: any; 23 | methodIdentifiers?: any; 24 | storageLayout?: any; 25 | evm?: any; 26 | }; 27 | 28 | export interface DeployFunction { 29 | (env: HardhatRuntimeEnvironment): Promise; 30 | skip?: (env: HardhatRuntimeEnvironment) => Promise; 31 | tags?: string[]; 32 | dependencies?: string[]; 33 | runAtTheEnd?: boolean; 34 | id?: string; 35 | } 36 | 37 | export type Address = string; 38 | 39 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 40 | export type ABI = any[]; // TODO abi 41 | 42 | export type Log = { 43 | blockNumber: number; 44 | blockHash: string; 45 | transactionHash: string; 46 | transactionIndex: number; 47 | logIndex: number; 48 | removed: boolean; 49 | address: string; 50 | topics: string[]; 51 | data: string; 52 | }; 53 | 54 | export type Receipt = { 55 | from: Address; 56 | transactionHash: string; 57 | blockHash: string; 58 | blockNumber: number; 59 | transactionIndex: number; 60 | cumulativeGasUsed: BigNumber | string | number; 61 | gasUsed: BigNumber | string | number; 62 | contractAddress?: string; 63 | to?: Address; 64 | logs?: Log[]; 65 | events?: any[]; 66 | logsBloom?: string; 67 | byzantium?: boolean; 68 | status?: number; 69 | confirmations?: number; 70 | }; 71 | 72 | export type FacetOptions = { 73 | name?: string; 74 | contract?: string | ArtifactData; 75 | args?: any[]; 76 | linkedData?: any; // JSONable ? 77 | libraries?: Libraries; 78 | deterministic?: boolean | string; 79 | }; 80 | export type DiamondFacets = Array | Array; 81 | export interface DiamondOptions extends TxOptions { 82 | diamondContract?: string | ArtifactData; // TODO 83 | diamondContractArgs?: any[]; 84 | owner?: Address; 85 | // defaultLoopeFacet?: boolean; // TODO // always there 86 | defaultOwnershipFacet?: boolean; 87 | defaultCutFacet?: boolean; 88 | facets: DiamondFacets; 89 | log?: boolean; 90 | libraries?: Libraries; 91 | linkedData?: any; // JSONable ? 92 | upgradeIndex?: number; 93 | execute?: { 94 | contract?: 95 | | string 96 | | {name: string; artifact: string | ArtifactData; args?: any[]}; 97 | methodName: string; 98 | args: any[]; 99 | }; 100 | excludeSelectors?: { 101 | [facetName: string]: string[]; 102 | }; 103 | deterministicSalt?: string; 104 | facetsArgs?: any[]; 105 | } 106 | 107 | type ProxyOptionsBase = { 108 | owner?: Address; 109 | upgradeIndex?: number; 110 | proxyContract?: // default to EIP173Proxy 111 | string | ArtifactData; 112 | proxyArgs?: any[]; // default to ["{implementation}", "{admin}", "{data}"] 113 | viaAdminContract?: 114 | | string 115 | | { 116 | name: string; 117 | artifact?: string | ArtifactData; 118 | }; 119 | implementationName?: string; 120 | checkABIConflict?: boolean; 121 | checkProxyAdmin?: boolean; 122 | upgradeFunction?: { 123 | methodName: string; 124 | upgradeArgs: any[]; 125 | }; 126 | }; 127 | 128 | export type ProxyOptions = 129 | | (ProxyOptionsBase & { 130 | methodName?: string; 131 | }) 132 | | (ProxyOptionsBase & { 133 | execute?: 134 | | { 135 | methodName: string; 136 | args: any[]; 137 | } 138 | | { 139 | init: { 140 | methodName: string; 141 | args: any[]; 142 | }; 143 | onUpgrade?: { 144 | methodName: string; 145 | args: any[]; 146 | }; 147 | }; 148 | }); 149 | 150 | export type ArtifactData = { 151 | abi: ABI; 152 | bytecode: string; 153 | deployedBytecode?: string; 154 | metadata?: string; 155 | methodIdentifiers?: any; 156 | storageLayout?: any; 157 | userdoc?: any; 158 | devdoc?: any; 159 | gasEstimates?: any; 160 | }; 161 | 162 | export interface DeployOptionsBase extends TxOptions { 163 | contract?: string | ArtifactData; 164 | args?: any[]; 165 | skipIfAlreadyDeployed?: boolean; 166 | linkedData?: any; // JSONable ? 167 | libraries?: Libraries; 168 | proxy?: boolean | string | ProxyOptions; // TODO support different type of proxies ? 169 | } 170 | 171 | export interface DeployOptions extends DeployOptionsBase { 172 | deterministicDeployment?: boolean | string; 173 | } 174 | 175 | export interface Create2DeployOptions extends DeployOptionsBase { 176 | salt?: string; 177 | } 178 | 179 | export interface CallOptions { 180 | from?: string; 181 | gasLimit?: string | number | BigNumber; 182 | gasPrice?: string | BigNumber; 183 | maxFeePerGas?: string | BigNumber; 184 | maxPriorityFeePerGas?: string | BigNumber; 185 | value?: string | BigNumber; 186 | nonce?: string | number | BigNumber; 187 | to?: string; // TODO make to and data part of a `SimpleCallOptions` interface 188 | data?: string; 189 | customData?: Record; 190 | } 191 | 192 | export interface TxOptions extends CallOptions { 193 | from: string; 194 | log?: boolean; // TODO string (for comment in log) 195 | autoMine?: boolean; 196 | estimatedGasLimit?: string | number | BigNumber; 197 | estimateGasExtra?: string | number | BigNumber; 198 | waitConfirmations?: number; 199 | } 200 | 201 | export interface Execute extends TxOptions { 202 | name: string; 203 | methodName: string; 204 | args?: any[]; 205 | } 206 | 207 | export interface SimpleTx extends TxOptions { 208 | to: string; 209 | } 210 | 211 | export interface DeployedContract { 212 | address: Address; 213 | abi: ABI; 214 | } 215 | 216 | export interface DeployResult extends Deployment { 217 | newlyDeployed: boolean; 218 | } 219 | 220 | export type FixtureFunc = ( 221 | env: HardhatRuntimeEnvironment, 222 | options?: O 223 | ) => Promise; 224 | 225 | export interface DeploymentsExtension { 226 | deploy(name: string, options: DeployOptions): Promise; // deploy a contract 227 | diamond: { 228 | // deploy diamond based contract (see section below) 229 | deploy(name: string, options: DiamondOptions): Promise; 230 | }; 231 | deterministic( // return the determinsitic address as well as a function to deploy the contract, can pass the `salt` field in the option to use different salt 232 | name: string, 233 | options: Create2DeployOptions 234 | ): Promise<{ 235 | address: Address; 236 | implementationAddress?: Address; 237 | deploy(): Promise; 238 | }>; 239 | fetchIfDifferent( // return true if new compiled code is different than deployed contract 240 | name: string, 241 | options: DeployOptions 242 | ): Promise<{differences: boolean; address?: string}>; 243 | 244 | readDotFile(name: string): Promise; 245 | saveDotFile(name: string, content: string): Promise; 246 | deleteDotFile(name: string): Promise; 247 | 248 | save(name: string, deployment: DeploymentSubmission): Promise; // low level save of deployment 249 | delete(name: string): Promise; 250 | get(name: string): Promise; // fetch a deployment by name, throw if not existing 251 | getOrNull(name: string): Promise; // fetch deployment by name, return null if not existing 252 | getDeploymentsFromAddress(address: string): Promise; 253 | all(): Promise<{[name: string]: Deployment}>; // return all deployments 254 | getArtifact(name: string): Promise; // return a hardhat artifact (compiled contract without deployment) 255 | getExtendedArtifact(name: string): Promise; // return a extended artifact (with more info) (compiled contract without deployment) 256 | run( // execute deployment scripts 257 | tags?: string | string[], 258 | options?: { 259 | resetMemory?: boolean; 260 | deletePreviousDeployments?: boolean; 261 | writeDeploymentsToFiles?: boolean; 262 | export?: string; 263 | exportAll?: string; 264 | } 265 | ): Promise<{[name: string]: Deployment}>; 266 | fixture( // execute deployment as fixture for test // use evm_snapshot to revert back 267 | tags?: string | string[], 268 | options?: {fallbackToGlobal?: boolean; keepExistingDeployments?: boolean} 269 | ): Promise<{[name: string]: Deployment}>; 270 | createFixture( // execute a function as fixture using evm_snaphost to revert back each time 271 | func: FixtureFunc, 272 | id?: string 273 | ): (options?: O) => Promise; 274 | log(...args: any[]): void; // log data only if log enabled (disabled in test fixture) 275 | 276 | getNetworkName(): string; 277 | getGasUsed(): number; 278 | 279 | execute( // execute function call on contract 280 | name: string, 281 | options: TxOptions, 282 | methodName: string, 283 | ...args: any[] 284 | ): Promise; 285 | rawTx(tx: SimpleTx): Promise; // execute a simple transaction 286 | catchUnknownSigner( // you can wrap other function with this function and it will catch failure due to missing signer with the details of the tx to be executed 287 | action: Promise | (() => Promise), 288 | options?: {log?: boolean} 289 | ): Promise; 295 | read( // make a read-only call to a contract 296 | name: string, 297 | options: CallOptions, 298 | methodName: string, 299 | ...args: any[] 300 | ): Promise; 301 | read(name: string, methodName: string, ...args: any[]): Promise; 302 | getSigner(address: string): Promise; 303 | // rawCall(to: Address, data: string): Promise; // TODO ? 304 | } 305 | 306 | export interface ContractExport { 307 | address: string; 308 | abi: any[]; 309 | linkedData?: any; 310 | } 311 | 312 | export interface Export { 313 | chainId: string; 314 | name: string; 315 | contracts: {[name: string]: ContractExport}; 316 | } 317 | 318 | export type MultiExport = { 319 | [chainId: string]: Export[]; 320 | }; 321 | 322 | export type Libraries = {[libraryName: string]: Address}; 323 | 324 | export enum FacetCutAction { 325 | Add, 326 | Replace, 327 | Remove, 328 | } 329 | 330 | export type FacetCut = Facet & { 331 | action: FacetCutAction; 332 | }; 333 | 334 | export type Facet = { 335 | facetAddress: string; 336 | functionSelectors: string[]; 337 | }; 338 | 339 | export interface DeploymentSubmission { 340 | abi: ABI; 341 | address: Address; // used to override receipt.contractAddress (useful for proxies) 342 | receipt?: Receipt; 343 | transactionHash?: string; 344 | history?: Deployment[]; 345 | implementation?: string; 346 | args?: any[]; 347 | linkedData?: any; 348 | solcInput?: string; 349 | solcInputHash?: string; 350 | metadata?: string; 351 | bytecode?: string; 352 | deployedBytecode?: string; 353 | userdoc?: any; 354 | devdoc?: any; 355 | methodIdentifiers?: any; 356 | facets?: Facet[]; 357 | execute?: { 358 | methodName: string; 359 | args: any[]; 360 | }; 361 | storageLayout?: any; 362 | libraries?: Libraries; 363 | gasEstimates?: any; 364 | factoryDeps?: string[]; 365 | } 366 | 367 | // export type LibraryReferences = { 368 | // [filepath: string]: { [name: string]: { length: number; start: number }[] }; 369 | // }; 370 | 371 | export interface Deployment { 372 | address: Address; 373 | abi: ABI; 374 | receipt?: Receipt; 375 | transactionHash?: string; 376 | history?: Deployment[]; 377 | numDeployments?: number; 378 | implementation?: string; 379 | args?: any[]; 380 | linkedData?: any; 381 | solcInputHash?: string; 382 | metadata?: string; 383 | bytecode?: string; 384 | deployedBytecode?: string; 385 | libraries?: Libraries; 386 | userdoc?: any; 387 | devdoc?: any; 388 | methodIdentifiers?: any; 389 | facets?: Facet[]; 390 | storageLayout?: any; 391 | gasEstimates?: any; 392 | factoryDeps?: string[]; 393 | } 394 | 395 | export interface DeterministicDeploymentInfo { 396 | factory: string; 397 | deployer: string; 398 | funding: string; 399 | signedTx: string; 400 | } 401 | --------------------------------------------------------------------------------