@sodax/dapp-kit 2.1.0-rc.1 → 2.1.0-rc.2
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/index.d.ts +189 -3
- package/dist/index.mjs +169 -3
- package/package.json +2 -2
- package/src/hooks/_mutationContract.test.ts +3 -0
- package/src/hooks/bridgeApi/index.ts +13 -0
- package/src/hooks/bridgeApi/useBridgeApiAllowance.ts +42 -0
- package/src/hooks/bridgeApi/useBridgeApiApprove.ts +42 -0
- package/src/hooks/bridgeApi/useBridgeApiBridgeableAmount.ts +45 -0
- package/src/hooks/bridgeApi/useBridgeApiCreateBridgeIntent.ts +42 -0
- package/src/hooks/bridgeApi/useBridgeApiFee.ts +44 -0
- package/src/hooks/bridgeApi/useBridgeApiIsBridgeable.ts +45 -0
- package/src/hooks/bridgeApi/useBridgeApiSubmitTx.ts +50 -0
- package/src/hooks/bridgeApi/useBridgeApiSubmitTxStatus.ts +60 -0
- package/src/hooks/bridgeApi/useBridgeApiTokens.ts +35 -0
- package/src/hooks/bridgeApi/useBridgeApiTokensByChain.ts +40 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseMutationOptions, UseQueryOptions, UseMutationResult, MutateOptions, UseQueryResult, QueryClientConfig, QueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { Result, Sodax, SpokeChainKey, GetEstimateGasReturnType, EstimateGasParams, StellarChainKey, IStellarWalletProvider, INearWalletProvider, GetWalletProviderType, StellarAccountStatus, ActivateStellarAccountResult, IXServiceBase, XToken, EvmHubProvider, IBitcoinWalletProvider, RadfiWalletBalance, IWalletProvider, RadfiUtxo, MoneyMarketBorrowActionParams, TxHashPair, MoneyMarketRepayActionParams, MoneyMarketSupplyActionParams, MoneyMarketWithdrawActionParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, ReservesDataHumanized, Address as Address$1, MoneyMarketParams, MoneyMarketApproveActionParams, TxReturnType, Erc20Token, ChainKey, ReserveDataHumanized, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteResponse, SolverErrorResponse, SolverIntentQuoteRequest, SwapActionParams, SwapResponse, SolverIntentStatusResponse, Hex, CreateIntentParams, CreateLimitOrderParams, Intent, LimitOrderActionParams, IntentResponse, UserIntentsResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, GetSwapTokensResponseV2, RequestOverrideConfig, GetSwapTokensByChainResponseV2, QuoteResponseV2, QuoteRequestV2, QuoteQueryV2, DeadlineResponseV2, DeadlineQueryV2, AllowanceCheckResponseV2, CreateIntentParamsV2, ApproveResponseV2, CreateIntentResponseV2, SubmitIntentRequestV2, SubmitIntentResponseV2, StatusResponseV2, SwapIntentStatusCodeV2, CancelIntentRequestV2, CancelIntentResponseV2, IntentHashResponseV2, IntentRequestV2, IntentPacketResponseV2, IntentPacketRequestV2, IntentExtraDataResponseV2, IntentExtraDataRequestV2, IntentStateV2, GetIntentResponseV2, CreateLimitOrderParamsV2, CreateLimitOrderResponseV2, GasEstimateResponseV2, GasEstimateRequestV2, FeeResponseV2, SubmitTxRequestV2, SubmitTxResponseV2, SubmitTxStatusResponseV2, BridgeParams, CreateBridgeIntentParams, BridgeLimit, StakeAction, StakeParams, UnstakeAction, ClaimAction, CancelUnstakeAction, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeAction, UnstakeParams, InstantUnstakeParams, PartnerFeeClaimAssetBalance, AutoSwapPreferences, FeeTokenApproveParams, FeeTokenApproveAction, HubChainKey, SetSwapPreferenceAction, PartnerFeeClaimSwapAction, IntentAutoSwapResult, PartnerFeeClaimCancelAction, GetUserIntentParams, HubAssetBalance, WithdrawHubAssetAction, IcxMigrateAction, IcxRevertMigrationAction, UnifiedBnUSDMigrateAction, BalnMigrateAction, MigrationAction, IcxMigrateParams, IcxCreateRevertMigrationParams, UnifiedBnUSDMigrateParams, BalnMigrateParams, PoolKey, PoolData, ClPositionInfo, AssetDepositAction, AssetWithdrawAction, CreateAssetDepositParams, ClSupplyParams, ClIncreaseLiquidityParams, ClLiquidityDecreaseLiquidityAction, ClDecreaseLiquidityParams, CreateAssetWithdrawParams, PoolSpokeAssets, DestinationParamsType, ClLiquidityClaimRewardsAction, LeverageYieldEffectiveApr, LeverageYieldPosition, LeverageYieldSwapDepositParams, LeverageYieldSwapPayload, SolverExecutionRequest, SolverExecutionResponse, VaultSwapActionParams, VaultSwapResponse, LeverageYieldSwapWithdrawParams, ActivateStellarAccountParams, StellarSponsorConfig, SodaxOptions } from '@sodax/sdk';
|
|
2
|
+
import { Result, Sodax, SpokeChainKey, GetEstimateGasReturnType, EstimateGasParams, StellarChainKey, IStellarWalletProvider, INearWalletProvider, GetWalletProviderType, StellarAccountStatus, ActivateStellarAccountResult, IXServiceBase, XToken, EvmHubProvider, IBitcoinWalletProvider, RadfiWalletBalance, IWalletProvider, RadfiUtxo, MoneyMarketBorrowActionParams, TxHashPair, MoneyMarketRepayActionParams, MoneyMarketSupplyActionParams, MoneyMarketWithdrawActionParams, UserReserveData, AggregatedReserveData, BaseCurrencyInfo, ReservesDataHumanized, Address as Address$1, MoneyMarketParams, MoneyMarketApproveActionParams, TxReturnType, Erc20Token, ChainKey, ReserveDataHumanized, FormatReserveUSDResponse, FormatUserSummaryResponse, SolverIntentQuoteResponse, SolverErrorResponse, SolverIntentQuoteRequest, SwapActionParams, SwapResponse, SolverIntentStatusResponse, Hex, CreateIntentParams, CreateLimitOrderParams, Intent, LimitOrderActionParams, IntentResponse, UserIntentsResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, GetSwapTokensResponseV2, RequestOverrideConfig, GetSwapTokensByChainResponseV2, QuoteResponseV2, QuoteRequestV2, QuoteQueryV2, DeadlineResponseV2, DeadlineQueryV2, AllowanceCheckResponseV2, CreateIntentParamsV2, ApproveResponseV2, CreateIntentResponseV2, SubmitIntentRequestV2, SubmitIntentResponseV2, StatusResponseV2, SwapIntentStatusCodeV2, CancelIntentRequestV2, CancelIntentResponseV2, IntentHashResponseV2, IntentRequestV2, IntentPacketResponseV2, IntentPacketRequestV2, IntentExtraDataResponseV2, IntentExtraDataRequestV2, IntentStateV2, GetIntentResponseV2, CreateLimitOrderParamsV2, CreateLimitOrderResponseV2, GasEstimateResponseV2, GasEstimateRequestV2, FeeResponseV2, SubmitTxRequestV2, SubmitTxResponseV2, SubmitTxStatusResponseV2, BridgeParams, CreateBridgeIntentParams, BridgeLimit, BridgeAllowanceCheckResponseV2, CreateBridgeIntentParamsV2, BridgeApproveResponseV2, BridgeableAmountResponseV2, BridgeQuoteRequestV2, CreateBridgeIntentResponseV2, BridgeFeeResponseV2, BridgeFeeRequestV2, BridgeableCheckResponseV2, BridgeSubmitTxRequestV2, BridgeSubmitTxResponseV2, BridgeSubmitTxStatusResponseV2, GetBridgeTokensResponseV2, GetBridgeTokensByChainResponseV2, StakeAction, StakeParams, UnstakeAction, ClaimAction, CancelUnstakeAction, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeAction, UnstakeParams, InstantUnstakeParams, PartnerFeeClaimAssetBalance, AutoSwapPreferences, FeeTokenApproveParams, FeeTokenApproveAction, HubChainKey, SetSwapPreferenceAction, PartnerFeeClaimSwapAction, IntentAutoSwapResult, PartnerFeeClaimCancelAction, GetUserIntentParams, HubAssetBalance, WithdrawHubAssetAction, IcxMigrateAction, IcxRevertMigrationAction, UnifiedBnUSDMigrateAction, BalnMigrateAction, MigrationAction, IcxMigrateParams, IcxCreateRevertMigrationParams, UnifiedBnUSDMigrateParams, BalnMigrateParams, PoolKey, PoolData, ClPositionInfo, AssetDepositAction, AssetWithdrawAction, CreateAssetDepositParams, ClSupplyParams, ClIncreaseLiquidityParams, ClLiquidityDecreaseLiquidityAction, ClDecreaseLiquidityParams, CreateAssetWithdrawParams, PoolSpokeAssets, DestinationParamsType, ClLiquidityClaimRewardsAction, LeverageYieldEffectiveApr, LeverageYieldPosition, LeverageYieldSwapDepositParams, LeverageYieldSwapPayload, SolverExecutionRequest, SolverExecutionResponse, VaultSwapActionParams, VaultSwapResponse, LeverageYieldSwapWithdrawParams, ActivateStellarAccountParams, StellarSponsorConfig, SodaxOptions } from '@sodax/sdk';
|
|
3
3
|
export * from '@sodax/sdk';
|
|
4
4
|
import { Address } from 'viem';
|
|
5
5
|
import { ReactNode, ReactElement } from 'react';
|
|
@@ -1319,7 +1319,8 @@ type UseSwapsApiSubmitTxStatusParams = ReadHookParams<SubmitTxStatusResponseV2 |
|
|
|
1319
1319
|
* });
|
|
1320
1320
|
*
|
|
1321
1321
|
* @remarks
|
|
1322
|
-
* - Default refetch interval is 1 second; stops on 'solved' or 'failed' status
|
|
1322
|
+
* - Default refetch interval is 1 second; stops on 'solved' or 'failed' status, or when the
|
|
1323
|
+
* backend marks the submission abandoned (`abandonedAt`) while `status` stays non-terminal.
|
|
1323
1324
|
*/
|
|
1324
1325
|
declare const useSwapsApiSubmitTxStatus: ({ params, queryOptions, }?: UseSwapsApiSubmitTxStatusParams) => UseQueryResult<SubmitTxStatusResponseV2 | undefined, Error>;
|
|
1325
1326
|
|
|
@@ -1372,6 +1373,191 @@ type UseGetBridgeableTokensParams = ReadHookParams<XToken[], {
|
|
|
1372
1373
|
}>;
|
|
1373
1374
|
declare function useGetBridgeableTokens({ params, queryOptions, }?: UseGetBridgeableTokensParams): UseQueryResult<XToken[], Error>;
|
|
1374
1375
|
|
|
1376
|
+
type UseBridgeApiAllowanceParams = ReadHookParams<BridgeAllowanceCheckResponseV2 | undefined, {
|
|
1377
|
+
body: CreateBridgeIntentParamsV2 | undefined;
|
|
1378
|
+
apiConfig?: RequestOverrideConfig;
|
|
1379
|
+
}>;
|
|
1380
|
+
/**
|
|
1381
|
+
* React hook to check whether the source-token allowance is already sufficient for a bridge via
|
|
1382
|
+
* the bridge API — `sodax.api.bridge.checkAllowance`. Returns `{ valid }`.
|
|
1383
|
+
*
|
|
1384
|
+
* The `body` uses the wire DTO field names (`inputToken`/`inputAmount`).
|
|
1385
|
+
*
|
|
1386
|
+
* @example
|
|
1387
|
+
* const { data: allowance } = useBridgeApiAllowance({ params: { body: createBridgeIntentParams } });
|
|
1388
|
+
*/
|
|
1389
|
+
declare const useBridgeApiAllowance: ({ params, queryOptions, }?: UseBridgeApiAllowanceParams) => UseQueryResult<BridgeAllowanceCheckResponseV2 | undefined, Error>;
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Mutation variables for {@link useBridgeApiApprove}. The per-request `apiConfig` override belongs
|
|
1393
|
+
* here rather than at the hook level — different calls in the same component can target different
|
|
1394
|
+
* endpoints without re-rendering.
|
|
1395
|
+
*/
|
|
1396
|
+
type UseBridgeApiApproveVars = {
|
|
1397
|
+
body: CreateBridgeIntentParamsV2;
|
|
1398
|
+
apiConfig?: RequestOverrideConfig;
|
|
1399
|
+
};
|
|
1400
|
+
/**
|
|
1401
|
+
* React hook to build an unsigned token-approval transaction for the source token via the bridge
|
|
1402
|
+
* API — `sodax.api.bridge.approve`. Returns `{ tx }` (chain-specific unsigned tx) to sign and
|
|
1403
|
+
* broadcast yourself; it does not change state, so no queries are invalidated.
|
|
1404
|
+
*
|
|
1405
|
+
* @example
|
|
1406
|
+
* const { mutateAsync: approve } = useBridgeApiApprove();
|
|
1407
|
+
* const { tx } = await approve({ body: createBridgeIntentParams });
|
|
1408
|
+
*/
|
|
1409
|
+
declare const useBridgeApiApprove: ({ mutationOptions, }?: MutationHookParams<BridgeApproveResponseV2, UseBridgeApiApproveVars>) => SafeUseMutationResult<BridgeApproveResponseV2, Error, UseBridgeApiApproveVars>;
|
|
1410
|
+
|
|
1411
|
+
type UseBridgeApiBridgeableAmountParams = ReadHookParams<BridgeableAmountResponseV2 | undefined, {
|
|
1412
|
+
body: BridgeQuoteRequestV2 | undefined;
|
|
1413
|
+
apiConfig?: RequestOverrideConfig;
|
|
1414
|
+
}>;
|
|
1415
|
+
/**
|
|
1416
|
+
* React hook to fetch the deposit capacity / withdrawal liquidity limit for a (from, to) token pair
|
|
1417
|
+
* via the bridge API — `sodax.api.bridge.getBridgeableAmount`. Returns `{ limit }`.
|
|
1418
|
+
*
|
|
1419
|
+
* Computable client-side from config + vault reserves — prefer `sodax.bridge.getBridgeableAmount`
|
|
1420
|
+
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/bridgeable-amount` endpoint.
|
|
1421
|
+
*
|
|
1422
|
+
* The `body` uses the wire DTO field names (`srcChainKey`/`dstChainKey`/`inputToken`/`outputToken`).
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* const { data } = useBridgeApiBridgeableAmount({ params: { body: quote } });
|
|
1426
|
+
*/
|
|
1427
|
+
declare const useBridgeApiBridgeableAmount: ({ params, queryOptions, }?: UseBridgeApiBridgeableAmountParams) => UseQueryResult<BridgeableAmountResponseV2 | undefined, Error>;
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* Mutation variables for {@link useBridgeApiCreateBridgeIntent}. The per-request `apiConfig`
|
|
1431
|
+
* override belongs here rather than at the hook level.
|
|
1432
|
+
*/
|
|
1433
|
+
type UseBridgeApiCreateBridgeIntentVars = {
|
|
1434
|
+
body: CreateBridgeIntentParamsV2;
|
|
1435
|
+
apiConfig?: RequestOverrideConfig;
|
|
1436
|
+
};
|
|
1437
|
+
/**
|
|
1438
|
+
* React hook to build an unsigned spoke-deposit (create-bridge-intent) transaction via the bridge
|
|
1439
|
+
* API — `sodax.api.bridge.createBridgeIntent`. Returns `{ tx, relayData }` (no `intent` struct —
|
|
1440
|
+
* bridge is vault-backed) to sign and broadcast yourself; it does not change state, so no queries
|
|
1441
|
+
* are invalidated.
|
|
1442
|
+
*
|
|
1443
|
+
* @example
|
|
1444
|
+
* const { mutateAsync: createBridgeIntent } = useBridgeApiCreateBridgeIntent();
|
|
1445
|
+
* const { tx, relayData } = await createBridgeIntent({ body: createBridgeIntentParams });
|
|
1446
|
+
*/
|
|
1447
|
+
declare const useBridgeApiCreateBridgeIntent: ({ mutationOptions, }?: MutationHookParams<CreateBridgeIntentResponseV2, UseBridgeApiCreateBridgeIntentVars>) => SafeUseMutationResult<CreateBridgeIntentResponseV2, Error, UseBridgeApiCreateBridgeIntentVars>;
|
|
1448
|
+
|
|
1449
|
+
type UseBridgeApiFeeParams = ReadHookParams<BridgeFeeResponseV2 | undefined, {
|
|
1450
|
+
body: BridgeFeeRequestV2 | undefined;
|
|
1451
|
+
apiConfig?: RequestOverrideConfig;
|
|
1452
|
+
}>;
|
|
1453
|
+
/**
|
|
1454
|
+
* React hook to fetch the bridge partner fee for an input amount via the bridge API (uses a per-request
|
|
1455
|
+
* `body.partnerFee` override when supplied, else the backend-configured fee) —
|
|
1456
|
+
* `sodax.api.bridge.getFee`. Returns `{ fee }` (smallest unit, decimal string).
|
|
1457
|
+
*
|
|
1458
|
+
* The fee is computable client-side (config-driven, token-independent) — prefer `sodax.bridge.getFee`
|
|
1459
|
+
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/fee` endpoint for parity.
|
|
1460
|
+
*
|
|
1461
|
+
* @example
|
|
1462
|
+
* const { data: fee } = useBridgeApiFee({ params: { body: { inputAmount } } });
|
|
1463
|
+
*/
|
|
1464
|
+
declare const useBridgeApiFee: ({ params, queryOptions, }?: UseBridgeApiFeeParams) => UseQueryResult<BridgeFeeResponseV2 | undefined, Error>;
|
|
1465
|
+
|
|
1466
|
+
type UseBridgeApiIsBridgeableParams = ReadHookParams<BridgeableCheckResponseV2 | undefined, {
|
|
1467
|
+
body: BridgeQuoteRequestV2 | undefined;
|
|
1468
|
+
apiConfig?: RequestOverrideConfig;
|
|
1469
|
+
}>;
|
|
1470
|
+
/**
|
|
1471
|
+
* React hook to check whether a (from, to) token pair is bridgeable via the bridge API —
|
|
1472
|
+
* `sodax.api.bridge.isBridgeable`. Returns `{ bridgeable }`.
|
|
1473
|
+
*
|
|
1474
|
+
* Computable client-side from config + vault reserves — prefer `sodax.bridge.isBridgeable`
|
|
1475
|
+
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/bridgeable/check` endpoint.
|
|
1476
|
+
*
|
|
1477
|
+
* The `body` uses the wire DTO field names (`srcChainKey`/`dstChainKey`/`inputToken`/`outputToken`).
|
|
1478
|
+
*
|
|
1479
|
+
* @example
|
|
1480
|
+
* const { data } = useBridgeApiIsBridgeable({ params: { body: quote } });
|
|
1481
|
+
*/
|
|
1482
|
+
declare const useBridgeApiIsBridgeable: ({ params, queryOptions, }?: UseBridgeApiIsBridgeableParams) => UseQueryResult<BridgeableCheckResponseV2 | undefined, Error>;
|
|
1483
|
+
|
|
1484
|
+
/**
|
|
1485
|
+
* Mutation variables for {@link useBridgeApiSubmitTx}. The per-request `apiConfig` override
|
|
1486
|
+
* (e.g. base URL) belongs here rather than at the hook level — different submissions in the same
|
|
1487
|
+
* component can target different endpoints without re-rendering.
|
|
1488
|
+
*/
|
|
1489
|
+
type UseBridgeApiSubmitTxVars = {
|
|
1490
|
+
request: BridgeSubmitTxRequestV2;
|
|
1491
|
+
apiConfig?: RequestOverrideConfig;
|
|
1492
|
+
};
|
|
1493
|
+
/**
|
|
1494
|
+
* React hook for submitting a broadcast bridge (spoke-deposit) transaction to be processed
|
|
1495
|
+
* (relayed server-side) via the bridge API — `sodax.api.bridge.submitTx`. Called AFTER signing +
|
|
1496
|
+
* broadcasting the spoke-deposit tx, handing it (with the FULL `relayData { address, payload }`
|
|
1497
|
+
* envelope) to the backend.
|
|
1498
|
+
*
|
|
1499
|
+
* Pure mutation: pass `{ request, apiConfig? }` to `mutate({...})`. Default `retry: 3` is applied
|
|
1500
|
+
* at the hook level — consumers can override via `mutationOptions.retry`.
|
|
1501
|
+
*
|
|
1502
|
+
* @example
|
|
1503
|
+
* const { mutateAsync: submitBridgeTx, isPending, error } = useBridgeApiSubmitTx();
|
|
1504
|
+
*
|
|
1505
|
+
* const result = await submitBridgeTx({
|
|
1506
|
+
* request: { txHash: '0x123...', srcChainKey: '0xa4b1.arbitrum', walletAddress: '0xabc...', relayData: { address: '0x...', payload: '0x...' } },
|
|
1507
|
+
* apiConfig: { baseURL: 'https://...' },
|
|
1508
|
+
* });
|
|
1509
|
+
*/
|
|
1510
|
+
declare const useBridgeApiSubmitTx: ({ mutationOptions, }?: MutationHookParams<BridgeSubmitTxResponseV2, UseBridgeApiSubmitTxVars>) => SafeUseMutationResult<BridgeSubmitTxResponseV2, Error, UseBridgeApiSubmitTxVars>;
|
|
1511
|
+
|
|
1512
|
+
type UseBridgeApiSubmitTxStatusParams = ReadHookParams<BridgeSubmitTxStatusResponseV2 | undefined, {
|
|
1513
|
+
txHash: string | undefined;
|
|
1514
|
+
srcChainKey?: string;
|
|
1515
|
+
apiConfig?: RequestOverrideConfig;
|
|
1516
|
+
}>;
|
|
1517
|
+
/**
|
|
1518
|
+
* React hook for polling the processing status of a submitted bridge transaction via the bridge
|
|
1519
|
+
* API — `sodax.api.bridge.getSubmitTxStatus`. Both `txHash` and `srcChainKey` are required for the
|
|
1520
|
+
* query to run.
|
|
1521
|
+
*
|
|
1522
|
+
* @example
|
|
1523
|
+
* const { data: status } = useBridgeApiSubmitTxStatus({
|
|
1524
|
+
* params: { txHash: '0x123...', srcChainKey: '0xa4b1.arbitrum' },
|
|
1525
|
+
* });
|
|
1526
|
+
*
|
|
1527
|
+
* @remarks
|
|
1528
|
+
* - Default refetch interval is 1 second; stops on 'executed' or 'failed' status, or when the
|
|
1529
|
+
* backend marks the submission abandoned (`abandonedAt`) while `status` stays non-terminal —
|
|
1530
|
+
* mirroring the SDK's backend submit-tx poll (no solver `posting_execution` state — bridge has
|
|
1531
|
+
* no post-execution).
|
|
1532
|
+
*/
|
|
1533
|
+
declare const useBridgeApiSubmitTxStatus: ({ params, queryOptions, }?: UseBridgeApiSubmitTxStatusParams) => UseQueryResult<BridgeSubmitTxStatusResponseV2 | undefined, Error>;
|
|
1534
|
+
|
|
1535
|
+
type UseBridgeApiTokensParams = ReadHookParams<GetBridgeTokensResponseV2, {
|
|
1536
|
+
apiConfig?: RequestOverrideConfig;
|
|
1537
|
+
}>;
|
|
1538
|
+
/**
|
|
1539
|
+
* React hook to fetch all supported bridge tokens grouped by SpokeChainKey via the bridge API —
|
|
1540
|
+
* `sodax.api.bridge.getTokens`. The token list is backend-served; the bridgeable-amount quote is
|
|
1541
|
+
* computable client-side via `useGetBridgeableAmount` (also mirrored by `useBridgeApiBridgeableAmount`).
|
|
1542
|
+
*
|
|
1543
|
+
* @example
|
|
1544
|
+
* const { data: tokensByChain } = useBridgeApiTokens();
|
|
1545
|
+
*/
|
|
1546
|
+
declare const useBridgeApiTokens: ({ params, queryOptions, }?: UseBridgeApiTokensParams) => UseQueryResult<GetBridgeTokensResponseV2, Error>;
|
|
1547
|
+
|
|
1548
|
+
type UseBridgeApiTokensByChainParams = ReadHookParams<GetBridgeTokensByChainResponseV2 | undefined, {
|
|
1549
|
+
chainKey: string | undefined;
|
|
1550
|
+
apiConfig?: RequestOverrideConfig;
|
|
1551
|
+
}>;
|
|
1552
|
+
/**
|
|
1553
|
+
* React hook to fetch supported bridge tokens for a single SpokeChainKey via the bridge API —
|
|
1554
|
+
* `sodax.api.bridge.getTokensByChain`. Use `useBridgeApiTokens` for every chain at once.
|
|
1555
|
+
*
|
|
1556
|
+
* @example
|
|
1557
|
+
* const { data: tokens } = useBridgeApiTokensByChain({ params: { chainKey: '0xa4b1.arbitrum' } });
|
|
1558
|
+
*/
|
|
1559
|
+
declare const useBridgeApiTokensByChain: ({ params, queryOptions, }?: UseBridgeApiTokensByChainParams) => UseQueryResult<GetBridgeTokensByChainResponseV2 | undefined, Error>;
|
|
1560
|
+
|
|
1375
1561
|
/**
|
|
1376
1562
|
* Mutation variables for {@link useStake}. Generic over `K extends SpokeChainKey` (defaults to
|
|
1377
1563
|
* the full union). Sophisticated callers can lock K at the hook call site to narrow the
|
|
@@ -2430,4 +2616,4 @@ interface NearStorageGateState {
|
|
|
2430
2616
|
*/
|
|
2431
2617
|
declare function resolveNearStorageGate(chainKey: SpokeChainKey, check: NearStorageCheckResult): NearStorageGateState;
|
|
2432
2618
|
|
|
2433
|
-
export { type ATokenData, type BackendPaginationParams, type BitcoinTradingSetup, type CreateSodaxQueryClientOptions, type DecreaseLiquidityParamsCore, type DepositParamsCore, type LeverageYieldShareHolder, type LeverageYieldShareHolding, type MutationHookOptions, type MutationHookParams, type NearStorageCheckResult, type NearStorageGateState, type RadfiSession, type ReadHookParams, type ReadQueryOptions, type ReserveUsdFormat, type SafeUseMutationResult, SodaxProvider, type StellarCheckResult, type StellarGate, type StellarGateInputs, type StellarGateState, type UseATokenParams, type UseATokensBalancesParams, type UseActivateStellarAccountVars, type UseApproveTokenVars, type UseBitcoinBalanceParams, type UseBitcoinTradingSetupParams, type UseBorrowVars, type UseBridgeAllowanceParams, type UseBridgeApproveVars, type UseBridgeVars, type UseClaimRewardsVars, type UseCreateDecreaseLiquidityParamsProps, type UseCreateDepositParamsProps, type UseCreateLimitOrderVars, type UseCreateSupplyLiquidityParamsProps, type UseCreateSupplyLiquidityParamsResult, type UseCreateWithdrawParamsProps, type UseDecreaseLiquidityVars, type UseDeriveUserWalletAddressParams, type UseDexAllowanceParams, type UseDexApproveVars, type UseDexDepositVars, type UseDexWithdrawVars, type UseEnsureRadfiAccessTokenVars, type UseEstablishTrustlineVars, type UseExpiredUtxosParams, type UseFeeClaimSwapVars, type UseFeeClaimWithdrawVars, type UseFetchAssetsBalancesParams, type UseFundTradingWalletVars, type UseGetAutoSwapPreferencesParams, type UseGetBridgeableAmountParams, type UseGetBridgeableTokensParams, type UseGetIntentDetailsParams, type UseGetUserHubWalletAddressParams, type UseGetUserIntentParams, type UseHubAssetBalancesParams, type UseIsTokenApprovedParams, type UseLeverageYieldDepositVars, type UseLeverageYieldEffectiveAprParams, type UseLeverageYieldNotifySolverVars, type UseLeverageYieldPositionParams, type UseLeverageYieldPreviewRedeemParams, type UseLeverageYieldShareBalancesParams, type UseLeverageYieldTotalAssetsParams, type UseLeverageYieldVaultSwapVars, type UseLeverageYieldWithdrawVars, type UseLiquidityAmountsResult, type UseMMAllowanceParams, type UseMMApproveVars, type UseMigrateBalnVars, type UseMigrateIcxToSodaVars, type UseMigratebnUSDVars, type UseMigrationAllowanceInputs, type UseMigrationAllowanceParams, type UseMigrationApproveVars, type UseNearStorageCheckParams, type UsePartnerCancelIntentVars, type UsePoolBalancesParams, type UsePoolBalancesResponse, type UsePoolDataParams, type UsePoolsParams, type UsePositionInfoParams, type UsePositionInfoResponse, type UseQuoteParams, type UseRadfiAuthVars, type UseRadfiSessionReturn, type UseRadfiWithdrawVars, type UseRegisterNearStorageVars, type UseRenewUtxosVars, type UseRepayVars, type UseReservesDataParams, type UseReservesHumanizedParams, type UseReservesListParams, type UseReservesUsdFormatParams, type UseRevertMigrateSodaToIcxVars, type UseSetSwapPreferenceVars, type UseSetSwapPreferenceVarsHub, type UseSponsorConfigParams, type UseStatusParams, type UseStellarAccountActiveParams, type UseStellarAccountStatusParams, type UseStellarGateParams, type UseStellarTrustlineCheckParams, type UseSupplyLiquidityVars, type UseSupplyVars, type UseSwapAllowanceParams, type UseSwapApproveVars, type UseSwapVars, type UseSwapsApiAllowanceParams, type UseSwapsApiApproveVars, type UseSwapsApiCancelIntentVars, type UseSwapsApiCreateIntentVars, type UseSwapsApiCreateLimitOrderVars, type UseSwapsApiDeadlineParams, type UseSwapsApiEstimateGasParams, type UseSwapsApiFilledIntentParams, type UseSwapsApiIntentExtraDataParams, type UseSwapsApiIntentHashParams, type UseSwapsApiIntentPacketParams, type UseSwapsApiIntentParams, type UseSwapsApiPartnerFeeParams, type UseSwapsApiQuoteParams, type UseSwapsApiSolverFeeParams, type UseSwapsApiStatusParams, type UseSwapsApiSubmitIntentVars, type UseSwapsApiSubmitTxStatusParams, type UseSwapsApiSubmitTxVars, type UseSwapsApiTokensByChainParams, type UseSwapsApiTokensParams, type UseTradingWalletBalanceParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawHubAssetVars, type UseWithdrawVars, type UseXBalancesParams, type WithdrawParamsCore, type XBalancesInputs, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
|
2619
|
+
export { type ATokenData, type BackendPaginationParams, type BitcoinTradingSetup, type CreateSodaxQueryClientOptions, type DecreaseLiquidityParamsCore, type DepositParamsCore, type LeverageYieldShareHolder, type LeverageYieldShareHolding, type MutationHookOptions, type MutationHookParams, type NearStorageCheckResult, type NearStorageGateState, type RadfiSession, type ReadHookParams, type ReadQueryOptions, type ReserveUsdFormat, type SafeUseMutationResult, SodaxProvider, type StellarCheckResult, type StellarGate, type StellarGateInputs, type StellarGateState, type UseATokenParams, type UseATokensBalancesParams, type UseActivateStellarAccountVars, type UseApproveTokenVars, type UseBitcoinBalanceParams, type UseBitcoinTradingSetupParams, type UseBorrowVars, type UseBridgeAllowanceParams, type UseBridgeApiAllowanceParams, type UseBridgeApiApproveVars, type UseBridgeApiBridgeableAmountParams, type UseBridgeApiCreateBridgeIntentVars, type UseBridgeApiFeeParams, type UseBridgeApiIsBridgeableParams, type UseBridgeApiSubmitTxStatusParams, type UseBridgeApiSubmitTxVars, type UseBridgeApiTokensByChainParams, type UseBridgeApiTokensParams, type UseBridgeApproveVars, type UseBridgeVars, type UseClaimRewardsVars, type UseCreateDecreaseLiquidityParamsProps, type UseCreateDepositParamsProps, type UseCreateLimitOrderVars, type UseCreateSupplyLiquidityParamsProps, type UseCreateSupplyLiquidityParamsResult, type UseCreateWithdrawParamsProps, type UseDecreaseLiquidityVars, type UseDeriveUserWalletAddressParams, type UseDexAllowanceParams, type UseDexApproveVars, type UseDexDepositVars, type UseDexWithdrawVars, type UseEnsureRadfiAccessTokenVars, type UseEstablishTrustlineVars, type UseExpiredUtxosParams, type UseFeeClaimSwapVars, type UseFeeClaimWithdrawVars, type UseFetchAssetsBalancesParams, type UseFundTradingWalletVars, type UseGetAutoSwapPreferencesParams, type UseGetBridgeableAmountParams, type UseGetBridgeableTokensParams, type UseGetIntentDetailsParams, type UseGetUserHubWalletAddressParams, type UseGetUserIntentParams, type UseHubAssetBalancesParams, type UseIsTokenApprovedParams, type UseLeverageYieldDepositVars, type UseLeverageYieldEffectiveAprParams, type UseLeverageYieldNotifySolverVars, type UseLeverageYieldPositionParams, type UseLeverageYieldPreviewRedeemParams, type UseLeverageYieldShareBalancesParams, type UseLeverageYieldTotalAssetsParams, type UseLeverageYieldVaultSwapVars, type UseLeverageYieldWithdrawVars, type UseLiquidityAmountsResult, type UseMMAllowanceParams, type UseMMApproveVars, type UseMigrateBalnVars, type UseMigrateIcxToSodaVars, type UseMigratebnUSDVars, type UseMigrationAllowanceInputs, type UseMigrationAllowanceParams, type UseMigrationApproveVars, type UseNearStorageCheckParams, type UsePartnerCancelIntentVars, type UsePoolBalancesParams, type UsePoolBalancesResponse, type UsePoolDataParams, type UsePoolsParams, type UsePositionInfoParams, type UsePositionInfoResponse, type UseQuoteParams, type UseRadfiAuthVars, type UseRadfiSessionReturn, type UseRadfiWithdrawVars, type UseRegisterNearStorageVars, type UseRenewUtxosVars, type UseRepayVars, type UseReservesDataParams, type UseReservesHumanizedParams, type UseReservesListParams, type UseReservesUsdFormatParams, type UseRevertMigrateSodaToIcxVars, type UseSetSwapPreferenceVars, type UseSetSwapPreferenceVarsHub, type UseSponsorConfigParams, type UseStatusParams, type UseStellarAccountActiveParams, type UseStellarAccountStatusParams, type UseStellarGateParams, type UseStellarTrustlineCheckParams, type UseSupplyLiquidityVars, type UseSupplyVars, type UseSwapAllowanceParams, type UseSwapApproveVars, type UseSwapVars, type UseSwapsApiAllowanceParams, type UseSwapsApiApproveVars, type UseSwapsApiCancelIntentVars, type UseSwapsApiCreateIntentVars, type UseSwapsApiCreateLimitOrderVars, type UseSwapsApiDeadlineParams, type UseSwapsApiEstimateGasParams, type UseSwapsApiFilledIntentParams, type UseSwapsApiIntentExtraDataParams, type UseSwapsApiIntentHashParams, type UseSwapsApiIntentPacketParams, type UseSwapsApiIntentParams, type UseSwapsApiPartnerFeeParams, type UseSwapsApiQuoteParams, type UseSwapsApiSolverFeeParams, type UseSwapsApiStatusParams, type UseSwapsApiSubmitIntentVars, type UseSwapsApiSubmitTxStatusParams, type UseSwapsApiSubmitTxVars, type UseSwapsApiTokensByChainParams, type UseSwapsApiTokensParams, type UseTradingWalletBalanceParams, type UseUserFormattedSummaryParams, type UseUserReservesDataParams, type UseWithdrawHubAssetVars, type UseWithdrawVars, type UseXBalancesParams, type WithdrawParamsCore, type XBalancesInputs, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
package/dist/index.mjs
CHANGED
|
@@ -1742,8 +1742,8 @@ var useSwapsApiSubmitTxStatus = ({
|
|
|
1742
1742
|
enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
|
|
1743
1743
|
retry: 3,
|
|
1744
1744
|
refetchInterval: (query) => {
|
|
1745
|
-
const
|
|
1746
|
-
if (status === "solved" || status === "failed") return false;
|
|
1745
|
+
const data = query.state.data?.data;
|
|
1746
|
+
if (data?.status === "solved" || data?.status === "failed" || data?.abandonedAt) return false;
|
|
1747
1747
|
return 1e3;
|
|
1748
1748
|
},
|
|
1749
1749
|
...queryOptions
|
|
@@ -1862,6 +1862,172 @@ function useGetBridgeableTokens({
|
|
|
1862
1862
|
...queryOptions
|
|
1863
1863
|
});
|
|
1864
1864
|
}
|
|
1865
|
+
var useBridgeApiAllowance = ({
|
|
1866
|
+
params,
|
|
1867
|
+
queryOptions
|
|
1868
|
+
} = {}) => {
|
|
1869
|
+
const { sodax } = useSodaxContext();
|
|
1870
|
+
const body = params?.body;
|
|
1871
|
+
const apiConfig = params?.apiConfig;
|
|
1872
|
+
return useQuery({
|
|
1873
|
+
queryKey: ["bridgeApi", "allowance", body?.srcChainKey, body?.inputToken, body?.inputAmount, body?.srcAddress],
|
|
1874
|
+
queryFn: async () => {
|
|
1875
|
+
if (!body) return void 0;
|
|
1876
|
+
return unwrapResult(await sodax.api.bridge.checkAllowance(body, apiConfig));
|
|
1877
|
+
},
|
|
1878
|
+
enabled: !!body,
|
|
1879
|
+
retry: 3,
|
|
1880
|
+
...queryOptions
|
|
1881
|
+
});
|
|
1882
|
+
};
|
|
1883
|
+
|
|
1884
|
+
// src/hooks/bridgeApi/useBridgeApiApprove.ts
|
|
1885
|
+
var useBridgeApiApprove = ({
|
|
1886
|
+
mutationOptions
|
|
1887
|
+
} = {}) => {
|
|
1888
|
+
const { sodax } = useSodaxContext();
|
|
1889
|
+
return useSafeMutation({
|
|
1890
|
+
mutationKey: ["bridgeApi", "approve"],
|
|
1891
|
+
retry: 3,
|
|
1892
|
+
...mutationOptions,
|
|
1893
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.bridge.approve(body, apiConfig))
|
|
1894
|
+
});
|
|
1895
|
+
};
|
|
1896
|
+
var useBridgeApiBridgeableAmount = ({
|
|
1897
|
+
params,
|
|
1898
|
+
queryOptions
|
|
1899
|
+
} = {}) => {
|
|
1900
|
+
const { sodax } = useSodaxContext();
|
|
1901
|
+
const body = params?.body;
|
|
1902
|
+
const apiConfig = params?.apiConfig;
|
|
1903
|
+
return useQuery({
|
|
1904
|
+
queryKey: ["bridgeApi", "bridgeableAmount", body?.srcChainKey, body?.dstChainKey, body?.inputToken, body?.outputToken],
|
|
1905
|
+
queryFn: async () => {
|
|
1906
|
+
if (!body) return void 0;
|
|
1907
|
+
return unwrapResult(await sodax.api.bridge.getBridgeableAmount(body, apiConfig));
|
|
1908
|
+
},
|
|
1909
|
+
enabled: !!body,
|
|
1910
|
+
retry: 3,
|
|
1911
|
+
...queryOptions
|
|
1912
|
+
});
|
|
1913
|
+
};
|
|
1914
|
+
|
|
1915
|
+
// src/hooks/bridgeApi/useBridgeApiCreateBridgeIntent.ts
|
|
1916
|
+
var useBridgeApiCreateBridgeIntent = ({
|
|
1917
|
+
mutationOptions
|
|
1918
|
+
} = {}) => {
|
|
1919
|
+
const { sodax } = useSodaxContext();
|
|
1920
|
+
return useSafeMutation({
|
|
1921
|
+
mutationKey: ["bridgeApi", "createBridgeIntent"],
|
|
1922
|
+
retry: 3,
|
|
1923
|
+
...mutationOptions,
|
|
1924
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.bridge.createBridgeIntent(body, apiConfig))
|
|
1925
|
+
});
|
|
1926
|
+
};
|
|
1927
|
+
var useBridgeApiFee = ({
|
|
1928
|
+
params,
|
|
1929
|
+
queryOptions
|
|
1930
|
+
} = {}) => {
|
|
1931
|
+
const { sodax } = useSodaxContext();
|
|
1932
|
+
const body = params?.body;
|
|
1933
|
+
const apiConfig = params?.apiConfig;
|
|
1934
|
+
return useQuery({
|
|
1935
|
+
queryKey: ["bridgeApi", "fee", body?.inputAmount, body?.partnerFee],
|
|
1936
|
+
queryFn: async () => {
|
|
1937
|
+
if (!body) return void 0;
|
|
1938
|
+
return unwrapResult(await sodax.api.bridge.getFee(body, apiConfig));
|
|
1939
|
+
},
|
|
1940
|
+
enabled: !!body,
|
|
1941
|
+
retry: 3,
|
|
1942
|
+
...queryOptions
|
|
1943
|
+
});
|
|
1944
|
+
};
|
|
1945
|
+
var useBridgeApiIsBridgeable = ({
|
|
1946
|
+
params,
|
|
1947
|
+
queryOptions
|
|
1948
|
+
} = {}) => {
|
|
1949
|
+
const { sodax } = useSodaxContext();
|
|
1950
|
+
const body = params?.body;
|
|
1951
|
+
const apiConfig = params?.apiConfig;
|
|
1952
|
+
return useQuery({
|
|
1953
|
+
queryKey: ["bridgeApi", "bridgeable", body?.srcChainKey, body?.dstChainKey, body?.inputToken, body?.outputToken],
|
|
1954
|
+
queryFn: async () => {
|
|
1955
|
+
if (!body) return void 0;
|
|
1956
|
+
return unwrapResult(await sodax.api.bridge.isBridgeable(body, apiConfig));
|
|
1957
|
+
},
|
|
1958
|
+
enabled: !!body,
|
|
1959
|
+
retry: 3,
|
|
1960
|
+
...queryOptions
|
|
1961
|
+
});
|
|
1962
|
+
};
|
|
1963
|
+
|
|
1964
|
+
// src/hooks/bridgeApi/useBridgeApiSubmitTx.ts
|
|
1965
|
+
var useBridgeApiSubmitTx = ({
|
|
1966
|
+
mutationOptions
|
|
1967
|
+
} = {}) => {
|
|
1968
|
+
const { sodax } = useSodaxContext();
|
|
1969
|
+
return useSafeMutation({
|
|
1970
|
+
mutationKey: ["bridgeApi", "submitTx"],
|
|
1971
|
+
retry: 3,
|
|
1972
|
+
...mutationOptions,
|
|
1973
|
+
mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.api.bridge.submitTx(request, apiConfig))
|
|
1974
|
+
});
|
|
1975
|
+
};
|
|
1976
|
+
var useBridgeApiSubmitTxStatus = ({
|
|
1977
|
+
params,
|
|
1978
|
+
queryOptions
|
|
1979
|
+
} = {}) => {
|
|
1980
|
+
const { sodax } = useSodaxContext();
|
|
1981
|
+
const txHash = params?.txHash;
|
|
1982
|
+
const srcChainKey = params?.srcChainKey;
|
|
1983
|
+
const apiConfig = params?.apiConfig;
|
|
1984
|
+
return useQuery({
|
|
1985
|
+
queryKey: ["bridgeApi", "submitTx", "status", txHash, srcChainKey],
|
|
1986
|
+
queryFn: async () => {
|
|
1987
|
+
if (!txHash || !srcChainKey) return void 0;
|
|
1988
|
+
return unwrapResult(await sodax.api.bridge.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
|
|
1989
|
+
},
|
|
1990
|
+
enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
|
|
1991
|
+
retry: 3,
|
|
1992
|
+
refetchInterval: (query) => {
|
|
1993
|
+
const data = query.state.data?.data;
|
|
1994
|
+
if (data?.status === "executed" || data?.status === "failed" || data?.abandonedAt) return false;
|
|
1995
|
+
return 1e3;
|
|
1996
|
+
},
|
|
1997
|
+
...queryOptions
|
|
1998
|
+
});
|
|
1999
|
+
};
|
|
2000
|
+
var useBridgeApiTokens = ({
|
|
2001
|
+
params,
|
|
2002
|
+
queryOptions
|
|
2003
|
+
} = {}) => {
|
|
2004
|
+
const { sodax } = useSodaxContext();
|
|
2005
|
+
const apiConfig = params?.apiConfig;
|
|
2006
|
+
return useQuery({
|
|
2007
|
+
queryKey: ["bridgeApi", "tokens"],
|
|
2008
|
+
queryFn: async () => unwrapResult(await sodax.api.bridge.getTokens(apiConfig)),
|
|
2009
|
+
retry: 3,
|
|
2010
|
+
...queryOptions
|
|
2011
|
+
});
|
|
2012
|
+
};
|
|
2013
|
+
var useBridgeApiTokensByChain = ({
|
|
2014
|
+
params,
|
|
2015
|
+
queryOptions
|
|
2016
|
+
} = {}) => {
|
|
2017
|
+
const { sodax } = useSodaxContext();
|
|
2018
|
+
const chainKey = params?.chainKey;
|
|
2019
|
+
const apiConfig = params?.apiConfig;
|
|
2020
|
+
return useQuery({
|
|
2021
|
+
queryKey: ["bridgeApi", "tokens", chainKey],
|
|
2022
|
+
queryFn: async () => {
|
|
2023
|
+
if (!chainKey) return void 0;
|
|
2024
|
+
return unwrapResult(await sodax.api.bridge.getTokensByChain(chainKey, apiConfig));
|
|
2025
|
+
},
|
|
2026
|
+
enabled: !!chainKey && chainKey.length > 0,
|
|
2027
|
+
retry: 3,
|
|
2028
|
+
...queryOptions
|
|
2029
|
+
});
|
|
2030
|
+
};
|
|
1865
2031
|
function useStake({
|
|
1866
2032
|
mutationOptions
|
|
1867
2033
|
} = {}) {
|
|
@@ -3419,4 +3585,4 @@ function createSodaxQueryClient({
|
|
|
3419
3585
|
});
|
|
3420
3586
|
}
|
|
3421
3587
|
|
|
3422
|
-
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
|
3588
|
+
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getSponsorConfigQueryOptions, getStellarAccountActiveQueryOptions, getStellarAccountStatusQueryOptions, getStellarTrustlineCheckQueryOptions, getXBalancesQueryOptions, isTerminalSwapIntentStatus, isUserRejectedError, loadRadfiSession, resolveNearStorageGate, resolveStellarGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useActivateStellarAccount, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApiAllowance, useBridgeApiApprove, useBridgeApiBridgeableAmount, useBridgeApiCreateBridgeIntent, useBridgeApiFee, useBridgeApiIsBridgeable, useBridgeApiSubmitTx, useBridgeApiSubmitTxStatus, useBridgeApiTokens, useBridgeApiTokensByChain, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstablishTrustline, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useSponsorConfig, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarAccountActive, useStellarAccountStatus, useStellarGate, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "2.1.0-rc.
|
|
8
|
+
"version": "2.1.0-rc.2",
|
|
9
9
|
"description": "React hooks for building dApps on the SODAX cross-chain DeFi platform",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"sodax",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"viem": "2.29.2",
|
|
37
|
-
"@sodax/sdk": "2.1.0-rc.
|
|
37
|
+
"@sodax/sdk": "2.1.0-rc.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@arethetypeswrong/cli": "0.17.4",
|
|
@@ -69,6 +69,9 @@ const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
|
|
|
69
69
|
{ path: 'swapsApi/useSwapsApiCreateLimitOrder.ts' },
|
|
70
70
|
{ path: 'swapsApi/useSwapsApiSubmitIntent.ts' },
|
|
71
71
|
{ path: 'swapsApi/useSwapsApiSubmitTx.ts' },
|
|
72
|
+
{ path: 'bridgeApi/useBridgeApiApprove.ts' },
|
|
73
|
+
{ path: 'bridgeApi/useBridgeApiCreateBridgeIntent.ts' },
|
|
74
|
+
{ path: 'bridgeApi/useBridgeApiSubmitTx.ts' },
|
|
72
75
|
];
|
|
73
76
|
|
|
74
77
|
describe.each(HOOKS)('mutation hook contract: $path', ({ path, nativeThrow }) => {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// bridgeApi/ — React Query hooks over the HTTP Bridge API (`sodax.api.bridge.*`).
|
|
2
|
+
// Distinct from the on-chain `bridge/` hooks (which call `sodax.bridge.*` directly).
|
|
3
|
+
|
|
4
|
+
export * from './useBridgeApiAllowance.js'; // query
|
|
5
|
+
export * from './useBridgeApiApprove.js'; // mutation
|
|
6
|
+
export * from './useBridgeApiBridgeableAmount.js'; // query (deposit capacity / withdrawal liquidity)
|
|
7
|
+
export * from './useBridgeApiCreateBridgeIntent.js'; // mutation
|
|
8
|
+
export * from './useBridgeApiFee.js'; // query (partner fee — per-request override or configured default)
|
|
9
|
+
export * from './useBridgeApiIsBridgeable.js'; // query (pair bridgeable?)
|
|
10
|
+
export * from './useBridgeApiSubmitTx.js'; // mutation
|
|
11
|
+
export * from './useBridgeApiSubmitTxStatus.js'; // query (poll)
|
|
12
|
+
export * from './useBridgeApiTokens.js'; // query (backend-served token list)
|
|
13
|
+
export * from './useBridgeApiTokensByChain.js'; // query (backend-served token list for one chain)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { BridgeAllowanceCheckResponseV2, CreateBridgeIntentParamsV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
export type UseBridgeApiAllowanceParams = ReadHookParams<
|
|
8
|
+
BridgeAllowanceCheckResponseV2 | undefined,
|
|
9
|
+
{
|
|
10
|
+
body: CreateBridgeIntentParamsV2 | undefined;
|
|
11
|
+
apiConfig?: RequestOverrideConfig;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* React hook to check whether the source-token allowance is already sufficient for a bridge via
|
|
17
|
+
* the bridge API — `sodax.api.bridge.checkAllowance`. Returns `{ valid }`.
|
|
18
|
+
*
|
|
19
|
+
* The `body` uses the wire DTO field names (`inputToken`/`inputAmount`).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data: allowance } = useBridgeApiAllowance({ params: { body: createBridgeIntentParams } });
|
|
23
|
+
*/
|
|
24
|
+
export const useBridgeApiAllowance = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseBridgeApiAllowanceParams = {}): UseQueryResult<BridgeAllowanceCheckResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const body = params?.body;
|
|
30
|
+
const apiConfig = params?.apiConfig;
|
|
31
|
+
|
|
32
|
+
return useQuery({
|
|
33
|
+
queryKey: ['bridgeApi', 'allowance', body?.srcChainKey, body?.inputToken, body?.inputAmount, body?.srcAddress],
|
|
34
|
+
queryFn: async (): Promise<BridgeAllowanceCheckResponseV2 | undefined> => {
|
|
35
|
+
if (!body) return undefined;
|
|
36
|
+
return unwrapResult(await sodax.api.bridge.checkAllowance(body, apiConfig));
|
|
37
|
+
},
|
|
38
|
+
enabled: !!body,
|
|
39
|
+
retry: 3,
|
|
40
|
+
...queryOptions,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BridgeApproveResponseV2, CreateBridgeIntentParamsV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
3
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
4
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
5
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mutation variables for {@link useBridgeApiApprove}. The per-request `apiConfig` override belongs
|
|
9
|
+
* here rather than at the hook level — different calls in the same component can target different
|
|
10
|
+
* endpoints without re-rendering.
|
|
11
|
+
*/
|
|
12
|
+
export type UseBridgeApiApproveVars = {
|
|
13
|
+
body: CreateBridgeIntentParamsV2;
|
|
14
|
+
apiConfig?: RequestOverrideConfig;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to build an unsigned token-approval transaction for the source token via the bridge
|
|
19
|
+
* API — `sodax.api.bridge.approve`. Returns `{ tx }` (chain-specific unsigned tx) to sign and
|
|
20
|
+
* broadcast yourself; it does not change state, so no queries are invalidated.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const { mutateAsync: approve } = useBridgeApiApprove();
|
|
24
|
+
* const { tx } = await approve({ body: createBridgeIntentParams });
|
|
25
|
+
*/
|
|
26
|
+
export const useBridgeApiApprove = ({
|
|
27
|
+
mutationOptions,
|
|
28
|
+
}: MutationHookParams<BridgeApproveResponseV2, UseBridgeApiApproveVars> = {}): SafeUseMutationResult<
|
|
29
|
+
BridgeApproveResponseV2,
|
|
30
|
+
Error,
|
|
31
|
+
UseBridgeApiApproveVars
|
|
32
|
+
> => {
|
|
33
|
+
const { sodax } = useSodaxContext();
|
|
34
|
+
|
|
35
|
+
return useSafeMutation<BridgeApproveResponseV2, Error, UseBridgeApiApproveVars>({
|
|
36
|
+
mutationKey: ['bridgeApi', 'approve'],
|
|
37
|
+
retry: 3,
|
|
38
|
+
...mutationOptions,
|
|
39
|
+
mutationFn: async ({ body, apiConfig }): Promise<BridgeApproveResponseV2> =>
|
|
40
|
+
unwrapResult(await sodax.api.bridge.approve(body, apiConfig)),
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { BridgeableAmountResponseV2, BridgeQuoteRequestV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
export type UseBridgeApiBridgeableAmountParams = ReadHookParams<
|
|
8
|
+
BridgeableAmountResponseV2 | undefined,
|
|
9
|
+
{
|
|
10
|
+
body: BridgeQuoteRequestV2 | undefined;
|
|
11
|
+
apiConfig?: RequestOverrideConfig;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* React hook to fetch the deposit capacity / withdrawal liquidity limit for a (from, to) token pair
|
|
17
|
+
* via the bridge API — `sodax.api.bridge.getBridgeableAmount`. Returns `{ limit }`.
|
|
18
|
+
*
|
|
19
|
+
* Computable client-side from config + vault reserves — prefer `sodax.bridge.getBridgeableAmount`
|
|
20
|
+
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/bridgeable-amount` endpoint.
|
|
21
|
+
*
|
|
22
|
+
* The `body` uses the wire DTO field names (`srcChainKey`/`dstChainKey`/`inputToken`/`outputToken`).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const { data } = useBridgeApiBridgeableAmount({ params: { body: quote } });
|
|
26
|
+
*/
|
|
27
|
+
export const useBridgeApiBridgeableAmount = ({
|
|
28
|
+
params,
|
|
29
|
+
queryOptions,
|
|
30
|
+
}: UseBridgeApiBridgeableAmountParams = {}): UseQueryResult<BridgeableAmountResponseV2 | undefined, Error> => {
|
|
31
|
+
const { sodax } = useSodaxContext();
|
|
32
|
+
const body = params?.body;
|
|
33
|
+
const apiConfig = params?.apiConfig;
|
|
34
|
+
|
|
35
|
+
return useQuery({
|
|
36
|
+
queryKey: ['bridgeApi', 'bridgeableAmount', body?.srcChainKey, body?.dstChainKey, body?.inputToken, body?.outputToken],
|
|
37
|
+
queryFn: async (): Promise<BridgeableAmountResponseV2 | undefined> => {
|
|
38
|
+
if (!body) return undefined;
|
|
39
|
+
return unwrapResult(await sodax.api.bridge.getBridgeableAmount(body, apiConfig));
|
|
40
|
+
},
|
|
41
|
+
enabled: !!body,
|
|
42
|
+
retry: 3,
|
|
43
|
+
...queryOptions,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CreateBridgeIntentParamsV2, CreateBridgeIntentResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
3
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
4
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
5
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mutation variables for {@link useBridgeApiCreateBridgeIntent}. The per-request `apiConfig`
|
|
9
|
+
* override belongs here rather than at the hook level.
|
|
10
|
+
*/
|
|
11
|
+
export type UseBridgeApiCreateBridgeIntentVars = {
|
|
12
|
+
body: CreateBridgeIntentParamsV2;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to build an unsigned spoke-deposit (create-bridge-intent) transaction via the bridge
|
|
18
|
+
* API — `sodax.api.bridge.createBridgeIntent`. Returns `{ tx, relayData }` (no `intent` struct —
|
|
19
|
+
* bridge is vault-backed) to sign and broadcast yourself; it does not change state, so no queries
|
|
20
|
+
* are invalidated.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const { mutateAsync: createBridgeIntent } = useBridgeApiCreateBridgeIntent();
|
|
24
|
+
* const { tx, relayData } = await createBridgeIntent({ body: createBridgeIntentParams });
|
|
25
|
+
*/
|
|
26
|
+
export const useBridgeApiCreateBridgeIntent = ({
|
|
27
|
+
mutationOptions,
|
|
28
|
+
}: MutationHookParams<CreateBridgeIntentResponseV2, UseBridgeApiCreateBridgeIntentVars> = {}): SafeUseMutationResult<
|
|
29
|
+
CreateBridgeIntentResponseV2,
|
|
30
|
+
Error,
|
|
31
|
+
UseBridgeApiCreateBridgeIntentVars
|
|
32
|
+
> => {
|
|
33
|
+
const { sodax } = useSodaxContext();
|
|
34
|
+
|
|
35
|
+
return useSafeMutation<CreateBridgeIntentResponseV2, Error, UseBridgeApiCreateBridgeIntentVars>({
|
|
36
|
+
mutationKey: ['bridgeApi', 'createBridgeIntent'],
|
|
37
|
+
retry: 3,
|
|
38
|
+
...mutationOptions,
|
|
39
|
+
mutationFn: async ({ body, apiConfig }): Promise<CreateBridgeIntentResponseV2> =>
|
|
40
|
+
unwrapResult(await sodax.api.bridge.createBridgeIntent(body, apiConfig)),
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { BridgeFeeRequestV2, BridgeFeeResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
export type UseBridgeApiFeeParams = ReadHookParams<
|
|
8
|
+
BridgeFeeResponseV2 | undefined,
|
|
9
|
+
{
|
|
10
|
+
body: BridgeFeeRequestV2 | undefined;
|
|
11
|
+
apiConfig?: RequestOverrideConfig;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* React hook to fetch the bridge partner fee for an input amount via the bridge API (uses a per-request
|
|
17
|
+
* `body.partnerFee` override when supplied, else the backend-configured fee) —
|
|
18
|
+
* `sodax.api.bridge.getFee`. Returns `{ fee }` (smallest unit, decimal string).
|
|
19
|
+
*
|
|
20
|
+
* The fee is computable client-side (config-driven, token-independent) — prefer `sodax.bridge.getFee`
|
|
21
|
+
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/fee` endpoint for parity.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const { data: fee } = useBridgeApiFee({ params: { body: { inputAmount } } });
|
|
25
|
+
*/
|
|
26
|
+
export const useBridgeApiFee = ({
|
|
27
|
+
params,
|
|
28
|
+
queryOptions,
|
|
29
|
+
}: UseBridgeApiFeeParams = {}): UseQueryResult<BridgeFeeResponseV2 | undefined, Error> => {
|
|
30
|
+
const { sodax } = useSodaxContext();
|
|
31
|
+
const body = params?.body;
|
|
32
|
+
const apiConfig = params?.apiConfig;
|
|
33
|
+
|
|
34
|
+
return useQuery({
|
|
35
|
+
queryKey: ['bridgeApi', 'fee', body?.inputAmount, body?.partnerFee],
|
|
36
|
+
queryFn: async (): Promise<BridgeFeeResponseV2 | undefined> => {
|
|
37
|
+
if (!body) return undefined;
|
|
38
|
+
return unwrapResult(await sodax.api.bridge.getFee(body, apiConfig));
|
|
39
|
+
},
|
|
40
|
+
enabled: !!body,
|
|
41
|
+
retry: 3,
|
|
42
|
+
...queryOptions,
|
|
43
|
+
});
|
|
44
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { BridgeableCheckResponseV2, BridgeQuoteRequestV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
export type UseBridgeApiIsBridgeableParams = ReadHookParams<
|
|
8
|
+
BridgeableCheckResponseV2 | undefined,
|
|
9
|
+
{
|
|
10
|
+
body: BridgeQuoteRequestV2 | undefined;
|
|
11
|
+
apiConfig?: RequestOverrideConfig;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* React hook to check whether a (from, to) token pair is bridgeable via the bridge API —
|
|
17
|
+
* `sodax.api.bridge.isBridgeable`. Returns `{ bridgeable }`.
|
|
18
|
+
*
|
|
19
|
+
* Computable client-side from config + vault reserves — prefer `sodax.bridge.isBridgeable`
|
|
20
|
+
* for a no-round-trip read; this HTTP variant mirrors the `/bridge/bridgeable/check` endpoint.
|
|
21
|
+
*
|
|
22
|
+
* The `body` uses the wire DTO field names (`srcChainKey`/`dstChainKey`/`inputToken`/`outputToken`).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const { data } = useBridgeApiIsBridgeable({ params: { body: quote } });
|
|
26
|
+
*/
|
|
27
|
+
export const useBridgeApiIsBridgeable = ({
|
|
28
|
+
params,
|
|
29
|
+
queryOptions,
|
|
30
|
+
}: UseBridgeApiIsBridgeableParams = {}): UseQueryResult<BridgeableCheckResponseV2 | undefined, Error> => {
|
|
31
|
+
const { sodax } = useSodaxContext();
|
|
32
|
+
const body = params?.body;
|
|
33
|
+
const apiConfig = params?.apiConfig;
|
|
34
|
+
|
|
35
|
+
return useQuery({
|
|
36
|
+
queryKey: ['bridgeApi', 'bridgeable', body?.srcChainKey, body?.dstChainKey, body?.inputToken, body?.outputToken],
|
|
37
|
+
queryFn: async (): Promise<BridgeableCheckResponseV2 | undefined> => {
|
|
38
|
+
if (!body) return undefined;
|
|
39
|
+
return unwrapResult(await sodax.api.bridge.isBridgeable(body, apiConfig));
|
|
40
|
+
},
|
|
41
|
+
enabled: !!body,
|
|
42
|
+
retry: 3,
|
|
43
|
+
...queryOptions,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { BridgeSubmitTxRequestV2, BridgeSubmitTxResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
3
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
4
|
+
import type { MutationHookParams } from '../shared/types.js';
|
|
5
|
+
import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mutation variables for {@link useBridgeApiSubmitTx}. The per-request `apiConfig` override
|
|
9
|
+
* (e.g. base URL) belongs here rather than at the hook level — different submissions in the same
|
|
10
|
+
* component can target different endpoints without re-rendering.
|
|
11
|
+
*/
|
|
12
|
+
export type UseBridgeApiSubmitTxVars = {
|
|
13
|
+
request: BridgeSubmitTxRequestV2;
|
|
14
|
+
apiConfig?: RequestOverrideConfig;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook for submitting a broadcast bridge (spoke-deposit) transaction to be processed
|
|
19
|
+
* (relayed server-side) via the bridge API — `sodax.api.bridge.submitTx`. Called AFTER signing +
|
|
20
|
+
* broadcasting the spoke-deposit tx, handing it (with the FULL `relayData { address, payload }`
|
|
21
|
+
* envelope) to the backend.
|
|
22
|
+
*
|
|
23
|
+
* Pure mutation: pass `{ request, apiConfig? }` to `mutate({...})`. Default `retry: 3` is applied
|
|
24
|
+
* at the hook level — consumers can override via `mutationOptions.retry`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const { mutateAsync: submitBridgeTx, isPending, error } = useBridgeApiSubmitTx();
|
|
28
|
+
*
|
|
29
|
+
* const result = await submitBridgeTx({
|
|
30
|
+
* request: { txHash: '0x123...', srcChainKey: '0xa4b1.arbitrum', walletAddress: '0xabc...', relayData: { address: '0x...', payload: '0x...' } },
|
|
31
|
+
* apiConfig: { baseURL: 'https://...' },
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
export const useBridgeApiSubmitTx = ({
|
|
35
|
+
mutationOptions,
|
|
36
|
+
}: MutationHookParams<BridgeSubmitTxResponseV2, UseBridgeApiSubmitTxVars> = {}): SafeUseMutationResult<
|
|
37
|
+
BridgeSubmitTxResponseV2,
|
|
38
|
+
Error,
|
|
39
|
+
UseBridgeApiSubmitTxVars
|
|
40
|
+
> => {
|
|
41
|
+
const { sodax } = useSodaxContext();
|
|
42
|
+
|
|
43
|
+
return useSafeMutation<BridgeSubmitTxResponseV2, Error, UseBridgeApiSubmitTxVars>({
|
|
44
|
+
mutationKey: ['bridgeApi', 'submitTx'],
|
|
45
|
+
retry: 3,
|
|
46
|
+
...mutationOptions,
|
|
47
|
+
mutationFn: async ({ request, apiConfig }): Promise<BridgeSubmitTxResponseV2> =>
|
|
48
|
+
unwrapResult(await sodax.api.bridge.submitTx(request, apiConfig)),
|
|
49
|
+
});
|
|
50
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { BridgeSubmitTxStatusResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
export type UseBridgeApiSubmitTxStatusParams = ReadHookParams<
|
|
8
|
+
BridgeSubmitTxStatusResponseV2 | undefined,
|
|
9
|
+
{
|
|
10
|
+
txHash: string | undefined;
|
|
11
|
+
srcChainKey?: string;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook for polling the processing status of a submitted bridge transaction via the bridge
|
|
18
|
+
* API — `sodax.api.bridge.getSubmitTxStatus`. Both `txHash` and `srcChainKey` are required for the
|
|
19
|
+
* query to run.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data: status } = useBridgeApiSubmitTxStatus({
|
|
23
|
+
* params: { txHash: '0x123...', srcChainKey: '0xa4b1.arbitrum' },
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - Default refetch interval is 1 second; stops on 'executed' or 'failed' status, or when the
|
|
28
|
+
* backend marks the submission abandoned (`abandonedAt`) while `status` stays non-terminal —
|
|
29
|
+
* mirroring the SDK's backend submit-tx poll (no solver `posting_execution` state — bridge has
|
|
30
|
+
* no post-execution).
|
|
31
|
+
*/
|
|
32
|
+
export const useBridgeApiSubmitTxStatus = ({
|
|
33
|
+
params,
|
|
34
|
+
queryOptions,
|
|
35
|
+
}: UseBridgeApiSubmitTxStatusParams = {}): UseQueryResult<BridgeSubmitTxStatusResponseV2 | undefined, Error> => {
|
|
36
|
+
const { sodax } = useSodaxContext();
|
|
37
|
+
const txHash = params?.txHash;
|
|
38
|
+
const srcChainKey = params?.srcChainKey;
|
|
39
|
+
const apiConfig = params?.apiConfig;
|
|
40
|
+
|
|
41
|
+
return useQuery({
|
|
42
|
+
queryKey: ['bridgeApi', 'submitTx', 'status', txHash, srcChainKey],
|
|
43
|
+
queryFn: async (): Promise<BridgeSubmitTxStatusResponseV2 | undefined> => {
|
|
44
|
+
// `srcChainKey` is required by the bridge API status query. The `enabled` gate below ensures
|
|
45
|
+
// both are present; this guard also narrows the types for the call.
|
|
46
|
+
if (!txHash || !srcChainKey) return undefined;
|
|
47
|
+
return unwrapResult(await sodax.api.bridge.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
|
|
48
|
+
},
|
|
49
|
+
enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
|
|
50
|
+
retry: 3,
|
|
51
|
+
refetchInterval: query => {
|
|
52
|
+
const data = query.state.data?.data;
|
|
53
|
+
// `abandonedAt` is terminal even when `status` is still non-terminal (e.g. 'relayed') —
|
|
54
|
+
// same rule as the SDK's pollBackendSubmitTx.
|
|
55
|
+
if (data?.status === 'executed' || data?.status === 'failed' || data?.abandonedAt) return false;
|
|
56
|
+
return 1000;
|
|
57
|
+
},
|
|
58
|
+
...queryOptions,
|
|
59
|
+
});
|
|
60
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { GetBridgeTokensResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
export type UseBridgeApiTokensParams = ReadHookParams<
|
|
8
|
+
GetBridgeTokensResponseV2,
|
|
9
|
+
{
|
|
10
|
+
apiConfig?: RequestOverrideConfig;
|
|
11
|
+
}
|
|
12
|
+
>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* React hook to fetch all supported bridge tokens grouped by SpokeChainKey via the bridge API —
|
|
16
|
+
* `sodax.api.bridge.getTokens`. The token list is backend-served; the bridgeable-amount quote is
|
|
17
|
+
* computable client-side via `useGetBridgeableAmount` (also mirrored by `useBridgeApiBridgeableAmount`).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { data: tokensByChain } = useBridgeApiTokens();
|
|
21
|
+
*/
|
|
22
|
+
export const useBridgeApiTokens = ({
|
|
23
|
+
params,
|
|
24
|
+
queryOptions,
|
|
25
|
+
}: UseBridgeApiTokensParams = {}): UseQueryResult<GetBridgeTokensResponseV2, Error> => {
|
|
26
|
+
const { sodax } = useSodaxContext();
|
|
27
|
+
const apiConfig = params?.apiConfig;
|
|
28
|
+
|
|
29
|
+
return useQuery<GetBridgeTokensResponseV2, Error>({
|
|
30
|
+
queryKey: ['bridgeApi', 'tokens'],
|
|
31
|
+
queryFn: async (): Promise<GetBridgeTokensResponseV2> => unwrapResult(await sodax.api.bridge.getTokens(apiConfig)),
|
|
32
|
+
retry: 3,
|
|
33
|
+
...queryOptions,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { GetBridgeTokensByChainResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
5
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
6
|
+
|
|
7
|
+
export type UseBridgeApiTokensByChainParams = ReadHookParams<
|
|
8
|
+
GetBridgeTokensByChainResponseV2 | undefined,
|
|
9
|
+
{
|
|
10
|
+
chainKey: string | undefined;
|
|
11
|
+
apiConfig?: RequestOverrideConfig;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* React hook to fetch supported bridge tokens for a single SpokeChainKey via the bridge API —
|
|
17
|
+
* `sodax.api.bridge.getTokensByChain`. Use `useBridgeApiTokens` for every chain at once.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { data: tokens } = useBridgeApiTokensByChain({ params: { chainKey: '0xa4b1.arbitrum' } });
|
|
21
|
+
*/
|
|
22
|
+
export const useBridgeApiTokensByChain = ({
|
|
23
|
+
params,
|
|
24
|
+
queryOptions,
|
|
25
|
+
}: UseBridgeApiTokensByChainParams = {}): UseQueryResult<GetBridgeTokensByChainResponseV2 | undefined, Error> => {
|
|
26
|
+
const { sodax } = useSodaxContext();
|
|
27
|
+
const chainKey = params?.chainKey;
|
|
28
|
+
const apiConfig = params?.apiConfig;
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ['bridgeApi', 'tokens', chainKey],
|
|
32
|
+
queryFn: async (): Promise<GetBridgeTokensByChainResponseV2 | undefined> => {
|
|
33
|
+
if (!chainKey) return undefined;
|
|
34
|
+
return unwrapResult(await sodax.api.bridge.getTokensByChain(chainKey, apiConfig));
|
|
35
|
+
},
|
|
36
|
+
enabled: !!chainKey && chainKey.length > 0,
|
|
37
|
+
retry: 3,
|
|
38
|
+
...queryOptions,
|
|
39
|
+
});
|
|
40
|
+
};
|
package/src/hooks/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './swap/index.js';
|
|
|
6
6
|
export * from './backend/index.js';
|
|
7
7
|
export * from './swapsApi/index.js';
|
|
8
8
|
export * from './bridge/index.js';
|
|
9
|
+
export * from './bridgeApi/index.js';
|
|
9
10
|
export * from './staking/index.js';
|
|
10
11
|
export * from './partner/index.js';
|
|
11
12
|
export * from './recovery/index.js';
|
|
@@ -24,7 +24,8 @@ export type UseSwapsApiSubmitTxStatusParams = ReadHookParams<
|
|
|
24
24
|
* });
|
|
25
25
|
*
|
|
26
26
|
* @remarks
|
|
27
|
-
* - Default refetch interval is 1 second; stops on 'solved' or 'failed' status
|
|
27
|
+
* - Default refetch interval is 1 second; stops on 'solved' or 'failed' status, or when the
|
|
28
|
+
* backend marks the submission abandoned (`abandonedAt`) while `status` stays non-terminal.
|
|
28
29
|
*/
|
|
29
30
|
export const useSwapsApiSubmitTxStatus = ({
|
|
30
31
|
params,
|
|
@@ -46,8 +47,10 @@ export const useSwapsApiSubmitTxStatus = ({
|
|
|
46
47
|
enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
|
|
47
48
|
retry: 3,
|
|
48
49
|
refetchInterval: query => {
|
|
49
|
-
const
|
|
50
|
-
|
|
50
|
+
const data = query.state.data?.data;
|
|
51
|
+
// `abandonedAt` is terminal even when `status` is still non-terminal — same rule as the
|
|
52
|
+
// SDK's pollBackendSubmitTx and the bridge-api status hook.
|
|
53
|
+
if (data?.status === 'solved' || data?.status === 'failed' || data?.abandonedAt) return false;
|
|
51
54
|
return 1000;
|
|
52
55
|
},
|
|
53
56
|
...queryOptions,
|