@sodax/dapp-kit 0.0.1-rc.5 → 0.0.1-rc.7

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 (49) hide show
  1. package/dist/contexts/index.d.ts +2 -1
  2. package/dist/contexts/index.d.ts.map +1 -1
  3. package/dist/hooks/mm/index.d.ts +2 -0
  4. package/dist/hooks/mm/index.d.ts.map +1 -1
  5. package/dist/hooks/mm/useAllowance.d.ts +4 -0
  6. package/dist/hooks/mm/useAllowance.d.ts.map +1 -0
  7. package/dist/hooks/{shared → mm}/useApprove.d.ts +5 -1
  8. package/dist/hooks/mm/useApprove.d.ts.map +1 -0
  9. package/dist/hooks/mm/useBorrow.d.ts +10 -1
  10. package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
  11. package/dist/hooks/mm/useRepay.d.ts +10 -1
  12. package/dist/hooks/mm/useRepay.d.ts.map +1 -1
  13. package/dist/hooks/mm/useSupply.d.ts +3 -1
  14. package/dist/hooks/mm/useSupply.d.ts.map +1 -1
  15. package/dist/hooks/mm/useUserReservesData.d.ts +1 -1
  16. package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
  17. package/dist/hooks/mm/useWithdraw.d.ts +8 -1
  18. package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
  19. package/dist/hooks/provider/useHubProvider.d.ts +1 -1
  20. package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
  21. package/dist/hooks/provider/useSpokeProvider.d.ts +16 -2
  22. package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
  23. package/dist/hooks/shared/index.d.ts +0 -2
  24. package/dist/hooks/shared/index.d.ts.map +1 -1
  25. package/dist/hooks/swap/useCreateIntentOrder.d.ts +4 -4
  26. package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +1 -1
  27. package/dist/index.js +148 -144
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +150 -146
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/providers/SodaxProvider.d.ts.map +1 -1
  32. package/package.json +4 -4
  33. package/src/contexts/index.ts +2 -1
  34. package/src/hooks/mm/index.ts +2 -0
  35. package/src/hooks/{shared → mm}/useAllowance.ts +4 -2
  36. package/src/hooks/{shared → mm}/useApprove.ts +9 -7
  37. package/src/hooks/mm/useBorrow.ts +14 -5
  38. package/src/hooks/mm/useRepay.ts +14 -4
  39. package/src/hooks/mm/useSupply.ts +7 -4
  40. package/src/hooks/mm/useUserReservesData.ts +22 -33
  41. package/src/hooks/mm/useWithdraw.ts +12 -4
  42. package/src/hooks/provider/useHubProvider.ts +2 -20
  43. package/src/hooks/provider/useSpokeProvider.ts +53 -7
  44. package/src/hooks/shared/index.ts +0 -2
  45. package/src/hooks/swap/useCreateIntentOrder.ts +4 -6
  46. package/src/providers/SodaxProvider.tsx +18 -3
  47. package/dist/hooks/shared/useAllowance.d.ts +0 -3
  48. package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
  49. package/dist/hooks/shared/useApprove.d.ts.map +0 -1
@@ -3,13 +3,14 @@ import type { SpokeChainId, XToken } from '@sodax/types';
3
3
  import { useSodaxContext } from '../shared/useSodaxContext';
4
4
  import { useSpokeProvider } from '../provider/useSpokeProvider';
5
5
  import { parseUnits } from 'viem';
6
+ import type { MoneyMarketAction } from '@sodax/sdk';
6
7
 
7
- export function useAllowance(token: XToken, amount: string) {
8
+ export function useAllowance(token: XToken, amount: string, action: MoneyMarketAction) {
8
9
  const { sodax } = useSodaxContext();
9
10
  const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);
10
11
 
11
12
  return useQuery({
12
- queryKey: ['allowance', token.address, amount],
13
+ queryKey: ['allowance', token.address, amount, action],
13
14
  queryFn: async () => {
14
15
  if (!spokeProvider) {
15
16
  return false;
@@ -18,6 +19,7 @@ export function useAllowance(token: XToken, amount: string) {
18
19
  {
19
20
  token: token.address,
20
21
  amount: parseUnits(amount, token.decimals),
22
+ action,
21
23
  },
22
24
  spokeProvider,
23
25
  );
@@ -3,10 +3,10 @@ import { useSpokeProvider } from '../provider/useSpokeProvider';
3
3
  import type { SpokeChainId, XToken } from '@sodax/types';
4
4
  import { parseUnits } from 'viem';
5
5
  import { useMutation, useQueryClient } from '@tanstack/react-query';
6
- import type { Address } from '@sodax/sdk';
6
+ import type { MoneyMarketAction } from '@sodax/sdk';
7
7
 
8
8
  interface UseApproveReturn {
9
- approve: (amount: string) => Promise<boolean>;
9
+ approve: ({ amount, action }: { amount: string; action: MoneyMarketAction }) => Promise<boolean>;
10
10
  isLoading: boolean;
11
11
  error: Error | null;
12
12
  resetError: () => void;
@@ -23,14 +23,16 @@ export function useApprove(token: XToken): UseApproveReturn {
23
23
  error,
24
24
  reset: resetError,
25
25
  } = useMutation({
26
- mutationFn: async (amount: string) => {
26
+ mutationFn: async ({ amount, action }: { amount: string; action: MoneyMarketAction }) => {
27
27
  if (!spokeProvider) {
28
28
  throw new Error('Spoke provider not found');
29
29
  }
30
30
  const allowance = await sodax.moneyMarket.approve(
31
- token.address as Address,
32
- parseUnits(amount, token.decimals),
33
- spokeProvider.chainConfig.addresses.assetManager as Address,
31
+ {
32
+ token: token.address,
33
+ amount: parseUnits(amount, token.decimals),
34
+ action,
35
+ },
34
36
  spokeProvider,
35
37
  );
36
38
  if (!allowance.ok) {
@@ -47,7 +49,7 @@ export function useApprove(token: XToken): UseApproveReturn {
47
49
  return {
48
50
  approve,
49
51
  isLoading: isPending,
50
- error: error as Error | null,
52
+ error: error,
51
53
  resetError,
52
54
  };
53
55
  }
@@ -1,9 +1,8 @@
1
1
  import type { XToken } from '@sodax/types';
2
2
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
3
3
  import { parseUnits } from 'viem';
4
- import { useSpokeProvider } from '../provider/useSpokeProvider';
5
4
  import { useSodaxContext } from '../shared/useSodaxContext';
6
- import type { SpokeChainId } from '@sodax/sdk';
5
+ import type { SpokeProvider } from '@sodax/sdk';
7
6
  interface BorrowResponse {
8
7
  ok: true;
9
8
  value: [`0x${string}`, `0x${string}`];
@@ -16,6 +15,14 @@ interface BorrowResponse {
16
15
  * handling the entire borrow process including transaction creation, submission,
17
16
  * and cross-chain communication.
18
17
  *
18
+ * @param {XToken} spokeToken - The token to borrow from the spoke chain. Must be an XToken with valid address and chain information.
19
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for the borrow transaction. Must be a valid SpokeProvider instance.
20
+ *
21
+ * @returns {UseMutationResult<BorrowResponse, Error, string>} A mutation result object with the following properties:
22
+ * - mutateAsync: Function to execute the borrow transaction
23
+ * - isPending: Boolean indicating if a transaction is in progress
24
+ * - error: Error object if the last transaction failed, null otherwise
25
+ *
19
26
  * @example
20
27
  * ```typescript
21
28
  * const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);
@@ -26,9 +33,11 @@ interface BorrowResponse {
26
33
  * - spokeProvider is not available
27
34
  * - Transaction execution fails
28
35
  */
29
- export function useBorrow(spokeToken: XToken): UseMutationResult<BorrowResponse, Error, string> {
36
+ export function useBorrow(
37
+ spokeToken: XToken,
38
+ spokeProvider: SpokeProvider | undefined,
39
+ ): UseMutationResult<BorrowResponse, Error, string> {
30
40
  const { sodax } = useSodaxContext();
31
- const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);
32
41
 
33
42
  return useMutation<BorrowResponse, Error, string>({
34
43
  mutationFn: async (amount: string) => {
@@ -40,12 +49,12 @@ export function useBorrow(spokeToken: XToken): UseMutationResult<BorrowResponse,
40
49
  {
41
50
  token: spokeToken.address,
42
51
  amount: parseUnits(amount, 18),
52
+ action: 'borrow',
43
53
  },
44
54
  spokeProvider,
45
55
  );
46
56
 
47
57
  if (!response.ok) {
48
- console.log('Failed to borrow tokens', response);
49
58
  throw new Error('Failed to borrow tokens');
50
59
  }
51
60
 
@@ -1,8 +1,7 @@
1
- import type { SpokeChainId } from '@sodax/sdk';
1
+ import type { SpokeProvider } from '@sodax/sdk';
2
2
  import type { XToken } from '@sodax/types';
3
3
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
4
4
  import { parseUnits } from 'viem';
5
- import { useSpokeProvider } from '../provider/useSpokeProvider';
6
5
  import { useSodaxContext } from '../shared/useSodaxContext';
7
6
 
8
7
  interface RepayResponse {
@@ -17,6 +16,14 @@ interface RepayResponse {
17
16
  * handling the entire repayment process including transaction creation, submission,
18
17
  * and cross-chain communication.
19
18
  *
19
+ * @param {XToken} spokeToken - The token to repay on the spoke chain. Must be an XToken with valid address and chain information.
20
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for the repay transaction. Must be a valid SpokeProvider instance.
21
+ *
22
+ * @returns {UseMutationResult<RepayResponse, Error, string>} A mutation result object with the following properties:
23
+ * - mutateAsync: Function to execute the repay transaction
24
+ * - isPending: Boolean indicating if a transaction is in progress
25
+ * - error: Error object if the last transaction failed, null otherwise
26
+ *
20
27
  * @example
21
28
  * ```typescript
22
29
  * const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);
@@ -27,9 +34,11 @@ interface RepayResponse {
27
34
  * - spokeProvider is not available
28
35
  * - Transaction execution fails
29
36
  */
30
- export function useRepay(spokeToken: XToken): UseMutationResult<RepayResponse, Error, string> {
37
+ export function useRepay(
38
+ spokeToken: XToken,
39
+ spokeProvider: SpokeProvider | undefined,
40
+ ): UseMutationResult<RepayResponse, Error, string> {
31
41
  const { sodax } = useSodaxContext();
32
- const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);
33
42
 
34
43
  return useMutation<RepayResponse, Error, string>({
35
44
  mutationFn: async (amount: string) => {
@@ -41,6 +50,7 @@ export function useRepay(spokeToken: XToken): UseMutationResult<RepayResponse, E
41
50
  {
42
51
  token: spokeToken.address,
43
52
  amount: parseUnits(amount, spokeToken.decimals),
53
+ action: 'repay',
44
54
  },
45
55
  spokeProvider,
46
56
  );
@@ -1,8 +1,7 @@
1
- import type { SpokeChainId } from '@sodax/sdk';
1
+ import type { SpokeProvider } from '@sodax/sdk';
2
2
  import type { XToken } from '@sodax/types';
3
3
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
4
4
  import { parseUnits } from 'viem';
5
- import { useSpokeProvider } from '../provider/useSpokeProvider';
6
5
  import { useSodaxContext } from '../shared/useSodaxContext';
7
6
 
8
7
  interface SupplyResponse {
@@ -18,6 +17,7 @@ interface SupplyResponse {
18
17
  * and cross-chain communication.
19
18
  *
20
19
  * @param {XToken} spokeToken - The token to supply on the spoke chain. Must be an XToken with valid address and chain information.
20
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for the supply transaction. Must be a valid SpokeProvider instance.
21
21
  *
22
22
  * @returns {UseMutationResult<SupplyResponse, Error, string>} A mutation result object with the following properties:
23
23
  * - mutateAsync: Function to execute the supply transaction
@@ -33,9 +33,11 @@ interface SupplyResponse {
33
33
  * @throws {Error} When:
34
34
  * - spokeProvider is not available
35
35
  */
36
- export function useSupply(spokeToken: XToken): UseMutationResult<SupplyResponse, Error, string> {
36
+ export function useSupply(
37
+ spokeToken: XToken,
38
+ spokeProvider: SpokeProvider | undefined,
39
+ ): UseMutationResult<SupplyResponse, Error, string> {
37
40
  const { sodax } = useSodaxContext();
38
- const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);
39
41
 
40
42
  return useMutation<SupplyResponse, Error, string>({
41
43
  mutationFn: async (amount: string) => {
@@ -47,6 +49,7 @@ export function useSupply(spokeToken: XToken): UseMutationResult<SupplyResponse,
47
49
  {
48
50
  token: spokeToken.address,
49
51
  amount: parseUnits(amount, spokeToken.decimals),
52
+ action: 'supply',
50
53
  },
51
54
  spokeProvider,
52
55
  );
@@ -1,56 +1,45 @@
1
1
  import { allXTokens } from '@/core';
2
- import { getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';
2
+ import { encodeAddress, EvmWalletAbstraction, getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';
3
3
  import type { HubChainId, SpokeChainId } from '@sodax/types';
4
- import { useXAccount, useWalletProvider } from '@sodax/wallet-sdk';
5
4
  import type { ChainId } from '@sodax/types';
6
5
  import { useQuery } from '@tanstack/react-query';
7
6
  import { useHubProvider } from '../provider/useHubProvider';
8
- import { useHubWalletAddress } from './useHubWalletAddress';
9
7
  import { useSodaxContext } from '../shared/useSodaxContext';
10
8
 
11
- export function useUserReservesData(spokeChainId: ChainId) {
9
+ export function useUserReservesData(spokeChainId: ChainId, address: string | undefined) {
12
10
  const { sodax } = useSodaxContext();
13
11
  const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;
14
- const hubWalletProvider = useWalletProvider(hubChainId);
15
12
  const hubProvider = useHubProvider();
16
- const { address } = useXAccount(spokeChainId);
17
- const { data: hubWalletAddress } = useHubWalletAddress(
18
- spokeChainId as SpokeChainId,
19
- address,
20
- hubProvider as EvmHubProvider,
21
- );
22
13
 
23
14
  const { data: userReserves } = useQuery({
24
- queryKey: ['userReserves', hubWalletAddress],
15
+ queryKey: ['userReserves', spokeChainId, address],
25
16
  queryFn: async () => {
26
- if (!hubWalletProvider) {
17
+ if (!hubProvider || !address) {
27
18
  return;
28
19
  }
29
20
 
30
- if (!hubWalletAddress) {
31
- return;
32
- }
21
+ const addressBytes = encodeAddress(spokeChainId, address);
22
+ const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(
23
+ spokeChainId as SpokeChainId,
24
+ addressBytes,
25
+ hubProvider as EvmHubProvider,
26
+ );
33
27
 
34
28
  const moneyMarketConfig = getMoneyMarketConfig(hubChainId);
35
- try {
36
- const [res] = await sodax.moneyMarket.getUserReservesData(
37
- hubWalletAddress as `0x${string}`,
38
- moneyMarketConfig.uiPoolDataProvider,
39
- moneyMarketConfig.poolAddressesProvider,
40
- );
29
+ const [res] = await sodax.moneyMarket.getUserReservesData(
30
+ hubWalletAddress as `0x${string}`,
31
+ moneyMarketConfig.uiPoolDataProvider,
32
+ moneyMarketConfig.poolAddressesProvider,
33
+ );
41
34
 
42
- return res?.map(r => {
43
- return {
44
- ...r,
45
- token: allXTokens.find(t => t.address === r.underlyingAsset),
46
- };
47
- });
48
- } catch (error) {
49
- console.log('error', error);
50
- return;
51
- }
35
+ return res?.map(r => {
36
+ return {
37
+ ...r,
38
+ token: allXTokens.find(t => t.address === r.underlyingAsset),
39
+ };
40
+ });
52
41
  },
53
- enabled: !!address && !!hubWalletProvider && !!hubWalletAddress,
42
+ enabled: !!spokeChainId && !!hubProvider && !!address,
54
43
  refetchInterval: 5000,
55
44
  });
56
45
 
@@ -1,8 +1,7 @@
1
- import type { SpokeChainId } from '@sodax/sdk';
1
+ import type { SpokeProvider } from '@sodax/sdk';
2
2
  import type { XToken } from '@sodax/types';
3
3
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
4
4
  import { parseUnits } from 'viem';
5
- import { useSpokeProvider } from '../provider/useSpokeProvider';
6
5
  import { useSodaxContext } from '../shared/useSodaxContext';
7
6
 
8
7
  interface WithdrawResponse {
@@ -17,6 +16,12 @@ interface WithdrawResponse {
17
16
  * handling the entire withdrawal process including transaction creation, submission,
18
17
  * and cross-chain communication.
19
18
  *
19
+ * @param {XToken} spokeToken - The token to withdraw from the spoke chain. Must be an XToken with valid address and chain information.
20
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for the withdraw transaction. Must be a valid SpokeProvider instance.
21
+ *
22
+ * @returns {UseMutationResult<WithdrawResponse, Error, string>} A mutation result object with the following properties:
23
+ * - mutateAsync: Function to execute the withdraw transaction
24
+ * - isPending: Boolean indicating if a transaction is in progress
20
25
  * @example
21
26
  * ```typescript
22
27
  * const { mutateAsync: withdraw, isPending, error } = useWithdraw(spokeToken);
@@ -27,9 +32,11 @@ interface WithdrawResponse {
27
32
  * - spokeProvider is not available
28
33
  * - Transaction execution fails
29
34
  */
30
- export function useWithdraw(spokeToken: XToken): UseMutationResult<WithdrawResponse, Error, string> {
35
+ export function useWithdraw(
36
+ spokeToken: XToken,
37
+ spokeProvider: SpokeProvider | undefined,
38
+ ): UseMutationResult<WithdrawResponse, Error, string> {
31
39
  const { sodax } = useSodaxContext();
32
- const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);
33
40
 
34
41
  return useMutation<WithdrawResponse, Error, string>({
35
42
  mutationFn: async (amount: string) => {
@@ -42,6 +49,7 @@ export function useWithdraw(spokeToken: XToken): UseMutationResult<WithdrawRespo
42
49
  token: spokeToken.address,
43
50
  // vault token on hub chain decimals is 18
44
51
  amount: parseUnits(amount, 18),
52
+ action: 'withdraw',
45
53
  },
46
54
  spokeProvider,
47
55
  );
@@ -1,26 +1,8 @@
1
- import { EvmHubProvider, getHubChainConfig, type HubChainId } from '@sodax/sdk';
2
- import { getXChainType } from '@sodax/wallet-sdk';
3
- import { useMemo } from 'react';
1
+ import type { EvmHubProvider } from '@sodax/sdk';
4
2
  import { useSodaxContext } from '../shared/useSodaxContext';
5
3
 
6
4
  export function useHubProvider(): EvmHubProvider | undefined {
7
- const { sodax } = useSodaxContext();
8
- const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;
9
- const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;
10
- const xChainType = getXChainType(hubChainId);
11
- const hubProvider = useMemo(() => {
12
- if (xChainType === 'EVM' && hubChainId && hubRpcUrl) {
13
- const hubChainCfg = getHubChainConfig(hubChainId);
14
-
15
- if (!hubChainCfg) return undefined;
16
-
17
- return new EvmHubProvider({
18
- hubRpcUrl: hubRpcUrl,
19
- chainConfig: hubChainCfg,
20
- });
21
- }
22
- return undefined;
23
- }, [xChainType, hubChainId, hubRpcUrl]);
5
+ const { hubProvider } = useSodaxContext();
24
6
 
25
7
  return hubProvider;
26
8
  }
@@ -4,30 +4,76 @@ import {
4
4
  type SuiSpokeChainConfig,
5
5
  SuiSpokeProvider,
6
6
  type EvmSpokeChainConfig,
7
+ IconSpokeProvider,
8
+ type IconSpokeChainConfig,
9
+ CWSpokeProvider,
10
+ type CosmosSpokeChainConfig,
11
+ type SpokeProvider,
12
+ type IWalletProvider,
7
13
  } from '@sodax/sdk';
8
- import type { IEvmWalletProvider, ISuiWalletProvider, SpokeChainId } from '@sodax/types';
14
+ import type {
15
+ IEvmWalletProvider,
16
+ IIconWalletProvider,
17
+ ISuiWalletProvider,
18
+ SpokeChainId,
19
+ IInjectiveWalletProvider,
20
+ } from '@sodax/types';
9
21
  import { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';
10
22
  import { useMemo } from 'react';
11
23
 
12
- export function useSpokeProvider(spokeChainId: SpokeChainId) {
24
+ /**
25
+ * Hook to get the appropriate spoke provider based on the chain type.
26
+ * Supports EVM, SUI, ICON and INJECTIVE chains.
27
+ *
28
+ * @param {SpokeChainId | undefined} spokeChainId - The spoke chain ID to get the provider for
29
+ * @param {IWalletProvider | undefined} walletProvider - The wallet provider to use
30
+ * @returns {SpokeProvider | undefined} The appropriate spoke provider instance for the given chain ID, or undefined if invalid/unsupported
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * // Using a specific SpokeChainId and wallet provider
35
+ * const spokeProvider = useSpokeProvider(spokeChainId, walletProvider);
36
+ * ```
37
+ */
38
+ export function useSpokeProvider(
39
+ spokeChainId: SpokeChainId | undefined,
40
+ walletProvider?: IWalletProvider | undefined,
41
+ ): SpokeProvider | undefined {
13
42
  const xChainType = getXChainType(spokeChainId);
14
- const walletProvider = useWalletProvider(spokeChainId);
43
+ const walletProvider_ = useWalletProvider(spokeChainId);
44
+ const _walletProvider = walletProvider ?? walletProvider_;
45
+
15
46
  const spokeProvider = useMemo(() => {
16
- if (!walletProvider) return undefined;
47
+ if (!_walletProvider) return undefined;
48
+ if (!spokeChainId) return undefined;
49
+
17
50
  if (xChainType === 'EVM') {
18
51
  return new EvmSpokeProvider(
19
- walletProvider as IEvmWalletProvider,
52
+ _walletProvider as IEvmWalletProvider,
20
53
  spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,
21
54
  );
22
55
  }
23
56
  if (xChainType === 'SUI') {
24
57
  return new SuiSpokeProvider(
25
58
  spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,
26
- walletProvider as ISuiWalletProvider,
59
+ _walletProvider as ISuiWalletProvider,
60
+ );
61
+ }
62
+ if (xChainType === 'ICON') {
63
+ return new IconSpokeProvider(
64
+ _walletProvider as IIconWalletProvider,
65
+ spokeChainConfig[spokeChainId] as IconSpokeChainConfig,
27
66
  );
28
67
  }
68
+ if (xChainType === 'INJECTIVE') {
69
+ return new CWSpokeProvider(
70
+ spokeChainConfig[spokeChainId] as CosmosSpokeChainConfig,
71
+ _walletProvider as IInjectiveWalletProvider,
72
+ );
73
+ }
74
+
29
75
  return undefined;
30
- }, [walletProvider, xChainType, spokeChainId]);
76
+ }, [spokeChainId, xChainType, _walletProvider]);
31
77
 
32
78
  return spokeProvider;
33
79
  }
@@ -1,3 +1 @@
1
1
  export * from './useSodaxContext';
2
- export * from './useAllowance';
3
- export * from './useApprove';
@@ -1,15 +1,14 @@
1
1
  import { useSodaxContext } from '../shared/useSodaxContext';
2
2
  import type {
3
3
  CreateIntentParams,
4
- SpokeChainId,
5
4
  IntentExecutionResponse,
6
5
  Result,
7
6
  IntentSubmitErrorCode,
8
7
  Intent,
9
8
  PacketData,
10
9
  IntentSubmitError,
10
+ SpokeProvider,
11
11
  } from '@sodax/sdk';
12
- import { useSpokeProvider } from '../provider/useSpokeProvider';
13
12
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
14
13
 
15
14
  type CreateIntentResult = Result<
@@ -21,12 +20,12 @@ type CreateIntentResult = Result<
21
20
  * Hook for creating and submitting an intent order for cross-chain swaps.
22
21
  * Uses React Query's useMutation for better state management and caching.
23
22
  *
24
- * @param {SpokeChainId} chainId - The source chain ID where the swap will originate
23
+ * @param {SpokeProvider} spokeProvider - The spoke provider to use for the swap
25
24
  * @returns {UseMutationResult} Mutation result object containing mutation function and state
26
25
  *
27
26
  * @example
28
27
  * ```typescript
29
- * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');
28
+ * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder(spokeProvider);
30
29
  *
31
30
  * const handleSwap = async () => {
32
31
  * const result = await createIntent({
@@ -41,10 +40,9 @@ type CreateIntentResult = Result<
41
40
  * ```
42
41
  */
43
42
  export function useCreateIntentOrder(
44
- chainId: SpokeChainId,
43
+ spokeProvider: SpokeProvider | undefined,
45
44
  ): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {
46
45
  const { sodax } = useSodaxContext();
47
- const spokeProvider = useSpokeProvider(chainId);
48
46
 
49
47
  return useMutation<CreateIntentResult, Error, CreateIntentParams>({
50
48
  mutationFn: async (params: CreateIntentParams) => {
@@ -1,7 +1,7 @@
1
1
  import type { ReactNode, ReactElement } from 'react';
2
- import { Sodax, type SodaxConfig } from '@sodax/sdk';
2
+ import { EvmHubProvider, getHubChainConfig, Sodax, type SodaxConfig } from '@sodax/sdk';
3
3
  import { SodaxContext } from '@/contexts';
4
- import React from 'react';
4
+ import React, { useMemo } from 'react';
5
5
 
6
6
  interface SodaxProviderProps {
7
7
  children: ReactNode;
@@ -12,5 +12,20 @@ interface SodaxProviderProps {
12
12
  export const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {
13
13
  const sodax = new Sodax(config);
14
14
 
15
- return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;
15
+ const hubChainId = config?.hubProviderConfig?.chainConfig.chain.id;
16
+ const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;
17
+
18
+ const hubProvider = useMemo(() => {
19
+ if (hubChainId && hubRpcUrl) {
20
+ const hubChainCfg = getHubChainConfig(hubChainId);
21
+
22
+ return new EvmHubProvider({
23
+ hubRpcUrl: hubRpcUrl,
24
+ chainConfig: hubChainCfg,
25
+ });
26
+ }
27
+ return undefined;
28
+ }, [hubChainId, hubRpcUrl]);
29
+
30
+ return <SodaxContext.Provider value={{ sodax, testnet, hubProvider }}>{children}</SodaxContext.Provider>;
16
31
  };
@@ -1,3 +0,0 @@
1
- import type { XToken } from '@sodax/types';
2
- export declare function useAllowance(token: XToken, amount: string): import("@tanstack/react-query").UseQueryResult<boolean, Error>;
3
- //# sourceMappingURL=useAllowance.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAllowance.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/useAllowance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAKzD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kEAwBzD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useApprove.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/useApprove.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAKzD,UAAU,gBAAgB;IACxB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAsC1D"}