@oydual31/more-vaults-sdk 0.3.0 → 0.3.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.
@@ -1,4 +1,4 @@
1
- import { getAddress, zeroAddress, pad, encodeAbiParameters, createPublicClient, http, fallback } from 'viem';
1
+ import { getAddress, zeroAddress, pad, encodeAbiParameters, encodeFunctionData, createPublicClient, http, fallback } from 'viem';
2
2
 
3
3
  // src/viem/chains.ts
4
4
  var CHAIN_IDS = {
@@ -1075,6 +1075,45 @@ var LZ_ADAPTER_ABI = [
1075
1075
  stateMutability: "view"
1076
1076
  }
1077
1077
  ];
1078
+ var ERC4626_FACET_ABI = [
1079
+ {
1080
+ type: "function",
1081
+ name: "erc4626Deposit",
1082
+ inputs: [
1083
+ { name: "vault", type: "address" },
1084
+ { name: "assets", type: "uint256" }
1085
+ ],
1086
+ outputs: [{ name: "shares", type: "uint256" }],
1087
+ stateMutability: "nonpayable"
1088
+ },
1089
+ {
1090
+ type: "function",
1091
+ name: "erc4626Redeem",
1092
+ inputs: [
1093
+ { name: "vault", type: "address" },
1094
+ { name: "shares", type: "uint256" }
1095
+ ],
1096
+ outputs: [{ name: "assets", type: "uint256" }],
1097
+ stateMutability: "nonpayable"
1098
+ }
1099
+ ];
1100
+ var VAULT_ANALYSIS_ABI = [
1101
+ // Asset management reads
1102
+ { type: "function", name: "getAvailableAssets", inputs: [], outputs: [{ type: "address[]" }], stateMutability: "view" },
1103
+ { type: "function", name: "getDepositableAssets", inputs: [], outputs: [{ type: "address[]" }], stateMutability: "view" },
1104
+ { type: "function", name: "isAssetAvailable", inputs: [{ name: "asset", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
1105
+ { type: "function", name: "isAssetDepositable", inputs: [{ name: "asset", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
1106
+ // Deposit whitelist
1107
+ { type: "function", name: "isDepositWhitelistEnabled", inputs: [], outputs: [{ type: "bool" }], stateMutability: "view" },
1108
+ { type: "function", name: "getAvailableToDeposit", inputs: [{ name: "depositor", type: "address" }], outputs: [{ type: "uint256" }], stateMutability: "view" },
1109
+ // Registry
1110
+ { type: "function", name: "moreVaultsRegistry", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" }
1111
+ ];
1112
+ var REGISTRY_ABI = [
1113
+ { type: "function", name: "isWhitelisted", inputs: [{ name: "protocol", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
1114
+ { type: "function", name: "isBridgeAllowed", inputs: [{ name: "bridge", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
1115
+ { type: "function", name: "getAllowedFacets", inputs: [], outputs: [{ type: "address[]" }], stateMutability: "view" }
1116
+ ];
1078
1117
  var LZ_ENDPOINT_ABI = [
1079
1118
  {
1080
1119
  type: "function",
@@ -3084,12 +3123,21 @@ async function canDeposit(publicClient, vault, user) {
3084
3123
  ],
3085
3124
  allowFailure: false
3086
3125
  });
3126
+ let whitelistEnabled = false;
3127
+ try {
3128
+ whitelistEnabled = await publicClient.readContract({
3129
+ address: v,
3130
+ abi: VAULT_ANALYSIS_ABI,
3131
+ functionName: "isDepositWhitelistEnabled"
3132
+ });
3133
+ } catch {
3134
+ }
3087
3135
  if (isPaused) {
3088
- return { allowed: false, reason: "paused" };
3136
+ return { allowed: false, reason: "paused", whitelistEnabled };
3089
3137
  }
3090
3138
  const isCrossChainAsync = isHub && !oraclesEnabled;
3091
3139
  if (isCrossChainAsync) {
3092
- return { allowed: true, reason: "ok" };
3140
+ return { allowed: true, reason: "ok", whitelistEnabled };
3093
3141
  }
3094
3142
  let maxDepositAmount;
3095
3143
  try {
@@ -3100,12 +3148,12 @@ async function canDeposit(publicClient, vault, user) {
3100
3148
  args: [getAddress(user)]
3101
3149
  });
3102
3150
  } catch {
3103
- return { allowed: false, reason: "not-whitelisted" };
3151
+ return { allowed: false, reason: "not-whitelisted", maxDeposit: 0n, whitelistEnabled };
3104
3152
  }
3105
3153
  if (maxDepositAmount === 0n) {
3106
- return { allowed: false, reason: "capacity-full" };
3154
+ return { allowed: false, reason: "capacity-full", maxDeposit: 0n, whitelistEnabled };
3107
3155
  }
3108
- return { allowed: true, reason: "ok" };
3156
+ return { allowed: true, reason: "ok", maxDeposit: maxDepositAmount, whitelistEnabled };
3109
3157
  }
3110
3158
  async function getVaultMetadata(publicClient, vault) {
3111
3159
  const v = getAddress(vault);
@@ -3509,6 +3557,230 @@ async function isCurator(publicClient, vault, address) {
3509
3557
  });
3510
3558
  return getAddress(curatorAddress) === getAddress(address);
3511
3559
  }
3560
+ async function getVaultAnalysis(publicClient, vault) {
3561
+ const v = getAddress(vault);
3562
+ const [availableRaw, depositableRaw, depositWhitelistEnabled, registryResult] = await Promise.all([
3563
+ publicClient.readContract({
3564
+ address: v,
3565
+ abi: VAULT_ANALYSIS_ABI,
3566
+ functionName: "getAvailableAssets"
3567
+ }),
3568
+ publicClient.readContract({
3569
+ address: v,
3570
+ abi: VAULT_ANALYSIS_ABI,
3571
+ functionName: "getDepositableAssets"
3572
+ }),
3573
+ publicClient.readContract({
3574
+ address: v,
3575
+ abi: VAULT_ANALYSIS_ABI,
3576
+ functionName: "isDepositWhitelistEnabled"
3577
+ }),
3578
+ publicClient.readContract({
3579
+ address: v,
3580
+ abi: VAULT_ANALYSIS_ABI,
3581
+ functionName: "moreVaultsRegistry"
3582
+ }).catch(() => null)
3583
+ ]);
3584
+ const availableAddresses = availableRaw.map(getAddress);
3585
+ const depositableAddresses = depositableRaw.map(getAddress);
3586
+ const allAddresses = Array.from(/* @__PURE__ */ new Set([...availableAddresses, ...depositableAddresses]));
3587
+ const metadataCalls = allAddresses.flatMap((addr) => [
3588
+ { address: addr, abi: METADATA_ABI, functionName: "name" },
3589
+ { address: addr, abi: METADATA_ABI, functionName: "symbol" },
3590
+ { address: addr, abi: METADATA_ABI, functionName: "decimals" }
3591
+ ]);
3592
+ const metadataResults = allAddresses.length > 0 ? await publicClient.multicall({ contracts: metadataCalls, allowFailure: true }) : [];
3593
+ const assetInfoMap = /* @__PURE__ */ new Map();
3594
+ for (let i = 0; i < allAddresses.length; i++) {
3595
+ const addr = allAddresses[i];
3596
+ const nameResult = metadataResults[i * 3];
3597
+ const symbolResult = metadataResults[i * 3 + 1];
3598
+ const decimalsResult = metadataResults[i * 3 + 2];
3599
+ assetInfoMap.set(addr, {
3600
+ address: addr,
3601
+ name: nameResult?.status === "success" ? nameResult.result : "",
3602
+ symbol: symbolResult?.status === "success" ? symbolResult.result : "",
3603
+ decimals: decimalsResult?.status === "success" ? decimalsResult.result : 18
3604
+ });
3605
+ }
3606
+ const registryAddress = registryResult ? getAddress(registryResult) : null;
3607
+ return {
3608
+ availableAssets: availableAddresses.map((a) => assetInfoMap.get(a)),
3609
+ depositableAssets: depositableAddresses.map((a) => assetInfoMap.get(a)),
3610
+ depositWhitelistEnabled,
3611
+ registryAddress
3612
+ };
3613
+ }
3614
+ async function checkProtocolWhitelist(publicClient, vault, protocols) {
3615
+ const v = getAddress(vault);
3616
+ const registryRaw = await publicClient.readContract({
3617
+ address: v,
3618
+ abi: VAULT_ANALYSIS_ABI,
3619
+ functionName: "moreVaultsRegistry"
3620
+ });
3621
+ const registry = getAddress(registryRaw);
3622
+ if (protocols.length === 0) return {};
3623
+ const results = await publicClient.multicall({
3624
+ contracts: protocols.map((protocol) => ({
3625
+ address: registry,
3626
+ abi: REGISTRY_ABI,
3627
+ functionName: "isWhitelisted",
3628
+ args: [getAddress(protocol)]
3629
+ })),
3630
+ allowFailure: true
3631
+ });
3632
+ const out = {};
3633
+ for (let i = 0; i < protocols.length; i++) {
3634
+ const r = results[i];
3635
+ out[getAddress(protocols[i])] = r?.status === "success" ? r.result : false;
3636
+ }
3637
+ return out;
3638
+ }
3639
+ function encodeCuratorAction(action) {
3640
+ switch (action.type) {
3641
+ case "swap":
3642
+ return encodeFunctionData({
3643
+ abi: DEX_ABI,
3644
+ functionName: "executeSwap",
3645
+ args: [
3646
+ {
3647
+ targetContract: getAddress(action.params.targetContract),
3648
+ tokenIn: getAddress(action.params.tokenIn),
3649
+ tokenOut: getAddress(action.params.tokenOut),
3650
+ maxAmountIn: action.params.maxAmountIn,
3651
+ minAmountOut: action.params.minAmountOut,
3652
+ swapCallData: action.params.swapCallData
3653
+ }
3654
+ ]
3655
+ });
3656
+ case "batchSwap":
3657
+ return encodeFunctionData({
3658
+ abi: DEX_ABI,
3659
+ functionName: "executeBatchSwap",
3660
+ args: [
3661
+ {
3662
+ swaps: action.params.swaps.map((s) => ({
3663
+ targetContract: getAddress(s.targetContract),
3664
+ tokenIn: getAddress(s.tokenIn),
3665
+ tokenOut: getAddress(s.tokenOut),
3666
+ maxAmountIn: s.maxAmountIn,
3667
+ minAmountOut: s.minAmountOut,
3668
+ swapCallData: s.swapCallData
3669
+ }))
3670
+ }
3671
+ ]
3672
+ });
3673
+ case "erc4626Deposit":
3674
+ return encodeFunctionData({
3675
+ abi: ERC4626_FACET_ABI,
3676
+ functionName: "erc4626Deposit",
3677
+ args: [getAddress(action.vault), action.assets]
3678
+ });
3679
+ case "erc4626Redeem":
3680
+ return encodeFunctionData({
3681
+ abi: ERC4626_FACET_ABI,
3682
+ functionName: "erc4626Redeem",
3683
+ args: [getAddress(action.vault), action.shares]
3684
+ });
3685
+ case "erc7540RequestDeposit":
3686
+ return encodeFunctionData({
3687
+ abi: ERC7540_FACET_ABI,
3688
+ functionName: "erc7540RequestDeposit",
3689
+ args: [getAddress(action.vault), action.assets]
3690
+ });
3691
+ case "erc7540Deposit":
3692
+ return encodeFunctionData({
3693
+ abi: ERC7540_FACET_ABI,
3694
+ functionName: "erc7540Deposit",
3695
+ args: [getAddress(action.vault), action.assets]
3696
+ });
3697
+ case "erc7540RequestRedeem":
3698
+ return encodeFunctionData({
3699
+ abi: ERC7540_FACET_ABI,
3700
+ functionName: "erc7540RequestRedeem",
3701
+ args: [getAddress(action.vault), action.shares]
3702
+ });
3703
+ case "erc7540Redeem":
3704
+ return encodeFunctionData({
3705
+ abi: ERC7540_FACET_ABI,
3706
+ functionName: "erc7540Redeem",
3707
+ args: [getAddress(action.vault), action.shares]
3708
+ });
3709
+ default: {
3710
+ const _exhaustive = action;
3711
+ throw new Error(`[MoreVaults] Unknown CuratorAction type: ${_exhaustive.type}`);
3712
+ }
3713
+ }
3714
+ }
3715
+ function buildCuratorBatch(actions) {
3716
+ return actions.map(encodeCuratorAction);
3717
+ }
3718
+ async function submitActions(walletClient, publicClient, vault, actions) {
3719
+ const account = walletClient.account;
3720
+ const v = getAddress(vault);
3721
+ await publicClient.simulateContract({
3722
+ address: v,
3723
+ abi: MULTICALL_ABI,
3724
+ functionName: "submitActions",
3725
+ args: [actions],
3726
+ account: account.address
3727
+ });
3728
+ const txHash = await walletClient.writeContract({
3729
+ address: v,
3730
+ abi: MULTICALL_ABI,
3731
+ functionName: "submitActions",
3732
+ args: [actions],
3733
+ account,
3734
+ chain: walletClient.chain
3735
+ });
3736
+ const nextNonce = await publicClient.readContract({
3737
+ address: v,
3738
+ abi: MULTICALL_ABI,
3739
+ functionName: "getCurrentNonce"
3740
+ });
3741
+ const nonce = nextNonce - 1n;
3742
+ return { txHash, nonce };
3743
+ }
3744
+ async function executeActions(walletClient, publicClient, vault, nonce) {
3745
+ const account = walletClient.account;
3746
+ const v = getAddress(vault);
3747
+ await publicClient.simulateContract({
3748
+ address: v,
3749
+ abi: MULTICALL_ABI,
3750
+ functionName: "executeActions",
3751
+ args: [nonce],
3752
+ account: account.address
3753
+ });
3754
+ const txHash = await walletClient.writeContract({
3755
+ address: v,
3756
+ abi: MULTICALL_ABI,
3757
+ functionName: "executeActions",
3758
+ args: [nonce],
3759
+ account,
3760
+ chain: walletClient.chain
3761
+ });
3762
+ return { txHash };
3763
+ }
3764
+ async function vetoActions(walletClient, publicClient, vault, nonces) {
3765
+ const account = walletClient.account;
3766
+ const v = getAddress(vault);
3767
+ await publicClient.simulateContract({
3768
+ address: v,
3769
+ abi: MULTICALL_ABI,
3770
+ functionName: "vetoActions",
3771
+ args: [nonces],
3772
+ account: account.address
3773
+ });
3774
+ const txHash = await walletClient.writeContract({
3775
+ address: v,
3776
+ abi: MULTICALL_ABI,
3777
+ functionName: "vetoActions",
3778
+ args: [nonces],
3779
+ account,
3780
+ chain: walletClient.chain
3781
+ });
3782
+ return { txHash };
3783
+ }
3512
3784
 
3513
3785
  // src/viem/wagmiCompat.ts
3514
3786
  function asSdkClient(client) {
@@ -3516,6 +3788,6 @@ function asSdkClient(client) {
3516
3788
  return client;
3517
3789
  }
3518
3790
 
3519
- export { ActionType, BRIDGE_ABI, BRIDGE_FACET_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CURATOR_CONFIG_ABI, CapacityFullError, DEX_ABI, EID_TO_CHAIN_ID, ERC20_ABI, ERC7540_FACET_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_ADAPTER_ABI, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, MULTICALL_ABI, MissingEscrowAddressError, MoreVaultsError, NATIVE_SYMBOL, NotHubVaultError, NotWhitelistedError, OFT_ABI, OFT_ROUTES, OMNI_FACTORY_ADDRESS, STARGATE_TAXI_CMD, USDC_STARGATE_OFT, USDC_TOKEN, VAULT_ABI, VaultPausedError, WrongChainError, asSdkClient, bridgeAssetsToSpoke, bridgeSharesToHub, canDeposit, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as depositFromSpokeAsync, depositMultiAsset, depositSimple, discoverVaultTopology, ensureAllowance, executeCompose, getAllVaultChainIds, getAsyncRequestStatus, getAsyncRequestStatusLabel, getCuratorVaultStatus, getFullVaultTopology, getInboundRoutes, getMaxWithdrawable, getOutboundRoutes, getPendingActions, getUserBalances, getUserBalancesForRoutes, getUserPosition, getUserPositionMultiChain, getVaultDistribution, getVaultDistributionWithTopology, getVaultMetadata, getVaultStatus, getVaultSummary, getVaultTopology, getWithdrawalRequest, isAsyncMode, isCurator, isOnHubChain, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSpokeDeposit, preflightSpokeRedeem, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, quoteRouteDepositFee, quoteShareBridgeFee, redeemAsync, redeemShares, requestRedeem, resolveRedeemAddresses, smartDeposit, smartRedeem, waitForAsyncRequest, waitForCompose, waitForTx, withdrawAssets };
3791
+ export { ActionType, BRIDGE_ABI, BRIDGE_FACET_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CURATOR_CONFIG_ABI, CapacityFullError, DEX_ABI, EID_TO_CHAIN_ID, ERC20_ABI, ERC4626_FACET_ABI, ERC7540_FACET_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_ADAPTER_ABI, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, MULTICALL_ABI, MissingEscrowAddressError, MoreVaultsError, NATIVE_SYMBOL, NotHubVaultError, NotWhitelistedError, OFT_ABI, OFT_ROUTES, OMNI_FACTORY_ADDRESS, REGISTRY_ABI, STARGATE_TAXI_CMD, USDC_STARGATE_OFT, USDC_TOKEN, VAULT_ABI, VAULT_ANALYSIS_ABI, VaultPausedError, WrongChainError, asSdkClient, bridgeAssetsToSpoke, bridgeSharesToHub, buildCuratorBatch, canDeposit, checkProtocolWhitelist, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as depositFromSpokeAsync, depositMultiAsset, depositSimple, discoverVaultTopology, encodeCuratorAction, ensureAllowance, executeActions, executeCompose, getAllVaultChainIds, getAsyncRequestStatus, getAsyncRequestStatusLabel, getCuratorVaultStatus, getFullVaultTopology, getInboundRoutes, getMaxWithdrawable, getOutboundRoutes, getPendingActions, getUserBalances, getUserBalancesForRoutes, getUserPosition, getUserPositionMultiChain, getVaultAnalysis, getVaultDistribution, getVaultDistributionWithTopology, getVaultMetadata, getVaultStatus, getVaultSummary, getVaultTopology, getWithdrawalRequest, isAsyncMode, isCurator, isOnHubChain, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSpokeDeposit, preflightSpokeRedeem, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, quoteRouteDepositFee, quoteShareBridgeFee, redeemAsync, redeemShares, requestRedeem, resolveRedeemAddresses, smartDeposit, smartRedeem, submitActions, vetoActions, waitForAsyncRequest, waitForCompose, waitForTx, withdrawAssets };
3520
3792
  //# sourceMappingURL=index.js.map
3521
3793
  //# sourceMappingURL=index.js.map