@sodax/dapp-kit 2.2.0-rc.1 → 2.2.0-rc.3

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 (84) hide show
  1. package/README.md +2 -0
  2. package/dist/index.d.ts +599 -3
  3. package/dist/index.mjs +705 -41
  4. package/package.json +3 -3
  5. package/src/hooks/_apiKeyWire.test.ts +384 -18
  6. package/src/hooks/_mutationContract.test.ts +13 -0
  7. package/src/hooks/backend/index.ts +4 -0
  8. package/src/hooks/backend/useBackendOracleCandles.ts +47 -0
  9. package/src/hooks/backend/useBackendOracleMarkets.ts +30 -0
  10. package/src/hooks/bitcoin/useFundTradingWallet.ts +2 -1
  11. package/src/hooks/bitcoin/useRadfiWithdraw.ts +2 -1
  12. package/src/hooks/bridge/useBridge.ts +2 -2
  13. package/src/hooks/dex/useDexDeposit.ts +2 -1
  14. package/src/hooks/dex/useDexWithdraw.ts +2 -1
  15. package/src/hooks/dex/useSupplyLiquidity.ts +2 -1
  16. package/src/hooks/index.ts +1 -0
  17. package/src/hooks/leverageYield/useLeverageYieldVaultSwap.ts +2 -2
  18. package/src/hooks/leverageYieldApi/index.ts +55 -0
  19. package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +50 -0
  20. package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +37 -0
  21. package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +176 -0
  22. package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +83 -0
  23. package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +41 -0
  24. package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +41 -0
  25. package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +37 -0
  26. package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +37 -0
  27. package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +37 -0
  28. package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +38 -0
  29. package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +57 -0
  30. package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +41 -0
  31. package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +41 -0
  32. package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +40 -0
  33. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +40 -0
  34. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +42 -0
  35. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +41 -0
  36. package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +41 -0
  37. package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +41 -0
  38. package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +43 -0
  39. package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +41 -0
  40. package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +41 -0
  41. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +43 -0
  42. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +43 -0
  43. package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +43 -0
  44. package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +43 -0
  45. package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +41 -0
  46. package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +48 -0
  47. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +36 -0
  48. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +37 -0
  49. package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +60 -0
  50. package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +41 -0
  51. package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +41 -0
  52. package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +36 -0
  53. package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +56 -0
  54. package/src/hooks/migrate/useMigrateBaln.ts +2 -2
  55. package/src/hooks/migrate/useMigrateIcxToSoda.ts +2 -2
  56. package/src/hooks/migrate/useMigratebnUSD.ts +2 -2
  57. package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +2 -2
  58. package/src/hooks/mm/useBorrow.ts +2 -4
  59. package/src/hooks/mm/useRepay.ts +2 -1
  60. package/src/hooks/mm/useSupply.ts +2 -1
  61. package/src/hooks/mm/useWithdraw.ts +2 -4
  62. package/src/hooks/partner/useFeeClaimWithdraw.ts +2 -1
  63. package/src/hooks/recovery/useWithdrawHubAsset.ts +2 -1
  64. package/src/hooks/shared/index.ts +2 -0
  65. package/src/hooks/shared/invalidateBalances.test.ts +71 -0
  66. package/src/hooks/shared/invalidateBalances.ts +25 -0
  67. package/src/hooks/shared/useBalances.test.ts +118 -0
  68. package/src/hooks/shared/useBalances.ts +81 -0
  69. package/src/hooks/shared/useEstablishTrustline.test.ts +2 -0
  70. package/src/hooks/shared/useEstablishTrustline.ts +2 -1
  71. package/src/hooks/shared/useStellarGate.test.ts +1 -1
  72. package/src/hooks/sponsoring/useActivateStellarAccount.test.ts +6 -4
  73. package/src/hooks/sponsoring/useActivateStellarAccount.ts +2 -1
  74. package/src/hooks/sponsoring/useSponsorConfig.test.ts +8 -2
  75. package/src/hooks/sponsoring/useStellarAccountActive.test.ts +2 -2
  76. package/src/hooks/sponsoring/useStellarAccountStatus.test.ts +8 -2
  77. package/src/hooks/staking/useClaim.ts +2 -1
  78. package/src/hooks/staking/useInstantUnstake.ts +2 -1
  79. package/src/hooks/staking/useStake.ts +2 -1
  80. package/src/hooks/swap/useDetailedStatus.test.ts +2 -2
  81. package/src/hooks/swap/useSwap.ts +2 -2
  82. package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -1
  83. package/src/providers/SodaxProvider.test.ts +1 -1
  84. package/src/utils/approvalPlan.ts +4 -1
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "access": "public"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "2.2.0-rc.1",
8
+ "version": "2.2.0-rc.3",
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.2.0-rc.1"
37
+ "@sodax/sdk": "2.2.0-rc.3"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@arethetypeswrong/cli": "0.17.4",
@@ -67,7 +67,7 @@
67
67
  "test": "vitest run",
68
68
  "clean": "rm -rf dist && rm -rf node_modules && rm -rf .turbo",
69
69
  "pretty": "biome format . --write",
70
- "checkTs": "tsc --noEmit",
70
+ "checkTs": "tsc --noEmit && node ../../scripts/check-tests-typechecked.mjs",
71
71
  "check-exports": "attw --pack --profile esm-only",
72
72
  "check:knip": "knip",
73
73
  "lint": "biome lint . --write"
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Executable API-key wire manifest for the swapsApi + bridgeApi hook families.
2
+ * Executable API-key wire manifest for the swapsApi + bridgeApi + leverageYieldApi hook families.
3
3
  *
4
4
  * Every hook that accepts a per-request `apiConfig` must land it on the outgoing HTTP request as
5
5
  * `x-api-key`. Each row renders its hook without a renderer (the package convention: the React
@@ -10,8 +10,8 @@
10
10
  * request that already went out is the whole subject. For the approveAndBroadcast hooks that
11
11
  * rejection also means the wallet machinery is never touched.
12
12
  *
13
- * To add a new swapsApi/bridgeApi hook, add its row here. The friction is intentional — it forces
14
- * key-on-wire coverage from day one.
13
+ * To add a new swapsApi/bridgeApi/leverageYieldApi hook, add its row here. The friction is
14
+ * intentional — it forces key-on-wire coverage from day one.
15
15
  */
16
16
 
17
17
  import { ChainKeys, Sodax, type RequestOverrideConfig } from '@sodax/sdk';
@@ -41,8 +41,9 @@ vi.mock('./shared/useSafeMutation.js', () => ({
41
41
 
42
42
  const swapsApi = await import('./swapsApi/index.js');
43
43
  const bridgeApi = await import('./bridgeApi/index.js');
44
+ const leverageYieldApi = await import('./leverageYieldApi/index.js');
44
45
 
45
- const fetchMock = vi.fn(
46
+ const fetchMock = vi.fn<typeof globalThis.fetch>(
46
47
  async () => new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } }),
47
48
  );
48
49
  vi.stubGlobal('fetch', fetchMock);
@@ -120,6 +121,47 @@ const BRIDGE_SUBMIT_REQUEST = {
120
121
  relayData: { address: '0x1111111111111111111111111111111111111111', payload: '0x' },
121
122
  };
122
123
 
124
+ const VAULT = '0x6666666666666666666666666666666666666666';
125
+
126
+ const LEVERAGE_DEPOSIT_BODY = {
127
+ vault: VAULT,
128
+ srcChainKey: ChainKeys.SONIC_MAINNET,
129
+ srcAddress: '0x1111111111111111111111111111111111111111',
130
+ inputToken: '0x4444444444444444444444444444444444444444',
131
+ inputAmount: '1000000',
132
+ minOutputAmount: '1',
133
+ };
134
+
135
+ const LEVERAGE_WITHDRAW_BODY = {
136
+ vault: VAULT,
137
+ srcChainKey: ChainKeys.SONIC_MAINNET,
138
+ srcAddress: '0x1111111111111111111111111111111111111111',
139
+ dstChainKey: ChainKeys.ARBITRUM_MAINNET,
140
+ outputToken: '0x5555555555555555555555555555555555555555',
141
+ inputAmount: '1000000000000000000',
142
+ minOutputAmount: '1',
143
+ };
144
+
145
+ const LEVERAGE_DEPOSIT_QUOTE_BODY = {
146
+ vault: VAULT,
147
+ tokenSrc: '0x4444444444444444444444444444444444444444',
148
+ tokenSrcChainKey: ChainKeys.SONIC_MAINNET,
149
+ amount: '1000000',
150
+ quoteType: 'exact_input' as const,
151
+ };
152
+
153
+ const LEVERAGE_WITHDRAW_QUOTE_BODY = {
154
+ vault: VAULT,
155
+ srcChainKey: ChainKeys.SONIC_MAINNET,
156
+ tokenDst: '0x5555555555555555555555555555555555555555',
157
+ tokenDstChainKey: ChainKeys.ARBITRUM_MAINNET,
158
+ amount: '1000000000000000000',
159
+ quoteType: 'exact_input' as const,
160
+ };
161
+
162
+ /** The leverage-yield submit-tx body carries the required `operation` discriminator. */
163
+ const LEVERAGE_SUBMIT_TX_REQUEST = { ...SUBMIT_TX_REQUEST, operation: 'deposit' as const };
164
+
123
165
  // --- manifest ---------------------------------------------------------------
124
166
 
125
167
  type Row = {
@@ -443,6 +485,325 @@ const ROWS: Row[] = [
443
485
  return captured.mutationFn({ body: BRIDGE_INTENT_BODY, walletProvider: {}, apiConfig });
444
486
  },
445
487
  },
488
+ // leverageYieldApi read hooks
489
+ {
490
+ hook: 'useLeverageYieldApiVaults',
491
+ path: '/leverage-yield/vaults',
492
+ method: 'GET',
493
+ run: apiConfig => {
494
+ leverageYieldApi.useLeverageYieldApiVaults({ params: { apiConfig } });
495
+ return captured.queryFn();
496
+ },
497
+ },
498
+ {
499
+ hook: 'useLeverageYieldApiVault',
500
+ path: '/leverage-yield/vaults/lsodaWEETH',
501
+ method: 'GET',
502
+ run: apiConfig => {
503
+ leverageYieldApi.useLeverageYieldApiVault({ params: { name: 'lsodaWEETH', apiConfig } });
504
+ return captured.queryFn();
505
+ },
506
+ },
507
+ {
508
+ hook: 'useLeverageYieldApiAsset',
509
+ path: '/leverage-yield/asset',
510
+ method: 'GET',
511
+ run: apiConfig => {
512
+ leverageYieldApi.useLeverageYieldApiAsset({ params: { vault: VAULT, apiConfig } });
513
+ return captured.queryFn();
514
+ },
515
+ },
516
+ {
517
+ hook: 'useLeverageYieldApiPosition',
518
+ path: '/leverage-yield/position',
519
+ method: 'GET',
520
+ run: apiConfig => {
521
+ leverageYieldApi.useLeverageYieldApiPosition({ params: { vault: VAULT, apiConfig } });
522
+ return captured.queryFn();
523
+ },
524
+ },
525
+ {
526
+ hook: 'useLeverageYieldApiApr',
527
+ path: '/leverage-yield/apr',
528
+ method: 'GET',
529
+ run: apiConfig => {
530
+ leverageYieldApi.useLeverageYieldApiApr({ params: { vault: VAULT, apiConfig } });
531
+ return captured.queryFn();
532
+ },
533
+ },
534
+ {
535
+ hook: 'useLeverageYieldApiEffectiveApr',
536
+ path: '/leverage-yield/apr/effective',
537
+ method: 'GET',
538
+ run: apiConfig => {
539
+ leverageYieldApi.useLeverageYieldApiEffectiveApr({ params: { vault: VAULT, apiConfig } });
540
+ return captured.queryFn();
541
+ },
542
+ },
543
+ {
544
+ hook: 'useLeverageYieldApiLsdApr',
545
+ path: '/leverage-yield/apr/lsd',
546
+ method: 'GET',
547
+ run: apiConfig => {
548
+ leverageYieldApi.useLeverageYieldApiLsdApr({ params: { vault: VAULT, apiConfig } });
549
+ return captured.queryFn();
550
+ },
551
+ },
552
+ {
553
+ hook: 'useLeverageYieldApiTotalAssets',
554
+ path: '/leverage-yield/total-assets',
555
+ method: 'GET',
556
+ run: apiConfig => {
557
+ leverageYieldApi.useLeverageYieldApiTotalAssets({ params: { vault: VAULT, apiConfig } });
558
+ return captured.queryFn();
559
+ },
560
+ },
561
+ {
562
+ hook: 'useLeverageYieldApiPreviewDeposit',
563
+ path: '/leverage-yield/preview/deposit',
564
+ method: 'GET',
565
+ run: apiConfig => {
566
+ leverageYieldApi.useLeverageYieldApiPreviewDeposit({ params: { vault: VAULT, assets: '1000000', apiConfig } });
567
+ return captured.queryFn();
568
+ },
569
+ },
570
+ {
571
+ hook: 'useLeverageYieldApiPreviewWithdraw',
572
+ path: '/leverage-yield/preview/withdraw',
573
+ method: 'GET',
574
+ run: apiConfig => {
575
+ leverageYieldApi.useLeverageYieldApiPreviewWithdraw({ params: { vault: VAULT, assets: '1000000', apiConfig } });
576
+ return captured.queryFn();
577
+ },
578
+ },
579
+ {
580
+ hook: 'useLeverageYieldApiPreviewRedeem',
581
+ path: '/leverage-yield/preview/redeem',
582
+ method: 'GET',
583
+ run: apiConfig => {
584
+ leverageYieldApi.useLeverageYieldApiPreviewRedeem({ params: { vault: VAULT, shares: '1000000', apiConfig } });
585
+ return captured.queryFn();
586
+ },
587
+ },
588
+ {
589
+ hook: 'useLeverageYieldApiShareBalance',
590
+ path: '/leverage-yield/share-balance',
591
+ method: 'GET',
592
+ run: apiConfig => {
593
+ leverageYieldApi.useLeverageYieldApiShareBalance({
594
+ params: { vault: VAULT, owner: '0x1111111111111111111111111111111111111111', apiConfig },
595
+ });
596
+ return captured.queryFn();
597
+ },
598
+ },
599
+ {
600
+ hook: 'useLeverageYieldApiMaxWithdraw',
601
+ path: '/leverage-yield/max-withdraw',
602
+ method: 'GET',
603
+ run: apiConfig => {
604
+ leverageYieldApi.useLeverageYieldApiMaxWithdraw({
605
+ params: { vault: VAULT, owner: '0x1111111111111111111111111111111111111111', apiConfig },
606
+ });
607
+ return captured.queryFn();
608
+ },
609
+ },
610
+ {
611
+ hook: 'useLeverageYieldApiDepositQuote',
612
+ path: '/leverage-yield/quote/deposit',
613
+ method: 'POST',
614
+ run: apiConfig => {
615
+ leverageYieldApi.useLeverageYieldApiDepositQuote({ params: { body: LEVERAGE_DEPOSIT_QUOTE_BODY, apiConfig } });
616
+ return captured.queryFn();
617
+ },
618
+ },
619
+ {
620
+ hook: 'useLeverageYieldApiWithdrawQuote',
621
+ path: '/leverage-yield/quote/withdraw',
622
+ method: 'POST',
623
+ run: apiConfig => {
624
+ leverageYieldApi.useLeverageYieldApiWithdrawQuote({ params: { body: LEVERAGE_WITHDRAW_QUOTE_BODY, apiConfig } });
625
+ return captured.queryFn();
626
+ },
627
+ },
628
+ {
629
+ hook: 'useLeverageYieldApiDeadline',
630
+ path: '/leverage-yield/deadline',
631
+ method: 'GET',
632
+ run: apiConfig => {
633
+ leverageYieldApi.useLeverageYieldApiDeadline({ params: { apiConfig } });
634
+ return captured.queryFn();
635
+ },
636
+ },
637
+ {
638
+ hook: 'useLeverageYieldApiAllowance',
639
+ path: '/leverage-yield/allowance/check',
640
+ method: 'POST',
641
+ run: apiConfig => {
642
+ leverageYieldApi.useLeverageYieldApiAllowance({ params: { body: LEVERAGE_DEPOSIT_BODY, apiConfig } });
643
+ return captured.queryFn();
644
+ },
645
+ },
646
+ {
647
+ hook: 'useLeverageYieldApiStatus',
648
+ path: '/leverage-yield/intents/status',
649
+ method: 'POST',
650
+ run: apiConfig => {
651
+ leverageYieldApi.useLeverageYieldApiStatus({ params: { intentTxHash: '0xabc', apiConfig } });
652
+ return captured.queryFn();
653
+ },
654
+ },
655
+ {
656
+ hook: 'useLeverageYieldApiIntentHash',
657
+ path: '/leverage-yield/intents/hash',
658
+ method: 'POST',
659
+ run: apiConfig => {
660
+ leverageYieldApi.useLeverageYieldApiIntentHash({ params: { intent: INTENT, apiConfig } });
661
+ return captured.queryFn();
662
+ },
663
+ },
664
+ {
665
+ hook: 'useLeverageYieldApiIntentPacket',
666
+ path: '/leverage-yield/intents/packet',
667
+ method: 'POST',
668
+ run: apiConfig => {
669
+ leverageYieldApi.useLeverageYieldApiIntentPacket({
670
+ params: { body: { chainId: '146', fillTxHash: '0xf' }, apiConfig },
671
+ });
672
+ return captured.queryFn();
673
+ },
674
+ },
675
+ {
676
+ hook: 'useLeverageYieldApiIntentExtraData',
677
+ path: '/leverage-yield/intents/extra-data',
678
+ method: 'POST',
679
+ run: apiConfig => {
680
+ leverageYieldApi.useLeverageYieldApiIntentExtraData({ params: { body: { txHash: '0xabc' }, apiConfig } });
681
+ return captured.queryFn();
682
+ },
683
+ },
684
+ {
685
+ hook: 'useLeverageYieldApiFilledIntent',
686
+ path: '/leverage-yield/intents/0xabc/fill',
687
+ method: 'GET',
688
+ run: apiConfig => {
689
+ leverageYieldApi.useLeverageYieldApiFilledIntent({ params: { txHash: '0xabc', apiConfig } });
690
+ return captured.queryFn();
691
+ },
692
+ },
693
+ {
694
+ hook: 'useLeverageYieldApiIntent',
695
+ path: '/leverage-yield/intents/0xabc',
696
+ method: 'GET',
697
+ run: apiConfig => {
698
+ leverageYieldApi.useLeverageYieldApiIntent({ params: { txHash: '0xabc', apiConfig } });
699
+ return captured.queryFn();
700
+ },
701
+ },
702
+ {
703
+ hook: 'useLeverageYieldApiEstimateGas',
704
+ path: '/leverage-yield/gas/estimate',
705
+ method: 'POST',
706
+ run: apiConfig => {
707
+ leverageYieldApi.useLeverageYieldApiEstimateGas({
708
+ params: { body: { chainKey: ChainKeys.SONIC_MAINNET, tx: { from: '0xf', to: '0xt', data: '0x' } }, apiConfig },
709
+ });
710
+ return captured.queryFn();
711
+ },
712
+ },
713
+ {
714
+ hook: 'useLeverageYieldApiPartnerFee',
715
+ path: '/leverage-yield/fees/partner',
716
+ method: 'GET',
717
+ run: apiConfig => {
718
+ leverageYieldApi.useLeverageYieldApiPartnerFee({ params: { amount: '1000', apiConfig } });
719
+ return captured.queryFn();
720
+ },
721
+ },
722
+ {
723
+ hook: 'useLeverageYieldApiSolverFee',
724
+ path: '/leverage-yield/fees/solver',
725
+ method: 'GET',
726
+ run: apiConfig => {
727
+ leverageYieldApi.useLeverageYieldApiSolverFee({ params: { amount: '1000', apiConfig } });
728
+ return captured.queryFn();
729
+ },
730
+ },
731
+ {
732
+ hook: 'useLeverageYieldApiSubmitTxStatus',
733
+ path: '/leverage-yield/submit-tx/status',
734
+ method: 'GET',
735
+ run: apiConfig => {
736
+ leverageYieldApi.useLeverageYieldApiSubmitTxStatus({
737
+ params: { txHash: '0xabc', srcChainKey: ChainKeys.SONIC_MAINNET, apiConfig },
738
+ });
739
+ return captured.queryFn();
740
+ },
741
+ },
742
+ // leverageYieldApi mutation hooks
743
+ {
744
+ hook: 'useLeverageYieldApiApprove',
745
+ path: '/leverage-yield/approve',
746
+ method: 'POST',
747
+ run: apiConfig => {
748
+ leverageYieldApi.useLeverageYieldApiApprove();
749
+ return captured.mutationFn({ body: LEVERAGE_DEPOSIT_BODY, apiConfig });
750
+ },
751
+ },
752
+ {
753
+ // Same shape as the swaps/bridge rows: the failed approve unwrap rejects before any wallet work.
754
+ hook: 'useLeverageYieldApiApproveAndBroadcast',
755
+ path: '/leverage-yield/approve',
756
+ method: 'POST',
757
+ run: apiConfig => {
758
+ leverageYieldApi.useLeverageYieldApiApproveAndBroadcast();
759
+ return captured.mutationFn({ body: LEVERAGE_DEPOSIT_BODY, walletProvider: {}, apiConfig });
760
+ },
761
+ },
762
+ {
763
+ hook: 'useLeverageYieldApiCreateDepositIntent',
764
+ path: '/leverage-yield/intents/deposit',
765
+ method: 'POST',
766
+ run: apiConfig => {
767
+ leverageYieldApi.useLeverageYieldApiCreateDepositIntent();
768
+ return captured.mutationFn({ body: LEVERAGE_DEPOSIT_BODY, apiConfig });
769
+ },
770
+ },
771
+ {
772
+ hook: 'useLeverageYieldApiCreateWithdrawIntent',
773
+ path: '/leverage-yield/intents/withdraw',
774
+ method: 'POST',
775
+ run: apiConfig => {
776
+ leverageYieldApi.useLeverageYieldApiCreateWithdrawIntent();
777
+ return captured.mutationFn({ body: LEVERAGE_WITHDRAW_BODY, apiConfig });
778
+ },
779
+ },
780
+ {
781
+ hook: 'useLeverageYieldApiCancelIntent',
782
+ path: '/leverage-yield/intents/cancel',
783
+ method: 'POST',
784
+ run: apiConfig => {
785
+ leverageYieldApi.useLeverageYieldApiCancelIntent();
786
+ return captured.mutationFn({ body: { srcChainKey: ChainKeys.SONIC_MAINNET, intent: INTENT }, apiConfig });
787
+ },
788
+ },
789
+ {
790
+ hook: 'useLeverageYieldApiSubmitIntent',
791
+ path: '/leverage-yield/intents/submit',
792
+ method: 'POST',
793
+ run: apiConfig => {
794
+ leverageYieldApi.useLeverageYieldApiSubmitIntent();
795
+ return captured.mutationFn({ body: { chainId: '146', txHash: '0xabc' }, apiConfig });
796
+ },
797
+ },
798
+ {
799
+ hook: 'useLeverageYieldApiSubmitTx',
800
+ path: '/leverage-yield/submit-tx',
801
+ method: 'POST',
802
+ run: apiConfig => {
803
+ leverageYieldApi.useLeverageYieldApiSubmitTx();
804
+ return captured.mutationFn({ request: LEVERAGE_SUBMIT_TX_REQUEST, apiConfig });
805
+ },
806
+ },
446
807
  ];
447
808
 
448
809
  /** Fails loudly when a named row is missing, so a hook rename cannot silently drop coverage. */
@@ -469,19 +830,24 @@ describe('apiConfig.apiKey reaches the wire (hook-level key beats the instance k
469
830
  });
470
831
 
471
832
  describe('a raw x-api-key header override wins in any casing, without duplicating the header', () => {
472
- const REPRESENTATIVES = [rowFor('useSwapsApiTokens'), rowFor('useBridgeApiTokens')];
833
+ const REPRESENTATIVES = [
834
+ rowFor('useSwapsApiTokens'),
835
+ rowFor('useBridgeApiTokens'),
836
+ rowFor('useLeverageYieldApiVaults'),
837
+ ];
473
838
 
474
- it.each(REPRESENTATIVES)(
475
- '$hook → $method $path carries exactly one x-api-key: raw-key',
476
- async ({ path, method, run }) => {
477
- await run({ headers: { 'X-Api-Key': 'raw-key' } }).catch(() => {});
478
- expect(fetchMock).toHaveBeenCalledTimes(1);
479
- const [url, init] = fetchMock.mock.calls[0] ?? [];
480
- expect(new URL(String(url)).pathname).toBe(`/v1${path}`);
481
- expect(init?.method).toBe(method);
482
- const headers = init?.headers as Record<string, string>;
483
- expect(Object.keys(headers).filter(name => name.toLowerCase() === 'x-api-key')).toHaveLength(1);
484
- expect(new Headers(headers).get('x-api-key')).toBe('raw-key');
485
- },
486
- );
839
+ it.each(REPRESENTATIVES)('$hook → $method $path carries exactly one x-api-key: raw-key', async ({
840
+ path,
841
+ method,
842
+ run,
843
+ }) => {
844
+ await run({ headers: { 'X-Api-Key': 'raw-key' } }).catch(() => {});
845
+ expect(fetchMock).toHaveBeenCalledTimes(1);
846
+ const [url, init] = fetchMock.mock.calls[0] ?? [];
847
+ expect(new URL(String(url)).pathname).toBe(`/v1${path}`);
848
+ expect(init?.method).toBe(method);
849
+ const headers = init?.headers as Record<string, string>;
850
+ expect(Object.keys(headers).filter(name => name.toLowerCase() === 'x-api-key')).toHaveLength(1);
851
+ expect(new Headers(headers).get('x-api-key')).toBe('raw-key');
852
+ });
487
853
  });
@@ -30,6 +30,13 @@ const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
30
30
  { path: 'leverageYield/useLeverageYieldNotifySolver.ts' },
31
31
  { path: 'leverageYield/useLeverageYieldVaultSwap.ts' },
32
32
  { path: 'leverageYield/useLeverageYieldWithdraw.ts' },
33
+ { path: 'leverageYieldApi/useLeverageYieldApiApprove.ts' },
34
+ { path: 'leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts' },
35
+ { path: 'leverageYieldApi/useLeverageYieldApiCancelIntent.ts' },
36
+ { path: 'leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts' },
37
+ { path: 'leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts' },
38
+ { path: 'leverageYieldApi/useLeverageYieldApiSubmitIntent.ts' },
39
+ { path: 'leverageYieldApi/useLeverageYieldApiSubmitTx.ts' },
33
40
  { path: 'migrate/useMigrateBaln.ts' },
34
41
  { path: 'migrate/useMigrateIcxToSoda.ts' },
35
42
  { path: 'migrate/useMigratebnUSD.ts' },
@@ -111,6 +118,12 @@ describe.each(HOOKS)('mutation hook contract: $path', ({ path, nativeThrow }) =>
111
118
  expect(fnIdx).toBeGreaterThan(spreadIdx);
112
119
  });
113
120
 
121
+ it('routes balance invalidation through invalidateBalances', () => {
122
+ // Hand-rolling one balance key invalidates only one of the two balance hooks (useBalances vs
123
+ // useXBalances) and leaves the other stale — the exact drift the shared helper exists to stop.
124
+ expect(src).not.toMatch(/invalidateQueries\(\{\s*queryKey:\s*\[\s*'shared',\s*'x?[bB]alances'/);
125
+ });
126
+
114
127
  if (!nativeThrow) {
115
128
  it('translates SDK Result via unwrapResult', () => {
116
129
  expect(src).toMatch(/unwrapResult\(/);
@@ -22,4 +22,8 @@ export { useBackendMoneyMarketAsset } from './useBackendMoneyMarketAsset.js';
22
22
  export { useBackendMoneyMarketAssetBorrowers } from './useBackendMoneyMarketAssetBorrowers.js';
23
23
  export { useBackendMoneyMarketAssetSuppliers } from './useBackendMoneyMarketAssetSuppliers.js';
24
24
  export { useBackendAllMoneyMarketBorrowers } from './useBackendAllMoneyMarketBorrowers.js';
25
+
26
+ // Oracle hooks
27
+ export { useBackendOracleMarkets } from './useBackendOracleMarkets.js';
28
+ export { useBackendOracleCandles } from './useBackendOracleCandles.js';
25
29
  export * from './types.js';
@@ -0,0 +1,47 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import type { OracleCandleInterval, OracleCandlesResponse } from '@sodax/sdk';
3
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
4
+ import { unwrapResult } from './unwrapResult.js';
5
+ import type { ReadHookParams } from '../shared/types.js';
6
+
7
+ export type UseBackendOracleCandlesParams = ReadHookParams<
8
+ OracleCandlesResponse,
9
+ {
10
+ symbol: string;
11
+ interval: OracleCandleInterval;
12
+ /** Range start, UNIX seconds, inclusive. */
13
+ from: number;
14
+ /** Range end, UNIX seconds, exclusive; the range may cover at most 5000 buckets. */
15
+ to: number;
16
+ }
17
+ >;
18
+
19
+ /**
20
+ * Hook for fetching USD OHLC candles for a symbol over the half-open range `[from, to)`
21
+ * from the backend API. Responses are cached server-side for roughly 10 seconds.
22
+ *
23
+ * @example
24
+ * const { data } = useBackendOracleCandles({
25
+ * params: { symbol: 'ETH', interval: '1h', from: 1756000000, to: 1756360000 },
26
+ * });
27
+ */
28
+ export const useBackendOracleCandles = ({
29
+ params,
30
+ queryOptions,
31
+ }: UseBackendOracleCandlesParams = {}): UseQueryResult<OracleCandlesResponse, Error> => {
32
+ const { sodax } = useSodaxContext();
33
+
34
+ return useQuery<OracleCandlesResponse, Error>({
35
+ queryKey: ['backend', 'oracle', 'candles', params?.symbol, params?.interval, params?.from, params?.to],
36
+ queryFn: async (): Promise<OracleCandlesResponse> => {
37
+ if (!params) {
38
+ throw new Error('symbol, interval, from and to are required');
39
+ }
40
+ return unwrapResult(await sodax.backendApi.getOracleCandles(params));
41
+ },
42
+ enabled: !!params?.symbol && !!params?.interval && params?.from != null && params?.to != null,
43
+ staleTime: 10 * 1000,
44
+ retry: 3,
45
+ ...queryOptions,
46
+ });
47
+ };
@@ -0,0 +1,30 @@
1
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
+ import type { OracleMarketsResponse } from '@sodax/sdk';
3
+ import { useSodaxContext } from '../shared/useSodaxContext.js';
4
+ import { unwrapResult } from './unwrapResult.js';
5
+ import type { ReadHookParams } from '../shared/types.js';
6
+
7
+ export type UseBackendOracleMarketsParams = ReadHookParams<OracleMarketsResponse>;
8
+
9
+ /**
10
+ * Hook for fetching the oracle candle store's discovery payload (quote currency,
11
+ * selectable intervals, and covered symbols) from the backend API.
12
+ *
13
+ * @example
14
+ * const { data: markets } = useBackendOracleMarkets();
15
+ */
16
+ export const useBackendOracleMarkets = ({
17
+ queryOptions,
18
+ }: UseBackendOracleMarketsParams = {}): UseQueryResult<OracleMarketsResponse, Error> => {
19
+ const { sodax } = useSodaxContext();
20
+
21
+ return useQuery<OracleMarketsResponse, Error>({
22
+ queryKey: ['backend', 'oracle', 'markets'],
23
+ queryFn: async (): Promise<OracleMarketsResponse> => {
24
+ return unwrapResult(await sodax.backendApi.getOracleMarkets());
25
+ },
26
+ staleTime: 60 * 1000,
27
+ retry: 3,
28
+ ...queryOptions,
29
+ });
30
+ };
@@ -2,6 +2,7 @@
2
2
  import { useQueryClient } from '@tanstack/react-query';
3
3
  import { ChainKeys, type IBitcoinWalletProvider } from '@sodax/sdk';
4
4
  import { useSodaxContext } from '../shared/useSodaxContext.js';
5
+ import { invalidateBalances } from '../shared/invalidateBalances.js';
5
6
  import type { MutationHookParams } from '../shared/types.js';
6
7
  import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
7
8
 
@@ -35,7 +36,7 @@ export function useFundTradingWallet({
35
36
  onSuccess: async (data, vars, ctx) => {
36
37
  queryClient.invalidateQueries({ queryKey: ['bitcoin', 'balance'] });
37
38
  queryClient.invalidateQueries({ queryKey: ['bitcoin', 'tradingWalletBalance'] });
38
- queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', ChainKeys.BITCOIN_MAINNET] });
39
+ invalidateBalances(queryClient, ChainKeys.BITCOIN_MAINNET);
39
40
  await mutationOptions?.onSuccess?.(data, vars, ctx);
40
41
  },
41
42
  });
@@ -3,6 +3,7 @@ import { normalizePsbtToBase64, ChainKeys, type IBitcoinWalletProvider } from '@
3
3
  import { useQueryClient } from '@tanstack/react-query';
4
4
  import { loadRadfiSession } from './useRadfiAuth.js';
5
5
  import { useSodaxContext } from '../shared/useSodaxContext.js';
6
+ import { invalidateBalances } from '../shared/invalidateBalances.js';
6
7
  import type { MutationHookParams } from '../shared/types.js';
7
8
  import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
8
9
 
@@ -60,7 +61,7 @@ export function useRadfiWithdraw({
60
61
  onSuccess: async (data, vars, ctx) => {
61
62
  queryClient.invalidateQueries({ queryKey: ['bitcoin', 'tradingWalletBalance'] });
62
63
  queryClient.invalidateQueries({ queryKey: ['bitcoin', 'balance'] });
63
- queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', ChainKeys.BITCOIN_MAINNET] });
64
+ invalidateBalances(queryClient, ChainKeys.BITCOIN_MAINNET);
64
65
  await mutationOptions?.onSuccess?.(data, vars, ctx);
65
66
  },
66
67
  });
@@ -1,5 +1,6 @@
1
1
  // packages/dapp-kit/src/hooks/bridge/useBridge.ts
2
2
  import { useSodaxContext } from '../shared/useSodaxContext.js';
3
+ import { invalidateBalances } from '../shared/invalidateBalances.js';
3
4
  import type { BridgeParams, SpokeChainKey, TxHashPair } from '@sodax/sdk';
4
5
  import { useQueryClient } from '@tanstack/react-query';
5
6
  import type { MutationHookParams } from '../shared/types.js';
@@ -30,8 +31,7 @@ export function useBridge<K extends SpokeChainKey = SpokeChainKey>({
30
31
  ...mutationOptions,
31
32
  mutationFn: async vars => unwrapResult(await sodax.bridge.bridge({ ...vars, raw: false })),
32
33
  onSuccess: async (data, vars, ctx) => {
33
- queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', vars.params.srcChainKey] });
34
- queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', vars.params.dstChainKey] });
34
+ invalidateBalances(queryClient, vars.params.srcChainKey, vars.params.dstChainKey);
35
35
  await mutationOptions?.onSuccess?.(data, vars, ctx);
36
36
  },
37
37
  });
@@ -2,6 +2,7 @@
2
2
  import type { AssetDepositAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
3
3
  import { useQueryClient } from '@tanstack/react-query';
4
4
  import { useSodaxContext } from '../shared/useSodaxContext.js';
5
+ import { invalidateBalances } from '../shared/invalidateBalances.js';
5
6
  import type { MutationHookParams } from '../shared/types.js';
6
7
  import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
7
8
  import { unwrapResult } from '../shared/unwrapResult.js';
@@ -50,7 +51,7 @@ export function useDexDeposit<K extends SpokeChainKey = SpokeChainKey>({
50
51
  queryClient.invalidateQueries({
51
52
  queryKey: ['dex', 'allowance', params.srcChainKey, params.asset, params.amount.toString()],
52
53
  });
53
- queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', params.srcChainKey] });
54
+ invalidateBalances(queryClient, params.srcChainKey);
54
55
  await mutationOptions?.onSuccess?.(data, vars, ctx);
55
56
  },
56
57
  });
@@ -2,6 +2,7 @@
2
2
  import type { AssetWithdrawAction, SpokeChainKey, TxHashPair } from '@sodax/sdk';
3
3
  import { useQueryClient } from '@tanstack/react-query';
4
4
  import { useSodaxContext } from '../shared/useSodaxContext.js';
5
+ import { invalidateBalances } from '../shared/invalidateBalances.js';
5
6
  import type { MutationHookParams } from '../shared/types.js';
6
7
  import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
7
8
  import { unwrapResult } from '../shared/unwrapResult.js';
@@ -36,7 +37,7 @@ export function useDexWithdraw<K extends SpokeChainKey = SpokeChainKey>({
36
37
  onSuccess: async (data, vars, ctx) => {
37
38
  const { params } = vars;
38
39
  queryClient.invalidateQueries({ queryKey: ['dex', 'poolBalances', params.srcChainKey, params.srcAddress] });
39
- queryClient.invalidateQueries({ queryKey: ['shared', 'xBalances', params.srcChainKey] });
40
+ invalidateBalances(queryClient, params.srcChainKey);
40
41
  await mutationOptions?.onSuccess?.(data, vars, ctx);
41
42
  },
42
43
  });