@oydual31/more-vaults-sdk 0.2.0 → 0.2.1

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.
@@ -435,6 +435,47 @@ interface UseSmartDepositReturn {
435
435
  */
436
436
  declare function useSmartDeposit(vault: `0x${string}` | undefined, hubChainId: number): UseSmartDepositReturn;
437
437
 
438
+ interface UseSmartRedeemReturn {
439
+ /**
440
+ * Execute redeem using the correct flow for this vault's mode.
441
+ * For async vaults: wraps redeemAsync (R5) — returns guid for tracking.
442
+ * For local/oracle vaults: wraps redeemShares (R1) — returns assets.
443
+ */
444
+ redeem: (sharesInWei: bigint, receiver: `0x${string}`, owner: `0x${string}`) => Promise<void>;
445
+ isLoading: boolean;
446
+ txHash: `0x${string}` | undefined;
447
+ /** Assets received (available for R1 vaults after confirmation, undefined for R5). */
448
+ assets: bigint | undefined;
449
+ /** GUID for cross-chain tracking (R5 vaults only). */
450
+ guid: `0x${string}` | undefined;
451
+ /** Cross-chain request status (R5 vaults only). */
452
+ requestStatus: AsyncRequestStatusInfo | undefined;
453
+ /** true when the wallet is connected to the wrong chain (R5 vaults only). */
454
+ wrongChain: boolean;
455
+ /** Vault mode loaded from getVaultStatus. undefined while loading. */
456
+ vaultMode: 'local' | 'cross-chain-oracle' | 'cross-chain-async' | 'paused' | 'full' | undefined;
457
+ error: Error | undefined;
458
+ reset: () => void;
459
+ }
460
+ /**
461
+ * Auto-selects the correct redeem flow based on vault mode.
462
+ * Best for frontends that support multiple vault types.
463
+ *
464
+ * Internally uses useVaultStatus to detect the mode, then delegates to:
465
+ * - useOmniRedeem (R5) for 'cross-chain-async' vaults
466
+ * - useRedeemShares (R1) for 'local' and 'cross-chain-oracle' vaults
467
+ *
468
+ * @example
469
+ * const { redeem, isLoading, guid, requestStatus, vaultMode } = useSmartRedeem('0xVAULT', 8453)
470
+ *
471
+ * if (vaultMode === 'paused') return <PausedBadge />
472
+ *
473
+ * await redeem(sharesInWei, userAddress, userAddress)
474
+ * // For async vaults: poll requestStatus until 'completed'
475
+ * // For sync vaults: txHash + assets are available immediately
476
+ */
477
+ declare function useSmartRedeem(vault: `0x${string}` | undefined, hubChainId: number): UseSmartRedeemReturn;
478
+
438
479
  interface UseInboundRoutesReturn {
439
480
  routes: InboundRouteWithBalance[];
440
481
  isLoading: boolean;
@@ -478,4 +519,4 @@ declare function getRouteTokenDecimals(symbol: string): number;
478
519
  */
479
520
  declare function useInboundRoutes(hubChainId: number | undefined, vault: Address | undefined, vaultAsset: Address | undefined, userAddress: Address | undefined): UseInboundRoutesReturn;
480
521
 
481
- export { AsyncRequestStatusInfo, UserPosition, VaultMetadata, VaultStatus, VaultTopology, getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
522
+ export { AsyncRequestStatusInfo, UserPosition, VaultMetadata, VaultStatus, VaultTopology, getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
@@ -435,6 +435,47 @@ interface UseSmartDepositReturn {
435
435
  */
436
436
  declare function useSmartDeposit(vault: `0x${string}` | undefined, hubChainId: number): UseSmartDepositReturn;
437
437
 
438
+ interface UseSmartRedeemReturn {
439
+ /**
440
+ * Execute redeem using the correct flow for this vault's mode.
441
+ * For async vaults: wraps redeemAsync (R5) — returns guid for tracking.
442
+ * For local/oracle vaults: wraps redeemShares (R1) — returns assets.
443
+ */
444
+ redeem: (sharesInWei: bigint, receiver: `0x${string}`, owner: `0x${string}`) => Promise<void>;
445
+ isLoading: boolean;
446
+ txHash: `0x${string}` | undefined;
447
+ /** Assets received (available for R1 vaults after confirmation, undefined for R5). */
448
+ assets: bigint | undefined;
449
+ /** GUID for cross-chain tracking (R5 vaults only). */
450
+ guid: `0x${string}` | undefined;
451
+ /** Cross-chain request status (R5 vaults only). */
452
+ requestStatus: AsyncRequestStatusInfo | undefined;
453
+ /** true when the wallet is connected to the wrong chain (R5 vaults only). */
454
+ wrongChain: boolean;
455
+ /** Vault mode loaded from getVaultStatus. undefined while loading. */
456
+ vaultMode: 'local' | 'cross-chain-oracle' | 'cross-chain-async' | 'paused' | 'full' | undefined;
457
+ error: Error | undefined;
458
+ reset: () => void;
459
+ }
460
+ /**
461
+ * Auto-selects the correct redeem flow based on vault mode.
462
+ * Best for frontends that support multiple vault types.
463
+ *
464
+ * Internally uses useVaultStatus to detect the mode, then delegates to:
465
+ * - useOmniRedeem (R5) for 'cross-chain-async' vaults
466
+ * - useRedeemShares (R1) for 'local' and 'cross-chain-oracle' vaults
467
+ *
468
+ * @example
469
+ * const { redeem, isLoading, guid, requestStatus, vaultMode } = useSmartRedeem('0xVAULT', 8453)
470
+ *
471
+ * if (vaultMode === 'paused') return <PausedBadge />
472
+ *
473
+ * await redeem(sharesInWei, userAddress, userAddress)
474
+ * // For async vaults: poll requestStatus until 'completed'
475
+ * // For sync vaults: txHash + assets are available immediately
476
+ */
477
+ declare function useSmartRedeem(vault: `0x${string}` | undefined, hubChainId: number): UseSmartRedeemReturn;
478
+
438
479
  interface UseInboundRoutesReturn {
439
480
  routes: InboundRouteWithBalance[];
440
481
  isLoading: boolean;
@@ -478,4 +519,4 @@ declare function getRouteTokenDecimals(symbol: string): number;
478
519
  */
479
520
  declare function useInboundRoutes(hubChainId: number | undefined, vault: Address | undefined, vaultAsset: Address | undefined, userAddress: Address | undefined): UseInboundRoutesReturn;
480
521
 
481
- export { AsyncRequestStatusInfo, UserPosition, VaultMetadata, VaultStatus, VaultTopology, getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
522
+ export { AsyncRequestStatusInfo, UserPosition, VaultMetadata, VaultStatus, VaultTopology, getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
@@ -2017,6 +2017,27 @@ function useSmartDeposit(vault, hubChainId) {
2017
2017
  reset: isAsync ? omni.reset : simple.reset
2018
2018
  };
2019
2019
  }
2020
+
2021
+ // src/react/useSmartRedeem.ts
2022
+ function useSmartRedeem(vault, hubChainId) {
2023
+ const { data: status } = useVaultStatus(vault, hubChainId);
2024
+ const omni = useOmniRedeem(vault, hubChainId);
2025
+ const simple = useRedeemShares(vault, hubChainId);
2026
+ const isAsync = status?.mode === "cross-chain-async";
2027
+ const redeem = isAsync ? omni.redeem : simple.redeem;
2028
+ return {
2029
+ redeem,
2030
+ isLoading: isAsync ? omni.isLoading : simple.isLoading,
2031
+ txHash: isAsync ? omni.txHash : simple.txHash,
2032
+ assets: isAsync ? void 0 : simple.assets,
2033
+ guid: isAsync ? omni.guid : void 0,
2034
+ requestStatus: isAsync ? omni.requestStatus : void 0,
2035
+ wrongChain: isAsync ? omni.wrongChain : false,
2036
+ vaultMode: status?.mode,
2037
+ error: isAsync ? omni.error : simple.error,
2038
+ reset: isAsync ? omni.reset : simple.reset
2039
+ };
2040
+ }
2020
2041
  function getRouteTokenDecimals(symbol) {
2021
2042
  switch (symbol) {
2022
2043
  case "stgUSDC":
@@ -2046,6 +2067,6 @@ function useInboundRoutes(hubChainId, vault, vaultAsset, userAddress) {
2046
2067
  };
2047
2068
  }
2048
2069
 
2049
- export { getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
2070
+ export { getRouteTokenDecimals, useAsyncRequestStatus, useDepositSimple, useInboundRoutes, useLzFee, useOmniDeposit, useOmniRedeem, useRedeemShares, useSmartDeposit, useSmartRedeem, useUserPosition, useVaultDistribution, useVaultMetadata, useVaultStatus, useVaultTopology };
2050
2071
  //# sourceMappingURL=index.js.map
2051
2072
  //# sourceMappingURL=index.js.map