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

fix: waitForUserOperationTx parameters were incorrect #634

Merged
merged 1 commit into from
Apr 30, 2024
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
19 changes: 19 additions & 0 deletions packages/core/src/actions/smartAccount/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ export type DropAndReplaceUserOperationParameters<
//#region WaitForUserOperationTxParameters
export type WaitForUserOperationTxParameters = {
hash: Hex;
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to reuse these from the client opts schema?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, but then didn't want to perpetuate zod cuz it's annoying in some places

* Exponential backoff paramters that can be used to override
* the configuration on the client. If not provided, this method
* will use the paramters passed via the `opts` parameter on the
* smart account client.
*/
retries?: {
/**
* the base retry interval or delay between requests
*/
intervalMs: number;
/**
* the multiplier to exponentiate based on the number retries
* setting this to one will result in a linear backoff
*/
multiplier: number;
/** the maximum number of retries before failing */
maxRetries: number;
};
};
//#endregion WaitForUserOperationTxParameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export const waitForUserOperationTransaction: <
client: Client<TTransport, TChain, any>,
args: WaitForUserOperationTxParameters
) => Promise<Hex> = async (client, args) => {
const { hash } = args;

if (!isBaseSmartAccountClient(client)) {
throw new IncompatibleClientError(
"BaseSmartAccountClient",
Expand All @@ -23,9 +21,18 @@ export const waitForUserOperationTransaction: <
);
}

for (let i = 0; i < client.txMaxRetries; i++) {
const {
hash,
retries = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these aren't provided is this going to use what the client passes in? I don't see that in the diff

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea that's what this line does, the destructue with the equals is setting the default value if it's not passed in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh neat okay

maxRetries: client.txMaxRetries,
intervalMs: client.txRetryIntervalMs,
multiplier: client.txRetryMultiplier,
},
} = args;

for (let i = 0; i < retries.maxRetries; i++) {
const txRetryIntervalWithJitterMs =
client.txRetryIntervalMs * Math.pow(client.txRetryMultiplier, i) +
retries.intervalMs * Math.pow(retries.multiplier, i) +
Math.random() * 100;

await new Promise((resolve) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/client/decorators/smartAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type SendTransactionParameters,
type Transport,
type TypedData,
type WaitForTransactionReceiptParameters,
} from "viem";
import type {
GetAccountParameter,
Expand Down Expand Up @@ -41,6 +40,7 @@ import type {
SignUserOperationParameters,
UpgradeAccountParams,
UserOperationContext,
WaitForUserOperationTxParameters,
} from "../../actions/smartAccount/types";
import { upgradeAccount } from "../../actions/smartAccount/upgradeAccount.js";
import { waitForUserOperationTransaction } from "../../actions/smartAccount/waitForUserOperationTransacation.js";
Expand Down Expand Up @@ -101,7 +101,7 @@ export type BaseSmartAccountClientActions<
args: SendUserOperationParameters<TAccount, TContext>
) => Promise<SendUserOperationResult<TEntryPointVersion>>;
waitForUserOperationTransaction: (
args: WaitForTransactionReceiptParameters
args: WaitForUserOperationTxParameters
) => Promise<Hex>;
upgradeAccount: (
args: UpgradeAccountParams<TAccount, TContext>
Expand Down
Loading