1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00

output total pool liquidity

* convert everything in the pool to OCEAN, then convert to user currency
This commit is contained in:
Matthias Kretschmann 2020-10-08 17:56:26 +02:00
parent 069ca2b6b8
commit ed02d66609
Signed by: m
GPG Key ID: 606EEEF3C479A91F
7 changed files with 38 additions and 14 deletions

View File

@ -68,9 +68,9 @@ export default function Conversion({
return ( return (
<span <span
className={styleClasses} className={styleClasses}
title="Approximation based on current spot price on Coingecko" title="Approximation based on current OCEAN spot price on Coingecko"
> >
{priceConverted} {currency} <strong>{priceConverted}</strong> {currency}
</span> </span>
) )
} }

View File

@ -4,3 +4,7 @@
.title { .title {
composes: title from './index.module.css'; composes: title from './index.module.css';
} }
.totalLiquidity {
composes: totalLiquidity from './index.module.css';
}

View File

@ -21,7 +21,7 @@ export default function PoolStatistics({
const { debug } = useUserPreferences() const { debug } = useUserPreferences()
const totalLiquidityInOcean = const totalLiquidityInOcean =
Number(totalBalance.ocean) + Number(totalBalance.datatoken) * Number(price) totalBalance.ocean + totalBalance.datatoken * Number(price)
return ( return (
<div className={styles.statistics}> <div className={styles.statistics}>
@ -29,8 +29,11 @@ export default function PoolStatistics({
<Token symbol="OCEAN" balance={`${totalBalance.ocean}`} /> <Token symbol="OCEAN" balance={`${totalBalance.ocean}`} />
<Token symbol={dtSymbol} balance={`${totalBalance.datatoken}`} /> <Token symbol={dtSymbol} balance={`${totalBalance.datatoken}`} />
{debug === true && <Token symbol="BPT" balance={totalPoolTokens} />} {debug === true && <Token symbol="BPT" balance={totalPoolTokens} />}
<Conversion
price={`${totalLiquidityInOcean}`}
className={styles.totalLiquidity}
/>
<Token symbol="% swap fee" balance={swapFee} /> <Token symbol="% swap fee" balance={swapFee} />
<Conversion price={`${totalLiquidityInOcean}`} />
</div> </div>
) )
} }

View File

@ -32,3 +32,16 @@
font-size: var(--font-size-base); font-size: var(--font-size-base);
margin-bottom: calc(var(--spacer) / 1.5); margin-bottom: calc(var(--spacer) / 1.5);
} }
.totalLiquidity {
composes: token from './Token.module.css';
font-weight: var(--font-weight-base) !important;
font-size: var(--font-size-small);
padding-left: var(--font-size-base);
}
.totalLiquidity strong {
font-size: var(--font-size-base);
color: var(--brand-grey-dark);
line-height: 1;
}

View File

@ -32,7 +32,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
const [poolTokens, setPoolTokens] = useState<string>() const [poolTokens, setPoolTokens] = useState<string>()
const [totalPoolTokens, setTotalPoolTokens] = useState<string>() const [totalPoolTokens, setTotalPoolTokens] = useState<string>()
const [dtSymbol, setDtSymbol] = useState<string>() const [dtSymbol, setDtSymbol] = useState<string>()
const [userLiquidity, setUserBalance] = useState<Balance>() const [userLiquidity, setUserLiquidity] = useState<Balance>()
const [swapFee, setSwapFee] = useState<string>() const [swapFee, setSwapFee] = useState<string>()
const [showAdd, setShowAdd] = useState(false) const [showAdd, setShowAdd] = useState(false)
@ -40,8 +40,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
const hasAddedLiquidity = const hasAddedLiquidity =
userLiquidity && userLiquidity && (userLiquidity.ocean > 0 || userLiquidity.datatoken > 0)
(Number(userLiquidity.ocean) > 0 || Number(userLiquidity.datatoken) > 0)
const poolShare = const poolShare =
price?.ocean && price?.ocean &&
@ -49,6 +48,9 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
userLiquidity && userLiquidity &&
((Number(poolTokens) / Number(totalPoolTokens)) * 100).toFixed(2) ((Number(poolTokens) / Number(totalPoolTokens)) * 100).toFixed(2)
const totalUserLiquidityInOcean =
userLiquidity?.ocean + userLiquidity?.datatoken * price?.value
useEffect(() => { useEffect(() => {
if (!ocean || !accountId || !price || !price.value) return if (!ocean || !accountId || !price || !price.value) return
@ -79,18 +81,17 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
// calculate user's provided liquidity based on pool tokens // calculate user's provided liquidity based on pool tokens
const userOceanBalance = const userOceanBalance =
(Number(poolTokens) / Number(totalPoolTokens)) * Number(price.ocean) (Number(poolTokens) / Number(totalPoolTokens)) * price.ocean
const userDtBalance = const userDtBalance =
(Number(poolTokens) / Number(totalPoolTokens)) * (Number(poolTokens) / Number(totalPoolTokens)) * price.datatoken
Number(price.datatoken)
const userLiquidity = { const userLiquidity = {
ocean: userOceanBalance, ocean: userOceanBalance,
datatoken: userDtBalance datatoken: userDtBalance
} }
setUserBalance(userLiquidity) setUserLiquidity(userLiquidity)
// Get swap fee // Get swap fee
// swapFee is tricky: to get 0.1% you need to convert from 0.001 // swapFee is tricky: to get 0.1% you need to convert from 0.001
@ -155,6 +156,10 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
<Token symbol="OCEAN" balance={`${userLiquidity.ocean}`} /> <Token symbol="OCEAN" balance={`${userLiquidity.ocean}`} />
<Token symbol={dtSymbol} balance={`${userLiquidity.datatoken}`} /> <Token symbol={dtSymbol} balance={`${userLiquidity.datatoken}`} />
{debug === true && <Token symbol="BPT" balance={poolTokens} />} {debug === true && <Token symbol="BPT" balance={poolTokens} />}
<Conversion
price={`${totalUserLiquidityInOcean}`}
className={styles.totalLiquidity}
/>
<Token symbol="% of pool" balance={poolShare} /> <Token symbol="% of pool" balance={poolShare} />
</div> </div>

View File

@ -12,8 +12,7 @@
@media (min-width: 60rem) { @media (min-width: 60rem) {
.grid { .grid {
/* lazy golden ratio */ grid-template-columns: 1.5fr minmax(0, 1fr);
grid-template-columns: 1.618fr minmax(0, 1fr);
} }
.sticky { .sticky {

View File

@ -14,7 +14,7 @@ import { useOcean } from '@oceanprotocol/react'
const queryHighest = { const queryHighest = {
page: 1, page: 1,
offset: 3, offset: 3,
query: { 'price.ocean': [0, 99999] }, query: { 'price.type': ['pool'] },
sort: { 'price.value': 1 } sort: { 'price.value': 1 }
} }