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

@routerprotocol/router-js-sdk

v0.2.0

Published

🛠 An SDK for building applications on top of router.

Downloads

3

Readme

RouterProtocol JS SDK

node npm downloads

Getting started

initialize

    import {RouterProtocol} from "@routerprotocol/router-js-sdk"

    const routerprotocol=new RouterProtocol("24","137",provider)
    await routerprotocol.initialize()

Fetch Bridge Fee

      const fees = await routerprotocol.getBridgeFee("56");

Response Type

    {
        address: string, // address of fee token
        transferFee: BigNumber, // transfer fee amount
        exchangeFee: BigNumber // exchange fee amount
    }[]

Response Example(polygon to harmony)

   [
      {
        address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
        transferFee: BigNumber { _hex: '0x30d400', _isBigNumber: true },
        exchangeFee: BigNumber { _hex: '0x30d400', _isBigNumber: true }
      },
      {
        address: '0x4c28f48448720e9000907BC2611F73022fdcE1fA',
        transferFee: BigNumber { _hex: '0x2c68af0bb1400000', _isBigNumber: true },
        exchangeFee: BigNumber { _hex: '0x2c68af0bb1400000', _isBigNumber: true }
      },
      {
        address: '0x16ECCfDbb4eE1A85A33f3A9B21175Cd7Ae753dB4',
        transferFee: BigNumber { _hex: '0x0b1a2bc2ec500000', _isBigNumber: true },
        exchangeFee: BigNumber { _hex: '0x0b1a2bc2ec500000', _isBigNumber: true }
      },
      {
        address: '0xC168E40227E4ebD8C1caE80F7a55a4F0e6D66C97',
        transferFee: BigNumber { _hex: '0x03e733628714200000', _isBigNumber: true },
        exchangeFee: BigNumber { _hex: '0x03e733628714200000', _isBigNumber: true }
      }
    ]

Getting Allowance

Source Token Allowance (one to be swapped)
    const allowanceBefore:BigNumber =await routerprotocol.getSourceTokenAllowance(POLYGON_USDC,"56",userAddress)
Fee Token Allowance (bridge fee to be paid)
    const feeAllowanceBefore:BigNumber =await routerprotocol.getFeeTokenAllowance(feeTokenAddress,"56",userAddress)

Getting Approved

Getting Source Token Approved (one to be swapped)
    routerprotocol.approveSourceToken(POLYGON_USDC,userAddress,MAX,"10",srcsigner)
Getting fee Token Approved (bridge fee to be paid)
    routerprotocol.approveFeeToken(feeTokenAddress,userAddress,MAX,srcsigner)

Getting Quote

    const quote =await routerprotocol.getQuote("100","56",POLYGON_USDC,BSC_USDC,userAddress,feeTokenAddress,slippageTolerance)

Response Type

interface Quote{ 
    source: {
    asset: {
      decimals: number,
      symbol: string,
      name: string,
      chainId: number,
      address: string,
      resourceID: string,
      isMintable: boolean,
      isWrappedAsset: boolean,
      tokenInstance: {
        decimals: number,
        symbol: string,
        name: string,
        chainId: number,
        address: string
      }
    },
    stableReserveAsset: {
      decimals: number,
      symbol: string,
      name: string,
      chainId: number,
      address: string,
      resourceID: string,
      isMintable: boolean,
      isWrappedAsset: boolean
    },
    tokenAmount: string,
    stableReserveAmount: string,
    path: any[],
    flags: string[],
    priceImpact: string,
    bridgeFee: {
      token: string,
      symbol: string,
      amount: string
    },
    tokenPath: string
  },
  destination: {
    asset: {
      decimals: number,
      symbolstring:string,
      name: string,
      chainId: number
      address: string,
      resourceID: string,
      isMintable: boolean,
      isWrappedAsset: boolean,
      tokenInstance: {
        decimals: number,
        symbolstring:string,
        name: string,
        chainId: number
        address: string
      }
    },
    stableReserveAsset: {
      decimals: number,
      symbol: string,
      name: string,
      chainId: number
      address: string,
      resourceID: string,
      isMintable: boolean,
      isWrappedAsset: boolean
    },
    tokenAmount: string,
    stableReserveAmount: string,
    priceImpact: string,
    tokenPath: string
  },
  txn: {
    feeToken: string,
    execution: {
      from: string,
      to: string,
      data: string
    }
  }
}

Response Example(polygon to bsc)

  {
  "isWrappedToken": false,
  "source": {
    "asset": {
      "decimals": 18,
      "symbol": "ROUTE",
      "name": "Route",
      "chainId": 137,
      "address": "0x16ECCfDbb4eE1A85A33f3A9B21175Cd7Ae753dB4",
      "resourceID": "0x000000000000000000000016eccfdbb4ee1a85a33f3a9b21175cd7ae753db400",
      "isMintable": false,
      "isWrappedAsset": false,
      "isReserveAsset": false,
      "tokenInstance": {
        "decimals": 18,
        "symbol": "ROUTE",
        "name": "Route",
        "chainId": 137,
        "address": "0x16ECCfDbb4eE1A85A33f3A9B21175Cd7Ae753dB4"
      }
    },
    "stableReserveAsset": {
      "decimals": 18,
      "symbol": "ROUTE",
      "name": "Route",
      "chainId": 137,
      "address": "0x16ECCfDbb4eE1A85A33f3A9B21175Cd7Ae753dB4",
      "resourceID": "0x000000000000000000000016eccfdbb4ee1a85a33f3a9b21175cd7ae753db400",
      "isMintable": false,
      "isWrappedAsset": false,
      "isReserveAsset": false
    },
    "tokenAmount": "1000000",
    "stableReserveAmount": "1000000",
    "path": [

    ],
    "flags": [

    ],
    "priceImpact": "0",
    "bridgeFee": {
      "token": "0x0000000000000000000000000000000000001010",
      "symbol": "WMATIC",
      "amount": "400000000000000000"
    },
    "tokenPath": "",
    "dataTx": [
      "0x00"
    ]
  },
  "destination": {
    "asset": {
      "decimals": 18,
      "symbol": "ROUTE",
      "name": "ROUTE",
      "chainId": 56,
      "address": "0xfD2700c51812753215754De9EC51Cdd42Bf725B9",
      "resourceID": "0x000000000000000000000016eccfdbb4ee1a85a33f3a9b21175cd7ae753db400",
      "isMintable": true,
      "isWrappedAsset": false,
      "isReserveAsset": false,
      "tokenInstance": {
        "decimals": 18,
        "symbol": "ROUTE",
        "name": "ROUTE",
        "chainId": 56,
        "address": "0xfD2700c51812753215754De9EC51Cdd42Bf725B9"
      }
    },
    "stableReserveAsset": {
      "decimals": 18,
      "symbol": "ROUTE",
      "name": "ROUTE",
      "chainId": 56,
      "address": "0xfD2700c51812753215754De9EC51Cdd42Bf725B9",
      "resourceID": "0x000000000000000000000016eccfdbb4ee1a85a33f3a9b21175cd7ae753db400",
      "isMintable": true,
      "isWrappedAsset": false,
      "isReserveAsset": false
    },
    "tokenAmount": "1000000",
    "stableReserveAmount": "1000000",
    "priceImpact": "0.00",
    "tokenPath": "ROUTE",
    "dataTx": [
      "0x00"
    ]
  },
  "txn": {
    "feeToken": "0x16ECCfDbb4eE1A85A33f3A9B21175Cd7Ae753dB4",
    "execution": {
      "from": "0xD253eDAF1B53a2E0e5E1B8021ba4937D21806dd3",
      "to": "0xf18aCC02628009231d7BAAF9a7a24C0860Dda6cb",
      "data": "0x43cee7190000000000000000000000000000000000000000000000000000000000000002000000000000000000000016eccfdbb4ee1a85a33f3a9b21175cd7ae753db40000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000016eccfdbb4ee1a85a33f3a9b21175cd7ae753db4000000000000000000000000000000000000000000000000000000000000017000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000d253edaf1b53a2e0e5e1b8021ba4937d21806dd316eccfdbb4ee1a85a33f3a9b21175cd7ae753db4fd2700c51812753215754de9ec51cdd42bf725b9fd2700c51812753215754de9ec51cdd42bf725b900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000",
      "gasLimit": "736386",
      "gasPrice": "241163008999"
    }
  }
}

Swap

    const tx = await routerprotocol.swap(quote,srcsigner)

Get transaction status

    const txStatus=await routerprotocol.getTransactionStatus("0xde12f05b718b3407633d00fb5834ae48fb6ec5970b3252d3a6eb5e18222f33ee")

Response Type

interface TransactionStatus{"tx_status":string,
"tx_status_code":number,
"src_chain_id":string,
"dest_chain_id":string,
"src_tx_hash":string,
"dest_tx_hash":string}

Response Example

{"tx_status":"Completed","tx_status_code":1,"src_chain_id":"1","dest_chain_id":"4","src_tx_hash":"0xde12f05b718b3407633d00fb5834ae48fb6ec5970b3252d3a6eb5e18222f33ee","dest_tx_hash":"0x437124f52c6efa61dccd8c1fa34206bdb7a079e64e368db6eda4bb6999843b23"}