@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.
@@ -25,6 +25,24 @@ declare const LZ_EIDS: {
25
25
  declare const EID_TO_CHAIN_ID: Record<number, number>;
26
26
  /** EVM Chain ID → LayerZero EID */
27
27
  declare const CHAIN_ID_TO_EID: Record<number, number>;
28
+ /**
29
+ * Recommended timeouts for cross-chain operations (milliseconds).
30
+ * UIs should show a progress indicator and NOT timeout before these values.
31
+ */
32
+ declare const LZ_TIMEOUTS: {
33
+ /** Poll interval between balance/event checks */
34
+ readonly POLL_INTERVAL: 30000;
35
+ /** Standard OFT bridge (shares or assets, non-Stargate) */
36
+ readonly OFT_BRIDGE: 900000;
37
+ /** Stargate bridge (USDC, USDT, WETH) — slower due to pool mechanics */
38
+ readonly STARGATE_BRIDGE: 1800000;
39
+ /** LZ Read callback (async vault actions) */
40
+ readonly LZ_READ_CALLBACK: 900000;
41
+ /** Compose delivery to hub (deposit from spoke) */
42
+ readonly COMPOSE_DELIVERY: 2700000;
43
+ /** Full spoke→hub→spoke redeem (all steps combined) */
44
+ readonly FULL_SPOKE_REDEEM: 3600000;
45
+ };
28
46
 
29
47
  /** Addresses involved in vault operations. */
30
48
  interface VaultAddresses {
@@ -410,6 +428,42 @@ declare function redeemAsync(signer: Signer, addresses: VaultAddresses, shares:
410
428
  declare function bridgeSharesToHub(signer: Signer, shareOFT: string, hubChainEid: number, shares: bigint, receiver: string, lzFee: bigint): Promise<{
411
429
  receipt: ContractTransactionReceipt;
412
430
  }>;
431
+ /**
432
+ * Smart redeem — auto-selects the correct flow based on vault configuration.
433
+ *
434
+ * Detects the vault mode and dispatches to:
435
+ * - Sync vaults (local / cross-chain-oracle): `redeemShares`
436
+ * - Async vaults (cross-chain, oracle OFF): `redeemAsync` (quotes LZ fee automatically)
437
+ *
438
+ * @param signer Wallet signer with account attached
439
+ * @param addresses Vault address set (`escrow` required for async vaults)
440
+ * @param shares Amount of shares to redeem
441
+ * @param receiver Address that will receive the underlying assets
442
+ * @param owner Owner of the shares being redeemed
443
+ * @param extraOptions Optional LZ extra options (only used for async vaults)
444
+ * @returns RedeemResult or AsyncRequestResult depending on vault mode
445
+ */
446
+ declare function smartRedeem(signer: Signer, addresses: VaultAddresses, shares: bigint, receiver: string, owner: string, extraOptions?: string): Promise<RedeemResult | AsyncRequestResult>;
447
+ /**
448
+ * Bridge underlying assets from hub back to spoke chain via OFT.
449
+ *
450
+ * Step 3 of the full spoke redeem flow:
451
+ * 1. bridgeSharesToHub() — shares spoke->hub
452
+ * 2. smartRedeem() — redeem on hub
453
+ * 3. bridgeAssetsToSpoke() — assets hub->spoke
454
+ *
455
+ * @param signer Wallet signer on the HUB chain
456
+ * @param assetOFT OFT address for the underlying asset on hub
457
+ * @param spokeChainEid LayerZero EID for the spoke (destination) chain
458
+ * @param amount Amount of underlying assets to bridge
459
+ * @param receiver Receiver address on the spoke chain
460
+ * @param lzFee OFT send fee (quote via OFT.quoteSend)
461
+ * @param isStargate Whether this is a Stargate OFT (uses TAXI mode)
462
+ * @returns Transaction receipt
463
+ */
464
+ declare function bridgeAssetsToSpoke(signer: Signer, assetOFT: string, spokeChainEid: number, amount: bigint, receiver: string, lzFee: bigint, isStargate?: boolean): Promise<{
465
+ receipt: ContractTransactionReceipt;
466
+ }>;
413
467
 
414
468
  /**
415
469
  * Utility helpers for the MoreVaults ethers.js v6 SDK.
@@ -741,4 +795,4 @@ declare function getVaultSummary(provider: Provider, vault: string): Promise<Vau
741
795
  */
742
796
  declare function asSdkSigner(signer: unknown): Signer;
743
797
 
744
- export { ActionType, type ActionTypeValue, type AsyncRequestResult, type AsyncRequestStatus, type AsyncRequestStatusInfo, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, type CrossChainRequestInfo, type DepositBlockReason, type DepositEligibility, type DepositResult, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, LZ_ENDPOINT_ABI, METADATA_ABI, type MaxWithdrawable, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, type RedeemResult, type UserBalances, type UserPosition, VAULT_ABI, type VaultAddresses, type VaultMetadata, type VaultMode, VaultPausedError, type VaultStatus, type VaultSummary, WrongChainError, asSdkSigner, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, executeCompose, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
798
+ export { ActionType, type ActionTypeValue, type AsyncRequestResult, type AsyncRequestStatus, type AsyncRequestStatusInfo, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, type CrossChainRequestInfo, type DepositBlockReason, type DepositEligibility, type DepositResult, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, type MaxWithdrawable, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, type RedeemResult, type UserBalances, type UserPosition, VAULT_ABI, type VaultAddresses, type VaultMetadata, type VaultMode, VaultPausedError, type VaultStatus, type VaultSummary, WrongChainError, asSdkSigner, bridgeAssetsToSpoke, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, executeCompose, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, smartRedeem, withdrawAssets };
@@ -25,6 +25,24 @@ declare const LZ_EIDS: {
25
25
  declare const EID_TO_CHAIN_ID: Record<number, number>;
26
26
  /** EVM Chain ID → LayerZero EID */
27
27
  declare const CHAIN_ID_TO_EID: Record<number, number>;
28
+ /**
29
+ * Recommended timeouts for cross-chain operations (milliseconds).
30
+ * UIs should show a progress indicator and NOT timeout before these values.
31
+ */
32
+ declare const LZ_TIMEOUTS: {
33
+ /** Poll interval between balance/event checks */
34
+ readonly POLL_INTERVAL: 30000;
35
+ /** Standard OFT bridge (shares or assets, non-Stargate) */
36
+ readonly OFT_BRIDGE: 900000;
37
+ /** Stargate bridge (USDC, USDT, WETH) — slower due to pool mechanics */
38
+ readonly STARGATE_BRIDGE: 1800000;
39
+ /** LZ Read callback (async vault actions) */
40
+ readonly LZ_READ_CALLBACK: 900000;
41
+ /** Compose delivery to hub (deposit from spoke) */
42
+ readonly COMPOSE_DELIVERY: 2700000;
43
+ /** Full spoke→hub→spoke redeem (all steps combined) */
44
+ readonly FULL_SPOKE_REDEEM: 3600000;
45
+ };
28
46
 
29
47
  /** Addresses involved in vault operations. */
30
48
  interface VaultAddresses {
@@ -410,6 +428,42 @@ declare function redeemAsync(signer: Signer, addresses: VaultAddresses, shares:
410
428
  declare function bridgeSharesToHub(signer: Signer, shareOFT: string, hubChainEid: number, shares: bigint, receiver: string, lzFee: bigint): Promise<{
411
429
  receipt: ContractTransactionReceipt;
412
430
  }>;
431
+ /**
432
+ * Smart redeem — auto-selects the correct flow based on vault configuration.
433
+ *
434
+ * Detects the vault mode and dispatches to:
435
+ * - Sync vaults (local / cross-chain-oracle): `redeemShares`
436
+ * - Async vaults (cross-chain, oracle OFF): `redeemAsync` (quotes LZ fee automatically)
437
+ *
438
+ * @param signer Wallet signer with account attached
439
+ * @param addresses Vault address set (`escrow` required for async vaults)
440
+ * @param shares Amount of shares to redeem
441
+ * @param receiver Address that will receive the underlying assets
442
+ * @param owner Owner of the shares being redeemed
443
+ * @param extraOptions Optional LZ extra options (only used for async vaults)
444
+ * @returns RedeemResult or AsyncRequestResult depending on vault mode
445
+ */
446
+ declare function smartRedeem(signer: Signer, addresses: VaultAddresses, shares: bigint, receiver: string, owner: string, extraOptions?: string): Promise<RedeemResult | AsyncRequestResult>;
447
+ /**
448
+ * Bridge underlying assets from hub back to spoke chain via OFT.
449
+ *
450
+ * Step 3 of the full spoke redeem flow:
451
+ * 1. bridgeSharesToHub() — shares spoke->hub
452
+ * 2. smartRedeem() — redeem on hub
453
+ * 3. bridgeAssetsToSpoke() — assets hub->spoke
454
+ *
455
+ * @param signer Wallet signer on the HUB chain
456
+ * @param assetOFT OFT address for the underlying asset on hub
457
+ * @param spokeChainEid LayerZero EID for the spoke (destination) chain
458
+ * @param amount Amount of underlying assets to bridge
459
+ * @param receiver Receiver address on the spoke chain
460
+ * @param lzFee OFT send fee (quote via OFT.quoteSend)
461
+ * @param isStargate Whether this is a Stargate OFT (uses TAXI mode)
462
+ * @returns Transaction receipt
463
+ */
464
+ declare function bridgeAssetsToSpoke(signer: Signer, assetOFT: string, spokeChainEid: number, amount: bigint, receiver: string, lzFee: bigint, isStargate?: boolean): Promise<{
465
+ receipt: ContractTransactionReceipt;
466
+ }>;
413
467
 
414
468
  /**
415
469
  * Utility helpers for the MoreVaults ethers.js v6 SDK.
@@ -741,4 +795,4 @@ declare function getVaultSummary(provider: Provider, vault: string): Promise<Vau
741
795
  */
742
796
  declare function asSdkSigner(signer: unknown): Signer;
743
797
 
744
- export { ActionType, type ActionTypeValue, type AsyncRequestResult, type AsyncRequestStatus, type AsyncRequestStatusInfo, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, type CrossChainRequestInfo, type DepositBlockReason, type DepositEligibility, type DepositResult, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, LZ_ENDPOINT_ABI, METADATA_ABI, type MaxWithdrawable, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, type RedeemResult, type UserBalances, type UserPosition, VAULT_ABI, type VaultAddresses, type VaultMetadata, type VaultMode, VaultPausedError, type VaultStatus, type VaultSummary, WrongChainError, asSdkSigner, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, executeCompose, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
798
+ export { ActionType, type ActionTypeValue, type AsyncRequestResult, type AsyncRequestStatus, type AsyncRequestStatusInfo, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, type CrossChainRequestInfo, type DepositBlockReason, type DepositEligibility, type DepositResult, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, type MaxWithdrawable, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, type RedeemResult, type UserBalances, type UserPosition, VAULT_ABI, type VaultAddresses, type VaultMetadata, type VaultMode, VaultPausedError, type VaultStatus, type VaultSummary, WrongChainError, asSdkSigner, bridgeAssetsToSpoke, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, executeCompose, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, smartRedeem, withdrawAssets };
@@ -29,6 +29,25 @@ var CHAIN_ID_TO_EID = {
29
29
  [CHAIN_IDS.base]: LZ_EIDS.base,
30
30
  [CHAIN_IDS.ethereum]: LZ_EIDS.ethereum
31
31
  };
32
+ var LZ_TIMEOUTS = {
33
+ /** Poll interval between balance/event checks */
34
+ POLL_INTERVAL: 3e4,
35
+ /** Standard OFT bridge (shares or assets, non-Stargate) */
36
+ OFT_BRIDGE: 9e5,
37
+ // 15 min
38
+ /** Stargate bridge (USDC, USDT, WETH) — slower due to pool mechanics */
39
+ STARGATE_BRIDGE: 18e5,
40
+ // 30 min
41
+ /** LZ Read callback (async vault actions) */
42
+ LZ_READ_CALLBACK: 9e5,
43
+ // 15 min
44
+ /** Compose delivery to hub (deposit from spoke) */
45
+ COMPOSE_DELIVERY: 27e5,
46
+ // 45 min
47
+ /** Full spoke→hub→spoke redeem (all steps combined) */
48
+ FULL_SPOKE_REDEEM: 36e5
49
+ // 60 min
50
+ };
32
51
 
33
52
  // src/ethers/types.ts
34
53
  var ActionType = {
@@ -825,6 +844,46 @@ async function bridgeSharesToHub(signer, shareOFT, hubChainEid, shares, receiver
825
844
  const receipt = await tx.wait();
826
845
  return { receipt };
827
846
  }
847
+ async function smartRedeem(signer, addresses, shares, receiver, owner, extraOptions = "0x") {
848
+ const provider = signer.provider;
849
+ const vault = addresses.vault;
850
+ const status = await getVaultStatus(provider, vault);
851
+ if (status.mode === "paused") {
852
+ throw new Error(`[MoreVaults] Vault ${vault} is paused. Cannot redeem.`);
853
+ }
854
+ if (status.recommendedDepositFlow === "depositAsync") {
855
+ const lzFee = await quoteLzFee(provider, vault, extraOptions);
856
+ return redeemAsync(signer, addresses, shares, receiver, owner, lzFee, extraOptions);
857
+ }
858
+ return redeemShares(signer, addresses, shares, receiver, owner);
859
+ }
860
+ async function bridgeAssetsToSpoke(signer, assetOFT, spokeChainEid, amount, receiver, lzFee, isStargate = true) {
861
+ const oft = new Contract(assetOFT, OFT_ABI, signer);
862
+ const token = await oft.token();
863
+ if (token.toLowerCase() !== assetOFT.toLowerCase()) {
864
+ await ensureAllowance4(signer, token, assetOFT, amount);
865
+ } else {
866
+ await ensureAllowance4(signer, assetOFT, assetOFT, amount);
867
+ }
868
+ const refundAddress = await signer.getAddress();
869
+ const toBytes32 = zeroPadValue(receiver, 32);
870
+ const sendParam = {
871
+ dstEid: spokeChainEid,
872
+ to: toBytes32,
873
+ amountLD: amount,
874
+ minAmountLD: amount * 99n / 100n,
875
+ // 1% slippage for Stargate
876
+ extraOptions: "0x",
877
+ composeMsg: "0x",
878
+ oftCmd: isStargate ? "0x01" : "0x"
879
+ };
880
+ const msgFee = { nativeFee: lzFee, lzTokenFee: 0n };
881
+ const tx = await oft.send(sendParam, msgFee, refundAddress, {
882
+ value: lzFee
883
+ });
884
+ const receipt = await tx.wait();
885
+ return { receipt };
886
+ }
828
887
  var MULTICALL3_ADDRESS2 = "0xcA11bde05977b3631167028862bE2a173976CA11";
829
888
  var MULTICALL3_ABI2 = [
830
889
  "function aggregate3(tuple(address target, bool allowFailure, bytes callData)[] calls) payable returns (tuple(bool success, bytes returnData)[] returnData)"
@@ -1042,6 +1101,6 @@ function asSdkSigner(signer) {
1042
1101
  return signer;
1043
1102
  }
1044
1103
 
1045
- export { ActionType, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, LZ_ENDPOINT_ABI, METADATA_ABI, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, VAULT_ABI, VaultPausedError, WrongChainError, asSdkSigner, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, executeCompose, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
1104
+ export { ActionType, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, VAULT_ABI, VaultPausedError, WrongChainError, asSdkSigner, bridgeAssetsToSpoke, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, executeCompose, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, smartRedeem, withdrawAssets };
1046
1105
  //# sourceMappingURL=index.js.map
1047
1106
  //# sourceMappingURL=index.js.map