From ff1e1f1d0a076d3d927e339aa38198d736d5a886 Mon Sep 17 00:00:00 2001 From: DemonBarber23 Date: Mon, 30 Sep 2024 01:28:45 -0400 Subject: [PATCH] Revert "Fix deployment (#452)" This reverts commit 7af70c8993a6f42973f520ae0752386a5032abe7. --- contracts/package.json | 7 ++++-- deploy/1_deploy_entrypoint.ts | 22 ++++++++++++++++-- deploy/2_deploy_SimpleAccountFactory.ts | 14 +++--------- gascalc/GasChecker.ts | 3 ++- hardhat.config.ts | 10 ++------- package.json | 6 +++-- reports/gas-checker.txt | 30 ++++++++++++------------- scripts/postpack-contracts-package.sh | 2 +- scripts/prepack-contracts-package.sh | 6 +++-- src/AASigner.ts | 19 +++++----------- test/testutils.ts | 2 +- 11 files changed, 63 insertions(+), 58 deletions(-) diff --git a/contracts/package.json b/contracts/package.json index bb1703cb7..d676c5133 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -1,7 +1,8 @@ { "name": "@account-abstraction/contracts", "description": "Account Abstraction (EIP 4337) contracts", - "version": "0.7.0", + "version": "0.6.0", + "main": "./dist/index.js", "scripts": { "prepack": "../scripts/prepack-contracts-package.sh", "postpack": "../scripts/postpack-contracts-package.sh" @@ -22,8 +23,10 @@ "bugs": { "url": "https://github.com/eth-infinitism/account-abstraction/issues" }, - "dependencies": { + "devDependencies": { "@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 f714da04d..8a44fd3bd 100644 --- a/deploy/1_deploy_entrypoint.ts +++ b/deploy/1_deploy_entrypoint.ts @@ -1,20 +1,38 @@ 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: process.env.SALT ?? true, - log: true + deterministicDeployment: 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 ca8ce0d28..33b81aec6 100644 --- a/deploy/2_deploy_SimpleAccountFactory.ts +++ b/deploy/2_deploy_SimpleAccountFactory.ts @@ -7,15 +7,12 @@ const deploySimpleAccountFactory: DeployFunction = async function (hre: HardhatR const from = await provider.getSigner().getAddress() const network = await provider.getNetwork() // only deploy on local test network. - - const forceDeployFactory = process.argv.join(' ').match(/simple-account-factory/) != null - - if (!forceDeployFactory && network.chainId !== 31337 && network.chainId !== 1337) { + if (network.chainId !== 31337 && network.chainId !== 1337) { return } const entrypoint = await hre.deployments.get('EntryPoint') - await hre.deployments.deploy( + const ret = await hre.deployments.deploy( 'SimpleAccountFactory', { from, args: [entrypoint.address], @@ -23,12 +20,7 @@ const deploySimpleAccountFactory: DeployFunction = async function (hre: HardhatR log: true, deterministicDeployment: true }) - - await hre.deployments.deploy('TestCounter', { - from, - deterministicDeployment: true, - log: true - }) + console.log('==SimpleAccountFactory addr=', ret.address) } export default deploySimpleAccountFactory diff --git a/gascalc/GasChecker.ts b/gascalc/GasChecker.ts index 45a21ff4e..8cdb9e938 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, hexConcat, parseEther } from 'ethers/lib/utils' +import { defaultAbiCoder, formatEther, hexConcat, parseEther } from 'ethers/lib/utils' import { AddressZero, checkForGeth, @@ -321,6 +321,7 @@ 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 4c499c2e2..b2c1a3fb0 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,6 +1,6 @@ import '@nomiclabs/hardhat-waffle' import '@typechain/hardhat' -import { HardhatUserConfig, task } from 'hardhat/config' +import { HardhatUserConfig } from 'hardhat/config' import 'hardhat-deploy' import '@nomiclabs/hardhat-etherscan' @@ -8,13 +8,7 @@ import 'solidity-coverage' import * as fs from 'fs' -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! +const mnemonicFileName = process.env.MNEMONIC_FILE ?? `${process.env.HOME}/.secret/testnet-mnemonic.txt` let mnemonic = 'test '.repeat(11) + 'junk' if (fs.existsSync(mnemonicFileName)) { mnemonic = fs.readFileSync(mnemonicFileName, 'ascii') } diff --git a/package.json b/package.json index 21f3550be..936f0f195 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "accountabstraction", - "version": "0.7.0", + "version": "0.6.0", "description": "ERC-4337 Account Abstraction Implementation", "scripts": { "clean": "rm -rf cache artifacts typechain typechain-types", @@ -19,7 +19,9 @@ "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": "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 " }, "keywords": [], "author": "", diff --git a/reports/gas-checker.txt b/reports/gas-checker.txt index 692322bf7..16e5f4349 100644 --- a/reports/gas-checker.txt +++ b/reports/gas-checker.txt @@ -16,40 +16,40 @@ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ simple - diff from previous │ 2 │ │ 42192 │ 13213 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple │ 10 │ 459921 │ │ ║ +║ simple │ 10 │ 459909 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple - diff from previous │ 11 │ │ 42223 │ 13244 ║ +║ simple - diff from previous │ 11 │ │ 42295 │ 13316 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ simple paymaster │ 1 │ 86113 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 2 │ │ 41024 │ 12045 ║ +║ simple paymaster with diff │ 2 │ │ 41072 │ 12093 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster │ 10 │ 455444 │ │ ║ +║ simple paymaster │ 10 │ 455732 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 11 │ │ 41088 │ 12109 ║ +║ simple paymaster with diff │ 11 │ │ 41040 │ 12061 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx 5k │ 1 │ 181026 │ │ ║ +║ big tx 5k │ 1 │ 181038 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx - diff from previous │ 2 │ │ 142714 │ 17490 ║ +║ big tx - diff from previous │ 2 │ │ 142678 │ 17454 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx 5k │ 10 │ 1465443 │ │ ║ +║ big tx 5k │ 10 │ 1465467 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ big tx - diff from previous │ 11 │ │ 142686 │ 17462 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 1 │ 87712 │ │ ║ +║ paymaster+postOp │ 1 │ 87736 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 2 │ │ 42671 │ 13692 ║ +║ paymaster+postOp with diff │ 2 │ │ 42659 │ 13680 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 10 │ 471754 │ │ ║ +║ paymaster+postOp │ 10 │ 471826 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 11 │ │ 42728 │ 13749 ║ +║ paymaster+postOp with diff │ 11 │ │ 42692 │ 13713 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster │ 1 │ 128777 │ │ ║ +║ token paymaster │ 1 │ 128765 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster with diff │ 2 │ │ 66386 │ 37407 ║ +║ token paymaster with diff │ 2 │ │ 66398 │ 37419 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ token paymaster │ 10 │ 726504 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster with diff │ 11 │ │ 66394 │ 37415 ║ +║ token paymaster with diff │ 11 │ │ 66454 │ 37475 ║ ╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝ diff --git a/scripts/postpack-contracts-package.sh b/scripts/postpack-contracts-package.sh index 6e1b23980..e5ad7bfcd 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 +rm -rf contracts/artifacts contracts/types contracts/dist diff --git a/scripts/prepack-contracts-package.sh b/scripts/prepack-contracts-package.sh index eac8c94b1..de4725d3d 100755 --- a/scripts/prepack-contracts-package.sh +++ b/scripts/prepack-contracts-package.sh @@ -11,7 +11,9 @@ yarn clean yarn compile cd contracts -rm -rf artifacts +rm -rf artifacts types dist mkdir -p artifacts -cp `find ../artifacts/contracts -type f | grep -v -E 'test|Test|dbg|bls|IOracle'` 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 diff --git a/src/AASigner.ts b/src/AASigner.ts index ca062c8e7..598a598ed 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 { decodeRevertReason, getAccountAddress, getAccountInitCode } from '../test/testutils' +import { getAccountAddress, getAccountInitCode } from '../test/testutils' import { fillAndSign, getUserOpHash, packUserOp } from '../test/UserOp' import { PackedUserOperation, UserOperation } from '../test/UserOperation' import { @@ -174,18 +174,11 @@ 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()) - 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 - } + const ret = await entryPoint.handleOps([packUserOp(userOp)], beneficiary ?? await signer.getAddress(), { + maxPriorityFeePerGas: userOp.maxPriorityFeePerGas, + maxFeePerGas: userOp.maxFeePerGas + }) + await ret.wait() return undefined } } diff --git a/test/testutils.ts b/test/testutils.ts index 3e18f7848..14370a7f2 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 { const create2factory = new Create2Factory(provider) - const addr = await create2factory.deploy(EntryPoint__factory.bytecode, process.env.SALT, process.env.COVERAGE != null ? 20e6 : 8e6) + const addr = await create2factory.deploy(EntryPoint__factory.bytecode, 0, process.env.COVERAGE != null ? 20e6 : 8e6) return EntryPoint__factory.connect(addr, provider.getSigner()) }