Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

fix: Add check for whether account is deployed #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion src/preset/builder/simpleAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export class SimpleAccount extends UserOperationBuilder {

private resolveAccount: UserOperationMiddlewareFn = async (ctx) => {
ctx.op.nonce = await this.entryPoint.getNonce(ctx.op.sender, 0);
ctx.op.initCode = ctx.op.nonce.eq(0) ? this.initCode : "0x";
const code = await this.provider.getCode(this.proxy.address)
const ifNotDeployed = code === "0x";
ctx.op.initCode = ifNotDeployed ? this.initCode : "0x";
};

public static async init(
Expand Down
3 changes: 3 additions & 0 deletions src/preset/middleware/gasLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const estimateCreationGas = async (
provider: ethers.providers.JsonRpcProvider,
initCode: BytesLike
): Promise<ethers.BigNumber> => {
if (initCode.length <= 20) {
return ethers.BigNumber.from(0);
}
const initCodeHex = ethers.utils.hexlify(initCode);
const factory = initCodeHex.substring(0, 42);
const callData = "0x" + initCodeHex.substring(42);
Expand Down