@oydual31/more-vaults-sdk 1.1.13 → 1.1.14

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.
@@ -414,6 +414,80 @@ interface VaultPortfolio {
414
414
  lockedAssets: bigint;
415
415
  }
416
416
 
417
+ /**
418
+ * Storage adapter interface (async — supports localStorage today, remote tomorrow).
419
+ * Implement this interface to plug in any storage backend.
420
+ */
421
+ interface FlowStorage {
422
+ get(key: string): Promise<string | null>;
423
+ set(key: string, value: string): Promise<void>;
424
+ del(key: string): Promise<void>;
425
+ }
426
+ /**
427
+ * Deposit flow state — discriminated union by phase.
428
+ * Persisted after each phase so the flow can be resumed on reload.
429
+ */
430
+ type DepositFlowState = {
431
+ phase: 'spoke_sent';
432
+ txHash: string;
433
+ /** Partial composeData from depositFromSpoke (message and from resolved later) */
434
+ composeData: Record<string, unknown>;
435
+ /** As decimal string — bigint not JSON-safe */
436
+ startBlock: string;
437
+ vault: string;
438
+ timestamp: number;
439
+ } | {
440
+ phase: 'compose_found';
441
+ /** Full composeData returned by waitForCompose */
442
+ composeData: Record<string, unknown>;
443
+ timestamp: number;
444
+ } | {
445
+ phase: 'hub_sent';
446
+ guid: string;
447
+ vault: string;
448
+ composerSentGuid?: string;
449
+ tokensLocked?: {
450
+ guid: string;
451
+ vault: string;
452
+ token: string;
453
+ amount: string;
454
+ };
455
+ timestamp: number;
456
+ } | {
457
+ phase: 'done';
458
+ };
459
+ /**
460
+ * localStorage-backed FlowStorage adapter.
461
+ * Safe to instantiate in any environment — localStorage is only accessed at call time.
462
+ */
463
+ declare class LocalStorageAdapter implements FlowStorage {
464
+ get(key: string): Promise<string | null>;
465
+ set(key: string, value: string): Promise<void>;
466
+ del(key: string): Promise<void>;
467
+ }
468
+ /**
469
+ * Returns a LocalStorageAdapter when running in a browser environment,
470
+ * or null in Node.js / non-browser environments.
471
+ *
472
+ * Used internally as the default storage — consumers can override by passing
473
+ * their own FlowStorage implementation, or pass null to disable persistence.
474
+ */
475
+ declare function getDefaultStorage(): FlowStorage | null;
476
+ /**
477
+ * Persist the current deposit flow state for a wallet.
478
+ */
479
+ declare function saveDepositFlow(storage: FlowStorage, walletAddress: string, state: DepositFlowState): Promise<void>;
480
+ /**
481
+ * Load a pending deposit flow for a wallet.
482
+ * Returns null if there is no state, the flow is done, or the state is older than 24h.
483
+ */
484
+ declare function loadDepositFlow(storage: FlowStorage, walletAddress: string): Promise<DepositFlowState | null>;
485
+ /**
486
+ * Clear the persisted deposit flow for a wallet.
487
+ * Call this when the flow completes or is explicitly cancelled.
488
+ */
489
+ declare function clearDepositFlow(storage: FlowStorage, walletAddress: string): Promise<void>;
490
+
417
491
  /**
418
492
  * Wait for a transaction receipt with generous timeout and retry logic.
419
493
  *
@@ -606,7 +680,10 @@ declare function waitForAsyncRequest(publicClient: PublicClient, vault: Address,
606
680
  finalized: boolean;
607
681
  refunded: boolean;
608
682
  result: bigint;
609
- }) => void): Promise<AsyncRequestFinalResult>;
683
+ }) => void, options?: {
684
+ storage?: FlowStorage | null;
685
+ walletAddress?: Address;
686
+ }): Promise<AsyncRequestFinalResult>;
610
687
  /**
611
688
  * Detect whether an OFT address is a Stargate V2 pool by calling `stargateType()`.
612
689
  *
@@ -1189,4 +1266,4 @@ declare function quoteCuratorBridgeFee(publicClient: PublicClient, vault: Addres
1189
1266
  */
1190
1267
  declare function executeCuratorBridge(walletClient: WalletClient, publicClient: PublicClient, vault: Address, token: Address, params: CuratorBridgeParams): Promise<Hash>;
1191
1268
 
1192
- export { ensureAllowance as $, type AsyncRequestResult as A, type BatchSwapParams as B, type ComposeData as C, type DepositResult as D, type ERC7540RequestStatus as E, type SpokeBalance as F, type SwapParams as G, type UserPosition as H, type InboundRoute as I, type VaultDistribution as J, type VaultMetadata as K, type VaultMode as L, type MultiChainPortfolio as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, type PendingAction as P, type VaultStatus as Q, type RedeemResult as R, type SpokeDepositResult as S, type VaultSummary as T, type UserBalances as U, type VaultAddresses as V, type VaultTopology as W, canDeposit as X, detectStargateOft as Y, discoverVaultTopology as Z, encodeBridgeParams as _, type CuratorVaultStatus as a, executeCuratorBridge as a0, findBridgeRoute as a1, getAllVaultChainIds as a2, getAsyncRequestStatus as a3, getAsyncRequestStatusLabel as a4, getFullVaultTopology as a5, getInboundRoutes as a6, getMaxWithdrawable as a7, getOutboundRoutes as a8, getUserBalances as a9, getUserBalancesForRoutes as aa, getUserPosition as ab, getUserPositionMultiChain as ac, getVaultDistribution as ad, getVaultDistributionWithTopology as ae, getVaultMetadata as af, getVaultStatus as ag, getVaultSummary as ah, getVaultTopology as ai, isAsyncMode as aj, isOnHubChain as ak, previewDeposit as al, previewRedeem as am, quoteCuratorBridgeFee as an, quoteLzFee as ao, quoteRouteDepositFee as ap, waitForAsyncRequest as aq, waitForTx as ar, type VaultAnalysis as b, type VaultAssetBreakdown as c, type CuratorAction as d, type SubmitActionsResult as e, type VaultConfiguration as f, type SubVaultInfo as g, type SubVaultPosition as h, type VaultPortfolio as i, ActionType as j, type ActionTypeValue as k, type AssetBalance as l, type AssetInfo as m, type AsyncRequestFinalResult as n, type AsyncRequestStatus as o, type AsyncRequestStatusInfo as p, type BridgeParams as q, type ChainPortfolio as r, type CrossChainRequestInfo as s, type CuratorBridgeParams as t, type DepositBlockReason as u, type DepositEligibility as v, type InboundRouteWithBalance as w, type MaxWithdrawable as x, type MultiChainUserPosition as y, type OutboundRoute as z };
1269
+ export { clearDepositFlow as $, type AsyncRequestResult as A, type BatchSwapParams as B, type ComposeData as C, type DepositResult as D, type ERC7540RequestStatus as E, type FlowStorage as F, type OutboundRoute as G, type SpokeBalance as H, type InboundRoute as I, type SwapParams as J, type UserPosition as K, LocalStorageAdapter as L, type MultiChainPortfolio as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, type PendingAction as P, type VaultDistribution as Q, type RedeemResult as R, type SpokeDepositResult as S, type VaultMetadata as T, type UserBalances as U, type VaultAddresses as V, type VaultMode as W, type VaultStatus as X, type VaultSummary as Y, type VaultTopology as Z, canDeposit as _, type CuratorVaultStatus as a, detectStargateOft as a0, discoverVaultTopology as a1, encodeBridgeParams as a2, ensureAllowance as a3, executeCuratorBridge as a4, findBridgeRoute as a5, getAllVaultChainIds as a6, getAsyncRequestStatus as a7, getAsyncRequestStatusLabel as a8, getDefaultStorage as a9, getFullVaultTopology as aa, getInboundRoutes as ab, getMaxWithdrawable as ac, getOutboundRoutes as ad, getUserBalances as ae, getUserBalancesForRoutes as af, getUserPosition as ag, getUserPositionMultiChain as ah, getVaultDistribution as ai, getVaultDistributionWithTopology as aj, getVaultMetadata as ak, getVaultStatus as al, getVaultSummary as am, getVaultTopology as an, isAsyncMode as ao, isOnHubChain as ap, loadDepositFlow as aq, previewDeposit as ar, previewRedeem as as, quoteCuratorBridgeFee as at, quoteLzFee as au, quoteRouteDepositFee as av, saveDepositFlow as aw, waitForAsyncRequest as ax, waitForTx as ay, type VaultAnalysis as b, type VaultAssetBreakdown as c, type CuratorAction as d, type SubmitActionsResult as e, type VaultConfiguration as f, type SubVaultInfo as g, type SubVaultPosition as h, type VaultPortfolio as i, ActionType as j, type ActionTypeValue as k, type AssetBalance as l, type AssetInfo as m, type AsyncRequestFinalResult as n, type AsyncRequestStatus as o, type AsyncRequestStatusInfo as p, type BridgeParams as q, type ChainPortfolio as r, type CrossChainRequestInfo as s, type CuratorBridgeParams as t, type DepositBlockReason as u, type DepositEligibility as v, type DepositFlowState as w, type InboundRouteWithBalance as x, type MaxWithdrawable as y, type MultiChainUserPosition as z };
@@ -414,6 +414,80 @@ interface VaultPortfolio {
414
414
  lockedAssets: bigint;
415
415
  }
416
416
 
417
+ /**
418
+ * Storage adapter interface (async — supports localStorage today, remote tomorrow).
419
+ * Implement this interface to plug in any storage backend.
420
+ */
421
+ interface FlowStorage {
422
+ get(key: string): Promise<string | null>;
423
+ set(key: string, value: string): Promise<void>;
424
+ del(key: string): Promise<void>;
425
+ }
426
+ /**
427
+ * Deposit flow state — discriminated union by phase.
428
+ * Persisted after each phase so the flow can be resumed on reload.
429
+ */
430
+ type DepositFlowState = {
431
+ phase: 'spoke_sent';
432
+ txHash: string;
433
+ /** Partial composeData from depositFromSpoke (message and from resolved later) */
434
+ composeData: Record<string, unknown>;
435
+ /** As decimal string — bigint not JSON-safe */
436
+ startBlock: string;
437
+ vault: string;
438
+ timestamp: number;
439
+ } | {
440
+ phase: 'compose_found';
441
+ /** Full composeData returned by waitForCompose */
442
+ composeData: Record<string, unknown>;
443
+ timestamp: number;
444
+ } | {
445
+ phase: 'hub_sent';
446
+ guid: string;
447
+ vault: string;
448
+ composerSentGuid?: string;
449
+ tokensLocked?: {
450
+ guid: string;
451
+ vault: string;
452
+ token: string;
453
+ amount: string;
454
+ };
455
+ timestamp: number;
456
+ } | {
457
+ phase: 'done';
458
+ };
459
+ /**
460
+ * localStorage-backed FlowStorage adapter.
461
+ * Safe to instantiate in any environment — localStorage is only accessed at call time.
462
+ */
463
+ declare class LocalStorageAdapter implements FlowStorage {
464
+ get(key: string): Promise<string | null>;
465
+ set(key: string, value: string): Promise<void>;
466
+ del(key: string): Promise<void>;
467
+ }
468
+ /**
469
+ * Returns a LocalStorageAdapter when running in a browser environment,
470
+ * or null in Node.js / non-browser environments.
471
+ *
472
+ * Used internally as the default storage — consumers can override by passing
473
+ * their own FlowStorage implementation, or pass null to disable persistence.
474
+ */
475
+ declare function getDefaultStorage(): FlowStorage | null;
476
+ /**
477
+ * Persist the current deposit flow state for a wallet.
478
+ */
479
+ declare function saveDepositFlow(storage: FlowStorage, walletAddress: string, state: DepositFlowState): Promise<void>;
480
+ /**
481
+ * Load a pending deposit flow for a wallet.
482
+ * Returns null if there is no state, the flow is done, or the state is older than 24h.
483
+ */
484
+ declare function loadDepositFlow(storage: FlowStorage, walletAddress: string): Promise<DepositFlowState | null>;
485
+ /**
486
+ * Clear the persisted deposit flow for a wallet.
487
+ * Call this when the flow completes or is explicitly cancelled.
488
+ */
489
+ declare function clearDepositFlow(storage: FlowStorage, walletAddress: string): Promise<void>;
490
+
417
491
  /**
418
492
  * Wait for a transaction receipt with generous timeout and retry logic.
419
493
  *
@@ -606,7 +680,10 @@ declare function waitForAsyncRequest(publicClient: PublicClient, vault: Address,
606
680
  finalized: boolean;
607
681
  refunded: boolean;
608
682
  result: bigint;
609
- }) => void): Promise<AsyncRequestFinalResult>;
683
+ }) => void, options?: {
684
+ storage?: FlowStorage | null;
685
+ walletAddress?: Address;
686
+ }): Promise<AsyncRequestFinalResult>;
610
687
  /**
611
688
  * Detect whether an OFT address is a Stargate V2 pool by calling `stargateType()`.
612
689
  *
@@ -1189,4 +1266,4 @@ declare function quoteCuratorBridgeFee(publicClient: PublicClient, vault: Addres
1189
1266
  */
1190
1267
  declare function executeCuratorBridge(walletClient: WalletClient, publicClient: PublicClient, vault: Address, token: Address, params: CuratorBridgeParams): Promise<Hash>;
1191
1268
 
1192
- export { ensureAllowance as $, type AsyncRequestResult as A, type BatchSwapParams as B, type ComposeData as C, type DepositResult as D, type ERC7540RequestStatus as E, type SpokeBalance as F, type SwapParams as G, type UserPosition as H, type InboundRoute as I, type VaultDistribution as J, type VaultMetadata as K, type VaultMode as L, type MultiChainPortfolio as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, type PendingAction as P, type VaultStatus as Q, type RedeemResult as R, type SpokeDepositResult as S, type VaultSummary as T, type UserBalances as U, type VaultAddresses as V, type VaultTopology as W, canDeposit as X, detectStargateOft as Y, discoverVaultTopology as Z, encodeBridgeParams as _, type CuratorVaultStatus as a, executeCuratorBridge as a0, findBridgeRoute as a1, getAllVaultChainIds as a2, getAsyncRequestStatus as a3, getAsyncRequestStatusLabel as a4, getFullVaultTopology as a5, getInboundRoutes as a6, getMaxWithdrawable as a7, getOutboundRoutes as a8, getUserBalances as a9, getUserBalancesForRoutes as aa, getUserPosition as ab, getUserPositionMultiChain as ac, getVaultDistribution as ad, getVaultDistributionWithTopology as ae, getVaultMetadata as af, getVaultStatus as ag, getVaultSummary as ah, getVaultTopology as ai, isAsyncMode as aj, isOnHubChain as ak, previewDeposit as al, previewRedeem as am, quoteCuratorBridgeFee as an, quoteLzFee as ao, quoteRouteDepositFee as ap, waitForAsyncRequest as aq, waitForTx as ar, type VaultAnalysis as b, type VaultAssetBreakdown as c, type CuratorAction as d, type SubmitActionsResult as e, type VaultConfiguration as f, type SubVaultInfo as g, type SubVaultPosition as h, type VaultPortfolio as i, ActionType as j, type ActionTypeValue as k, type AssetBalance as l, type AssetInfo as m, type AsyncRequestFinalResult as n, type AsyncRequestStatus as o, type AsyncRequestStatusInfo as p, type BridgeParams as q, type ChainPortfolio as r, type CrossChainRequestInfo as s, type CuratorBridgeParams as t, type DepositBlockReason as u, type DepositEligibility as v, type InboundRouteWithBalance as w, type MaxWithdrawable as x, type MultiChainUserPosition as y, type OutboundRoute as z };
1269
+ export { clearDepositFlow as $, type AsyncRequestResult as A, type BatchSwapParams as B, type ComposeData as C, type DepositResult as D, type ERC7540RequestStatus as E, type FlowStorage as F, type OutboundRoute as G, type SpokeBalance as H, type InboundRoute as I, type SwapParams as J, type UserPosition as K, LocalStorageAdapter as L, type MultiChainPortfolio as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, type PendingAction as P, type VaultDistribution as Q, type RedeemResult as R, type SpokeDepositResult as S, type VaultMetadata as T, type UserBalances as U, type VaultAddresses as V, type VaultMode as W, type VaultStatus as X, type VaultSummary as Y, type VaultTopology as Z, canDeposit as _, type CuratorVaultStatus as a, detectStargateOft as a0, discoverVaultTopology as a1, encodeBridgeParams as a2, ensureAllowance as a3, executeCuratorBridge as a4, findBridgeRoute as a5, getAllVaultChainIds as a6, getAsyncRequestStatus as a7, getAsyncRequestStatusLabel as a8, getDefaultStorage as a9, getFullVaultTopology as aa, getInboundRoutes as ab, getMaxWithdrawable as ac, getOutboundRoutes as ad, getUserBalances as ae, getUserBalancesForRoutes as af, getUserPosition as ag, getUserPositionMultiChain as ah, getVaultDistribution as ai, getVaultDistributionWithTopology as aj, getVaultMetadata as ak, getVaultStatus as al, getVaultSummary as am, getVaultTopology as an, isAsyncMode as ao, isOnHubChain as ap, loadDepositFlow as aq, previewDeposit as ar, previewRedeem as as, quoteCuratorBridgeFee as at, quoteLzFee as au, quoteRouteDepositFee as av, saveDepositFlow as aw, waitForAsyncRequest as ax, waitForTx as ay, type VaultAnalysis as b, type VaultAssetBreakdown as c, type CuratorAction as d, type SubmitActionsResult as e, type VaultConfiguration as f, type SubVaultInfo as g, type SubVaultPosition as h, type VaultPortfolio as i, ActionType as j, type ActionTypeValue as k, type AssetBalance as l, type AssetInfo as m, type AsyncRequestFinalResult as n, type AsyncRequestStatus as o, type AsyncRequestStatusInfo as p, type BridgeParams as q, type ChainPortfolio as r, type CrossChainRequestInfo as s, type CuratorBridgeParams as t, type DepositBlockReason as u, type DepositEligibility as v, type DepositFlowState as w, type InboundRouteWithBalance as x, type MaxWithdrawable as y, type MultiChainUserPosition as z };
@@ -1285,6 +1285,8 @@ var UnsupportedAssetError = class extends MoreVaultsError {
1285
1285
  this.asset = asset;
1286
1286
  }
1287
1287
  };
1288
+
1289
+ // src/viem/utils.ts
1288
1290
  async function waitForTx(publicClient, hash, maxRetries = 3) {
1289
1291
  const timeouts = [6e4, 12e4, 18e4];
1290
1292
  for (let i = 0; i < maxRetries; i++) {