-
Couldn't load subscription status.
- Fork 29
NuCypher tvl #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
NuCypher tvl #86
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { | |
| useKeepAssetPoolContract, | ||
| useTStakingContract, | ||
| useKeepTokenStakingContract, | ||
| useContract, | ||
| } from "../web3/hooks" | ||
| import { useETHData } from "./useETHData" | ||
| import { useToken } from "./useToken" | ||
|
|
@@ -20,6 +21,8 @@ interface TVLRawData { | |
| keepCoveragePoolTVL: string | ||
| keepStakingTVL: string | ||
| tStakingTVL: string | ||
| stakedNU: string | ||
| ethInNuNetwork: string | ||
| // TODO: add PRE and NU TVL | ||
| } | ||
|
|
||
|
|
@@ -38,8 +41,29 @@ const initialState = { | |
| keepCoveragePoolTVL: "0", | ||
| keepStakingTVL: "0", | ||
| tStakingTVL: "0", | ||
| stakedNU: "0", | ||
| ethInNuNetwork: "0", | ||
| } | ||
|
|
||
| // TODO: Get contract abi from the package and figure out how to use these | ||
| // contracts on ropste and local network. This only works on mainnet. | ||
| const ESCROW_ABI = [ | ||
| { | ||
| inputs: [], | ||
| name: "currentPeriodSupply", | ||
| outputs: [{ internalType: "uint128", name: "", type: "uint128" }], | ||
| stateMutability: "view", | ||
| type: "function", | ||
| }, | ||
| ] | ||
|
|
||
| const ESCROW_ADDRESS = "0xbbD3C0C794F40c4f993B03F65343aCC6fcfCb2e2" | ||
| const useNuStakingEscrowContract = () => { | ||
| return useContract(ESCROW_ADDRESS, ESCROW_ABI) | ||
| } | ||
|
|
||
| const WORK_LOCK_ADDRESS = "0xe9778E69a961e64d3cdBB34CF6778281d34667c2" | ||
|
|
||
| export const useFetchTvl = (): [TVLData, () => Promise<TVLRawData>] => { | ||
| const [rawData, setRawData] = useState<TVLRawData>(initialState) | ||
| const { | ||
|
|
@@ -48,12 +72,16 @@ export const useFetchTvl = (): [TVLData, () => Promise<TVLRawData>] => { | |
| keepCoveragePoolTVL, | ||
| keepStakingTVL, | ||
| tStakingTVL, | ||
| stakedNU, | ||
| ethInNuNetwork, | ||
| } = rawData | ||
|
|
||
| const eth = useETHData() | ||
| const keep = useToken(Token.Keep) | ||
| const tbtc = useToken(Token.TBTC) | ||
| const t = useToken(Token.T) | ||
| const nu = useToken(Token.Nu) | ||
| const nuStakingEscrow = useNuStakingEscrowContract() | ||
| const keepBonding = useKeepBondingContract() | ||
| const multicall = useMulticallContract() | ||
| const keepAssetPool = useKeepAssetPoolContract() | ||
|
|
@@ -81,6 +109,24 @@ export const useFetchTvl = (): [TVLData, () => Promise<TVLRawData>] => { | |
| method: "balanceOf", | ||
| args: [tTokenStaking?.address], | ||
| }, | ||
| { | ||
| contract: nu.contract!, | ||
| method: "totalSupply", | ||
| }, | ||
| { | ||
| contract: nuStakingEscrow!, | ||
| method: "currentPeriodSupply", | ||
| }, | ||
| { | ||
| contract: nu.contract!, | ||
| method: "balanceOf", | ||
| args: [nuStakingEscrow?.address], | ||
| }, | ||
| { | ||
| contract: multicall!, | ||
| method: "getEthBalance", | ||
| args: [WORK_LOCK_ADDRESS], | ||
| }, | ||
| ]) | ||
|
|
||
| const fetchTVLData = useCallback(async () => { | ||
|
|
@@ -93,14 +139,28 @@ export const useFetchTvl = (): [TVLData, () => Promise<TVLRawData>] => { | |
| coveragePoolTvl, | ||
| keepStaking, | ||
| tStaking, | ||
| nuTotalSupply, | ||
| nuCurrenctPeriodSupply, | ||
| nuInEscrow, | ||
| ethInNuNetwork, | ||
| ] = chainData.map((amount: string) => formatUnits(amount.toString())) | ||
|
|
||
| const stakedNU = FixedNumber.fromString(nuInEscrow) | ||
| .subUnsafe( | ||
| FixedNumber.fromString(nuTotalSupply).subUnsafe( | ||
| FixedNumber.fromString(nuCurrenctPeriodSupply) | ||
|
||
| ) | ||
| ) | ||
| .toString() | ||
|
|
||
| const data: TVLRawData = { | ||
| ecdsaTVL: ethInKeepBonding, | ||
| tbtcTVL: tbtcTokenTotalSupply, | ||
| keepCoveragePoolTVL: coveragePoolTvl, | ||
| keepStakingTVL: keepStaking, | ||
| tStakingTVL: tStaking, | ||
| stakedNU, | ||
| ethInNuNetwork, | ||
| } | ||
| setRawData(data) | ||
|
|
||
|
|
@@ -121,17 +181,23 @@ export const useFetchTvl = (): [TVLData, () => Promise<TVLRawData>] => { | |
|
|
||
| const tStaking = toUsdBalance(tStakingTVL, t.usdConversion) | ||
|
|
||
| const stakedNuInUSD = toUsdBalance(stakedNU, nu.usdConversion) | ||
| const ethInNu = toUsdBalance(ethInNuNetwork, eth.usdPrice) | ||
| const totalNu = stakedNuInUSD.addUnsafe(ethInNu) | ||
|
|
||
| return { | ||
| ecdsa: ecdsa.toString(), | ||
| tbtc: tbtcUSD.toString(), | ||
| keepCoveragePool: keepCoveragePool.toString(), | ||
| keepStaking: keepStaking.toString(), | ||
| tStaking: tStaking.toString(), | ||
| nu: totalNu.toString(), | ||
| total: ecdsa | ||
| .addUnsafe(tbtcUSD) | ||
| .addUnsafe(keepCoveragePool) | ||
| .addUnsafe(keepStaking) | ||
| .addUnsafe(tStaking) | ||
| .addUnsafe(totalNu) | ||
| .toString(), | ||
| } as TVLData | ||
| }, [ | ||
|
|
@@ -144,6 +210,9 @@ export const useFetchTvl = (): [TVLData, () => Promise<TVLRawData>] => { | |
| keep.usdConversion, | ||
| tbtc.usdConversion, | ||
| t.usdConversion, | ||
| stakedNU, | ||
| ethInNuNetwork, | ||
| nu.usdConversion, | ||
| ]) | ||
|
|
||
| return [data, fetchTVLData] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify why we're tracking here the NU balance of staking escrow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I implemented based on the https://github.com/nucypher/nucypher-monitor/blob/main/monitor/dashboard.py#L146-L163. Any tips on how to calculate NU TVL correctly would be appreciated 🙂