@sodax/dapp-kit 0.0.1-rc.17 → 0.0.1-rc.19
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 +10 -21
- 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/useSwap.d.ts +2 -2
- package/dist/hooks/swap/useSwap.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -44
- 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 +57 -0
- package/src/hooks/mm/useUserReservesData.ts +29 -28
- package/src/hooks/provider/useSpokeProvider.ts +23 -14
- package/src/hooks/swap/useSwap.ts +2 -2
- package/src/index.ts +1 -0
- package/src/providers/SodaxProvider.tsx +5 -3
- package/src/types.ts +22 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StellarRpcConfig } from '@sodax/sdk';
|
|
2
|
+
export type RpcConfig = {
|
|
3
|
+
sonic?: string;
|
|
4
|
+
'0xa86a.avax'?: string;
|
|
5
|
+
'0xa4b1.arbitrum'?: string;
|
|
6
|
+
'0x2105.base'?: string;
|
|
7
|
+
'0x38.bsc'?: string;
|
|
8
|
+
'0xa.optimism'?: string;
|
|
9
|
+
'0x89.polygon'?: string;
|
|
10
|
+
nibiru?: string;
|
|
11
|
+
'injective-1'?: string;
|
|
12
|
+
sui?: string;
|
|
13
|
+
solana?: string;
|
|
14
|
+
'0x1.icon'?: string;
|
|
15
|
+
stellar?: StellarRpcConfig;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG;IAEtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sodax/dapp-kit",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.0.1-rc.
|
|
4
|
+
"version": "0.0.1-rc.19",
|
|
5
5
|
"description": "dapp-kit of New World",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"viem": "^2.29.2",
|
|
19
|
-
"@sodax/sdk": "0.0.1-rc.
|
|
20
|
-
"@sodax/types": "0.0.1-rc.
|
|
21
|
-
"@sodax/wallet-sdk": "0.0.1-rc.17"
|
|
19
|
+
"@sodax/sdk": "0.0.1-rc.22",
|
|
20
|
+
"@sodax/types": "0.0.1-rc.15"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"@types/react": "^19.0.8",
|
package/src/contexts/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
2
|
import type { EvmHubProvider, Sodax } from '@sodax/sdk';
|
|
3
|
+
import type { RpcConfig } from '@/types';
|
|
3
4
|
|
|
4
5
|
export interface SodaxContextType {
|
|
5
6
|
sodax: Sodax;
|
|
6
7
|
testnet: boolean;
|
|
7
8
|
hubProvider: EvmHubProvider | undefined;
|
|
9
|
+
rpcConfig: RpcConfig;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export const SodaxContext = createContext<SodaxContextType | null>(null);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getMoneyMarketConfig } from '@sodax/sdk';
|
|
2
|
-
import type { HubChainId } from '@sodax/types';
|
|
3
1
|
import { useQuery } from '@tanstack/react-query';
|
|
4
2
|
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
3
|
/**
|
|
@@ -22,16 +20,11 @@ import { useSodaxContext } from '../shared/useSodaxContext';
|
|
|
22
20
|
|
|
23
21
|
export function useReservesData() {
|
|
24
22
|
const { sodax } = useSodaxContext();
|
|
25
|
-
const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;
|
|
26
23
|
|
|
27
24
|
return useQuery({
|
|
28
25
|
queryKey: ['reservesData'],
|
|
29
26
|
queryFn: async () => {
|
|
30
|
-
|
|
31
|
-
return await sodax.moneyMarket.getReservesData(
|
|
32
|
-
moneyMarketConfig.uiPoolDataProvider,
|
|
33
|
-
moneyMarketConfig.poolAddressesProvider,
|
|
34
|
-
);
|
|
27
|
+
return await sodax.moneyMarket.data.getReservesData();
|
|
35
28
|
},
|
|
36
29
|
});
|
|
37
30
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReservesDataHumanized } from '@sodax/sdk';
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
4
|
+
/**
|
|
5
|
+
* Hook for fetching humanized reserves data from the Sodax money market.
|
|
6
|
+
*
|
|
7
|
+
* This hook provides access to the current state of all reserves (humanized format) in the money market protocol,
|
|
8
|
+
* including liquidity, interest rates, and other key metrics. The data is automatically
|
|
9
|
+
* fetched and cached using React Query.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const { data: reservesHumanized, isLoading, error } = useReservesHumanized();
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @returns A React Query result object containing:
|
|
17
|
+
* - data: The reserves humanized data when available
|
|
18
|
+
* - isLoading: Loading state indicator
|
|
19
|
+
* - error: Any error that occurred during data fetching
|
|
20
|
+
*/
|
|
21
|
+
export function useReservesHumanized(): UseQueryResult<ReservesDataHumanized, Error> {
|
|
22
|
+
const { sodax } = useSodaxContext();
|
|
23
|
+
|
|
24
|
+
return useQuery({
|
|
25
|
+
queryKey: ['reservesHumanized'],
|
|
26
|
+
queryFn: async () => {
|
|
27
|
+
return await sodax.moneyMarket.data.getReservesHumanized();
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook for fetching list of reserves from the Sodax money market.
|
|
6
|
+
*
|
|
7
|
+
* This hook provides access to the list of addresses of all 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: reservesList, isLoading, error } = useReservesList();
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @returns A React Query result object containing:
|
|
16
|
+
* - data: The reserves list when available
|
|
17
|
+
* - isLoading: Loading state indicator
|
|
18
|
+
* - error: Any error that occurred during data fetching
|
|
19
|
+
*/
|
|
20
|
+
export function useReservesList() {
|
|
21
|
+
const { sodax } = useSodaxContext();
|
|
22
|
+
|
|
23
|
+
return useQuery({
|
|
24
|
+
queryKey: ['reservesList'],
|
|
25
|
+
queryFn: async () => {
|
|
26
|
+
return await sodax.moneyMarket.data.getReservesList();
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FormatReserveUSDResponse, ReserveData } from '@sodax/sdk';
|
|
2
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook for fetching formatted summary of Sodax user portfolio (holdings, total liquidity,
|
|
7
|
+
* collateral, borrows, liquidation threshold, health factor, available borrowing power, etc..).
|
|
8
|
+
*
|
|
9
|
+
* This hook provides access to the current state of user portfolio in the money market protocol.
|
|
10
|
+
* The data is automatically fetched and cached using React Query.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const { data: userFormattedSummary, isLoading, error } = useUserFormattedSummary();
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns A React Query result object containing:
|
|
18
|
+
* - data: The formatted summary of Sodax user portfolio when available
|
|
19
|
+
* - isLoading: Loading state indicator
|
|
20
|
+
* - error: Any error that occurred during data fetching
|
|
21
|
+
*/
|
|
22
|
+
export function useReservesUsdFormat(): UseQueryResult<
|
|
23
|
+
(ReserveData & { priceInMarketReferenceCurrency: string } & FormatReserveUSDResponse)[],
|
|
24
|
+
Error
|
|
25
|
+
> {
|
|
26
|
+
const { sodax } = useSodaxContext();
|
|
27
|
+
|
|
28
|
+
return useQuery({
|
|
29
|
+
queryKey: ['reservesUsdFormat'],
|
|
30
|
+
queryFn: async () => {
|
|
31
|
+
// fetch reserves and hub wallet address
|
|
32
|
+
const reserves = await sodax.moneyMarket.data.getReservesHumanized();
|
|
33
|
+
|
|
34
|
+
// format reserves
|
|
35
|
+
return sodax.moneyMarket.data.formatReservesUSD(sodax.moneyMarket.data.buildReserveDataWithPrice(reserves));
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type FormatUserSummaryResponse, type FormatReserveUSDResponse, WalletAbstractionService } from '@sodax/sdk';
|
|
2
|
+
import type { ChainId } from '@sodax/types';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook for fetching formatted summary of Sodax user portfolio (holdings, total liquidity,
|
|
9
|
+
* collateral, borrows, liquidation threshold, health factor, available borrowing power, etc..).
|
|
10
|
+
*
|
|
11
|
+
* This hook provides access to the current state of user portfolio in the money market protocol.
|
|
12
|
+
* The data is automatically fetched and cached using React Query.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const { data: userFormattedSummary, isLoading, error } = useUserFormattedSummary();
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @returns A React Query result object containing:
|
|
20
|
+
* - data: The formatted summary of Sodax user portfolio when available
|
|
21
|
+
* - isLoading: Loading state indicator
|
|
22
|
+
* - error: Any error that occurred during data fetching
|
|
23
|
+
*/
|
|
24
|
+
export function useUserFormattedSummary(
|
|
25
|
+
spokeChainId: ChainId | undefined,
|
|
26
|
+
address: string | undefined,
|
|
27
|
+
): UseQueryResult<FormatUserSummaryResponse<FormatReserveUSDResponse> | undefined, Error> {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['userFormattedSummary', spokeChainId, address],
|
|
33
|
+
queryFn: async () => {
|
|
34
|
+
if (!spokeProvider || !address) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// fetch reserves and hub wallet address
|
|
39
|
+
const reserves = await sodax.moneyMarket.data.getReservesHumanized();
|
|
40
|
+
|
|
41
|
+
// format reserves
|
|
42
|
+
const formattedReserves = sodax.moneyMarket.data.formatReservesUSD(
|
|
43
|
+
sodax.moneyMarket.data.buildReserveDataWithPrice(reserves),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// fetch user reserves
|
|
47
|
+
const userReserves = await sodax.moneyMarket.data.getUserReservesHumanized(spokeProvider);
|
|
48
|
+
|
|
49
|
+
// format user summary
|
|
50
|
+
return sodax.moneyMarket.data.formatUserSummary(
|
|
51
|
+
sodax.moneyMarket.data.buildUserSummaryRequest(reserves, formattedReserves, userReserves),
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
enabled: !!spokeChainId && !!address,
|
|
55
|
+
refetchInterval: 5000,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { HubChainId } from '@sodax/types';
|
|
1
|
+
import { type UserReserveData, WalletAbstractionService } from '@sodax/sdk';
|
|
3
2
|
import type { ChainId } from '@sodax/types';
|
|
4
|
-
import { useQuery } from '@tanstack/react-query';
|
|
5
|
-
import { useHubProvider } from '../provider/useHubProvider';
|
|
3
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
6
4
|
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
7
5
|
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Hook for fetching user reserves data from the Sodax money market.
|
|
9
|
+
*
|
|
10
|
+
* This hook provides access to the current state of user reserves in the money market protocol.
|
|
11
|
+
* The data is automatically fetched and cached using React Query.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const { data: userReservesData, isLoading, error } = useUserReservesData();
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @returns A React Query result object containing:
|
|
19
|
+
* - data: The user reserves data when available
|
|
20
|
+
* - isLoading: Loading state indicator
|
|
21
|
+
* - error: Any error that occurred during data fetching
|
|
22
|
+
*/
|
|
23
|
+
export function useUserReservesData(
|
|
24
|
+
spokeChainId: ChainId | undefined,
|
|
25
|
+
address: string | undefined,
|
|
26
|
+
refetchInterval = 5000,
|
|
27
|
+
): UseQueryResult<readonly [readonly UserReserveData[], number] | undefined, Error> {
|
|
10
28
|
const { sodax } = useSodaxContext();
|
|
11
|
-
const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;
|
|
12
|
-
const hubProvider = useHubProvider();
|
|
13
29
|
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
return useQuery({
|
|
16
32
|
queryKey: ['userReserves', spokeChainId, address],
|
|
17
33
|
queryFn: async () => {
|
|
18
|
-
if (!
|
|
19
|
-
return;
|
|
34
|
+
if (!spokeProvider || !address) {
|
|
35
|
+
return undefined;
|
|
20
36
|
}
|
|
21
37
|
|
|
22
|
-
|
|
23
|
-
address,
|
|
24
|
-
spokeProvider,
|
|
25
|
-
hubProvider,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const moneyMarketConfig = getMoneyMarketConfig(hubChainId);
|
|
29
|
-
const [res] = await sodax.moneyMarket.getUserReservesData(
|
|
30
|
-
hubWalletAddress,
|
|
31
|
-
moneyMarketConfig.uiPoolDataProvider,
|
|
32
|
-
moneyMarketConfig.poolAddressesProvider,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
return res;
|
|
38
|
+
return await sodax.moneyMarket.data.getUserReservesData(spokeProvider);
|
|
36
39
|
},
|
|
37
|
-
enabled: !!spokeChainId && !!
|
|
38
|
-
refetchInterval
|
|
40
|
+
enabled: !!spokeChainId && !!address,
|
|
41
|
+
refetchInterval,
|
|
39
42
|
});
|
|
40
|
-
|
|
41
|
-
return userReserves;
|
|
42
43
|
}
|
|
@@ -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
|
}
|
|
@@ -7,11 +7,11 @@ 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
17
|
* Hook for creating and submitting an swap intent order for cross-chain swaps.
|
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
|
+
};
|