├── .gitignore ├── .nvmrc ├── .vscode ├── extensions.json └── launch.json ├── README.md ├── contracts ├── AsyncCall.solpp ├── Await.solpp ├── CallWithValue.solpp ├── CallWithValueAsync.solpp ├── HelloWorld.solpp ├── NFT.solpp ├── SyncCall.solpp ├── TryCatch.sol ├── builtin │ ├── TestAsset.solpp │ └── builtin.solpp ├── callback.solpp ├── constructor.solpp ├── cross_lang │ ├── Strings.sol │ └── Test.solpp ├── events.solpp ├── legacy │ └── HelloWorld.solpp ├── library.solpp ├── magic.solpp ├── openzeppelin │ ├── access │ │ ├── AccessControl.sol │ │ ├── AccessControlEnumerable.sol │ │ ├── IAccessControl.sol │ │ ├── IAccessControlEnumerable.sol │ │ ├── Ownable.sol │ │ └── README.adoc │ ├── finance │ │ ├── PaymentSplitter.sol │ │ ├── README.adoc │ │ └── VestingWallet.sol │ ├── governance │ │ ├── Governor.sol │ │ ├── IGovernor.sol │ │ ├── README.adoc │ │ ├── TimelockController.sol │ │ ├── compatibility │ │ │ ├── GovernorCompatibilityBravo.sol │ │ │ └── IGovernorCompatibilityBravo.sol │ │ ├── extensions │ │ │ ├── GovernorCountingSimple.sol │ │ │ ├── GovernorPreventLateQuorum.sol │ │ │ ├── GovernorProposalThreshold.sol │ │ │ ├── GovernorSettings.sol │ │ │ ├── GovernorTimelockCompound.sol │ │ │ ├── GovernorTimelockControl.sol │ │ │ ├── GovernorVotes.sol │ │ │ ├── GovernorVotesComp.sol │ │ │ ├── GovernorVotesQuorumFraction.sol │ │ │ └── IGovernorTimelock.sol │ │ └── utils │ │ │ ├── IVotes.sol │ │ │ └── Votes.sol │ ├── interfaces │ │ ├── IERC1155.sol │ │ ├── IERC1155MetadataURI.sol │ │ ├── IERC1155Receiver.sol │ │ ├── IERC1271.sol │ │ ├── IERC1363.sol │ │ ├── IERC1363Receiver.sol │ │ ├── IERC1363Spender.sol │ │ ├── IERC165.sol │ │ ├── IERC1820Implementer.sol │ │ ├── IERC1820Registry.sol │ │ ├── IERC20.sol │ │ ├── IERC20Metadata.sol │ │ ├── IERC2981.sol │ │ ├── IERC3156.sol │ │ ├── IERC3156FlashBorrower.sol │ │ ├── IERC3156FlashLender.sol │ │ ├── IERC721.sol │ │ ├── IERC721Enumerable.sol │ │ ├── IERC721Metadata.sol │ │ ├── IERC721Receiver.sol │ │ ├── IERC777.sol │ │ ├── IERC777Recipient.sol │ │ ├── IERC777Sender.sol │ │ ├── README.adoc │ │ └── draft-IERC2612.sol │ ├── metatx │ │ ├── ERC2771Context.sol │ │ ├── MinimalForwarder.sol │ │ └── README.adoc │ ├── mocks │ │ ├── AccessControlEnumerableMock.sol │ │ ├── AccessControlMock.sol │ │ ├── AddressImpl.sol │ │ ├── ArraysImpl.sol │ │ ├── BadBeacon.sol │ │ ├── BitmapMock.sol │ │ ├── CallReceiverMock.sol │ │ ├── CheckpointsImpl.sol │ │ ├── ClashingImplementation.sol │ │ ├── ClonesMock.sol │ │ ├── ConditionalEscrowMock.sol │ │ ├── ContextMock.sol │ │ ├── CountersImpl.sol │ │ ├── Create2Impl.sol │ │ ├── DummyImplementation.sol │ │ ├── ECDSAMock.sol │ │ ├── EIP712External.sol │ │ ├── ERC1155BurnableMock.sol │ │ ├── ERC1155Mock.sol │ │ ├── ERC1155PausableMock.sol │ │ ├── ERC1155ReceiverMock.sol │ │ ├── ERC1155SupplyMock.sol │ │ ├── ERC1271WalletMock.sol │ │ ├── ERC165 │ │ │ ├── ERC165InterfacesSupported.sol │ │ │ ├── ERC165MissingData.sol │ │ │ └── ERC165NotSupported.sol │ │ ├── ERC165CheckerMock.sol │ │ ├── ERC165Mock.sol │ │ ├── ERC165StorageMock.sol │ │ ├── ERC1820ImplementerMock.sol │ │ ├── ERC20BurnableMock.sol │ │ ├── ERC20CappedMock.sol │ │ ├── ERC20DecimalsMock.sol │ │ ├── ERC20FlashMintMock.sol │ │ ├── ERC20Mock.sol │ │ ├── ERC20PausableMock.sol │ │ ├── ERC20PermitMock.sol │ │ ├── ERC20SnapshotMock.sol │ │ ├── ERC20VotesCompMock.sol │ │ ├── ERC20VotesMock.sol │ │ ├── ERC20WrapperMock.sol │ │ ├── ERC2771ContextMock.sol │ │ ├── ERC3156FlashBorrowerMock.sol │ │ ├── ERC721BurnableMock.sol │ │ ├── ERC721EnumerableMock.sol │ │ ├── ERC721Mock.sol │ │ ├── ERC721PausableMock.sol │ │ ├── ERC721ReceiverMock.sol │ │ ├── ERC721URIStorageMock.sol │ │ ├── ERC721VotesMock.sol │ │ ├── ERC777Mock.sol │ │ ├── ERC777SenderRecipientMock.sol │ │ ├── EnumerableMapMock.sol │ │ ├── EnumerableSetMock.sol │ │ ├── EtherReceiverMock.sol │ │ ├── GovernorCompMock.sol │ │ ├── GovernorCompatibilityBravoMock.sol │ │ ├── GovernorMock.sol │ │ ├── GovernorPreventLateQuorumMock.sol │ │ ├── GovernorTimelockCompoundMock.sol │ │ ├── GovernorTimelockControlMock.sol │ │ ├── GovernorVoteMock.sol │ │ ├── InitializableMock.sol │ │ ├── MathMock.sol │ │ ├── MerkleProofWrapper.sol │ │ ├── MulticallTest.sol │ │ ├── MulticallTokenMock.sol │ │ ├── MultipleInheritanceInitializableMocks.sol │ │ ├── OwnableMock.sol │ │ ├── PausableMock.sol │ │ ├── PullPaymentMock.sol │ │ ├── ReentrancyAttack.sol │ │ ├── ReentrancyMock.sol │ │ ├── RegressionImplementation.sol │ │ ├── SafeCastMock.sol │ │ ├── SafeERC20Helper.sol │ │ ├── SafeMathMock.sol │ │ ├── SignatureCheckerMock.sol │ │ ├── SignedSafeMathMock.sol │ │ ├── SingleInheritanceInitializableMocks.sol │ │ ├── StorageSlotMock.sol │ │ ├── StringsMock.sol │ │ ├── TimersBlockNumberImpl.sol │ │ ├── TimersTimestampImpl.sol │ │ ├── UUPS │ │ │ └── TestInProd.sol │ │ ├── VotesMock.sol │ │ ├── compound │ │ │ └── CompTimelock.sol │ │ └── wizard │ │ │ ├── MyGovernor1.sol │ │ │ ├── MyGovernor2.sol │ │ │ └── MyGovernor3.sol │ ├── proxy │ │ ├── Clones.sol │ │ ├── ERC1967 │ │ │ ├── ERC1967Proxy.sol │ │ │ └── ERC1967Upgrade.sol │ │ ├── Proxy.sol │ │ ├── README.adoc │ │ ├── beacon │ │ │ ├── BeaconProxy.sol │ │ │ ├── IBeacon.sol │ │ │ └── UpgradeableBeacon.sol │ │ ├── transparent │ │ │ ├── ProxyAdmin.sol │ │ │ └── TransparentUpgradeableProxy.sol │ │ └── utils │ │ │ ├── Initializable.sol │ │ │ └── UUPSUpgradeable.sol │ ├── security │ │ ├── Pausable.sol │ │ ├── PullPayment.sol │ │ ├── README.adoc │ │ └── ReentrancyGuard.sol │ ├── token │ │ ├── ERC1155 │ │ │ ├── ERC1155.sol │ │ │ ├── IERC1155.sol │ │ │ ├── IERC1155Receiver.sol │ │ │ ├── README.adoc │ │ │ ├── extensions │ │ │ │ ├── ERC1155Burnable.sol │ │ │ │ ├── ERC1155Pausable.sol │ │ │ │ ├── ERC1155Supply.sol │ │ │ │ └── IERC1155MetadataURI.sol │ │ │ ├── presets │ │ │ │ ├── ERC1155PresetMinterPauser.sol │ │ │ │ └── README.md │ │ │ └── utils │ │ │ │ ├── ERC1155Holder.sol │ │ │ │ └── ERC1155Receiver.sol │ │ ├── ERC20 │ │ │ ├── ERC20.sol │ │ │ ├── IERC20.sol │ │ │ ├── README.adoc │ │ │ ├── extensions │ │ │ │ ├── ERC20Burnable.sol │ │ │ │ ├── ERC20Capped.sol │ │ │ │ ├── ERC20FlashMint.sol │ │ │ │ ├── ERC20Pausable.sol │ │ │ │ ├── ERC20Snapshot.sol │ │ │ │ ├── ERC20Votes.sol │ │ │ │ ├── ERC20VotesComp.sol │ │ │ │ ├── ERC20Wrapper.sol │ │ │ │ ├── IERC20Metadata.sol │ │ │ │ ├── draft-ERC20Permit.sol │ │ │ │ └── draft-IERC20Permit.sol │ │ │ ├── presets │ │ │ │ ├── ERC20PresetFixedSupply.sol │ │ │ │ ├── ERC20PresetMinterPauser.sol │ │ │ │ └── README.md │ │ │ └── utils │ │ │ │ ├── SafeERC20.sol │ │ │ │ └── TokenTimelock.sol │ │ ├── ERC721 │ │ │ ├── ERC721.sol │ │ │ ├── IERC721.sol │ │ │ ├── IERC721Receiver.sol │ │ │ ├── README.adoc │ │ │ ├── extensions │ │ │ │ ├── ERC721Burnable.sol │ │ │ │ ├── ERC721Enumerable.sol │ │ │ │ ├── ERC721Pausable.sol │ │ │ │ ├── ERC721URIStorage.sol │ │ │ │ ├── IERC721Enumerable.sol │ │ │ │ ├── IERC721Metadata.sol │ │ │ │ └── draft-ERC721Votes.sol │ │ │ ├── presets │ │ │ │ ├── ERC721PresetMinterPauserAutoId.sol │ │ │ │ └── README.md │ │ │ └── utils │ │ │ │ └── ERC721Holder.sol │ │ └── ERC777 │ │ │ ├── ERC777.sol │ │ │ ├── IERC777.sol │ │ │ ├── IERC777Recipient.sol │ │ │ ├── IERC777Sender.sol │ │ │ ├── README.adoc │ │ │ └── presets │ │ │ └── ERC777PresetFixedSupply.sol │ └── utils │ │ ├── Address.sol │ │ ├── Arrays.sol │ │ ├── Checkpoints.sol │ │ ├── Context.sol │ │ ├── Counters.sol │ │ ├── Create2.sol │ │ ├── Multicall.sol │ │ ├── README.adoc │ │ ├── StorageSlot.sol │ │ ├── Strings.sol │ │ ├── Timers.sol │ │ ├── cryptography │ │ ├── ECDSA.sol │ │ ├── MerkleProof.sol │ │ ├── SignatureChecker.sol │ │ └── draft-EIP712.sol │ │ ├── escrow │ │ ├── ConditionalEscrow.sol │ │ ├── Escrow.sol │ │ └── RefundEscrow.sol │ │ ├── introspection │ │ ├── ERC165.sol │ │ ├── ERC165Checker.sol │ │ ├── ERC165Storage.sol │ │ ├── ERC1820Implementer.sol │ │ ├── IERC165.sol │ │ ├── IERC1820Implementer.sol │ │ └── IERC1820Registry.sol │ │ ├── math │ │ ├── Math.sol │ │ ├── SafeCast.sol │ │ ├── SafeMath.sol │ │ └── SignedSafeMath.sol │ │ └── structs │ │ ├── BitMaps.sol │ │ ├── EnumerableMap.sol │ │ └── EnumerableSet.sol ├── revert.solpp └── transfer.solpp ├── package-lock.json ├── package.json ├── test ├── AsyncCall.spec.ts ├── Await.spec.ts ├── CallWithValue.spec.ts ├── CallWithValueAsync.spec.ts ├── HelloWorld.spec.ts ├── NFT.spec.ts ├── SyncCall.spec.ts ├── TryCatch.spec.ts ├── builtin │ ├── TestAsset.spec.ts │ └── builtin.Asset.spec.ts ├── callback.spec.ts ├── constructor.spec.ts ├── cross_lang.spec.ts ├── events.spec.ts ├── legacy │ └── HelloWorld.spec.ts ├── library.spec.ts ├── magic.spec.ts ├── openzeppelin │ └── utils │ │ └── strings.spec.ts ├── revert.spec.ts ├── smoke.ts ├── transfer.spec.ts ├── utils.ts ├── vite.config.json └── vite.node.json └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | /bin/ledger -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v14 -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ViteLabs.solppdebugger" 4 | ] 5 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "soliditypp", 9 | "request": "launch", 10 | "name": "Soliditypp Debug", 11 | "program": "${file}", 12 | "gviteVersion": "v2.12.0-nightly-202204221713" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # soliditypp-examples 2 | Examples of Solidity++ 0.8.0 / 0.8.1. 3 | 4 | This is a preview version. DO NOT use it in production environment. 5 | # Getting Started 6 | ``` 7 | npm install 8 | npm test 9 | ``` 10 | # Test Environments 11 | 12 | Open `test/vite.node.json` and edit `defaultNode` to switch test environment. 13 | 14 | - **Release Environment**: 15 | Contracts are deployed on local network running the release version of gvite. 16 | 17 | - **Beta Environment**: 18 | Contracts are deployed on local network running the beta version of gvite. 19 | 20 | - **Nightly Environment**: 21 | Contracts are deployed on local network running the nightly version of gvite. 22 | -------------------------------------------------------------------------------- /contracts/AsyncCall.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | // Demonstrate how to call a contract asynchronously. 3 | 4 | pragma soliditypp >=0.8.0; 5 | 6 | interface Receiver { 7 | function callback(string memory payload) external; 8 | } 9 | 10 | contract A { 11 | function echo(string memory s) external { 12 | string memory result = string(abi.encodePacked("hello ", s)); 13 | Receiver(msg.sender).callback(result); 14 | } 15 | } 16 | 17 | contract B is Receiver { 18 | event Received(string data); 19 | function invoke(address a, string memory s) external { 20 | A(a).echo(s); 21 | } 22 | 23 | function callback(string memory payload) external override { 24 | emit Received(payload); 25 | } 26 | } -------------------------------------------------------------------------------- /contracts/Await.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | // Demonstrate how to use await operator 3 | 4 | pragma soliditypp >=0.8.0; 5 | pragma experimental Await; 6 | 7 | // step1: deploy A 8 | contract A { 9 | uint public data; 10 | 11 | function add(uint a, uint b) external returns(uint) { 12 | data = a + b; 13 | return data; 14 | } 15 | } 16 | 17 | // step2: deploy B by passing the address of A as a parameter of contructor 18 | contract B { 19 | A a; 20 | uint public b; 21 | 22 | constructor (address addr) { 23 | a = A(addr); 24 | } 25 | 26 | function test(uint data) external returns(uint) { 27 | uint temp1 = 1; 28 | uint256 temp2 = 0x1122334455667788112233445566778811223344556677881122334455667788; 29 | // call A synchronously 30 | uint result = await a.add(data, 10); 31 | require(temp1 == 1); 32 | require(temp2 == 0x1122334455667788112233445566778811223344556677881122334455667788); 33 | b = result; 34 | return b; 35 | } 36 | } -------------------------------------------------------------------------------- /contracts/CallWithValue.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | // Demostrate how to call a contract and send tokens at the same time. 3 | 4 | pragma soliditypp >=0.8.0; 5 | pragma experimental Await; 6 | 7 | contract A { 8 | event Received(uint indexed topic, uint data, address sender, vitetoken token, uint amount); 9 | 10 | function f(uint a, uint t) external payable returns(uint) { 11 | address sender = msg.sender; 12 | vitetoken token = msg.token; 13 | uint amount = msg.value; 14 | 15 | emit Received(t, a, sender, token, amount); 16 | return a + 1; 17 | } 18 | } 19 | 20 | // deploy B with a minimum of 3 VITE to test 21 | contract B { 22 | A a; 23 | uint public b; 24 | 25 | constructor (address payable addr) payable { 26 | a = A(addr); 27 | } 28 | 29 | function test(uint data) external { 30 | // send an asynchronous call to a.f() with 1 VITE 31 | a.f{value: 1e18}(data, 1); // Note: there are no return values for async calls 32 | 33 | // send a synchronous call to a.f() with 2 VITE 34 | b = await a.f{token: "tti_5649544520544f4b454e6e40", value: 2e18}(data, 2); 35 | } 36 | } -------------------------------------------------------------------------------- /contracts/CallWithValueAsync.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | // Demostrate how to call a contract and send tokens at the same time. 3 | 4 | pragma soliditypp >=0.8.0; 5 | 6 | contract A { 7 | event Received(uint indexed topic, uint data, address sender, vitetoken token, uint amount); 8 | 9 | function f(uint a, uint t) external payable returns(uint) { 10 | address sender = msg.sender; 11 | vitetoken token = msg.token; 12 | uint amount = msg.value; 13 | 14 | emit Received(t, a, sender, token, amount); 15 | return a + 1; 16 | } 17 | } 18 | 19 | // deploy B with a minimum of 1 VITE to test 20 | contract B { 21 | A a; 22 | 23 | constructor (address payable addr) payable { 24 | a = A(addr); 25 | } 26 | 27 | function test(uint data) external { 28 | // send an asynchronous call to a.f() with 1 VITE 29 | // Note: there are no return values for async calls 30 | a.f{value: 1e18}(data, 1); 31 | } 32 | } -------------------------------------------------------------------------------- /contracts/HelloWorld.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp >=0.8.0; 3 | 4 | contract HelloWorld { 5 | uint public data = 123; 6 | 7 | function set(uint a) external { 8 | data = a; 9 | } 10 | } -------------------------------------------------------------------------------- /contracts/NFT.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma soliditypp ^0.8.0; 4 | 5 | import "./openzeppelin/token/ERC721/extensions/ERC721Enumerable.sol"; 6 | 7 | contract NFT is ERC721Enumerable { 8 | constructor(string memory name, string memory symbol) ERC721(name, symbol) {} 9 | 10 | function baseURI() public view returns (string memory) { 11 | return _baseURI(); 12 | } 13 | 14 | function exists(uint256 tokenId) public view returns (bool) { 15 | return _exists(tokenId); 16 | } 17 | 18 | function mint(address to, uint256 tokenId) public { 19 | _mint(to, tokenId); 20 | } 21 | 22 | function safeMint(address to, uint256 tokenId) public { 23 | _safeMint(to, tokenId); 24 | } 25 | 26 | function safeMint( 27 | address to, 28 | uint256 tokenId, 29 | bytes memory _data 30 | ) public { 31 | _safeMint(to, tokenId, _data); 32 | } 33 | 34 | function burn(uint256 tokenId) public { 35 | _burn(tokenId); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /contracts/SyncCall.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | // Demonstrate how a contract call another contract synchronously and wait for an asynchronous function to return. 3 | 4 | /* call hierarchy: 5 | C --> B 6 | B --> A 7 | B <-- A 8 | B --> A 9 | B <-- A 10 | C <-- B 11 | C --------> A 12 | C <-------- A 13 | */ 14 | 15 | pragma soliditypp >=0.8.0; 16 | pragma experimental Await; 17 | 18 | // step1: deploy A 19 | contract A { 20 | uint public data; 21 | 22 | function add(uint a, uint b) external returns(uint) { 23 | data = a + b; 24 | return data; 25 | } 26 | } 27 | 28 | // step2: deploy B by passing the address of A as a parameter of contructor 29 | contract B { 30 | A a; 31 | uint public b; 32 | 33 | constructor (address addr) { 34 | a = A(addr); 35 | } 36 | 37 | function test(uint data) external returns(uint) { 38 | // call A synchronously 39 | b = await a.add(data, 10); 40 | 41 | // call A synchronously one more time 42 | return await a.add(b, 100); 43 | } 44 | } 45 | 46 | // step3: deploy C by passing the address of A and B as the parameters of contructor 47 | contract C { 48 | A a; 49 | B b; 50 | uint public c; 51 | 52 | constructor (address _a, address _b) { 53 | a = A(_a); 54 | b = B(_b); 55 | } 56 | 57 | function f(uint data) external returns(uint) { 58 | // call B synchronously 59 | c = await b.test(data); 60 | 61 | // call A synchronously after that b.test() returns 62 | c = await a.add(c, 1000); 63 | 64 | return c; 65 | } 66 | } -------------------------------------------------------------------------------- /contracts/TryCatch.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma solidity >=0.8.0; 3 | 4 | contract A { 5 | uint public data; 6 | function inc(uint a) external returns(uint) { 7 | data = a; // It will be reverted if the following require condition isn't satisfied. 8 | require(a < 10, "too big"); 9 | return a + 1; 10 | } 11 | } 12 | 13 | contract B { 14 | A a; 15 | string public s; 16 | uint public b; 17 | 18 | constructor (address addr) { 19 | a = A(addr); 20 | } 21 | 22 | function test(uint data) external returns(uint, string memory) { 23 | try a.inc(data) returns (uint r) { 24 | b = r; 25 | s = "OK"; 26 | } catch Error(string memory err) { 27 | b = 0; 28 | s = err; 29 | } 30 | return (b, s); 31 | } 32 | } 33 | 34 | contract C { 35 | B b; 36 | uint public data; 37 | string public err; 38 | 39 | constructor (address _b) { 40 | b = B(_b); 41 | } 42 | 43 | function invoke(uint a) external { 44 | (data, err) = b.test(a); 45 | return; 46 | } 47 | } -------------------------------------------------------------------------------- /contracts/builtin/TestAsset.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp >=0.8.0; 3 | pragma experimental Await; 4 | 5 | import "./builtin.solpp"; 6 | 7 | contract Test { 8 | vitetoken public tokenId; 9 | string public name; 10 | 11 | function issue() external returns(vitetoken) { 12 | tokenId = await BuiltinContractAsset.issue(true, "Test Coin", "TST", 1e5, 2, 1e6); 13 | return tokenId; 14 | } 15 | 16 | function mint(uint256 amount, address addr) external returns(bytes32) { 17 | return await BuiltinContractAsset.mint(tokenId, addr, amount); 18 | } 19 | 20 | function burn(uint256 amount) external { 21 | await BuiltinContractAsset.burn{token: tokenId, value: amount}(); 22 | } 23 | 24 | function getName() external returns(string memory) { 25 | name = await BuiltinContractAsset.name(tokenId); 26 | return name; 27 | } 28 | } -------------------------------------------------------------------------------- /contracts/builtin/builtin.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp ^0.8.0; 3 | 4 | // Asset Built-in Contract 5 | interface BuiltinContractAssetInterface { 6 | // Functions 7 | function issue(bool _mintable, string memory _name, string memory _symbol, uint256 _totalSupply, uint8 _decimals, uint256 _maxSupply) external returns(vitetoken); 8 | function mint(vitetoken tokenId, address to, uint256 amount) external returns(bytes32 mintBlockHash); 9 | function burn() external payable returns(bool); 10 | function transferOwnership(vitetoken tokenId, address newOwner) external returns(bool); 11 | function name(vitetoken tokenId) external view returns(string memory); 12 | function symbol(vitetoken tokenId) external view returns(string memory); 13 | function decimals(vitetoken tokenId) external view returns(uint8); 14 | function totalSupply(vitetoken tokenId) external view returns(uint256); 15 | function maxSupply(vitetoken tokenId) external view returns(uint256); 16 | function mintable(vitetoken tokenId) external view returns(bool); 17 | function owner(vitetoken tokenId) external view returns(address); 18 | // Events 19 | event Issue(vitetoken indexed tokenId, address indexed owner); 20 | event Mint(vitetoken indexed tokenId, address indexed to, uint256 amount); 21 | event Burn(vitetoken indexed tokenId, uint256 amount); 22 | event OwnershipTransferred(vitetoken indexed tokenId, address indexed previousOwner, address indexed newOwner); 23 | } 24 | 25 | BuiltinContractAssetInterface constant BuiltinContractAsset = BuiltinContractAssetInterface("vite_000000000000000000000000000000000000000595292d996d"); -------------------------------------------------------------------------------- /contracts/callback.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp ^0.8.0; 3 | 4 | contract A { 5 | function add(uint a, uint b, function(uint) external callback) external { 6 | if (callback.address != address(0)) { 7 | // send callback to return data to the caller 8 | callback(a + b); 9 | } 10 | } 11 | } 12 | 13 | contract B { 14 | A contractA; 15 | uint public data; 16 | 17 | constructor (address addr) { 18 | contractA = A(addr); 19 | } 20 | 21 | function test() external { 22 | contractA.add(1, 2, this.callback_onAdd); 23 | } 24 | 25 | function callback_onAdd(uint result) external { 26 | // receive data from the called contract 27 | require(msg.sender == address(contractA)); 28 | data = result; 29 | } 30 | } -------------------------------------------------------------------------------- /contracts/constructor.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp ^0.8.0; 3 | 4 | contract Test { 5 | uint public data; 6 | 7 | constructor(uint a) { 8 | data = a; 9 | } 10 | 11 | function set(uint a) external { 12 | data = a; 13 | } 14 | } -------------------------------------------------------------------------------- /contracts/cross_lang/Strings.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev String operations. 8 | */ 9 | library Strings { 10 | bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; 11 | 12 | /** 13 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 14 | */ 15 | function toString(uint256 value) internal pure returns (string memory) { 16 | // Inspired by OraclizeAPI's implementation - MIT licence 17 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 18 | 19 | if (value == 0) { 20 | return "0"; 21 | } 22 | uint256 temp = value; 23 | uint256 digits; 24 | while (temp != 0) { 25 | digits++; 26 | temp /= 10; 27 | } 28 | bytes memory buffer = new bytes(digits); 29 | while (value != 0) { 30 | digits -= 1; 31 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 32 | value /= 10; 33 | } 34 | return string(buffer); 35 | } 36 | 37 | /** 38 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 39 | */ 40 | function toHexString(uint256 value) internal pure returns (string memory) { 41 | if (value == 0) { 42 | return "0x00"; 43 | } 44 | uint256 temp = value; 45 | uint256 length = 0; 46 | while (temp != 0) { 47 | length++; 48 | temp >>= 8; 49 | } 50 | return toHexString(value, length); 51 | } 52 | 53 | /** 54 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 55 | */ 56 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 57 | bytes memory buffer = new bytes(2 * length + 2); 58 | buffer[0] = "0"; 59 | buffer[1] = "x"; 60 | for (uint256 i = 2 * length + 1; i > 1; --i) { 61 | buffer[i] = _HEX_SYMBOLS[value & 0xf]; 62 | value >>= 4; 63 | } 64 | require(value == 0, "Strings: hex length insufficient"); 65 | return string(buffer); 66 | } 67 | } -------------------------------------------------------------------------------- /contracts/cross_lang/Test.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp >=0.8.0; 3 | 4 | import "cross_lang/Strings.sol"; 5 | 6 | contract Test { 7 | using Strings for uint256; 8 | 9 | function toString(uint256 a) external pure returns(string memory) { 10 | return a.toString(); 11 | } 12 | 13 | function toHexString(uint256 a) external pure returns(string memory) { 14 | return a.toHexString(); 15 | } 16 | } -------------------------------------------------------------------------------- /contracts/events.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | // Demonstrate events and vmlogs. 3 | 4 | pragma soliditypp >=0.8.0; 5 | 6 | contract A { 7 | event Event1(string data); 8 | event Event2(uint i, string s); 9 | event Event3(uint indexed t, uint i, string s); 10 | event Event4(uint i, uint indexed t1, string s, string indexed t2); 11 | event AnonymousEvent(uint indexed i, string data) anonymous; 12 | 13 | function test() external { 14 | emit Event1('hello world'); 15 | emit Event2(123, 'hello world'); 16 | emit Event3(1 ,123, 'hello world'); 17 | emit Event4(123 , 1, 'hello world', 'my_topic'); 18 | // emit AnonymousEvent(123, 'hello world'); 19 | } 20 | } -------------------------------------------------------------------------------- /contracts/legacy/HelloWorld.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp ^0.4.3; 3 | 4 | contract HelloWorld { 5 | uint _data = 123; 6 | 7 | onMessage set(uint a) { 8 | _data = a; 9 | } 10 | 11 | getter data() returns(uint) { 12 | return _data; 13 | } 14 | } -------------------------------------------------------------------------------- /contracts/library.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp >=0.8.0; 3 | 4 | library L { 5 | function double(uint self) public returns (uint) { 6 | // do something with side effects 7 | return 2 * self; 8 | } 9 | } 10 | 11 | contract A { 12 | using L for uint; 13 | uint public data; 14 | 15 | function f(uint a) public returns (uint) { 16 | data = a.double(); 17 | return data; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/magic.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | // Demonstrate how to visit magic variables and functions. 3 | 4 | pragma soliditypp >=0.8.0; 5 | 6 | contract Magic { 7 | uint64 public rand; 8 | 9 | function _blake2b(string memory data) external pure returns(bytes32) { 10 | return blake2b(bytes(data)); 11 | } 12 | 13 | function _keccak256(string memory data) external pure returns(bytes32) { 14 | return keccak256(bytes(data)); 15 | } 16 | 17 | // fixme: return zeros on local network 18 | function _sha256(string memory data) external pure returns(bytes32) { 19 | return sha256(bytes(data)); 20 | } 21 | 22 | // fixme: return zeros on local network 23 | function _ripemd160(bytes memory data) external pure returns(bytes20) { 24 | return ripemd160(data); 25 | } 26 | 27 | function _selector() external pure returns (bytes4) { 28 | return this._blake2b.selector; 29 | } 30 | 31 | // fixme: return zero on local network 32 | // state mutability can not be view or pure to get a random number 33 | function nextRandom() external returns (uint64) { 34 | return nextrandom(); 35 | } 36 | 37 | function balanceOfVITE() external view returns (uint256) { 38 | return balance("tti_5649544520544f4b454e6e40"); 39 | } 40 | 41 | function getPrevHash() external view returns (bytes32) { 42 | return prevhash(); 43 | } 44 | 45 | function getAccountHeight() external view returns (uint64) { 46 | return accountheight(); 47 | } 48 | } -------------------------------------------------------------------------------- /contracts/openzeppelin/access/IAccessControlEnumerable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IAccessControl.sol"; 7 | 8 | /** 9 | * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. 10 | */ 11 | interface IAccessControlEnumerable is IAccessControl { 12 | /** 13 | * @dev Returns one of the accounts that have `role`. `index` must be a 14 | * value between 0 and {getRoleMemberCount}, non-inclusive. 15 | * 16 | * Role bearers are not sorted in any particular way, and their ordering may 17 | * change at any point. 18 | * 19 | * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure 20 | * you perform all queries on the same block. See the following 21 | * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] 22 | * for more information. 23 | */ 24 | function getRoleMember(bytes32 role, uint256 index) external view returns (address); 25 | 26 | /** 27 | * @dev Returns the number of accounts that have `role`. Can be used 28 | * together with {getRoleMember} to enumerate all bearers of a role. 29 | */ 30 | function getRoleMemberCount(bytes32 role) external view returns (uint256); 31 | } 32 | -------------------------------------------------------------------------------- /contracts/openzeppelin/access/README.adoc: -------------------------------------------------------------------------------- 1 | = Access Control 2 | 3 | [.readme-notice] 4 | NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/access 5 | 6 | This directory provides ways to restrict who can access the functions of a contract or when they can do it. 7 | 8 | - {AccessControl} provides a general role based access control mechanism. Multiple hierarchical roles can be created and assigned each to multiple accounts. 9 | - {Ownable} is a simpler mechanism with a single owner "role" that can be assigned to a single account. This simpler mechanism can be useful for quick tests but projects with production concerns are likely to outgrow it. 10 | 11 | == Authorization 12 | 13 | {{Ownable}} 14 | 15 | {{IAccessControl}} 16 | 17 | {{AccessControl}} 18 | 19 | {{IAccessControlEnumerable}} 20 | 21 | {{AccessControlEnumerable}} 22 | -------------------------------------------------------------------------------- /contracts/openzeppelin/finance/README.adoc: -------------------------------------------------------------------------------- 1 | = Finance 2 | 3 | [.readme-notice] 4 | NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/finance 5 | 6 | This directory includes primitives for financial systems: 7 | 8 | - {PaymentSplitter} allows to split Ether and ERC20 payments among a group of accounts. The sender does not need to be 9 | aware that the assets will be split in this way, since it is handled transparently by the contract. The split can be 10 | in equal parts or in any other arbitrary proportion. 11 | 12 | - {VestingWallet} handles the vesting of Ether and ERC20 tokens for a given beneficiary. Custody of multiple tokens can 13 | be given to this contract, which will release the token to the beneficiary following a given, customizable, vesting 14 | schedule. 15 | 16 | == Contracts 17 | 18 | {{PaymentSplitter}} 19 | 20 | {{VestingWallet}} 21 | -------------------------------------------------------------------------------- /contracts/openzeppelin/governance/extensions/GovernorProposalThreshold.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorProposalThreshold.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../Governor.sol"; 7 | 8 | /** 9 | * @dev Extension of {Governor} for proposal restriction to token holders with a minimum balance. 10 | * 11 | * _Available since v4.3._ 12 | * _Deprecated since v4.4._ 13 | */ 14 | abstract contract GovernorProposalThreshold is Governor { 15 | function propose( 16 | address[] memory targets, 17 | uint256[] memory values, 18 | bytes[] memory calldatas, 19 | string memory description 20 | ) public virtual override returns (uint256) { 21 | return super.propose(targets, values, calldatas, description); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/openzeppelin/governance/extensions/GovernorVotes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorVotes.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../Governor.sol"; 7 | import "../utils/IVotes.sol"; 8 | 9 | /** 10 | * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token, or since v4.5 an {ERC721Votes} token. 11 | * 12 | * _Available since v4.3._ 13 | */ 14 | abstract contract GovernorVotes is Governor { 15 | IVotes public immutable token; 16 | 17 | constructor(IVotes tokenAddress) { 18 | token = tokenAddress; 19 | } 20 | 21 | /** 22 | * Read the voting weight from the token's built in snapshot mechanism (see {IGovernor-getVotes}). 23 | */ 24 | function getVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) { 25 | return token.getPastVotes(account, blockNumber); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /contracts/openzeppelin/governance/extensions/GovernorVotesComp.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorVotesComp.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../Governor.sol"; 7 | import "../../token/ERC20/extensions/ERC20VotesComp.sol"; 8 | 9 | /** 10 | * @dev Extension of {Governor} for voting weight extraction from a Comp token. 11 | * 12 | * _Available since v4.3._ 13 | */ 14 | abstract contract GovernorVotesComp is Governor { 15 | ERC20VotesComp public immutable token; 16 | 17 | constructor(ERC20VotesComp token_) { 18 | token = token_; 19 | } 20 | 21 | /** 22 | * Read the voting weight from the token's built in snapshot mechanism (see {IGovernor-getVotes}). 23 | */ 24 | function getVotes(address account, uint256 blockNumber) public view virtual override returns (uint256) { 25 | return token.getPriorVotes(account, blockNumber); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /contracts/openzeppelin/governance/extensions/GovernorVotesQuorumFraction.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (governance/extensions/GovernorVotesQuorumFraction.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./GovernorVotes.sol"; 7 | 8 | /** 9 | * @dev Extension of {Governor} for voting weight extraction from an {ERC20Votes} token and a quorum expressed as a 10 | * fraction of the total supply. 11 | * 12 | * _Available since v4.3._ 13 | */ 14 | abstract contract GovernorVotesQuorumFraction is GovernorVotes { 15 | uint256 private _quorumNumerator; 16 | 17 | event QuorumNumeratorUpdated(uint256 oldQuorumNumerator, uint256 newQuorumNumerator); 18 | 19 | constructor(uint256 quorumNumeratorValue) { 20 | _updateQuorumNumerator(quorumNumeratorValue); 21 | } 22 | 23 | function quorumNumerator() public view virtual returns (uint256) { 24 | return _quorumNumerator; 25 | } 26 | 27 | function quorumDenominator() public view virtual returns (uint256) { 28 | return 100; 29 | } 30 | 31 | function quorum(uint256 blockNumber) public view virtual override returns (uint256) { 32 | return (token.getPastTotalSupply(blockNumber) * quorumNumerator()) / quorumDenominator(); 33 | } 34 | 35 | function updateQuorumNumerator(uint256 newQuorumNumerator) external virtual onlyGovernance { 36 | _updateQuorumNumerator(newQuorumNumerator); 37 | } 38 | 39 | function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual { 40 | require( 41 | newQuorumNumerator <= quorumDenominator(), 42 | "GovernorVotesQuorumFraction: quorumNumerator over quorumDenominator" 43 | ); 44 | 45 | uint256 oldQuorumNumerator = _quorumNumerator; 46 | _quorumNumerator = newQuorumNumerator; 47 | 48 | emit QuorumNumeratorUpdated(oldQuorumNumerator, newQuorumNumerator); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /contracts/openzeppelin/governance/extensions/IGovernorTimelock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (governance/extensions/IGovernorTimelock.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../IGovernor.sol"; 7 | 8 | /** 9 | * @dev Extension of the {IGovernor} for timelock supporting modules. 10 | * 11 | * _Available since v4.3._ 12 | */ 13 | abstract contract IGovernorTimelock is IGovernor { 14 | event ProposalQueued(uint256 proposalId, uint256 eta); 15 | 16 | function timelock() public view virtual returns (address); 17 | 18 | function proposalEta(uint256 proposalId) public view virtual returns (uint256); 19 | 20 | function queue( 21 | address[] memory targets, 22 | uint256[] memory values, 23 | bytes[] memory calldatas, 24 | bytes32 descriptionHash 25 | ) public virtual returns (uint256 proposalId); 26 | } 27 | -------------------------------------------------------------------------------- /contracts/openzeppelin/governance/utils/IVotes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.0 (interfaces/IVotes.sol) 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts. 7 | * 8 | * _Available since v4.5._ 9 | */ 10 | interface IVotes { 11 | /** 12 | * @dev Emitted when an account changes their delegate. 13 | */ 14 | event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); 15 | 16 | /** 17 | * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of votes. 18 | */ 19 | event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance); 20 | 21 | /** 22 | * @dev Returns the current amount of votes that `account` has. 23 | */ 24 | function getVotes(address account) external view returns (uint256); 25 | 26 | /** 27 | * @dev Returns the amount of votes that `account` had at the end of a past block (`blockNumber`). 28 | */ 29 | function getPastVotes(address account, uint256 blockNumber) external view returns (uint256); 30 | 31 | /** 32 | * @dev Returns the total supply of votes available at the end of a past block (`blockNumber`). 33 | * 34 | * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes. 35 | * Votes that have not been delegated are still part of total supply, even though they would not participate in a 36 | * vote. 37 | */ 38 | function getPastTotalSupply(uint256 blockNumber) external view returns (uint256); 39 | 40 | /** 41 | * @dev Returns the delegate that `account` has chosen. 42 | */ 43 | function delegates(address account) external view returns (address); 44 | 45 | /** 46 | * @dev Delegates votes from the sender to `delegatee`. 47 | */ 48 | function delegate(address delegatee) external; 49 | 50 | /** 51 | * @dev Delegates votes from signer to `delegatee`. 52 | */ 53 | function delegateBySig( 54 | address delegatee, 55 | uint256 nonce, 56 | uint256 expiry, 57 | uint8 v, 58 | bytes32 r, 59 | bytes32 s 60 | ) external; 61 | } 62 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC1155.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1155.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC1155/IERC1155.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC1155MetadataURI.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1155MetadataURI.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC1155/extensions/IERC1155MetadataURI.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC1155Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1155Receiver.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC1155/IERC1155Receiver.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC1271.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC1271 standard signature validation method for 8 | * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271]. 9 | * 10 | * _Available since v4.1._ 11 | */ 12 | interface IERC1271 { 13 | /** 14 | * @dev Should return whether the signature provided is valid for the provided data 15 | * @param hash Hash of the data to be signed 16 | * @param signature Signature byte array associated with _data 17 | */ 18 | function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue); 19 | } 20 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC1363Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1363Receiver.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | interface IERC1363Receiver { 7 | /* 8 | * Note: the ERC-165 identifier for this interface is 0x88a7ca5c. 9 | * 0x88a7ca5c === bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)")) 10 | */ 11 | 12 | /** 13 | * @notice Handle the receipt of ERC1363 tokens 14 | * @dev Any ERC1363 smart contract calls this function on the recipient 15 | * after a `transfer` or a `transferFrom`. This function MAY throw to revert and reject the 16 | * transfer. Return of other than the magic value MUST result in the 17 | * transaction being reverted. 18 | * Note: the token contract address is always the message sender. 19 | * @param operator address The address which called `transferAndCall` or `transferFromAndCall` function 20 | * @param from address The address which are token transferred from 21 | * @param value uint256 The amount of tokens transferred 22 | * @param data bytes Additional data with no specified format 23 | * @return `bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))` 24 | * unless throwing 25 | */ 26 | function onTransferReceived( 27 | address operator, 28 | address from, 29 | uint256 value, 30 | bytes memory data 31 | ) external returns (bytes4); 32 | } 33 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC1363Spender.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1363Spender.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | interface IERC1363Spender { 7 | /* 8 | * Note: the ERC-165 identifier for this interface is 0x7b04a2d0. 9 | * 0x7b04a2d0 === bytes4(keccak256("onApprovalReceived(address,uint256,bytes)")) 10 | */ 11 | 12 | /** 13 | * @notice Handle the approval of ERC1363 tokens 14 | * @dev Any ERC1363 smart contract calls this function on the recipient 15 | * after an `approve`. This function MAY throw to revert and reject the 16 | * approval. Return of other than the magic value MUST result in the 17 | * transaction being reverted. 18 | * Note: the token contract address is always the message sender. 19 | * @param owner address The address which called `approveAndCall` function 20 | * @param value uint256 The amount of tokens to be spent 21 | * @param data bytes Additional data with no specified format 22 | * @return `bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))` 23 | * unless throwing 24 | */ 25 | function onApprovalReceived( 26 | address owner, 27 | uint256 value, 28 | bytes memory data 29 | ) external returns (bytes4); 30 | } 31 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../utils/introspection/IERC165.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC1820Implementer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1820Implementer.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../utils/introspection/IERC1820Implementer.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC1820Registry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1820Registry.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../utils/introspection/IERC1820Registry.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC20/IERC20.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC20Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20Metadata.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC20/extensions/IERC20Metadata.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC2981.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC2981.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IERC165.sol"; 7 | 8 | /** 9 | * @dev Interface for the NFT Royalty Standard 10 | */ 11 | interface IERC2981 is IERC165 { 12 | /** 13 | * @dev Called with the sale price to determine how much royalty is owed and to whom. 14 | * @param tokenId - the NFT asset queried for royalty information 15 | * @param salePrice - the sale price of the NFT asset specified by `tokenId` 16 | * @return receiver - address of who should be sent the royalty payment 17 | * @return royaltyAmount - the royalty payment amount for `salePrice` 18 | */ 19 | function royaltyInfo(uint256 tokenId, uint256 salePrice) 20 | external 21 | view 22 | returns (address receiver, uint256 royaltyAmount); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC3156.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC3156.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IERC3156FlashBorrower.sol"; 7 | import "./IERC3156FlashLender.sol"; 8 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC3156FlashBorrower.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC3156FlashBorrower.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC3156 FlashBorrower, as defined in 8 | * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156]. 9 | * 10 | * _Available since v4.1._ 11 | */ 12 | interface IERC3156FlashBorrower { 13 | /** 14 | * @dev Receive a flash loan. 15 | * @param initiator The initiator of the loan. 16 | * @param token The loan currency. 17 | * @param amount The amount of tokens lent. 18 | * @param fee The additional amount of tokens to repay. 19 | * @param data Arbitrary data structure, intended to contain user-defined parameters. 20 | * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan" 21 | */ 22 | function onFlashLoan( 23 | address initiator, 24 | address token, 25 | uint256 amount, 26 | uint256 fee, 27 | bytes calldata data 28 | ) external returns (bytes32); 29 | } 30 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC3156FlashLender.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC3156FlashLender.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IERC3156FlashBorrower.sol"; 7 | 8 | /** 9 | * @dev Interface of the ERC3156 FlashLender, as defined in 10 | * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156]. 11 | * 12 | * _Available since v4.1._ 13 | */ 14 | interface IERC3156FlashLender { 15 | /** 16 | * @dev The amount of currency available to be lended. 17 | * @param token The loan currency. 18 | * @return The amount of `token` that can be borrowed. 19 | */ 20 | function maxFlashLoan(address token) external view returns (uint256); 21 | 22 | /** 23 | * @dev The fee to be charged for a given loan. 24 | * @param token The loan currency. 25 | * @param amount The amount of tokens lent. 26 | * @return The amount of `token` to be charged for the loan, on top of the returned principal. 27 | */ 28 | function flashFee(address token, uint256 amount) external view returns (uint256); 29 | 30 | /** 31 | * @dev Initiate a flash loan. 32 | * @param receiver The receiver of the tokens in the loan, and the receiver of the callback. 33 | * @param token The loan currency. 34 | * @param amount The amount of tokens lent. 35 | * @param data Arbitrary data structure, intended to contain user-defined parameters. 36 | */ 37 | function flashLoan( 38 | IERC3156FlashBorrower receiver, 39 | address token, 40 | uint256 amount, 41 | bytes calldata data 42 | ) external returns (bool); 43 | } 44 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC721.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC721/IERC721.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC721Enumerable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC721/extensions/IERC721Enumerable.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC721Metadata.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC721/extensions/IERC721Metadata.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC721Receiver.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC721/IERC721Receiver.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC777.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC777.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC777/IERC777.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC777Recipient.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC777Recipient.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC777/IERC777Recipient.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/IERC777Sender.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/IERC777Sender.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC777/IERC777Sender.sol"; 7 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/README.adoc: -------------------------------------------------------------------------------- 1 | = Interfaces 2 | 3 | [.readme-notice] 4 | NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/interfaces 5 | 6 | == List of standardized interfaces 7 | These interfaces are available as `.sol` files, and also as compiler `.json` ABI files (through the npm package). These 8 | are usefull to interract with third party contracts that implement them. 9 | 10 | - {IERC20} 11 | - {IERC20Metadata} 12 | - {IERC165} 13 | - {IERC721} 14 | - {IERC721Receiver} 15 | - {IERC721Enumerable} 16 | - {IERC721Metadata} 17 | - {IERC777} 18 | - {IERC777Recipient} 19 | - {IERC777Sender} 20 | - {IERC1155} 21 | - {IERC1155Receiver} 22 | - {IERC1155MetadataURI} 23 | - {IERC1271} 24 | - {IERC1363} 25 | - {IERC1820Implementer} 26 | - {IERC1820Registry} 27 | - {IERC2612} 28 | - {IERC2981} 29 | - {IERC3156FlashLender} 30 | - {IERC3156FlashBorrower} 31 | 32 | == Detailed ABI 33 | 34 | {{IERC1271}} 35 | 36 | {{IERC1363}} 37 | 38 | {{IERC1363Receiver}} 39 | 40 | {{IERC1820Implementer}} 41 | 42 | {{IERC1820Registry}} 43 | 44 | {{IERC2612}} 45 | 46 | {{IERC2981}} 47 | 48 | {{IERC3156FlashLender}} 49 | 50 | {{IERC3156FlashBorrower}} 51 | -------------------------------------------------------------------------------- /contracts/openzeppelin/interfaces/draft-IERC2612.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (interfaces/draft-IERC2612.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../token/ERC20/extensions/draft-IERC20Permit.sol"; 7 | 8 | interface IERC2612 is IERC20Permit {} 9 | -------------------------------------------------------------------------------- /contracts/openzeppelin/metatx/ERC2771Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (metatx/ERC2771Context.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../utils/Context.sol"; 7 | 8 | /** 9 | * @dev Context variant with ERC2771 support. 10 | */ 11 | abstract contract ERC2771Context is Context { 12 | address private _trustedForwarder; 13 | 14 | constructor(address trustedForwarder) { 15 | _trustedForwarder = trustedForwarder; 16 | } 17 | 18 | function isTrustedForwarder(address forwarder) public view virtual returns (bool) { 19 | return forwarder == _trustedForwarder; 20 | } 21 | 22 | function _msgSender() internal view virtual override returns (address sender) { 23 | if (isTrustedForwarder(msg.sender)) { 24 | // The assembly code is more direct than the Solidity version using `abi.decode`. 25 | assembly { 26 | sender := shr(96, calldataload(sub(calldatasize(), 20))) 27 | } 28 | } else { 29 | return super._msgSender(); 30 | } 31 | } 32 | 33 | function _msgData() internal view virtual override returns (bytes calldata) { 34 | if (isTrustedForwarder(msg.sender)) { 35 | return msg.data[:msg.data.length - 20]; 36 | } else { 37 | return super._msgData(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/openzeppelin/metatx/MinimalForwarder.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (metatx/MinimalForwarder.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../utils/cryptography/ECDSA.sol"; 7 | import "../utils/cryptography/draft-EIP712.sol"; 8 | 9 | /** 10 | * @dev Simple minimal forwarder to be used together with an ERC2771 compatible contract. See {ERC2771Context}. 11 | */ 12 | contract MinimalForwarder is EIP712 { 13 | using ECDSA for bytes32; 14 | 15 | struct ForwardRequest { 16 | address from; 17 | address to; 18 | uint256 value; 19 | uint256 gas; 20 | uint256 nonce; 21 | bytes data; 22 | } 23 | 24 | bytes32 private constant _TYPEHASH = 25 | keccak256("ForwardRequest(address from,address to,uint256 value,uint256 gas,uint256 nonce,bytes data)"); 26 | 27 | mapping(address => uint256) private _nonces; 28 | 29 | constructor() EIP712("MinimalForwarder", "0.0.1") {} 30 | 31 | function getNonce(address from) public view returns (uint256) { 32 | return _nonces[from]; 33 | } 34 | 35 | function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) { 36 | address signer = _hashTypedDataV4( 37 | keccak256(abi.encode(_TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data))) 38 | ).recover(signature); 39 | return _nonces[req.from] == req.nonce && signer == req.from; 40 | } 41 | 42 | function execute(ForwardRequest calldata req, bytes calldata signature) 43 | public 44 | payable 45 | returns (bool, bytes memory) 46 | { 47 | require(verify(req, signature), "MinimalForwarder: signature does not match request"); 48 | _nonces[req.from] = req.nonce + 1; 49 | 50 | (bool success, bytes memory returndata) = req.to.call{gas: req.gas, value: req.value}( 51 | abi.encodePacked(req.data, req.from) 52 | ); 53 | // Validate that the relayer has sent enough gas for the call. 54 | // See https://ronan.eth.link/blog/ethereum-gas-dangers/ 55 | assert(gasleft() > req.gas / 63); 56 | 57 | return (success, returndata); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /contracts/openzeppelin/metatx/README.adoc: -------------------------------------------------------------------------------- 1 | = Meta Transactions 2 | 3 | [.readme-notice] 4 | NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/metatx 5 | 6 | == Core 7 | 8 | {{ERC2771Context}} 9 | 10 | == Utils 11 | 12 | {{MinimalForwarder}} 13 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/AccessControlEnumerableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../access/AccessControlEnumerable.sol"; 6 | 7 | contract AccessControlEnumerableMock is AccessControlEnumerable { 8 | constructor() { 9 | _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); 10 | } 11 | 12 | function setRoleAdmin(bytes32 roleId, bytes32 adminRoleId) public { 13 | _setRoleAdmin(roleId, adminRoleId); 14 | } 15 | 16 | function senderProtected(bytes32 roleId) public onlyRole(roleId) {} 17 | } 18 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/AccessControlMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../access/AccessControl.sol"; 6 | 7 | contract AccessControlMock is AccessControl { 8 | constructor() { 9 | _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); 10 | } 11 | 12 | function setRoleAdmin(bytes32 roleId, bytes32 adminRoleId) public { 13 | _setRoleAdmin(roleId, adminRoleId); 14 | } 15 | 16 | function senderProtected(bytes32 roleId) public onlyRole(roleId) {} 17 | } 18 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/AddressImpl.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Address.sol"; 6 | 7 | contract AddressImpl { 8 | string public sharedAnswer; 9 | 10 | event CallReturnValue(string data); 11 | 12 | function isContract(address account) external view returns (bool) { 13 | return Address.isContract(account); 14 | } 15 | 16 | function sendValue(address payable receiver, uint256 amount) external { 17 | Address.sendValue(receiver, amount); 18 | } 19 | 20 | function functionCall(address target, bytes calldata data) external { 21 | bytes memory returnData = Address.functionCall(target, data); 22 | emit CallReturnValue(abi.decode(returnData, (string))); 23 | } 24 | 25 | function functionCallWithValue( 26 | address target, 27 | bytes calldata data, 28 | uint256 value 29 | ) external payable { 30 | bytes memory returnData = Address.functionCallWithValue(target, data, value); 31 | emit CallReturnValue(abi.decode(returnData, (string))); 32 | } 33 | 34 | function functionStaticCall(address target, bytes calldata data) external { 35 | bytes memory returnData = Address.functionStaticCall(target, data); 36 | emit CallReturnValue(abi.decode(returnData, (string))); 37 | } 38 | 39 | function functionDelegateCall(address target, bytes calldata data) external { 40 | bytes memory returnData = Address.functionDelegateCall(target, data); 41 | emit CallReturnValue(abi.decode(returnData, (string))); 42 | } 43 | 44 | // sendValue's tests require the contract to hold Ether 45 | receive() external payable {} 46 | } 47 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ArraysImpl.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Arrays.sol"; 6 | 7 | contract ArraysImpl { 8 | using Arrays for uint256[]; 9 | 10 | uint256[] private _array; 11 | 12 | constructor(uint256[] memory array) { 13 | _array = array; 14 | } 15 | 16 | function findUpperBound(uint256 element) external view returns (uint256) { 17 | return _array.findUpperBound(element); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/BadBeacon.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | contract BadBeaconNoImpl {} 6 | 7 | contract BadBeaconNotContract { 8 | function implementation() external pure returns (address) { 9 | return address(0x1); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/BitmapMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/structs/BitMaps.sol"; 6 | 7 | contract BitMapMock { 8 | using BitMaps for BitMaps.BitMap; 9 | 10 | BitMaps.BitMap private _bitmap; 11 | 12 | function get(uint256 index) public view returns (bool) { 13 | return _bitmap.get(index); 14 | } 15 | 16 | function setTo(uint256 index, bool value) public { 17 | _bitmap.setTo(index, value); 18 | } 19 | 20 | function set(uint256 index) public { 21 | _bitmap.set(index); 22 | } 23 | 24 | function unset(uint256 index) public { 25 | _bitmap.unset(index); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/CallReceiverMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | contract CallReceiverMock { 6 | string public sharedAnswer; 7 | 8 | event MockFunctionCalled(); 9 | 10 | uint256[] private _array; 11 | 12 | function mockFunction() public payable returns (string memory) { 13 | emit MockFunctionCalled(); 14 | 15 | return "0x1234"; 16 | } 17 | 18 | function mockFunctionNonPayable() public returns (string memory) { 19 | emit MockFunctionCalled(); 20 | 21 | return "0x1234"; 22 | } 23 | 24 | function mockStaticFunction() public pure returns (string memory) { 25 | return "0x1234"; 26 | } 27 | 28 | function mockFunctionRevertsNoReason() public payable { 29 | revert(); 30 | } 31 | 32 | function mockFunctionRevertsReason() public payable { 33 | revert("CallReceiverMock: reverting"); 34 | } 35 | 36 | function mockFunctionThrows() public payable { 37 | assert(false); 38 | } 39 | 40 | function mockFunctionOutOfGas() public payable { 41 | for (uint256 i = 0; ; ++i) { 42 | _array.push(i); 43 | } 44 | } 45 | 46 | function mockFunctionWritesStorage() public returns (string memory) { 47 | sharedAnswer = "42"; 48 | return "0x1234"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/CheckpointsImpl.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Checkpoints.sol"; 6 | 7 | contract CheckpointsImpl { 8 | using Checkpoints for Checkpoints.History; 9 | 10 | Checkpoints.History private _totalCheckpoints; 11 | 12 | function latest() public view returns (uint256) { 13 | return _totalCheckpoints.latest(); 14 | } 15 | 16 | function getAtBlock(uint256 blockNumber) public view returns (uint256) { 17 | return _totalCheckpoints.getAtBlock(blockNumber); 18 | } 19 | 20 | function push(uint256 value) public returns (uint256, uint256) { 21 | return _totalCheckpoints.push(value); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ClashingImplementation.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Implementation contract with an admin() function made to clash with 7 | * @dev TransparentUpgradeableProxy's to test correct functioning of the 8 | * @dev Transparent Proxy feature. 9 | */ 10 | contract ClashingImplementation { 11 | function admin() external pure returns (address) { 12 | return 0x0000000000000000000000000000000011111142; 13 | } 14 | 15 | function delegatedFunction() external pure returns (bool) { 16 | return true; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ClonesMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../proxy/Clones.sol"; 6 | import "../utils/Address.sol"; 7 | 8 | contract ClonesMock { 9 | using Address for address; 10 | using Clones for address; 11 | 12 | event NewInstance(address instance); 13 | 14 | function clone(address implementation, bytes calldata initdata) public payable { 15 | _initAndEmit(implementation.clone(), initdata); 16 | } 17 | 18 | function cloneDeterministic( 19 | address implementation, 20 | bytes32 salt, 21 | bytes calldata initdata 22 | ) public payable { 23 | _initAndEmit(implementation.cloneDeterministic(salt), initdata); 24 | } 25 | 26 | function predictDeterministicAddress(address implementation, bytes32 salt) public view returns (address predicted) { 27 | return implementation.predictDeterministicAddress(salt); 28 | } 29 | 30 | function _initAndEmit(address instance, bytes memory initdata) private { 31 | if (initdata.length > 0) { 32 | instance.functionCallWithValue(initdata, msg.value); 33 | } 34 | emit NewInstance(instance); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ConditionalEscrowMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/escrow/ConditionalEscrow.sol"; 6 | 7 | // mock class using ConditionalEscrow 8 | contract ConditionalEscrowMock is ConditionalEscrow { 9 | mapping(address => bool) private _allowed; 10 | 11 | function setAllowed(address payee, bool allowed) public { 12 | _allowed[payee] = allowed; 13 | } 14 | 15 | function withdrawalAllowed(address payee) public view override returns (bool) { 16 | return _allowed[payee]; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ContextMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Context.sol"; 6 | 7 | contract ContextMock is Context { 8 | event Sender(address sender); 9 | 10 | function msgSender() public { 11 | emit Sender(_msgSender()); 12 | } 13 | 14 | event Data(bytes data, uint256 integerValue, string stringValue); 15 | 16 | function msgData(uint256 integerValue, string memory stringValue) public { 17 | emit Data(_msgData(), integerValue, stringValue); 18 | } 19 | } 20 | 21 | contract ContextMockCaller { 22 | function callSender(ContextMock context) public { 23 | context.msgSender(); 24 | } 25 | 26 | function callData( 27 | ContextMock context, 28 | uint256 integerValue, 29 | string memory stringValue 30 | ) public { 31 | context.msgData(integerValue, stringValue); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/CountersImpl.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Counters.sol"; 6 | 7 | contract CountersImpl { 8 | using Counters for Counters.Counter; 9 | 10 | Counters.Counter private _counter; 11 | 12 | function current() public view returns (uint256) { 13 | return _counter.current(); 14 | } 15 | 16 | function increment() public { 17 | _counter.increment(); 18 | } 19 | 20 | function decrement() public { 21 | _counter.decrement(); 22 | } 23 | 24 | function reset() public { 25 | _counter.reset(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/Create2Impl.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Create2.sol"; 6 | import "../utils/introspection/ERC1820Implementer.sol"; 7 | 8 | contract Create2Impl { 9 | function deploy( 10 | uint256 value, 11 | bytes32 salt, 12 | bytes memory code 13 | ) public { 14 | Create2.deploy(value, salt, code); 15 | } 16 | 17 | function deployERC1820Implementer(uint256 value, bytes32 salt) public { 18 | Create2.deploy(value, salt, type(ERC1820Implementer).creationCode); 19 | } 20 | 21 | function computeAddress(bytes32 salt, bytes32 codeHash) public view returns (address) { 22 | return Create2.computeAddress(salt, codeHash); 23 | } 24 | 25 | function computeAddressWithDeployer( 26 | bytes32 salt, 27 | bytes32 codeHash, 28 | address deployer 29 | ) public pure returns (address) { 30 | return Create2.computeAddress(salt, codeHash, deployer); 31 | } 32 | 33 | receive() external payable {} 34 | } 35 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/DummyImplementation.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | abstract contract Impl { 6 | function version() public pure virtual returns (string memory); 7 | } 8 | 9 | contract DummyImplementation { 10 | uint256 public value; 11 | string public text; 12 | uint256[] public values; 13 | 14 | function initializeNonPayable() public { 15 | value = 10; 16 | } 17 | 18 | function initializePayable() public payable { 19 | value = 100; 20 | } 21 | 22 | function initializeNonPayableWithValue(uint256 _value) public { 23 | value = _value; 24 | } 25 | 26 | function initializePayableWithValue(uint256 _value) public payable { 27 | value = _value; 28 | } 29 | 30 | function initialize( 31 | uint256 _value, 32 | string memory _text, 33 | uint256[] memory _values 34 | ) public { 35 | value = _value; 36 | text = _text; 37 | values = _values; 38 | } 39 | 40 | function get() public pure returns (bool) { 41 | return true; 42 | } 43 | 44 | function version() public pure virtual returns (string memory) { 45 | return "V1"; 46 | } 47 | 48 | function reverts() public pure { 49 | require(false, "DummyImplementation reverted"); 50 | } 51 | } 52 | 53 | contract DummyImplementationV2 is DummyImplementation { 54 | function migrate(uint256 newVal) public payable { 55 | value = newVal; 56 | } 57 | 58 | function version() public pure override returns (string memory) { 59 | return "V2"; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ECDSAMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/cryptography/ECDSA.sol"; 6 | 7 | contract ECDSAMock { 8 | using ECDSA for bytes32; 9 | using ECDSA for bytes; 10 | 11 | function recover(bytes32 hash, bytes memory signature) public pure returns (address) { 12 | return hash.recover(signature); 13 | } 14 | 15 | // solhint-disable-next-line func-name-mixedcase 16 | function recover_v_r_s( 17 | bytes32 hash, 18 | uint8 v, 19 | bytes32 r, 20 | bytes32 s 21 | ) public pure returns (address) { 22 | return hash.recover(v, r, s); 23 | } 24 | 25 | // solhint-disable-next-line func-name-mixedcase 26 | function recover_r_vs( 27 | bytes32 hash, 28 | bytes32 r, 29 | bytes32 vs 30 | ) public pure returns (address) { 31 | return hash.recover(r, vs); 32 | } 33 | 34 | function toEthSignedMessageHash(bytes32 hash) public pure returns (bytes32) { 35 | return hash.toEthSignedMessageHash(); 36 | } 37 | 38 | function toEthSignedMessageHash(bytes memory s) public pure returns (bytes32) { 39 | return s.toEthSignedMessageHash(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/EIP712External.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/cryptography/draft-EIP712.sol"; 6 | import "../utils/cryptography/ECDSA.sol"; 7 | 8 | contract EIP712External is EIP712 { 9 | constructor(string memory name, string memory version) EIP712(name, version) {} 10 | 11 | function domainSeparator() external view returns (bytes32) { 12 | return _domainSeparatorV4(); 13 | } 14 | 15 | function verify( 16 | bytes memory signature, 17 | address signer, 18 | address mailTo, 19 | string memory mailContents 20 | ) external view { 21 | bytes32 digest = _hashTypedDataV4( 22 | keccak256(abi.encode(keccak256("Mail(address to,string contents)"), mailTo, keccak256(bytes(mailContents)))) 23 | ); 24 | address recoveredSigner = ECDSA.recover(digest, signature); 25 | require(recoveredSigner == signer); 26 | } 27 | 28 | function getChainId() external view returns (uint256) { 29 | return block.chainid; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC1155BurnableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC1155/extensions/ERC1155Burnable.sol"; 6 | 7 | contract ERC1155BurnableMock is ERC1155Burnable { 8 | constructor(string memory uri) ERC1155(uri) {} 9 | 10 | function mint( 11 | address to, 12 | uint256 id, 13 | uint256 value, 14 | bytes memory data 15 | ) public { 16 | _mint(to, id, value, data); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC1155Mock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC1155/ERC1155.sol"; 6 | 7 | /** 8 | * @title ERC1155Mock 9 | * This mock just publicizes internal functions for testing purposes 10 | */ 11 | contract ERC1155Mock is ERC1155 { 12 | constructor(string memory uri) ERC1155(uri) {} 13 | 14 | function setURI(string memory newuri) public { 15 | _setURI(newuri); 16 | } 17 | 18 | function mint( 19 | address to, 20 | uint256 id, 21 | uint256 value, 22 | bytes memory data 23 | ) public { 24 | _mint(to, id, value, data); 25 | } 26 | 27 | function mintBatch( 28 | address to, 29 | uint256[] memory ids, 30 | uint256[] memory values, 31 | bytes memory data 32 | ) public { 33 | _mintBatch(to, ids, values, data); 34 | } 35 | 36 | function burn( 37 | address owner, 38 | uint256 id, 39 | uint256 value 40 | ) public { 41 | _burn(owner, id, value); 42 | } 43 | 44 | function burnBatch( 45 | address owner, 46 | uint256[] memory ids, 47 | uint256[] memory values 48 | ) public { 49 | _burnBatch(owner, ids, values); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC1155PausableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./ERC1155Mock.sol"; 6 | import "../token/ERC1155/extensions/ERC1155Pausable.sol"; 7 | 8 | contract ERC1155PausableMock is ERC1155Mock, ERC1155Pausable { 9 | constructor(string memory uri) ERC1155Mock(uri) {} 10 | 11 | function pause() external { 12 | _pause(); 13 | } 14 | 15 | function unpause() external { 16 | _unpause(); 17 | } 18 | 19 | function _beforeTokenTransfer( 20 | address operator, 21 | address from, 22 | address to, 23 | uint256[] memory ids, 24 | uint256[] memory amounts, 25 | bytes memory data 26 | ) internal virtual override(ERC1155, ERC1155Pausable) { 27 | super._beforeTokenTransfer(operator, from, to, ids, amounts, data); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC1155ReceiverMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC1155/IERC1155Receiver.sol"; 6 | import "../utils/introspection/ERC165.sol"; 7 | 8 | contract ERC1155ReceiverMock is ERC165, IERC1155Receiver { 9 | bytes4 private _recRetval; 10 | bool private _recReverts; 11 | bytes4 private _batRetval; 12 | bool private _batReverts; 13 | 14 | event Received(address operator, address from, uint256 id, uint256 value, bytes data, uint256 gas); 15 | event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data, uint256 gas); 16 | 17 | constructor( 18 | bytes4 recRetval, 19 | bool recReverts, 20 | bytes4 batRetval, 21 | bool batReverts 22 | ) { 23 | _recRetval = recRetval; 24 | _recReverts = recReverts; 25 | _batRetval = batRetval; 26 | _batReverts = batReverts; 27 | } 28 | 29 | function onERC1155Received( 30 | address operator, 31 | address from, 32 | uint256 id, 33 | uint256 value, 34 | bytes calldata data 35 | ) external override returns (bytes4) { 36 | require(!_recReverts, "ERC1155ReceiverMock: reverting on receive"); 37 | emit Received(operator, from, id, value, data, gasleft()); 38 | return _recRetval; 39 | } 40 | 41 | function onERC1155BatchReceived( 42 | address operator, 43 | address from, 44 | uint256[] calldata ids, 45 | uint256[] calldata values, 46 | bytes calldata data 47 | ) external override returns (bytes4) { 48 | require(!_batReverts, "ERC1155ReceiverMock: reverting on batch receive"); 49 | emit BatchReceived(operator, from, ids, values, data, gasleft()); 50 | return _batRetval; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC1155SupplyMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./ERC1155Mock.sol"; 6 | import "../token/ERC1155/extensions/ERC1155Supply.sol"; 7 | 8 | contract ERC1155SupplyMock is ERC1155Mock, ERC1155Supply { 9 | constructor(string memory uri) ERC1155Mock(uri) {} 10 | 11 | function _beforeTokenTransfer( 12 | address operator, 13 | address from, 14 | address to, 15 | uint256[] memory ids, 16 | uint256[] memory amounts, 17 | bytes memory data 18 | ) internal virtual override(ERC1155, ERC1155Supply) { 19 | super._beforeTokenTransfer(operator, from, to, ids, amounts, data); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC1271WalletMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../access/Ownable.sol"; 6 | import "../interfaces/IERC1271.sol"; 7 | import "../utils/cryptography/ECDSA.sol"; 8 | 9 | contract ERC1271WalletMock is Ownable, IERC1271 { 10 | constructor(address originalOwner) { 11 | transferOwnership(originalOwner); 12 | } 13 | 14 | function isValidSignature(bytes32 hash, bytes memory signature) public view override returns (bytes4 magicValue) { 15 | return ECDSA.recover(hash, signature) == owner() ? this.isValidSignature.selector : bytes4(0); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC165/ERC165InterfacesSupported.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../../utils/introspection/IERC165.sol"; 6 | 7 | /** 8 | * https://eips.ethereum.org/EIPS/eip-214#specification 9 | * From the specification: 10 | * > Any attempts to make state-changing operations inside an execution instance with STATIC set to true will instead 11 | * throw an exception. 12 | * > These operations include [...], LOG0, LOG1, LOG2, [...] 13 | * 14 | * therefore, because this contract is staticcall'd we need to not emit events (which is how solidity-coverage works) 15 | * solidity-coverage ignores the /mocks folder, so we duplicate its implementation here to avoid instrumenting it 16 | */ 17 | contract SupportsInterfaceWithLookupMock is IERC165 { 18 | /* 19 | * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7 20 | */ 21 | bytes4 public constant INTERFACE_ID_ERC165 = 0x01ffc9a7; 22 | 23 | /** 24 | * @dev A mapping of interface id to whether or not it's supported. 25 | */ 26 | mapping(bytes4 => bool) private _supportedInterfaces; 27 | 28 | /** 29 | * @dev A contract implementing SupportsInterfaceWithLookup 30 | * implement ERC165 itself. 31 | */ 32 | constructor() { 33 | _registerInterface(INTERFACE_ID_ERC165); 34 | } 35 | 36 | /** 37 | * @dev Implement supportsInterface(bytes4) using a lookup table. 38 | */ 39 | function supportsInterface(bytes4 interfaceId) public view override returns (bool) { 40 | return _supportedInterfaces[interfaceId]; 41 | } 42 | 43 | /** 44 | * @dev Private method for registering an interface. 45 | */ 46 | function _registerInterface(bytes4 interfaceId) internal { 47 | require(interfaceId != 0xffffffff, "ERC165InterfacesSupported: invalid interface id"); 48 | _supportedInterfaces[interfaceId] = true; 49 | } 50 | } 51 | 52 | contract ERC165InterfacesSupported is SupportsInterfaceWithLookupMock { 53 | constructor(bytes4[] memory interfaceIds) { 54 | for (uint256 i = 0; i < interfaceIds.length; i++) { 55 | _registerInterface(interfaceIds[i]); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC165/ERC165MissingData.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | contract ERC165MissingData { 6 | function supportsInterface(bytes4 interfaceId) public view {} // missing return 7 | } 8 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC165/ERC165NotSupported.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | contract ERC165NotSupported {} 6 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC165CheckerMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/introspection/ERC165Checker.sol"; 6 | 7 | contract ERC165CheckerMock { 8 | using ERC165Checker for address; 9 | 10 | function supportsERC165(address account) public view returns (bool) { 11 | return account.supportsERC165(); 12 | } 13 | 14 | function supportsInterface(address account, bytes4 interfaceId) public view returns (bool) { 15 | return account.supportsInterface(interfaceId); 16 | } 17 | 18 | function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) public view returns (bool) { 19 | return account.supportsAllInterfaces(interfaceIds); 20 | } 21 | 22 | function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) public view returns (bool[] memory) { 23 | return account.getSupportedInterfaces(interfaceIds); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC165Mock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/introspection/ERC165.sol"; 6 | 7 | contract ERC165Mock is ERC165 {} 8 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC165StorageMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/introspection/ERC165Storage.sol"; 6 | 7 | contract ERC165StorageMock is ERC165Storage { 8 | function registerInterface(bytes4 interfaceId) public { 9 | _registerInterface(interfaceId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC1820ImplementerMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/introspection/ERC1820Implementer.sol"; 6 | 7 | contract ERC1820ImplementerMock is ERC1820Implementer { 8 | function registerInterfaceForAddress(bytes32 interfaceHash, address account) public { 9 | _registerInterfaceForAddress(interfaceHash, account); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20BurnableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/ERC20Burnable.sol"; 6 | 7 | contract ERC20BurnableMock is ERC20Burnable { 8 | constructor( 9 | string memory name, 10 | string memory symbol, 11 | address initialAccount, 12 | uint256 initialBalance 13 | ) ERC20(name, symbol) { 14 | _mint(initialAccount, initialBalance); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20CappedMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/ERC20Capped.sol"; 6 | 7 | contract ERC20CappedMock is ERC20Capped { 8 | constructor( 9 | string memory name, 10 | string memory symbol, 11 | uint256 cap 12 | ) ERC20(name, symbol) ERC20Capped(cap) {} 13 | 14 | function mint(address to, uint256 tokenId) public { 15 | _mint(to, tokenId); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20DecimalsMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/ERC20.sol"; 6 | 7 | contract ERC20DecimalsMock is ERC20 { 8 | uint8 private immutable _decimals; 9 | 10 | constructor( 11 | string memory name_, 12 | string memory symbol_, 13 | uint8 decimals_ 14 | ) ERC20(name_, symbol_) { 15 | _decimals = decimals_; 16 | } 17 | 18 | function decimals() public view virtual override returns (uint8) { 19 | return _decimals; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20FlashMintMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/ERC20FlashMint.sol"; 6 | 7 | contract ERC20FlashMintMock is ERC20FlashMint { 8 | constructor( 9 | string memory name, 10 | string memory symbol, 11 | address initialAccount, 12 | uint256 initialBalance 13 | ) ERC20(name, symbol) { 14 | _mint(initialAccount, initialBalance); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20Mock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/ERC20.sol"; 6 | 7 | // mock class using ERC20 8 | contract ERC20Mock is ERC20 { 9 | constructor( 10 | string memory name, 11 | string memory symbol, 12 | address initialAccount, 13 | uint256 initialBalance 14 | ) payable ERC20(name, symbol) { 15 | _mint(initialAccount, initialBalance); 16 | } 17 | 18 | function mint(address account, uint256 amount) public { 19 | _mint(account, amount); 20 | } 21 | 22 | function burn(address account, uint256 amount) public { 23 | _burn(account, amount); 24 | } 25 | 26 | function transferInternal( 27 | address from, 28 | address to, 29 | uint256 value 30 | ) public { 31 | _transfer(from, to, value); 32 | } 33 | 34 | function approveInternal( 35 | address owner, 36 | address spender, 37 | uint256 value 38 | ) public { 39 | _approve(owner, spender, value); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20PausableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/ERC20Pausable.sol"; 6 | 7 | // mock class using ERC20Pausable 8 | contract ERC20PausableMock is ERC20Pausable { 9 | constructor( 10 | string memory name, 11 | string memory symbol, 12 | address initialAccount, 13 | uint256 initialBalance 14 | ) ERC20(name, symbol) { 15 | _mint(initialAccount, initialBalance); 16 | } 17 | 18 | function pause() external { 19 | _pause(); 20 | } 21 | 22 | function unpause() external { 23 | _unpause(); 24 | } 25 | 26 | function mint(address to, uint256 amount) public { 27 | _mint(to, amount); 28 | } 29 | 30 | function burn(address from, uint256 amount) public { 31 | _burn(from, amount); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20PermitMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/draft-ERC20Permit.sol"; 6 | 7 | contract ERC20PermitMock is ERC20Permit { 8 | constructor( 9 | string memory name, 10 | string memory symbol, 11 | address initialAccount, 12 | uint256 initialBalance 13 | ) payable ERC20(name, symbol) ERC20Permit(name) { 14 | _mint(initialAccount, initialBalance); 15 | } 16 | 17 | function getChainId() external view returns (uint256) { 18 | return block.chainid; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20SnapshotMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/ERC20Snapshot.sol"; 6 | 7 | contract ERC20SnapshotMock is ERC20Snapshot { 8 | constructor( 9 | string memory name, 10 | string memory symbol, 11 | address initialAccount, 12 | uint256 initialBalance 13 | ) ERC20(name, symbol) { 14 | _mint(initialAccount, initialBalance); 15 | } 16 | 17 | function snapshot() public { 18 | _snapshot(); 19 | } 20 | 21 | function mint(address account, uint256 amount) public { 22 | _mint(account, amount); 23 | } 24 | 25 | function burn(address account, uint256 amount) public { 26 | _burn(account, amount); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20VotesCompMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/ERC20VotesComp.sol"; 6 | 7 | contract ERC20VotesCompMock is ERC20VotesComp { 8 | constructor(string memory name, string memory symbol) ERC20(name, symbol) ERC20Permit(name) {} 9 | 10 | function mint(address account, uint256 amount) public { 11 | _mint(account, amount); 12 | } 13 | 14 | function burn(address account, uint256 amount) public { 15 | _burn(account, amount); 16 | } 17 | 18 | function getChainId() external view returns (uint256) { 19 | return block.chainid; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20VotesMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/ERC20Votes.sol"; 6 | 7 | contract ERC20VotesMock is ERC20Votes { 8 | constructor(string memory name, string memory symbol) ERC20(name, symbol) ERC20Permit(name) {} 9 | 10 | function mint(address account, uint256 amount) public { 11 | _mint(account, amount); 12 | } 13 | 14 | function burn(address account, uint256 amount) public { 15 | _burn(account, amount); 16 | } 17 | 18 | function getChainId() external view returns (uint256) { 19 | return block.chainid; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC20WrapperMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/extensions/ERC20Wrapper.sol"; 6 | 7 | contract ERC20WrapperMock is ERC20Wrapper { 8 | constructor( 9 | IERC20 _underlyingToken, 10 | string memory name, 11 | string memory symbol 12 | ) ERC20(name, symbol) ERC20Wrapper(_underlyingToken) {} 13 | 14 | function recover(address account) public returns (uint256) { 15 | return _recover(account); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC2771ContextMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./ContextMock.sol"; 6 | import "../metatx/ERC2771Context.sol"; 7 | 8 | // By inheriting from ERC2771Context, Context's internal functions are overridden automatically 9 | contract ERC2771ContextMock is ContextMock, ERC2771Context { 10 | constructor(address trustedForwarder) ERC2771Context(trustedForwarder) {} 11 | 12 | function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address) { 13 | return ERC2771Context._msgSender(); 14 | } 15 | 16 | function _msgData() internal view virtual override(Context, ERC2771Context) returns (bytes calldata) { 17 | return ERC2771Context._msgData(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC3156FlashBorrowerMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC20/IERC20.sol"; 6 | import "../interfaces/IERC3156.sol"; 7 | import "../utils/Address.sol"; 8 | 9 | /** 10 | * @dev WARNING: this IERC3156FlashBorrower mock implementation is for testing purposes ONLY. 11 | * Writing a secure flash lock borrower is not an easy task, and should be done with the utmost care. 12 | * This is not an example of how it should be done, and no pattern present in this mock should be considered secure. 13 | * Following best practices, always have your contract properly audited before using them to manipulate important funds on 14 | * live networks. 15 | */ 16 | contract ERC3156FlashBorrowerMock is IERC3156FlashBorrower { 17 | bytes32 internal constant _RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan"); 18 | 19 | bool immutable _enableApprove; 20 | bool immutable _enableReturn; 21 | 22 | event BalanceOf(address token, address account, uint256 value); 23 | event TotalSupply(address token, uint256 value); 24 | 25 | constructor(bool enableReturn, bool enableApprove) { 26 | _enableApprove = enableApprove; 27 | _enableReturn = enableReturn; 28 | } 29 | 30 | function onFlashLoan( 31 | address, /*initiator*/ 32 | address token, 33 | uint256 amount, 34 | uint256 fee, 35 | bytes calldata data 36 | ) public override returns (bytes32) { 37 | require(msg.sender == token); 38 | 39 | emit BalanceOf(token, address(this), IERC20(token).balanceOf(address(this))); 40 | emit TotalSupply(token, IERC20(token).totalSupply()); 41 | 42 | if (data.length > 0) { 43 | // WARNING: This code is for testing purposes only! Do not use. 44 | Address.functionCall(token, data); 45 | } 46 | 47 | if (_enableApprove) { 48 | IERC20(token).approve(token, amount + fee); 49 | } 50 | 51 | return _enableReturn ? _RETURN_VALUE : bytes32(0); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC721BurnableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC721/extensions/ERC721Burnable.sol"; 6 | 7 | contract ERC721BurnableMock is ERC721Burnable { 8 | constructor(string memory name, string memory symbol) ERC721(name, symbol) {} 9 | 10 | function exists(uint256 tokenId) public view returns (bool) { 11 | return _exists(tokenId); 12 | } 13 | 14 | function mint(address to, uint256 tokenId) public { 15 | _mint(to, tokenId); 16 | } 17 | 18 | function safeMint(address to, uint256 tokenId) public { 19 | _safeMint(to, tokenId); 20 | } 21 | 22 | function safeMint( 23 | address to, 24 | uint256 tokenId, 25 | bytes memory _data 26 | ) public { 27 | _safeMint(to, tokenId, _data); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC721EnumerableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC721/extensions/ERC721Enumerable.sol"; 6 | 7 | /** 8 | * @title ERC721Mock 9 | * This mock just provides a public safeMint, mint, and burn functions for testing purposes 10 | */ 11 | contract ERC721EnumerableMock is ERC721Enumerable { 12 | string private _baseTokenURI; 13 | 14 | constructor(string memory name, string memory symbol) ERC721(name, symbol) {} 15 | 16 | function _baseURI() internal view virtual override returns (string memory) { 17 | return _baseTokenURI; 18 | } 19 | 20 | function setBaseURI(string calldata newBaseTokenURI) public { 21 | _baseTokenURI = newBaseTokenURI; 22 | } 23 | 24 | function baseURI() public view returns (string memory) { 25 | return _baseURI(); 26 | } 27 | 28 | function exists(uint256 tokenId) public view returns (bool) { 29 | return _exists(tokenId); 30 | } 31 | 32 | function mint(address to, uint256 tokenId) public { 33 | _mint(to, tokenId); 34 | } 35 | 36 | function safeMint(address to, uint256 tokenId) public { 37 | _safeMint(to, tokenId); 38 | } 39 | 40 | function safeMint( 41 | address to, 42 | uint256 tokenId, 43 | bytes memory _data 44 | ) public { 45 | _safeMint(to, tokenId, _data); 46 | } 47 | 48 | function burn(uint256 tokenId) public { 49 | _burn(tokenId); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC721Mock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC721/ERC721.sol"; 6 | 7 | /** 8 | * @title ERC721Mock 9 | * This mock just provides a public safeMint, mint, and burn functions for testing purposes 10 | */ 11 | contract ERC721Mock is ERC721 { 12 | constructor(string memory name, string memory symbol) ERC721(name, symbol) {} 13 | 14 | function baseURI() public view returns (string memory) { 15 | return _baseURI(); 16 | } 17 | 18 | function exists(uint256 tokenId) public view returns (bool) { 19 | return _exists(tokenId); 20 | } 21 | 22 | function mint(address to, uint256 tokenId) public { 23 | _mint(to, tokenId); 24 | } 25 | 26 | function safeMint(address to, uint256 tokenId) public { 27 | _safeMint(to, tokenId); 28 | } 29 | 30 | function safeMint( 31 | address to, 32 | uint256 tokenId, 33 | bytes memory _data 34 | ) public { 35 | _safeMint(to, tokenId, _data); 36 | } 37 | 38 | function burn(uint256 tokenId) public { 39 | _burn(tokenId); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC721PausableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC721/extensions/ERC721Pausable.sol"; 6 | 7 | /** 8 | * @title ERC721PausableMock 9 | * This mock just provides a public mint, burn and exists functions for testing purposes 10 | */ 11 | contract ERC721PausableMock is ERC721Pausable { 12 | constructor(string memory name, string memory symbol) ERC721(name, symbol) {} 13 | 14 | function pause() external { 15 | _pause(); 16 | } 17 | 18 | function unpause() external { 19 | _unpause(); 20 | } 21 | 22 | function exists(uint256 tokenId) public view returns (bool) { 23 | return _exists(tokenId); 24 | } 25 | 26 | function mint(address to, uint256 tokenId) public { 27 | _mint(to, tokenId); 28 | } 29 | 30 | function safeMint(address to, uint256 tokenId) public { 31 | _safeMint(to, tokenId); 32 | } 33 | 34 | function safeMint( 35 | address to, 36 | uint256 tokenId, 37 | bytes memory _data 38 | ) public { 39 | _safeMint(to, tokenId, _data); 40 | } 41 | 42 | function burn(uint256 tokenId) public { 43 | _burn(tokenId); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC721ReceiverMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC721/IERC721Receiver.sol"; 6 | 7 | contract ERC721ReceiverMock is IERC721Receiver { 8 | enum Error { 9 | None, 10 | RevertWithMessage, 11 | RevertWithoutMessage, 12 | Panic 13 | } 14 | 15 | bytes4 private immutable _retval; 16 | Error private immutable _error; 17 | 18 | event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas); 19 | 20 | constructor(bytes4 retval, Error error) { 21 | _retval = retval; 22 | _error = error; 23 | } 24 | 25 | function onERC721Received( 26 | address operator, 27 | address from, 28 | uint256 tokenId, 29 | bytes memory data 30 | ) public override returns (bytes4) { 31 | if (_error == Error.RevertWithMessage) { 32 | revert("ERC721ReceiverMock: reverting"); 33 | } else if (_error == Error.RevertWithoutMessage) { 34 | revert(); 35 | } else if (_error == Error.Panic) { 36 | uint256 a = uint256(0) / uint256(0); 37 | a; 38 | } 39 | emit Received(operator, from, tokenId, data, gasleft()); 40 | return _retval; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC721URIStorageMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC721/extensions/ERC721URIStorage.sol"; 6 | 7 | /** 8 | * @title ERC721Mock 9 | * This mock just provides a public safeMint, mint, and burn functions for testing purposes 10 | */ 11 | contract ERC721URIStorageMock is ERC721URIStorage { 12 | string private _baseTokenURI; 13 | 14 | constructor(string memory name, string memory symbol) ERC721(name, symbol) {} 15 | 16 | function _baseURI() internal view virtual override returns (string memory) { 17 | return _baseTokenURI; 18 | } 19 | 20 | function setBaseURI(string calldata newBaseTokenURI) public { 21 | _baseTokenURI = newBaseTokenURI; 22 | } 23 | 24 | function baseURI() public view returns (string memory) { 25 | return _baseURI(); 26 | } 27 | 28 | function setTokenURI(uint256 tokenId, string memory _tokenURI) public { 29 | _setTokenURI(tokenId, _tokenURI); 30 | } 31 | 32 | function exists(uint256 tokenId) public view returns (bool) { 33 | return _exists(tokenId); 34 | } 35 | 36 | function mint(address to, uint256 tokenId) public { 37 | _mint(to, tokenId); 38 | } 39 | 40 | function safeMint(address to, uint256 tokenId) public { 41 | _safeMint(to, tokenId); 42 | } 43 | 44 | function safeMint( 45 | address to, 46 | uint256 tokenId, 47 | bytes memory _data 48 | ) public { 49 | _safeMint(to, tokenId, _data); 50 | } 51 | 52 | function burn(uint256 tokenId) public { 53 | _burn(tokenId); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC721VotesMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../token/ERC721/extensions/draft-ERC721Votes.sol"; 6 | 7 | contract ERC721VotesMock is ERC721Votes { 8 | constructor(string memory name, string memory symbol) ERC721(name, symbol) EIP712(name, "1") {} 9 | 10 | function getTotalSupply() public view returns (uint256) { 11 | return _getTotalSupply(); 12 | } 13 | 14 | function mint(address account, uint256 tokenId) public { 15 | _mint(account, tokenId); 16 | } 17 | 18 | function burn(uint256 tokenId) public { 19 | _burn(tokenId); 20 | } 21 | 22 | function getChainId() external view returns (uint256) { 23 | return block.chainid; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ERC777Mock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Context.sol"; 6 | import "../token/ERC777/ERC777.sol"; 7 | 8 | contract ERC777Mock is Context, ERC777 { 9 | event BeforeTokenTransfer(); 10 | 11 | constructor( 12 | address initialHolder, 13 | uint256 initialBalance, 14 | string memory name, 15 | string memory symbol, 16 | address[] memory defaultOperators 17 | ) ERC777(name, symbol, defaultOperators) { 18 | _mint(initialHolder, initialBalance, "", ""); 19 | } 20 | 21 | function mintInternal( 22 | address to, 23 | uint256 amount, 24 | bytes memory userData, 25 | bytes memory operatorData 26 | ) public { 27 | _mint(to, amount, userData, operatorData); 28 | } 29 | 30 | function mintInternalExtended( 31 | address to, 32 | uint256 amount, 33 | bytes memory userData, 34 | bytes memory operatorData, 35 | bool requireReceptionAck 36 | ) public { 37 | _mint(to, amount, userData, operatorData, requireReceptionAck); 38 | } 39 | 40 | function approveInternal( 41 | address holder, 42 | address spender, 43 | uint256 value 44 | ) public { 45 | _approve(holder, spender, value); 46 | } 47 | 48 | function _beforeTokenTransfer( 49 | address, 50 | address, 51 | address, 52 | uint256 53 | ) internal override { 54 | emit BeforeTokenTransfer(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/EnumerableMapMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/structs/EnumerableMap.sol"; 6 | 7 | contract EnumerableMapMock { 8 | using EnumerableMap for EnumerableMap.UintToAddressMap; 9 | 10 | event OperationResult(bool result); 11 | 12 | EnumerableMap.UintToAddressMap private _map; 13 | 14 | function contains(uint256 key) public view returns (bool) { 15 | return _map.contains(key); 16 | } 17 | 18 | function set(uint256 key, address value) public { 19 | bool result = _map.set(key, value); 20 | emit OperationResult(result); 21 | } 22 | 23 | function remove(uint256 key) public { 24 | bool result = _map.remove(key); 25 | emit OperationResult(result); 26 | } 27 | 28 | function length() public view returns (uint256) { 29 | return _map.length(); 30 | } 31 | 32 | function at(uint256 index) public view returns (uint256 key, address value) { 33 | return _map.at(index); 34 | } 35 | 36 | function tryGet(uint256 key) public view returns (bool, address) { 37 | return _map.tryGet(key); 38 | } 39 | 40 | function get(uint256 key) public view returns (address) { 41 | return _map.get(key); 42 | } 43 | 44 | function getWithMessage(uint256 key, string calldata errorMessage) public view returns (address) { 45 | return _map.get(key, errorMessage); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/EtherReceiverMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | contract EtherReceiverMock { 6 | bool private _acceptEther; 7 | 8 | function setAcceptEther(bool acceptEther) public { 9 | _acceptEther = acceptEther; 10 | } 11 | 12 | receive() external payable { 13 | if (!_acceptEther) { 14 | revert(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/GovernorCompMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../governance/extensions/GovernorCountingSimple.sol"; 6 | import "../governance/extensions/GovernorVotesComp.sol"; 7 | 8 | contract GovernorCompMock is GovernorVotesComp, GovernorCountingSimple { 9 | constructor(string memory name_, ERC20VotesComp token_) Governor(name_) GovernorVotesComp(token_) {} 10 | 11 | function quorum(uint256) public pure override returns (uint256) { 12 | return 0; 13 | } 14 | 15 | function votingDelay() public pure override returns (uint256) { 16 | return 4; 17 | } 18 | 19 | function votingPeriod() public pure override returns (uint256) { 20 | return 16; 21 | } 22 | 23 | function cancel( 24 | address[] memory targets, 25 | uint256[] memory values, 26 | bytes[] memory calldatas, 27 | bytes32 salt 28 | ) public returns (uint256 proposalId) { 29 | return _cancel(targets, values, calldatas, salt); 30 | } 31 | 32 | function getVotes(address account, uint256 blockNumber) 33 | public 34 | view 35 | virtual 36 | override(IGovernor, GovernorVotesComp) 37 | returns (uint256) 38 | { 39 | return super.getVotes(account, blockNumber); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/GovernorMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../governance/extensions/GovernorProposalThreshold.sol"; 6 | import "../governance/extensions/GovernorSettings.sol"; 7 | import "../governance/extensions/GovernorCountingSimple.sol"; 8 | import "../governance/extensions/GovernorVotesQuorumFraction.sol"; 9 | 10 | contract GovernorMock is 11 | GovernorProposalThreshold, 12 | GovernorSettings, 13 | GovernorVotesQuorumFraction, 14 | GovernorCountingSimple 15 | { 16 | constructor( 17 | string memory name_, 18 | IVotes token_, 19 | uint256 votingDelay_, 20 | uint256 votingPeriod_, 21 | uint256 quorumNumerator_ 22 | ) 23 | Governor(name_) 24 | GovernorSettings(votingDelay_, votingPeriod_, 0) 25 | GovernorVotes(token_) 26 | GovernorVotesQuorumFraction(quorumNumerator_) 27 | {} 28 | 29 | function cancel( 30 | address[] memory targets, 31 | uint256[] memory values, 32 | bytes[] memory calldatas, 33 | bytes32 salt 34 | ) public returns (uint256 proposalId) { 35 | return _cancel(targets, values, calldatas, salt); 36 | } 37 | 38 | function getVotes(address account, uint256 blockNumber) 39 | public 40 | view 41 | virtual 42 | override(IGovernor, GovernorVotes) 43 | returns (uint256) 44 | { 45 | return super.getVotes(account, blockNumber); 46 | } 47 | 48 | function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) { 49 | return super.proposalThreshold(); 50 | } 51 | 52 | function propose( 53 | address[] memory targets, 54 | uint256[] memory values, 55 | bytes[] memory calldatas, 56 | string memory description 57 | ) public virtual override(Governor, GovernorProposalThreshold) returns (uint256) { 58 | return super.propose(targets, values, calldatas, description); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/GovernorPreventLateQuorumMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../governance/extensions/GovernorPreventLateQuorum.sol"; 6 | import "../governance/extensions/GovernorSettings.sol"; 7 | import "../governance/extensions/GovernorCountingSimple.sol"; 8 | import "../governance/extensions/GovernorVotes.sol"; 9 | 10 | contract GovernorPreventLateQuorumMock is 11 | GovernorSettings, 12 | GovernorVotes, 13 | GovernorCountingSimple, 14 | GovernorPreventLateQuorum 15 | { 16 | uint256 private _quorum; 17 | 18 | constructor( 19 | string memory name_, 20 | IVotes token_, 21 | uint256 votingDelay_, 22 | uint256 votingPeriod_, 23 | uint256 quorum_, 24 | uint64 voteExtension_ 25 | ) 26 | Governor(name_) 27 | GovernorSettings(votingDelay_, votingPeriod_, 0) 28 | GovernorVotes(token_) 29 | GovernorPreventLateQuorum(voteExtension_) 30 | { 31 | _quorum = quorum_; 32 | } 33 | 34 | function quorum(uint256) public view virtual override returns (uint256) { 35 | return _quorum; 36 | } 37 | 38 | function proposalDeadline(uint256 proposalId) 39 | public 40 | view 41 | virtual 42 | override(Governor, GovernorPreventLateQuorum) 43 | returns (uint256) 44 | { 45 | return super.proposalDeadline(proposalId); 46 | } 47 | 48 | function proposalThreshold() public view virtual override(Governor, GovernorSettings) returns (uint256) { 49 | return super.proposalThreshold(); 50 | } 51 | 52 | function _castVote( 53 | uint256 proposalId, 54 | address account, 55 | uint8 support, 56 | string memory reason 57 | ) internal virtual override(Governor, GovernorPreventLateQuorum) returns (uint256) { 58 | return super._castVote(proposalId, account, support, reason); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/GovernorVoteMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../governance/extensions/GovernorCountingSimple.sol"; 6 | import "../governance/extensions/GovernorVotes.sol"; 7 | 8 | contract GovernorVoteMocks is GovernorVotes, GovernorCountingSimple { 9 | constructor(string memory name_, IVotes token_) Governor(name_) GovernorVotes(token_) {} 10 | 11 | function quorum(uint256) public pure override returns (uint256) { 12 | return 0; 13 | } 14 | 15 | function votingDelay() public pure override returns (uint256) { 16 | return 4; 17 | } 18 | 19 | function votingPeriod() public pure override returns (uint256) { 20 | return 16; 21 | } 22 | 23 | function cancel( 24 | address[] memory targets, 25 | uint256[] memory values, 26 | bytes[] memory calldatas, 27 | bytes32 salt 28 | ) public returns (uint256 proposalId) { 29 | return _cancel(targets, values, calldatas, salt); 30 | } 31 | 32 | function getVotes(address account, uint256 blockNumber) 33 | public 34 | view 35 | virtual 36 | override(IGovernor, GovernorVotes) 37 | returns (uint256) 38 | { 39 | return super.getVotes(account, blockNumber); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/InitializableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../proxy/utils/Initializable.sol"; 6 | 7 | /** 8 | * @title InitializableMock 9 | * @dev This contract is a mock to test initializable functionality 10 | */ 11 | contract InitializableMock is Initializable { 12 | bool public initializerRan; 13 | bool public onlyInitializingRan; 14 | uint256 public x; 15 | 16 | function initialize() public initializer { 17 | initializerRan = true; 18 | } 19 | 20 | function initializeOnlyInitializing() public onlyInitializing { 21 | onlyInitializingRan = true; 22 | } 23 | 24 | function initializerNested() public initializer { 25 | initialize(); 26 | } 27 | 28 | function onlyInitializingNested() public initializer { 29 | initializeOnlyInitializing(); 30 | } 31 | 32 | function initializeWithX(uint256 _x) public payable initializer { 33 | x = _x; 34 | } 35 | 36 | function nonInitializable(uint256 _x) public payable { 37 | x = _x; 38 | } 39 | 40 | function fail() public pure { 41 | require(false, "InitializableMock forced failure"); 42 | } 43 | } 44 | 45 | contract ConstructorInitializableMock is Initializable { 46 | bool public initializerRan; 47 | bool public onlyInitializingRan; 48 | 49 | constructor() initializer { 50 | initialize(); 51 | initializeOnlyInitializing(); 52 | } 53 | 54 | function initialize() public initializer { 55 | initializerRan = true; 56 | } 57 | 58 | function initializeOnlyInitializing() public onlyInitializing { 59 | onlyInitializingRan = true; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/MathMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/math/Math.sol"; 6 | 7 | contract MathMock { 8 | function max(uint256 a, uint256 b) public pure returns (uint256) { 9 | return Math.max(a, b); 10 | } 11 | 12 | function min(uint256 a, uint256 b) public pure returns (uint256) { 13 | return Math.min(a, b); 14 | } 15 | 16 | function average(uint256 a, uint256 b) public pure returns (uint256) { 17 | return Math.average(a, b); 18 | } 19 | 20 | function ceilDiv(uint256 a, uint256 b) public pure returns (uint256) { 21 | return Math.ceilDiv(a, b); 22 | } 23 | 24 | function abs(int256 n) public pure returns (uint256) { 25 | return Math.abs(n); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/MerkleProofWrapper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/cryptography/MerkleProof.sol"; 6 | 7 | contract MerkleProofWrapper { 8 | function verify( 9 | bytes32[] memory proof, 10 | bytes32 root, 11 | bytes32 leaf 12 | ) public pure returns (bool) { 13 | return MerkleProof.verify(proof, root, leaf); 14 | } 15 | 16 | function processProof(bytes32[] memory proof, bytes32 leaf) public pure returns (bytes32) { 17 | return MerkleProof.processProof(proof, leaf); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/MulticallTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./MulticallTokenMock.sol"; 6 | 7 | contract MulticallTest { 8 | function testReturnValues( 9 | MulticallTokenMock multicallToken, 10 | address[] calldata recipients, 11 | uint256[] calldata amounts 12 | ) external { 13 | bytes[] memory calls = new bytes[](recipients.length); 14 | for (uint256 i = 0; i < recipients.length; i++) { 15 | calls[i] = abi.encodeWithSignature("transfer(address,uint256)", recipients[i], amounts[i]); 16 | } 17 | 18 | bytes[] memory results = multicallToken.multicall(calls); 19 | for (uint256 i = 0; i < results.length; i++) { 20 | require(abi.decode(results[i], (bool))); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/MulticallTokenMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Multicall.sol"; 6 | import "./ERC20Mock.sol"; 7 | 8 | contract MulticallTokenMock is ERC20Mock, Multicall { 9 | constructor(uint256 initialBalance) ERC20Mock("MulticallToken", "BCT", msg.sender, initialBalance) {} 10 | } 11 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/OwnableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../access/Ownable.sol"; 6 | 7 | contract OwnableMock is Ownable {} 8 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/PausableMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../security/Pausable.sol"; 6 | 7 | contract PausableMock is Pausable { 8 | bool public drasticMeasureTaken; 9 | uint256 public count; 10 | 11 | constructor() { 12 | drasticMeasureTaken = false; 13 | count = 0; 14 | } 15 | 16 | function normalProcess() external whenNotPaused { 17 | count++; 18 | } 19 | 20 | function drasticMeasure() external whenPaused { 21 | drasticMeasureTaken = true; 22 | } 23 | 24 | function pause() external { 25 | _pause(); 26 | } 27 | 28 | function unpause() external { 29 | _unpause(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/PullPaymentMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../security/PullPayment.sol"; 6 | 7 | // mock class using PullPayment 8 | contract PullPaymentMock is PullPayment { 9 | constructor() payable {} 10 | 11 | // test helper function to call asyncTransfer 12 | function callTransfer(address dest, uint256 amount) public { 13 | _asyncTransfer(dest, amount); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ReentrancyAttack.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Context.sol"; 6 | 7 | contract ReentrancyAttack is Context { 8 | function callSender(bytes4 data) public { 9 | (bool success, ) = _msgSender().call(abi.encodeWithSelector(data)); 10 | require(success, "ReentrancyAttack: failed call"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/ReentrancyMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../security/ReentrancyGuard.sol"; 6 | import "./ReentrancyAttack.sol"; 7 | 8 | contract ReentrancyMock is ReentrancyGuard { 9 | uint256 public counter; 10 | 11 | constructor() { 12 | counter = 0; 13 | } 14 | 15 | function callback() external nonReentrant { 16 | _count(); 17 | } 18 | 19 | function countLocalRecursive(uint256 n) public nonReentrant { 20 | if (n > 0) { 21 | _count(); 22 | countLocalRecursive(n - 1); 23 | } 24 | } 25 | 26 | function countThisRecursive(uint256 n) public nonReentrant { 27 | if (n > 0) { 28 | _count(); 29 | (bool success, ) = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1)); 30 | require(success, "ReentrancyMock: failed call"); 31 | } 32 | } 33 | 34 | function countAndCall(ReentrancyAttack attacker) public nonReentrant { 35 | _count(); 36 | bytes4 func = bytes4(keccak256("callback()")); 37 | attacker.callSender(func); 38 | } 39 | 40 | function _count() private { 41 | counter += 1; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/RegressionImplementation.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../proxy/utils/Initializable.sol"; 6 | 7 | contract Implementation1 is Initializable { 8 | uint256 internal _value; 9 | 10 | function initialize() public initializer {} 11 | 12 | function setValue(uint256 _number) public { 13 | _value = _number; 14 | } 15 | } 16 | 17 | contract Implementation2 is Initializable { 18 | uint256 internal _value; 19 | 20 | function initialize() public initializer {} 21 | 22 | function setValue(uint256 _number) public { 23 | _value = _number; 24 | } 25 | 26 | function getValue() public view returns (uint256) { 27 | return _value; 28 | } 29 | } 30 | 31 | contract Implementation3 is Initializable { 32 | uint256 internal _value; 33 | 34 | function initialize() public initializer {} 35 | 36 | function setValue(uint256 _number) public { 37 | _value = _number; 38 | } 39 | 40 | function getValue(uint256 _number) public view returns (uint256) { 41 | return _value + _number; 42 | } 43 | } 44 | 45 | contract Implementation4 is Initializable { 46 | uint256 internal _value; 47 | 48 | function initialize() public initializer {} 49 | 50 | function setValue(uint256 _number) public { 51 | _value = _number; 52 | } 53 | 54 | function getValue() public view returns (uint256) { 55 | return _value; 56 | } 57 | 58 | fallback() external { 59 | _value = 1; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/SafeCastMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/math/SafeCast.sol"; 6 | 7 | contract SafeCastMock { 8 | using SafeCast for uint256; 9 | using SafeCast for int256; 10 | 11 | function toUint256(int256 a) public pure returns (uint256) { 12 | return a.toUint256(); 13 | } 14 | 15 | function toUint224(uint256 a) public pure returns (uint224) { 16 | return a.toUint224(); 17 | } 18 | 19 | function toUint128(uint256 a) public pure returns (uint128) { 20 | return a.toUint128(); 21 | } 22 | 23 | function toUint96(uint256 a) public pure returns (uint96) { 24 | return a.toUint96(); 25 | } 26 | 27 | function toUint64(uint256 a) public pure returns (uint64) { 28 | return a.toUint64(); 29 | } 30 | 31 | function toUint32(uint256 a) public pure returns (uint32) { 32 | return a.toUint32(); 33 | } 34 | 35 | function toUint16(uint256 a) public pure returns (uint16) { 36 | return a.toUint16(); 37 | } 38 | 39 | function toUint8(uint256 a) public pure returns (uint8) { 40 | return a.toUint8(); 41 | } 42 | 43 | function toInt256(uint256 a) public pure returns (int256) { 44 | return a.toInt256(); 45 | } 46 | 47 | function toInt128(int256 a) public pure returns (int128) { 48 | return a.toInt128(); 49 | } 50 | 51 | function toInt64(int256 a) public pure returns (int64) { 52 | return a.toInt64(); 53 | } 54 | 55 | function toInt32(int256 a) public pure returns (int32) { 56 | return a.toInt32(); 57 | } 58 | 59 | function toInt16(int256 a) public pure returns (int16) { 60 | return a.toInt16(); 61 | } 62 | 63 | function toInt8(int256 a) public pure returns (int8) { 64 | return a.toInt8(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/SignatureCheckerMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/cryptography/SignatureChecker.sol"; 6 | 7 | contract SignatureCheckerMock { 8 | using SignatureChecker for address; 9 | 10 | function isValidSignatureNow( 11 | address signer, 12 | bytes32 hash, 13 | bytes memory signature 14 | ) public view returns (bool) { 15 | return signer.isValidSignatureNow(hash, signature); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/SignedSafeMathMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/math/SignedSafeMath.sol"; 6 | 7 | contract SignedSafeMathMock { 8 | function mul(int256 a, int256 b) public pure returns (int256) { 9 | return SignedSafeMath.mul(a, b); 10 | } 11 | 12 | function div(int256 a, int256 b) public pure returns (int256) { 13 | return SignedSafeMath.div(a, b); 14 | } 15 | 16 | function sub(int256 a, int256 b) public pure returns (int256) { 17 | return SignedSafeMath.sub(a, b); 18 | } 19 | 20 | function add(int256 a, int256 b) public pure returns (int256) { 21 | return SignedSafeMath.add(a, b); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/SingleInheritanceInitializableMocks.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../proxy/utils/Initializable.sol"; 6 | 7 | /** 8 | * @title MigratableMockV1 9 | * @dev This contract is a mock to test initializable functionality through migrations 10 | */ 11 | contract MigratableMockV1 is Initializable { 12 | uint256 public x; 13 | 14 | function initialize(uint256 value) public payable initializer { 15 | x = value; 16 | } 17 | } 18 | 19 | /** 20 | * @title MigratableMockV2 21 | * @dev This contract is a mock to test migratable functionality with params 22 | */ 23 | contract MigratableMockV2 is MigratableMockV1 { 24 | bool internal _migratedV2; 25 | uint256 public y; 26 | 27 | function migrate(uint256 value, uint256 anotherValue) public payable { 28 | require(!_migratedV2); 29 | x = value; 30 | y = anotherValue; 31 | _migratedV2 = true; 32 | } 33 | } 34 | 35 | /** 36 | * @title MigratableMockV3 37 | * @dev This contract is a mock to test migratable functionality without params 38 | */ 39 | contract MigratableMockV3 is MigratableMockV2 { 40 | bool internal _migratedV3; 41 | 42 | function migrate() public payable { 43 | require(!_migratedV3); 44 | uint256 oldX = x; 45 | x = y; 46 | y = oldX; 47 | _migratedV3 = true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/StorageSlotMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/StorageSlot.sol"; 6 | 7 | contract StorageSlotMock { 8 | using StorageSlot for bytes32; 9 | 10 | function setBoolean(bytes32 slot, bool value) public { 11 | slot.getBooleanSlot().value = value; 12 | } 13 | 14 | function setAddress(bytes32 slot, address value) public { 15 | slot.getAddressSlot().value = value; 16 | } 17 | 18 | function setBytes32(bytes32 slot, bytes32 value) public { 19 | slot.getBytes32Slot().value = value; 20 | } 21 | 22 | function setUint256(bytes32 slot, uint256 value) public { 23 | slot.getUint256Slot().value = value; 24 | } 25 | 26 | function getBoolean(bytes32 slot) public view returns (bool) { 27 | return slot.getBooleanSlot().value; 28 | } 29 | 30 | function getAddress(bytes32 slot) public view returns (address) { 31 | return slot.getAddressSlot().value; 32 | } 33 | 34 | function getBytes32(bytes32 slot) public view returns (bytes32) { 35 | return slot.getBytes32Slot().value; 36 | } 37 | 38 | function getUint256(bytes32 slot) public view returns (uint256) { 39 | return slot.getUint256Slot().value; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/StringsMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Strings.sol"; 6 | 7 | contract StringsMock { 8 | function fromUint256(uint256 value) public pure returns (string memory) { 9 | return Strings.toString(value); 10 | } 11 | 12 | function fromUint256Hex(uint256 value) public pure returns (string memory) { 13 | return Strings.toHexString(value); 14 | } 15 | 16 | function fromUint256HexFixed(uint256 value, uint256 length) public pure returns (string memory) { 17 | return Strings.toHexString(value, length); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/TimersBlockNumberImpl.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Timers.sol"; 6 | 7 | contract TimersBlockNumberImpl { 8 | using Timers for Timers.BlockNumber; 9 | 10 | Timers.BlockNumber private _timer; 11 | 12 | function getDeadline() public view returns (uint64) { 13 | return _timer.getDeadline(); 14 | } 15 | 16 | function setDeadline(uint64 timestamp) public { 17 | _timer.setDeadline(timestamp); 18 | } 19 | 20 | function reset() public { 21 | _timer.reset(); 22 | } 23 | 24 | function isUnset() public view returns (bool) { 25 | return _timer.isUnset(); 26 | } 27 | 28 | function isStarted() public view returns (bool) { 29 | return _timer.isStarted(); 30 | } 31 | 32 | function isPending() public view returns (bool) { 33 | return _timer.isPending(); 34 | } 35 | 36 | function isExpired() public view returns (bool) { 37 | return _timer.isExpired(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/TimersTimestampImpl.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/Timers.sol"; 6 | 7 | contract TimersTimestampImpl { 8 | using Timers for Timers.Timestamp; 9 | 10 | Timers.Timestamp private _timer; 11 | 12 | function getDeadline() public view returns (uint64) { 13 | return _timer.getDeadline(); 14 | } 15 | 16 | function setDeadline(uint64 timestamp) public { 17 | _timer.setDeadline(timestamp); 18 | } 19 | 20 | function reset() public { 21 | _timer.reset(); 22 | } 23 | 24 | function isUnset() public view returns (bool) { 25 | return _timer.isUnset(); 26 | } 27 | 28 | function isStarted() public view returns (bool) { 29 | return _timer.isStarted(); 30 | } 31 | 32 | function isPending() public view returns (bool) { 33 | return _timer.isPending(); 34 | } 35 | 36 | function isExpired() public view returns (bool) { 37 | return _timer.isExpired(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/UUPS/TestInProd.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../CountersImpl.sol"; 6 | import "../../proxy/utils/UUPSUpgradeable.sol"; 7 | 8 | contract UUPSUpgradeableMock is CountersImpl, UUPSUpgradeable { 9 | // Not having any checks in this function is dangerous! Do not do this outside tests! 10 | function _authorizeUpgrade(address) internal virtual override {} 11 | } 12 | 13 | contract UUPSUpgradeableUnsafeMock is UUPSUpgradeableMock { 14 | function upgradeTo(address newImplementation) external virtual override { 15 | ERC1967Upgrade._upgradeToAndCall(newImplementation, bytes(""), false); 16 | } 17 | 18 | function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual override { 19 | ERC1967Upgrade._upgradeToAndCall(newImplementation, data, false); 20 | } 21 | } 22 | 23 | contract UUPSUpgradeableBrokenMock is UUPSUpgradeableMock { 24 | function upgradeTo(address) external virtual override { 25 | // pass 26 | } 27 | 28 | function upgradeToAndCall(address, bytes memory) external payable virtual override { 29 | // pass 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/openzeppelin/mocks/VotesMock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../governance/utils/Votes.sol"; 6 | 7 | contract VotesMock is Votes { 8 | mapping(address => uint256) private _balances; 9 | mapping(uint256 => address) private _owners; 10 | 11 | constructor(string memory name) EIP712(name, "1") {} 12 | 13 | function getTotalSupply() public view returns (uint256) { 14 | return _getTotalSupply(); 15 | } 16 | 17 | function delegate(address account, address newDelegation) public { 18 | return _delegate(account, newDelegation); 19 | } 20 | 21 | function _getVotingUnits(address account) internal virtual override returns (uint256) { 22 | return _balances[account]; 23 | } 24 | 25 | function mint(address account, uint256 voteId) external { 26 | _balances[account] += 1; 27 | _owners[voteId] = account; 28 | _transferVotingUnits(address(0), account, 1); 29 | } 30 | 31 | function burn(uint256 voteId) external { 32 | address owner = _owners[voteId]; 33 | _balances[owner] -= 1; 34 | _transferVotingUnits(owner, address(0), 1); 35 | } 36 | 37 | function getChainId() external view returns (uint256) { 38 | return block.chainid; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/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 | -------------------------------------------------------------------------------- /contracts/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 | -------------------------------------------------------------------------------- /contracts/openzeppelin/security/README.adoc: -------------------------------------------------------------------------------- 1 | = Security 2 | 3 | [.readme-notice] 4 | NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/security 5 | 6 | These contracts aim to cover common security practices. 7 | 8 | * {PullPayment}: A pattern that can be used to avoid reentrancy attacks. 9 | * {ReentrancyGuard}: A modifier that can prevent reentrancy during certain functions. 10 | * {Pausable}: A common emergency response mechanism that can pause functionality while a remediation is pending. 11 | 12 | TIP: For an overview on reentrancy and the possible mechanisms to prevent it, read our article https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. 13 | 14 | == Contracts 15 | 16 | {{PullPayment}} 17 | 18 | {{ReentrancyGuard}} 19 | 20 | {{Pausable}} 21 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC1155/README.adoc: -------------------------------------------------------------------------------- 1 | = ERC 1155 2 | 3 | [.readme-notice] 4 | NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/token/erc1155 5 | 6 | This set of interfaces and contracts are all related to the https://eips.ethereum.org/EIPS/eip-1155[ERC1155 Multi Token Standard]. 7 | 8 | The EIP consists of three interfaces which fulfill different roles, found here as {IERC1155}, {IERC1155MetadataURI} and {IERC1155Receiver}. 9 | 10 | {ERC1155} implements the mandatory {IERC1155} interface, as well as the optional extension {IERC1155MetadataURI}, by relying on the substitution mechanism to use the same URI for all token types, dramatically reducing gas costs. 11 | 12 | Additionally there are multiple custom extensions, including: 13 | 14 | * designation of addresses that can pause token transfers for all users ({ERC1155Pausable}). 15 | * destruction of own tokens ({ERC1155Burnable}). 16 | 17 | NOTE: This core set of contracts is designed to be unopinionated, allowing developers to access the internal functions in ERC1155 (such as <>) and expose them as external functions in the way they prefer. On the other hand, xref:ROOT:erc1155.adoc#Presets[ERC1155 Presets] (such as {ERC1155PresetMinterPauser}) are designed using opinionated patterns to provide developers with ready to use, deployable contracts. 18 | 19 | == Core 20 | 21 | {{IERC1155}} 22 | 23 | {{IERC1155MetadataURI}} 24 | 25 | {{ERC1155}} 26 | 27 | {{IERC1155Receiver}} 28 | 29 | {{ERC1155Receiver}} 30 | 31 | == Extensions 32 | 33 | {{ERC1155Pausable}} 34 | 35 | {{ERC1155Burnable}} 36 | 37 | {{ERC1155Supply}} 38 | 39 | == Presets 40 | 41 | These contracts are preconfigured combinations of the above features. They can be used through inheritance or as models to copy and paste their source code. 42 | 43 | {{ERC1155PresetMinterPauser}} 44 | 45 | == Utilities 46 | 47 | {{ERC1155Holder}} 48 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC1155/extensions/ERC1155Burnable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/ERC1155Burnable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC1155.sol"; 7 | 8 | /** 9 | * @dev Extension of {ERC1155} that allows token holders to destroy both their 10 | * own tokens and those that they have been approved to use. 11 | * 12 | * _Available since v3.1._ 13 | */ 14 | abstract contract ERC1155Burnable is ERC1155 { 15 | function burn( 16 | address account, 17 | uint256 id, 18 | uint256 value 19 | ) public virtual { 20 | require( 21 | account == _msgSender() || isApprovedForAll(account, _msgSender()), 22 | "ERC1155: caller is not owner nor approved" 23 | ); 24 | 25 | _burn(account, id, value); 26 | } 27 | 28 | function burnBatch( 29 | address account, 30 | uint256[] memory ids, 31 | uint256[] memory values 32 | ) public virtual { 33 | require( 34 | account == _msgSender() || isApprovedForAll(account, _msgSender()), 35 | "ERC1155: caller is not owner nor approved" 36 | ); 37 | 38 | _burnBatch(account, ids, values); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC1155/extensions/ERC1155Pausable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/ERC1155Pausable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC1155.sol"; 7 | import "../../../security/Pausable.sol"; 8 | 9 | /** 10 | * @dev ERC1155 token with pausable token transfers, minting and burning. 11 | * 12 | * Useful for scenarios such as preventing trades until the end of an evaluation 13 | * period, or having an emergency switch for freezing all token transfers in the 14 | * event of a large bug. 15 | * 16 | * _Available since v3.1._ 17 | */ 18 | abstract contract ERC1155Pausable is ERC1155, Pausable { 19 | /** 20 | * @dev See {ERC1155-_beforeTokenTransfer}. 21 | * 22 | * Requirements: 23 | * 24 | * - the contract must not be paused. 25 | */ 26 | function _beforeTokenTransfer( 27 | address operator, 28 | address from, 29 | address to, 30 | uint256[] memory ids, 31 | uint256[] memory amounts, 32 | bytes memory data 33 | ) internal virtual override { 34 | super._beforeTokenTransfer(operator, from, to, ids, amounts, data); 35 | 36 | require(!paused(), "ERC1155Pausable: token transfer while paused"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC1155/extensions/ERC1155Supply.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/ERC1155Supply.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC1155.sol"; 7 | 8 | /** 9 | * @dev Extension of ERC1155 that adds tracking of total supply per id. 10 | * 11 | * Useful for scenarios where Fungible and Non-fungible tokens have to be 12 | * clearly identified. Note: While a totalSupply of 1 might mean the 13 | * corresponding is an NFT, there is no guarantees that no other token with the 14 | * same id are not going to be minted. 15 | */ 16 | abstract contract ERC1155Supply is ERC1155 { 17 | mapping(uint256 => uint256) private _totalSupply; 18 | 19 | /** 20 | * @dev Total amount of tokens in with a given id. 21 | */ 22 | function totalSupply(uint256 id) public view virtual returns (uint256) { 23 | return _totalSupply[id]; 24 | } 25 | 26 | /** 27 | * @dev Indicates whether any token exist with a given id, or not. 28 | */ 29 | function exists(uint256 id) public view virtual returns (bool) { 30 | return ERC1155Supply.totalSupply(id) > 0; 31 | } 32 | 33 | /** 34 | * @dev See {ERC1155-_beforeTokenTransfer}. 35 | */ 36 | function _beforeTokenTransfer( 37 | address operator, 38 | address from, 39 | address to, 40 | uint256[] memory ids, 41 | uint256[] memory amounts, 42 | bytes memory data 43 | ) internal virtual override { 44 | super._beforeTokenTransfer(operator, from, to, ids, amounts, data); 45 | 46 | if (from == address(0)) { 47 | for (uint256 i = 0; i < ids.length; ++i) { 48 | _totalSupply[ids[i]] += amounts[i]; 49 | } 50 | } 51 | 52 | if (to == address(0)) { 53 | for (uint256 i = 0; i < ids.length; ++i) { 54 | _totalSupply[ids[i]] -= amounts[i]; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC1155/extensions/IERC1155MetadataURI.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../IERC1155.sol"; 7 | 8 | /** 9 | * @dev Interface of the optional ERC1155MetadataExtension interface, as defined 10 | * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP]. 11 | * 12 | * _Available since v3.1._ 13 | */ 14 | interface IERC1155MetadataURI is IERC1155 { 15 | /** 16 | * @dev Returns the URI for token type `id`. 17 | * 18 | * If the `\{id\}` substring is present in the URI, it must be replaced by 19 | * clients with the actual token type ID. 20 | */ 21 | function uri(uint256 id) external view returns (string memory); 22 | } 23 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC1155/presets/README.md: -------------------------------------------------------------------------------- 1 | Contract presets are now deprecated in favor of [Contracts Wizard](https://wizard.openzeppelin.com/) as a more powerful alternative. 2 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC1155/utils/ERC1155Holder.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Holder.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./ERC1155Receiver.sol"; 7 | 8 | /** 9 | * Simple implementation of `ERC1155Receiver` that will allow a contract to hold ERC1155 tokens. 10 | * 11 | * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be 12 | * stuck. 13 | * 14 | * @dev _Available since v3.1._ 15 | */ 16 | contract ERC1155Holder is ERC1155Receiver { 17 | function onERC1155Received( 18 | address, 19 | address, 20 | uint256, 21 | uint256, 22 | bytes memory 23 | ) public virtual override returns (bytes4) { 24 | return this.onERC1155Received.selector; 25 | } 26 | 27 | function onERC1155BatchReceived( 28 | address, 29 | address, 30 | uint256[] memory, 31 | uint256[] memory, 32 | bytes memory 33 | ) public virtual override returns (bytes4) { 34 | return this.onERC1155BatchReceived.selector; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC1155/utils/ERC1155Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../IERC1155Receiver.sol"; 7 | import "../../../utils/introspection/ERC165.sol"; 8 | 9 | /** 10 | * @dev _Available since v3.1._ 11 | */ 12 | abstract contract ERC1155Receiver is ERC165, IERC1155Receiver { 13 | /** 14 | * @dev See {IERC165-supportsInterface}. 15 | */ 16 | function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { 17 | return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC20/extensions/ERC20Burnable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Burnable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC20.sol"; 7 | import "../../../utils/Context.sol"; 8 | 9 | /** 10 | * @dev Extension of {ERC20} that allows token holders to destroy both their own 11 | * tokens and those that they have an allowance for, in a way that can be 12 | * recognized off-chain (via event analysis). 13 | */ 14 | abstract contract ERC20Burnable is Context, ERC20 { 15 | /** 16 | * @dev Destroys `amount` tokens from the caller. 17 | * 18 | * See {ERC20-_burn}. 19 | */ 20 | function burn(uint256 amount) public virtual { 21 | _burn(_msgSender(), amount); 22 | } 23 | 24 | /** 25 | * @dev Destroys `amount` tokens from `account`, deducting from the caller's 26 | * allowance. 27 | * 28 | * See {ERC20-_burn} and {ERC20-allowance}. 29 | * 30 | * Requirements: 31 | * 32 | * - the caller must have allowance for ``accounts``'s tokens of at least 33 | * `amount`. 34 | */ 35 | function burnFrom(address account, uint256 amount) public virtual { 36 | uint256 currentAllowance = allowance(account, _msgSender()); 37 | require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance"); 38 | unchecked { 39 | _approve(account, _msgSender(), currentAllowance - amount); 40 | } 41 | _burn(account, amount); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC20/extensions/ERC20Capped.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Capped.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC20.sol"; 7 | 8 | /** 9 | * @dev Extension of {ERC20} that adds a cap to the supply of tokens. 10 | */ 11 | abstract contract ERC20Capped is ERC20 { 12 | uint256 private immutable _cap; 13 | 14 | /** 15 | * @dev Sets the value of the `cap`. This value is immutable, it can only be 16 | * set once during construction. 17 | */ 18 | constructor(uint256 cap_) { 19 | require(cap_ > 0, "ERC20Capped: cap is 0"); 20 | _cap = cap_; 21 | } 22 | 23 | /** 24 | * @dev Returns the cap on the token's total supply. 25 | */ 26 | function cap() public view virtual returns (uint256) { 27 | return _cap; 28 | } 29 | 30 | /** 31 | * @dev See {ERC20-_mint}. 32 | */ 33 | function _mint(address account, uint256 amount) internal virtual override { 34 | require(ERC20.totalSupply() + amount <= cap(), "ERC20Capped: cap exceeded"); 35 | super._mint(account, amount); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC20/extensions/ERC20Pausable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Pausable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC20.sol"; 7 | import "../../../security/Pausable.sol"; 8 | 9 | /** 10 | * @dev ERC20 token with pausable token transfers, minting and burning. 11 | * 12 | * Useful for scenarios such as preventing trades until the end of an evaluation 13 | * period, or having an emergency switch for freezing all token transfers in the 14 | * event of a large bug. 15 | */ 16 | abstract contract ERC20Pausable is ERC20, Pausable { 17 | /** 18 | * @dev See {ERC20-_beforeTokenTransfer}. 19 | * 20 | * Requirements: 21 | * 22 | * - the contract must not be paused. 23 | */ 24 | function _beforeTokenTransfer( 25 | address from, 26 | address to, 27 | uint256 amount 28 | ) internal virtual override { 29 | super._beforeTokenTransfer(from, to, amount); 30 | 31 | require(!paused(), "ERC20Pausable: token transfer while paused"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC20/extensions/ERC20Wrapper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Wrapper.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC20.sol"; 7 | import "../utils/SafeERC20.sol"; 8 | 9 | /** 10 | * @dev Extension of the ERC20 token contract to support token wrapping. 11 | * 12 | * Users can deposit and withdraw "underlying tokens" and receive a matching number of "wrapped tokens". This is useful 13 | * in conjunction with other modules. For example, combining this wrapping mechanism with {ERC20Votes} will allow the 14 | * wrapping of an existing "basic" ERC20 into a governance token. 15 | * 16 | * _Available since v4.2._ 17 | */ 18 | abstract contract ERC20Wrapper is ERC20 { 19 | IERC20 public immutable underlying; 20 | 21 | constructor(IERC20 underlyingToken) { 22 | underlying = underlyingToken; 23 | } 24 | 25 | /** 26 | * @dev Allow a user to deposit underlying tokens and mint the corresponding number of wrapped tokens. 27 | */ 28 | function depositFor(address account, uint256 amount) public virtual returns (bool) { 29 | SafeERC20.safeTransferFrom(underlying, _msgSender(), address(this), amount); 30 | _mint(account, amount); 31 | return true; 32 | } 33 | 34 | /** 35 | * @dev Allow a user to burn a number of wrapped tokens and withdraw the corresponding number of underlying tokens. 36 | */ 37 | function withdrawTo(address account, uint256 amount) public virtual returns (bool) { 38 | _burn(_msgSender(), amount); 39 | SafeERC20.safeTransfer(underlying, account, amount); 40 | return true; 41 | } 42 | 43 | /** 44 | * @dev Mint wrapped token to cover any underlyingTokens that would have been transfered by mistake. Internal 45 | * function that can be exposed with access control if desired. 46 | */ 47 | function _recover(address account) internal virtual returns (uint256) { 48 | uint256 value = underlying.balanceOf(address(this)) - totalSupply(); 49 | _mint(account, value); 50 | return value; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC20/extensions/IERC20Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../IERC20.sol"; 7 | 8 | /** 9 | * @dev Interface for the optional metadata functions from the ERC20 standard. 10 | * 11 | * _Available since v4.1._ 12 | */ 13 | interface IERC20Metadata is IERC20 { 14 | /** 15 | * @dev Returns the name of the token. 16 | */ 17 | function name() external view returns (string memory); 18 | 19 | /** 20 | * @dev Returns the symbol of the token. 21 | */ 22 | function symbol() external view returns (string memory); 23 | 24 | /** 25 | * @dev Returns the decimals places of the token. 26 | */ 27 | function decimals() external view returns (uint8); 28 | } 29 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC20/presets/ERC20PresetFixedSupply.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/presets/ERC20PresetFixedSupply.sol) 3 | pragma solidity ^0.8.0; 4 | 5 | import "../extensions/ERC20Burnable.sol"; 6 | 7 | /** 8 | * @dev {ERC20} token, including: 9 | * 10 | * - Preminted initial supply 11 | * - Ability for holders to burn (destroy) their tokens 12 | * - No access control mechanism (for minting/pausing) and hence no governance 13 | * 14 | * This contract uses {ERC20Burnable} to include burn capabilities - head to 15 | * its documentation for details. 16 | * 17 | * _Available since v3.4._ 18 | * 19 | * _Deprecated in favor of https://wizard.openzeppelin.com/[Contracts Wizard]._ 20 | */ 21 | contract ERC20PresetFixedSupply is ERC20Burnable { 22 | /** 23 | * @dev Mints `initialSupply` amount of token and transfers them to `owner`. 24 | * 25 | * See {ERC20-constructor}. 26 | */ 27 | constructor( 28 | string memory name, 29 | string memory symbol, 30 | uint256 initialSupply, 31 | address owner 32 | ) ERC20(name, symbol) { 33 | _mint(owner, initialSupply); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC20/presets/README.md: -------------------------------------------------------------------------------- 1 | Contract presets are now deprecated in favor of [Contracts Wizard](https://wizard.openzeppelin.com/) as a more powerful alternative. 2 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC20/utils/TokenTimelock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/TokenTimelock.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./SafeERC20.sol"; 7 | 8 | /** 9 | * @dev A token holder contract that will allow a beneficiary to extract the 10 | * tokens after a given release time. 11 | * 12 | * Useful for simple vesting schedules like "advisors get all of their tokens 13 | * after 1 year". 14 | */ 15 | contract TokenTimelock { 16 | using SafeERC20 for IERC20; 17 | 18 | // ERC20 basic token contract being held 19 | IERC20 private immutable _token; 20 | 21 | // beneficiary of tokens after they are released 22 | address private immutable _beneficiary; 23 | 24 | // timestamp when token release is enabled 25 | uint256 private immutable _releaseTime; 26 | 27 | constructor( 28 | IERC20 token_, 29 | address beneficiary_, 30 | uint256 releaseTime_ 31 | ) { 32 | require(releaseTime_ > block.timestamp, "TokenTimelock: release time is before current time"); 33 | _token = token_; 34 | _beneficiary = beneficiary_; 35 | _releaseTime = releaseTime_; 36 | } 37 | 38 | /** 39 | * @return the token being held. 40 | */ 41 | function token() public view virtual returns (IERC20) { 42 | return _token; 43 | } 44 | 45 | /** 46 | * @return the beneficiary of the tokens. 47 | */ 48 | function beneficiary() public view virtual returns (address) { 49 | return _beneficiary; 50 | } 51 | 52 | /** 53 | * @return the time when the tokens are released. 54 | */ 55 | function releaseTime() public view virtual returns (uint256) { 56 | return _releaseTime; 57 | } 58 | 59 | /** 60 | * @notice Transfers tokens held by timelock to beneficiary. 61 | */ 62 | function release() public virtual { 63 | require(block.timestamp >= releaseTime(), "TokenTimelock: current time is before release time"); 64 | 65 | uint256 amount = token().balanceOf(address(this)); 66 | require(amount > 0, "TokenTimelock: no tokens to release"); 67 | 68 | token().safeTransfer(beneficiary(), amount); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @title ERC721 token receiver interface 8 | * @dev Interface for any contract that wants to support safeTransfers 9 | * from ERC721 asset contracts. 10 | */ 11 | interface IERC721Receiver { 12 | /** 13 | * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} 14 | * by `operator` from `from`, this function is called. 15 | * 16 | * It must return its Solidity selector to confirm the token transfer. 17 | * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. 18 | * 19 | * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. 20 | */ 21 | function onERC721Received( 22 | address operator, 23 | address from, 24 | uint256 tokenId, 25 | bytes calldata data 26 | ) external returns (bytes4); 27 | } 28 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/extensions/ERC721Burnable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Burnable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC721.sol"; 7 | import "../../../utils/Context.sol"; 8 | 9 | /** 10 | * @title ERC721 Burnable Token 11 | * @dev ERC721 Token that can be irreversibly burned (destroyed). 12 | */ 13 | abstract contract ERC721Burnable is Context, ERC721 { 14 | /** 15 | * @dev Burns `tokenId`. See {ERC721-_burn}. 16 | * 17 | * Requirements: 18 | * 19 | * - The caller must own `tokenId` or be an approved operator. 20 | */ 21 | function burn(uint256 tokenId) public virtual { 22 | //solhint-disable-next-line max-line-length 23 | require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721Burnable: caller is not owner nor approved"); 24 | _burn(tokenId); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/extensions/ERC721Pausable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Pausable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC721.sol"; 7 | import "../../../security/Pausable.sol"; 8 | 9 | /** 10 | * @dev ERC721 token with pausable token transfers, minting and burning. 11 | * 12 | * Useful for scenarios such as preventing trades until the end of an evaluation 13 | * period, or having an emergency switch for freezing all token transfers in the 14 | * event of a large bug. 15 | */ 16 | abstract contract ERC721Pausable is ERC721, Pausable { 17 | /** 18 | * @dev See {ERC721-_beforeTokenTransfer}. 19 | * 20 | * Requirements: 21 | * 22 | * - the contract must not be paused. 23 | */ 24 | function _beforeTokenTransfer( 25 | address from, 26 | address to, 27 | uint256 tokenId 28 | ) internal virtual override { 29 | super._beforeTokenTransfer(from, to, tokenId); 30 | 31 | require(!paused(), "ERC721Pausable: token transfer while paused"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/extensions/ERC721URIStorage.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721URIStorage.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC721.sol"; 7 | 8 | /** 9 | * @dev ERC721 token with storage based token URI management. 10 | */ 11 | abstract contract ERC721URIStorage is ERC721 { 12 | using Strings for uint256; 13 | 14 | // Optional mapping for token URIs 15 | mapping(uint256 => string) private _tokenURIs; 16 | 17 | /** 18 | * @dev See {IERC721Metadata-tokenURI}. 19 | */ 20 | function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { 21 | require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token"); 22 | 23 | string memory _tokenURI = _tokenURIs[tokenId]; 24 | string memory base = _baseURI(); 25 | 26 | // If there is no base URI, return the token URI. 27 | if (bytes(base).length == 0) { 28 | return _tokenURI; 29 | } 30 | // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). 31 | if (bytes(_tokenURI).length > 0) { 32 | return string(abi.encodePacked(base, _tokenURI)); 33 | } 34 | 35 | return super.tokenURI(tokenId); 36 | } 37 | 38 | /** 39 | * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. 40 | * 41 | * Requirements: 42 | * 43 | * - `tokenId` must exist. 44 | */ 45 | function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { 46 | require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token"); 47 | _tokenURIs[tokenId] = _tokenURI; 48 | } 49 | 50 | /** 51 | * @dev Destroys `tokenId`. 52 | * The approval is cleared when the token is burned. 53 | * 54 | * Requirements: 55 | * 56 | * - `tokenId` must exist. 57 | * 58 | * Emits a {Transfer} event. 59 | */ 60 | function _burn(uint256 tokenId) internal virtual override { 61 | super._burn(tokenId); 62 | 63 | if (bytes(_tokenURIs[tokenId]).length != 0) { 64 | delete _tokenURIs[tokenId]; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/extensions/IERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Enumerable.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../IERC721.sol"; 7 | 8 | /** 9 | * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension 10 | * @dev See https://eips.ethereum.org/EIPS/eip-721 11 | */ 12 | interface IERC721Enumerable is IERC721 { 13 | /** 14 | * @dev Returns the total amount of tokens stored by the contract. 15 | */ 16 | function totalSupply() external view returns (uint256); 17 | 18 | /** 19 | * @dev Returns a token ID owned by `owner` at a given `index` of its token list. 20 | * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. 21 | */ 22 | function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); 23 | 24 | /** 25 | * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. 26 | * Use along with {totalSupply} to enumerate all tokens. 27 | */ 28 | function tokenByIndex(uint256 index) external view returns (uint256); 29 | } 30 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/extensions/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../IERC721.sol"; 7 | 8 | /** 9 | * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 10 | * @dev See https://eips.ethereum.org/EIPS/eip-721 11 | */ 12 | interface IERC721Metadata is IERC721 { 13 | /** 14 | * @dev Returns the token collection name. 15 | */ 16 | function name() external view returns (string memory); 17 | 18 | /** 19 | * @dev Returns the token collection symbol. 20 | */ 21 | function symbol() external view returns (string memory); 22 | 23 | /** 24 | * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. 25 | */ 26 | function tokenURI(uint256 tokenId) external view returns (string memory); 27 | } 28 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/extensions/draft-ERC721Votes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.0 (token/ERC721/extensions/draft-ERC721Votes.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../ERC721.sol"; 7 | import "../../../governance/utils/Votes.sol"; 8 | 9 | /** 10 | * @dev Extension of ERC721 to support voting and delegation as implemented by {Votes}, where each individual NFT counts 11 | * as 1 vote unit. 12 | * 13 | * Tokens do not count as votes until they are delegated, because votes must be tracked which incurs an additional cost 14 | * on every transfer. Token holders can either delegate to a trusted representative who will decide how to make use of 15 | * the votes in governance decisions, or they can delegate to themselves to be their own representative. 16 | * 17 | * _Available since v4.5._ 18 | */ 19 | abstract contract ERC721Votes is ERC721, Votes { 20 | /** 21 | * @dev Adjusts votes when tokens are transferred. 22 | * 23 | * Emits a {Votes-DelegateVotesChanged} event. 24 | */ 25 | function _afterTokenTransfer( 26 | address from, 27 | address to, 28 | uint256 tokenId 29 | ) internal virtual override { 30 | _transferVotingUnits(from, to, 1); 31 | super._afterTokenTransfer(from, to, tokenId); 32 | } 33 | 34 | /** 35 | * @dev Returns the balance of `account`. 36 | */ 37 | function _getVotingUnits(address account) internal virtual override returns (uint256) { 38 | return balanceOf(account); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/presets/README.md: -------------------------------------------------------------------------------- 1 | Contract presets are now deprecated in favor of [Contracts Wizard](https://wizard.openzeppelin.com/) as a more powerful alternative. 2 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC721/utils/ERC721Holder.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "../IERC721Receiver.sol"; 7 | 8 | /** 9 | * @dev Implementation of the {IERC721Receiver} interface. 10 | * 11 | * Accepts all token transfers. 12 | * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}. 13 | */ 14 | contract ERC721Holder is IERC721Receiver { 15 | /** 16 | * @dev See {IERC721Receiver-onERC721Received}. 17 | * 18 | * Always returns `IERC721Receiver.onERC721Received.selector`. 19 | */ 20 | function onERC721Received( 21 | address, 22 | address, 23 | uint256, 24 | bytes memory 25 | ) public virtual override returns (bytes4) { 26 | return this.onERC721Received.selector; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC777/IERC777Recipient.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC777/IERC777Recipient.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC777TokensRecipient standard as defined in the EIP. 8 | * 9 | * Accounts can be notified of {IERC777} tokens being sent to them by having a 10 | * contract implement this interface (contract holders can be their own 11 | * implementer) and registering it on the 12 | * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry]. 13 | * 14 | * See {IERC1820Registry} and {ERC1820Implementer}. 15 | */ 16 | interface IERC777Recipient { 17 | /** 18 | * @dev Called by an {IERC777} token contract whenever tokens are being 19 | * moved or created into a registered account (`to`). The type of operation 20 | * is conveyed by `from` being the zero address or not. 21 | * 22 | * This call occurs _after_ the token contract's state is updated, so 23 | * {IERC777-balanceOf}, etc., can be used to query the post-operation state. 24 | * 25 | * This function may revert to prevent the operation from being executed. 26 | */ 27 | function tokensReceived( 28 | address operator, 29 | address from, 30 | address to, 31 | uint256 amount, 32 | bytes calldata userData, 33 | bytes calldata operatorData 34 | ) external; 35 | } 36 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC777/IERC777Sender.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC777/IERC777Sender.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC777TokensSender standard as defined in the EIP. 8 | * 9 | * {IERC777} Token holders can be notified of operations performed on their 10 | * tokens by having a contract implement this interface (contract holders can be 11 | * their own implementer) and registering it on the 12 | * https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry]. 13 | * 14 | * See {IERC1820Registry} and {ERC1820Implementer}. 15 | */ 16 | interface IERC777Sender { 17 | /** 18 | * @dev Called by an {IERC777} token contract whenever a registered holder's 19 | * (`from`) tokens are about to be moved or destroyed. The type of operation 20 | * is conveyed by `to` being the zero address or not. 21 | * 22 | * This call occurs _before_ the token contract's state is updated, so 23 | * {IERC777-balanceOf}, etc., can be used to query the pre-operation state. 24 | * 25 | * This function may revert to prevent the operation from being executed. 26 | */ 27 | function tokensToSend( 28 | address operator, 29 | address from, 30 | address to, 31 | uint256 amount, 32 | bytes calldata userData, 33 | bytes calldata operatorData 34 | ) external; 35 | } 36 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC777/README.adoc: -------------------------------------------------------------------------------- 1 | = ERC 777 2 | 3 | [.readme-notice] 4 | NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/token/erc777 5 | 6 | This set of interfaces and contracts are all related to the [ERC777 token standard](https://eips.ethereum.org/EIPS/eip-777). 7 | 8 | TIP: For an overview of ERC777 tokens and a walk through on how to create a token contract read our xref:ROOT:erc777.adoc[ERC777 guide]. 9 | 10 | The token behavior itself is implemented in the core contracts: {IERC777}, {ERC777}. 11 | 12 | Additionally there are interfaces used to develop contracts that react to token movements: {IERC777Sender}, {IERC777Recipient}. 13 | 14 | == Core 15 | 16 | {{IERC777}} 17 | 18 | {{ERC777}} 19 | 20 | == Hooks 21 | 22 | {{IERC777Sender}} 23 | 24 | {{IERC777Recipient}} 25 | 26 | == Presets 27 | 28 | These contracts are preconfigured combinations of features. They can be used through inheritance or as models to copy and paste their source code. 29 | 30 | {{ERC777PresetFixedSupply}} 31 | -------------------------------------------------------------------------------- /contracts/openzeppelin/token/ERC777/presets/ERC777PresetFixedSupply.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (token/ERC777/presets/ERC777PresetFixedSupply.sol) 3 | pragma solidity ^0.8.0; 4 | 5 | import "../ERC777.sol"; 6 | 7 | /** 8 | * @dev {ERC777} token, including: 9 | * 10 | * - Preminted initial supply 11 | * - No access control mechanism (for minting/pausing) and hence no governance 12 | * 13 | * _Available since v3.4._ 14 | */ 15 | contract ERC777PresetFixedSupply is ERC777 { 16 | /** 17 | * @dev Mints `initialSupply` amount of token and transfers them to `owner`. 18 | * 19 | * See {ERC777-constructor}. 20 | */ 21 | constructor( 22 | string memory name, 23 | string memory symbol, 24 | address[] memory defaultOperators, 25 | uint256 initialSupply, 26 | address owner 27 | ) ERC777(name, symbol, defaultOperators) { 28 | _mint(owner, initialSupply, "", ""); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/Arrays.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/Arrays.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./math/Math.sol"; 7 | 8 | /** 9 | * @dev Collection of functions related to array types. 10 | */ 11 | library Arrays { 12 | /** 13 | * @dev Searches a sorted `array` and returns the first index that contains 14 | * a value greater or equal to `element`. If no such index exists (i.e. all 15 | * values in the array are strictly less than `element`), the array length is 16 | * returned. Time complexity O(log n). 17 | * 18 | * `array` is expected to be sorted in ascending order, and to contain no 19 | * repeated elements. 20 | */ 21 | function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) { 22 | if (array.length == 0) { 23 | return 0; 24 | } 25 | 26 | uint256 low = 0; 27 | uint256 high = array.length; 28 | 29 | while (low < high) { 30 | uint256 mid = Math.average(low, high); 31 | 32 | // Note that mid will always be strictly less than high (i.e. it will be a valid array index) 33 | // because Math.average rounds down (it does integer division with truncation). 34 | if (array[mid] > element) { 35 | high = mid; 36 | } else { 37 | low = mid + 1; 38 | } 39 | } 40 | 41 | // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound. 42 | if (low > 0 && array[low - 1] == element) { 43 | return low - 1; 44 | } else { 45 | return low; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /contracts/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 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/Counters.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @title Counters 8 | * @author Matt Condon (@shrugs) 9 | * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number 10 | * of elements in a mapping, issuing ERC721 ids, or counting request ids. 11 | * 12 | * Include with `using Counters for Counters.Counter;` 13 | */ 14 | library Counters { 15 | struct Counter { 16 | // This variable should never be directly accessed by users of the library: interactions must be restricted to 17 | // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add 18 | // this feature: see https://github.com/ethereum/solidity/issues/4637 19 | uint256 _value; // default: 0 20 | } 21 | 22 | function current(Counter storage counter) internal view returns (uint256) { 23 | return counter._value; 24 | } 25 | 26 | function increment(Counter storage counter) internal { 27 | unchecked { 28 | counter._value += 1; 29 | } 30 | } 31 | 32 | function decrement(Counter storage counter) internal { 33 | uint256 value = counter._value; 34 | require(value > 0, "Counter: decrement overflow"); 35 | unchecked { 36 | counter._value = value - 1; 37 | } 38 | } 39 | 40 | function reset(Counter storage counter) internal { 41 | counter._value = 0; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/Multicall.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/Multicall.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./Address.sol"; 7 | 8 | /** 9 | * @dev Provides a function to batch together multiple calls in a single external call. 10 | * 11 | * _Available since v4.1._ 12 | */ 13 | abstract contract Multicall { 14 | /** 15 | * @dev Receives and executes a batch of function calls on this contract. 16 | */ 17 | function multicall(bytes[] calldata data) external returns (bytes[] memory results) { 18 | results = new bytes[](data.length); 19 | for (uint256 i = 0; i < data.length; i++) { 20 | results[i] = Address.functionDelegateCall(address(this), data[i]); 21 | } 22 | return results; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/Strings.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev String operations. 8 | */ 9 | library Strings { 10 | bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; 11 | 12 | /** 13 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 14 | */ 15 | function toString(uint256 value) internal pure returns (string memory) { 16 | // Inspired by OraclizeAPI's implementation - MIT licence 17 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 18 | 19 | if (value == 0) { 20 | return "0"; 21 | } 22 | uint256 temp = value; 23 | uint256 digits; 24 | while (temp != 0) { 25 | digits++; 26 | temp /= 10; 27 | } 28 | bytes memory buffer = new bytes(digits); 29 | while (value != 0) { 30 | digits -= 1; 31 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 32 | value /= 10; 33 | } 34 | return string(buffer); 35 | } 36 | 37 | /** 38 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 39 | */ 40 | function toHexString(uint256 value) internal pure returns (string memory) { 41 | if (value == 0) { 42 | return "0x00"; 43 | } 44 | uint256 temp = value; 45 | uint256 length = 0; 46 | while (temp != 0) { 47 | length++; 48 | temp >>= 8; 49 | } 50 | return toHexString(value, length); 51 | } 52 | 53 | /** 54 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 55 | */ 56 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 57 | bytes memory buffer = new bytes(2 * length + 2); 58 | buffer[0] = "0"; 59 | buffer[1] = "x"; 60 | for (uint256 i = 2 * length + 1; i > 1; --i) { 61 | buffer[i] = _HEX_SYMBOLS[value & 0xf]; 62 | value >>= 4; 63 | } 64 | require(value == 0, "Strings: hex length insufficient"); 65 | return string(buffer); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/cryptography/SignatureChecker.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/cryptography/SignatureChecker.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./ECDSA.sol"; 7 | import "../Address.sol"; 8 | import "../../interfaces/IERC1271.sol"; 9 | 10 | /** 11 | * @dev Signature verification helper: Provide a single mechanism to verify both private-key (EOA) ECDSA signature and 12 | * ERC1271 contract signatures. Using this instead of ECDSA.recover in your contract will make them compatible with 13 | * smart contract wallets such as Argent and Gnosis. 14 | * 15 | * Note: unlike ECDSA signatures, contract signature's are revocable, and the outcome of this function can thus change 16 | * through time. It could return true at block N and false at block N+1 (or the opposite). 17 | * 18 | * _Available since v4.1._ 19 | */ 20 | library SignatureChecker { 21 | function isValidSignatureNow( 22 | address signer, 23 | bytes32 hash, 24 | bytes memory signature 25 | ) internal view returns (bool) { 26 | (address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature); 27 | if (error == ECDSA.RecoverError.NoError && recovered == signer) { 28 | return true; 29 | } 30 | 31 | (bool success, bytes memory result) = signer.staticcall( 32 | abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature) 33 | ); 34 | return (success && result.length == 32 && abi.decode(result, (bytes4)) == IERC1271.isValidSignature.selector); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/escrow/ConditionalEscrow.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/escrow/ConditionalEscrow.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./Escrow.sol"; 7 | 8 | /** 9 | * @title ConditionalEscrow 10 | * @dev Base abstract escrow to only allow withdrawal if a condition is met. 11 | * @dev Intended usage: See {Escrow}. Same usage guidelines apply here. 12 | */ 13 | abstract contract ConditionalEscrow is Escrow { 14 | /** 15 | * @dev Returns whether an address is allowed to withdraw their funds. To be 16 | * implemented by derived contracts. 17 | * @param payee The destination address of the funds. 18 | */ 19 | function withdrawalAllowed(address payee) public view virtual returns (bool); 20 | 21 | function withdraw(address payable payee) public virtual override { 22 | require(withdrawalAllowed(payee), "ConditionalEscrow: payee is not allowed to withdraw"); 23 | super.withdraw(payee); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contracts/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 | -------------------------------------------------------------------------------- /contracts/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 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/introspection/ERC1820Implementer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC1820Implementer.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | import "./IERC1820Implementer.sol"; 7 | 8 | /** 9 | * @dev Implementation of the {IERC1820Implementer} interface. 10 | * 11 | * Contracts may inherit from this and call {_registerInterfaceForAddress} to 12 | * declare their willingness to be implementers. 13 | * {IERC1820Registry-setInterfaceImplementer} should then be called for the 14 | * registration to be complete. 15 | */ 16 | contract ERC1820Implementer is IERC1820Implementer { 17 | bytes32 private constant _ERC1820_ACCEPT_MAGIC = keccak256("ERC1820_ACCEPT_MAGIC"); 18 | 19 | mapping(bytes32 => mapping(address => bool)) private _supportedInterfaces; 20 | 21 | /** 22 | * @dev See {IERC1820Implementer-canImplementInterfaceForAddress}. 23 | */ 24 | function canImplementInterfaceForAddress(bytes32 interfaceHash, address account) 25 | public 26 | view 27 | virtual 28 | override 29 | returns (bytes32) 30 | { 31 | return _supportedInterfaces[interfaceHash][account] ? _ERC1820_ACCEPT_MAGIC : bytes32(0x00); 32 | } 33 | 34 | /** 35 | * @dev Declares the contract as willing to be an implementer of 36 | * `interfaceHash` for `account`. 37 | * 38 | * See {IERC1820Registry-setInterfaceImplementer} and 39 | * {IERC1820Registry-interfaceHash}. 40 | */ 41 | function _registerInterfaceForAddress(bytes32 interfaceHash, address account) internal virtual { 42 | _supportedInterfaces[interfaceHash][account] = true; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /contracts/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 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/introspection/IERC1820Implementer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC1820Implementer.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface for an ERC1820 implementer, as defined in the 8 | * https://eips.ethereum.org/EIPS/eip-1820#interface-implementation-erc1820implementerinterface[EIP]. 9 | * Used by contracts that will be registered as implementers in the 10 | * {IERC1820Registry}. 11 | */ 12 | interface IERC1820Implementer { 13 | /** 14 | * @dev Returns a special value (`ERC1820_ACCEPT_MAGIC`) if this contract 15 | * implements `interfaceHash` for `account`. 16 | * 17 | * See {IERC1820Registry-setInterfaceImplementer}. 18 | */ 19 | function canImplementInterfaceForAddress(bytes32 interfaceHash, address account) external view returns (bytes32); 20 | } 21 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/math/Math.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/math/Math.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Standard math utilities missing in the Solidity language. 8 | */ 9 | library Math { 10 | /** 11 | * @dev Returns the largest of two numbers. 12 | */ 13 | function max(uint256 a, uint256 b) internal pure returns (uint256) { 14 | return a >= b ? a : b; 15 | } 16 | 17 | /** 18 | * @dev Returns the smallest of two numbers. 19 | */ 20 | function min(uint256 a, uint256 b) internal pure returns (uint256) { 21 | return a < b ? a : b; 22 | } 23 | 24 | /** 25 | * @dev Returns the average of two numbers. The result is rounded towards 26 | * zero. 27 | */ 28 | function average(uint256 a, uint256 b) internal pure returns (uint256) { 29 | // (a + b) / 2 can overflow. 30 | return (a & b) + (a ^ b) / 2; 31 | } 32 | 33 | /** 34 | * @dev Returns the ceiling of the division of two numbers. 35 | * 36 | * This differs from standard division with `/` in that it rounds up instead 37 | * of rounding down. 38 | */ 39 | function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { 40 | // (a + b - 1) / b can overflow on addition, so we distribute. 41 | return a / b + (a % b == 0 ? 0 : 1); 42 | } 43 | 44 | /** 45 | * @dev Returns the absolute unsigned value of a signed value. 46 | */ 47 | function abs(int256 n) internal pure returns (uint256) { 48 | unchecked { 49 | // must be unchecked in order to support `n = type(int256).min` 50 | return uint256(n >= 0 ? n : -n); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/math/SignedSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/math/SignedSafeMath.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Wrappers over Solidity's arithmetic operations. 8 | * 9 | * NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler 10 | * now has built in overflow checking. 11 | */ 12 | library SignedSafeMath { 13 | /** 14 | * @dev Returns the multiplication of two signed integers, reverting on 15 | * overflow. 16 | * 17 | * Counterpart to Solidity's `*` operator. 18 | * 19 | * Requirements: 20 | * 21 | * - Multiplication cannot overflow. 22 | */ 23 | function mul(int256 a, int256 b) internal pure returns (int256) { 24 | return a * b; 25 | } 26 | 27 | /** 28 | * @dev Returns the integer division of two signed integers. Reverts on 29 | * division by zero. The result is rounded towards zero. 30 | * 31 | * Counterpart to Solidity's `/` operator. 32 | * 33 | * Requirements: 34 | * 35 | * - The divisor cannot be zero. 36 | */ 37 | function div(int256 a, int256 b) internal pure returns (int256) { 38 | return a / b; 39 | } 40 | 41 | /** 42 | * @dev Returns the subtraction of two signed integers, reverting on 43 | * overflow. 44 | * 45 | * Counterpart to Solidity's `-` operator. 46 | * 47 | * Requirements: 48 | * 49 | * - Subtraction cannot overflow. 50 | */ 51 | function sub(int256 a, int256 b) internal pure returns (int256) { 52 | return a - b; 53 | } 54 | 55 | /** 56 | * @dev Returns the addition of two signed integers, reverting on 57 | * overflow. 58 | * 59 | * Counterpart to Solidity's `+` operator. 60 | * 61 | * Requirements: 62 | * 63 | * - Addition cannot overflow. 64 | */ 65 | function add(int256 a, int256 b) internal pure returns (int256) { 66 | return a + b; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /contracts/openzeppelin/utils/structs/BitMaps.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/structs/BitMaps.sol) 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential. 7 | * Largelly inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor]. 8 | */ 9 | library BitMaps { 10 | struct BitMap { 11 | mapping(uint256 => uint256) _data; 12 | } 13 | 14 | /** 15 | * @dev Returns whether the bit at `index` is set. 16 | */ 17 | function get(BitMap storage bitmap, uint256 index) internal view returns (bool) { 18 | uint256 bucket = index >> 8; 19 | uint256 mask = 1 << (index & 0xff); 20 | return bitmap._data[bucket] & mask != 0; 21 | } 22 | 23 | /** 24 | * @dev Sets the bit at `index` to the boolean `value`. 25 | */ 26 | function setTo( 27 | BitMap storage bitmap, 28 | uint256 index, 29 | bool value 30 | ) internal { 31 | if (value) { 32 | set(bitmap, index); 33 | } else { 34 | unset(bitmap, index); 35 | } 36 | } 37 | 38 | /** 39 | * @dev Sets the bit at `index`. 40 | */ 41 | function set(BitMap storage bitmap, uint256 index) internal { 42 | uint256 bucket = index >> 8; 43 | uint256 mask = 1 << (index & 0xff); 44 | bitmap._data[bucket] |= mask; 45 | } 46 | 47 | /** 48 | * @dev Unsets the bit at `index`. 49 | */ 50 | function unset(BitMap storage bitmap, uint256 index) internal { 51 | uint256 bucket = index >> 8; 52 | uint256 mask = 1 << (index & 0xff); 53 | bitmap._data[bucket] &= ~mask; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /contracts/revert.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma soliditypp >=0.8.0; 3 | pragma experimental Await; 4 | 5 | contract A { 6 | uint public data; 7 | function inc(uint a) external returns(uint) { 8 | data = a; // It will be reverted too. 9 | revert("something wrong"); 10 | return a + 1; 11 | } 12 | } 13 | 14 | contract B { 15 | A a; 16 | uint public b; 17 | 18 | constructor (address addr) { 19 | a = A(addr); 20 | } 21 | 22 | function assertB(uint _b) external view { 23 | require(b == _b); 24 | } 25 | 26 | function test() external { 27 | // NOTE: This assignment will NOT be reverted, 28 | // because the functions in Solidity++ don't have atomic semantics. 29 | // This function is split into two transactions from the await statement to execute, 30 | // the first one will success and the second one will revert. 31 | b = 1; 32 | 33 | await a.inc(1); // It will be reverted from here. 34 | 35 | b = 2; // It will be reverted too. 36 | } 37 | } -------------------------------------------------------------------------------- /contracts/transfer.solpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | // Demonstrate how to transfer tokens from / to a contract. 3 | 4 | pragma soliditypp >=0.8.0; 5 | 6 | contract A { 7 | event Received(address sender, vitetoken token, uint amount); 8 | 9 | constructor() payable {} 10 | 11 | // Receive Token function 12 | receive() external payable { 13 | address sender = msg.sender; 14 | vitetoken token = msg.token; 15 | uint amount = msg.value; 16 | 17 | logEvent(sender, token, amount); 18 | } 19 | 20 | function sendViteTo(address payable addr, uint amount) external { 21 | // send VITE to `addr` 22 | addr.transfer("tti_5649544520544f4b454e6e40", amount); 23 | } 24 | 25 | function logEvent(address sender, vitetoken token, uint amount) internal { 26 | emit Received(sender, token, amount); 27 | } 28 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examples", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "app.js", 6 | "scripts": { 7 | "test": "npx vuilder test --config test/vite.node.json", 8 | "run": "./node_modules/.bin/ts-node " 9 | }, 10 | "author": "charles@vite.org", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@types/chai": "^4.2.21", 14 | "@types/chai-like": "^1.1.1", 15 | "@types/chai-things": "^0.0.35", 16 | "chai-as-promised": "^7.1.1", 17 | "@types/mocha": "^9.0.0", 18 | "@types/node": "^14.6.2", 19 | "axios": "^0.21.4", 20 | "chai": "^4.3.4", 21 | "chai-like": "^1.1.1", 22 | "chai-things": "^0.2.0", 23 | "get-stream": "^6.0.1", 24 | "mocha": "^9.1.1", 25 | "nodemon": "^2.0.4", 26 | "ts-node": "^9.0.0", 27 | "typescript": "^4.0.2" 28 | }, 29 | "dependencies": { 30 | "@vite/vuilder": "^0.1.0-alpha.12", 31 | "@vite/solppc": "0.8.0-alpha.4" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/AsyncCall.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "./vite.config.json"; 5 | 6 | 7 | let provider: any; 8 | let deployer: any; 9 | 10 | describe('test AsyncCall', () => { 11 | before(async function() { 12 | provider = vite.newProvider("http://127.0.0.1:23456"); 13 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 14 | }); 15 | 16 | it('test contract', async () => { 17 | // compile 18 | const compiledContracts = await vite.compile('AsyncCall.solpp'); 19 | expect(compiledContracts).has.property('A'); 20 | expect(compiledContracts).has.property('B'); 21 | 22 | // deploy A 23 | let a = compiledContracts.A; 24 | a.setDeployer(deployer).setProvider(provider); 25 | await a.deploy({}); 26 | expect(a.address).to.be.a('string'); 27 | console.log(a.address); 28 | 29 | // deploy B 30 | let b = compiledContracts.B; 31 | b.setDeployer(deployer).setProvider(provider); 32 | await b.deploy({ 33 | params: [a.address!] 34 | }); 35 | expect(b.address).to.be.a('string'); 36 | console.log(b.address); 37 | 38 | // call b.invoke(a, 'world'); 39 | await b.call('invoke', [a.address!, 'world'], {}); 40 | 41 | vite.utils.sleep(1000); 42 | 43 | // check events 44 | let events = await b.getPastEvents('Received', {fromHeight: 0, toHeight: 0}); 45 | // console.log(events); 46 | expect(events).to.be.an('array'); 47 | expect(events[0]).has.property('returnValues'); 48 | expect(events[0].returnValues).has.property('data'); 49 | expect(events[0].returnValues.data).to.be.equals('hello world'); 50 | 51 | }); 52 | }); -------------------------------------------------------------------------------- /test/Await.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "./vite.config.json"; 5 | 6 | let provider: any; 7 | let deployer: any; 8 | 9 | describe('test Await', () => { 10 | before(async function() { 11 | provider = vite.newProvider("http://127.0.0.1:23456"); 12 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 13 | }); 14 | 15 | it('test Await', async () => { 16 | // compile 17 | const compiledContracts = await vite.compile('Await.solpp'); 18 | expect(compiledContracts).to.have.property('A'); 19 | expect(compiledContracts).to.have.property('B'); 20 | 21 | // deploy A 22 | const A = compiledContracts.A; 23 | A.setDeployer(deployer).setProvider(provider); 24 | await A.deploy({}); 25 | expect(A.address).to.be.a('string'); 26 | 27 | // deploy B 28 | const B = compiledContracts.B; 29 | B.setDeployer(deployer).setProvider(provider); 30 | await B.deploy({ 31 | params: [A.address!] 32 | }); 33 | expect(B.address).to.be.a('string'); 34 | 35 | // call B.test(); 36 | await B.call('test', ['123'], {}); 37 | 38 | // check B.b 39 | expect(await B.query('b', [])).to.be.deep.equal(['133']); 40 | 41 | }); 42 | }); -------------------------------------------------------------------------------- /test/HelloWorld.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "./vite.config.json"; 5 | 6 | let provider: any; 7 | let deployer: any; 8 | 9 | describe('test HelloWorld', () => { 10 | before(async function() { 11 | provider = vite.newProvider("http://127.0.0.1:23456"); 12 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 13 | // console.log('deployer', deployer.address); 14 | }); 15 | 16 | it('test contract', async () => { 17 | // compile 18 | const compiledContracts = await vite.compile('HelloWorld.solpp'); 19 | expect(compiledContracts).to.have.property('HelloWorld'); 20 | 21 | // deploy 22 | let helloWorld = compiledContracts.HelloWorld; 23 | helloWorld.setDeployer(deployer).setProvider(provider); 24 | await helloWorld.deploy({}); 25 | expect(helloWorld.address).to.be.a('string'); 26 | console.log(helloWorld.address); 27 | 28 | // check default value of data 29 | let result = await helloWorld.query('data', []); 30 | console.log('return', result); 31 | expect(result).to.be.an('array').with.lengthOf(1); 32 | expect(result![0]).to.be.equal('123'); 33 | 34 | // call HelloWorld.set(456); 35 | await helloWorld.call('set', ['456'], {}); 36 | 37 | // check value of data 38 | result = await helloWorld.query('data', []); 39 | console.log('return', result); 40 | expect(result).to.be.an('array').with.lengthOf(1); 41 | expect(result![0]).to.be.equal('456'); 42 | }); 43 | }); -------------------------------------------------------------------------------- /test/SyncCall.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "./vite.config.json"; 5 | 6 | let provider: any; 7 | let deployer: any; 8 | 9 | describe('test SyncCall', () => { 10 | before(async function() { 11 | provider = vite.newProvider("http://127.0.0.1:23456"); 12 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 13 | console.log('deployer', deployer.address); 14 | }); 15 | 16 | it('test contract', async () => { 17 | // compile 18 | const compiledContracts = await vite.compile('SyncCall.solpp'); 19 | expect(compiledContracts).to.have.property('A'); 20 | expect(compiledContracts).to.have.property('B'); 21 | expect(compiledContracts).to.have.property('C'); 22 | 23 | // deploy A 24 | let a = compiledContracts.A; 25 | a.setDeployer(deployer).setProvider(provider); 26 | await a.deploy({}); 27 | expect(a.address).to.be.a('string'); 28 | console.log(a.address); 29 | 30 | // deploy B 31 | let b = compiledContracts.B; 32 | b.setDeployer(deployer).setProvider(provider); 33 | await b.deploy({ 34 | params: [a.address!] 35 | }); 36 | expect(b.address).to.be.a('string'); 37 | console.log(b.address); 38 | 39 | // deploy C 40 | let c = compiledContracts.C; 41 | c.setDeployer(deployer).setProvider(provider); 42 | await c.deploy({ 43 | params: [a.address!, b.address!] 44 | }); 45 | expect(c.address).to.be.a('string'); 46 | console.log(c.address); 47 | 48 | // call C.f(1); 49 | await c.call('f', ['1'], {}); 50 | 51 | // check value of c 52 | let result = await c.query('c', []); 53 | console.log('return', result); 54 | expect(result).to.be.an('array').with.lengthOf(1); 55 | expect(result![0]).to.be.equal('1111'); 56 | }); 57 | }); -------------------------------------------------------------------------------- /test/callback.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "./vite.config.json"; 5 | 6 | let provider: any; 7 | let deployer: any; 8 | 9 | describe('test callback', () => { 10 | before(async function() { 11 | provider = vite.newProvider("http://127.0.0.1:23456"); 12 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 13 | }); 14 | 15 | it('test callback', async () => { 16 | // compile 17 | const compiledContracts = await vite.compile('callback.solpp'); 18 | expect(compiledContracts).to.have.property('A'); 19 | expect(compiledContracts).to.have.property('B'); 20 | 21 | // deploy A 22 | const A = compiledContracts.A; 23 | A.setDeployer(deployer).setProvider(provider); 24 | await A.deploy({}); 25 | expect(A.address).to.be.a('string'); 26 | 27 | // deploy B 28 | const B = compiledContracts.B; 29 | B.setDeployer(deployer).setProvider(provider); 30 | await B.deploy({ 31 | params: [A.address!] 32 | }); 33 | expect(B.address).to.be.a('string'); 34 | console.log(B.address) 35 | 36 | // call B.test(); 37 | await B.call('test', [], {}); 38 | 39 | await B.waitForHeight(3); 40 | 41 | // check B.data 42 | expect(await B.query('data', [])).to.be.deep.equal(['3']); 43 | }); 44 | }); -------------------------------------------------------------------------------- /test/constructor.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import { Account } from "@vite/vitejs-accountblock"; 5 | import config from "./vite.config.json"; 6 | 7 | let provider: any; 8 | let deployer: any; 9 | 10 | describe('test constructor', () => { 11 | before(async function() { 12 | provider = vite.newProvider("http://127.0.0.1:23456"); 13 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 14 | console.log('deployer', deployer.address); 15 | }); 16 | 17 | it('test contract', async () => { 18 | // compile 19 | const compiledContracts = await vite.compile('constructor.solpp'); 20 | expect(compiledContracts).to.have.property('Test'); 21 | 22 | // deploy 23 | let contract = compiledContracts.Test; 24 | contract.setDeployer(deployer).setProvider(provider); 25 | await contract.deploy({ 26 | params: ['111'] 27 | }); 28 | expect(contract.address).to.be.a('string'); 29 | console.log(contract.address); 30 | 31 | // check default value of data 32 | let result = await contract.query('data', []); 33 | 34 | console.log('return', result); 35 | expect(result).to.be.an('array').with.lengthOf(1); 36 | expect(result![0]).to.be.equal('111'); 37 | 38 | // call HelloWorld.set(456); 39 | await contract.call('set', ['456'], {}); 40 | 41 | // check value of data 42 | result = await contract.query('data', []); 43 | console.log('return', result); 44 | expect(result).to.be.an('array').with.lengthOf(1); 45 | expect(result![0]).to.be.equal('456'); 46 | }); 47 | }); -------------------------------------------------------------------------------- /test/cross_lang.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "./vite.config.json"; 5 | 6 | let provider: any; 7 | let deployer: any; 8 | 9 | describe('test cross lang features', () => { 10 | before(async function() { 11 | provider = vite.newProvider("http://127.0.0.1:23456"); 12 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 13 | }); 14 | 15 | it('test Strings.sol contract', async () => { 16 | // compile 17 | const compiledContracts = await vite.compile('cross_lang/Strings.sol'); 18 | expect(compiledContracts).to.have.property('Strings'); 19 | }); 20 | 21 | it('test Test.solpp contract', async () => { 22 | // compile 23 | const compiledContracts = await vite.compile('cross_lang/Test.solpp'); 24 | expect(compiledContracts).to.have.property('Test'); 25 | let test = compiledContracts.Test; 26 | 27 | // deploy 28 | test.setDeployer(deployer).setProvider(provider); 29 | await test.deploy({}); 30 | expect(test.address).to.be.a('string'); 31 | 32 | // toString 33 | expect(await test.query('toString', ['12345'])).to.be.deep.equal(['12345']); 34 | 35 | // toHexString 36 | expect(await test.query('toHexString', ['12345'])).to.be.deep.equal(['0x3039']); 37 | }); 38 | }); -------------------------------------------------------------------------------- /test/legacy/HelloWorld.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "../vite.config.json"; 5 | 6 | let provider: any; 7 | let deployer: any; 8 | 9 | describe('test HelloWorld', () => { 10 | before(async function() { 11 | provider = vite.newProvider("http://127.0.0.1:23456"); 12 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 13 | }); 14 | 15 | it('test contract', async () => { 16 | // compile 17 | const compiledContracts = await vite.compileLegacy('legacy/HelloWorld.solpp'); 18 | expect(compiledContracts).to.have.property('HelloWorld'); 19 | 20 | // deploy 21 | let helloWorld = compiledContracts.HelloWorld; 22 | helloWorld.setDeployer(deployer).setProvider(provider); 23 | await helloWorld.deploy({}); 24 | expect(helloWorld.address).to.be.a('string'); 25 | console.log(helloWorld.address); 26 | 27 | // check default value of data 28 | let result = await helloWorld.query('data', []); 29 | console.log('return', result); 30 | expect(result).to.be.an('array').with.lengthOf(1); 31 | expect(result![0]).to.be.equal('123'); 32 | 33 | // call HelloWorld.set(456); 34 | await helloWorld.call('set', ['456'], {}); 35 | 36 | // check value of data 37 | result = await helloWorld.query('data', []); 38 | console.log('return', result); 39 | expect(result).to.be.an('array').with.lengthOf(1); 40 | expect(result![0]).to.be.equal('456'); 41 | }); 42 | }); -------------------------------------------------------------------------------- /test/library.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "./vite.config.json"; 5 | 6 | let provider: any; 7 | let deployer: any; 8 | 9 | describe('test library', () => { 10 | before(async function() { 11 | provider = vite.newProvider("http://127.0.0.1:23456"); 12 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 13 | }); 14 | 15 | it('test library', async () => { 16 | // compile 17 | const compiledContracts = await vite.compile('library.solpp'); 18 | expect(compiledContracts).to.have.property('A'); 19 | expect(compiledContracts).to.have.property('L'); 20 | 21 | // deploy L 22 | let lib = compiledContracts.L; 23 | lib.setDeployer(deployer).setProvider(provider); 24 | await lib.deploy({}); 25 | expect(lib.address).to.be.a('string'); 26 | // console.log('L:', lib.address); 27 | 28 | // deploy A 29 | let a = compiledContracts.A; 30 | a.setDeployer(deployer).setProvider(provider); 31 | await a.deploy({libraries: {"library.solpp:L": lib.address}}); 32 | expect(a.address).to.be.a('string'); 33 | // console.log('A:', a.address); 34 | 35 | // call A.f(11); 36 | await a.call('f', ['11'], {}); 37 | 38 | // check value of data 39 | let result = await a.query('data', []); 40 | expect(result).to.be.deep.equal(['22']); 41 | }); 42 | }); -------------------------------------------------------------------------------- /test/magic.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | import config from "./vite.config.json"; 5 | 6 | let provider: any; 7 | let deployer: any; 8 | 9 | describe('test magic', () => { 10 | before(async function() { 11 | provider = vite.newProvider("http://127.0.0.1:23456"); 12 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 13 | }); 14 | 15 | it('test contract', async () => { 16 | // compile 17 | const compiledContracts = await vite.compile('magic.solpp'); 18 | expect(compiledContracts).to.have.property('Magic'); 19 | let magic = compiledContracts.Magic; 20 | 21 | // deploy by setting a random degree which is greater than 0 22 | magic.setDeployer(deployer).setProvider(provider); 23 | await magic.deploy({randomDegree: 1, responseLatency: 1}); 24 | expect(magic.address).to.be.a('string'); 25 | 26 | // blake2b 27 | expect(await magic.query('_blake2b', ['hello world'])).to.be.deep.equal(['256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610']); 28 | 29 | // keccak256 30 | expect(await magic.query('_keccak256', ['hello world'])).to.be.deep.equal(['47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad']); 31 | 32 | // sha256 33 | // @fixme: not work 34 | // expect(await magic.query('_sha256', ['hello world'])).to.be.deep.equal(['b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9']); 35 | 36 | // _ripemd160 37 | // @fixme: not work 38 | // expect(await magic.query('_ripemd160', ['hello world'])).to.be.deep.equal(['98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f']); 39 | 40 | // selector 41 | expect(await magic.query('_selector', [])).to.be.deep.equal(['7321116e']); 42 | 43 | // nextRandom 44 | // @fixme: not work 45 | 46 | // balance 47 | expect(await magic.query('balanceOfVITE', [])).to.be.deep.equal(['0']); 48 | 49 | // prev hash 50 | const block = await provider.request("ledger_getAccountBlockByHeight", magic.address, 1); 51 | expect(await magic.query('getPrevHash', [])).to.be.deep.equal([block.hash]); 52 | 53 | // account height 54 | expect(await magic.query('getAccountHeight', [])).to.be.deep.equal(['1']); 55 | 56 | }); 57 | }); -------------------------------------------------------------------------------- /test/revert.spec.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | var chai = require("chai"); 3 | var chaiAsPromised = require("chai-as-promised"); 4 | 5 | chai.use(chaiAsPromised); 6 | const expect = chai.expect; 7 | 8 | 9 | const vite = require('@vite/vuilder'); 10 | import config from "./vite.config.json"; 11 | 12 | let provider: any; 13 | let deployer: any; 14 | 15 | describe('test revert', () => { 16 | before(async function() { 17 | provider = vite.newProvider("http://127.0.0.1:23456"); 18 | deployer = vite.newAccount(config.networks.local.mnemonic, 0, provider); 19 | }); 20 | 21 | it('test revert', async () => { 22 | // compile 23 | const compiledContracts = await vite.compile('revert.solpp'); 24 | expect(compiledContracts).to.have.property('A'); 25 | expect(compiledContracts).to.have.property('B'); 26 | 27 | // deploy A 28 | let a = compiledContracts.A; 29 | a.setDeployer(deployer).setProvider(provider); 30 | await a.deploy({}); 31 | expect(a.address).to.be.a('string'); 32 | 33 | // deploy B 34 | let b = compiledContracts.B; 35 | b.setDeployer(deployer).setProvider(provider); 36 | await b.deploy({ 37 | params: [a.address!] 38 | }); 39 | expect(b.address).to.be.a('string'); 40 | 41 | // B.assert(1234) should revert 42 | await expect( 43 | b.call('assertB', ['1234'], {}) 44 | ).to.eventually.be.rejectedWith("revert"); 45 | 46 | // call B.test() 47 | await b.call('test', [], {}); 48 | 49 | // check state of B 50 | let result = await b.query('b', []); 51 | expect(result).to.be.deep.equal(['1']); 52 | 53 | // check state of A 54 | result = await a.query('data', []); 55 | // A.data remains 0 because that the receive transaction is reverted. 56 | expect(result).to.be.deep.equal(['0']); 57 | }); 58 | }); -------------------------------------------------------------------------------- /test/smoke.ts: -------------------------------------------------------------------------------- 1 | import { describe } from "mocha"; 2 | import { expect } from "chai"; 3 | const vite = require('@vite/vuilder'); 4 | 5 | let provider: any; 6 | 7 | describe("smoke test", () => { 8 | before(async function() { 9 | provider = vite.newProvider("http://127.0.0.1:23456"); 10 | }); 11 | 12 | it("checking height", async () => { 13 | 14 | for (let i = 0; i < 5; i++) { 15 | vite.mint(provider); 16 | let h = await vite.getSnapshotHeight(provider); 17 | console.log('snapshot height:', h); 18 | await vite.utils.sleep(1000); 19 | } 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /test/utils.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai" 2 | 3 | export abstract class CommonUtil { 4 | public static expectThrowsAsync = async (method: () => Promise, errorMessage?: string) => { 5 | let error: any 6 | try { 7 | await method() 8 | } 9 | catch (err) { 10 | error = err 11 | } 12 | expect(error).to.not.be.undefined 13 | if (errorMessage) { 14 | expect(error.message).to.equal(errorMessage) 15 | } 16 | return error 17 | } 18 | } -------------------------------------------------------------------------------- /test/vite.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "networks": { 3 | "local": { 4 | "http": "http://127.0.0.1:23456/", 5 | "ws": "http://127.0.0.1:23457/", 6 | "mnemonic": "record deliver increase organ subject whisper private tourist final athlete unit jacket arrow trick sweet chuckle direct print master post senior pluck whale taxi" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/vite.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "release": { 4 | "name": "gvite", 5 | "version": "v2.11.0", 6 | "http": "http://127.0.0.1:23456/" 7 | }, 8 | "beta": { 9 | "name": "gvite", 10 | "version": "v2.11.1", 11 | "http": "http://127.0.0.1:23456/" 12 | }, 13 | "nightly": { 14 | "name": "gvite", 15 | "version": "v2.11.3-nightly-202207201142", 16 | "http": "http://127.0.0.1:23456/" 17 | } 18 | }, 19 | "defaultNode": "nightly" 20 | } --------------------------------------------------------------------------------