Skip to content

Commit

Permalink
fix deployment of v0.7
Browse files Browse the repository at this point in the history
- 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 committed Feb 19, 2024
1 parent 8086e7b commit c085074
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 46 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"
}
}
23 changes: 3 additions & 20 deletions deploy/1_deploy_entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
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()

console.log('from=', from, 'bal=', await provider.getBalance(from))
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
7 changes: 5 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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`
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
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 c085074

Please sign in to comment.