@@ -3,12 +3,13 @@ package message
33import (
44 "context"
55 "fmt"
6+ "maps"
67 "math/big"
8+ "slices"
79 "time"
810
911 "github.com/ethereum/go-ethereum"
1012 "github.com/ethereum/go-ethereum/common"
11- "github.com/ethereum/go-ethereum/common/hexutil"
1213 "github.com/ethereum/go-ethereum/common/math"
1314 "github.com/ethereum/go-ethereum/core/types"
1415 "github.com/ethereum/go-ethereum/crypto"
@@ -79,7 +80,7 @@ type AcrossMessageHandler struct {
7980 confirmations map [uint64 ]uint64
8081 blocktime time.Duration
8182 tokenPricer TokenPricer
82- pool common.Address
83+ pools map [ uint64 ] common.Address
8384
8485 coordinator Coordinator
8586 host host.Host
@@ -92,7 +93,7 @@ type AcrossMessageHandler struct {
9293func NewAcrossMessageHandler (
9394 chainID uint64 ,
9495 client EventFilterer ,
95- pool common.Address ,
96+ pools map [ uint64 ] common.Address ,
9697 coordinator Coordinator ,
9798 host host.Host ,
9899 comm comm.Communication ,
@@ -106,7 +107,7 @@ func NewAcrossMessageHandler(
106107 return & AcrossMessageHandler {
107108 chainID : chainID ,
108109 client : client ,
109- pool : pool ,
110+ pools : pools ,
110111 coordinator : coordinator ,
111112 host : host ,
112113 comm : comm ,
@@ -241,18 +242,21 @@ func (h *AcrossMessageHandler) minimalConfirmations(d *events.AcrossDeposit) (ui
241242 return 0 , err
242243 }
243244
244- orderValue , _ := new (big.Float ).Quo (
245+ orderValueInt := new (big.Int )
246+ orderValueInt , _ = new (big.Float ).Quo (
245247 new (big.Float ).Mul (big .NewFloat (price ), new (big.Float ).SetInt (d .InputAmount )),
246248 new (big.Float ).SetInt (new (big.Int ).Exp (big .NewInt (10 ), big .NewInt (int64 (c .Decimals )), nil )),
247- ).Float64 ( )
249+ ).Int ( orderValueInt )
248250
249- for bucket , confirmation := range h .confirmations {
250- if uint64 (orderValue ) < bucket {
251- return confirmation , nil
251+ buckets := slices .Collect (maps .Keys (h .confirmations ))
252+ slices .Sort (buckets )
253+ for _ , bucket := range buckets {
254+ if orderValueInt .Cmp (new (big.Int ).SetUint64 (bucket )) < 0 {
255+ return h .confirmations [bucket ], nil
252256 }
253257 }
254258
255- return 0 , fmt .Errorf ("order value %f exceeds confirmation buckets" , orderValue )
259+ return 0 , fmt .Errorf ("order value %f exceeds confirmation buckets" , orderValueInt )
256260}
257261
258262func (h * AcrossMessageHandler ) waitForConfirmations (
@@ -319,7 +323,7 @@ func (h *AcrossMessageHandler) deposit(depositId *big.Int) (common.Hash, *events
319323 ToBlock : latestBlock ,
320324 FromBlock : new (big.Int ).Sub (latestBlock , big .NewInt (BLOCK_RANGE )),
321325 Addresses : []common.Address {
322- h .pool ,
326+ h .pools [ h . chainID ] ,
323327 },
324328 Topics : [][]common.Hash {
325329 {
@@ -374,7 +378,7 @@ func (h *AcrossMessageHandler) unlockHash(
374378) ([]byte , error ) {
375379 calldata , err := deposit .ToV3RelayData (
376380 new (big.Int ).SetUint64 (sourceChainId ),
377- ).Calldata (deposit .DestinationChainId , data .LiquidityPool )
381+ ).Calldata (deposit .DestinationChainId , data .Caller )
378382 if err != nil {
379383 return []byte {}, err
380384 }
@@ -383,8 +387,8 @@ func (h *AcrossMessageHandler) unlockHash(
383387 "caller" : data .Caller .Hex (),
384388 "borrowToken" : common .BytesToAddress (deposit .OutputToken [12 :]).Hex (),
385389 "amount" : deposit .OutputAmount ,
386- "target" : common . BytesToAddress ( deposit .Recipient [ 12 :]) .Hex (),
387- "targetCallData" : hexutil . Encode ( calldata ) ,
390+ "target" : h . pools [ deposit .DestinationChainId . Uint64 ()] .Hex (),
391+ "targetCallData" : calldata ,
388392 "nonce" : data .Nonce ,
389393 "deadline" : new (big.Int ).SetUint64 (uint64 (deposit .FillDeadline )),
390394 }
0 commit comments