@sodax/dapp-kit 1.0.0-rc.6 → 1.0.0-rc.8

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.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _sodax_sdk from '@sodax/sdk';
2
- import { Sodax, SpokeProvider, GetEstimateGasReturnType, TxReturnType, SpokeChainId, StellarSpokeProvider, EvmHubProvider, IWalletProvider, UserReserveData, MoneyMarketAction, Address as Address$1, XToken as XToken$1, SolverIntentQuoteRequest, Result, SolverIntentQuoteResponse, SolverErrorResponse, SolverExecutionResponse, Intent, IntentDeliveryInfo, IntentError, IntentErrorCode, CreateIntentParams, Hex, SolverIntentStatusResponse, IntentResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, CreateBridgeIntentParams, SpokeTxHash, HubTxHash, BridgeError, BridgeErrorCode, StakeParams, UnstakeParams, ClaimParams, CancelUnstakeParams, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeParams, SodaxConfig } from '@sodax/sdk';
3
- import { RpcConfig, SpokeChainId as SpokeChainId$1, XToken, ChainId } from '@sodax/types';
2
+ import { Sodax, SpokeProvider, GetEstimateGasReturnType, TxReturnType, SpokeChainId, StellarSpokeProvider, EvmHubProvider, IWalletProvider, UserReserveData, MoneyMarketAction, Address as Address$1, XToken as XToken$1, ReserveData, FormatReserveUSDResponse, SolverIntentQuoteRequest, Result, SolverIntentQuoteResponse, SolverErrorResponse, SolverExecutionResponse, Intent, IntentDeliveryInfo, IntentError, IntentErrorCode, CreateIntentParams, Hex, SolverIntentStatusResponse, IntentResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, CreateBridgeIntentParams, SpokeTxHash, HubTxHash, BridgeError, BridgeErrorCode, StakeParams, UnstakeParams, ClaimParams, CancelUnstakeParams, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeParams, SodaxConfig } from '@sodax/sdk';
3
+ import { RpcConfig, SpokeChainId as SpokeChainId$1, XToken } from '@sodax/types';
4
4
  import * as _tanstack_react_query from '@tanstack/react-query';
5
5
  import { UseMutationResult, UseQueryResult } from '@tanstack/react-query';
6
6
  import { Address } from 'viem';
@@ -374,6 +374,27 @@ declare function useMMApprove(token: XToken, spokeProvider: SpokeProvider | unde
374
374
  */
375
375
  declare function useAToken(aToken: Address$1 | undefined): UseQueryResult<XToken$1, Error>;
376
376
 
377
+ /**
378
+ * Hook for fetching formatted summary of Sodax user portfolio (holdings, total liquidity,
379
+ * collateral, borrows, liquidation threshold, health factor, available borrowing power, etc..).
380
+ *
381
+ * This hook provides access to the current state of user portfolio in the money market protocol.
382
+ * The data is automatically fetched and cached using React Query.
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const { data: userFormattedSummary, isLoading, error } = useUserFormattedSummary();
387
+ * ```
388
+ *
389
+ * @returns A React Query result object containing:
390
+ * - data: The formatted summary of Sodax user portfolio when available
391
+ * - isLoading: Loading state indicator
392
+ * - error: Any error that occurred during data fetching
393
+ */
394
+ declare function useReservesUsdFormat(): UseQueryResult<(ReserveData & {
395
+ priceInMarketReferenceCurrency: string;
396
+ } & FormatReserveUSDResponse)[], Error>;
397
+
377
398
  /**
378
399
  * Hook for fetching a quote for an intent-based swap.
379
400
  *
@@ -537,13 +558,13 @@ type CancelIntentResult = Result<TxReturnType<SpokeProvider, boolean>>;
537
558
  declare function useCancelSwap(spokeProvider: SpokeProvider | undefined): UseMutationResult<CancelIntentResult, Error, CancelIntentParams>;
538
559
 
539
560
  /**
540
- * Hook for fetching intent details by transaction hash from the backend API.
561
+ * Hook for fetching intent details by intent created transaction hash from the backend API.
541
562
  *
542
- * This hook provides access to intent data associated with a specific transaction hash,
543
- * including intent details, events, and transaction information. The data is automatically
544
- * fetched and cached using React Query.
563
+ * This hook provides access to intent data associated with the transaction hash from when
564
+ * the intent was created on the hub chain, including intent details, events, and transaction
565
+ * information. The data is automatically fetched and cached using React Query.
545
566
  *
546
- * @param {string | undefined} txHash - The transaction hash to fetch intent for. If undefined, the query will be disabled.
567
+ * @param {string | undefined} txHash - The intent created transaction hash from the hub chain to fetch intent for. If undefined, the query will be disabled.
547
568
  *
548
569
  * @returns {UseQueryResult<IntentResponse | undefined>} A query result object containing:
549
570
  * - data: The intent response data when available
@@ -563,11 +584,12 @@ declare function useCancelSwap(spokeProvider: SpokeProvider | undefined): UseMut
563
584
  * ```
564
585
  *
565
586
  * @remarks
587
+ * - Intents are only created on the hub chain, so the transaction hash must be from the hub chain
566
588
  * - The query is disabled when txHash is undefined or empty
567
589
  * - Uses React Query for efficient caching and state management
568
590
  * - Automatically handles error states and loading indicators
569
591
  */
570
- declare const useBackendIntentByTxHash: (txHash: string | undefined) => UseQueryResult<IntentResponse | undefined>;
592
+ declare const useBackendIntentByTxHash: (txHash: string | undefined, refetchInterval?: number) => UseQueryResult<IntentResponse | undefined>;
571
593
 
572
594
  /**
573
595
  * Hook for fetching intent details by intent hash from the backend API.
@@ -1533,6 +1555,4 @@ interface SodaxProviderProps {
1533
1555
  }
1534
1556
  declare const SodaxProvider: ({ children, testnet, config, rpcConfig }: SodaxProviderProps) => ReactElement;
1535
1557
 
1536
- declare const getSpokeTokenAddressByVault: (spokeChainId: ChainId, vault: string) => string | undefined;
1537
-
1538
- export { MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, type MigrationIntentParams, type MigrationMode, SodaxProvider, getSpokeTokenAddressByVault, useAToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserReservesData, useWithdraw };
1558
+ export { MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, type MigrationIntentParams, type MigrationMode, SodaxProvider, useAToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useReservesUsdFormat, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserReservesData, useWithdraw };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _sodax_sdk from '@sodax/sdk';
2
- import { Sodax, SpokeProvider, GetEstimateGasReturnType, TxReturnType, SpokeChainId, StellarSpokeProvider, EvmHubProvider, IWalletProvider, UserReserveData, MoneyMarketAction, Address as Address$1, XToken as XToken$1, SolverIntentQuoteRequest, Result, SolverIntentQuoteResponse, SolverErrorResponse, SolverExecutionResponse, Intent, IntentDeliveryInfo, IntentError, IntentErrorCode, CreateIntentParams, Hex, SolverIntentStatusResponse, IntentResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, CreateBridgeIntentParams, SpokeTxHash, HubTxHash, BridgeError, BridgeErrorCode, StakeParams, UnstakeParams, ClaimParams, CancelUnstakeParams, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeParams, SodaxConfig } from '@sodax/sdk';
3
- import { RpcConfig, SpokeChainId as SpokeChainId$1, XToken, ChainId } from '@sodax/types';
2
+ import { Sodax, SpokeProvider, GetEstimateGasReturnType, TxReturnType, SpokeChainId, StellarSpokeProvider, EvmHubProvider, IWalletProvider, UserReserveData, MoneyMarketAction, Address as Address$1, XToken as XToken$1, ReserveData, FormatReserveUSDResponse, SolverIntentQuoteRequest, Result, SolverIntentQuoteResponse, SolverErrorResponse, SolverExecutionResponse, Intent, IntentDeliveryInfo, IntentError, IntentErrorCode, CreateIntentParams, Hex, SolverIntentStatusResponse, IntentResponse, OrderbookResponse, MoneyMarketPosition, MoneyMarketAsset, MoneyMarketAssetBorrowers, MoneyMarketAssetSuppliers, MoneyMarketBorrowers, CreateBridgeIntentParams, SpokeTxHash, HubTxHash, BridgeError, BridgeErrorCode, StakeParams, UnstakeParams, ClaimParams, CancelUnstakeParams, StakingInfo, UnstakingInfo, UnstakeRequestWithPenalty, StakingConfig, InstantUnstakeParams, SodaxConfig } from '@sodax/sdk';
3
+ import { RpcConfig, SpokeChainId as SpokeChainId$1, XToken } from '@sodax/types';
4
4
  import * as _tanstack_react_query from '@tanstack/react-query';
5
5
  import { UseMutationResult, UseQueryResult } from '@tanstack/react-query';
6
6
  import { Address } from 'viem';
@@ -374,6 +374,27 @@ declare function useMMApprove(token: XToken, spokeProvider: SpokeProvider | unde
374
374
  */
375
375
  declare function useAToken(aToken: Address$1 | undefined): UseQueryResult<XToken$1, Error>;
376
376
 
377
+ /**
378
+ * Hook for fetching formatted summary of Sodax user portfolio (holdings, total liquidity,
379
+ * collateral, borrows, liquidation threshold, health factor, available borrowing power, etc..).
380
+ *
381
+ * This hook provides access to the current state of user portfolio in the money market protocol.
382
+ * The data is automatically fetched and cached using React Query.
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const { data: userFormattedSummary, isLoading, error } = useUserFormattedSummary();
387
+ * ```
388
+ *
389
+ * @returns A React Query result object containing:
390
+ * - data: The formatted summary of Sodax user portfolio when available
391
+ * - isLoading: Loading state indicator
392
+ * - error: Any error that occurred during data fetching
393
+ */
394
+ declare function useReservesUsdFormat(): UseQueryResult<(ReserveData & {
395
+ priceInMarketReferenceCurrency: string;
396
+ } & FormatReserveUSDResponse)[], Error>;
397
+
377
398
  /**
378
399
  * Hook for fetching a quote for an intent-based swap.
379
400
  *
@@ -537,13 +558,13 @@ type CancelIntentResult = Result<TxReturnType<SpokeProvider, boolean>>;
537
558
  declare function useCancelSwap(spokeProvider: SpokeProvider | undefined): UseMutationResult<CancelIntentResult, Error, CancelIntentParams>;
538
559
 
539
560
  /**
540
- * Hook for fetching intent details by transaction hash from the backend API.
561
+ * Hook for fetching intent details by intent created transaction hash from the backend API.
541
562
  *
542
- * This hook provides access to intent data associated with a specific transaction hash,
543
- * including intent details, events, and transaction information. The data is automatically
544
- * fetched and cached using React Query.
563
+ * This hook provides access to intent data associated with the transaction hash from when
564
+ * the intent was created on the hub chain, including intent details, events, and transaction
565
+ * information. The data is automatically fetched and cached using React Query.
545
566
  *
546
- * @param {string | undefined} txHash - The transaction hash to fetch intent for. If undefined, the query will be disabled.
567
+ * @param {string | undefined} txHash - The intent created transaction hash from the hub chain to fetch intent for. If undefined, the query will be disabled.
547
568
  *
548
569
  * @returns {UseQueryResult<IntentResponse | undefined>} A query result object containing:
549
570
  * - data: The intent response data when available
@@ -563,11 +584,12 @@ declare function useCancelSwap(spokeProvider: SpokeProvider | undefined): UseMut
563
584
  * ```
564
585
  *
565
586
  * @remarks
587
+ * - Intents are only created on the hub chain, so the transaction hash must be from the hub chain
566
588
  * - The query is disabled when txHash is undefined or empty
567
589
  * - Uses React Query for efficient caching and state management
568
590
  * - Automatically handles error states and loading indicators
569
591
  */
570
- declare const useBackendIntentByTxHash: (txHash: string | undefined) => UseQueryResult<IntentResponse | undefined>;
592
+ declare const useBackendIntentByTxHash: (txHash: string | undefined, refetchInterval?: number) => UseQueryResult<IntentResponse | undefined>;
571
593
 
572
594
  /**
573
595
  * Hook for fetching intent details by intent hash from the backend API.
@@ -1533,6 +1555,4 @@ interface SodaxProviderProps {
1533
1555
  }
1534
1556
  declare const SodaxProvider: ({ children, testnet, config, rpcConfig }: SodaxProviderProps) => ReactElement;
1535
1557
 
1536
- declare const getSpokeTokenAddressByVault: (spokeChainId: ChainId, vault: string) => string | undefined;
1537
-
1538
- export { MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, type MigrationIntentParams, type MigrationMode, SodaxProvider, getSpokeTokenAddressByVault, useAToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserReservesData, useWithdraw };
1558
+ export { MIGRATION_MODE_BNUSD, MIGRATION_MODE_ICX_SODA, type MigrationIntentParams, type MigrationMode, SodaxProvider, useAToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelSwap, useCancelUnstake, useClaim, useConvertedAssets, useDeriveUserWalletAddress, useEstimateGas, useGetBridgeableAmount, useGetBridgeableTokens, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useMMAllowance, useMMApprove, useMigrate, useMigrationAllowance, useMigrationApprove, useQuote, useRepay, useRequestTrustline, useReservesData, useReservesUsdFormat, useSodaxContext, useSpokeProvider, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSwap, useSwapAllowance, useSwapApprove, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserReservesData, useWithdraw };
package/dist/index.js CHANGED
@@ -374,6 +374,16 @@ function useAToken(aToken) {
374
374
  enabled: !!aToken
375
375
  });
376
376
  }
377
+ function useReservesUsdFormat() {
378
+ const { sodax } = useSodaxContext();
379
+ return reactQuery.useQuery({
380
+ queryKey: ["reservesUsdFormat"],
381
+ queryFn: async () => {
382
+ const reserves = await sodax.moneyMarket.data.getReservesHumanized();
383
+ return sodax.moneyMarket.data.formatReservesUSD(sodax.moneyMarket.data.buildReserveDataWithPrice(reserves));
384
+ }
385
+ });
386
+ }
377
387
  var useQuote = (payload) => {
378
388
  const { sodax } = useSodaxContext();
379
389
  const queryKey = React.useMemo(() => {
@@ -495,7 +505,7 @@ function useCancelSwap(spokeProvider) {
495
505
  }
496
506
  });
497
507
  }
498
- var useBackendIntentByTxHash = (txHash) => {
508
+ var useBackendIntentByTxHash = (txHash, refetchInterval = 1e3) => {
499
509
  const { sodax } = useSodaxContext();
500
510
  return reactQuery.useQuery({
501
511
  queryKey: ["backend", "intent", "txHash", txHash],
@@ -505,6 +515,7 @@ var useBackendIntentByTxHash = (txHash) => {
505
515
  }
506
516
  return sodax.backendApi.getIntentByTxHash(txHash);
507
517
  },
518
+ refetchInterval,
508
519
  enabled: !!txHash && txHash.length > 0,
509
520
  retry: 3
510
521
  });
@@ -1264,18 +1275,10 @@ var SodaxProvider = ({ children, testnet = false, config, rpcConfig }) => {
1264
1275
  const sodax = new sdk.Sodax(config);
1265
1276
  return /* @__PURE__ */ React__default.default.createElement(SodaxContext.Provider, { value: { sodax, testnet, rpcConfig } }, children);
1266
1277
  };
1267
- var getSpokeTokenAddressByVault = (spokeChainId, vault) => {
1268
- const tokens = sdk.hubAssets[spokeChainId];
1269
- const address = Object.keys(tokens).find(
1270
- (tokenAddress) => tokens[tokenAddress].vault.toLowerCase() === vault.toLowerCase()
1271
- );
1272
- return address;
1273
- };
1274
1278
 
1275
1279
  exports.MIGRATION_MODE_BNUSD = MIGRATION_MODE_BNUSD;
1276
1280
  exports.MIGRATION_MODE_ICX_SODA = MIGRATION_MODE_ICX_SODA;
1277
1281
  exports.SodaxProvider = SodaxProvider;
1278
- exports.getSpokeTokenAddressByVault = getSpokeTokenAddressByVault;
1279
1282
  exports.useAToken = useAToken;
1280
1283
  exports.useBackendAllMoneyMarketAssets = useBackendAllMoneyMarketAssets;
1281
1284
  exports.useBackendAllMoneyMarketBorrowers = useBackendAllMoneyMarketBorrowers;
@@ -1312,6 +1315,7 @@ exports.useQuote = useQuote;
1312
1315
  exports.useRepay = useRepay;
1313
1316
  exports.useRequestTrustline = useRequestTrustline;
1314
1317
  exports.useReservesData = useReservesData;
1318
+ exports.useReservesUsdFormat = useReservesUsdFormat;
1315
1319
  exports.useSodaxContext = useSodaxContext;
1316
1320
  exports.useSpokeProvider = useSpokeProvider;
1317
1321
  exports.useStake = useStake;