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

migrate Pool index query

This commit is contained in:
Matthias Kretschmann 2022-01-13 19:08:34 +00:00
parent 76bb997fe1
commit c5583c691c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 38 additions and 33 deletions

View File

@ -28,21 +28,28 @@ Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
const poolLiquidityQuery = gql` const poolLiquidityQuery = gql`
query PoolLiquidity($id: ID!, $shareId: ID) { query PoolLiquidity($id: ID!, $shareId: ID) {
pool(id: $id) { pool(id: $id, subgraphError: deny) {
id id
totalShares totalShares
swapFee poolFee
opfFee
marketFee
spotPrice spotPrice
tokens { baseToken {
address address
symbol symbol
isDatatoken
balance
denormWeight
} }
baseTokenWeight
baseTokenLiquidity
datatoken {
address
symbol
}
datatokenWeight
datatokenLiquidity
shares(where: { id: $shareId }) { shares(where: { id: $shareId }) {
id id
balance shares
} }
} }
} }
@ -54,7 +61,7 @@ const userPoolShareQuery = gql`
id id
shares(where: { id: $shareId }) { shares(where: { id: $shareId }) {
id id
balance shares
} }
} }
} }
@ -147,52 +154,43 @@ export default function Pool(): ReactElement {
useEffect(() => { useEffect(() => {
async function init() { async function init() {
if (!dataLiquidity || !dataLiquidity.pool) { if (!dataLiquidity?.pool) {
await getPoolLiquidity() await getPoolLiquidity()
return return
} }
// Set symbols // Set symbols
dataLiquidity.pool.tokens.forEach((token) => { setOceanSymbol(dataLiquidity.pool.baseToken.symbol)
token.isDatatoken setDtSymbol(dataLiquidity.pool.datatoken.symbol)
? setDtSymbol(token.symbol)
: setOceanSymbol(token.symbol)
})
// Total pool shares // Total pool shares
const totalPoolTokens = dataLiquidity.pool.totalShares const totalPoolTokens = dataLiquidity.pool.totalShares
setTotalPoolTokens(totalPoolTokens) setTotalPoolTokens(totalPoolTokens)
// Get swap fee // Get poolFee
// swapFee is tricky: to get 0.1% you need to convert from 0.001 // poolFee is tricky: to get 0.1% you need to convert from 0.001
const swapFee = isValidNumber(dataLiquidity.pool.swapFee) const swapFee = isValidNumber(dataLiquidity.pool.poolFee)
? new Decimal(dataLiquidity.pool.swapFee).mul(100).toString() ? new Decimal(dataLiquidity.pool.poolFee).mul(100).toString()
: '0' : '0'
setSwapFee(swapFee) setSwapFee(swapFee)
// Get weights // Get weights
const weightDt = dataLiquidity.pool.tokens.filter( const weightDt = dataLiquidity.pool.datatokenWeight
(token: any) =>
token.address === ddo.services[0].datatokenAddress.toLowerCase()
)[0].denormWeight
const weightDtDecimal = isValidNumber(weightDt) const weightDtDecimal = isValidNumber(weightDt)
? new Decimal(weightDt).mul(10).toString() ? new Decimal(weightDt).mul(10).toString()
: '0' : '0'
setWeightDt(weightDtDecimal) setWeightDt(weightDtDecimal)
const weightOceanDecimal = isValidNumber(weightDt) const weightOceanDecimal = isValidNumber(weightDt)
? new Decimal(100).minus(new Decimal(weightDt).mul(10)).toString() ? new Decimal(100).minus(new Decimal(weightDt).mul(10)).toString()
: '0' : '0'
setWeightOcean(weightOceanDecimal) setWeightOcean(weightOceanDecimal)
// //
// Get everything the creator put into the pool // Get everything the creator put into the pool
// //
const creatorPoolTokens = dataLiquidity.pool.shares[0].balance const creatorPoolTokens = dataLiquidity.pool.shares[0].shares
setCreatorPoolTokens(creatorPoolTokens) setCreatorPoolTokens(creatorPoolTokens)
const creatorOceanBalance = const creatorOceanBalance =
@ -250,7 +248,7 @@ export default function Pool(): ReactElement {
refetchLiquidity() refetchLiquidity()
} }
init() init()
}, [dataLiquidity, ddo, price.datatoken, price.ocean, price?.value]) }, [dataLiquidity, ddo, price])
useEffect(() => { useEffect(() => {
setIsRemoveDisabled(isInPurgatory && owner === accountId) setIsRemoveDisabled(isInPurgatory && owner === accountId)
@ -258,6 +256,7 @@ export default function Pool(): ReactElement {
useEffect(() => { useEffect(() => {
if (!dataLiquidity) return if (!dataLiquidity) return
const poolShare = const poolShare =
isValidNumber(poolTokens) && isValidNumber(poolTokens) &&
isValidNumber(totalPoolTokens) && isValidNumber(totalPoolTokens) &&
@ -294,10 +293,11 @@ export default function Pool(): ReactElement {
: new Decimal(0) : new Decimal(0)
setTotalLiquidityInOcean(totalLiquidityInOcean) setTotalLiquidityInOcean(totalLiquidityInOcean)
}, [userLiquidity, price, poolTokens, totalPoolTokens]) }, [dataLiquidity, userLiquidity, price, poolTokens, totalPoolTokens])
useEffect(() => { useEffect(() => {
if (!accountId || !price) return if (!accountId || !price) return
async function init() { async function init() {
try { try {
// //

View File

@ -131,8 +131,13 @@ export default function MarketStats(): ReactElement {
const response = await fetchData(getGlobalStatsValues, null, context) const response = await fetchData(getGlobalStatsValues, null, context)
if (!response) continue if (!response) continue
const { totalValueLocked, totalOceanLiquidity, finalizedPoolCount } = const {
response?.data?.globalStats[0] poolCount,
nftCount,
datatokenCount,
orderCount,
totalLiquidity
} = response?.data?.globalStats[0]
await setTotalValueLocked((prevState) => ({ await setTotalValueLocked((prevState) => ({
...prevState, ...prevState,
@ -144,12 +149,12 @@ export default function MarketStats(): ReactElement {
})) }))
await setPoolCount((prevState) => ({ await setPoolCount((prevState) => ({
...prevState, ...prevState,
[chainId]: finalizedPoolCount [chainId]: poolCount
})) }))
newTotalValueLockedSum += parseInt(totalValueLocked) newTotalValueLockedSum += parseInt(totalValueLocked)
newTotalOceanLiquiditySum += parseInt(totalOceanLiquidity) newTotalOceanLiquiditySum += parseInt(totalOceanLiquidity)
newPoolCountSum += parseInt(finalizedPoolCount) newPoolCountSum += parseInt(poolCount)
} catch (error) { } catch (error) {
LoggerInstance.error('Error fetchData: ', error.message) LoggerInstance.error('Error fetchData: ', error.message)
} }