@@ -76,6 +76,10 @@ func NewTransferToSettlement(
7676 if err != nil {
7777 return nil , fmt .Errorf ("failed to dial settlement rpc: %s" , err )
7878 }
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+ }
7983 initialBlock , err := settlementClient .BlockNumber (context .Background ())
8084 if err != nil {
8185 return nil , fmt .Errorf ("failed to get initial block: %s" , err )
@@ -85,6 +89,13 @@ func NewTransferToSettlement(
8589 return nil , fmt .Errorf ("failed to create settlement filterer: %s" , err )
8690 }
8791
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+
8899 return & Transfer {
89100 signer : signer ,
90101 amount : amount ,
@@ -111,6 +122,10 @@ func NewTransferToL1(
111122 if err != nil {
112123 return nil , fmt .Errorf ("failed to dial l1 rpc: %s" , err )
113124 }
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+ }
114129 initialBlock , err := l1Client .BlockNumber (context .Background ())
115130 if err != nil {
116131 return nil , fmt .Errorf ("failed to get initial block: %s" , err )
@@ -143,6 +158,13 @@ func NewTransferToL1(
143158 return nil , fmt .Errorf ("failed to create settlement filterer: %s" , err )
144159 }
145160
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+
146168 return & Transfer {
147169 amount : amount ,
148170 destAddress : destAddress ,
@@ -156,6 +178,24 @@ func NewTransferToL1(
156178 }, nil
157179}
158180
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+
159199func (t * Transfer ) Do (ctx context.Context ) <- chan TransferStatus {
160200 statusChan := make (chan TransferStatus )
161201 go func () {
0 commit comments