1- import { BigNumber , Bytes , ethers , Event , Signer } from 'ethers '
2- import { zeroAddress } from 'ethereumjs-util '
3- import { BaseProvider , Provider , TransactionRequest } from '@ethersproject/providers '
1+ import { TransactionResponse } from '@ethersproject/abstract-provider '
2+ import { TransactionReceipt } from '@ethersproject/abstract-provider/src.ts/index '
3+ import { BytesLike , hexValue } from '@ethersproject/bytes '
44import { Deferrable , resolveProperties } from '@ethersproject/properties'
5+ import { BaseProvider , Provider , TransactionRequest } from '@ethersproject/providers'
6+ import { BigNumber , Bytes , ethers , Event , Signer } from 'ethers'
7+ import { clearInterval } from 'timers'
8+ import { getAccountAddress , getAccountInitCode } from '../test/testutils'
9+ import { fillAndSign , getUserOpHash } from '../test/UserOp'
10+ import { UserOperation } from '../test/UserOperation'
511import {
612 EntryPoint ,
713 EntryPoint__factory ,
8- ERC1967Proxy__factory ,
914 SimpleAccount ,
15+ SimpleAccountFactory ,
16+ SimpleAccountFactory__factory ,
1017 SimpleAccount__factory
1118} from '../typechain'
12- import { BytesLike , hexValue } from '@ethersproject/bytes'
13- import { TransactionResponse } from '@ethersproject/abstract-provider'
14- import { fillAndSign , getUserOpHash } from '../test/UserOp'
15- import { UserOperation } from '../test/UserOperation'
16- import { TransactionReceipt } from '@ethersproject/abstract-provider/src.ts/index'
17- import { clearInterval } from 'timers'
18- import { Create2Factory } from './Create2Factory'
19- import { getCreate2Address , hexConcat , Interface , keccak256 } from 'ethers/lib/utils'
20- import { HashZero } from '../test/testutils'
2119
2220export type SendUserOp = ( userOp : UserOperation ) => Promise < TransactionResponse | undefined >
2321
@@ -202,6 +200,7 @@ export class AASigner extends Signer {
202200
203201 private _isPhantom = true
204202 public entryPoint : EntryPoint
203+ public accountFactory : SimpleAccountFactory
205204
206205 private _chainId : Promise < number > | undefined
207206
@@ -212,9 +211,10 @@ export class AASigner extends Signer {
212211 * @param sendUserOp function to actually send the UserOp to the entryPoint.
213212 * @param index - index of this account for this signer.
214213 */
215- constructor ( readonly signer : Signer , readonly entryPointAddress : string , readonly sendUserOp : SendUserOp , readonly index = 0 , readonly provider = signer . provider ) {
214+ constructor ( readonly signer : Signer , readonly entryPointAddress : string , readonly sendUserOp : SendUserOp , readonly accountFactoryAddress : string , readonly index = 0 , readonly provider = signer . provider ) {
216215 super ( )
217216 this . entryPoint = EntryPoint__factory . connect ( entryPointAddress , signer )
217+ this . accountFactory = SimpleAccountFactory__factory . connect ( accountFactoryAddress , signer )
218218 }
219219
220220 // connect to a specific pre-deployed address
@@ -234,18 +234,6 @@ export class AASigner extends Signer {
234234 throw new Error ( 'connect not implemented' )
235235 }
236236
237- async _deploymentAddress ( ) : Promise < string > {
238- return getCreate2Address ( Create2Factory . contractAddress , HashZero , keccak256 ( await this . _deploymentTransaction ( ) ) )
239- }
240-
241- // TODO TODO: THERE IS UTILS.getAccountInitCode - why not use that?
242- async _deploymentTransaction ( ) : Promise < BytesLike > {
243- const implementationAddress = zeroAddress ( ) // TODO: pass implementation in here
244- const ownerAddress = await this . signer . getAddress ( )
245- const initializeCall = new Interface ( SimpleAccount__factory . abi ) . encodeFunctionData ( 'initialize' , [ ownerAddress ] )
246- return new ERC1967Proxy__factory ( this . signer ) . getDeployTransaction ( implementationAddress , initializeCall ) . data !
247- }
248-
249237 async getAddress ( ) : Promise < string > {
250238 await this . syncAccount ( )
251239 return this . _account ! . address
@@ -353,7 +341,7 @@ export class AASigner extends Signer {
353341
354342 async syncAccount ( ) : Promise < void > {
355343 if ( this . _account == null ) {
356- const address = await this . _deploymentAddress ( )
344+ const address = await getAccountAddress ( await this . signer . getAddress ( ) , this . accountFactory )
357345 this . _account = SimpleAccount__factory . connect ( address , this . signer )
358346 }
359347
@@ -380,12 +368,7 @@ export class AASigner extends Signer {
380368
381369 let initCode : BytesLike | undefined
382370 if ( this . _isPhantom ) {
383- const initCallData = new Create2Factory ( this . provider ! ) . getDeployTransactionCallData ( hexValue ( await this . _deploymentTransaction ( ) ) , HashZero )
384-
385- initCode = hexConcat ( [
386- Create2Factory . contractAddress ,
387- initCallData
388- ] )
371+ initCode = getAccountInitCode ( await this . signer . getAddress ( ) , this . accountFactory )
389372 }
390373 const execFromEntryPoint = await this . _account ! . populateTransaction . execute ( tx . to ! , tx . value ?? 0 , tx . data ! )
391374
0 commit comments