diff --git a/package.json b/package.json index 375bdbcac..1bf794753 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ }, "dependencies": { "@changesets/cli": "^2.14.1", - "ethers": "5.4.5" + "ethers": "5.6.2" }, "devDependencies": { "@chainsafe/eslint-config": "^1.1.0", diff --git a/packages/sdk/src/constants.ts b/packages/sdk/src/constants.ts index 6c32244b1..f587ebd08 100644 --- a/packages/sdk/src/constants.ts +++ b/packages/sdk/src/constants.ts @@ -8,3 +8,8 @@ export enum IndexerUrl { MAINNET = 'https://api.buildwithsygma.com', TESTNET = 'https://api.test.buildwithsygma.com', } + +export enum ExplorerUrl { + MAINNET = 'https://scan.buildwithsygma.com', + TESTNET = 'https://scan.test.buildwithsygma.com', +} diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 3594a7f1b..d58ca1c1f 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -2,3 +2,4 @@ export * from './chains/index.js'; export * from './config.js'; export * from './constants.js'; export * from './types/index.js'; +export { getTransferStatusData } from './utils.js'; diff --git a/packages/sdk/src/types/types.ts b/packages/sdk/src/types/types.ts index 59764c94f..24f19d385 100644 --- a/packages/sdk/src/types/types.ts +++ b/packages/sdk/src/types/types.ts @@ -84,3 +84,8 @@ export type Transfer = { export type LiquidityError = Error & { maximumTransferAmount: bigint }; export type TransferStatus = 'pending' | 'executed' | 'failed'; + +export type TransferStatusResponse = { + status: TransferStatus; + explorerUrl: string; +}; diff --git a/packages/sdk/src/utils.ts b/packages/sdk/src/utils.ts index 5d5478076..4b7e246b1 100644 --- a/packages/sdk/src/utils.ts +++ b/packages/sdk/src/utils.ts @@ -1,5 +1,5 @@ -import { IndexerUrl } from './constants'; -import { Environment, TransferStatus } from './types'; +import { IndexerUrl, ExplorerUrl } from './constants'; +import { Environment, TransferStatus, TransferStatusResponse } from './types'; export const DEVNET_FEE_ORACLE_BASE_URL: string = 'https://fee-oracle.develop.buildwithsygma.com/'; export const TESTNET_FEE_ORACLE_BASE_URL: string = 'https://fee-oracle.test.buildwithsygma.com/'; @@ -18,26 +18,34 @@ export function getFeeOracleBaseURL(environment?: Environment): string { } /** - * @@description Get the status of a transfer using transaction hash and optionally domain id + * @@description Get the status of a transfer using transaction hash and optionally domain id */ -export async function getTransferStatus( +export async function getTransferStatusData( environment: Environment, txHash: string, domainId?: string, -): Promise { +): Promise { let url: string; + let explorerUrl: string; if (environment === Environment.TESTNET) { - url = IndexerUrl.TESTNET; + url = `${IndexerUrl.TESTNET}/api/transfers/txHash/${txHash}${ + domainId ? `?domainId=${domainId}` : '' + }`; + explorerUrl = `${ExplorerUrl.TESTNET}/transfer/${txHash}`; } else if (environment === Environment.MAINNET) { - url = IndexerUrl.MAINNET; + url = `${IndexerUrl.MAINNET}/api/transfers/txHash/${txHash}${ + domainId ? `?domainId=${domainId}` : '' + }`; + explorerUrl = `${ExplorerUrl.MAINNET}/transfer/${txHash}`; } else { throw new Error('Invalid environment'); } - const response = await fetch( - `${url}/api/transfers/txHash/${txHash}?${domainId ? `domainId=${domainId}` : ''}}`, - ); + const response = await fetch(url); const data = (await response.json()) as Record & { status: TransferStatus }; - return data.status; + return { + status: data.status, + explorerUrl, + }; }