@oydual31/more-vaults-sdk 0.3.1 → 0.3.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.
@@ -387,6 +387,18 @@ var LZ_TIMEOUTS = {
387
387
  FULL_SPOKE_REDEEM: 36e5
388
388
  // 60 min
389
389
  };
390
+ var UNISWAP_V3_ROUTERS = {
391
+ [8453]: "0x2626664c2603336E57B271c5C0b26F421741e481",
392
+ // Base — SwapRouter02 (no deadline)
393
+ [1]: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
394
+ // Ethereum — SwapRouter
395
+ [42161]: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
396
+ // Arbitrum — SwapRouter
397
+ [10]: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
398
+ // Optimism — SwapRouter
399
+ [747]: "0xeEDC6Ff75e1b10B903D9013c358e446a73d35341"
400
+ // Flow EVM — FlowSwap V3 SwapRouter
401
+ };
390
402
  var USDC_STARGATE_OFT = Object.fromEntries(
391
403
  Object.entries(OFT_ROUTES.stgUSDC).map(([k, v]) => [k, v.oft])
392
404
  );
@@ -3638,6 +3650,45 @@ async function checkProtocolWhitelist(publicClient, vault, protocols) {
3638
3650
  }
3639
3651
  return out;
3640
3652
  }
3653
+ async function getVaultAssetBreakdown(publicClient, vault) {
3654
+ const v = viem.getAddress(vault);
3655
+ const availableRaw = await publicClient.readContract({
3656
+ address: v,
3657
+ abi: VAULT_ANALYSIS_ABI,
3658
+ functionName: "getAvailableAssets"
3659
+ });
3660
+ const addresses = availableRaw.map(viem.getAddress);
3661
+ const results = await publicClient.multicall({
3662
+ contracts: [
3663
+ // Per-asset: balanceOf, name, symbol, decimals
3664
+ ...addresses.flatMap((addr) => [
3665
+ { address: addr, abi: ERC20_ABI, functionName: "balanceOf", args: [v] },
3666
+ { address: addr, abi: METADATA_ABI, functionName: "name" },
3667
+ { address: addr, abi: METADATA_ABI, functionName: "symbol" },
3668
+ { address: addr, abi: METADATA_ABI, functionName: "decimals" }
3669
+ ]),
3670
+ // Vault totals
3671
+ { address: v, abi: VAULT_ABI, functionName: "totalAssets" },
3672
+ { address: v, abi: VAULT_ABI, functionName: "totalSupply" },
3673
+ { address: v, abi: METADATA_ABI, functionName: "decimals" }
3674
+ ],
3675
+ allowFailure: true
3676
+ });
3677
+ const perAssetFields = 4;
3678
+ const assets = addresses.map((addr, i) => {
3679
+ const base = i * perAssetFields;
3680
+ const balance = results[base]?.status === "success" ? results[base].result : 0n;
3681
+ const name = results[base + 1]?.status === "success" ? results[base + 1].result : "";
3682
+ const symbol = results[base + 2]?.status === "success" ? results[base + 2].result : "";
3683
+ const decimals = results[base + 3]?.status === "success" ? results[base + 3].result : 18;
3684
+ return { address: addr, name, symbol, decimals, balance };
3685
+ });
3686
+ const totalsBase = addresses.length * perAssetFields;
3687
+ const totalAssets = results[totalsBase]?.status === "success" ? results[totalsBase].result : 0n;
3688
+ const totalSupply = results[totalsBase + 1]?.status === "success" ? results[totalsBase + 1].result : 0n;
3689
+ const underlyingDecimals = results[totalsBase + 2]?.status === "success" ? results[totalsBase + 2].result : 6;
3690
+ return { assets, totalAssets, totalSupply, underlyingDecimals };
3691
+ }
3641
3692
  function encodeCuratorAction(action) {
3642
3693
  switch (action.type) {
3643
3694
  case "swap":
@@ -3783,6 +3834,114 @@ async function vetoActions(walletClient, publicClient, vault, nonces) {
3783
3834
  });
3784
3835
  return { txHash };
3785
3836
  }
3837
+ var UNISWAP_V3_SWAP_ROUTER_ABI = [
3838
+ {
3839
+ type: "function",
3840
+ name: "exactInputSingle",
3841
+ inputs: [
3842
+ {
3843
+ type: "tuple",
3844
+ name: "params",
3845
+ components: [
3846
+ { name: "tokenIn", type: "address" },
3847
+ { name: "tokenOut", type: "address" },
3848
+ { name: "fee", type: "uint24" },
3849
+ { name: "recipient", type: "address" },
3850
+ { name: "deadline", type: "uint256" },
3851
+ { name: "amountIn", type: "uint256" },
3852
+ { name: "amountOutMinimum", type: "uint256" },
3853
+ { name: "sqrtPriceLimitX96", type: "uint160" }
3854
+ ]
3855
+ }
3856
+ ],
3857
+ outputs: [{ name: "amountOut", type: "uint256" }],
3858
+ stateMutability: "payable"
3859
+ }
3860
+ ];
3861
+ var UNISWAP_V3_SWAP_ROUTER02_ABI = [
3862
+ {
3863
+ type: "function",
3864
+ name: "exactInputSingle",
3865
+ inputs: [
3866
+ {
3867
+ type: "tuple",
3868
+ name: "params",
3869
+ components: [
3870
+ { name: "tokenIn", type: "address" },
3871
+ { name: "tokenOut", type: "address" },
3872
+ { name: "fee", type: "uint24" },
3873
+ { name: "recipient", type: "address" },
3874
+ { name: "amountIn", type: "uint256" },
3875
+ { name: "amountOutMinimum", type: "uint256" },
3876
+ { name: "sqrtPriceLimitX96", type: "uint160" }
3877
+ ]
3878
+ }
3879
+ ],
3880
+ outputs: [{ name: "amountOut", type: "uint256" }],
3881
+ stateMutability: "payable"
3882
+ }
3883
+ ];
3884
+ var SWAP_ROUTER02_CHAINS = /* @__PURE__ */ new Set([8453]);
3885
+ function encodeUniswapV3SwapCalldata(params) {
3886
+ const { chainId, tokenIn, tokenOut, fee, amountIn, minAmountOut, recipient } = params;
3887
+ const router = UNISWAP_V3_ROUTERS[chainId];
3888
+ if (!router) {
3889
+ throw new Error(
3890
+ `[MoreVaults] No Uniswap V3 router configured for chainId ${chainId}. Supported chains: ${Object.keys(UNISWAP_V3_ROUTERS).join(", ")}`
3891
+ );
3892
+ }
3893
+ let swapCallData;
3894
+ if (SWAP_ROUTER02_CHAINS.has(chainId)) {
3895
+ swapCallData = viem.encodeFunctionData({
3896
+ abi: UNISWAP_V3_SWAP_ROUTER02_ABI,
3897
+ functionName: "exactInputSingle",
3898
+ args: [
3899
+ {
3900
+ tokenIn,
3901
+ tokenOut,
3902
+ fee,
3903
+ recipient,
3904
+ amountIn,
3905
+ amountOutMinimum: minAmountOut,
3906
+ sqrtPriceLimitX96: 0n
3907
+ }
3908
+ ]
3909
+ });
3910
+ } else {
3911
+ const deadline = BigInt(Math.floor(Date.now() / 1e3) + 1200);
3912
+ swapCallData = viem.encodeFunctionData({
3913
+ abi: UNISWAP_V3_SWAP_ROUTER_ABI,
3914
+ functionName: "exactInputSingle",
3915
+ args: [
3916
+ {
3917
+ tokenIn,
3918
+ tokenOut,
3919
+ fee,
3920
+ recipient,
3921
+ deadline,
3922
+ amountIn,
3923
+ amountOutMinimum: minAmountOut,
3924
+ sqrtPriceLimitX96: 0n
3925
+ }
3926
+ ]
3927
+ });
3928
+ }
3929
+ return { targetContract: router, swapCallData };
3930
+ }
3931
+ function buildUniswapV3Swap(params) {
3932
+ const { targetContract, swapCallData } = encodeUniswapV3SwapCalldata(params);
3933
+ return {
3934
+ type: "swap",
3935
+ params: {
3936
+ targetContract,
3937
+ tokenIn: params.tokenIn,
3938
+ tokenOut: params.tokenOut,
3939
+ maxAmountIn: params.amountIn,
3940
+ minAmountOut: params.minAmountOut,
3941
+ swapCallData
3942
+ }
3943
+ };
3944
+ }
3786
3945
 
3787
3946
  // src/viem/wagmiCompat.ts
3788
3947
  function asSdkClient(client) {
@@ -3822,6 +3981,7 @@ exports.OFT_ROUTES = OFT_ROUTES;
3822
3981
  exports.OMNI_FACTORY_ADDRESS = OMNI_FACTORY_ADDRESS;
3823
3982
  exports.REGISTRY_ABI = REGISTRY_ABI;
3824
3983
  exports.STARGATE_TAXI_CMD = STARGATE_TAXI_CMD;
3984
+ exports.UNISWAP_V3_ROUTERS = UNISWAP_V3_ROUTERS;
3825
3985
  exports.USDC_STARGATE_OFT = USDC_STARGATE_OFT;
3826
3986
  exports.USDC_TOKEN = USDC_TOKEN;
3827
3987
  exports.VAULT_ABI = VAULT_ABI;
@@ -3832,6 +3992,7 @@ exports.asSdkClient = asSdkClient;
3832
3992
  exports.bridgeAssetsToSpoke = bridgeAssetsToSpoke;
3833
3993
  exports.bridgeSharesToHub = bridgeSharesToHub;
3834
3994
  exports.buildCuratorBatch = buildCuratorBatch;
3995
+ exports.buildUniswapV3Swap = buildUniswapV3Swap;
3835
3996
  exports.canDeposit = canDeposit;
3836
3997
  exports.checkProtocolWhitelist = checkProtocolWhitelist;
3837
3998
  exports.depositAsync = depositAsync;
@@ -3842,6 +4003,7 @@ exports.depositMultiAsset = depositMultiAsset;
3842
4003
  exports.depositSimple = depositSimple;
3843
4004
  exports.discoverVaultTopology = discoverVaultTopology;
3844
4005
  exports.encodeCuratorAction = encodeCuratorAction;
4006
+ exports.encodeUniswapV3SwapCalldata = encodeUniswapV3SwapCalldata;
3845
4007
  exports.ensureAllowance = ensureAllowance;
3846
4008
  exports.executeActions = executeActions;
3847
4009
  exports.executeCompose = executeCompose;
@@ -3859,6 +4021,7 @@ exports.getUserBalancesForRoutes = getUserBalancesForRoutes;
3859
4021
  exports.getUserPosition = getUserPosition;
3860
4022
  exports.getUserPositionMultiChain = getUserPositionMultiChain;
3861
4023
  exports.getVaultAnalysis = getVaultAnalysis;
4024
+ exports.getVaultAssetBreakdown = getVaultAssetBreakdown;
3862
4025
  exports.getVaultDistribution = getVaultDistribution;
3863
4026
  exports.getVaultDistributionWithTopology = getVaultDistributionWithTopology;
3864
4027
  exports.getVaultMetadata = getVaultMetadata;