Readonly
tradeCalculates cross-chain trades and sorts them by exchange courses. Wrapped trade object may contain error, but sometimes course can be calculated even with thrown error (e.g. min/max amount error).
const fromBlockchain = BLOCKCHAIN_NAME.ETHEREUM;
// ETH
const fromTokenAddress = '0x0000000000000000000000000000000000000000';
const fromAmount = 1;
const toBlockchain = BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN;
// BUSD
const toTokenAddress = '0xe9e7cea3dedca5984780bafc599bd69add087d56';
const wrappedTrades = await sdk.crossChainManager.calculateTrade(
{ blockchain: fromBlockchain, address: fromTokenAddress },
fromAmount,
{ blockchain: toBlockchain, address: toTokenAddress }
);
const bestTrade = wrappedTrades[0];
wrappedTrades.forEach(wrappedTrade => {
if (wrappedTrade.trade) {
console.log(wrappedTrade.tradeType, `to amount: ${wrappedTrade.trade.to.tokenAmount.toFormat(3)}`));
}
if (wrappedTrade.error) {
console.error(wrappedTrade.tradeType, 'error: wrappedTrade.error');
}
});
Array of sorted wrapped cross-chain trades with possible errors.
Token to sell.
Amount to sell.
Token to get.
Optional
options: CrossChainManagerCalculationOptionsAdditional options.
Calculates cross-chain trades reactively in sequence. Contains wrapped trade object which may contain error, but sometimes course can be calculated even with thrown error (e.g. min/max amount error).
const fromBlockchain = BLOCKCHAIN_NAME.ETHEREUM;
// ETH
const fromTokenAddress = '0x0000000000000000000000000000000000000000';
const fromAmount = 1;
const toBlockchain = BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN;
// BUSD
const toTokenAddress = '0xe9e7cea3dedca5984780bafc599bd69add087d56';
sdk.crossChain.calculateTrade(
{ blockchain: fromBlockchain, address: fromTokenAddress },
fromAmount,
{ blockchain: toBlockchain, address: toTokenAddress }
).subscribe(tradeData => {
console.log(tradeData.total) // 3
console.log(tradeData.calculated) // 0 or 1 ... or tradeData.total
const wrappedTrade = tradeData.wrappedTrade;
if (wrappedTrade) {
console.log(wrappedTrade.tradeType, `to amount: ${wrappedTrade.trade.to.tokenAmount.toFormat(3)}`));
if (wrappedTrade.error) {
console.error(wrappedTrade.tradeType, 'error: wrappedTrade.error');
}
}
});
Observable of cross-chain providers calculation data with best trade and possible errors.
Token to sell.
Amount to sell.
Token to get.
Optional
options: CrossChainManagerCalculationOptionsAdditional options.
Generated using TypeDoc
Contains method to calculate best cross-chain trade.