diff --git a/subgraphs/rocket-pool/abis/RocketVault.json b/subgraphs/rocket-pool/abis/RocketVault.json new file mode 100644 index 0000000000..a060392212 --- /dev/null +++ b/subgraphs/rocket-pool/abis/RocketVault.json @@ -0,0 +1,318 @@ +[ + { + "inputs": [ + { + "internalType": "contract RocketStorageInterface", + "name": "_rocketStorageAddress", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "string", + "name": "by", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "EtherDeposited", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "string", + "name": "by", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "EtherWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "by", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "TokenBurned", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "by", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "TokenDeposited", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "by", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "to", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "TokenTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "by", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "TokenWithdrawn", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_networkContractName", + "type": "string" + } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_networkContractName", + "type": "string" + }, + { + "internalType": "contract IERC20", + "name": "_tokenAddress", + "type": "address" + } + ], + "name": "balanceOfToken", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract ERC20Burnable", + "name": "_tokenAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "burnToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "depositEther", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_networkContractName", + "type": "string" + }, + { + "internalType": "contract IERC20", + "name": "_tokenContract", + "type": "address" + }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "depositToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_networkContractName", + "type": "string" + }, + { + "internalType": "contract IERC20", + "name": "_tokenAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "transferToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "withdrawEther", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_withdrawalAddress", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "_tokenAddress", + "type": "address" + }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "withdrawToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/subgraphs/rocket-pool/package-lock.json b/subgraphs/rocket-pool/package-lock.json index c0f6afeb83..f099717f45 100644 --- a/subgraphs/rocket-pool/package-lock.json +++ b/subgraphs/rocket-pool/package-lock.json @@ -1,5 +1,5 @@ { - "name": "rocket-pool-2", + "name": "rocket-pool", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/subgraphs/rocket-pool/protocols/rocket-pool/config/templates/rocket-pool.template.yaml b/subgraphs/rocket-pool/protocols/rocket-pool/config/templates/rocket-pool.template.yaml index 6a89b88d1e..446d3a20f1 100644 --- a/subgraphs/rocket-pool/protocols/rocket-pool/config/templates/rocket-pool.template.yaml +++ b/subgraphs/rocket-pool/protocols/rocket-pool/config/templates/rocket-pool.template.yaml @@ -148,6 +148,10 @@ templates: file: ./abis/RocketNetworkPrices.json - name: RocketStorage file: ./abis/RocketStorage.json + - name: rocketVault + file: ./abis/RocketVault.json + - name: rocketNodeStaking + file: ./abis/RocketNodeStaking.json ########################################### ############## Price Oracle ############### ########################################### @@ -302,8 +306,41 @@ templates: file: ./abis/RocketTokenRETH.json - name: RocketStorage file: ./abis/RocketStorage.json + ########################################### + ############## Price Oracle ############### + ########################################### + # ERC20 - name: _ERC20 file: ./abis/Prices/ERC20.json + # Curve Contracts + - name: CurveRegistry + file: ./abis/Prices/Curve/Registry.json + - name: CurvePoolRegistry + file: ./abis/Prices/Curve/PoolRegistry.json + - name: CalculationsCurve + file: ./abis/Prices/Calculations/Curve.json + # YearnLens Contracts + - name: YearnLensContract + file: ./abis/Prices/YearnLens.json + # ChainLink Contracts + - name: ChainLinkContract + file: ./abis/Prices/ChainLink.json + # Uniswap Contracts + - name: UniswapRouter + file: ./abis/Prices/Uniswap/Router.json + - name: UniswapFactory + file: ./abis/Prices/Uniswap/Factory.json + - name: UniswapPair + file: ./abis/Prices/Uniswap/Pair.json + # SushiSwap Contracts + - name: SushiSwapRouter + file: ./abis/Prices/SushiSwap/Router.json + - name: SushiSwapFactory + file: ./abis/Prices/SushiSwap/Factory.json + - name: SushiSwapPair + file: ./abis/Prices/SushiSwap/Pair.json + - name: CalculationsSushiSwap + file: ./abis/Prices/Calculations/SushiSwap.json eventHandlers: - event: RPLTokensClaimed(indexed address,indexed address,uint256,uint256) handler: handleRPLTokensClaimed diff --git a/subgraphs/rocket-pool/src/constants/contractConstants.ts b/subgraphs/rocket-pool/src/constants/contractConstants.ts index 9955dd4ace..eee8699e3a 100644 --- a/subgraphs/rocket-pool/src/constants/contractConstants.ts +++ b/subgraphs/rocket-pool/src/constants/contractConstants.ts @@ -5,6 +5,7 @@ export const ZERO_ADDRESS_STRING = "0x0000000000000000000000000000000000000000"; export const ZERO_ADDRESS = Address.fromString(ZERO_ADDRESS_STRING); export namespace RocketContractNames { + export const ROCKET_VAULT = "rocketVault"; export const ROCKET_TOKEN_RETH = "rocketTokenRETH"; export const ROCKET_NETWORK_BALANCES = "rocketNetworkBalances"; export const ROCKET_NETWORK_PRICES = "rocketNetworkPrices"; @@ -12,7 +13,7 @@ export namespace RocketContractNames { export const ROCKET_NODE_STAKING = "rocketNodeStaking"; export const ROCKET_REWARDS_POOL = "rocketRewardsPool"; export const ROCKET_MINIPOOL_MANAGER = "rocketMinipoolManager"; - export const ROCKET_MINIPOOL_QUEUE = "rocketMinipoolqueue"; + export const ROCKET_MINIPOOL_QUEUE = "rocketMinipoolQueue"; export const ROCKET_MINIPOOL_DELEGATE = "rocketMinipoolDelegate"; export const ROCKET_DAO_NODE_TRUSTED_ACTIONS = "rocketDAONodeTrustedActions"; export const ROCKET_DEPOSIT_POOL = "rocketDepositPool"; @@ -25,10 +26,19 @@ export namespace RocketContractNames { export const ROCKET_DAO_SETTINGS_MINIPOOL = "rocketDAOProtocolSettingsMinipool"; export const ROCKET_DAO_SETTINGS_NODE = "rocketDAOProtocolSettingsNode"; + export const ROCKET_AUCTION_MANAGER = "rocketAuctionManager"; } // https://docs.rocketpool.net/developers/usage/contracts/contracts.html#interacting-with-rocket-pool export const KeyToContractName = new TypedMap(); +KeyToContractName.set( + crypto.keccak256( + ByteArray.fromUTF8( + "contract.address".concat(RocketContractNames.ROCKET_VAULT) + ) + ), + RocketContractNames.ROCKET_VAULT +); KeyToContractName.set( crypto.keccak256( ByteArray.fromUTF8( @@ -93,6 +103,14 @@ KeyToContractName.set( ), RocketContractNames.ROCKET_MINIPOOL_QUEUE ); +KeyToContractName.set( + crypto.keccak256( + ByteArray.fromUTF8( + "contract.address".concat(RocketContractNames.ROCKET_MINIPOOL_DELEGATE) + ) + ), + RocketContractNames.ROCKET_MINIPOOL_DELEGATE +); KeyToContractName.set( crypto.keccak256( ByteArray.fromUTF8( @@ -177,3 +195,11 @@ KeyToContractName.set( ), RocketContractNames.ROCKET_DAO_SETTINGS_NODE ); +KeyToContractName.set( + crypto.keccak256( + ByteArray.fromUTF8( + "contract.address".concat(RocketContractNames.ROCKET_AUCTION_MANAGER) + ) + ), + RocketContractNames.ROCKET_AUCTION_MANAGER +); diff --git a/subgraphs/rocket-pool/src/mappings/rocketNetworkBalancesMapping.ts b/subgraphs/rocket-pool/src/mappings/rocketNetworkBalancesMapping.ts index bbd2941146..a459753583 100644 --- a/subgraphs/rocket-pool/src/mappings/rocketNetworkBalancesMapping.ts +++ b/subgraphs/rocket-pool/src/mappings/rocketNetworkBalancesMapping.ts @@ -1,6 +1,8 @@ import { BalancesUpdated } from "../../generated/templates/rocketNetworkBalances/rocketNetworkBalances"; import { rocketTokenRETH } from "../../generated/templates/rocketNetworkBalances/rocketTokenRETH"; import { rocketDepositPool } from "../../generated/templates/rocketNetworkBalances/rocketDepositPool"; +import { rocketVault } from "../../generated/templates/rocketNetworkBalances/rocketVault"; +import { rocketNodeStaking } from "../../generated/templates/rocketNetworkBalances/rocketNodeStaking"; import { Staker, NetworkStakerBalanceCheckpoint, @@ -14,7 +16,7 @@ import { ZERO_ADDRESS_STRING, RocketContractNames, } from "../constants/contractConstants"; -import { Address, BigInt, ethereum, log } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; import { getOrCreateProtocol } from "../entities/protocol"; import { getOrCreatePool } from "../entities/pool"; import { updateUsageMetrics } from "../updaters/usageMetrics"; @@ -31,6 +33,7 @@ import { BIGINT_SIXTEEN, BIGINT_THIRTYTWO, BIGINT_ZERO, + RPL_ADDRESS, } from "../utils/constants"; import { getRocketContract } from "../entities/rocketContracts"; @@ -174,31 +177,59 @@ export function handleBalancesUpdated(event: BalancesUpdated): void { const withdrawableMinipools = balanceCheckpoint!.withdrawableMinipools.times(BIGINT_THIRTYTWO); - log.error( - "[master TVL calculation raw inputs] queuedMinipools: {}, stakingMinipools: {}, stakingUnbondedMinipools: {}, withdrawableMinipools: {} ", - [ - balanceCheckpoint!.queuedMinipools.toString(), - balanceCheckpoint!.stakingMinipools.toString(), - balanceCheckpoint!.stakingUnbondedMinipools.toString(), - balanceCheckpoint!.withdrawableMinipools.toString(), - ] + // TVL Methodology: https://github.com/DefiLlama/DefiLlama-Adapters/blob/main/projects/rocketpool/index.js#L90 + + const rocketVaultContractEntity = getRocketContract( + RocketContractNames.ROCKET_VAULT + ); + const rocketVaultContract = rocketVault.bind( + Address.fromBytes(rocketVaultContractEntity.latestAddress) ); - log.error( - "[master TVL calculation] queuedMinipools: {}, stakingMinipools: {}, stakingUnbondedMinipools: {}, withdrawableMinipools: {} ", - [ - queuedMinipools.toString(), - stakingMinipools.toString(), - stakingUnbondedMinipools.toString(), - withdrawableMinipools.toString(), - ] + const rocketDepositPoolBalance = rocketVaultContract.balanceOf( + RocketContractNames.ROCKET_DEPOSIT_POOL + ); + const rocketTokenRETHBalance = rocketVaultContract.balanceOf( + RocketContractNames.ROCKET_TOKEN_RETH ); const ethTVL = queuedMinipools .plus(stakingMinipools) - .plus(stakingMinipools) - .plus(stakingUnbondedMinipools) - .plus(withdrawableMinipools); - updateProtocolAndPoolTvl(event.block.number, event.block.timestamp, ethTVL); + .plus(withdrawableMinipools) + .plus(rocketDepositPoolBalance) + .plus(rocketTokenRETHBalance); + + const rocketNodeStakingContractEntity = getRocketContract( + RocketContractNames.ROCKET_NODE_STAKING + ); + const rocketNodeStakingContract = rocketNodeStaking.bind( + Address.fromBytes(rocketNodeStakingContractEntity.latestAddress) + ); + const totalRPLStakeCall = rocketNodeStakingContract.try_getTotalRPLStake(); + let totalRPLStake = BIGINT_ZERO; + if (!totalRPLStakeCall.reverted) { + totalRPLStake = totalRPLStakeCall.value; + } + + const rocketDAONodeTrustedActions_rplBalance = + rocketVaultContract.balanceOfToken( + RocketContractNames.ROCKET_DAO_NODE_TRUSTED_ACTIONS, + Address.fromString(RPL_ADDRESS) + ); + const rocketAuctionManager_rplBalance = rocketVaultContract.balanceOfToken( + RocketContractNames.ROCKET_AUCTION_MANAGER, + Address.fromString(RPL_ADDRESS) + ); + + const rplTVL = totalRPLStake + .plus(rocketDAONodeTrustedActions_rplBalance) + .plus(rocketAuctionManager_rplBalance); + + updateProtocolAndPoolTvl( + event.block.number, + event.block.timestamp, + rplTVL, + ethTVL + ); } /** diff --git a/subgraphs/rocket-pool/src/mappings/rocketNetworkPricesMapping.ts b/subgraphs/rocket-pool/src/mappings/rocketNetworkPricesMapping.ts index f17069b0a6..5585571f0e 100644 --- a/subgraphs/rocket-pool/src/mappings/rocketNetworkPricesMapping.ts +++ b/subgraphs/rocket-pool/src/mappings/rocketNetworkPricesMapping.ts @@ -22,6 +22,7 @@ import { ONE_ETHER_IN_WEI } from "../constants/generalConstants"; import { updateUsageMetrics } from "../updaters/usageMetrics"; import { updateSnapshotsTvl } from "../updaters/financialMetrics"; import { getRocketContract } from "../entities/rocketContracts"; +import { BIGINT_TWO } from "../utils/constants"; /** * When enough ODAO members submitted their votes and a consensus threshold is reached, a new RPL price is comitted to the smart contracts. @@ -309,8 +310,9 @@ function getEffectiveMinipoolRPLBounds( ) ); - halfDepositAmount = - rocketDAOProtocolSettingsMinipoolContract.getHalfDepositNodeAmount(); + halfDepositAmount = rocketDAOProtocolSettingsMinipoolContract + .getLaunchBalance() + .div(BIGINT_TWO); // Get the DAO Protocol settings node contract instance. const rocketDAOProtocolSettingsNodeContractEntity = getRocketContract( diff --git a/subgraphs/rocket-pool/src/mappings/rocketNodeStakingMapping.ts b/subgraphs/rocket-pool/src/mappings/rocketNodeStakingMapping.ts index 846af87478..2ecd0d4d58 100644 --- a/subgraphs/rocket-pool/src/mappings/rocketNodeStakingMapping.ts +++ b/subgraphs/rocket-pool/src/mappings/rocketNodeStakingMapping.ts @@ -18,7 +18,6 @@ import { ethereum } from "@graphprotocol/graph-ts"; import { generalUtilities } from "../checkpoints/generalUtilities"; import { rocketPoolEntityFactory } from "../entityFactory"; import { updateUsageMetrics } from "../updaters/usageMetrics"; -import { updateProtocolAndPoolRewardsTvl } from "../updaters/financialMetrics"; import { getRocketContract } from "../entities/rocketContracts"; /** @@ -35,20 +34,6 @@ export function handleRPLStaked(event: RPLStaked): void { event.params.amount ); updateUsageMetrics(event.block, event.params.from); - const rocketNodeStakingContractEntity = getRocketContract( - RocketContractNames.ROCKET_NODE_STAKING - ); - const rocketNodeStakingContract = rocketNodeStaking.bind( - Address.fromBytes(rocketNodeStakingContractEntity.latestAddress) - ); - const totalStake = rocketNodeStakingContract.try_getTotalEffectiveRPLStake(); - if (!totalStake.reverted) { - updateProtocolAndPoolRewardsTvl( - event.block.number, - event.block.timestamp, - totalStake.value - ); - } } /** diff --git a/subgraphs/rocket-pool/src/prices/index.ts b/subgraphs/rocket-pool/src/prices/index.ts index e0734aa764..2c37f3fb72 100644 --- a/subgraphs/rocket-pool/src/prices/index.ts +++ b/subgraphs/rocket-pool/src/prices/index.ts @@ -71,14 +71,19 @@ export function getUsdPricePerToken(tokenAddr: Address): CustomPriceType { return new CustomPriceType(); } - const tokenPrice: BigDecimal = utils + const tokenPriceInEth: BigDecimal = utils .readValue( rplPriceContract.try_getRPLPrice(), constants.BIGINT_ZERO ) .toBigDecimal(); + const ethPrice = getUsdPricePerToken(Address.fromString(ETH_ADDRESS)); + + const tokenPrice = tokenPriceInEth + .times(ethPrice.usdPrice) + .div(ethPrice.decimalsBaseTen); - return CustomPriceType.initialize(tokenPrice, constants.SIXTEEN_DECIMALS); + return CustomPriceType.initialize(tokenPrice, constants.EIGHTEEN_DECIMALS); } const network = dataSource.network(); diff --git a/subgraphs/rocket-pool/src/updaters/financialMetrics.ts b/subgraphs/rocket-pool/src/updaters/financialMetrics.ts index 8773d4d914..c54cf83364 100644 --- a/subgraphs/rocket-pool/src/updaters/financialMetrics.ts +++ b/subgraphs/rocket-pool/src/updaters/financialMetrics.ts @@ -1,10 +1,4 @@ -import { - Address, - BigInt, - BigDecimal, - ethereum, - log, -} from "@graphprotocol/graph-ts"; +import { Address, BigInt, BigDecimal, ethereum } from "@graphprotocol/graph-ts"; import { bigIntToBigDecimal } from "../utils/numbers"; import { getOrCreateProtocol } from "../entities/protocol"; import { getOrCreatePool } from "../entities/pool"; @@ -25,62 +19,18 @@ import { const PROTOCOL_ID = RETH_ADDRESS; -export function updateProtocolAndPoolRewardsTvl( - blockNumber: BigInt, - blockTimestamp: BigInt, - rewardAmount: BigInt -): void { - const pool = getOrCreatePool(blockNumber, blockTimestamp); - const protocol = getOrCreateProtocol(); - - const inputTokenBalances: BigInt[] = []; - inputTokenBalances.push(rewardAmount); - inputTokenBalances.push(pool.inputTokenBalances[1]); - - pool.inputTokenBalances = inputTokenBalances; - - // inputToken is ETH, price with ETH - - const rplPriceUSD = getOrCreateToken( - Address.fromString(RPL_ADDRESS), - blockNumber - ).lastPriceUSD!; - const ethPriceUSD = getOrCreateToken( - Address.fromString(ETH_ADDRESS), - blockNumber - ).lastPriceUSD!; - - const ethTVLUSD = bigIntToBigDecimal(inputTokenBalances[1]).times( - ethPriceUSD - ); - const rplTVLUSD = bigIntToBigDecimal(inputTokenBalances[0]).times( - rplPriceUSD - ); - - pool.inputTokenBalancesUSD = [rplTVLUSD, ethTVLUSD]; - - const totalValueLockedUSD = ethTVLUSD.plus(rplTVLUSD); - pool.totalValueLockedUSD = totalValueLockedUSD; - pool.save(); - - // Protocol - protocol.totalValueLockedUSD = pool.totalValueLockedUSD; - protocol.save(); -} - export function updateProtocolAndPoolTvl( blockNumber: BigInt, blockTimestamp: BigInt, - amount: BigInt + rplTVL: BigInt, + ethTVL: BigInt ): void { const pool = getOrCreatePool(blockNumber, blockTimestamp); const protocol = getOrCreateProtocol(); - log.error("[updateProtocolAndPooLTvl] amount: {}", [amount.toString()]); - const inputTokenBalances: BigInt[] = []; - inputTokenBalances.push(pool.inputTokenBalances[0]); - inputTokenBalances.push(amount); + inputTokenBalances.push(rplTVL); + inputTokenBalances.push(ethTVL); pool.inputTokenBalances = inputTokenBalances;