Skip to content

Commit

Permalink
feat: steth-digest
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyWh1te committed Aug 15, 2024
1 parent cecf971 commit adf164b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,7 @@ describe('Steth.srv functional tests', () => {
},
}

const results = await stethOperationSrv.handleTransaction(transactionDto)

const expected = {
name: 'ℹ️ Lido: Token rebased',
description: 'reportTimestamp: 1706011211\n\nBlockNumber 19069339',
alertId: 'LIDO-TOKEN-REBASED',
severity: 1,
type: 4,
}

expect(results[0].getAlertid()).toEqual(expected.alertId)
expect(results[0].getDescription()).toEqual(expected.description)
expect(results[0].getName()).toEqual(expected.name)
expect(results[0].getSeverity()).toEqual(expected.severity)
expect(results[0].getType()).toEqual(expected.type)
await stethOperationSrv.handleTransaction(transactionDto)

expect(stethOperationSrv.getStorage().getShareRate().blockNumber).toEqual(19069339)
expect(stethOperationSrv.getStorage().getShareRate().amount).toEqual(new BigNumber('1.1546900318248249941'))
Expand Down
36 changes: 20 additions & 16 deletions ethereum-steth/src/services/steth_operation/StethOperation.srv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,28 +225,32 @@ export class StethOperationSrv {
const depositSecFindings = handleEventsOfNotice(txEvent, this.depositSecurityEvents)
const insuranceFundFindings = handleEventsOfNotice(txEvent, this.insuranceFundEvents)
const burnerFindings = handleEventsOfNotice(txEvent, this.burnerEvents)
out.push(...lidoFindings, ...depositSecFindings, ...insuranceFundFindings, ...burnerFindings)

for (const f of lidoFindings) {
if (f.getAlertid() === alertId_token_rebased) {
const shareRate = await this.stethClient.getShareRate(txEvent.block.number)
if (E.isLeft(shareRate)) {
const f: Finding = networkAlert(
shareRate.left,
`Error in ${StethOperationSrv.name}.${this.handleTransaction.name}:192`,
`Could not call stethClient.getShareRate`,
)
if (f.getAlertid() !== alertId_token_rebased) {
out.push(f)
continue
}

out.push(f)
} else {
this.cache.setShareRate({
amount: shareRate.right,
blockNumber: txEvent.block.number,
})
}
const shareRate = await this.stethClient.getShareRate(txEvent.block.number)
if (E.isLeft(shareRate)) {
const f: Finding = networkAlert(
shareRate.left,
`Error in ${StethOperationSrv.name}.${this.handleTransaction.name}:192`,
`Could not call stethClient.getShareRate`,
)

out.push(f)
} else {
this.cache.setShareRate({
amount: shareRate.right,
blockNumber: txEvent.block.number,
})
}
}

out.push(...depositSecFindings, ...insuranceFundFindings, ...burnerFindings)

return out
}

Expand Down
26 changes: 21 additions & 5 deletions ethereum-steth/src/services/withdrawals/Withdrawals.srv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Finding } from '../../generated/proto/alert_pb'
import { WithdrawalClaimedEvent } from '../../generated/typechain/WithdrawalQueueERC721'
import { ETH_DECIMALS } from '../../utils/constants'
import { dbAlert, networkAlert } from '../../utils/errors'
import { alertId_token_rebased, LIDO_TOKEN_REBASED_EVENT } from '../../utils/events/lido_events'
import {
LIDO_TOKEN_REBASED_EVENT,
WITHDRAWAL_QUEUE_WITHDRAWAL_CLAIMED_EVENT,
WITHDRAWAL_QUEUE_WITHDRAWAL_REQUESTED_EVENT,
WITHDRAWAL_QUEUE_WITHDRAWALS_FINALIZED_EVENT,
Expand Down Expand Up @@ -245,7 +245,7 @@ export class WithdrawalsSrv {

const withdrawalsEventsFindings = handleEventsOfNotice(txEvent, this.withdrawalsEvents)
const bunkerStatusFindings = this.handleBunkerStatus(txEvent)
this.handleLastTokenRebase(txEvent)
const rebasedFinding = await this.handleLastTokenRebase(txEvent)

const [finalizedFindings, withdrawalRequestFindings, withdrawalClaimedFindings] = await Promise.all([
this.handleWithdrawalFinalized(txEvent),
Expand All @@ -259,6 +259,7 @@ export class WithdrawalsSrv {
...withdrawalRequestFindings,
...withdrawalClaimedFindings,
...withdrawalsEventsFindings,
...rebasedFinding,
)

return out
Expand Down Expand Up @@ -557,7 +558,7 @@ export class WithdrawalsSrv {
this.cache.setBunkerModeEnabledSinceTimestamp(bunkerEnabled.args._sinceTimestamp)

const f: Finding = new Finding()
f.setName('🚨 Withdrawals: BUNKER MODE ON! 🚨')
f.setName('🚨🚨🚨 Withdrawals: BUNKER MODE ON! 🚨🚨🚨')
f.setDescription(
`Started from ${new Date(String(this.cache.getBunkerModeEnabledSinceTimestamp())).toUTCString()}`,
)
Expand Down Expand Up @@ -681,14 +682,29 @@ export class WithdrawalsSrv {
return out
}

public handleLastTokenRebase(txEvent: TransactionDto): void {
public async handleLastTokenRebase(txEvent: TransactionDto): Promise<Finding[]> {
const [rebaseEvent] = filterLog(txEvent.logs, LIDO_TOKEN_REBASED_EVENT, this.lidoStethAddress)
if (!rebaseEvent) {
return
return []
}

this.cache.setLastTokenRebaseTimestamp(rebaseEvent.args.reportTimestamp)
this.cache.setAmountOfRequestedStETHSinceLastTokenRebase(new BigNumber(0))

const f = new Finding()
f.setName(`ℹ️ Lido: Token rebased`)
f.setAlertid(alertId_token_rebased)
f.setSeverity(Finding.Severity.INFO)
f.setType(Finding.FindingType.INFORMATION)
f.setDescription(`reportTimestamp: ${rebaseEvent.args.reportTimestamp}`)
f.setProtocol('ethereum')

const state = await this.getStatisticString()
if (E.isRight(state)) {
f.setDescription(state.right)
}

return [f]
}

public async handleWithdrawalFinalized(txEvent: TransactionDto): Promise<Finding[]> {
Expand Down
2 changes: 2 additions & 0 deletions ethereum-steth/src/utils/events/lido_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Finding } from '../../generated/proto/alert_pb'
import { etherscanAddress } from '../string'

export const alertId_token_rebased = 'LIDO-TOKEN-REBASED'
export const LIDO_TOKEN_REBASED_EVENT =
'event TokenRebased(uint256 indexed reportTimestamp, uint256 timeElapsed, uint256 preTotalShares, uint256 preTotalEther, uint256 postTotalShares, uint256 postTotalEther, uint256 sharesMintedAsFees)'

export function getLidoEvents(LIDO_STETH_ADDRESS: string): EventOfNotice[] {
return [
Expand Down
3 changes: 0 additions & 3 deletions ethereum-steth/src/utils/events/withdrawals_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export const WITHDRAWALS_BUNKER_MODE_DISABLED_EVENT = 'event BunkerModeDisabled(
export const WITHDRAWAL_QUEUE_WITHDRAWAL_REQUESTED_EVENT =
'event WithdrawalRequested(uint256 indexed requestId, address indexed requestor, address indexed owner, uint256 amountOfStETH, uint256 amountOfShares)'

export const LIDO_TOKEN_REBASED_EVENT =
'event TokenRebased(uint256 indexed reportTimestamp, uint256 timeElapsed, uint256 preTotalShares, uint256 preTotalEther, uint256 postTotalShares, uint256 postTotalEther, uint256 sharesMintedAsFees)'

export const WITHDRAWAL_QUEUE_WITHDRAWALS_FINALIZED_EVENT =
'event WithdrawalsFinalized(uint256 indexed from, uint256 indexed to, uint256 amountOfETHLocked, uint256 sharesToBurn, uint256 timestamp)'

Expand Down

0 comments on commit adf164b

Please sign in to comment.