@sodax/dapp-kit 0.0.1-rc.6 → 0.0.1-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/mm/index.d.ts +2 -0
- package/dist/hooks/mm/index.d.ts.map +1 -1
- package/dist/hooks/mm/useAllowance.d.ts +4 -0
- package/dist/hooks/mm/useAllowance.d.ts.map +1 -0
- package/dist/hooks/{shared → mm}/useApprove.d.ts +5 -1
- package/dist/hooks/mm/useApprove.d.ts.map +1 -0
- package/dist/hooks/mm/useBorrow.d.ts +10 -1
- package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
- package/dist/hooks/mm/useRepay.d.ts +10 -1
- package/dist/hooks/mm/useRepay.d.ts.map +1 -1
- package/dist/hooks/mm/useSupply.d.ts +3 -1
- package/dist/hooks/mm/useSupply.d.ts.map +1 -1
- package/dist/hooks/mm/useUserReservesData.d.ts +1 -1
- package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
- package/dist/hooks/mm/useWithdraw.d.ts +8 -1
- package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts +16 -2
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
- package/dist/hooks/shared/index.d.ts +0 -2
- package/dist/hooks/shared/index.d.ts.map +1 -1
- package/dist/hooks/swap/useCreateIntentOrder.d.ts +4 -4
- package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +1 -1
- package/dist/index.js +98 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/hooks/mm/index.ts +2 -0
- package/src/hooks/{shared → mm}/useAllowance.ts +4 -2
- package/src/hooks/{shared → mm}/useApprove.ts +9 -7
- package/src/hooks/mm/useBorrow.ts +14 -5
- package/src/hooks/mm/useRepay.ts +14 -4
- package/src/hooks/mm/useSupply.ts +7 -4
- package/src/hooks/mm/useUserReservesData.ts +6 -12
- package/src/hooks/mm/useWithdraw.ts +12 -4
- package/src/hooks/provider/useSpokeProvider.ts +31 -8
- package/src/hooks/shared/index.ts +0 -2
- package/src/hooks/swap/useCreateIntentOrder.ts +4 -6
- package/dist/hooks/shared/useAllowance.d.ts +0 -3
- package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
- package/dist/hooks/shared/useApprove.d.ts.map +0 -1
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;AACtC,cAAc,mBAAmB,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;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { XToken } from '@sodax/types';
|
|
2
|
+
import type { MoneyMarketAction } from '@sodax/sdk';
|
|
3
|
+
export declare function useAllowance(token: XToken, amount: string, action: MoneyMarketAction): import("@tanstack/react-query").UseQueryResult<boolean, Error>;
|
|
4
|
+
//# sourceMappingURL=useAllowance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAllowance.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useAllowance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAIzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,kEAyBpF"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { XToken } from '@sodax/types';
|
|
2
|
+
import type { MoneyMarketAction } from '@sodax/sdk';
|
|
2
3
|
interface UseApproveReturn {
|
|
3
|
-
approve: (amount
|
|
4
|
+
approve: ({ amount, action }: {
|
|
5
|
+
amount: string;
|
|
6
|
+
action: MoneyMarketAction;
|
|
7
|
+
}) => Promise<boolean>;
|
|
4
8
|
isLoading: boolean;
|
|
5
9
|
error: Error | null;
|
|
6
10
|
resetError: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApprove.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useApprove.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC;AAGzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,UAAU,gBAAgB;IACxB,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjG,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAwC1D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { XToken } from '@sodax/types';
|
|
2
2
|
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
|
+
import type { SpokeProvider } from '@sodax/sdk';
|
|
3
4
|
interface BorrowResponse {
|
|
4
5
|
ok: true;
|
|
5
6
|
value: [`0x${string}`, `0x${string}`];
|
|
@@ -11,6 +12,14 @@ interface BorrowResponse {
|
|
|
11
12
|
* handling the entire borrow process including transaction creation, submission,
|
|
12
13
|
* and cross-chain communication.
|
|
13
14
|
*
|
|
15
|
+
* @param {XToken} spokeToken - The token to borrow from the spoke chain. Must be an XToken with valid address and chain information.
|
|
16
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for the borrow transaction. Must be a valid SpokeProvider instance.
|
|
17
|
+
*
|
|
18
|
+
* @returns {UseMutationResult<BorrowResponse, Error, string>} A mutation result object with the following properties:
|
|
19
|
+
* - mutateAsync: Function to execute the borrow transaction
|
|
20
|
+
* - isPending: Boolean indicating if a transaction is in progress
|
|
21
|
+
* - error: Error object if the last transaction failed, null otherwise
|
|
22
|
+
*
|
|
14
23
|
* @example
|
|
15
24
|
* ```typescript
|
|
16
25
|
* const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);
|
|
@@ -21,6 +30,6 @@ interface BorrowResponse {
|
|
|
21
30
|
* - spokeProvider is not available
|
|
22
31
|
* - Transaction execution fails
|
|
23
32
|
*/
|
|
24
|
-
export declare function useBorrow(spokeToken: XToken): UseMutationResult<BorrowResponse, Error, string>;
|
|
33
|
+
export declare function useBorrow(spokeToken: XToken, spokeProvider: SpokeProvider | undefined): UseMutationResult<BorrowResponse, Error, string>;
|
|
25
34
|
export {};
|
|
26
35
|
//# 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,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
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;AAG5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,UAAU,cAAc;IACtB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,cAAc,EAAE,KAAK,EAAE,MAAM,CAAC,CA0BlD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SpokeProvider } from '@sodax/sdk';
|
|
1
2
|
import type { XToken } from '@sodax/types';
|
|
2
3
|
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
4
|
interface RepayResponse {
|
|
@@ -11,6 +12,14 @@ interface RepayResponse {
|
|
|
11
12
|
* handling the entire repayment process including transaction creation, submission,
|
|
12
13
|
* and cross-chain communication.
|
|
13
14
|
*
|
|
15
|
+
* @param {XToken} spokeToken - The token to repay on the spoke chain. Must be an XToken with valid address and chain information.
|
|
16
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for the repay transaction. Must be a valid SpokeProvider instance.
|
|
17
|
+
*
|
|
18
|
+
* @returns {UseMutationResult<RepayResponse, Error, string>} A mutation result object with the following properties:
|
|
19
|
+
* - mutateAsync: Function to execute the repay transaction
|
|
20
|
+
* - isPending: Boolean indicating if a transaction is in progress
|
|
21
|
+
* - error: Error object if the last transaction failed, null otherwise
|
|
22
|
+
*
|
|
14
23
|
* @example
|
|
15
24
|
* ```typescript
|
|
16
25
|
* const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);
|
|
@@ -21,6 +30,6 @@ interface RepayResponse {
|
|
|
21
30
|
* - spokeProvider is not available
|
|
22
31
|
* - Transaction execution fails
|
|
23
32
|
*/
|
|
24
|
-
export declare function useRepay(spokeToken: XToken): UseMutationResult<RepayResponse, Error, string>;
|
|
33
|
+
export declare function useRepay(spokeToken: XToken, spokeProvider: SpokeProvider | undefined): UseMutationResult<RepayResponse, Error, string>;
|
|
25
34
|
export {};
|
|
26
35
|
//# sourceMappingURL=useRepay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRepay.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useRepay.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRepay.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useRepay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI5E,UAAU,aAAa;IACrB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CACtB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,CA0BjD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SpokeProvider } from '@sodax/sdk';
|
|
1
2
|
import type { XToken } from '@sodax/types';
|
|
2
3
|
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
4
|
interface SupplyResponse {
|
|
@@ -12,6 +13,7 @@ interface SupplyResponse {
|
|
|
12
13
|
* and cross-chain communication.
|
|
13
14
|
*
|
|
14
15
|
* @param {XToken} spokeToken - The token to supply on the spoke chain. Must be an XToken with valid address and chain information.
|
|
16
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for the supply transaction. Must be a valid SpokeProvider instance.
|
|
15
17
|
*
|
|
16
18
|
* @returns {UseMutationResult<SupplyResponse, Error, string>} A mutation result object with the following properties:
|
|
17
19
|
* - mutateAsync: Function to execute the supply transaction
|
|
@@ -27,6 +29,6 @@ interface SupplyResponse {
|
|
|
27
29
|
* @throws {Error} When:
|
|
28
30
|
* - spokeProvider is not available
|
|
29
31
|
*/
|
|
30
|
-
export declare function useSupply(spokeToken: XToken): UseMutationResult<SupplyResponse, Error, string>;
|
|
32
|
+
export declare function useSupply(spokeToken: XToken, spokeProvider: SpokeProvider | undefined): UseMutationResult<SupplyResponse, Error, string>;
|
|
31
33
|
export {};
|
|
32
34
|
//# sourceMappingURL=useSupply.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSupply.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useSupply.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSupply.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useSupply.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI5E,UAAU,cAAc;IACtB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,cAAc,EAAE,KAAK,EAAE,MAAM,CAAC,CA0BlD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChainId } from '@sodax/types';
|
|
2
|
-
export declare function useUserReservesData(spokeChainId: ChainId): {
|
|
2
|
+
export declare function useUserReservesData(spokeChainId: ChainId, address: string | undefined): {
|
|
3
3
|
token: import("@sodax/sdk").XToken | undefined;
|
|
4
4
|
underlyingAsset: string;
|
|
5
5
|
scaledATokenBalance: bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUserReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserReservesData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"useUserReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserReservesData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS;;;;;;gBAsCrF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SpokeProvider } from '@sodax/sdk';
|
|
1
2
|
import type { XToken } from '@sodax/types';
|
|
2
3
|
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
4
|
interface WithdrawResponse {
|
|
@@ -11,6 +12,12 @@ interface WithdrawResponse {
|
|
|
11
12
|
* handling the entire withdrawal process including transaction creation, submission,
|
|
12
13
|
* and cross-chain communication.
|
|
13
14
|
*
|
|
15
|
+
* @param {XToken} spokeToken - The token to withdraw from the spoke chain. Must be an XToken with valid address and chain information.
|
|
16
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for the withdraw transaction. Must be a valid SpokeProvider instance.
|
|
17
|
+
*
|
|
18
|
+
* @returns {UseMutationResult<WithdrawResponse, Error, string>} A mutation result object with the following properties:
|
|
19
|
+
* - mutateAsync: Function to execute the withdraw transaction
|
|
20
|
+
* - isPending: Boolean indicating if a transaction is in progress
|
|
14
21
|
* @example
|
|
15
22
|
* ```typescript
|
|
16
23
|
* const { mutateAsync: withdraw, isPending, error } = useWithdraw(spokeToken);
|
|
@@ -21,6 +28,6 @@ interface WithdrawResponse {
|
|
|
21
28
|
* - spokeProvider is not available
|
|
22
29
|
* - Transaction execution fails
|
|
23
30
|
*/
|
|
24
|
-
export declare function useWithdraw(spokeToken: XToken): UseMutationResult<WithdrawResponse, Error, string>;
|
|
31
|
+
export declare function useWithdraw(spokeToken: XToken, spokeProvider: SpokeProvider | undefined): UseMutationResult<WithdrawResponse, Error, string>;
|
|
25
32
|
export {};
|
|
26
33
|
//# sourceMappingURL=useWithdraw.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWithdraw.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useWithdraw.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useWithdraw.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useWithdraw.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI5E,UAAU,gBAAgB;IACxB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,KAAK,MAAM,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,gBAAgB,EAAE,KAAK,EAAE,MAAM,CAAC,CA2BpD"}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type SpokeProvider, type IWalletProvider } from '@sodax/sdk';
|
|
2
2
|
import type { SpokeChainId } from '@sodax/types';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get the appropriate spoke provider based on the chain type.
|
|
5
|
+
* Supports EVM, SUI, ICON and INJECTIVE chains.
|
|
6
|
+
*
|
|
7
|
+
* @param {SpokeChainId | undefined} spokeChainId - The spoke chain ID to get the provider for
|
|
8
|
+
* @param {IWalletProvider | undefined} walletProvider - The wallet provider to use
|
|
9
|
+
* @returns {SpokeProvider | undefined} The appropriate spoke provider instance for the given chain ID, or undefined if invalid/unsupported
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* // Using a specific SpokeChainId and wallet provider
|
|
14
|
+
* const spokeProvider = useSpokeProvider(spokeChainId, walletProvider);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function useSpokeProvider(spokeChainId: SpokeChainId | undefined, walletProvider?: IWalletProvider | undefined): SpokeProvider | undefined;
|
|
4
18
|
//# sourceMappingURL=useSpokeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSpokeProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/provider/useSpokeProvider.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"useSpokeProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/provider/useSpokeProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAIV,YAAY,EAEb,MAAM,cAAc,CAAC;AAItB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,cAAc,CAAC,EAAE,eAAe,GAAG,SAAS,GAC3C,aAAa,GAAG,SAAS,CAsC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CreateIntentParams,
|
|
1
|
+
import type { CreateIntentParams, IntentExecutionResponse, Result, IntentSubmitErrorCode, Intent, PacketData, IntentSubmitError, SpokeProvider } from '@sodax/sdk';
|
|
2
2
|
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
3
|
type CreateIntentResult = Result<[
|
|
4
4
|
IntentExecutionResponse,
|
|
@@ -9,12 +9,12 @@ type CreateIntentResult = Result<[
|
|
|
9
9
|
* Hook for creating and submitting an intent order for cross-chain swaps.
|
|
10
10
|
* Uses React Query's useMutation for better state management and caching.
|
|
11
11
|
*
|
|
12
|
-
* @param {
|
|
12
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for the swap
|
|
13
13
|
* @returns {UseMutationResult} Mutation result object containing mutation function and state
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```typescript
|
|
17
|
-
* const { mutateAsync: createIntent, isPending } = useCreateIntentOrder(
|
|
17
|
+
* const { mutateAsync: createIntent, isPending } = useCreateIntentOrder(spokeProvider);
|
|
18
18
|
*
|
|
19
19
|
* const handleSwap = async () => {
|
|
20
20
|
* const result = await createIntent({
|
|
@@ -28,6 +28,6 @@ type CreateIntentResult = Result<[
|
|
|
28
28
|
* };
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export declare function useCreateIntentOrder(
|
|
31
|
+
export declare function useCreateIntentOrder(spokeProvider: SpokeProvider | undefined): UseMutationResult<CreateIntentResult, Error, CreateIntentParams>;
|
|
32
32
|
export {};
|
|
33
33
|
//# sourceMappingURL=useCreateIntentOrder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCreateIntentOrder.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useCreateIntentOrder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"useCreateIntentOrder.d.ts","sourceRoot":"","sources":["../../../src/hooks/swap/useCreateIntentOrder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,EACN,qBAAqB,EACrB,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,KAAK,kBAAkB,GAAG,MAAM,CAC9B;IAAC,uBAAuB;IAAE,MAAM;IAAE,UAAU;CAAC,EAC7C,iBAAiB,CAAC,qBAAqB,CAAC,CACzC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,kBAAkB,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAWlE"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
|
-
var reactQuery = require('@tanstack/react-query');
|
|
5
4
|
var sdk = require('@sodax/sdk');
|
|
6
5
|
var walletSdk = require('@sodax/wallet-sdk');
|
|
6
|
+
var reactQuery = require('@tanstack/react-query');
|
|
7
7
|
var viem = require('viem');
|
|
8
8
|
|
|
9
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -19,108 +19,49 @@ var useSodaxContext = () => {
|
|
|
19
19
|
}
|
|
20
20
|
return context;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
// src/hooks/provider/useHubProvider.ts
|
|
24
|
+
function useHubProvider() {
|
|
25
|
+
const { hubProvider } = useSodaxContext();
|
|
26
|
+
return hubProvider;
|
|
27
|
+
}
|
|
28
|
+
function useSpokeProvider(spokeChainId, walletProvider) {
|
|
23
29
|
const xChainType = walletSdk.getXChainType(spokeChainId);
|
|
24
|
-
const
|
|
30
|
+
const walletProvider_ = walletSdk.useWalletProvider(spokeChainId);
|
|
31
|
+
const _walletProvider = walletProvider ?? walletProvider_;
|
|
25
32
|
const spokeProvider = React.useMemo(() => {
|
|
26
|
-
if (!
|
|
33
|
+
if (!_walletProvider) return void 0;
|
|
34
|
+
if (!spokeChainId) return void 0;
|
|
27
35
|
if (xChainType === "EVM") {
|
|
28
36
|
return new sdk.EvmSpokeProvider(
|
|
29
|
-
|
|
37
|
+
_walletProvider,
|
|
30
38
|
sdk.spokeChainConfig[spokeChainId]
|
|
31
39
|
);
|
|
32
40
|
}
|
|
33
41
|
if (xChainType === "SUI") {
|
|
34
42
|
return new sdk.SuiSpokeProvider(
|
|
35
43
|
sdk.spokeChainConfig[spokeChainId],
|
|
36
|
-
|
|
44
|
+
_walletProvider
|
|
37
45
|
);
|
|
38
46
|
}
|
|
39
47
|
if (xChainType === "ICON") {
|
|
40
48
|
return new sdk.IconSpokeProvider(
|
|
41
|
-
|
|
49
|
+
_walletProvider,
|
|
42
50
|
sdk.spokeChainConfig[spokeChainId]
|
|
43
51
|
);
|
|
44
52
|
}
|
|
45
53
|
if (xChainType === "INJECTIVE") {
|
|
46
54
|
return new sdk.CWSpokeProvider(
|
|
47
55
|
sdk.spokeChainConfig[spokeChainId],
|
|
48
|
-
|
|
56
|
+
_walletProvider
|
|
49
57
|
);
|
|
50
58
|
}
|
|
51
59
|
return void 0;
|
|
52
|
-
}, [
|
|
60
|
+
}, [spokeChainId, xChainType, _walletProvider]);
|
|
53
61
|
return spokeProvider;
|
|
54
62
|
}
|
|
55
|
-
function
|
|
56
|
-
const { sodax } = useSodaxContext();
|
|
57
|
-
const spokeProvider = useSpokeProvider(token.xChainId);
|
|
58
|
-
return reactQuery.useQuery({
|
|
59
|
-
queryKey: ["allowance", token.address, amount],
|
|
60
|
-
queryFn: async () => {
|
|
61
|
-
if (!spokeProvider) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
const allowance = await sodax.moneyMarket.isAllowanceValid(
|
|
65
|
-
{
|
|
66
|
-
token: token.address,
|
|
67
|
-
amount: viem.parseUnits(amount, token.decimals)
|
|
68
|
-
},
|
|
69
|
-
spokeProvider
|
|
70
|
-
);
|
|
71
|
-
if (allowance.ok) {
|
|
72
|
-
return allowance.value;
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
},
|
|
76
|
-
enabled: !!spokeProvider
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function useApprove(token) {
|
|
63
|
+
function useBorrow(spokeToken, spokeProvider) {
|
|
80
64
|
const { sodax } = useSodaxContext();
|
|
81
|
-
const spokeProvider = useSpokeProvider(token.xChainId);
|
|
82
|
-
const queryClient = reactQuery.useQueryClient();
|
|
83
|
-
const {
|
|
84
|
-
mutateAsync: approve,
|
|
85
|
-
isPending,
|
|
86
|
-
error,
|
|
87
|
-
reset: resetError
|
|
88
|
-
} = reactQuery.useMutation({
|
|
89
|
-
mutationFn: async (amount) => {
|
|
90
|
-
if (!spokeProvider) {
|
|
91
|
-
throw new Error("Spoke provider not found");
|
|
92
|
-
}
|
|
93
|
-
const allowance = await sodax.moneyMarket.approve(
|
|
94
|
-
token.address,
|
|
95
|
-
viem.parseUnits(amount, token.decimals),
|
|
96
|
-
spokeProvider.chainConfig.addresses.assetManager,
|
|
97
|
-
spokeProvider
|
|
98
|
-
);
|
|
99
|
-
if (!allowance.ok) {
|
|
100
|
-
throw new Error("Failed to approve tokens");
|
|
101
|
-
}
|
|
102
|
-
return allowance.ok;
|
|
103
|
-
},
|
|
104
|
-
onSuccess: () => {
|
|
105
|
-
queryClient.invalidateQueries({ queryKey: ["allowance", token.address] });
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
return {
|
|
109
|
-
approve,
|
|
110
|
-
isLoading: isPending,
|
|
111
|
-
error,
|
|
112
|
-
resetError
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/hooks/provider/useHubProvider.ts
|
|
117
|
-
function useHubProvider() {
|
|
118
|
-
const { hubProvider } = useSodaxContext();
|
|
119
|
-
return hubProvider;
|
|
120
|
-
}
|
|
121
|
-
function useBorrow(spokeToken) {
|
|
122
|
-
const { sodax } = useSodaxContext();
|
|
123
|
-
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
124
65
|
return reactQuery.useMutation({
|
|
125
66
|
mutationFn: async (amount) => {
|
|
126
67
|
if (!spokeProvider) {
|
|
@@ -129,12 +70,12 @@ function useBorrow(spokeToken) {
|
|
|
129
70
|
const response = await sodax.moneyMarket.borrowAndSubmit(
|
|
130
71
|
{
|
|
131
72
|
token: spokeToken.address,
|
|
132
|
-
amount: viem.parseUnits(amount, 18)
|
|
73
|
+
amount: viem.parseUnits(amount, 18),
|
|
74
|
+
action: "borrow"
|
|
133
75
|
},
|
|
134
76
|
spokeProvider
|
|
135
77
|
);
|
|
136
78
|
if (!response.ok) {
|
|
137
|
-
console.log("Failed to borrow tokens", response);
|
|
138
79
|
throw new Error("Failed to borrow tokens");
|
|
139
80
|
}
|
|
140
81
|
console.log("Borrow transaction submitted:", response);
|
|
@@ -142,9 +83,8 @@ function useBorrow(spokeToken) {
|
|
|
142
83
|
}
|
|
143
84
|
});
|
|
144
85
|
}
|
|
145
|
-
function useRepay(spokeToken) {
|
|
86
|
+
function useRepay(spokeToken, spokeProvider) {
|
|
146
87
|
const { sodax } = useSodaxContext();
|
|
147
|
-
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
148
88
|
return reactQuery.useMutation({
|
|
149
89
|
mutationFn: async (amount) => {
|
|
150
90
|
if (!spokeProvider) {
|
|
@@ -153,7 +93,8 @@ function useRepay(spokeToken) {
|
|
|
153
93
|
const response = await sodax.moneyMarket.repayAndSubmit(
|
|
154
94
|
{
|
|
155
95
|
token: spokeToken.address,
|
|
156
|
-
amount: viem.parseUnits(amount, spokeToken.decimals)
|
|
96
|
+
amount: viem.parseUnits(amount, spokeToken.decimals),
|
|
97
|
+
action: "repay"
|
|
157
98
|
},
|
|
158
99
|
spokeProvider
|
|
159
100
|
);
|
|
@@ -165,9 +106,8 @@ function useRepay(spokeToken) {
|
|
|
165
106
|
}
|
|
166
107
|
});
|
|
167
108
|
}
|
|
168
|
-
function useSupply(spokeToken) {
|
|
109
|
+
function useSupply(spokeToken, spokeProvider) {
|
|
169
110
|
const { sodax } = useSodaxContext();
|
|
170
|
-
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
171
111
|
return reactQuery.useMutation({
|
|
172
112
|
mutationFn: async (amount) => {
|
|
173
113
|
if (!spokeProvider) {
|
|
@@ -176,7 +116,8 @@ function useSupply(spokeToken) {
|
|
|
176
116
|
const response = await sodax.moneyMarket.supplyAndSubmit(
|
|
177
117
|
{
|
|
178
118
|
token: spokeToken.address,
|
|
179
|
-
amount: viem.parseUnits(amount, spokeToken.decimals)
|
|
119
|
+
amount: viem.parseUnits(amount, spokeToken.decimals),
|
|
120
|
+
action: "supply"
|
|
180
121
|
},
|
|
181
122
|
spokeProvider
|
|
182
123
|
);
|
|
@@ -188,9 +129,8 @@ function useSupply(spokeToken) {
|
|
|
188
129
|
}
|
|
189
130
|
});
|
|
190
131
|
}
|
|
191
|
-
function useWithdraw(spokeToken) {
|
|
132
|
+
function useWithdraw(spokeToken, spokeProvider) {
|
|
192
133
|
const { sodax } = useSodaxContext();
|
|
193
|
-
const spokeProvider = useSpokeProvider(spokeToken.xChainId);
|
|
194
134
|
return reactQuery.useMutation({
|
|
195
135
|
mutationFn: async (amount) => {
|
|
196
136
|
if (!spokeProvider) {
|
|
@@ -200,7 +140,8 @@ function useWithdraw(spokeToken) {
|
|
|
200
140
|
{
|
|
201
141
|
token: spokeToken.address,
|
|
202
142
|
// vault token on hub chain decimals is 18
|
|
203
|
-
amount: viem.parseUnits(amount, 18)
|
|
143
|
+
amount: viem.parseUnits(amount, 18),
|
|
144
|
+
action: "withdraw"
|
|
204
145
|
},
|
|
205
146
|
spokeProvider
|
|
206
147
|
);
|
|
@@ -238,21 +179,17 @@ var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
|
238
179
|
const address = Object.keys(tokens).find((tokenAddress) => tokens[tokenAddress].vault === vault);
|
|
239
180
|
return address;
|
|
240
181
|
};
|
|
241
|
-
function useUserReservesData(spokeChainId) {
|
|
182
|
+
function useUserReservesData(spokeChainId, address) {
|
|
242
183
|
const { sodax } = useSodaxContext();
|
|
243
184
|
const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? "sonic";
|
|
244
185
|
const hubProvider = useHubProvider();
|
|
245
|
-
const spokeProvider = useSpokeProvider(spokeChainId);
|
|
246
186
|
const { data: userReserves } = reactQuery.useQuery({
|
|
247
|
-
queryKey: ["userReserves", spokeChainId],
|
|
187
|
+
queryKey: ["userReserves", spokeChainId, address],
|
|
248
188
|
queryFn: async () => {
|
|
249
|
-
if (!hubProvider) {
|
|
189
|
+
if (!hubProvider || !address) {
|
|
250
190
|
return;
|
|
251
191
|
}
|
|
252
|
-
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
const addressBytes = await spokeProvider.walletProvider.getWalletAddressBytes();
|
|
192
|
+
const addressBytes = sdk.encodeAddress(spokeChainId, address);
|
|
256
193
|
const hubWalletAddress = await sdk.EvmWalletAbstraction.getUserHubWalletAddress(
|
|
257
194
|
spokeChainId,
|
|
258
195
|
addressBytes,
|
|
@@ -271,7 +208,7 @@ function useUserReservesData(spokeChainId) {
|
|
|
271
208
|
};
|
|
272
209
|
});
|
|
273
210
|
},
|
|
274
|
-
enabled: !!
|
|
211
|
+
enabled: !!spokeChainId && !!hubProvider && !!address,
|
|
275
212
|
refetchInterval: 5e3
|
|
276
213
|
});
|
|
277
214
|
return userReserves;
|
|
@@ -310,6 +247,69 @@ function useReservesData() {
|
|
|
310
247
|
}
|
|
311
248
|
});
|
|
312
249
|
}
|
|
250
|
+
function useAllowance(token, amount, action) {
|
|
251
|
+
const { sodax } = useSodaxContext();
|
|
252
|
+
const spokeProvider = useSpokeProvider(token.xChainId);
|
|
253
|
+
return reactQuery.useQuery({
|
|
254
|
+
queryKey: ["allowance", token.address, amount, action],
|
|
255
|
+
queryFn: async () => {
|
|
256
|
+
if (!spokeProvider) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
const allowance = await sodax.moneyMarket.isAllowanceValid(
|
|
260
|
+
{
|
|
261
|
+
token: token.address,
|
|
262
|
+
amount: viem.parseUnits(amount, token.decimals),
|
|
263
|
+
action
|
|
264
|
+
},
|
|
265
|
+
spokeProvider
|
|
266
|
+
);
|
|
267
|
+
if (allowance.ok) {
|
|
268
|
+
return allowance.value;
|
|
269
|
+
}
|
|
270
|
+
return false;
|
|
271
|
+
},
|
|
272
|
+
enabled: !!spokeProvider
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function useApprove(token) {
|
|
276
|
+
const { sodax } = useSodaxContext();
|
|
277
|
+
const spokeProvider = useSpokeProvider(token.xChainId);
|
|
278
|
+
const queryClient = reactQuery.useQueryClient();
|
|
279
|
+
const {
|
|
280
|
+
mutateAsync: approve,
|
|
281
|
+
isPending,
|
|
282
|
+
error,
|
|
283
|
+
reset: resetError
|
|
284
|
+
} = reactQuery.useMutation({
|
|
285
|
+
mutationFn: async ({ amount, action }) => {
|
|
286
|
+
if (!spokeProvider) {
|
|
287
|
+
throw new Error("Spoke provider not found");
|
|
288
|
+
}
|
|
289
|
+
const allowance = await sodax.moneyMarket.approve(
|
|
290
|
+
{
|
|
291
|
+
token: token.address,
|
|
292
|
+
amount: viem.parseUnits(amount, token.decimals),
|
|
293
|
+
action
|
|
294
|
+
},
|
|
295
|
+
spokeProvider
|
|
296
|
+
);
|
|
297
|
+
if (!allowance.ok) {
|
|
298
|
+
throw new Error("Failed to approve tokens");
|
|
299
|
+
}
|
|
300
|
+
return allowance.ok;
|
|
301
|
+
},
|
|
302
|
+
onSuccess: () => {
|
|
303
|
+
queryClient.invalidateQueries({ queryKey: ["allowance", token.address] });
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
return {
|
|
307
|
+
approve,
|
|
308
|
+
isLoading: isPending,
|
|
309
|
+
error,
|
|
310
|
+
resetError
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
313
|
var useQuote = (payload) => {
|
|
314
314
|
const { sodax } = useSodaxContext();
|
|
315
315
|
return reactQuery.useQuery({
|
|
@@ -324,9 +324,8 @@ var useQuote = (payload) => {
|
|
|
324
324
|
refetchInterval: 3e3
|
|
325
325
|
});
|
|
326
326
|
};
|
|
327
|
-
function useCreateIntentOrder(
|
|
327
|
+
function useCreateIntentOrder(spokeProvider) {
|
|
328
328
|
const { sodax } = useSodaxContext();
|
|
329
|
-
const spokeProvider = useSpokeProvider(chainId);
|
|
330
329
|
return reactQuery.useMutation({
|
|
331
330
|
mutationFn: async (params) => {
|
|
332
331
|
if (!spokeProvider) {
|