Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account V2 implementation first version + dev notes #255

Merged
merged 18 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"publishConfig": {
"access": "public"
},
"dependencies": {
"@biconomy-devx/account-contracts-v2": "npm:@biconomy-devx/account-contracts-v2@^1.0.0"
},
"devDependencies": {
"@biconomy/bundler": "^3.1.1-alpha.0",
"@biconomy/common": "^3.1.1-alpha.0",
Expand Down
23 changes: 16 additions & 7 deletions packages/account/src/BaseSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { calcPreVerificationGas, DefaultGasLimits } from './utils/Preverificaito
import { NotPromise, packUserOp } from '@biconomy/common'
import { IBundler, UserOpResponse } from '@biconomy/bundler'
import { IPaymaster, PaymasterAndDataResponse } from '@biconomy/paymaster'
import { EntryPoint_v100, Logger } from '@biconomy/common'
import { EntryPoint_v005, Logger } from '@biconomy/common'
import { BaseSmartAccountConfig, Overrides, TransactionDetailsForUserOp } from './utils/Types'
import { GasOverheads } from './utils/Preverificaiton'
import { EntryPoint, EntryPoint__factory } from '@account-abstraction/contracts'
Expand All @@ -17,14 +17,17 @@ import { RPC_PROVIDER_URLS } from '@biconomy/common'
type UserOperationKey = keyof UserOperation

export abstract class BaseSmartAccount implements IBaseSmartAccount {
// Review : compare with BaseAccountAPI
// private senderAddress!: string

private isDeployed = false
bundler?: IBundler // httpRpcClient
paymaster?: IPaymaster // paymasterAPI
overheads?: Partial<GasOverheads>
entryPointAddress!: string
accountAddress?: string
// owner?: Signer // owner is not mandatory for some account implementations
index?: number
index: number
chainId?: ChainId
provider: Provider // Review

Expand Down Expand Up @@ -57,18 +60,22 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount {
)
}

await this.getAccountAddress()
// Note: Review
// on Init itself since we're already getting account address, mark isDeployed as well!

if ((await this.provider.getCode(await this.getAccountAddress())) === '0x') {
this.isDeployed = false
} else {
this.isDeployed = true
}
return this
}

setEntryPointAddress(entryPointAddress: string) {
this.entryPointAddress = entryPointAddress
}

private validateUserOp(
userOp: Partial<UserOperation>,
requiredFields: UserOperationKey[]
): boolean {
validateUserOp(userOp: Partial<UserOperation>, requiredFields: UserOperationKey[]): boolean {
for (const field of requiredFields) {
if (!userOp[field]) {
throw new Error(`${field} is missing`)
Expand Down Expand Up @@ -312,6 +319,7 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount {
return '0x'
}

// Review : usage trace of this method. in the order of init and methods called on the Account
async isAccountDeployed(address: string): Promise<boolean> {
this.isProviderDefined()
let contractCode
Expand Down Expand Up @@ -386,6 +394,7 @@ export abstract class BaseSmartAccount implements IBaseSmartAccount {
* return the account's address.
* this value is valid even before deploying the contract.
*/
// Review: Probably should accept index as well as we rely on factory!
async getAccountAddress(): Promise<string> {
if (this.accountAddress == null) {
// means it needs deployment
Expand Down
2 changes: 1 addition & 1 deletion packages/account/src/BiconomySmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class BiconomySmartAccount extends SmartAccount implements IBiconomySmart
contractAddress: _factoryAddress,
provider: this.provider
}
this.factory = getSAFactoryContract(factoryInstanceDto)
this.factory = getSAFactoryContract(factoryInstanceDto) as SmartAccountFactory_v100
}

private async setContractsState() {
Expand Down
Loading