@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2025] [Sodax]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -10,14 +10,18 @@ dApp Kit is a collection of React components, hooks, and utilities designed to s
10
10
  - Withdraw tokens from the money market (`useWithdraw`)
11
11
  - Borrow tokens from the money market (`useBorrow`)
12
12
  - Repay borrowed tokens (`useRepay`)
13
- - Get user reserves data (`useUserReservesData`)
14
- - Get reserves data (`useReservesData`)
15
13
  - Check token allowance (`useMMAllowance`)
16
14
  - Approve token spending (`useMMApprove`)
15
+ - Get user reserves data (`useUserReservesData`)
16
+ - Get reserves data (`useReservesData`)
17
+ - Get humanized reserves data (`useReservesHumanized`)
18
+ - Get list of reserves (`useReservesList`)
19
+ - Get USD formatted reserves data (`useReservesUsdFormat`)
20
+ - Get formatted user portfolio summary (`useUserFormattedSummary`)
17
21
 
18
22
  - Swap/Intent
19
23
  - Get quote for an intent order (`useQuote`)
20
- - Create and submit an intent order (`useCreateIntentOrder`)
24
+ - Create and submit an swap intent order (`useSwap`)
21
25
  - Get status of an intent order (`useStatus`)
22
26
  - Check token allowance (`useSwapAllowance`)
23
27
  - Approve token spending (`useSwapApprove`)
@@ -42,7 +46,7 @@ pnpm add @sodax/dapp-kit
42
46
  1. First, install the required dependencies:
43
47
 
44
48
  ```bash
45
- npm install @sodax/dapp-kit @tanstack/react-query @sodax/wallet-sdk
49
+ pnpm install @sodax/dapp-kit @tanstack/react-query @sodax/wallet-sdk
46
50
  ```
47
51
 
48
52
  2. Set up the providers in your app:
@@ -51,31 +55,16 @@ npm install @sodax/dapp-kit @tanstack/react-query @sodax/wallet-sdk
51
55
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
52
56
  import { XWagmiProviders } from '@sodax/wallet-sdk';
53
57
  import { SodaxProvider } from '@sodax/dapp-kit';
54
- import { SONIC_MAINNET_CHAIN_ID } from '@sodax/types';
55
58
 
56
59
  const queryClient = new QueryClient();
57
60
 
58
- // Configure Sodax
59
- const sodaxConfig = {
60
- hubProviderConfig: {
61
- hubRpcUrl: 'https://rpc.soniclabs.com',
62
- chainConfig: getHubChainConfig(SONIC_MAINNET_CHAIN_ID),
63
- },
64
- moneyMarket: getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID),
65
- solver: {
66
- intentsContract: '0x6382D6ccD780758C5e8A6123c33ee8F4472F96ef',
67
- solverApiEndpoint: 'https://sodax-solver-staging.iconblockchain.xyz',
68
- partnerFee: {
69
- address: '0x0Ab764AB3816cD036Ea951bE973098510D8105A6',
70
- percentage: 100, // 1%
71
- },
72
- },
73
- relayerApiEndpoint: 'https://xcall-relay.nw.iconblockchain.xyz',
61
+ const rpcConfig = {
62
+ "solana": "private rpc url",
74
63
  };
75
64
 
76
65
  function App() {
77
66
  return (
78
- <SodaxProvider testnet={false} config={sodaxConfig}>
67
+ <SodaxProvider testnet={false} rpcConfig={rpcConfig}>
79
68
  <QueryClientProvider client={queryClient}>
80
69
  <XWagmiProviders
81
70
  config={{
@@ -159,7 +148,7 @@ function TokenManagementComponent() {
159
148
  }
160
149
 
161
150
  // Swap Operations
162
- import { useQuote, useCreateIntentOrder, useStatus } from '@sodax/dapp-kit';
151
+ import { useQuote, useSwap, useStatus } from '@sodax/dapp-kit';
163
152
 
164
153
  function SwapComponent() {
165
154
  // Get quote for an intent order
@@ -173,9 +162,9 @@ function SwapComponent() {
173
162
  });
174
163
 
175
164
  // Create and submit an intent order
176
- const { mutateAsync: createOrder, isPending: isCreating } = useCreateIntentOrder();
177
- const handleCreateOrder = async () => {
178
- const order = await createOrder({
165
+ const { mutateAsync: swap, isPending: isCreating } = useSwap();
166
+ const handleSwap = async () => {
167
+ const order = await swap({
179
168
  token_src: '0x...',
180
169
  token_src_blockchain_id: '0xa86a.avax',
181
170
  token_dst: '0x...',
@@ -216,7 +205,7 @@ function SwapComponent() {
216
205
 
217
206
  #### Swap Hooks
218
207
  - [`useQuote()`](./src/hooks/swap/useQuote.ts) - Get quote for an intent order
219
- - [`useCreateIntentOrder()`](./src/hooks/swap/useCreateIntentOrder.ts) - Create and submit an intent order
208
+ - [`useSwap()`](./src/hooks/swap/useSwap.ts) - Create and submit an intent order
220
209
  - [`useStatus()`](./src/hooks/swap/useStatus.ts) - Get status of an intent order
221
210
  - [`useSwapAllowance()`](./src/hooks/swap/useSwapAllowance.ts) - Check token allowance for an intent order
222
211
  - [`useSwapApprove()`](./src/hooks/swap/useSwapApprove.ts) - Approve token spending
@@ -1,8 +1,10 @@
1
1
  import type { EvmHubProvider, Sodax } from '@sodax/sdk';
2
+ import type { RpcConfig } from '@/types';
2
3
  export interface SodaxContextType {
3
4
  sodax: Sodax;
4
5
  testnet: boolean;
5
6
  hubProvider: EvmHubProvider | undefined;
7
+ rpcConfig: RpcConfig;
6
8
  }
7
9
  export declare const SodaxContext: import("react").Context<SodaxContextType | null>;
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC;CACzC;AAED,eAAO,MAAM,YAAY,kDAA+C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,cAAc,GAAG,SAAS,CAAC;IACxC,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,YAAY,kDAA+C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useReservesData.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,eAAe,mKAc9B"}
1
+ {"version":3,"file":"useReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useReservesData.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,eAAe,mKAS9B"}
@@ -0,0 +1,21 @@
1
+ import type { ReservesDataHumanized } from '@sodax/sdk';
2
+ import { type UseQueryResult } from '@tanstack/react-query';
3
+ /**
4
+ * Hook for fetching humanized reserves data from the Sodax money market.
5
+ *
6
+ * This hook provides access to the current state of all reserves (humanized format) in the money market protocol,
7
+ * including liquidity, interest rates, and other key metrics. The data is automatically
8
+ * fetched and cached using React Query.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const { data: reservesHumanized, isLoading, error } = useReservesHumanized();
13
+ * ```
14
+ *
15
+ * @returns A React Query result object containing:
16
+ * - data: The reserves humanized data when available
17
+ * - isLoading: Loading state indicator
18
+ * - error: Any error that occurred during data fetching
19
+ */
20
+ export declare function useReservesHumanized(): UseQueryResult<ReservesDataHumanized, Error>;
21
+ //# sourceMappingURL=useReservesHumanized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReservesHumanized.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useReservesHumanized.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAAC,qBAAqB,EAAE,KAAK,CAAC,CASnF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Hook for fetching list of reserves from the Sodax money market.
3
+ *
4
+ * This hook provides access to the list of addresses of all reserves in the money market protocol.
5
+ * The data is automatically fetched and cached using React Query.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const { data: reservesList, isLoading, error } = useReservesList();
10
+ * ```
11
+ *
12
+ * @returns A React Query result object containing:
13
+ * - data: The reserves list when available
14
+ * - isLoading: Loading state indicator
15
+ * - error: Any error that occurred during data fetching
16
+ */
17
+ export declare function useReservesList(): import("@tanstack/react-query").UseQueryResult<readonly `0x${string}`[], Error>;
18
+ //# sourceMappingURL=useReservesList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReservesList.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useReservesList.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,oFAS9B"}
@@ -0,0 +1,23 @@
1
+ import type { FormatReserveUSDResponse, ReserveData } from '@sodax/sdk';
2
+ import { type UseQueryResult } from '@tanstack/react-query';
3
+ /**
4
+ * Hook for fetching formatted summary of Sodax user portfolio (holdings, total liquidity,
5
+ * collateral, borrows, liquidation threshold, health factor, available borrowing power, etc..).
6
+ *
7
+ * This hook provides access to the current state of user portfolio in the money market protocol.
8
+ * The data is automatically fetched and cached using React Query.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const { data: userFormattedSummary, isLoading, error } = useUserFormattedSummary();
13
+ * ```
14
+ *
15
+ * @returns A React Query result object containing:
16
+ * - data: The formatted summary of Sodax user portfolio when available
17
+ * - isLoading: Loading state indicator
18
+ * - error: Any error that occurred during data fetching
19
+ */
20
+ export declare function useReservesUsdFormat(): UseQueryResult<(ReserveData & {
21
+ priceInMarketReferenceCurrency: string;
22
+ } & FormatReserveUSDResponse)[], Error>;
23
+ //# sourceMappingURL=useReservesUsdFormat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReservesUsdFormat.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useReservesUsdFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGtE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CACpD,CAAC,WAAW,GAAG;IAAE,8BAA8B,EAAE,MAAM,CAAA;CAAE,GAAG,wBAAwB,CAAC,EAAE,EACvF,KAAK,CACN,CAaA"}
@@ -0,0 +1,22 @@
1
+ import { type FormatUserSummaryResponse, type FormatReserveUSDResponse } from '@sodax/sdk';
2
+ import type { ChainId } from '@sodax/types';
3
+ import { type UseQueryResult } from '@tanstack/react-query';
4
+ /**
5
+ * Hook for fetching formatted summary of Sodax user portfolio (holdings, total liquidity,
6
+ * collateral, borrows, liquidation threshold, health factor, available borrowing power, etc..).
7
+ *
8
+ * This hook provides access to the current state of user portfolio in the money market protocol.
9
+ * The data is automatically fetched and cached using React Query.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const { data: userFormattedSummary, isLoading, error } = useUserFormattedSummary();
14
+ * ```
15
+ *
16
+ * @returns A React Query result object containing:
17
+ * - data: The formatted summary of Sodax user portfolio when available
18
+ * - isLoading: Loading state indicator
19
+ * - error: Any error that occurred during data fetching
20
+ */
21
+ export declare function useUserFormattedSummary(spokeChainId: ChainId | undefined, address: string | undefined): UseQueryResult<FormatUserSummaryResponse<FormatReserveUSDResponse> | undefined, Error>;
22
+ //# sourceMappingURL=useUserFormattedSummary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUserFormattedSummary.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserFormattedSummary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,yBAAyB,EAAE,KAAK,wBAAwB,EAA4B,MAAM,YAAY,CAAC;AACrH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAItE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,OAAO,GAAG,SAAS,EACjC,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,cAAc,CAAC,yBAAyB,CAAC,wBAAwB,CAAC,GAAG,SAAS,EAAE,KAAK,CAAC,CAiCxF"}
@@ -1,3 +1,21 @@
1
+ import { type UserReserveData } from '@sodax/sdk';
1
2
  import type { ChainId } from '@sodax/types';
2
- export declare function useUserReservesData(spokeChainId: ChainId, address: string | undefined): readonly import("@sodax/sdk").UserReserveData[] | undefined;
3
+ import { type UseQueryResult } from '@tanstack/react-query';
4
+ /**
5
+ * Hook for fetching user reserves data from the Sodax money market.
6
+ *
7
+ * This hook provides access to the current state of user reserves in the money market protocol.
8
+ * The data is automatically fetched and cached using React Query.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const { data: userReservesData, isLoading, error } = useUserReservesData();
13
+ * ```
14
+ *
15
+ * @returns A React Query result object containing:
16
+ * - data: The user reserves data when available
17
+ * - isLoading: Loading state indicator
18
+ * - error: Any error that occurred during data fetching
19
+ */
20
+ export declare function useUserReservesData(spokeChainId: ChainId | undefined, address: string | undefined, refetchInterval?: number): UseQueryResult<readonly [readonly UserReserveData[], number] | undefined, Error>;
3
21
  //# sourceMappingURL=useUserReservesData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useUserReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserReservesData.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAM5C,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,+DAiCrF"}
1
+ {"version":3,"file":"useUserReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserReservesData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAA4B,MAAM,YAAY,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAItE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,OAAO,GAAG,SAAS,EACjC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,eAAe,SAAO,GACrB,cAAc,CAAC,SAAS,CAAC,SAAS,eAAe,EAAE,EAAE,MAAM,CAAC,GAAG,SAAS,EAAE,KAAK,CAAC,CAsBlF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSpokeProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/provider/useSpokeProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,KAAK,aAAa,EAClB,KAAK,eAAe,EAMrB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAIV,YAAY,EAIb,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,cAAc,CAAC,EAAE,eAAe,GAAG,SAAS,GAC3C,aAAa,GAAG,SAAS,CA2D3B"}
1
+ {"version":3,"file":"useSpokeProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/provider/useSpokeProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAYL,KAAK,aAAa,EAClB,KAAK,eAAe,EAMrB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAIV,YAAY,EAIb,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,cAAc,CAAC,EAAE,eAAe,GAAG,SAAS,GAC3C,aAAa,GAAG,SAAS,CAoE3B"}
@@ -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';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC"}
@@ -1,8 +1,8 @@
1
- import type { CreateIntentParams, SolverExecutionResponse, Result, IntentErrorCode, Intent, IntentError, SpokeProvider, Hex } from '@sodax/sdk';
1
+ import type { CreateIntentParams, SolverExecutionResponse, Result, IntentErrorCode, Intent, IntentError, SpokeProvider, IntentDeliveryInfo } from '@sodax/sdk';
2
2
  import { type UseMutationResult } from '@tanstack/react-query';
3
- type CreateIntentResult = Result<[SolverExecutionResponse, Intent, Hex], IntentError<IntentErrorCode>>;
3
+ type CreateIntentResult = Result<[SolverExecutionResponse, Intent, IntentDeliveryInfo], IntentError<IntentErrorCode>>;
4
4
  /**
5
- * Hook for creating and submitting an intent order for cross-chain swaps.
5
+ * Hook for creating and submitting an swap intent order for cross-chain swaps.
6
6
  * Uses React Query's useMutation for better state management and caching.
7
7
  *
8
8
  * @param {SpokeProvider} spokeProvider - The spoke provider to use for the swap
@@ -10,10 +10,10 @@ type CreateIntentResult = Result<[SolverExecutionResponse, Intent, Hex], IntentE
10
10
  *
11
11
  * @example
12
12
  * ```typescript
13
- * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder(spokeProvider);
13
+ * const { mutateAsync: swap, isPending } = useSwap(spokeProvider);
14
14
  *
15
15
  * const handleSwap = async () => {
16
- * const result = await createIntent({
16
+ * const result = await swap({
17
17
  * token_src: '0x...',
18
18
  * token_src_blockchain_id: 'arbitrum',
19
19
  * token_dst: '0x...',
@@ -24,6 +24,6 @@ type CreateIntentResult = Result<[SolverExecutionResponse, Intent, Hex], IntentE
24
24
  * };
25
25
  * ```
26
26
  */
27
- export declare function useCreateIntentOrder(spokeProvider: SpokeProvider | undefined): UseMutationResult<CreateIntentResult, Error, CreateIntentParams>;
27
+ export declare function useSwap(spokeProvider: SpokeProvider | undefined): UseMutationResult<CreateIntentResult, Error, CreateIntentParams>;
28
28
  export {};
29
- //# sourceMappingURL=useCreateIntentOrder.d.ts.map
29
+ //# sourceMappingURL=useSwap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSwap.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useSwap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,EACN,eAAe,EACf,MAAM,EACN,WAAW,EACX,aAAa,EACb,kBAAkB,EACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,KAAK,kBAAkB,GAAG,MAAM,CAAC,CAAC,uBAAuB,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC;AAEtH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,OAAO,CACrB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,kBAAkB,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAclE"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSwapAllowance.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useSwapAllowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAiBhC"}
1
+ {"version":3,"file":"useSwapAllowance.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useSwapAllowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAoBhC"}
@@ -1,8 +1,7 @@
1
- import type { Token } from '@sodax/types';
2
- import type { SpokeProvider } from '@sodax/sdk';
1
+ import type { CreateIntentParams, SpokeProvider } from '@sodax/sdk';
3
2
  interface UseApproveReturn {
4
- approve: ({ amount }: {
5
- amount: string;
3
+ approve: ({ params }: {
4
+ params: CreateIntentParams;
6
5
  }) => Promise<boolean>;
7
6
  isLoading: boolean;
8
7
  error: Error | null;
@@ -21,6 +20,6 @@ interface UseApproveReturn {
21
20
  * await approve({ amount: "100", action: "supply" });
22
21
  * ```
23
22
  */
24
- export declare function useSwapApprove(token: Token | undefined, spokeProvider: SpokeProvider | undefined): UseApproveReturn;
23
+ export declare function useSwapApprove(params: CreateIntentParams | undefined, spokeProvider: SpokeProvider | undefined): UseApproveReturn;
25
24
  export {};
26
25
  //# sourceMappingURL=useSwapApprove.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSwapApprove.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useSwapApprove.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,UAAU,gBAAgB;IACxB,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9D,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;GAYG;AAEH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,aAAa,EAAE,aAAa,GAAG,SAAS,GAAG,gBAAgB,CAwCnH"}
1
+ {"version":3,"file":"useSwapApprove.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useSwapApprove.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpE,UAAU,gBAAgB;IACxB,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,kBAAkB,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1E,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;GAYG;AAEH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,gBAAgB,CAuClB"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './hooks';
2
2
  export * from './providers';
3
3
  export * from './core';
4
+ export * from './types';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  var React = require('react');
4
4
  var sdk = require('@sodax/sdk');
5
5
  var reactQuery = require('@tanstack/react-query');
6
- var walletSdk = require('@sodax/wallet-sdk');
7
6
  var viem = require('viem');
8
7
 
9
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -37,57 +36,61 @@ function useHubProvider() {
37
36
  return hubProvider;
38
37
  }
39
38
  function useSpokeProvider(spokeChainId, walletProvider) {
40
- const xChainType = walletSdk.getXChainType(spokeChainId);
41
- const walletProvider_ = walletSdk.useWalletProvider(spokeChainId);
42
- const _walletProvider = walletProvider ?? walletProvider_;
39
+ const { rpcConfig } = useSodaxContext();
40
+ const xChainType = spokeChainId ? sdk.spokeChainConfig[spokeChainId]?.chain.type : void 0;
43
41
  const spokeProvider = React.useMemo(() => {
44
- if (!_walletProvider) return void 0;
42
+ if (!walletProvider) return void 0;
45
43
  if (!spokeChainId) return void 0;
44
+ if (!xChainType) return void 0;
45
+ if (!rpcConfig) return void 0;
46
46
  if (xChainType === "EVM") {
47
47
  if (spokeChainId === sdk.SONIC_MAINNET_CHAIN_ID) {
48
48
  return new sdk.SonicSpokeProvider(
49
- _walletProvider,
49
+ walletProvider,
50
50
  sdk.spokeChainConfig[spokeChainId]
51
51
  );
52
52
  }
53
53
  return new sdk.EvmSpokeProvider(
54
- _walletProvider,
54
+ walletProvider,
55
55
  sdk.spokeChainConfig[spokeChainId]
56
56
  );
57
57
  }
58
58
  if (xChainType === "SUI") {
59
59
  return new sdk.SuiSpokeProvider(
60
60
  sdk.spokeChainConfig[spokeChainId],
61
- _walletProvider
61
+ walletProvider
62
62
  );
63
63
  }
64
64
  if (xChainType === "ICON") {
65
65
  return new sdk.IconSpokeProvider(
66
- _walletProvider,
66
+ walletProvider,
67
67
  sdk.spokeChainConfig[spokeChainId]
68
68
  );
69
69
  }
70
70
  if (xChainType === "INJECTIVE") {
71
71
  return new sdk.InjectiveSpokeProvider(
72
72
  sdk.spokeChainConfig[spokeChainId],
73
- _walletProvider
73
+ walletProvider
74
74
  );
75
75
  }
76
76
  if (xChainType === "STELLAR") {
77
77
  const stellarConfig = sdk.spokeChainConfig[spokeChainId];
78
- return new sdk.StellarSpokeProvider(_walletProvider, stellarConfig, {
78
+ return new sdk.StellarSpokeProvider(walletProvider, stellarConfig, {
79
79
  horizonRpcUrl: stellarConfig.horizonRpcUrl,
80
80
  sorobanRpcUrl: stellarConfig.sorobanRpcUrl
81
81
  });
82
82
  }
83
83
  if (xChainType === "SOLANA") {
84
84
  return new sdk.SolanaSpokeProvider(
85
- _walletProvider,
86
- sdk.spokeChainConfig[spokeChainId]
85
+ walletProvider,
86
+ rpcConfig.solana ? {
87
+ ...sdk.spokeChainConfig[spokeChainId],
88
+ rpcUrl: rpcConfig.solana
89
+ } : sdk.spokeChainConfig[spokeChainId]
87
90
  );
88
91
  }
89
92
  return void 0;
90
- }, [spokeChainId, xChainType, _walletProvider]);
93
+ }, [spokeChainId, xChainType, walletProvider, rpcConfig]);
91
94
  return spokeProvider;
92
95
  }
93
96
  function useBorrow(spokeToken, spokeProvider) {
@@ -183,46 +186,32 @@ function useWithdraw(spokeToken, spokeProvider) {
183
186
  }
184
187
  });
185
188
  }
186
- function useUserReservesData(spokeChainId, address) {
189
+ function useUserReservesData(spokeChainId, address, refetchInterval = 5e3) {
187
190
  const { sodax } = useSodaxContext();
188
- const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? "sonic";
189
- const hubProvider = useHubProvider();
190
191
  const spokeProvider = useSpokeProvider(spokeChainId);
191
- const { data: userReserves } = reactQuery.useQuery({
192
+ return reactQuery.useQuery({
192
193
  queryKey: ["userReserves", spokeChainId, address],
193
194
  queryFn: async () => {
194
- if (!hubProvider || !spokeProvider || !address) {
195
- return;
195
+ if (!spokeProvider || !address) {
196
+ return void 0;
196
197
  }
197
198
  const hubWalletAddress = await sdk.WalletAbstractionService.getUserHubWalletAddress(
198
199
  address,
199
200
  spokeProvider,
200
- hubProvider
201
+ sodax.hubProvider
201
202
  );
202
- const moneyMarketConfig = sdk.getMoneyMarketConfig(hubChainId);
203
- const [res] = await sodax.moneyMarket.getUserReservesData(
204
- hubWalletAddress,
205
- moneyMarketConfig.uiPoolDataProvider,
206
- moneyMarketConfig.poolAddressesProvider
207
- );
208
- return res;
203
+ return await sodax.moneyMarket.data.getUserReservesData(hubWalletAddress);
209
204
  },
210
- enabled: !!spokeChainId && !!hubProvider && !!address,
211
- refetchInterval: 5e3
205
+ enabled: !!spokeChainId && !!address,
206
+ refetchInterval
212
207
  });
213
- return userReserves;
214
208
  }
215
209
  function useReservesData() {
216
210
  const { sodax } = useSodaxContext();
217
- const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? "sonic";
218
211
  return reactQuery.useQuery({
219
212
  queryKey: ["reservesData"],
220
213
  queryFn: async () => {
221
- const moneyMarketConfig = sdk.getMoneyMarketConfig(hubChainId);
222
- return await sodax.moneyMarket.getReservesData(
223
- moneyMarketConfig.uiPoolDataProvider,
224
- moneyMarketConfig.poolAddressesProvider
225
- );
214
+ return await sodax.moneyMarket.data.getReservesData();
226
215
  }
227
216
  });
228
217
  }
@@ -299,14 +288,17 @@ var useQuote = (payload) => {
299
288
  refetchInterval: 3e3
300
289
  });
301
290
  };
302
- function useCreateIntentOrder(spokeProvider) {
291
+ function useSwap(spokeProvider) {
303
292
  const { sodax } = useSodaxContext();
304
293
  return reactQuery.useMutation({
305
294
  mutationFn: async (params) => {
306
295
  if (!spokeProvider) {
307
296
  throw new Error("Spoke provider not found");
308
297
  }
309
- return sodax.solver.createAndSubmitIntent(params, spokeProvider);
298
+ return sodax.solver.swap({
299
+ intentParams: params,
300
+ spokeProvider
301
+ });
310
302
  }
311
303
  });
312
304
  }
@@ -329,7 +321,10 @@ function useSwapAllowance(params, spokeProvider) {
329
321
  if (!spokeProvider || !params) {
330
322
  return false;
331
323
  }
332
- const allowance = await sodax.solver.isAllowanceValid(params, spokeProvider);
324
+ const allowance = await sodax.solver.isAllowanceValid({
325
+ intentParams: params,
326
+ spokeProvider
327
+ });
333
328
  if (allowance.ok) {
334
329
  return allowance.value;
335
330
  }
@@ -338,7 +333,7 @@ function useSwapAllowance(params, spokeProvider) {
338
333
  enabled: !!spokeProvider && !!params
339
334
  });
340
335
  }
341
- function useSwapApprove(token, spokeProvider) {
336
+ function useSwapApprove(params, spokeProvider) {
342
337
  const { sodax } = useSodaxContext();
343
338
  const queryClient = reactQuery.useQueryClient();
344
339
  const {
@@ -347,25 +342,24 @@ function useSwapApprove(token, spokeProvider) {
347
342
  error,
348
343
  reset: resetError
349
344
  } = reactQuery.useMutation({
350
- mutationFn: async ({ amount }) => {
345
+ mutationFn: async ({ params: params2 }) => {
351
346
  if (!spokeProvider) {
352
347
  throw new Error("Spoke provider not found");
353
348
  }
354
- if (!token) {
355
- throw new Error("Token not found");
349
+ if (!params2) {
350
+ throw new Error("Swap Params not found");
356
351
  }
357
- const allowance = await sodax.solver.approve(
358
- token.address,
359
- viem.parseUnits(amount, token.decimals),
352
+ const allowance = await sodax.solver.approve({
353
+ intentParams: params2,
360
354
  spokeProvider
361
- );
355
+ });
362
356
  if (!allowance.ok) {
363
- throw new Error("Failed to approve tokens");
357
+ throw new Error("Failed to approve input token");
364
358
  }
365
359
  return allowance.ok;
366
360
  },
367
361
  onSuccess: () => {
368
- queryClient.invalidateQueries({ queryKey: ["allowance", token?.address] });
362
+ queryClient.invalidateQueries({ queryKey: ["allowance", params?.inputToken] });
369
363
  }
370
364
  });
371
365
  return {
@@ -375,7 +369,7 @@ function useSwapApprove(token, spokeProvider) {
375
369
  resetError
376
370
  };
377
371
  }
378
- var SodaxProvider = ({ children, testnet = false, config }) => {
372
+ var SodaxProvider = ({ children, testnet = false, config, rpcConfig }) => {
379
373
  const sodax = new sdk.Sodax(config);
380
374
  const hubChainId = config?.hubProviderConfig?.chainConfig.chain.id;
381
375
  const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;
@@ -389,7 +383,7 @@ var SodaxProvider = ({ children, testnet = false, config }) => {
389
383
  }
390
384
  return void 0;
391
385
  }, [hubChainId, hubRpcUrl]);
392
- return /* @__PURE__ */ React__default.default.createElement(SodaxContext.Provider, { value: { sodax, testnet, hubProvider } }, children);
386
+ return /* @__PURE__ */ React__default.default.createElement(SodaxContext.Provider, { value: { sodax, testnet, hubProvider, rpcConfig } }, children);
393
387
  };
394
388
  var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
395
389
  const tokens = sdk.hubAssets[spokeChainId];
@@ -402,7 +396,6 @@ var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
402
396
  exports.SodaxProvider = SodaxProvider;
403
397
  exports.getSpokeTokenAddressByVault = getSpokeTokenAddressByVault;
404
398
  exports.useBorrow = useBorrow;
405
- exports.useCreateIntentOrder = useCreateIntentOrder;
406
399
  exports.useEstimateGas = useEstimateGas;
407
400
  exports.useHubProvider = useHubProvider;
408
401
  exports.useMMAllowance = useMMAllowance;
@@ -414,6 +407,7 @@ exports.useSodaxContext = useSodaxContext;
414
407
  exports.useSpokeProvider = useSpokeProvider;
415
408
  exports.useStatus = useStatus;
416
409
  exports.useSupply = useSupply;
410
+ exports.useSwap = useSwap;
417
411
  exports.useSwapAllowance = useSwapAllowance;
418
412
  exports.useSwapApprove = useSwapApprove;
419
413
  exports.useUserReservesData = useUserReservesData;