Private
layer2This call will convert a SPEND amount into the specified token amount, where the result is a string that represents the token in units of wei
. Since SPEND tokens represent $0.01 USD, it is safe to represent SPEND as a number when providing the input value.
let weiAmount = await layerTwoOracle.convertFromSpend(daicpxdAddress, 10000); // convert 10000 SPEND into DAI
console.log(`DAI value ${fromWei(weiAmount)}`);
This returns a function that converts an amount of a token in wei to USD. Similar to LayerTwoOracle.getUSDPrice
, an exception will be thrown if we don't have the exchange rate for the token. The returned function accepts a string that represents an amount in wei and returns a number that represents the USD value of that amount of the token. Currently, we assume 18 decimals so only tokens conforming to this can be supported.
let layerTwoOracle = await getSDK('LayerTwoOracle', web3);
let converter = await layerTwoOracle.getUSDConverter("DAI");
console.log(`USD value: $${converter(amountInWei)} USD`);
This call will return the USD value for the specified amount of the specified token. If we do not have an exchange rate for the token, then an exception will be thrown. This API requires that the token amount be specified in wei
(1018 wei
= 1 token) as a string, and will return a floating point value in units of USD. You can easily convert a token value to wei by using the Web3.utils.toWei()
function. Currently, we assume 18 decimals so only tokens conforming to this can be supported.
let layerTwoOracle = await getSDK('LayerTwoOracle', web3);
let usdPrice = await layerTwoOracleRate.getUSDPrice("DAI", amountInWei);
console.log(`USD value: $${usdPrice.toFixed(2)} USD`);
This call will return the ETH value for the specified amount of the specified token. If we do not have an exchange rate for the token, then an exception will be thrown. This API requires that the token amount be specified in wei
(1018 wei
= 1 token) as a string, and will return a string that represents the ETH value in units of wei
as well. You can easily convert a token value to wei by using the Web3.utils.toWei()
function. You can also easily convert units of wei
back into ethers
by using the Web3.utils.fromWei()
function. Currently, we assume 18 decimals so only tokens conforming to this can be supported.
let layerTwoOracle = await getSDK('LayerTwoOracle', web3);
let ethWeiPrice = await layerTwoOracle.getETHPrice("CARD", amountInWei);
console.log(`ETH value: ${fromWei(ethWeiPrice)} ETH`);
This call will return a Date
instance that indicates the date the token rate was last updated.
let layerTwoOracle = await getSDK('LayerTwoOracle', web3);
let date = await layerTwoOracle.getUpdatedAt("DAI");
console.log(`The ${token} rate was last updated at ${date.toString()}`);
Private
getGenerated using TypeDoc
The
LayerTwoOracle
API is used to get the current exchange rates in USD and ETH for the various stablecoin that we support. These rates are fed by the Chainlink price feeds for the stablecoin rates and the DIA oracle for the CARD token rates. As we onboard new stablecoin we'll add more exchange rates. The price oracles that we use reside in layer 2, so please supply a layer 2 web3 instance obtaining anLayerTwoOracle
API fromgetSDK()
.Example