1.1.0 • Published 4 years ago

uniswap-v2-helper v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

npm GitHub last commit npm NPM

Uniswap V2 Helper

Uniswap trades in a single function call. Currently only supports direct erc20 token pairs with a decimals getter. Single outside dependency on ethers.js.

Usage

import { getSwapParams, swapTokens } from 'uniswap-v2-helper'
import { ethers } from 'ethers'

const privateKey = '0x...'
const provider = ethers.getDefaultProvider() // use default provider or any other ethers provider
const signer = new ethers.Wallet(privateKey, provider)

// get swap params

const {
  amountIn,
  amountOut,
  expectedAmount,
  expectedSlippage,
  path,
  deadline,
} = await getSwapParams(
  '0x...', // input token address
  '0x...', // output token address
  '1.0', // ammount to buy or sell with decimals
  true, // true if amount is input token, false if amount is output token
  {
    maxSlippage: 100, // optional frontrunning tolerance (default to 100 basis points)
    maxDelay: 60 * 2, // optional max settlement time in seconds (default to 2 minutes)
    ethersProvider: provider, // optional ethers provider (defaults to default mainnet ethers provider)
  },
)

// perform swap with exact output

const receipt = await swapTokens(
  signer, // ethers signer
  '0x...', // input token address
  '0x...', // output token address
  '1.0', // ammount to buy or sell with decimals
  true, // true if amount is input token, false if amount is output token
  {
    recipient: '0x...', // optional recipient address (default to signer)
    maxSlippage: 100, // optional frontrunning tolerance (default to 100 basis points)
    maxDelay: 60 * 2, // optional max settlement time in seconds (default to 2 minutes)
  },
)
1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.3

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago