diff --git a/contracts/package.json b/contracts/package.json index d676c5133..bb1703cb7 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -1,8 +1,7 @@ { "name": "@account-abstraction/contracts", "description": "Account Abstraction (EIP 4337) contracts", - "version": "0.6.0", - "main": "./dist/index.js", + "version": "0.7.0", "scripts": { "prepack": "../scripts/prepack-contracts-package.sh", "postpack": "../scripts/postpack-contracts-package.sh" @@ -23,10 +22,8 @@ "bugs": { "url": "https://github.com/eth-infinitism/account-abstraction/issues" }, - "devDependencies": { + "dependencies": { "@openzeppelin/contracts": "^5.0.0", - "@nomiclabs/hardhat-ethers": "^2.0.2", - "@nomiclabs/hardhat-waffle": "^2.0.1", "@uniswap/v3-periphery": "^1.4.3" } } diff --git a/deploy/1_deploy_entrypoint.ts b/deploy/1_deploy_entrypoint.ts index 8a44fd3bd..f714da04d 100644 --- a/deploy/1_deploy_entrypoint.ts +++ b/deploy/1_deploy_entrypoint.ts @@ -1,38 +1,20 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types' import { DeployFunction } from 'hardhat-deploy/types' -import { Create2Factory } from '../src/Create2Factory' import { ethers } from 'hardhat' const deployEntryPoint: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const provider = ethers.provider const from = await provider.getSigner().getAddress() - await new Create2Factory(ethers.provider).deployFactory() const ret = await hre.deployments.deploy( 'EntryPoint', { from, args: [], gasLimit: 6e6, - deterministicDeployment: true + deterministicDeployment: process.env.SALT ?? true, + log: true }) console.log('==entrypoint addr=', ret.address) - - const entryPointAddress = ret.address - const w = await hre.deployments.deploy( - 'SimpleAccount', { - from, - args: [entryPointAddress], - gasLimit: 2e6, - deterministicDeployment: true - }) - - console.log('== wallet=', w.address) - - const t = await hre.deployments.deploy('TestCounter', { - from, - deterministicDeployment: true - }) - console.log('==testCounter=', t.address) } export default deployEntryPoint diff --git a/deploy/2_deploy_SimpleAccountFactory.ts b/deploy/2_deploy_SimpleAccountFactory.ts index 33b81aec6..ca8ce0d28 100644 --- a/deploy/2_deploy_SimpleAccountFactory.ts +++ b/deploy/2_deploy_SimpleAccountFactory.ts @@ -7,12 +7,15 @@ const deploySimpleAccountFactory: DeployFunction = async function (hre: HardhatR const from = await provider.getSigner().getAddress() const network = await provider.getNetwork() // only deploy on local test network. - if (network.chainId !== 31337 && network.chainId !== 1337) { + + const forceDeployFactory = process.argv.join(' ').match(/simple-account-factory/) != null + + if (!forceDeployFactory && network.chainId !== 31337 && network.chainId !== 1337) { return } const entrypoint = await hre.deployments.get('EntryPoint') - const ret = await hre.deployments.deploy( + await hre.deployments.deploy( 'SimpleAccountFactory', { from, args: [entrypoint.address], @@ -20,7 +23,12 @@ const deploySimpleAccountFactory: DeployFunction = async function (hre: HardhatR log: true, deterministicDeployment: true }) - console.log('==SimpleAccountFactory addr=', ret.address) + + await hre.deployments.deploy('TestCounter', { + from, + deterministicDeployment: true, + log: true + }) } export default deploySimpleAccountFactory diff --git a/gascalc/GasChecker.ts b/gascalc/GasChecker.ts index 8cdb9e938..45a21ff4e 100644 --- a/gascalc/GasChecker.ts +++ b/gascalc/GasChecker.ts @@ -1,6 +1,6 @@ // calculate gas usage of different bundle sizes import '../test/aa.init' -import { defaultAbiCoder, formatEther, hexConcat, parseEther } from 'ethers/lib/utils' +import { defaultAbiCoder, hexConcat, parseEther } from 'ethers/lib/utils' import { AddressZero, checkForGeth, @@ -321,7 +321,6 @@ export class GasCheckCollector { const bal = await getBalance(ethersSigner.getAddress()) if (bal.gt(parseEther('100000000'))) { - console.log('bal=', formatEther(bal)) console.log('DONT use geth miner.. use account 2 instead') await checkForGeth() ethersSigner = ethers.provider.getSigner(2) diff --git a/hardhat.config.ts b/hardhat.config.ts index b2c1a3fb0..4c499c2e2 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,6 +1,6 @@ import '@nomiclabs/hardhat-waffle' import '@typechain/hardhat' -import { HardhatUserConfig } from 'hardhat/config' +import { HardhatUserConfig, task } from 'hardhat/config' import 'hardhat-deploy' import '@nomiclabs/hardhat-etherscan' @@ -8,7 +8,13 @@ import 'solidity-coverage' import * as fs from 'fs' -const mnemonicFileName = process.env.MNEMONIC_FILE ?? `${process.env.HOME}/.secret/testnet-mnemonic.txt` +const SALT = '0x90d8084deab30c2a37c45e8d47f49f2f7965183cb6990a98943ef94940681de3' +process.env.SALT = process.env.SALT ?? SALT + +task('deploy', 'Deploy contracts') + .addFlag('simpleAccountFactory', 'deploy sample factory (by default, enabled only on localhost)') + +const mnemonicFileName = process.env.MNEMONIC_FILE! let mnemonic = 'test '.repeat(11) + 'junk' if (fs.existsSync(mnemonicFileName)) { mnemonic = fs.readFileSync(mnemonicFileName, 'ascii') } diff --git a/package.json b/package.json index 936f0f195..21f3550be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "accountabstraction", - "version": "0.6.0", + "version": "0.7.0", "description": "ERC-4337 Account Abstraction Implementation", "scripts": { "clean": "rm -rf cache artifacts typechain typechain-types", @@ -19,9 +19,7 @@ "ci": "yarn compile && hardhat test && yarn run runop", "ci-gas-calc": "yarn gas-calc && yarn check-gas-reports", "check-gas-reports": "./scripts/check-gas-reports", - "runop": "hardhat run src/runop.ts ", - "runop-goerli": "AA_URL=https://account-abstraction-goerli.nethermind.io yarn runop --network goerli", - "runop3": "hardhat run src/runop3.ts " + "runop": "hardhat run src/runop.ts " }, "keywords": [], "author": "", diff --git a/reports/gas-checker.txt b/reports/gas-checker.txt index 16e5f4349..692322bf7 100644 --- a/reports/gas-checker.txt +++ b/reports/gas-checker.txt @@ -16,40 +16,40 @@ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ simple - diff from previous │ 2 │ │ 42192 │ 13213 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple │ 10 │ 459909 │ │ ║ +║ simple │ 10 │ 459921 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple - diff from previous │ 11 │ │ 42295 │ 13316 ║ +║ simple - diff from previous │ 11 │ │ 42223 │ 13244 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ simple paymaster │ 1 │ 86113 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 2 │ │ 41072 │ 12093 ║ +║ simple paymaster with diff │ 2 │ │ 41024 │ 12045 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster │ 10 │ 455732 │ │ ║ +║ simple paymaster │ 10 │ 455444 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 11 │ │ 41040 │ 12061 ║ +║ simple paymaster with diff │ 11 │ │ 41088 │ 12109 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx 5k │ 1 │ 181038 │ │ ║ +║ big tx 5k │ 1 │ 181026 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx - diff from previous │ 2 │ │ 142678 │ 17454 ║ +║ big tx - diff from previous │ 2 │ │ 142714 │ 17490 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx 5k │ 10 │ 1465467 │ │ ║ +║ big tx 5k │ 10 │ 1465443 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ big tx - diff from previous │ 11 │ │ 142686 │ 17462 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 1 │ 87736 │ │ ║ +║ paymaster+postOp │ 1 │ 87712 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 2 │ │ 42659 │ 13680 ║ +║ paymaster+postOp with diff │ 2 │ │ 42671 │ 13692 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 10 │ 471826 │ │ ║ +║ paymaster+postOp │ 10 │ 471754 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 11 │ │ 42692 │ 13713 ║ +║ paymaster+postOp with diff │ 11 │ │ 42728 │ 13749 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster │ 1 │ 128765 │ │ ║ +║ token paymaster │ 1 │ 128777 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster with diff │ 2 │ │ 66398 │ 37419 ║ +║ token paymaster with diff │ 2 │ │ 66386 │ 37407 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ token paymaster │ 10 │ 726504 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster with diff │ 11 │ │ 66454 │ 37475 ║ +║ token paymaster with diff │ 11 │ │ 66394 │ 37415 ║ ╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝ diff --git a/scripts/postpack-contracts-package.sh b/scripts/postpack-contracts-package.sh index e5ad7bfcd..6e1b23980 100755 --- a/scripts/postpack-contracts-package.sh +++ b/scripts/postpack-contracts-package.sh @@ -2,5 +2,5 @@ #echo postpack for "contracts" package cd `dirname $0`/.. pwd -rm -rf contracts/artifacts contracts/types contracts/dist +rm -rf contracts/artifacts diff --git a/scripts/prepack-contracts-package.sh b/scripts/prepack-contracts-package.sh index de4725d3d..eac8c94b1 100755 --- a/scripts/prepack-contracts-package.sh +++ b/scripts/prepack-contracts-package.sh @@ -11,9 +11,7 @@ yarn clean yarn compile cd contracts -rm -rf artifacts types dist +rm -rf artifacts mkdir -p artifacts -cp `find ../artifacts/contracts -type f | grep -v -E 'Test|dbg|bls|IOracle'` artifacts/ -npx typechain --target ethers-v5 --out-dir types artifacts/** -npx tsc index.ts -d --outDir dist +cp `find ../artifacts/contracts -type f | grep -v -E 'test|Test|dbg|bls|IOracle'` artifacts/ diff --git a/src/AASigner.ts b/src/AASigner.ts index 598a598ed..ca062c8e7 100644 --- a/src/AASigner.ts +++ b/src/AASigner.ts @@ -5,7 +5,7 @@ import { Deferrable, resolveProperties } from '@ethersproject/properties' import { BaseProvider, Provider, TransactionRequest } from '@ethersproject/providers' import { BigNumber, Bytes, ethers, Event, Signer } from 'ethers' import { clearInterval } from 'timers' -import { getAccountAddress, getAccountInitCode } from '../test/testutils' +import { decodeRevertReason, getAccountAddress, getAccountInitCode } from '../test/testutils' import { fillAndSign, getUserOpHash, packUserOp } from '../test/UserOp' import { PackedUserOperation, UserOperation } from '../test/UserOperation' import { @@ -174,11 +174,18 @@ export function localUserOpSender (entryPointAddress: string, signer: Signer, be } const gasLimit = BigNumber.from(userOp.preVerificationGas).add(userOp.verificationGasLimit).add(userOp.callGasLimit) console.log('calc gaslimit=', gasLimit.toString()) - const ret = await entryPoint.handleOps([packUserOp(userOp)], beneficiary ?? await signer.getAddress(), { - maxPriorityFeePerGas: userOp.maxPriorityFeePerGas, - maxFeePerGas: userOp.maxFeePerGas - }) - await ret.wait() + try { + const ret = await entryPoint.handleOps([packUserOp(userOp)], beneficiary ?? await signer.getAddress(), { + maxPriorityFeePerGas: userOp.maxPriorityFeePerGas, + maxFeePerGas: userOp.maxFeePerGas, + gasLimit: 1e6 + + }) + await ret.wait() + } catch (e: any) { + console.log('decoded err=', decodeRevertReason(e)) + throw e + } return undefined } } diff --git a/test/testutils.ts b/test/testutils.ts index 14370a7f2..3e18f7848 100644 --- a/test/testutils.ts +++ b/test/testutils.ts @@ -275,7 +275,7 @@ export async function checkForBannedOps (txHash: string, checkPaymaster: boolean export async function deployEntryPoint (provider = ethers.provider): Promise<EntryPoint> { const create2factory = new Create2Factory(provider) - const addr = await create2factory.deploy(EntryPoint__factory.bytecode, 0, process.env.COVERAGE != null ? 20e6 : 8e6) + const addr = await create2factory.deploy(EntryPoint__factory.bytecode, process.env.SALT, process.env.COVERAGE != null ? 20e6 : 8e6) return EntryPoint__factory.connect(addr, provider.getSigner()) }