@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.
- package/LICENSE +21 -0
- package/README.md +16 -27
- package/dist/contexts/index.d.ts +2 -0
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/hooks/mm/useReservesData.d.ts.map +1 -1
- package/dist/hooks/mm/useReservesHumanized.d.ts +21 -0
- package/dist/hooks/mm/useReservesHumanized.d.ts.map +1 -0
- package/dist/hooks/mm/useReservesList.d.ts +18 -0
- package/dist/hooks/mm/useReservesList.d.ts.map +1 -0
- package/dist/hooks/mm/useReservesUsdFormat.d.ts +23 -0
- package/dist/hooks/mm/useReservesUsdFormat.d.ts.map +1 -0
- package/dist/hooks/mm/useUserFormattedSummary.d.ts +22 -0
- package/dist/hooks/mm/useUserFormattedSummary.d.ts.map +1 -0
- package/dist/hooks/mm/useUserReservesData.d.ts +19 -1
- package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
- package/dist/hooks/swap/index.d.ts +1 -1
- package/dist/hooks/swap/index.d.ts.map +1 -1
- package/dist/hooks/swap/{useCreateIntentOrder.d.ts → useSwap.d.ts} +7 -7
- package/dist/hooks/swap/useSwap.d.ts.map +1 -0
- package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -1
- package/dist/hooks/swap/useSwapApprove.d.ts +4 -5
- package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -54
- package/dist/index.mjs.map +1 -1
- package/dist/providers/SodaxProvider.d.ts +4 -2
- package/dist/providers/SodaxProvider.d.ts.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +3 -4
- package/src/contexts/index.ts +2 -0
- package/src/hooks/mm/useReservesData.ts +1 -8
- package/src/hooks/mm/useReservesHumanized.ts +30 -0
- package/src/hooks/mm/useReservesList.ts +29 -0
- package/src/hooks/mm/useReservesUsdFormat.ts +38 -0
- package/src/hooks/mm/useUserFormattedSummary.ts +60 -0
- package/src/hooks/mm/useUserReservesData.ts +30 -23
- package/src/hooks/provider/useSpokeProvider.ts +23 -14
- package/src/hooks/swap/index.ts +1 -1
- package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +10 -7
- package/src/hooks/swap/useSwapAllowance.ts +4 -1
- package/src/hooks/swap/useSwapApprove.ts +14 -14
- package/src/index.ts +1 -0
- package/src/providers/SodaxProvider.tsx +5 -3
- package/src/types.ts +22 -0
- 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
|
|
52
|
-
const
|
|
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 (!
|
|
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
|
-
|
|
63
|
+
walletProvider as IEvmWalletProvider,
|
|
63
64
|
spokeChainConfig[spokeChainId] as SonicSpokeChainConfig,
|
|
64
65
|
);
|
|
65
66
|
}
|
|
66
67
|
return new EvmSpokeProvider(
|
|
67
|
-
|
|
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
|
-
|
|
76
|
+
walletProvider as ISuiWalletProvider,
|
|
75
77
|
);
|
|
76
78
|
}
|
|
79
|
+
|
|
77
80
|
if (xChainType === 'ICON') {
|
|
78
81
|
return new IconSpokeProvider(
|
|
79
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
101
|
-
|
|
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,
|
|
115
|
+
}, [spokeChainId, xChainType, walletProvider, rpcConfig]);
|
|
107
116
|
|
|
108
117
|
return spokeProvider;
|
|
109
118
|
}
|
package/src/hooks/swap/index.ts
CHANGED
|
@@ -7,14 +7,14 @@ import type {
|
|
|
7
7
|
Intent,
|
|
8
8
|
IntentError,
|
|
9
9
|
SpokeProvider,
|
|
10
|
-
|
|
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,
|
|
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:
|
|
25
|
+
* const { mutateAsync: swap, isPending } = useSwap(spokeProvider);
|
|
26
26
|
*
|
|
27
27
|
* const handleSwap = async () => {
|
|
28
|
-
* const result = await
|
|
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
|
|
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.
|
|
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(
|
|
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: ({
|
|
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(
|
|
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 ({
|
|
39
|
+
mutationFn: async ({ params }: { params: CreateIntentParams | undefined }) => {
|
|
39
40
|
if (!spokeProvider) {
|
|
40
41
|
throw new Error('Spoke provider not found');
|
|
41
42
|
}
|
|
42
|
-
if (!
|
|
43
|
-
throw new Error('
|
|
43
|
+
if (!params) {
|
|
44
|
+
throw new Error('Swap Params not found');
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
const allowance = await sodax.solver.approve(
|
|
47
|
-
|
|
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
|
|
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',
|
|
58
|
+
queryClient.invalidateQueries({ queryKey: ['allowance', params?.inputToken] });
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
|
package/src/index.ts
CHANGED
|
@@ -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
|
|
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"}
|