@sodax/dapp-kit 2.3.0 → 2.4.0-rc.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/index.d.ts +48 -28
- package/dist/index.mjs +108 -20
- package/package.json +10 -5
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.test.ts +28 -3
- package/src/hooks/bridge/getBridgeDetailedStatusRefetchInterval.ts +17 -8
- package/src/hooks/bridge/useBridge.ts +6 -0
- package/src/hooks/bridge/useBridgeDetailedStatus.test.ts +56 -1
- package/src/hooks/bridge/useBridgeDetailedStatus.ts +26 -9
- package/src/hooks/bridge/useBridgeWithApproval.test.ts +24 -1
- package/src/hooks/bridge/useBridgeWithApproval.ts +6 -0
- package/src/hooks/dex/useDexDeposit.ts +6 -0
- package/src/hooks/dex/useDexWithdraw.ts +12 -5
- package/src/hooks/mm/useBorrow.ts +15 -4
- package/src/hooks/mm/useRepay.ts +6 -0
- package/src/hooks/mm/useSupply.ts +6 -0
- package/src/hooks/mm/useWithdraw.ts +12 -5
- package/src/hooks/recovery/useWithdrawHubAsset.ts +12 -5
- package/src/hooks/shared/notFoundStreak.ts +5 -0
- package/src/hooks/shared/retryBeforeSubmission.ts +26 -0
- package/src/hooks/shared/useBalances.test.ts +10 -0
- package/src/hooks/shared/useBalances.ts +17 -4
- package/src/hooks/shared/useSafeMutation.retry.test.ts +47 -0
- package/src/hooks/shared/useSafeMutation.ts +8 -1
- package/src/hooks/swap/useCreateLimitOrder.ts +8 -0
- package/src/hooks/swap/useSwap.ts +6 -0
- package/src/hooks/swap/useSwapLifecycle.test.ts +27 -1
- package/src/hooks/swap/useSwapWithApproval.test.ts +24 -1
- package/src/hooks/swap/useSwapWithApproval.ts +6 -0
- package/src/utils/swapLifecycle.ts +14 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isSodaxError, isAuthFailure, ChainKeys, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, RadfiApiError, normalizePsbtToBase64, summarizeSwapStatus, isEvmChainKeyType, resolveApprovalStrategy, isEvmSpokeOnlyChainKeyType, sendApprovalBatch, DEFAULT_RELAY_TX_TIMEOUT, isAtomicBatchRefusal, SodaxError, ATOMIC_BATCH_REFUSED, getEvmViemChain, DETAILED_STATUS_NOT_DELIVERED, ClService, SPONSOR_CONFIG_TTL_MS, Sodax, SolverIntentStatusCode, isApprovalSupportedChainKeyType, isHubChainKeyType, isStellarChainKeyType
|
|
1
|
+
import { isSodaxError, isAuthFailure, ChainKeys, STELLAR_TRUSTLINE_MIN_XLM_STROOPS, RadfiApiError, normalizePsbtToBase64, summarizeSwapStatus, isEvmChainKeyType, resolveApprovalStrategy, isEvmSpokeOnlyChainKeyType, sendApprovalBatch, DEFAULT_RELAY_TX_TIMEOUT, isAtomicBatchRefusal, SodaxError, ATOMIC_BATCH_REFUSED, getEvmViemChain, DETAILED_STATUS_NOT_DELIVERED, ClService, SPONSOR_CONFIG_TTL_MS, Sodax, isIndeterminateOutcomeError, ATOMIC_BATCH_UNCONFIRMED, SolverIntentStatusCode, isApprovalSupportedChainKeyType, isHubChainKeyType, isStellarChainKeyType } from '@sodax/sdk';
|
|
2
2
|
export * from '@sodax/sdk';
|
|
3
|
-
import { useMutation, useQuery,
|
|
3
|
+
import { useQueryClient, useMutation, useQuery, useIsFetching, useQueries, QueryClient, MutationCache } from '@tanstack/react-query';
|
|
4
4
|
import { createContext, useCallback, useContext, useRef, useState, useEffect, useMemo } from 'react';
|
|
5
5
|
import { isAddress, erc20Abi, parseUnits } from 'viem';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
@@ -22,6 +22,22 @@ function unwrapResult(result) {
|
|
|
22
22
|
}
|
|
23
23
|
return result.value;
|
|
24
24
|
}
|
|
25
|
+
function retryBeforeSubmission(retry) {
|
|
26
|
+
return (failureCount, error) => {
|
|
27
|
+
if (isIndeterminateOutcomeError(error)) return false;
|
|
28
|
+
if (isSodaxError(error)) {
|
|
29
|
+
const { srcTxHash, hubTxHash, dstTxHash, trackingId, recovery, batchId, reason } = error.context ?? {};
|
|
30
|
+
if (srcTxHash || hubTxHash || dstTxHash || trackingId || recovery || batchId || reason === ATOMIC_BATCH_UNCONFIRMED) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (typeof retry === "function") return retry(failureCount, error);
|
|
35
|
+
if (typeof retry === "number") return failureCount < retry;
|
|
36
|
+
return retry === true;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/hooks/shared/useSafeMutation.ts
|
|
25
41
|
async function toResult(promise) {
|
|
26
42
|
try {
|
|
27
43
|
const value = await promise;
|
|
@@ -31,7 +47,12 @@ async function toResult(promise) {
|
|
|
31
47
|
}
|
|
32
48
|
}
|
|
33
49
|
function useSafeMutation(options) {
|
|
34
|
-
const
|
|
50
|
+
const queryClient = useQueryClient();
|
|
51
|
+
const { retry } = queryClient.defaultMutationOptions(options);
|
|
52
|
+
const mutation = useMutation({
|
|
53
|
+
...options,
|
|
54
|
+
retry: retryBeforeSubmission(retry)
|
|
55
|
+
});
|
|
35
56
|
const { mutateAsync } = mutation;
|
|
36
57
|
const mutateAsyncSafe = useCallback(
|
|
37
58
|
(vars, opts) => toResult(mutateAsync(vars, opts)),
|
|
@@ -518,14 +539,24 @@ function useXBalances({
|
|
|
518
539
|
});
|
|
519
540
|
}
|
|
520
541
|
var REFETCH_INTERVAL_MS2 = 5e3;
|
|
521
|
-
function getBalancesQueryOptions(sodax, { chainKey, tokens, address }) {
|
|
542
|
+
function getBalancesQueryOptions(sodax, { chainKey, tokens, address, accountAddress }) {
|
|
543
|
+
const tonAccount = chainKey === ChainKeys.TON_MAINNET && accountAddress ? { accountAddress } : void 0;
|
|
522
544
|
return {
|
|
523
545
|
// Pair symbol + address: readable in devtools, unique on-chain (symbol alone can collide —
|
|
524
546
|
// e.g. scam tokens copying a legitimate ticker).
|
|
525
|
-
queryKey: [
|
|
547
|
+
queryKey: [
|
|
548
|
+
"shared",
|
|
549
|
+
"balances",
|
|
550
|
+
chainKey,
|
|
551
|
+
tokens.map((t) => [t.symbol, t.address]),
|
|
552
|
+
address,
|
|
553
|
+
...tonAccount ? [tonAccount.accountAddress] : []
|
|
554
|
+
],
|
|
526
555
|
queryFn: async () => {
|
|
527
556
|
if (!chainKey || !address) return {};
|
|
528
|
-
return unwrapResult(
|
|
557
|
+
return unwrapResult(
|
|
558
|
+
await sodax.spoke.getWalletBalances({ srcChainKey: chainKey, srcAddress: address, tokens, ...tonAccount })
|
|
559
|
+
);
|
|
529
560
|
},
|
|
530
561
|
enabled: !!chainKey && !!address && tokens.length > 0,
|
|
531
562
|
refetchInterval: REFETCH_INTERVAL_MS2
|
|
@@ -540,7 +571,8 @@ function useBalances({ params, queryOptions } = {}) {
|
|
|
540
571
|
...getBalancesQueryOptions(sodax, {
|
|
541
572
|
chainKey: params?.chainKey,
|
|
542
573
|
tokens: params?.tokens ?? [],
|
|
543
|
-
address: params?.address
|
|
574
|
+
address: params?.address,
|
|
575
|
+
accountAddress: params?.accountAddress
|
|
544
576
|
}),
|
|
545
577
|
...queryOptions
|
|
546
578
|
});
|
|
@@ -814,6 +846,9 @@ function useBorrow({
|
|
|
814
846
|
return useSafeMutation({
|
|
815
847
|
mutationKey: ["mm", "borrow"],
|
|
816
848
|
...mutationOptions,
|
|
849
|
+
retry: retryBeforeSubmission(
|
|
850
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["mm", "borrow"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
851
|
+
),
|
|
817
852
|
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.borrow({ ...vars, raw: false })),
|
|
818
853
|
onSuccess: async (data, vars, ctx) => {
|
|
819
854
|
const { params } = vars;
|
|
@@ -835,6 +870,9 @@ function useRepay({
|
|
|
835
870
|
return useSafeMutation({
|
|
836
871
|
mutationKey: ["mm", "repay"],
|
|
837
872
|
...mutationOptions,
|
|
873
|
+
retry: retryBeforeSubmission(
|
|
874
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["mm", "repay"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
875
|
+
),
|
|
838
876
|
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.repay({ ...vars, raw: false })),
|
|
839
877
|
onSuccess: async (data, vars, ctx) => {
|
|
840
878
|
const { params } = vars;
|
|
@@ -857,6 +895,9 @@ function useSupply({
|
|
|
857
895
|
return useSafeMutation({
|
|
858
896
|
mutationKey: ["mm", "supply"],
|
|
859
897
|
...mutationOptions,
|
|
898
|
+
retry: retryBeforeSubmission(
|
|
899
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["mm", "supply"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
900
|
+
),
|
|
860
901
|
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.supply({ ...vars, raw: false })),
|
|
861
902
|
onSuccess: async (data, vars, ctx) => {
|
|
862
903
|
const { params } = vars;
|
|
@@ -879,6 +920,9 @@ function useWithdraw({
|
|
|
879
920
|
return useSafeMutation({
|
|
880
921
|
mutationKey: ["mm", "withdraw"],
|
|
881
922
|
...mutationOptions,
|
|
923
|
+
retry: retryBeforeSubmission(
|
|
924
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["mm", "withdraw"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
925
|
+
),
|
|
882
926
|
mutationFn: async (vars) => unwrapResult(await sodax.moneyMarket.withdraw({ ...vars, raw: false })),
|
|
883
927
|
onSuccess: async (data, vars, ctx) => {
|
|
884
928
|
const { params } = vars;
|
|
@@ -1144,6 +1188,9 @@ function useSwap({
|
|
|
1144
1188
|
return useSafeMutation({
|
|
1145
1189
|
mutationKey: ["swap"],
|
|
1146
1190
|
...mutationOptions,
|
|
1191
|
+
retry: retryBeforeSubmission(
|
|
1192
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["swap"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
1193
|
+
),
|
|
1147
1194
|
mutationFn: async (vars) => unwrapResult(await sodax.swaps.swap({ ...vars, raw: false })),
|
|
1148
1195
|
onSuccess: async (data, vars, ctx) => {
|
|
1149
1196
|
invalidateBalances(queryClient, vars.params.srcChainKey, vars.params.dstChainKey);
|
|
@@ -1155,6 +1202,7 @@ function useSwap({
|
|
|
1155
1202
|
// src/hooks/shared/notFoundStreak.ts
|
|
1156
1203
|
var STATUS_POLL_MS = 3e3;
|
|
1157
1204
|
var MAX_NOT_FOUND_POLLS = 40;
|
|
1205
|
+
var MAX_MPC_RELAY_NOT_FOUND_POLLS = 100;
|
|
1158
1206
|
var INITIAL_NOT_FOUND_STREAK = {
|
|
1159
1207
|
pollKey: void 0,
|
|
1160
1208
|
seenUpdates: 0,
|
|
@@ -1352,6 +1400,9 @@ function useSwapWithApproval({
|
|
|
1352
1400
|
return useSafeMutation({
|
|
1353
1401
|
mutationKey: ["swap", "swapWithApproval"],
|
|
1354
1402
|
...mutationOptions,
|
|
1403
|
+
retry: retryBeforeSubmission(
|
|
1404
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["swap", "swapWithApproval"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
1405
|
+
),
|
|
1355
1406
|
mutationFn: async (vars) => unwrapResult(await sodax.swaps.swapWithApproval({ ...vars, raw: false })),
|
|
1356
1407
|
onSuccess: async (data, vars, ctx) => {
|
|
1357
1408
|
invalidateBalances(queryClient, vars.params.srcChainKey, vars.params.dstChainKey);
|
|
@@ -1369,7 +1420,7 @@ function toSwapAttempt(mutation, intentParams) {
|
|
|
1369
1420
|
const attempted = mutation.variables?.params;
|
|
1370
1421
|
if (mutation.status === "idle" || !attempted) return { phase: "none" };
|
|
1371
1422
|
const attempt = toFinishedAttempt(mutation, attempted);
|
|
1372
|
-
const mayStillLand = attempt.phase === "unconfirmed" || attempt.phase === "broadcast" && attempt.error !== void 0;
|
|
1423
|
+
const mayStillLand = attempt.phase === "unconfirmed" || attempt.phase === "recovering" || attempt.phase === "broadcast" && attempt.error !== void 0;
|
|
1373
1424
|
if (mayStillLand || intentParams && isSameIntent(attempted, intentParams)) return attempt;
|
|
1374
1425
|
return { phase: "none" };
|
|
1375
1426
|
}
|
|
@@ -1383,6 +1434,9 @@ function toFinishedAttempt(mutation, attempted) {
|
|
|
1383
1434
|
if (typeof context?.srcTxHash === "string") {
|
|
1384
1435
|
return { phase: "broadcast", srcChainKey: attempted.srcChainKey, srcTxHash: context.srcTxHash, error };
|
|
1385
1436
|
}
|
|
1437
|
+
if (context?.recovery !== void 0) {
|
|
1438
|
+
return { phase: "recovering", srcChainKey: attempted.srcChainKey, recovery: context.recovery, error };
|
|
1439
|
+
}
|
|
1386
1440
|
if (context?.reason === ATOMIC_BATCH_UNCONFIRMED && typeof context.batchId === "string") {
|
|
1387
1441
|
return typeof context.callCount === "number" ? { phase: "unconfirmed", batchId: context.batchId, callCount: context.callCount, error } : { phase: "unconfirmed", batchId: context.batchId, error };
|
|
1388
1442
|
}
|
|
@@ -1400,6 +1454,10 @@ function resolveSwapLifecycle(inputs) {
|
|
|
1400
1454
|
const error = attempt.error ?? inputs.statusError;
|
|
1401
1455
|
return error ? { kind: "pending", srcChainKey, srcTxHash, error } : { kind: "pending", srcChainKey, srcTxHash };
|
|
1402
1456
|
}
|
|
1457
|
+
if (attempt.phase === "recovering") {
|
|
1458
|
+
const { srcChainKey, recovery, error } = attempt;
|
|
1459
|
+
return { kind: "pending", srcChainKey, recovery, error };
|
|
1460
|
+
}
|
|
1403
1461
|
if (attempt.phase === "unconfirmed") {
|
|
1404
1462
|
const { batchId, callCount, error } = attempt;
|
|
1405
1463
|
return callCount === void 0 ? { kind: "unconfirmed", batchId, error } : { kind: "unconfirmed", batchId, callCount, error };
|
|
@@ -1549,15 +1607,17 @@ function useCancelSwap({
|
|
|
1549
1607
|
mutationFn: async ({ srcChainKey, walletProvider, intent }) => unwrapResult(await sodax.swaps.cancelIntent({ params: { srcChainKey, intent }, walletProvider }))
|
|
1550
1608
|
});
|
|
1551
1609
|
}
|
|
1552
|
-
|
|
1553
|
-
// src/hooks/swap/useCreateLimitOrder.ts
|
|
1554
1610
|
function useCreateLimitOrder({
|
|
1555
1611
|
mutationOptions
|
|
1556
1612
|
} = {}) {
|
|
1557
1613
|
const { sodax } = useSodaxContext();
|
|
1614
|
+
const queryClient = useQueryClient();
|
|
1558
1615
|
return useSafeMutation({
|
|
1559
1616
|
mutationKey: ["swap", "limitOrder", "create"],
|
|
1560
1617
|
...mutationOptions,
|
|
1618
|
+
retry: retryBeforeSubmission(
|
|
1619
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["swap", "limitOrder", "create"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
1620
|
+
),
|
|
1561
1621
|
mutationFn: async (vars) => unwrapResult(await sodax.swaps.createLimitOrder({ ...vars, raw: false }))
|
|
1562
1622
|
});
|
|
1563
1623
|
}
|
|
@@ -2374,14 +2434,20 @@ var useSwapsApiSubmitTxStatus = ({
|
|
|
2374
2434
|
function isBridgeNotDelivered(data) {
|
|
2375
2435
|
return data !== void 0 && !data.ok && data.error?.context?.reason === DETAILED_STATUS_NOT_DELIVERED;
|
|
2376
2436
|
}
|
|
2437
|
+
function isBridgeMpcRelayRead(data) {
|
|
2438
|
+
return data !== void 0 && !data.ok && data.error?.context?.mpcRelay === true;
|
|
2439
|
+
}
|
|
2377
2440
|
function getBridgeDetailedStatusRefetchInterval(data, consecutiveNotFound) {
|
|
2378
2441
|
if (data?.ok) {
|
|
2379
|
-
if (data.value.source
|
|
2442
|
+
if (data.value.source !== "backend") return false;
|
|
2380
2443
|
const { status, abandonedAt } = data.value.data;
|
|
2381
2444
|
return status === "executed" || status === "failed" || abandonedAt ? false : STATUS_POLL_MS;
|
|
2382
2445
|
}
|
|
2383
|
-
if (data && !data.ok
|
|
2384
|
-
|
|
2446
|
+
if (data && !data.ok) {
|
|
2447
|
+
if (isAuthFailure(data.error)) return false;
|
|
2448
|
+
const budget = isBridgeMpcRelayRead(data) ? MAX_MPC_RELAY_NOT_FOUND_POLLS : MAX_NOT_FOUND_POLLS;
|
|
2449
|
+
if (isBridgeNotDelivered(data) && consecutiveNotFound >= budget) return false;
|
|
2450
|
+
}
|
|
2385
2451
|
return STATUS_POLL_MS;
|
|
2386
2452
|
}
|
|
2387
2453
|
function useBridge({
|
|
@@ -2392,6 +2458,9 @@ function useBridge({
|
|
|
2392
2458
|
return useSafeMutation({
|
|
2393
2459
|
mutationKey: ["bridge"],
|
|
2394
2460
|
...mutationOptions,
|
|
2461
|
+
retry: retryBeforeSubmission(
|
|
2462
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["bridge"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
2463
|
+
),
|
|
2395
2464
|
mutationFn: async (vars) => unwrapResult(await sodax.bridge.bridge({ ...vars, raw: false })),
|
|
2396
2465
|
onSuccess: async (data, vars, ctx) => {
|
|
2397
2466
|
invalidateBalances(queryClient, vars.params.srcChainKey, vars.params.dstChainKey);
|
|
@@ -2399,6 +2468,10 @@ function useBridge({
|
|
|
2399
2468
|
}
|
|
2400
2469
|
});
|
|
2401
2470
|
}
|
|
2471
|
+
function onwardHubTxHash(data) {
|
|
2472
|
+
const hubTxHash = data && !data.ok ? data.error.context?.hubTxHash : void 0;
|
|
2473
|
+
return typeof hubTxHash === "string" ? hubTxHash : void 0;
|
|
2474
|
+
}
|
|
2402
2475
|
var useBridgeDetailedStatus = ({
|
|
2403
2476
|
params,
|
|
2404
2477
|
queryOptions
|
|
@@ -2406,24 +2479,27 @@ var useBridgeDetailedStatus = ({
|
|
|
2406
2479
|
const { sodax } = useSodaxContext();
|
|
2407
2480
|
const srcChainKey = params?.srcChainKey;
|
|
2408
2481
|
const srcTxHash = params?.srcTxHash;
|
|
2482
|
+
const dstChainKey = params?.dstChainKey;
|
|
2409
2483
|
const apiConfig = params?.apiConfig;
|
|
2410
|
-
const pollKey = srcChainKey && srcTxHash ? `${srcChainKey}:${srcTxHash}` : void 0;
|
|
2484
|
+
const pollKey = srcChainKey && srcTxHash ? `${srcChainKey}:${srcTxHash}:${dstChainKey ?? ""}` : void 0;
|
|
2411
2485
|
const notFoundStreakRef = useRef({ ...INITIAL_NOT_FOUND_STREAK });
|
|
2412
2486
|
return useQuery({
|
|
2413
|
-
queryKey: ["bridge", "detailedStatus", srcChainKey, srcTxHash],
|
|
2487
|
+
queryKey: ["bridge", "detailedStatus", srcChainKey, srcTxHash, ...dstChainKey ? [dstChainKey] : []],
|
|
2414
2488
|
queryFn: async () => {
|
|
2415
2489
|
if (!srcChainKey || !srcTxHash) return void 0;
|
|
2416
|
-
return sodax.bridge.getDetailedStatus({ srcChainKey, srcTxHash }, apiConfig);
|
|
2490
|
+
return sodax.bridge.getDetailedStatus({ srcChainKey, srcTxHash, dstChainKey }, apiConfig);
|
|
2417
2491
|
},
|
|
2418
2492
|
enabled: !!srcChainKey && !!srcTxHash,
|
|
2419
2493
|
refetchInterval: (query) => {
|
|
2494
|
+
const { data } = query.state;
|
|
2495
|
+
const leg = [onwardHubTxHash(data), isBridgeMpcRelayRead(data) ? "mpcRelay" : void 0].filter(Boolean);
|
|
2420
2496
|
notFoundStreakRef.current = advanceNotFoundStreak(
|
|
2421
2497
|
notFoundStreakRef.current,
|
|
2422
|
-
pollKey,
|
|
2423
|
-
isBridgeNotDelivered(
|
|
2498
|
+
pollKey && [pollKey, ...leg].join(":"),
|
|
2499
|
+
isBridgeNotDelivered(data),
|
|
2424
2500
|
query.state.dataUpdateCount
|
|
2425
2501
|
);
|
|
2426
|
-
return getBridgeDetailedStatusRefetchInterval(
|
|
2502
|
+
return getBridgeDetailedStatusRefetchInterval(data, notFoundStreakRef.current.consecutiveNotFound);
|
|
2427
2503
|
},
|
|
2428
2504
|
...queryOptions
|
|
2429
2505
|
});
|
|
@@ -2514,6 +2590,9 @@ function useBridgeWithApproval({
|
|
|
2514
2590
|
return useSafeMutation({
|
|
2515
2591
|
mutationKey: ["bridge", "bridgeWithApproval"],
|
|
2516
2592
|
...mutationOptions,
|
|
2593
|
+
retry: retryBeforeSubmission(
|
|
2594
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["bridge", "bridgeWithApproval"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
2595
|
+
),
|
|
2517
2596
|
mutationFn: async (vars) => unwrapResult(await sodax.bridge.bridgeWithApproval({ ...vars, raw: false })),
|
|
2518
2597
|
onSuccess: async (data, vars, ctx) => {
|
|
2519
2598
|
invalidateBalances(queryClient, vars.params.srcChainKey, vars.params.dstChainKey);
|
|
@@ -3407,6 +3486,9 @@ function useWithdrawHubAsset({
|
|
|
3407
3486
|
return useSafeMutation({
|
|
3408
3487
|
mutationKey: ["recovery", "withdrawHubAsset"],
|
|
3409
3488
|
...mutationOptions,
|
|
3489
|
+
retry: retryBeforeSubmission(
|
|
3490
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["recovery", "withdrawHubAsset"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
3491
|
+
),
|
|
3410
3492
|
mutationFn: async (vars) => unwrapResult(await sodax.recovery.withdrawHubAsset({ ...vars, raw: false })),
|
|
3411
3493
|
onSuccess: async (data, vars, ctx) => {
|
|
3412
3494
|
const { params } = vars;
|
|
@@ -3632,6 +3714,9 @@ function useDexDeposit({
|
|
|
3632
3714
|
return useSafeMutation({
|
|
3633
3715
|
mutationKey: ["dex", "deposit"],
|
|
3634
3716
|
...mutationOptions,
|
|
3717
|
+
retry: retryBeforeSubmission(
|
|
3718
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["dex", "deposit"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
3719
|
+
),
|
|
3635
3720
|
mutationFn: async (vars) => unwrapResult(await sodax.dex.assetService.deposit({ ...vars, raw: false })),
|
|
3636
3721
|
onSuccess: async (data, vars, ctx) => {
|
|
3637
3722
|
const { params } = vars;
|
|
@@ -3652,6 +3737,9 @@ function useDexWithdraw({
|
|
|
3652
3737
|
return useSafeMutation({
|
|
3653
3738
|
mutationKey: ["dex", "withdraw"],
|
|
3654
3739
|
...mutationOptions,
|
|
3740
|
+
retry: retryBeforeSubmission(
|
|
3741
|
+
mutationOptions?.retry ?? queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ["dex", "withdraw"])?.retry ?? queryClient.getDefaultOptions?.().mutations?.retry
|
|
3742
|
+
),
|
|
3655
3743
|
mutationFn: async (vars) => unwrapResult(await sodax.dex.assetService.withdraw({ ...vars, raw: false })),
|
|
3656
3744
|
onSuccess: async (data, vars, ctx) => {
|
|
3657
3745
|
const { params } = vars;
|
|
@@ -5249,4 +5337,4 @@ function createSodaxQueryClient({
|
|
|
5249
5337
|
});
|
|
5250
5338
|
}
|
|
5251
5339
|
|
|
5252
|
-
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getBalancesQueryOptions, getBridgeDetailedStatusRefetchInterval, getLeverageYieldQuoteQueryOptions, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getSwapQuoteQueryOptions, getXBalancesQueryOptions, invalidateBalances, isBridgeNotDelivered, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, retryUnlessAuthFailure, runApprovalPlan, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveLeveragePositionFunding, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOracleCandles, useBackendOracleMarkets, useBackendOrderbook, useBackendUserIntents, useBalances, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiApproveAndBroadcast, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprovalStrategy, useBridgeApprove, useBridgeDetailedStatus, useBridgeWithApproval, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDetailedStatus, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEModes, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeveragePositionAccount, useLeveragePositionCollateral, useLeveragePositionFundingAllowance, useLeveragePositionInfo, useLeveragePositionPayoutAddress, useLeveragePositionPending, useLeveragePositions, useLeveragePositionsForUser, useLeverageYieldApiAllowance, useLeverageYieldApiApprove, useLeverageYieldApiApproveAndBroadcast, useLeverageYieldApiApr, useLeverageYieldApiAsset, useLeverageYieldApiCancelIntent, useLeverageYieldApiCreateDepositIntent, useLeverageYieldApiCreateWithdrawIntent, useLeverageYieldApiDeadline, useLeverageYieldApiDepositQuote, useLeverageYieldApiEffectiveApr, useLeverageYieldApiEstimateGas, useLeverageYieldApiFilledIntent, useLeverageYieldApiIntent, useLeverageYieldApiIntentExtraData, useLeverageYieldApiIntentHash, useLeverageYieldApiIntentPacket, useLeverageYieldApiLsdApr, useLeverageYieldApiMaxWithdraw, useLeverageYieldApiPartnerFee, useLeverageYieldApiPosition, useLeverageYieldApiPreviewDeposit, useLeverageYieldApiPreviewRedeem, useLeverageYieldApiPreviewWithdraw, useLeverageYieldApiShareBalance, useLeverageYieldApiSolverFee, useLeverageYieldApiStatus, useLeverageYieldApiSubmitIntent, useLeverageYieldApiSubmitTx, useLeverageYieldApiSubmitTxStatus, useLeverageYieldApiTotalAssets, useLeverageYieldApiVault, useLeverageYieldApiVaults, useLeverageYieldApiWithdrawQuote, useLeverageYieldApprovalStrategy, useLeverageYieldDeposit, useLeverageYieldDetailedStatus, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldQuote, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldVaultSwapWithApproval, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, useOpenLeveragePosition, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useRunLeveragePositionOperation, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSubmitLeveragePositionIntent, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprovalStrategy, useSwapApprove, useSwapLifecycle, useSwapWithApproval, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiApproveAndBroadcast, useSwapsApiBroadcastWithApproval, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
|
5340
|
+
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getBalancesQueryOptions, getBridgeDetailedStatusRefetchInterval, getLeverageYieldQuoteQueryOptions, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getSwapQuoteQueryOptions, getXBalancesQueryOptions, invalidateBalances, isBridgeMpcRelayRead, isBridgeNotDelivered, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, retryUnlessAuthFailure, runApprovalPlan, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveLeveragePositionFunding, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOracleCandles, useBackendOracleMarkets, useBackendOrderbook, useBackendUserIntents, useBalances, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiApproveAndBroadcast, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprovalStrategy, useBridgeApprove, useBridgeDetailedStatus, useBridgeWithApproval, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDetailedStatus, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEModes, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeveragePositionAccount, useLeveragePositionCollateral, useLeveragePositionFundingAllowance, useLeveragePositionInfo, useLeveragePositionPayoutAddress, useLeveragePositionPending, useLeveragePositions, useLeveragePositionsForUser, useLeverageYieldApiAllowance, useLeverageYieldApiApprove, useLeverageYieldApiApproveAndBroadcast, useLeverageYieldApiApr, useLeverageYieldApiAsset, useLeverageYieldApiCancelIntent, useLeverageYieldApiCreateDepositIntent, useLeverageYieldApiCreateWithdrawIntent, useLeverageYieldApiDeadline, useLeverageYieldApiDepositQuote, useLeverageYieldApiEffectiveApr, useLeverageYieldApiEstimateGas, useLeverageYieldApiFilledIntent, useLeverageYieldApiIntent, useLeverageYieldApiIntentExtraData, useLeverageYieldApiIntentHash, useLeverageYieldApiIntentPacket, useLeverageYieldApiLsdApr, useLeverageYieldApiMaxWithdraw, useLeverageYieldApiPartnerFee, useLeverageYieldApiPosition, useLeverageYieldApiPreviewDeposit, useLeverageYieldApiPreviewRedeem, useLeverageYieldApiPreviewWithdraw, useLeverageYieldApiShareBalance, useLeverageYieldApiSolverFee, useLeverageYieldApiStatus, useLeverageYieldApiSubmitIntent, useLeverageYieldApiSubmitTx, useLeverageYieldApiSubmitTxStatus, useLeverageYieldApiTotalAssets, useLeverageYieldApiVault, useLeverageYieldApiVaults, useLeverageYieldApiWithdrawQuote, useLeverageYieldApprovalStrategy, useLeverageYieldDeposit, useLeverageYieldDetailedStatus, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldQuote, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldVaultSwapWithApproval, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, useOpenLeveragePosition, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useRunLeveragePositionOperation, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSubmitLeveragePositionIntent, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprovalStrategy, useSwapApprove, useSwapLifecycle, useSwapWithApproval, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiApproveAndBroadcast, useSwapsApiBroadcastWithApproval, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "2.
|
|
8
|
+
"version": "2.4.0-rc.1",
|
|
9
9
|
"description": "React hooks for building dApps on the SODAX cross-chain DeFi platform",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"sodax",
|
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
"react",
|
|
14
14
|
"react-query",
|
|
15
15
|
"hooks",
|
|
16
|
-
"defi"
|
|
16
|
+
"defi",
|
|
17
|
+
"cross-chain",
|
|
18
|
+
"swap",
|
|
19
|
+
"web3",
|
|
20
|
+
"sdk"
|
|
17
21
|
],
|
|
18
|
-
"homepage": "https://
|
|
22
|
+
"homepage": "https://docs.sodax.com/developers/packages/experience/dapp-kit",
|
|
19
23
|
"bugs": {
|
|
20
24
|
"url": "https://github.com/gosodax/sodax-sdks/issues"
|
|
21
25
|
},
|
|
@@ -30,11 +34,12 @@
|
|
|
30
34
|
],
|
|
31
35
|
"repository": {
|
|
32
36
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/gosodax/sodax-sdks"
|
|
37
|
+
"url": "git+https://github.com/gosodax/sodax-sdks.git",
|
|
38
|
+
"directory": "packages/dapp-kit"
|
|
34
39
|
},
|
|
35
40
|
"dependencies": {
|
|
36
41
|
"viem": "2.29.2",
|
|
37
|
-
"@sodax/sdk": "2.
|
|
42
|
+
"@sodax/sdk": "2.4.0-rc.1"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
40
45
|
"@arethetypeswrong/cli": "0.17.4",
|
|
@@ -10,6 +10,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
10
10
|
import {
|
|
11
11
|
advanceNotFoundStreak,
|
|
12
12
|
INITIAL_NOT_FOUND_STREAK,
|
|
13
|
+
MAX_MPC_RELAY_NOT_FOUND_POLLS,
|
|
13
14
|
MAX_NOT_FOUND_POLLS,
|
|
14
15
|
STATUS_POLL_MS,
|
|
15
16
|
} from '../shared/notFoundStreak.js';
|
|
@@ -20,9 +21,10 @@ import {
|
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Guards the polling-stop invariant for `useBridgeDetailedStatus.refetchInterval`: stop on a
|
|
23
|
-
* terminal or abandoned backend record, on any relay packet
|
|
24
|
-
* key, and on an exhausted not-delivered budget — but keep polling
|
|
25
|
-
* pure function because dapp-kit's vitest runs in the `node`
|
|
24
|
+
* terminal or abandoned backend record, on any relay packet or MPC deposit record (always
|
|
25
|
+
* terminal), on a rejected API key, and on an exhausted not-delivered budget — but keep polling
|
|
26
|
+
* through an outage. Tested as a pure function because dapp-kit's vitest runs in the `node`
|
|
27
|
+
* environment.
|
|
26
28
|
*/
|
|
27
29
|
const KEY_A = 'arb:0xaaa';
|
|
28
30
|
const KEY_B = 'arb:0xbbb';
|
|
@@ -52,6 +54,19 @@ const packet: PacketData = {
|
|
|
52
54
|
|
|
53
55
|
const relayed: Read = { ok: true, value: { source: 'relay', data: packet } };
|
|
54
56
|
|
|
57
|
+
const minted: Read = {
|
|
58
|
+
ok: true,
|
|
59
|
+
value: {
|
|
60
|
+
source: 'mpcRelay',
|
|
61
|
+
data: {
|
|
62
|
+
depositId: 'id',
|
|
63
|
+
status: 'minted',
|
|
64
|
+
createdAt: 0,
|
|
65
|
+
txs: { hubMint: { chain: 'sonic', hash: '0xdst', ts: 0 } },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
55
70
|
const lookupFailed = (context: Record<string, unknown>): Read => ({
|
|
56
71
|
ok: false,
|
|
57
72
|
error: new SodaxError('LOOKUP_FAILED', 'no source could answer', {
|
|
@@ -61,6 +76,7 @@ const lookupFailed = (context: Record<string, unknown>): Read => ({
|
|
|
61
76
|
});
|
|
62
77
|
|
|
63
78
|
const notDelivered = lookupFailed({ reason: DETAILED_STATUS_NOT_DELIVERED });
|
|
79
|
+
const mpcRelayNotDelivered = lookupFailed({ reason: DETAILED_STATUS_NOT_DELIVERED, mpcRelay: true });
|
|
64
80
|
const outage = lookupFailed({});
|
|
65
81
|
const rejectedKey = lookupFailed({ status: 401 });
|
|
66
82
|
|
|
@@ -93,6 +109,10 @@ describe('getBridgeDetailedStatusRefetchInterval', () => {
|
|
|
93
109
|
expect(getBridgeDetailedStatusRefetchInterval(relayed, 0)).toBe(false);
|
|
94
110
|
});
|
|
95
111
|
|
|
112
|
+
it('stops on a minted MPC-relay deposit record — that arm is terminal on arrival too', () => {
|
|
113
|
+
expect(getBridgeDetailedStatusRefetchInterval(minted, 0)).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
|
|
96
116
|
it('stops on a rejected API key, at the first read', () => {
|
|
97
117
|
expect(getBridgeDetailedStatusRefetchInterval(rejectedKey, 0)).toBe(false);
|
|
98
118
|
});
|
|
@@ -102,6 +122,11 @@ describe('getBridgeDetailedStatusRefetchInterval', () => {
|
|
|
102
122
|
expect(getBridgeDetailedStatusRefetchInterval(notDelivered, MAX_NOT_FOUND_POLLS)).toBe(false);
|
|
103
123
|
});
|
|
104
124
|
|
|
125
|
+
it('gives a miss on a bridge with an MPC-relay end the longer budget', () => {
|
|
126
|
+
expect(getBridgeDetailedStatusRefetchInterval(mpcRelayNotDelivered, MAX_NOT_FOUND_POLLS)).toBe(STATUS_POLL_MS);
|
|
127
|
+
expect(getBridgeDetailedStatusRefetchInterval(mpcRelayNotDelivered, MAX_MPC_RELAY_NOT_FOUND_POLLS)).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
105
130
|
it('keeps polling an outage forever — that is how the read recovers', () => {
|
|
106
131
|
expect(getBridgeDetailedStatusRefetchInterval(outage, MAX_NOT_FOUND_POLLS)).toBe(STATUS_POLL_MS);
|
|
107
132
|
});
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type DetailedBridgeStatus,
|
|
6
6
|
type Result,
|
|
7
7
|
} from '@sodax/sdk';
|
|
8
|
-
import { MAX_NOT_FOUND_POLLS, STATUS_POLL_MS } from '../shared/notFoundStreak.js';
|
|
8
|
+
import { MAX_MPC_RELAY_NOT_FOUND_POLLS, MAX_NOT_FOUND_POLLS, STATUS_POLL_MS } from '../shared/notFoundStreak.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Structural mirror of `useBridgeDetailedStatus`'s data type. Declared locally rather than imported
|
|
@@ -23,13 +23,19 @@ export function isBridgeNotDelivered(data: DetailedBridgeStatusRead): boolean {
|
|
|
23
23
|
return data !== undefined && !data.ok && data.error?.context?.reason === DETAILED_STATUS_NOT_DELIVERED;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/** A read the SDK tags `context.mpcRelay`: a bridge with an MPC-relay end, which gets the longer budget. */
|
|
27
|
+
export function isBridgeMpcRelayRead(data: DetailedBridgeStatusRead): boolean {
|
|
28
|
+
return data !== undefined && !data.ok && data.error?.context?.mpcRelay === true;
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
/**
|
|
27
32
|
* Polling interval for `useBridgeDetailedStatus`.
|
|
28
33
|
*
|
|
29
34
|
* Unlike the swap analog there is no in-flight second arm to wait on: the relay arm only ever
|
|
30
|
-
* carries a matched `executed` packet,
|
|
31
|
-
* terminal
|
|
32
|
-
* run `MAX_NOT_FOUND_POLLS` times in a row
|
|
35
|
+
* carries a matched `executed` packet, and the MPC-relay arm a minted deposit record, so both are
|
|
36
|
+
* terminal on arrival. That leaves three stops — a terminal or abandoned backend record, a rejected
|
|
37
|
+
* API key, and the ambiguous relay miss once it has run `MAX_NOT_FOUND_POLLS` times in a row, or
|
|
38
|
+
* `MAX_MPC_RELAY_NOT_FOUND_POLLS` when the SDK tags it `context.mpcRelay`.
|
|
33
39
|
*
|
|
34
40
|
* Kept in its own pure module (no React/context imports) so it is unit-testable in dapp-kit's `node`
|
|
35
41
|
* test environment — importing the hook itself pulls in `useSodaxContext`.
|
|
@@ -39,14 +45,17 @@ export function getBridgeDetailedStatusRefetchInterval(
|
|
|
39
45
|
consecutiveNotFound: number,
|
|
40
46
|
): number | false {
|
|
41
47
|
if (data?.ok) {
|
|
42
|
-
if (data.value.source
|
|
48
|
+
if (data.value.source !== 'backend') return false;
|
|
43
49
|
// The two terminal states of the bridge wire contract, plus a record the backend abandoned
|
|
44
50
|
// while its status was still non-terminal.
|
|
45
51
|
const { status, abandonedAt } = data.value.data;
|
|
46
52
|
return status === 'executed' || status === 'failed' || abandonedAt ? false : STATUS_POLL_MS;
|
|
47
53
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
if (data && !data.ok) {
|
|
55
|
+
// A rejected key is terminal — only a corrected key changes the answer, so stop asking.
|
|
56
|
+
if (isAuthFailure(data.error)) return false;
|
|
57
|
+
const budget = isBridgeMpcRelayRead(data) ? MAX_MPC_RELAY_NOT_FOUND_POLLS : MAX_NOT_FOUND_POLLS;
|
|
58
|
+
if (isBridgeNotDelivered(data) && consecutiveNotFound >= budget) return false;
|
|
59
|
+
}
|
|
51
60
|
return STATUS_POLL_MS;
|
|
52
61
|
}
|
|
@@ -6,6 +6,7 @@ import { useQueryClient } from '@tanstack/react-query';
|
|
|
6
6
|
import type { MutationHookParams } from '../shared/types.js';
|
|
7
7
|
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
8
8
|
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
9
|
+
import { retryBeforeSubmission } from '../shared/retryBeforeSubmission.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Mutation variables for {@link useBridge}. Generic over `K extends SpokeChainKey` (defaults to
|
|
@@ -29,6 +30,11 @@ export function useBridge<K extends SpokeChainKey = SpokeChainKey>({
|
|
|
29
30
|
return useSafeMutation<TxHashPair, Error, UseBridgeVars<K>>({
|
|
30
31
|
mutationKey: ['bridge'],
|
|
31
32
|
...mutationOptions,
|
|
33
|
+
retry: retryBeforeSubmission(
|
|
34
|
+
mutationOptions?.retry ??
|
|
35
|
+
queryClient.getMutationDefaults?.(mutationOptions?.mutationKey ?? ['bridge'])?.retry ??
|
|
36
|
+
queryClient.getDefaultOptions?.().mutations?.retry,
|
|
37
|
+
),
|
|
32
38
|
mutationFn: async vars => unwrapResult(await sodax.bridge.bridge({ ...vars, raw: false })),
|
|
33
39
|
onSuccess: async (data, vars, ctx) => {
|
|
34
40
|
invalidateBalances(queryClient, vars.params.srcChainKey, vars.params.dstChainKey);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { MAX_NOT_FOUND_POLLS, STATUS_POLL_MS } from '../shared/notFoundStreak.js';
|
|
2
|
+
import { MAX_MPC_RELAY_NOT_FOUND_POLLS, MAX_NOT_FOUND_POLLS, STATUS_POLL_MS } from '../shared/notFoundStreak.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Pins the WIRING the pure-policy test cannot see: the hook must pass the read into the policy and
|
|
@@ -73,12 +73,36 @@ describe('useBridgeDetailedStatus wiring', () => {
|
|
|
73
73
|
);
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
+
it('keys and reads by the destination too, which decides when a Tron-source bridge is delivered', async () => {
|
|
77
|
+
refCursor = 0;
|
|
78
|
+
useBridgeDetailedStatus({ params: { srcChainKey: 'tron', srcTxHash: SRC_TX, dstChainKey: SRC_CHAIN } });
|
|
79
|
+
expect(captured.queryKey).toEqual(['bridge', 'detailedStatus', 'tron', SRC_TX, SRC_CHAIN]);
|
|
80
|
+
await captured.queryFn();
|
|
81
|
+
expect(getDetailedStatus).toHaveBeenLastCalledWith(
|
|
82
|
+
{ srcChainKey: 'tron', srcTxHash: SRC_TX, dstChainKey: SRC_CHAIN },
|
|
83
|
+
undefined,
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
76
87
|
it('feeds the read into the policy, so a terminal answer stops the poll', () => {
|
|
77
88
|
render();
|
|
78
89
|
const relayed = { ok: true, value: { source: 'relay', data: { dst_tx_hash: '0xdst' } } };
|
|
79
90
|
expect(captured.refetchInterval({ state: { data: relayed, dataUpdateCount: 1 } })).toBe(false);
|
|
80
91
|
});
|
|
81
92
|
|
|
93
|
+
it('gives the leg after the hub mint a budget of its own', () => {
|
|
94
|
+
refSlots.length = 0;
|
|
95
|
+
render();
|
|
96
|
+
for (let update = 1; update <= MAX_NOT_FOUND_POLLS - 1; update++) {
|
|
97
|
+
captured.refetchInterval({ state: { data: notDeliveredRead, dataUpdateCount: update } });
|
|
98
|
+
}
|
|
99
|
+
const onwardMiss = {
|
|
100
|
+
ok: false,
|
|
101
|
+
error: { code: 'LOOKUP_FAILED', context: { reason: 'relay_not_delivered', hubTxHash: '0xhub' } },
|
|
102
|
+
};
|
|
103
|
+
expect(captured.refetchInterval({ state: { data: onwardMiss, dataUpdateCount: 40 } })).toBe(STATUS_POLL_MS);
|
|
104
|
+
});
|
|
105
|
+
|
|
82
106
|
it('advances the not-delivered budget once per update, and stops when it is spent', () => {
|
|
83
107
|
refSlots.length = 0;
|
|
84
108
|
render();
|
|
@@ -90,4 +114,35 @@ describe('useBridgeDetailedStatus wiring', () => {
|
|
|
90
114
|
expect(captured.refetchInterval({ state: { data: notDeliveredRead, dataUpdateCount: 39 } })).toBe(STATUS_POLL_MS);
|
|
91
115
|
expect(captured.refetchInterval({ state: { data: notDeliveredRead, dataUpdateCount: 40 } })).toBe(false);
|
|
92
116
|
});
|
|
117
|
+
|
|
118
|
+
it('gives a miss the SDK tags as an MPC-relay bridge the longer budget', () => {
|
|
119
|
+
refSlots.length = 0;
|
|
120
|
+
render();
|
|
121
|
+
const mpcRelayMiss = {
|
|
122
|
+
ok: false,
|
|
123
|
+
error: { code: 'LOOKUP_FAILED', context: { reason: 'relay_not_delivered', mpcRelay: true } },
|
|
124
|
+
};
|
|
125
|
+
for (let update = 1; update < MAX_MPC_RELAY_NOT_FOUND_POLLS; update++) {
|
|
126
|
+
expect(captured.refetchInterval({ state: { data: mpcRelayMiss, dataUpdateCount: update } })).toBe(STATUS_POLL_MS);
|
|
127
|
+
}
|
|
128
|
+
const last = { state: { data: mpcRelayMiss, dataUpdateCount: MAX_MPC_RELAY_NOT_FOUND_POLLS } };
|
|
129
|
+
expect(captured.refetchInterval(last)).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('does not let one untagged miss cut an MPC-relay streak to the short budget', () => {
|
|
133
|
+
refSlots.length = 0;
|
|
134
|
+
render();
|
|
135
|
+
const mpcRelayMiss = {
|
|
136
|
+
ok: false,
|
|
137
|
+
error: { code: 'LOOKUP_FAILED', context: { reason: 'relay_not_delivered', mpcRelay: true } },
|
|
138
|
+
};
|
|
139
|
+
let update = 0;
|
|
140
|
+
while (update < MAX_NOT_FOUND_POLLS + 5) {
|
|
141
|
+
update += 1;
|
|
142
|
+
captured.refetchInterval({ state: { data: mpcRelayMiss, dataUpdateCount: update } });
|
|
143
|
+
}
|
|
144
|
+
expect(captured.refetchInterval({ state: { data: notDeliveredRead, dataUpdateCount: update + 1 } })).toBe(
|
|
145
|
+
STATUS_POLL_MS,
|
|
146
|
+
);
|
|
147
|
+
});
|
|
93
148
|
});
|