Skip to content
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

fix(#patch); eigenlayer; use strategyContract.totalShares for pool tvl #2426

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -9796,7 +9796,7 @@
"status": "prod",
"versions": {
"schema": "2.1.1",
"subgraph": "1.0.0",
"subgraph": "1.1.0",
"methodology": "1.0.0"
},
"files": {
Expand Down
1 change: 1 addition & 0 deletions subgraphs/eigenlayer/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ type Withdraw implements Event @entity @transaction {

" Block number of this event "
blockNumber: BigInt!
blockNumberCompleted: BigInt

" Timestamp of this event "
timestamp: BigInt!
Expand Down
1 change: 1 addition & 0 deletions subgraphs/eigenlayer/src/common/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export function updateWithdraw(
);
withdrawEvent.hashCompleted = event.transaction.hash;
withdrawEvent.completed = true;
withdrawEvent.blockNumberCompleted = event.block.number;
withdrawEvent.save();

const account = getOrCreateAccount(accountAddress);
Expand Down
9 changes: 2 additions & 7 deletions subgraphs/eigenlayer/src/common/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ export function updatePoolIsActive(
export function updateTVL(
poolAddress: Address,
tokenAddress: Address,
isDeposit: boolean,
amount: BigInt,
balance: BigInt,
event: ethereum.Event
): void {
const protocol = getOrCreateProtocol();
const pool = getPool(poolAddress);
const token = getOrCreateToken(tokenAddress, event);

if (isDeposit) {
pool.inputTokenBalances = [pool.inputTokenBalances[0].plus(amount)];
} else {
pool.inputTokenBalances = [pool.inputTokenBalances[0].minus(amount)];
}
pool.inputTokenBalances = [balance];
pool.inputTokenBalancesUSD = [
bigIntToBigDecimal(pool.inputTokenBalances[0]).times(token.lastPriceUSD!),
];
Expand Down
91 changes: 75 additions & 16 deletions subgraphs/eigenlayer/src/mappings/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
BIGINT_ZERO,
ETH_ADDRESS,
INT_FOUR,
INT_ONE,
INT_THREE,
INT_TWO,
INT_ZERO,
Expand Down Expand Up @@ -163,12 +164,18 @@ export function handleDeposit(event: Deposit): void {
const logTopicSignature = thisLog.topics.at(INT_ZERO);

if (logTopicSignature.equals(TRANSFER_SIGNATURE)) {
const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data);
if (!decoded) continue;

const logData = decoded.toTuple();
amount = logData[INT_ZERO].toBigInt();
break;
const logTopicTo = ethereum
.decode("address", thisLog.topics.at(INT_TWO))!
.toAddress();

if (logTopicTo.equals(Address.fromBytes(pool.id))) {
const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data);
if (!decoded) continue;

const logData = decoded.toTuple();
amount = logData[INT_ZERO].toBigInt();
break;
}
}
}

Expand All @@ -189,11 +196,34 @@ export function handleDeposit(event: Deposit): void {
depositID,
event
);

const strategyContract = Strategy.bind(Address.fromBytes(pool.id));
const totalSharesResult = strategyContract.try_totalShares();
if (totalSharesResult.reverted) {
log.error(
"[handleDeposit] strategyContract.try_totalShares() reverted for strategy: {}",
[Address.fromBytes(pool.id).toHexString()]
);
return;
}
const sharesToUnderlyingResult = strategyContract.try_sharesToUnderlying(
totalSharesResult.value
);
if (sharesToUnderlyingResult.reverted) {
log.error(
"[handleDeposit] strategyContract.try_sharesToUnderlying() reverted for strategy: {} and value: {}",
[
Address.fromBytes(pool.id).toHexString(),
totalSharesResult.value.toString(),
]
);
return;
}

updateTVL(
Address.fromBytes(pool.id),
Address.fromBytes(token.id),
true,
amount,
sharesToUnderlyingResult.value,
event
);
updateVolume(
Expand Down Expand Up @@ -323,12 +353,18 @@ export function handleWithdrawalCompleted(event: WithdrawalCompleted): void {
const logTopicSignature = thisLog.topics.at(INT_ZERO);

if (logTopicSignature.equals(TRANSFER_SIGNATURE)) {
const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data);
if (!decoded) continue;

const logData = decoded.toTuple();
amount = logData[INT_ZERO].toBigInt();
break;
const logTopicFrom = ethereum
.decode("address", thisLog.topics.at(INT_ONE))!
.toAddress();

if (logTopicFrom.equals(Address.fromBytes(poolID))) {
const decoded = ethereum.decode(TRANSFER_DATA_TYPE, thisLog.data);
if (!decoded) continue;

const logData = decoded.toTuple();
amount = logData[INT_ZERO].toBigInt();
break;
}
}
}

Expand All @@ -341,11 +377,34 @@ export function handleWithdrawalCompleted(event: WithdrawalCompleted): void {
withdrawID,
event
);

const strategyContract = Strategy.bind(Address.fromBytes(poolID));
dhruv-chauhan marked this conversation as resolved.
Show resolved Hide resolved
const totalSharesResult = strategyContract.try_totalShares();
if (totalSharesResult.reverted) {
log.error(
"[handleWithdrawalCompleted] strategyContract.try_totalShares() reverted for strategy: {}",
[Address.fromBytes(poolID).toHexString()]
);
return;
}
const sharesToUnderlyingResult = strategyContract.try_sharesToUnderlying(
totalSharesResult.value
);
if (sharesToUnderlyingResult.reverted) {
log.error(
"[handleWithdrawalCompleted] strategyContract.try_sharesToUnderlying() reverted for strategy: {} and value: {}",
[
Address.fromBytes(poolID).toHexString(),
totalSharesResult.value.toString(),
]
);
return;
}

updateTVL(
Address.fromBytes(poolID),
Address.fromBytes(tokenID),
false,
amount,
sharesToUnderlyingResult.value,
event
);
updateVolume(
Expand Down
Loading