@oydual31/more-vaults-sdk 0.3.1 → 0.3.3

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.
@@ -385,6 +385,18 @@ var LZ_TIMEOUTS = {
385
385
  FULL_SPOKE_REDEEM: 36e5
386
386
  // 60 min
387
387
  };
388
+ var UNISWAP_V3_ROUTERS = {
389
+ [8453]: "0x2626664c2603336E57B271c5C0b26F421741e481",
390
+ // Base — SwapRouter02 (no deadline)
391
+ [1]: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
392
+ // Ethereum — SwapRouter
393
+ [42161]: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
394
+ // Arbitrum — SwapRouter
395
+ [10]: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
396
+ // Optimism — SwapRouter
397
+ [747]: "0xeEDC6Ff75e1b10B903D9013c358e446a73d35341"
398
+ // Flow EVM — FlowSwap V3 SwapRouter
399
+ };
388
400
  var USDC_STARGATE_OFT = Object.fromEntries(
389
401
  Object.entries(OFT_ROUTES.stgUSDC).map(([k, v]) => [k, v.oft])
390
402
  );
@@ -1456,6 +1468,27 @@ async function waitForAsyncRequest(publicClient, vault, guid, pollInterval = 3e4
1456
1468
  `[MoreVaults] Async request ${guid} did not finalize within ${timeout / 1e3}s. The request may still complete \u2014 check https://layerzeroscan.com/tx/${guid}`
1457
1469
  );
1458
1470
  }
1471
+ var STARGATE_TYPE_ABI = [
1472
+ {
1473
+ type: "function",
1474
+ name: "stargateType",
1475
+ inputs: [],
1476
+ outputs: [{ type: "uint8" }],
1477
+ stateMutability: "view"
1478
+ }
1479
+ ];
1480
+ async function detectStargateOft(publicClient, oft) {
1481
+ try {
1482
+ await publicClient.readContract({
1483
+ address: getAddress(oft),
1484
+ abi: STARGATE_TYPE_ABI,
1485
+ functionName: "stargateType"
1486
+ });
1487
+ return true;
1488
+ } catch {
1489
+ return false;
1490
+ }
1491
+ }
1459
1492
  var PUBLIC_RPCS = {
1460
1493
  1: [
1461
1494
  "https://ethereum-rpc.publicnode.com",
@@ -1854,21 +1887,11 @@ var COMPOSER_ABI = [
1854
1887
  stateMutability: "view"
1855
1888
  }
1856
1889
  ];
1857
- var STARGATE_ASSETS = /* @__PURE__ */ new Set(["stgUSDC", "USDT", "WETH"]);
1858
1890
  function buildLzComposeOption(gas, nativeValue) {
1859
1891
  const gasHex = gas.toString(16).padStart(32, "0");
1860
1892
  const valueHex = nativeValue.toString(16).padStart(32, "0");
1861
1893
  return `0x00030300220000${gasHex}${valueHex}`;
1862
1894
  }
1863
- function isStargateOft(oft) {
1864
- for (const [symbol, chainMap] of Object.entries(OFT_ROUTES)) {
1865
- if (!STARGATE_ASSETS.has(symbol)) continue;
1866
- for (const entry of Object.values(chainMap)) {
1867
- if (getAddress(entry.oft) === oft) return true;
1868
- }
1869
- }
1870
- return false;
1871
- }
1872
1895
  async function resolveComposeNativeValue(hubClient, vault, composerAddress, spokeEid, receiverBytes32) {
1873
1896
  const [readFeeResult, shareOftResult] = await Promise.allSettled([
1874
1897
  hubClient.readContract({
@@ -1932,7 +1955,7 @@ async function depositFromSpoke(walletClient, publicClient, vault, spokeOFT, hub
1932
1955
  if (composerAddress === zeroAddress) throw new Error(`No composer registered for vault ${vault} on hub chainId ${hubChainId}`);
1933
1956
  const composerBytes32 = pad(composerAddress, { size: 32 });
1934
1957
  const receiverBytes32 = pad(getAddress(receiver), { size: 32 });
1935
- const isStargate = isStargateOft(oft);
1958
+ const isStargate = await detectStargateOft(publicClient, oft);
1936
1959
  let resolvedExtraOptions;
1937
1960
  if (extraOptions !== "0x") {
1938
1961
  resolvedExtraOptions = extraOptions;
@@ -2029,7 +2052,7 @@ async function depositFromSpoke(walletClient, publicClient, vault, spokeOFT, hub
2029
2052
  account,
2030
2053
  chain: walletClient.chain
2031
2054
  });
2032
- const stargate = isStargateOft(getAddress(spokeOFT));
2055
+ const stargate = isStargate;
2033
2056
  let composeData;
2034
2057
  if (stargate) {
2035
2058
  const hubBlockStart = await hubClient.getBlockNumber();
@@ -2063,7 +2086,7 @@ async function quoteDepositFromSpokeFee(publicClient, vault, spokeOFT, hubEid, s
2063
2086
  args: [getAddress(vault)]
2064
2087
  });
2065
2088
  const composerBytes32 = pad(composerAddress, { size: 32 });
2066
- const isStargate = isStargateOft(oft);
2089
+ const isStargate = await detectStargateOft(publicClient, oft);
2067
2090
  let resolvedExtraOptions;
2068
2091
  if (extraOptions !== "0x") {
2069
2092
  resolvedExtraOptions = extraOptions;
@@ -2132,13 +2155,16 @@ async function waitForCompose(hubPublicClient, composeData, receiver, pollInterv
2132
2155
  const endpoint = getAddress(composeData.endpoint);
2133
2156
  const receiverNeedle = getAddress(receiver).slice(2).toLowerCase();
2134
2157
  const startBlock = composeData.hubBlockStart;
2135
- const knownFromAddresses = [];
2136
2158
  const hubChainId = composeData.hubChainId;
2137
- for (const [symbol, chainMap] of Object.entries(OFT_ROUTES)) {
2138
- if (!STARGATE_ASSETS.has(symbol)) continue;
2159
+ const candidateAddresses = [];
2160
+ for (const chainMap of Object.values(OFT_ROUTES)) {
2139
2161
  const entry = chainMap[hubChainId];
2140
- if (entry) knownFromAddresses.push(getAddress(entry.oft));
2162
+ if (entry) candidateAddresses.push(getAddress(entry.oft));
2141
2163
  }
2164
+ const stargateChecks = await Promise.all(
2165
+ candidateAddresses.map(async (addr) => ({ addr, isSg: await detectStargateOft(hubPublicClient, addr) }))
2166
+ );
2167
+ const knownFromAddresses = stargateChecks.filter((c) => c.isSg).map((c) => c.addr);
2142
2168
  let attempt = 0;
2143
2169
  let scannedUpTo = startBlock - 1n;
2144
2170
  while (Date.now() < deadline) {
@@ -2471,14 +2497,7 @@ async function preflightSpokeDeposit(spokePublicClient, vault, spokeOFT, hubEid,
2471
2497
  Have: ${spokeNativeBalance} wei`
2472
2498
  );
2473
2499
  }
2474
- const STARGATE_ASSETS3 = /* @__PURE__ */ new Set(["stgUSDC", "USDT", "WETH"]);
2475
- let isStargate = false;
2476
- for (const [symbol, chainMap] of Object.entries(OFT_ROUTES)) {
2477
- if (!STARGATE_ASSETS3.has(symbol)) continue;
2478
- for (const entry of Object.values(chainMap)) {
2479
- if (getAddress(entry.oft) === oft) isStargate = true;
2480
- }
2481
- }
2500
+ const isStargate = await detectStargateOft(spokePublicClient, oft);
2482
2501
  let hubNativeBalance = 0n;
2483
2502
  let estimatedComposeFee = 0n;
2484
2503
  if (isStargate) {
@@ -2980,7 +2999,6 @@ async function bridgeAssetsToSpoke(walletClient, publicClient, assetOFT, spokeCh
2980
2999
  });
2981
3000
  return { txHash };
2982
3001
  }
2983
- var STARGATE_ASSETS2 = /* @__PURE__ */ new Set(["stgUSDC", "USDT", "WETH"]);
2984
3002
  var FACTORY_COMPOSER_ABI2 = [
2985
3003
  {
2986
3004
  type: "function",
@@ -3030,7 +3048,6 @@ async function resolveRedeemAddresses(hubPublicClient, vault, hubChainId, spokeC
3030
3048
  const spokeShareOft = getAddress(`0x${spokeShareOftBytes32.slice(-40)}`);
3031
3049
  let hubAssetOft = null;
3032
3050
  let spokeAsset = null;
3033
- let isStargate = false;
3034
3051
  let symbol = "";
3035
3052
  for (const [sym, chainMap] of Object.entries(OFT_ROUTES)) {
3036
3053
  const hubEntry = chainMap[hubChainId];
@@ -3039,7 +3056,6 @@ async function resolveRedeemAddresses(hubPublicClient, vault, hubChainId, spokeC
3039
3056
  if (getAddress(hubEntry.token) === getAddress(hubAsset)) {
3040
3057
  hubAssetOft = getAddress(hubEntry.oft);
3041
3058
  spokeAsset = getAddress(spokeEntry.token);
3042
- isStargate = STARGATE_ASSETS2.has(sym);
3043
3059
  symbol = sym;
3044
3060
  break;
3045
3061
  }
@@ -3049,6 +3065,7 @@ async function resolveRedeemAddresses(hubPublicClient, vault, hubChainId, spokeC
3049
3065
  `[MoreVaults] No OFT route found for vault asset ${hubAsset} between hub chain ${hubChainId} and spoke chain ${spokeChainId}`
3050
3066
  );
3051
3067
  }
3068
+ const isStargate = await detectStargateOft(hubPublicClient, hubAssetOft);
3052
3069
  return {
3053
3070
  hubChainId,
3054
3071
  spokeChainId,
@@ -3636,6 +3653,45 @@ async function checkProtocolWhitelist(publicClient, vault, protocols) {
3636
3653
  }
3637
3654
  return out;
3638
3655
  }
3656
+ async function getVaultAssetBreakdown(publicClient, vault) {
3657
+ const v = getAddress(vault);
3658
+ const availableRaw = await publicClient.readContract({
3659
+ address: v,
3660
+ abi: VAULT_ANALYSIS_ABI,
3661
+ functionName: "getAvailableAssets"
3662
+ });
3663
+ const addresses = availableRaw.map(getAddress);
3664
+ const results = await publicClient.multicall({
3665
+ contracts: [
3666
+ // Per-asset: balanceOf, name, symbol, decimals
3667
+ ...addresses.flatMap((addr) => [
3668
+ { address: addr, abi: ERC20_ABI, functionName: "balanceOf", args: [v] },
3669
+ { address: addr, abi: METADATA_ABI, functionName: "name" },
3670
+ { address: addr, abi: METADATA_ABI, functionName: "symbol" },
3671
+ { address: addr, abi: METADATA_ABI, functionName: "decimals" }
3672
+ ]),
3673
+ // Vault totals
3674
+ { address: v, abi: VAULT_ABI, functionName: "totalAssets" },
3675
+ { address: v, abi: VAULT_ABI, functionName: "totalSupply" },
3676
+ { address: v, abi: METADATA_ABI, functionName: "decimals" }
3677
+ ],
3678
+ allowFailure: true
3679
+ });
3680
+ const perAssetFields = 4;
3681
+ const assets = addresses.map((addr, i) => {
3682
+ const base = i * perAssetFields;
3683
+ const balance = results[base]?.status === "success" ? results[base].result : 0n;
3684
+ const name = results[base + 1]?.status === "success" ? results[base + 1].result : "";
3685
+ const symbol = results[base + 2]?.status === "success" ? results[base + 2].result : "";
3686
+ const decimals = results[base + 3]?.status === "success" ? results[base + 3].result : 18;
3687
+ return { address: addr, name, symbol, decimals, balance };
3688
+ });
3689
+ const totalsBase = addresses.length * perAssetFields;
3690
+ const totalAssets = results[totalsBase]?.status === "success" ? results[totalsBase].result : 0n;
3691
+ const totalSupply = results[totalsBase + 1]?.status === "success" ? results[totalsBase + 1].result : 0n;
3692
+ const underlyingDecimals = results[totalsBase + 2]?.status === "success" ? results[totalsBase + 2].result : 6;
3693
+ return { assets, totalAssets, totalSupply, underlyingDecimals };
3694
+ }
3639
3695
  function encodeCuratorAction(action) {
3640
3696
  switch (action.type) {
3641
3697
  case "swap":
@@ -3781,6 +3837,114 @@ async function vetoActions(walletClient, publicClient, vault, nonces) {
3781
3837
  });
3782
3838
  return { txHash };
3783
3839
  }
3840
+ var UNISWAP_V3_SWAP_ROUTER_ABI = [
3841
+ {
3842
+ type: "function",
3843
+ name: "exactInputSingle",
3844
+ inputs: [
3845
+ {
3846
+ type: "tuple",
3847
+ name: "params",
3848
+ components: [
3849
+ { name: "tokenIn", type: "address" },
3850
+ { name: "tokenOut", type: "address" },
3851
+ { name: "fee", type: "uint24" },
3852
+ { name: "recipient", type: "address" },
3853
+ { name: "deadline", type: "uint256" },
3854
+ { name: "amountIn", type: "uint256" },
3855
+ { name: "amountOutMinimum", type: "uint256" },
3856
+ { name: "sqrtPriceLimitX96", type: "uint160" }
3857
+ ]
3858
+ }
3859
+ ],
3860
+ outputs: [{ name: "amountOut", type: "uint256" }],
3861
+ stateMutability: "payable"
3862
+ }
3863
+ ];
3864
+ var UNISWAP_V3_SWAP_ROUTER02_ABI = [
3865
+ {
3866
+ type: "function",
3867
+ name: "exactInputSingle",
3868
+ inputs: [
3869
+ {
3870
+ type: "tuple",
3871
+ name: "params",
3872
+ components: [
3873
+ { name: "tokenIn", type: "address" },
3874
+ { name: "tokenOut", type: "address" },
3875
+ { name: "fee", type: "uint24" },
3876
+ { name: "recipient", type: "address" },
3877
+ { name: "amountIn", type: "uint256" },
3878
+ { name: "amountOutMinimum", type: "uint256" },
3879
+ { name: "sqrtPriceLimitX96", type: "uint160" }
3880
+ ]
3881
+ }
3882
+ ],
3883
+ outputs: [{ name: "amountOut", type: "uint256" }],
3884
+ stateMutability: "payable"
3885
+ }
3886
+ ];
3887
+ var SWAP_ROUTER02_CHAINS = /* @__PURE__ */ new Set([8453]);
3888
+ function encodeUniswapV3SwapCalldata(params) {
3889
+ const { chainId, tokenIn, tokenOut, fee, amountIn, minAmountOut, recipient } = params;
3890
+ const router = UNISWAP_V3_ROUTERS[chainId];
3891
+ if (!router) {
3892
+ throw new Error(
3893
+ `[MoreVaults] No Uniswap V3 router configured for chainId ${chainId}. Supported chains: ${Object.keys(UNISWAP_V3_ROUTERS).join(", ")}`
3894
+ );
3895
+ }
3896
+ let swapCallData;
3897
+ if (SWAP_ROUTER02_CHAINS.has(chainId)) {
3898
+ swapCallData = encodeFunctionData({
3899
+ abi: UNISWAP_V3_SWAP_ROUTER02_ABI,
3900
+ functionName: "exactInputSingle",
3901
+ args: [
3902
+ {
3903
+ tokenIn,
3904
+ tokenOut,
3905
+ fee,
3906
+ recipient,
3907
+ amountIn,
3908
+ amountOutMinimum: minAmountOut,
3909
+ sqrtPriceLimitX96: 0n
3910
+ }
3911
+ ]
3912
+ });
3913
+ } else {
3914
+ const deadline = BigInt(Math.floor(Date.now() / 1e3) + 1200);
3915
+ swapCallData = encodeFunctionData({
3916
+ abi: UNISWAP_V3_SWAP_ROUTER_ABI,
3917
+ functionName: "exactInputSingle",
3918
+ args: [
3919
+ {
3920
+ tokenIn,
3921
+ tokenOut,
3922
+ fee,
3923
+ recipient,
3924
+ deadline,
3925
+ amountIn,
3926
+ amountOutMinimum: minAmountOut,
3927
+ sqrtPriceLimitX96: 0n
3928
+ }
3929
+ ]
3930
+ });
3931
+ }
3932
+ return { targetContract: router, swapCallData };
3933
+ }
3934
+ function buildUniswapV3Swap(params) {
3935
+ const { targetContract, swapCallData } = encodeUniswapV3SwapCalldata(params);
3936
+ return {
3937
+ type: "swap",
3938
+ params: {
3939
+ targetContract,
3940
+ tokenIn: params.tokenIn,
3941
+ tokenOut: params.tokenOut,
3942
+ maxAmountIn: params.amountIn,
3943
+ minAmountOut: params.minAmountOut,
3944
+ swapCallData
3945
+ }
3946
+ };
3947
+ }
3784
3948
 
3785
3949
  // src/viem/wagmiCompat.ts
3786
3950
  function asSdkClient(client) {
@@ -3788,6 +3952,6 @@ function asSdkClient(client) {
3788
3952
  return client;
3789
3953
  }
3790
3954
 
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 };
3955
+ 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, UNISWAP_V3_ROUTERS, USDC_STARGATE_OFT, USDC_TOKEN, VAULT_ABI, VAULT_ANALYSIS_ABI, VaultPausedError, WrongChainError, asSdkClient, bridgeAssetsToSpoke, bridgeSharesToHub, buildCuratorBatch, buildUniswapV3Swap, canDeposit, checkProtocolWhitelist, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as depositFromSpokeAsync, depositMultiAsset, depositSimple, detectStargateOft, discoverVaultTopology, encodeCuratorAction, encodeUniswapV3SwapCalldata, ensureAllowance, executeActions, executeCompose, getAllVaultChainIds, getAsyncRequestStatus, getAsyncRequestStatusLabel, getCuratorVaultStatus, getFullVaultTopology, getInboundRoutes, getMaxWithdrawable, getOutboundRoutes, getPendingActions, getUserBalances, getUserBalancesForRoutes, getUserPosition, getUserPositionMultiChain, getVaultAnalysis, getVaultAssetBreakdown, 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 };
3792
3956
  //# sourceMappingURL=index.js.map
3793
3957
  //# sourceMappingURL=index.js.map