@sodax/dapp-kit 0.0.1-rc.21 → 0.0.1-rc.23
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 +83 -1
- package/dist/contexts/index.d.ts +1 -2
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/hooks/backend/index.d.ts +17 -0
- package/dist/hooks/backend/index.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendAllMoneyMarketAssets.d.ts +37 -0
- package/dist/hooks/backend/useBackendAllMoneyMarketAssets.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendAllMoneyMarketBorrowers.d.ts +45 -0
- package/dist/hooks/backend/useBackendAllMoneyMarketBorrowers.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendIntentByHash.d.ts +36 -0
- package/dist/hooks/backend/useBackendIntentByHash.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendIntentByTxHash.d.ts +35 -0
- package/dist/hooks/backend/useBackendIntentByTxHash.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendMoneyMarketAsset.d.ts +38 -0
- package/dist/hooks/backend/useBackendMoneyMarketAsset.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendMoneyMarketAssetBorrowers.d.ts +47 -0
- package/dist/hooks/backend/useBackendMoneyMarketAssetBorrowers.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendMoneyMarketAssetSuppliers.d.ts +47 -0
- package/dist/hooks/backend/useBackendMoneyMarketAssetSuppliers.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendMoneyMarketPosition.d.ts +37 -0
- package/dist/hooks/backend/useBackendMoneyMarketPosition.d.ts.map +1 -0
- package/dist/hooks/backend/useBackendOrderbook.d.ts +46 -0
- package/dist/hooks/backend/useBackendOrderbook.d.ts.map +1 -0
- package/dist/hooks/bridge/index.d.ts +6 -0
- package/dist/hooks/bridge/index.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridge.d.ts +33 -0
- package/dist/hooks/bridge/useBridge.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridgeAllowance.d.ts +23 -0
- package/dist/hooks/bridge/useBridgeAllowance.d.ts.map +1 -0
- package/dist/hooks/bridge/useBridgeApprove.d.ts +29 -0
- package/dist/hooks/bridge/useBridgeApprove.d.ts.map +1 -0
- package/dist/hooks/bridge/useGetBridgeableAmount.d.ts +26 -0
- package/dist/hooks/bridge/useGetBridgeableAmount.d.ts.map +1 -0
- package/dist/hooks/bridge/useGetBridgeableTokens.d.ts +37 -0
- package/dist/hooks/bridge/useGetBridgeableTokens.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/mm/useUserFormattedSummary.d.ts +1 -1
- package/dist/hooks/mm/useUserFormattedSummary.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/provider/useHubProvider.d.ts +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
- package/dist/hooks/shared/index.d.ts +1 -0
- package/dist/hooks/shared/index.d.ts.map +1 -1
- package/dist/hooks/shared/useDeriveUserWalletAddress.d.ts +24 -0
- package/dist/hooks/shared/useDeriveUserWalletAddress.d.ts.map +1 -0
- package/dist/index.js +278 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -21
- package/dist/index.mjs.map +1 -1
- package/dist/providers/SodaxProvider.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/contexts/index.ts +1 -2
- package/src/hooks/backend/README.md +135 -0
- package/src/hooks/backend/index.ts +23 -0
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +49 -0
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +61 -0
- package/src/hooks/backend/useBackendIntentByHash.ts +53 -0
- package/src/hooks/backend/useBackendIntentByTxHash.ts +52 -0
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +57 -0
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +67 -0
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +67 -0
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +56 -0
- package/src/hooks/backend/useBackendOrderbook.ts +63 -0
- package/src/hooks/bridge/index.ts +5 -0
- package/src/hooks/bridge/useBridge.ts +57 -0
- package/src/hooks/bridge/useBridgeAllowance.ts +49 -0
- package/src/hooks/bridge/useBridgeApprove.ts +68 -0
- package/src/hooks/bridge/useGetBridgeableAmount.ts +50 -0
- package/src/hooks/bridge/useGetBridgeableTokens.ts +62 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/mm/useUserFormattedSummary.ts +1 -1
- package/src/hooks/mm/useUserReservesData.ts +1 -1
- package/src/hooks/provider/useHubProvider.ts +3 -3
- package/src/hooks/provider/useSpokeProvider.ts +10 -4
- package/src/hooks/shared/index.ts +1 -0
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +44 -0
- package/src/providers/SodaxProvider.tsx +4 -18
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CreateBridgeIntentParams, SpokeProvider } from '@sodax/sdk';
|
|
2
|
+
interface UseBridgeApproveReturn {
|
|
3
|
+
approve: (params: CreateBridgeIntentParams) => Promise<boolean>;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
error: Error | null;
|
|
6
|
+
resetError: () => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Hook for approving token spending for bridge actions
|
|
10
|
+
* @param spokeProvider The spoke provider instance for the chain
|
|
11
|
+
* @returns Object containing approve function, loading state, error state and reset function
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const { approve, isLoading, error } = useBridgeApprove(spokeProvider);
|
|
15
|
+
*
|
|
16
|
+
* // Approve tokens for bridge action
|
|
17
|
+
* await approve({
|
|
18
|
+
* srcChainId: '0x2105.base',
|
|
19
|
+
* srcAsset: '0x...',
|
|
20
|
+
* amount: 1000n,
|
|
21
|
+
* dstChainId: '0x89.polygon',
|
|
22
|
+
* dstAsset: '0x...',
|
|
23
|
+
* recipient: '0x...'
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function useBridgeApprove(spokeProvider: SpokeProvider | undefined): UseBridgeApproveReturn;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=useBridgeApprove.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBridgeApprove.d.ts","sourceRoot":"","sources":["../../../src/hooks/bridge/useBridgeApprove.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG1E,UAAU,sBAAsB;IAC9B,OAAO,EAAE,CAAC,MAAM,EAAE,wBAAwB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAChE,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS,GAAG,sBAAsB,CAqCjG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { XToken } from '@sodax/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for getting the amount available to be bridged.
|
|
5
|
+
*
|
|
6
|
+
* This hook is used to check if a target chain has enough balance to bridge when bridging.
|
|
7
|
+
* It automatically queries and tracks the available amount to be bridged.
|
|
8
|
+
*
|
|
9
|
+
* @param {SpokeChainId | undefined} chainId - The chain ID to get the balance for
|
|
10
|
+
* @param {string | undefined} token - The token address to get the balance for
|
|
11
|
+
*
|
|
12
|
+
* @returns {UseQueryResult<bigint, Error>} A React Query result containing:
|
|
13
|
+
* - data: The available amount to be bridged (bigint)
|
|
14
|
+
* - error: Any error that occurred during the check
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const { data: balance, isLoading } = useSpokeAssetManagerTokenBalance(chainId, tokenAddress);
|
|
19
|
+
*
|
|
20
|
+
* if (balance) {
|
|
21
|
+
* console.log('Asset manager token balance:', balance.toString());
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function useGetBridgeableAmount(from: XToken | undefined, to: XToken | undefined): UseQueryResult<bigint, Error>;
|
|
26
|
+
//# sourceMappingURL=useGetBridgeableAmount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetBridgeableAmount.d.ts","sourceRoot":"","sources":["../../../src/hooks/bridge/useGetBridgeableAmount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAwB,MAAM,EAAE,MAAM,YAAY,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,EAAE,EAAE,MAAM,GAAG,SAAS,GACrB,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAoB/B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { XToken, SpokeChainId } from '@sodax/sdk';
|
|
3
|
+
/**
|
|
4
|
+
/**
|
|
5
|
+
* Hook for retrieving all bridgeable tokens from a source token on one chain to a destination chain.
|
|
6
|
+
*
|
|
7
|
+
* This hook queries and tracks the set of tokens on the destination chain that can be bridged to,
|
|
8
|
+
* given a source chain, destination chain, and source token address.
|
|
9
|
+
*
|
|
10
|
+
* @param {SpokeChainId | undefined} from - The source chain ID
|
|
11
|
+
* @param {SpokeChainId | undefined} to - The destination chain ID
|
|
12
|
+
* @param {string | undefined} token - The source token address
|
|
13
|
+
*
|
|
14
|
+
* @returns {UseQueryResult<XToken[], Error>} A React Query result containing:
|
|
15
|
+
* - data: Array of bridgeable tokens (XToken[]) on the destination chain
|
|
16
|
+
* - error: Any error that occurred during the query
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const { data: bridgeableTokens, isLoading } = useGetBridgeableTokens(
|
|
22
|
+
* fromChainId,
|
|
23
|
+
* toChainId,
|
|
24
|
+
* fromTokenAddress
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* if (bridgeableTokens && bridgeableTokens.length > 0) {
|
|
28
|
+
* bridgeableTokens.forEach(token => {
|
|
29
|
+
* console.log(`Bridgeable token: ${token.symbol} (${token.address}) on chain ${token.xChainId}`);
|
|
30
|
+
* });
|
|
31
|
+
* } else {
|
|
32
|
+
* console.log('No bridgeable tokens found for the selected route.');
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function useGetBridgeableTokens(from: SpokeChainId | undefined, to: SpokeChainId | undefined, token: string | undefined): UseQueryResult<XToken[], Error>;
|
|
37
|
+
//# sourceMappingURL=useGetBridgeableTokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetBridgeableTokens.d.ts","sourceRoot":"","sources":["../../../src/hooks/bridge/useGetBridgeableTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,EAAE,EAAE,YAAY,GAAG,SAAS,EAC5B,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,cAAc,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,CAoBjC"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FormatUserSummaryResponse, FormatReserveUSDResponse, SpokeProvider } from '@sodax/sdk';
|
|
2
2
|
import { type UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
/**
|
|
4
4
|
* Hook for fetching formatted summary of Sodax user portfolio (holdings, total liquidity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUserFormattedSummary.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserFormattedSummary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useUserFormattedSummary.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserFormattedSummary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACrG,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGtE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,aAAa,GAAG,SAAS,EACxC,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,cAAc,CAAC,yBAAyB,CAAC,wBAAwB,CAAC,EAAE,KAAK,CAAC,CA6B5E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SpokeProvider,
|
|
1
|
+
import type { SpokeProvider, UserReserveData } from '@sodax/sdk';
|
|
2
2
|
import { type UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
/**
|
|
4
4
|
* Hook for fetching user reserves data from the Sodax money market.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUserReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserReservesData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"useUserReservesData.d.ts","sourceRoot":"","sources":["../../../src/hooks/mm/useUserReservesData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGtE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,aAAa,GAAG,SAAS,EACxC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,eAAe,SAAO,GACrB,cAAc,CAAC,SAAS,CAAC,SAAS,eAAe,EAAE,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAetE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHubProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/provider/useHubProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,wBAAgB,cAAc,IAAI,cAAc,
|
|
1
|
+
{"version":3,"file":"useHubProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/provider/useHubProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,wBAAgB,cAAc,IAAI,cAAc,CAI/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSpokeProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/provider/useSpokeProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAYL,KAAK,aAAa,EAClB,KAAK,eAAe,EAMrB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAIV,YAAY,EAIb,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,cAAc,CAAC,EAAE,eAAe,GAAG,SAAS,GAC3C,aAAa,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"useSpokeProvider.d.ts","sourceRoot":"","sources":["../../../src/hooks/provider/useSpokeProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAYL,KAAK,aAAa,EAClB,KAAK,eAAe,EAMrB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAIV,YAAY,EAIb,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,cAAc,CAAC,EAAE,eAAe,GAAG,SAAS,GAC3C,aAAa,GAAG,SAAS,CA0E3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type SpokeProvider } from '@sodax/sdk';
|
|
2
|
+
import { type UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import type { Address } from 'viem';
|
|
4
|
+
/**
|
|
5
|
+
* Hook for deriving user wallet address for hub abstraction.
|
|
6
|
+
*
|
|
7
|
+
* This hook derives the user's abstracted wallet address for the hub chain.
|
|
8
|
+
* If the spoke chain is the same as the hub chain, it returns the original wallet address.
|
|
9
|
+
* Otherwise, it returns the abstracted wallet address for cross-chain operations.
|
|
10
|
+
*
|
|
11
|
+
* @param spokeProvider - The spoke provider instance for the origin chain
|
|
12
|
+
* @param walletAddress - Optional user wallet address on spoke chain. If not provided, will fetch from spokeProvider
|
|
13
|
+
* @returns A React Query result object containing:
|
|
14
|
+
* - data: The derived user wallet address when available
|
|
15
|
+
* - isLoading: Loading state indicator
|
|
16
|
+
* - error: Any error that occurred during derivation
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function useDeriveUserWalletAddress(spokeProvider: SpokeProvider | undefined, walletAddress?: string | undefined): UseQueryResult<Address, Error>;
|
|
24
|
+
//# sourceMappingURL=useDeriveUserWalletAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDeriveUserWalletAddress.d.ts","sourceRoot":"","sources":["../../../src/hooks/shared/useDeriveUserWalletAddress.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,aAAa,EAAuB,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,aAAa,GAAG,SAAS,EACxC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,GACjC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAehC"}
|
package/dist/index.js
CHANGED
|
@@ -29,11 +29,26 @@ function useEstimateGas(spokeProvider) {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
+
function useDeriveUserWalletAddress(spokeProvider, walletAddress) {
|
|
33
|
+
const { sodax } = useSodaxContext();
|
|
34
|
+
return reactQuery.useQuery({
|
|
35
|
+
queryKey: ["deriveUserWalletAddress", spokeProvider?.chainConfig.chain.id, walletAddress],
|
|
36
|
+
queryFn: async () => {
|
|
37
|
+
if (!spokeProvider) {
|
|
38
|
+
throw new Error("Spoke provider is required");
|
|
39
|
+
}
|
|
40
|
+
return await sdk.deriveUserWalletAddress(spokeProvider, sodax.hubProvider, walletAddress);
|
|
41
|
+
},
|
|
42
|
+
enabled: !!spokeProvider,
|
|
43
|
+
refetchInterval: false
|
|
44
|
+
// This is a deterministic operation, no need to refetch
|
|
45
|
+
});
|
|
46
|
+
}
|
|
32
47
|
|
|
33
48
|
// src/hooks/provider/useHubProvider.ts
|
|
34
49
|
function useHubProvider() {
|
|
35
|
-
const {
|
|
36
|
-
return hubProvider;
|
|
50
|
+
const { sodax } = useSodaxContext();
|
|
51
|
+
return sodax.hubProvider;
|
|
37
52
|
}
|
|
38
53
|
function useSpokeProvider(spokeChainId, walletProvider) {
|
|
39
54
|
const { rpcConfig } = useSodaxContext();
|
|
@@ -75,10 +90,14 @@ function useSpokeProvider(spokeChainId, walletProvider) {
|
|
|
75
90
|
}
|
|
76
91
|
if (xChainType === "STELLAR") {
|
|
77
92
|
const stellarConfig = sdk.spokeChainConfig[spokeChainId];
|
|
78
|
-
return new sdk.StellarSpokeProvider(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
return new sdk.StellarSpokeProvider(
|
|
94
|
+
walletProvider,
|
|
95
|
+
stellarConfig,
|
|
96
|
+
rpcConfig.stellar ? rpcConfig.stellar : {
|
|
97
|
+
horizonRpcUrl: stellarConfig.horizonRpcUrl,
|
|
98
|
+
sorobanRpcUrl: stellarConfig.sorobanRpcUrl
|
|
99
|
+
}
|
|
100
|
+
);
|
|
82
101
|
}
|
|
83
102
|
if (xChainType === "SOLANA") {
|
|
84
103
|
return new sdk.SolanaSpokeProvider(
|
|
@@ -374,21 +393,246 @@ function useCancelSwap(spokeProvider) {
|
|
|
374
393
|
}
|
|
375
394
|
});
|
|
376
395
|
}
|
|
377
|
-
var
|
|
378
|
-
const sodax =
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
396
|
+
var useBackendIntentByTxHash = (txHash) => {
|
|
397
|
+
const { sodax } = useSodaxContext();
|
|
398
|
+
return reactQuery.useQuery({
|
|
399
|
+
queryKey: ["backend", "intent", "txHash", txHash],
|
|
400
|
+
queryFn: async () => {
|
|
401
|
+
if (!txHash) {
|
|
402
|
+
return void 0;
|
|
403
|
+
}
|
|
404
|
+
return sodax.backendApiService.getIntentByTxHash(txHash);
|
|
405
|
+
},
|
|
406
|
+
enabled: !!txHash && txHash.length > 0,
|
|
407
|
+
retry: 3
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
var useBackendIntentByHash = (intentHash) => {
|
|
411
|
+
const { sodax } = useSodaxContext();
|
|
412
|
+
return reactQuery.useQuery({
|
|
413
|
+
queryKey: ["backend", "intent", "hash", intentHash],
|
|
414
|
+
queryFn: async () => {
|
|
415
|
+
if (!intentHash) {
|
|
416
|
+
return void 0;
|
|
417
|
+
}
|
|
418
|
+
return sodax.backendApiService.getIntentByHash(intentHash);
|
|
419
|
+
},
|
|
420
|
+
enabled: !!intentHash && intentHash.length > 0,
|
|
421
|
+
retry: 3
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
var useBackendOrderbook = (params) => {
|
|
425
|
+
const { sodax } = useSodaxContext();
|
|
426
|
+
return reactQuery.useQuery({
|
|
427
|
+
queryKey: ["backend", "solver", "orderbook", params],
|
|
428
|
+
queryFn: async () => {
|
|
429
|
+
if (!params || !params.offset || !params.limit) {
|
|
430
|
+
return void 0;
|
|
431
|
+
}
|
|
432
|
+
return sodax.backendApiService.getOrderbook(params);
|
|
433
|
+
},
|
|
434
|
+
enabled: !!params && !!params.offset && !!params.limit,
|
|
435
|
+
staleTime: 30 * 1e3,
|
|
436
|
+
// 30 seconds for real-time data
|
|
437
|
+
retry: 3
|
|
438
|
+
});
|
|
439
|
+
};
|
|
440
|
+
var useBackendMoneyMarketPosition = (userAddress) => {
|
|
441
|
+
const { sodax } = useSodaxContext();
|
|
442
|
+
return reactQuery.useQuery({
|
|
443
|
+
queryKey: ["backend", "moneymarket", "position", userAddress],
|
|
444
|
+
queryFn: async () => {
|
|
445
|
+
if (!userAddress) {
|
|
446
|
+
return void 0;
|
|
447
|
+
}
|
|
448
|
+
return sodax.backendApiService.getMoneyMarketPosition(userAddress);
|
|
449
|
+
},
|
|
450
|
+
enabled: !!userAddress && userAddress.length > 0,
|
|
451
|
+
retry: 3
|
|
452
|
+
});
|
|
453
|
+
};
|
|
454
|
+
var useBackendAllMoneyMarketAssets = () => {
|
|
455
|
+
const { sodax } = useSodaxContext();
|
|
456
|
+
return reactQuery.useQuery({
|
|
457
|
+
queryKey: ["backend", "moneymarket", "assets", "all"],
|
|
458
|
+
queryFn: async () => {
|
|
459
|
+
return sodax.backendApiService.getAllMoneyMarketAssets();
|
|
460
|
+
},
|
|
461
|
+
retry: 3
|
|
462
|
+
});
|
|
463
|
+
};
|
|
464
|
+
var useBackendMoneyMarketAsset = (reserveAddress) => {
|
|
465
|
+
const { sodax } = useSodaxContext();
|
|
466
|
+
return reactQuery.useQuery({
|
|
467
|
+
queryKey: ["backend", "moneymarket", "asset", reserveAddress],
|
|
468
|
+
queryFn: async () => {
|
|
469
|
+
if (!reserveAddress) {
|
|
470
|
+
return void 0;
|
|
471
|
+
}
|
|
472
|
+
return sodax.backendApiService.getMoneyMarketAsset(reserveAddress);
|
|
473
|
+
},
|
|
474
|
+
enabled: !!reserveAddress && reserveAddress.length > 0,
|
|
475
|
+
retry: 3
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
var useBackendMoneyMarketAssetBorrowers = (params) => {
|
|
479
|
+
const { sodax } = useSodaxContext();
|
|
480
|
+
return reactQuery.useQuery({
|
|
481
|
+
queryKey: ["backend", "moneymarket", "asset", "borrowers", params],
|
|
482
|
+
queryFn: async () => {
|
|
483
|
+
if (!params.reserveAddress || !params.offset || !params.limit) {
|
|
484
|
+
return void 0;
|
|
485
|
+
}
|
|
486
|
+
return sodax.backendApiService.getMoneyMarketAssetBorrowers(params.reserveAddress, {
|
|
487
|
+
offset: params.offset,
|
|
488
|
+
limit: params.limit
|
|
387
489
|
});
|
|
490
|
+
},
|
|
491
|
+
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
492
|
+
retry: 3
|
|
493
|
+
});
|
|
494
|
+
};
|
|
495
|
+
var useBackendMoneyMarketAssetSuppliers = (params) => {
|
|
496
|
+
const { sodax } = useSodaxContext();
|
|
497
|
+
return reactQuery.useQuery({
|
|
498
|
+
queryKey: ["backend", "moneymarket", "asset", "suppliers", params],
|
|
499
|
+
queryFn: async () => {
|
|
500
|
+
if (!params.reserveAddress || !params.offset || !params.limit) {
|
|
501
|
+
return void 0;
|
|
502
|
+
}
|
|
503
|
+
return sodax.backendApiService.getMoneyMarketAssetSuppliers(params.reserveAddress, {
|
|
504
|
+
offset: params.offset,
|
|
505
|
+
limit: params.limit
|
|
506
|
+
});
|
|
507
|
+
},
|
|
508
|
+
enabled: !!params.reserveAddress && !!params.offset && !!params.limit,
|
|
509
|
+
retry: 3
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
var useBackendAllMoneyMarketBorrowers = (params) => {
|
|
513
|
+
const { sodax } = useSodaxContext();
|
|
514
|
+
return reactQuery.useQuery({
|
|
515
|
+
queryKey: ["backend", "moneymarket", "borrowers", "all", params],
|
|
516
|
+
queryFn: async () => {
|
|
517
|
+
if (!params || !params.offset || !params.limit) {
|
|
518
|
+
return void 0;
|
|
519
|
+
}
|
|
520
|
+
return sodax.backendApiService.getAllMoneyMarketBorrowers(params);
|
|
521
|
+
},
|
|
522
|
+
enabled: !!params && !!params.offset && !!params.limit,
|
|
523
|
+
retry: 3
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
function useBridgeAllowance(params, spokeProvider) {
|
|
527
|
+
const { sodax } = useSodaxContext();
|
|
528
|
+
return reactQuery.useQuery({
|
|
529
|
+
queryKey: ["bridge-allowance", params],
|
|
530
|
+
queryFn: async () => {
|
|
531
|
+
if (!spokeProvider || !params) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
const allowance = await sodax.bridge.isAllowanceValid({
|
|
535
|
+
params,
|
|
536
|
+
spokeProvider
|
|
537
|
+
});
|
|
538
|
+
if (allowance.ok) {
|
|
539
|
+
return allowance.value;
|
|
540
|
+
}
|
|
541
|
+
return false;
|
|
542
|
+
},
|
|
543
|
+
enabled: !!spokeProvider && !!params
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
function useBridgeApprove(spokeProvider) {
|
|
547
|
+
const { sodax } = useSodaxContext();
|
|
548
|
+
const queryClient = reactQuery.useQueryClient();
|
|
549
|
+
const {
|
|
550
|
+
mutateAsync: approve,
|
|
551
|
+
isPending,
|
|
552
|
+
error,
|
|
553
|
+
reset: resetError
|
|
554
|
+
} = reactQuery.useMutation({
|
|
555
|
+
mutationFn: async (params) => {
|
|
556
|
+
if (!spokeProvider) {
|
|
557
|
+
throw new Error("Spoke provider not found");
|
|
558
|
+
}
|
|
559
|
+
const allowance = await sodax.bridge.approve({
|
|
560
|
+
params,
|
|
561
|
+
spokeProvider
|
|
562
|
+
});
|
|
563
|
+
if (!allowance.ok) {
|
|
564
|
+
throw new Error("Failed to approve tokens for bridge");
|
|
565
|
+
}
|
|
566
|
+
return true;
|
|
567
|
+
},
|
|
568
|
+
onSuccess: (_, params) => {
|
|
569
|
+
queryClient.invalidateQueries({ queryKey: ["bridge-allowance", params] });
|
|
388
570
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
571
|
+
});
|
|
572
|
+
return {
|
|
573
|
+
approve,
|
|
574
|
+
isLoading: isPending,
|
|
575
|
+
error,
|
|
576
|
+
resetError
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function useBridge(spokeProvider) {
|
|
580
|
+
const { sodax } = useSodaxContext();
|
|
581
|
+
return reactQuery.useMutation({
|
|
582
|
+
mutationFn: async (params) => {
|
|
583
|
+
if (!spokeProvider) {
|
|
584
|
+
throw new Error("Spoke provider not found");
|
|
585
|
+
}
|
|
586
|
+
const result = await sodax.bridge.bridge({
|
|
587
|
+
params,
|
|
588
|
+
spokeProvider
|
|
589
|
+
});
|
|
590
|
+
if (!result.ok) {
|
|
591
|
+
throw new Error(`Bridge failed: ${result.error.code}`);
|
|
592
|
+
}
|
|
593
|
+
return result;
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
function useGetBridgeableAmount(from, to) {
|
|
598
|
+
const { sodax } = useSodaxContext();
|
|
599
|
+
return reactQuery.useQuery({
|
|
600
|
+
queryKey: ["spoke-asset-manager-token-balance", from, to],
|
|
601
|
+
queryFn: async () => {
|
|
602
|
+
if (!from || !to) {
|
|
603
|
+
return 0n;
|
|
604
|
+
}
|
|
605
|
+
const result = await sodax.bridge.getBridgeableAmount(from, to);
|
|
606
|
+
if (result.ok) {
|
|
607
|
+
return result.value;
|
|
608
|
+
}
|
|
609
|
+
console.error("Error getting bridgeable amount:", result.error);
|
|
610
|
+
return 0n;
|
|
611
|
+
},
|
|
612
|
+
enabled: !!from && !!to
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
function useGetBridgeableTokens(from, to, token) {
|
|
616
|
+
const { sodax } = useSodaxContext();
|
|
617
|
+
return reactQuery.useQuery({
|
|
618
|
+
queryKey: ["bridgeable-tokens", from, to, token],
|
|
619
|
+
queryFn: async () => {
|
|
620
|
+
if (!from || !to || !token) {
|
|
621
|
+
return [];
|
|
622
|
+
}
|
|
623
|
+
const result = sodax.bridge.getBridgeableTokens(from, to, token);
|
|
624
|
+
if (result.ok) {
|
|
625
|
+
return result.value;
|
|
626
|
+
}
|
|
627
|
+
console.error("Error getting bridgeable tokens:", result.error);
|
|
628
|
+
return [];
|
|
629
|
+
},
|
|
630
|
+
enabled: !!from && !!to && !!token
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
var SodaxProvider = ({ children, testnet = false, config, rpcConfig }) => {
|
|
634
|
+
const sodax = new sdk.Sodax(config);
|
|
635
|
+
return /* @__PURE__ */ React__default.default.createElement(SodaxContext.Provider, { value: { sodax, testnet, rpcConfig } }, children);
|
|
392
636
|
};
|
|
393
637
|
var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
394
638
|
const tokens = sdk.hubAssets[spokeChainId];
|
|
@@ -400,9 +644,24 @@ var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
|
400
644
|
|
|
401
645
|
exports.SodaxProvider = SodaxProvider;
|
|
402
646
|
exports.getSpokeTokenAddressByVault = getSpokeTokenAddressByVault;
|
|
647
|
+
exports.useBackendAllMoneyMarketAssets = useBackendAllMoneyMarketAssets;
|
|
648
|
+
exports.useBackendAllMoneyMarketBorrowers = useBackendAllMoneyMarketBorrowers;
|
|
649
|
+
exports.useBackendIntentByHash = useBackendIntentByHash;
|
|
650
|
+
exports.useBackendIntentByTxHash = useBackendIntentByTxHash;
|
|
651
|
+
exports.useBackendMoneyMarketAsset = useBackendMoneyMarketAsset;
|
|
652
|
+
exports.useBackendMoneyMarketAssetBorrowers = useBackendMoneyMarketAssetBorrowers;
|
|
653
|
+
exports.useBackendMoneyMarketAssetSuppliers = useBackendMoneyMarketAssetSuppliers;
|
|
654
|
+
exports.useBackendMoneyMarketPosition = useBackendMoneyMarketPosition;
|
|
655
|
+
exports.useBackendOrderbook = useBackendOrderbook;
|
|
403
656
|
exports.useBorrow = useBorrow;
|
|
657
|
+
exports.useBridge = useBridge;
|
|
658
|
+
exports.useBridgeAllowance = useBridgeAllowance;
|
|
659
|
+
exports.useBridgeApprove = useBridgeApprove;
|
|
404
660
|
exports.useCancelSwap = useCancelSwap;
|
|
661
|
+
exports.useDeriveUserWalletAddress = useDeriveUserWalletAddress;
|
|
405
662
|
exports.useEstimateGas = useEstimateGas;
|
|
663
|
+
exports.useGetBridgeableAmount = useGetBridgeableAmount;
|
|
664
|
+
exports.useGetBridgeableTokens = useGetBridgeableTokens;
|
|
406
665
|
exports.useHubProvider = useHubProvider;
|
|
407
666
|
exports.useMMAllowance = useMMAllowance;
|
|
408
667
|
exports.useMMApprove = useMMApprove;
|