export const getQuote = async ( address: Address, amount: number, fromAssetTypeId: AssetTypeIdentifier, toAssetTypeId: AssetTypeIdentifier ) => { if (!amount) { throw new Error('Amount must be defined and bigger than 0'); } if (fromAssetTypeId === toAssetTypeId) { throw new Error('You can not swap to the same token'); } const fromAssetType = ASSET_TYPES_ENTITIES[fromAssetTypeId]; if (!fromAssetType.swap) { throw new Error('Unsupported from token'); } const toAssetType = ASSET_TYPES_ENTITIES[toAssetTypeId]; if (!toAssetType.swap) { throw new Error('Unsupported to token'); } const sellToken = fromAssetType.contractAddress ? fromAssetType.contractAddress : fromAssetType.include ? ASSET_TYPES_ENTITIES[fromAssetType.include].contractAddress : undefined; if (!sellToken) { throw new Error('Undefined sell token'); } const buyToken = toAssetType.contractAddress ? toAssetType.contractAddress : toAssetType.include ? ASSET_TYPES_ENTITIES[toAssetType.include].contractAddress : undefined; if (!buyToken) { throw new Error('Undefined buy token'); } return await orderBookApi.getQuote({ sellToken, buyToken, from: address, receiver: address, sellAmountBeforeFee: (amount * 10 ** 18).toString(), // 0.4 WETH kind: OrderQuoteSideKindSell.SELL }); };