diff --git a/package.json b/package.json index eb83b52..b3259d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.47", + "version": "0.19.48", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Orion/bridge/index.ts b/src/Orion/bridge/index.ts index f935eda..80f87fb 100644 --- a/src/Orion/bridge/index.ts +++ b/src/Orion/bridge/index.ts @@ -1,6 +1,6 @@ import type { ethers } from 'ethers'; import { - AtomicSwapStatus, type AtomicSwap, type SupportedChainId, + type AtomicSwap, type SupportedChainId, type Unit, INTERNAL_PROTOCOL_PRECISION } from '../../index.js'; import getHistoryExt from './getHistory.js'; @@ -8,14 +8,6 @@ import swapExt from './swap.js'; import { BigNumber } from 'bignumber.js'; -const backendStatusToAtomicSwapStatus = { - LOCKED: AtomicSwapStatus.ROUTING, - CLAIMED: AtomicSwapStatus.SETTLED, - REFUNDED: AtomicSwapStatus.REFUNDED, - REDEEMED: AtomicSwapStatus.SETTLED, - 'BEFORE-REDEEM': AtomicSwapStatus.ROUTING, -} as const; - export default class Bridge { constructor( private readonly unitsArray: Unit[], @@ -38,13 +30,12 @@ export default class Bridge { targetChainId, asset, sourceChainId, - status: asStatus, - claimed, sender, transactions, expiration, creationDate, } = atomicSwap; + const localSwap = externalStoredAtomicSwaps.find( (swap) => secretHash === swap.secretHash, ); @@ -61,53 +52,24 @@ export default class Bridge { assetName = '—'; // We don't want to display address even if we can't find asset name } - // Define status - let historyStatus = backendStatusToAtomicSwapStatus[asStatus.source]; - if (asStatus.source === 'LOCKED') { - const historySwap = bridgeHistory[secretHash]; - if (historySwap?.status.target === 'REDEEMED') { - historyStatus = AtomicSwapStatus.SETTLED; - } - } - if (claimed) historyStatus = AtomicSwapStatus.SETTLED; - let status: AtomicSwapStatus | undefined; - if ( - [AtomicSwapStatus.SETTLED, AtomicSwapStatus.REFUNDED].includes( - historyStatus, - ) - ) { - status = historyStatus; - } else { - status = localSwap !== undefined ? localSwap.status : historyStatus; - } - - // Define secret - const secret = localSwap !== undefined ? localSwap.secret : ''; - - // Define environment - const env = localSwap?.env; - return { - liquidityMigrationTxHash: localSwap?.liquidityMigrationTxHash, + localSwap, sourceNetwork: sourceChainId, targetNetwork: targetChainId, amount: new BigNumber(amount) .multipliedBy(new BigNumber(10).pow(INTERNAL_PROTOCOL_PRECISION)) .toString(), walletAddress: sender, - secret, secretHash, lockTransactionHash: transactions?.lock, refundTransactionHash: transactions?.refund, - status, asset: assetName, expiration: expiration?.lock ?? creationDate.getTime() + 60 * 60 * 24 * 4, // Or default 4 days creationDate: creationDate.getTime(), - env, redeemOrder: atomicSwap.redeemOrder, }; - }).filter((swap) => swap.env === undefined || swap.env === this.env); + }); } getHistory(address: string, limit = 1000) { diff --git a/src/types.ts b/src/types.ts index 3e7be3d..0c19b6c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -283,42 +283,9 @@ export type RedeemOrder = { claimReceiver: string } -export enum AtomicSwapStatus { - ROUTING_REQUESTED = 'ROUTING_REQUESTED', - ROUTING_PENDING = 'ROUTING_PENDING', - ROUTING = 'ROUTING', - ROUTING_FAILED = 'ROUTING_FAILED', - - // ACCEPTED = 'ACCEPTED', - FAILED = 'FAILED', - REJECTED = 'REJECTED', - - CHECK_REDEEM_THROUGH_OB_AVAILABLE = 'CHECK_REDEEM_THROUGH_OB_AVAILABLE', - // Redeem - // Blockchain redeem - READY_TO_REDEEM = 'READY_TO_REDEEM', - REDEEM_REQUESTED = 'REDEEM_REQUESTED', - REDEEM_PENDING = 'REDEEM_PENDING', - REDEEM_FAILED = 'REDEEM_FAILED', - - // Orion blockchain redeem - READY_TO_REDEEM_THROUGH_OB = 'READY_TO_REDEEM_THROUGH_OB', - REDEEM_PENDING_THROUGH_OB = 'REDEEM_PENDING_THROUGH_OB', - REDEEM_FAILED_THROUGH_OB = 'REDEEM_FAILED_THROUGH_OB', - - SETTLED = 'SETTLED', - - // Refund - REFUND_REQUESTED = 'REFUND_REQUESTED', - REFUND_PENDING = 'REFUND_PENDING', - REFUNDED = 'REFUNDED', - REFUND_FAILED = 'REFUND_FAILED', -} - export type AtomicSwap = { secret: string secretHash: string - status: AtomicSwapStatus walletAddress: string env?: string | undefined diff --git a/src/utils/convertPrice.ts b/src/utils/convertPrice.ts index 3a56e9c..a7807f4 100644 --- a/src/utils/convertPrice.ts +++ b/src/utils/convertPrice.ts @@ -7,10 +7,10 @@ export default function convertPrice( prices: Partial> // quoted in quoteAsset. [name]: priceQuotedInQuoteAsset ) { const assetInPrice = prices[assetInName]; - if (assetInPrice === undefined) throw Error(`Price conversion: AssetIn (${assetInName}) price is undefined`); + if (assetInPrice === undefined) throw Error(`Price conversion: AssetIn (${assetInName}) price is undefined. Available prices: ${JSON.stringify(prices)}`); const assetOutPrice = prices[assetOutName]; - if (assetOutPrice === undefined) throw Error(`Price conversion: AssetOut (${assetOutName}) price is undefined`); + if (assetOutPrice === undefined) throw Error(`Price conversion: AssetOut (${assetOutName}) price is undefined. Available prices: ${JSON.stringify(prices)}`); const assetInPriceBN = new BigNumber(assetInPrice); const assetOutPriceBN = new BigNumber(assetOutPrice); diff --git a/src/utils/index.ts b/src/utils/index.ts index 1a7aea2..df7e0d7 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -16,6 +16,7 @@ export { default as getNativeCryptocurrencyName } from './getNativeCryptocurrenc export { default as laconicParse } from './laconic-parse.js'; export { default as isValidChainId } from './isValidChainId.js'; export { default as isKnownEnv } from './isKnownEnv.js'; +export { default as removeFieldsFromObject } from './removeFieldsFromObject.js'; // export { default as HttpError } from './httpError'; export * from './typeHelpers.js'; diff --git a/src/utils/removeFieldsFromObject.ts b/src/utils/removeFieldsFromObject.ts new file mode 100644 index 0000000..276a3de --- /dev/null +++ b/src/utils/removeFieldsFromObject.ts @@ -0,0 +1,16 @@ +const removeFieldsFromObject = < + T extends Record, + K extends keyof T +>( + obj: T, + fields: K[] +): Omit => { + const result = { ...obj }; + for (const field of fields) { + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete + delete result[field]; + } + return result; +}; + +export default removeFieldsFromObject;