@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.cjs
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
var viem = require('viem');
|
|
4
4
|
|
|
5
|
+
// src/viem/chains.ts
|
|
6
|
+
var CHAIN_IDS = {
|
|
7
|
+
flowEVMMainnet: 747,
|
|
8
|
+
flowEVMTestnet: 545,
|
|
9
|
+
arbitrum: 42161,
|
|
10
|
+
base: 8453,
|
|
11
|
+
ethereum: 1
|
|
12
|
+
};
|
|
13
|
+
var LZ_EIDS = {
|
|
14
|
+
flowMainnet: 30332,
|
|
15
|
+
flowTestnet: 30333,
|
|
16
|
+
arbitrum: 30110,
|
|
17
|
+
base: 30184,
|
|
18
|
+
ethereum: 30101
|
|
19
|
+
};
|
|
20
|
+
var EID_TO_CHAIN_ID = {
|
|
21
|
+
[LZ_EIDS.flowMainnet]: CHAIN_IDS.flowEVMMainnet,
|
|
22
|
+
[LZ_EIDS.flowTestnet]: CHAIN_IDS.flowEVMTestnet,
|
|
23
|
+
[LZ_EIDS.arbitrum]: CHAIN_IDS.arbitrum,
|
|
24
|
+
[LZ_EIDS.base]: CHAIN_IDS.base,
|
|
25
|
+
[LZ_EIDS.ethereum]: CHAIN_IDS.ethereum
|
|
26
|
+
};
|
|
27
|
+
var CHAIN_ID_TO_EID = {
|
|
28
|
+
[CHAIN_IDS.flowEVMMainnet]: LZ_EIDS.flowMainnet,
|
|
29
|
+
[CHAIN_IDS.flowEVMTestnet]: LZ_EIDS.flowTestnet,
|
|
30
|
+
[CHAIN_IDS.arbitrum]: LZ_EIDS.arbitrum,
|
|
31
|
+
[CHAIN_IDS.base]: LZ_EIDS.base,
|
|
32
|
+
[CHAIN_IDS.ethereum]: LZ_EIDS.ethereum
|
|
33
|
+
};
|
|
34
|
+
|
|
5
35
|
// src/viem/abis.ts
|
|
6
36
|
var VAULT_ABI = [
|
|
7
37
|
{
|
|
@@ -453,6 +483,14 @@ var MissingEscrowAddressError = class extends MoreVaultsError {
|
|
|
453
483
|
this.name = "MissingEscrowAddressError";
|
|
454
484
|
}
|
|
455
485
|
};
|
|
486
|
+
var WrongChainError = class extends MoreVaultsError {
|
|
487
|
+
constructor(currentChainId, expectedChainId) {
|
|
488
|
+
super(
|
|
489
|
+
`Wrong network: wallet is on chain ${currentChainId}, but the vault hub requires chain ${expectedChainId}. Switch networks before proceeding.`
|
|
490
|
+
);
|
|
491
|
+
this.name = "WrongChainError";
|
|
492
|
+
}
|
|
493
|
+
};
|
|
456
494
|
async function getVaultStatus(publicClient, vault) {
|
|
457
495
|
const v = viem.getAddress(vault);
|
|
458
496
|
const b1 = await publicClient.multicall({
|
|
@@ -760,10 +798,20 @@ async function preflightSync(publicClient, vault) {
|
|
|
760
798
|
}
|
|
761
799
|
}
|
|
762
800
|
|
|
801
|
+
// src/viem/chainValidation.ts
|
|
802
|
+
function validateWalletChain(walletClient, hubChainId) {
|
|
803
|
+
if (!hubChainId) return;
|
|
804
|
+
const current = walletClient.chain?.id;
|
|
805
|
+
if (current !== void 0 && current !== hubChainId) {
|
|
806
|
+
throw new WrongChainError(current, hubChainId);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
763
810
|
// src/viem/depositFlows.ts
|
|
764
811
|
async function depositSimple(walletClient, publicClient, addresses, assets, receiver) {
|
|
765
812
|
const account = walletClient.account;
|
|
766
813
|
const vault = viem.getAddress(addresses.vault);
|
|
814
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
767
815
|
await preflightSync(publicClient, vault);
|
|
768
816
|
const underlying = await publicClient.readContract({
|
|
769
817
|
address: vault,
|
|
@@ -791,6 +839,7 @@ async function depositSimple(walletClient, publicClient, addresses, assets, rece
|
|
|
791
839
|
async function depositMultiAsset(walletClient, publicClient, addresses, tokens, amounts, receiver, minShares) {
|
|
792
840
|
const account = walletClient.account;
|
|
793
841
|
const vault = viem.getAddress(addresses.vault);
|
|
842
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
794
843
|
for (let i = 0; i < tokens.length; i++) {
|
|
795
844
|
await ensureAllowance(walletClient, publicClient, tokens[i], vault, amounts[i]);
|
|
796
845
|
}
|
|
@@ -816,6 +865,7 @@ async function depositAsync(walletClient, publicClient, addresses, assets, recei
|
|
|
816
865
|
const vault = viem.getAddress(addresses.vault);
|
|
817
866
|
if (!addresses.escrow) throw new MissingEscrowAddressError();
|
|
818
867
|
const escrow = viem.getAddress(addresses.escrow);
|
|
868
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
819
869
|
await preflightAsync(publicClient, vault);
|
|
820
870
|
const underlying = await publicClient.readContract({
|
|
821
871
|
address: vault,
|
|
@@ -851,6 +901,7 @@ async function mintAsync(walletClient, publicClient, addresses, shares, maxAsset
|
|
|
851
901
|
const vault = viem.getAddress(addresses.vault);
|
|
852
902
|
if (!addresses.escrow) throw new MissingEscrowAddressError();
|
|
853
903
|
const escrow = viem.getAddress(addresses.escrow);
|
|
904
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
854
905
|
await preflightAsync(publicClient, vault);
|
|
855
906
|
const underlying = await publicClient.readContract({
|
|
856
907
|
address: vault,
|
|
@@ -1004,6 +1055,7 @@ async function quoteDepositFromSpokeFee(publicClient, spokeOFT, hubEid, spokeEid
|
|
|
1004
1055
|
async function redeemShares(walletClient, publicClient, addresses, shares, receiver, owner) {
|
|
1005
1056
|
const account = walletClient.account;
|
|
1006
1057
|
const vault = viem.getAddress(addresses.vault);
|
|
1058
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
1007
1059
|
const { result: assets } = await publicClient.simulateContract({
|
|
1008
1060
|
address: vault,
|
|
1009
1061
|
abi: VAULT_ABI,
|
|
@@ -1024,6 +1076,7 @@ async function redeemShares(walletClient, publicClient, addresses, shares, recei
|
|
|
1024
1076
|
async function withdrawAssets(walletClient, publicClient, addresses, assets, receiver, owner) {
|
|
1025
1077
|
const account = walletClient.account;
|
|
1026
1078
|
const vault = viem.getAddress(addresses.vault);
|
|
1079
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
1027
1080
|
const { result: sharesBurned } = await publicClient.simulateContract({
|
|
1028
1081
|
address: vault,
|
|
1029
1082
|
abi: VAULT_ABI,
|
|
@@ -1044,6 +1097,7 @@ async function withdrawAssets(walletClient, publicClient, addresses, assets, rec
|
|
|
1044
1097
|
async function requestRedeem(walletClient, publicClient, addresses, shares, owner) {
|
|
1045
1098
|
const account = walletClient.account;
|
|
1046
1099
|
const vault = viem.getAddress(addresses.vault);
|
|
1100
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
1047
1101
|
await publicClient.simulateContract({
|
|
1048
1102
|
address: vault,
|
|
1049
1103
|
abi: VAULT_ABI,
|
|
@@ -1076,6 +1130,7 @@ async function redeemAsync(walletClient, publicClient, addresses, shares, receiv
|
|
|
1076
1130
|
const vault = viem.getAddress(addresses.vault);
|
|
1077
1131
|
if (!addresses.escrow) throw new MissingEscrowAddressError();
|
|
1078
1132
|
const escrow = viem.getAddress(addresses.escrow);
|
|
1133
|
+
validateWalletChain(walletClient, addresses.hubChainId);
|
|
1079
1134
|
await preflightAsync(publicClient, vault);
|
|
1080
1135
|
await preflightRedeemLiquidity(publicClient, vault, shares);
|
|
1081
1136
|
await ensureAllowance(walletClient, publicClient, vault, escrow, shares);
|
|
@@ -1374,14 +1429,24 @@ async function getVaultSummary(publicClient, vault) {
|
|
|
1374
1429
|
return { ...status, ...metadata };
|
|
1375
1430
|
}
|
|
1376
1431
|
|
|
1432
|
+
// src/viem/wagmiCompat.ts
|
|
1433
|
+
function asSdkClient(client) {
|
|
1434
|
+
if (!client) throw new Error("[MoreVaults] No public client available. Make sure wagmi is configured correctly.");
|
|
1435
|
+
return client;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1377
1438
|
exports.ActionType = ActionType;
|
|
1378
1439
|
exports.BRIDGE_ABI = BRIDGE_ABI;
|
|
1379
1440
|
exports.CCManagerNotConfiguredError = CCManagerNotConfiguredError;
|
|
1441
|
+
exports.CHAIN_IDS = CHAIN_IDS;
|
|
1442
|
+
exports.CHAIN_ID_TO_EID = CHAIN_ID_TO_EID;
|
|
1380
1443
|
exports.CONFIG_ABI = CONFIG_ABI;
|
|
1381
1444
|
exports.CapacityFullError = CapacityFullError;
|
|
1445
|
+
exports.EID_TO_CHAIN_ID = EID_TO_CHAIN_ID;
|
|
1382
1446
|
exports.ERC20_ABI = ERC20_ABI;
|
|
1383
1447
|
exports.EscrowNotConfiguredError = EscrowNotConfiguredError;
|
|
1384
1448
|
exports.InsufficientLiquidityError = InsufficientLiquidityError;
|
|
1449
|
+
exports.LZ_EIDS = LZ_EIDS;
|
|
1385
1450
|
exports.METADATA_ABI = METADATA_ABI;
|
|
1386
1451
|
exports.MissingEscrowAddressError = MissingEscrowAddressError;
|
|
1387
1452
|
exports.MoreVaultsError = MoreVaultsError;
|
|
@@ -1390,6 +1455,8 @@ exports.NotWhitelistedError = NotWhitelistedError;
|
|
|
1390
1455
|
exports.OFT_ABI = OFT_ABI;
|
|
1391
1456
|
exports.VAULT_ABI = VAULT_ABI;
|
|
1392
1457
|
exports.VaultPausedError = VaultPausedError;
|
|
1458
|
+
exports.WrongChainError = WrongChainError;
|
|
1459
|
+
exports.asSdkClient = asSdkClient;
|
|
1393
1460
|
exports.bridgeSharesToHub = bridgeSharesToHub;
|
|
1394
1461
|
exports.canDeposit = canDeposit;
|
|
1395
1462
|
exports.depositAsync = depositAsync;
|