Skip to content

Commit

Permalink
Merge pull request #186 from jayden-sudo/develop
Browse files Browse the repository at this point in the history
The original struct is not modified by the function estimateUserOpera…
  • Loading branch information
jayden-sudo authored Sep 26, 2024
2 parents 314ecd1 + 444ba80 commit c14a717
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-students-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@soulwallet/sdk": patch
---

The original struct is not modified by the function estimateUserOperationGas()
5 changes: 3 additions & 2 deletions packages/soulwallet-sdk/src/interface/ISoulWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UserOpErrors } from "./IUserOpErrors.js";
import { Result } from '@soulwallet/result';
import { ECCPoint, RSAPublicKey } from "../tools/webauthn.js";
import { TypedDataDomain, TypedDataField } from "ethers";
import { UserOpGas } from "./IBundler.js";

/**
* Transaction is the interface for the transaction.
Expand Down Expand Up @@ -115,10 +116,10 @@ export abstract class ISoulWallet {
* @param {UserOperation} userOp UserOperation
* @param {SignkeyType} [signkeyType] default: SignkeyType.EOA
* @param {GuardHookInputData} [semiValidGuardHookInputData] sender: wallet address, inputData: key: guardHookPlugin address, value: input data
* @return {*} {Promise<Result<true, UserOpErrors>>}
* @return {*} {Promise<Result<UserOpGas, UserOpErrors>>}
* @memberof ISoulWallet
*/
abstract estimateUserOperationGas(validatorAddress: string, userOp: UserOperation, signkeyType?: SignkeyType, semiValidGuardHookInputData?: GuardHookInputData): Promise<Result<true, UserOpErrors>>;
abstract estimateUserOperationGas(validatorAddress: string, userOp: UserOperation, signkeyType?: SignkeyType, semiValidGuardHookInputData?: GuardHookInputData): Promise<Result<UserOpGas, UserOpErrors>>;

/**
* broadcast the userOp.
Expand Down
31 changes: 23 additions & 8 deletions packages/soulwallet-sdk/src/soulWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getUserOpHash } from "./tools/userOpHash.js";
import { SocialRecovery } from "./socialRecovery.js";
import { ECCPoint, RSAPublicKey } from "./tools/webauthn.js";
import { WalletFactory } from "./tools/walletFactory.js";
import { UserOpGas } from "./interface/IBundler.js";

export class onChainConfig {
chainId: number = 0;
Expand Down Expand Up @@ -617,7 +618,7 @@ export class SoulWallet implements ISoulWallet {
return new Ok(signatureRet.OK);
}

async estimateUserOperationGas(validatorAddress: string, userOp: UserOperation, signkeyType?: SignkeyType, semiValidGuardHookInputData?: GuardHookInputData): Promise<Result<true, UserOpErrors>> {
async estimateUserOperationGas(validatorAddress: string, userOp: UserOperation, signkeyType?: SignkeyType, semiValidGuardHookInputData?: GuardHookInputData): Promise<Result<UserOpGas, UserOpErrors>> {
const semiValidSignature = userOp.signature === "0x";
const _onChainConfig = await this.getOnChainConfig();
if (_onChainConfig.isErr() === true) {
Expand All @@ -636,15 +637,29 @@ export class SoulWallet implements ISoulWallet {
return new Err(userOpGasRet.ERR);
}

userOp.callGasLimit = `0x${BigInt(userOpGasRet.OK.callGasLimit).toString(16)}`;
userOp.paymasterPostOpGasLimit = `0x${BigInt(userOpGasRet.OK.paymasterPostOpGasLimit).toString(16)}`;
userOp.paymasterVerificationGasLimit = `0x${BigInt(userOpGasRet.OK.paymasterVerificationGasLimit).toString(16)}`;
userOp.preVerificationGas = `0x${BigInt(userOpGasRet.OK.preVerificationGas).toString(16)}`;
userOp.verificationGasLimit = `0x${BigInt(userOpGasRet.OK.verificationGasLimit).toString(16)}`;
// userOp.callGasLimit = `0x${BigInt(userOpGasRet.OK.callGasLimit).toString(16)}`;
// userOp.paymasterPostOpGasLimit = `0x${BigInt(userOpGasRet.OK.paymasterPostOpGasLimit).toString(16)}`;
// userOp.paymasterVerificationGasLimit = `0x${BigInt(userOpGasRet.OK.paymasterVerificationGasLimit).toString(16)}`;
// userOp.preVerificationGas = `0x${BigInt(userOpGasRet.OK.preVerificationGas).toString(16)}`;
// userOp.verificationGasLimit = `0x${BigInt(userOpGasRet.OK.verificationGasLimit).toString(16)}`;

//GasOverhead.calcGasOverhead(userOp, signkeyType);
return new Ok(true);
} finally {

return new Ok(userOpGasRet.OK);

}
catch (error: unknown) {
if (error instanceof Error) {
return new Err(
new UserOpErrors(UserOpErrorCodes.UnknownError, error.message)
);
} else {
return new Err(
new UserOpErrors(UserOpErrorCodes.UnknownError, "unknown error")
);
}
}
finally {
if (semiValidSignature) {
userOp.signature = "0x";
}
Expand Down

0 comments on commit c14a717

Please sign in to comment.