mirror of
https://github.com/oceanprotocol/market.git
synced 2024-06-30 13:51:42 +02:00
fixed highest liquidity price, and prices for assets with pool and free asset
This commit is contained in:
parent
4fbac1e2e0
commit
34ab37f592
|
@ -23,7 +23,7 @@ import { useUserPreferences } from '../../providers/UserPreferences'
|
|||
async function getQueryHighest(
|
||||
chainIds: number[]
|
||||
): Promise<[SearchQuery, string]> {
|
||||
const dids = await getHighestLiquidityDIDs()
|
||||
const dids = await getHighestLiquidityDIDs(chainIds)
|
||||
|
||||
// TODO: this query needs to adapt to chainIds
|
||||
const queryHighest = {
|
||||
|
|
|
@ -6,6 +6,7 @@ import web3 from 'web3'
|
|||
import { AssetsFreePrice } from '../@types/apollo/AssetsFreePrice'
|
||||
import { AssetPreviousOrder } from '../@types/apollo/AssetPreviousOrder'
|
||||
// import {AssetPreviousOrder} from '../@types/graph.types'
|
||||
// import { AssetFree } from '../@types/graph.types'
|
||||
|
||||
export interface PriceList {
|
||||
[key: string]: string
|
||||
|
@ -247,11 +248,11 @@ async function getAssetsPoolsExchangesAndDatatokenMap(
|
|||
for (const ddo of assets) {
|
||||
didDTMap[ddo?.dataToken.toLowerCase()] = ddo.id
|
||||
// harcoded until we have chainId on assets
|
||||
if (chainAssetLists[1]) {
|
||||
chainAssetLists[1].push(ddo?.dataToken.toLowerCase())
|
||||
if (chainAssetLists[ddo.chainId]) {
|
||||
chainAssetLists[ddo.chainId].push(ddo?.dataToken.toLowerCase())
|
||||
} else {
|
||||
chainAssetLists[1] = []
|
||||
chainAssetLists[1].push(ddo?.dataToken.toLowerCase())
|
||||
chainAssetLists[ddo.chainId] = []
|
||||
chainAssetLists[ddo.chainId].push(ddo?.dataToken.toLowerCase())
|
||||
}
|
||||
}
|
||||
let poolPriceResponse: AssetsPoolPricePools[] = []
|
||||
|
@ -268,9 +269,11 @@ async function getAssetsPoolsExchangesAndDatatokenMap(
|
|||
const freeVariables = {
|
||||
datatoken_in: chainAssetLists[chainKey]
|
||||
}
|
||||
// harcoded until we have chainId on assets
|
||||
|
||||
const queryContext: OperationContext = {
|
||||
url: `${getSubgrahUri(1)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
||||
url: `${getSubgrahUri(
|
||||
Number(chainKey)
|
||||
)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
||||
requestPolicy: 'network-only'
|
||||
}
|
||||
|
||||
|
@ -282,12 +285,14 @@ async function getAssetsPoolsExchangesAndDatatokenMap(
|
|||
)
|
||||
const chainFrePriceResponse: OperationResult<AssetsFrePrice> =
|
||||
await fetchData(FreQuery, freVariables, queryContext)
|
||||
|
||||
frePriceResponse = frePriceResponse.concat(
|
||||
chainFrePriceResponse.data.fixedRateExchanges
|
||||
)
|
||||
|
||||
const chainFreePriceResponse: OperationResult<AssetsFreePrice> =
|
||||
await fetchData(FreeQuery, freeVariables, queryContext)
|
||||
|
||||
freePriceResponse = freePriceResponse.concat(
|
||||
chainFreePriceResponse.data.dispensers
|
||||
)
|
||||
|
@ -318,7 +323,7 @@ export async function getAssetsPriceList(assets: DDO[]): Promise<PriceList> {
|
|||
for (const frePrice of frePriceResponse) {
|
||||
priceList[didDTMap[frePrice.datatoken?.address]] = frePrice.rate
|
||||
}
|
||||
for (const freePrice of freePriceResponse.data?.dispensers) {
|
||||
for (const freePrice of freePriceResponse) {
|
||||
priceList[didDTMap[freePrice.datatoken?.address]] = '0'
|
||||
}
|
||||
return priceList
|
||||
|
@ -335,9 +340,10 @@ export async function getPrice(asset: DDO): Promise<BestPrice> {
|
|||
datatokenAddress: asset?.dataToken.toLowerCase()
|
||||
}
|
||||
|
||||
// hardcoded with mainet until we have the chainid param on asset like getSubgrahUri(asset.chainId)
|
||||
const queryContext: OperationContext = {
|
||||
url: `${getSubgrahUri(1)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
||||
url: `${getSubgrahUri(
|
||||
asset.chainId
|
||||
)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
||||
requestPolicy: 'network-only'
|
||||
}
|
||||
const poolPriceResponse: OperationResult<AssetsPoolPrice> = await fetchData(
|
||||
|
@ -376,25 +382,24 @@ export async function getAssetsBestPrices(
|
|||
ApolloQueryResult<AssetsFreePrice>,
|
||||
DidAndDatatokenMap
|
||||
] = await getAssetsPoolsExchangesAndDatatokenMap(assets)
|
||||
|
||||
const poolPriceResponse = values[0]
|
||||
const frePriceResponse = values[1]
|
||||
const freePriceResponse = values[2]
|
||||
|
||||
for (const ddo of assets) {
|
||||
const dataToken = ddo.dataToken.toLowerCase()
|
||||
const poolPrice: AssetsPoolPricePools[] = []
|
||||
const frePrice: AssetsFrePriceFixedRateExchanges[] = []
|
||||
const freePrice: AssetFreePriceDispenser[] = []
|
||||
const pool = poolPriceResponse.data?.pools.find(
|
||||
const pool = poolPriceResponse.find(
|
||||
(pool: any) => pool.datatokenAddress === dataToken
|
||||
)
|
||||
|
||||
pool && poolPrice.push(pool)
|
||||
const fre = frePriceResponse.find(
|
||||
(fre: any) => fre.datatoken.address === dataToken
|
||||
)
|
||||
fre && frePrice.push(fre)
|
||||
const free = freePriceResponse.data?.dispensers.find(
|
||||
const free = freePriceResponse.find(
|
||||
(free: any) => free.datatoken.address === dataToken
|
||||
)
|
||||
free && freePrice.push(free)
|
||||
|
@ -408,25 +413,30 @@ export async function getAssetsBestPrices(
|
|||
return assetsWithPrice
|
||||
}
|
||||
|
||||
export async function getHighestLiquidityDIDs(): Promise<string> {
|
||||
export async function getHighestLiquidityDIDs(
|
||||
chainIds: number[]
|
||||
): Promise<string> {
|
||||
const didList: string[] = []
|
||||
const queryContext: OperationContext = {
|
||||
url: `${getSubgrahUri(1)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
||||
requestPolicy: 'network-only'
|
||||
}
|
||||
|
||||
const fetchedPools = await fetchData(
|
||||
HighestLiquidityAssets,
|
||||
null,
|
||||
queryContext
|
||||
)
|
||||
if (fetchedPools.data?.pools?.length === 0) return null
|
||||
for (let i = 0; i < fetchedPools.data.pools.length; i++) {
|
||||
if (!fetchedPools.data.pools[i].datatokenAddress) continue
|
||||
const did = web3.utils
|
||||
.toChecksumAddress(fetchedPools.data.pools[i].datatokenAddress)
|
||||
.replace('0x', 'did:op:')
|
||||
didList.push(did)
|
||||
for (const chain of chainIds) {
|
||||
const queryContext: OperationContext = {
|
||||
url: `${getSubgrahUri(
|
||||
Number(chain)
|
||||
)}/subgraphs/name/oceanprotocol/ocean-subgraph`,
|
||||
requestPolicy: 'network-only'
|
||||
}
|
||||
const fetchedPools = await fetchData(
|
||||
HighestLiquidityAssets,
|
||||
null,
|
||||
queryContext
|
||||
)
|
||||
if (fetchedPools.data?.pools?.length === 0) return null
|
||||
for (let i = 0; i < fetchedPools.data.pools.length; i++) {
|
||||
if (!fetchedPools.data.pools[i].datatokenAddress) continue
|
||||
const did = web3.utils
|
||||
.toChecksumAddress(fetchedPools.data.pools[i].datatokenAddress)
|
||||
.replace('0x', 'did:op:')
|
||||
didList.push(did)
|
||||
}
|
||||
}
|
||||
const searchDids = JSON.stringify(didList)
|
||||
.replace(/,/g, ' ')
|
||||
|
|
Loading…
Reference in New Issue
Block a user