@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.
@@ -241,6 +241,10 @@ type DepositBlockReason = 'paused' | 'capacity-full' | 'not-whitelisted' | 'ok';
241
241
  interface DepositEligibility {
242
242
  allowed: boolean;
243
243
  reason: DepositBlockReason;
244
+ /** Max deposit amount for this user (0n if capacity full or not whitelisted) */
245
+ maxDeposit?: bigint;
246
+ /** Whether the vault restricts deposits to whitelisted addresses */
247
+ whitelistEnabled?: boolean;
244
248
  }
245
249
  /**
246
250
  * Check whether a user is eligible to deposit into the vault right now.
@@ -241,6 +241,10 @@ type DepositBlockReason = 'paused' | 'capacity-full' | 'not-whitelisted' | 'ok';
241
241
  interface DepositEligibility {
242
242
  allowed: boolean;
243
243
  reason: DepositBlockReason;
244
+ /** Max deposit amount for this user (0n if capacity full or not whitelisted) */
245
+ maxDeposit?: bigint;
246
+ /** Whether the vault restricts deposits to whitelisted addresses */
247
+ whitelistEnabled?: boolean;
244
248
  }
245
249
  /**
246
250
  * Check whether a user is eligible to deposit into the vault right now.
@@ -1077,6 +1077,45 @@ var LZ_ADAPTER_ABI = [
1077
1077
  stateMutability: "view"
1078
1078
  }
1079
1079
  ];
1080
+ var ERC4626_FACET_ABI = [
1081
+ {
1082
+ type: "function",
1083
+ name: "erc4626Deposit",
1084
+ inputs: [
1085
+ { name: "vault", type: "address" },
1086
+ { name: "assets", type: "uint256" }
1087
+ ],
1088
+ outputs: [{ name: "shares", type: "uint256" }],
1089
+ stateMutability: "nonpayable"
1090
+ },
1091
+ {
1092
+ type: "function",
1093
+ name: "erc4626Redeem",
1094
+ inputs: [
1095
+ { name: "vault", type: "address" },
1096
+ { name: "shares", type: "uint256" }
1097
+ ],
1098
+ outputs: [{ name: "assets", type: "uint256" }],
1099
+ stateMutability: "nonpayable"
1100
+ }
1101
+ ];
1102
+ var VAULT_ANALYSIS_ABI = [
1103
+ // Asset management reads
1104
+ { type: "function", name: "getAvailableAssets", inputs: [], outputs: [{ type: "address[]" }], stateMutability: "view" },
1105
+ { type: "function", name: "getDepositableAssets", inputs: [], outputs: [{ type: "address[]" }], stateMutability: "view" },
1106
+ { type: "function", name: "isAssetAvailable", inputs: [{ name: "asset", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
1107
+ { type: "function", name: "isAssetDepositable", inputs: [{ name: "asset", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
1108
+ // Deposit whitelist
1109
+ { type: "function", name: "isDepositWhitelistEnabled", inputs: [], outputs: [{ type: "bool" }], stateMutability: "view" },
1110
+ { type: "function", name: "getAvailableToDeposit", inputs: [{ name: "depositor", type: "address" }], outputs: [{ type: "uint256" }], stateMutability: "view" },
1111
+ // Registry
1112
+ { type: "function", name: "moreVaultsRegistry", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" }
1113
+ ];
1114
+ var REGISTRY_ABI = [
1115
+ { type: "function", name: "isWhitelisted", inputs: [{ name: "protocol", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
1116
+ { type: "function", name: "isBridgeAllowed", inputs: [{ name: "bridge", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
1117
+ { type: "function", name: "getAllowedFacets", inputs: [], outputs: [{ type: "address[]" }], stateMutability: "view" }
1118
+ ];
1080
1119
  var LZ_ENDPOINT_ABI = [
1081
1120
  {
1082
1121
  type: "function",
@@ -3086,12 +3125,21 @@ async function canDeposit(publicClient, vault, user) {
3086
3125
  ],
3087
3126
  allowFailure: false
3088
3127
  });
3128
+ let whitelistEnabled = false;
3129
+ try {
3130
+ whitelistEnabled = await publicClient.readContract({
3131
+ address: v,
3132
+ abi: VAULT_ANALYSIS_ABI,
3133
+ functionName: "isDepositWhitelistEnabled"
3134
+ });
3135
+ } catch {
3136
+ }
3089
3137
  if (isPaused) {
3090
- return { allowed: false, reason: "paused" };
3138
+ return { allowed: false, reason: "paused", whitelistEnabled };
3091
3139
  }
3092
3140
  const isCrossChainAsync = isHub && !oraclesEnabled;
3093
3141
  if (isCrossChainAsync) {
3094
- return { allowed: true, reason: "ok" };
3142
+ return { allowed: true, reason: "ok", whitelistEnabled };
3095
3143
  }
3096
3144
  let maxDepositAmount;
3097
3145
  try {
@@ -3102,12 +3150,12 @@ async function canDeposit(publicClient, vault, user) {
3102
3150
  args: [viem.getAddress(user)]
3103
3151
  });
3104
3152
  } catch {
3105
- return { allowed: false, reason: "not-whitelisted" };
3153
+ return { allowed: false, reason: "not-whitelisted", maxDeposit: 0n, whitelistEnabled };
3106
3154
  }
3107
3155
  if (maxDepositAmount === 0n) {
3108
- return { allowed: false, reason: "capacity-full" };
3156
+ return { allowed: false, reason: "capacity-full", maxDeposit: 0n, whitelistEnabled };
3109
3157
  }
3110
- return { allowed: true, reason: "ok" };
3158
+ return { allowed: true, reason: "ok", maxDeposit: maxDepositAmount, whitelistEnabled };
3111
3159
  }
3112
3160
  async function getVaultMetadata(publicClient, vault) {
3113
3161
  const v = viem.getAddress(vault);
@@ -3511,6 +3559,230 @@ async function isCurator(publicClient, vault, address) {
3511
3559
  });
3512
3560
  return viem.getAddress(curatorAddress) === viem.getAddress(address);
3513
3561
  }
3562
+ async function getVaultAnalysis(publicClient, vault) {
3563
+ const v = viem.getAddress(vault);
3564
+ const [availableRaw, depositableRaw, depositWhitelistEnabled, registryResult] = await Promise.all([
3565
+ publicClient.readContract({
3566
+ address: v,
3567
+ abi: VAULT_ANALYSIS_ABI,
3568
+ functionName: "getAvailableAssets"
3569
+ }),
3570
+ publicClient.readContract({
3571
+ address: v,
3572
+ abi: VAULT_ANALYSIS_ABI,
3573
+ functionName: "getDepositableAssets"
3574
+ }),
3575
+ publicClient.readContract({
3576
+ address: v,
3577
+ abi: VAULT_ANALYSIS_ABI,
3578
+ functionName: "isDepositWhitelistEnabled"
3579
+ }),
3580
+ publicClient.readContract({
3581
+ address: v,
3582
+ abi: VAULT_ANALYSIS_ABI,
3583
+ functionName: "moreVaultsRegistry"
3584
+ }).catch(() => null)
3585
+ ]);
3586
+ const availableAddresses = availableRaw.map(viem.getAddress);
3587
+ const depositableAddresses = depositableRaw.map(viem.getAddress);
3588
+ const allAddresses = Array.from(/* @__PURE__ */ new Set([...availableAddresses, ...depositableAddresses]));
3589
+ const metadataCalls = allAddresses.flatMap((addr) => [
3590
+ { address: addr, abi: METADATA_ABI, functionName: "name" },
3591
+ { address: addr, abi: METADATA_ABI, functionName: "symbol" },
3592
+ { address: addr, abi: METADATA_ABI, functionName: "decimals" }
3593
+ ]);
3594
+ const metadataResults = allAddresses.length > 0 ? await publicClient.multicall({ contracts: metadataCalls, allowFailure: true }) : [];
3595
+ const assetInfoMap = /* @__PURE__ */ new Map();
3596
+ for (let i = 0; i < allAddresses.length; i++) {
3597
+ const addr = allAddresses[i];
3598
+ const nameResult = metadataResults[i * 3];
3599
+ const symbolResult = metadataResults[i * 3 + 1];
3600
+ const decimalsResult = metadataResults[i * 3 + 2];
3601
+ assetInfoMap.set(addr, {
3602
+ address: addr,
3603
+ name: nameResult?.status === "success" ? nameResult.result : "",
3604
+ symbol: symbolResult?.status === "success" ? symbolResult.result : "",
3605
+ decimals: decimalsResult?.status === "success" ? decimalsResult.result : 18
3606
+ });
3607
+ }
3608
+ const registryAddress = registryResult ? viem.getAddress(registryResult) : null;
3609
+ return {
3610
+ availableAssets: availableAddresses.map((a) => assetInfoMap.get(a)),
3611
+ depositableAssets: depositableAddresses.map((a) => assetInfoMap.get(a)),
3612
+ depositWhitelistEnabled,
3613
+ registryAddress
3614
+ };
3615
+ }
3616
+ async function checkProtocolWhitelist(publicClient, vault, protocols) {
3617
+ const v = viem.getAddress(vault);
3618
+ const registryRaw = await publicClient.readContract({
3619
+ address: v,
3620
+ abi: VAULT_ANALYSIS_ABI,
3621
+ functionName: "moreVaultsRegistry"
3622
+ });
3623
+ const registry = viem.getAddress(registryRaw);
3624
+ if (protocols.length === 0) return {};
3625
+ const results = await publicClient.multicall({
3626
+ contracts: protocols.map((protocol) => ({
3627
+ address: registry,
3628
+ abi: REGISTRY_ABI,
3629
+ functionName: "isWhitelisted",
3630
+ args: [viem.getAddress(protocol)]
3631
+ })),
3632
+ allowFailure: true
3633
+ });
3634
+ const out = {};
3635
+ for (let i = 0; i < protocols.length; i++) {
3636
+ const r = results[i];
3637
+ out[viem.getAddress(protocols[i])] = r?.status === "success" ? r.result : false;
3638
+ }
3639
+ return out;
3640
+ }
3641
+ function encodeCuratorAction(action) {
3642
+ switch (action.type) {
3643
+ case "swap":
3644
+ return viem.encodeFunctionData({
3645
+ abi: DEX_ABI,
3646
+ functionName: "executeSwap",
3647
+ args: [
3648
+ {
3649
+ targetContract: viem.getAddress(action.params.targetContract),
3650
+ tokenIn: viem.getAddress(action.params.tokenIn),
3651
+ tokenOut: viem.getAddress(action.params.tokenOut),
3652
+ maxAmountIn: action.params.maxAmountIn,
3653
+ minAmountOut: action.params.minAmountOut,
3654
+ swapCallData: action.params.swapCallData
3655
+ }
3656
+ ]
3657
+ });
3658
+ case "batchSwap":
3659
+ return viem.encodeFunctionData({
3660
+ abi: DEX_ABI,
3661
+ functionName: "executeBatchSwap",
3662
+ args: [
3663
+ {
3664
+ swaps: action.params.swaps.map((s) => ({
3665
+ targetContract: viem.getAddress(s.targetContract),
3666
+ tokenIn: viem.getAddress(s.tokenIn),
3667
+ tokenOut: viem.getAddress(s.tokenOut),
3668
+ maxAmountIn: s.maxAmountIn,
3669
+ minAmountOut: s.minAmountOut,
3670
+ swapCallData: s.swapCallData
3671
+ }))
3672
+ }
3673
+ ]
3674
+ });
3675
+ case "erc4626Deposit":
3676
+ return viem.encodeFunctionData({
3677
+ abi: ERC4626_FACET_ABI,
3678
+ functionName: "erc4626Deposit",
3679
+ args: [viem.getAddress(action.vault), action.assets]
3680
+ });
3681
+ case "erc4626Redeem":
3682
+ return viem.encodeFunctionData({
3683
+ abi: ERC4626_FACET_ABI,
3684
+ functionName: "erc4626Redeem",
3685
+ args: [viem.getAddress(action.vault), action.shares]
3686
+ });
3687
+ case "erc7540RequestDeposit":
3688
+ return viem.encodeFunctionData({
3689
+ abi: ERC7540_FACET_ABI,
3690
+ functionName: "erc7540RequestDeposit",
3691
+ args: [viem.getAddress(action.vault), action.assets]
3692
+ });
3693
+ case "erc7540Deposit":
3694
+ return viem.encodeFunctionData({
3695
+ abi: ERC7540_FACET_ABI,
3696
+ functionName: "erc7540Deposit",
3697
+ args: [viem.getAddress(action.vault), action.assets]
3698
+ });
3699
+ case "erc7540RequestRedeem":
3700
+ return viem.encodeFunctionData({
3701
+ abi: ERC7540_FACET_ABI,
3702
+ functionName: "erc7540RequestRedeem",
3703
+ args: [viem.getAddress(action.vault), action.shares]
3704
+ });
3705
+ case "erc7540Redeem":
3706
+ return viem.encodeFunctionData({
3707
+ abi: ERC7540_FACET_ABI,
3708
+ functionName: "erc7540Redeem",
3709
+ args: [viem.getAddress(action.vault), action.shares]
3710
+ });
3711
+ default: {
3712
+ const _exhaustive = action;
3713
+ throw new Error(`[MoreVaults] Unknown CuratorAction type: ${_exhaustive.type}`);
3714
+ }
3715
+ }
3716
+ }
3717
+ function buildCuratorBatch(actions) {
3718
+ return actions.map(encodeCuratorAction);
3719
+ }
3720
+ async function submitActions(walletClient, publicClient, vault, actions) {
3721
+ const account = walletClient.account;
3722
+ const v = viem.getAddress(vault);
3723
+ await publicClient.simulateContract({
3724
+ address: v,
3725
+ abi: MULTICALL_ABI,
3726
+ functionName: "submitActions",
3727
+ args: [actions],
3728
+ account: account.address
3729
+ });
3730
+ const txHash = await walletClient.writeContract({
3731
+ address: v,
3732
+ abi: MULTICALL_ABI,
3733
+ functionName: "submitActions",
3734
+ args: [actions],
3735
+ account,
3736
+ chain: walletClient.chain
3737
+ });
3738
+ const nextNonce = await publicClient.readContract({
3739
+ address: v,
3740
+ abi: MULTICALL_ABI,
3741
+ functionName: "getCurrentNonce"
3742
+ });
3743
+ const nonce = nextNonce - 1n;
3744
+ return { txHash, nonce };
3745
+ }
3746
+ async function executeActions(walletClient, publicClient, vault, nonce) {
3747
+ const account = walletClient.account;
3748
+ const v = viem.getAddress(vault);
3749
+ await publicClient.simulateContract({
3750
+ address: v,
3751
+ abi: MULTICALL_ABI,
3752
+ functionName: "executeActions",
3753
+ args: [nonce],
3754
+ account: account.address
3755
+ });
3756
+ const txHash = await walletClient.writeContract({
3757
+ address: v,
3758
+ abi: MULTICALL_ABI,
3759
+ functionName: "executeActions",
3760
+ args: [nonce],
3761
+ account,
3762
+ chain: walletClient.chain
3763
+ });
3764
+ return { txHash };
3765
+ }
3766
+ async function vetoActions(walletClient, publicClient, vault, nonces) {
3767
+ const account = walletClient.account;
3768
+ const v = viem.getAddress(vault);
3769
+ await publicClient.simulateContract({
3770
+ address: v,
3771
+ abi: MULTICALL_ABI,
3772
+ functionName: "vetoActions",
3773
+ args: [nonces],
3774
+ account: account.address
3775
+ });
3776
+ const txHash = await walletClient.writeContract({
3777
+ address: v,
3778
+ abi: MULTICALL_ABI,
3779
+ functionName: "vetoActions",
3780
+ args: [nonces],
3781
+ account,
3782
+ chain: walletClient.chain
3783
+ });
3784
+ return { txHash };
3785
+ }
3514
3786
 
3515
3787
  // src/viem/wagmiCompat.ts
3516
3788
  function asSdkClient(client) {
@@ -3530,6 +3802,7 @@ exports.CapacityFullError = CapacityFullError;
3530
3802
  exports.DEX_ABI = DEX_ABI;
3531
3803
  exports.EID_TO_CHAIN_ID = EID_TO_CHAIN_ID;
3532
3804
  exports.ERC20_ABI = ERC20_ABI;
3805
+ exports.ERC4626_FACET_ABI = ERC4626_FACET_ABI;
3533
3806
  exports.ERC7540_FACET_ABI = ERC7540_FACET_ABI;
3534
3807
  exports.EscrowNotConfiguredError = EscrowNotConfiguredError;
3535
3808
  exports.InsufficientLiquidityError = InsufficientLiquidityError;
@@ -3547,16 +3820,20 @@ exports.NotWhitelistedError = NotWhitelistedError;
3547
3820
  exports.OFT_ABI = OFT_ABI;
3548
3821
  exports.OFT_ROUTES = OFT_ROUTES;
3549
3822
  exports.OMNI_FACTORY_ADDRESS = OMNI_FACTORY_ADDRESS;
3823
+ exports.REGISTRY_ABI = REGISTRY_ABI;
3550
3824
  exports.STARGATE_TAXI_CMD = STARGATE_TAXI_CMD;
3551
3825
  exports.USDC_STARGATE_OFT = USDC_STARGATE_OFT;
3552
3826
  exports.USDC_TOKEN = USDC_TOKEN;
3553
3827
  exports.VAULT_ABI = VAULT_ABI;
3828
+ exports.VAULT_ANALYSIS_ABI = VAULT_ANALYSIS_ABI;
3554
3829
  exports.VaultPausedError = VaultPausedError;
3555
3830
  exports.WrongChainError = WrongChainError;
3556
3831
  exports.asSdkClient = asSdkClient;
3557
3832
  exports.bridgeAssetsToSpoke = bridgeAssetsToSpoke;
3558
3833
  exports.bridgeSharesToHub = bridgeSharesToHub;
3834
+ exports.buildCuratorBatch = buildCuratorBatch;
3559
3835
  exports.canDeposit = canDeposit;
3836
+ exports.checkProtocolWhitelist = checkProtocolWhitelist;
3560
3837
  exports.depositAsync = depositAsync;
3561
3838
  exports.depositCrossChainOracleOn = depositSimple;
3562
3839
  exports.depositFromSpoke = depositFromSpoke;
@@ -3564,7 +3841,9 @@ exports.depositFromSpokeAsync = depositFromSpoke;
3564
3841
  exports.depositMultiAsset = depositMultiAsset;
3565
3842
  exports.depositSimple = depositSimple;
3566
3843
  exports.discoverVaultTopology = discoverVaultTopology;
3844
+ exports.encodeCuratorAction = encodeCuratorAction;
3567
3845
  exports.ensureAllowance = ensureAllowance;
3846
+ exports.executeActions = executeActions;
3568
3847
  exports.executeCompose = executeCompose;
3569
3848
  exports.getAllVaultChainIds = getAllVaultChainIds;
3570
3849
  exports.getAsyncRequestStatus = getAsyncRequestStatus;
@@ -3579,6 +3858,7 @@ exports.getUserBalances = getUserBalances;
3579
3858
  exports.getUserBalancesForRoutes = getUserBalancesForRoutes;
3580
3859
  exports.getUserPosition = getUserPosition;
3581
3860
  exports.getUserPositionMultiChain = getUserPositionMultiChain;
3861
+ exports.getVaultAnalysis = getVaultAnalysis;
3582
3862
  exports.getVaultDistribution = getVaultDistribution;
3583
3863
  exports.getVaultDistributionWithTopology = getVaultDistributionWithTopology;
3584
3864
  exports.getVaultMetadata = getVaultMetadata;
@@ -3608,6 +3888,8 @@ exports.requestRedeem = requestRedeem;
3608
3888
  exports.resolveRedeemAddresses = resolveRedeemAddresses;
3609
3889
  exports.smartDeposit = smartDeposit;
3610
3890
  exports.smartRedeem = smartRedeem;
3891
+ exports.submitActions = submitActions;
3892
+ exports.vetoActions = vetoActions;
3611
3893
  exports.waitForAsyncRequest = waitForAsyncRequest;
3612
3894
  exports.waitForCompose = waitForCompose;
3613
3895
  exports.waitForTx = waitForTx;