@sodax/dapp-kit 1.0.4-beta-rc1 → 1.0.4-beta

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sodax/dapp-kit",
3
3
  "license": "MIT",
4
- "version": "1.0.4-beta-rc1",
4
+ "version": "1.0.4-beta",
5
5
  "description": "dapp-kit of New World",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -16,13 +16,13 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "viem": "2.29.2",
19
- "@sodax/sdk": "1.0.4-beta-rc1",
20
- "@sodax/types": "1.0.4-beta-rc1"
19
+ "@sodax/sdk": "1.0.4-beta",
20
+ "@sodax/types": "1.0.4-beta"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/react": "19.0.8",
24
24
  "knip": "5.30.5",
25
- "tsup": "^8.4.0",
25
+ "tsup": "8.5.0",
26
26
  "typescript": "5.5.4"
27
27
  },
28
28
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  import { useQuery, type UseQueryResult } from '@tanstack/react-query';
2
2
  import { useSodaxContext } from '../shared/useSodaxContext';
3
- import type { XToken } from '@sodax/sdk';
3
+ import type { BridgeLimit, XToken } from '@sodax/sdk';
4
4
 
5
5
  /**
6
6
  * Hook for getting the amount available to be bridged.
@@ -11,8 +11,8 @@ import type { XToken } from '@sodax/sdk';
11
11
  * @param {SpokeChainId | undefined} chainId - The chain ID to get the balance for
12
12
  * @param {string | undefined} token - The token address to get the balance for
13
13
  *
14
- * @returns {UseQueryResult<bigint, Error>} A React Query result containing:
15
- * - data: The available amount to be bridged (bigint)
14
+ * @returns {UseQueryResult<BridgeLimit, Error>} A React Query result containing:
15
+ * - data: Data about available amount to be bridged
16
16
  * - error: Any error that occurred during the check
17
17
  *
18
18
  * @example
@@ -27,23 +27,24 @@ import type { XToken } from '@sodax/sdk';
27
27
  export function useGetBridgeableAmount(
28
28
  from: XToken | undefined,
29
29
  to: XToken | undefined,
30
- ): UseQueryResult<bigint, Error> {
30
+ ): UseQueryResult<BridgeLimit, Error> {
31
31
  const { sodax } = useSodaxContext();
32
32
 
33
33
  return useQuery({
34
34
  queryKey: ['spoke-asset-manager-token-balance', from, to],
35
35
  queryFn: async () => {
36
36
  if (!from || !to) {
37
- return 0n;
37
+ return { amount: 0n, decimals: 0, type: 'DEPOSIT_LIMIT' } as const;
38
38
  }
39
39
 
40
40
  const result = await sodax.bridge.getBridgeableAmount(from, to);
41
+
41
42
  if (result.ok) {
42
43
  return result.value;
43
44
  }
44
45
 
45
46
  console.error('Error getting bridgeable amount:', result.error);
46
- return 0n;
47
+ return { amount: 0n, decimals: 0, type: 'DEPOSIT_LIMIT' } as const;
47
48
  },
48
49
  enabled: !!from && !!to,
49
50
  });
@@ -3,7 +3,7 @@ import { isAddress, type Address } from 'viem';
3
3
  import { useQuery, type UseQueryOptions, type UseQueryResult } from '@tanstack/react-query';
4
4
  import { useSodaxContext } from '../shared/useSodaxContext';
5
5
  import type { SpokeProvider } from '@sodax/sdk';
6
- import { deriveUserWalletAddress } from '@sodax/sdk';
6
+ import { HubService } from '@sodax/sdk';
7
7
 
8
8
  export type UseATokensBalancesParams = {
9
9
  aTokens: readonly Address[];
@@ -74,12 +74,7 @@ export function useATokensBalances({
74
74
  }
75
75
  }
76
76
 
77
- // Derive user's hub wallet address
78
- const hubWalletAddress = await deriveUserWalletAddress(
79
- sodax.hubProvider,
80
- spokeProvider.chainConfig.chain.id,
81
- userAddress,
82
- );
77
+ const hubWalletAddress = await HubService.getUserHubWalletAddress(userAddress, spokeProvider.chainConfig.chain.id, sodax.hubProvider);
83
78
 
84
79
  return await sodax.moneyMarket.data.getATokensBalances(aTokens, hubWalletAddress);
85
80
  },
@@ -3,3 +3,4 @@ export * from './useEstimateGas';
3
3
  export * from './useDeriveUserWalletAddress';
4
4
  export * from './useStellarTrustlineCheck';
5
5
  export * from './useRequestTrustline';
6
+ export * from './useGetUserHubWalletAddress';
@@ -0,0 +1,54 @@
1
+ import { type SpokeProvider, type SpokeChainId, HubService } from '@sodax/sdk';
2
+ import { useQuery, type UseQueryResult } from '@tanstack/react-query';
3
+ import { useSodaxContext } from './useSodaxContext';
4
+ import type { Address } from 'viem';
5
+
6
+ /**
7
+ * Hook for deriving user wallet address for hub abstraction.
8
+ *
9
+ * This hook derives the user's abstracted wallet address for the hub chain based on the spoke chain ID and address.
10
+ * If the spoke chain is the same as the hub chain, it returns the encoded spoke address.
11
+ * Otherwise, it derives and returns the abstracted wallet address for cross-chain operations.
12
+ * NOTE: This hook is different from useDeriveUserWalletAddress because it uses wallet router address instead of CREATE3 address for Sonic (hub).
13
+ *
14
+ * The query is automatically enabled when both `spokeChainId` and `spokeAddress` are provided.
15
+ * This is a deterministic operation, so the result is cached and not refetched automatically.
16
+ *
17
+ * @param spokeChainId - Optional spoke chain ID. If not provided, the query will be disabled.
18
+ * @param spokeAddress - Optional user wallet address on the spoke chain. If not provided, the query will be disabled.
19
+ * @returns A React Query result object containing:
20
+ * - data: The derived user wallet address (Address) when available
21
+ * - isLoading: Loading state indicator
22
+ * - error: Any error that occurred during derivation (Error)
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeChainId, userAddress);
27
+ *
28
+ * if (isLoading) return <div>Deriving address...</div>;
29
+ * if (error) return <div>Error: {error.message}</div>;
30
+ * if (derivedAddress) return <div>Derived Address: {derivedAddress}</div>;
31
+ * ```
32
+ */
33
+ export function useGetUserHubWalletAddress(
34
+ spokeChainId?: SpokeChainId | SpokeProvider | undefined,
35
+ spokeAddress?: string | undefined,
36
+ ): UseQueryResult<Address, Error> {
37
+ const { sodax } = useSodaxContext();
38
+
39
+ return useQuery({
40
+ queryKey: ['getUserHubWalletAddress', spokeChainId, spokeAddress],
41
+ queryFn: async (): Promise<Address> => {
42
+ if (!spokeChainId || !spokeAddress) {
43
+ throw new Error('Spoke chain id and address are required');
44
+ }
45
+
46
+ // Determine if spokeChainId is a SpokeProvider object or SpokeChainId value
47
+ spokeChainId = typeof spokeChainId === 'object' ? spokeChainId.chainConfig.chain.id : spokeChainId;
48
+
49
+ return await HubService.getUserHubWalletAddress(spokeAddress, spokeChainId, sodax.hubProvider);
50
+ },
51
+ enabled: !!spokeChainId && !!spokeAddress,
52
+ refetchInterval: false, // This is a deterministic operation, no need to refetch
53
+ });
54
+ }