@sodax/dapp-kit 0.0.1-rc.2 → 0.0.1-rc.4
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 +3 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/hooks/mm/index.d.ts +1 -0
- package/dist/hooks/mm/index.d.ts.map +1 -1
- package/dist/hooks/mm/useBorrow.d.ts +3 -3
- package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
- package/dist/hooks/mm/useRepay.d.ts +3 -3
- package/dist/hooks/mm/useRepay.d.ts.map +1 -1
- package/dist/hooks/mm/useReservesData.d.ts +19 -0
- package/dist/hooks/mm/useReservesData.d.ts.map +1 -0
- package/dist/hooks/mm/useWithdraw.d.ts +3 -3
- package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
- package/dist/index.js +31 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/core/index.ts +2 -7
- package/src/hooks/mm/index.ts +1 -0
- package/src/hooks/mm/useBorrow.ts +7 -6
- package/src/hooks/mm/useRepay.ts +6 -6
- package/src/hooks/mm/useReservesData.ts +37 -0
- package/src/hooks/mm/useWithdraw.ts +7 -9
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ dApp Kit is a collection of React components, hooks, and utilities designed to s
|
|
|
12
12
|
- Repay borrowed tokens (`useRepay`)
|
|
13
13
|
- Get user reserves data (`useUserReservesData`)
|
|
14
14
|
- Calculate hub wallet address by using spoke chain id and spoke chain wallet address (`useHubWalletAddress`)
|
|
15
|
+
- Get reserves data (`useReservesData`)
|
|
15
16
|
|
|
16
17
|
- Swap/Intent
|
|
17
18
|
- Get quote for an intent order (`useQuote`)
|
|
@@ -210,8 +211,9 @@ function SwapComponent() {
|
|
|
210
211
|
- [`useRepay()`](./src/hooks/mm/useRepay.ts) - Repay borrowed tokens
|
|
211
212
|
- [`useSupply()`](./src/hooks/mm/useSupply.ts) - Supply tokens to the money market
|
|
212
213
|
- [`useWithdraw()`](./src/hooks/mm/useWithdraw.ts) - Withdraw supplied tokens
|
|
213
|
-
- [`useUserReservesData()`](./src/hooks/mm/useUserReservesData.ts) - Get
|
|
214
|
+
- [`useUserReservesData()`](./src/hooks/mm/useUserReservesData.ts) - Get user's reserves data(supplied asset and debt)
|
|
214
215
|
- [`useHubWalletAddress()`](./src/hooks/mm/useHubWalletAddress.ts) - Get hub wallet address for a spoke chain
|
|
216
|
+
- [`useReservesData()`](./src/hooks/mm/useReservesData.ts) - Get reserves data
|
|
215
217
|
|
|
216
218
|
#### Swap Hooks
|
|
217
219
|
- [`useQuote()`](./src/hooks/swap/useQuote.ts) - Get quote for an intent order
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { XToken, ChainId } from '@sodax/types';
|
|
2
2
|
export declare const allXTokens: XToken[];
|
|
3
|
-
export declare const getSpokeTokenAddressByVault: (spokeChainId: ChainId, vault: string) => string;
|
|
3
|
+
export declare const getSpokeTokenAddressByVault: (spokeChainId: ChainId, vault: string) => string | undefined;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIpD,eAAO,MAAM,UAAU,EAAE,MAAM,EAAO,CAAC;AAyBvC,eAAO,MAAM,2BAA2B,iBAAkB,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIpD,eAAO,MAAM,UAAU,EAAE,MAAM,EAAO,CAAC;AAyBvC,eAAO,MAAM,2BAA2B,iBAAkB,OAAO,SAAS,MAAM,uBAK/E,CAAC"}
|
package/dist/hooks/mm/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { XToken } from '@sodax/types';
|
|
2
2
|
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
3
|
interface BorrowResponse {
|
|
4
4
|
ok: true;
|
|
@@ -13,7 +13,7 @@ interface BorrowResponse {
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
|
-
* const { mutateAsync: borrow, isPending, error } = useBorrow(
|
|
16
|
+
* const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);
|
|
17
17
|
* await borrow('100');
|
|
18
18
|
* ```
|
|
19
19
|
*
|
|
@@ -21,6 +21,6 @@ interface BorrowResponse {
|
|
|
21
21
|
* - spokeProvider is not available
|
|
22
22
|
* - Transaction execution fails
|
|
23
23
|
*/
|
|
24
|
-
export declare function useBorrow(
|
|
24
|
+
export declare function useBorrow(spokeToken: XToken): UseMutationResult<BorrowResponse, Error, string>;
|
|
25
25
|
export {};
|
|
26
26
|
//# sourceMappingURL=useBorrow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBorrow.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useBorrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"useBorrow.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useBorrow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAK5E,UAAU,cAAc;IACtB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAAC,cAAc,EAAE,KAAK,EAAE,MAAM,CAAC,CA2B9F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { XToken } from '@sodax/types';
|
|
2
2
|
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
3
|
interface RepayResponse {
|
|
4
4
|
ok: true;
|
|
@@ -13,7 +13,7 @@ interface RepayResponse {
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
|
-
* const { mutateAsync: repay, isPending, error } = useRepay(
|
|
16
|
+
* const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);
|
|
17
17
|
* await repay('100');
|
|
18
18
|
* ```
|
|
19
19
|
*
|
|
@@ -21,6 +21,6 @@ interface RepayResponse {
|
|
|
21
21
|
* - spokeProvider is not available
|
|
22
22
|
* - Transaction execution fails
|
|
23
23
|
*/
|
|
24
|
-
export declare function useRepay(
|
|
24
|
+
export declare function useRepay(spokeToken: XToken): UseMutationResult<RepayResponse, Error, string>;
|
|
25
25
|
export {};
|
|
26
26
|
//# sourceMappingURL=useRepay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRepay.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useRepay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"useRepay.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useRepay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAK5E,UAAU,aAAa;IACrB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAAC,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,CA0B5F"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for fetching reserves data from the Sodax money market.
|
|
3
|
+
*
|
|
4
|
+
* This hook provides access to the current state of all reserves in the money market protocol,
|
|
5
|
+
* including liquidity, interest rates, and other key metrics. The data is automatically
|
|
6
|
+
* fetched and cached using React Query.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const { data: reservesData, isLoading, error } = useReservesData();
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @returns A React Query result object containing:
|
|
14
|
+
* - data: The reserves data when available
|
|
15
|
+
* - isLoading: Loading state indicator
|
|
16
|
+
* - error: Any error that occurred during data fetching
|
|
17
|
+
*/
|
|
18
|
+
export declare function useReservesData(): import("@tanstack/react-query").UseQueryResult<readonly [readonly import("@sodax/sdk").AggregatedReserveData[], import("@sodax/sdk").BaseCurrencyInfo], Error>;
|
|
19
|
+
//# sourceMappingURL=useReservesData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useReservesData.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,eAAe,mKAc9B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { XToken } from '@sodax/types';
|
|
2
2
|
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
3
|
interface WithdrawResponse {
|
|
4
4
|
ok: true;
|
|
@@ -13,7 +13,7 @@ interface WithdrawResponse {
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
|
-
* const { mutateAsync: withdraw, isPending, error } = useWithdraw(
|
|
16
|
+
* const { mutateAsync: withdraw, isPending, error } = useWithdraw(spokeToken);
|
|
17
17
|
* await withdraw('100');
|
|
18
18
|
* ```
|
|
19
19
|
*
|
|
@@ -21,6 +21,6 @@ interface WithdrawResponse {
|
|
|
21
21
|
* - spokeProvider is not available
|
|
22
22
|
* - Transaction execution fails
|
|
23
23
|
*/
|
|
24
|
-
export declare function useWithdraw(
|
|
24
|
+
export declare function useWithdraw(spokeToken: XToken): UseMutationResult<WithdrawResponse, Error, string>;
|
|
25
25
|
export {};
|
|
26
26
|
//# sourceMappingURL=useWithdraw.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWithdraw.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useWithdraw.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"useWithdraw.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useWithdraw.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAK5E,UAAU,gBAAgB;IACxB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAAC,gBAAgB,EAAE,KAAK,EAAE,MAAM,CAAC,CA2BlG"}
|
package/dist/index.js
CHANGED
|
@@ -118,9 +118,9 @@ function useHubProvider() {
|
|
|
118
118
|
}, [xChainType, hubChainId, hubRpcUrl]);
|
|
119
119
|
return hubProvider;
|
|
120
120
|
}
|
|
121
|
-
function useBorrow(
|
|
121
|
+
function useBorrow(spokeToken) {
|
|
122
122
|
const { sodax } = useSodaxContext();
|
|
123
|
-
const spokeProvider = useSpokeProvider(
|
|
123
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
124
124
|
return reactQuery.useMutation({
|
|
125
125
|
mutationFn: async (amount) => {
|
|
126
126
|
if (!spokeProvider) {
|
|
@@ -128,12 +128,13 @@ function useBorrow(hubToken, spokeChainId) {
|
|
|
128
128
|
}
|
|
129
129
|
const response = await sodax.moneyMarket.borrowAndSubmit(
|
|
130
130
|
{
|
|
131
|
-
token:
|
|
132
|
-
amount: viem.parseUnits(amount,
|
|
131
|
+
token: spokeToken.address,
|
|
132
|
+
amount: viem.parseUnits(amount, 18)
|
|
133
133
|
},
|
|
134
134
|
spokeProvider
|
|
135
135
|
);
|
|
136
136
|
if (!response.ok) {
|
|
137
|
+
console.log("Failed to borrow tokens", response);
|
|
137
138
|
throw new Error("Failed to borrow tokens");
|
|
138
139
|
}
|
|
139
140
|
console.log("Borrow transaction submitted:", response);
|
|
@@ -141,9 +142,9 @@ function useBorrow(hubToken, spokeChainId) {
|
|
|
141
142
|
}
|
|
142
143
|
});
|
|
143
144
|
}
|
|
144
|
-
function useRepay(
|
|
145
|
+
function useRepay(spokeToken) {
|
|
145
146
|
const { sodax } = useSodaxContext();
|
|
146
|
-
const spokeProvider = useSpokeProvider(
|
|
147
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
147
148
|
return reactQuery.useMutation({
|
|
148
149
|
mutationFn: async (amount) => {
|
|
149
150
|
if (!spokeProvider) {
|
|
@@ -151,8 +152,8 @@ function useRepay(hubToken, spokeChainId) {
|
|
|
151
152
|
}
|
|
152
153
|
const response = await sodax.moneyMarket.repayAndSubmit(
|
|
153
154
|
{
|
|
154
|
-
token:
|
|
155
|
-
amount: viem.parseUnits(amount,
|
|
155
|
+
token: spokeToken.address,
|
|
156
|
+
amount: viem.parseUnits(amount, spokeToken.decimals)
|
|
156
157
|
},
|
|
157
158
|
spokeProvider
|
|
158
159
|
);
|
|
@@ -187,9 +188,9 @@ function useSupply(spokeToken) {
|
|
|
187
188
|
}
|
|
188
189
|
});
|
|
189
190
|
}
|
|
190
|
-
function useWithdraw(
|
|
191
|
+
function useWithdraw(spokeToken) {
|
|
191
192
|
const { sodax } = useSodaxContext();
|
|
192
|
-
const spokeProvider = useSpokeProvider(
|
|
193
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
193
194
|
return reactQuery.useMutation({
|
|
194
195
|
mutationFn: async (amount) => {
|
|
195
196
|
if (!spokeProvider) {
|
|
@@ -197,8 +198,9 @@ function useWithdraw(hubToken, spokeChainId) {
|
|
|
197
198
|
}
|
|
198
199
|
const response = await sodax.moneyMarket.withdrawAndSubmit(
|
|
199
200
|
{
|
|
200
|
-
token:
|
|
201
|
-
|
|
201
|
+
token: spokeToken.address,
|
|
202
|
+
// vault token on hub chain decimals is 18
|
|
203
|
+
amount: viem.parseUnits(amount, 18)
|
|
202
204
|
},
|
|
203
205
|
spokeProvider
|
|
204
206
|
);
|
|
@@ -233,11 +235,8 @@ Object.keys(sdk.hubAssets).forEach((xChainId) => {
|
|
|
233
235
|
});
|
|
234
236
|
var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
235
237
|
const tokens = sdk.hubAssets[spokeChainId];
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
throw new Error("Token not found");
|
|
239
|
-
}
|
|
240
|
-
return token;
|
|
238
|
+
const address = Object.keys(tokens).find((tokenAddress) => tokens[tokenAddress].vault === vault);
|
|
239
|
+
return address;
|
|
241
240
|
};
|
|
242
241
|
function useHubWalletAddress(spokeChainId, address, hubProvider) {
|
|
243
242
|
return reactQuery.useQuery({
|
|
@@ -304,6 +303,20 @@ function useUserReservesData(spokeChainId) {
|
|
|
304
303
|
});
|
|
305
304
|
return userReserves;
|
|
306
305
|
}
|
|
306
|
+
function useReservesData() {
|
|
307
|
+
const { sodax } = useSodaxContext();
|
|
308
|
+
const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? "sonic";
|
|
309
|
+
return reactQuery.useQuery({
|
|
310
|
+
queryKey: ["reservesData"],
|
|
311
|
+
queryFn: async () => {
|
|
312
|
+
const moneyMarketConfig = sdk.getMoneyMarketConfig(hubChainId);
|
|
313
|
+
return await sodax.moneyMarket.getReservesData(
|
|
314
|
+
moneyMarketConfig.uiPoolDataProvider,
|
|
315
|
+
moneyMarketConfig.poolAddressesProvider
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
307
320
|
var useQuote = (payload) => {
|
|
308
321
|
const { sodax } = useSodaxContext();
|
|
309
322
|
return reactQuery.useQuery({
|
|
@@ -357,6 +370,7 @@ exports.useHubProvider = useHubProvider;
|
|
|
357
370
|
exports.useHubWalletAddress = useHubWalletAddress;
|
|
358
371
|
exports.useQuote = useQuote;
|
|
359
372
|
exports.useRepay = useRepay;
|
|
373
|
+
exports.useReservesData = useReservesData;
|
|
360
374
|
exports.useSodaxContext = useSodaxContext;
|
|
361
375
|
exports.useSpokeProvider = useSpokeProvider;
|
|
362
376
|
exports.useStatus = useStatus;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contexts/index.ts","../src/hooks/shared/useSodaxContext.ts","../src/hooks/provider/useSpokeProvider.ts","../src/hooks/shared/useAllowance.ts","../src/hooks/shared/useApprove.ts","../src/hooks/provider/useHubProvider.ts","../src/hooks/mm/useBorrow.ts","../src/hooks/mm/useRepay.ts","../src/hooks/mm/useSupply.ts","../src/hooks/mm/useWithdraw.ts","../src/core/index.ts","../src/hooks/mm/useHubWalletAddress.ts","../src/hooks/mm/useUserReservesData.ts","../src/hooks/swap/useQuote.ts","../src/hooks/swap/useCreateIntentOrder.ts","../src/hooks/swap/useStatus.ts","../src/providers/SodaxProvider.tsx"],"names":["createContext","useContext","getXChainType","useWalletProvider","useMemo","EvmSpokeProvider","spokeChainConfig","SuiSpokeProvider","useQuery","parseUnits","useQueryClient","useMutation","getHubChainConfig","EvmHubProvider","hubAssets","EvmWalletAbstraction","useXAccount","getMoneyMarketConfig","Sodax","React"],"mappings":";;;;;;;;;;;;;AAQO,IAAM,YAAA,GAAeA,oBAAuC,IAAI,CAAA;ACChE,IAAM,kBAAkB,MAAwB;AACrD,EAAM,MAAA,OAAA,GAAUC,iBAAW,YAAY,CAAA;AACvC,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,qDAAqD,CAAA;AAAA;AAEvE,EAAO,OAAA,OAAA;AACT;ACJO,SAAS,iBAAiB,YAA4B,EAAA;AAC3D,EAAM,MAAA,UAAA,GAAaC,wBAAc,YAAY,CAAA;AAC7C,EAAM,MAAA,cAAA,GAAiBC,4BAAkB,YAAY,CAAA;AACrD,EAAM,MAAA,aAAA,GAAgBC,cAAQ,MAAM;AAClC,IAAI,IAAA,CAAC,gBAAuB,OAAA,MAAA;AAC5B,IAAA,IAAI,eAAe,KAAO,EAAA;AACxB,MAAA,OAAO,IAAIC,oBAAA;AAAA,QACT,cAAA;A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,SAAA,GAAY,CACvB,cACkF,KAAA;AAClF,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,eAAgB,EAAA;AAClC,EAAA,OAAOH,mBAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,cAAc,CAAA;AAAA,IACzB,SAAS,YAAY;AACnB,MAAA,OAAO,KAAM,CAAA,MAAA,CAAO,SAAU,CAAA,EAAE,gBAAgB,CAAA;AAAA,KAClD;AAAA,IACA,eAAiB,EAAA;AAAA;AAAA,GAClB,CAAA;AACH;AChCO,IAAM,gBAAgB,CAAC,EAAE,UAAU,OAAU,GAAA,KAAA,EAAO,QAA+C,KAAA;AACxG,EAAM,MAAA,KAAA,GAAQ,IAAIU,SAAA,CAAM,MAAM,CAAA;AAE9B,EAAO,uBAAAC,sBAAA,CAAA,aAAA,CAAC,aAAa,QAAb,EAAA,EAAsB,OAAO,EAAE,KAAA,EAAO,OAAQ,EAAA,EAAA,EAAI,QAAS,CAAA;AACrE","file":"index.js","sourcesContent":["import { createContext } from 'react';\nimport type { Sodax } from '@sodax/sdk';\n\nexport interface SodaxContextType {\n sodax: Sodax;\n testnet: boolean;\n}\n\nexport const SodaxContext = createContext<SodaxContextType | null>(null);\n","import { SodaxContext, type SodaxContextType } from '@/contexts';\nimport { useContext } from 'react';\n\n/**\n * Hook to access the Sodax context which provides access to the Sodax SDK instance and chain configuration\n * @throws {Error} If used outside of a SodaxProvider\n * @returns {SodaxContextType} The Sodax context containing SDK instance and configuration\n */\n\nexport const useSodaxContext = (): SodaxContextType => {\n const context = useContext(SodaxContext);\n if (!context) {\n throw new Error('useSodaxContext must be used within a SodaxProvider');\n }\n return context;\n};\n","import {\n EvmSpokeProvider,\n spokeChainConfig,\n type SuiSpokeChainConfig,\n SuiSpokeProvider,\n type EvmSpokeChainConfig,\n} from '@sodax/sdk';\nimport type { IEvmWalletProvider, ISuiWalletProvider, SpokeChainId } from '@sodax/types';\nimport { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\n\nexport function useSpokeProvider(spokeChainId: SpokeChainId) {\n const xChainType = getXChainType(spokeChainId);\n const walletProvider = useWalletProvider(spokeChainId);\n const spokeProvider = useMemo(() => {\n if (!walletProvider) return undefined;\n if (xChainType === 'EVM') {\n return new EvmSpokeProvider(\n walletProvider as IEvmWalletProvider,\n spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,\n );\n }\n if (xChainType === 'SUI') {\n return new SuiSpokeProvider(\n spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,\n walletProvider as ISuiWalletProvider,\n );\n }\n return undefined;\n }, [walletProvider, xChainType, spokeChainId]);\n\n return spokeProvider;\n}\n","import { useQuery } from '@tanstack/react-query';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { parseUnits } from 'viem';\n\nexport function useAllowance(token: XToken, amount: string) {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n\n return useQuery({\n queryKey: ['allowance', token.address, amount],\n queryFn: async () => {\n if (!spokeProvider) {\n return false;\n }\n const allowance = await sodax.moneyMarket.isAllowanceValid(\n {\n token: token.address,\n amount: parseUnits(amount, token.decimals),\n },\n spokeProvider,\n );\n if (allowance.ok) {\n return allowance.value;\n }\n return false;\n },\n enabled: !!spokeProvider,\n });\n}\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { parseUnits } from 'viem';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport type { Address } from '@sodax/sdk';\n\ninterface UseApproveReturn {\n approve: (amount: string) => Promise<boolean>;\n isLoading: boolean;\n error: Error | null;\n resetError: () => void;\n}\n\nexport function useApprove(token: XToken): UseApproveReturn {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n const queryClient = useQueryClient();\n\n const {\n mutateAsync: approve,\n isPending,\n error,\n reset: resetError,\n } = useMutation({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n const allowance = await sodax.moneyMarket.approve(\n token.address as Address,\n parseUnits(amount, token.decimals),\n spokeProvider.chainConfig.addresses.assetManager as Address,\n spokeProvider,\n );\n if (!allowance.ok) {\n throw new Error('Failed to approve tokens');\n }\n return allowance.ok;\n },\n onSuccess: () => {\n // Invalidate allowance query to refetch the new allowance\n queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });\n },\n });\n\n return {\n approve,\n isLoading: isPending,\n error: error as Error | null,\n resetError,\n };\n}\n","import { EvmHubProvider, getHubChainConfig, type HubChainId } from '@sodax/sdk';\nimport { getXChainType } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useHubProvider(): EvmHubProvider | undefined {\n const { sodax } = useSodaxContext();\n const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;\n const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;\n const xChainType = getXChainType(hubChainId);\n const hubProvider = useMemo(() => {\n if (xChainType === 'EVM' && hubChainId && hubRpcUrl) {\n const hubChainCfg = getHubChainConfig(hubChainId);\n\n if (!hubChainCfg) return undefined;\n\n return new EvmHubProvider({\n hubRpcUrl: hubRpcUrl,\n chainConfig: hubChainCfg,\n });\n }\n return undefined;\n }, [xChainType, hubChainId, hubRpcUrl]);\n\n return hubProvider;\n}\n","import type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport type { SpokeChainId } from '@sodax/sdk';\ninterface BorrowResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for borrowing tokens from the Sodax money market.\n *\n * This hook provides functionality to borrow tokens from the money market protocol,\n * handling the entire borrow process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: borrow, isPending, error } = useBorrow(hubToken, spokeChainId);\n * await borrow('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useBorrow(hubToken: XToken, spokeChainId: ChainId): UseMutationResult<BorrowResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<BorrowResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.borrowAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to borrow tokens');\n }\n\n console.log('Borrow transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface RepayResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for repaying borrowed tokens to the Sodax money market.\n *\n * This hook provides functionality to repay borrowed tokens back to the money market protocol,\n * handling the entire repayment process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: repay, isPending, error } = useRepay(hubToken, spokeChainId);\n * await repay('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useRepay(hubToken: XToken, spokeChainId: ChainId): UseMutationResult<RepayResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<RepayResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.repayAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to repay tokens');\n }\n\n console.log('Repay transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface SupplyResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for supplying tokens to the Sodax money market.\n *\n * This hook provides functionality to supply tokens to the money market protocol,\n * handling the entire supply process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to supply on the spoke chain. Must be an XToken with valid address and chain information.\n *\n * @returns {UseMutationResult<SupplyResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the supply transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * - error: Error object if the last transaction failed, null otherwise\n *\n * @example\n * ```typescript\n * const { mutateAsync: supply, isPending, error } = useSupply(spokeToken);\n * await supply('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n */\nexport function useSupply(spokeToken: XToken): UseMutationResult<SupplyResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<SupplyResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.supplyAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to supply tokens');\n }\n\n console.log('Supply transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface WithdrawResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for withdrawing supplied tokens from the Sodax money market.\n *\n * This hook provides functionality to withdraw previously supplied tokens from the money market protocol,\n * handling the entire withdrawal process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: withdraw, isPending, error } = useWithdraw(hubToken, spokeChainId);\n * await withdraw('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useWithdraw(\n hubToken: XToken,\n spokeChainId: ChainId,\n): UseMutationResult<WithdrawResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<WithdrawResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.withdrawAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to withdraw tokens');\n }\n\n console.log('Withdraw transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { XToken, ChainId } from '@sodax/types';\n\nimport { hubAssets } from '@sodax/sdk';\n\nexport const allXTokens: XToken[] = [];\n\nObject.keys(hubAssets).forEach(xChainId => {\n const tokens = hubAssets[xChainId];\n\n Object.keys(tokens).forEach(tokenAddress => {\n const token = tokens[tokenAddress];\n allXTokens.push({\n xChainId: xChainId as ChainId,\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: tokenAddress,\n });\n\n allXTokens.push({\n xChainId: 'sonic',\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: token.vault,\n });\n });\n});\n\nexport const getSpokeTokenAddressByVault = (spokeChainId: ChainId, vault: string) => {\n const tokens = hubAssets[spokeChainId];\n\n const token = Object.keys(tokens).find(tokenAddress => tokens[tokenAddress].vault === vault);\n\n if (!token) {\n throw new Error('Token not found');\n }\n\n return token;\n};\n","import { type EvmHubProvider, EvmWalletAbstraction, type SpokeChainId } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for retrieving the hub wallet address for a given spoke chain and address.\n *\n * This hook fetches the hub wallet address associated with a user's address on a specific spoke chain.\n * It uses the EvmWalletAbstraction to query the hub wallet address from the hub provider.\n *\n * @param spokeChainId - The chain ID of the spoke chain\n * @param address - The user's address on the spoke chain\n * @param hubProvider - The hub provider instance\n *\n * @returns {UseQueryResult<string | null>} A query result object containing:\n * - data: The hub wallet address or null if not found\n * - isLoading: Boolean indicating if the query is in progress\n * - error: Error object if the query failed, null otherwise\n *\n * @example\n * ```typescript\n * const { data: hubWalletAddress, isLoading, error } = useHubWalletAddress(spokeChainId, address, hubProvider);\n * ```\n */\n\nexport function useHubWalletAddress(\n spokeChainId: SpokeChainId,\n address: string | undefined,\n hubProvider: EvmHubProvider,\n): UseQueryResult<string | null> {\n return useQuery({\n queryKey: ['hubWallet', spokeChainId, address],\n queryFn: async () => {\n if (!address) return null;\n\n try {\n const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(\n spokeChainId,\n address as `0x${string}`,\n hubProvider,\n );\n return hubWalletAddress;\n } catch (error) {\n console.log('error', error);\n return null;\n }\n },\n enabled: !!address && !!hubProvider,\n });\n}\n","import { allXTokens } from '@/core';\nimport { getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';\nimport type { HubChainId, SpokeChainId } from '@sodax/types';\nimport { useXAccount, useWalletProvider } from '@sodax/wallet-sdk';\nimport type { ChainId } from '@sodax/types';\nimport { useQuery } from '@tanstack/react-query';\nimport { useHubProvider } from '../provider/useHubProvider';\nimport { useHubWalletAddress } from './useHubWalletAddress';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useUserReservesData(spokeChainId: ChainId) {\n const { sodax } = useSodaxContext();\n const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;\n const hubWalletProvider = useWalletProvider(hubChainId);\n const hubProvider = useHubProvider();\n const { address } = useXAccount(spokeChainId);\n const { data: hubWalletAddress } = useHubWalletAddress(\n spokeChainId as SpokeChainId,\n address,\n hubProvider as EvmHubProvider,\n );\n\n const { data: userReserves } = useQuery({\n queryKey: ['userReserves', hubWalletAddress],\n queryFn: async () => {\n if (!hubWalletProvider) {\n return;\n }\n\n if (!hubWalletAddress) {\n return;\n }\n\n const moneyMarketConfig = getMoneyMarketConfig(hubChainId);\n try {\n const [res] = await sodax.moneyMarket.getUserReservesData(\n hubWalletAddress as `0x${string}`,\n moneyMarketConfig.uiPoolDataProvider,\n moneyMarketConfig.poolAddressesProvider,\n );\n\n return res?.map(r => {\n return {\n ...r,\n token: allXTokens.find(t => t.address === r.underlyingAsset),\n };\n });\n } catch (error) {\n console.log('error', error);\n return;\n }\n },\n enabled: !!address && !!hubWalletProvider && !!hubWalletAddress,\n refetchInterval: 5000,\n });\n\n return userReserves;\n}\n","import type { IntentErrorResponse, IntentQuoteRequest, IntentQuoteResponse, Result } from '@sodax/sdk';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for fetching a quote for an intent-based swap.\n *\n * This hook provides real-time quote data for an intent-based swap.\n *\n * @param {IntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.\n *\n * @returns {UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The quote result from the solver\n * - isLoading: Boolean indicating if the quote is being fetched\n * - error: Error object if the quote request failed\n * - refetch: Function to manually trigger a quote refresh\n *\n * @example\n * ```typescript\n * const { data: quote, isLoading } = useQuote({\n * token_src: '0x...',\n * token_src_blockchain_id: '1',\n * token_dst: '0x...',\n * token_dst_blockchain_id: '2',\n * amount: '1000000000000000000',\n * quote_type: 'exact_input',\n * });\n *\n * if (isLoading) return <div>Loading quote...</div>;\n * if (quote) {\n * console.log('Quote received:', quote);\n * }\n * ```\n *\n * @remarks\n * - The quote is automatically refreshed every 3 seconds\n * - The query is disabled when payload is undefined\n * - Uses React Query for efficient caching and state management\n */\nexport const useQuote = (\n payload: IntentQuoteRequest | undefined,\n): UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [payload],\n queryFn: async () => {\n if (!payload) {\n return undefined;\n }\n return sodax.solver.getQuote(payload);\n },\n enabled: !!payload,\n refetchInterval: 3000,\n });\n};\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport type {\n CreateIntentParams,\n SpokeChainId,\n IntentExecutionResponse,\n Result,\n IntentSubmitErrorCode,\n Intent,\n PacketData,\n IntentSubmitError,\n} from '@sodax/sdk';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\n\ntype CreateIntentResult = Result<\n [IntentExecutionResponse, Intent, PacketData],\n IntentSubmitError<IntentSubmitErrorCode>\n>;\n\n/**\n * Hook for creating and submitting an intent order for cross-chain swaps.\n * Uses React Query's useMutation for better state management and caching.\n *\n * @param {SpokeChainId} chainId - The source chain ID where the swap will originate\n * @returns {UseMutationResult} Mutation result object containing mutation function and state\n *\n * @example\n * ```typescript\n * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');\n *\n * const handleSwap = async () => {\n * const result = await createIntent({\n * token_src: '0x...',\n * token_src_blockchain_id: 'arbitrum',\n * token_dst: '0x...',\n * token_dst_blockchain_id: 'polygon',\n * amount: '1000000000000000000',\n * min_output_amount: '900000000000000000'\n * });\n * };\n * ```\n */\nexport function useCreateIntentOrder(\n chainId: SpokeChainId,\n): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(chainId);\n\n return useMutation<CreateIntentResult, Error, CreateIntentParams>({\n mutationFn: async (params: CreateIntentParams) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n return sodax.solver.createAndSubmitIntent(params, spokeProvider);\n },\n });\n}\n","import type { Hex, IntentErrorResponse, IntentStatusResponse, Result } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\n/**\n * Hook for monitoring the status of an intent-based swap.\n *\n * This hook provides real-time status updates for an intent-based swap transaction.\n *\n * @param {Hex} intent_tx_hash - The transaction hash of the intent order on the hub chain\n *\n * @returns {UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The status result from the solver\n * - isLoading: Boolean indicating if the status is being fetched\n * - error: Error object if the status request failed\n * - refetch: Function to manually trigger a status refresh\n *\n * @example\n * ```typescript\n * const { data: status, isLoading } = useStatus('0x...');\n *\n * if (isLoading) return <div>Loading status...</div>;\n * if (status?.ok) {\n * console.log('Status:', status.value);\n * }\n * ```\n *\n * @remarks\n * - The status is automatically refreshed every 3 seconds\n * - Uses React Query for efficient caching and state management\n */\n\nexport const useStatus = (\n intent_tx_hash: Hex,\n): UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [intent_tx_hash],\n queryFn: async () => {\n return sodax.solver.getStatus({ intent_tx_hash });\n },\n refetchInterval: 3000, // 3s\n });\n};\n","import type { ReactNode, ReactElement } from 'react';\nimport { Sodax, type SodaxConfig } from '@sodax/sdk';\nimport { SodaxContext } from '@/contexts';\nimport React from 'react';\n\ninterface SodaxProviderProps {\n children: ReactNode;\n testnet?: boolean;\n config: SodaxConfig;\n}\n\nexport const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {\n const sodax = new Sodax(config);\n\n return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/contexts/index.ts","../src/hooks/shared/useSodaxContext.ts","../src/hooks/provider/useSpokeProvider.ts","../src/hooks/shared/useAllowance.ts","../src/hooks/shared/useApprove.ts","../src/hooks/provider/useHubProvider.ts","../src/hooks/mm/useBorrow.ts","../src/hooks/mm/useRepay.ts","../src/hooks/mm/useSupply.ts","../src/hooks/mm/useWithdraw.ts","../src/core/index.ts","../src/hooks/mm/useHubWalletAddress.ts","../src/hooks/mm/useUserReservesData.ts","../src/hooks/mm/useReservesData.ts","../src/hooks/swap/useQuote.ts","../src/hooks/swap/useCreateIntentOrder.ts","../src/hooks/swap/useStatus.ts","../src/providers/SodaxProvider.tsx"],"names":["createContext","useContext","getXChainType","useWalletProvider","useMemo","EvmSpokeProvider","spokeChainConfig","SuiSpokeProvider","useQuery","parseUnits","useQueryClient","useMutation","getHubChainConfig","EvmHubProvider","hubAssets","EvmWalletAbstraction","useXAccount","getMoneyMarketConfig","Sodax","React"],"mappings":";;;;;;;;;;;;;AAQO,IAAM,YAAA,GAAeA,oBAAuC,IAAI,CAAA;ACChE,IAAM,kBAAkB,MAAwB;AACrD,EAAM,MAAA,OAAA,GAAUC,iBAAW,YAAY,CAAA;AACvC,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,qDAAqD,CAAA;AAAA;AAEvE,EAAO,OAAA,OAAA;AACT;ACJO,SAAS,iBAAiB,YAA4B,EAAA;AAC3D,EAAM,MAAA,UAAA,GAAaC,wBAAc,YAAY,CAAA;AAC7C,EAAM,MAAA,cAAA,GAAiBC,4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AAS,CAAA;AACrE","file":"index.js","sourcesContent":["import { createContext } from 'react';\nimport type { Sodax } from '@sodax/sdk';\n\nexport interface SodaxContextType {\n sodax: Sodax;\n testnet: boolean;\n}\n\nexport const SodaxContext = createContext<SodaxContextType | null>(null);\n","import { SodaxContext, type SodaxContextType } from '@/contexts';\nimport { useContext } from 'react';\n\n/**\n * Hook to access the Sodax context which provides access to the Sodax SDK instance and chain configuration\n * @throws {Error} If used outside of a SodaxProvider\n * @returns {SodaxContextType} The Sodax context containing SDK instance and configuration\n */\n\nexport const useSodaxContext = (): SodaxContextType => {\n const context = useContext(SodaxContext);\n if (!context) {\n throw new Error('useSodaxContext must be used within a SodaxProvider');\n }\n return context;\n};\n","import {\n EvmSpokeProvider,\n spokeChainConfig,\n type SuiSpokeChainConfig,\n SuiSpokeProvider,\n type EvmSpokeChainConfig,\n} from '@sodax/sdk';\nimport type { IEvmWalletProvider, ISuiWalletProvider, SpokeChainId } from '@sodax/types';\nimport { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\n\nexport function useSpokeProvider(spokeChainId: SpokeChainId) {\n const xChainType = getXChainType(spokeChainId);\n const walletProvider = useWalletProvider(spokeChainId);\n const spokeProvider = useMemo(() => {\n if (!walletProvider) return undefined;\n if (xChainType === 'EVM') {\n return new EvmSpokeProvider(\n walletProvider as IEvmWalletProvider,\n spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,\n );\n }\n if (xChainType === 'SUI') {\n return new SuiSpokeProvider(\n spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,\n walletProvider as ISuiWalletProvider,\n );\n }\n return undefined;\n }, [walletProvider, xChainType, spokeChainId]);\n\n return spokeProvider;\n}\n","import { useQuery } from '@tanstack/react-query';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { parseUnits } from 'viem';\n\nexport function useAllowance(token: XToken, amount: string) {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n\n return useQuery({\n queryKey: ['allowance', token.address, amount],\n queryFn: async () => {\n if (!spokeProvider) {\n return false;\n }\n const allowance = await sodax.moneyMarket.isAllowanceValid(\n {\n token: token.address,\n amount: parseUnits(amount, token.decimals),\n },\n spokeProvider,\n );\n if (allowance.ok) {\n return allowance.value;\n }\n return false;\n },\n enabled: !!spokeProvider,\n });\n}\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { parseUnits } from 'viem';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport type { Address } from '@sodax/sdk';\n\ninterface UseApproveReturn {\n approve: (amount: string) => Promise<boolean>;\n isLoading: boolean;\n error: Error | null;\n resetError: () => void;\n}\n\nexport function useApprove(token: XToken): UseApproveReturn {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n const queryClient = useQueryClient();\n\n const {\n mutateAsync: approve,\n isPending,\n error,\n reset: resetError,\n } = useMutation({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n const allowance = await sodax.moneyMarket.approve(\n token.address as Address,\n parseUnits(amount, token.decimals),\n spokeProvider.chainConfig.addresses.assetManager as Address,\n spokeProvider,\n );\n if (!allowance.ok) {\n throw new Error('Failed to approve tokens');\n }\n return allowance.ok;\n },\n onSuccess: () => {\n // Invalidate allowance query to refetch the new allowance\n queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });\n },\n });\n\n return {\n approve,\n isLoading: isPending,\n error: error as Error | null,\n resetError,\n };\n}\n","import { EvmHubProvider, getHubChainConfig, type HubChainId } from '@sodax/sdk';\nimport { getXChainType } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useHubProvider(): EvmHubProvider | undefined {\n const { sodax } = useSodaxContext();\n const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;\n const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;\n const xChainType = getXChainType(hubChainId);\n const hubProvider = useMemo(() => {\n if (xChainType === 'EVM' && hubChainId && hubRpcUrl) {\n const hubChainCfg = getHubChainConfig(hubChainId);\n\n if (!hubChainCfg) return undefined;\n\n return new EvmHubProvider({\n hubRpcUrl: hubRpcUrl,\n chainConfig: hubChainCfg,\n });\n }\n return undefined;\n }, [xChainType, hubChainId, hubRpcUrl]);\n\n return hubProvider;\n}\n","import type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport type { SpokeChainId } from '@sodax/sdk';\ninterface BorrowResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for borrowing tokens from the Sodax money market.\n *\n * This hook provides functionality to borrow tokens from the money market protocol,\n * handling the entire borrow process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);\n * await borrow('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useBorrow(spokeToken: XToken): UseMutationResult<BorrowResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<BorrowResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.borrowAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, 18),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n console.log('Failed to borrow tokens', response);\n throw new Error('Failed to borrow tokens');\n }\n\n console.log('Borrow transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface RepayResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for repaying borrowed tokens to the Sodax money market.\n *\n * This hook provides functionality to repay borrowed tokens back to the money market protocol,\n * handling the entire repayment process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);\n * await repay('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useRepay(spokeToken: XToken): UseMutationResult<RepayResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<RepayResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.repayAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to repay tokens');\n }\n\n console.log('Repay transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface SupplyResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for supplying tokens to the Sodax money market.\n *\n * This hook provides functionality to supply tokens to the money market protocol,\n * handling the entire supply process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to supply on the spoke chain. Must be an XToken with valid address and chain information.\n *\n * @returns {UseMutationResult<SupplyResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the supply transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * - error: Error object if the last transaction failed, null otherwise\n *\n * @example\n * ```typescript\n * const { mutateAsync: supply, isPending, error } = useSupply(spokeToken);\n * await supply('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n */\nexport function useSupply(spokeToken: XToken): UseMutationResult<SupplyResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<SupplyResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.supplyAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to supply tokens');\n }\n\n console.log('Supply transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface WithdrawResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for withdrawing supplied tokens from the Sodax money market.\n *\n * This hook provides functionality to withdraw previously supplied tokens from the money market protocol,\n * handling the entire withdrawal process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: withdraw, isPending, error } = useWithdraw(spokeToken);\n * await withdraw('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useWithdraw(spokeToken: XToken): UseMutationResult<WithdrawResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<WithdrawResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.withdrawAndSubmit(\n {\n token: spokeToken.address,\n // vault token on hub chain decimals is 18\n amount: parseUnits(amount, 18),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to withdraw tokens');\n }\n\n console.log('Withdraw transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { XToken, ChainId } from '@sodax/types';\n\nimport { hubAssets } from '@sodax/sdk';\n\nexport const allXTokens: XToken[] = [];\n\nObject.keys(hubAssets).forEach(xChainId => {\n const tokens = hubAssets[xChainId];\n\n Object.keys(tokens).forEach(tokenAddress => {\n const token = tokens[tokenAddress];\n allXTokens.push({\n xChainId: xChainId as ChainId,\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: tokenAddress,\n });\n\n allXTokens.push({\n xChainId: 'sonic',\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: token.vault,\n });\n });\n});\n\nexport const getSpokeTokenAddressByVault = (spokeChainId: ChainId, vault: string) => {\n const tokens = hubAssets[spokeChainId];\n const address = Object.keys(tokens).find(tokenAddress => tokens[tokenAddress].vault === vault);\n\n return address;\n};\n","import { type EvmHubProvider, EvmWalletAbstraction, type SpokeChainId } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for retrieving the hub wallet address for a given spoke chain and address.\n *\n * This hook fetches the hub wallet address associated with a user's address on a specific spoke chain.\n * It uses the EvmWalletAbstraction to query the hub wallet address from the hub provider.\n *\n * @param spokeChainId - The chain ID of the spoke chain\n * @param address - The user's address on the spoke chain\n * @param hubProvider - The hub provider instance\n *\n * @returns {UseQueryResult<string | null>} A query result object containing:\n * - data: The hub wallet address or null if not found\n * - isLoading: Boolean indicating if the query is in progress\n * - error: Error object if the query failed, null otherwise\n *\n * @example\n * ```typescript\n * const { data: hubWalletAddress, isLoading, error } = useHubWalletAddress(spokeChainId, address, hubProvider);\n * ```\n */\n\nexport function useHubWalletAddress(\n spokeChainId: SpokeChainId,\n address: string | undefined,\n hubProvider: EvmHubProvider,\n): UseQueryResult<string | null> {\n return useQuery({\n queryKey: ['hubWallet', spokeChainId, address],\n queryFn: async () => {\n if (!address) return null;\n\n try {\n const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(\n spokeChainId,\n address as `0x${string}`,\n hubProvider,\n );\n return hubWalletAddress;\n } catch (error) {\n console.log('error', error);\n return null;\n }\n },\n enabled: !!address && !!hubProvider,\n });\n}\n","import { allXTokens } from '@/core';\nimport { getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';\nimport type { HubChainId, SpokeChainId } from '@sodax/types';\nimport { useXAccount, useWalletProvider } from '@sodax/wallet-sdk';\nimport type { ChainId } from '@sodax/types';\nimport { useQuery } from '@tanstack/react-query';\nimport { useHubProvider } from '../provider/useHubProvider';\nimport { useHubWalletAddress } from './useHubWalletAddress';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useUserReservesData(spokeChainId: ChainId) {\n const { sodax } = useSodaxContext();\n const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;\n const hubWalletProvider = useWalletProvider(hubChainId);\n const hubProvider = useHubProvider();\n const { address } = useXAccount(spokeChainId);\n const { data: hubWalletAddress } = useHubWalletAddress(\n spokeChainId as SpokeChainId,\n address,\n hubProvider as EvmHubProvider,\n );\n\n const { data: userReserves } = useQuery({\n queryKey: ['userReserves', hubWalletAddress],\n queryFn: async () => {\n if (!hubWalletProvider) {\n return;\n }\n\n if (!hubWalletAddress) {\n return;\n }\n\n const moneyMarketConfig = getMoneyMarketConfig(hubChainId);\n try {\n const [res] = await sodax.moneyMarket.getUserReservesData(\n hubWalletAddress as `0x${string}`,\n moneyMarketConfig.uiPoolDataProvider,\n moneyMarketConfig.poolAddressesProvider,\n );\n\n return res?.map(r => {\n return {\n ...r,\n token: allXTokens.find(t => t.address === r.underlyingAsset),\n };\n });\n } catch (error) {\n console.log('error', error);\n return;\n }\n },\n enabled: !!address && !!hubWalletProvider && !!hubWalletAddress,\n refetchInterval: 5000,\n });\n\n return userReserves;\n}\n","import { getMoneyMarketConfig } from '@sodax/sdk';\nimport type { HubChainId } from '@sodax/types';\nimport { useQuery } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n/**\n * Hook for fetching reserves data from the Sodax money market.\n *\n * This hook provides access to the current state of all reserves in the money market protocol,\n * including liquidity, interest rates, and other key metrics. The data is automatically\n * fetched and cached using React Query.\n *\n * @example\n * ```typescript\n * const { data: reservesData, isLoading, error } = useReservesData();\n * ```\n *\n * @returns A React Query result object containing:\n * - data: The reserves data when available\n * - isLoading: Loading state indicator\n * - error: Any error that occurred during data fetching\n */\n\nexport function useReservesData() {\n const { sodax } = useSodaxContext();\n const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;\n\n return useQuery({\n queryKey: ['reservesData'],\n queryFn: async () => {\n const moneyMarketConfig = getMoneyMarketConfig(hubChainId);\n return await sodax.moneyMarket.getReservesData(\n moneyMarketConfig.uiPoolDataProvider,\n moneyMarketConfig.poolAddressesProvider,\n );\n },\n });\n}\n","import type { IntentErrorResponse, IntentQuoteRequest, IntentQuoteResponse, Result } from '@sodax/sdk';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for fetching a quote for an intent-based swap.\n *\n * This hook provides real-time quote data for an intent-based swap.\n *\n * @param {IntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.\n *\n * @returns {UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The quote result from the solver\n * - isLoading: Boolean indicating if the quote is being fetched\n * - error: Error object if the quote request failed\n * - refetch: Function to manually trigger a quote refresh\n *\n * @example\n * ```typescript\n * const { data: quote, isLoading } = useQuote({\n * token_src: '0x...',\n * token_src_blockchain_id: '1',\n * token_dst: '0x...',\n * token_dst_blockchain_id: '2',\n * amount: '1000000000000000000',\n * quote_type: 'exact_input',\n * });\n *\n * if (isLoading) return <div>Loading quote...</div>;\n * if (quote) {\n * console.log('Quote received:', quote);\n * }\n * ```\n *\n * @remarks\n * - The quote is automatically refreshed every 3 seconds\n * - The query is disabled when payload is undefined\n * - Uses React Query for efficient caching and state management\n */\nexport const useQuote = (\n payload: IntentQuoteRequest | undefined,\n): UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [payload],\n queryFn: async () => {\n if (!payload) {\n return undefined;\n }\n return sodax.solver.getQuote(payload);\n },\n enabled: !!payload,\n refetchInterval: 3000,\n });\n};\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport type {\n CreateIntentParams,\n SpokeChainId,\n IntentExecutionResponse,\n Result,\n IntentSubmitErrorCode,\n Intent,\n PacketData,\n IntentSubmitError,\n} from '@sodax/sdk';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\n\ntype CreateIntentResult = Result<\n [IntentExecutionResponse, Intent, PacketData],\n IntentSubmitError<IntentSubmitErrorCode>\n>;\n\n/**\n * Hook for creating and submitting an intent order for cross-chain swaps.\n * Uses React Query's useMutation for better state management and caching.\n *\n * @param {SpokeChainId} chainId - The source chain ID where the swap will originate\n * @returns {UseMutationResult} Mutation result object containing mutation function and state\n *\n * @example\n * ```typescript\n * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');\n *\n * const handleSwap = async () => {\n * const result = await createIntent({\n * token_src: '0x...',\n * token_src_blockchain_id: 'arbitrum',\n * token_dst: '0x...',\n * token_dst_blockchain_id: 'polygon',\n * amount: '1000000000000000000',\n * min_output_amount: '900000000000000000'\n * });\n * };\n * ```\n */\nexport function useCreateIntentOrder(\n chainId: SpokeChainId,\n): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(chainId);\n\n return useMutation<CreateIntentResult, Error, CreateIntentParams>({\n mutationFn: async (params: CreateIntentParams) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n return sodax.solver.createAndSubmitIntent(params, spokeProvider);\n },\n });\n}\n","import type { Hex, IntentErrorResponse, IntentStatusResponse, Result } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\n/**\n * Hook for monitoring the status of an intent-based swap.\n *\n * This hook provides real-time status updates for an intent-based swap transaction.\n *\n * @param {Hex} intent_tx_hash - The transaction hash of the intent order on the hub chain\n *\n * @returns {UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The status result from the solver\n * - isLoading: Boolean indicating if the status is being fetched\n * - error: Error object if the status request failed\n * - refetch: Function to manually trigger a status refresh\n *\n * @example\n * ```typescript\n * const { data: status, isLoading } = useStatus('0x...');\n *\n * if (isLoading) return <div>Loading status...</div>;\n * if (status?.ok) {\n * console.log('Status:', status.value);\n * }\n * ```\n *\n * @remarks\n * - The status is automatically refreshed every 3 seconds\n * - Uses React Query for efficient caching and state management\n */\n\nexport const useStatus = (\n intent_tx_hash: Hex,\n): UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [intent_tx_hash],\n queryFn: async () => {\n return sodax.solver.getStatus({ intent_tx_hash });\n },\n refetchInterval: 3000, // 3s\n });\n};\n","import type { ReactNode, ReactElement } from 'react';\nimport { Sodax, type SodaxConfig } from '@sodax/sdk';\nimport { SodaxContext } from '@/contexts';\nimport React from 'react';\n\ninterface SodaxProviderProps {\n children: ReactNode;\n testnet?: boolean;\n config: SodaxConfig;\n}\n\nexport const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {\n const sodax = new Sodax(config);\n\n return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;\n};\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -112,9 +112,9 @@ function useHubProvider() {
|
|
|
112
112
|
}, [xChainType, hubChainId, hubRpcUrl]);
|
|
113
113
|
return hubProvider;
|
|
114
114
|
}
|
|
115
|
-
function useBorrow(
|
|
115
|
+
function useBorrow(spokeToken) {
|
|
116
116
|
const { sodax } = useSodaxContext();
|
|
117
|
-
const spokeProvider = useSpokeProvider(
|
|
117
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
118
118
|
return useMutation({
|
|
119
119
|
mutationFn: async (amount) => {
|
|
120
120
|
if (!spokeProvider) {
|
|
@@ -122,12 +122,13 @@ function useBorrow(hubToken, spokeChainId) {
|
|
|
122
122
|
}
|
|
123
123
|
const response = await sodax.moneyMarket.borrowAndSubmit(
|
|
124
124
|
{
|
|
125
|
-
token:
|
|
126
|
-
amount: parseUnits(amount,
|
|
125
|
+
token: spokeToken.address,
|
|
126
|
+
amount: parseUnits(amount, 18)
|
|
127
127
|
},
|
|
128
128
|
spokeProvider
|
|
129
129
|
);
|
|
130
130
|
if (!response.ok) {
|
|
131
|
+
console.log("Failed to borrow tokens", response);
|
|
131
132
|
throw new Error("Failed to borrow tokens");
|
|
132
133
|
}
|
|
133
134
|
console.log("Borrow transaction submitted:", response);
|
|
@@ -135,9 +136,9 @@ function useBorrow(hubToken, spokeChainId) {
|
|
|
135
136
|
}
|
|
136
137
|
});
|
|
137
138
|
}
|
|
138
|
-
function useRepay(
|
|
139
|
+
function useRepay(spokeToken) {
|
|
139
140
|
const { sodax } = useSodaxContext();
|
|
140
|
-
const spokeProvider = useSpokeProvider(
|
|
141
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
141
142
|
return useMutation({
|
|
142
143
|
mutationFn: async (amount) => {
|
|
143
144
|
if (!spokeProvider) {
|
|
@@ -145,8 +146,8 @@ function useRepay(hubToken, spokeChainId) {
|
|
|
145
146
|
}
|
|
146
147
|
const response = await sodax.moneyMarket.repayAndSubmit(
|
|
147
148
|
{
|
|
148
|
-
token:
|
|
149
|
-
amount: parseUnits(amount,
|
|
149
|
+
token: spokeToken.address,
|
|
150
|
+
amount: parseUnits(amount, spokeToken.decimals)
|
|
150
151
|
},
|
|
151
152
|
spokeProvider
|
|
152
153
|
);
|
|
@@ -181,9 +182,9 @@ function useSupply(spokeToken) {
|
|
|
181
182
|
}
|
|
182
183
|
});
|
|
183
184
|
}
|
|
184
|
-
function useWithdraw(
|
|
185
|
+
function useWithdraw(spokeToken) {
|
|
185
186
|
const { sodax } = useSodaxContext();
|
|
186
|
-
const spokeProvider = useSpokeProvider(
|
|
187
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
187
188
|
return useMutation({
|
|
188
189
|
mutationFn: async (amount) => {
|
|
189
190
|
if (!spokeProvider) {
|
|
@@ -191,8 +192,9 @@ function useWithdraw(hubToken, spokeChainId) {
|
|
|
191
192
|
}
|
|
192
193
|
const response = await sodax.moneyMarket.withdrawAndSubmit(
|
|
193
194
|
{
|
|
194
|
-
token:
|
|
195
|
-
|
|
195
|
+
token: spokeToken.address,
|
|
196
|
+
// vault token on hub chain decimals is 18
|
|
197
|
+
amount: parseUnits(amount, 18)
|
|
196
198
|
},
|
|
197
199
|
spokeProvider
|
|
198
200
|
);
|
|
@@ -227,11 +229,8 @@ Object.keys(hubAssets).forEach((xChainId) => {
|
|
|
227
229
|
});
|
|
228
230
|
var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
229
231
|
const tokens = hubAssets[spokeChainId];
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
throw new Error("Token not found");
|
|
233
|
-
}
|
|
234
|
-
return token;
|
|
232
|
+
const address = Object.keys(tokens).find((tokenAddress) => tokens[tokenAddress].vault === vault);
|
|
233
|
+
return address;
|
|
235
234
|
};
|
|
236
235
|
function useHubWalletAddress(spokeChainId, address, hubProvider) {
|
|
237
236
|
return useQuery({
|
|
@@ -298,6 +297,20 @@ function useUserReservesData(spokeChainId) {
|
|
|
298
297
|
});
|
|
299
298
|
return userReserves;
|
|
300
299
|
}
|
|
300
|
+
function useReservesData() {
|
|
301
|
+
const { sodax } = useSodaxContext();
|
|
302
|
+
const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? "sonic";
|
|
303
|
+
return useQuery({
|
|
304
|
+
queryKey: ["reservesData"],
|
|
305
|
+
queryFn: async () => {
|
|
306
|
+
const moneyMarketConfig = getMoneyMarketConfig(hubChainId);
|
|
307
|
+
return await sodax.moneyMarket.getReservesData(
|
|
308
|
+
moneyMarketConfig.uiPoolDataProvider,
|
|
309
|
+
moneyMarketConfig.poolAddressesProvider
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
301
314
|
var useQuote = (payload) => {
|
|
302
315
|
const { sodax } = useSodaxContext();
|
|
303
316
|
return useQuery({
|
|
@@ -340,6 +353,6 @@ var SodaxProvider = ({ children, testnet = false, config }) => {
|
|
|
340
353
|
return /* @__PURE__ */ React.createElement(SodaxContext.Provider, { value: { sodax, testnet } }, children);
|
|
341
354
|
};
|
|
342
355
|
|
|
343
|
-
export { SodaxProvider, allXTokens, getSpokeTokenAddressByVault, useAllowance, useApprove, useBorrow, useCreateIntentOrder, useHubProvider, useHubWalletAddress, useQuote, useRepay, useSodaxContext, useSpokeProvider, useStatus, useSupply, useUserReservesData, useWithdraw };
|
|
356
|
+
export { SodaxProvider, allXTokens, getSpokeTokenAddressByVault, useAllowance, useApprove, useBorrow, useCreateIntentOrder, useHubProvider, useHubWalletAddress, useQuote, useRepay, useReservesData, useSodaxContext, useSpokeProvider, useStatus, useSupply, useUserReservesData, useWithdraw };
|
|
344
357
|
//# sourceMappingURL=index.mjs.map
|
|
345
358
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contexts/index.ts","../src/hooks/shared/useSodaxContext.ts","../src/hooks/provider/useSpokeProvider.ts","../src/hooks/shared/useAllowance.ts","../src/hooks/shared/useApprove.ts","../src/hooks/provider/useHubProvider.ts","../src/hooks/mm/useBorrow.ts","../src/hooks/mm/useRepay.ts","../src/hooks/mm/useSupply.ts","../src/hooks/mm/useWithdraw.ts","../src/core/index.ts","../src/hooks/mm/useHubWalletAddress.ts","../src/hooks/mm/useUserReservesData.ts","../src/hooks/swap/useQuote.ts","../src/hooks/swap/useCreateIntentOrder.ts","../src/hooks/swap/useStatus.ts","../src/providers/SodaxProvider.tsx"],"names":["parseUnits","getXChainType","useMemo","useMutation","useQuery","useWalletProvider"],"mappings":";;;;;;;AAQO,IAAM,YAAA,GAAe,cAAuC,IAAI,CAAA;ACChE,IAAM,kBAAkB,MAAwB;AACrD,EAAM,MAAA,OAAA,GAAU,WAAW,YAAY,CAAA;AACvC,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,qDAAqD,CAAA;AAAA;AAEvE,EAAO,OAAA,OAAA;AACT;ACJO,SAAS,iBAAiB,YAA4B,EAAA;AAC3D,EAAM,MAAA,UAAA,GAAa,cAAc,YAAY,CAAA;AAC7C,EAAM,MAAA,cAAA,GAAiB,kBAAkB,YAAY,CAAA;AACrD,EAAM,MAAA,aAAA,GAAgB,QAAQ,MAAM;AAClC,IAAI,IAAA,CAAC,gBAAuB,OAAA,MAAA;AAC5B,IAAA,IAAI,eAAe,KAAO,EAAA;AACxB,MAAA,OAAO,IAAI,gBAAA;AAAA,QACT,cAAA;AAAA,QACA,iBAAiB,YAAY;AAAA,OAC/B;AAAA;AAEF,IAAA,IAAI,eAAe,K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C,QAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,cAAc,CAAA;AAAA,IACzB,SAAS,YAAY;AACnB,MAAA,OAAO,KAAM,CAAA,MAAA,CAAO,SAAU,CAAA,EAAE,gBAAgB,CAAA;AAAA,KAClD;AAAA,IACA,eAAiB,EAAA;AAAA;AAAA,GAClB,CAAA;AACH;AChCO,IAAM,gBAAgB,CAAC,EAAE,UAAU,OAAU,GAAA,KAAA,EAAO,QAA+C,KAAA;AACxG,EAAM,MAAA,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAM,CAAA;AAE9B,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,aAAa,QAAb,EAAA,EAAsB,OAAO,EAAE,KAAA,EAAO,OAAQ,EAAA,EAAA,EAAI,QAAS,CAAA;AACrE","file":"index.mjs","sourcesContent":["import { createContext } from 'react';\nimport type { Sodax } from '@sodax/sdk';\n\nexport interface SodaxContextType {\n sodax: Sodax;\n testnet: boolean;\n}\n\nexport const SodaxContext = createContext<SodaxContextType | null>(null);\n","import { SodaxContext, type SodaxContextType } from '@/contexts';\nimport { useContext } from 'react';\n\n/**\n * Hook to access the Sodax context which provides access to the Sodax SDK instance and chain configuration\n * @throws {Error} If used outside of a SodaxProvider\n * @returns {SodaxContextType} The Sodax context containing SDK instance and configuration\n */\n\nexport const useSodaxContext = (): SodaxContextType => {\n const context = useContext(SodaxContext);\n if (!context) {\n throw new Error('useSodaxContext must be used within a SodaxProvider');\n }\n return context;\n};\n","import {\n EvmSpokeProvider,\n spokeChainConfig,\n type SuiSpokeChainConfig,\n SuiSpokeProvider,\n type EvmSpokeChainConfig,\n} from '@sodax/sdk';\nimport type { IEvmWalletProvider, ISuiWalletProvider, SpokeChainId } from '@sodax/types';\nimport { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\n\nexport function useSpokeProvider(spokeChainId: SpokeChainId) {\n const xChainType = getXChainType(spokeChainId);\n const walletProvider = useWalletProvider(spokeChainId);\n const spokeProvider = useMemo(() => {\n if (!walletProvider) return undefined;\n if (xChainType === 'EVM') {\n return new EvmSpokeProvider(\n walletProvider as IEvmWalletProvider,\n spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,\n );\n }\n if (xChainType === 'SUI') {\n return new SuiSpokeProvider(\n spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,\n walletProvider as ISuiWalletProvider,\n );\n }\n return undefined;\n }, [walletProvider, xChainType, spokeChainId]);\n\n return spokeProvider;\n}\n","import { useQuery } from '@tanstack/react-query';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { parseUnits } from 'viem';\n\nexport function useAllowance(token: XToken, amount: string) {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n\n return useQuery({\n queryKey: ['allowance', token.address, amount],\n queryFn: async () => {\n if (!spokeProvider) {\n return false;\n }\n const allowance = await sodax.moneyMarket.isAllowanceValid(\n {\n token: token.address,\n amount: parseUnits(amount, token.decimals),\n },\n spokeProvider,\n );\n if (allowance.ok) {\n return allowance.value;\n }\n return false;\n },\n enabled: !!spokeProvider,\n });\n}\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { parseUnits } from 'viem';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport type { Address } from '@sodax/sdk';\n\ninterface UseApproveReturn {\n approve: (amount: string) => Promise<boolean>;\n isLoading: boolean;\n error: Error | null;\n resetError: () => void;\n}\n\nexport function useApprove(token: XToken): UseApproveReturn {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n const queryClient = useQueryClient();\n\n const {\n mutateAsync: approve,\n isPending,\n error,\n reset: resetError,\n } = useMutation({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n const allowance = await sodax.moneyMarket.approve(\n token.address as Address,\n parseUnits(amount, token.decimals),\n spokeProvider.chainConfig.addresses.assetManager as Address,\n spokeProvider,\n );\n if (!allowance.ok) {\n throw new Error('Failed to approve tokens');\n }\n return allowance.ok;\n },\n onSuccess: () => {\n // Invalidate allowance query to refetch the new allowance\n queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });\n },\n });\n\n return {\n approve,\n isLoading: isPending,\n error: error as Error | null,\n resetError,\n };\n}\n","import { EvmHubProvider, getHubChainConfig, type HubChainId } from '@sodax/sdk';\nimport { getXChainType } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useHubProvider(): EvmHubProvider | undefined {\n const { sodax } = useSodaxContext();\n const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;\n const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;\n const xChainType = getXChainType(hubChainId);\n const hubProvider = useMemo(() => {\n if (xChainType === 'EVM' && hubChainId && hubRpcUrl) {\n const hubChainCfg = getHubChainConfig(hubChainId);\n\n if (!hubChainCfg) return undefined;\n\n return new EvmHubProvider({\n hubRpcUrl: hubRpcUrl,\n chainConfig: hubChainCfg,\n });\n }\n return undefined;\n }, [xChainType, hubChainId, hubRpcUrl]);\n\n return hubProvider;\n}\n","import type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport type { SpokeChainId } from '@sodax/sdk';\ninterface BorrowResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for borrowing tokens from the Sodax money market.\n *\n * This hook provides functionality to borrow tokens from the money market protocol,\n * handling the entire borrow process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: borrow, isPending, error } = useBorrow(hubToken, spokeChainId);\n * await borrow('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useBorrow(hubToken: XToken, spokeChainId: ChainId): UseMutationResult<BorrowResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<BorrowResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.borrowAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to borrow tokens');\n }\n\n console.log('Borrow transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface RepayResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for repaying borrowed tokens to the Sodax money market.\n *\n * This hook provides functionality to repay borrowed tokens back to the money market protocol,\n * handling the entire repayment process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: repay, isPending, error } = useRepay(hubToken, spokeChainId);\n * await repay('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useRepay(hubToken: XToken, spokeChainId: ChainId): UseMutationResult<RepayResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<RepayResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.repayAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to repay tokens');\n }\n\n console.log('Repay transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface SupplyResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for supplying tokens to the Sodax money market.\n *\n * This hook provides functionality to supply tokens to the money market protocol,\n * handling the entire supply process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to supply on the spoke chain. Must be an XToken with valid address and chain information.\n *\n * @returns {UseMutationResult<SupplyResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the supply transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * - error: Error object if the last transaction failed, null otherwise\n *\n * @example\n * ```typescript\n * const { mutateAsync: supply, isPending, error } = useSupply(spokeToken);\n * await supply('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n */\nexport function useSupply(spokeToken: XToken): UseMutationResult<SupplyResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<SupplyResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.supplyAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to supply tokens');\n }\n\n console.log('Supply transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface WithdrawResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for withdrawing supplied tokens from the Sodax money market.\n *\n * This hook provides functionality to withdraw previously supplied tokens from the money market protocol,\n * handling the entire withdrawal process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: withdraw, isPending, error } = useWithdraw(hubToken, spokeChainId);\n * await withdraw('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useWithdraw(\n hubToken: XToken,\n spokeChainId: ChainId,\n): UseMutationResult<WithdrawResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<WithdrawResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.withdrawAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to withdraw tokens');\n }\n\n console.log('Withdraw transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { XToken, ChainId } from '@sodax/types';\n\nimport { hubAssets } from '@sodax/sdk';\n\nexport const allXTokens: XToken[] = [];\n\nObject.keys(hubAssets).forEach(xChainId => {\n const tokens = hubAssets[xChainId];\n\n Object.keys(tokens).forEach(tokenAddress => {\n const token = tokens[tokenAddress];\n allXTokens.push({\n xChainId: xChainId as ChainId,\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: tokenAddress,\n });\n\n allXTokens.push({\n xChainId: 'sonic',\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: token.vault,\n });\n });\n});\n\nexport const getSpokeTokenAddressByVault = (spokeChainId: ChainId, vault: string) => {\n const tokens = hubAssets[spokeChainId];\n\n const token = Object.keys(tokens).find(tokenAddress => tokens[tokenAddress].vault === vault);\n\n if (!token) {\n throw new Error('Token not found');\n }\n\n return token;\n};\n","import { type EvmHubProvider, EvmWalletAbstraction, type SpokeChainId } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for retrieving the hub wallet address for a given spoke chain and address.\n *\n * This hook fetches the hub wallet address associated with a user's address on a specific spoke chain.\n * It uses the EvmWalletAbstraction to query the hub wallet address from the hub provider.\n *\n * @param spokeChainId - The chain ID of the spoke chain\n * @param address - The user's address on the spoke chain\n * @param hubProvider - The hub provider instance\n *\n * @returns {UseQueryResult<string | null>} A query result object containing:\n * - data: The hub wallet address or null if not found\n * - isLoading: Boolean indicating if the query is in progress\n * - error: Error object if the query failed, null otherwise\n *\n * @example\n * ```typescript\n * const { data: hubWalletAddress, isLoading, error } = useHubWalletAddress(spokeChainId, address, hubProvider);\n * ```\n */\n\nexport function useHubWalletAddress(\n spokeChainId: SpokeChainId,\n address: string | undefined,\n hubProvider: EvmHubProvider,\n): UseQueryResult<string | null> {\n return useQuery({\n queryKey: ['hubWallet', spokeChainId, address],\n queryFn: async () => {\n if (!address) return null;\n\n try {\n const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(\n spokeChainId,\n address as `0x${string}`,\n hubProvider,\n );\n return hubWalletAddress;\n } catch (error) {\n console.log('error', error);\n return null;\n }\n },\n enabled: !!address && !!hubProvider,\n });\n}\n","import { allXTokens } from '@/core';\nimport { getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';\nimport type { HubChainId, SpokeChainId } from '@sodax/types';\nimport { useXAccount, useWalletProvider } from '@sodax/wallet-sdk';\nimport type { ChainId } from '@sodax/types';\nimport { useQuery } from '@tanstack/react-query';\nimport { useHubProvider } from '../provider/useHubProvider';\nimport { useHubWalletAddress } from './useHubWalletAddress';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useUserReservesData(spokeChainId: ChainId) {\n const { sodax } = useSodaxContext();\n const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;\n const hubWalletProvider = useWalletProvider(hubChainId);\n const hubProvider = useHubProvider();\n const { address } = useXAccount(spokeChainId);\n const { data: hubWalletAddress } = useHubWalletAddress(\n spokeChainId as SpokeChainId,\n address,\n hubProvider as EvmHubProvider,\n );\n\n const { data: userReserves } = useQuery({\n queryKey: ['userReserves', hubWalletAddress],\n queryFn: async () => {\n if (!hubWalletProvider) {\n return;\n }\n\n if (!hubWalletAddress) {\n return;\n }\n\n const moneyMarketConfig = getMoneyMarketConfig(hubChainId);\n try {\n const [res] = await sodax.moneyMarket.getUserReservesData(\n hubWalletAddress as `0x${string}`,\n moneyMarketConfig.uiPoolDataProvider,\n moneyMarketConfig.poolAddressesProvider,\n );\n\n return res?.map(r => {\n return {\n ...r,\n token: allXTokens.find(t => t.address === r.underlyingAsset),\n };\n });\n } catch (error) {\n console.log('error', error);\n return;\n }\n },\n enabled: !!address && !!hubWalletProvider && !!hubWalletAddress,\n refetchInterval: 5000,\n });\n\n return userReserves;\n}\n","import type { IntentErrorResponse, IntentQuoteRequest, IntentQuoteResponse, Result } from '@sodax/sdk';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for fetching a quote for an intent-based swap.\n *\n * This hook provides real-time quote data for an intent-based swap.\n *\n * @param {IntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.\n *\n * @returns {UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The quote result from the solver\n * - isLoading: Boolean indicating if the quote is being fetched\n * - error: Error object if the quote request failed\n * - refetch: Function to manually trigger a quote refresh\n *\n * @example\n * ```typescript\n * const { data: quote, isLoading } = useQuote({\n * token_src: '0x...',\n * token_src_blockchain_id: '1',\n * token_dst: '0x...',\n * token_dst_blockchain_id: '2',\n * amount: '1000000000000000000',\n * quote_type: 'exact_input',\n * });\n *\n * if (isLoading) return <div>Loading quote...</div>;\n * if (quote) {\n * console.log('Quote received:', quote);\n * }\n * ```\n *\n * @remarks\n * - The quote is automatically refreshed every 3 seconds\n * - The query is disabled when payload is undefined\n * - Uses React Query for efficient caching and state management\n */\nexport const useQuote = (\n payload: IntentQuoteRequest | undefined,\n): UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [payload],\n queryFn: async () => {\n if (!payload) {\n return undefined;\n }\n return sodax.solver.getQuote(payload);\n },\n enabled: !!payload,\n refetchInterval: 3000,\n });\n};\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport type {\n CreateIntentParams,\n SpokeChainId,\n IntentExecutionResponse,\n Result,\n IntentSubmitErrorCode,\n Intent,\n PacketData,\n IntentSubmitError,\n} from '@sodax/sdk';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\n\ntype CreateIntentResult = Result<\n [IntentExecutionResponse, Intent, PacketData],\n IntentSubmitError<IntentSubmitErrorCode>\n>;\n\n/**\n * Hook for creating and submitting an intent order for cross-chain swaps.\n * Uses React Query's useMutation for better state management and caching.\n *\n * @param {SpokeChainId} chainId - The source chain ID where the swap will originate\n * @returns {UseMutationResult} Mutation result object containing mutation function and state\n *\n * @example\n * ```typescript\n * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');\n *\n * const handleSwap = async () => {\n * const result = await createIntent({\n * token_src: '0x...',\n * token_src_blockchain_id: 'arbitrum',\n * token_dst: '0x...',\n * token_dst_blockchain_id: 'polygon',\n * amount: '1000000000000000000',\n * min_output_amount: '900000000000000000'\n * });\n * };\n * ```\n */\nexport function useCreateIntentOrder(\n chainId: SpokeChainId,\n): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(chainId);\n\n return useMutation<CreateIntentResult, Error, CreateIntentParams>({\n mutationFn: async (params: CreateIntentParams) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n return sodax.solver.createAndSubmitIntent(params, spokeProvider);\n },\n });\n}\n","import type { Hex, IntentErrorResponse, IntentStatusResponse, Result } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\n/**\n * Hook for monitoring the status of an intent-based swap.\n *\n * This hook provides real-time status updates for an intent-based swap transaction.\n *\n * @param {Hex} intent_tx_hash - The transaction hash of the intent order on the hub chain\n *\n * @returns {UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The status result from the solver\n * - isLoading: Boolean indicating if the status is being fetched\n * - error: Error object if the status request failed\n * - refetch: Function to manually trigger a status refresh\n *\n * @example\n * ```typescript\n * const { data: status, isLoading } = useStatus('0x...');\n *\n * if (isLoading) return <div>Loading status...</div>;\n * if (status?.ok) {\n * console.log('Status:', status.value);\n * }\n * ```\n *\n * @remarks\n * - The status is automatically refreshed every 3 seconds\n * - Uses React Query for efficient caching and state management\n */\n\nexport const useStatus = (\n intent_tx_hash: Hex,\n): UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [intent_tx_hash],\n queryFn: async () => {\n return sodax.solver.getStatus({ intent_tx_hash });\n },\n refetchInterval: 3000, // 3s\n });\n};\n","import type { ReactNode, ReactElement } from 'react';\nimport { Sodax, type SodaxConfig } from '@sodax/sdk';\nimport { SodaxContext } from '@/contexts';\nimport React from 'react';\n\ninterface SodaxProviderProps {\n children: ReactNode;\n testnet?: boolean;\n config: SodaxConfig;\n}\n\nexport const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {\n const sodax = new Sodax(config);\n\n return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/contexts/index.ts","../src/hooks/shared/useSodaxContext.ts","../src/hooks/provider/useSpokeProvider.ts","../src/hooks/shared/useAllowance.ts","../src/hooks/shared/useApprove.ts","../src/hooks/provider/useHubProvider.ts","../src/hooks/mm/useBorrow.ts","../src/hooks/mm/useRepay.ts","../src/hooks/mm/useSupply.ts","../src/hooks/mm/useWithdraw.ts","../src/core/index.ts","../src/hooks/mm/useHubWalletAddress.ts","../src/hooks/mm/useUserReservesData.ts","../src/hooks/mm/useReservesData.ts","../src/hooks/swap/useQuote.ts","../src/hooks/swap/useCreateIntentOrder.ts","../src/hooks/swap/useStatus.ts","../src/providers/SodaxProvider.tsx"],"names":["parseUnits","getXChainType","useMemo","useMutation","useQuery","useWalletProvider","getMoneyMarketConfig"],"mappings":";;;;;;;AAQO,IAAM,YAAA,GAAe,cAAuC,IAAI,CAAA;ACChE,IAAM,kBAAkB,MAAwB;AACrD,EAAM,MAAA,OAAA,GAAU,WAAW,YAAY,CAAA;AACvC,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,qDAAqD,CAAA;AAAA;AAEvE,EAAO,OAAA,OAAA;AACT;ACJO,SAAS,iBAAiB,YAA4B,EAAA;AAC3D,EAAM,MAAA,UAAA,GAAa,cAAc,YAAY,CAAA;AAC7C,EAAM,MAAA,cAAA,GAAiB,kBAAkB,YAAY,CAAA;AACrD,EAAM,MAAA,aAAA,GAAgB,QAAQ,MAAM;AAClC,IAAI,IAAA,CAAC,gBAAuB,OAAA,MAAA;AAC5B,IAAA,IAAI,eAAe,KAAO,EAAA;AACxB,MAAA,OAAO,IAAI,gBAAA;AAAA,QACT,cAAA;AAAA,QACA,iBAAiB,YAAY;AAAA,OAC/B;AAA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AE,KAAM,EAAA,GAAI,eAAgB,EAAA;AAClC,EAAM,MAAA,aAAA,GAAgB,iBAAiB,OAAO,CAAA;AAE9C,EAAA,OAAOD,WAA2D,CAAA;AAAA,IAChE,UAAA,EAAY,OAAO,MAA+B,KAAA;AAChD,MAAA,IAAI,CAAC,aAAe,EAAA;AAClB,QAAM,MAAA,IAAI,MAAM,0BAA0B,CAAA;AAAA;AAE5C,MAAA,OAAO,KAAM,CAAA,MAAA,CAAO,qBAAsB,CAAA,MAAA,EAAQ,aAAa,CAAA;AAAA;AACjE,GACD,CAAA;AACH;ACxBa,IAAA,SAAA,GAAY,CACvB,cACkF,KAAA;AAClF,EAAM,MAAA,EAAE,KAAM,EAAA,GAAI,eAAgB,EAAA;AAClC,EAAA,OAAOC,QAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,cAAc,CAAA;AAAA,IACzB,SAAS,YAAY;AACnB,MAAA,OAAO,KAAM,CAAA,MAAA,CAAO,SAAU,CAAA,EAAE,gBAAgB,CAAA;AAAA,KAClD;AAAA,IACA,eAAiB,EAAA;AAAA;AAAA,GAClB,CAAA;AACH;AChCO,IAAM,gBAAgB,CAAC,EAAE,UAAU,OAAU,GAAA,KAAA,EAAO,QAA+C,KAAA;AACxG,EAAM,MAAA,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAM,CAAA;AAE9B,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,aAAa,QAAb,EAAA,EAAsB,OAAO,EAAE,KAAA,EAAO,OAAQ,EAAA,EAAA,EAAI,QAAS,CAAA;AACrE","file":"index.mjs","sourcesContent":["import { createContext } from 'react';\nimport type { Sodax } from '@sodax/sdk';\n\nexport interface SodaxContextType {\n sodax: Sodax;\n testnet: boolean;\n}\n\nexport const SodaxContext = createContext<SodaxContextType | null>(null);\n","import { SodaxContext, type SodaxContextType } from '@/contexts';\nimport { useContext } from 'react';\n\n/**\n * Hook to access the Sodax context which provides access to the Sodax SDK instance and chain configuration\n * @throws {Error} If used outside of a SodaxProvider\n * @returns {SodaxContextType} The Sodax context containing SDK instance and configuration\n */\n\nexport const useSodaxContext = (): SodaxContextType => {\n const context = useContext(SodaxContext);\n if (!context) {\n throw new Error('useSodaxContext must be used within a SodaxProvider');\n }\n return context;\n};\n","import {\n EvmSpokeProvider,\n spokeChainConfig,\n type SuiSpokeChainConfig,\n SuiSpokeProvider,\n type EvmSpokeChainConfig,\n} from '@sodax/sdk';\nimport type { IEvmWalletProvider, ISuiWalletProvider, SpokeChainId } from '@sodax/types';\nimport { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\n\nexport function useSpokeProvider(spokeChainId: SpokeChainId) {\n const xChainType = getXChainType(spokeChainId);\n const walletProvider = useWalletProvider(spokeChainId);\n const spokeProvider = useMemo(() => {\n if (!walletProvider) return undefined;\n if (xChainType === 'EVM') {\n return new EvmSpokeProvider(\n walletProvider as IEvmWalletProvider,\n spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,\n );\n }\n if (xChainType === 'SUI') {\n return new SuiSpokeProvider(\n spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,\n walletProvider as ISuiWalletProvider,\n );\n }\n return undefined;\n }, [walletProvider, xChainType, spokeChainId]);\n\n return spokeProvider;\n}\n","import { useQuery } from '@tanstack/react-query';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { parseUnits } from 'viem';\n\nexport function useAllowance(token: XToken, amount: string) {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n\n return useQuery({\n queryKey: ['allowance', token.address, amount],\n queryFn: async () => {\n if (!spokeProvider) {\n return false;\n }\n const allowance = await sodax.moneyMarket.isAllowanceValid(\n {\n token: token.address,\n amount: parseUnits(amount, token.decimals),\n },\n spokeProvider,\n );\n if (allowance.ok) {\n return allowance.value;\n }\n return false;\n },\n enabled: !!spokeProvider,\n });\n}\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { parseUnits } from 'viem';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport type { Address } from '@sodax/sdk';\n\ninterface UseApproveReturn {\n approve: (amount: string) => Promise<boolean>;\n isLoading: boolean;\n error: Error | null;\n resetError: () => void;\n}\n\nexport function useApprove(token: XToken): UseApproveReturn {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n const queryClient = useQueryClient();\n\n const {\n mutateAsync: approve,\n isPending,\n error,\n reset: resetError,\n } = useMutation({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n const allowance = await sodax.moneyMarket.approve(\n token.address as Address,\n parseUnits(amount, token.decimals),\n spokeProvider.chainConfig.addresses.assetManager as Address,\n spokeProvider,\n );\n if (!allowance.ok) {\n throw new Error('Failed to approve tokens');\n }\n return allowance.ok;\n },\n onSuccess: () => {\n // Invalidate allowance query to refetch the new allowance\n queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });\n },\n });\n\n return {\n approve,\n isLoading: isPending,\n error: error as Error | null,\n resetError,\n };\n}\n","import { EvmHubProvider, getHubChainConfig, type HubChainId } from '@sodax/sdk';\nimport { getXChainType } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useHubProvider(): EvmHubProvider | undefined {\n const { sodax } = useSodaxContext();\n const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;\n const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;\n const xChainType = getXChainType(hubChainId);\n const hubProvider = useMemo(() => {\n if (xChainType === 'EVM' && hubChainId && hubRpcUrl) {\n const hubChainCfg = getHubChainConfig(hubChainId);\n\n if (!hubChainCfg) return undefined;\n\n return new EvmHubProvider({\n hubRpcUrl: hubRpcUrl,\n chainConfig: hubChainCfg,\n });\n }\n return undefined;\n }, [xChainType, hubChainId, hubRpcUrl]);\n\n return hubProvider;\n}\n","import type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport type { SpokeChainId } from '@sodax/sdk';\ninterface BorrowResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for borrowing tokens from the Sodax money market.\n *\n * This hook provides functionality to borrow tokens from the money market protocol,\n * handling the entire borrow process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);\n * await borrow('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useBorrow(spokeToken: XToken): UseMutationResult<BorrowResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<BorrowResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.borrowAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, 18),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n console.log('Failed to borrow tokens', response);\n throw new Error('Failed to borrow tokens');\n }\n\n console.log('Borrow transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface RepayResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for repaying borrowed tokens to the Sodax money market.\n *\n * This hook provides functionality to repay borrowed tokens back to the money market protocol,\n * handling the entire repayment process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);\n * await repay('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useRepay(spokeToken: XToken): UseMutationResult<RepayResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<RepayResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.repayAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to repay tokens');\n }\n\n console.log('Repay transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface SupplyResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for supplying tokens to the Sodax money market.\n *\n * This hook provides functionality to supply tokens to the money market protocol,\n * handling the entire supply process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to supply on the spoke chain. Must be an XToken with valid address and chain information.\n *\n * @returns {UseMutationResult<SupplyResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the supply transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * - error: Error object if the last transaction failed, null otherwise\n *\n * @example\n * ```typescript\n * const { mutateAsync: supply, isPending, error } = useSupply(spokeToken);\n * await supply('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n */\nexport function useSupply(spokeToken: XToken): UseMutationResult<SupplyResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<SupplyResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.supplyAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to supply tokens');\n }\n\n console.log('Supply transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface WithdrawResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for withdrawing supplied tokens from the Sodax money market.\n *\n * This hook provides functionality to withdraw previously supplied tokens from the money market protocol,\n * handling the entire withdrawal process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: withdraw, isPending, error } = useWithdraw(spokeToken);\n * await withdraw('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useWithdraw(spokeToken: XToken): UseMutationResult<WithdrawResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<WithdrawResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.withdrawAndSubmit(\n {\n token: spokeToken.address,\n // vault token on hub chain decimals is 18\n amount: parseUnits(amount, 18),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to withdraw tokens');\n }\n\n console.log('Withdraw transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { XToken, ChainId } from '@sodax/types';\n\nimport { hubAssets } from '@sodax/sdk';\n\nexport const allXTokens: XToken[] = [];\n\nObject.keys(hubAssets).forEach(xChainId => {\n const tokens = hubAssets[xChainId];\n\n Object.keys(tokens).forEach(tokenAddress => {\n const token = tokens[tokenAddress];\n allXTokens.push({\n xChainId: xChainId as ChainId,\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: tokenAddress,\n });\n\n allXTokens.push({\n xChainId: 'sonic',\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: token.vault,\n });\n });\n});\n\nexport const getSpokeTokenAddressByVault = (spokeChainId: ChainId, vault: string) => {\n const tokens = hubAssets[spokeChainId];\n const address = Object.keys(tokens).find(tokenAddress => tokens[tokenAddress].vault === vault);\n\n return address;\n};\n","import { type EvmHubProvider, EvmWalletAbstraction, type SpokeChainId } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for retrieving the hub wallet address for a given spoke chain and address.\n *\n * This hook fetches the hub wallet address associated with a user's address on a specific spoke chain.\n * It uses the EvmWalletAbstraction to query the hub wallet address from the hub provider.\n *\n * @param spokeChainId - The chain ID of the spoke chain\n * @param address - The user's address on the spoke chain\n * @param hubProvider - The hub provider instance\n *\n * @returns {UseQueryResult<string | null>} A query result object containing:\n * - data: The hub wallet address or null if not found\n * - isLoading: Boolean indicating if the query is in progress\n * - error: Error object if the query failed, null otherwise\n *\n * @example\n * ```typescript\n * const { data: hubWalletAddress, isLoading, error } = useHubWalletAddress(spokeChainId, address, hubProvider);\n * ```\n */\n\nexport function useHubWalletAddress(\n spokeChainId: SpokeChainId,\n address: string | undefined,\n hubProvider: EvmHubProvider,\n): UseQueryResult<string | null> {\n return useQuery({\n queryKey: ['hubWallet', spokeChainId, address],\n queryFn: async () => {\n if (!address) return null;\n\n try {\n const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(\n spokeChainId,\n address as `0x${string}`,\n hubProvider,\n );\n return hubWalletAddress;\n } catch (error) {\n console.log('error', error);\n return null;\n }\n },\n enabled: !!address && !!hubProvider,\n });\n}\n","import { allXTokens } from '@/core';\nimport { getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';\nimport type { HubChainId, SpokeChainId } from '@sodax/types';\nimport { useXAccount, useWalletProvider } from '@sodax/wallet-sdk';\nimport type { ChainId } from '@sodax/types';\nimport { useQuery } from '@tanstack/react-query';\nimport { useHubProvider } from '../provider/useHubProvider';\nimport { useHubWalletAddress } from './useHubWalletAddress';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useUserReservesData(spokeChainId: ChainId) {\n const { sodax } = useSodaxContext();\n const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;\n const hubWalletProvider = useWalletProvider(hubChainId);\n const hubProvider = useHubProvider();\n const { address } = useXAccount(spokeChainId);\n const { data: hubWalletAddress } = useHubWalletAddress(\n spokeChainId as SpokeChainId,\n address,\n hubProvider as EvmHubProvider,\n );\n\n const { data: userReserves } = useQuery({\n queryKey: ['userReserves', hubWalletAddress],\n queryFn: async () => {\n if (!hubWalletProvider) {\n return;\n }\n\n if (!hubWalletAddress) {\n return;\n }\n\n const moneyMarketConfig = getMoneyMarketConfig(hubChainId);\n try {\n const [res] = await sodax.moneyMarket.getUserReservesData(\n hubWalletAddress as `0x${string}`,\n moneyMarketConfig.uiPoolDataProvider,\n moneyMarketConfig.poolAddressesProvider,\n );\n\n return res?.map(r => {\n return {\n ...r,\n token: allXTokens.find(t => t.address === r.underlyingAsset),\n };\n });\n } catch (error) {\n console.log('error', error);\n return;\n }\n },\n enabled: !!address && !!hubWalletProvider && !!hubWalletAddress,\n refetchInterval: 5000,\n });\n\n return userReserves;\n}\n","import { getMoneyMarketConfig } from '@sodax/sdk';\nimport type { HubChainId } from '@sodax/types';\nimport { useQuery } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n/**\n * Hook for fetching reserves data from the Sodax money market.\n *\n * This hook provides access to the current state of all reserves in the money market protocol,\n * including liquidity, interest rates, and other key metrics. The data is automatically\n * fetched and cached using React Query.\n *\n * @example\n * ```typescript\n * const { data: reservesData, isLoading, error } = useReservesData();\n * ```\n *\n * @returns A React Query result object containing:\n * - data: The reserves data when available\n * - isLoading: Loading state indicator\n * - error: Any error that occurred during data fetching\n */\n\nexport function useReservesData() {\n const { sodax } = useSodaxContext();\n const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;\n\n return useQuery({\n queryKey: ['reservesData'],\n queryFn: async () => {\n const moneyMarketConfig = getMoneyMarketConfig(hubChainId);\n return await sodax.moneyMarket.getReservesData(\n moneyMarketConfig.uiPoolDataProvider,\n moneyMarketConfig.poolAddressesProvider,\n );\n },\n });\n}\n","import type { IntentErrorResponse, IntentQuoteRequest, IntentQuoteResponse, Result } from '@sodax/sdk';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for fetching a quote for an intent-based swap.\n *\n * This hook provides real-time quote data for an intent-based swap.\n *\n * @param {IntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.\n *\n * @returns {UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The quote result from the solver\n * - isLoading: Boolean indicating if the quote is being fetched\n * - error: Error object if the quote request failed\n * - refetch: Function to manually trigger a quote refresh\n *\n * @example\n * ```typescript\n * const { data: quote, isLoading } = useQuote({\n * token_src: '0x...',\n * token_src_blockchain_id: '1',\n * token_dst: '0x...',\n * token_dst_blockchain_id: '2',\n * amount: '1000000000000000000',\n * quote_type: 'exact_input',\n * });\n *\n * if (isLoading) return <div>Loading quote...</div>;\n * if (quote) {\n * console.log('Quote received:', quote);\n * }\n * ```\n *\n * @remarks\n * - The quote is automatically refreshed every 3 seconds\n * - The query is disabled when payload is undefined\n * - Uses React Query for efficient caching and state management\n */\nexport const useQuote = (\n payload: IntentQuoteRequest | undefined,\n): UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [payload],\n queryFn: async () => {\n if (!payload) {\n return undefined;\n }\n return sodax.solver.getQuote(payload);\n },\n enabled: !!payload,\n refetchInterval: 3000,\n });\n};\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport type {\n CreateIntentParams,\n SpokeChainId,\n IntentExecutionResponse,\n Result,\n IntentSubmitErrorCode,\n Intent,\n PacketData,\n IntentSubmitError,\n} from '@sodax/sdk';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\n\ntype CreateIntentResult = Result<\n [IntentExecutionResponse, Intent, PacketData],\n IntentSubmitError<IntentSubmitErrorCode>\n>;\n\n/**\n * Hook for creating and submitting an intent order for cross-chain swaps.\n * Uses React Query's useMutation for better state management and caching.\n *\n * @param {SpokeChainId} chainId - The source chain ID where the swap will originate\n * @returns {UseMutationResult} Mutation result object containing mutation function and state\n *\n * @example\n * ```typescript\n * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');\n *\n * const handleSwap = async () => {\n * const result = await createIntent({\n * token_src: '0x...',\n * token_src_blockchain_id: 'arbitrum',\n * token_dst: '0x...',\n * token_dst_blockchain_id: 'polygon',\n * amount: '1000000000000000000',\n * min_output_amount: '900000000000000000'\n * });\n * };\n * ```\n */\nexport function useCreateIntentOrder(\n chainId: SpokeChainId,\n): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(chainId);\n\n return useMutation<CreateIntentResult, Error, CreateIntentParams>({\n mutationFn: async (params: CreateIntentParams) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n return sodax.solver.createAndSubmitIntent(params, spokeProvider);\n },\n });\n}\n","import type { Hex, IntentErrorResponse, IntentStatusResponse, Result } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\n/**\n * Hook for monitoring the status of an intent-based swap.\n *\n * This hook provides real-time status updates for an intent-based swap transaction.\n *\n * @param {Hex} intent_tx_hash - The transaction hash of the intent order on the hub chain\n *\n * @returns {UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The status result from the solver\n * - isLoading: Boolean indicating if the status is being fetched\n * - error: Error object if the status request failed\n * - refetch: Function to manually trigger a status refresh\n *\n * @example\n * ```typescript\n * const { data: status, isLoading } = useStatus('0x...');\n *\n * if (isLoading) return <div>Loading status...</div>;\n * if (status?.ok) {\n * console.log('Status:', status.value);\n * }\n * ```\n *\n * @remarks\n * - The status is automatically refreshed every 3 seconds\n * - Uses React Query for efficient caching and state management\n */\n\nexport const useStatus = (\n intent_tx_hash: Hex,\n): UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [intent_tx_hash],\n queryFn: async () => {\n return sodax.solver.getStatus({ intent_tx_hash });\n },\n refetchInterval: 3000, // 3s\n });\n};\n","import type { ReactNode, ReactElement } from 'react';\nimport { Sodax, type SodaxConfig } from '@sodax/sdk';\nimport { SodaxContext } from '@/contexts';\nimport React from 'react';\n\ninterface SodaxProviderProps {\n children: ReactNode;\n testnet?: boolean;\n config: SodaxConfig;\n}\n\nexport const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {\n const sodax = new Sodax(config);\n\n return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;\n};\n"]}
|
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.4",
|
|
5
5
|
"description": "dapp-kit of New World",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -16,9 +16,9 @@
|
|
|
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.
|
|
19
|
+
"@sodax/sdk": "0.0.1-rc.5",
|
|
20
|
+
"@sodax/types": "0.0.1-rc.2",
|
|
21
|
+
"@sodax/wallet-sdk": "0.0.1-rc.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/react": "^19.0.8",
|
package/src/core/index.ts
CHANGED
|
@@ -29,12 +29,7 @@ Object.keys(hubAssets).forEach(xChainId => {
|
|
|
29
29
|
|
|
30
30
|
export const getSpokeTokenAddressByVault = (spokeChainId: ChainId, vault: string) => {
|
|
31
31
|
const tokens = hubAssets[spokeChainId];
|
|
32
|
+
const address = Object.keys(tokens).find(tokenAddress => tokens[tokenAddress].vault === vault);
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!token) {
|
|
36
|
-
throw new Error('Token not found');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return token;
|
|
34
|
+
return address;
|
|
40
35
|
};
|
package/src/hooks/mm/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { XToken } from '@sodax/types';
|
|
2
2
|
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
3
3
|
import { parseUnits } from 'viem';
|
|
4
4
|
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
@@ -18,7 +18,7 @@ interface BorrowResponse {
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```typescript
|
|
21
|
-
* const { mutateAsync: borrow, isPending, error } = useBorrow(
|
|
21
|
+
* const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);
|
|
22
22
|
* await borrow('100');
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
@@ -26,9 +26,9 @@ interface BorrowResponse {
|
|
|
26
26
|
* - spokeProvider is not available
|
|
27
27
|
* - Transaction execution fails
|
|
28
28
|
*/
|
|
29
|
-
export function useBorrow(
|
|
29
|
+
export function useBorrow(spokeToken: XToken): UseMutationResult<BorrowResponse, Error, string> {
|
|
30
30
|
const { sodax } = useSodaxContext();
|
|
31
|
-
const spokeProvider = useSpokeProvider(
|
|
31
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);
|
|
32
32
|
|
|
33
33
|
return useMutation<BorrowResponse, Error, string>({
|
|
34
34
|
mutationFn: async (amount: string) => {
|
|
@@ -38,13 +38,14 @@ export function useBorrow(hubToken: XToken, spokeChainId: ChainId): UseMutationR
|
|
|
38
38
|
|
|
39
39
|
const response = await sodax.moneyMarket.borrowAndSubmit(
|
|
40
40
|
{
|
|
41
|
-
token:
|
|
42
|
-
amount: parseUnits(amount,
|
|
41
|
+
token: spokeToken.address,
|
|
42
|
+
amount: parseUnits(amount, 18),
|
|
43
43
|
},
|
|
44
44
|
spokeProvider,
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
if (!response.ok) {
|
|
48
|
+
console.log('Failed to borrow tokens', response);
|
|
48
49
|
throw new Error('Failed to borrow tokens');
|
|
49
50
|
}
|
|
50
51
|
|
package/src/hooks/mm/useRepay.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SpokeChainId } from '@sodax/sdk';
|
|
2
|
-
import type {
|
|
2
|
+
import type { XToken } from '@sodax/types';
|
|
3
3
|
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
4
4
|
import { parseUnits } from 'viem';
|
|
5
5
|
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
@@ -19,7 +19,7 @@ interface RepayResponse {
|
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```typescript
|
|
22
|
-
* const { mutateAsync: repay, isPending, error } = useRepay(
|
|
22
|
+
* const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);
|
|
23
23
|
* await repay('100');
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
@@ -27,9 +27,9 @@ interface RepayResponse {
|
|
|
27
27
|
* - spokeProvider is not available
|
|
28
28
|
* - Transaction execution fails
|
|
29
29
|
*/
|
|
30
|
-
export function useRepay(
|
|
30
|
+
export function useRepay(spokeToken: XToken): UseMutationResult<RepayResponse, Error, string> {
|
|
31
31
|
const { sodax } = useSodaxContext();
|
|
32
|
-
const spokeProvider = useSpokeProvider(
|
|
32
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);
|
|
33
33
|
|
|
34
34
|
return useMutation<RepayResponse, Error, string>({
|
|
35
35
|
mutationFn: async (amount: string) => {
|
|
@@ -39,8 +39,8 @@ export function useRepay(hubToken: XToken, spokeChainId: ChainId): UseMutationRe
|
|
|
39
39
|
|
|
40
40
|
const response = await sodax.moneyMarket.repayAndSubmit(
|
|
41
41
|
{
|
|
42
|
-
token:
|
|
43
|
-
amount: parseUnits(amount,
|
|
42
|
+
token: spokeToken.address,
|
|
43
|
+
amount: parseUnits(amount, spokeToken.decimals),
|
|
44
44
|
},
|
|
45
45
|
spokeProvider,
|
|
46
46
|
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getMoneyMarketConfig } from '@sodax/sdk';
|
|
2
|
+
import type { HubChainId } from '@sodax/types';
|
|
3
|
+
import { useQuery } from '@tanstack/react-query';
|
|
4
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
5
|
+
/**
|
|
6
|
+
* Hook for fetching reserves data from the Sodax money market.
|
|
7
|
+
*
|
|
8
|
+
* This hook provides access to the current state of all reserves in the money market protocol,
|
|
9
|
+
* including liquidity, interest rates, and other key metrics. The data is automatically
|
|
10
|
+
* fetched and cached using React Query.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const { data: reservesData, isLoading, error } = useReservesData();
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns A React Query result object containing:
|
|
18
|
+
* - data: The reserves data when available
|
|
19
|
+
* - isLoading: Loading state indicator
|
|
20
|
+
* - error: Any error that occurred during data fetching
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export function useReservesData() {
|
|
24
|
+
const { sodax } = useSodaxContext();
|
|
25
|
+
const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;
|
|
26
|
+
|
|
27
|
+
return useQuery({
|
|
28
|
+
queryKey: ['reservesData'],
|
|
29
|
+
queryFn: async () => {
|
|
30
|
+
const moneyMarketConfig = getMoneyMarketConfig(hubChainId);
|
|
31
|
+
return await sodax.moneyMarket.getReservesData(
|
|
32
|
+
moneyMarketConfig.uiPoolDataProvider,
|
|
33
|
+
moneyMarketConfig.poolAddressesProvider,
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SpokeChainId } from '@sodax/sdk';
|
|
2
|
-
import type {
|
|
2
|
+
import type { XToken } from '@sodax/types';
|
|
3
3
|
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
4
4
|
import { parseUnits } from 'viem';
|
|
5
5
|
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
@@ -19,7 +19,7 @@ interface WithdrawResponse {
|
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```typescript
|
|
22
|
-
* const { mutateAsync: withdraw, isPending, error } = useWithdraw(
|
|
22
|
+
* const { mutateAsync: withdraw, isPending, error } = useWithdraw(spokeToken);
|
|
23
23
|
* await withdraw('100');
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
@@ -27,12 +27,9 @@ interface WithdrawResponse {
|
|
|
27
27
|
* - spokeProvider is not available
|
|
28
28
|
* - Transaction execution fails
|
|
29
29
|
*/
|
|
30
|
-
export function useWithdraw(
|
|
31
|
-
hubToken: XToken,
|
|
32
|
-
spokeChainId: ChainId,
|
|
33
|
-
): UseMutationResult<WithdrawResponse, Error, string> {
|
|
30
|
+
export function useWithdraw(spokeToken: XToken): UseMutationResult<WithdrawResponse, Error, string> {
|
|
34
31
|
const { sodax } = useSodaxContext();
|
|
35
|
-
const spokeProvider = useSpokeProvider(
|
|
32
|
+
const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);
|
|
36
33
|
|
|
37
34
|
return useMutation<WithdrawResponse, Error, string>({
|
|
38
35
|
mutationFn: async (amount: string) => {
|
|
@@ -42,8 +39,9 @@ export function useWithdraw(
|
|
|
42
39
|
|
|
43
40
|
const response = await sodax.moneyMarket.withdrawAndSubmit(
|
|
44
41
|
{
|
|
45
|
-
token:
|
|
46
|
-
|
|
42
|
+
token: spokeToken.address,
|
|
43
|
+
// vault token on hub chain decimals is 18
|
|
44
|
+
amount: parseUnits(amount, 18),
|
|
47
45
|
},
|
|
48
46
|
spokeProvider,
|
|
49
47
|
);
|