Advertisement
dennoh

Adding Liquidity

Jun 3rd, 2022
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const uniswap = new Contract(config.UNISWAP_ADDRESS, [
  2.   `function addLiquidityETH(
  3.       address token,
  4.       uint amountTokenDesired,
  5.       uint amountTokenMin,
  6.       uint amountETHMin,
  7.       address to,
  8.       uint deadline
  9.   ) external payable returns (uint amountToken, uint amountETH, uint liquidity)`,
  10.   `function addLiquidity(
  11.     address tokenA,
  12.     address tokenB,
  13.     uint amountADesired,
  14.     uint amountBDesired,
  15.     uint amountAMin,
  16.     uint amountBMin,
  17.     address to,
  18.     uint deadline
  19. ) external returns (uint amountA, uint amountB, uint liquidity)`,
  20. ]);
  21.  
  22. const addLiquidityETH = async () => {
  23.   const amountTokenDesired = 1000000000000000000;
  24.   const amountTokenMin = 1000000000000000000;
  25.   const amountETHMin = 1000000000000000000;
  26.   const to = '0x0000000000000000000000000000000000000000';
  27.   const deadline = Math.floor(Date.now() / 1000) + 60;
  28.  
  29.   const tx = await uniswap.addLiquidityETH(
  30.     config.TOKEN_ADDRESS,
  31.     amountTokenDesired,
  32.     amountTokenMin,
  33.     amountETHMin,
  34.     to,
  35.     deadline
  36.   );
  37.  
  38.   console.log({ tx });
  39. };
  40.  
  41. const addLiquidity = async () => {
  42.   const amountADesired = 1000000000000000000;
  43.   const amountBDesired = 1000000000000000000;
  44.   const amountAMin = 1000000000000000000;
  45.   const amountBMin = 1000000000000000000;
  46.   const to = '0x0000000000000000000000000000000000000000';
  47.   const deadline = Math.floor(Date.now() / 1000) + 60;
  48.  
  49.   const tx = await uniswap.addLiquidity(
  50.     config.TOKEN_ADDRESS,
  51.     config.TOKEN_ADDRESS, // could be any token like USDC
  52.     amountADesired, // amount of tokenA desired
  53.     amountBDesired, // amount of tokenB desired e.g 1000 USDC
  54.     amountAMin,
  55.     amountBMin,
  56.     to,
  57.     deadline
  58.   );
  59.  
  60.   console.log({ tx });
  61. };
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement