0.4.1 • Published 8 months ago

@uniblock/uniswap v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

uniblock-sdk uniswap

This sdk can be used to integrate uniswap interactions into your dapp

Setup

yarn install @uniblock/uniswap or npm install @uniblock/uniswap

Functions

Note

In examples below providers and signers were declared as follows:

// getting metamask provider and signer using ethers js
let provider;
let signer;

if (window.ethereum) {
  await window.ethereum.request({ method: 'eth_requestAccounts' });
  provider = await new ethers.providers.Web3Provider(window.ethereum);
  signer = await provider.getSigner();
}

To access the functions associated with the SDK you must first create an instance of the Uniswap class from @uniblock/uniswap. This is done using our initializeUniswap function. Given your uniblock api key the function will return an instance of the Uniswap class. You may then use this object to access the functions of the SDK:

// creating instance of the Uniswap class
const uniswap = await initializeUniswap(uniblockApiKey);

getPrices

gets spot prices for tokens associated with a uniswap pool

Params

parametertype
poolAddressstring
providerethers provider
chainIdnumber

Return

  • Object containing the following
    • spotPrice0
    • spotPrice0Units
    • spotPrice1
    • spotPrice1Units

Example

const prices = await uniswap.getPrices(
  '0x4d1892f15B03db24b55E73F9801826a56d6f0755', // UNI WETH Pool Address
  provider,
  5, // Goerli Testnet
);

trade

makes a trade on uniswap

Params

parametertype
poolAddressstring
providerethers provider
signerethers signer
chainIdnumber
amountnumber
walletAddressstring
tokenInAddressstring
slippageInPercentnumber where default is 0.5%
deadlineInMinnumber where default is 10 min

Return

  • Object containing transaction data

Example

const res = await uniswap.trade(
  '0x4d1892f15B03db24b55E73F9801826a56d6f0755', // UNI WETH Pool Address
  provider,
  signer,
  5, // Goerli Testnet
  0.001, // 0.001 WETH
  RECIPIENT_WALLET_ADDRESS,
  '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', // WETH Address
  5, // 5%
  2, // 2 min
);

getLiquidityPositionTokenIds

gets account's liquidity position token ids

Params

parametertype
walletAddressstring
chainIdnumber

Return

  • Array of token ids

Example

const res = await uniswap.getLiquidityPositionTokenIds(
  OWNER_WALLET_ADDRESS,
  5, // Goerli Testnet
);

getPoolAddress

gets pool address associated with a token pair and fee tier

Params

parametertype
token0string
token1string
feenumber
providerethers provider

Return

  • Pool address

Example

const res = await uniswap.getPoolAddress(
  '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', // WETH Address
  '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', // UNI Address
  3000, // 0.3% Fee Tier
  provider,
);

createNewPool

create a new pool for a pair and fee tier

Params

parametertype
token0string
token1string
feenumber
signerethers signer

Return

  • Object containing transaction data

Example

const res = await uniswap.createNewPool(
  YOUR_TOKEN_0_ADDRESS,
  YOUR_TOKEN_1_ADDRESS,
  3000, // 0.3% Fee Tier
  signer,
);

addLiquidity

adds liquidity to a specified pool, where amount of liquidity is based on quantity of one of the tokens being deposited

Params

parametertype
poolAddressstring
providerethers provider
signerethers signer
chainIdnumber
tokenInAddressstring
tokenInAmountnumber
walletAddressstring
slippageInPercentnumber where default is 0.5%
deadlineInMinnumber where default is 10 min
ticksFromNearestUseableUppernumber where default is 2 ticks
ticksFromNearestUseableLowernumber where default is 2 ticks

Return

  • Object containing transaction data

Example

const res = await uniswap.addLiquidity(
  '0x4d1892f15B03db24b55E73F9801826a56d6f0755', // UNI WETH Pool Address
  provider,
  signer,
  5, // Goerli Testnet
  '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', // WETH Address
  0.002, // 0.002 WETH
  OWNER_WALLET_ADDRESS,
  12, // 12%
  5, // 5 min
  3, // 3 ticks more than nearest useable tick
  3, // 3 ticks less than nearest useable tick
);

addLiquidityToExistingPosition

adds liquidity to an existing position, where amount of liquidity is based on quantity of one of the tokens being deposited

Params

parametertype
poolAddressstring
providerethers provider
signerethers signer
chainIdnumber
tokenInAddressstring
tokenInAmountnumber
tokenIdnumber
slippageInPercentnumber where default is 0.5%
deadlineInMinnumber where default is 10 min

Return

  • Object containing transaction data

Example

const res = await uniswap.addLiquidityToExistingPosition(
  '0x4d1892f15B03db24b55E73F9801826a56d6f0755', // UNI WETH Pool Address
  provider,
  signer,
  5, // Goerli Testnet
  '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', // WETH Address
  0.005, // 0.005 WETH
  22134,
  5, // 5%
  30, // 30 min
);

removeLiquidity

removes liquidity from an existing position, where percentage of the liquidity removed is specified

Params

parametertype
poolAddressstring
providerethers provider
signerethers signer
chainIdnumber
tokenIdnumber
slippageInPercentnumber where default is 0.5%
liquidityToRemoveInPercentnumber where default is 100%
deadlineInMinnumber where default is 10 min

Return

  • Object containing transaction data

Example

const res = await uniswap.removeLiquidity(
  '0x4d1892f15B03db24b55E73F9801826a56d6f0755', // UNI WETH Pool Address
  provider,
  signer,
  5, // Goerli Testnet
  22134,
  5, // 5%
  25, // 25%
  30, // 30 min
);

claimLiquidity

claims all tokens owed from a liquidity position

Params

parametertype
signerethers signer
walletAddressstring
tokenIdnumber

Return

  • Object containing transaction data

Example

const res = await uniswap.claimLiquidity(
  signer,
  RECIPIENT_WALLET_ADDRESS,
  22134,
);
0.0.1-7

9 months ago

0.0.1-test.8

9 months ago

0.0.1-test.9

9 months ago

0.0.1-test.6

10 months ago

0.0.1-test.7

9 months ago

0.0.1-test.4

10 months ago

0.0.1-test.5

10 months ago

0.0.1-test.2

10 months ago

0.0.1-test.3

10 months ago

0.0.1-test.1

10 months ago

0.0.1-10

9 months ago

0.0.1-12

9 months ago

0.0.1-11

9 months ago

0.0.1-14

9 months ago

0.0.1-13

9 months ago

0.0.1-15

9 months ago

0.4.1-test.1

8 months ago

0.0.1-9

9 months ago

0.0.1-8

9 months ago

0.4.1

8 months ago

0.4.0

8 months ago

0.4.2-test.1

8 months ago

0.0.1-6

10 months ago

0.0.1-5

12 months ago

0.0.1-4

1 year ago

0.0.1-3

1 year ago

0.0.1-2

1 year ago

0.0.1-1

1 year ago

0.0.1-0

1 year ago