@oydual31/more-vaults-sdk 0.1.0 → 0.1.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.
@@ -1,6 +1,27 @@
1
1
  import { ContractTransactionReceipt, Signer, Provider } from 'ethers';
2
2
  export { ContractTransactionReceipt, Provider, Signer } from 'ethers';
3
3
 
4
+ /** EVM Chain IDs for chains supported by MoreVaults */
5
+ declare const CHAIN_IDS: {
6
+ readonly flowEVMMainnet: 747;
7
+ readonly flowEVMTestnet: 545;
8
+ readonly arbitrum: 42161;
9
+ readonly base: 8453;
10
+ readonly ethereum: 1;
11
+ };
12
+ /** LayerZero Endpoint IDs (EID) for chains supported by MoreVaults */
13
+ declare const LZ_EIDS: {
14
+ readonly flowMainnet: 30332;
15
+ readonly flowTestnet: 30333;
16
+ readonly arbitrum: 30110;
17
+ readonly base: 30184;
18
+ readonly ethereum: 30101;
19
+ };
20
+ /** LayerZero EID → EVM Chain ID */
21
+ declare const EID_TO_CHAIN_ID: Record<number, number>;
22
+ /** EVM Chain ID → LayerZero EID */
23
+ declare const CHAIN_ID_TO_EID: Record<number, number>;
24
+
4
25
  /** Addresses involved in vault operations. */
5
26
  interface VaultAddresses {
6
27
  /** Hub vault (diamond proxy) address. */
@@ -11,6 +32,12 @@ interface VaultAddresses {
11
32
  shareOFT?: string;
12
33
  /** OFT address for USDC bridging (cross-chain only). */
13
34
  usdcOFT?: string;
35
+ /**
36
+ * Expected EVM chain ID of the hub. When provided, SDK functions will
37
+ * throw a clear WrongChainError if the signer is on a different chain.
38
+ * Prevents silent failures when MetaMask is connected to the wrong network.
39
+ */
40
+ hubChainId?: number;
14
41
  }
15
42
  /** Result of a synchronous deposit or mint. */
16
43
  interface DepositResult {
@@ -107,6 +134,9 @@ declare class NotHubVaultError extends MoreVaultsError {
107
134
  declare class MissingEscrowAddressError extends MoreVaultsError {
108
135
  constructor();
109
136
  }
137
+ declare class WrongChainError extends MoreVaultsError {
138
+ constructor(currentChainId: number, expectedChainId: number);
139
+ }
110
140
 
111
141
  /**
112
142
  * Deposit `assets` of the vault's underlying token and receive shares.
@@ -668,4 +698,17 @@ type VaultSummary = VaultStatus & VaultMetadata;
668
698
  */
669
699
  declare function getVaultSummary(provider: Provider, vault: string): Promise<VaultSummary>;
670
700
 
671
- export { ActionType, type ActionTypeValue, type AsyncRequestResult, type AsyncRequestStatus, type AsyncRequestStatusInfo, BRIDGE_ABI, CCManagerNotConfiguredError, CONFIG_ABI, CapacityFullError, type CrossChainRequestInfo, type DepositBlockReason, type DepositEligibility, type DepositResult, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, 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, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
701
+ /**
702
+ * Cast an ethers Signer (e.g. from wagmi's useEthersSigner adapter) to
703
+ * the SDK's expected type. Use this to avoid `as any` casts:
704
+ * ```ts
705
+ * import { useEthersSigner } from './wagmi-ethers-adapter'
706
+ * import { asSdkSigner } from '@oydual31/more-vaults-sdk/ethers'
707
+ * const signer = asSdkSigner(useEthersSigner())
708
+ * ```
709
+ * This function validates the signer is non-null and applies a documented
710
+ * cast instead of an opaque `as any`.
711
+ */
712
+ declare function asSdkSigner(signer: unknown): Signer;
713
+
714
+ 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, 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, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
@@ -1,6 +1,27 @@
1
1
  import { ContractTransactionReceipt, Signer, Provider } from 'ethers';
2
2
  export { ContractTransactionReceipt, Provider, Signer } from 'ethers';
3
3
 
4
+ /** EVM Chain IDs for chains supported by MoreVaults */
5
+ declare const CHAIN_IDS: {
6
+ readonly flowEVMMainnet: 747;
7
+ readonly flowEVMTestnet: 545;
8
+ readonly arbitrum: 42161;
9
+ readonly base: 8453;
10
+ readonly ethereum: 1;
11
+ };
12
+ /** LayerZero Endpoint IDs (EID) for chains supported by MoreVaults */
13
+ declare const LZ_EIDS: {
14
+ readonly flowMainnet: 30332;
15
+ readonly flowTestnet: 30333;
16
+ readonly arbitrum: 30110;
17
+ readonly base: 30184;
18
+ readonly ethereum: 30101;
19
+ };
20
+ /** LayerZero EID → EVM Chain ID */
21
+ declare const EID_TO_CHAIN_ID: Record<number, number>;
22
+ /** EVM Chain ID → LayerZero EID */
23
+ declare const CHAIN_ID_TO_EID: Record<number, number>;
24
+
4
25
  /** Addresses involved in vault operations. */
5
26
  interface VaultAddresses {
6
27
  /** Hub vault (diamond proxy) address. */
@@ -11,6 +32,12 @@ interface VaultAddresses {
11
32
  shareOFT?: string;
12
33
  /** OFT address for USDC bridging (cross-chain only). */
13
34
  usdcOFT?: string;
35
+ /**
36
+ * Expected EVM chain ID of the hub. When provided, SDK functions will
37
+ * throw a clear WrongChainError if the signer is on a different chain.
38
+ * Prevents silent failures when MetaMask is connected to the wrong network.
39
+ */
40
+ hubChainId?: number;
14
41
  }
15
42
  /** Result of a synchronous deposit or mint. */
16
43
  interface DepositResult {
@@ -107,6 +134,9 @@ declare class NotHubVaultError extends MoreVaultsError {
107
134
  declare class MissingEscrowAddressError extends MoreVaultsError {
108
135
  constructor();
109
136
  }
137
+ declare class WrongChainError extends MoreVaultsError {
138
+ constructor(currentChainId: number, expectedChainId: number);
139
+ }
110
140
 
111
141
  /**
112
142
  * Deposit `assets` of the vault's underlying token and receive shares.
@@ -668,4 +698,17 @@ type VaultSummary = VaultStatus & VaultMetadata;
668
698
  */
669
699
  declare function getVaultSummary(provider: Provider, vault: string): Promise<VaultSummary>;
670
700
 
671
- export { ActionType, type ActionTypeValue, type AsyncRequestResult, type AsyncRequestStatus, type AsyncRequestStatusInfo, BRIDGE_ABI, CCManagerNotConfiguredError, CONFIG_ABI, CapacityFullError, type CrossChainRequestInfo, type DepositBlockReason, type DepositEligibility, type DepositResult, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, 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, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
701
+ /**
702
+ * Cast an ethers Signer (e.g. from wagmi's useEthersSigner adapter) to
703
+ * the SDK's expected type. Use this to avoid `as any` casts:
704
+ * ```ts
705
+ * import { useEthersSigner } from './wagmi-ethers-adapter'
706
+ * import { asSdkSigner } from '@oydual31/more-vaults-sdk/ethers'
707
+ * const signer = asSdkSigner(useEthersSigner())
708
+ * ```
709
+ * This function validates the signer is non-null and applies a documented
710
+ * cast instead of an opaque `as any`.
711
+ */
712
+ declare function asSdkSigner(signer: unknown): Signer;
713
+
714
+ 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, 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, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
@@ -1,5 +1,35 @@
1
1
  import { Contract, ZeroAddress, Interface, AbiCoder, zeroPadValue } from 'ethers';
2
2
 
3
+ // src/ethers/chains.ts
4
+ var CHAIN_IDS = {
5
+ flowEVMMainnet: 747,
6
+ flowEVMTestnet: 545,
7
+ arbitrum: 42161,
8
+ base: 8453,
9
+ ethereum: 1
10
+ };
11
+ var LZ_EIDS = {
12
+ flowMainnet: 30332,
13
+ flowTestnet: 30333,
14
+ arbitrum: 30110,
15
+ base: 30184,
16
+ ethereum: 30101
17
+ };
18
+ var EID_TO_CHAIN_ID = {
19
+ [LZ_EIDS.flowMainnet]: CHAIN_IDS.flowEVMMainnet,
20
+ [LZ_EIDS.flowTestnet]: CHAIN_IDS.flowEVMTestnet,
21
+ [LZ_EIDS.arbitrum]: CHAIN_IDS.arbitrum,
22
+ [LZ_EIDS.base]: CHAIN_IDS.base,
23
+ [LZ_EIDS.ethereum]: CHAIN_IDS.ethereum
24
+ };
25
+ var CHAIN_ID_TO_EID = {
26
+ [CHAIN_IDS.flowEVMMainnet]: LZ_EIDS.flowMainnet,
27
+ [CHAIN_IDS.flowEVMTestnet]: LZ_EIDS.flowTestnet,
28
+ [CHAIN_IDS.arbitrum]: LZ_EIDS.arbitrum,
29
+ [CHAIN_IDS.base]: LZ_EIDS.base,
30
+ [CHAIN_IDS.ethereum]: LZ_EIDS.ethereum
31
+ };
32
+
3
33
  // src/ethers/types.ts
4
34
  var ActionType = {
5
35
  DEPOSIT: 0,
@@ -145,6 +175,14 @@ var MissingEscrowAddressError = class extends MoreVaultsError {
145
175
  this.name = "MissingEscrowAddressError";
146
176
  }
147
177
  };
178
+ var WrongChainError = class extends MoreVaultsError {
179
+ constructor(currentChainId, expectedChainId) {
180
+ super(
181
+ `Wrong network: wallet is on chain ${currentChainId}, but the vault hub requires chain ${expectedChainId}. Switch networks before proceeding.`
182
+ );
183
+ this.name = "WrongChainError";
184
+ }
185
+ };
148
186
  async function preflightAsync(provider, vault, escrow) {
149
187
  const config = new Contract(vault, CONFIG_ABI, provider);
150
188
  const bridge = new Contract(vault, BRIDGE_ABI, provider);
@@ -216,6 +254,17 @@ async function preflightSync(provider, vault) {
216
254
  );
217
255
  }
218
256
  }
257
+
258
+ // src/ethers/chainValidation.ts
259
+ async function validateWalletChain(signer, hubChainId) {
260
+ if (!hubChainId) return;
261
+ const network = await signer.provider?.getNetwork();
262
+ if (!network) return;
263
+ const current = Number(network.chainId);
264
+ if (current !== hubChainId) {
265
+ throw new WrongChainError(current, hubChainId);
266
+ }
267
+ }
219
268
  var MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
220
269
  var MULTICALL3_ABI = [
221
270
  "function aggregate3(tuple(address target, bool allowFailure, bytes callData)[] calls) payable returns (tuple(bool success, bytes returnData)[] returnData)"
@@ -407,6 +456,7 @@ async function ensureAllowance2(signer, token, spender, amount) {
407
456
  }
408
457
  async function depositSimple(signer, addresses, assets, receiver) {
409
458
  const provider = signer.provider;
459
+ await validateWalletChain(signer, addresses.hubChainId);
410
460
  await preflightSync(provider, addresses.vault);
411
461
  const vault = new Contract(addresses.vault, VAULT_ABI, signer);
412
462
  const underlying = await vault.asset();
@@ -430,6 +480,7 @@ async function depositSimple(signer, addresses, assets, receiver) {
430
480
  return { receipt, shares };
431
481
  }
432
482
  async function depositMultiAsset(signer, addresses, tokens, amounts, receiver, minShares) {
483
+ await validateWalletChain(signer, addresses.hubChainId);
433
484
  for (let i = 0; i < tokens.length; i++) {
434
485
  await ensureAllowance2(signer, tokens[i], addresses.vault, amounts[i]);
435
486
  }
@@ -457,6 +508,7 @@ async function depositAsync(signer, addresses, assets, receiver, lzFee, extraOpt
457
508
  const provider = signer.provider;
458
509
  if (!addresses.escrow) throw new MissingEscrowAddressError();
459
510
  const escrow = addresses.escrow;
511
+ await validateWalletChain(signer, addresses.hubChainId);
460
512
  await preflightAsync(provider, addresses.vault);
461
513
  const vault = new Contract(addresses.vault, VAULT_ABI, signer);
462
514
  const underlying = await vault.asset();
@@ -489,6 +541,7 @@ async function mintAsync(signer, addresses, shares, maxAssets, receiver, lzFee,
489
541
  const provider = signer.provider;
490
542
  if (!addresses.escrow) throw new MissingEscrowAddressError();
491
543
  const escrow = addresses.escrow;
544
+ await validateWalletChain(signer, addresses.hubChainId);
492
545
  await preflightAsync(provider, addresses.vault);
493
546
  const vault = new Contract(addresses.vault, VAULT_ABI, signer);
494
547
  const underlying = await vault.asset();
@@ -629,6 +682,7 @@ async function ensureAllowance4(signer, token, spender, amount) {
629
682
  }
630
683
  }
631
684
  async function redeemShares(signer, addresses, shares, receiver, owner) {
685
+ await validateWalletChain(signer, addresses.hubChainId);
632
686
  const vault = new Contract(addresses.vault, VAULT_ABI, signer);
633
687
  const assets = await vault.redeem.staticCall(shares, receiver, owner);
634
688
  const tx = await vault.redeem(shares, receiver, owner);
@@ -636,12 +690,14 @@ async function redeemShares(signer, addresses, shares, receiver, owner) {
636
690
  return { receipt, assets };
637
691
  }
638
692
  async function withdrawAssets(signer, addresses, assets, receiver, owner) {
693
+ await validateWalletChain(signer, addresses.hubChainId);
639
694
  const vault = new Contract(addresses.vault, VAULT_ABI, signer);
640
695
  const tx = await vault.withdraw(assets, receiver, owner);
641
696
  const receipt = await tx.wait();
642
697
  return { receipt, assets };
643
698
  }
644
699
  async function requestRedeem(signer, addresses, shares, owner) {
700
+ await validateWalletChain(signer, addresses.hubChainId);
645
701
  const vault = new Contract(addresses.vault, VAULT_ABI, signer);
646
702
  const tx = await vault.requestRedeem(shares, owner);
647
703
  const receipt = await tx.wait();
@@ -659,6 +715,7 @@ async function redeemAsync(signer, addresses, shares, receiver, owner, lzFee, ex
659
715
  const provider = signer.provider;
660
716
  if (!addresses.escrow) throw new MissingEscrowAddressError();
661
717
  const escrow = addresses.escrow;
718
+ await validateWalletChain(signer, addresses.hubChainId);
662
719
  await preflightAsync(provider, addresses.vault);
663
720
  await preflightRedeemLiquidity(provider, addresses.vault, shares);
664
721
  await ensureAllowance4(signer, addresses.vault, escrow, shares);
@@ -919,6 +976,12 @@ async function getVaultSummary(provider, vault) {
919
976
  return { ...status, ...metadata };
920
977
  }
921
978
 
922
- export { ActionType, BRIDGE_ABI, CCManagerNotConfiguredError, CONFIG_ABI, CapacityFullError, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, METADATA_ABI, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, VAULT_ABI, VaultPausedError, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
979
+ // src/ethers/wagmiCompat.ts
980
+ function asSdkSigner(signer) {
981
+ if (!signer) throw new Error("[MoreVaults] No signer available. Make sure the wallet is connected and wagmi is configured correctly.");
982
+ return signer;
983
+ }
984
+
985
+ export { ActionType, BRIDGE_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CapacityFullError, EID_TO_CHAIN_ID, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_EIDS, METADATA_ABI, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, VAULT_ABI, VaultPausedError, WrongChainError, asSdkSigner, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
923
986
  //# sourceMappingURL=index.js.map
924
987
  //# sourceMappingURL=index.js.map