├── .gitignore ├── package.json ├── README.md └── patches └── @openzeppelin+contracts+3.4.1.patch /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@thesatoshicompany/optimism-openzeppelin-compat", 3 | "version": "1.0.3", 4 | "description": "OpenZeppelin patch module for Optimism", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/derekbar90/optimism-openzeppelin-compat.git" 12 | }, 13 | "author": "Derek Barrera (derekbarrera@gmail.com)", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/derekbar90/optimism-openzeppelin-compat/issues" 17 | }, 18 | "homepage": "https://github.com/derekbar90/optimism-openzeppelin-compat#readme", 19 | "dependencies": { 20 | "patch-package": "^6.4.7" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # optimism-openzeppelin-compat 3 | [![NPM Package](https://img.shields.io/npm/v/@thesatoshicompany/optimism-openzeppelin-compat/latest?label=%40thesatoshicompany%2Foptimism-openzeppelin-compat&logo=npm)](https://www.npmjs.com/package/@thesatoshicompany/optimism-openzeppelin-compat) 4 | 5 | This repo contains patches needed to use the OpenZeppelin contracts with Optimism L2. 6 | 7 | > Example: When using Optimism ETH is not supported and instead WETH 8 | > must be used. When using OpenZeppelin Address contract via ERC20, 9 | > there are balance checks for ETH and thus the compilation fails due to 10 | > an unsupported OPCODE. This patches these issues and allows for 11 | > seamless development. 12 | 13 | ## Installation 14 | 15 | Use the following command to install: 16 | 17 | ``` 18 | npm i --save @thesatoshicompany/optimism-openzeppelin-compat 19 | ``` 20 | 21 | Add the following to the package.json scripts section: 22 | 23 | ``` 24 | "scripts": { 25 | + "postinstall": "patch-package --patch-dir node_modules/@thesatoshicompany/optimism-openzeppelin-compat/patches" 26 | }, 27 | ``` 28 | 29 | `Note: Post install script is needed because this package does not patch files on install automatically. It only provides the appropriate patches and the needed module to apply them.` 30 | 31 | `This was a design choice so full control is left to the consumer of the module for if and when they are applied.` 32 | 33 | ## Supported OpenZeppelin Versions 34 | 35 | v3.4.1 36 | 37 | ## Have an additional patch which should be included? 38 | 39 | Provide a PR and a review will happen so that it can be included. -------------------------------------------------------------------------------- /patches/@openzeppelin+contracts+3.4.1.patch: -------------------------------------------------------------------------------- 1 | diff --git a/node_modules/@openzeppelin/contracts/utils/Address.sol b/node_modules/@openzeppelin/contracts/utils/Address.sol 2 | index 42a9dc1..7fdeabe 100644 3 | --- a/node_modules/@openzeppelin/contracts/utils/Address.sol 4 | +++ b/node_modules/@openzeppelin/contracts/utils/Address.sol 5 | @@ -1,6 +1,7 @@ 6 | // SPDX-License-Identifier: MIT 7 | 8 | pragma solidity >=0.6.2 <0.8.0; 9 | +import "../token/ERC20/IERC20.sol"; 10 | 11 | /** 12 | * @dev Collection of functions related to the address type 13 | @@ -34,6 +35,11 @@ library Address { 14 | return size > 0; 15 | } 16 | 17 | + function WETHBalance(address _addressToQuery) view public returns (uint) { 18 | + return IERC20(0x4200000000000000000000000000000000000006).balanceOf(_addressToQuery); 19 | + } 20 | + 21 | + 22 | /** 23 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 24 | * `recipient`, forwarding all available gas and reverting on errors. 25 | @@ -51,7 +57,7 @@ library Address { 26 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 27 | */ 28 | function sendValue(address payable recipient, uint256 amount) internal { 29 | - require(address(this).balance >= amount, "Address: insufficient balance"); 30 | + require(WETHBalance(address(this)) >= amount, "Address: insufficient balance"); 31 | 32 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 33 | (bool success, ) = recipient.call{ value: amount }(""); 34 | @@ -112,7 +118,7 @@ library Address { 35 | * _Available since v3.1._ 36 | */ 37 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 38 | - require(address(this).balance >= value, "Address: insufficient balance for call"); 39 | + require(WETHBalance(address(this)) >= value, "Address: insufficient balance for call"); 40 | require(isContract(target), "Address: call to non-contract"); 41 | 42 | // solhint-disable-next-line avoid-low-level-calls 43 | --------------------------------------------------------------------------------