Skip to content

Commit

Permalink
Fix deployment (#452)
Browse files Browse the repository at this point in the history
* fix deployment of v0.7
- new package version
- move test contracts to separate deployment script, deploy only on testnet
- add deploy param --simpleAccountFactory
- use env SALT
- remove typechain output from contracts package
  • Loading branch information
drortirosh authored Feb 22, 2024
1 parent 8086e7b commit 7af70c8
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 63 deletions.
7 changes: 2 additions & 5 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
}
}
22 changes: 2 additions & 20 deletions deploy/1_deploy_entrypoint.ts
Original file line number Diff line number Diff line change
@@ -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
14 changes: 11 additions & 3 deletions deploy/2_deploy_SimpleAccountFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@ 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],
gasLimit: 6e6,
log: true,
deterministicDeployment: true
})
console.log('==SimpleAccountFactory addr=', ret.address)

await hre.deployments.deploy('TestCounter', {
from,
deterministicDeployment: true,
log: true
})
}

export default deploySimpleAccountFactory
3 changes: 1 addition & 2 deletions gascalc/GasChecker.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
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'

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') }

Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": "",
Expand Down
30 changes: 15 additions & 15 deletions reports/gas-checker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,40 @@
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 2 │ │ 42192 │ 13213 ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple │ 10 │ 459909 │ │ ║
║ simple │ 10 │ 459921 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple - diff from previous │ 11 │ │ 4229513316
║ simple - diff from previous │ 11 │ │ 4222313244
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 1 │ 86113 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 2 │ │ 4107212093
║ simple paymaster with diff │ 2 │ │ 4102412045
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster │ 10 │ 455732 │ │ ║
║ simple paymaster │ 10 │ 455444 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ simple paymaster with diff │ 11 │ │ 4104012061
║ simple paymaster with diff │ 11 │ │ 4108812109
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx 5k │ 1 │ 181038 │ │ ║
║ big tx 5k │ 1 │ 181026 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ big tx - diff from previous │ 2 │ │ 14267817454
║ big tx - diff from previous │ 2 │ │ 14271417490
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ 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 │ │ 4265913680
║ paymaster+postOp with diff │ 2 │ │ 4267113692
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp │ 10 │ 471826 │ │ ║
║ paymaster+postOp │ 10 │ 471754 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ paymaster+postOp with diff │ 11 │ │ 4269213713
║ paymaster+postOp with diff │ 11 │ │ 4272813749
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 1 │ 128765 │ │ ║
║ token paymaster │ 1 │ 128777 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 2 │ │ 6639837419
║ token paymaster with diff │ 2 │ │ 6638637407
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster │ 10 │ 726504 │ │ ║
╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢
║ token paymaster with diff │ 11 │ │ 6645437475
║ token paymaster with diff │ 11 │ │ 6639437415
╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝

2 changes: 1 addition & 1 deletion scripts/postpack-contracts-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 2 additions & 4 deletions scripts/prepack-contracts-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
19 changes: 13 additions & 6 deletions src/AASigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/testutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down

0 comments on commit 7af70c8

Please sign in to comment.