Skip to content

Commit

Permalink
Merge pull request #503 from lidofinance/feat/scroll-support
Browse files Browse the repository at this point in the history
Add Scroll support (a separate bot)
  • Loading branch information
arwer13 authored May 28, 2024
2 parents 8377b40 + f5103eb commit a50e133
Show file tree
Hide file tree
Showing 42 changed files with 8,029 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/l2-bridge-zksync/ @lidofinance/lido-eth-protocol
/l2-bridge-mantle/ @lidofinance/lido-eth-protocol
/l2-bridge-linea/ @lidofinance/lido-eth-protocol
/l2-bridge-scroll/ @lidofinance/lido-eth-protocol
/ethereum-financial/ @lidofinance/lido-eth-protocol
/arb-subgraph/ @lidofinance/lido-si
/ethereum-governance/ @lidofinance/lido-dao-ops-team
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/test-l2-bridge-scroll.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Tests @ l2-bridge-scroll

on:
workflow_dispatch:
pull_request:
paths:
- "l2-bridge-scroll/**"

jobs:
tests:
uses: ./.github/workflows/_tests.yml
with:
path: ./l2-bridge-scroll
secrets: inherit
17 changes: 10 additions & 7 deletions L2_BOT.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
1. Find out a repository which contains WstETH information. For current project it's
1. https://www.notion.so/wstETH-on-Mantle-Deployment-Verification-08a1e257034b4ed9b6f5de1ef5293399
2. https://github.com/mantlenetworkio/lido-l2
3. Get Proofs of addreses and constants got from https://docs.lido.fi/deployed-contracts/:
3. Get Proofs of addresses and constants got from https://docs.lido.fi/deployed-contracts/:
1. L1ERC20TokenBridge
Impl : [0x6fBBe1Af52D22557D7F161Dc5952E306F4742e23](https://etherscan.io/address/0x2D001d79E5aF5F65a939781FE228B267a8Ed468B)
2. L1ERC20TokenBridge
Expand All @@ -18,7 +18,7 @@
Proxy: [0x9c46560D6209743968cC24150893631A39AfDe4d](https://explorer.mantle.xyz/address/0x9c46560D6209743968cC24150893631A39AfDe4d)
7. OptimismBridgeExecutor: [0x3a7b055bf88cdc59d20d0245809c6e6b3c5819dd](https://explorer.mantle.xyz/address/0x3a7b055bf88cdc59d20d0245809c6e6b3c5819dd)
2. Clone https://github.com/mantlenetworkio/lido-l2 repository and compile contracts.
1. Then copy and past needed abi's into ./abi folder in current repo
1. Then copy and past needed abi's into ./scr/abi folder in current repo
3. `yarn install`
4. `yarn generate-types` Install abi bindings though typechain. Generated files place in ./src/generated
5. Set up correct contract addresses.
Expand All @@ -43,11 +43,14 @@
3. proxy_admin_events.ts
1. Replace all network name to your-network name
2. Check event signatures
10. Go to ./src/workers and replace all network name to your-network name
11. Add new folder to .github/CODEOWNERS file
12. Add new bot for root [Readme.md](README.md)
13. Add alerts of bot to bot's Readme.md
14. Finish. Type yarn run in your CLI
10. Get sure there are no duplicate GUIDs by running root of all bots directory:
`grep -E -oh "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" --exclude-dir=node_modules -r . | tr '[:upper:]' '[:lower:]' | sort | uniq -cd`
11. Go to ./src/workers and replace all network name to your-network name
12. Add new folder to .github/CODEOWNERS file
13. Add new bot for root [Readme.md](README.md)
14. Add alerts of bot to bot's Readme.md
15. Add github CI flow for the network (see `.github/workflows/test-l2-bridge-mantle.yml`)
16. Finish. Type yarn run in your CLI

## Update l2-bridge-balance bot

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ mainnet)

[l2-bridge-zkSync](./l2-bridge-zksync) - Detection bot for ZkSync part of L2 bridge

[l2-bridge-scroll](./l2-bridge-scroll) - Detection bot for Scroll part of L2 bridge

[phishing-detect](./phishing-detect) - Phishing detection bot for the Lido ERC20 tokens

[multisig-watcher](./multisig-watcher) - Multisig events detector bot
Expand Down
3 changes: 3 additions & 0 deletions l2-bridge-scroll/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
forta.config.json
13 changes: 13 additions & 0 deletions l2-bridge-scroll/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"parser": "@typescript-eslint/parser",
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"plugins": ["@typescript-eslint", "prettier"],
"env": {
"node": true,
"es6": true
},
"rules": {
"prettier/prettier": "error",
"curly": "error"
}
}
9 changes: 9 additions & 0 deletions l2-bridge-scroll/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
dist
forta.config.json
.yarn/*
!.yarn/releases/
*.log
version.json
.DS_Store
src/generated
7 changes: 7 additions & 0 deletions l2-bridge-scroll/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}
24 changes: 24 additions & 0 deletions l2-bridge-scroll/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Build stage: compile Typescript to Javascript
FROM node:20.9.0-alpine3.18 AS base

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
LABEL "network.forta.settings.agent-logs.enable"="true"
ENV NODE_ENV=production
WORKDIR /app

COPY package*.json yarn.lock ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./src
COPY version.json ./

CMD ["yarn", "run", "start:prod"]
66 changes: 66 additions & 0 deletions l2-bridge-scroll/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Lido Detection Scroll Bot

How does it work.

The bot works on two networks: ETH mainnet and Scroll.
Here's how it operates: The bot monitors new blocks on the ETH mainnet.
Since Forta doesn't currently support Scroll, the bot reads blocks on the L2 network (Scroll) and stores the latest one
in an in-memory cache.
When the bot reads the next block on ETH, it also retrieves a segment of Scroll blocks (cachedBlock, latestBlock) from
the cache.

## Supported chains

- Ethereum mainnet, Scroll network

## Alerts

1. Bridge events
1. 🚨🚨🚨 Scroll bridge balance mismatch 🚨🚨🚨
2. 🚨 Scroll L2 Bridge: (re-)initialized
3. 🚨 Scroll L2 Bridge: Deposits Disabled
4. 🚨 Scroll: L2 gateway owner changed
5. 🚨 Scroll L2 Bridge: Withdrawals Disabled
6. ⚠️ Scroll L2 Bridge: Role granted
7. ⚠️ Scroll L2 Bridge: Role revoked
8. ℹ️ Scroll L2 Bridge: Deposits Enabled
9. ℹ️ Scroll L2 Bridge: Withdrawals Enabled
2. Gov Events
1. 🚨 Scroll Gov Bridge: Ethereum Governance Executor Updated
2. 🚨 Scroll Gov Bridge: Guardian Updated
3. ⚠️ Scroll Gov Bridge: Delay Updated
4. ⚠️ Scroll Gov Bridge: Grace Period Updated
5. ⚠️ Scroll Gov Bridge: Min Delay Updated
6. ⚠️ Scroll Gov Bridge: Max Delay Updated
7. ℹ️ Scroll Gov Bridge: Action set queued
8. ℹ️ Scroll Gov Bridge: Action set executed
9. ℹ️ Scroll Gov Bridge: Action set canceled
3. Proxy events
1. 🚨 Scroll: Proxy admin changed
2. 🚨 Scroll: Proxy implementation changed
3. 🚨 Scroll: Proxy upgraded
4. 🚨 Scroll: Proxy beacon upgraded
4. Monitor Withdrawals
1. ⚠️ Scroll: Huge withdrawals during the last ...

## Development (Forta specific)

Edit `alerting-forta/<SUBMODULE>/forta.config.json` and set `jsonRpcUrl` to your JSON-RPC provider. Install deps:

```
yarn install
```

Running in a live mode:

```
yarn start:dev
```

Testing on a specific block/range/transaction:

```
yarn block 13626668
yarn range '13626667..13626668'
yarn tx 0x2d2774c04e3faf9f17cd26e0978bb812081b9d0b5cc6fd8bf04cc441f92c0a8c
```
6 changes: 6 additions & 0 deletions l2-bridge-scroll/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import("ts-jest").JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['dist'],
}
93 changes: 93 additions & 0 deletions l2-bridge-scroll/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"name": "lido-l2-bridge-scroll-bot",
"displayName": "Forta Agent Starter",
"version": "0.0.1",
"description": "Lido Detection Bot for Scroll part of L2 bridge",
"repository": {
"type": "git",
"directory": "https://github.com/lidofinance/alerting-forta/tree/main/l2-bridge-scroll"
},
"license": "MIT",
"chainIds": [
1
],
"chainSettings": {
"default": {
"shards": 1,
"target": 5
}
},
"husky": {
"hooks": {
"pre-commit": "yarn run lint"
}
},
"scripts": {
"update-version": "node ../utils/write-version.js",
"build": "tsc && yarn run copy-version",
"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",
"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/*",
"eslint:lint": "eslint ./src",
"eslint:format": "eslint ./src --fix",
"prettier:check": "prettier --check ./src",
"prettier:format": "prettier --write ./src",
"lint": "yarn run prettier:check && yarn run eslint:lint",
"format": "yarn run eslint:format && yarn run prettier:format",
"postinstall": "yarn generate-types"
},
"dependencies": {
"@types/lodash": "^4.14.202",
"async-mutex": "^0.4.0",
"bignumber.js": "^9.1.2",
"ethers": "^5.5.1",
"forta-agent": "^0.1.48",
"fp-ts": "^2.16.1",
"lodash": "^4.17.21",
"ts-retry": "^4.2.4",
"winston": "^3.11.0"
},
"devDependencies": {
"@ethersproject/abi": "^5.0.0",
"@ethersproject/providers": "^5.0.0",
"@jest/globals": "^29.7.0",
"@tsconfig/node20": "^20.1.2",
"@typechain/ethers-v5": "^11.1.2",
"@types/jest": "^29.5.10",
"@types/nodemon": "^1.19.0",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-prettier": "^5.0.1",
"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.1",
"typechain": "^8.3.2",
"typescript": "^5.3.2"
},
"packageManager": "yarn@1.22.21"
}
34 changes: 34 additions & 0 deletions l2-bridge-scroll/src/abi/ERC20Short.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
]
Loading

0 comments on commit a50e133

Please sign in to comment.