npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@weav3npm/routing-api

v1.0.1

Published

This repository contains routing API for the Uniswap V3 protocol.

Downloads

5

Readme

Uniswap Routing API

This repository contains routing API for the Uniswap V3 protocol.

It deploys an API to AWS that uses @uniswap/smart-order-router to search for the most efficient way to swap token A for token B.

Development

To develop on the Routing API you must have an AWS account where you can deploy your API for testing.

Deploying the API

The best way to develop and test the API is to deploy your own instance to AWS.

  1. Install and configure AWS CLI and AWS CDK V1.
  2. Create .env file in the root directory of the project with :
    THROTTLE_PER_FIVE_MINS = '' # Optional
    JSON_RPC_PROVIDER_{CHAIN ID} = { RPC Provider}
    # RPC Providers must be set for the following CHAIN IDs:
    # MAINNET = 1
    # ROPSTEN = 3
    # RINKEBY = 4
    # GÖRLI = 5
    # KOVAN = 42
    # OPTIMISM = 10
    # OPTIMISTIC_KOVAN = 69
    # ARBITRUM_ONE = 42161
    # ARBITRUM_RINKEBY = 421611
    # POLYGON = 137
    # POLYGON_MUMBAI = 80001
    # BSC = 56
    TENDERLY_USER = '' # For enabling Tenderly simulations
    TENDERLY_PROJECT = '' # For enabling Tenderly simulations
    TENDERLY_ACCESS_KEY = '' # For enabling Tenderly simulations
  3. Install and build the package
    npm install && npm run build
  4. To deploy the API run:
    cdk deploy RoutingAPIStack
    This will deploy to the default account your AWS CLI is configured for. Once complete it will output something like:
    RoutingAPIStack.Url = https://...
    You can then try it out:
    curl --request GET '<INSERT_YOUR_URL_HERE>/quote?tokenInAddress=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&tokenInChainId=1&tokenOutAddress=0x1f9840a85d5af5bf1d1762f925bdaddc4201f984&tokenOutChainId=1&amount=100&type=exactIn'

Tenderly Simulation

  1. To get a more accurate estimate of the transaction's gas cost, request a tenderly simulation along with the swap. This is done by setting the optional query param "simulateFromAddress". For example:
curl --request GET '<INSERT_YOUR_URL_HERE>/quote?tokenInAddress=<0x...>&simulateFromAddress=<FROM_ADDRESS>&...'
  1. Tenderly simulates the transaction and returns to us the simulated gasLimit as 'gasUseEstimate'. We use this gasLimit to update all our gas estimate heuristics. In the response body, the
{'gasUseEstimate':string, 'gasUseEstimateQuote':string, 'quoteGasAdjusted':string, and 'gasUseEstimateUSD':string}

fields will be updated/calculated using tenderly gasLimit estimate. These fields are already present even without Tenderly simulation, however in that case they are simply heuristics. The Tenderly gas estimates will be more accurate.

  1. If the simulation fails, there will be one more field present in the response body: 'simulationError'. If this field is set and it is set to true, that means the Tenderly Simulation failed. The
{'gasUseEstimate':string, 'gasUseEstimateQuote':string, 'quoteGasAdjusted':string, and 'gasUseEstimateUSD':string}

fields will still be included, however they will be heuristics rather then Tenderly estimates. These heuristic values are not reliable for sending transactions on chain.

Integration Tests

The integration tests fetch quotes from your deployed API, then execute the swaps on a Hardhat mainnet fork.

  1. First deploy your test API using the intructions above. Then update your .env file with the URL of the API, and the RPC URL of an archive node:

    UNISWAP_ROUTING_API='...'
    ARCHIVE_NODE_RPC='...'
  2. Run the tests with:

    npm run integ-test