@@ -76,6 +76,10 @@ func NewTransferToSettlement(
76
76
if err != nil {
77
77
return nil , fmt .Errorf ("failed to dial settlement rpc: %s" , err )
78
78
}
79
+ settlementChainID , err := settlementClient .ChainID (context .Background ())
80
+ if err != nil {
81
+ return nil , fmt .Errorf ("failed to get settlement chain id: %s" , err )
82
+ }
79
83
initialBlock , err := settlementClient .BlockNumber (context .Background ())
80
84
if err != nil {
81
85
return nil , fmt .Errorf ("failed to get initial block: %s" , err )
@@ -85,6 +89,13 @@ func NewTransferToSettlement(
85
89
return nil , fmt .Errorf ("failed to create settlement filterer: %s" , err )
86
90
}
87
91
92
+ if err := validateChainIDs (
93
+ l1ChainID , // src
94
+ settlementChainID , // dest
95
+ ); err != nil {
96
+ return nil , fmt .Errorf ("invalid chain ids: %s" , err )
97
+ }
98
+
88
99
return & Transfer {
89
100
signer : signer ,
90
101
amount : amount ,
@@ -111,6 +122,10 @@ func NewTransferToL1(
111
122
if err != nil {
112
123
return nil , fmt .Errorf ("failed to dial l1 rpc: %s" , err )
113
124
}
125
+ l1ChainID , err := l1Client .ChainID (context .Background ())
126
+ if err != nil {
127
+ return nil , fmt .Errorf ("failed to get l1 chain id: %s" , err )
128
+ }
114
129
initialBlock , err := l1Client .BlockNumber (context .Background ())
115
130
if err != nil {
116
131
return nil , fmt .Errorf ("failed to get initial block: %s" , err )
@@ -143,6 +158,13 @@ func NewTransferToL1(
143
158
return nil , fmt .Errorf ("failed to create settlement filterer: %s" , err )
144
159
}
145
160
161
+ if err := validateChainIDs (
162
+ settlementChainID , // src
163
+ l1ChainID , // dest
164
+ ); err != nil {
165
+ return nil , fmt .Errorf ("invalid chain ids: %s" , err )
166
+ }
167
+
146
168
return & Transfer {
147
169
amount : amount ,
148
170
destAddress : destAddress ,
@@ -156,6 +178,24 @@ func NewTransferToL1(
156
178
}, nil
157
179
}
158
180
181
+ func validateChainIDs (srcChainID * big.Int , destChainID * big.Int ) error {
182
+ allowedPairs := map [int64 ]int64 {
183
+ 1 : 8855 , // mainnet -> mainnet mev-commit
184
+ 8855 : 1 , // mainnet mev-commit -> mainnet
185
+ 17000 : 17864 , // holesky -> testnet mev-commit
186
+ 17864 : 17000 , // testnet mev-commit -> holesky
187
+ }
188
+ expectedDest , ok := allowedPairs [srcChainID .Int64 ()]
189
+ if ! ok {
190
+ return fmt .Errorf ("source chain ID %d not recognized. Options are: %v" , srcChainID .Int64 (), allowedPairs )
191
+ }
192
+ if expectedDest != destChainID .Int64 () {
193
+ return fmt .Errorf ("invalid destination chain ID %d for source %d. Expected is %d" ,
194
+ destChainID .Int64 (), srcChainID .Int64 (), expectedDest )
195
+ }
196
+ return nil
197
+ }
198
+
159
199
func (t * Transfer ) Do (ctx context.Context ) <- chan TransferStatus {
160
200
statusChan := make (chan TransferStatus )
161
201
go func () {
0 commit comments