Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mellow-vaults bot scaffold #555

Open
wants to merge 66 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
40885fb
feat: add mellow-vaults bot scaffold
katamarinaki Jun 2, 2024
38206fd
feat: add some alerts and tests:
BATMAH69 Jun 10, 2024
d52beb4
feat: change owners
BATMAH69 Jun 10, 2024
c798523
feat: uncomment handleTransaction
BATMAH69 Jun 10, 2024
19f19ca
feat: add storage watcher
BATMAH69 Jun 10, 2024
40d2057
feat: fix some pr comments
BATMAH69 Jun 10, 2024
bf5a71d
feat: revert old notice logic
BATMAH69 Jun 10, 2024
48178fd
feat: alert once
BATMAH69 Jun 10, 2024
d48c42d
feat: fix README.md
BATMAH69 Jun 10, 2024
7284c1a
feat: fix provider rpc
BATMAH69 Jun 10, 2024
3faa0a9
feat: fix import
BATMAH69 Jun 10, 2024
19cace8
feat: fix types
BATMAH69 Jun 10, 2024
9c69451
feat: fix imports
BATMAH69 Jun 10, 2024
bbe74fd
feat: separate multisig watchers
BATMAH69 Jun 11, 2024
3750735
feat: rollback multisig bot
BATMAH69 Jun 11, 2024
bb7a822
feat: update feat: fix README.md
BATMAH69 Jun 11, 2024
0d70416
feat: move acl check to this bot, rollback changes in ethethereum-gov…
BATMAH69 Jun 11, 2024
1692d01
feat: add readme
BATMAH69 Jun 11, 2024
f7d1a29
feat: add alert, cleanup description
BATMAH69 Jun 11, 2024
a34cd9d
feat: filter max Supply event, add symbiotic limit watcher
BATMAH69 Jun 17, 2024
8bb1b26
feat: add limit reached alert, fix critical alert number
BATMAH69 Jun 17, 2024
feb9bee
feat: add curators alerts
BATMAH69 Jun 20, 2024
ccc3846
feat: change type for VAULT-WSTETH-LIMIT-REACHED
BATMAH69 Jun 20, 2024
021c9a8
feat: improve withdrawals alert logic
BATMAH69 Jun 20, 2024
066a546
feat: change period for notifications
BATMAH69 Jun 20, 2024
a98a7be
feat: add Vault name, fix handle multicall tx, add condition to 48h a…
BATMAH69 Jun 24, 2024
84cecdb
feat: add new Vaults
BATMAH69 Jun 28, 2024
66e876c
feat: test for forta
BATMAH69 Jun 30, 2024
dc729fc
feat: update test blocks aft adding new vaults
BATMAH69 Jul 1, 2024
5ca1dd0
fix: distribute vault config check by block number to solve slow Fort…
Ivan-Feofanov Jul 3, 2024
b9ac5f0
feat: update handleEventsOfNotice
BATMAH69 Jul 14, 2024
394c08a
feat: add multicall
BATMAH69 Jul 15, 2024
fbee818
feat: remove multicall, it works slow
BATMAH69 Jul 15, 2024
3de8767
feat: change connect position
BATMAH69 Jul 15, 2024
9da7e7f
fix: fix typo
BATMAH69 Jul 16, 2024
8b7c300
feat: move vault-watcher spec, change interfaces to last version
BATMAH69 Jul 16, 2024
b806315
feat: move acl-changes and multisig-changes spec, change test interfa…
BATMAH69 Jul 17, 2024
588079b
feat: add test for slot change
BATMAH69 Jul 17, 2024
15b407e
feat: update acl snapshot
BATMAH69 Jul 17, 2024
fd2c3bd
cln: remove unused and format
BATMAH69 Jul 17, 2024
5f08277
fix: resolve conflict
BATMAH69 Jul 17, 2024
0d784a1
Merge branch 'main' into feat/mellow-alerts
BATMAH69 Jul 17, 2024
0dd291d
fix: fix pr comments
BATMAH69 Jul 23, 2024
8be29ae
fix: fix pr comments
BATMAH69 Jul 23, 2024
04a1912
fix: change work with keys
BATMAH69 Jul 23, 2024
f767351
fix: change cast to lower case
BATMAH69 Jul 23, 2024
63b109c
cln: lint
BATMAH69 Jul 23, 2024
f95fe36
cln: removed await
BATMAH69 Jul 23, 2024
27a7e51
feat: change divide multi vault handler into 2 methods add loggers
BATMAH69 Jul 24, 2024
252b402
feat: divide historical query by 5 min one after another
BATMAH69 Jul 24, 2024
2c97999
test: added test for withdrawal event
BATMAH69 Jul 24, 2024
32e9e57
fix: remove spam logs
BATMAH69 Jul 25, 2024
f417353
feat: add new vault, add fix for tests, remove empty initialize
BATMAH69 Aug 12, 2024
ea6b5ed
fix: vault config to lower case
BATMAH69 Aug 12, 2024
d6e828f
fix: remove DVstETH vault
BATMAH69 Aug 12, 2024
8d39107
fix: fix DVSTETH vault address
BATMAH69 Aug 12, 2024
351a73e
feat: add custom limits option
BATMAH69 Aug 12, 2024
e961463
feat: add alert for vault with 2 tokens, add period for notification …
BATMAH69 Aug 19, 2024
c532ea7
fix: inc warning limit
BATMAH69 Sep 8, 2024
ff08525
fix: inc warning limit
BATMAH69 Sep 12, 2024
cff80e5
fix: inc warning limit, add more info to description
BATMAH69 Sep 25, 2024
d46ae9d
fix: inc warning limit
BATMAH69 Oct 16, 2024
54c77bd
fix: inc warning limit
katamarinaki Nov 19, 2024
908a601
fix: relax limits
TheDZhon Dec 9, 2024
ad46085
Merge branch 'main' of github.com:lidofinance/alerting-forta into fea…
katamarinaki Dec 10, 2024
d250679
fix: relax limits; add etherscan links to vaults
katamarinaki Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/ethereum-financial/ @lidofinance/lido-eth-protocol
/arb-subgraph/ @lidofinance/lido-si
/ethereum-governance/ @lidofinance/lido-dao-ops-team
/ethereum-governance-v2/ @lidofinance/lido-dao-ops-team
/mellow-vaults/ @lidofinance/lido-dao-ops-team
/multisig-watcher/ @lidofinance/lido-dao-ops-team
/voting-watcher/ @lidofinance/lido-dao-ops-team
/ethereum-validators-set/ @lidofinance/lido-tooling
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('AclChangesSrv', () => {
jest.spyOn(ethProvider, 'getContractOwner').mockResolvedValue(E.left(new Error('Test error')))
const finding = networkAlert(
new Error('Test error'),
`Error in AclChangesSrv.handleOwnerChange (uid:790dc305)`,
`Error in AclChangesSrv.handleOwnerChange (uid:3197e652)`,
`Could not call ethProvider.getOwner for address - ${dsAddress}`,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,19 @@ export class AclChangesSrv {
out.push(
networkAlert(
curOwner.left,
`Error in ${AclChangesSrv.name}.${this.handleOwnerChange.name} (uid:790dc305)`,
`Error in ${AclChangesSrv.name}.${this.handleOwnerChange.name} (uid:3197e652)`,
`Could not call ethProvider.getOwner for address - ${address}`,
),
)
return
}

if (WHITELISTED_OWNERS.includes(curOwner.right.toLowerCase())) {
const curOwnerAddress = curOwner.right.toLowerCase()
if (data?.ownerAddress && data?.ownerAddress === curOwnerAddress) {
return
}

if (!data?.ownerAddress && WHITELISTED_OWNERS.includes(curOwnerAddress)) {
return
}

Expand Down
21 changes: 16 additions & 5 deletions ethereum-governance/src/shared/constants/acl-changes/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
ANCHOR_VAULT_ADDRESS as anchorVaultAddress,
EMERGENCY_BRAKES_MS_ADDRESS as emergencyMsAddress,
DEV_MS_ADDRESS as devMsAddress,
MELLOW_VAULT_PROXY_ADDRESS as vaultProxyAddress,
MELLOW_VAULT_PROXY_OWNER as vaultProxyOwner,
} from 'constants/common'

export const NEW_OWNER_IS_CONTRACT_REPORT_INTERVAL = 24 * 60 * 60 // 24h
Expand Down Expand Up @@ -133,6 +135,7 @@ export const LIDO_ROLES = new Map([
export interface IOwnable {
name: string
ownershipMethod: string
ownerAddress?: string
}

// List of contracts to monitor for owner
Expand Down Expand Up @@ -194,17 +197,25 @@ export const OWNABLE_CONTRACTS = new Map<string, IOwnable>([
},
],
[
anchorVaultAddress,
evmExecutorAddress,
{
name: 'AnchorVault',
ownershipMethod: 'admin',
name: 'Easy Track EVMScriptExecutor',
ownershipMethod: 'owner',
},
],
[
evmExecutorAddress,
vaultProxyAddress,
{
name: 'Easy Track EVMScriptExecutor',
name: 'Mellow Vault upgradeable Proxy Admin',
ownershipMethod: 'owner',
ownerAddress: vaultProxyOwner,
},
],
[
anchorVaultAddress,
{
name: 'AnchorVault',
ownershipMethod: 'admin',
},
],
[
Expand Down
3 changes: 3 additions & 0 deletions ethereum-governance/src/shared/constants/common/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export const USDC_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
export const EMERGENCY_BRAKES_MS_ADDRESS = '0x73b047fe6337183a454c5217241d780a932777bd'
export const DEV_MS_ADDRESS = '0x3cd9f71f80ab08ea5a7dca348b5e94bc595f26a0'

export const MELLOW_VAULT_PROXY_ADDRESS = '0xed792a3fdeb9044c70c951260aaae974fb3db38f'
export const MELLOW_VAULT_PROXY_OWNER = '0x81698f87c6482bf1ce9bfcfc0f103c4a0adf0af0'

// COMMON CONSTS
export const BN_ZERO = new BigNumber(0)
export const RUN_TIER = process.env.FORTA_AGENT_RUN_TIER
Expand Down
3 changes: 3 additions & 0 deletions mellow-vaults/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
forta.config.json
14 changes: 14 additions & 0 deletions mellow-vaults/.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"
}
}
10 changes: 10 additions & 0 deletions mellow-vaults/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
dist
forta.config.json
.yarn/*
!.yarn/releases/
*.log
version.json
.DS_Store
/coverage/
/src/generated/
1 change: 1 addition & 0 deletions mellow-vaults/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.10.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless. Just look on CI file

Copy link
Contributor

@BATMAH69 BATMAH69 Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is help to change env without looking in file

7 changes: 7 additions & 0 deletions mellow-vaults/.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
}
22 changes: 22 additions & 0 deletions mellow-vaults/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build stage: compile Typescript to Javascript
FROM node:20.10.0-alpine3.18 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 run the app
FROM node:20.10.0-alpine3.18 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"]
83 changes: 83 additions & 0 deletions mellow-vaults/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Lido x Mellow Detection Bot for Forta

## Supported chains

- Ethereum mainnet

## Alerts

1. Aave operations
BATMAH69 marked this conversation as resolved.
Show resolved Hide resolved
1. HandleBlock
1. 🚨🚨🚨 astETH balance - astETH totalSupply >= 1ETH
BATMAH69 marked this conversation as resolved.
Show resolved Hide resolved
2. 🚨🚨🚨 stableDebtStETH totalSupply is not 0
3. 🚨🚨🚨 variableDebtStETH totalSupply is not 0
2. Pool balances
1. HandleBlock
1. 🚨 Super low stETH:ETH price on Curve
2. 🚨 Super low stETH:ETH price on Chainlink
3. 🚨 Curve Pool rapid imbalance change
4. 🚨️ Significant Curve Pool size change
5. ⚠️ Significant Curve Pool size change
6. ⚠️ Curve Pool is imbalanced
7. ⚠️ stETH:ETH price on Curve decreased
8. ⚠️ stETH:ETH price on Chainlink decreased

## Development

Install deps:

```
yarn install
```

### Mainnet

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

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

### Testnet

For example, you need to add `testnet` tier support for some new sub-agent:

1. Change default import from `./constants` to `requireWithTier` function call:
##### Before:
```typescript
import {
NODE_OPERATORS_REGISTRY_ADDRESS,
EASY_TRACK_ADDRESS,
MOTION_ENACTED_EVENT,
SIGNING_KEY_REMOVED_EVENT,
NODE_OPERATOR_STAKING_LIMIT_SET_EVENT,
NODE_OPERATORS_REGISTRY_EVENTS_OF_NOTICE,
} from './constants'
```
##### After:
```typescript
import type * as Constants from './constants'
const {
NODE_OPERATORS_REGISTRY_ADDRESS,
EASY_TRACK_ADDRESS,
MOTION_ENACTED_EVENT,
SIGNING_KEY_REMOVED_EVENT,
NODE_OPERATOR_STAKING_LIMIT_SET_EVENT,
NODE_OPERATORS_REGISTRY_EVENTS_OF_NOTICE,
} = requireWithTier<typeof Constants>(module, './constants')
```
2. Copy `./constants.ts` file to `./constants.testnet.ts` and change the addresses and other vars to the testnet ones.
3. Edit `alerting-forta/<SUBMODULE>/forta.config.json` and set `jsonRpcUrl` to your Testnet JSON-RPC provider.
4. Run `export FORTA_AGENT_RUN_TIER=testnet && yarn start:dev`

That's it! Only sub-agents that have `testnet` tier support will be run.
12 changes: 12 additions & 0 deletions mellow-vaults/jest.config-e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
BATMAH69 marked this conversation as resolved.
Show resolved Hide resolved
"moduleFileExtensions": ["js", "json", "ts"],
"moduleDirectories": ["node_modules", "src"],
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"preset": "ts-jest",
"testPathIgnorePatterns": ["dist"],
"moduleNameMapper": {
"^src/(.*)": "<rootDir>/src/$1",
"constants/common": "<rootDir>/src/shared/constants/common/mainnet"
}
}
9 changes: 9 additions & 0 deletions mellow-vaults/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import("ts-jest").JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['dist'],
moduleNameMapper: {
'constants/common': '<rootDir>/src/shared/constants/common/mainnet',
},
}
97 changes: 97 additions & 0 deletions mellow-vaults/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"name": "lido-governance-forta-bot",
"version": "1.0.0",
"description": "Forta Bot for Lido protocol governance",
"repository": {
"type": "git",
"directory": "https://github.com/lidofinance/alerting-forta/tree/main/ethereum-steth"
BATMAH69 marked this conversation as resolved.
Show resolved Hide resolved
},
"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 && tsc-alias && 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 --passWithNoTests",
"test:e2e": "yarn build && jest --config ./jest.config-e2e.json --passWithNoTests",
"generate-types": "typechain --target=ethers-v5 --out-dir=./src/generated ./src/abi/*",
"eslint:lint": "eslint ./src ./tests",
"eslint:format": "eslint ./src ./tests --fix",
"prettier:check": "prettier --check ./src ./tests",
"prettier:format": "prettier --write ./src ./tests README.md",
"lint": "yarn run prettier:check && yarn run eslint:lint",
"format": "yarn run eslint:format && yarn run prettier:format",
"postinstall": "yarn generate-types"
},
"dependencies": {
"@ethersproject/abi": "^5.0.0",
"@ethersproject/providers": "^5.0.0",
"@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",
"knex": "^3.1.0",
"lodash": "^4.17.21",
"ts-retry": "^4.2.4",
"winston": "^3.11.0"
},
"devDependencies": {
"@faker-js/faker": "^8.3.1",
"@jest/globals": "^29.7.0",
"@tsconfig/node20": "^20.1.2",
"@typechain/ethers-v5": "^11.1.2",
"@types/jest": "^29.5.11",
"@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",
"jest-resolve": "^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",
"tsc-alias": "^1.8.8",
"typechain": "^8.3.2",
"typescript": "^5.3.2"
},
"packageManager": "[email protected]"
}
Loading
Loading