mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
update price value for pool assets using consumePrice and added isConsumable logic
This commit is contained in:
parent
d73b921a48
commit
0cef2cccd5
2
package-lock.json
generated
2
package-lock.json
generated
@ -18101,7 +18101,7 @@
|
||||
}
|
||||
},
|
||||
"ethereumjs-abi": {
|
||||
"version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1a27c59c15ab1e95ee8e5c4ed6ad814c49cc439e",
|
||||
"version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1ce6a1d64235fabe2aaf827fd606def55693508f",
|
||||
"from": "git+https://github.com/ethereumjs/ethereumjs-abi.git",
|
||||
"requires": {
|
||||
"bn.js": "^4.11.8",
|
||||
|
@ -117,13 +117,8 @@ function AssetProvider({
|
||||
const initMetadata = useCallback(async (ddo: DDO): Promise<void> => {
|
||||
if (!ddo) return
|
||||
|
||||
// Set price & metadata from DDO first
|
||||
// TODO Hacky hack, temporary™: set isConsumable to true by default since Aquarius can't be trusted.
|
||||
// setPrice({ ...ddo.price, isConsumable: 'true' })
|
||||
|
||||
const returnedPrice = await getPrice(ddo)
|
||||
console.log('returnedPrice', returnedPrice)
|
||||
setPrice({ ...returnedPrice, isConsumable: 'true' })
|
||||
setPrice({ ...returnedPrice })
|
||||
|
||||
// Get metadata from DDO
|
||||
const { attributes } = ddo.findServiceByType('metadata')
|
||||
|
@ -32,8 +32,9 @@ const AssetFreQuery = gql`
|
||||
const PoolQuery = gql`
|
||||
query AssetsPoolPrice($datatokenAddress_in: [String!]) {
|
||||
pools(where: { datatokenAddress_in: $datatokenAddress_in }) {
|
||||
spotPrice
|
||||
id
|
||||
spotPrice
|
||||
consumePrice
|
||||
datatokenAddress
|
||||
}
|
||||
}
|
||||
@ -44,9 +45,10 @@ const AssetPoolPriceQuerry = gql`
|
||||
pools(where: { datatokenAddress: $datatokenAddress }) {
|
||||
id
|
||||
spotPrice
|
||||
consumePrice
|
||||
datatokenAddress
|
||||
datatokenReserve
|
||||
oceanReserve
|
||||
datatokenAddress
|
||||
}
|
||||
}
|
||||
`
|
||||
@ -127,7 +129,10 @@ export async function getAssetPrices(assets: DDO[]): Promise<PriceList> {
|
||||
}
|
||||
const poolPriceResponse: any = await fetchData(PoolQuery, poolVariables)
|
||||
for (const poolPrice of poolPriceResponse.data?.pools) {
|
||||
priceList[didDTMap[poolPrice.datatokenAddress]] = poolPrice.spotPrice
|
||||
priceList[didDTMap[poolPrice.datatokenAddress]] =
|
||||
poolPrice.consumePrice === '-1'
|
||||
? poolPrice.spotPrice
|
||||
: poolPrice.consumePrice
|
||||
}
|
||||
const frePriceResponse: any = await fetchData(FreQuery, freVariables)
|
||||
for (const frePrice of frePriceResponse.data?.fixedRateExchanges) {
|
||||
@ -154,13 +159,22 @@ export async function getPrice(asset: DDO): Promise<BestPrice> {
|
||||
const price: BestPrice = {
|
||||
type: 'pool',
|
||||
address: poolPriceResponse.data?.pools[0]?.id,
|
||||
value: poolPriceResponse.data?.pools[0]?.spotPrice,
|
||||
value:
|
||||
poolPriceResponse.data?.pools[0]?.consumePrice === '-1'
|
||||
? poolPriceResponse.data?.pools[0]?.spotPrice
|
||||
: poolPriceResponse.data?.pools[0]?.consumePrice,
|
||||
ocean: poolPriceResponse.data?.pools[0]?.oceanReserve,
|
||||
datatoken: poolPriceResponse.data?.pools[0]?.datatokenReserve,
|
||||
pools: [poolPriceResponse.data?.pools[0]?.id]
|
||||
pools: [poolPriceResponse.data?.pools[0]?.id],
|
||||
isConsumable:
|
||||
poolPriceResponse.data?.pools[0]?.consumePrice === '-1'
|
||||
? 'false'
|
||||
: 'true'
|
||||
}
|
||||
return price
|
||||
} else if (frePriceResponse.data?.fixedRateExchanges.length > 0) {
|
||||
// TODO Hacky hack, temporary™: set isConsumable to true for fre assets.
|
||||
// isConsumable: 'true'
|
||||
const price: BestPrice = {
|
||||
type: 'exchange',
|
||||
value: frePriceResponse.data?.fixedRateExchanges[0]?.rate,
|
||||
@ -168,7 +182,8 @@ export async function getPrice(asset: DDO): Promise<BestPrice> {
|
||||
exchange_id: frePriceResponse.data?.fixedRateExchanges[0]?.id,
|
||||
ocean: 0,
|
||||
datatoken: 0,
|
||||
pools: []
|
||||
pools: [],
|
||||
isConsumable: 'true'
|
||||
}
|
||||
return price
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user