1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-14 21:10:38 +01:00

switch to first pool

This commit is contained in:
alexcos20 2020-10-16 03:27:33 -07:00
parent e912b9f2bd
commit 81b190dd93

View File

@ -86,11 +86,38 @@ export async function getCheapestExchange(
}
}
export async function getFirstPool(
ocean: Ocean,
dataTokenAddress: string
): Promise<Pool | null> {
if (!ocean || !dataTokenAddress) return null
const tokenPools = await ocean.pool.searchPoolforDT(dataTokenAddress)
if (tokenPools === undefined || tokenPools.length === 0) {
return {
address: '',
price: 0
}
}
const firstPoolAddress = tokenPools[0]
const firstPoolPrice = await ocean.pool.getOceanNeeded(firstPoolAddress, '1')
const oceanReserve = await ocean.pool.getOceanReserve(firstPoolAddress)
const dtReserve = await ocean.pool.getDTReserve(firstPoolAddress)
return {
address: firstPoolAddress,
price: Number(firstPoolPrice),
ocean: Number(oceanReserve),
datatoken: Number(dtReserve)
}
}
export async function getBestDataTokenPrice(
ocean: Ocean,
dataTokenAddress: string
): Promise<BestPrice> {
const cheapestPool = await getCheapestPool(ocean, dataTokenAddress)
const cheapestPool = await getFirstPool(ocean, dataTokenAddress)
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
Decimal.set({ precision: 5 })