@sodax/dapp-kit 0.0.1-rc.16 → 0.0.1-rc.18

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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -27
  3. package/dist/contexts/index.d.ts +2 -0
  4. package/dist/contexts/index.d.ts.map +1 -1
  5. package/dist/hooks/mm/useReservesData.d.ts.map +1 -1
  6. package/dist/hooks/mm/useReservesHumanized.d.ts +21 -0
  7. package/dist/hooks/mm/useReservesHumanized.d.ts.map +1 -0
  8. package/dist/hooks/mm/useReservesList.d.ts +18 -0
  9. package/dist/hooks/mm/useReservesList.d.ts.map +1 -0
  10. package/dist/hooks/mm/useReservesUsdFormat.d.ts +23 -0
  11. package/dist/hooks/mm/useReservesUsdFormat.d.ts.map +1 -0
  12. package/dist/hooks/mm/useUserFormattedSummary.d.ts +22 -0
  13. package/dist/hooks/mm/useUserFormattedSummary.d.ts.map +1 -0
  14. package/dist/hooks/mm/useUserReservesData.d.ts +19 -1
  15. package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
  16. package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
  17. package/dist/hooks/swap/index.d.ts +1 -1
  18. package/dist/hooks/swap/index.d.ts.map +1 -1
  19. package/dist/hooks/swap/{useCreateIntentOrder.d.ts → useSwap.d.ts} +7 -7
  20. package/dist/hooks/swap/useSwap.d.ts.map +1 -0
  21. package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -1
  22. package/dist/hooks/swap/useSwapApprove.d.ts +4 -5
  23. package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -1
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +47 -53
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +48 -54
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/providers/SodaxProvider.d.ts +4 -2
  31. package/dist/providers/SodaxProvider.d.ts.map +1 -1
  32. package/dist/types.d.ts +17 -0
  33. package/dist/types.d.ts.map +1 -0
  34. package/package.json +3 -4
  35. package/src/contexts/index.ts +2 -0
  36. package/src/hooks/mm/useReservesData.ts +1 -8
  37. package/src/hooks/mm/useReservesHumanized.ts +30 -0
  38. package/src/hooks/mm/useReservesList.ts +29 -0
  39. package/src/hooks/mm/useReservesUsdFormat.ts +38 -0
  40. package/src/hooks/mm/useUserFormattedSummary.ts +60 -0
  41. package/src/hooks/mm/useUserReservesData.ts +30 -23
  42. package/src/hooks/provider/useSpokeProvider.ts +23 -14
  43. package/src/hooks/swap/index.ts +1 -1
  44. package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +10 -7
  45. package/src/hooks/swap/useSwapAllowance.ts +4 -1
  46. package/src/hooks/swap/useSwapApprove.ts +14 -14
  47. package/src/index.ts +1 -0
  48. package/src/providers/SodaxProvider.tsx +5 -3
  49. package/src/types.ts +22 -0
  50. package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { useSodaxContext } from '@/index';
1
2
  import {
2
3
  EvmSpokeProvider,
3
4
  spokeChainConfig,
@@ -27,7 +28,6 @@ import type {
27
28
  IStellarWalletProvider,
28
29
  ISolanaWalletProvider,
29
30
  } from '@sodax/types';
30
- import { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';
31
31
  import { useMemo } from 'react';
32
32
 
33
33
  /**
@@ -48,48 +48,52 @@ export function useSpokeProvider(
48
48
  spokeChainId: SpokeChainId | undefined,
49
49
  walletProvider?: IWalletProvider | undefined,
50
50
  ): SpokeProvider | undefined {
51
- const xChainType = getXChainType(spokeChainId);
52
- const walletProvider_ = useWalletProvider(spokeChainId);
53
- const _walletProvider = walletProvider ?? walletProvider_;
51
+ const { rpcConfig } = useSodaxContext();
52
+ const xChainType = spokeChainId ? spokeChainConfig[spokeChainId]?.chain.type : undefined;
54
53
 
55
54
  const spokeProvider = useMemo(() => {
56
- if (!_walletProvider) return undefined;
55
+ if (!walletProvider) return undefined;
57
56
  if (!spokeChainId) return undefined;
57
+ if (!xChainType) return undefined;
58
+ if (!rpcConfig) return undefined;
58
59
 
59
60
  if (xChainType === 'EVM') {
60
61
  if (spokeChainId === SONIC_MAINNET_CHAIN_ID) {
61
62
  return new SonicSpokeProvider(
62
- _walletProvider as IEvmWalletProvider,
63
+ walletProvider as IEvmWalletProvider,
63
64
  spokeChainConfig[spokeChainId] as SonicSpokeChainConfig,
64
65
  );
65
66
  }
66
67
  return new EvmSpokeProvider(
67
- _walletProvider as IEvmWalletProvider,
68
+ walletProvider as IEvmWalletProvider,
68
69
  spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,
69
70
  );
70
71
  }
72
+
71
73
  if (xChainType === 'SUI') {
72
74
  return new SuiSpokeProvider(
73
75
  spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,
74
- _walletProvider as ISuiWalletProvider,
76
+ walletProvider as ISuiWalletProvider,
75
77
  );
76
78
  }
79
+
77
80
  if (xChainType === 'ICON') {
78
81
  return new IconSpokeProvider(
79
- _walletProvider as IIconWalletProvider,
82
+ walletProvider as IIconWalletProvider,
80
83
  spokeChainConfig[spokeChainId] as IconSpokeChainConfig,
81
84
  );
82
85
  }
86
+
83
87
  if (xChainType === 'INJECTIVE') {
84
88
  return new InjectiveSpokeProvider(
85
89
  spokeChainConfig[spokeChainId] as InjectiveSpokeChainConfig,
86
- _walletProvider as IInjectiveWalletProvider,
90
+ walletProvider as IInjectiveWalletProvider,
87
91
  );
88
92
  }
89
93
 
90
94
  if (xChainType === 'STELLAR') {
91
95
  const stellarConfig = spokeChainConfig[spokeChainId] as StellarSpokeChainConfig;
92
- return new StellarSpokeProvider(_walletProvider as IStellarWalletProvider, stellarConfig, {
96
+ return new StellarSpokeProvider(walletProvider as IStellarWalletProvider, stellarConfig, {
93
97
  horizonRpcUrl: stellarConfig.horizonRpcUrl,
94
98
  sorobanRpcUrl: stellarConfig.sorobanRpcUrl,
95
99
  });
@@ -97,13 +101,18 @@ export function useSpokeProvider(
97
101
 
98
102
  if (xChainType === 'SOLANA') {
99
103
  return new SolanaSpokeProvider(
100
- _walletProvider as ISolanaWalletProvider,
101
- spokeChainConfig[spokeChainId] as SolanaChainConfig,
104
+ walletProvider as ISolanaWalletProvider,
105
+ rpcConfig.solana
106
+ ? ({
107
+ ...spokeChainConfig[spokeChainId],
108
+ rpcUrl: rpcConfig.solana,
109
+ } as SolanaChainConfig)
110
+ : (spokeChainConfig[spokeChainId] as SolanaChainConfig),
102
111
  );
103
112
  }
104
113
 
105
114
  return undefined;
106
- }, [spokeChainId, xChainType, _walletProvider]);
115
+ }, [spokeChainId, xChainType, walletProvider, rpcConfig]);
107
116
 
108
117
  return spokeProvider;
109
118
  }
@@ -1,5 +1,5 @@
1
1
  export * from './useQuote';
2
- export * from './useCreateIntentOrder';
2
+ export * from './useSwap';
3
3
  export * from './useStatus';
4
4
  export * from './useSwapAllowance';
5
5
  export * from './useSwapApprove';
@@ -7,14 +7,14 @@ import type {
7
7
  Intent,
8
8
  IntentError,
9
9
  SpokeProvider,
10
- Hex,
10
+ IntentDeliveryInfo,
11
11
  } from '@sodax/sdk';
12
12
  import { useMutation, type UseMutationResult } from '@tanstack/react-query';
13
13
 
14
- type CreateIntentResult = Result<[SolverExecutionResponse, Intent, Hex], IntentError<IntentErrorCode>>;
14
+ type CreateIntentResult = Result<[SolverExecutionResponse, Intent, IntentDeliveryInfo], IntentError<IntentErrorCode>>;
15
15
 
16
16
  /**
17
- * Hook for creating and submitting an intent order for cross-chain swaps.
17
+ * Hook for creating and submitting an swap intent order for cross-chain swaps.
18
18
  * Uses React Query's useMutation for better state management and caching.
19
19
  *
20
20
  * @param {SpokeProvider} spokeProvider - The spoke provider to use for the swap
@@ -22,10 +22,10 @@ type CreateIntentResult = Result<[SolverExecutionResponse, Intent, Hex], IntentE
22
22
  *
23
23
  * @example
24
24
  * ```typescript
25
- * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder(spokeProvider);
25
+ * const { mutateAsync: swap, isPending } = useSwap(spokeProvider);
26
26
  *
27
27
  * const handleSwap = async () => {
28
- * const result = await createIntent({
28
+ * const result = await swap({
29
29
  * token_src: '0x...',
30
30
  * token_src_blockchain_id: 'arbitrum',
31
31
  * token_dst: '0x...',
@@ -36,7 +36,7 @@ type CreateIntentResult = Result<[SolverExecutionResponse, Intent, Hex], IntentE
36
36
  * };
37
37
  * ```
38
38
  */
39
- export function useCreateIntentOrder(
39
+ export function useSwap(
40
40
  spokeProvider: SpokeProvider | undefined,
41
41
  ): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {
42
42
  const { sodax } = useSodaxContext();
@@ -46,7 +46,10 @@ export function useCreateIntentOrder(
46
46
  if (!spokeProvider) {
47
47
  throw new Error('Spoke provider not found');
48
48
  }
49
- return sodax.solver.createAndSubmitIntent(params, spokeProvider);
49
+ return sodax.solver.swap({
50
+ intentParams: params,
51
+ spokeProvider,
52
+ });
50
53
  },
51
54
  });
52
55
  }
@@ -33,7 +33,10 @@ export function useSwapAllowance(
33
33
  if (!spokeProvider || !params) {
34
34
  return false;
35
35
  }
36
- const allowance = await sodax.solver.isAllowanceValid(params, spokeProvider);
36
+ const allowance = await sodax.solver.isAllowanceValid({
37
+ intentParams: params,
38
+ spokeProvider,
39
+ });
37
40
  if (allowance.ok) {
38
41
  return allowance.value;
39
42
  }
@@ -1,11 +1,9 @@
1
1
  import { useSodaxContext } from '../shared/useSodaxContext';
2
- import type { Token } from '@sodax/types';
3
- import { type Address, parseUnits } from 'viem';
4
2
  import { useMutation, useQueryClient } from '@tanstack/react-query';
5
- import type { SpokeProvider } from '@sodax/sdk';
3
+ import type { CreateIntentParams, SpokeProvider } from '@sodax/sdk';
6
4
 
7
5
  interface UseApproveReturn {
8
- approve: ({ amount }: { amount: string }) => Promise<boolean>;
6
+ approve: ({ params }: { params: CreateIntentParams }) => Promise<boolean>;
9
7
  isLoading: boolean;
10
8
  error: Error | null;
11
9
  resetError: () => void;
@@ -25,7 +23,10 @@ interface UseApproveReturn {
25
23
  * ```
26
24
  */
27
25
 
28
- export function useSwapApprove(token: Token | undefined, spokeProvider: SpokeProvider | undefined): UseApproveReturn {
26
+ export function useSwapApprove(
27
+ params: CreateIntentParams | undefined,
28
+ spokeProvider: SpokeProvider | undefined,
29
+ ): UseApproveReturn {
29
30
  const { sodax } = useSodaxContext();
30
31
  const queryClient = useQueryClient();
31
32
 
@@ -35,27 +36,26 @@ export function useSwapApprove(token: Token | undefined, spokeProvider: SpokePro
35
36
  error,
36
37
  reset: resetError,
37
38
  } = useMutation({
38
- mutationFn: async ({ amount }: { amount: string }) => {
39
+ mutationFn: async ({ params }: { params: CreateIntentParams | undefined }) => {
39
40
  if (!spokeProvider) {
40
41
  throw new Error('Spoke provider not found');
41
42
  }
42
- if (!token) {
43
- throw new Error('Token not found');
43
+ if (!params) {
44
+ throw new Error('Swap Params not found');
44
45
  }
45
46
 
46
- const allowance = await sodax.solver.approve(
47
- token.address as Address,
48
- parseUnits(amount, token.decimals),
47
+ const allowance = await sodax.solver.approve({
48
+ intentParams: params,
49
49
  spokeProvider,
50
- );
50
+ });
51
51
  if (!allowance.ok) {
52
- throw new Error('Failed to approve tokens');
52
+ throw new Error('Failed to approve input token');
53
53
  }
54
54
  return allowance.ok;
55
55
  },
56
56
  onSuccess: () => {
57
57
  // Invalidate allowance query to refetch the new allowance
58
- queryClient.invalidateQueries({ queryKey: ['allowance', token?.address] });
58
+ queryClient.invalidateQueries({ queryKey: ['allowance', params?.inputToken] });
59
59
  },
60
60
  });
61
61
 
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './hooks';
2
2
  export * from './providers';
3
3
  export * from './core';
4
+ export * from './types';
@@ -2,14 +2,16 @@ import type { ReactNode, ReactElement } from 'react';
2
2
  import { EvmHubProvider, getHubChainConfig, Sodax, type SodaxConfig } from '@sodax/sdk';
3
3
  import { SodaxContext } from '@/contexts';
4
4
  import React, { useMemo } from 'react';
5
+ import type { RpcConfig } from '@/types';
5
6
 
6
7
  interface SodaxProviderProps {
7
8
  children: ReactNode;
8
9
  testnet?: boolean;
9
- config: SodaxConfig;
10
+ config?: SodaxConfig;
11
+ rpcConfig: RpcConfig;
10
12
  }
11
13
 
12
- export const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {
14
+ export const SodaxProvider = ({ children, testnet = false, config, rpcConfig }: SodaxProviderProps): ReactElement => {
13
15
  const sodax = new Sodax(config);
14
16
 
15
17
  const hubChainId = config?.hubProviderConfig?.chainConfig.chain.id;
@@ -27,5 +29,5 @@ export const SodaxProvider = ({ children, testnet = false, config }: SodaxProvid
27
29
  return undefined;
28
30
  }, [hubChainId, hubRpcUrl]);
29
31
 
30
- return <SodaxContext.Provider value={{ sodax, testnet, hubProvider }}>{children}</SodaxContext.Provider>;
32
+ return <SodaxContext.Provider value={{ sodax, testnet, hubProvider, rpcConfig }}>{children}</SodaxContext.Provider>;
31
33
  };
package/src/types.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { StellarRpcConfig } from '@sodax/sdk';
2
+
3
+ export type RpcConfig = {
4
+ // EVM chains - all use string RPC URLs
5
+ sonic?: string;
6
+ '0xa86a.avax'?: string;
7
+ '0xa4b1.arbitrum'?: string;
8
+ '0x2105.base'?: string;
9
+ '0x38.bsc'?: string;
10
+ '0xa.optimism'?: string;
11
+ '0x89.polygon'?: string;
12
+ nibiru?: string;
13
+
14
+ // Other chains - all use string RPC URLs
15
+ 'injective-1'?: string;
16
+ sui?: string;
17
+ solana?: string;
18
+ '0x1.icon'?: string;
19
+
20
+ // Stellar - uses object with horizon and soroban RPC URLs
21
+ stellar?: StellarRpcConfig;
22
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCreateIntentOrder.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useCreateIntentOrder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,EACN,eAAe,EACf,MAAM,EACN,WAAW,EACX,aAAa,EACb,GAAG,EACJ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,KAAK,kBAAkB,GAAG,MAAM,CAAC,CAAC,uBAAuB,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC;AAEvG;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,kBAAkB,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAWlE"}