diff --git a/sdk/package-lock.json b/sdk/package-lock.json index 34482793..82101c90 100644 --- a/sdk/package-lock.json +++ b/sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gobob/bob-sdk", - "version": "2.3.2", + "version": "2.3.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@gobob/bob-sdk", - "version": "2.3.2", + "version": "2.3.4", "dependencies": { "@scure/base": "^1.1.7", "@scure/btc-signer": "^1.3.2", diff --git a/sdk/package.json b/sdk/package.json index 21676f9d..7a911d52 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@gobob/bob-sdk", - "version": "2.3.3", + "version": "2.3.4", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { diff --git a/sdk/src/gateway/client.ts b/sdk/src/gateway/client.ts index c83272c8..eefda339 100644 --- a/sdk/src/gateway/client.ts +++ b/sdk/src/gateway/client.ts @@ -15,7 +15,6 @@ import { EvmAddress, GatewayTokensInfo, OrderStatus, - OrderStatusType, } from "./types"; import { SYMBOL_LOOKUP, ADDRESS_LOOKUP } from "./tokens"; import { createBitcoinPsbt } from "../wallet"; @@ -299,17 +298,16 @@ export class GatewayApiClient { async getStatus(esploraClient: EsploraClient, latestHeight?: number): Promise { const confirmations = await getConfirmations(esploraClient, latestHeight); const hasEnoughConfirmations = confirmations >= order.txProofDifficultyFactor; - const data = { - confirmations, - confirmed: hasEnoughConfirmations - }; - return order.status - ? order.strategyAddress - ? order.outputTokenAddress - ? { status: OrderStatusType.Success, data } - : { status: OrderStatusType.Failed, data } - : { status: OrderStatusType.Success, data } - : { status: OrderStatusType.Pending, data }; + const data = { confirmations }; + return !hasEnoughConfirmations + ? { confirmed: false, data } + : order.status + ? order.strategyAddress + ? order.outputTokenAddress + ? { success: true, data } + : { success: false, data } + : { success: true, data } + : { pending: true, data }; }, }; }); diff --git a/sdk/src/gateway/index.ts b/sdk/src/gateway/index.ts index 4edebc63..eaf010e3 100644 --- a/sdk/src/gateway/index.ts +++ b/sdk/src/gateway/index.ts @@ -4,6 +4,5 @@ export { GatewayQuote, GatewayOrder, GatewayStrategyContract, - OrderStatusType, OrderStatus, } from "./types"; diff --git a/sdk/src/gateway/types.ts b/sdk/src/gateway/types.ts index bfb90875..70f49826 100644 --- a/sdk/src/gateway/types.ts +++ b/sdk/src/gateway/types.ts @@ -189,22 +189,6 @@ export type GatewayCreateOrderRequest = { satoshis: number; }; -export type OrderStatusData = { - confirmations: number; - confirmed: boolean; -}; - -export enum OrderStatusType { - Success = "Success", - Failed = "Failed", - Pending = "Pending", -} - -export type OrderStatus = - | { status: OrderStatusType.Success; data: OrderStatusData } - | { status: OrderStatusType.Failed; data: OrderStatusData } - | { status: OrderStatusType.Pending; data: OrderStatusData }; - export interface GatewayOrderResponse { /** @description The gateway address */ gatewayAddress: EvmAddress; @@ -236,6 +220,37 @@ export interface GatewayOrderResponse { outputTokenAmount?: string; /** @description The tx hash on the EVM chain */ txHash?: string; +}; + +export type OrderStatusData = { + confirmations: number; +}; + +export type OrderStatus = { + confirmed: false; + pending?: never; + success?: never; + data: OrderStatusData; +} | { + confirmed?: never; + pending: true; + success?: never; + data: OrderStatusData; +} | { + confirmed?: never; + pending?: never; + success: boolean; + data: OrderStatusData; +};; + +/** Order given by the Gateway API once the bitcoin tx is submitted */ +export type GatewayOrder = Omit< + GatewayOrderResponse & { + /** @description The gas refill in satoshis */ + gasRefill: number; + }, + "satsToConvertToEth" +> & { /** @description Get the actual token address received */ getTokenAddress(): string | undefined; /** @description Get the actual token received */ @@ -248,15 +263,6 @@ export interface GatewayOrderResponse { getStatus(esploraClient: EsploraClient, latestHeight?: number): Promise; }; -/** Order given by the Gateway API once the bitcoin tx is submitted */ -export type GatewayOrder = Omit< - GatewayOrderResponse & { - /** @description The gas refill in satoshis */ - gasRefill: number; - }, - "satsToConvertToEth" ->; - export type GatewayTokensInfo = { /** @description The base token (e.g. wBTC or tBTC) */ baseToken: Token,