Skip to content

Commit

Permalink
feat: ethereum-steth-v2 cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyWh1te committed Jan 26, 2024
1 parent 28db487 commit cfac870
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions ethereum-steth-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
"stake": "forta-agent stake",
"test": "jest",
"generate-types": "typechain --target=ethers-v5 --out-dir=./src/generated ./src/abi/*",
"eslint:lint": "eslint ./src",
"eslint:format": "eslint ./src --fix",
"prettier:check": "prettier --check .",
"prettier:format": "prettier --write .",
"eslint:lint": "eslint ./src ./tests",
"eslint:format": "eslint ./src ./tests --fix",
"prettier:check": "prettier --check ./src ./tests",
"prettier:format": "prettier --write ./src ./tests",
"lint": "yarn run prettier:check && yarn run eslint:lint",
"format": "yarn run eslint:format && yarn run prettier:format",
"postinstall": "yarn generate-types"
Expand Down
3 changes: 0 additions & 3 deletions ethereum-steth-v2/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export const handleBlock = (): HandleBlock => {

const [bufferedEthFindings, withdrawalsFindings, gateSealFindings, vaultFindings] = await Promise.all([
app.StethOperationSrv.handleBlock(blockEvent),
app.StethOperationSrv.handleInvariants(blockEvent.blockNumber),
app.WithdrawalsSrv.handleBlock(blockEvent),
app.GateSealSrv.handleBlock(blockEvent),
app.VaultSrv.handleBlock(blockEvent),
Expand All @@ -146,7 +145,6 @@ export const handleBlock = (): HandleBlock => {
let isHandleTransactionRunning: boolean = false
export const handleTransaction = (): HandleTransaction => {
return async function (txEvent: TransactionEvent): Promise<Finding[]> {
const startTime = new Date().getTime()
if (isHandleTransactionRunning) {
return []
}
Expand All @@ -161,7 +159,6 @@ export const handleTransaction = (): HandleTransaction => {

out.push(...stethOperationFindings, ...withdrawalsFindings, ...gateSealFindings, ...vaultFindings)

console.log(elapsedTime('handleTransaction', startTime) + '\n')
isHandleTransactionRunning = false
return out
}
Expand Down
2 changes: 1 addition & 1 deletion ethereum-steth-v2/src/clients/eth_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { retryAsync } from 'ts-retry'
import { BigNumber as EtherBigNumber } from '@ethersproject/bignumber/lib/bignumber'
import BigNumber from 'bignumber.js'
import { ETH_DECIMALS } from '../utils/constants'
import { StakingLimitInfo } from '../entity/stakingLimitInfo'
import { StakingLimitInfo } from '../entity/staking_limit_info'
import {
GateSeal as GateSealContract,
Lido as LidoContract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import BigNumber from 'bignumber.js'
import { Finding, FindingSeverity, FindingType, LogDescription } from 'forta-agent'
import * as Winston from 'winston'
import { TypedEvent } from '../../generated/common'
import { StakingLimitInfo } from '../../entity/stakingLimitInfo'
import { StakingLimitInfo } from '../../entity/staking_limit_info'
import {
getFilteredBurnerEventsMock,
getFilteredDepositSecurityEventsMock,
Expand Down Expand Up @@ -1012,7 +1012,7 @@ describe('StethOperationSrv', () => {
})
})

describe('handleInvariants', () => {
describe('handleShareRateChange', () => {
test(`ethProviderErr`, async () => {
const want = new Error(`getShareRateErr`)
ethProviderMock.getShareRate.mockResolvedValue(E.left(want))
Expand All @@ -1039,12 +1039,12 @@ describe('StethOperationSrv', () => {
amount: new BigNumber('1.15490045560519776042410219381324898101464198621e+27'),
})

const result = await srv.handleInvariants(currentBlock)
const result = await srv.handleShareRateChange(currentBlock)

const expectedShareRateErrFinding = Finding.fromObject({
alertId: 'LIDO-AGENT-ERROR',
description: `Could not call "ethProvider.getShareRate". Cause getShareRateErr`,
name: 'Error in StethOperationSrv.handleInvariants:136',
name: 'Error in StethOperationSrv.handleShareRateChange:136',
severity: FindingSeverity.Low,
type: FindingType.Degraded,
})
Expand Down Expand Up @@ -1085,7 +1085,7 @@ describe('StethOperationSrv', () => {
amount: cachedShareRate,
})

const result = await srv.handleInvariants(currentBlock)
const result = await srv.handleShareRateChange(currentBlock)

const expectedShareRateErrFinding = Finding.fromObject({
alertId: 'LIDO-INVARIANT-ERROR',
Expand Down Expand Up @@ -1133,7 +1133,7 @@ Diff: 1.5490045560519778e+26`,
amount: cachedShareRate,
})

const result = await srv.handleInvariants(currentBlock)
const result = await srv.handleShareRateChange(currentBlock)

const expectedShareRateErrFinding = Finding.fromObject({
alertId: 'LIDO-INVARIANT-ERROR',
Expand Down Expand Up @@ -1179,7 +1179,7 @@ Diff: -1.5490045560519778e+26`,
amount: cachedShareRate,
})

const result = await srv.handleInvariants(currentBlock)
const result = await srv.handleShareRateChange(currentBlock)
expect(result.length).toEqual(0)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class StethOperationSrv {
this.handleBufferedEth(blockEvent.block.number, blockEvent.block.timestamp),
this.handleDepositExecutorBalance(blockEvent.block.number, blockEvent.block.timestamp),
this.handleStakingLimit(blockEvent.block.number, blockEvent.block.timestamp),
this.handleShareRateChange(blockEvent.block.number),
])

findings.push(...bufferedEthFindings, ...depositorBalanceFindings, ...stakingLimitFindings)
Expand All @@ -128,15 +129,15 @@ export class StethOperationSrv {
return findings
}

public async handleInvariants(blockNumber: number): Promise<Finding[]> {
public async handleShareRateChange(blockNumber: number): Promise<Finding[]> {
const start = new Date().getTime()
const findings: Finding[] = []

if (this.cache.getShareRate().blockNumber !== 0) {
const shareRate = await this.ethProvider.getShareRate(blockNumber)
if (E.isLeft(shareRate)) {
const f: Finding = Finding.fromObject({
name: `Error in ${StethOperationSrv.name}.${this.handleInvariants.name}:136`,
name: `Error in ${StethOperationSrv.name}.${this.handleShareRateChange.name}:136`,
description: `Could not call "ethProvider.getShareRate". Cause ${shareRate.left.message}`,
alertId: 'LIDO-AGENT-ERROR',
severity: FindingSeverity.Low,
Expand Down Expand Up @@ -172,7 +173,7 @@ export class StethOperationSrv {
}
}

this.logger.info(elapsedTime(StethOperationSrv.name + '.' + this.handleInvariants.name, start))
this.logger.info(elapsedTime(StethOperationSrv.name + '.' + this.handleShareRateChange.name, start))

return findings
}
Expand Down
2 changes: 1 addition & 1 deletion ethereum-steth-v2/tests/e2e/agent-steth-ops.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe('agent-steth-ops e2e tests', () => {
new BigNumber('1.15469003182482499409518734333781126194978625178e+27'),
)

const findings = await app.StethOperationSrv.handleInvariants(19069340)
const findings = await app.StethOperationSrv.handleShareRateChange(19069340)
expect(findings.length).toEqual(0)
},
TEST_TIMEOUT,
Expand Down
2 changes: 1 addition & 1 deletion ethereum-steth-v2/tests/e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Block as EtherBlock } from '@ethersproject/abstract-provider'
import { Block, BlockEvent, ethers, EventType, Log, LogDescription, Network, Trace } from 'forta-agent'
import { Block, BlockEvent, EventType, Network, Trace } from 'forta-agent'
import { formatAddress, isZeroAddress } from 'forta-agent/dist/cli/utils'
import { TransactionEvent } from 'forta-agent/dist/sdk/transaction.event'
import { getContractAddress } from 'ethers/lib/utils'
Expand Down

0 comments on commit cfac870

Please sign in to comment.