@sodax/dapp-kit 0.0.1-rc.27 → 0.0.1-rc.29

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.
package/README.md CHANGED
@@ -41,6 +41,8 @@ dApp Kit is a collection of React components, hooks, and utilities designed to s
41
41
 
42
42
  - Shared
43
43
  - Derive user wallet address for hub abstraction (`useDeriveUserWalletAddress`)
44
+ - Check if Stellar trustline is established for an asset (`useStellarTrustlineCheck`)
45
+ - Request creation of Stellar trustline line for an asset (`useRequestTrustline`)
44
46
 
45
47
  ## Installation
46
48
 
@@ -66,6 +68,17 @@ pnpm install @sodax/dapp-kit @tanstack/react-query @sodax/wallet-sdk-react
66
68
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
67
69
  import { SodaxWalletProvider } from '@sodax/wallet-sdk-react';
68
70
  import { SodaxProvider } from '@sodax/dapp-kit';
71
+ import {
72
+ ARBITRUM_MAINNET_CHAIN_ID,
73
+ AVALANCHE_MAINNET_CHAIN_ID,
74
+ BASE_MAINNET_CHAIN_ID,
75
+ BSC_MAINNET_CHAIN_ID,
76
+ OPTIMISM_MAINNET_CHAIN_ID,
77
+ POLYGON_MAINNET_CHAIN_ID,
78
+ SONIC_MAINNET_CHAIN_ID,
79
+ HYPEREVM_MAINNET_CHAIN_ID,
80
+ LIGHTLINK_MAINNET_CHAIN_ID,
81
+ } from '@sodax/types';
69
82
 
70
83
  const queryClient = new QueryClient();
71
84
 
@@ -80,7 +93,18 @@ function App() {
80
93
  <SodaxWalletProvider
81
94
  config={{
82
95
  EVM: {
83
- wagmiConfig: wagmiConfig,
96
+ // Add all the EVM chains you want to support
97
+ chains: [
98
+ ARBITRUM_MAINNET_CHAIN_ID,
99
+ AVALANCHE_MAINNET_CHAIN_ID,
100
+ BASE_MAINNET_CHAIN_ID,
101
+ BSC_MAINNET_CHAIN_ID,
102
+ OPTIMISM_MAINNET_CHAIN_ID,
103
+ POLYGON_MAINNET_CHAIN_ID,
104
+ SONIC_MAINNET_CHAIN_ID,
105
+ HYPEREVM_MAINNET_CHAIN_ID,
106
+ LIGHTLINK_MAINNET_CHAIN_ID,
107
+ ],
84
108
  },
85
109
  SUI: {
86
110
  isMainnet: true,
@@ -1,4 +1,6 @@
1
1
  export * from './useSodaxContext';
2
2
  export * from './useEstimateGas';
3
3
  export * from './useDeriveUserWalletAddress';
4
+ export * from './useStellarTrustlineCheck';
5
+ export * from './useRequestTrustline';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { type SpokeProvider, StellarSpokeProvider, type TxReturnType } from '@sodax/sdk';
2
+ import { type UseMutationResult } from '@tanstack/react-query';
3
+ /**
4
+ * React hook to request a Stellar trustline for a given token and amount.
5
+ *
6
+ * This hook provides a mutation for requesting a trustline on the Stellar network
7
+ * using the provided SpokeProvider. It is intended for use with StellarSpokeProvider
8
+ * and will throw if used with a non-Stellar provider. Upon success, it invalidates
9
+ * the trustline check query to ensure UI reflects the updated trustline state.
10
+ *
11
+ * @template T - The type of SpokeProvider, defaults to SpokeProvider.
12
+ * @param {string | undefined} token - The Stellar asset code or token address for which to request a trustline.
13
+ * @returns {UseMutationResult<TxReturnType<StellarSpokeProvider, false>, Error, { token: string; amount: bigint; spokeProvider: T }>}
14
+ * A React Query mutation result object containing:
15
+ * - `mutate`/`mutateAsync`: Function to trigger the trustline request.
16
+ * - `data`: The transaction result if successful.
17
+ * - `error`: Any error encountered during the request.
18
+ * - `isLoading`: Whether the mutation is in progress.
19
+ * - Other React Query mutation state.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * import { useRequestTrustline } from '@sodax/dapp-kit';
24
+ *
25
+ * const { mutate: requestTrustline, isLoading, error, data } = useRequestTrustline('USDC-G...TOKEN');
26
+ *
27
+ * // To request a trustline:
28
+ * requestTrustline({
29
+ * token: 'USDC-G...TOKEN',
30
+ * amount: 10000000n,
31
+ * spokeProvider: stellarProvider,
32
+ * });
33
+ *
34
+ * if (isLoading) return <span>Requesting trustline...</span>;
35
+ * if (error) return <span>Error: {error.message}</span>;
36
+ * if (data) return <span>Trustline requested! Tx: {data.txHash}</span>;
37
+ * ```
38
+ */
39
+ export declare function useRequestTrustline<T extends SpokeProvider = SpokeProvider>(token: string | undefined): UseMutationResult<TxReturnType<StellarSpokeProvider, false>, Error, {
40
+ token: string;
41
+ amount: bigint;
42
+ spokeProvider: T;
43
+ }>;
44
+ //# sourceMappingURL=useRequestTrustline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRequestTrustline.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/useRequestTrustline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,oBAAoB,EAAuB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC9G,OAAO,EAAe,KAAK,iBAAiB,EAAkB,MAAM,uBAAuB,CAAC;AAE5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EACzE,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,iBAAiB,CAClB,YAAY,CAAC,oBAAoB,EAAE,KAAK,CAAC,EACzC,KAAK,EACL;IACE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,CAAC,CAAC;CAClB,CACF,CA+BA"}
@@ -0,0 +1,40 @@
1
+ import type { SpokeChainId, SpokeProvider } from '@sodax/sdk';
2
+ import { type UseQueryResult } from '@tanstack/react-query';
3
+ /**
4
+ * React hook to check if a Stellar account has a sufficient trustline for a given token and amount.
5
+ *
6
+ * This hook queries the Stellar network (via the provided SpokeProvider) to determine
7
+ * whether the account has established a trustline for the specified token and if the trustline
8
+ * is sufficient for the intended amount. It is useful for gating UI actions that require
9
+ * a trustline to be present and funded.
10
+ *
11
+ * @template T - The type of SpokeProvider, defaults to SpokeProvider.
12
+ * @param {string | undefined} token - The Stellar asset code or token address to check the trustline for.
13
+ * @param {bigint | undefined} amount - The minimum amount required for the trustline.
14
+ * @param {T | undefined} spokeProvider - The provider instance for interacting with the Stellar network.
15
+ * @param {SpokeChainId | undefined} chainId - The chain ID to determine if the check should be performed (only on Stellar mainnet).
16
+ * @returns {UseQueryResult<boolean, Error>} A React Query result object containing:
17
+ * - `data`: `true` if the trustline exists and is sufficient, `false` otherwise.
18
+ * - `error`: Any error encountered during the check.
19
+ * - `isLoading`: Whether the query is in progress.
20
+ * - Other React Query state.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * import { useStellarTrustlineCheck } from '@sodax/dapp-kit';
25
+ *
26
+ * const { data: hasTrustline, isLoading, error } = useStellarTrustlineCheck(
27
+ * 'USDC-G...TOKEN',
28
+ * 10000000n,
29
+ * stellarProvider,
30
+ * 'stellar'
31
+ * );
32
+ *
33
+ * if (isLoading) return <span>Checking trustline...</span>;
34
+ * if (error) return <span>Error: {error.message}</span>;
35
+ * if (!hasTrustline) return <span>Trustline not established or insufficient.</span>;
36
+ * return <span>Trustline is sufficient!</span>;
37
+ * ```
38
+ */
39
+ export declare function useStellarTrustlineCheck<T extends SpokeProvider = SpokeProvider>(token: string | undefined, amount: bigint | undefined, spokeProvider: T | undefined, chainId: SpokeChainId | undefined): UseQueryResult<boolean, Error>;
40
+ //# sourceMappingURL=useStellarTrustlineCheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStellarTrustlineCheck.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/useStellarTrustlineCheck.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EAC9E,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,aAAa,EAAE,CAAC,GAAG,SAAS,EAC5B,OAAO,EAAE,YAAY,GAAG,SAAS,GAChC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAwBhC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useQuote.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useQuote.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEnH,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,QAAQ,YACV,wBAAwB,GAAG,SAAS,KAC5C,cAAc,CAAC,MAAM,CAAC,yBAAyB,EAAE,mBAAmB,CAAC,GAAG,SAAS,CAanF,CAAC"}
1
+ {"version":3,"file":"useQuote.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useQuote.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEnH,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,QAAQ,YACV,wBAAwB,GAAG,SAAS,KAC5C,cAAc,CAAC,MAAM,CAAC,yBAAyB,EAAE,mBAAmB,CAAC,GAAG,SAAS,CA0BnF,CAAC"}
@@ -1 +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
+ {"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,EAAkB,MAAM,uBAAuB,CAAC;AAE5F,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,CAmBlE"}
@@ -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,CAoBhC"}
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,CAqBhC"}
package/dist/index.js CHANGED
@@ -44,6 +44,48 @@ function useDeriveUserWalletAddress(spokeProvider, walletAddress) {
44
44
  // This is a deterministic operation, no need to refetch
45
45
  });
46
46
  }
47
+ function useStellarTrustlineCheck(token, amount, spokeProvider, chainId) {
48
+ return reactQuery.useQuery({
49
+ queryKey: ["stellar-trustline-check", token],
50
+ queryFn: async () => {
51
+ if (chainId !== sdk.STELLAR_MAINNET_CHAIN_ID) {
52
+ return true;
53
+ }
54
+ if (!spokeProvider || !token || !amount || !(spokeProvider instanceof sdk.StellarSpokeProvider)) {
55
+ console.error(
56
+ "Spoke provider, token or amount not found. Details: spokeProvider:",
57
+ spokeProvider,
58
+ "token:",
59
+ token,
60
+ "amount:",
61
+ amount
62
+ );
63
+ return false;
64
+ }
65
+ const response = await sdk.StellarSpokeService.hasSufficientTrustline(token, amount, spokeProvider);
66
+ return response;
67
+ },
68
+ enabled: !!spokeProvider && !!token && !!amount
69
+ });
70
+ }
71
+ function useRequestTrustline(token) {
72
+ const queryClient = reactQuery.useQueryClient();
73
+ return reactQuery.useMutation({
74
+ mutationFn: async ({
75
+ token: token2,
76
+ amount,
77
+ spokeProvider
78
+ }) => {
79
+ if (!spokeProvider || !token2 || !amount || !(spokeProvider instanceof sdk.StellarSpokeProvider)) {
80
+ throw new Error("Spoke provider, token or amount not found");
81
+ }
82
+ return sdk.StellarSpokeService.requestTrustline(token2, amount, spokeProvider);
83
+ },
84
+ onSuccess: () => {
85
+ queryClient.invalidateQueries({ queryKey: ["stellar-trustline-check", token] });
86
+ }
87
+ });
88
+ }
47
89
 
48
90
  // src/hooks/provider/useHubProvider.ts
49
91
  function useHubProvider() {
@@ -289,8 +331,18 @@ function useMMApprove(token, spokeProvider) {
289
331
  }
290
332
  var useQuote = (payload) => {
291
333
  const { sodax } = useSodaxContext();
334
+ const queryKey = React.useMemo(() => {
335
+ if (!payload) return ["quote", void 0];
336
+ return [
337
+ "quote",
338
+ {
339
+ ...payload,
340
+ amount: payload.amount.toString()
341
+ }
342
+ ];
343
+ }, [payload]);
292
344
  return reactQuery.useQuery({
293
- queryKey: [payload],
345
+ queryKey,
294
346
  queryFn: async () => {
295
347
  if (!payload) {
296
348
  return void 0;
@@ -303,6 +355,7 @@ var useQuote = (payload) => {
303
355
  };
304
356
  function useSwap(spokeProvider) {
305
357
  const { sodax } = useSodaxContext();
358
+ const queryClient = reactQuery.useQueryClient();
306
359
  return reactQuery.useMutation({
307
360
  mutationFn: async (params) => {
308
361
  if (!spokeProvider) {
@@ -312,6 +365,9 @@ function useSwap(spokeProvider) {
312
365
  intentParams: params,
313
366
  spokeProvider
314
367
  });
368
+ },
369
+ onSuccess: () => {
370
+ queryClient.invalidateQueries({ queryKey: ["xBalances"] });
315
371
  }
316
372
  });
317
373
  }
@@ -343,7 +399,8 @@ function useSwapAllowance(params, spokeProvider) {
343
399
  }
344
400
  return false;
345
401
  },
346
- enabled: !!spokeProvider && !!params
402
+ enabled: !!spokeProvider && !!params,
403
+ refetchInterval: 2e3
347
404
  });
348
405
  }
349
406
  function useSwapApprove(params, spokeProvider) {
@@ -372,7 +429,7 @@ function useSwapApprove(params, spokeProvider) {
372
429
  return allowance.ok;
373
430
  },
374
431
  onSuccess: () => {
375
- queryClient.invalidateQueries({ queryKey: ["allowance", params?.inputToken] });
432
+ queryClient.invalidateQueries({ queryKey: ["allowance", params] });
376
433
  }
377
434
  });
378
435
  return {
@@ -667,10 +724,12 @@ exports.useMMAllowance = useMMAllowance;
667
724
  exports.useMMApprove = useMMApprove;
668
725
  exports.useQuote = useQuote;
669
726
  exports.useRepay = useRepay;
727
+ exports.useRequestTrustline = useRequestTrustline;
670
728
  exports.useReservesData = useReservesData;
671
729
  exports.useSodaxContext = useSodaxContext;
672
730
  exports.useSpokeProvider = useSpokeProvider;
673
731
  exports.useStatus = useStatus;
732
+ exports.useStellarTrustlineCheck = useStellarTrustlineCheck;
674
733
  exports.useSupply = useSupply;
675
734
  exports.useSwap = useSwap;
676
735
  exports.useSwapAllowance = useSwapAllowance;