Skip to content

Commit d4023d0

Browse files
committed
fix for supported chains in token transfer fee config
revert change:
1 parent 96d272c commit d4023d0

File tree

2 files changed

+50
-80
lines changed

2 files changed

+50
-80
lines changed

chains/evm/deployment/v1_5_0/adapters/configimport.go

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

123122
func (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

158150
func (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
}

chains/evm/deployment/v1_6_0/adapters/configimport.go

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import (
44
"fmt"
55

66
"github.com/Masterminds/semver/v3"
7-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
87
"github.com/ethereum/go-ethereum/common"
98
cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
109
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
1110
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
1211
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
1312

14-
"github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_2_0/router"
15-
1613
evm_datastore_utils "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/utils/datastore"
14+
adapters1_2 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_2_0/adapters"
1715
routerops "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_2_0/operations/router"
1816
adapters1_5 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/adapters"
1917
tokenadminops "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/operations/token_admin_registry"
@@ -90,49 +88,27 @@ func (ci *ConfigImportAdapter) SupportedTokensPerRemoteChain(e cldf.Environment,
9088
if !ok {
9189
return nil, fmt.Errorf("chain with selector %d not found in environment", chainsel)
9290
}
91+
remoteChains, err := ci.ConnectedChains(e, chainsel)
92+
if err != nil {
93+
return nil, fmt.Errorf("failed to get connected chains for chain %d: %w", chainsel, err)
94+
}
9395
// get all supported tokens from token admin registry
94-
return adapters1_5.GetSupportedTokensPerRemoteChain(e.GetContext(), e.Logger, ci.TokenAdminReg, chain)
96+
return adapters1_5.GetSupportedTokensPerRemoteChain(e.GetContext(), e.Logger, ci.TokenAdminReg, chain, remoteChains)
9597
}
9698

9799
func (ci *ConfigImportAdapter) ConnectedChains(e cldf.Environment, chainsel uint64) ([]uint64, error) {
98-
chain, ok := e.BlockChains.EVMChains()[chainsel]
99-
if !ok {
100-
return nil, fmt.Errorf("chain with selector %d not found in environment", chainsel)
101-
}
102-
routerAddr := ci.Router
103-
if routerAddr == (common.Address{}) {
104-
return nil, fmt.Errorf("router address not initialized for chain %d", chainsel)
105-
}
106-
// get all offRamps from router to find connected chains
107-
routerC, err := router.NewRouter(ci.Router, chain.Client)
108-
if err != nil {
109-
return nil, fmt.Errorf("failed to instantiate router contract at %s on chain %d: %w", routerAddr.String(), chain.Selector, err)
110-
}
111-
offRamps, err := routerC.GetOffRamps(&bind.CallOpts{
112-
Context: e.GetContext(),
113-
})
100+
var connected []uint64
101+
laneResolver := adapters1_2.LaneVersionResolver{}
102+
remoteChainToVersionMap, _, err := laneResolver.DeriveLaneVersionsForChain(e, chainsel)
114103
if err != nil {
115-
return nil, fmt.Errorf("failed to get off ramps from router at %s on chain %d: %w", routerAddr.String(), chain.Selector, err)
104+
return nil, fmt.Errorf("failed to derive lane versions for chain %d: %w", chainsel, err)
116105
}
117-
connectedChains := make([]uint64, 0)
118-
for _, offRamp := range offRamps {
119-
// if the offramp's address matches our offramp, then we are connected to the source chain via 1.6
120-
if offRamp.OffRamp == ci.OffRamp {
121-
// get the onRamp on router for the source chain and check if it matches our onRamp, if it does then we are connected to that chain
122-
// lanes are always bi-directional so source and destination chain selectors are interchangeable for the purpose of finding connected chains
123-
onRamp, err := routerC.GetOnRamp(&bind.CallOpts{
124-
Context: e.GetContext(),
125-
}, offRamp.SourceChainSelector)
126-
if err != nil {
127-
return nil, fmt.Errorf("failed to get on ramp for source chain selector %d from router at %s on chain %d: %w", offRamp.SourceChainSelector, routerAddr.String(), chain.Selector, err)
128-
}
129-
if onRamp != ci.OnRamp {
130-
continue
131-
}
132-
connectedChains = append(connectedChains, offRamp.SourceChainSelector)
106+
for destSel, version := range remoteChainToVersionMap {
107+
if version.Equal(semver.MustParse("1.6.0")) {
108+
connected = append(connected, destSel)
133109
}
134110
}
135-
return connectedChains, nil
111+
return connected, nil
136112
}
137113

138114
func (ci *ConfigImportAdapter) SequenceImportConfig() *cldf_ops.Sequence[api.ImportConfigPerChainInput, sequences.OnChainOutput, cldf_chain.BlockChains] {

0 commit comments

Comments
 (0)