From 4c57fc8715494336d9ba6ab059542d51be7abb44 Mon Sep 17 00:00:00 2001 From: yorhodes Date: Thu, 7 Apr 2022 21:12:58 -0700 Subject: [PATCH] Upgrade to solidity ^0.8 --- .solhint.json | 2 +- contracts/AbcToken.sol | 1 + contracts/TransferRouter.sol | 50 +++++++++++++++++++++++++++--------- hardhat.config.ts | 25 +++++++++++------- interfaces/IAbcToken.sol | 2 +- package-lock.json | 49 +++++++++++++++-------------------- package.json | 12 ++++----- 7 files changed, 83 insertions(+), 58 deletions(-) diff --git a/.solhint.json b/.solhint.json index 0c60b09bb..0a512e65b 100644 --- a/.solhint.json +++ b/.solhint.json @@ -1,7 +1,7 @@ { "extends": "solhint:recommended", "rules": { - "compiler-version": ["error", "^0.6.11"], + "compiler-version": ["error", ">=0.6.0"], "func-visibility": ["warn", {"ignoreConstructors":true}], "not-rely-on-time": "off" } diff --git a/contracts/AbcToken.sol b/contracts/AbcToken.sol index 25b310a65..71c3d9c41 100644 --- a/contracts/AbcToken.sol +++ b/contracts/AbcToken.sol @@ -3,6 +3,7 @@ pragma solidity >=0.6.11; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import {TransferRouter} from "./TransferRouter.sol"; import {IAbcToken} from "../interfaces/IAbcToken.sol"; contract AbcToken is IAbcToken, ERC20 { diff --git a/contracts/TransferRouter.sol b/contracts/TransferRouter.sol index 1ecb83d2b..123ebe624 100644 --- a/contracts/TransferRouter.sol +++ b/contracts/TransferRouter.sol @@ -1,19 +1,45 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -pragma solidity >=0.6.11; - -import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +pragma solidity ^0.8.13; +// ============ Internal Imports ============ +import {IAbcToken} from "../interfaces/IAbcToken.sol"; +// ============ External Imports ============ import {Router} from "@abacus-network/core/contracts/router/Router.sol"; +import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {IAbcToken} from "../interfaces/IAbcToken.sol"; +contract TransferRouter is Router { + // The address of the token contract. + IERC20 public token; + + constructor(address _token) { + token = IERC20(_token); + } + + error SenderNotToken(); + + modifier onlyToken() { + if (msg.sender != address(token)) { + revert SenderNotToken(); + } + _; + } + + // Dispatches a message to a remote router to mint `amount` to `recipient`. + function transferRemote( + uint32 domain, + address sender, + address recipient, + uint256 amount + ) external onlyToken {} -contract AbcRouter is Router { - // The address of the token contract. - ERC20Mintable public token; + // Mints message.amount to message.recipient. + function handleTransferMessage(bytes memory message) internal {} - // Dispatches a message to a remote router to mint `amount` to `recipient`. - function transferRemote(uint32 domain, address sender, address recipient, uint256 amount) external onlyToken; + function handle( + uint32 _origin, + bytes32 _sender, + bytes calldata _message + ) external override { - // Mints message.amount to message.recipient. - function handleTransferMessage(bytes memory message) internal; - } \ No newline at end of file + } +} diff --git a/hardhat.config.ts b/hardhat.config.ts index 4e4a112c3..f672a152c 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,21 +1,28 @@ -import 'solidity-coverage'; -import '@typechain/hardhat'; +import '@abacus-network/hardhat'; import '@nomiclabs/hardhat-waffle'; +import '@typechain/hardhat'; import 'hardhat-gas-reporter'; -import '@abacus-network/hardhat'; +import 'solidity-coverage'; /** * @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: { - version: '0.7.6', - settings: { - optimizer: { - enabled: true, - runs: 999999, + compilers: [ + { + version: '0.8.13', + }, + { + version: '0.7.6', + // settings: { + // optimizer: { + // enabled: true, + // runs: 999999, + // }, + // }, }, - }, + ], }, gasReporter: { currency: 'USD', diff --git a/interfaces/IAbcToken.sol b/interfaces/IAbcToken.sol index 9dd0b386c..1d329ac93 100644 --- a/interfaces/IAbcToken.sol +++ b/interfaces/IAbcToken.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -pragma solidity >=0.6.11; +pragma solidity ^0.8.13; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/package-lock.json b/package-lock.json index bb0df8fb3..dbdc6c894 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,21 +9,21 @@ "version": "0.0.0", "license": "MIT OR Apache-2.0", "dependencies": { + "@abacus-network/apps": "file:../abacus-monorepo/solidity/apps", + "@abacus-network/core": "file:../abacus-monorepo/solidity/core", + "@abacus-network/hardhat": "file:../abacus-monorepo/typescript/hardhat", "@abacus-network/sdk": "file:../abacus-monorepo/typescript/sdk", "@abacus-network/utils": "file:../abacus-monorepo/typescript/utils", "@ethersproject/bignumber": "^5.5.0", "@ethersproject/bytes": "^5.5.0", + "@openzeppelin/contracts": "~4.5.0", + "@openzeppelin/contracts-upgradeable": "~4.5.0", + "@summa-tx/memview-sol": "^2.0.0", "ethers": "^5.4.7" }, "devDependencies": { - "@abacus-network/apps": "file:../abacus-monorepo/solidity/apps", - "@abacus-network/core": "file:../abacus-monorepo/solidity/core", - "@abacus-network/hardhat": "file:../abacus-monorepo/typescript/hardhat", "@nomiclabs/hardhat-ethers": "^2.0.1", "@nomiclabs/hardhat-waffle": "^2.0.1", - "@openzeppelin/contracts": "~3.4.2", - "@openzeppelin/contracts-upgradeable": "~3.4.2", - "@summa-tx/memview-sol": "^2.0.0", "@typechain/ethers-v5": "~7.0.0", "@typechain/hardhat": "^2.0.1", "@types/mocha": "^9.1.0", @@ -44,7 +44,6 @@ "../abacus-monorepo/solidity/apps": { "name": "@abacus-network/apps", "version": "0.0.0", - "dev": true, "license": "MIT OR Apache-2.0", "dependencies": { "@abacus-network/core": "file:../core", @@ -79,7 +78,6 @@ "../abacus-monorepo/solidity/core": { "name": "@abacus-network/core", "version": "0.0.1", - "dev": true, "license": "MIT OR Apache-2.0", "dependencies": { "@abacus-network/utils": "^0.0.5", @@ -111,7 +109,6 @@ "../abacus-monorepo/typescript/hardhat": { "name": "@abacus-network/hardhat", "version": "0.0.5", - "dev": true, "license": "MIT OR Apache-2.0", "dependencies": { "@abacus-network/core": "file:../../solidity/core", @@ -1619,16 +1616,14 @@ } }, "node_modules/@openzeppelin/contracts": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-3.4.2.tgz", - "integrity": "sha512-z0zMCjyhhp4y7XKAcDAi3Vgms4T2PstwBdahiO0+9NaGICQKjynK3wduSRplTgk4LXmoO1yfDGO5RbjKYxtuxA==", - "dev": true + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.5.0.tgz", + "integrity": "sha512-fdkzKPYMjrRiPK6K4y64e6GzULR7R7RwxSigHS8DDp7aWDeoReqsQI+cxHV1UuhAqX69L1lAaWDxenfP+xiqzA==" }, "node_modules/@openzeppelin/contracts-upgradeable": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-3.4.2.tgz", - "integrity": "sha512-mDlBS17ymb2wpaLcrqRYdnBAmP1EwqhOXMvqWk2c5Q1N1pm5TkiCtXM9Xzznh4bYsQBq0aIWEkFFE2+iLSN1Tw==", - "dev": true + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.5.2.tgz", + "integrity": "sha512-xgWZYaPlrEOQo3cBj97Ufiuv79SPd8Brh4GcFYhPgb6WvAq4ppz8dWKL6h+jLAK01rUqMRp/TS9AdXgAeNvCLA==" }, "node_modules/@resolver-engine/core": { "version": "0.3.3", @@ -1887,8 +1882,7 @@ "node_modules/@summa-tx/memview-sol": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@summa-tx/memview-sol/-/memview-sol-2.0.1.tgz", - "integrity": "sha512-GuaXBYG6/aIjKae3UJSBS61J/IuK/NTuk2IJBpGxytkxN1p3ZdRNIp8HQAIOVoCKZQtvzdPaBWokzCk/LakA/Q==", - "dev": true + "integrity": "sha512-GuaXBYG6/aIjKae3UJSBS61J/IuK/NTuk2IJBpGxytkxN1p3ZdRNIp8HQAIOVoCKZQtvzdPaBWokzCk/LakA/Q==" }, "node_modules/@szmarczak/http-timer": { "version": "1.1.2", @@ -25000,16 +24994,14 @@ } }, "@openzeppelin/contracts": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-3.4.2.tgz", - "integrity": "sha512-z0zMCjyhhp4y7XKAcDAi3Vgms4T2PstwBdahiO0+9NaGICQKjynK3wduSRplTgk4LXmoO1yfDGO5RbjKYxtuxA==", - "dev": true + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.5.0.tgz", + "integrity": "sha512-fdkzKPYMjrRiPK6K4y64e6GzULR7R7RwxSigHS8DDp7aWDeoReqsQI+cxHV1UuhAqX69L1lAaWDxenfP+xiqzA==" }, "@openzeppelin/contracts-upgradeable": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-3.4.2.tgz", - "integrity": "sha512-mDlBS17ymb2wpaLcrqRYdnBAmP1EwqhOXMvqWk2c5Q1N1pm5TkiCtXM9Xzznh4bYsQBq0aIWEkFFE2+iLSN1Tw==", - "dev": true + "version": "4.5.2", + "resolved": "https://registry.npmjs.org/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.5.2.tgz", + "integrity": "sha512-xgWZYaPlrEOQo3cBj97Ufiuv79SPd8Brh4GcFYhPgb6WvAq4ppz8dWKL6h+jLAK01rUqMRp/TS9AdXgAeNvCLA==" }, "@resolver-engine/core": { "version": "0.3.3", @@ -25234,8 +25226,7 @@ "@summa-tx/memview-sol": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@summa-tx/memview-sol/-/memview-sol-2.0.1.tgz", - "integrity": "sha512-GuaXBYG6/aIjKae3UJSBS61J/IuK/NTuk2IJBpGxytkxN1p3ZdRNIp8HQAIOVoCKZQtvzdPaBWokzCk/LakA/Q==", - "dev": true + "integrity": "sha512-GuaXBYG6/aIjKae3UJSBS61J/IuK/NTuk2IJBpGxytkxN1p3ZdRNIp8HQAIOVoCKZQtvzdPaBWokzCk/LakA/Q==" }, "@szmarczak/http-timer": { "version": "1.1.2", diff --git a/package.json b/package.json index c51266a38..20ee0acb3 100644 --- a/package.json +++ b/package.json @@ -20,17 +20,17 @@ "dependencies": { "@abacus-network/sdk": "file:../abacus-monorepo/typescript/sdk", "@abacus-network/utils": "file:../abacus-monorepo/typescript/utils", + "@abacus-network/hardhat": "file:../abacus-monorepo/typescript/hardhat", + "@abacus-network/core": "file:../abacus-monorepo/solidity/core", + "@abacus-network/apps": "file:../abacus-monorepo/solidity/apps", + "@summa-tx/memview-sol": "^2.0.0", + "@openzeppelin/contracts": "~4.5.0", + "@openzeppelin/contracts-upgradeable": "~4.5.0", "@ethersproject/bignumber": "^5.5.0", "@ethersproject/bytes": "^5.5.0", "ethers": "^5.4.7" }, "devDependencies": { - "@abacus-network/hardhat": "file:../abacus-monorepo/typescript/hardhat", - "@abacus-network/core": "file:../abacus-monorepo/solidity/core", - "@abacus-network/apps": "file:../abacus-monorepo/solidity/apps", - "@openzeppelin/contracts": "~3.4.2", - "@openzeppelin/contracts-upgradeable": "~3.4.2", - "@summa-tx/memview-sol": "^2.0.0", "@nomiclabs/hardhat-ethers": "^2.0.1", "@nomiclabs/hardhat-waffle": "^2.0.1", "@typechain/ethers-v5": "~7.0.0",