Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Confusion of sdk and v2-sdk #62

Open
tennox opened this issue Apr 5, 2021 · 9 comments
Open

Confusion of sdk and v2-sdk #62

tennox opened this issue Apr 5, 2021 · 9 comments

Comments

@tennox
Copy link

tennox commented Apr 5, 2021

Installing @uniswap/sdk returns a package from "https://github.com/Uniswap/uniswap-sdk.git" - but that URL forwards to this repository, which holds a v1.0.7 version. (not 3.0.3)

Is it now recommended to install @uniswap/v2-sdk ?
Then the docs on uniswap.org (which are also linked in the Readme of this repository) still talk about the old version and should be updated.

@tennox
Copy link
Author

tennox commented Apr 5, 2021

Also: I don't find the Fetcher source code (is it not part of the v2-sdk anymore?)

@pmanion0
Copy link

pmanion0 commented Apr 6, 2021

I'm here trying to figure out the same questions @tennox !

@pmanion0
Copy link

pmanion0 commented Apr 6, 2021

@tennox It looks like they redid the versioning and renamed this repository about a month back. You can see the old naming here with the v3.0.3, the name is @uniswap/sdk, and the Fetcher class still exists:

https://github.com/Uniswap/uniswap-v2-sdk/tree/a88048e9c4198a5bdaea00883ca00c8c8e582605

About a month back, the name changed to @uniswap/uniswap-v2-sdk, redid the numbering to start at 1.0.0, and the Fetcher class disappeared. It seems that npm hasn't been updated since these changes.

So it seems that the answer is yes, we should be using @uniswap/v2-sdk instead, and they might need some help updating the documentation on the site.

@Vanclief
Copy link

Vanclief commented Apr 12, 2021

Having same issue.

The module @uniswap/uniswap-sdk gives me a dependency error, and I can't access the fetcher in @uniswap/uniswap-v2-sdk.

I have managed to follow some of their docs by importing dependencies such as ChainId from @uniswap/sdk-core, but this is a mess.

@monokh
Copy link

monokh commented Jun 9, 2021

This is the best I could do using as much sdk-v2 code as possible. But the execution price retrieved is very wrong.

const { Token, WETH9, CurrencyAmount, TradeType } = require('@uniswap/sdk-core')
const { Route, Trade, Pair } = require('@uniswap/v2-sdk')
const { Fetcher } = require('@uniswap/sdk')

async function v2 () {
  const CHAIN_ID = 1
  const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
  const tokenA = WETH9[CHAIN_ID]
  const tokenB = new Token(CHAIN_ID, daiAddress, 18, 'DAI', 'DAI')
  const legacyPair = await Fetcher.fetchPairData(tokenA, tokenB)

  const reserveA = CurrencyAmount.fromFractionalAmount(tokenA, legacyPair.reserveOf(tokenA).numerator, legacyPair.reserveOf(tokenA).denominator)
  const reserveB = CurrencyAmount.fromFractionalAmount(tokenB, legacyPair.reserveOf(tokenB).numerator, legacyPair.reserveOf(tokenB).denominator)
  const pair = new Pair(reserveA, reserveB)

  const route = new Route([pair], tokenA, tokenB)

  const tokenAmount = CurrencyAmount.fromRawAmount(tokenA, '1000000000000000000')
  const trade = new Trade(route, tokenAmount, TradeType.EXACT_INPUT)
  console.log('execution price', trade.executionPrice.toSignificant(6))
  console.log('inverse execution price', trade.executionPrice.invert().toSignificant(6))
}

Someone can spot what may be wrong?
Using just @uniswa/sdk package works fine though.

@monokh
Copy link

monokh commented Jun 9, 2021

In the end, I let go of the Fetcher and called the pair contract directly for the reserves. See gist:
https://gist.github.com/monokh/5dc494b9fb7887ac02d6898b6458648c

@dieptang
Copy link

@uniswa/sdk is v1
@uniswa/sdk-v2 is v2
@uniswa/sdk-v3 is v3

@imsys
Copy link

imsys commented Feb 18, 2022

The npm package @uniswap/sdk works for what is in the Uniswap v2 SDK documentation. But I'm not really sure what source is used for that.
It seems that it is github.com/Uniswap/[email protected], as most things were removed in 52266e3, just before Uniswap/[email protected]

@0xhohenheim
Copy link

Well since the Fetcher class isn't exported anymore, here's a function to get Pair:

const getChainProvider = () => {
    return (new ethers.providers.JsonRpcProvider(process.env.RPC));
}

const getPair = async (tokenA: Token, tokenB: Token) => {
    const pairAddress = Pair.getAddress(tokenA, tokenB)
    const contract = new ethers.Contract(pairAddress, [
        'function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)',
        'function token0() external view returns (address)',
        'function token1() external view returns (address)'
    ], getChainProvider());
    const reserves = await contract.getReserves()
    const token0Address = await contract.token0()
    const token1Address = await contract.token1()
    const token0 = [tokenA, tokenB].find(token => token.address === token0Address)
    const token1 = [tokenA, tokenB].find(token => token.address === token1Address)
    const pair = new Pair(
        CurrencyAmount.fromRawAmount(token0, reserves.reserve0.toString()),
        CurrencyAmount.fromRawAmount(token1, reserves.reserve1.toString())
    )
    return pair;
}

Source: https://gist.github.com/monokh/5dc494b9fb7887ac02d6898b6458648c

royalaid pushed a commit to royalaid/qidao-sdk that referenced this issue Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants