Options
All
  • Public
  • Public/Protected
  • All
Menu

chainlink-asset-converter

Index

Type aliases

Variables

Functions

Type aliases

ConvertProps

ConvertProps: { amount: number; endpoint?: string; feeds?: readonly Feed[]; from: string; provider?: JsonRpcProvider; to: string }

Options for convert

Type declaration

  • Readonly amount: number

    The amount of the from asset to convert

  • Optional Readonly endpoint?: string

    The JSON RPC endpoint (either this or the provider must be provided)

  • Optional Readonly feeds?: readonly Feed[]

    Optionally pass in a custom array of price feeds

  • Readonly from: string

    The asset to convert from

  • Optional Readonly provider?: JsonRpcProvider

    The JsonRpcProvider (either this or the endpoint must be provided)

  • Readonly to: string

    The asset to convert to

Feed

Feed: { address: string; decimals: number; from: string; id: number; to: string }

Type declaration

  • Readonly address: string
  • Readonly decimals: number
  • Readonly from: string
  • Readonly id: number
  • Readonly to: string

Path

Path: readonly PathSection[]

PathSection

PathSection: { feedId: number; inverse: boolean }

Type declaration

  • Readonly feedId: number
  • Readonly inverse: boolean

Variables

Const AAVE_ETH_AGGREGATOR

AAVE_ETH_AGGREGATOR: "aave-eth.data.eth" = "aave-eth.data.eth"

Const AAVE_USD_AGGREGATOR

AAVE_USD_AGGREGATOR: "aave-usd.data.eth" = "aave-usd.data.eth"

Const ADA_USD_AGGREGATOR

ADA_USD_AGGREGATOR: "ada-usd.data.eth" = "ada-usd.data.eth"

Const ADX_USD_AGGREGATOR

ADX_USD_AGGREGATOR: "adx-usd.data.eth" = "adx-usd.data.eth"

Const AUD_USD_AGGREGATOR

AUD_USD_AGGREGATOR: "aud-usd.data.eth" = "aud-usd.data.eth"

Const BAT_ETH_AGGREGATOR

BAT_ETH_AGGREGATOR: "bat-eth.data.eth" = "bat-eth.data.eth"

Const BCH_USD_AGGREGATOR

BCH_USD_AGGREGATOR: "bch-usd.data.eth" = "bch-usd.data.eth"

Const BNB_USD_AGGREGATOR

BNB_USD_AGGREGATOR: "bnb-usd.data.eth" = "bnb-usd.data.eth"

Const BNT_ETH_AGGREGATOR

BNT_ETH_AGGREGATOR: "bnt-eth.data.eth" = "bnt-eth.data.eth"

Const BNT_USD_AGGREGATOR

BNT_USD_AGGREGATOR: "bnt-usd.data.eth" = "bnt-usd.data.eth"

Const BRENT_USD_AGGREGATOR

BRENT_USD_AGGREGATOR: "brent-usd.data.eth" = "brent-usd.data.eth"

Const BTC_ETH_AGGREGATOR

BTC_ETH_AGGREGATOR: "btc-eth.data.eth" = "btc-eth.data.eth"

Const BTC_USD_AGGREGATOR

BTC_USD_AGGREGATOR: "btc-usd.data.eth" = "btc-usd.data.eth"

Const BUSD_ETH_AGGREGATOR

BUSD_ETH_AGGREGATOR: "busd-eth.data.eth" = "busd-eth.data.eth"

Const BZRX_ETH_AGGREGATOR

BZRX_ETH_AGGREGATOR: "bzrx-eth.data.eth" = "bzrx-eth.data.eth"

Const CHF_USD_AGGREGATOR

CHF_USD_AGGREGATOR: "chf-usd.data.eth" = "chf-usd.data.eth"

Const COMP_USD_AGGREGATOR

COMP_USD_AGGREGATOR: "comp-usd.data.eth" = "comp-usd.data.eth"

Const CRO_ETH_AGGREGATOR

CRO_ETH_AGGREGATOR: "cro-eth.data.eth" = "cro-eth.data.eth"

Const CRV_ETH_AGGREGATOR

CRV_ETH_AGGREGATOR: "crv-eth.data.eth" = "crv-eth.data.eth"

Const DAI_ETH_AGGREGATOR

DAI_ETH_AGGREGATOR: "dai-eth.data.eth" = "dai-eth.data.eth"

Const DAI_USD_AGGREGATOR

DAI_USD_AGGREGATOR: "dai-usd.data.eth" = "dai-usd.data.eth"

Const DASH_USD_AGGREGATOR

DASH_USD_AGGREGATOR: "dash-usd.data.eth" = "dash-usd.data.eth"

Const DMG_ETH_AGGREGATOR

DMG_ETH_AGGREGATOR: "dmg-eth.data.eth" = "dmg-eth.data.eth"

Const DOT_USD_AGGREGATOR

DOT_USD_AGGREGATOR: "dot-usd.data.eth" = "dot-usd.data.eth"

Const ENJ_ETH_AGGREGATOR

ENJ_ETH_AGGREGATOR: "enj-eth.data.eth" = "enj-eth.data.eth"

Const EOS_USD_AGGREGATOR

EOS_USD_AGGREGATOR: "eos-usd.data.eth" = "eos-usd.data.eth"

Const ETC_USD_AGGREGATOR

ETC_USD_AGGREGATOR: "etc-usd.data.eth" = "etc-usd.data.eth"

Const ETH_USD_AGGREGATOR

ETH_USD_AGGREGATOR: "eth-usd.data.eth" = "eth-usd.data.eth"

Const ETH_XDR_AGGREGATOR

ETH_XDR_AGGREGATOR: "eth-xdr.data.eth" = "eth-xdr.data.eth"

Const EUR_USD_AGGREGATOR

EUR_USD_AGGREGATOR: "eur-usd.data.eth" = "eur-usd.data.eth"

Const FIL_USD_AGGREGATOR

FIL_USD_AGGREGATOR: "fil-usd.data.eth" = "fil-usd.data.eth"

Const FNX_USD_AGGREGATOR

FNX_USD_AGGREGATOR: "fnx-usd.data.eth" = "fnx-usd.data.eth"

Const FTSE_GBP_AGGREGATOR

FTSE_GBP_AGGREGATOR: "ftse-gbp.data.eth" = "ftse-gbp.data.eth"

Const GBP_USD_AGGREGATOR

GBP_USD_AGGREGATOR: "gbp-usd.data.eth" = "gbp-usd.data.eth"

Const JPY_USD_AGGREGATOR

JPY_USD_AGGREGATOR: "jpy-usd.data.eth" = "jpy-usd.data.eth"

Const KNC_ETH_AGGREGATOR

KNC_ETH_AGGREGATOR: "knc-eth.data.eth" = "knc-eth.data.eth"

Const KNC_USD_AGGREGATOR

KNC_USD_AGGREGATOR: "knc-usd.data.eth" = "knc-usd.data.eth"

Const LINK_ETH_AGGREGATOR

LINK_ETH_AGGREGATOR: "link-eth.data.eth" = "link-eth.data.eth"

Const LINK_USD_AGGREGATOR

LINK_USD_AGGREGATOR: "link-usd.data.eth" = "link-usd.data.eth"

Const LRC_ETH_AGGREGATOR

LRC_ETH_AGGREGATOR: "lrc-eth.data.eth" = "lrc-eth.data.eth"

Const LTC_USD_AGGREGATOR

LTC_USD_AGGREGATOR: "ltc-usd.data.eth" = "ltc-usd.data.eth"

Const MANA_ETH_AGGREGATOR

MANA_ETH_AGGREGATOR: "mana-eth.data.eth" = "mana-eth.data.eth"

Const MCAP_USD_AGGREGATOR

MCAP_USD_AGGREGATOR: "0xEC8761a0A73c34329CA5B1D3Dc7eD07F30e836e2" = "0xEC8761a0A73c34329CA5B1D3Dc7eD07F30e836e2"

Const MKR_ETH_AGGREGATOR

MKR_ETH_AGGREGATOR: "mkr-eth.data.eth" = "mkr-eth.data.eth"

Const N225_JPY_AGGREGATOR

N225_JPY_AGGREGATOR: "n225-jpy.data.eth" = "n225-jpy.data.eth"

Const OXT_USD_AGGREGATOR

OXT_USD_AGGREGATOR: "oxt-usd.data.eth" = "oxt-usd.data.eth"

Const PAX_ETH_AGGREGATOR

PAX_ETH_AGGREGATOR: "0x3a08ebBaB125224b7b6474384Ee39fBb247D2200" = "0x3a08ebBaB125224b7b6474384Ee39fBb247D2200"

Const RCN_BTC_AGGREGATOR

RCN_BTC_AGGREGATOR: "rcn-btc.data.eth" = "rcn-btc.data.eth"

Const REN_ETH_AGGREGATOR

REN_ETH_AGGREGATOR: "ren-eth.data.eth" = "ren-eth.data.eth"

Const REN_USD_AGGREGATOR

REN_USD_AGGREGATOR: "ren-usd.data.eth" = "ren-usd.data.eth"

Const REP_ETH_AGGREGATOR

REP_ETH_AGGREGATOR: "rep-eth.data.eth" = "rep-eth.data.eth"

Const SCEX_USD_AGGREGATOR

SCEX_USD_AGGREGATOR: "scex-usd.data.eth" = "scex-usd.data.eth"

Const SDEFI_USD_AGGREGATOR

SDEFI_USD_AGGREGATOR: "sdefi-usd.data.eth" = "sdefi-usd.data.eth"

Const SNX_ETH_AGGREGATOR

SNX_ETH_AGGREGATOR: "snx-eth.data.eth" = "snx-eth.data.eth"

Const SNX_USD_AGGREGATOR

SNX_USD_AGGREGATOR: "snx-usd.data.eth" = "snx-usd.data.eth"

Const SUSD_ETH_AGGREGATOR

SUSD_ETH_AGGREGATOR: "susd-eth.data.eth" = "susd-eth.data.eth"

Const SXP_USD_AGGREGATOR

SXP_USD_AGGREGATOR: "sxp-usd.data.eth" = "sxp-usd.data.eth"

Const TRX_USD_AGGREGATOR

TRX_USD_AGGREGATOR: "trx-usd.data.eth" = "trx-usd.data.eth"

Const TUSD_ETH_AGGREGATOR

TUSD_ETH_AGGREGATOR: "tusd-eth.data.eth" = "tusd-eth.data.eth"

Const UNI_ETH_AGGREGATOR

UNI_ETH_AGGREGATOR: "uni-eth.data.eth" = "uni-eth.data.eth"

Const UNI_USD_AGGREGATOR

UNI_USD_AGGREGATOR: "uni-usd.data.eth" = "uni-usd.data.eth"

Const USDC_ETH_AGGREGATOR

USDC_ETH_AGGREGATOR: "usdc-eth.data.eth" = "usdc-eth.data.eth"

Const USDT_ETH_AGGREGATOR

USDT_ETH_AGGREGATOR: "usdt-eth.data.eth" = "usdt-eth.data.eth"

Const WOM_ETH_AGGREGATOR

WOM_ETH_AGGREGATOR: "wom-eth.data.eth" = "wom-eth.data.eth"

Const XAG_USD_AGGREGATOR

XAG_USD_AGGREGATOR: "xag-usd.data.eth" = "xag-usd.data.eth"

Const XAU_USD_AGGREGATOR

XAU_USD_AGGREGATOR: "xau-usd.data.eth" = "xau-usd.data.eth"

Const XMR_USD_AGGREGATOR

XMR_USD_AGGREGATOR: "xmr-usd.data.eth" = "xmr-usd.data.eth"

Const XRP_USD_AGGREGATOR

XRP_USD_AGGREGATOR: "xrp-usd.data.eth" = "xrp-usd.data.eth"

Const XTZ_USD_AGGREGATOR

XTZ_USD_AGGREGATOR: "xtz-usd.data.eth" = "xtz-usd.data.eth"

Const YFI_ETH_AGGREGATOR

YFI_ETH_AGGREGATOR: "yfi-eth.data.eth" = "yfi-eth.data.eth"

Const YFI_USD_AGGREGATOR

YFI_USD_AGGREGATOR: "yfi-usd.data.eth" = "yfi-usd.data.eth"

Const ZRX_ETH_AGGREGATOR

ZRX_ETH_AGGREGATOR: "zrx-eth.data.eth" = "zrx-eth.data.eth"

Const mainnetPriceFeeds

mainnetPriceFeeds: readonly Feed[] = [{id: 0,from: 'ETH',to: 'USD',address: ETH_USD_AGGREGATOR,decimals: 8,},{id: 1,from: 'BTC',to: 'USD',address: BTC_USD_AGGREGATOR,decimals: 8,},{id: 2,from: 'LINK',to: 'USD',address: LINK_USD_AGGREGATOR,decimals: 8,},{id: 3,from: 'XAU',to: 'USD',address: XAU_USD_AGGREGATOR,decimals: 8,},{id: 4,from: 'SNX',to: 'USD',address: SNX_USD_AGGREGATOR,decimals: 8,},{id: 5,from: 'DAI',to: 'USD',address: DAI_USD_AGGREGATOR,decimals: 8,},{id: 6,from: 'COMP',to: 'USD',address: COMP_USD_AGGREGATOR,decimals: 8,},{id: 7,from: 'DASH',to: 'USD',address: DASH_USD_AGGREGATOR,decimals: 8,},{id: 8,from: 'AUD',to: 'USD',address: AUD_USD_AGGREGATOR,decimals: 8,},{id: 9,from: 'LTC',to: 'USD',address: LTC_USD_AGGREGATOR,decimals: 8,},{id: 10,from: 'GBP',to: 'USD',address: GBP_USD_AGGREGATOR,decimals: 8,},{id: 11,from: 'ETC',to: 'USD',address: ETC_USD_AGGREGATOR,decimals: 8,},{id: 12,from: 'BCH',to: 'USD',address: BCH_USD_AGGREGATOR,decimals: 8,},{id: 13,from: 'XRP',to: 'USD',address: XRP_USD_AGGREGATOR,decimals: 8,},{id: 14,from: 'EOS',to: 'USD',address: EOS_USD_AGGREGATOR,decimals: 8,},{id: 15,from: 'XAG',to: 'USD',address: XAG_USD_AGGREGATOR,decimals: 8,},{id: 16,from: 'KNC',to: 'USD',address: KNC_USD_AGGREGATOR,decimals: 8,},{id: 17,from: 'SDEFI',to: 'USD',address: SDEFI_USD_AGGREGATOR,decimals: 8,},{id: 18,from: 'FIL',to: 'USD',address: FIL_USD_AGGREGATOR,decimals: 8,},{id: 19,from: 'MCAP',to: 'USD',address: MCAP_USD_AGGREGATOR,decimals: 8,},{id: 20,from: 'XMR',to: 'USD',address: XMR_USD_AGGREGATOR,decimals: 8,},{id: 21,from: 'BNT',to: 'USD',address: BNT_USD_AGGREGATOR,decimals: 8,},{id: 22,from: 'SXP',to: 'USD',address: SXP_USD_AGGREGATOR,decimals: 8,},{id: 23,from: 'TRX',to: 'USD',address: TRX_USD_AGGREGATOR,decimals: 8,},{id: 24,from: 'N225',to: 'JPY',address: N225_JPY_AGGREGATOR,decimals: 8,},{id: 25,from: 'UNI',to: 'USD',address: UNI_USD_AGGREGATOR,decimals: 8,},{id: 26,from: 'XTZ',to: 'USD',address: XTZ_USD_AGGREGATOR,decimals: 8,},{id: 27,from: 'DOT',to: 'USD',address: DOT_USD_AGGREGATOR,decimals: 8,},{id: 28,from: 'JPY',to: 'USD',address: JPY_USD_AGGREGATOR,decimals: 8,},{id: 29,from: 'EUR',to: 'USD',address: EUR_USD_AGGREGATOR,decimals: 8,},{id: 30,from: 'BNB',to: 'USD',address: BNB_USD_AGGREGATOR,decimals: 8,},{id: 31,from: 'OXT',to: 'USD',address: OXT_USD_AGGREGATOR,decimals: 8,},{id: 32,from: 'ADX',to: 'USD',address: ADX_USD_AGGREGATOR,decimals: 8,},{id: 33,from: 'YFI',to: 'USD',address: YFI_USD_AGGREGATOR,decimals: 8,},{id: 34,from: 'SCEX',to: 'USD',address: SCEX_USD_AGGREGATOR,decimals: 8,},{id: 35,from: 'REN',to: 'USD',address: REN_USD_AGGREGATOR,decimals: 8,},{id: 36,from: 'FNX',to: 'USD',address: FNX_USD_AGGREGATOR,decimals: 8,},{id: 37,from: 'BRENT',to: 'USD',address: BRENT_USD_AGGREGATOR,decimals: 8,},{id: 38,from: 'AAVE',to: 'USD',address: AAVE_USD_AGGREGATOR,decimals: 8,},{id: 39,from: 'FTSE',to: 'GBP',address: FTSE_GBP_AGGREGATOR,decimals: 8,},{id: 40,from: 'CHF',to: 'USD',address: CHF_USD_AGGREGATOR,decimals: 8,},{id: 41,from: 'ADA',to: 'USD',address: ADA_USD_AGGREGATOR,decimals: 8,},{id: 42,from: 'DAI',to: 'ETH',address: DAI_ETH_AGGREGATOR,decimals: 18,},{id: 43,from: 'USDC',to: 'ETH',address: USDC_ETH_AGGREGATOR,decimals: 18,},{id: 44,from: 'USDT',to: 'ETH',address: USDT_ETH_AGGREGATOR,decimals: 18,},{id: 45,from: 'SUSD',to: 'ETH',address: SUSD_ETH_AGGREGATOR,decimals: 18,},{id: 46,from: 'LINK',to: 'ETH',address: LINK_ETH_AGGREGATOR,decimals: 18,},{id: 47,from: 'ZRX',to: 'ETH',address: ZRX_ETH_AGGREGATOR,decimals: 18,},{id: 48,from: 'BTC',to: 'ETH',address: BTC_ETH_AGGREGATOR,decimals: 18,},{id: 49,from: 'KNC',to: 'ETH',address: KNC_ETH_AGGREGATOR,decimals: 18,},{id: 50,from: 'TUSD',to: 'ETH',address: TUSD_ETH_AGGREGATOR,decimals: 18,},{id: 51,from: 'BAT',to: 'ETH',address: BAT_ETH_AGGREGATOR,decimals: 18,},{id: 52,from: 'AAVE',to: 'ETH',address: AAVE_ETH_AGGREGATOR,decimals: 18,},{id: 53,from: 'LRC',to: 'ETH',address: LRC_ETH_AGGREGATOR,decimals: 18,},{id: 54,from: 'MKR',to: 'ETH',address: MKR_ETH_AGGREGATOR,decimals: 18,},{id: 55,from: 'MANA',to: 'ETH',address: MANA_ETH_AGGREGATOR,decimals: 18,},{id: 56,from: 'BUSD',to: 'ETH',address: BUSD_ETH_AGGREGATOR,decimals: 18,},{id: 57,from: 'REP',to: 'ETH',address: REP_ETH_AGGREGATOR,decimals: 18,},{id: 58,from: 'SNX',to: 'ETH',address: SNX_ETH_AGGREGATOR,decimals: 18,},{id: 59,from: 'REN',to: 'ETH',address: REN_ETH_AGGREGATOR,decimals: 18,},{id: 60,from: 'ENJ',to: 'ETH',address: ENJ_ETH_AGGREGATOR,decimals: 18,},{id: 61,from: 'UNI',to: 'ETH',address: UNI_ETH_AGGREGATOR,decimals: 18,},{id: 62,from: 'CRV',to: 'ETH',address: CRV_ETH_AGGREGATOR,decimals: 18,},{id: 63,from: 'BNT',to: 'ETH',address: BNT_ETH_AGGREGATOR,decimals: 18,},{id: 64,from: 'PAX',to: 'ETH',address: PAX_ETH_AGGREGATOR,decimals: 18,},{id: 65,from: 'ETH',to: 'XDR',address: ETH_XDR_AGGREGATOR,decimals: 8,},{id: 66,from: 'YFI',to: 'ETH',address: YFI_ETH_AGGREGATOR,decimals: 18,},{id: 67,from: 'CRO',to: 'ETH',address: CRO_ETH_AGGREGATOR,decimals: 18,},{id: 68,from: 'DMG',to: 'ETH',address: DMG_ETH_AGGREGATOR,decimals: 18,},{id: 69,from: 'RCN',to: 'BTC',address: RCN_BTC_AGGREGATOR,decimals: 8,},{id: 70,from: 'BZRX',to: 'ETH',address: BZRX_ETH_AGGREGATOR,decimals: 18,},{id: 71,from: 'WOM',to: 'ETH',address: WOM_ETH_AGGREGATOR,decimals: 18,},]

Const supportedAssets

supportedAssets: { code: string }[] = [{code: 'USD',},{code: 'ETH',},{code: 'BTC',},{code: 'LINK',},{code: 'XAU',},{code: 'SNX',},{code: 'DAI',},{code: 'COMP',},{code: 'DASH',},{code: 'AUD',},{code: 'LTC',},{code: 'GBP',},{code: 'ETC',},{code: 'BCH',},{code: 'XRP',},{code: 'EOS',},{code: 'XAG',},{code: 'KNC',},{code: 'SDEFI',},{code: 'FIL',},{code: 'MCAP',},{code: 'XMR',},{code: 'BNT',},{code: 'SXP',},{code: 'TRX',},{code: 'N225',},{code: 'UNI',},{code: 'XTZ',},{code: 'DOT',},{code: 'JPY',},{code: 'EUR',},{code: 'BNB',},{code: 'OXT',},{code: 'ADX',},{code: 'YFI',},{code: 'SCEX',},{code: 'REN',},{code: 'FNX',},{code: 'BRENT',},{code: 'AAVE',},{code: 'FTSE',},{code: 'CHF',},{code: 'ADA',},{code: 'USDC',},{code: 'USDT',},{code: 'SUSD',},{code: 'TUSD',},{code: 'ZRX',},{code: 'BAT',},{code: 'LRC',},{code: 'MKR',},{code: 'MANA',},{code: 'BUSD',},{code: 'REP',},{code: 'ENJ',},{code: 'CRV',},{code: 'PAX',},{code: 'XDR',},{code: 'CRO',},{code: 'DMG',},{code: 'RCN',},{code: 'BZRX',},{code: 'WOM',},]

Functions

Const convert

  • Convert a known amount in one asset to some amount of another asset.

    Example

    await convert({
     amount: 5,
     from: 'ETH',
     to: 'BTC',
     endpoint: 'https://mainnet.infura.io/v3/ab01ab01ab01ab01ab01ab01'
    });
    // => '0.2'

    Parameters

    Returns Promise<string>

    The resulting amount of the to asset after conversion

Const createProvider

  • createProvider(endpoint: string): JsonRpcProvider
  • Parameters

    • endpoint: string

      Your Ethereum JSON-RPC endpoint

    Returns JsonRpcProvider

Const getShortestPath

  • getShortestPath(fromAsset: string, toAsset: string, feeds?: readonly Feed[]): Path
  • By modelling a tree where all the assets are our vertices and all the price feeds are our path sections between those vertices, we can recursively traverse through to find the shortest path between our origin asset and the destination asset.

    Example

    const feeds: readonly Feed[] = [
      {
        id: 0,
        from: 'ETH',
        to: 'USD',
        address: '',
        decimals: 1,
      },
      {
        id: 1,
        from: 'BTC',
        to: 'USD',
        address: '',
        decimals: 1,
      }
    ];
    
    getShortestPath('ETH', 'BTC', feeds);
    // => [
    //   {
    //     feedId: 0,
    //     inverse: false,
    //   },
    //   {
    //     feedId: 1,
    //     inverse: true,
    //   },
    // ];

    Parameters

    • fromAsset: string

      The asset vertex to begin pathing from for this iteration

    • toAsset: string

      The destination asset vertex (the asset we ultimately wish to convert to)

    • Default value feeds: readonly Feed[] = mainnetPriceFeeds

      The feeds representing the paths between all vertices

    Returns Path

    Path representing the shortest path between our origin and destination asset vertices

Generated using TypeDoc