8000 Add ability to pass trackTxPollingOptions to executeRoute by toddkao · Pull Request #1306 · skip-mev/skip-go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add ability to pass trackTxPollingOptions to executeRoute #1306

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

Merged
merged 2 commits into from
Jun 3, 2025
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
5 changes: 5 additions & 0 deletions .changeset/pretty-cooks-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skip-go/client": patch
---

Add trackTxPollingOptions to ExecuteRouteOptions and waitForTransaction
28 changes: 22 additions & 6 deletions packages/client/src/api/postTrackTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import { pollingApi } from "../utils/generateApi";
import type {
ApiRequest,
PollingProps,
} from "../utils/generateApi";

export const trackTransaction = pollingApi({
methodName: "track",
path: "/v2/tx/track",
method: "post",
backoffMultiplier: 2.5,
});
export type TrackTxRequest = ApiRequest<"status"> & TrackTxPollingProps;
export type TrackTxPollingProps = Omit<PollingProps<"status">, "isSuccess" | "onError" | "onSuccess">;

export const trackTransaction = ({
maxRetries,
retryInterval,
backoffMultiplier = 2.5,
...trackTxRequest
}: TrackTxRequest) => {
return pollingApi({
methodName: "track",
path: "/v2/tx/track",
method: "post",
maxRetries,
retryInterval,
backoffMultiplier,
})(trackTxRequest);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const executeTransactions = async (options: ExecuteRouteOptions & { txs?:
getCosmosSigner,
getEvmSigner,
onValidateGasBalance,
trackTxPollingOptions,
} = options;

if (txs === undefined) {
Expand Down Expand Up @@ -114,6 +115,7 @@ export const executeTransactions = async (options: ExecuteRouteOptions & { txs?:

const txStatusResponse = await waitForTransaction({
...txResult,
...trackTxPollingOptions,
onTransactionTracked: options.onTransactionTracked,
});

Expand Down Expand Up @@ -141,7 +143,7 @@ const getDefaultFallbackGasAmount = async (chainId: string, chainType: ChainType

const venuesResult = await venues();
const isSwapChain = venuesResult?.some((venue: { chainId?: string }) => venue.chainId === chainId) ?? false;

const defaultGasAmount = Math.ceil(
isSwapChain ? COSMOS_GAS_AMOUNT.SWAP : COSMOS_GAS_AMOUNT.DEFAULT,
);
Expand Down
13 changes: 12 additions & 1 deletion packages/client/src/public-functions/executeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { messages } from "../api/postMessages";
import { isAddress } from "viem";
import type { SignerGetters, GasOptions, UserAddress } from "src/types/client-types";
import { ApiState } from "src/state/apiState";
import type { TrackTxPollingProps } from "src/api/postTrackTransaction";

/** Execute Route Options */
export type ExecuteRouteOptions = SignerGetters &
Expand Down Expand Up @@ -45,7 +46,17 @@ export type ExecuteRouteOptions = SignerGetters &
* If `batchSimulate` is set to `false`, it will simulate each message one by one.
*/
batchSimulate?: boolean;
};

/**
* Optional configuration for transaction polling behavior.
* - `maxRetries`: Maximum number of polling attempts (default: 5)
* - `retryInterval`: Retry interval in milliseconds (default: 1000)
* - `backoffMultiplier`: Exponential backoff multiplier for increasing delay between retries (default: 2.5)
* Example backoff with retryInterval = 1000 and backoffMultiplier = 2:
* 1st retry: 1000ms → 2nd: 2000ms → 3rd: 4000ms → 4th: 8000ms ...
*/
trackTxPollingOptions?: TrackTxPollingProps;
}

export const executeRoute = async (options: ExecuteRouteOptions) => {
const { route, userAddresses, beforeMsg, afterMsg, timeoutSeconds } = options;
Expand Down
8 changes: 4 additions & 4 deletions packages/client/src/public-functions/waitForTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { trackTransaction } from "../api/postTrackTransaction";
import { trackTransaction, type TrackTxRequest } from "../api/postTrackTransaction";
import { transactionStatus } from "../api/postTransactionStatus";
import type { TransactionCallbacks } from "../types/callbacks";
import { wait } from "../utils/timer";

export type WaitForTransactionProps = {
chainId: string;
txHash: string;
export type WaitForTransactionProps = TrackTxRequest & {
onTransactionTracked?: TransactionCallbacks["onTransactionTracked"];
};

export const waitForTransaction = async ({
chainId,
txHash,
onTransactionTracked,
...trackTxPollingOptions
}: WaitForTransactionProps) => {
const { explorerLink } = await trackTransaction({
chainId,
txHash,
...trackTxPollingOptions,
});
await onTransactionTracked?.({ txHash, chainId, explorerLink });

Expand Down
6 changes: 4 additions & 2 deletions packages/client/src/utils/generateApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export function api<K extends ValidApiMethodKeys, TransformedResponse = ApiRespo
});
}

type PollingApiProps<K extends ValidApiMethodKeys> = Omit<ApiProps<K>, "options"> & {
export type PollingProps<K extends ValidApiMethodKeys> = {
isSuccess?: (result: ApiResponse<K>) => boolean;
/**
* Maximum number of retries
Expand Down Expand Up @@ -239,7 +239,9 @@ type PollingApiProps<K extends ValidApiMethodKeys> = Omit<ApiProps<K>, "options"
backoffMultiplier?: number;
onError?: (error: unknown, attempt: number) => void;
onSuccess?: (result: ApiResponse<K>, attempt: number) => void;
};
}

export type PollingApiProps<K extends ValidApiMethodKeys> = Omit<ApiProps<K>, "options"> & PollingProps<K>;

export function pollingApi<K extends ValidApiMethodKeys>({
methodName,
Expand Down
0