@@ -16,8 +16,7 @@ import (
1616 cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
1717 "golang.org/x/sync/errgroup"
1818
19- "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_2_0/router"
20-
19+ adapters1_2 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_2_0/adapters"
2120 "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_5_0/evm_2_evm_offramp"
2221 "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_5_0/evm_2_evm_onramp"
2322 "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_5_0/token_admin_registry"
@@ -122,25 +121,14 @@ func (ci *ConfigImportAdapter) InitializeAdapter(e cldf.Environment, sel uint64)
122121
123122func (ci * ConfigImportAdapter ) ConnectedChains (e cldf.Environment , chainsel uint64 ) ([]uint64 , error ) {
124123 var connected []uint64
125- // to ensure deduplication in case there are multiple onramps addresses in datastore for the same remote chain selector
126- var mapConnectedChains = make (map [uint64 ]bool )
127- chain , ok := e .BlockChains .EVMChains ()[chainsel ]
128- if ! ok {
129- return nil , fmt .Errorf ("chain with selector %d not found in environment" , chainsel )
130- }
131- routerC , err := router .NewRouter (ci .Router , chain .Client )
124+ laneResolver := adapters1_2.LaneVersionResolver {}
125+ remoteChainToVersionMap , _ , err := laneResolver .DeriveLaneVersionsForChain (e , chainsel )
132126 if err != nil {
133- return nil , fmt .Errorf ("failed to instantiate router contract at %s on chain %d: %w" , ci . Router . String (), chain . Selector , err )
127+ return nil , fmt .Errorf ("failed to derive lane versions for chain %d: %w" , chainsel , err )
134128 }
135- for destSel , onrampForDest := range ci .OnRamp {
136- onRamp , err := routerC .GetOnRamp (nil , destSel )
137- if err != nil {
138- return nil , fmt .Errorf ("failed to get onramp for dest chain %d from router at %s on chain %d: %w" , destSel , ci .Router .String (), chain .Selector , err )
139- }
140- // if the onramp address from the router doesn't match the onramp address we have, then this chain is not actually connected with 1.5
141- if onRamp == onrampForDest && ! mapConnectedChains [destSel ] {
129+ for destSel , version := range remoteChainToVersionMap {
130+ if version .Equal (semver .MustParse ("1.5.0" )) {
142131 connected = append (connected , destSel )
143- mapConnectedChains [destSel ] = true
144132 }
145133 }
146134 return connected , nil
@@ -151,8 +139,12 @@ func (ci *ConfigImportAdapter) SupportedTokensPerRemoteChain(e cldf.Environment,
151139 if ! ok {
152140 return nil , fmt .Errorf ("chain with selector %d not found in environment" , chainsel )
153141 }
142+ remoteChains , err := ci .ConnectedChains (e , chainsel )
143+ if err != nil {
144+ return nil , fmt .Errorf ("failed to get connected chains for chain %d: %w" , chainsel , err )
145+ }
154146 // get all supported tokens from token admin registry
155- return GetSupportedTokensPerRemoteChain (e .GetContext (), e .Logger , ci .TokenAdminReg , chain )
147+ return GetSupportedTokensPerRemoteChain (e .GetContext (), e .Logger , ci .TokenAdminReg , chain , remoteChains )
156148}
157149
158150func (ci * ConfigImportAdapter ) SequenceImportConfig () * cldf_ops.Sequence [api.ImportConfigPerChainInput , sequences.OnChainOutput , cldf_chain.BlockChains ] {
@@ -192,7 +184,7 @@ func (ci *ConfigImportAdapter) SequenceImportConfig() *cldf_ops.Sequence[api.Imp
192184 })
193185}
194186
195- func GetSupportedTokensPerRemoteChain (ctx context.Context , l logger.Logger , tokenAdminRegAddr common.Address , chain evm.Chain ) (map [uint64 ][]common.Address , error ) {
187+ func GetSupportedTokensPerRemoteChain (ctx context.Context , l logger.Logger , tokenAdminRegAddr common.Address , chain evm.Chain , remoteChains [] uint64 ) (map [uint64 ][]common.Address , error ) {
196188 // get all supported tokens from token admin registry
197189 tokenAdminRegC , err := token_admin_registry .NewTokenAdminRegistry (tokenAdminRegAddr , chain .Client )
198190 if err != nil {
@@ -230,29 +222,31 @@ func GetSupportedTokensPerRemoteChain(ctx context.Context, l logger.Logger, toke
230222 if err != nil {
231223 return fmt .Errorf ("failed to instantiate token pool contract at %s on chain %d: %w" , poolAddr .String (), chain .Selector , err )
232224 }
233- chains , err := tokenPoolC .GetSupportedChains (& bind.CallOpts {
234- Context : grpCtx ,
235- })
236- if err != nil {
237- // if we fail to get the supported chains for a pool, we skip it and move on to avoid failing the entire config import
238- // since it's possible for some pools do not support the getSupportedChains function
239- l .Warnf ("failed to get supported chains for token pool at %s on chain %d: %v" , poolAddr .String (), chain .Selector , err )
240- return nil
241- }
242- tokenAddr , err := tokenPoolC .GetToken (& bind.CallOpts {
243- Context : grpCtx ,
244- })
245- if err != nil {
246- // if we fail to get the token address for a pool, we skip it and move on to avoid failing the entire config import
247- // since it's possible for some pools do not support the getToken function
248- l .Warnf ("failed to get token address for token pool at %s on chain %d: %v" , poolAddr .String (), chain .Selector , err )
249- return nil
250- }
251- mu .Lock ()
252- for _ , remoteChain := range chains {
253- tokensPerRemoteChain [remoteChain ] = append (tokensPerRemoteChain [remoteChain ], tokenAddr )
225+ for _ , remoteChain := range remoteChains {
226+ supported , err := tokenPoolC .IsSupportedChain (& bind.CallOpts {
227+ Context : grpCtx ,
228+ }, remoteChain )
229+ if err != nil {
230+ // if we fail to check if the pool supports a remote chain, we skip it and move on to avoid failing the entire config import
231+ // since it's possible for some pools do not support the isSupportedChain function
232+ l .Warnf ("failed to check if token pool at %s on chain %d supports remote chain %d: %v" , poolAddr .String (), chain .Selector , remoteChain , err )
233+ continue
234+ }
235+ if supported {
236+ tokenAddr , err := tokenPoolC .GetToken (& bind.CallOpts {
237+ Context : grpCtx ,
238+ })
239+ if err != nil {
240+ // if we fail to get the token address for a pool, we skip it and move on to avoid failing the entire config import
241+ // since it's possible for some pools do not support the getToken function
242+ l .Warnf ("failed to get token address for token pool at %s on chain %d: %v" , poolAddr .String (), chain .Selector , err )
243+ continue
244+ }
245+ mu .Lock ()
246+ tokensPerRemoteChain [remoteChain ] = append (tokensPerRemoteChain [remoteChain ], tokenAddr )
247+ mu .Unlock ()
248+ }
254249 }
255- mu .Unlock ()
256250 return nil
257251 })
258252 }
0 commit comments