Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh9200 committed Aug 12, 2024
1 parent 925999b commit 3637dcb
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 9 deletions.
31 changes: 31 additions & 0 deletions subgraphs/eigenpie/abis/EigenStaking.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,37 @@
"name": "AssetDeposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "depositor",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "asset",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "depositAmount",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "referral",
"type": "address"
}
],
"name": "AssetDeposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ dataSources:
eventHandlers:
- event: AssetDeposit(indexed address,indexed address,uint256,indexed address,uint256,bool)
handler: handleAssetDeposit
- event: AssetDeposit(indexed address,indexed address,uint256,indexed address)
handler: handleAssetDepositWithoutMintAmount
file: ./src/mappings/eigenStakingMappings.ts
1 change: 1 addition & 0 deletions subgraphs/eigenpie/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const EIGEN_CONFIG_ADDRESS =
"0x20b70e4a1883b81429533fed944d7957121c7cab";
export const EIGEN_STAKING_ADDRESS =
"0x24db6717db1c75b9db6ea47164d8730b63875db7";
export const EGETH_TOKEN_ADDRESS = "0xefefefefefefefefefefefefefefefefefefefef";

////////////////////////
///// Type Helpers /////
Expand Down
9 changes: 3 additions & 6 deletions subgraphs/eigenpie/src/common/initializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { MLRT } from "../../generated/EigenConfig/MLRT";
import { ProtocolConfig } from "../sdk/protocols/config";
import { ERC20 } from "../../generated/EigenConfig/ERC20";
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { EigenStaking } from "../../generated/EigenConfig/EigenStaking";

export function initializeSDKFromEvent(event: ethereum.Event): SDK {
const protocolConfig = new ProtocolConfig(
Expand Down Expand Up @@ -72,13 +71,11 @@ export function getOrCreatePool(poolAddress: Address, sdk: SDK): Pool {
return pool;
}

export function updatePoolTVL(pool: Pool, asset: Address): void {
const stakingContract = EigenStaking.bind(
Address.fromString(constants.EIGEN_STAKING_ADDRESS)
);
export function updatePoolTVL(pool: Pool): void {
const contract = MLRT.bind(Address.fromBytes(pool.getBytesID()));

const poolUnderlyingTVL = readValue<BigInt>(
stakingContract.try_getTotalAssetDeposits(asset),
contract.try_totalSupply(),
constants.BIGINT_ZERO
);

Expand Down
2 changes: 1 addition & 1 deletion subgraphs/eigenpie/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TokenInit implements TokenInitializer {
let default_symbol = "UNKNOWN";
let default_decimals = constants.INT_ZERO as i32;

if (address == Address.fromString(constants.ETH_ADDRESS)) {
if (address == Address.fromString(constants.EGETH_TOKEN_ADDRESS)) {
default_name = constants.ETH_NAME;
default_symbol = constants.ETH_SYMBOL;
default_decimals = constants.DEFAULT_DECIMALS as i32;
Expand Down
23 changes: 21 additions & 2 deletions subgraphs/eigenpie/src/mappings/eigenStakingMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import {
initializeSDKFromEvent,
updatePoolOutputTokenSupply,
} from "../common/initializers";
import {
AssetDeposit,
AssetDeposit1 as AssetDepositWithoutMintAmount,
} from "../../generated/EigenStaking/EigenStaking";
import { getReceiptByAsset } from "../common/utils";
import { AssetDeposit } from "../../generated/EigenStaking/EigenStaking";

export function handleAssetDeposit(event: AssetDeposit): void {
const assetAddress = event.params.asset;
Expand All @@ -14,8 +17,24 @@ export function handleAssetDeposit(event: AssetDeposit): void {
const sdk = initializeSDKFromEvent(event);
const pool = getOrCreatePool(receiptAddress, sdk);

updatePoolTVL(pool, assetAddress);
updatePoolOutputTokenSupply(pool);
updatePoolTVL(pool);

const account = sdk.Accounts.loadAccount(event.transaction.from);
account.trackActivity();
}

export function handleAssetDepositWithoutMintAmount(
event: AssetDepositWithoutMintAmount
): void {
const assetAddress = event.params.asset;
const receiptAddress = getReceiptByAsset(assetAddress);

const sdk = initializeSDKFromEvent(event);
const pool = getOrCreatePool(receiptAddress, sdk);

updatePoolOutputTokenSupply(pool);
updatePoolTVL(pool);

const account = sdk.Accounts.loadAccount(event.transaction.from);
account.trackActivity();
Expand Down
9 changes: 9 additions & 0 deletions subgraphs/eigenpie/src/prices/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ export const BIGDECIMAL_USD_PRICE = BigDecimal.fromString("1000000");
export const AAVE_ORACLE_DECIMALS = 8;
export const DEFAULT_USDC_DECIMALS = 6;
export const DEFAULT_DECIMALS = BigInt.fromI32(18);

export const WETH_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";

export const WETH_LIKE_TOKENS: Address[] = [
Address.fromString("0xefefefefefefefefefefefefefefefefefefefef"), // egETH
Address.fromString("0xf1c9acdc66974dfb6decb12aa385b9cd01190e38"), // osETH
Address.fromString("0xac3e018457b222d93114458476f3e3416abbe38f"), // sfrxETH
Address.fromString("0xa2e3356610840701bdf5611a53974510ae27e2e1"), // wBETH
];
3 changes: 3 additions & 0 deletions subgraphs/eigenpie/src/prices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export function getUsdPricePerToken(
return new CustomPriceType();
}

if (constants.WETH_LIKE_TOKENS.includes(tokenAddr))
tokenAddr = Address.fromString(constants.WETH_ADDRESS);

const config = utils.getConfig();
if (config.network() == "default") {
log.warning("Failed to fetch price: network {} not implemented", [
Expand Down

0 comments on commit 3637dcb

Please sign in to comment.