Skip to content

Commit 7d65fe8

Browse files
authored
Merge branch 'develop' into tt/combine
2 parents a6e18cc + 64dd61a commit 7d65fe8

File tree

11 files changed

+953
-113
lines changed

11 files changed

+953
-113
lines changed

ccv/chains/evm/deployment/v1_7_0/adapters/deploy_chain_contracts_adapter.go

Lines changed: 148 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,174 @@ import (
55

66
"github.com/Masterminds/semver/v3"
77
"github.com/ethereum/go-ethereum/common"
8+
rmnops1_5 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/operations/rmn"
9+
offrampops_v160 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_6_0/operations/offramp"
10+
onrampops_v160 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_6_0/operations/onramp"
11+
seq1_6 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_6_0/sequences"
12+
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
13+
14+
"github.com/smartcontractkit/chainlink-deployments-framework/chain"
15+
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
816

917
"github.com/smartcontractkit/chainlink-ccip/ccv/chains/evm/deployment/v1_7_0/operations/executor"
1018
"github.com/smartcontractkit/chainlink-ccip/ccv/chains/evm/deployment/v1_7_0/sequences"
19+
datastore_utils "github.com/smartcontractkit/chainlink-ccip/deployment/utils/datastore"
1120
seq_core "github.com/smartcontractkit/chainlink-ccip/deployment/utils/sequences"
1221
ccvadapters "github.com/smartcontractkit/chainlink-ccip/deployment/v1_7_0/adapters"
13-
"github.com/smartcontractkit/chainlink-deployments-framework/chain"
14-
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
1522
)
1623

1724
type EVMDeployChainContractsAdapter struct{}
1825

1926
var _ ccvadapters.DeployChainContractsAdapter = (*EVMDeployChainContractsAdapter)(nil)
2027

21-
var evmDeployChainContracts = cldf_ops.NewSequence(
22-
"evm-deploy-chain-contracts",
23-
semver.MustParse("2.0.0"),
24-
"Wraps the EVM DeployChainContracts sequence with chain-agnostic input conversion",
25-
func(b cldf_ops.Bundle, chains chain.BlockChains, input ccvadapters.DeployChainContractsInput) (seq_core.OnChainOutput, error) {
26-
evmChains := chains.EVMChains()
27-
evmChain, ok := evmChains[input.ChainSelector]
28-
if !ok {
29-
return seq_core.OnChainOutput{}, fmt.Errorf("EVM chain not found for selector %d", input.ChainSelector)
30-
}
28+
var (
29+
evmDeployChainContracts = cldf_ops.NewSequence(
30+
"evm-deploy-chain-contracts",
31+
semver.MustParse("2.0.0"),
32+
"Wraps the EVM DeployChainContracts sequence with chain-agnostic input conversion",
33+
func(b cldf_ops.Bundle, chains chain.BlockChains, input ccvadapters.DeployChainContractsInput) (seq_core.OnChainOutput, error) {
34+
evmChains := chains.EVMChains()
35+
evmChain, ok := evmChains[input.ChainSelector]
36+
if !ok {
37+
return seq_core.OnChainOutput{}, fmt.Errorf("EVM chain not found for selector %d", input.ChainSelector)
38+
}
3139

32-
evmInput, err := toEVMDeployInput(input)
33-
if err != nil {
34-
return seq_core.OnChainOutput{}, fmt.Errorf("failed to convert deploy input to EVM types: %w", err)
35-
}
40+
evmInput, err := toEVMDeployInput(input)
41+
if err != nil {
42+
return seq_core.OnChainOutput{}, fmt.Errorf("failed to convert deploy input to EVM types: %w", err)
43+
}
3644

37-
report, err := cldf_ops.ExecuteSequence(b, sequences.DeployChainContracts, evmChain, evmInput)
38-
if err != nil {
39-
return seq_core.OnChainOutput{}, fmt.Errorf("failed to execute EVM deploy chain contracts sequence: %w", err)
40-
}
45+
report, err := cldf_ops.ExecuteSequence(b, sequences.DeployChainContracts, evmChain, evmInput)
46+
if err != nil {
47+
return seq_core.OnChainOutput{}, fmt.Errorf("failed to execute EVM deploy chain contracts sequence: %w", err)
48+
}
4149

42-
return report.Output, nil
43-
},
50+
return report.Output, nil
51+
})
52+
53+
importConfigForDeployContracts = cldf_ops.NewSequence(
54+
"evm-import-config-for-deploy-chain-contracts",
55+
semver.MustParse("2.0.0"),
56+
"Reads contract parameters from the datastore based on the chain selector and returns them in the format needed for DeployChainContracts",
57+
func(b cldf_ops.Bundle, chains chain.BlockChains, input ccvadapters.DeployChainConfigCreatorInput) (output ccvadapters.DeployContractParams, err error) {
58+
evmChains := chains.EVMChains()
59+
evmChain, ok := evmChains[input.ChainSelector]
60+
if !ok {
61+
return ccvadapters.DeployContractParams{}, fmt.Errorf("EVM chain not found for selector %d", input.ChainSelector)
62+
}
63+
paramsFrom1_6_0, err := importConfigFromv1_6_0(b, evmChain, input)
64+
if err != nil {
65+
return output, fmt.Errorf("failed to import config from v1.6.0: %w", err)
66+
}
67+
paramsFrom1_5_0, err := importConfigFromv1_5_0(input)
68+
if err != nil {
69+
return output, fmt.Errorf("failed to import config from v1.5.0: %w", err)
70+
}
71+
output, err = paramsFrom1_5_0.MergeWithOverrideIfNotEmpty(paramsFrom1_6_0)
72+
return
73+
})
4474
)
4575

76+
func (a *EVMDeployChainContractsAdapter) SetContractParamsFromImportedConfig() *cldf_ops.Sequence[ccvadapters.DeployChainConfigCreatorInput, ccvadapters.DeployContractParams, chain.BlockChains] {
77+
return importConfigForDeployContracts
78+
}
79+
4680
func (a *EVMDeployChainContractsAdapter) DeployChainContracts() *cldf_ops.Sequence[ccvadapters.DeployChainContractsInput, seq_core.OnChainOutput, chain.BlockChains] {
4781
return evmDeployChainContracts
4882
}
4983

84+
func importConfigFromv1_5_0(input ccvadapters.DeployChainConfigCreatorInput) (ccvadapters.DeployContractParams, error) {
85+
output := input.UserProvidedConfig
86+
// find legacy RMN address
87+
rmnAddr := datastore_utils.GetAddressRef(
88+
input.ExistingAddresses,
89+
input.ChainSelector,
90+
rmnops1_5.ContractType,
91+
semver.MustParse("1.5.0"),
92+
"",
93+
)
94+
if rmnAddr.Address != "" {
95+
output.RMNRemote.LegacyRMN = rmnAddr.Address
96+
}
97+
// set default value for gas for call exact check based on v1.5.0 deployments
98+
//https://github.com/smartcontractkit/ccip/blob/b5529a39311a2fd39cafceb62e4bb8f40eeb2e9e/contracts/src/v0.8/ccip/libraries/Internal.sol#L14C55-L14C60
99+
output.OffRamp.GasForCallExactCheck = 5000
100+
return output, nil
101+
}
102+
103+
func importConfigFromv1_6_0(b cldf_ops.Bundle, chain evm.Chain, input ccvadapters.DeployChainConfigCreatorInput) (ccvadapters.DeployContractParams, error) {
104+
output := input.UserProvidedConfig
105+
// fetch onRamp 1.6.0 , if not found, it's possible onRamp wasn't deployed in v1.6.0 for this chain, so we just return
106+
onRampAddr := datastore_utils.GetAddressRef(
107+
input.ExistingAddresses,
108+
input.ChainSelector,
109+
onrampops_v160.ContractType,
110+
onrampops_v160.Version,
111+
"",
112+
)
113+
if onRampAddr.Address == "" {
114+
return output, nil
115+
}
116+
// if onRamp address is found, we assume the other onRamp metadata fields are also present
117+
metadataForonRamp16, err := datastore_utils.FilterContractMetaByContractTypeAndVersion(
118+
input.ExistingAddresses,
119+
input.ContractMeta,
120+
onrampops_v160.ContractType,
121+
onrampops_v160.Version,
122+
"",
123+
input.ChainSelector,
124+
)
125+
if err != nil {
126+
return output, fmt.Errorf("failed to get onRamp metadata for chain selector %d: %w", input.ChainSelector, err)
127+
}
128+
if len(metadataForonRamp16) == 0 {
129+
return output, fmt.Errorf("no metadata found for onRamp v1.6.0 on chain selector %d", input.ChainSelector)
130+
}
131+
if len(metadataForonRamp16) > 1 {
132+
return output, fmt.Errorf("multiple metadata entries found for onRamp v1.6.0 on chain selector %d", input.ChainSelector)
133+
}
134+
metadataForoffRamp16, err := datastore_utils.FilterContractMetaByContractTypeAndVersion(
135+
input.ExistingAddresses,
136+
input.ContractMeta,
137+
offrampops_v160.ContractType,
138+
offrampops_v160.Version,
139+
"",
140+
input.ChainSelector,
141+
)
142+
if err != nil {
143+
return output, fmt.Errorf("failed to get offRamp metadata for chain selector %d: %w", input.ChainSelector, err)
144+
}
145+
if len(metadataForoffRamp16) == 0 {
146+
return output, fmt.Errorf("no metadata found for offRamp v1.6.0 on chain selector %d", input.ChainSelector)
147+
}
148+
if len(metadataForoffRamp16) > 1 {
149+
return output, fmt.Errorf("multiple metadata entries found for offRamp v1.6.0 on chain selector %d", input.ChainSelector)
150+
}
151+
// Convert metadata to typed struct if needed
152+
onRampCfg16, err := datastore_utils.ConvertMetadataToType[seq1_6.OnRampImportConfigSequenceOutput](metadataForonRamp16[0].Metadata)
153+
if err != nil {
154+
return output, fmt.Errorf("failed to convert metadata to "+
155+
"OnRampImportConfigSequenceOutput for chain selector %d: %w", input.ChainSelector, err)
156+
}
157+
offRampCfg16, err := datastore_utils.ConvertMetadataToType[seq1_6.OffRampImportConfigSequenceOutput](metadataForoffRamp16[0].Metadata)
158+
if err != nil {
159+
return output, fmt.Errorf("failed to convert metadata to "+
160+
"OffRampImportConfigSequenceOutput for chain selector %d: %w", input.ChainSelector, err)
161+
}
162+
163+
feeAggr := onRampCfg16.DynamicConfig.FeeAggregator.String()
164+
output.OnRamp.FeeAggregator = feeAggr
165+
166+
for i := range output.Executors {
167+
output.Executors[i].DynamicConfig.FeeAggregator = feeAggr
168+
}
169+
for i := range output.CommitteeVerifiers {
170+
output.CommitteeVerifiers[i].FeeAggregator = feeAggr
171+
}
172+
output.OffRamp.GasForCallExactCheck = offRampCfg16.StaticConfig.GasForCallExactCheck
173+
return output, nil
174+
}
175+
50176
func toEVMDeployInput(input ccvadapters.DeployChainContractsInput) (sequences.DeployChainContractsInput, error) {
51177
create2Factory, err := parseRequiredHexAddress(input.DeployerContract, "DeployerContract")
52178
if err != nil {

0 commit comments

Comments
 (0)