Skip to content

Commit

Permalink
Fix Bug: UserOpHash for chainId (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Oct 9, 2024
1 parent 0102bfc commit f13475a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/send-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function main(): Promise<void> {
usePaymaster,
});
console.log("Unsigned UserOp", unsignedUserOp);
const safeOpHash = await txManager.opHash(unsignedUserOp);
const safeOpHash = await txManager.opHash(chainId, unsignedUserOp);
console.log("Safe Op Hash", safeOpHash);

// TODO: Evaluate gas cost (in ETH)
Expand Down
8 changes: 6 additions & 2 deletions src/lib/safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export class SafeContractSuite {
});
}

async getOpHash(unsignedUserOp: UserOperation): Promise<Hash> {
async getOpHash(
chainId: number,
unsignedUserOp: UserOperation
): Promise<Hash> {
const {
factory,
factoryData,
Expand All @@ -116,7 +119,8 @@ export class SafeContractSuite {
maxPriorityFeePerGas,
maxFeePerGas,
} = unsignedUserOp;
const opHash = await this.dummyClient.readContract({
const client = await getClient(chainId);
const opHash = await client.readContract({
address: this.m4337.address,
abi: this.m4337.abi,
functionName: "getOperationHash",
Expand Down
8 changes: 4 additions & 4 deletions src/near-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export class NearSafe {
* @param {UserOperation} userOp - The user operation for which the hash needs to be computed.
* @returns {Promise<Hash>} - A promise that resolves to the hash of the provided user operation.
*/
async opHash(userOp: UserOperation): Promise<Hash> {
return this.safePack.getOpHash(userOp);
async opHash(chainId: number, userOp: UserOperation): Promise<Hash> {
return this.safePack.getOpHash(chainId, userOp);
}

/**
Expand Down Expand Up @@ -455,11 +455,11 @@ export class NearSafe {
transactions,
usePaymaster,
});
const opHash = await this.opHash(userOp);
const opHash = await this.opHash(chainId, userOp);
return {
payload: toPayload(opHash),
evmMessage: JSON.stringify(userOp),
hash: await this.opHash(userOp),
hash: await this.opHash(chainId, userOp),
};
}
}
Expand Down

0 comments on commit f13475a

Please sign in to comment.