From 7716ab122365da4bce838c82b7cd8c3ed6d01b06 Mon Sep 17 00:00:00 2001 From: Michael Standen Date: Fri, 7 Jul 2023 12:11:56 +1200 Subject: [PATCH 1/4] Update deployment files --- hardhat.config.ts | 5 +-- networks/arbitrumGoerli.json | 22 ++++++++++ utils/config-loader.ts | 84 ++++++++++++++++++++---------------- 3 files changed, 72 insertions(+), 39 deletions(-) create mode 100644 networks/arbitrumGoerli.json diff --git a/hardhat.config.ts b/hardhat.config.ts index 13cf12de..80ed4a30 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -23,21 +23,20 @@ const config: HardhatUserConfig = { settings: { optimizer: { enabled: true, - runs: 500000 + runs: 500000, } } }, networks: { mainnet: networkConfig('mainnet'), ropsten: networkConfig('ropsten'), - rinkeby: networkConfig('rinkeby'), kovan: networkConfig('kovan'), goerli: networkConfig('goerli'), polygon: networkConfig('polygon'), polygonZkevm: networkConfig('polygon-zkevm'), mumbai: networkConfig('mumbai'), arbitrum: networkConfig('arbitrum'), - arbitrumTestnet: networkConfig('arbitrum-testnet'), + arbitrumGoerli: networkConfig('arbitrum-goerli'), arbitrumNova: networkConfig('arbitrum-nova'), optimism: networkConfig('optimism'), bnb: networkConfig('bnb'), diff --git a/networks/arbitrumGoerli.json b/networks/arbitrumGoerli.json new file mode 100644 index 00000000..d9273250 --- /dev/null +++ b/networks/arbitrumGoerli.json @@ -0,0 +1,22 @@ +[ + { + "contractName": "WalletFactory", + "address": "0xFaA5c0b14d1bED5C888Ca655B9a8A5911F78eF4A" + }, + { + "contractName": "MainModule", + "address": "0xfBf8f1A5E00034762D928f46d438B947f5d4065d" + }, + { + "contractName": "MainModuleUpgradable", + "address": "0x4222dcA3974E39A8b41c411FeDDE9b09Ae14b911" + }, + { + "contractName": "GuestModule", + "address": "0xfea230Ee243f88BC698dD8f1aE93F8301B6cdfaE" + }, + { + "contractName": "SequenceUtils", + "address": "0xdbbFa3cB3B087B64F4ef5E3D20Dda2488AA244e6" + } +] \ No newline at end of file diff --git a/utils/config-loader.ts b/utils/config-loader.ts index dc03d07c..319707ef 100644 --- a/utils/config-loader.ts +++ b/utils/config-loader.ts @@ -3,7 +3,23 @@ import * as path from 'path' import { HttpNetworkConfig } from 'hardhat/types' import { ethers } from 'ethers' -type EthereumNetworksTypes = 'rinkeby' | 'ropsten' | 'kovan' | 'goerli' | 'mainnet' | 'mumbai' | 'polygon' | 'arbitrum' | 'arbitrum-testnet' | 'arbitrum-nova' | 'optimism' | 'bnb' | 'gnosis' | 'polygon-zkevm' | 'avalanche' | 'bnb-testnet' | 'avalanche-fuji' +type EthereumNetworksTypes = + | 'mainnet' + | 'ropsten' + | 'kovan' + | 'goerli' + | 'polygon' + | 'polygon-zkevm' + | 'mumbai' + | 'arbitrum' + | 'arbitrum-goerli' + | 'arbitrum-nova' + | 'optimism' + | 'bnb' + | 'bnb-testnet' + | 'gnosis' + | 'avalanche' + | 'avalanche-fuji' export const getEnvConfig = (env: string) => { const envFile = path.resolve(__dirname, `../config/${env}.env`) @@ -34,12 +50,15 @@ export const networkRpcUrl = (network: EthereumNetworksTypes): string => { case 'polygon': return 'https://nodes.sequence.app/polygon' - case 'arbitrum-testnet': - return 'https://rinkeby.arbitrum.io/rpc' + case 'polygon-zkevm': + return 'https://zkevm-rpc.com' case 'arbitrum': return 'https://endpoints.omniatech.io/v1/arbitrum/one/public' - + + case 'arbitrum-goerli': + return 'https://goerli-rollup.arbitrum.io/rpc' + case 'arbitrum-nova': return 'https://nova.arbitrum.io/rpc' @@ -49,18 +68,15 @@ export const networkRpcUrl = (network: EthereumNetworksTypes): string => { case 'bnb': return 'https://bsc-dataseed3.binance.org' + case 'bnb-testnet': + return 'https://endpoints.omniatech.io/v1/bsc/testnet/public' + case 'gnosis': return 'https://gnosis-mainnet.public.blastapi.io' - case 'polygon-zkevm': - return 'https://zkevm-rpc.com' - case 'avalanche': return 'https://endpoints.omniatech.io/v1/avax/mainnet/public' - case 'bnb-testnet': - return 'https://endpoints.omniatech.io/v1/bsc/testnet/public' - case 'avalanche-fuji': return 'https://endpoints.omniatech.io/v1/avax/fuji/public' @@ -70,35 +86,33 @@ export const networkRpcUrl = (network: EthereumNetworksTypes): string => { } export const networkChainId = (network: EthereumNetworksTypes): number => { - const config = getEnvConfig('PROD') - switch (network) { - case 'mumbai': - return 80001 + case 'mainnet': + return 1 case 'ropsten': return 3 + case 'goerli': + return 5 + + case 'kovan': + return 42 + + case 'mumbai': + return 80001 + case 'polygon': return 137 - case 'arbitrum-testnet': - return 421611 + case 'polygon-zkevm': + return 1101 case 'arbitrum': return 42161 - case 'rinkeby': - return 4 - - case 'goerli': - return 5 - - case 'mainnet': - return 1 - - case 'kovan': - return 42 + case 'arbitrum-goerli': + return 421613 case 'arbitrum-nova': return 42170 @@ -109,30 +123,28 @@ export const networkChainId = (network: EthereumNetworksTypes): number => { case 'bnb': return 56 + case 'bnb-testnet': + return 97 + case 'gnosis': return 100 - case 'polygon-zkevm': - return 1101 - case 'avalanche': return 43114 - case 'bnb-testnet': - return 97 - case 'avalanche-fuji': return 43113 } } export const networkConfig = (network: EthereumNetworksTypes): HttpNetworkConfig & { etherscan?: string } => { - const config = getEnvConfig('PROD') + const prodConfig = getEnvConfig('PROD') + const networkConfig = getEnvConfig(network) return { url: networkRpcUrl(network), chainId: networkChainId(network), accounts: { - mnemonic: config['ETH_MNEMONIC'], + mnemonic: networkConfig['ETH_MNEMONIC'] ?? prodConfig['ETH_MNEMONIC'], initialIndex: 0, count: 10, path: `m/44'/60'/0'/0`, @@ -143,6 +155,6 @@ export const networkConfig = (network: EthereumNetworksTypes): HttpNetworkConfig gasMultiplier: networkGasMultiplier(network), timeout: 20000, httpHeaders: {}, - etherscan: config['ETHERSCAN'] + etherscan: networkConfig['ETHERSCAN'] ?? prodConfig['ETHERSCAN'] } } From c8fcb7e5d24abafa39bf0acbe7c4c002498bd64b Mon Sep 17 00:00:00 2001 From: Michael Standen Date: Fri, 7 Jul 2023 13:22:49 +1200 Subject: [PATCH 2/4] Add singleton deployer deployment to deploy script --- utils/deploy-contracts.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/utils/deploy-contracts.ts b/utils/deploy-contracts.ts index a9ca23db..975ed71e 100644 --- a/utils/deploy-contracts.ts +++ b/utils/deploy-contracts.ts @@ -10,7 +10,7 @@ import { Factory__factory } from '../gen/typechain' -import { ContractFactory, ethers } from 'ethers' +import { BigNumber, ContractFactory, ethers } from 'ethers' import fs from 'fs' const provider = hethers.provider @@ -37,6 +37,9 @@ const singletonFactoryFactory = { "type": "function" }] } +const singletonFactoryDeployTx = + '0xf9016c8085174876e8008303c4d88080b90154608060405234801561001057600080fd5b50610134806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634af63f0214602d575b600080fd5b60cf60048036036040811015604157600080fd5b810190602081018135640100000000811115605b57600080fd5b820183602082011115606c57600080fd5b80359060200191846001830284011164010000000083111715608d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550509135925060eb915050565b604080516001600160a01b039092168252519081900360200190f35b6000818351602085016000f5939250505056fea26469706673582212206b44f8a82cb6b156bfcc3dc6aadd6df4eefd204bc928a4397fd15dacf6d5320564736f6c634300060200331b83247000822470' +const singletonFactoryDeployer = '0xBb6e024b9cFFACB947A71991E386681B1Cd1477D' const prompt = ora() const attempVerify = async (name: string, _: new () => T, address: string, ...args: Parameters) => { @@ -67,8 +70,30 @@ type simpleContractFactory> = { attach: (address: string) => ethers.Contract } -const deploy = async , Y extends Array>(name: string, contract: new (...args: [signer: ethers.Signer]) => T, ...args: Y): Promise => { - const singletonFactory = new ethers.Contract(singletonFactoryFactory.address, singletonFactoryFactory.abi, signer) +const deploy = async , Y extends Array>( + name: string, + contract: new (...args: [signer: ethers.Signer]) => T, + ...args: Y +): Promise => { + const singletonFactory = new ethers.Contract(singletonFactoryFactory.address, singletonFactoryFactory.abi, signer) + + if (ethers.utils.arrayify(await provider.getCode(singletonFactory.address)).length <= 2) { + // Deploy singleton deployer + const o = ora().start(`Deploying singleton factory`) + const deployerBal = BigNumber.from('24700000000000000') + if ((await provider.getBalance(singletonFactoryDeployer)).lt(deployerBal)) { + o.info('Funding singleton factory deployer') + const tx = await signer.sendTransaction({ + to: singletonFactoryDeployer, + value: deployerBal, + }) + await tx.wait() + o.info('Funded. Deploying singleton factory') + } + const tx = await provider.sendTransaction(singletonFactoryDeployTx) + await tx.wait() + o.succeed(`Deployed singleton factory`) + } const o = ora().start(`Deploying ${name}`) const c = new contract(signer) From afc1d7bbff789a8e63b78745e88eccb53eb2f24a Mon Sep 17 00:00:00 2001 From: Michael Standen Date: Mon, 10 Jul 2023 09:33:57 +1200 Subject: [PATCH 3/4] Update contracts to match deployment on chain --- contracts/modules/commons/ModuleHooks.sol | 15 +-------------- contracts/modules/utils/RequireUtils.sol | 2 +- foundry_test/modules/utils/RequireUtils.t.sol | 6 +----- test/ERC165.spec.ts | 1 - 4 files changed, 3 insertions(+), 21 deletions(-) diff --git a/contracts/modules/commons/ModuleHooks.sol b/contracts/modules/commons/ModuleHooks.sol index 5d5a7b60..80996977 100644 --- a/contracts/modules/commons/ModuleHooks.sol +++ b/contracts/modules/commons/ModuleHooks.sol @@ -8,12 +8,11 @@ import "./ModuleStorage.sol"; import "./ModuleERC165.sol"; import "../../interfaces/receivers/IERC1155Receiver.sol"; -import "../../interfaces/receivers/IERC777Receiver.sol"; import "../../interfaces/receivers/IERC721Receiver.sol"; import "../../interfaces/receivers/IERC223Receiver.sol"; -contract ModuleHooks is IERC1155Receiver, IERC777Receiver, IERC721Receiver, IERC223Receiver, IModuleHooks, ModuleERC165, ModuleSelfAuth { +contract ModuleHooks is IERC1155Receiver, IERC721Receiver, IModuleHooks, ModuleERC165, ModuleSelfAuth { // HOOKS_KEY = keccak256("org.arcadeum.module.hooks.hooks"); bytes32 private constant HOOKS_KEY = bytes32(0xbe27a319efc8734e89e26ba4bc95f5c788584163b959f03fa04e2d7ab4b9a120); @@ -95,12 +94,6 @@ contract ModuleHooks is IERC1155Receiver, IERC777Receiver, IERC721Receiver, IERC return ModuleHooks.onERC1155BatchReceived.selector; } - /** - * @notice Handle the receipt of ERC777 token types. - */ - // solhint-disable-next-line no-empty-blocks - function tokensReceived(address, address, address, uint256, bytes calldata, bytes calldata) external override virtual {} - /** * @notice Handle the receipt of a single ERC721 token. * @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` @@ -109,11 +102,6 @@ contract ModuleHooks is IERC1155Receiver, IERC777Receiver, IERC721Receiver, IERC return ModuleHooks.onERC721Received.selector; } - /** - * @notice Handle the receipt of ERC223 tokens. - */ - function tokenFallback(address, uint256, bytes calldata) external override virtual {} // solhint-disable-line no-empty-blocks - /** * @notice Routes fallback calls through hooks */ @@ -147,7 +135,6 @@ contract ModuleHooks is IERC1155Receiver, IERC777Receiver, IERC721Receiver, IERC if ( _interfaceID == type(IModuleHooks).interfaceId || _interfaceID == type(IERC1155Receiver).interfaceId || - _interfaceID == type(IERC777Receiver).interfaceId || _interfaceID == type(IERC721Receiver).interfaceId || _interfaceID == type(IERC223Receiver).interfaceId ) { diff --git a/contracts/modules/utils/RequireUtils.sol b/contracts/modules/utils/RequireUtils.sol index c9a9eb00..957e2c94 100644 --- a/contracts/modules/utils/RequireUtils.sol +++ b/contracts/modules/utils/RequireUtils.sol @@ -13,7 +13,7 @@ contract RequireUtils { * @param _expiration Expiration to check */ function requireNonExpired(uint256 _expiration) external view { - require(block.timestamp <= _expiration, "RequireUtils#requireNonExpired: EXPIRED"); + require(block.timestamp < _expiration, "RequireUtils#requireNonExpired: EXPIRED"); } /** diff --git a/foundry_test/modules/utils/RequireUtils.t.sol b/foundry_test/modules/utils/RequireUtils.t.sol index b137b307..66acdbb4 100644 --- a/foundry_test/modules/utils/RequireUtils.t.sol +++ b/foundry_test/modules/utils/RequireUtils.t.sol @@ -54,16 +54,12 @@ contract SubModuleNonceTest is AdvTest { } function test_requireNonExpired(uint256 _expiration) external { - if (block.timestamp > _expiration) { + if (block.timestamp >= _expiration) { vm.expectRevert(bytes('RequireUtils#requireNonExpired: EXPIRED')); } requireUtils.requireNonExpired(_expiration); } - function test_requireNonExpiredWithExactBlock() external view { - requireUtils.requireNonExpired(block.timestamp); - } - function test_requireMinNonce(uint160 _space, uint96 _nonce, uint96 _nonceToCheck) external { imp.writeNonce(_space, _nonce); uint256 encoded = abi.decode(abi.encodePacked(_space, _nonceToCheck), (uint256)); diff --git a/test/ERC165.spec.ts b/test/ERC165.spec.ts index 3eed32c8..3cd718ff 100644 --- a/test/ERC165.spec.ts +++ b/test/ERC165.spec.ts @@ -6,7 +6,6 @@ import { expect, interfaceIdOf, randomHex } from './utils' const interfaceIds = [ 'IERC223Receiver', 'IERC721Receiver', - 'IERC777Receiver', 'IERC1155Receiver', 'IERC1271Wallet', 'IModuleAuth', From 3d5298a615c8c5cd9455f35e38837717dfb4b382 Mon Sep 17 00:00:00 2001 From: Michael Standen Date: Mon, 10 Jul 2023 11:56:53 +1200 Subject: [PATCH 4/4] Update package.json --- package.json | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 05f022fd..43d03744 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "private": true, "license": "Apache-2.0", "scripts": { - "postinstall": "yarn build", "build": "yarn compile && yarn adapter", "compile": "hardhat --max-memory 4096 compile", "clean": "rimraf artifacts && rimraf cache", @@ -16,15 +15,19 @@ "release": "yarn publish src", "lint": "yarn lint:ts && yarn lint:sol", "lint:fix": "yarn lint:ts:fix && yarn lint:sol:fix", - "lint:sol": "solhint './contracts/**/*.sol'", - "lint:sol:fix": "solhint './contracts/**/*.sol' --fix", - "lint:ts": "eslint -c .eslintrc.js './**/*.ts'", - "lint:ts:fix": "eslint -c .eslintrc.js --fix './**/*.ts'", + "lint:sol": "solhint \"./contracts/**/*.sol\"", + "lint:sol:fix": "solhint \"./contracts/**/*.sol\" --fix", + "lint:ts": "eslint -c .eslintrc.js \"./**/*.ts\"", + "lint:ts:fix": "eslint -c .eslintrc.js --fix \"./**/*.ts\"", "format": "prettier --write ./**/*.ts", - "adapter": "rimraf gen && typechain --target ethers-v5 --out-dir gen/typechain './artifacts/contracts/**/*[^dbg].json'" + "adapter": "typechain --target ethers-v5 --out-dir gen/typechain \"./artifacts/contracts/**/*[^dbg].json\"" }, - "main": "gen/adapter/index.js", "types": "gen/typechain/index.ts", + "files": [ + "./contracts/**/*.sol", + "!**/*Mock*", + "./gen/typechain" + ], "husky": { "hooks": { "pre-commit": "yarn lint", @@ -37,7 +40,6 @@ "@nomiclabs/hardhat-truffle5": "^2.0.0", "@nomiclabs/hardhat-web3": "^2.0.0", "@tenderly/hardhat-tenderly": "^1.0.11", - "@typechain/ethers-v5": "^7.0.1", "@types/chai-as-promised": "^7.1.0", "@types/chai-string": "^1.4.1", "@types/mocha": "^8.2.1", @@ -56,7 +58,6 @@ "eslint-plugin-import": "^2.22.0", "eslint-plugin-prettier": "^3.3.1", "ethereum-waffle": "^3.4.4", - "ethers": "^5.7.2", "ganache-cli": "6.12.2", "hardhat": "^2.16.1", "hardhat-gas-reporter": "1.0.4", @@ -66,6 +67,7 @@ "scrypt": "github:barrysteyn/node-scrypt#fb60a8d3c158fe115a624b5ffa7480f3a24b03fb", "solhint": "^3.4.1", "solidity-coverage": "0.8.3", + "threads": "^1.7.0", "ts-node": "^10.9.1", "typechain": "^8.1.0", "typescript": "^4.7.4", @@ -81,7 +83,8 @@ "extra": "" }, "dependencies": { - "keccak256": "^1.0.6", - "threads": "^1.7.0" + "@typechain/ethers-v5": "^7.0.1", + "ethers": "^5.7.2", + "keccak256": "^1.0.6" } }