diff --git a/connect/src/whscan-api.ts b/connect/src/whscan-api.ts index 3cb13030e..8a86518c7 100644 --- a/connect/src/whscan-api.ts +++ b/connect/src/whscan-api.ts @@ -71,42 +71,51 @@ export interface TransactionStatus { }; } -export interface RelayData { - from: { - chain: string; - chainId: number; - txHash: string; - senderAddress: string; - symbol: string; - amountSent: number; - amountToSwap: number; - estimatedNativeAssetAmount: number; - }; - vaa: string; - status: string; - fee: { - amount: number; - symbol: string; - }; - error: any; - to: { - chain: string; - chainId: number; - recipientAddress: string; - txHash: string; - gasUsed: number; - nativeAssetSymbol: string; - nativeAssetReceived: number; - }; - metrics: { - receivedAt: string; - completedAt: string; - failedAt: any; - attempts: number; +export interface RelayStatus { + completedAt: string; + data: { + delivery: { + budget: string; + execution: { + detail: string; + gasUsed: string; + refundStatus: string; + revertString: string; + status: string; + transactionHash: string; + }; + maxRefund: string; + relayGasUsed: number; + targetChainDecimals: number; + }; + fromTxHash: string; + instructions: { + encodedExecutionInfo: string; + extraReceiverValue: { + _hex: string; + _isBigNumber: boolean; + }; + refundAddress: string; + refundChainId: number; + refundDeliveryProvider: string; + requestedReceiverValue: { + _hex: string; + _isBigNumber: boolean; + }; + senderAddress: string; + sourceDeliveryProvider: string; + targetAddress: string; + targetChainId: number; + vaaKeys: string[]; + }; maxAttempts: number; - waitingForTxInMs: number; - waitingForWalletInMs: number; + toTxHash: string; }; + failedAt: string; + id: string; + receivedAt: string; + relayer: string; + status: string; } export interface ApiVaa { @@ -235,11 +244,17 @@ export async function getTransactionStatusWithRetry( ); } -export async function getRelayStatus(rpcUrl: string, txid: TxHash): Promise { - const url = `${rpcUrl}/v1/relays?txHash=${txid}`; +export async function getRelayStatus( + rpcUrl: string, + whm: WormholeMessageId, +): Promise { + const { chain, emitter, sequence } = whm; + const chainId = toChainId(chain); + const emitterAddress = emitter.toUniversalAddress().toString(); + const url = `${rpcUrl}/api/v1/relays/${chainId}/${emitterAddress}/${sequence}`; try { - const response = await axios.get<{ data: RelayData }>(url); - if (response.data.data.to.txHash) return response.data.data; + const response = await axios.get(url); + return response.data || null; } catch (error) { if (!error) return null; if (typeof error === "object") { @@ -250,16 +265,15 @@ export async function getRelayStatus(rpcUrl: string, txid: TxHash): Promise { - const task = () => getRelayStatus(rpcUrl, txid); - return retry(task, WHSCAN_RETRY_INTERVAL, timeout, "Wormholescan:GetRelayStatus"); +): Promise { + const task = () => getRelayStatus(rpcUrl, whm); + return retry(task, WHSCAN_RETRY_INTERVAL, timeout, "Wormholescan:GetRelayStatus"); } export async function getVaaByTxHash(rpcUrl: string, txid: string): Promise { diff --git a/connect/src/wormhole.ts b/connect/src/wormhole.ts index 630a3eed3..440bc444b 100644 --- a/connect/src/wormhole.ts +++ b/connect/src/wormhole.ts @@ -31,9 +31,10 @@ import { TokenTransfer } from "./protocols/tokenBridge/tokenTransfer.js"; import type { RouteConstructor } from "./routes/index.js"; import { RouteResolver } from "./routes/resolver.js"; import { retry } from "./tasks.js"; -import type { TransactionStatus } from "./whscan-api.js"; +import type { RelayStatus, TransactionStatus } from "./whscan-api.js"; import { getIsVaaEnqueued, + getRelayStatus, getTransactionStatusWithRetry, getTxsByAddress, getVaaByTxHashWithRetry, @@ -333,6 +334,16 @@ export class Wormhole { return await getVaaWithRetry(this.config.api, id, decodeAs, timeout); } + /** + * Gets the RelayStatus for a given WormholeMessageId + * + * @param wormholeMessageId The WormholeMessageId corresponding to the relay status to be fetched + * @returns The RelayStatus if available otherwise null + */ + async getRelayStatus(wormholeMessageId: WormholeMessageId): Promise { + return await getRelayStatus(this.config.api, wormholeMessageId); + } + /** * Gets if the token bridge transfer VAA has been enqueued by the Governor. * @param id The WormholeMessageId corresponding to the token bridge transfer VAA to check