@sodax/dapp-kit 1.0.0-rc.8 → 1.0.1-beta-rc1
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/dist/index.d.mts +16 -9
- package/dist/index.d.ts +16 -9
- package/dist/index.js +13 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/hooks/bridge/useBridge.ts +8 -1
- package/src/hooks/migrate/types.ts +15 -15
- package/src/hooks/mm/useAToken.ts +1 -3
- package/src/hooks/provider/useSpokeProvider.ts +1 -1
- package/src/hooks/shared/index.ts +1 -1
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +26 -17
- package/src/hooks/swap/useCancelSwap.ts +1 -1
- package/src/hooks/swap/useQuote.ts +2 -2
- package/src/hooks/swap/useStatus.ts +1 -1
- package/src/hooks/swap/useSwap.ts +1 -1
- package/src/hooks/swap/useSwapAllowance.ts +1 -1
- package/src/hooks/swap/useSwapApprove.ts +1 -1
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
|
+
"version": "1.0.1-beta-rc1",
|
|
5
5
|
"description": "dapp-kit of New World",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"viem": "2.29.2",
|
|
19
|
-
"@sodax/sdk": "1.0.
|
|
20
|
-
"@sodax/types": "1.0.
|
|
19
|
+
"@sodax/sdk": "1.0.1-beta-rc1",
|
|
20
|
+
"@sodax/types": "1.0.1-beta-rc1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/react": "18.3.1",
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
BridgeError,
|
|
4
|
+
BridgeErrorCode,
|
|
5
|
+
SpokeTxHash,
|
|
6
|
+
HubTxHash,
|
|
7
|
+
Result,
|
|
8
|
+
CreateBridgeIntentParams,
|
|
9
|
+
} from '@sodax/sdk';
|
|
3
10
|
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
4
11
|
import type { SpokeProvider } from '@sodax/sdk';
|
|
5
12
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { XToken } from '@sodax/types';
|
|
2
|
-
|
|
3
|
-
export const MIGRATION_MODE_ICX_SODA = 'icxsoda';
|
|
4
|
-
export const MIGRATION_MODE_BNUSD = 'bnusd';
|
|
5
|
-
|
|
6
|
-
export type MigrationMode = typeof MIGRATION_MODE_ICX_SODA | typeof MIGRATION_MODE_BNUSD;
|
|
7
|
-
|
|
8
|
-
export interface MigrationIntentParams {
|
|
9
|
-
token: XToken | undefined;
|
|
10
|
-
amount: string | undefined;
|
|
11
|
-
sourceAddress: string | undefined;
|
|
12
|
-
migrationMode?: MigrationMode;
|
|
13
|
-
toToken?: XToken;
|
|
14
|
-
destinationAddress?: string;
|
|
15
|
-
}
|
|
1
|
+
import type { XToken } from '@sodax/types';
|
|
2
|
+
|
|
3
|
+
export const MIGRATION_MODE_ICX_SODA = 'icxsoda';
|
|
4
|
+
export const MIGRATION_MODE_BNUSD = 'bnusd';
|
|
5
|
+
|
|
6
|
+
export type MigrationMode = typeof MIGRATION_MODE_ICX_SODA | typeof MIGRATION_MODE_BNUSD;
|
|
7
|
+
|
|
8
|
+
export interface MigrationIntentParams {
|
|
9
|
+
token: XToken | undefined;
|
|
10
|
+
amount: string | undefined;
|
|
11
|
+
sourceAddress: string | undefined;
|
|
12
|
+
migrationMode?: MigrationMode;
|
|
13
|
+
toToken?: XToken;
|
|
14
|
+
destinationAddress?: string;
|
|
15
|
+
}
|
|
@@ -24,9 +24,7 @@ import { useSodaxContext } from '../shared/useSodaxContext';
|
|
|
24
24
|
* - isLoading: Loading state indicator.
|
|
25
25
|
* - error: Any error that occurred during data fetching.
|
|
26
26
|
*/
|
|
27
|
-
export function useAToken(
|
|
28
|
-
aToken: Address | undefined,
|
|
29
|
-
): UseQueryResult<XToken, Error> {
|
|
27
|
+
export function useAToken(aToken: Address | undefined): UseQueryResult<XToken, Error> {
|
|
30
28
|
const { sodax } = useSodaxContext();
|
|
31
29
|
|
|
32
30
|
return useQuery({
|
|
@@ -56,7 +56,7 @@ export function useSpokeProvider(
|
|
|
56
56
|
if (!spokeChainId) return undefined;
|
|
57
57
|
if (!xChainType) return undefined;
|
|
58
58
|
if (!rpcConfig) return undefined;
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
if (xChainType === 'EVM') {
|
|
61
61
|
if (spokeChainId === SONIC_MAINNET_CHAIN_ID) {
|
|
62
62
|
return new SonicSpokeProvider(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { deriveUserWalletAddress, type SpokeProvider } from '@sodax/sdk';
|
|
1
|
+
import { deriveUserWalletAddress, type SpokeProvider, type SpokeChainId } from '@sodax/sdk';
|
|
3
2
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
3
|
import { useSodaxContext } from './useSodaxContext';
|
|
5
4
|
import type { Address } from 'viem';
|
|
@@ -7,38 +6,48 @@ import type { Address } from 'viem';
|
|
|
7
6
|
/**
|
|
8
7
|
* Hook for deriving user wallet address for hub abstraction.
|
|
9
8
|
*
|
|
10
|
-
* This hook derives the user's abstracted wallet address for the hub chain.
|
|
11
|
-
* If the spoke chain is the same as the hub chain, it returns the
|
|
12
|
-
* Otherwise, it returns the abstracted wallet address for cross-chain operations.
|
|
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.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* The query is automatically enabled when both `spokeChainId` and `spokeAddress` are provided.
|
|
14
|
+
* This is a deterministic operation, so the result is cached and not refetched automatically.
|
|
15
|
+
*
|
|
16
|
+
* @param spokeChainId - Optional spoke chain ID. If not provided, the query will be disabled.
|
|
17
|
+
* @param spokeAddress - Optional user wallet address on the spoke chain. If not provided, the query will be disabled.
|
|
16
18
|
* @returns A React Query result object containing:
|
|
17
|
-
* - data: The derived user wallet address when available
|
|
19
|
+
* - data: The derived user wallet address (Address) when available
|
|
18
20
|
* - isLoading: Loading state indicator
|
|
19
|
-
* - error: Any error that occurred during derivation
|
|
21
|
+
* - error: Any error that occurred during derivation (Error)
|
|
20
22
|
*
|
|
21
23
|
* @example
|
|
22
24
|
* ```typescript
|
|
23
|
-
* const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(
|
|
25
|
+
* const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeChainId, userAddress);
|
|
26
|
+
*
|
|
27
|
+
* if (isLoading) return <div>Deriving address...</div>;
|
|
28
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
29
|
+
* if (derivedAddress) return <div>Derived Address: {derivedAddress}</div>;
|
|
24
30
|
* ```
|
|
25
31
|
*/
|
|
26
32
|
export function useDeriveUserWalletAddress(
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
spokeChainId?: SpokeChainId | SpokeProvider | undefined,
|
|
34
|
+
spokeAddress?: string | undefined,
|
|
29
35
|
): UseQueryResult<Address, Error> {
|
|
30
36
|
const { sodax } = useSodaxContext();
|
|
31
37
|
|
|
32
38
|
return useQuery({
|
|
33
|
-
queryKey: ['deriveUserWalletAddress',
|
|
39
|
+
queryKey: ['deriveUserWalletAddress', spokeChainId, spokeAddress],
|
|
34
40
|
queryFn: async (): Promise<Address> => {
|
|
35
|
-
if (!
|
|
36
|
-
throw new Error('Spoke
|
|
41
|
+
if (!spokeChainId || !spokeAddress) {
|
|
42
|
+
throw new Error('Spoke chain id and address are required');
|
|
37
43
|
}
|
|
38
44
|
|
|
39
|
-
|
|
45
|
+
// Determine if spokeChainId is a SpokeProvider object or SpokeChainId value
|
|
46
|
+
spokeChainId = typeof spokeChainId === 'object' ? spokeChainId.chainConfig.chain.id : spokeChainId;
|
|
47
|
+
|
|
48
|
+
return await deriveUserWalletAddress(sodax.hubProvider, spokeChainId, spokeAddress);
|
|
40
49
|
},
|
|
41
|
-
enabled: !!
|
|
50
|
+
enabled: !!spokeChainId && !!spokeAddress,
|
|
42
51
|
refetchInterval: false, // This is a deterministic operation, no need to refetch
|
|
43
52
|
});
|
|
44
53
|
}
|
|
@@ -42,7 +42,7 @@ export const useQuote = (
|
|
|
42
42
|
payload: SolverIntentQuoteRequest | undefined,
|
|
43
43
|
): UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined> => {
|
|
44
44
|
const { sodax } = useSodaxContext();
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
// Create a serializable query key by converting BigInt to string
|
|
47
47
|
const queryKey = useMemo(() => {
|
|
48
48
|
if (!payload) return ['quote', undefined];
|
|
@@ -61,7 +61,7 @@ export const useQuote = (
|
|
|
61
61
|
if (!payload) {
|
|
62
62
|
return undefined;
|
|
63
63
|
}
|
|
64
|
-
return sodax.
|
|
64
|
+
return sodax.swaps.getQuote(payload);
|
|
65
65
|
},
|
|
66
66
|
enabled: !!payload,
|
|
67
67
|
refetchInterval: 3000,
|