1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Highest liquidity correct assets order (#736)

* ordered subgraph did array before return

* updated aqua querry offset to fit multi network

* fixed typo and removed logs

* sort assets by oceanReserve

* added TVL label and rename Pool Creator Liquidity to Pool Creator Statistics

* remove obsolete comments

Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
This commit is contained in:
Bogdan Fazakas 2021-07-15 18:25:53 +03:00 committed by GitHub
parent 565c0324f9
commit 5a6d267199
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 25 deletions

View File

@ -6,6 +6,9 @@
font-weight: var(--font-weight-base); font-weight: var(--font-weight-base);
} }
.removeTvlPadding {
padding-left: 0 !important;
}
/* fiat currency symbol */ /* fiat currency symbol */
.conversion strong span { .conversion strong span {
font-weight: var(--font-weight-base); font-weight: var(--font-weight-base);

View File

@ -10,11 +10,13 @@ const cx = classNames.bind(styles)
export default function Conversion({ export default function Conversion({
price, price,
className, className,
hideApproximateSymbol hideApproximateSymbol,
showTVLLabel
}: { }: {
price: string // expects price in OCEAN, not wei price: string // expects price in OCEAN, not wei
className?: string className?: string
hideApproximateSymbol?: boolean hideApproximateSymbol?: boolean
showTVLLabel?: boolean
}): ReactElement { }): ReactElement {
const { prices } = usePrices() const { prices } = usePrices()
const { currency, locale } = useUserPreferences() const { currency, locale } = useUserPreferences()
@ -27,6 +29,7 @@ export default function Conversion({
const styleClasses = cx({ const styleClasses = cx({
conversion: true, conversion: true,
removeTvlPadding: showTVLLabel,
[className]: className [className]: className
}) })
@ -61,6 +64,7 @@ export default function Conversion({
className={styleClasses} className={styleClasses}
title="Approximation based on current OCEAN spot price on Coingecko" title="Approximation based on current OCEAN spot price on Coingecko"
> >
{showTVLLabel && 'TVL'}
{!hideApproximateSymbol && '≈ '} {!hideApproximateSymbol && '≈ '}
<strong dangerouslySetInnerHTML={{ __html: priceConverted }} />{' '} <strong dangerouslySetInnerHTML={{ __html: priceConverted }} />{' '}
{!isFiat && currency} {!isFiat && currency}

View File

@ -11,7 +11,8 @@ export default function TokenList({
dtSymbol, dtSymbol,
poolShares, poolShares,
conversion, conversion,
highlight highlight,
showTVLLabel
}: { }: {
title: string | ReactNode title: string | ReactNode
children: ReactNode children: ReactNode
@ -21,6 +22,7 @@ export default function TokenList({
poolShares: string poolShares: string
conversion: number conversion: number
highlight?: boolean highlight?: boolean
showTVLLabel?: boolean
}): ReactElement { }): ReactElement {
return ( return (
<div className={`${styles.tokenlist} ${highlight ? styles.highlight : ''}`}> <div className={`${styles.tokenlist} ${highlight ? styles.highlight : ''}`}>
@ -33,6 +35,7 @@ export default function TokenList({
<Conversion <Conversion
price={`${conversion}`} price={`${conversion}`}
className={styles.totalLiquidity} className={styles.totalLiquidity}
showTVLLabel={showTVLLabel}
/> />
)} )}
</div> </div>

View File

@ -288,7 +288,7 @@ export default function Pool(): ReactElement {
</TokenList> </TokenList>
<TokenList <TokenList
title="Pool Creator Liquidity" title="Pool Creator Statistics"
ocean={`${creatorLiquidity?.ocean}`} ocean={`${creatorLiquidity?.ocean}`}
dt={`${creatorLiquidity?.datatoken}`} dt={`${creatorLiquidity?.datatoken}`}
dtSymbol={dtSymbol} dtSymbol={dtSymbol}
@ -318,6 +318,7 @@ export default function Pool(): ReactElement {
dtSymbol={dtSymbol} dtSymbol={dtSymbol}
poolShares={totalPoolTokens} poolShares={totalPoolTokens}
conversion={totalLiquidityInOcean} conversion={totalLiquidityInOcean}
showTVLLabel
> >
<Token symbol="% swap fee" balance={swapFee} noIcon /> <Token symbol="% swap fee" balance={swapFee} noIcon />
</TokenList> </TokenList>

View File

@ -24,11 +24,9 @@ async function getQueryHighest(
chainIds: number[] chainIds: number[]
): Promise<[SearchQuery, string]> { ): Promise<[SearchQuery, string]> {
const dids = await getHighestLiquidityDIDs(chainIds) const dids = await getHighestLiquidityDIDs(chainIds)
// TODO: this query needs to adapt to chainIds
const queryHighest = { const queryHighest = {
page: 1, page: 1,
offset: 9, offset: dids.length,
query: { query: {
query_string: { query_string: {
query: `(${dids}) AND (${transformChainIdsListToQuery( query: `(${dids}) AND (${transformChainIdsListToQuery(
@ -43,7 +41,6 @@ async function getQueryHighest(
} }
function getQueryLatest(chainIds: number[]): SearchQuery { function getQueryLatest(chainIds: number[]): SearchQuery {
// TODO: this query needs to adapt to chainIds
return { return {
page: 1, page: 1,
offset: 9, offset: 9,
@ -89,12 +86,9 @@ function SectionQueryResult({
try { try {
setLoading(true) setLoading(true)
const result = await queryMetadata(query, source.token) const result = await queryMetadata(query, source.token)
if (queryData && result.totalResults > 0 && result.totalResults <= 15) { if (queryData && result.totalResults > 0) {
const searchDIDs = queryData.split(' ') const searchDIDs = queryData.split(' ')
const sortedAssets = sortElements(result.results, searchDIDs) const sortedAssets = sortElements(result.results, searchDIDs)
// We take more assets than we need from the subgraph (to make sure
// all the 9 assets with highest liquidity we need are in OceanDB)
// so we need to get rid of the surplus
const overflow = sortedAssets.length - 9 const overflow = sortedAssets.length - 9
sortedAssets.splice(sortedAssets.length - overflow, overflow) sortedAssets.splice(sortedAssets.length - overflow, overflow)
result.results = sortedAssets result.results = sortedAssets

View File

@ -16,6 +16,10 @@ import {
AssetsFreePrice_dispensers as AssetFreePriceDispenser AssetsFreePrice_dispensers as AssetFreePriceDispenser
} from '../@types/apollo/AssetsFreePrice' } from '../@types/apollo/AssetsFreePrice'
import { AssetPreviousOrder } from '../@types/apollo/AssetPreviousOrder' import { AssetPreviousOrder } from '../@types/apollo/AssetPreviousOrder'
import {
HighestLiquidityAssets_pools as HighestLiquidityAssetsPools,
HighestLiquidityAssets as HighestLiquidityGraphAssets
} from '../@types/apollo/HighestLiquidityAssets'
export interface PriceList { export interface PriceList {
[key: string]: string [key: string]: string
@ -122,16 +126,17 @@ const PreviousOrderQuery = gql`
} }
` `
const HighestLiquidityAssets = gql` const HighestLiquidityAssets = gql`
query HighestLiquidiyAssets { query HighestLiquidityAssets {
pools( pools(
where: { datatokenReserve_gte: 1 } where: { datatokenReserve_gte: 1 }
orderBy: valueLocked orderBy: oceanReserve
orderDirection: desc orderDirection: desc
first: 15 first: 15
) { ) {
id id
datatokenAddress datatokenAddress
valueLocked valueLocked
oceanReserve
} }
} }
` `
@ -426,6 +431,7 @@ export async function getHighestLiquidityDIDs(
chainIds: number[] chainIds: number[]
): Promise<string> { ): Promise<string> {
const didList: string[] = [] const didList: string[] = []
let highestLiquidiyAssets: HighestLiquidityAssetsPools[] = []
for (const chain of chainIds) { for (const chain of chainIds) {
const queryContext: OperationContext = { const queryContext: OperationContext = {
url: `${getSubgrahUri( url: `${getSubgrahUri(
@ -433,19 +439,21 @@ export async function getHighestLiquidityDIDs(
)}/subgraphs/name/oceanprotocol/ocean-subgraph`, )}/subgraphs/name/oceanprotocol/ocean-subgraph`,
requestPolicy: 'network-only' requestPolicy: 'network-only'
} }
const fetchedPools = await fetchData( const fetchedPools: OperationResult<HighestLiquidityGraphAssets, any> =
HighestLiquidityAssets, await fetchData(HighestLiquidityAssets, null, queryContext)
null, highestLiquidiyAssets = highestLiquidiyAssets.concat(
queryContext fetchedPools.data.pools
) )
if (fetchedPools.data?.pools?.length === 0) return null }
for (let i = 0; i < fetchedPools.data.pools.length; i++) { highestLiquidiyAssets
if (!fetchedPools.data.pools[i].datatokenAddress) continue .sort((a, b) => a.oceanReserve - b.oceanReserve)
const did = web3.utils .reverse()
.toChecksumAddress(fetchedPools.data.pools[i].datatokenAddress) for (let i = 0; i < highestLiquidiyAssets.length; i++) {
.replace('0x', 'did:op:') if (!highestLiquidiyAssets[i].datatokenAddress) continue
didList.push(did) const did = web3.utils
} .toChecksumAddress(highestLiquidiyAssets[i].datatokenAddress)
.replace('0x', 'did:op:')
didList.push(did)
} }
const searchDids = JSON.stringify(didList) const searchDids = JSON.stringify(didList)
.replace(/,/g, ' ') .replace(/,/g, ' ')