Skip to content

Commit

Permalink
type updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh committed Feb 1, 2024
1 parent 20d168b commit fd1d2fd
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
29 changes: 16 additions & 13 deletions packages/sdk/src/BaseAccountAPI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ethers, BigNumber, BigNumberish, BytesLike } from 'ethers'
import { Provider } from '@ethersproject/providers'
import {
EntryPoint, EntryPoint__factory
} from '@account-abstraction/contracts'
import { IEntryPoint, IEntryPoint__factory } from '@account-abstraction/contracts'

import { TransactionDetailsForUserOp } from './TransactionDetailsForUserOp'
import { defaultAbiCoder } from 'ethers/lib/utils'
Expand Down Expand Up @@ -45,7 +43,7 @@ export abstract class BaseAccountAPI {
private senderAddress!: string
private isPhantom = true
// entryPoint connected to "zero" address. allowed to make static calls (e.g. to getSenderAddress)
private readonly entryPointView: EntryPoint
private readonly entryPointView: IEntryPoint

provider: Provider
overheads?: Partial<GasOverheads>
Expand All @@ -65,7 +63,7 @@ export abstract class BaseAccountAPI {
this.paymasterAPI = params.paymasterAPI

// factory "connect" define the contract address. the contract "connect" defines the "from" address.
this.entryPointView = EntryPoint__factory.connect(params.entryPointAddress, params.provider).connect(ethers.constants.AddressZero)
this.entryPointView = IEntryPoint__factory.connect(params.entryPointAddress, params.provider).connect(ethers.constants.AddressZero)
}

async init (): Promise<this> {
Expand Down Expand Up @@ -254,31 +252,36 @@ export abstract class BaseAccountAPI {
}
}

const partialUserOp: Partial<UserOperation> = {
let partialUserOp = {
sender: await this.getAccountAddress(),
nonce: info.nonce ?? await this.getNonce(),
factory: factoryParams?.factory,
factoryData: factoryParams?.factoryData,
callData,
callGasLimit,
verificationGasLimit,
maxFeePerGas,
maxPriorityFeePerGas
maxFeePerGas: maxFeePerGas as any,
maxPriorityFeePerGas: maxPriorityFeePerGas as any
}

if (this.paymasterAPI != null) {
// fill (partial) preVerificationGas (all except the cost of the generated paymasterAndData)
const pmFields = await this.paymasterAPI.getTemporaryPaymasterData(partialUserOp)
partialUserOp.paymaster = pmFields?.paymaster
partialUserOp.paymasterVerificationGasLimit = pmFields?.paymasterVerificationGasLimit
partialUserOp.paymasterPostOpGasLimit = pmFields?.paymasterPostOpGasLimit
partialUserOp.paymasterData = pmFields?.paymasterData
if (pmFields != null) {
partialUserOp = {
...partialUserOp,
paymaster: pmFields?.paymaster,
paymasterPostOpGasLimit: pmFields?.paymasterPostOpGasLimit,
paymasterVerificationGasLimit: pmFields?.paymasterVerificationGasLimit,
paymasterData: pmFields?.paymasterData
} as any
}
}
return {
...partialUserOp,
preVerificationGas: await this.getPreVerificationGas(partialUserOp),
signature: ''
} as any
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/ERC4337EthersProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ClientConfig } from './ClientConfig'
import { ERC4337EthersSigner } from './ERC4337EthersSigner'
import { UserOperationEventListener } from './UserOperationEventListener'
import { HttpRpcClient } from './HttpRpcClient'
import { EntryPoint } from '@account-abstraction/contracts'
import { IEntryPoint } from '@account-abstraction/contracts'
import { getUserOpHash, packUserOp, UserOperation } from '@account-abstraction/utils'
import { BaseAccountAPI } from './BaseAccountAPI'
import Debug from 'debug'
Expand All @@ -24,7 +24,7 @@ export class ERC4337EthersProvider extends BaseProvider {
readonly originalSigner: Signer,
readonly originalProvider: BaseProvider,
readonly httpRpcClient: HttpRpcClient,
readonly entryPoint: EntryPoint,
readonly entryPoint: IEntryPoint,
readonly smartAccountAPI: BaseAccountAPI
) {
super({
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/Provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsonRpcProvider } from '@ethersproject/providers'

import { EntryPoint__factory, SimpleAccountFactory__factory } from '@account-abstraction/contracts'
import { IEntryPoint__factory, SimpleAccountFactory__factory } from '@account-abstraction/contracts'

import { ClientConfig } from './ClientConfig'
import { SimpleAccountAPI } from './SimpleAccountAPI'
Expand All @@ -20,7 +20,7 @@ export async function wrapProvider (
config: ClientConfig,
originalSigner: Signer = originalProvider.getSigner()
): Promise<ERC4337EthersProvider> {
const entryPoint = EntryPoint__factory.connect(config.entryPointAddress, originalProvider)
const entryPoint = IEntryPoint__factory.connect(config.entryPointAddress, originalProvider)
// Initial SimpleAccount instance is not deployed and exists just for the interface
const detDeployer = new DeterministicDeployer(originalProvider)
const SimpleAccountFactory = await detDeployer.deterministicDeploy(new SimpleAccountFactory__factory(), 0, [entryPoint.address])
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/UserOperationEventListener.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumberish, Event } from 'ethers'
import { TransactionReceipt } from '@ethersproject/providers'
import { EntryPoint } from '@account-abstraction/contracts'
import { IEntryPoint } from '@account-abstraction/contracts'
import { defaultAbiCoder } from 'ethers/lib/utils'
import Debug from 'debug'

Expand All @@ -19,7 +19,7 @@ export class UserOperationEventListener {
constructor (
readonly resolve: (t: TransactionReceipt) => void,
readonly reject: (reason?: any) => void,
readonly entryPoint: EntryPoint,
readonly entryPoint: IEntryPoint,
readonly sender: string,
readonly userOpHash: string,
readonly nonce?: BigNumberish,
Expand Down
10 changes: 3 additions & 7 deletions packages/sdk/test/1-SimpleAccountAPI.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
EntryPoint,
EntryPoint__factory,
SimpleAccountFactory__factory
EntryPoint__factory, IEntryPoint, SimpleAccountFactory__factory
} from '@account-abstraction/contracts'
import { Wallet } from 'ethers'
import { parseEther } from 'ethers/lib/utils'
Expand All @@ -10,10 +8,8 @@ import { anyValue } from '@nomicfoundation/hardhat-chai-matchers/withArgs'
import { ethers } from 'hardhat'
import { DeterministicDeployer, SimpleAccountAPI } from '../src'
import {
SampleRecipient,
SampleRecipient__factory,
UserOperation,
packUserOp, decodeErrorReason
packUserOp, decodeErrorReason, SampleRecipient, SampleRecipient__factory
} from '@account-abstraction/utils'

const provider = ethers.provider
Expand All @@ -22,7 +18,7 @@ const signer = provider.getSigner()
describe('SimpleAccountAPI', () => {
let owner: Wallet
let api: SimpleAccountAPI
let entryPoint: EntryPoint
let entryPoint: IEntryPoint
let beneficiary: string
let recipient: SampleRecipient
let accountAddress: string
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/ERC4337Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ export function unpackUserOp (packed: PackedUserOperation): UserOperation {
export function encodeUserOp (op1: NotPromise<PackedUserOperationStruct> | UserOperation, forSignature = true): string {
// if "op" is unpacked UserOperation, then pack it first, before we ABI-encode it.
let op: NotPromise<PackedUserOperationStruct>
if ((op1 as any).callGasLimit != null) {
op = packUserOp(op1 as UserOperation)
if ('callGasLimit' in op1) {
op = packUserOp(op1)
} else {
op = op1 as NotPromise<PackedUserOperationStruct>
op = op1
}
if (forSignature) {
return defaultAbiCoder.encode(
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/postExecCheck.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { resolveProperties } from 'ethers/lib/utils'
import { NotPromise } from './ERC4337Utils'
import { EntryPoint, PackedUserOperationStruct } from '@account-abstraction/contracts'
import Debug from 'debug'
import { IEntryPoint, PackedUserOperationStruct } from '@account-abstraction/contracts'

const debug = Debug('aa.postExec')

export async function postExecutionDump (entryPoint: EntryPoint, userOpHash: string): Promise<void> {
export async function postExecutionDump (entryPoint: IEntryPoint, userOpHash: string): Promise<void> {
const { gasPaid, gasUsed, success, userOp } = await postExecutionCheck(entryPoint, userOpHash)
/// / debug dump:
debug('==== used=', gasUsed, 'paid', gasPaid, 'over=', gasPaid - gasUsed,
Expand All @@ -20,7 +20,7 @@ export async function postExecutionDump (entryPoint: EntryPoint, userOpHash: str
* @param entryPoint
* @param userOpHash
*/
export async function postExecutionCheck (entryPoint: EntryPoint, userOpHash: string): Promise<{
export async function postExecutionCheck (entryPoint: IEntryPoint, userOpHash: string): Promise<{
gasUsed: number
gasPaid: number
success: boolean
Expand Down

0 comments on commit fd1d2fd

Please sign in to comment.