diff --git a/ethereum-steth-v2/package.json b/ethereum-steth-v2/package.json index 8b2746ec..3ea77c7a 100644 --- a/ethereum-steth-v2/package.json +++ b/ethereum-steth-v2/package.json @@ -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" diff --git a/ethereum-steth-v2/src/agent.ts b/ethereum-steth-v2/src/agent.ts index d76d22fe..94c79095 100644 --- a/ethereum-steth-v2/src/agent.ts +++ b/ethereum-steth-v2/src/agent.ts @@ -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), @@ -146,7 +145,6 @@ export const handleBlock = (): HandleBlock => { let isHandleTransactionRunning: boolean = false export const handleTransaction = (): HandleTransaction => { return async function (txEvent: TransactionEvent): Promise { - const startTime = new Date().getTime() if (isHandleTransactionRunning) { return [] } @@ -161,7 +159,6 @@ export const handleTransaction = (): HandleTransaction => { out.push(...stethOperationFindings, ...withdrawalsFindings, ...gateSealFindings, ...vaultFindings) - console.log(elapsedTime('handleTransaction', startTime) + '\n') isHandleTransactionRunning = false return out } diff --git a/ethereum-steth-v2/src/clients/eth_provider.ts b/ethereum-steth-v2/src/clients/eth_provider.ts index 8fd32253..036c3f82 100644 --- a/ethereum-steth-v2/src/clients/eth_provider.ts +++ b/ethereum-steth-v2/src/clients/eth_provider.ts @@ -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, diff --git a/ethereum-steth-v2/src/entity/stakingLimitInfo.ts b/ethereum-steth-v2/src/entity/staking_limit_info.ts similarity index 100% rename from ethereum-steth-v2/src/entity/stakingLimitInfo.ts rename to ethereum-steth-v2/src/entity/staking_limit_info.ts diff --git a/ethereum-steth-v2/src/services/steth_operation/StethOperation.spec.ts b/ethereum-steth-v2/src/services/steth_operation/StethOperation.spec.ts index d5100cb7..98d98eda 100644 --- a/ethereum-steth-v2/src/services/steth_operation/StethOperation.spec.ts +++ b/ethereum-steth-v2/src/services/steth_operation/StethOperation.spec.ts @@ -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, @@ -1012,7 +1012,7 @@ describe('StethOperationSrv', () => { }) }) - describe('handleInvariants', () => { + describe('handleShareRateChange', () => { test(`ethProviderErr`, async () => { const want = new Error(`getShareRateErr`) ethProviderMock.getShareRate.mockResolvedValue(E.left(want)) @@ -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, }) @@ -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', @@ -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', @@ -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) }) }) diff --git a/ethereum-steth-v2/src/services/steth_operation/StethOperation.srv.ts b/ethereum-steth-v2/src/services/steth_operation/StethOperation.srv.ts index 7f961153..fb874fd1 100644 --- a/ethereum-steth-v2/src/services/steth_operation/StethOperation.srv.ts +++ b/ethereum-steth-v2/src/services/steth_operation/StethOperation.srv.ts @@ -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) @@ -128,7 +129,7 @@ export class StethOperationSrv { return findings } - public async handleInvariants(blockNumber: number): Promise { + public async handleShareRateChange(blockNumber: number): Promise { const start = new Date().getTime() const findings: Finding[] = [] @@ -136,7 +137,7 @@ export class StethOperationSrv { 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, @@ -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 } diff --git a/ethereum-steth-v2/tests/e2e/agent-steth-ops.spec.ts b/ethereum-steth-v2/tests/e2e/agent-steth-ops.spec.ts index 4ac44dc9..a9e558d1 100644 --- a/ethereum-steth-v2/tests/e2e/agent-steth-ops.spec.ts +++ b/ethereum-steth-v2/tests/e2e/agent-steth-ops.spec.ts @@ -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, diff --git a/ethereum-steth-v2/tests/e2e/utils.ts b/ethereum-steth-v2/tests/e2e/utils.ts index af8cfc25..1fccfdb1 100644 --- a/ethereum-steth-v2/tests/e2e/utils.ts +++ b/ethereum-steth-v2/tests/e2e/utils.ts @@ -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'