Skip to content

Commit

Permalink
feat: l2-optimism-bridge to local-infra
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyWh1te committed Jun 27, 2024
1 parent d8de307 commit 0915a32
Show file tree
Hide file tree
Showing 67 changed files with 10,143 additions and 7,750 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test-l2-bridge-optimism.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Tests @ l2-bridge-optimism

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

jobs:
tests:
uses: ./.github/workflows/_tests.yml
with:
path: ./l2-bridge-optimism
secrets: inherit
790 changes: 789 additions & 1 deletion l2-bridge-arbitrum/src/abi/L2Bridge.json

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions l2-bridge-balance/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface BridgeParamWstETH {

export interface BridgeParamsWstETH {
Arbitrum: BridgeParamWstETH;
Optimism: BridgeParamWstETH;
}

export const BRIDGE_PARAMS_WSTETH: BridgeParamsWstETH = {
Expand All @@ -29,12 +28,6 @@ export const BRIDGE_PARAMS_WSTETH: BridgeParamsWstETH = {
wstEthBridged: "0x5979d7b546e38e414f7e9822514be443a4800529",
rpcUrl: config.Arbitrum.RpcUrl,
},
Optimism: {
name: "Optimism",
l1Gateway: "0x76943c0d61395d8f2edf9060e1533529cae05de6",
wstEthBridged: "0x1f32b1c2345538c0c6f582fcb022739c4a194ebb",
rpcUrl: config.Optimism.RpcUrl,
},
};

export const LDO_ADDRESS = "0x5a98fcbea516cf06857215779fd812ca3bef1b32";
Expand All @@ -48,7 +41,6 @@ export interface BridgeParamLDO {

export interface BridgeParamsLDO {
Arbitrum: BridgeParamLDO;
Optimism: BridgeParamLDO;
}

export const BRIDGE_PARAMS_LDO: BridgeParamsLDO = {
Expand All @@ -58,10 +50,4 @@ export const BRIDGE_PARAMS_LDO: BridgeParamsLDO = {
ldoBridged: "0x13ad51ed4f1b7e9dc168d8a00cb3f4ddd85efa60",
rpcUrl: config.Arbitrum.RpcUrl,
},
Optimism: {
name: "Optimism",
l1Gateway: "0x99c9fc46f92e8a1c0dec1b1747d010903e884be1",
ldoBridged: "0xfdb794692724153d1488ccdbe0c56c252596735f",
rpcUrl: config.Optimism.RpcUrl,
},
};
15 changes: 15 additions & 0 deletions l2-bridge-optimism/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
APP_NAME=l2-bridge-optimism
INSTANCE=forta

HTTP_PORT=3000
LOG_FORMAT=simple
LOG_LEVEL=debug
ETHEREUM_RPC_URL=https://eth.drpc.com
OPTIMSIM_RPC_URL=https://optimism.drpc.com

USE_FORTA_RPC_URL=true

## FORTA compatible env names
NODE_ENV=local
AGENT_GRPC_PORT=50051
FORTA_CHAIN_ID=10
2 changes: 2 additions & 0 deletions l2-bridge-optimism/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generated
proto
14 changes: 14 additions & 0 deletions l2-bridge-optimism/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"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",
"semi": "off"
}
}
6 changes: 6 additions & 0 deletions l2-bridge-optimism/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ forta.config.json
*.log
version.json
.DS_Store
/coverage/

tools/vendor
bin

.env
1 change: 0 additions & 1 deletion l2-bridge-optimism/.nvmrc

This file was deleted.

2 changes: 2 additions & 0 deletions l2-bridge-optimism/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
generated
proto
7 changes: 7 additions & 0 deletions l2-bridge-optimism/.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
}
807 changes: 0 additions & 807 deletions l2-bridge-optimism/.yarn/releases/yarn-3.3.0.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions l2-bridge-optimism/.yarnrc.yml

This file was deleted.

28 changes: 17 additions & 11 deletions l2-bridge-optimism/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
# Build stage: compile Typescript to Javascript
FROM node:16.17.1-alpine3.16 AS base
FROM node:20.15.0-alpine3.20 AS base

FROM base as builder
WORKDIR /app

COPY package*.json .yarnrc.yml yarn.lock ./
COPY .yarn/releases ./.yarn/releases/
RUN yarn install --immutable
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 APP_NAME=l2-bridge-optimism
ENV NODE_ENV=production
WORKDIR /app
ENV ETHEREUM_RPC_URL=https://optimism.drpc.org

ENV AGENT_GRPC_PORT=50051
ENV HTTP_PORT=3000
ENV LOG_FORMAT=simple
ENV LOG_LEVEL=info
ENV INSTANCE=forta
ENV USE_FORTA_RPC_URL=true

RUN apk add --no-cache tini=0.19.0-r0
WORKDIR /app

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

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["yarn", "run", "start:prod"]
CMD ["yarn", "run", "start:docker:prod"]
42 changes: 42 additions & 0 deletions l2-bridge-optimism/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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

tools:
cd tools && go mod tidy && go mod vendor && go mod verify && go generate -tags tools
.PHONY: tools

.PHONY: check_alerts_syntax
check_alerts_syntax:
./bin/promtool check rules ./alerts.yml

.PHONY: test_alerts
test_alerts:
bin/promtool test rules ./alerts_tests.yml
87 changes: 30 additions & 57 deletions l2-bridge-optimism/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,33 @@

- Optimism

## Sub-bots

### Bridge-watcher

Alerts about events on the L2-bridge (optimism side)

**Alerts:**

- Alerts on the admin events in L2-bridge (optimism side)

### Governance

Alerts about events on the gov-bridge (optimism side)

**Alerts:**

- Alerts on all events in gov-bridge (optimism side)

### Proxy-watcher

Alert on proxy state changes

**Alerts:**

- PROXY-UPGRADED - One of the proxies on the Optimism side was upgraded
- PROXY-ADMIN-CHANGED - Admin for of the proxies on the Optimism side was changed
- Alerts on the admin events in L2-bridge (optimism side)

### Withdrawals

Alert on huge withdrawals

**Alerts:**

- HUGE-WITHDRAWALS-FROM-L2 - There were more than 10k wstETH withdrawal requests over the last 48h or less

## Development

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
```
## Alerts

1. Bridge events
1. 🚨🚨🚨 Optimism bridge wstETH:stEth balance mismatch
2. 🚨🚨🚨 Optimism bridge LDO balance mismatch
3. 🚨 Optimism L2 Bridge: Deposits Disabled
4. 🚨 Optimism L2 Bridge: Role Admin changed
5. 🚨 Optimism L2 Bridge: Withdrawals Disabled
6. ⚠️ Optimism L2 Bridge: Role granted
7. ⚠️ Optimism L2 Bridge: Role revoked
8. ℹ️ Optimism L2 Bridge: Deposits Enabled
9. ℹ️ Optimism L2 Bridge: Withdrawals Enabled
2. Gov Events
1. 🚨 Optimism Gov Bridge: Ethereum Governance Executor Updated
2. 🚨 Optimism Gov Bridge: Guardian Updated
3. ⚠️ Optimism Gov Bridge: Delay Updated
4. ⚠️ Optimism Gov Bridge: Grace Period Updated
5. ⚠️ Optimism Gov Bridge: Min Delay Updated
6. ⚠️ Optimism Gov Bridge: Max Delay Updated
7. ℹ️ Optimism Gov Bridge: Action set queued
8. ℹ️ Optimism Gov Bridge: Action set executed
9. ℹ️ Optimism Gov Bridge: Action set canceled
3. Proxy events
1. 🚨 Optimism: Proxy ossified
2. 🚨 Optimism: Proxy admin changed
3. 🚨 Optimism: Proxy implementation changed
4. 🚨 Optimism: Proxy upgraded
5. 🚨 Optimism: Proxy beacon upgraded
4. Monitor Withdrawals
1. ⚠️ Optimism: Huge withdrawals during the last ...
6 changes: 6 additions & 0 deletions l2-bridge-optimism/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'],
}
Loading

0 comments on commit 0915a32

Please sign in to comment.