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

Create contract utility #14

Merged
merged 15 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
15 changes: 11 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@ module github.com/LiskHQ/op-fault-detector
go 1.21.5

require (
github.com/ethereum-optimism/optimism/op-bindings v0.10.14
github.com/ethereum/go-ethereum v1.13.10
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/tools v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
30 changes: 20 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=
github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand All @@ -14,6 +12,8 @@ github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPx
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cockroachdb/errors v1.8.1 h1:A5+txlVZfOqFBDa4mGz2bUWSp0aHElvHX2bKkdbQu+Y=
Expand Down Expand Up @@ -46,6 +46,8 @@ github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/ethereum-optimism/optimism/op-bindings v0.10.14 h1:SMMnMdNb1QIhJDyvk7QMUv+crAP4UHHoSYBOASBDIjM=
github.com/ethereum-optimism/optimism/op-bindings v0.10.14/go.mod h1:9ZSUq/rjlzp3uYyBN4sZmhTc3oZgDVqJ4wrUja7vj6c=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-ethereum v1.13.10 h1:Ppdil79nN+Vc+mXfge0AuUgmKWuVv4eMqzoIVSdqZek=
Expand All @@ -58,8 +60,8 @@ github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqG
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2GihuqhwdILrV+7GJel5lyPV3u1+PgzrWLc0TkE=
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc=
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand All @@ -70,11 +72,13 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0=
github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw=
Expand Down Expand Up @@ -134,16 +138,16 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI=
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
Expand All @@ -154,6 +158,8 @@ github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
Expand All @@ -169,6 +175,7 @@ golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
Expand All @@ -181,6 +188,9 @@ golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=
golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
121 changes: 121 additions & 0 deletions pkg/chain/chain_constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package chain

type L2ChainIDs struct {
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
OPTIMISM uint64
OPTIMISM_GOERLI uint64
OPTIMISM_HARDHAT_LOCAL uint64
OPTIMISM_HARDHAT_DEVNET uint64
OPTIMISM_BEDROCK_LOCAL_DEVNET uint64
OPTIMISM_BEDROCK_ALPHA_TESTNET uint64
BASE_GOERLI uint64
ZORA_GOERLI uint64
ZORA_MAINNET uint64
OPTIMISM_SEPOLIA uint64
BASE_SEPOLIA uint64
BASE_MAINNET uint64
}
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved

var L2_CHAIN_IDS = L2ChainIDs{
OPTIMISM: 10,
OPTIMISM_GOERLI: 420,
OPTIMISM_SEPOLIA: 11155420,
OPTIMISM_HARDHAT_LOCAL: 31337,
OPTIMISM_HARDHAT_DEVNET: 17,
OPTIMISM_BEDROCK_ALPHA_TESTNET: 28528,
BASE_GOERLI: 84531,
BASE_SEPOLIA: 84532,
BASE_MAINNET: 8453,
ZORA_GOERLI: 999,
ZORA_MAINNET: 7777777,
}

type L1Contracts struct {
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
stateCommitmentChain string
optimismPortal string
l2OutputOracle string
}
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved

// GetContractAddressesByChainID returns contract addresses by chainID.
func GetContractAddressesByChainID(chainID uint64) map[string]L1Contracts {
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
CONTRACT_ADDRESSES := map[uint64]map[string]L1Contracts{
L2_CHAIN_IDS.OPTIMISM: {
"l1": {
stateCommitmentChain: "0xBe5dAb4A2e9cd0F27300dB4aB94BeE3A233AEB19",
optimismPortal: "0xbEb5Fc579115071764c7423A4f12eDde41f106Ed",
l2OutputOracle: "0xdfe97868233d1aa22e815a266982f2cf17685a27",
},
},
L2_CHAIN_IDS.OPTIMISM_GOERLI: {
"l1": {
stateCommitmentChain: "0x9c945aC97Baf48cB784AbBB61399beB71aF7A378",
optimismPortal: "0x5b47E1A08Ea6d985D6649300584e6722Ec4B1383",
l2OutputOracle: "0xE6Dfba0953616Bacab0c9A8ecb3a9BBa77FC15c0",
},
},
L2_CHAIN_IDS.OPTIMISM_SEPOLIA: {
"l1": {
stateCommitmentChain: "0x0000000000000000000000000000000000000000",
optimismPortal: "0x16Fc5058F25648194471939df75CF27A2fdC48BC",
l2OutputOracle: "0x90E9c4f8a994a250F6aEfd61CAFb4F2e895D458F",
},
},
L2_CHAIN_IDS.OPTIMISM_HARDHAT_LOCAL: {
"l1": {
stateCommitmentChain: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
optimismPortal: "0x0000000000000000000000000000000000000000",
l2OutputOracle: "0x0000000000000000000000000000000000000000",
},
},
L2_CHAIN_IDS.OPTIMISM_HARDHAT_DEVNET: {
"l1": {
stateCommitmentChain: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
optimismPortal: "0x0000000000000000000000000000000000000000",
l2OutputOracle: "0x0000000000000000000000000000000000000000",
},
},
L2_CHAIN_IDS.OPTIMISM_BEDROCK_ALPHA_TESTNET: {
"l1": {
stateCommitmentChain: "0x0000000000000000000000000000000000000000",
optimismPortal: "0xA581Ca3353DB73115C4625FFC7aDF5dB379434A8",
l2OutputOracle: "0x3A234299a14De50027eA65dCdf1c0DaC729e04A6",
},
},
L2_CHAIN_IDS.BASE_GOERLI: {
"l1": {
stateCommitmentChain: "0x0000000000000000000000000000000000000000",
optimismPortal: "0xe93c8cD0D409341205A592f8c4Ac1A5fe5585cfA",
l2OutputOracle: "0x2A35891ff30313CcFa6CE88dcf3858bb075A2298",
},
},
L2_CHAIN_IDS.BASE_SEPOLIA: {
"l1": {
stateCommitmentChain: "0x0000000000000000000000000000000000000000",
optimismPortal: "0x49f53e41452C74589E85cA1677426Ba426459e85",
l2OutputOracle: "0x84457ca9D0163FbC4bbfe4Dfbb20ba46e48DF254",
},
},
L2_CHAIN_IDS.BASE_MAINNET: {
"l1": {
stateCommitmentChain: "0x0000000000000000000000000000000000000000",
optimismPortal: "0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",
l2OutputOracle: "0x56315b90c40730925ec5485cf004d835058518A0",
},
},
L2_CHAIN_IDS.ZORA_GOERLI: {
"l1": {
stateCommitmentChain: "0x0000000000000000000000000000000000000000",
optimismPortal: "0xDb9F51790365e7dc196e7D072728df39Be958ACe",
l2OutputOracle: "0xdD292C9eEd00f6A32Ff5245d0BCd7f2a15f24e00",
},
},
L2_CHAIN_IDS.ZORA_MAINNET: {
"l1": {
stateCommitmentChain: "0x0000000000000000000000000000000000000000",
optimismPortal: "0x1a0ad011913A150f69f6A19DF447A0CfD9551054",
l2OutputOracle: "0x9E6204F750cD866b299594e2aC9eA824E2e5f95c",
},
},
}

return CONTRACT_ADDRESSES[chainID]
}
25 changes: 25 additions & 0 deletions pkg/chain/chain_constants_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package chain

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetContractAddressesByChainID(t *testing.T) {
const availableChainID uint64 = 10
var contractAddresses = GetContractAddressesByChainID(availableChainID)
var contractAddressesExpected = map[string]L1Contracts{
"l1": {
stateCommitmentChain: "0xBe5dAb4A2e9cd0F27300dB4aB94BeE3A233AEB19",
optimismPortal: "0xbEb5Fc579115071764c7423A4f12eDde41f106Ed",
l2OutputOracle: "0xdfe97868233d1aa22e815a266982f2cf17685a27",
}}

assert.Equal(t, contractAddressesExpected, contractAddresses)

const unavailableChainID uint64 = 5
contractAddresses = GetContractAddressesByChainID(unavailableChainID)

assert.Equal(t, 0, len(contractAddresses))
}
68 changes: 68 additions & 0 deletions pkg/chain/contracts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package chain

import (
"math/big"

"github.com/LiskHQ/op-fault-detector/pkg/log"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"

"github.com/ethereum-optimism/optimism/op-bindings/bindings"
)

// OracleContract binds oracle contract to an instance for querying data.
type OracleContract struct {
contractInstance *bindings.L2OutputOracle
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
log log.Logger
}

// GetL1OracleContractAddressByChainID returns L1 oracle contract address by chainID.
func GetL1OracleContractAddressByChainID(chainID uint64) string {
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
ContractAddresses := GetContractAddressesByChainID(chainID)
address := ContractAddresses["l1"].l2OutputOracle
return address
}

// CreateOracleContractInstance returns [OracleContract] with contract instance.
func CreateOracleContractInstance(url string, chainID uint64, logger log.Logger) (*OracleContract, error) {
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
client, err := ethclient.Dial(url)

nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

oracleContractAddress := GetL1OracleContractAddressByChainID(chainID)
contractInstance, err := bindings.NewL2OutputOracle(common.HexToAddress(oracleContractAddress), client)

nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

return &OracleContract{
contractInstance: contractInstance,
log: logger,
}, nil
}

// GetNextOutputIndex returns index of next output to be proposed.
func (oc *OracleContract) GetNextOutputIndex() *big.Int {
nextOutputIndex, err := oc.contractInstance.NextOutputIndex(&bind.CallOpts{})

if err != nil {
oc.log.Errorf("Error occurred while retrieving next output index %w", err)
}

return nextOutputIndex
nagdahimanshu marked this conversation as resolved.
Show resolved Hide resolved
}

// GetL2Output returns L2 output at given index.
func (oc *OracleContract) GetL2Output(index *big.Int) bindings.TypesOutputProposal {
l2Output, err := oc.contractInstance.GetL2Output(&bind.CallOpts{}, index)

if err != nil {
oc.log.Errorf("Error occurred while retrieving L2 outout %w", err)
}

return l2Output
}
19 changes: 19 additions & 0 deletions pkg/chain/contracts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package chain

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetL1OracleContractAddressByChainID(t *testing.T) {
const availableChainID uint64 = 10
var contractAddresses = GetL1OracleContractAddressByChainID(availableChainID)
var oracleContractAddressesExpected = "0xdfe97868233d1aa22e815a266982f2cf17685a27"

assert.Equal(t, oracleContractAddressesExpected, contractAddresses)

const unavailableChainID uint64 = 5
contractAddresses = GetL1OracleContractAddressByChainID(unavailableChainID)
assert.Equal(t, 0, len(contractAddresses))
}