@sodax/dapp-kit 2.0.0-rc.18 → 2.0.0-rc.19

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.
Files changed (34) hide show
  1. package/README.md +12 -3
  2. package/dist/index.d.ts +371 -46
  3. package/dist/index.mjs +370 -46
  4. package/package.json +2 -2
  5. package/src/hooks/_mutationContract.test.ts +6 -1
  6. package/src/hooks/backend/index.ts +1 -5
  7. package/src/hooks/bitcoin/index.ts +1 -0
  8. package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +45 -0
  9. package/src/hooks/index.ts +1 -0
  10. package/src/hooks/swapsApi/index.ts +41 -0
  11. package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +24 -0
  12. package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +11 -0
  13. package/src/hooks/swapsApi/useSwapsApiAllowance.ts +40 -0
  14. package/src/hooks/swapsApi/useSwapsApiApprove.ts +42 -0
  15. package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +41 -0
  16. package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +41 -0
  17. package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +41 -0
  18. package/src/hooks/swapsApi/useSwapsApiDeadline.ts +36 -0
  19. package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +40 -0
  20. package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +41 -0
  21. package/src/hooks/swapsApi/useSwapsApiIntent.ts +40 -0
  22. package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +41 -0
  23. package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +40 -0
  24. package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +43 -0
  25. package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +40 -0
  26. package/src/hooks/swapsApi/useSwapsApiQuote.ts +55 -0
  27. package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +40 -0
  28. package/src/hooks/swapsApi/useSwapsApiStatus.ts +45 -0
  29. package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +43 -0
  30. package/src/hooks/{backend/useBackendSubmitSwapTx.ts → swapsApi/useSwapsApiSubmitTx.ts} +16 -17
  31. package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +55 -0
  32. package/src/hooks/swapsApi/useSwapsApiTokens.ts +34 -0
  33. package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +40 -0
  34. package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +0 -59
package/dist/index.mjs CHANGED
@@ -507,6 +507,19 @@ function useTradingWalletBalance({
507
507
  ...queryOptions
508
508
  });
509
509
  }
510
+ var INERT = { wallet: void 0, tradingBalance: void 0 };
511
+ function useBitcoinTradingSetup({
512
+ chainKey,
513
+ walletProvider,
514
+ address
515
+ }) {
516
+ const isBitcoin = chainKey === ChainKeys.BITCOIN_MAINNET;
517
+ const wallet = isBitcoin ? walletProvider : void 0;
518
+ const { tradingAddress } = useTradingWallet(isBitcoin ? address : void 0);
519
+ const { data: tradingBalance } = useTradingWalletBalance({ params: { walletProvider: wallet, tradingAddress } });
520
+ if (!isBitcoin) return INERT;
521
+ return { wallet, tradingBalance };
522
+ }
510
523
  function useExpiredUtxos({
511
524
  params,
512
525
  queryOptions
@@ -1075,51 +1088,6 @@ var useBackendUserIntents = ({
1075
1088
  ...queryOptions
1076
1089
  });
1077
1090
  };
1078
-
1079
- // src/hooks/backend/useBackendSubmitSwapTx.ts
1080
- var useBackendSubmitSwapTx = ({
1081
- mutationOptions
1082
- } = {}) => {
1083
- const { sodax } = useSodaxContext();
1084
- return useSafeMutation({
1085
- mutationKey: ["backend", "submitSwapTx"],
1086
- retry: 3,
1087
- ...mutationOptions,
1088
- mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.backendApi.submitSwapTx(request, apiConfig))
1089
- });
1090
- };
1091
- var useBackendSubmitSwapTxStatus = ({
1092
- params,
1093
- queryOptions
1094
- } = {}) => {
1095
- const { sodax } = useSodaxContext();
1096
- const txHash = params?.txHash;
1097
- const srcChainKey = params?.srcChainKey;
1098
- const apiConfig = params?.apiConfig;
1099
- return useQuery({
1100
- queryKey: ["backend", "submitSwapTx", "status", txHash, srcChainKey],
1101
- queryFn: async () => {
1102
- if (!txHash) return void 0;
1103
- return unwrapResult(
1104
- await sodax.backendApi.getSubmitSwapTxStatus(
1105
- {
1106
- txHash,
1107
- srcChainKey
1108
- },
1109
- apiConfig
1110
- )
1111
- );
1112
- },
1113
- enabled: !!txHash && txHash.length > 0,
1114
- retry: 3,
1115
- refetchInterval: (query) => {
1116
- const status = query.state.data?.data?.status;
1117
- if (status === "executed" || status === "failed") return false;
1118
- return 1e3;
1119
- },
1120
- ...queryOptions
1121
- });
1122
- };
1123
1091
  var useBackendOrderbook = ({
1124
1092
  params,
1125
1093
  queryOptions
@@ -1261,6 +1229,362 @@ var useBackendAllMoneyMarketBorrowers = ({
1261
1229
  ...queryOptions
1262
1230
  });
1263
1231
  };
1232
+ var useSwapsApiTokens = ({
1233
+ params,
1234
+ queryOptions
1235
+ } = {}) => {
1236
+ const { sodax } = useSodaxContext();
1237
+ const apiConfig = params?.apiConfig;
1238
+ return useQuery({
1239
+ queryKey: ["swapsApi", "tokens"],
1240
+ queryFn: async () => unwrapResult(await sodax.api.swaps.getTokens(apiConfig)),
1241
+ retry: 3,
1242
+ ...queryOptions
1243
+ });
1244
+ };
1245
+ var useSwapsApiTokensByChain = ({
1246
+ params,
1247
+ queryOptions
1248
+ } = {}) => {
1249
+ const { sodax } = useSodaxContext();
1250
+ const chainKey = params?.chainKey;
1251
+ const apiConfig = params?.apiConfig;
1252
+ return useQuery({
1253
+ queryKey: ["swapsApi", "tokens", chainKey],
1254
+ queryFn: async () => {
1255
+ if (!chainKey) return void 0;
1256
+ return unwrapResult(await sodax.api.swaps.getTokensByChain(chainKey, apiConfig));
1257
+ },
1258
+ enabled: !!chainKey && chainKey.length > 0,
1259
+ retry: 3,
1260
+ ...queryOptions
1261
+ });
1262
+ };
1263
+ var useSwapsApiQuote = ({
1264
+ params,
1265
+ queryOptions
1266
+ } = {}) => {
1267
+ const { sodax } = useSodaxContext();
1268
+ const body = params?.body;
1269
+ const query = params?.query;
1270
+ const apiConfig = params?.apiConfig;
1271
+ return useQuery({
1272
+ // Hash the whole request body so every quote input — including partnerFee and the other
1273
+ // SwapExtrasV2 fields — is a cache dimension; a partnerFee change alters the quote and must
1274
+ // miss the cache. QuoteRequestV2 is bigint-free (compile-time guaranteed), so React Query's
1275
+ // default key hashing handles the object directly.
1276
+ queryKey: ["swapsApi", "quote", body, query?.includeTxData ?? false],
1277
+ queryFn: async () => {
1278
+ if (!body) return void 0;
1279
+ return unwrapResult(await sodax.api.swaps.getQuote(body, query, apiConfig));
1280
+ },
1281
+ enabled: !!body,
1282
+ retry: 3,
1283
+ ...queryOptions
1284
+ });
1285
+ };
1286
+ var useSwapsApiDeadline = ({
1287
+ params,
1288
+ queryOptions
1289
+ } = {}) => {
1290
+ const { sodax } = useSodaxContext();
1291
+ const query = params?.query;
1292
+ const apiConfig = params?.apiConfig;
1293
+ return useQuery({
1294
+ queryKey: ["swapsApi", "deadline", query?.offsetSeconds ?? null],
1295
+ queryFn: async () => unwrapResult(await sodax.api.swaps.getDeadline(query, apiConfig)),
1296
+ retry: 3,
1297
+ ...queryOptions
1298
+ });
1299
+ };
1300
+ var useSwapsApiAllowance = ({
1301
+ params,
1302
+ queryOptions
1303
+ } = {}) => {
1304
+ const { sodax } = useSodaxContext();
1305
+ const body = params?.body;
1306
+ const apiConfig = params?.apiConfig;
1307
+ return useQuery({
1308
+ queryKey: ["swapsApi", "allowance", body?.srcChainKey, body?.inputToken, body?.inputAmount, body?.srcAddress],
1309
+ queryFn: async () => {
1310
+ if (!body) return void 0;
1311
+ return unwrapResult(await sodax.api.swaps.checkAllowance(body, apiConfig));
1312
+ },
1313
+ enabled: !!body,
1314
+ retry: 3,
1315
+ ...queryOptions
1316
+ });
1317
+ };
1318
+
1319
+ // src/hooks/swapsApi/useSwapsApiApprove.ts
1320
+ var useSwapsApiApprove = ({
1321
+ mutationOptions
1322
+ } = {}) => {
1323
+ const { sodax } = useSodaxContext();
1324
+ return useSafeMutation({
1325
+ mutationKey: ["swapsApi", "approve"],
1326
+ retry: 3,
1327
+ ...mutationOptions,
1328
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.approve(body, apiConfig))
1329
+ });
1330
+ };
1331
+
1332
+ // src/hooks/swapsApi/useSwapsApiCreateIntent.ts
1333
+ var useSwapsApiCreateIntent = ({
1334
+ mutationOptions
1335
+ } = {}) => {
1336
+ const { sodax } = useSodaxContext();
1337
+ return useSafeMutation({
1338
+ mutationKey: ["swapsApi", "createIntent"],
1339
+ retry: 3,
1340
+ ...mutationOptions,
1341
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.createIntent(body, apiConfig))
1342
+ });
1343
+ };
1344
+
1345
+ // src/hooks/swapsApi/useSwapsApiSubmitIntent.ts
1346
+ var useSwapsApiSubmitIntent = ({
1347
+ mutationOptions
1348
+ } = {}) => {
1349
+ const { sodax } = useSodaxContext();
1350
+ return useSafeMutation({
1351
+ mutationKey: ["swapsApi", "submitIntent"],
1352
+ retry: false,
1353
+ ...mutationOptions,
1354
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.submitIntent(body, apiConfig))
1355
+ });
1356
+ };
1357
+
1358
+ // src/hooks/swapsApi/isTerminalSwapIntentStatus.ts
1359
+ var isTerminalSwapIntentStatus = (status) => status === 3 || status === 4;
1360
+
1361
+ // src/hooks/swapsApi/useSwapsApiStatus.ts
1362
+ var useSwapsApiStatus = ({
1363
+ params,
1364
+ queryOptions
1365
+ } = {}) => {
1366
+ const { sodax } = useSodaxContext();
1367
+ const intentTxHash = params?.intentTxHash;
1368
+ const apiConfig = params?.apiConfig;
1369
+ return useQuery({
1370
+ queryKey: ["swapsApi", "status", intentTxHash],
1371
+ queryFn: async () => {
1372
+ if (!intentTxHash) return void 0;
1373
+ return unwrapResult(await sodax.api.swaps.getStatus({ intentTxHash }, apiConfig));
1374
+ },
1375
+ enabled: !!intentTxHash && intentTxHash.length > 0,
1376
+ retry: 3,
1377
+ refetchInterval: (query) => isTerminalSwapIntentStatus(query.state.data?.status) ? false : 1e3,
1378
+ ...queryOptions
1379
+ });
1380
+ };
1381
+
1382
+ // src/hooks/swapsApi/useSwapsApiCancelIntent.ts
1383
+ var useSwapsApiCancelIntent = ({
1384
+ mutationOptions
1385
+ } = {}) => {
1386
+ const { sodax } = useSodaxContext();
1387
+ return useSafeMutation({
1388
+ mutationKey: ["swapsApi", "cancelIntent"],
1389
+ retry: 3,
1390
+ ...mutationOptions,
1391
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.cancelIntent(body, apiConfig))
1392
+ });
1393
+ };
1394
+ var useSwapsApiIntentHash = ({
1395
+ params,
1396
+ queryOptions
1397
+ } = {}) => {
1398
+ const { sodax } = useSodaxContext();
1399
+ const intent = params?.intent;
1400
+ const apiConfig = params?.apiConfig;
1401
+ return useQuery({
1402
+ queryKey: ["swapsApi", "intentHash", intent?.intentId?.toString()],
1403
+ queryFn: async () => {
1404
+ if (!intent) return void 0;
1405
+ return unwrapResult(await sodax.api.swaps.getIntentHash({ intent }, apiConfig));
1406
+ },
1407
+ enabled: !!intent,
1408
+ retry: 3,
1409
+ ...queryOptions
1410
+ });
1411
+ };
1412
+ var useSwapsApiIntentPacket = ({
1413
+ params,
1414
+ queryOptions
1415
+ } = {}) => {
1416
+ const { sodax } = useSodaxContext();
1417
+ const body = params?.body;
1418
+ const apiConfig = params?.apiConfig;
1419
+ return useQuery({
1420
+ queryKey: ["swapsApi", "intentPacket", body?.chainId, body?.fillTxHash],
1421
+ queryFn: async () => {
1422
+ if (!body) return void 0;
1423
+ return unwrapResult(await sodax.api.swaps.getSolvedIntentPacket(body, apiConfig));
1424
+ },
1425
+ enabled: !!body,
1426
+ retry: 3,
1427
+ ...queryOptions
1428
+ });
1429
+ };
1430
+ var useSwapsApiIntentExtraData = ({
1431
+ params,
1432
+ queryOptions
1433
+ } = {}) => {
1434
+ const { sodax } = useSodaxContext();
1435
+ const body = params?.body;
1436
+ const apiConfig = params?.apiConfig;
1437
+ return useQuery({
1438
+ queryKey: ["swapsApi", "intentExtraData", body?.txHash ?? body?.intent?.intentId?.toString()],
1439
+ queryFn: async () => {
1440
+ if (!body || !body.txHash && !body.intent) return void 0;
1441
+ return unwrapResult(await sodax.api.swaps.getIntentSubmitTxExtraData(body, apiConfig));
1442
+ },
1443
+ enabled: !!body && (!!body.txHash || !!body.intent),
1444
+ retry: 3,
1445
+ ...queryOptions
1446
+ });
1447
+ };
1448
+ var useSwapsApiFilledIntent = ({
1449
+ params,
1450
+ queryOptions
1451
+ } = {}) => {
1452
+ const { sodax } = useSodaxContext();
1453
+ const txHash = params?.txHash;
1454
+ const apiConfig = params?.apiConfig;
1455
+ return useQuery({
1456
+ queryKey: ["swapsApi", "filledIntent", txHash],
1457
+ queryFn: async () => {
1458
+ if (!txHash) return void 0;
1459
+ return unwrapResult(await sodax.api.swaps.getFilledIntent(txHash, apiConfig));
1460
+ },
1461
+ enabled: !!txHash && txHash.length > 0,
1462
+ retry: 3,
1463
+ ...queryOptions
1464
+ });
1465
+ };
1466
+ var useSwapsApiIntent = ({
1467
+ params,
1468
+ queryOptions
1469
+ } = {}) => {
1470
+ const { sodax } = useSodaxContext();
1471
+ const txHash = params?.txHash;
1472
+ const apiConfig = params?.apiConfig;
1473
+ return useQuery({
1474
+ queryKey: ["swapsApi", "intent", txHash],
1475
+ queryFn: async () => {
1476
+ if (!txHash) return void 0;
1477
+ return unwrapResult(await sodax.api.swaps.getIntent(txHash, apiConfig));
1478
+ },
1479
+ enabled: !!txHash && txHash.length > 0,
1480
+ retry: 3,
1481
+ ...queryOptions
1482
+ });
1483
+ };
1484
+
1485
+ // src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts
1486
+ var useSwapsApiCreateLimitOrder = ({
1487
+ mutationOptions
1488
+ } = {}) => {
1489
+ const { sodax } = useSodaxContext();
1490
+ return useSafeMutation({
1491
+ mutationKey: ["swapsApi", "createLimitOrder"],
1492
+ retry: 3,
1493
+ ...mutationOptions,
1494
+ mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.createLimitOrderIntent(body, apiConfig))
1495
+ });
1496
+ };
1497
+ var useSwapsApiEstimateGas = ({
1498
+ params,
1499
+ queryOptions
1500
+ } = {}) => {
1501
+ const { sodax } = useSodaxContext();
1502
+ const body = params?.body;
1503
+ const apiConfig = params?.apiConfig;
1504
+ return useQuery({
1505
+ queryKey: ["swapsApi", "estimateGas", body?.chainKey, body?.tx],
1506
+ queryFn: async () => {
1507
+ if (!body) return void 0;
1508
+ return unwrapResult(await sodax.api.swaps.estimateGas(body, apiConfig));
1509
+ },
1510
+ enabled: !!body,
1511
+ retry: 3,
1512
+ ...queryOptions
1513
+ });
1514
+ };
1515
+ var useSwapsApiPartnerFee = ({
1516
+ params,
1517
+ queryOptions
1518
+ } = {}) => {
1519
+ const { sodax } = useSodaxContext();
1520
+ const amount = params?.amount;
1521
+ const apiConfig = params?.apiConfig;
1522
+ return useQuery({
1523
+ queryKey: ["swapsApi", "partnerFee", amount],
1524
+ queryFn: async () => {
1525
+ if (!amount) return void 0;
1526
+ return unwrapResult(await sodax.api.swaps.getPartnerFee({ amount }, apiConfig));
1527
+ },
1528
+ enabled: !!amount && amount.length > 0,
1529
+ retry: 3,
1530
+ ...queryOptions
1531
+ });
1532
+ };
1533
+ var useSwapsApiSolverFee = ({
1534
+ params,
1535
+ queryOptions
1536
+ } = {}) => {
1537
+ const { sodax } = useSodaxContext();
1538
+ const amount = params?.amount;
1539
+ const apiConfig = params?.apiConfig;
1540
+ return useQuery({
1541
+ queryKey: ["swapsApi", "solverFee", amount],
1542
+ queryFn: async () => {
1543
+ if (!amount) return void 0;
1544
+ return unwrapResult(await sodax.api.swaps.getSolverFee({ amount }, apiConfig));
1545
+ },
1546
+ enabled: !!amount && amount.length > 0,
1547
+ retry: 3,
1548
+ ...queryOptions
1549
+ });
1550
+ };
1551
+
1552
+ // src/hooks/swapsApi/useSwapsApiSubmitTx.ts
1553
+ var useSwapsApiSubmitTx = ({
1554
+ mutationOptions
1555
+ } = {}) => {
1556
+ const { sodax } = useSodaxContext();
1557
+ return useSafeMutation({
1558
+ mutationKey: ["swapsApi", "submitTx"],
1559
+ retry: 3,
1560
+ ...mutationOptions,
1561
+ mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.api.swaps.submitTx(request, apiConfig))
1562
+ });
1563
+ };
1564
+ var useSwapsApiSubmitTxStatus = ({
1565
+ params,
1566
+ queryOptions
1567
+ } = {}) => {
1568
+ const { sodax } = useSodaxContext();
1569
+ const txHash = params?.txHash;
1570
+ const srcChainKey = params?.srcChainKey;
1571
+ const apiConfig = params?.apiConfig;
1572
+ return useQuery({
1573
+ queryKey: ["swapsApi", "submitTx", "status", txHash, srcChainKey],
1574
+ queryFn: async () => {
1575
+ if (!txHash || !srcChainKey) return void 0;
1576
+ return unwrapResult(await sodax.api.swaps.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
1577
+ },
1578
+ enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
1579
+ retry: 3,
1580
+ refetchInterval: (query) => {
1581
+ const status = query.state.data?.data?.status;
1582
+ if (status === "executed" || status === "failed") return false;
1583
+ return 1e3;
1584
+ },
1585
+ ...queryOptions
1586
+ });
1587
+ };
1264
1588
  function useBridge({
1265
1589
  mutationOptions
1266
1590
  } = {}) {
@@ -2885,4 +3209,4 @@ function createSodaxQueryClient({
2885
3209
  });
2886
3210
  }
2887
3211
 
2888
- export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendSubmitSwapTx, useBackendSubmitSwapTxStatus, useBackendUserIntents, useBitcoinBalance, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
3212
+ export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, isTerminalSwapIntentStatus, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, 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.0.0-rc.18",
8
+ "version": "2.0.0-rc.19",
9
9
  "description": "React hooks for building dApps on the SODAX cross-chain DeFi platform",
10
10
  "keywords": [
11
11
  "sodax",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "viem": "2.29.2",
37
- "@sodax/sdk": "2.0.0-rc.18"
37
+ "@sodax/sdk": "2.0.0-rc.19"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@arethetypeswrong/cli": "0.17.4",
@@ -13,7 +13,6 @@ const HOOKS_DIR = resolve(fileURLToPath(import.meta.url), '..');
13
13
  * registration so the contract is enforced from day one.
14
14
  */
15
15
  const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
16
- { path: 'backend/useBackendSubmitSwapTx.ts' },
17
16
  { path: 'bitcoin/useEnsureRadfiAccessToken.ts', nativeThrow: true },
18
17
  { path: 'bitcoin/useFundTradingWallet.ts', nativeThrow: true },
19
18
  { path: 'bitcoin/useRadfiAuth.ts', nativeThrow: true },
@@ -62,6 +61,12 @@ const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
62
61
  { path: 'swap/useCreateLimitOrder.ts' },
63
62
  { path: 'swap/useSwap.ts' },
64
63
  { path: 'swap/useSwapApprove.ts' },
64
+ { path: 'swapsApi/useSwapsApiApprove.ts' },
65
+ { path: 'swapsApi/useSwapsApiCancelIntent.ts' },
66
+ { path: 'swapsApi/useSwapsApiCreateIntent.ts' },
67
+ { path: 'swapsApi/useSwapsApiCreateLimitOrder.ts' },
68
+ { path: 'swapsApi/useSwapsApiSubmitIntent.ts' },
69
+ { path: 'swapsApi/useSwapsApiSubmitTx.ts' },
65
70
  ];
66
71
 
67
72
  describe.each(HOOKS)('mutation hook contract: $path', ({ path, nativeThrow }) => {
@@ -12,10 +12,6 @@ export { useBackendIntentByTxHash } from './useBackendIntentByTxHash.js';
12
12
  export { useBackendIntentByHash } from './useBackendIntentByHash.js';
13
13
  export { useBackendUserIntents } from './useBackendUserIntents.js';
14
14
 
15
- // Swap submit-tx hooks
16
- export { useBackendSubmitSwapTx } from './useBackendSubmitSwapTx.js';
17
- export { useBackendSubmitSwapTxStatus } from './useBackendSubmitSwapTxStatus.js';
18
-
19
15
  // Solver hooks
20
16
  export { useBackendOrderbook } from './useBackendOrderbook.js';
21
17
 
@@ -26,4 +22,4 @@ export { useBackendMoneyMarketAsset } from './useBackendMoneyMarketAsset.js';
26
22
  export { useBackendMoneyMarketAssetBorrowers } from './useBackendMoneyMarketAssetBorrowers.js';
27
23
  export { useBackendMoneyMarketAssetSuppliers } from './useBackendMoneyMarketAssetSuppliers.js';
28
24
  export { useBackendAllMoneyMarketBorrowers } from './useBackendAllMoneyMarketBorrowers.js';
29
- export * from './types.js';
25
+ export * from './types.js';
@@ -5,6 +5,7 @@ export * from './useFundTradingWallet.js';
5
5
  export * from './useBitcoinBalance.js';
6
6
  export * from './useTradingWallet.js';
7
7
  export * from './useTradingWalletBalance.js';
8
+ export * from './useBitcoinTradingSetup.js';
8
9
  export * from './useExpiredUtxos.js';
9
10
  export * from './useRenewUtxos.js';
10
11
  export * from './useRadfiWithdraw.js';
@@ -0,0 +1,45 @@
1
+ import {
2
+ ChainKeys,
3
+ type IBitcoinWalletProvider,
4
+ type IWalletProvider,
5
+ type RadfiWalletBalance,
6
+ type SpokeChainKey,
7
+ } from '@sodax/sdk';
8
+ import { useTradingWallet } from './useTradingWallet.js';
9
+ import { useTradingWalletBalance } from './useTradingWalletBalance.js';
10
+
11
+ export interface UseBitcoinTradingSetupParams {
12
+ chainKey: SpokeChainKey;
13
+ /** This side's wallet provider + account, e.g. `useWalletProvider` / `useXAccount`. */
14
+ walletProvider: IWalletProvider | undefined;
15
+ address: string | undefined;
16
+ }
17
+
18
+ export interface BitcoinTradingSetup {
19
+ wallet: IBitcoinWalletProvider | undefined;
20
+ tradingBalance: RadfiWalletBalance | undefined;
21
+ }
22
+
23
+ const INERT: BitcoinTradingSetup = { wallet: undefined, tradingBalance: undefined };
24
+
25
+ /**
26
+ * Bitcoin trading-wallet setup for one side of a cross-chain flow: Bitcoin funds move through a
27
+ * Bound Exchange (Radfi) trading wallet, not the personal wallet. Inert (no work) unless `chainKey`
28
+ * is Bitcoin. Wallet-layer inputs are passed in — this package doesn't depend on wallet-sdk-react.
29
+ */
30
+ export function useBitcoinTradingSetup({
31
+ chainKey,
32
+ walletProvider,
33
+ address,
34
+ }: UseBitcoinTradingSetupParams): BitcoinTradingSetup {
35
+ const isBitcoin = chainKey === ChainKeys.BITCOIN_MAINNET;
36
+ // Safe: when this side is Bitcoin its provider IS the Bitcoin one (TS can't relate chainKey to provider type).
37
+ const wallet = isBitcoin ? (walletProvider as IBitcoinWalletProvider | undefined) : undefined;
38
+
39
+ // Hooks run every render; undefined inputs keep the Bound balance query disabled when not Bitcoin.
40
+ const { tradingAddress } = useTradingWallet(isBitcoin ? address : undefined);
41
+ const { data: tradingBalance } = useTradingWalletBalance({ params: { walletProvider: wallet, tradingAddress } });
42
+
43
+ if (!isBitcoin) return INERT;
44
+ return { wallet, tradingBalance };
45
+ }
@@ -4,6 +4,7 @@ export * from './bitcoin/index.js';
4
4
  export * from './mm/index.js';
5
5
  export * from './swap/index.js';
6
6
  export * from './backend/index.js';
7
+ export * from './swapsApi/index.js';
7
8
  export * from './bridge/index.js';
8
9
  export * from './staking/index.js';
9
10
  export * from './partner/index.js';
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Swaps API v2 hooks — typed React Query wrappers over `sodax.api.swaps.*` (the SwapsApiService
3
+ * HTTP client). One hook per endpoint of the backend Swaps API v2.
4
+ *
5
+ * Distinct from the on-chain `swap/` hooks (`useQuote`/`useStatus`/`useSwap`/…), which drive the
6
+ * `SwapService` path (wallet → hub chain). These hooks call the backend HTTP API instead.
7
+ */
8
+
9
+ // Tokens
10
+ export * from './useSwapsApiTokens.js';
11
+ export * from './useSwapsApiTokensByChain.js';
12
+
13
+ // Quote · deadline
14
+ export * from './useSwapsApiQuote.js';
15
+ export * from './useSwapsApiDeadline.js';
16
+
17
+ // Allowance · approve · create intent
18
+ export * from './useSwapsApiAllowance.js';
19
+ export * from './useSwapsApiApprove.js';
20
+ export * from './useSwapsApiCreateIntent.js';
21
+
22
+ // Intent lifecycle: submit · status · cancel · hash · packet · extra-data · lookup
23
+ export * from './useSwapsApiSubmitIntent.js';
24
+ export * from './useSwapsApiStatus.js';
25
+ export * from './isTerminalSwapIntentStatus.js'; // terminal-status predicate (drives the status hook's polling)
26
+ export * from './useSwapsApiCancelIntent.js';
27
+ export * from './useSwapsApiIntentHash.js';
28
+ export * from './useSwapsApiIntentPacket.js';
29
+ export * from './useSwapsApiIntentExtraData.js';
30
+ export * from './useSwapsApiFilledIntent.js';
31
+ export * from './useSwapsApiIntent.js';
32
+
33
+ // Limit orders · gas · fees
34
+ export * from './useSwapsApiCreateLimitOrder.js';
35
+ export * from './useSwapsApiEstimateGas.js';
36
+ export * from './useSwapsApiPartnerFee.js';
37
+ export * from './useSwapsApiSolverFee.js';
38
+
39
+ // Submit-tx state machine
40
+ export * from './useSwapsApiSubmitTx.js';
41
+ export * from './useSwapsApiSubmitTxStatus.js';
@@ -0,0 +1,24 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { isTerminalSwapIntentStatus } from './isTerminalSwapIntentStatus.js';
3
+
4
+ /**
5
+ * Guards the polling-stop invariant for `useSwapsApiStatus.refetchInterval`: the hook keeps polling
6
+ * (1s) until the solver reports a terminal status, then stops. Tested as a pure predicate because
7
+ * dapp-kit's vitest runs in the `node` environment (no hook rendering) — see nearStorageGate.test.ts.
8
+ */
9
+ describe('isTerminalSwapIntentStatus', () => {
10
+ it('is terminal for SOLVED (3) and FAILED (4)', () => {
11
+ expect(isTerminalSwapIntentStatus(3)).toBe(true);
12
+ expect(isTerminalSwapIntentStatus(4)).toBe(true);
13
+ });
14
+
15
+ it('is non-terminal for NOT_FOUND (-1), NOT_STARTED_YET (1), and STARTED_NOT_FINISHED (2)', () => {
16
+ expect(isTerminalSwapIntentStatus(-1)).toBe(false);
17
+ expect(isTerminalSwapIntentStatus(1)).toBe(false);
18
+ expect(isTerminalSwapIntentStatus(2)).toBe(false);
19
+ });
20
+
21
+ it('is non-terminal when no status has arrived yet (undefined) — keeps polling', () => {
22
+ expect(isTerminalSwapIntentStatus(undefined)).toBe(false);
23
+ });
24
+ });
@@ -0,0 +1,11 @@
1
+ import type { SwapIntentStatusCodeV2 } from '@sodax/sdk';
2
+
3
+ /**
4
+ * Terminal solver intent states: once reached, the intent is resolved and polling stops.
5
+ * `3` = SOLVED, `4` = FAILED (per `SwapIntentStatusCodeV2`); `-1` / `1` / `2` are non-terminal.
6
+ *
7
+ * Kept in its own pure module (no React/context imports) so it is unit-testable in dapp-kit's
8
+ * `node` test environment — importing the hook itself pulls in `useSodaxContext`.
9
+ */
10
+ export const isTerminalSwapIntentStatus = (status: SwapIntentStatusCodeV2 | undefined): boolean =>
11
+ status === 3 || status === 4;