Skip to content

Commit b325c16

Browse files
committed
Add FindAndFormatRef for filtering in fees.go for all versions
1 parent ab058dd commit b325c16

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
evmseq "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/sequences"
1313
"github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_5_0/evm_2_evm_onramp"
1414
"github.com/smartcontractkit/chainlink-ccip/deployment/fees"
15+
datastore_utils "github.com/smartcontractkit/chainlink-ccip/deployment/utils/datastore"
1516
"github.com/smartcontractkit/chainlink-ccip/deployment/utils/sequences"
1617
cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
1718
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
@@ -177,17 +178,23 @@ func (a *FeesAdapter) GetFeeContractRef(e cldf.Environment, src uint64, dst uint
177178
return datastore.AddressRef{}, fmt.Errorf("no OnRamp address found for src %d and dst %d", src, dst)
178179
}
179180

180-
feecontractref := e.DataStore.Addresses().Filter(
181-
datastore.AddressRefByAddress(cacheAddr.Hex()),
182-
datastore.AddressRefByType(datastore.ContractType(onramp.ContractType)),
183-
datastore.AddressRefByVersion(onramp.Version),
184-
datastore.AddressRefByChainSelector(src),
181+
filter := datastore.AddressRef{
182+
Type: datastore.ContractType(onramp.ContractType),
183+
Address: cacheAddr.Hex(),
184+
ChainSelector: src,
185+
}
186+
feecontractref, err := datastore_utils.FindAndFormatRef(
187+
e.DataStore,
188+
filter,
189+
src,
190+
datastore_utils.FullRef,
185191
)
186192

187-
if len(feecontractref) == 0 || len(feecontractref) > 1 {
188-
return datastore.AddressRef{}, fmt.Errorf("incorrect number of address ref found for OnRamp contract at address %s on chain selector %d", cacheAddr.Hex(), src)
193+
if err != nil {
194+
return datastore.AddressRef{}, fmt.Errorf("failed to find FeeQuoter address ref for chain selector %d: %w", src, err)
189195
}
190-
return feecontractref[0], nil
196+
197+
return feecontractref, nil
191198
}
192199

193200
func (a *FeesAdapter) GetDefaultTokenTransferFeeConfig(src uint64, dst uint64) fees.TokenTransferFeeArgs {

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
evmseq "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_6_0/sequences"
1111
"github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_3/fee_quoter"
1212
"github.com/smartcontractkit/chainlink-ccip/deployment/fees"
13+
datastore_utils "github.com/smartcontractkit/chainlink-ccip/deployment/utils/datastore"
1314
"github.com/smartcontractkit/chainlink-ccip/deployment/utils/sequences"
1415
cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
1516
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
@@ -36,18 +37,25 @@ func (a *FeesAdapter) GetFeeContractRef(e cldf.Environment, src uint64, dst uint
3637
return datastore.AddressRef{}, fmt.Errorf("failed to get FeeQuoter address for chain selector %d: %w", src, err)
3738
}
3839

39-
feecontractref := ds.Addresses().Filter(
40-
datastore.AddressRefByAddress(common.BytesToAddress(fqAddr).Hex()),
41-
datastore.AddressRefByType(datastore.ContractType(fqops.ContractType)),
42-
datastore.AddressRefByChainSelector(src),
40+
filter := datastore.AddressRef{
41+
Type: datastore.ContractType(fqops.ContractType),
42+
Address: common.BytesToAddress(fqAddr).Hex(),
43+
ChainSelector: src,
44+
}
45+
feecontractref, err := datastore_utils.FindAndFormatRef(
46+
ds,
47+
filter,
48+
src,
49+
datastore_utils.FullRef,
4350
)
4451

45-
if len(feecontractref) == 0 {
46-
return datastore.AddressRef{}, fmt.Errorf("no address ref found for FeeQuoter contract at address %s on chain selector %d", common.BytesToAddress(fqAddr).Hex(), src)
52+
if err != nil {
53+
return datastore.AddressRef{}, fmt.Errorf("failed to find FeeQuoter address ref for chain selector %d: %w", src, err)
54+
4755
}
4856

4957
// Since we're filtering by address+type+chain selector, there should be exactly one match
50-
return feecontractref[0], nil
58+
return feecontractref, nil
5159
}
5260

5361
func (a *FeesAdapter) GetDefaultTokenTransferFeeConfig(src uint64, dst uint64) fees.TokenTransferFeeArgs {

chains/evm/deployment/v2_0_0/adapters/fees.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
fqops "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/operations/fee_quoter"
1111
evmseq "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v2_0_0/sequences"
1212
"github.com/smartcontractkit/chainlink-ccip/deployment/fees"
13+
datastore_utils "github.com/smartcontractkit/chainlink-ccip/deployment/utils/datastore"
1314
"github.com/smartcontractkit/chainlink-ccip/deployment/utils/sequences"
1415
cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
1516
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
@@ -36,17 +37,24 @@ func (a *FeesAdapter) GetFeeContractRef(e cldf.Environment, src uint64, dst uint
3637
return datastore.AddressRef{}, fmt.Errorf("failed to get FeeQuoter address for chain selector %d: %w", src, err)
3738
}
3839

39-
feecontractref := ds.Addresses().Filter(
40-
datastore.AddressRefByAddress(common.BytesToAddress(fqAddr).Hex()),
41-
datastore.AddressRefByType(datastore.ContractType(fqops.ContractType)),
42-
datastore.AddressRefByChainSelector(src),
40+
filter := datastore.AddressRef{
41+
Type: datastore.ContractType(fqops.ContractType),
42+
Address: common.BytesToAddress(fqAddr).Hex(),
43+
ChainSelector: src,
44+
}
45+
feecontractref, err := datastore_utils.FindAndFormatRef(
46+
ds,
47+
filter,
48+
src,
49+
datastore_utils.FullRef,
4350
)
4451

45-
if len(feecontractref) == 0 || len(feecontractref) > 1 {
46-
return datastore.AddressRef{}, fmt.Errorf("incorrect number of address ref found for FeeQuoter contract at address %s on chain selector %d", common.BytesToAddress(fqAddr).Hex(), src)
52+
if err != nil {
53+
return datastore.AddressRef{}, fmt.Errorf("failed to find FeeQuoter address ref for chain selector %d: %w", src, err)
54+
4755
}
4856

49-
return feecontractref[0], nil
57+
return feecontractref, nil
5058
}
5159

5260
func (a *FeesAdapter) GetDefaultTokenTransferFeeConfig(src uint64, dst uint64) fees.TokenTransferFeeArgs {

0 commit comments

Comments
 (0)