@velora-dex/widget 0.8.2 → 0.8.3-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/widget/BridgeList/hooks.d.ts +2 -2
- package/dist/components/widget/BridgeList/hooks.d.ts.map +1 -1
- package/dist/components/widget/BridgeList/hooks.js +79 -73
- package/dist/components/widget/BridgeList/hooks.js.map +1 -1
- package/dist/components/widget/BridgeSelectorExpandable/BridgeSelectorExpandable.d.ts +2 -2
- package/dist/components/widget/BridgeSelectorExpandable/BridgeSelectorExpandable.d.ts.map +1 -1
- package/dist/components/widget/BridgeSelectorExpandable/BridgeSelectorExpandable.js.map +1 -1
- package/dist/components/widget/TradeOverview/DeltaOrderTradeOverview.d.ts +2 -2
- package/dist/components/widget/TradeOverview/DeltaOrderTradeOverview.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/DeltaOrderTradeOverview.js +2 -2
- package/dist/components/widget/TradeOverview/DeltaOrderTradeOverview.js.map +1 -1
- package/dist/components/widget/TradeOverview/TwapOrderTradeOverview.d.ts +2 -2
- package/dist/components/widget/TradeOverview/TwapOrderTradeOverview.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/TwapOrderTradeOverview.js.map +1 -1
- package/dist/components/widget/TradeOverview/utils/useSwapAmountsWithSlippage.d.ts +4 -1
- package/dist/components/widget/TradeOverview/utils/useSwapAmountsWithSlippage.d.ts.map +1 -1
- package/dist/components/widget/TradeOverview/utils/useSwapAmountsWithSlippage.js +1 -1
- package/dist/components/widget/TradeOverview/utils/useSwapAmountsWithSlippage.js.map +1 -1
- package/dist/core/LimitOrderButton.d.ts.map +1 -1
- package/dist/core/LimitOrderButton.js +46 -52
- package/dist/core/LimitOrderButton.js.map +1 -1
- package/dist/core/TradeFlowScreenButton.d.ts +3 -4
- package/dist/core/TradeFlowScreenButton.d.ts.map +1 -1
- package/dist/core/TradeFlowScreenButton.js.map +1 -1
- package/dist/core/button/hooks/useWidgetButtonExtraProps.d.ts.map +1 -1
- package/dist/core/button/hooks/useWidgetButtonExtraProps.js +1 -4
- package/dist/core/button/hooks/useWidgetButtonExtraProps.js.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/inputs/hooks/useTokenFromInputProps.d.ts.map +1 -1
- package/dist/core/inputs/hooks/useTokenFromInputProps.js +2 -2
- package/dist/core/inputs/hooks/useTokenFromInputProps.js.map +1 -1
- package/dist/core/inputs/hooks/useTokenToInputProps.d.ts.map +1 -1
- package/dist/core/inputs/hooks/useTokenToInputProps.js +2 -2
- package/dist/core/inputs/hooks/useTokenToInputProps.js.map +1 -1
- package/dist/core/inputs/hooks/utils.d.ts.map +1 -1
- package/dist/core/inputs/hooks/utils.js +7 -5
- package/dist/core/inputs/hooks/utils.js.map +1 -1
- package/dist/core/limit/useLimitRate.d.ts +2 -3
- package/dist/core/limit/useLimitRate.d.ts.map +1 -1
- package/dist/core/limit/useLimitRate.js +54 -110
- package/dist/core/limit/useLimitRate.js.map +1 -1
- package/dist/core/limit/useLimitTokenToInputProps.d.ts.map +1 -1
- package/dist/core/limit/useLimitTokenToInputProps.js +1 -4
- package/dist/core/limit/useLimitTokenToInputProps.js.map +1 -1
- package/dist/core/swapDetails/fees.d.ts.map +1 -1
- package/dist/core/swapDetails/fees.js +16 -11
- package/dist/core/swapDetails/fees.js.map +1 -1
- package/dist/core/swapDetails/maxToPay.d.ts.map +1 -1
- package/dist/core/swapDetails/maxToPay.js +18 -17
- package/dist/core/swapDetails/maxToPay.js.map +1 -1
- package/dist/core/twap/twapDetails/minimumReceiveable.d.ts +2 -2
- package/dist/core/twap/twapDetails/minimumReceiveable.d.ts.map +1 -1
- package/dist/core/twap/twapDetails/minimumReceiveable.js.map +1 -1
- package/dist/events/hooks/useOnPriceUpdates.js.map +1 -1
- package/dist/events/types/priceChange.d.ts +2 -2
- package/dist/events/types/priceChange.d.ts.map +1 -1
- package/dist/events/types/swap.d.ts +2 -2
- package/dist/events/types/swap.d.ts.map +1 -1
- package/dist/events/types/twap.d.ts +2 -2
- package/dist/events/types/twap.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/bridge/useSelectedBridgePrice.d.ts +3 -4
- package/dist/hooks/swap/prices/delta/bridge/useSelectedBridgePrice.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/bridge/useSelectedBridgePrice.js.map +1 -1
- package/dist/hooks/swap/prices/delta/bridge/utils.d.ts +6 -3
- package/dist/hooks/swap/prices/delta/bridge/utils.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/bridge/utils.js +20 -17
- package/dist/hooks/swap/prices/delta/bridge/utils.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/twap/useCreateTwapOrder.d.ts +2 -2
- package/dist/hooks/swap/prices/delta/mutations/twap/useCreateTwapOrder.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/twap/useCreateTwapOrder.js +5 -5
- package/dist/hooks/swap/prices/delta/mutations/twap/useCreateTwapOrder.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/twap/usePostTwapOrder.d.ts +2 -2
- package/dist/hooks/swap/prices/delta/mutations/twap/usePostTwapOrder.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/twap/usePostTwapOrder.js +2 -2
- package/dist/hooks/swap/prices/delta/mutations/twap/usePostTwapOrder.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/twap/useTwapOrderToPost.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/twap/useTwapOrderToPost.js +27 -28
- package/dist/hooks/swap/prices/delta/mutations/twap/useTwapOrderToPost.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/types.d.ts +3 -3
- package/dist/hooks/swap/prices/delta/mutations/types.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useCancelDeltaOrders.js +2 -2
- package/dist/hooks/swap/prices/delta/mutations/useCancelDeltaOrders.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useCancelOrWithdrawAndCancelDeltaOrder.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useCancelOrWithdrawAndCancelDeltaOrder.js +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useCancelOrWithdrawAndCancelDeltaOrder.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useCreateDeltaOrder.d.ts +2 -2
- package/dist/hooks/swap/prices/delta/mutations/useCreateDeltaOrder.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useCreateDeltaOrder.js +5 -5
- package/dist/hooks/swap/prices/delta/mutations/useCreateDeltaOrder.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useDeltaOrderToPost.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useDeltaOrderToPost.js +27 -28
- package/dist/hooks/swap/prices/delta/mutations/useDeltaOrderToPost.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/usePostDeltaOrder.d.ts +2 -2
- package/dist/hooks/swap/prices/delta/mutations/usePostDeltaOrder.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/usePostDeltaOrder.js +2 -2
- package/dist/hooks/swap/prices/delta/mutations/usePostDeltaOrder.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useSendDepositPreSignDeltaOrderTx.js +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useSendDepositPreSignDeltaOrderTx.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useWithdrawAndCancelDeltaOrder.js +1 -1
- package/dist/hooks/swap/prices/delta/mutations/useWithdrawAndCancelDeltaOrder.js.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/utils.d.ts +5 -6
- package/dist/hooks/swap/prices/delta/mutations/utils.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/mutations/utils.js +6 -6
- package/dist/hooks/swap/prices/delta/mutations/utils.js.map +1 -1
- package/dist/hooks/swap/prices/delta/orders/unposted/utils.d.ts +3 -3
- package/dist/hooks/swap/prices/delta/orders/unposted/utils.js +3 -3
- package/dist/hooks/swap/prices/delta/orders/unposted/utils.js.map +1 -1
- package/dist/hooks/swap/prices/delta/orders/utils.d.ts +3 -3
- package/dist/hooks/swap/prices/delta/orders/utils.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/orders/utils.js +7 -4
- package/dist/hooks/swap/prices/delta/orders/utils.js.map +1 -1
- package/dist/hooks/swap/prices/delta/queries/errors.js.map +1 -1
- package/dist/hooks/swap/prices/delta/queries/useDeltaPriceQuery.d.ts +16 -33
- package/dist/hooks/swap/prices/delta/queries/useDeltaPriceQuery.d.ts.map +1 -1
- package/dist/hooks/swap/prices/delta/queries/useDeltaPriceQuery.js +6 -6
- package/dist/hooks/swap/prices/delta/queries/useDeltaPriceQuery.js.map +1 -1
- package/dist/hooks/swap/prices/factory.d.ts.map +1 -1
- package/dist/hooks/swap/prices/factory.js +1 -1
- package/dist/hooks/swap/prices/factory.js.map +1 -1
- package/dist/hooks/swap/prices/market/queries/useMarketPriceQuery.d.ts +1 -1
- package/dist/hooks/swap/prices/types.d.ts +2 -3
- package/dist/hooks/swap/prices/types.d.ts.map +1 -1
- package/dist/hooks/swap/prices/useSwapPrices.d.ts +3 -3
- package/dist/hooks/swap/prices/useSwapPrices.d.ts.map +1 -1
- package/dist/hooks/swap/prices/useSwapPrices.js.map +1 -1
- package/dist/hooks/swap/prices/useTokenInputsFromPrice.js +3 -3
- package/dist/hooks/swap/prices/useTokenInputsFromPrice.js.map +1 -1
- package/dist/hooks/swap/prices/useTokenInputsFromTwapPrice.d.ts +2 -2
- package/dist/hooks/swap/prices/useTokenInputsFromTwapPrice.d.ts.map +1 -1
- package/dist/hooks/swap/prices/useTokenInputsFromTwapPrice.js.map +1 -1
- package/dist/hooks/swap/prices/useTwapPrices.d.ts +4 -5
- package/dist/hooks/swap/prices/useTwapPrices.d.ts.map +1 -1
- package/dist/hooks/swap/prices/useTwapPrices.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/common/factory/depositAndSubmitOrderFactory.d.ts +10 -17
- package/dist/hooks/swap/tradeFlow/common/factory/depositAndSubmitOrderFactory.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/common/factory/depositAndSubmitOrderFactory.js +6 -6
- package/dist/hooks/swap/tradeFlow/common/factory/depositAndSubmitOrderFactory.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/useDeltaFlow.d.ts +5 -5
- package/dist/hooks/swap/tradeFlow/useDeltaFlow.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useDeltaFlow.js +119 -124
- package/dist/hooks/swap/tradeFlow/useDeltaFlow.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/useLimitOrderFlow.d.ts +2 -2
- package/dist/hooks/swap/tradeFlow/useLimitOrderFlow.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useLimitOrderFlow.js +159 -196
- package/dist/hooks/swap/tradeFlow/useLimitOrderFlow.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/useTwapFlow.d.ts +5 -5
- package/dist/hooks/swap/tradeFlow/useTwapFlow.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useTwapFlow.js +217 -229
- package/dist/hooks/swap/tradeFlow/useTwapFlow.js.map +1 -1
- package/dist/hooks/useSDK.d.ts +19 -3
- package/dist/hooks/useSDK.d.ts.map +1 -1
- package/dist/hooks/useSDK.js +65 -35
- package/dist/hooks/useSDK.js.map +1 -1
- package/dist/lib/queryClient.js +1 -1
- package/dist/lib/queryClient.js.map +1 -1
- package/dist/lib/utils/price.d.ts +5 -2
- package/dist/lib/utils/price.d.ts.map +1 -1
- package/dist/lib/utils/price.js +8 -5
- package/dist/lib/utils/price.js.map +1 -1
- package/dist/lib/utils/twap.d.ts +2 -2
- package/dist/lib/utils/twap.d.ts.map +1 -1
- package/dist/lib/utils/twap.js +2 -2
- package/dist/lib/utils/twap.js.map +1 -1
- package/package.json +2 -2
- package/dist/hooks/swap/prices/delta/bridge/const.d.ts +0 -8
- package/dist/hooks/swap/prices/delta/bridge/const.d.ts.map +0 -1
- package/dist/hooks/swap/prices/delta/bridge/const.js +0 -13
- package/dist/hooks/swap/prices/delta/bridge/const.js.map +0 -1
|
@@ -8,7 +8,7 @@ import { userPreSignTransactionsAtom as s } from "../../../../../../transactions
|
|
|
8
8
|
import { logger as c } from "./const.js";
|
|
9
9
|
import { deltaOrdersQueryKey as l, ensureDeltaOrderByHashFactory as u } from "../../queries/useDeltaOrders.js";
|
|
10
10
|
import d from "axios";
|
|
11
|
-
import { constructAxiosFetcher as f, constructGetDeltaOrders as p, constructPartialSDK as m,
|
|
11
|
+
import { constructAxiosFetcher as f, constructGetDeltaOrders as p, constructPartialSDK as m, constructPostDeltaOrderV2 as h, constructPostTWAPDeltaOrderV2 as g } from "@velora-dex/sdk";
|
|
12
12
|
import { TransactionReceiptNotFoundError as _ } from "viem";
|
|
13
13
|
import { getCallsStatus as v, getTransactionReceipt as y } from "@wagmi/core";
|
|
14
14
|
//#region src/hooks/swap/prices/delta/orders/unposted/utils.ts
|
|
@@ -66,11 +66,11 @@ async function w(e) {
|
|
|
66
66
|
excludeAgents: e.excludeAgents,
|
|
67
67
|
degenMode: e.degenMode
|
|
68
68
|
}, r;
|
|
69
|
-
return r = b(e) ? await t.
|
|
69
|
+
return r = b(e) ? await t.postTWAPDeltaOrderV2({
|
|
70
70
|
onChainOrderType: e.onChainOrderType,
|
|
71
71
|
order: e.order,
|
|
72
72
|
...n
|
|
73
|
-
}) : await t.
|
|
73
|
+
}) : await t.postDeltaOrderV2({
|
|
74
74
|
order: e.order,
|
|
75
75
|
...n
|
|
76
76
|
}), r && i.invalidateQueries({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["TransactionReceiptNotFoundError","constructAxiosFetcher","constructGetDeltaOrders","constructPartialSDK","
|
|
1
|
+
{"version":3,"file":"utils.js","names":["TransactionReceiptNotFoundError","constructAxiosFetcher","constructGetDeltaOrders","constructPartialSDK","constructPostDeltaOrderV2","constructPostTWAPDeltaOrderV2","DeltaAuction","GetDeltaOrdersFunctions","PostDeltaOrderV2Functions","PostTWAPDeltaOrderV2Functions","isBatchTransactionItem","isStandaloneTransactionItem","PreSignTransactionItem","apiConfigAtom","axios","getApiURL","jotaiStore","deltaOrdersQueryKey","ensureDeltaOrderByHashFactory","userPreSignTransactionsAtom","queryClient","getCallsStatus","getTransactionReceipt","wagmiConfig","PreSignTxData","UnpostedOrder","logger","ORDER_TTL_MS","PreSignTwapOrderToPost","isTwapUnpostedOrder","order","onChainOrderType","findPreSignTxForOrder","preSignTransactions","txHash","transactionHash","toLowerCase","callsId","find","tx","MinPostOrderSDK","constructSDK","chainId","apiURL","fetcher","get","shouldPostOrder","sdk","Promise","orderHash","ensureOrderByHash","e","isAxiosError","response","status","error","preSignTx","dropped","receipt","hash","callsStatus","id","processUnpostedOrder","Date","now","timestamp","shouldPost","baseParams","signature","partner","referrerAddress","type","includeAgents","excludeAgents","degenMode","postedOrder","postTWAPDeltaOrderV2","postDeltaOrderV2","invalidateQueries","queryKey","userAddress","owner","exact"],"sources":["../../../../../../../src/hooks/swap/prices/delta/orders/unposted/utils.ts"],"sourcesContent":["import { TransactionReceiptNotFoundError } from \"viem\";\n\nimport {\n constructAxiosFetcher,\n constructGetDeltaOrders,\n constructPartialSDK,\n constructPostDeltaOrderV2,\n constructPostTWAPDeltaOrderV2,\n type DeltaAuction,\n type GetDeltaOrdersFunctions,\n type PostDeltaOrderV2Functions,\n type PostTWAPDeltaOrderV2Functions,\n} from \"@velora-dex/sdk\";\nimport {\n isBatchTransactionItem,\n isStandaloneTransactionItem,\n} from \"@/transactions/utils\";\nimport type { PreSignTransactionItem } from \"@/transactions/types\";\nimport { apiConfigAtom } from \"@/core/state/apiConfigAtom\";\nimport axios from \"axios\";\nimport { getApiURL } from \"@/lib/constants/urls\";\nimport { jotaiStore } from \"@/core/store\";\nimport {\n deltaOrdersQueryKey,\n ensureDeltaOrderByHashFactory,\n} from \"../../queries/useDeltaOrders\";\nimport { userPreSignTransactionsAtom } from \"@/transactions/state/transactionsAtom\";\nimport { queryClient } from \"@/lib/queryClient\";\nimport { getCallsStatus, getTransactionReceipt } from \"@wagmi/core\";\nimport { wagmiConfig } from \"@/lib/web3/wagmi/config\";\nimport { type PreSignTxData, type UnpostedOrder } from \"./types\";\nimport { logger, ORDER_TTL_MS } from \"./const\";\nimport type { PreSignTwapOrderToPost } from \"../../mutations/types\";\n\nfunction isTwapUnpostedOrder(\n order: UnpostedOrder\n): order is PreSignTwapOrderToPost & PreSignTxData {\n return (\n \"onChainOrderType\" in order &&\n // order.onChainOrderType exists only for TWAP unposted orders,\n // but we add an extra check for defensive programming\n (order.onChainOrderType === \"TWAPOrder\" ||\n order.onChainOrderType === \"TWAPBuyOrder\")\n );\n}\n\nfunction findPreSignTxForOrder(\n order: UnpostedOrder,\n preSignTransactions: PreSignTransactionItem[]\n) {\n const txHash =\n \"transactionHash\" in order ? order.transactionHash.toLowerCase() : null;\n const callsId = \"callsId\" in order ? order.callsId.toLowerCase() : null;\n\n return preSignTransactions.find((tx) => {\n if (txHash && isStandaloneTransactionItem(tx)) {\n return tx.transactionHash.toLowerCase() === txHash;\n }\n\n return isBatchTransactionItem(tx) && tx.callsId.toLowerCase() === callsId;\n });\n}\n\ntype MinPostOrderSDK = GetDeltaOrdersFunctions &\n PostDeltaOrderV2Functions &\n PostTWAPDeltaOrderV2Functions;\n\nfunction constructSDK(chainId: number): MinPostOrderSDK {\n return constructPartialSDK(\n {\n apiURL: getApiURL(),\n chainId,\n fetcher: constructAxiosFetcher(axios, jotaiStore.get(apiConfigAtom)),\n },\n constructGetDeltaOrders,\n constructPostDeltaOrderV2,\n constructPostTWAPDeltaOrderV2\n );\n}\n\nasync function shouldPostOrder(\n order: UnpostedOrder,\n sdk: MinPostOrderSDK\n): Promise<boolean> {\n const { orderHash } = order;\n\n try {\n const ensureOrderByHash = ensureDeltaOrderByHashFactory({ sdk });\n await ensureOrderByHash(orderHash);\n return false; // order already posted\n } catch (e) {\n if (!axios.isAxiosError(e) || e.response?.status !== 404) {\n logger.error(\"ensureOrderByHash error\", { orderHash, error: e });\n return false; // safer not to retry if we cannot identify the error\n }\n }\n\n const preSignTx = findPreSignTxForOrder(\n order,\n jotaiStore.get(userPreSignTransactionsAtom)\n );\n\n // localStorage was cleared in between\n if (!preSignTx || preSignTx.dropped) return false;\n\n if (isStandaloneTransactionItem(preSignTx)) {\n // tx from localStorage reverted\n if (preSignTx.receipt?.status === \"reverted\") return false;\n\n try {\n const receipt = await getTransactionReceipt(wagmiConfig, {\n hash: preSignTx.transactionHash,\n });\n // tx reverted\n if (receipt.status === \"reverted\") return false;\n } catch (error) {\n // tx may still be pending if no receipt is returned\n if (!(error instanceof TransactionReceiptNotFoundError)) {\n return false; // do not retry for other errors\n }\n }\n } else {\n // batch from localStorage failed\n if (preSignTx.callsStatus === \"failure\") return false;\n\n try {\n const callsStatus = await getCallsStatus(wagmiConfig, {\n id: preSignTx.callsId,\n });\n // batch failed\n if (callsStatus?.status === \"failure\") return false;\n } catch {\n // likely wallet that doesn't support batches,\n // or different wallet was connected and callsId is not found\n }\n }\n\n return true;\n}\n\nexport async function processUnpostedOrder(order: UnpostedOrder) {\n // ignore expired orders\n if (Date.now() - order.timestamp > ORDER_TTL_MS) return;\n\n const sdk = constructSDK(order.chainId);\n\n const shouldPost = await shouldPostOrder(order, sdk);\n if (!shouldPost) return;\n\n const baseParams = {\n signature: order.signature,\n partner: order.partner,\n referrerAddress: order.referrerAddress,\n type: order.type,\n includeAgents: order.includeAgents,\n excludeAgents: order.excludeAgents,\n degenMode: order.degenMode,\n };\n\n let postedOrder: DeltaAuction;\n\n if (isTwapUnpostedOrder(order)) {\n postedOrder = await sdk.postTWAPDeltaOrderV2({\n onChainOrderType: order.onChainOrderType,\n order: order.order,\n ...baseParams,\n });\n } else {\n postedOrder = await sdk.postDeltaOrderV2({\n order: order.order,\n ...baseParams,\n });\n }\n\n if (postedOrder) {\n // invalidate delta orders query so UI picks up the new order\n queryClient.invalidateQueries({\n queryKey: deltaOrdersQueryKey({ userAddress: postedOrder.order.owner }),\n exact: false,\n });\n }\n\n return postedOrder;\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCA,SAAS6B,EACPC,GACiD;CACjD,OACE,sBAAsBA,MAGrBA,EAAMC,qBAAqB,eAC1BD,EAAMC,qBAAqB;;AAIjC,SAASC,EACPF,GACAG,GACA;CACA,IAAMC,IACJ,qBAAqBJ,IAAQA,EAAMK,gBAAgBC,aAAa,GAAG,MAC/DC,IAAU,aAAaP,IAAQA,EAAMO,QAAQD,aAAa,GAAG;CAEnE,OAAOH,EAAoBK,MAAMC,MAC3BL,KAAUvB,EAA4B4B,EAAG,GACpCA,EAAGJ,gBAAgBC,aAAa,KAAKF,IAGvCxB,EAAuB6B,EAAG,IAAIA,EAAGF,QAAQD,aAAa,KAAKC,EAClE;;AAOJ,SAASI,EAAaC,GAAkC;CACtD,OAAOvC,EACL;EACEwC,QAAQ5B,GAAW;EACnB2B;EACAE,SAAS3C,EAAsBa,GAAOE,EAAW6B,IAAIhC,EAAc,CAAA;EACpE,EACDX,GACAE,GACAC,EACD;;AAGH,eAAeyC,EACbhB,GACAiB,GACkB;CAClB,IAAM,EAAEE,iBAAcnB;CAEtB,IAAI;EAGF,OADA,MAD0BZ,EAA8B,EAAE6B,QAAK,CACzDG,CAAkBD,EAAU,EAC3B;UACAE,GAAG;EACV,IAAI,CAACrC,EAAMsC,aAAaD,EAAE,IAAIA,EAAEE,UAAUC,WAAW,KAEnD,OADA5B,EAAO6B,MAAM,2BAA2B;GAAEN;GAAWM,OAAOJ;GAAG,CAAC,EACzD;;CAIX,IAAMK,IAAYxB,EAChBF,GACAd,EAAW6B,IAAI1B,EACjB,CAAC;CAGD,IAAI,CAACqC,KAAaA,EAAUC,SAAS,OAAO;CAE5C,IAAI9C,EAA4B6C,EAAU,EAAE;EAE1C,IAAIA,EAAUE,SAASJ,WAAW,YAAY,OAAO;EAErD,IAAI;GAKF,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aAuctionStatus, DeltaPriceV2, ExternalDeltaOrder, ProductiveDeltaOrder, SwapSideUnion, TWAPBuyDeltaOrder, TWAPDeltaOrder } from '@velora-dex/sdk';
|
|
2
2
|
import { DeltaAuctionWithTwapOrder, ExecutedDeltaAuction, FailedDeltaAuction, TwapSellOrBuyOrder } from './types';
|
|
3
3
|
export declare function isTwapSellDeltaOrder(order: DeltaAuction["order"]): order is TWAPDeltaOrder;
|
|
4
4
|
export declare function isTwapBuyDeltaOrder(order: DeltaAuction["order"]): order is TWAPBuyDeltaOrder;
|
|
@@ -68,8 +68,8 @@ export declare function getOrderTokenAddresses(order: DeltaAuction["order"]): {
|
|
|
68
68
|
destToken: string;
|
|
69
69
|
};
|
|
70
70
|
export declare function getAuctionSwapSide(auction: DeltaAuction): SwapSideUnion;
|
|
71
|
-
export declare function getSwapSideFromDeltaPrice(price:
|
|
72
|
-
export declare function getSwapSideFromDeltaOrder(order: DeltaAuctionOrder | ExternalDeltaOrder): SwapSideUnion;
|
|
71
|
+
export declare function getSwapSideFromDeltaPrice(price: DeltaPriceV2): SwapSideUnion;
|
|
72
|
+
export declare function getSwapSideFromDeltaOrder(order: DeltaAuctionOrder | ExternalDeltaOrder | ProductiveDeltaOrder): SwapSideUnion;
|
|
73
73
|
export declare function getSwapSideFromTwapOrderType(onChainOrderType: "TWAPOrder" | "TWAPBuyOrder"): SwapSideUnion;
|
|
74
74
|
export {};
|
|
75
75
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../src/hooks/swap/prices/delta/orders/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../src/hooks/swap/prices/delta/orders/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAC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qBAAqB,CAoBvB;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC;;;EASlE;AAkED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,CAMvE;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,YAAY,GAAG,aAAa,CAE5E;AAOD,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,oBAAoB,GACnE,aAAa,CAKf;AAOD,wBAAgB,4BAA4B,CAC1C,gBAAgB,EAAE,WAAW,GAAG,cAAc,GAC7C,aAAa,CAEf"}
|
|
@@ -154,9 +154,12 @@ function k(e) {
|
|
|
154
154
|
if (b(e)) return w(e);
|
|
155
155
|
if (l(e)) return O(e.transactions);
|
|
156
156
|
let t = e.order, r = t.srcAmount, i = t.expectedAmount || t.destAmount;
|
|
157
|
-
return o(t) ? {
|
|
157
|
+
return o(t) ? e.type === "LIMIT" ? {
|
|
158
158
|
srcAmount: r,
|
|
159
|
-
destAmount:
|
|
159
|
+
destAmount: i
|
|
160
|
+
} : {
|
|
161
|
+
srcAmount: r,
|
|
162
|
+
destAmount: e.bridgeMetadata?.outputAmount || e.bridgeMetadata?.expectedOutputAmount || n(i, t.bridge.scalingFactor).toFixed(0)
|
|
160
163
|
} : {
|
|
161
164
|
srcAmount: r,
|
|
162
165
|
destAmount: i
|
|
@@ -166,14 +169,14 @@ function A(e) {
|
|
|
166
169
|
return b(e) ? F(e.onChainOrderType) : N(e.order);
|
|
167
170
|
}
|
|
168
171
|
function j(e) {
|
|
169
|
-
return e.
|
|
172
|
+
return e.side;
|
|
170
173
|
}
|
|
171
174
|
var M = {
|
|
172
175
|
0: "SELL",
|
|
173
176
|
1: "BUY"
|
|
174
177
|
};
|
|
175
178
|
function N(e) {
|
|
176
|
-
return M[e.kind];
|
|
179
|
+
return "strategy" in e ? "SELL" : M[e.kind];
|
|
177
180
|
}
|
|
178
181
|
var P = {
|
|
179
182
|
TWAPOrder: "SELL",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["BridgeStatus","DeltaAuction","DeltaAuctionOrder","DeltaAuctionStatus","DeltaPrice","ExternalDeltaOrder","SwapSideUnion","TWAPBuyDeltaOrder","TWAPDeltaOrder","DeltaAuctionTransaction","DeltaAuctionWithTwapOrder","ExecutedDeltaAuction","FailedDeltaAuction","TwapSellOrBuyOrder","replaceUnderscoresWithSpaces","Big","millisecondsToSeconds","scaleByFactor","isTwapSellDeltaOrder","order","isTwapBuyDeltaOrder","isOrderCrosschain","bridge","destinationChainId","isDeltaAuctionData","data","isCrosschainAuctionExecuted","auction","isTwapAuction","transactions","length","numSlices","bridgeStatus","isExecutedDeltaAuction","status","isFailedDeltaAuction","DeltaOrderStatusChecker","failed","has","isCanceledDeltaAuction","isDeltaAuctionExpired","pending","Set","executing","active","success","completed","cancellable","BridgeStatusChecker","VisualOrderStatus","getSingleChainOrderStatus","orderStatus","getCrossChainOrderStatus","getAuctionDestChainId","chainId","Pick","getOverallOrderStatus","getDisplayedOrderStatus","onChainOrderType","isTwapOrder","getTotalTwapSrcAmount","totalSrcAmount","maxSrcAmount","getTotalTwapDestAmount","destAmount","destAmountPerSlice","times","totalDestAmount","scalingFactor","toFixed","getTotalTwapOrderAmounts","srcAmount","getTwapAuctionAmounts","twapAuction","isExecuted","getTransactionAmounts","getTwapOrderDeadlineFromSlices","createdAt","Math","floor","Date","getTime","interval","UnifiedDeltaOrderData","srcChainId","destChainId","srcToken","destToken","swapSide","getUnifiedDeltaOrderData","getOrderTokenAddresses","getAuctionAmounts","getAuctionSwapSide","outputToken","reduce","acc","spentAmount","receivedAmount","bridgeMetadata","BigInt","outputAmount","toString","isTwap","expectedAmount","getSwapSideFromTwapOrderType","getSwapSideFromDeltaOrder","getSwapSideFromDeltaPrice","price","srcAmountBeforeFee","OrderKindToSwapSide","const","kind","TwapTypeToSwapSide","TWAPOrder","TWAPBuyOrder"],"sources":["../../../../../../src/hooks/swap/prices/delta/orders/utils.ts"],"sourcesContent":["import type {\n BridgeStatus,\n DeltaAuction,\n DeltaAuctionOrder,\n DeltaAuctionStatus,\n DeltaPrice,\n ExternalDeltaOrder,\n SwapSideUnion,\n TWAPBuyDeltaOrder,\n TWAPDeltaOrder,\n} from \"@velora-dex/sdk\";\nimport type {\n DeltaAuctionTransaction,\n DeltaAuctionWithTwapOrder,\n ExecutedDeltaAuction,\n FailedDeltaAuction,\n TwapSellOrBuyOrder,\n} from \"./types\";\nimport { replaceUnderscoresWithSpaces } from \"@/lib/utils\";\nimport Big from \"big.js\";\nimport { millisecondsToSeconds } from \"@/lib/utils/time\";\nimport { scaleByFactor } from \"@/lib/utils/scaleFactor\";\n\nexport function isTwapSellDeltaOrder(\n order: DeltaAuction[\"order\"]\n): order is TWAPDeltaOrder {\n return \"destAmountPerSlice\" in order && \"totalSrcAmount\" in order;\n}\n\nexport function isTwapBuyDeltaOrder(\n order: DeltaAuction[\"order\"]\n): order is TWAPBuyDeltaOrder {\n return \"totalDestAmount\" in order && \"maxSrcAmount\" in order;\n}\n\nexport function isOrderCrosschain(\n order: DeltaAuction[\"order\"]\n): order is DeltaAuctionOrder | TwapSellOrBuyOrder {\n return (\n \"bridge\" in order && order.bridge && order.bridge.destinationChainId !== 0\n );\n}\n\nexport function isDeltaAuctionData(data: unknown): data is DeltaAuction {\n return (\n typeof data === \"object\" &&\n data !== null &&\n \"id\" in data &&\n \"chainId\" in data &&\n \"status\" in data &&\n \"order\" in data &&\n \"orderHash\" in data\n );\n}\n\nfunction isCrosschainAuctionExecuted(\n auction: DeltaAuction\n): auction is ExecutedDeltaAuction {\n // crosschain TWAP order is executed when all slices are executed on source chain\n if (isTwapAuction(auction)) {\n return auction.transactions.length === auction.order.numSlices;\n }\n\n // crosschain Order is executed if bridgeStatus is filled\n return auction.bridgeStatus === \"filled\";\n}\n\nexport function isExecutedDeltaAuction(\n auction: DeltaAuction\n): auction is ExecutedDeltaAuction {\n if (auction.status !== \"EXECUTED\") return false;\n\n if (isOrderCrosschain(auction.order)) {\n return isCrosschainAuctionExecuted(auction);\n }\n\n return true;\n}\n\nexport function isFailedDeltaAuction(\n auction: DeltaAuction\n): auction is FailedDeltaAuction {\n // already failed on srcChain, whether Order is crosschain or not\n if (DeltaOrderStatusChecker.failed.has(auction.status)) return true;\n\n // crosschain Order is executed on srcChain, but failed on destChain\n if (auction.status === \"EXECUTED\" && isOrderCrosschain(auction.order)) {\n return (\n auction.bridgeStatus === \"expired\" || auction.bridgeStatus === \"refunded\"\n );\n }\n\n return false;\n}\n\nexport function isCanceledDeltaAuction(\n auction: DeltaAuction\n): auction is DeltaAuction & {\n status: \"CANCELLED\";\n} {\n return auction.status === \"CANCELLED\";\n}\n\nexport function isDeltaAuctionExpired(\n auction: DeltaAuction\n): auction is DeltaAuction & {\n status: \"EXPIRED\";\n} {\n return auction.status === \"EXPIRED\";\n}\n\n/// ------------------- Order status checks -------------------\n\n// specific to submit DeltaOrder substep\nexport const DeltaOrderStatusChecker = {\n pending: new Set<DeltaAuctionStatus>([\n \"NOT_STARTED\",\n \"RUNNING\",\n \"AWAITING_PRE_SIGNATURE\",\n \"CANCELLING\",\n ]), // adjust for when we want to show Pending state\n executing: new Set<DeltaAuctionStatus>([\"EXECUTING\"]),\n active: new Set<DeltaAuctionStatus>([\n \"EXECUTING\",\n \"NOT_STARTED\",\n \"AWAITING_PRE_SIGNATURE\",\n \"RUNNING\",\n \"EXECUTED\",\n \"FAILED\",\n \"EXPIRED\",\n \"CANCELLED\",\n \"CANCELLING\",\n ]), // order always active, unless actual submission breaks\n success: new Set<DeltaAuctionStatus>([\"EXECUTED\"]),\n completed: new Set<DeltaAuctionStatus>([\n \"EXECUTED\",\n \"FAILED\",\n \"EXPIRED\",\n \"CANCELLED\",\n \"REFUNDED\",\n ]),\n failed: new Set<DeltaAuctionStatus>([\n \"FAILED\",\n \"EXPIRED\",\n \"CANCELLED\",\n \"REFUNDED\",\n ]),\n cancellable: new Set<DeltaAuctionStatus>([\n \"NOT_STARTED\",\n \"RUNNING\",\n \"AWAITING_PRE_SIGNATURE\",\n \"EXECUTING\",\n \"SUSPENDED\",\n ]),\n};\n\nexport const BridgeStatusChecker = {\n pending: new Set<BridgeStatus>([\"pending\"]),\n completed: new Set<BridgeStatus>([\"filled\", \"expired\", \"refunded\"]),\n failed: new Set<BridgeStatus>([\"expired\", \"refunded\"]),\n};\n\n// visually we show only \"In progress\", \"Executing\" and separate components for success and failure\nexport type VisualOrderStatus =\n | \"pending\"\n | \"executing\"\n | \"failed\"\n | \"confirmed\";\n\nexport function getSingleChainOrderStatus(\n orderStatus: DeltaAuctionStatus\n): VisualOrderStatus {\n if (DeltaOrderStatusChecker.pending.has(orderStatus)) return \"pending\";\n\n if (DeltaOrderStatusChecker.executing.has(orderStatus)) return \"executing\";\n\n if (DeltaOrderStatusChecker.failed.has(orderStatus)) return \"failed\";\n\n return \"confirmed\";\n}\n\nexport function getCrossChainOrderStatus(\n status: DeltaAuctionStatus,\n bridgeStatus: BridgeStatus | null\n): VisualOrderStatus {\n if (\n DeltaOrderStatusChecker.failed.has(status) ||\n (bridgeStatus && BridgeStatusChecker.failed.has(bridgeStatus))\n )\n return \"failed\";\n\n if (bridgeStatus === \"filled\") return \"confirmed\";\n\n // Order awaiting signature can't be already executing no matter the bridge status\n if (status === \"AWAITING_PRE_SIGNATURE\") return \"pending\";\n\n return \"executing\"; // executed already on source chain, but not yet on destination chain,\n // visually we show \"executing\"\n}\n\nexport function getAuctionDestChainId({\n order,\n chainId,\n}: Pick<DeltaAuction, \"order\" | \"chainId\">) {\n return isOrderCrosschain(order) ? order.bridge.destinationChainId : chainId;\n}\n\n/**\n * For Delta Orders in the Trade Flow to switch between flow steps based on the order status\n */\nexport function getOverallOrderStatus(\n order: Pick<DeltaAuction, \"status\" | \"bridgeStatus\" | \"order\">\n): VisualOrderStatus {\n return isOrderCrosschain(order.order)\n ? // TWAP orders don't have order.bridgeStatus, instead\n // each slice has its own bridgeStatus in transactions[].bridgeMetadata,\n // and some slices could have been bridged while others not yet, or refunded\n // @TODO display \"partially executed\" for TWAP?\n getCrossChainOrderStatus(order.status, order.bridgeStatus)\n : getSingleChainOrderStatus(order.status);\n}\n\n/**\n * For displaying order status to users.\n */\nexport function getDisplayedOrderStatus(status: DeltaAuctionStatus): string {\n if (status === \"AWAITING_PRE_SIGNATURE\") return \"UNSIGNED\";\n return replaceUnderscoresWithSpaces(status);\n}\n\n// -------------------- TWAP -------------------\n\nexport function isTwapAuction(\n order: DeltaAuction\n): order is DeltaAuctionWithTwapOrder {\n return (\n order.onChainOrderType === \"TWAPOrder\" ||\n order.onChainOrderType === \"TWAPBuyOrder\"\n );\n}\n\nexport function isTwapOrder(\n order: DeltaAuction[\"order\"]\n): order is TwapSellOrBuyOrder {\n return \"numSlices\" in order && typeof order.numSlices === \"number\";\n}\n\nfunction getTotalTwapSrcAmount(order: TwapSellOrBuyOrder) {\n return \"totalSrcAmount\" in order ? order.totalSrcAmount : order.maxSrcAmount;\n}\n\nfunction getTotalTwapDestAmount(order: TwapSellOrBuyOrder) {\n const destAmount =\n \"destAmountPerSlice\" in order\n ? Big(order.destAmountPerSlice).times(order.numSlices) // SELL\n : Big(order.totalDestAmount); // BUY\n\n if (isOrderCrosschain(order)) {\n return scaleByFactor(destAmount, order.bridge.scalingFactor).toFixed(0);\n }\n\n return destAmount.toFixed(0);\n}\n\nexport function getTotalTwapOrderAmounts(order: TwapSellOrBuyOrder) {\n const srcAmount = getTotalTwapSrcAmount(order);\n const destAmount = getTotalTwapDestAmount(order);\n return { srcAmount, destAmount };\n}\n\nfunction getTwapAuctionAmounts(twapAuction: DeltaAuctionWithTwapOrder) {\n const isExecuted =\n twapAuction.status === \"EXECUTED\" &&\n twapAuction.transactions.length === twapAuction.order.numSlices;\n\n if (isExecuted) {\n return getTransactionAmounts(\n twapAuction.transactions as DeltaAuctionTransaction[]\n );\n }\n\n return getTotalTwapOrderAmounts(twapAuction.order);\n}\n\n/** Returns the order deadline based on slices and interval */\nexport function getTwapOrderDeadlineFromSlices(\n order: TwapSellOrBuyOrder,\n createdAt: string\n) {\n return Math.floor(\n millisecondsToSeconds(new Date(createdAt).getTime()) +\n order.numSlices * order.interval // order.interval is in seconds\n );\n}\n\n// -------------------- Auction Unified Data --------------------\n\ntype UnifiedDeltaOrderData = {\n /** @description source chain id */\n srcChainId: number;\n /** @description destination chain id (same as source chain id for single chain orders) */\n destChainId: number;\n /** @description input token amount */\n srcAmount: string;\n /** @description output token amount (expected amount for pending orders, actual received amount for executed orders) */\n destAmount: string;\n /** @description input token address */\n srcToken: string;\n /** @description output token address */\n destToken: string;\n /** @description swap side of the order */\n swapSide: SwapSideUnion;\n};\n\nexport function getUnifiedDeltaOrderData(\n auction: DeltaAuction\n): UnifiedDeltaOrderData {\n const { order, chainId } = auction;\n\n const { srcToken, destToken } = getOrderTokenAddresses(order);\n const { srcAmount, destAmount } = getAuctionAmounts(auction);\n\n const srcChainId = chainId;\n const destChainId = getAuctionDestChainId({ order, chainId });\n\n const swapSide = getAuctionSwapSide(auction);\n\n return {\n srcChainId,\n destChainId,\n srcAmount,\n destAmount,\n srcToken,\n destToken,\n swapSide,\n };\n}\n\nexport function getOrderTokenAddresses(order: DeltaAuction[\"order\"]) {\n const srcToken = order.srcToken;\n const destToken = isOrderCrosschain(order)\n ? order.bridge.outputToken\n : order.destToken;\n return {\n srcToken,\n destToken,\n };\n}\n\nfunction getTransactionAmounts(transactions: DeltaAuctionTransaction[]) {\n const { srcAmount, destAmount } = transactions.reduce(\n (acc, { spentAmount, receivedAmount, bridgeMetadata }) => {\n return {\n srcAmount: acc.srcAmount + BigInt(spentAmount),\n destAmount:\n acc.destAmount +\n BigInt(bridgeMetadata ? bridgeMetadata.outputAmount : receivedAmount),\n };\n },\n {\n srcAmount: 0n,\n destAmount: 0n,\n }\n );\n\n return {\n srcAmount: srcAmount.toString(),\n destAmount: destAmount.toString(),\n };\n}\n\nfunction getAuctionAmounts(auction: DeltaAuction) {\n const isTwap = isTwapAuction(auction);\n if (isTwap) {\n return getTwapAuctionAmounts(auction);\n }\n\n const isExecuted = isExecutedDeltaAuction(auction);\n if (isExecuted) {\n return getTransactionAmounts(\n auction.transactions as DeltaAuctionTransaction[]\n );\n }\n\n const order = auction.order;\n\n const srcAmount = order.srcAmount;\n const destAmount = order.expectedAmount || order.destAmount;\n\n if (isOrderCrosschain(order)) {\n return {\n srcAmount,\n destAmount: scaleByFactor(destAmount, order.bridge.scalingFactor).toFixed(\n 0\n ),\n };\n }\n\n return {\n srcAmount,\n destAmount,\n };\n}\n\n// -------------------- SwapSide --------------------\n\nexport function getAuctionSwapSide(auction: DeltaAuction): SwapSideUnion {\n if (isTwapAuction(auction)) {\n // TWAP orders have onChainOrderType instead of kind\n return getSwapSideFromTwapOrderType(auction.onChainOrderType);\n }\n return getSwapSideFromDeltaOrder(auction.order);\n}\n\nexport function getSwapSideFromDeltaPrice(price: DeltaPrice): SwapSideUnion {\n if (price.srcAmountBeforeFee) {\n // srcAmountBeforeFee is only available for BUY side\n return \"BUY\";\n }\n return \"SELL\";\n}\n\nconst OrderKindToSwapSide = {\n 0: \"SELL\",\n 1: \"BUY\",\n} as const;\n\nexport function getSwapSideFromDeltaOrder(\n order: DeltaAuctionOrder | ExternalDeltaOrder\n): SwapSideUnion {\n return OrderKindToSwapSide[order.kind];\n}\n\nconst TwapTypeToSwapSide = {\n TWAPOrder: \"SELL\",\n TWAPBuyOrder: \"BUY\",\n} as const;\n\nexport function getSwapSideFromTwapOrderType(\n onChainOrderType: \"TWAPOrder\" | \"TWAPBuyOrder\"\n): SwapSideUnion {\n return TwapTypeToSwapSide[onChainOrderType];\n}\n"],"mappings":";;;;;AAuBA,SAAgBkB,EACdC,GACyB;CACzB,OAAO,wBAAwBA,KAAS,oBAAoBA;;AAG9D,SAAgBC,EACdD,GAC4B;CAC5B,OAAO,qBAAqBA,KAAS,kBAAkBA;;AAGzD,SAAgBE,EACdF,GACiD;CACjD,OACE,YAA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AAYA,EAAWqC,UAAS;EACjC;;AAGH,SAASV,EAAkBhE,GAAuB;CAEhD,IADeC,EAAcD,EACzB2E,EACF,OAAO9B,EAAsB7C,EAAQ;CAIvC,IADmBM,EAAuBN,EACtC+C,EACF,OAAOC,EACLhD,EAAQE,aACT;CAGH,IAAMV,IAAQQ,EAAQR,OAEhBoD,IAAYpD,EAAMoD,WAClBP,IAAa7C,EAAMoF,kBAAkBpF,EAAM6C;CAWjD,OATI3C,EAAkBF,EAAM,GACnB;EACLoD;EACAP,YAAY/C,EAAc+C,GAAY7C,EAAMG,OAAO8C,cAAc,CAACC,QAChE,EACF;EACD,GAGI;EACLE;EACAP;EACD;;AAKH,SAAgB4B,EAAmBjE,GAAsC;CAKvE,OAJIC,EAAcD,EAAQ,GAEjB6E,EAA6B7E,EAAQ+B,iBAAiB,GAExD+C,EAA0B9E,EAAQR,MAAM;;AAGjD,SAAgBuF,EAA0BC,GAAkC;CAK1E,OAJIA,EAAMC,qBAED,QAEF;;AAGT,IAAMC,IAAsB;CAC1B,GAAG;CACH,GAAG;CACJ;AAED,SAAgBJ,EACdtF,GACe;CACf,OAAO0F,EAAoB1F,EAAM4F;;AAGnC,IAAMC,IAAqB;CACzBC,WAAW;CACXC,cAAc;CACf;AAED,SAAgBV,EACd9C,GACe;CACf,OAAOsD,EAAmBtD"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["BridgeStatus","DeltaAuction","DeltaAuctionOrder","DeltaAuctionStatus","DeltaPriceV2","ExternalDeltaOrder","ProductiveDeltaOrder","SwapSideUnion","TWAPBuyDeltaOrder","TWAPDeltaOrder","DeltaAuctionTransaction","DeltaAuctionWithTwapOrder","ExecutedDeltaAuction","FailedDeltaAuction","TwapSellOrBuyOrder","replaceUnderscoresWithSpaces","Big","millisecondsToSeconds","scaleByFactor","isTwapSellDeltaOrder","order","isTwapBuyDeltaOrder","isOrderCrosschain","bridge","destinationChainId","isDeltaAuctionData","data","isCrosschainAuctionExecuted","auction","isTwapAuction","transactions","length","numSlices","bridgeStatus","isExecutedDeltaAuction","status","isFailedDeltaAuction","DeltaOrderStatusChecker","failed","has","isCanceledDeltaAuction","isDeltaAuctionExpired","pending","Set","executing","active","success","completed","cancellable","BridgeStatusChecker","VisualOrderStatus","getSingleChainOrderStatus","orderStatus","getCrossChainOrderStatus","getAuctionDestChainId","chainId","Pick","getOverallOrderStatus","getDisplayedOrderStatus","onChainOrderType","isTwapOrder","getTotalTwapSrcAmount","totalSrcAmount","maxSrcAmount","getTotalTwapDestAmount","destAmount","destAmountPerSlice","times","totalDestAmount","scalingFactor","toFixed","getTotalTwapOrderAmounts","srcAmount","getTwapAuctionAmounts","twapAuction","isExecuted","getTransactionAmounts","getTwapOrderDeadlineFromSlices","createdAt","Math","floor","Date","getTime","interval","UnifiedDeltaOrderData","srcChainId","destChainId","srcToken","destToken","swapSide","getUnifiedDeltaOrderData","getOrderTokenAddresses","getAuctionAmounts","getAuctionSwapSide","outputToken","reduce","acc","spentAmount","receivedAmount","bridgeMetadata","BigInt","outputAmount","toString","isTwap","expectedAmount","type","expectedOutputAmount","getSwapSideFromTwapOrderType","getSwapSideFromDeltaOrder","getSwapSideFromDeltaPrice","price","side","OrderKindToSwapSide","const","kind","TwapTypeToSwapSide","TWAPOrder","TWAPBuyOrder"],"sources":["../../../../../../src/hooks/swap/prices/delta/orders/utils.ts"],"sourcesContent":["import type {\n BridgeStatus,\n DeltaAuction,\n DeltaAuctionOrder,\n DeltaAuctionStatus,\n DeltaPriceV2,\n ExternalDeltaOrder,\n ProductiveDeltaOrder,\n SwapSideUnion,\n TWAPBuyDeltaOrder,\n TWAPDeltaOrder,\n} from \"@velora-dex/sdk\";\nimport type {\n DeltaAuctionTransaction,\n DeltaAuctionWithTwapOrder,\n ExecutedDeltaAuction,\n FailedDeltaAuction,\n TwapSellOrBuyOrder,\n} from \"./types\";\nimport { replaceUnderscoresWithSpaces } from \"@/lib/utils\";\nimport Big from \"big.js\";\nimport { millisecondsToSeconds } from \"@/lib/utils/time\";\nimport { scaleByFactor } from \"@/lib/utils/scaleFactor\";\n\nexport function isTwapSellDeltaOrder(\n order: DeltaAuction[\"order\"]\n): order is TWAPDeltaOrder {\n return \"destAmountPerSlice\" in order && \"totalSrcAmount\" in order;\n}\n\nexport function isTwapBuyDeltaOrder(\n order: DeltaAuction[\"order\"]\n): order is TWAPBuyDeltaOrder {\n return \"totalDestAmount\" in order && \"maxSrcAmount\" in order;\n}\n\nexport function isOrderCrosschain(\n order: DeltaAuction[\"order\"]\n): order is DeltaAuctionOrder | TwapSellOrBuyOrder {\n return (\n \"bridge\" in order && order.bridge && order.bridge.destinationChainId !== 0\n );\n}\n\nexport function isDeltaAuctionData(data: unknown): data is DeltaAuction {\n return (\n typeof data === \"object\" &&\n data !== null &&\n \"id\" in data &&\n \"chainId\" in data &&\n \"status\" in data &&\n \"order\" in data &&\n \"orderHash\" in data\n );\n}\n\nfunction isCrosschainAuctionExecuted(\n auction: DeltaAuction\n): auction is ExecutedDeltaAuction {\n // crosschain TWAP order is executed when all slices are executed on source chain\n if (isTwapAuction(auction)) {\n return auction.transactions.length === auction.order.numSlices;\n }\n\n // crosschain Order is executed if bridgeStatus is filled\n return auction.bridgeStatus === \"filled\";\n}\n\nexport function isExecutedDeltaAuction(\n auction: DeltaAuction\n): auction is ExecutedDeltaAuction {\n if (auction.status !== \"EXECUTED\") return false;\n\n if (isOrderCrosschain(auction.order)) {\n return isCrosschainAuctionExecuted(auction);\n }\n\n return true;\n}\n\nexport function isFailedDeltaAuction(\n auction: DeltaAuction\n): auction is FailedDeltaAuction {\n // already failed on srcChain, whether Order is crosschain or not\n if (DeltaOrderStatusChecker.failed.has(auction.status)) return true;\n\n // crosschain Order is executed on srcChain, but failed on destChain\n if (auction.status === \"EXECUTED\" && isOrderCrosschain(auction.order)) {\n return (\n auction.bridgeStatus === \"expired\" || auction.bridgeStatus === \"refunded\"\n );\n }\n\n return false;\n}\n\nexport function isCanceledDeltaAuction(\n auction: DeltaAuction\n): auction is DeltaAuction & {\n status: \"CANCELLED\";\n} {\n return auction.status === \"CANCELLED\";\n}\n\nexport function isDeltaAuctionExpired(\n auction: DeltaAuction\n): auction is DeltaAuction & {\n status: \"EXPIRED\";\n} {\n return auction.status === \"EXPIRED\";\n}\n\n/// ------------------- Order status checks -------------------\n\n// specific to submit DeltaOrder substep\nexport const DeltaOrderStatusChecker = {\n pending: new Set<DeltaAuctionStatus>([\n \"NOT_STARTED\",\n \"RUNNING\",\n \"AWAITING_PRE_SIGNATURE\",\n \"CANCELLING\",\n ]), // adjust for when we want to show Pending state\n executing: new Set<DeltaAuctionStatus>([\"EXECUTING\"]),\n active: new Set<DeltaAuctionStatus>([\n \"EXECUTING\",\n \"NOT_STARTED\",\n \"AWAITING_PRE_SIGNATURE\",\n \"RUNNING\",\n \"EXECUTED\",\n \"FAILED\",\n \"EXPIRED\",\n \"CANCELLED\",\n \"CANCELLING\",\n ]), // order always active, unless actual submission breaks\n success: new Set<DeltaAuctionStatus>([\"EXECUTED\"]),\n completed: new Set<DeltaAuctionStatus>([\n \"EXECUTED\",\n \"FAILED\",\n \"EXPIRED\",\n \"CANCELLED\",\n \"REFUNDED\",\n ]),\n failed: new Set<DeltaAuctionStatus>([\n \"FAILED\",\n \"EXPIRED\",\n \"CANCELLED\",\n \"REFUNDED\",\n ]),\n cancellable: new Set<DeltaAuctionStatus>([\n \"NOT_STARTED\",\n \"RUNNING\",\n \"AWAITING_PRE_SIGNATURE\",\n \"EXECUTING\",\n \"SUSPENDED\",\n ]),\n};\n\nexport const BridgeStatusChecker = {\n pending: new Set<BridgeStatus>([\"pending\"]),\n completed: new Set<BridgeStatus>([\"filled\", \"expired\", \"refunded\"]),\n failed: new Set<BridgeStatus>([\"expired\", \"refunded\"]),\n};\n\n// visually we show only \"In progress\", \"Executing\" and separate components for success and failure\nexport type VisualOrderStatus =\n | \"pending\"\n | \"executing\"\n | \"failed\"\n | \"confirmed\";\n\nexport function getSingleChainOrderStatus(\n orderStatus: DeltaAuctionStatus\n): VisualOrderStatus {\n if (DeltaOrderStatusChecker.pending.has(orderStatus)) return \"pending\";\n\n if (DeltaOrderStatusChecker.executing.has(orderStatus)) return \"executing\";\n\n if (DeltaOrderStatusChecker.failed.has(orderStatus)) return \"failed\";\n\n return \"confirmed\";\n}\n\nexport function getCrossChainOrderStatus(\n status: DeltaAuctionStatus,\n bridgeStatus: BridgeStatus | null\n): VisualOrderStatus {\n if (\n DeltaOrderStatusChecker.failed.has(status) ||\n (bridgeStatus && BridgeStatusChecker.failed.has(bridgeStatus))\n )\n return \"failed\";\n\n if (bridgeStatus === \"filled\") return \"confirmed\";\n\n // Order awaiting signature can't be already executing no matter the bridge status\n if (status === \"AWAITING_PRE_SIGNATURE\") return \"pending\";\n\n return \"executing\"; // executed already on source chain, but not yet on destination chain,\n // visually we show \"executing\"\n}\n\nexport function getAuctionDestChainId({\n order,\n chainId,\n}: Pick<DeltaAuction, \"order\" | \"chainId\">) {\n return isOrderCrosschain(order) ? order.bridge.destinationChainId : chainId;\n}\n\n/**\n * For Delta Orders in the Trade Flow to switch between flow steps based on the order status\n */\nexport function getOverallOrderStatus(\n order: Pick<DeltaAuction, \"status\" | \"bridgeStatus\" | \"order\">\n): VisualOrderStatus {\n return isOrderCrosschain(order.order)\n ? // TWAP orders don't have order.bridgeStatus, instead\n // each slice has its own bridgeStatus in transactions[].bridgeMetadata,\n // and some slices could have been bridged while others not yet, or refunded\n // @TODO display \"partially executed\" for TWAP?\n getCrossChainOrderStatus(order.status, order.bridgeStatus)\n : getSingleChainOrderStatus(order.status);\n}\n\n/**\n * For displaying order status to users.\n */\nexport function getDisplayedOrderStatus(status: DeltaAuctionStatus): string {\n if (status === \"AWAITING_PRE_SIGNATURE\") return \"UNSIGNED\";\n return replaceUnderscoresWithSpaces(status);\n}\n\n// -------------------- TWAP -------------------\n\nexport function isTwapAuction(\n order: DeltaAuction\n): order is DeltaAuctionWithTwapOrder {\n return (\n order.onChainOrderType === \"TWAPOrder\" ||\n order.onChainOrderType === \"TWAPBuyOrder\"\n );\n}\n\nexport function isTwapOrder(\n order: DeltaAuction[\"order\"]\n): order is TwapSellOrBuyOrder {\n return \"numSlices\" in order && typeof order.numSlices === \"number\";\n}\n\nfunction getTotalTwapSrcAmount(order: TwapSellOrBuyOrder) {\n return \"totalSrcAmount\" in order ? order.totalSrcAmount : order.maxSrcAmount;\n}\n\nfunction getTotalTwapDestAmount(order: TwapSellOrBuyOrder) {\n const destAmount =\n \"destAmountPerSlice\" in order\n ? Big(order.destAmountPerSlice).times(order.numSlices) // SELL\n : Big(order.totalDestAmount); // BUY\n\n if (isOrderCrosschain(order)) {\n return scaleByFactor(destAmount, order.bridge.scalingFactor).toFixed(0);\n }\n\n return destAmount.toFixed(0);\n}\n\nexport function getTotalTwapOrderAmounts(order: TwapSellOrBuyOrder) {\n const srcAmount = getTotalTwapSrcAmount(order);\n const destAmount = getTotalTwapDestAmount(order);\n return { srcAmount, destAmount };\n}\n\nfunction getTwapAuctionAmounts(twapAuction: DeltaAuctionWithTwapOrder) {\n const isExecuted =\n twapAuction.status === \"EXECUTED\" &&\n twapAuction.transactions.length === twapAuction.order.numSlices;\n\n if (isExecuted) {\n return getTransactionAmounts(\n twapAuction.transactions as DeltaAuctionTransaction[]\n );\n }\n\n return getTotalTwapOrderAmounts(twapAuction.order);\n}\n\n/** Returns the order deadline based on slices and interval */\nexport function getTwapOrderDeadlineFromSlices(\n order: TwapSellOrBuyOrder,\n createdAt: string\n) {\n return Math.floor(\n millisecondsToSeconds(new Date(createdAt).getTime()) +\n order.numSlices * order.interval // order.interval is in seconds\n );\n}\n\n// -------------------- Auction Unified Data --------------------\n\ntype UnifiedDeltaOrderData = {\n /** @description source chain id */\n srcChainId: number;\n /** @description destination chain id (same as source chain id for single chain orders) */\n destChainId: number;\n /** @description input token amount */\n srcAmount: string;\n /** @description output token amount (expected amount for pending orders, actual received amount for executed orders) */\n destAmount: string;\n /** @description input token address */\n srcToken: string;\n /** @description output token address */\n destToken: string;\n /** @description swap side of the order */\n swapSide: SwapSideUnion;\n};\n\nexport function getUnifiedDeltaOrderData(\n auction: DeltaAuction\n): UnifiedDeltaOrderData {\n const { order, chainId } = auction;\n\n const { srcToken, destToken } = getOrderTokenAddresses(order);\n const { srcAmount, destAmount } = getAuctionAmounts(auction);\n\n const srcChainId = chainId;\n const destChainId = getAuctionDestChainId({ order, chainId });\n\n const swapSide = getAuctionSwapSide(auction);\n\n return {\n srcChainId,\n destChainId,\n srcAmount,\n destAmount,\n srcToken,\n destToken,\n swapSide,\n };\n}\n\nexport function getOrderTokenAddresses(order: DeltaAuction[\"order\"]) {\n const srcToken = order.srcToken;\n const destToken = isOrderCrosschain(order)\n ? order.bridge.outputToken\n : order.destToken;\n return {\n srcToken,\n destToken,\n };\n}\n\nfunction getTransactionAmounts(transactions: DeltaAuctionTransaction[]) {\n const { srcAmount, destAmount } = transactions.reduce(\n (acc, { spentAmount, receivedAmount, bridgeMetadata }) => {\n return {\n srcAmount: acc.srcAmount + BigInt(spentAmount),\n destAmount:\n acc.destAmount +\n BigInt(bridgeMetadata ? bridgeMetadata.outputAmount : receivedAmount),\n };\n },\n {\n srcAmount: 0n,\n destAmount: 0n,\n }\n );\n\n return {\n srcAmount: srcAmount.toString(),\n destAmount: destAmount.toString(),\n };\n}\n\nfunction getAuctionAmounts(auction: DeltaAuction) {\n const isTwap = isTwapAuction(auction);\n if (isTwap) {\n return getTwapAuctionAmounts(auction);\n }\n\n const isExecuted = isExecutedDeltaAuction(auction);\n if (isExecuted) {\n return getTransactionAmounts(\n auction.transactions as DeltaAuctionTransaction[]\n );\n }\n\n const order = auction.order;\n\n const srcAmount = order.srcAmount;\n const destAmount = order.expectedAmount || order.destAmount;\n\n if (isOrderCrosschain(order)) {\n if (auction.type === \"LIMIT\") {\n return {\n srcAmount,\n destAmount, // for LIMIT -- destAmount is the amount of the output token on the destination chain\n };\n }\n return {\n srcAmount,\n destAmount:\n auction.bridgeMetadata?.outputAmount ||\n auction.bridgeMetadata?.expectedOutputAmount ||\n scaleByFactor(destAmount, order.bridge.scalingFactor).toFixed(0),\n };\n }\n\n return {\n srcAmount,\n destAmount,\n };\n}\n\n// -------------------- SwapSide --------------------\n\nexport function getAuctionSwapSide(auction: DeltaAuction): SwapSideUnion {\n if (isTwapAuction(auction)) {\n // TWAP orders have onChainOrderType instead of kind\n return getSwapSideFromTwapOrderType(auction.onChainOrderType);\n }\n return getSwapSideFromDeltaOrder(auction.order);\n}\n\nexport function getSwapSideFromDeltaPrice(price: DeltaPriceV2): SwapSideUnion {\n return price.side;\n}\n\nconst OrderKindToSwapSide = {\n 0: \"SELL\",\n 1: \"BUY\",\n} as const;\n\nexport function getSwapSideFromDeltaOrder(\n order: DeltaAuctionOrder | ExternalDeltaOrder | ProductiveDeltaOrder\n): SwapSideUnion {\n if (\"strategy\" in order) {\n return \"SELL\"; // ProductiveOrders don't carry an explicit OrderKind; treated as SELL.\n }\n return OrderKindToSwapSide[order.kind];\n}\n\nconst TwapTypeToSwapSide = {\n TWAPOrder: \"SELL\",\n TWAPBuyOrder: \"BUY\",\n} as const;\n\nexport function getSwapSideFromTwapOrderType(\n onChainOrderType: \"TWAPOrder\" | \"TWAPBuyOrder\"\n): SwapSideUnion {\n return TwapTypeToSwapSide[onChainOrderType];\n}\n"],"mappings":";;;;;AAwBA,SAAgBmB,EACdC,GACyB;CACzB,OAAO,wBAAwBA,KAAS,oBAAoBA;;AAG9D,SAAgBC,EACdD,GAC4B;CAC5B,OAAO,qBAAqBA,KAAS,kBAAkBA;;AAGzD,SAAgBE,EACdF,GACiD;CACjD,OACE,YAAYA,KAASA,EAAMG,UAAUH,EAAMG,OAAOC,uBAAuB;;AAI7E,SAAgBC,EAAmBC,GAAqC;CACtE,OACE,OAAOA,KAAS,cAChBA,KACA,QAAQA,KACR,aAAaA,KACb,YAAYA,KACZ,WAAWA,KACX,eAAeA;;AAInB,SAASC,EACPC,GACiC;CAOjC,OALIC,EAAcD,EAAQ,GACjBA,EAAQE,aAAaC,WAAW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AMoF,kBAAkBpF,EAAM6C;CAkBjD,OAhBI3C,EAAkBF,EAAM,GACtBQ,EAAQ6E,SAAS,UACZ;EACLjC;EACAP;EACD,GAEI;EACLO;EACAP,YACErC,EAAQuE,gBAAgBE,gBACxBzE,EAAQuE,gBAAgBO,wBACxBxF,EAAc+C,GAAY7C,EAAMG,OAAO8C,cAAc,CAACC,QAAQ,EAAC;EAClE,GAGI;EACLE;EACAP;EACD;;AAKH,SAAgB4B,EAAmBjE,GAAsC;CAKvE,OAJIC,EAAcD,EAAQ,GAEjB+E,EAA6B/E,EAAQ+B,iBAAiB,GAExDiD,EAA0BhF,EAAQR,MAAM;;AAGjD,SAAgByF,EAA0BC,GAAoC;CAC5E,OAAOA,EAAMC;;AAGf,IAAMC,IAAsB;CAC1B,GAAG;CACH,GAAG;CACJ;AAED,SAAgBJ,EACdxF,GACe;CAIf,OAHI,cAAcA,IACT,SAEF4F,EAAoB5F,EAAM8F;;AAGnC,IAAMC,IAAqB;CACzBC,WAAW;CACXC,cAAc;CACf;AAED,SAAgBV,EACdhD,GACe;CACf,OAAOwD,EAAmBxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["FailedDeltaAuction","DeltaOrderFailedError","Error","order","constructor","message","name","captureStackTrace","isDeltaOrderFailedError","error","DeltaPriceErrorType","DELTA_PRICE_ERROR_TYPES","Set","getDeltaPriceErrorType","has"],"sources":["../../../../../../src/hooks/swap/prices/delta/queries/errors.ts"],"sourcesContent":["import type { FailedDeltaAuction } from \"../orders/types\";\n\nexport class DeltaOrderFailedError extends Error {\n public readonly order: FailedDeltaAuction;\n\n public constructor({\n message,\n order,\n }: {\n message?: string;\n order: FailedDeltaAuction;\n }) {\n super(message);\n this.name = this.constructor.name;\n this.message = message || \"DeltaOrderFailed\";\n this.order = order;\n\n // Capture stack trace, excluding the constructor call\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, DeltaOrderFailedError);\n }\n }\n}\n\nexport function isDeltaOrderFailedError(\n error: unknown\n): error is DeltaOrderFailedError {\n return error instanceof DeltaOrderFailedError;\n}\n\n// ------------------------------
|
|
1
|
+
{"version":3,"file":"errors.js","names":["FailedDeltaAuction","DeltaOrderFailedError","Error","order","constructor","message","name","captureStackTrace","isDeltaOrderFailedError","error","DeltaPriceErrorType","DELTA_PRICE_ERROR_TYPES","Set","getDeltaPriceErrorType","has"],"sources":["../../../../../../src/hooks/swap/prices/delta/queries/errors.ts"],"sourcesContent":["import type { FailedDeltaAuction } from \"../orders/types\";\n\nexport class DeltaOrderFailedError extends Error {\n public readonly order: FailedDeltaAuction;\n\n public constructor({\n message,\n order,\n }: {\n message?: string;\n order: FailedDeltaAuction;\n }) {\n super(message);\n this.name = this.constructor.name;\n this.message = message || \"DeltaOrderFailed\";\n this.order = order;\n\n // Capture stack trace, excluding the constructor call\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, DeltaOrderFailedError);\n }\n }\n}\n\nexport function isDeltaOrderFailedError(\n error: unknown\n): error is DeltaOrderFailedError {\n return error instanceof DeltaOrderFailedError;\n}\n\n// ------------------------------ DeltaPriceV2 errors ------------------------------\n\n/**\n * API error shapes (e.errorType returned as e.message in SDK):\n * - { \"errorType\": \"MaxImpactReached\", \"details\": \"Max price impact reached. Impact: 97.81%\" }\n * - { \"errorType\": \"NoUSDPriceForToken\", \"details\": \"No USD price available for token 0x6eed...\" }\n * - { \"errorType\": \"NoAvailablePrices\", \"details\": \"No available prices found\" }\n * - { \"errorType\": \"UnsupportedToken\", \"details\": \"Token 0xc4d4... is not supported\" }\n * - { \"errorType\": \"NoAvailableBridgeOptions\", \"details\": \"No available bridge options\" }\n */\nexport type DeltaPriceErrorType =\n | \"MaxImpactReached\"\n | \"NoUSDPriceForToken\"\n | \"NoAvailablePrices\"\n | \"UnsupportedToken\"\n | \"NoAvailableBridgeOptions\";\n\nconst DELTA_PRICE_ERROR_TYPES = new Set<string>([\n \"MaxImpactReached\",\n \"NoUSDPriceForToken\",\n \"NoAvailablePrices\",\n \"UnsupportedToken\",\n \"NoAvailableBridgeOptions\",\n] satisfies DeltaPriceErrorType[]);\n\nexport function getDeltaPriceErrorType(\n error: unknown\n): DeltaPriceErrorType | null {\n if (!(error instanceof Error)) return null;\n if (DELTA_PRICE_ERROR_TYPES.has(error.message)) {\n return error.message as DeltaPriceErrorType;\n }\n return null;\n}\n"],"mappings":";AAEA,IAAaC,IAAb,MAAaA,UAA8BC,MAAM;CAC/C;CAEA,YAAmB,EACjBG,YACAF,YAIC;EAOD,AANA,MAAME,EAAQ,EACd,KAAKC,OAAO,KAAKF,YAAYE,MAC7B,KAAKD,UAAUA,KAAW,oBAC1B,KAAKF,QAAQA,GAGTD,MAAMK,qBACRL,MAAMK,kBAAkB,MAAMN,EAAsB;;;AAK1D,SAAgBO,EACdC,GACgC;CAChC,OAAOA,aAAiBR;;AAoB1B,IAAMU,IAA0B,IAAIC,IAAY;CAC9C;CACA;CACA;CACA;CACA;CACD,CAAiC;AAElC,SAAgBC,EACdJ,GAC4B;CAK5B,OAJMA,aAAiBP,SACnBS,EAAwBG,IAAIL,EAAMJ,QAAQ,GACrCI,EAAMJ,UAER"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Query, QueryClient, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
2
|
+
import { DeltaPriceV2, DeltaPriceV2Params as DParams, OptimalRate } from '@velora-dex/sdk';
|
|
3
3
|
import { MarkOptional } from 'ts-essentials';
|
|
4
4
|
type RequiredDeltaPriceParams = Omit<DParams, "destChainId">;
|
|
5
5
|
export type DeltaPriceQueryParams = MarkOptional<RequiredDeltaPriceParams, "destToken" | "destDecimals">;
|
|
6
|
-
type DeltaQueryParams<TData =
|
|
7
|
-
type DeltaQueryResult<TData =
|
|
8
|
-
type DeltaPriceQueryInput<TData =
|
|
6
|
+
type DeltaQueryParams<TData = DeltaPriceV2> = Omit<UseQueryOptions<DeltaPriceV2, Error, TData, DeltaPriceQueryKey>, "queryKey" | "queryFn">;
|
|
7
|
+
type DeltaQueryResult<TData = DeltaPriceV2> = UseQueryResult<TData, Error>;
|
|
8
|
+
type DeltaPriceQueryInput<TData = DeltaPriceV2> = {
|
|
9
9
|
priceParams: DeltaPriceQueryParams;
|
|
10
10
|
query?: DeltaQueryParams<TData>;
|
|
11
11
|
chainId: number;
|
|
12
12
|
timeout?: number;
|
|
13
|
+
destChainId?: number;
|
|
13
14
|
};
|
|
14
15
|
export declare const DeltaPriceQueryKeyPrefix = "swap/prices/delta";
|
|
15
16
|
export type DeltaPriceQueryKey = readonly [
|
|
@@ -19,63 +20,45 @@ export type DeltaPriceQueryKey = readonly [
|
|
|
19
20
|
destChainId?: number;
|
|
20
21
|
}
|
|
21
22
|
];
|
|
22
|
-
|
|
23
|
-
* 1. With destChainId: number -> returns BridgePrice
|
|
24
|
-
* 2. With destChainId?: undefined -> returns DeltaPrice
|
|
25
|
-
* 3. With destChainId?: number -> returns DeltaPrice | BridgePrice
|
|
26
|
-
*/
|
|
27
|
-
export declare function useDeltaPriceQuery<TData = BridgePrice>({ priceParams, query, chainId, timeout, }: DeltaPriceQueryInput<TData> & {
|
|
28
|
-
destChainId: number;
|
|
29
|
-
}): {
|
|
23
|
+
export declare function useDeltaPriceQuery<TData = DeltaPriceV2>({ priceParams: _priceParams, query, chainId, timeout, destChainId, }: DeltaPriceQueryInput<TData>): {
|
|
30
24
|
result: DeltaQueryResult<TData>;
|
|
31
25
|
queryKey: DeltaPriceQueryKey;
|
|
32
26
|
};
|
|
33
|
-
export declare function
|
|
34
|
-
|
|
35
|
-
}): {
|
|
36
|
-
result: DeltaQueryResult<TData>;
|
|
37
|
-
queryKey: DeltaPriceQueryKey;
|
|
38
|
-
};
|
|
39
|
-
export declare function useDeltaPriceQuery<TData = DeltaPrice | BridgePrice>({ priceParams, query, chainId, timeout, }: DeltaPriceQueryInput<TData> & {
|
|
40
|
-
destChainId?: number;
|
|
41
|
-
}): {
|
|
42
|
-
result: DeltaQueryResult<TData>;
|
|
43
|
-
queryKey: DeltaPriceQueryKey;
|
|
44
|
-
};
|
|
45
|
-
export declare function isDeltaPrice(price: OptimalRate | DeltaPrice): price is DeltaPrice;
|
|
46
|
-
export declare function isBridgePrice(price: DeltaPrice | BridgePrice): price is BridgePrice;
|
|
27
|
+
export declare function isDeltaPrice(price: OptimalRate | DeltaPriceV2): price is DeltaPriceV2;
|
|
28
|
+
export declare function isBridgePrice(price: DeltaPriceV2): boolean;
|
|
47
29
|
type GetDeltaPriceQueryForPriceInput = {
|
|
48
|
-
price:
|
|
30
|
+
price: DeltaPriceV2;
|
|
49
31
|
chainId: number;
|
|
50
32
|
};
|
|
51
|
-
type
|
|
33
|
+
type DeltaPriceQuery = Query<DeltaPriceV2, Error, DeltaPriceV2, DeltaPriceQueryKey>;
|
|
34
|
+
type GetDeltaPriceQueryForPrice = (input: GetDeltaPriceQueryForPriceInput) => DeltaPriceQuery | undefined;
|
|
52
35
|
export declare function useDeltaPriceQueryForPrice(): GetDeltaPriceQueryForPrice;
|
|
53
36
|
type SubscribeToDeltaPriceInput = {
|
|
54
37
|
queryKey: DeltaPriceQueryKey;
|
|
55
|
-
onData?: (data:
|
|
38
|
+
onData?: (data: DeltaPriceV2) => void;
|
|
56
39
|
onError?: (error: Error) => void;
|
|
57
40
|
};
|
|
58
41
|
type SubscribeToDeltaPriceResult = (input: SubscribeToDeltaPriceInput) => () => void;
|
|
59
42
|
export declare function useSubscribeToDeltaPrice(): SubscribeToDeltaPriceResult;
|
|
60
|
-
export declare function getLastDeltaPrice(queryClient: QueryClient):
|
|
43
|
+
export declare function getLastDeltaPrice(queryClient: QueryClient): DeltaPriceV2 | undefined;
|
|
61
44
|
export declare function isLastDeltaPriceQueryInError(queryClient: QueryClient): boolean;
|
|
62
|
-
export declare function
|
|
45
|
+
export declare function isDataDeltaPriceV2(price: unknown): price is DeltaPriceV2;
|
|
63
46
|
export declare function useDeltaPriceQueryKey({ priceParams, chainId, destChainId, }: Pick<DeltaPriceQueryInput, "priceParams" | "chainId"> & {
|
|
64
47
|
destChainId?: number;
|
|
65
48
|
}): {
|
|
66
49
|
queryKey: DeltaPriceQueryKey;
|
|
67
50
|
sanitizedPriceParams: {
|
|
68
51
|
amount: string;
|
|
69
|
-
side?: ("
|
|
52
|
+
side?: ("BUY" | "SELL") | undefined;
|
|
70
53
|
partner?: string | undefined;
|
|
71
54
|
excludeAgents?: string[] | undefined;
|
|
72
55
|
includeAgents?: string[] | undefined;
|
|
73
56
|
userAddress?: string | undefined;
|
|
74
57
|
degenMode?: boolean | undefined;
|
|
75
58
|
beneficiary?: string | undefined;
|
|
59
|
+
partnerFeeBps?: number | undefined;
|
|
76
60
|
srcToken: string;
|
|
77
61
|
destToken?: string | undefined;
|
|
78
|
-
partnerFeeBps?: number | undefined;
|
|
79
62
|
srcDecimals: number;
|
|
80
63
|
destDecimals?: number | undefined;
|
|
81
64
|
maxImpact?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeltaPriceQuery.d.ts","sourceRoot":"","sources":["../../../../../../src/hooks/swap/prices/delta/queries/useDeltaPriceQuery.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,WAAW,EAIX,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"useDeltaPriceQuery.d.ts","sourceRoot":"","sources":["../../../../../../src/hooks/swap/prices/delta/queries/useDeltaPriceQuery.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,WAAW,EAIX,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,IAAI,OAAO,EAC7B,WAAW,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAK1D,KAAK,wBAAwB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../useSDK.js";
|
|
2
2
|
import { PRICE_FETCH_TIMEOUT_MS as t } from "../../constants.js";
|
|
3
3
|
import { c as n } from "react-compiler-runtime";
|
|
4
4
|
import { useMemo as r } from "react";
|
|
@@ -19,7 +19,7 @@ function u(r) {
|
|
|
19
19
|
let { queryKey: v, sanitizedPriceParams: b } = y(_), x;
|
|
20
20
|
i[6] !== b || i[7] !== h || i[8] !== p ? (x = (e) => {
|
|
21
21
|
let { signal: t } = e;
|
|
22
|
-
return s(d(b), "destToken is required"), h.
|
|
22
|
+
return s(d(b), "destToken is required"), h.getDeltaPriceV2(b, {
|
|
23
23
|
signal: t,
|
|
24
24
|
timeout: p
|
|
25
25
|
});
|
|
@@ -43,10 +43,10 @@ function d(e) {
|
|
|
43
43
|
return !!e.destToken && e.destDecimals !== void 0 && Number(e.amount) > 0;
|
|
44
44
|
}
|
|
45
45
|
function f(e) {
|
|
46
|
-
return "
|
|
46
|
+
return "route" in e;
|
|
47
47
|
}
|
|
48
48
|
function p(e) {
|
|
49
|
-
return e.bridge
|
|
49
|
+
return e.route.bridge !== null;
|
|
50
50
|
}
|
|
51
51
|
function m() {
|
|
52
52
|
let e = n(2), t = o(), r;
|
|
@@ -78,7 +78,7 @@ function _(e) {
|
|
|
78
78
|
return !!h(e)?.state.error;
|
|
79
79
|
}
|
|
80
80
|
function v(e) {
|
|
81
|
-
return typeof e == "object" && !!e && "
|
|
81
|
+
return typeof e == "object" && !!e && "route" in e && "inputToken" in e && "outputToken" in e;
|
|
82
82
|
}
|
|
83
83
|
function y({ priceParams: e, chainId: t, destChainId: n }) {
|
|
84
84
|
"use no memo";
|
|
@@ -135,6 +135,6 @@ function y({ priceParams: e, chainId: t, destChainId: n }) {
|
|
|
135
135
|
]);
|
|
136
136
|
}
|
|
137
137
|
//#endregion
|
|
138
|
-
export { l as DeltaPriceQueryKeyPrefix, g as getLastDeltaPrice, p as isBridgePrice, v as
|
|
138
|
+
export { l as DeltaPriceQueryKeyPrefix, g as getLastDeltaPrice, p as isBridgePrice, v as isDataDeltaPriceV2, f as isDeltaPrice, _ as isLastDeltaPriceQueryInError, u as useDeltaPriceQuery, m as useSubscribeToDeltaPrice };
|
|
139
139
|
|
|
140
140
|
//# sourceMappingURL=useDeltaPriceQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeltaPriceQuery.js","names":["useDeltaSDK","Query","QueryClient","QueryObserver","useQuery","useQueryClient","UseQueryOptions","UseQueryResult","useDebouncedValue","DeltaPrice","BridgePrice","DeltaPriceParams","DParams","OptimalRate","assert","MarkOptional","useMemo","PRICE_FETCH_TIMEOUT_MS","RequiredDeltaPriceParams","Omit","DeltaPriceQueryParams","DeltaQueryParams","Error","TData","DeltaPriceQueryKey","DeltaQueryResult","DeltaPriceQueryInput","priceParams","query","chainId","timeout","DeltaPriceQueryKeyPrefix","base","destChainId","useDeltaPriceQuery","result","queryKey","t0","$","_c","_priceParams","t1","undefined","t2","sdk","queryEnabled","enabled","t3","sanitizedPriceParams","useDeltaPriceQueryKey","t4","t5","signal","isPriceParamsValid","price","getDeltaPrice","t6","queryFn","t7","destToken","destDecimals","Number","amount","isDeltaPrice","isBridgePrice","bridge","destinationChainId","GetDeltaPriceQueryForPriceInput","DeltaPriceQuery","GetDeltaPriceQueryForPrice","input","useDeltaPriceQueryForPrice","queryClient","queryCache","getQueryCache","query_0","find","exact","predicate","state","data","SubscribeToDeltaPriceInput","onData","onError","error","SubscribeToDeltaPriceResult","useSubscribeToDeltaPrice","observer","subscribe","getLastDeltaPriceQuery","type","getLastDeltaPrice","isLastDeltaPriceQueryInError","isDataDeltaOrBridgePrice","Pick","debouncedAmount","wait","srcToken","srcDecimals","userAddress","beneficiary","partner","partnerFeeBps","side","includeAgents","excludeAgents","includeBridges","excludeBridges","allowBridgeAndSwap","maxImpact","degenMode"],"sources":["../../../../../../src/hooks/swap/prices/delta/queries/useDeltaPriceQuery.ts"],"sourcesContent":["import { useDeltaSDK } from \"@/hooks/useSDK\";\nimport {\n Query,\n QueryClient,\n QueryObserver,\n useQuery,\n useQueryClient,\n type UseQueryOptions,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { useDebouncedValue } from \"@tanstack/react-pacer/debouncer\";\nimport type {\n DeltaPrice,\n BridgePrice,\n DeltaPriceParams as DParams,\n OptimalRate,\n} from \"@velora-dex/sdk\";\nimport { assert, type MarkOptional } from \"ts-essentials\";\nimport { useMemo } from \"react\";\nimport { PRICE_FETCH_TIMEOUT_MS } from \"../../constants\";\n\n// overload is easier with input.destChainId\ntype RequiredDeltaPriceParams = Omit<DParams, \"destChainId\">;\nexport type DeltaPriceQueryParams = MarkOptional<\n RequiredDeltaPriceParams,\n \"destToken\" | \"destDecimals\" // destToken is not available in SwapForm initially\n>;\n\ntype DeltaQueryParams<TData = DeltaPrice | BridgePrice> = Omit<\n UseQueryOptions<DeltaPrice | BridgePrice, Error, TData, DeltaPriceQueryKey>,\n \"queryKey\" | \"queryFn\"\n>;\ntype DeltaQueryResult<TData = DeltaPrice> = UseQueryResult<TData, Error>;\n\ntype DeltaPriceQueryInput<TData = DeltaPrice> = {\n priceParams: DeltaPriceQueryParams;\n query?: DeltaQueryParams<TData>;\n chainId: number;\n timeout?: number;\n};\n\nexport const DeltaPriceQueryKeyPrefix = \"swap/prices/delta\";\n\nexport type DeltaPriceQueryKey = readonly [\n base: typeof DeltaPriceQueryKeyPrefix,\n chainId: number,\n priceParams: DeltaPriceQueryParams & {\n destChainId?: number;\n },\n];\n\n/**\n * 1. With destChainId: number -> returns BridgePrice\n * 2. With destChainId?: undefined -> returns DeltaPrice\n * 3. With destChainId?: number -> returns DeltaPrice | BridgePrice\n */\nexport function useDeltaPriceQuery<TData = BridgePrice>({\n priceParams,\n query,\n chainId,\n timeout,\n}: DeltaPriceQueryInput<TData> & {\n destChainId: number;\n}): {\n result: DeltaQueryResult<TData>;\n queryKey: DeltaPriceQueryKey;\n};\nexport function useDeltaPriceQuery<TData = DeltaPrice>({\n priceParams,\n query,\n chainId,\n timeout,\n}: DeltaPriceQueryInput<TData> & {\n destChainId?: undefined;\n}): {\n result: DeltaQueryResult<TData>;\n queryKey: DeltaPriceQueryKey;\n};\nexport function useDeltaPriceQuery<TData = DeltaPrice | BridgePrice>({\n priceParams,\n query,\n chainId,\n timeout,\n}: DeltaPriceQueryInput<TData> & {\n destChainId?: number;\n}): {\n result: DeltaQueryResult<TData>;\n queryKey: DeltaPriceQueryKey;\n};\nexport function useDeltaPriceQuery<TData = DeltaPrice | BridgePrice>({\n priceParams: _priceParams,\n query,\n chainId,\n timeout = PRICE_FETCH_TIMEOUT_MS,\n destChainId,\n}: DeltaPriceQueryInput<TData> & {\n destChainId?: number;\n}): {\n result: DeltaQueryResult<TData>;\n queryKey: DeltaPriceQueryKey;\n} {\n const { sdk } = useDeltaSDK({ chainId });\n\n const queryEnabled = query?.enabled ?? true;\n\n const { queryKey, sanitizedPriceParams } = useDeltaPriceQueryKey({\n priceParams: _priceParams,\n chainId,\n destChainId,\n });\n\n const result = useQuery<\n DeltaPrice | BridgePrice,\n Error,\n TData,\n DeltaPriceQueryKey\n >({\n queryKey,\n queryFn: ({ signal }) => {\n assert(isPriceParamsValid(sanitizedPriceParams), \"destToken is required\");\n const price = sdk.getDeltaPrice(sanitizedPriceParams, {\n signal,\n timeout,\n });\n return price;\n },\n ...query,\n enabled: queryEnabled && isPriceParamsValid(sanitizedPriceParams),\n });\n\n return { result, queryKey };\n}\n\nfunction isPriceParamsValid(\n priceParams: DeltaPriceQueryParams\n): priceParams is RequiredDeltaPriceParams {\n return (\n !!priceParams.destToken &&\n priceParams.destDecimals !== undefined &&\n Number(priceParams.amount) > 0\n );\n}\n\nexport function isDeltaPrice(\n price: OptimalRate | DeltaPrice\n): price is DeltaPrice {\n return \"bridge\" in price;\n}\n\nexport function isBridgePrice(\n price: DeltaPrice | BridgePrice\n): price is BridgePrice {\n return price.bridge.destinationChainId !== 0;\n}\n\ntype GetDeltaPriceQueryForPriceInput = {\n price: DeltaPrice | BridgePrice;\n chainId: number;\n};\n\ntype DeltaPriceQuery = Query<\n DeltaPrice | BridgePrice,\n Error,\n DeltaPrice | BridgePrice,\n DeltaPriceQueryKey\n>;\n\ntype GetDeltaPriceQueryForPrice = (\n input: GetDeltaPriceQueryForPriceInput\n) =>\n | Query<\n DeltaPrice | BridgePrice,\n Error,\n DeltaPrice | BridgePrice,\n DeltaPriceQueryKey\n >\n | undefined;\n\n// get query for a given deltaPrice\nexport function useDeltaPriceQueryForPrice(): GetDeltaPriceQueryForPrice {\n const queryClient = useQueryClient();\n\n return ({ chainId, price }) => {\n const queryKey: [DeltaPriceQueryKey[0], DeltaPriceQueryKey[1]] = [\n DeltaPriceQueryKeyPrefix,\n chainId,\n ];\n const queryCache = queryClient.getQueryCache();\n const query = queryCache.find<\n DeltaPrice | BridgePrice,\n Error,\n DeltaPrice | BridgePrice\n >({\n queryKey,\n exact: false,\n predicate: (query) => {\n return query.state.data === price;\n },\n });\n\n return query as DeltaPriceQuery | undefined;\n };\n}\n\ntype SubscribeToDeltaPriceInput = {\n queryKey: DeltaPriceQueryKey;\n onData?: (data: DeltaPrice | BridgePrice) => void;\n onError?: (error: Error) => void;\n};\n\ntype SubscribeToDeltaPriceResult = (\n input: SubscribeToDeltaPriceInput\n) => () => void;\n\n// independently subscribe to a price query\nexport function useSubscribeToDeltaPrice(): SubscribeToDeltaPriceResult {\n const queryClient = useQueryClient();\n\n return ({ queryKey, onData, onError }) => {\n const observer = new QueryObserver<\n DeltaPrice | BridgePrice,\n Error,\n DeltaPrice | BridgePrice,\n DeltaPrice | BridgePrice,\n DeltaPriceQueryKey\n >(queryClient, {\n queryKey,\n // only receive updates from existing subscriptions\n enabled: false,\n });\n\n // return unsubscribe function\n return observer.subscribe((result) => {\n if (result.error) {\n onError?.(result.error);\n return;\n }\n if (result.data) {\n onData?.(result.data);\n }\n });\n };\n}\n\nfunction getLastDeltaPriceQuery(\n queryClient: QueryClient\n):\n | Query<DeltaPrice | BridgePrice, Error, DeltaPrice | BridgePrice>\n | undefined {\n return queryClient\n .getQueryCache()\n .find<DeltaPrice | BridgePrice, Error, DeltaPrice | BridgePrice>({\n queryKey: [DeltaPriceQueryKeyPrefix],\n exact: false,\n type: \"active\", // only the most recent query will be active\n });\n}\n\nexport function getLastDeltaPrice(\n queryClient: QueryClient\n): DeltaPrice | BridgePrice | undefined {\n const query = getLastDeltaPriceQuery(queryClient);\n\n return query?.state.data;\n}\n\nexport function isLastDeltaPriceQueryInError(\n queryClient: QueryClient\n): boolean {\n const query = getLastDeltaPriceQuery(queryClient);\n const error = query?.state.error;\n return !!error;\n}\n\nexport function isDataDeltaOrBridgePrice(\n price: unknown\n): price is DeltaPrice | BridgePrice {\n return (\n typeof price === \"object\" &&\n price !== null &&\n \"bridge\" in price &&\n \"srcToken\" in price &&\n \"destToken\" in price &&\n \"srcAmount\" in price &&\n \"destAmount\" in price\n );\n}\n\nexport function useDeltaPriceQueryKey({\n priceParams,\n chainId,\n destChainId,\n}: Pick<DeltaPriceQueryInput, \"priceParams\" | \"chainId\"> & {\n destChainId?: number;\n}) {\n \"use no memo\";\n\n // amount tends to change fast during input\n const [debouncedAmount] = useDebouncedValue(priceParams.amount, {\n wait: 500,\n });\n\n return useMemo(() => {\n // avoid passing unnecessary params to url?search and queryKey\n const sanitizedPriceParams: DeltaPriceQueryParams & {\n destChainId?: number;\n } = {\n amount: debouncedAmount,\n srcToken: priceParams.srcToken,\n destToken: priceParams.destToken,\n srcDecimals: priceParams.srcDecimals,\n destDecimals: priceParams.destDecimals,\n userAddress: priceParams.userAddress,\n beneficiary: priceParams.beneficiary,\n partner: priceParams.partner,\n partnerFeeBps: priceParams.partnerFeeBps,\n side: priceParams.side,\n includeAgents: priceParams.includeAgents,\n excludeAgents: priceParams.excludeAgents,\n includeBridges: priceParams.includeBridges,\n excludeBridges: priceParams.excludeBridges,\n allowBridgeAndSwap: priceParams.allowBridgeAndSwap,\n destChainId: destChainId,\n maxImpact: priceParams.maxImpact,\n degenMode: priceParams.degenMode,\n };\n\n const queryKey: DeltaPriceQueryKey = [\n DeltaPriceQueryKeyPrefix,\n chainId,\n sanitizedPriceParams,\n ];\n\n return { queryKey, sanitizedPriceParams };\n }, [\n priceParams.beneficiary,\n priceParams.destDecimals,\n priceParams.destToken,\n priceParams.excludeAgents,\n priceParams.includeAgents,\n priceParams.includeBridges,\n priceParams.excludeBridges,\n priceParams.partner,\n priceParams.partnerFeeBps,\n priceParams.side,\n priceParams.srcDecimals,\n priceParams.srcToken,\n priceParams.userAddress,\n priceParams.allowBridgeAndSwap,\n priceParams.maxImpact,\n priceParams.degenMode,\n chainId,\n debouncedAmount,\n destChainId,\n ]);\n}\n"],"mappings":";;;;;;;;AAyCA,IAAa+B,IAA2B;AAgDxC,SAAOG,EAAAG,GAAA;CAAA,IAAAC,IAAAC,EAAA,GAAA,EAA8D,EAAAZ,aAAAa,GAAAZ,UAAAC,YAAAC,SAAAW,GAAAR,mBAAAI,GAInEP,IAAAW,MAAAC,KAAAA,IAAAzB,IAAAwB,GAAgCE;CAAA,AAAAL,EAAA,OAAAT,IAQOc,IAAAL,EAAA,MAAXK,IAAA,EAAAd,YAAW,EAAAS,EAAA,KAAAT,GAAAS,EAAA,KAAAK;CAAvC,IAAA,EAAAC,WAAgB5C,EAAY2C,EAAY,EAExCE,IAAqBjB,GAAKkB,WAAL,IAAuBC;CAAA,AAAAT,EAAA,OAAAE,KAAAF,EAAA,OAAAT,KAAAS,EAAA,OAAAL,KAEqBc,IAAA;EAAApB,aAClDa;EAAYX;EAAAI;EAG1B,EAAAK,EAAA,KAAAE,GAAAF,EAAA,KAAAT,GAAAS,EAAA,KAAAL,GAAAK,EAAA,KAAAS,KAAAA,IAAAT,EAAA;CAJD,IAAA,EAAAF,aAAAY,4BAA2CC,EAAsBF,EAI/D,EAACG;CAAA,AAAAZ,EAAA,OAAAU,KAAAV,EAAA,OAAAM,KAAAN,EAAA,OAAAR,KASQoB,KAAAC,MAAA;EAAC,IAAA,EAAAC,cAAA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;GAC3BC,MAAM5E,EAAY4E;GAClBC,eAAe7E,EAAY6E;GAC3BC,eAAe9E,EAAY8E;GAC3BC,gBAAgB/E,EAAY+E;GAC5BC,gBAAgBhF,EAAYgF;GAC5BC,oBAAoBjF,EAAYiF;GACnB3E;GACb4E,WAAWlF,EAAYkF;GACvBC,WAAWnF,EAAYmF;GACxB;EAQD,OAAO;GAAE1E,UAAAA;IALPL;IACAF;IACAmB;IAGOZ;GAAUY;GAAsB;IACxC;EACDrB,EAAYyE;EACZzE,EAAYiC;EACZjC,EAAYgC;EACZhC,EAAY8E;EACZ9E,EAAY6E;EACZ7E,EAAY+E;EACZ/E,EAAYgF;EACZhF,EAAY0E;EACZ1E,EAAY2E;EACZ3E,EAAY4E;EACZ5E,EAAYuE;EACZvE,EAAYsE;EACZtE,EAAYwE;EACZxE,EAAYiF;EACZjF,EAAYkF;EACZlF,EAAYmF;EACZjF;EACAkE;EACA9D;EACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"useDeltaPriceQuery.js","names":["useDeltaV2SDK","Query","QueryClient","QueryObserver","useQuery","useQueryClient","UseQueryOptions","UseQueryResult","useDebouncedValue","DeltaPriceV2","DeltaPriceV2Params","DParams","OptimalRate","assert","MarkOptional","useMemo","PRICE_FETCH_TIMEOUT_MS","RequiredDeltaPriceParams","Omit","DeltaPriceQueryParams","DeltaQueryParams","Error","TData","DeltaPriceQueryKey","DeltaQueryResult","DeltaPriceQueryInput","priceParams","query","chainId","timeout","destChainId","DeltaPriceQueryKeyPrefix","base","useDeltaPriceQuery","t0","$","_c","_priceParams","t1","undefined","t2","sdk","queryEnabled","enabled","t3","queryKey","sanitizedPriceParams","useDeltaPriceQueryKey","t4","t5","signal","isPriceParamsValid","price","getDeltaPriceV2","t6","queryFn","result","t7","destToken","destDecimals","Number","amount","isDeltaPrice","isBridgePrice","route","bridge","GetDeltaPriceQueryForPriceInput","DeltaPriceQuery","GetDeltaPriceQueryForPrice","input","useDeltaPriceQueryForPrice","queryClient","queryCache","getQueryCache","query_0","find","exact","predicate","state","data","SubscribeToDeltaPriceInput","onData","onError","error","SubscribeToDeltaPriceResult","useSubscribeToDeltaPrice","observer","subscribe","getLastDeltaPriceQuery","type","getLastDeltaPrice","isLastDeltaPriceQueryInError","isDataDeltaPriceV2","Pick","debouncedAmount","wait","srcToken","srcDecimals","userAddress","beneficiary","partner","partnerFeeBps","side","includeAgents","excludeAgents","includeBridges","excludeBridges","allowBridgeAndSwap","maxImpact","degenMode"],"sources":["../../../../../../src/hooks/swap/prices/delta/queries/useDeltaPriceQuery.ts"],"sourcesContent":["import { useDeltaV2SDK } from \"@/hooks/useSDK\";\nimport {\n Query,\n QueryClient,\n QueryObserver,\n useQuery,\n useQueryClient,\n type UseQueryOptions,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport { useDebouncedValue } from \"@tanstack/react-pacer/debouncer\";\nimport type {\n DeltaPriceV2,\n DeltaPriceV2Params as DParams,\n OptimalRate,\n} from \"@velora-dex/sdk\";\nimport { assert, type MarkOptional } from \"ts-essentials\";\nimport { useMemo } from \"react\";\nimport { PRICE_FETCH_TIMEOUT_MS } from \"../../constants\";\n\n// destChainId is passed separately to keep the query key stable\ntype RequiredDeltaPriceParams = Omit<DParams, \"destChainId\">;\nexport type DeltaPriceQueryParams = MarkOptional<\n RequiredDeltaPriceParams,\n \"destToken\" | \"destDecimals\" // destToken is not available in SwapForm initially\n>;\n\ntype DeltaQueryParams<TData = DeltaPriceV2> = Omit<\n UseQueryOptions<DeltaPriceV2, Error, TData, DeltaPriceQueryKey>,\n \"queryKey\" | \"queryFn\"\n>;\ntype DeltaQueryResult<TData = DeltaPriceV2> = UseQueryResult<TData, Error>;\n\ntype DeltaPriceQueryInput<TData = DeltaPriceV2> = {\n priceParams: DeltaPriceQueryParams;\n query?: DeltaQueryParams<TData>;\n chainId: number;\n timeout?: number;\n destChainId?: number;\n};\n\nexport const DeltaPriceQueryKeyPrefix = \"swap/prices/delta\";\n\nexport type DeltaPriceQueryKey = readonly [\n base: typeof DeltaPriceQueryKeyPrefix,\n chainId: number,\n priceParams: DeltaPriceQueryParams & {\n destChainId?: number;\n },\n];\n\nexport function useDeltaPriceQuery<TData = DeltaPriceV2>({\n priceParams: _priceParams,\n query,\n chainId,\n timeout = PRICE_FETCH_TIMEOUT_MS,\n destChainId,\n}: DeltaPriceQueryInput<TData>): {\n result: DeltaQueryResult<TData>;\n queryKey: DeltaPriceQueryKey;\n} {\n const { sdk } = useDeltaV2SDK({ chainId });\n\n const queryEnabled = query?.enabled ?? true;\n\n const { queryKey, sanitizedPriceParams } = useDeltaPriceQueryKey({\n priceParams: _priceParams,\n chainId,\n destChainId,\n });\n\n const result = useQuery<DeltaPriceV2, Error, TData, DeltaPriceQueryKey>({\n queryKey,\n queryFn: ({ signal }) => {\n assert(isPriceParamsValid(sanitizedPriceParams), \"destToken is required\");\n const price = sdk.getDeltaPriceV2(sanitizedPriceParams, {\n signal,\n timeout,\n });\n return price;\n },\n ...query,\n enabled: queryEnabled && isPriceParamsValid(sanitizedPriceParams),\n });\n\n return { result, queryKey };\n}\n\nfunction isPriceParamsValid(\n priceParams: DeltaPriceQueryParams\n): priceParams is RequiredDeltaPriceParams {\n return (\n !!priceParams.destToken &&\n priceParams.destDecimals !== undefined &&\n Number(priceParams.amount) > 0\n );\n}\n\nexport function isDeltaPrice(\n price: OptimalRate | DeltaPriceV2\n): price is DeltaPriceV2 {\n return \"route\" in price;\n}\n\nexport function isBridgePrice(price: DeltaPriceV2): boolean {\n return price.route.bridge !== null;\n}\n\ntype GetDeltaPriceQueryForPriceInput = {\n price: DeltaPriceV2;\n chainId: number;\n};\n\ntype DeltaPriceQuery = Query<\n DeltaPriceV2,\n Error,\n DeltaPriceV2,\n DeltaPriceQueryKey\n>;\n\ntype GetDeltaPriceQueryForPrice = (\n input: GetDeltaPriceQueryForPriceInput\n) => DeltaPriceQuery | undefined;\n\n// get query for a given deltaPrice\nexport function useDeltaPriceQueryForPrice(): GetDeltaPriceQueryForPrice {\n const queryClient = useQueryClient();\n\n return ({ chainId, price }) => {\n const queryKey: [DeltaPriceQueryKey[0], DeltaPriceQueryKey[1]] = [\n DeltaPriceQueryKeyPrefix,\n chainId,\n ];\n const queryCache = queryClient.getQueryCache();\n const query = queryCache.find<DeltaPriceV2, Error, DeltaPriceV2>({\n queryKey,\n exact: false,\n predicate: (query) => {\n return query.state.data === price;\n },\n });\n\n return query as DeltaPriceQuery | undefined;\n };\n}\n\ntype SubscribeToDeltaPriceInput = {\n queryKey: DeltaPriceQueryKey;\n onData?: (data: DeltaPriceV2) => void;\n onError?: (error: Error) => void;\n};\n\ntype SubscribeToDeltaPriceResult = (\n input: SubscribeToDeltaPriceInput\n) => () => void;\n\n// independently subscribe to a price query\nexport function useSubscribeToDeltaPrice(): SubscribeToDeltaPriceResult {\n const queryClient = useQueryClient();\n\n return ({ queryKey, onData, onError }) => {\n const observer = new QueryObserver<\n DeltaPriceV2,\n Error,\n DeltaPriceV2,\n DeltaPriceV2,\n DeltaPriceQueryKey\n >(queryClient, {\n queryKey,\n // only receive updates from existing subscriptions\n enabled: false,\n });\n\n // return unsubscribe function\n return observer.subscribe((result) => {\n if (result.error) {\n onError?.(result.error);\n return;\n }\n if (result.data) {\n onData?.(result.data);\n }\n });\n };\n}\n\nfunction getLastDeltaPriceQuery(\n queryClient: QueryClient\n): Query<DeltaPriceV2, Error, DeltaPriceV2> | undefined {\n return queryClient\n .getQueryCache()\n .find<DeltaPriceV2, Error, DeltaPriceV2>({\n queryKey: [DeltaPriceQueryKeyPrefix],\n exact: false,\n type: \"active\", // only the most recent query will be active\n });\n}\n\nexport function getLastDeltaPrice(\n queryClient: QueryClient\n): DeltaPriceV2 | undefined {\n const query = getLastDeltaPriceQuery(queryClient);\n\n return query?.state.data;\n}\n\nexport function isLastDeltaPriceQueryInError(\n queryClient: QueryClient\n): boolean {\n const query = getLastDeltaPriceQuery(queryClient);\n const error = query?.state.error;\n return !!error;\n}\n\nexport function isDataDeltaPriceV2(\n price: unknown\n): price is DeltaPriceV2 {\n return (\n typeof price === \"object\" &&\n price !== null &&\n \"route\" in price &&\n \"inputToken\" in price &&\n \"outputToken\" in price\n );\n}\n\nexport function useDeltaPriceQueryKey({\n priceParams,\n chainId,\n destChainId,\n}: Pick<DeltaPriceQueryInput, \"priceParams\" | \"chainId\"> & {\n destChainId?: number;\n}) {\n \"use no memo\";\n\n // amount tends to change fast during input\n const [debouncedAmount] = useDebouncedValue(priceParams.amount, {\n wait: 500,\n });\n\n return useMemo(() => {\n // avoid passing unnecessary params to url?search and queryKey\n const sanitizedPriceParams: DeltaPriceQueryParams & {\n destChainId?: number;\n } = {\n amount: debouncedAmount,\n srcToken: priceParams.srcToken,\n destToken: priceParams.destToken,\n srcDecimals: priceParams.srcDecimals,\n destDecimals: priceParams.destDecimals,\n userAddress: priceParams.userAddress,\n beneficiary: priceParams.beneficiary,\n partner: priceParams.partner,\n partnerFeeBps: priceParams.partnerFeeBps,\n side: priceParams.side,\n includeAgents: priceParams.includeAgents,\n excludeAgents: priceParams.excludeAgents,\n includeBridges: priceParams.includeBridges,\n excludeBridges: priceParams.excludeBridges,\n allowBridgeAndSwap: priceParams.allowBridgeAndSwap,\n destChainId: destChainId,\n maxImpact: priceParams.maxImpact,\n degenMode: priceParams.degenMode,\n };\n\n const queryKey: DeltaPriceQueryKey = [\n DeltaPriceQueryKeyPrefix,\n chainId,\n sanitizedPriceParams,\n ];\n\n return { queryKey, sanitizedPriceParams };\n }, [\n priceParams.beneficiary,\n priceParams.destDecimals,\n priceParams.destToken,\n priceParams.excludeAgents,\n priceParams.includeAgents,\n priceParams.includeBridges,\n priceParams.excludeBridges,\n priceParams.partner,\n priceParams.partnerFeeBps,\n priceParams.side,\n priceParams.srcDecimals,\n priceParams.srcToken,\n priceParams.userAddress,\n priceParams.allowBridgeAndSwap,\n priceParams.maxImpact,\n priceParams.degenMode,\n chainId,\n debouncedAmount,\n destChainId,\n ]);\n}\n"],"mappings":";;;;;;;;AAyCA,IAAa+B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E;EACZvE,EAAYsE;EACZtE,EAAYwE;EACZxE,EAAYiF;EACZjF,EAAYkF;EACZlF,EAAYmF;EACZjF;EACAkE;EACAhE;EACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/hooks/swap/prices/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAIlD,wBAAgB,8BAA8B,CAAC,EAC7C,KAAK,EACL,UAAU,GACX,EAAE;IACD,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,KAAK,GAAG,IAAI,CAAC;CAC1B,GAAG,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/hooks/swap/prices/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAIlD,wBAAgB,8BAA8B,CAAC,EAC7C,KAAK,EACL,UAAU,GACX,EAAE;IACD,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,KAAK,GAAG,IAAI,CAAC;CAC1B,GAAG,MAAM,iBAAiB,CAiC1B"}
|
|
@@ -11,7 +11,7 @@ function r({ price: r, priceError: i }) {
|
|
|
11
11
|
isUnavailable: !1
|
|
12
12
|
};
|
|
13
13
|
let a = null, o = null;
|
|
14
|
-
return r ? (a = r.
|
|
14
|
+
return r ? e(r) ? (a = r.route.origin.input.amountUSD, o = r.route.destination.output.amountUSD) : (a = r.srcUSD, o = r.destUSD) : i && n(i) && i.response && (a = i.response.data.priceRoute.srcUSD, o = i.response.data.priceRoute.destUSD), t({
|
|
15
15
|
srcUSD: a,
|
|
16
16
|
destUSD: o
|
|
17
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","names":["getPriceImpact","PriceImpactResult","DeltaOrMarketPrice","isMarketPriceImpactError","isDeltaPrice","getPriceImpactFromPriceFactory","price","priceError","Error","priceImpact","undefined","isHighImpact","isMediumImpact","isUnavailable","srcUSD","destUSD","
|
|
1
|
+
{"version":3,"file":"factory.js","names":["getPriceImpact","PriceImpactResult","DeltaOrMarketPrice","isMarketPriceImpactError","isDeltaPrice","getPriceImpactFromPriceFactory","price","priceError","Error","priceImpact","undefined","isHighImpact","isMediumImpact","isUnavailable","srcUSD","destUSD","route","origin","input","amountUSD","destination","output","response","data","priceRoute"],"sources":["../../../../src/hooks/swap/prices/factory.ts"],"sourcesContent":["import {\n getPriceImpact,\n type PriceImpactResult,\n} from \"@/lib/utils/priceImpact\";\nimport type { DeltaOrMarketPrice } from \"./types\";\nimport { isMarketPriceImpactError } from \"./market/queries/errors\";\nimport { isDeltaPrice } from \"./delta/queries/useDeltaPriceQuery\";\n\nexport function getPriceImpactFromPriceFactory({\n price,\n priceError,\n}: {\n price?: DeltaOrMarketPrice;\n priceError: Error | null;\n}): () => PriceImpactResult {\n return () => {\n if (!price && !priceError) {\n return {\n priceImpact: undefined,\n isHighImpact: false,\n isMediumImpact: false,\n isUnavailable: false,\n };\n }\n\n let srcUSD: string | null = null;\n let destUSD: string | null = null;\n\n if (price) {\n if (isDeltaPrice(price)) {\n srcUSD = price.route.origin.input.amountUSD;\n destUSD = price.route.destination.output.amountUSD;\n } else {\n srcUSD = price.srcUSD;\n destUSD = price.destUSD;\n }\n } else if (\n priceError &&\n isMarketPriceImpactError(priceError) &&\n priceError.response\n ) {\n srcUSD = priceError.response.data.priceRoute.srcUSD;\n destUSD = priceError.response.data.priceRoute.destUSD;\n }\n\n return getPriceImpact({ srcUSD, destUSD });\n };\n}\n"],"mappings":";;;;AAQA,SAAgBK,EAA+B,EAC7CC,UACAC,iBAI0B;CAC1B,aAAa;EACX,IAAI,CAACD,KAAS,CAACC,GACb,OAAO;GACLE,aAAaC,KAAAA;GACbC,cAAc;GACdC,gBAAgB;GAChBC,eAAe;GAChB;EAGH,IAAIC,IAAwB,MACxBC,IAAyB;EAmB7B,OAjBIT,IACEF,EAAaE,EAAM,IACrBQ,IAASR,EAAMU,MAAMC,OAAOC,MAAMC,WAClCJ,IAAUT,EAAMU,MAAMI,YAAYC,OAAOF,cAEzCL,IAASR,EAAMQ,QACfC,IAAUT,EAAMS,WAGlBR,KACAJ,EAAyBI,EAAW,IACpCA,EAAWe,aAEXR,IAASP,EAAWe,SAASC,KAAKC,WAAWV,QAC7CC,IAAUR,EAAWe,SAASC,KAAKC,WAAWT,UAGzCf,EAAe;GAAEc;GAAQC;GAAS,CAAC"}
|
|
@@ -42,7 +42,7 @@ export declare function useMarketPriceQueryKey({ priceParams, chainId, }: Pick<M
|
|
|
42
42
|
sanitizedPriceParams: {
|
|
43
43
|
amount: string;
|
|
44
44
|
userAddress: string | undefined;
|
|
45
|
-
side: "
|
|
45
|
+
side: "BUY" | "SELL" | undefined;
|
|
46
46
|
srcDecimals: number | undefined;
|
|
47
47
|
destDecimals: number | undefined;
|
|
48
48
|
srcToken: string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type DeltaOrMarketPrice = OptimalRate |
|
|
3
|
-
export type DeltaOrBridgePrice = DeltaPrice | BridgePrice;
|
|
1
|
+
import { DeltaPriceV2, OptimalRate } from '@velora-dex/sdk';
|
|
2
|
+
export type DeltaOrMarketPrice = OptimalRate | DeltaPriceV2;
|
|
4
3
|
export type UseSwapPricesInput = {
|
|
5
4
|
enabled?: boolean;
|
|
6
5
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/hooks/swap/prices/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/hooks/swap/prices/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEjE,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,YAAY,CAAC;AAE5D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MarketPriceQueryKey } from './market/queries/useMarketPriceQuery';
|
|
2
2
|
import { DeltaPriceQueryKey } from './delta/queries/useDeltaPriceQuery';
|
|
3
3
|
import { SwapMode } from '../../../components/widget/SwapModeSwitcher/state/types';
|
|
4
|
-
import {
|
|
4
|
+
import { DeltaPriceV2, OptimalRate, SwapSideUnion } from '@velora-dex/sdk';
|
|
5
5
|
import { DeltaOrMarketPrice, UseSwapPricesInput } from './types';
|
|
6
6
|
import { QueryObserverResult, RefetchOptions } from '@tanstack/react-query';
|
|
7
7
|
import { PriceImpactResult } from '../../../lib/utils/priceImpact';
|
|
@@ -23,7 +23,7 @@ type UseSwapPricesReturn = {
|
|
|
23
23
|
queryKey: MarketPriceQueryKey;
|
|
24
24
|
};
|
|
25
25
|
delta: {
|
|
26
|
-
price?:
|
|
26
|
+
price?: DeltaPriceV2;
|
|
27
27
|
side?: SwapSideUnion;
|
|
28
28
|
/** @description whether the delta price can be used for the current price params && widget config */
|
|
29
29
|
canBeUsed: boolean;
|
|
@@ -31,7 +31,7 @@ type UseSwapPricesReturn = {
|
|
|
31
31
|
isFetching: boolean;
|
|
32
32
|
isRefetching: boolean;
|
|
33
33
|
isError: boolean;
|
|
34
|
-
refetch: (options?: RefetchOptions) => Promise<QueryObserverResult<
|
|
34
|
+
refetch: (options?: RefetchOptions) => Promise<QueryObserverResult<DeltaPriceV2, Error>>;
|
|
35
35
|
error: Error | null;
|
|
36
36
|
cachedError: Error | null;
|
|
37
37
|
queryKey: DeltaPriceQueryKey;
|