Skip to content

Commit

Permalink
Merge branch 'main' into feat/scroll-support
Browse files Browse the repository at this point in the history
  • Loading branch information
arwer13 committed May 22, 2024
2 parents 5b70777 + e1bfad1 commit fbea6bd
Show file tree
Hide file tree
Showing 56 changed files with 2,909 additions and 1,036 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-ethereum-steth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
uses: ./.github/workflows/_tests.yml
with:
path: ./ethereum-steth
secrets: inherit
secrets: inherit
2 changes: 2 additions & 0 deletions ethereum-steth/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generated
proto
2 changes: 2 additions & 0 deletions ethereum-steth/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generated
proto
6 changes: 2 additions & 4 deletions ethereum-steth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Build stage: compile Typescript to Javascript
FROM node:20.10.0-alpine3.18 AS base

RUN apk add --no-cache python3=3.11.6-r0 g++=12.2.1_git20220924-r10 make=4.4.1-r1 sqlite=3.41.2-r3
RUN apk add --no-cache python3=3.11.8-r0 g++=12.2.1_git20220924-r10 make=4.4.1-r1 sqlite=3.41.2-r3

FROM base as builder

WORKDIR /app

COPY . .
RUN yarn install --immutable && yarn run build
# Build app
RUN yarn run build

# Final stage: copy compiled Javascript from previous stage and install production dependencies
FROM base as production
Expand All @@ -23,4 +21,4 @@ COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./src
COPY version.json ./

CMD ["yarn", "run", "start:prod"]
CMD ["yarn", "run", "start:docker:prod"]
30 changes: 30 additions & 0 deletions ethereum-steth/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Makefile

.PHONY: gen_proto_prod
gen_proto_prod:
# generate js codes via grpc-tools
yarn grpc_tools_node_protoc \
--js_out=import_style=commonjs,binary:./dist/generated/proto \
--grpc_out=grpc_js:./dist/generated/proto \
--plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin \
-I ./src/brief/proto \
./src/brief/proto/*.proto

.PHONY: gen_js
gen_js:
# generate js codes via grpc-tools
yarn grpc_tools_node_protoc \
--js_out=import_style=commonjs,binary:./src/generated/proto \
--grpc_out=grpc_js:./src/generated/proto \
--plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin \
--proto_path=./src/brief/proto \
./src/brief/proto/*.proto

.PHONY: gen_ts
gen_ts:
# generate d.ts codes
yarn grpc_tools_node_protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=grpc_js:./src/generated/proto \
--proto_path=./src/brief/proto \
./src/brief/proto/*.proto
6 changes: 4 additions & 2 deletions ethereum-steth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ Edit `alerting-forta/<SUBMODULE>/forta.config.json` and set `jsonRpcUrl` to your

```
yarn install
yarn build
yarn start
```

Running in a live mode:
In separate console run

```
yarn start:dev
docker-compose up -d
```
33 changes: 14 additions & 19 deletions ethereum-steth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,37 @@
"scripts": {
"update-version": "node ../utils/write-version.js",
"move-migrations": "mkdir -p dist/db/migrations && cp src/db/migrations/* dist/db/migrations/",
"build": "tsc && yarn run copy-version && yarn run move-migrations",
"build": "tsc && yarn run copy-version && yarn run move-migrations && mkdir dist/generated/proto && make gen_proto_prod",
"copy-version": "cp version.json dist",
"start": "yarn run update-version && yarn run start:dev",
"start:dev": "nodemon --watch src --watch forta.config.json -e js,ts,json --exec \"yarn run build && yarn run copy-version && forta-agent run\"",
"start:prod": "forta-agent run --prod",
"tx": "yarn run build && forta-agent run --tx",
"block": "yarn run build && forta-agent run --block",
"range": "yarn run build && forta-agent run --range",
"alert": "yarn run build && forta-agent run --alert",
"sequence": "yarn run build && forta-agent run --sequence",
"file": "yarn run build && forta-agent run --file",
"publish": "yarn run update-version && forta-agent publish",
"info": "forta-agent info",
"logs": "forta-agent logs",
"start": "ts-node src/main.ts",
"start:prod": "node dist/main.js",
"start:docker:prod": "node src/main.js",
"push": "yarn run update-version && forta-agent push",
"disable": "forta-agent disable",
"enable": "forta-agent enable",
"keyfile": "forta-agent keyfile",
"stake": "forta-agent stake",
"test": "jest",
"generate-types": "typechain --target=ethers-v5 --out-dir=./src/generated ./src/abi/*",
"generate-types": "typechain --target=ethers-v5 --out-dir=./src/generated/typechain ./src/brief/abi/*",
"generate-proto": "make gen_ts && make gen_js",
"eslint:lint": "eslint ./src",
"eslint:format": "eslint ./src --fix",
"prettier:check": "prettier --check ./src",
"prettier:format": "prettier --write ./src README.md",
"lint": "yarn run prettier:check && yarn run eslint:lint",
"format": "yarn run eslint:format && yarn run prettier:format",
"postinstall": "yarn generate-types"
"postinstall": "yarn generate-types && yarn generate-proto"
},
"dependencies": {
"@ethersproject/abi": "^5.0.0",
"@ethersproject/providers": "^5.0.0",
"@grpc/grpc-js": "^1.10.2",
"@types/lodash": "^4.14.202",
"async-mutex": "^0.4.0",
"bignumber.js": "^9.1.2",
"ethers": "^5.5.1",
"express": "^4.19.2",
"forta-agent": "^0.1.48",
"fp-ts": "^2.16.1",
"knex": "^3.1.0",
"lodash": "^4.17.21",
"prom-client": "^15.1.2",
"sqlite": "3",
"ts-retry": "^4.2.4",
"winston": "^3.11.0"
Expand All @@ -67,6 +58,7 @@
"@jest/globals": "^29.7.0",
"@tsconfig/node20": "^20.1.2",
"@typechain/ethers-v5": "^11.1.2",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.11",
"@types/nodemon": "^1.19.0",
"@types/ws": "^8.5.10",
Expand All @@ -76,13 +68,16 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-prettier": "^5.0.1",
"grpc-tools": "^1.12.4",
"grpc_tools_node_protoc_ts": "^5.3.3",
"husky": "^8.0.3",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"postinstall": "^0.8.0",
"prettier": "^3.1.0",
"ts-generator": "^0.1.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.3.2"
},
Expand Down
72 changes: 35 additions & 37 deletions ethereum-steth/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StethOperationSrv } from './services/steth_operation/StethOperation.srv'
import { ethers, fetchJwt, Finding, getEthersProvider, verifyJwt } from 'forta-agent'
import { getEthersProvider } from 'forta-agent'
import { Address } from './utils/constants'
import { StethOperationCache } from './services/steth_operation/StethOperation.cache'
import { ETHProvider } from './clients/eth_provider'
Expand All @@ -9,7 +9,7 @@ import {
Lido__factory,
ValidatorsExitBusOracle__factory,
WithdrawalQueueERC721__factory,
} from './generated'
} from './generated/typechain'
import { getDepositSecurityEvents } from './utils/events/deposit_security_events'
import { getLidoEvents } from './utils/events/lido_events'
import { getInsuranceFundEvents } from './utils/events/insurance_fund_events'
Expand All @@ -22,49 +22,32 @@ import { DataRW } from './utils/mutex'
import { GateSealCache } from './services/gate-seal/GateSeal.cache'
import * as Winston from 'winston'
import { VaultSrv } from './services/vault/Vault.srv'
import * as E from 'fp-ts/Either'
import { Knex, knex } from 'knex'
import { WithdrawalsRepo } from './services/withdrawals/Withdrawals.repo'
import { BorderTime, HealthChecker, MaxNumberErrorsPerBorderTime } from './services/health-checker/health-checker.srv'
import promClient from 'prom-client'
import { Metrics } from './utils/metrics/metrics'
import { ethers } from 'ethers'
import { Finding } from './generated/proto/alert_pb'

export type Container = {
db: Knex
logger: Winston.Logger
prometheus: promClient.Registry
metrics: Metrics
ethClient: ETHProvider
StethOperationSrv: StethOperationSrv
WithdrawalsSrv: WithdrawalsSrv
GateSealSrv: GateSealSrv
VaultSrv: VaultSrv
findingsRW: DataRW<Finding>
db: Knex
healthChecker: HealthChecker
}

export class App {
private static instance: Container

private constructor() {}

public static async getJwt(): Promise<E.Either<Error, string>> {
let token: string
try {
token = await fetchJwt({})
} catch (e) {
return E.left(new Error(`Could not fetch jwt. Cause ${e}`))
}

if (process.env.NODE_ENV === 'production') {
try {
const isTokenOk = await verifyJwt(token)
if (!isTokenOk) {
return E.left(new Error(`Token verification failed`))
}
} catch (e) {
return E.left(new Error(`Token verification failed`))
}
}

return E.right(token)
}

private static getConnection(): Knex {
const config: knex.Knex.Config = {
client: 'sqlite3',
Expand Down Expand Up @@ -123,6 +106,16 @@ export class App {
veboRunner,
)

const drpcClient = new ETHProvider(
logger,
drpcProvider,
etherscanProvider,
lidoRunner,
wdQueueRunner,
gateSealRunner,
veboRunner,
)

const stethOperationCache = new StethOperationCache()
const stethOperationSrv = new StethOperationSrv(
logger,
Expand Down Expand Up @@ -155,16 +148,6 @@ export class App {
address.GATE_SEAL_FACTORY_ADDRESS,
)

const drpcClient = new ETHProvider(
logger,
drpcProvider,
etherscanProvider,
lidoRunner,
wdQueueRunner,
gateSealRunner,
veboRunner,
)

const vaultSrv = new VaultSrv(
logger,
drpcClient,
Expand All @@ -174,7 +157,22 @@ export class App {
address.LIDO_STETH_ADDRESS,
)

const prefix = 'ethereum_steth_'
const defaultRegistry = promClient
defaultRegistry.collectDefaultMetrics({
prefix: prefix,
})

const customRegister = new promClient.Registry()
const mergedRegistry = promClient.Registry.merge([defaultRegistry.register, customRegister])
mergedRegistry.setDefaultLabels({ instance: 'local-infra' })

const metrics = new Metrics(mergedRegistry, prefix)

App.instance = {
logger: logger,
metrics: metrics,
prometheus: mergedRegistry,
ethClient: ethClient,
StethOperationSrv: stethOperationSrv,
WithdrawalsSrv: withdrawalsSrv,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit fbea6bd

Please sign in to comment.