@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.
- package/README.md +15 -3
- package/dist/ethers/index.cjs +69 -0
- package/dist/ethers/index.cjs.map +1 -1
- package/dist/ethers/index.d.cts +44 -1
- package/dist/ethers/index.d.ts +44 -1
- package/dist/ethers/index.js +64 -1
- package/dist/ethers/index.js.map +1 -1
- package/dist/viem/index.cjs +67 -0
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.d.cts +46 -1
- package/dist/viem/index.d.ts +46 -1
- package/dist/viem/index.js +62 -1
- package/dist/viem/index.js.map +1 -1
- package/package.json +7 -3
- package/src/ethers/chainValidation.ts +16 -0
- package/src/ethers/chains.ts +35 -0
- package/src/ethers/depositFlows.ts +13 -0
- package/src/ethers/errors.ts +9 -0
- package/src/ethers/index.ts +7 -0
- package/src/ethers/redeemFlows.ts +13 -0
- package/src/ethers/types.ts +6 -0
- package/src/ethers/wagmiCompat.ts +17 -0
- package/src/viem/chainValidation.ts +14 -0
- package/src/viem/chains.ts +35 -0
- package/src/viem/depositFlows.ts +13 -0
- package/src/viem/errors.ts +9 -0
- package/src/viem/index.ts +11 -0
- package/src/viem/redeemFlows.ts +13 -0
- package/src/viem/types.ts +6 -0
- package/src/viem/wagmiCompat.ts +18 -0
package/dist/viem/index.d.cts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import { Hash, Address, WalletClient, PublicClient } from 'viem';
|
|
2
|
+
export { PublicClient as SdkPublicClient } from 'viem';
|
|
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>;
|
|
2
24
|
|
|
3
25
|
/**
|
|
4
26
|
* ABI fragments for MoreVaults SDK.
|
|
@@ -591,6 +613,12 @@ interface VaultAddresses {
|
|
|
591
613
|
shareOFT?: Address;
|
|
592
614
|
/** OFT for USDC bridging (cross-chain deposits from spoke) */
|
|
593
615
|
usdcOFT?: Address;
|
|
616
|
+
/**
|
|
617
|
+
* Expected EVM chain ID of the hub. When provided, SDK functions will
|
|
618
|
+
* throw a clear WrongChainError if the walletClient is on a different chain.
|
|
619
|
+
* Prevents silent failures when MetaMask is connected to the wrong network.
|
|
620
|
+
*/
|
|
621
|
+
hubChainId?: number;
|
|
594
622
|
}
|
|
595
623
|
interface DepositResult {
|
|
596
624
|
txHash: Hash;
|
|
@@ -668,6 +696,9 @@ declare class NotHubVaultError extends MoreVaultsError {
|
|
|
668
696
|
declare class MissingEscrowAddressError extends MoreVaultsError {
|
|
669
697
|
constructor();
|
|
670
698
|
}
|
|
699
|
+
declare class WrongChainError extends MoreVaultsError {
|
|
700
|
+
constructor(currentChainId: number, expectedChainId: number);
|
|
701
|
+
}
|
|
671
702
|
|
|
672
703
|
/**
|
|
673
704
|
* D1 / D3 — Simple deposit (ERC-4626 standard).
|
|
@@ -1288,4 +1319,18 @@ type VaultSummary = VaultStatus & VaultMetadata;
|
|
|
1288
1319
|
*/
|
|
1289
1320
|
declare function getVaultSummary(publicClient: PublicClient, vault: Address): Promise<VaultSummary>;
|
|
1290
1321
|
|
|
1291
|
-
|
|
1322
|
+
/**
|
|
1323
|
+
* Cast a wagmi PublicClient to the SDK's expected type.
|
|
1324
|
+
* Use this in React components to avoid `as any` casts:
|
|
1325
|
+
* ```ts
|
|
1326
|
+
* import { usePublicClient } from 'wagmi'
|
|
1327
|
+
* import { asSdkClient } from '@oydual31/more-vaults-sdk/viem'
|
|
1328
|
+
* const pc = asSdkClient(usePublicClient())
|
|
1329
|
+
* ```
|
|
1330
|
+
* wagmi v2 uses viem as a peer dependency, so the types are structurally
|
|
1331
|
+
* identical — this function validates the client is non-null and applies
|
|
1332
|
+
* a documented cast instead of an opaque `as any`.
|
|
1333
|
+
*/
|
|
1334
|
+
declare function asSdkClient(client: unknown): PublicClient;
|
|
1335
|
+
|
|
1336
|
+
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, asSdkClient, bridgeSharesToHub, canDeposit, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as 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 };
|
package/dist/viem/index.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import { Hash, Address, WalletClient, PublicClient } from 'viem';
|
|
2
|
+
export { PublicClient as SdkPublicClient } from 'viem';
|
|
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>;
|
|
2
24
|
|
|
3
25
|
/**
|
|
4
26
|
* ABI fragments for MoreVaults SDK.
|
|
@@ -591,6 +613,12 @@ interface VaultAddresses {
|
|
|
591
613
|
shareOFT?: Address;
|
|
592
614
|
/** OFT for USDC bridging (cross-chain deposits from spoke) */
|
|
593
615
|
usdcOFT?: Address;
|
|
616
|
+
/**
|
|
617
|
+
* Expected EVM chain ID of the hub. When provided, SDK functions will
|
|
618
|
+
* throw a clear WrongChainError if the walletClient is on a different chain.
|
|
619
|
+
* Prevents silent failures when MetaMask is connected to the wrong network.
|
|
620
|
+
*/
|
|
621
|
+
hubChainId?: number;
|
|
594
622
|
}
|
|
595
623
|
interface DepositResult {
|
|
596
624
|
txHash: Hash;
|
|
@@ -668,6 +696,9 @@ declare class NotHubVaultError extends MoreVaultsError {
|
|
|
668
696
|
declare class MissingEscrowAddressError extends MoreVaultsError {
|
|
669
697
|
constructor();
|
|
670
698
|
}
|
|
699
|
+
declare class WrongChainError extends MoreVaultsError {
|
|
700
|
+
constructor(currentChainId: number, expectedChainId: number);
|
|
701
|
+
}
|
|
671
702
|
|
|
672
703
|
/**
|
|
673
704
|
* D1 / D3 — Simple deposit (ERC-4626 standard).
|
|
@@ -1288,4 +1319,18 @@ type VaultSummary = VaultStatus & VaultMetadata;
|
|
|
1288
1319
|
*/
|
|
1289
1320
|
declare function getVaultSummary(publicClient: PublicClient, vault: Address): Promise<VaultSummary>;
|
|
1290
1321
|
|
|
1291
|
-
|
|
1322
|
+
/**
|
|
1323
|
+
* Cast a wagmi PublicClient to the SDK's expected type.
|
|
1324
|
+
* Use this in React components to avoid `as any` casts:
|
|
1325
|
+
* ```ts
|
|
1326
|
+
* import { usePublicClient } from 'wagmi'
|
|
1327
|
+
* import { asSdkClient } from '@oydual31/more-vaults-sdk/viem'
|
|
1328
|
+
* const pc = asSdkClient(usePublicClient())
|
|
1329
|
+
* ```
|
|
1330
|
+
* wagmi v2 uses viem as a peer dependency, so the types are structurally
|
|
1331
|
+
* identical — this function validates the client is non-null and applies
|
|
1332
|
+
* a documented cast instead of an opaque `as any`.
|
|
1333
|
+
*/
|
|
1334
|
+
declare function asSdkClient(client: unknown): PublicClient;
|
|
1335
|
+
|
|
1336
|
+
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, asSdkClient, bridgeSharesToHub, canDeposit, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as 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 };
|
package/dist/viem/index.js
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { getAddress, zeroAddress, encodeAbiParameters, pad } from 'viem';
|
|
2
2
|
|
|
3
|
+
// src/viem/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/viem/abis.ts
|
|
4
34
|
var VAULT_ABI = [
|
|
5
35
|
{
|
|
@@ -451,6 +481,14 @@ var MissingEscrowAddressError = class extends MoreVaultsError {
|
|
|
451
481
|
this.name = "MissingEscrowAddressError";
|
|
452
482
|
}
|
|
453
483
|
};
|
|
484
|
+
var WrongChainError = class extends MoreVaultsError {
|
|
485
|
+
constructor(currentChainId, expectedChainId) {
|
|
486
|
+
super(
|
|
487
|
+
`Wrong network: wallet is on chain ${currentChainId}, but the vault hub requires chain ${expectedChainId}. Switch networks before proceeding.`
|
|
488
|
+
);
|
|
489
|
+
this.name = "WrongChainError";
|
|
490
|
+
}
|
|
491
|
+
};
|
|
454
492
|
async function getVaultStatus(publicClient, vault) {
|
|
455
493
|
const v = getAddress(vault);
|
|
456
494
|
const b1 = await publicClient.multicall({
|
|
@@ -758,10 +796,20 @@ async function preflightSync(publicClient, vault) {
|
|
|
758
796
|
}
|
|
759
797
|
}
|
|
760
798
|
|
|
799
|
+
// src/viem/chainValidation.ts
|
|
800
|
+
function validateWalletChain(walletClient, hubChainId) {
|
|
801
|
+
if (!hubChainId) return;
|
|
802
|
+
const current = walletClient.chain?.id;
|
|
803
|
+
if (current !== void 0 && current !== hubChainId) {
|
|
804
|
+
throw new WrongChainError(current, hubChainId);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
761
808
|
// src/viem/depositFlows.ts
|
|
762
809
|
async function depositSimple(walletClient, publicClient, addresses, assets, receiver) {
|
|
763
810
|
const account = walletClient.account;
|
|
764
811
|
const vault = getAddress(addresses.vault);
|
|
812
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
765
813
|
await preflightSync(publicClient, vault);
|
|
766
814
|
const underlying = await publicClient.readContract({
|
|
767
815
|
address: vault,
|
|
@@ -789,6 +837,7 @@ async function depositSimple(walletClient, publicClient, addresses, assets, rece
|
|
|
789
837
|
async function depositMultiAsset(walletClient, publicClient, addresses, tokens, amounts, receiver, minShares) {
|
|
790
838
|
const account = walletClient.account;
|
|
791
839
|
const vault = getAddress(addresses.vault);
|
|
840
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
792
841
|
for (let i = 0; i < tokens.length; i++) {
|
|
793
842
|
await ensureAllowance(walletClient, publicClient, tokens[i], vault, amounts[i]);
|
|
794
843
|
}
|
|
@@ -814,6 +863,7 @@ async function depositAsync(walletClient, publicClient, addresses, assets, recei
|
|
|
814
863
|
const vault = getAddress(addresses.vault);
|
|
815
864
|
if (!addresses.escrow) throw new MissingEscrowAddressError();
|
|
816
865
|
const escrow = getAddress(addresses.escrow);
|
|
866
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
817
867
|
await preflightAsync(publicClient, vault);
|
|
818
868
|
const underlying = await publicClient.readContract({
|
|
819
869
|
address: vault,
|
|
@@ -849,6 +899,7 @@ async function mintAsync(walletClient, publicClient, addresses, shares, maxAsset
|
|
|
849
899
|
const vault = getAddress(addresses.vault);
|
|
850
900
|
if (!addresses.escrow) throw new MissingEscrowAddressError();
|
|
851
901
|
const escrow = getAddress(addresses.escrow);
|
|
902
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
852
903
|
await preflightAsync(publicClient, vault);
|
|
853
904
|
const underlying = await publicClient.readContract({
|
|
854
905
|
address: vault,
|
|
@@ -1002,6 +1053,7 @@ async function quoteDepositFromSpokeFee(publicClient, spokeOFT, hubEid, spokeEid
|
|
|
1002
1053
|
async function redeemShares(walletClient, publicClient, addresses, shares, receiver, owner) {
|
|
1003
1054
|
const account = walletClient.account;
|
|
1004
1055
|
const vault = getAddress(addresses.vault);
|
|
1056
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
1005
1057
|
const { result: assets } = await publicClient.simulateContract({
|
|
1006
1058
|
address: vault,
|
|
1007
1059
|
abi: VAULT_ABI,
|
|
@@ -1022,6 +1074,7 @@ async function redeemShares(walletClient, publicClient, addresses, shares, recei
|
|
|
1022
1074
|
async function withdrawAssets(walletClient, publicClient, addresses, assets, receiver, owner) {
|
|
1023
1075
|
const account = walletClient.account;
|
|
1024
1076
|
const vault = getAddress(addresses.vault);
|
|
1077
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
1025
1078
|
const { result: sharesBurned } = await publicClient.simulateContract({
|
|
1026
1079
|
address: vault,
|
|
1027
1080
|
abi: VAULT_ABI,
|
|
@@ -1042,6 +1095,7 @@ async function withdrawAssets(walletClient, publicClient, addresses, assets, rec
|
|
|
1042
1095
|
async function requestRedeem(walletClient, publicClient, addresses, shares, owner) {
|
|
1043
1096
|
const account = walletClient.account;
|
|
1044
1097
|
const vault = getAddress(addresses.vault);
|
|
1098
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
1045
1099
|
await publicClient.simulateContract({
|
|
1046
1100
|
address: vault,
|
|
1047
1101
|
abi: VAULT_ABI,
|
|
@@ -1074,6 +1128,7 @@ async function redeemAsync(walletClient, publicClient, addresses, shares, receiv
|
|
|
1074
1128
|
const vault = getAddress(addresses.vault);
|
|
1075
1129
|
if (!addresses.escrow) throw new MissingEscrowAddressError();
|
|
1076
1130
|
const escrow = getAddress(addresses.escrow);
|
|
1131
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
1077
1132
|
await preflightAsync(publicClient, vault);
|
|
1078
1133
|
await preflightRedeemLiquidity(publicClient, vault, shares);
|
|
1079
1134
|
await ensureAllowance(walletClient, publicClient, vault, escrow, shares);
|
|
@@ -1372,6 +1427,12 @@ async function getVaultSummary(publicClient, vault) {
|
|
|
1372
1427
|
return { ...status, ...metadata };
|
|
1373
1428
|
}
|
|
1374
1429
|
|
|
1375
|
-
|
|
1430
|
+
// src/viem/wagmiCompat.ts
|
|
1431
|
+
function asSdkClient(client) {
|
|
1432
|
+
if (!client) throw new Error("[MoreVaults] No public client available. Make sure wagmi is configured correctly.");
|
|
1433
|
+
return client;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
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, asSdkClient, bridgeSharesToHub, canDeposit, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as 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 };
|
|
1376
1437
|
//# sourceMappingURL=index.js.map
|
|
1377
1438
|
//# sourceMappingURL=index.js.map
|