Skip to content

Commit

Permalink
Update revenue logic and add EarlyAdopterPool
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh9200 committed May 29, 2024
1 parent 2c667bf commit 45ab336
Show file tree
Hide file tree
Showing 11 changed files with 1,886 additions and 55 deletions.
541 changes: 541 additions & 0 deletions subgraphs/etherfi/abis/EarlyAdopterPool.json

Large diffs are not rendered by default.

991 changes: 991 additions & 0 deletions subgraphs/etherfi/abis/EtherFiNode.json

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions subgraphs/etherfi/abis/EtherFiNodesManager.json
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,48 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_validatorId",
"type": "uint256"
},
{
"internalType": "address",
"name": "_address",
"type": "address"
}
],
"name": "registerEtherFiNode",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_validatorId",
"type": "uint256"
},
{
"internalType": "bool",
"name": "_enableRestaking",
"type": "bool"
}
],
"name": "registerEtherFiNode",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"network": "mainnet",

"EarlyAdopterPool": {
"address": "0x7623e9dc0da6ff821ddb9ebaba794054e078f8c4",
"startBlock": "16722425"
},
"LiquidityPool": {
"address": "0x308861a430be4cce5502d0a12724771fc6daf216",
"startBlock": "17664317"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,67 @@ graft:
block: {{ graftStartBlock }} # Block number
{{/graftEnabled}}
dataSources:
- kind: ethereum
network: {{ network }}
name: EarlyAdopterPool
source:
address: "{{ EarlyAdopterPool.address }}"
abi: EarlyAdopterPool
startBlock: {{ EarlyAdopterPool.startBlock }}
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- Pool
abis:
- name: EarlyAdopterPool
file: ./abis/EarlyAdopterPool.json
- name: ERC20
file: ./abis/ERC20.json

###########################################
############## Price Oracle ###############
###########################################
# ERC20
- name: _ERC20
file: ./abis/Prices/ERC20.json
# Curve Contracts
- name: CurvePool
file: ./abis/Prices/Curve/Pool.json
- name: CurveRegistry
file: ./abis/Prices/Curve/Registry.json
- name: CalculationsCurve
file: ./abis/Prices/Calculations/Curve.json
# YearnLens Contracts
- name: YearnLensContract
file: ./abis/Prices/YearnLens.json
# Aave Oracle Contract
- name: AaveOracleContract
file: ./abis/Prices/AaveOracle.json
# SushiSwap Contracts
- name: CalculationsSushiSwap
file: ./abis/Prices/Calculations/SushiSwap.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
eventHandlers:
- event: DepositEth(indexed address,uint256)
handler: handleDepositEth
- event: DepositERC20(indexed address,uint256)
handler: handleDepositERC20
- event: Withdrawn(indexed address)
handler: handleWithdrawn
- event: ERC20TVLUpdated(uint256,uint256,uint256,uint256,uint256,uint256)
handler: handleERC20TVLUpdated
file: ./src/mappings/earlyAdopterPoolMappings.ts
- kind: ethereum
network: {{ network }}
name: LiquidityPool
Expand Down Expand Up @@ -71,7 +132,7 @@ dataSources:
handler: handleWithdrawWithSource
file: ./src/mappings/liquidityPoolMappings.ts
- kind: ethereum
network: mainnet
network: {{ network }}
name: NodesManager
source:
address: "{{ NodesManager.address }}"
Expand Down Expand Up @@ -123,9 +184,70 @@ dataSources:
file: ./abis/Prices/Uniswap/Factory.json
- name: UniswapPair
file: ./abis/Prices/Uniswap/Pair.json
eventHandlers:
- event: PartialWithdrawal(indexed uint256,indexed address,uint256,uint256,uint256,uint256)
handler: handlePartialWithdrawal
- event: FullWithdrawal(indexed uint256,indexed address,uint256,uint256,uint256,uint256)
handler: handleFullWithdrawal
file: ./src/mappings/nodesManagerMappings.ts
callHandlers:
- function: registerValidator(uint256,bool,address)
handler: handleRegisterValidator
- function: registerEtherFiNode(uint256,address)
handler: handleRegisterEtherFiNode
- function: registerEtherFiNode(uint256,bool)
handler: handleRegisterEtherFiNodeWithOutput
file: ./src/mappings/nodesManagerMappings.ts

templates:
- kind: ethereum
network: {{ network }}
name: EtherFiNode
source:
abi: EtherFiNode
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- Pool
abis:
- name: EtherFiNode
file: ./abis/EtherFiNode.json
- name: NodesManager
file: ./abis/EtherFiNodesManager.json
- name: LiquidityPool
file: ./abis/LiquidityPool.json
- name: ERC20
file: ./abis/ERC20.json

###########################################
############## Price Oracle ###############
###########################################
# ERC20
- name: _ERC20
file: ./abis/Prices/ERC20.json
# Curve Contracts
- name: CurvePool
file: ./abis/Prices/Curve/Pool.json
- name: CurveRegistry
file: ./abis/Prices/Curve/Registry.json
- name: CalculationsCurve
file: ./abis/Prices/Calculations/Curve.json
# YearnLens Contracts
- name: YearnLensContract
file: ./abis/Prices/YearnLens.json
# Aave Oracle Contract
- name: AaveOracleContract
file: ./abis/Prices/AaveOracle.json
# SushiSwap Contracts
- name: CalculationsSushiSwap
file: ./abis/Prices/Calculations/SushiSwap.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
callHandlers:
- function: withdrawFunds(address,uint256,address,uint256,address,uint256,address,uint256)
handler: handleWithdrawFunds
file: ./src/mappings/etherFiNodeMappings.ts
5 changes: 5 additions & 0 deletions subgraphs/etherfi/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export namespace Protocol {
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
export const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
export const EETH_ADDRESS = "0x35fa164735182de50811e8e2e824cfb9b6118ac2";
export const RETH_ADDRESS = "0xae78736cd615f374d3085123a210448e74fc6393"; // rETH
export const WSTETH_ADDRESS = "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0"; // wstETH
export const SFRXETH_ADDRESS = "0xac3e018457b222d93114458476f3e3416abbe38f"; // sfrxETH
export const CBETH_ADDRESS = "0xbe9895146f7af43049ca1c1ae358b0541ea49704"; // cbETH

export const EETH_LIQUIDITY_POOL_ADDRESS =
"0x308861a430be4cce5502d0a12724771fc6daf216";

Expand Down
77 changes: 69 additions & 8 deletions subgraphs/etherfi/src/common/initializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Pricer, TokenInit, readValue } from "../common/utils";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { LiquidityPool } from "../../generated/LiquidityPool/LiquidityPool";

export function initializeSDK(event: ethereum.Event): SDK {
export function initializeSDKFromEvent(event: ethereum.Event): SDK {
const protocolConfig = new ProtocolConfig(
constants.Protocol.ID,
constants.Protocol.NAME,
Expand All @@ -28,17 +28,37 @@ export function initializeSDK(event: ethereum.Event): SDK {
return sdk;
}

export function getOrCreatePool(poolAddress: Address, sdk: SDK): Pool {
const pool = sdk.Pools.loadPool(poolAddress);

const inputToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.ETH_ADDRESS)
export function initializeSDKFromCall(call: ethereum.Call): SDK {
const protocolConfig = new ProtocolConfig(
constants.Protocol.ID,
constants.Protocol.NAME,
constants.Protocol.SLUG,
Versions
);
const outputToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.EETH_ADDRESS)
const tokenPricer = new Pricer();
const tokenInitializer = new TokenInit();

const sdk = SDK.initializeFromCall(
protocolConfig,
tokenPricer,
tokenInitializer,
call
);

return sdk;
}

export function getOrCreatePool(poolAddress: Address, sdk: SDK): Pool {
const pool = sdk.Pools.loadPool(poolAddress);

if (!pool.isInitialized) {
const inputToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.ETH_ADDRESS)
);
const outputToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.EETH_ADDRESS)
);

pool.initialize(
outputToken.name,
outputToken.symbol,
Expand All @@ -51,6 +71,47 @@ export function getOrCreatePool(poolAddress: Address, sdk: SDK): Pool {
return pool;
}

export function getOrCreateEarlyAdopterPool(
poolAddress: Address,
sdk: SDK
): Pool {
const pool = sdk.Pools.loadPool(poolAddress);

if (!pool.isInitialized) {
const rEthToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.RETH_ADDRESS)
);
const wstEthToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.WSTETH_ADDRESS)
);
const sfrxEthToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.SFRXETH_ADDRESS)
);
const cbEthToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.CBETH_ADDRESS)
);
const ethToken = sdk.Tokens.getOrCreateToken(
Address.fromString(constants.ETH_ADDRESS)
);

pool.initialize(
"EarlyAdopterPool",
"adopter-pool",
[
rEthToken.id,
wstEthToken.id,
sfrxEthToken.id,
cbEthToken.id,
ethToken.id,
],
null,
true
);
}

return pool;
}

export function updatePoolTVL(pool: Pool): void {
const poolContract = LiquidityPool.bind(Address.fromBytes(pool.getBytesID()));

Expand Down
55 changes: 55 additions & 0 deletions subgraphs/etherfi/src/mappings/earlyAdopterPoolMappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
updatePoolTVL,
initializeSDKFromEvent,
updatePoolOutputTokenSupply,
getOrCreateEarlyAdopterPool,
} from "../common/initializers";
import {
Withdrawn,
DepositEth,
DepositERC20,
ERC20TVLUpdated,
} from "../../generated/EarlyAdopterPool/EarlyAdopterPool";

export function handleERC20TVLUpdated(event: ERC20TVLUpdated): void {
const sdk = initializeSDKFromEvent(event);
const pool = getOrCreateEarlyAdopterPool(event.address, sdk);

pool.setInputTokenBalances(
[
event.params.rETHBal,
event.params.wstETHBal,
event.params.sfrxETHBal,
event.params.cbETHBal,
event.params.ETHBal,
],
true
);

updatePoolOutputTokenSupply(pool);
updatePoolTVL(pool);
}

export function handleDepositEth(event: DepositEth): void {
const sender = event.params.sender;
const sdk = initializeSDKFromEvent(event);

const account = sdk.Accounts.loadAccount(sender);
account.trackActivity();
}

export function handleDepositERC20(event: DepositERC20): void {
const sender = event.params.sender;
const sdk = initializeSDKFromEvent(event);

const account = sdk.Accounts.loadAccount(sender);
account.trackActivity();
}

export function handleWithdrawn(event: Withdrawn): void {
const sender = event.params.sender;
const sdk = initializeSDKFromEvent(event);

const account = sdk.Accounts.loadAccount(sender);
account.trackActivity();
}
Loading

0 comments on commit 45ab336

Please sign in to comment.