Giter Site home page Giter Site logo

sdks's Introduction

Uniswap SDK's

A repository for many Uniswap SDK's. All SDK's can be found in sdk/ and have more information in their individual README's.

Development Commands

# Clone
git clone --recurse-submodules https://github.com/Uniswap/sdks.git
# Install
yarn
# Build
yarn g:build
# Typecheck
yarn g:typecheck
# Lint
yarn g:lint
# Test
yarn g:test
# Run a specific package.json command for an individual SDK
yarn sdk @uniswap/{sdk-name} {command}

Publishing SDK's

Publishing of each SDK is done on merge to main using semantic-release and semantic-release-monorepo. PR titles / commits follow angular conventional commits with custom settings that map as follows:

- `fix(SDK name):` will trigger a patch version
- `<type>(public):` will trigger a patch version
- `feat(SDK name):` will trigger a minor version
- `feat(breaking):` will trigger a major version for a breaking change

Versions will only be generated based on the changelog of the relevant SDK's folder/files.

sdks's People

Contributors

moodysalem avatar marktoda avatar noahzinsmeister avatar conjunctivenormalform avatar jsy1218 avatar ewilz avatar hensha256 avatar willpote avatar rileydcampbell avatar tinaszheng avatar zhongeric avatar adjkant avatar just-toby avatar lint-action avatar snreynolds avatar jfrankfurt avatar cbachmeier avatar raghava-pamula avatar ianlapham avatar zzmp avatar dependabot[bot] avatar akarys92 avatar mikeki avatar robert-seitz-uniswap avatar jesse-sawa avatar andysmith415 avatar mr-uniswap avatar aadams avatar felipebrahm avatar jackshort avatar

Stargazers

 avatar Unknown avatar Shun Kakinoki avatar George Mathew avatar Sonami avatar İbrahim Keçici avatar Toan Nhu avatar Moshe Demri avatar Philip London avatar chens avatar Seiya Kobayashi avatar  avatar Pablo Estades avatar Regison avatar  avatar  avatar  avatar zkfarmoor avatar Luis Thiago Padilha avatar wade avatar Antoine Karcher avatar TANZINA AKTER avatar Eshin Kunishima avatar

Watchers

 avatar  avatar

sdks's Issues

SDK prepares data for old router

This has already been reported here in the old repo:
Uniswap/v3-sdk#199
here I'll provide a more detailed explanation of the bug because it literally took me a whole day to figure this out (thanks @allush for the issue)

The current SDK version ("@uniswap/v3-sdk": "^3.11.2") does not allow swaps for Router 2 because it does not allow to construct correct swapCallParameters.

Steps to reproduce:

import { abi as SWAP_ROUTER_ABI } from "@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json";
    const options: SwapOptions = {
      slippageTolerance: new Percent(50, 10_000), // 50 bips, or 0.50%
      deadline: Math.floor(Date.now() / 1000) + 60 * 20, // 20 minutes from the current Unix time
      recipient: address,
    };
   const methodParameters = SwapRouter.swapCallParameters([uncheckedTrade], options);
    const tuple = {
      tokenIn: fromToken.address,
      tokenOut: toToken.address,
      fee: poolFee,
      recipient: address,
      amountIn: fromReadableAmount(amountIn, fromToken.decimals),
      deadline: options.deadline,
      amountOutMinimum: 0,
      sqrtPriceLimitX96: 0,
    };

    const customCalldata = encodeFunctionData({
      abi: SWAP_ROUTER_ABI,
      functionName: "exactInputSingle",
      args: [tuple],
    });
import { SWAP_ROUTER_02_ADDRESSES } from "@uniswap/sdk-core";
 const swapRouterAddress = SWAP_ROUTER_02_ADDRESSES(chainId);

    const result = await sendTransaction(wagmiConfig, {
      account: address,
      to: swapRouterAddress,
      value: BigInt(methodParameters.value),
      data: customCalldata,
    });

I use wagmi in this example, but it doesn't matter.
The fix to this would be to use the old SwapRouter (https://docs.uniswap.org/contracts/v3/reference/deployments/ethereum-deployments)
I didn't manage to get it working with the new SwapRouter 2 because of this error:
image

Versions used:
"@uniswap/sdk-core": "^5.0.0",
"@uniswap/v3-sdk": "^3.11.2",

feat: add CurrencyAmount.{greaterThan,equalTo,lessThan}

I am using sdk-core for my projects and safety checks on this.currency.equals(other.currency) for CurrencyAmount would be great. Something like this(you may want to omit | 0 but this is quite handy in practice)

class CurrencyAmount<T> {
  ...

  public greaterThan(other: CurrencyAmount<T> | 0): boolean {
    invariant(other === 0 || this.currency.equals(other.currency), "CURRENCY");
    return super.greaterThan(other);
  }
  
  public equalTo(other: CurrencyAmount<T> | 0): boolean {
    invariant(other === 0 || this.currency.equals(other.currency), "CURRENCY");
    return super.equalTo(other);
  }
  
  public lessThan(other: CurrencyAmount<T> | 0): boolean {
    invariant(other === 0 || this.currency.equals(other.currency), "CURRENCY");
    return super.lessThan(other);
  }
}

Could u please share me a full example ?

Could u please share me a full example ?

import { TradeType } from '@uniswap/sdk-core'
import { Trade as V2TradeSDK } from '@uniswap/v2-sdk'
import { Trade as V3TradeSDK } from '@uniswap/v3-sdk'
import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk'

const options = { slippageTolerance, recipient }
const routerTrade = new UniswapTrade(
new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_INPUT },
options
)
// Use the raw calldata and value returned to call into Universal Swap Router contracts
const { calldata, value } = SwapRouter.swapCallParameters(routerTrade)

LIQUIDITY_ZERO

onstructing a position that is out of range returns it as zero liquidity. Then, when I try to use the position instance to increase this position's liquidity, I receive the ZERO_LIQUIDITY error

const token0 = CurrencyAmount.fromRawAmount(
      positionData.amount0.currency,
      BigNumber(positionData.amount0.quotient.toString()).multipliedBy(fractionToAdd).toFixed(0),
    );
    const token1 = CurrencyAmount.fromRawAmount(
      positionData.amount1.currency,
      BigNumber(positionData.amount1.quotient.toString()).multipliedBy(fractionToAdd).toFixed(0),
    );

const configuredPool = new Pool(
      token0.currency,
      token1.currency,
      poolFee,
      sqrtPriceX96.toFixed(),
      liquidity.toFixed(),
      tick,
    );

    const position =  Position.fromAmounts({
      pool: configuredPool,
      tickLower: nearestUsableTick(tick, tickSpacing) - tickSpacing * 2,
      tickUpper: nearestUsableTick(tick, tickSpacing) + tickSpacing * 2,
      amount0: token0.quotient,
      amount1: token1.quotient,
      useFullPrecision: true,
    });

const addLiquidityOptions: IncreaseOptions = {
      deadline: Math.floor(Date.now() / 1000) + 60 * 20,
      slippageTolerance: new Percent(50, 10_000),
      tokenId: positionData.positionId,
    };

    const { calldata, value } = NonfungiblePositionManager.addCallParameters(position, addLiquidityOptions);

UniswapX V2 documentation

there's no documentation of how to use UniswapX V2. Please add some code snippet and explanation wheter V2 is compatible with V1 or not, and whether the V1 version should be deprecated or not

Incorrect output of computePoolAddress function

import { FeeAmount, computePoolAddress } from "@uniswap/v3-sdk";

const tokenA = {
    "chainId": 1,
    "decimals": 18,
    "symbol": "ARB",
    "name": "Arbitrum",
    "isNative": false,
    "isToken": true,
    "address": "0xB50721BCf8d664c30412Cfbc6cf7a15145234ad1"
}
const tokenB = {
    "chainId": 1,
    "decimals": 6,
    "symbol": "USDC",
    "name": "USD Coin",
    "isNative": false,
    "isToken": true,
    "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
}

const fee = FeeAmount.MEDIUM

const chainId = 1

const currentPoolAddress = computePoolAddress({
      factoryAddress: getFactoryAddress(chainId),
      tokenA,
      tokenB,
      fee,
      chainId,
    });

output:

0xEbD785B899b3DdCDE792D04e3d849d10d5Db7555

this pool address is wrong, last transaction was executed more than 400 days ago:
https://etherscan.io/address/0xEbD785B899b3DdCDE792D04e3d849d10d5Db7555#tokentxns

If we try to computePoolAddress for Arbitrum One, it outputs a non-existing contract address (0xD47449fdB21761F11796216Ce5a8F3ABDE7aff22)

router-sdk: Expand mixed route capabilities

Trade objects with Mixed Routes can be formed but is still missing some featrures:

  • Enable mixed Routes that go from WETH --> ETH intermediary pools. (universal-router-sdk and quoters will need to understand to unwrap WETH from v2/v3 to then trade on a V4 native pool.
  • Enable switching between ETH/WETH in potential pure v4 routes. (double check with protocols that PoolManager doesn't inherently already know how to do this)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.