@sodax/dapp-kit 0.0.1-rc.21 → 0.0.1-rc.22
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/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 +1 -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 +139 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -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/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 +1 -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
package/README.md
CHANGED
|
@@ -32,6 +32,16 @@ dApp Kit is a collection of React components, hooks, and utilities designed to s
|
|
|
32
32
|
- Get spoke chain provider (`useSpokeProvider`)
|
|
33
33
|
- Get wallet provider (`useWalletProvider`)
|
|
34
34
|
|
|
35
|
+
- Bridge
|
|
36
|
+
- Bridge tokens between chains (`useBridge`)
|
|
37
|
+
- Check token allowance for bridging (`useBridgeAllowance`)
|
|
38
|
+
- Approve source token for bridging (`useBridgeApprove`)
|
|
39
|
+
- Get max amount available to be bridged (`useGetBridgeableAmount`)
|
|
40
|
+
- Get available destination tokens based on provided source token (`useGetBridgeableTokens`)
|
|
41
|
+
|
|
42
|
+
- Shared
|
|
43
|
+
- Derive user wallet address for hub abstraction (`useDeriveUserWalletAddress`)
|
|
44
|
+
|
|
35
45
|
## Installation
|
|
36
46
|
|
|
37
47
|
```bash
|
|
@@ -148,6 +158,24 @@ function TokenManagementComponent() {
|
|
|
148
158
|
};
|
|
149
159
|
}
|
|
150
160
|
|
|
161
|
+
// Wallet Address Derivation
|
|
162
|
+
import { useDeriveUserWalletAddress, useSpokeProvider } from '@sodax/dapp-kit';
|
|
163
|
+
|
|
164
|
+
function WalletAddressComponent() {
|
|
165
|
+
const spokeProvider = useSpokeProvider(chainId, walletProvider);
|
|
166
|
+
|
|
167
|
+
// Derive user wallet address for hub abstraction
|
|
168
|
+
const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div>
|
|
172
|
+
{isLoading && <div>Deriving wallet address...</div>}
|
|
173
|
+
{error && <div>Error: {error.message}</div>}
|
|
174
|
+
{derivedAddress && <div>Derived Address: {derivedAddress}</div>}
|
|
175
|
+
</div>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
151
179
|
// Swap Operations
|
|
152
180
|
import { useQuote, useSwap, useStatus } from '@sodax/dapp-kit';
|
|
153
181
|
|
|
@@ -178,6 +206,53 @@ function SwapComponent() {
|
|
|
178
206
|
// Get status of an intent order
|
|
179
207
|
const { data: orderStatus } = useStatus('0x...');
|
|
180
208
|
}
|
|
209
|
+
|
|
210
|
+
// Bridge Operations
|
|
211
|
+
import { useBridge, useBridgeAllowance, useBridgeApprove, useGetBridgeableAmount, useGetBridgeableTokens } from '@sodax/dapp-kit';
|
|
212
|
+
|
|
213
|
+
function BridgeComponent() {
|
|
214
|
+
const spokeProvider = useSpokeProvider(chainId, walletProvider);
|
|
215
|
+
|
|
216
|
+
// Get available destination tokens for bridging
|
|
217
|
+
const { data: bridgeableTokens, isLoading: isTokensLoading } = useGetBridgeableTokens(
|
|
218
|
+
'0x2105.base', // from chain
|
|
219
|
+
'0x89.polygon', // to chain
|
|
220
|
+
'0x...' // source token address
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// Get maximum amount available to bridge
|
|
224
|
+
const { data: bridgeableAmount } = useGetBridgeableAmount(
|
|
225
|
+
{ address: '0x...', xChainId: '0x2105.base' }, // from token
|
|
226
|
+
{ address: '0x...', xChainId: '0x89.polygon' } // to token
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// Check token allowance for bridge
|
|
230
|
+
const { data: hasAllowed } = useBridgeAllowance(bridgeParams, spokeProvider);
|
|
231
|
+
|
|
232
|
+
// Approve tokens for bridge
|
|
233
|
+
const { approve: approveBridge, isLoading: isApproving } = useBridgeApprove(spokeProvider);
|
|
234
|
+
const handleApprove = async () => {
|
|
235
|
+
await approveBridge(bridgeParams);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// Execute bridge transaction
|
|
239
|
+
const { mutateAsync: bridge, isPending: isBridging } = useBridge(spokeProvider);
|
|
240
|
+
const handleBridge = async () => {
|
|
241
|
+
const result = await bridge({
|
|
242
|
+
srcChainId: '0x2105.base',
|
|
243
|
+
srcAsset: '0x...',
|
|
244
|
+
amount: 1000n,
|
|
245
|
+
dstChainId: '0x89.polygon',
|
|
246
|
+
dstAsset: '0x...',
|
|
247
|
+
recipient: '0x...'
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
console.log('Bridge transaction hashes:', {
|
|
251
|
+
spokeTxHash: result.value[0],
|
|
252
|
+
hubTxHash: result.value[1]
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
}
|
|
181
256
|
```
|
|
182
257
|
|
|
183
258
|
## Requirements
|
|
@@ -215,7 +290,14 @@ function SwapComponent() {
|
|
|
215
290
|
#### Shared Hooks
|
|
216
291
|
- [`useSodaxContext()`](./src/hooks/shared/useSodaxContext.ts) - Access Sodax context and configuration
|
|
217
292
|
- [`useEstimateGas()`](./src/hooks/shared/useEstimateGas.ts) - Estimate gas costs for transactions
|
|
218
|
-
|
|
293
|
+
- [`useDeriveUserWalletAddress()`](./src/hooks/shared/useDeriveUserWalletAddress.ts) - Derive user wallet address for hub abstraction
|
|
294
|
+
|
|
295
|
+
#### Bridge Hooks
|
|
296
|
+
- [`useBridge()`](./src/hooks/bridge/useBridge.ts) - Execute bridge transactions to transfer tokens between chains
|
|
297
|
+
- [`useBridgeAllowance()`](./src/hooks/bridge/useBridgeAllowance.ts) - Check token allowance for bridge operations
|
|
298
|
+
- [`useBridgeApprove()`](./src/hooks/bridge/useBridgeApprove.ts) - Approve token spending for bridge actions
|
|
299
|
+
- [`useGetBridgeableAmount()`](./src/hooks/bridge/useGetBridgeableAmount.ts) - Get maximum amount available to be bridged
|
|
300
|
+
- [`useGetBridgeableTokens()`](./src/hooks/bridge/useGetBridgeableTokens.ts) - Get available destination tokens for bridging
|
|
219
301
|
|
|
220
302
|
## Contributing
|
|
221
303
|
|
package/dist/contexts/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Sodax } from '@sodax/sdk';
|
|
2
2
|
import type { RpcConfig } from '@/types';
|
|
3
3
|
export interface SodaxContextType {
|
|
4
4
|
sodax: Sodax;
|
|
5
5
|
testnet: boolean;
|
|
6
|
-
hubProvider: EvmHubProvider | undefined;
|
|
7
6
|
rpcConfig: RpcConfig;
|
|
8
7
|
}
|
|
9
8
|
export declare const SodaxContext: import("react").Context<SodaxContextType | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,YAAY,kDAA+C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/bridge/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BridgeError, BridgeErrorCode, SpokeTxHash, HubTxHash, Result, CreateBridgeIntentParams } from '@sodax/sdk';
|
|
2
|
+
import { type UseMutationResult } from '@tanstack/react-query';
|
|
3
|
+
import type { SpokeProvider } from '@sodax/sdk';
|
|
4
|
+
/**
|
|
5
|
+
* Hook for executing bridge transactions to transfer tokens between chains.
|
|
6
|
+
* Uses React Query's useMutation for better state management and caching.
|
|
7
|
+
*
|
|
8
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for the bridge
|
|
9
|
+
* @returns {UseMutationResult} Mutation result object containing mutation function and state
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const { mutateAsync: bridge, isPending } = useBridge(spokeProvider);
|
|
14
|
+
*
|
|
15
|
+
* const handleBridge = async () => {
|
|
16
|
+
* const result = await bridge({
|
|
17
|
+
* srcChainId: '0x2105.base',
|
|
18
|
+
* srcAsset: '0x...',
|
|
19
|
+
* amount: 1000n,
|
|
20
|
+
* dstChainId: '0x89.polygon',
|
|
21
|
+
* dstAsset: '0x...',
|
|
22
|
+
* recipient: '0x...'
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* console.log('Bridge transaction hashes:', {
|
|
26
|
+
* spokeTxHash: result.spokeTxHash,
|
|
27
|
+
* hubTxHash: result.hubTxHash
|
|
28
|
+
* });
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function useBridge(spokeProvider: SpokeProvider | undefined): UseMutationResult<Result<[SpokeTxHash, HubTxHash], BridgeError<BridgeErrorCode>>, Error, CreateBridgeIntentParams>;
|
|
33
|
+
//# sourceMappingURL=useBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBridge.d.ts","sourceRoot":"","sources":["../../../src/hooks/bridge/useBridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACzH,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,SAAS,CACvB,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,iBAAiB,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAqBpH"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { SpokeProvider, CreateBridgeIntentParams } from '@sodax/sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for checking token allowance for bridge operations.
|
|
5
|
+
*
|
|
6
|
+
* This hook verifies if the user has approved enough tokens for a specific bridge action.
|
|
7
|
+
* It automatically queries and tracks the allowance status.
|
|
8
|
+
*
|
|
9
|
+
* @param {BridgeParams} params - The parameters for the bridge to check allowance for.
|
|
10
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for allowance checks
|
|
11
|
+
*
|
|
12
|
+
* @returns {UseQueryResult<boolean, Error>} A React Query result containing:
|
|
13
|
+
* - data: Boolean indicating if allowance is sufficient
|
|
14
|
+
* - isLoading: Loading state indicator
|
|
15
|
+
* - error: Any error that occurred during the check
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const { data: hasAllowed, isLoading } = useBridgeAllowance(params, spokeProvider);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function useBridgeAllowance(params: CreateBridgeIntentParams | undefined, spokeProvider: SpokeProvider | undefined): UseQueryResult<boolean, Error>;
|
|
23
|
+
//# sourceMappingURL=useBridgeAllowance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBridgeAllowance.d.ts","sourceRoot":"","sources":["../../../src/hooks/bridge/useBridgeAllowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,wBAAwB,GAAG,SAAS,EAC5C,aAAa,EAAE,aAAa,GAAG,SAAS,GACvC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAsBhC"}
|
|
@@ -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, type 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,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAG5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,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,116 @@ function useCancelSwap(spokeProvider) {
|
|
|
374
393
|
}
|
|
375
394
|
});
|
|
376
395
|
}
|
|
377
|
-
|
|
378
|
-
const sodax =
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
396
|
+
function useBridgeAllowance(params, spokeProvider) {
|
|
397
|
+
const { sodax } = useSodaxContext();
|
|
398
|
+
return reactQuery.useQuery({
|
|
399
|
+
queryKey: ["bridge-allowance", params],
|
|
400
|
+
queryFn: async () => {
|
|
401
|
+
if (!spokeProvider || !params) {
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
const allowance = await sodax.bridge.isAllowanceValid({
|
|
405
|
+
params,
|
|
406
|
+
spokeProvider
|
|
407
|
+
});
|
|
408
|
+
if (allowance.ok) {
|
|
409
|
+
return allowance.value;
|
|
410
|
+
}
|
|
411
|
+
return false;
|
|
412
|
+
},
|
|
413
|
+
enabled: !!spokeProvider && !!params
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function useBridgeApprove(spokeProvider) {
|
|
417
|
+
const { sodax } = useSodaxContext();
|
|
418
|
+
const queryClient = reactQuery.useQueryClient();
|
|
419
|
+
const {
|
|
420
|
+
mutateAsync: approve,
|
|
421
|
+
isPending,
|
|
422
|
+
error,
|
|
423
|
+
reset: resetError
|
|
424
|
+
} = reactQuery.useMutation({
|
|
425
|
+
mutationFn: async (params) => {
|
|
426
|
+
if (!spokeProvider) {
|
|
427
|
+
throw new Error("Spoke provider not found");
|
|
428
|
+
}
|
|
429
|
+
const allowance = await sodax.bridge.approve({
|
|
430
|
+
params,
|
|
431
|
+
spokeProvider
|
|
387
432
|
});
|
|
433
|
+
if (!allowance.ok) {
|
|
434
|
+
throw new Error("Failed to approve tokens for bridge");
|
|
435
|
+
}
|
|
436
|
+
return true;
|
|
437
|
+
},
|
|
438
|
+
onSuccess: (_, params) => {
|
|
439
|
+
queryClient.invalidateQueries({ queryKey: ["bridge-allowance", params] });
|
|
388
440
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
441
|
+
});
|
|
442
|
+
return {
|
|
443
|
+
approve,
|
|
444
|
+
isLoading: isPending,
|
|
445
|
+
error,
|
|
446
|
+
resetError
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
function useBridge(spokeProvider) {
|
|
450
|
+
const { sodax } = useSodaxContext();
|
|
451
|
+
return reactQuery.useMutation({
|
|
452
|
+
mutationFn: async (params) => {
|
|
453
|
+
if (!spokeProvider) {
|
|
454
|
+
throw new Error("Spoke provider not found");
|
|
455
|
+
}
|
|
456
|
+
const result = await sodax.bridge.bridge({
|
|
457
|
+
params,
|
|
458
|
+
spokeProvider
|
|
459
|
+
});
|
|
460
|
+
if (!result.ok) {
|
|
461
|
+
throw new Error(`Bridge failed: ${result.error.code}`);
|
|
462
|
+
}
|
|
463
|
+
return result;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
function useGetBridgeableAmount(from, to) {
|
|
468
|
+
const { sodax } = useSodaxContext();
|
|
469
|
+
return reactQuery.useQuery({
|
|
470
|
+
queryKey: ["spoke-asset-manager-token-balance", from, to],
|
|
471
|
+
queryFn: async () => {
|
|
472
|
+
if (!from || !to) {
|
|
473
|
+
return 0n;
|
|
474
|
+
}
|
|
475
|
+
const result = await sodax.bridge.getBridgeableAmount(from, to);
|
|
476
|
+
if (result.ok) {
|
|
477
|
+
return result.value;
|
|
478
|
+
}
|
|
479
|
+
console.error("Error getting bridgeable amount:", result.error);
|
|
480
|
+
return 0n;
|
|
481
|
+
},
|
|
482
|
+
enabled: !!from && !!to
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
function useGetBridgeableTokens(from, to, token) {
|
|
486
|
+
const { sodax } = useSodaxContext();
|
|
487
|
+
return reactQuery.useQuery({
|
|
488
|
+
queryKey: ["bridgeable-tokens", from, to, token],
|
|
489
|
+
queryFn: async () => {
|
|
490
|
+
if (!from || !to || !token) {
|
|
491
|
+
return [];
|
|
492
|
+
}
|
|
493
|
+
const result = sodax.bridge.getBridgeableTokens(from, to, token);
|
|
494
|
+
if (result.ok) {
|
|
495
|
+
return result.value;
|
|
496
|
+
}
|
|
497
|
+
console.error("Error getting bridgeable tokens:", result.error);
|
|
498
|
+
return [];
|
|
499
|
+
},
|
|
500
|
+
enabled: !!from && !!to && !!token
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
var SodaxProvider = ({ children, testnet = false, config, rpcConfig }) => {
|
|
504
|
+
const sodax = new sdk.Sodax(config);
|
|
505
|
+
return /* @__PURE__ */ React__default.default.createElement(SodaxContext.Provider, { value: { sodax, testnet, rpcConfig } }, children);
|
|
392
506
|
};
|
|
393
507
|
var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
394
508
|
const tokens = sdk.hubAssets[spokeChainId];
|
|
@@ -401,8 +515,14 @@ var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
|
|
|
401
515
|
exports.SodaxProvider = SodaxProvider;
|
|
402
516
|
exports.getSpokeTokenAddressByVault = getSpokeTokenAddressByVault;
|
|
403
517
|
exports.useBorrow = useBorrow;
|
|
518
|
+
exports.useBridge = useBridge;
|
|
519
|
+
exports.useBridgeAllowance = useBridgeAllowance;
|
|
520
|
+
exports.useBridgeApprove = useBridgeApprove;
|
|
404
521
|
exports.useCancelSwap = useCancelSwap;
|
|
522
|
+
exports.useDeriveUserWalletAddress = useDeriveUserWalletAddress;
|
|
405
523
|
exports.useEstimateGas = useEstimateGas;
|
|
524
|
+
exports.useGetBridgeableAmount = useGetBridgeableAmount;
|
|
525
|
+
exports.useGetBridgeableTokens = useGetBridgeableTokens;
|
|
406
526
|
exports.useHubProvider = useHubProvider;
|
|
407
527
|
exports.useMMAllowance = useMMAllowance;
|
|
408
528
|
exports.useMMApprove = useMMApprove;
|