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:
parent
e912b9f2bd
commit
81b190dd93
@ -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(
|
export async function getBestDataTokenPrice(
|
||||||
ocean: Ocean,
|
ocean: Ocean,
|
||||||
dataTokenAddress: string
|
dataTokenAddress: string
|
||||||
): Promise<BestPrice> {
|
): Promise<BestPrice> {
|
||||||
const cheapestPool = await getCheapestPool(ocean, dataTokenAddress)
|
const cheapestPool = await getFirstPool(ocean, dataTokenAddress)
|
||||||
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
|
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
|
||||||
Decimal.set({ precision: 5 })
|
Decimal.set({ precision: 5 })
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user