Skip to content

Commit

Permalink
Aggregate suckers balance
Browse files Browse the repository at this point in the history
  • Loading branch information
aeolianeth committed Jan 13, 2025
1 parent dec70c3 commit 6a21f12
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 39 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
"graphql": "^16.8.1",
"he": "^1.2.0",
"jsonwebtoken": "^9.0.0",
"juice-sdk-core": "^12.4.0-alpha",
"juice-sdk-react": "^12.4.1-alpha",
"juice-sdk-core": "^12.5.1-alpha",
"juice-sdk-react": "^12.5.0-alpha",
"juicebox-metadata-helper": "0.1.7",
"less": "4.1.2",
"lodash": "^4.17.21",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,122 @@
import { Tooltip } from 'antd'
import { NETWORKS } from 'constants/networks'
import {
JBChainId,
NativeTokenValue,
useJBRulesetMetadata,
useSuckersNativeTokenSurplus
useSuckersNativeTokenBalance,
useSuckersNativeTokenSurplus,
} from 'juice-sdk-react'

import { Tooltip } from 'antd'
import { NETWORKS } from 'constants/networks'
import { ChainLogo } from 'packages/v4/components/ChainLogo'
import { useV4BalanceOfNativeTerminal } from 'packages/v4/hooks/useV4BalanceOfNativeTerminal'
import { useMemo } from 'react'
import { useV4DistributableAmount } from './useV4DistributableAmount'

export const useV4TreasuryStats = () => {
const { data: rulesetMetadata } = useJBRulesetMetadata()
const { distributableAmount } = useV4DistributableAmount()

const { data: _treasuryBalance } = useV4BalanceOfNativeTerminal()
const { data: suckersBalance } = useSuckersNativeTokenBalance()
const totalBalance =
suckersBalance?.reduce((acc, curr) => {
return acc + curr.balance
}, 0n) ?? 0n

const surplusQuery = useSuckersNativeTokenSurplus();
const surplusQuery = useSuckersNativeTokenSurplus()

// NOTE: if loading state or conversion to USD necessary
// const { data: ethPrice, isLoading: isEthLoading } = useEtherPrice();
// const loading = isEthLoading || surplusQuery.isLoading;

const ethSurplusByChain = surplusQuery?.data
const ethSurplusByChain = surplusQuery?.data
const totalEthSurplus =
ethSurplusByChain?.reduce((acc, curr) => {
return acc + curr.surplus;
}, 0n) ?? 0n;
return acc + curr.surplus
}, 0n) ?? 0n

const treasuryBalance = <NativeTokenValue wei={_treasuryBalance ?? 0n} />
const treasuryBalance = useMemo(() => {
// NOTE: Don't think we need this since other chains payouts limits may be different?
// if (payoutLimit && payoutLimit.amount === MAX_PAYOUT_LIMIT)
// return t`No surplus`
return (
<Tooltip
title={
suckersBalance?.length && suckersBalance.length > 0 ? (
<div className="flex flex-col gap-2">
{suckersBalance?.map((balance, index) => (
<div
className="flex items-center justify-between gap-4"
key={suckersBalance[index].chainId}
>
<div
key={suckersBalance[index].chainId}
className="flex items-center gap-2"
>
<ChainLogo
chainId={suckersBalance[index].chainId as JBChainId}
/>
<span>{NETWORKS[balance.chainId].label}</span>
</div>
{/* (NOTE: Following comment copied from Revnet:
"TODO maybe show USD-converted value here instead?" */}
<span className="whitespace-nowrap font-medium">
<NativeTokenValue wei={balance.balance ?? 0n} />
</span>
</div>
))}
</div>
) : undefined
}
>
<span>
<NativeTokenValue wei={totalBalance} />
</span>
</Tooltip>
)
}, [totalBalance, suckersBalance])

const surplusElement = useMemo(() => {
// NOTE: Don't think we need this since other chains payouts limits may be different?
// if (payoutLimit && payoutLimit.amount === MAX_PAYOUT_LIMIT)
// return t`No surplus`
return (
<Tooltip
title={ethSurplusByChain?.length && ethSurplusByChain.length > 0 ?
<div className="flex flex-col gap-2">
{ethSurplusByChain?.map((surplus, index) => (
<div className="flex justify-between gap-4 items-center" key={ethSurplusByChain[index].chainId}>
<div key={ethSurplusByChain[index].chainId} className="flex items-center gap-2">
<ChainLogo chainId={ethSurplusByChain[index].chainId as JBChainId} />
<span>{NETWORKS[surplus.chainId].label}</span>
</div>
{/* (NOTE: Following comment copied from Revnet:
title={
ethSurplusByChain?.length && ethSurplusByChain.length > 0 ? (
<div className="flex flex-col gap-2">
{ethSurplusByChain?.map((surplus, index) => (
<div
className="flex items-center justify-between gap-4"
key={ethSurplusByChain[index].chainId}
>
<div
key={ethSurplusByChain[index].chainId}
className="flex items-center gap-2"
>
<ChainLogo
chainId={ethSurplusByChain[index].chainId as JBChainId}
/>
<span>{NETWORKS[surplus.chainId].label}</span>
</div>
{/* (NOTE: Following comment copied from Revnet:
"TODO maybe show USD-converted value here instead?" */}
<span className="font-medium whitespace-nowrap">
<NativeTokenValue wei={surplus.surplus ?? 0n} />
</span>
</div>
))}

</div>
: undefined}
<span className="whitespace-nowrap font-medium">
<NativeTokenValue wei={surplus.surplus ?? 0n} />
</span>
</div>
))}
</div>
) : undefined
}
>
<span><NativeTokenValue wei={totalEthSurplus ?? 0n} /></span>
<span>
<NativeTokenValue wei={totalEthSurplus} />
</span>
</Tooltip>
)
}, [totalEthSurplus, ethSurplusByChain])

const availableToPayout = <NativeTokenValue wei={distributableAmount.value} />

return {
treasuryBalance,
availableToPayout,
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12178,18 +12178,18 @@ jsx-ast-utils@^3.3.5:
object.assign "^4.1.4"
object.values "^1.1.6"

juice-sdk-core@^12.4.0-alpha:
version "12.4.0-alpha"
resolved "https://registry.yarnpkg.com/juice-sdk-core/-/juice-sdk-core-12.4.0-alpha.tgz#966283a87a0ba2fcfbf7499912e8fe3213557dbb"
integrity sha512-qL8YEoID45pm+levjtJ5jCThfkmqTvsNYKIpWr+z+Ij+lmWmRambVXvKp6SlYNqD7jp3F4s+uSmLDEZEeYaDpw==
juice-sdk-core@^12.5.1-alpha:
version "12.5.1-alpha"
resolved "https://registry.yarnpkg.com/juice-sdk-core/-/juice-sdk-core-12.5.1-alpha.tgz#66c2fccf059c8c6326943f5220afdb2ddaf1db46"
integrity sha512-K8/F8QlpMcALtWAA4QcHkoOJKeTFg/+kCKguI3H+VjTW5gKr8MHVx2uKJMELzyaDS8ti0SvwQLU32wPYA1rArg==
dependencies:
bs58 "^5.0.0"
fpnum "^1.0.0"

juice-sdk-react@^12.4.1-alpha:
version "12.4.1-alpha"
resolved "https://registry.yarnpkg.com/juice-sdk-react/-/juice-sdk-react-12.4.1-alpha.tgz#e63bafd1e21e0d30bf1e47f9f6a45b6f323747ff"
integrity sha512-9jqxaprt2+DQiz3drSEdidbdLS4C5DTyUHGqLsQEVbPSwH2PjO2WTr8HbVMtMcRdtdZrytDRCSkJdMOPtmg3BQ==
juice-sdk-react@^12.5.0-alpha:
version "12.5.0-alpha"
resolved "https://registry.yarnpkg.com/juice-sdk-react/-/juice-sdk-react-12.5.0-alpha.tgz#0841d0785e9365a8ff72462a75d7d0fc7edc9dee"
integrity sha512-PgpmpxbEjytXu79Uc9e48J2NBeO8UQy7DlJMSKO7njxv5kbN7Gf/YtrCZ5fRNNA9EWEkXeoqz3p0lI7HXZVIdw==

juice@^10.0.0:
version "10.0.0"
Expand Down

0 comments on commit 6a21f12

Please sign in to comment.