Skip to content

Commit

Permalink
fet: l2-bridge-arb iterate over l1
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyWh1te committed Jul 12, 2024
1 parent f374408 commit 594dee0
Show file tree
Hide file tree
Showing 33 changed files with 1,719 additions and 800 deletions.
1 change: 1 addition & 0 deletions l2-bridge-arbitrum/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
!.yarn/releases/
dist/
forta.config.json
.env
4 changes: 2 additions & 2 deletions l2-bridge-arbitrum/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ HTTP_PORT=3000
LOG_FORMAT=simple
LOG_LEVEL=debug
ETHEREUM_RPC_URL=https://eth.drpc.com
ARBITRUM_RPC_URL=https://arbitrum.drpc.com
ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc

USE_FORTA_RPC_URL=true

## FORTA compatible env names
NODE_ENV=local
AGENT_GRPC_PORT=50051
FORTA_CHAIN_ID=42161
FORTA_CHAIN_ID=1
2 changes: 0 additions & 2 deletions l2-bridge-arbitrum/.eslintignore

This file was deleted.

14 changes: 0 additions & 14 deletions l2-bridge-arbitrum/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion l2-bridge-arbitrum/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LABEL "network.forta.settings.agent-logs.enable"="true"
ENV APP_NAME=l2-bridge-arbitrum
ENV NODE_ENV=production
ENV ETHEREUM_RPC_URL=https://eth.drpc.org
ENV ARBITRUM_RPC_URL=https://arbitrum.drpc.org
ENV ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc

ENV AGENT_GRPC_PORT=50051
ENV HTTP_PORT=3000
Expand Down
35 changes: 35 additions & 0 deletions l2-bridge-arbitrum/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import eslint from '@eslint/js'
import prettier from 'eslint-plugin-prettier'
import tseslint from 'typescript-eslint'
import tsParser from '@typescript-eslint/parser'
import globals from 'globals'

export default tseslint.config({
...eslint.configs.recommended,
...tseslint.configs.strict,
...tseslint.configs.stylistic,
files: ['** /*.ts'],
ignores: ['**/generated', '**/proto'],
plugins: {
prettier,
},
languageOptions: {
globals: {
...globals.node,
},
parser: tsParser,
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
},
},
rules: {
'@typescript-eslint/ array-type': 'error',
'@typescript-eslint/ consistent-type-imports': 'error',
'prettier/prettier': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
curly: 'error',
semi: 'off',
},
})
6 changes: 0 additions & 6 deletions l2-bridge-arbitrum/jest.config.js

This file was deleted.

70 changes: 38 additions & 32 deletions l2-bridge-arbitrum/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "lido-l2-bridge-arbitrum-bot",
"name": "lido-l2-bridge-arbitrum",
"version": "0.0.1",
"license": "MIT",
"description": "Lido Detection Bot for Arbitrum part of L2 bridge",
"chainIds": [
42161
42161,
1
],
"chainSettings": {
"default": {
Expand All @@ -24,57 +26,61 @@
"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",
"prettier:check": "prettier --check ./src eslint.config.mjs",
"prettier:format": "prettier --write ./src README.md eslint.config.mjs",
"lint": "yarn run prettier:check && yarn run eslint:lint",
"format": "yarn run eslint:format && yarn run prettier:format",
"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",
"@types/node": "^20.14.2",
"async-mutex": "^0.4.0",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@grpc/grpc-js": "^1.10.10",
"@types/node": "^20.14.10",
"async-mutex": "^0.5.0",
"bignumber.js": "^9.1.2",
"dotenv": "^16.4.5",
"ethers": "^5.5.1",
"ethers": "^5.7.2",
"express": "^4.19.2",
"forta-agent": "^0.1.48",
"fp-ts": "^2.16.1",
"lodash": "^4.17.21",
"prom-client": "^15.1.2",
"ts-retry": "^4.2.4",
"winston": "^3.11.0"
"fp-ts": "^2.16.8",
"prom-client": "^15.1.3",
"ts-retry": "^4.2.5",
"winston": "^3.13.0"
},
"devDependencies": {
"@faker-js/faker": "^8.3.1",
"@faker-js/faker": "^8.4.1",
"@jest/globals": "^29.7.0",
"@tsconfig/node20": "^20.1.2",
"@tsconfig/node20": "^20.1.4",
"@typechain/ethers-v5": "^11.1.2",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.11",
"@types/nodemon": "^1.19.0",
"@types/jest": "^29.5.12",
"@types/nodemon": "^1.19.6",
"@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",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-prettier": "^5.1.3",
"grpc-tools": "^1.12.4",
"grpc_tools_node_protoc_ts": "^5.3.3",
"husky": "^8.0.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"postinstall": "^0.8.0",
"prettier": "^3.1.0",
"nodemon": "^3.1.4",
"postinstall": "^0.10.3",
"prettier": "^3.3.2",
"ts-generator": "^0.1.1",
"ts-jest": "^29.1.2",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.3.2"
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.0-alpha.39"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testPathIgnorePatterns": ["dist"]
},
"packageManager": "yarn@1.22.22"
}
41 changes: 33 additions & 8 deletions l2-bridge-arbitrum/src/clients/arbitrum_client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
import { ArbERC20__factory, ERC20Bridged__factory, L2ERC20TokenGateway__factory } from '../generated/typechain'
import { ArbitrumClient } from './arbitrum_client'
import { Address, ETH_DECIMALS } from '../utils/constants'
import { ethers } from 'forta-agent'
import { ethers } from 'ethers'
import { Config } from '../utils/env/env'
import promClient from 'prom-client'
import * as E from 'fp-ts/Either'
import { Metrics } from '../utils/metrics/metrics'
import BigNumber from 'bignumber.js'
import { BlockDtoWithTransactions, BlockHash } from '../entity/blockDto'
import { LRUCache } from 'lru-cache'
import { elapsedTime } from '../utils/time'

const TEST_TIMEOUT = 120_000

describe('arbitrumProvider', () => {
const config = new Config()
const adr: Address = Address

const arbitrumProvider = new ethers.providers.JsonRpcProvider(config.arbitrumRpcUrl, config.chainId)
const arbitrumProvider = new ethers.providers.JsonRpcProvider(config.arbitrumRpcUrl, config.arbChainID)

const l2Bridge = L2ERC20TokenGateway__factory.connect(adr.ARBITRUM_L2_TOKEN_GATEWAY.address, arbitrumProvider)
const bridgedWSthEthRunner = ERC20Bridged__factory.connect(adr.ARBITRUM_WSTETH_BRIDGED.address, arbitrumProvider)
const bridgedLdoRunner = ArbERC20__factory.connect(adr.ARBITRUM_LDO_BRIDGED_ADDRESS, arbitrumProvider)

const customRegister = new promClient.Registry()
const metrics = new Metrics(customRegister, config.promPrefix)
const l2Client = new ArbitrumClient(arbitrumProvider, metrics, l2Bridge, bridgedWSthEthRunner, bridgedLdoRunner)

const l2BlockNumber = 228_303_887
const l2BlocksStore = new LRUCache<BlockHash, BlockDtoWithTransactions>({
max: 500,
ttl: 1000 * 60 * 2,
updateAgeOnGet: true,
updateAgeOnHas: true,
})

const l2BridgeCache = new LRUCache<BlockHash, BigNumber>({
max: 500,
ttl: 1000 * 60 * 2,
updateAgeOnGet: true,
updateAgeOnHas: true,
})
const l2Client = new ArbitrumClient(
arbitrumProvider,
metrics,
l2Bridge,
bridgedWSthEthRunner,
bridgedLdoRunner,
l2BlocksStore,
l2BridgeCache,
)

const l2BlockHash = '0x5f0b1658096ed3521655dd968e867b6bcf7c8bde6fdc6049150ada403a0cd5e1'
test(
'getWithdrawalEvents is 1',
async () => {
Expand Down Expand Up @@ -59,20 +84,20 @@ describe('arbitrumProvider', () => {
test(
'getBlockNumber',
async () => {
const blockNumber = await l2Client.getBlockNumber()
const blockNumber = await l2Client.getLatestL2Block()
if (E.isLeft(blockNumber)) {
throw blockNumber.left
}

expect(Number.isInteger(blockNumber.right)).toBe(true)
expect(Number.isInteger(blockNumber.right.number)).toBe(true)
},
TEST_TIMEOUT,
)

test(
'getWstEthTotalSupply is 64_352.622267221200683868 wstEth',
async () => {
const wstBalance = await l2Client.getWstEthTotalSupply(l2BlockNumber)
const wstBalance = await l2Client.getWstEthTotalSupply(l2BlockHash)
if (E.isLeft(wstBalance)) {
throw wstBalance.left
}
Expand All @@ -85,7 +110,7 @@ describe('arbitrumProvider', () => {
test(
'getLdoTotalSupply is 92_8089.575013945159998755 ldo',
async () => {
const ldoBalance = await l2Client.getLdoTotalSupply(l2BlockNumber)
const ldoBalance = await l2Client.getLdoTotalSupply(l2BlockHash)
if (E.isLeft(ldoBalance)) {
throw ldoBalance.left
}
Expand Down
Loading

0 comments on commit 594dee0

Please sign in to comment.