@1llet.xyz/erc4337-gasless-sdk 0.4.70 → 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.d.mts CHANGED
@@ -510,15 +510,17 @@ declare function getStargateSimulation(sourceChain: string, destChain: string, a
510
510
 
511
511
  declare class UniswapService {
512
512
  private publicClient;
513
- constructor(rpcUrl: string);
513
+ constructor();
514
514
  /**
515
- * Quote USDC needed for exact ETH output using Uniswap V3
515
+ * Get amount of USDC needed to buy exact amount of ETH
516
+ * @param amountETHWei Amount of ETH (Wei) needed
516
517
  */
517
- quoteUSDCForETH(amountOutETH: bigint): Promise<bigint>;
518
+ quoteUSDCForETH(amountETHWei: bigint): Promise<bigint>;
518
519
  /**
519
- * Build tx data for swapping USDC -> ETH using Uniswap V3 SwapRouter02
520
+ * Build tx data for swapping USDC -> ETH
521
+ * Uses SwapRouter02.exactOutputSingle + unwrapWETH9
520
522
  */
521
- buildSwapData(recipient: Address, amountInMax: bigint, amountOutETH: bigint): Hex;
523
+ buildSwapData(recipient: Address, amountOutETH: bigint, maxAmountInUSDC: bigint): Hex;
522
524
  getRouterAddress(): Address;
523
525
  getUSDCAddress(): Address;
524
526
  }
package/dist/index.d.ts CHANGED
@@ -510,15 +510,17 @@ declare function getStargateSimulation(sourceChain: string, destChain: string, a
510
510
 
511
511
  declare class UniswapService {
512
512
  private publicClient;
513
- constructor(rpcUrl: string);
513
+ constructor();
514
514
  /**
515
- * Quote USDC needed for exact ETH output using Uniswap V3
515
+ * Get amount of USDC needed to buy exact amount of ETH
516
+ * @param amountETHWei Amount of ETH (Wei) needed
516
517
  */
517
- quoteUSDCForETH(amountOutETH: bigint): Promise<bigint>;
518
+ quoteUSDCForETH(amountETHWei: bigint): Promise<bigint>;
518
519
  /**
519
- * Build tx data for swapping USDC -> ETH using Uniswap V3 SwapRouter02
520
+ * Build tx data for swapping USDC -> ETH
521
+ * Uses SwapRouter02.exactOutputSingle + unwrapWETH9
520
522
  */
521
- buildSwapData(recipient: Address, amountInMax: bigint, amountOutETH: bigint): Hex;
523
+ buildSwapData(recipient: Address, amountOutETH: bigint, maxAmountInUSDC: bigint): Hex;
522
524
  getRouterAddress(): Address;
523
525
  getUSDCAddress(): Address;
524
526
  }
package/dist/index.js CHANGED
@@ -2851,8 +2851,8 @@ init_TransferManager();
2851
2851
  init_near();
2852
2852
  init_cctp2();
2853
2853
  init_stargate();
2854
- var SWAP_ROUTER_02 = "0x2626664c2603336E57B271c5C0b26F421741e481";
2855
- var QUOTER_V2 = "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a";
2854
+ var UNISWAP_V3_ROUTER = "0x2626664c2603336E57B271c5C0b26F421741e481";
2855
+ var UNISWAP_V3_QUOTER = "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a";
2856
2856
  var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
2857
2857
  var WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
2858
2858
  var QUOTER_ABI = viem.parseAbi([
@@ -2862,63 +2862,79 @@ var ROUTER_ABI = viem.parseAbi([
2862
2862
  "function exactOutputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountIn)"
2863
2863
  ]);
2864
2864
  var UniswapService = class {
2865
- constructor(rpcUrl) {
2865
+ constructor() {
2866
2866
  this.publicClient = viem.createPublicClient({
2867
- transport: viem.http(rpcUrl)
2867
+ chain: chains.base,
2868
+ transport: viem.http("https://mainnet.base.org")
2869
+ // Default public RPC
2868
2870
  });
2869
2871
  }
2870
2872
  /**
2871
- * Quote USDC needed for exact ETH output using Uniswap V3
2873
+ * Get amount of USDC needed to buy exact amount of ETH
2874
+ * @param amountETHWei Amount of ETH (Wei) needed
2872
2875
  */
2873
- async quoteUSDCForETH(amountOutETH) {
2876
+ async quoteUSDCForETH(amountETHWei) {
2874
2877
  try {
2878
+ const params = {
2879
+ tokenIn: USDC_ADDRESS,
2880
+ tokenOut: WETH_ADDRESS,
2881
+ amount: amountETHWei,
2882
+ fee: 500,
2883
+ sqrtPriceLimitX96: 0n
2884
+ };
2875
2885
  const result = await this.publicClient.readContract({
2876
- address: QUOTER_V2,
2886
+ address: UNISWAP_V3_QUOTER,
2877
2887
  abi: QUOTER_ABI,
2878
2888
  functionName: "quoteExactOutputSingle",
2879
- args: [{
2880
- tokenIn: USDC_ADDRESS,
2881
- tokenOut: WETH_ADDRESS,
2882
- amount: amountOutETH,
2883
- fee: 500,
2884
- // 0.05%
2885
- sqrtPriceLimitX96: 0n
2886
- }]
2889
+ args: [params]
2887
2890
  });
2888
2891
  const amountIn = result[0];
2889
2892
  return amountIn * 105n / 100n;
2890
- } catch (error) {
2891
- console.error("Failed to quote USDC for ETH swap on Uniswap V3", error);
2892
- throw new Error(`Failed to quote USDC for ETH swap on Uniswap V3`);
2893
+ } catch (e) {
2894
+ console.error("Quote failed", e);
2895
+ throw new Error("Failed to quote USDC for ETH swap");
2893
2896
  }
2894
2897
  }
2895
2898
  /**
2896
- * Build tx data for swapping USDC -> ETH using Uniswap V3 SwapRouter02
2899
+ * Build tx data for swapping USDC -> ETH
2900
+ * Uses SwapRouter02.exactOutputSingle + unwrapWETH9
2897
2901
  */
2898
- buildSwapData(recipient, amountInMax, amountOutETH) {
2899
- return viem.encodeFunctionData({
2902
+ buildSwapData(recipient, amountOutETH, maxAmountInUSDC) {
2903
+ const swapParams = {
2904
+ tokenIn: USDC_ADDRESS,
2905
+ tokenOut: WETH_ADDRESS,
2906
+ fee: 500,
2907
+ recipient: UNISWAP_V3_ROUTER,
2908
+ // Router must hold WETH to unwrap it
2909
+ amountOut: amountOutETH,
2910
+ amountInMaximum: maxAmountInUSDC,
2911
+ sqrtPriceLimitX96: 0n
2912
+ };
2913
+ const swapCalldata = viem.encodeFunctionData({
2900
2914
  abi: ROUTER_ABI,
2901
2915
  functionName: "exactOutputSingle",
2902
- args: [{
2903
- tokenIn: USDC_ADDRESS,
2904
- tokenOut: WETH_ADDRESS,
2905
- fee: 500,
2906
- // 0.05%
2907
- recipient,
2908
- amountOut: amountOutETH,
2909
- amountInMaximum: amountInMax,
2910
- sqrtPriceLimitX96: 0n
2911
- }]
2916
+ args: [swapParams]
2917
+ });
2918
+ const unwrapCalldata = viem.encodeFunctionData({
2919
+ abi: viem.parseAbi(["function unwrapWETH9(uint256 amountMinimum, address recipient) payable"]),
2920
+ functionName: "unwrapWETH9",
2921
+ args: [amountOutETH, recipient]
2922
+ });
2923
+ const multicallCalldata = viem.encodeFunctionData({
2924
+ abi: viem.parseAbi(["function multicall(bytes[] data) payable returns (bytes[])"]),
2925
+ functionName: "multicall",
2926
+ args: [[swapCalldata, unwrapCalldata]]
2912
2927
  });
2928
+ return multicallCalldata;
2913
2929
  }
2914
2930
  getRouterAddress() {
2915
- return SWAP_ROUTER_02;
2931
+ return UNISWAP_V3_ROUTER;
2916
2932
  }
2917
2933
  getUSDCAddress() {
2918
2934
  return USDC_ADDRESS;
2919
2935
  }
2920
2936
  };
2921
- var uniswapService = new UniswapService("https://mainnet.base.org");
2937
+ var uniswapService = new UniswapService();
2922
2938
 
2923
2939
  exports.AccountAbstraction = AccountAbstraction;
2924
2940
  exports.BASE_MAINNET = BASE_MAINNET;