@1llet.xyz/erc4337-gasless-sdk 0.4.68 → 0.4.71

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/dist/index.mjs CHANGED
@@ -2827,74 +2827,90 @@ init_TransferManager();
2827
2827
  init_near();
2828
2828
  init_cctp2();
2829
2829
  init_stargate();
2830
- var SWAP_ROUTER_02 = "0x2626664c2603336E57B271c5C0b26F421741e481";
2831
- var QUOTER_V2 = "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a";
2830
+ var UNISWAP_V3_ROUTER = "0x2626664c2603336E57B271c5C0b26F421741e481";
2831
+ var UNISWAP_V3_QUOTER = "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a";
2832
2832
  var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
2833
2833
  var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
2834
2834
  var QUOTER_ABI = parseAbi([
2835
- "function quoteExactOutputSingle(tuple(address tokenIn, address tokenOut, uint256 amount, uint24 fee, uint160 sqrtPriceLimitX96) params) external returns (uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)"
2835
+ "function quoteExactOutputSingle((address tokenIn, address tokenOut, uint256 amount, uint24 fee, uint160 sqrtPriceLimitX96) params) external returns (uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)"
2836
2836
  ]);
2837
2837
  var ROUTER_ABI = parseAbi([
2838
- "function exactOutputSingle(tuple(address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountIn)"
2838
+ "function exactOutputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountIn)"
2839
2839
  ]);
2840
2840
  var UniswapService = class {
2841
- constructor(rpcUrl) {
2841
+ constructor() {
2842
2842
  this.publicClient = createPublicClient({
2843
- transport: http(rpcUrl)
2843
+ chain: base,
2844
+ transport: http("https://mainnet.base.org")
2845
+ // Default public RPC
2844
2846
  });
2845
2847
  }
2846
2848
  /**
2847
- * Quote USDC needed for exact ETH output using Uniswap V3
2849
+ * Get amount of USDC needed to buy exact amount of ETH
2850
+ * @param amountETHWei Amount of ETH (Wei) needed
2848
2851
  */
2849
- async quoteUSDCForETH(amountOutETH) {
2852
+ async quoteUSDCForETH(amountETHWei) {
2850
2853
  try {
2854
+ const params = {
2855
+ tokenIn: USDC_ADDRESS,
2856
+ tokenOut: WETH_ADDRESS,
2857
+ amount: amountETHWei,
2858
+ fee: 500,
2859
+ sqrtPriceLimitX96: 0n
2860
+ };
2851
2861
  const result = await this.publicClient.readContract({
2852
- address: QUOTER_V2,
2862
+ address: UNISWAP_V3_QUOTER,
2853
2863
  abi: QUOTER_ABI,
2854
2864
  functionName: "quoteExactOutputSingle",
2855
- args: [{
2856
- tokenIn: USDC_ADDRESS,
2857
- tokenOut: WETH_ADDRESS,
2858
- amount: amountOutETH,
2859
- fee: 500,
2860
- // 0.05%
2861
- sqrtPriceLimitX96: 0n
2862
- }]
2865
+ args: [params]
2863
2866
  });
2864
2867
  const amountIn = result[0];
2865
2868
  return amountIn * 105n / 100n;
2866
- } catch (error) {
2867
- console.error("Failed to quote USDC for ETH swap on Uniswap V3", error);
2868
- throw new Error(`Failed to quote USDC for ETH swap on Uniswap V3`);
2869
+ } catch (e) {
2870
+ console.error("Quote failed", e);
2871
+ throw new Error("Failed to quote USDC for ETH swap");
2869
2872
  }
2870
2873
  }
2871
2874
  /**
2872
- * Build tx data for swapping USDC -> ETH using Uniswap V3 SwapRouter02
2875
+ * Build tx data for swapping USDC -> ETH
2876
+ * Uses SwapRouter02.exactOutputSingle + unwrapWETH9
2873
2877
  */
2874
- buildSwapData(recipient, amountInMax, amountOutETH) {
2875
- return encodeFunctionData({
2878
+ buildSwapData(recipient, amountOutETH, maxAmountInUSDC) {
2879
+ const swapParams = {
2880
+ tokenIn: USDC_ADDRESS,
2881
+ tokenOut: WETH_ADDRESS,
2882
+ fee: 500,
2883
+ recipient: UNISWAP_V3_ROUTER,
2884
+ // Router must hold WETH to unwrap it
2885
+ amountOut: amountOutETH,
2886
+ amountInMaximum: maxAmountInUSDC,
2887
+ sqrtPriceLimitX96: 0n
2888
+ };
2889
+ const swapCalldata = encodeFunctionData({
2876
2890
  abi: ROUTER_ABI,
2877
2891
  functionName: "exactOutputSingle",
2878
- args: [{
2879
- tokenIn: USDC_ADDRESS,
2880
- tokenOut: WETH_ADDRESS,
2881
- fee: 500,
2882
- // 0.05%
2883
- recipient,
2884
- amountOut: amountOutETH,
2885
- amountInMaximum: amountInMax,
2886
- sqrtPriceLimitX96: 0n
2887
- }]
2892
+ args: [swapParams]
2893
+ });
2894
+ const unwrapCalldata = encodeFunctionData({
2895
+ abi: parseAbi(["function unwrapWETH9(uint256 amountMinimum, address recipient) payable"]),
2896
+ functionName: "unwrapWETH9",
2897
+ args: [amountOutETH, recipient]
2898
+ });
2899
+ const multicallCalldata = encodeFunctionData({
2900
+ abi: parseAbi(["function multicall(bytes[] data) payable returns (bytes[])"]),
2901
+ functionName: "multicall",
2902
+ args: [[swapCalldata, unwrapCalldata]]
2888
2903
  });
2904
+ return multicallCalldata;
2889
2905
  }
2890
2906
  getRouterAddress() {
2891
- return SWAP_ROUTER_02;
2907
+ return UNISWAP_V3_ROUTER;
2892
2908
  }
2893
2909
  getUSDCAddress() {
2894
2910
  return USDC_ADDRESS;
2895
2911
  }
2896
2912
  };
2897
- var uniswapService = new UniswapService("https://mainnet.base.org");
2913
+ var uniswapService = new UniswapService();
2898
2914
 
2899
2915
  export { AccountAbstraction, BASE_MAINNET, BASE_SEPOLIA2 as BASE_SEPOLIA, BundlerClient, CCTPStrategy, CHAIN_CONFIGS, CHAIN_ID_TO_KEY, GNOSIS_MAINNET, NearStrategy, OPTIMISM_MAINNET, STELLAR, STELLAR_MAINNET, StargateStrategy, StellarService, TransferManager, UniswapService, entryPointAbi, erc20Abi, getNearSimulation, getStargateSimulation, smartAccountAbi, uniswapService };
2900
2916
  //# sourceMappingURL=index.mjs.map