jds-js-sdk
v5.1.5
Published
🛠 An SDK for building applications on top of router.
Downloads
5
Readme
RouterProtocol JS SDK
Getting started
Initailize
import {RouterProtocol} from "@router/router-js-sdk"
const routerprotocol=new RouterProtocol("SDK_ID_HERE","SOURCE_CHAIN_ID","PROVIDER_HERE")
await routerprotocol.initailize()
Fetch Bridge Fee
const fees = await routerprotocol.getBridgeFee("DESTINATION_CHAIN_ID");
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 allowance:BigNumber =await routerprotocol.getSourceTokenAllowance("TOKEN_ADDRESS","DESTINATION_CHAIN_ID","USER_ADDRESS")
Fee Token Allowance (bridge fee to be paid)
const allowance:BigNumber =await routerprotocol.getFeeTokenAllowance("TOKEN_ADDRESS","DESTINATION_CHAIN_ID","USER_ADDRESS")
Getting Approved
Getting Source Token Approved (one to be swapped)
await routerprotocol.approveSourceToken("TOKEN_ADDRESS","USER_ADDRESS","AMOUNT_TO_BE_APPROVED","DESTINATION_CHAIN_ID","SOURCE_SIGNER")
Getting fee Token Approved (bridge fee to be paid)
await routerprotocol.approveFeeToken("TOKEN_ADDRESS","USER_ADDRESS","AMOUNT_TO_BE_APPROVED","SOURCE_SIGNER")
Getting Quote
const quote =await routerprotocol.getQuote("AMOUNT","DESTINATION_CHAIN_ID","SOURCE_TOKEN_ADDRESS","DESTINATION_TOKEN_ADDRESS",""USER_ADDRESS"","FEE_TOKEN_ADDRESS","SLIPPAGE_TOLERANCE")
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: number,
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
}
}
Response Example(polygon to harmony)
{
source: {
asset: {
decimals: 6,
symbol: 'USDC',
name: 'USDC',
chainId: 137,
address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
resourceID: '0x00000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa8417400',
isMintable: false,
isWrappedAsset: false,
tokenInstance: [Object]
},
stableReserveAsset: {
decimals: 6,
symbol: 'USDC',
name: 'USDC',
chainId: 137,
address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
resourceID: '0x00000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa8417400',
isMintable: false,
isWrappedAsset: false
},
tokenAmount: '100',
stableReserveAmount: '100',
path: [],
flags: [ '17716742144' ],
priceImpact: '0',
bridgeFee: 0,
tokenPath: ''
},
destination: {
asset: {
decimals: 6,
symbol: 'USDC',
name: 'USD Coin',
chainId: 1666600000,
address: '0x985458E523dB3d53125813eD68c274899e9DfAb4',
resourceID: '0x00000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa8417400',
isMintable: false,
isWrappedAsset: false,
tokenInstance: [Object]
},
stableReserveAsset: {
decimals: 6,
symbol: 'USDC',
name: 'USD Coin',
chainId: 1666600000,
address: '0x985458E523dB3d53125813eD68c274899e9DfAb4',
resourceID: '0x00000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa8417400',
isMintable: false,
isWrappedAsset: false
},
tokenAmount: '100',
stableReserveAmount: '100',
priceImpact: '0',
tokenPath: ''
}
}
Swap
const tx = await routerprotocol.swap("SOURCE_SIGNER")
Get transaction status
const txStatus=await routerprotocol.getTransactionStatus("TXN_HASH")
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"}