Skip to content

Commit fc85fae

Browse files
authored
Transfer ownership cherry pick (#1326)
* cherry-pick transferownership * resolve conflict * resolve conflict * fix tests * fix tests * more fixes * go mod tidy
1 parent 093ed1b commit fc85fae

File tree

21 files changed

+1608
-120
lines changed

21 files changed

+1608
-120
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package deployment_test
2+
3+
import (
4+
"math/big"
5+
"testing"
6+
7+
"github.com/Masterminds/semver/v3"
8+
"github.com/aws/smithy-go/ptr"
9+
"github.com/ethereum/go-ethereum/common"
10+
chainsel "github.com/smartcontractkit/chain-selectors"
11+
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
12+
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
13+
"github.com/smartcontractkit/chainlink-evm/pkg/utils"
14+
15+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/adapters"
16+
"github.com/smartcontractkit/chainlink-ccip/deployment/deploy"
17+
"github.com/smartcontractkit/chainlink-ccip/deployment/testhelpers"
18+
19+
"github.com/smartcontractkit/chainlink-deployments-framework/engine/test/environment"
20+
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
21+
"github.com/stretchr/testify/require"
22+
23+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_5_0/rmn_contract"
24+
25+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/utils/operations/contract"
26+
routerops1_2 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_2_0/operations/router"
27+
rmnops1_5 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/operations/rmn"
28+
rmnremoteops1_6 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_6_0/operations/rmn_remote"
29+
)
30+
31+
func TestFastCurse(t *testing.T) {
32+
chain1 := chainsel.TEST_90000001.Selector
33+
chain2 := chainsel.TEST_90000002.Selector
34+
env, err := environment.New(t.Context(),
35+
environment.WithEVMSimulated(t, []uint64{chain1, chain2}),
36+
)
37+
require.NoError(t, err)
38+
bundle := env.OperationsBundle
39+
// deploy RMN 1.5 on chain1 and RMN 1.6 on chain2, set up routers, etc.
40+
chain := env.BlockChains.EVMChains()[chain1]
41+
deployRMNOp, err := cldf_ops.ExecuteOperation(bundle, rmnops1_5.Deploy, chain, contract.DeployInput[rmnops1_5.ConstructorArgs]{
42+
TypeAndVersion: deployment.NewTypeAndVersion(rmnops1_5.ContractType, *semver.MustParse("1.5.0")),
43+
ChainSelector: chain.Selector,
44+
Args: rmnops1_5.ConstructorArgs{
45+
RMNConfig: rmn_contract.RMNConfig{
46+
BlessWeightThreshold: 2,
47+
CurseWeightThreshold: 2,
48+
// setting dummy voters
49+
Voters: []rmn_contract.RMNVoter{
50+
{
51+
BlessWeight: 2,
52+
CurseWeight: 2,
53+
BlessVoteAddr: utils.RandomAddress(),
54+
CurseVoteAddr: utils.RandomAddress(),
55+
},
56+
},
57+
},
58+
},
59+
})
60+
require.NoError(t, err)
61+
ds := datastore.NewMemoryDataStore()
62+
require.NoError(t, ds.Addresses().Add(datastore.AddressRef{
63+
Type: datastore.ContractType(rmnops1_5.ContractType),
64+
Version: semver.MustParse("1.5.0"),
65+
ChainSelector: chain1,
66+
Address: deployRMNOp.Output.Address,
67+
}))
68+
// deploy RMNRemote 1.6 on chain2
69+
chain = env.BlockChains.EVMChains()[chain2]
70+
deployRMNRemoteOp, err := cldf_ops.ExecuteOperation(bundle, rmnremoteops1_6.Deploy, chain, contract.DeployInput[rmnremoteops1_6.ConstructorArgs]{
71+
TypeAndVersion: deployment.NewTypeAndVersion(rmnremoteops1_6.ContractType, *semver.MustParse("1.6.0")),
72+
ChainSelector: chain.Selector,
73+
Args: rmnremoteops1_6.ConstructorArgs{
74+
LocalChainSelector: chain.Selector,
75+
LegacyRMN: utils.RandomAddress(),
76+
},
77+
})
78+
require.NoError(t, err)
79+
require.NoError(t, ds.Addresses().Add(datastore.AddressRef{
80+
Type: datastore.ContractType(rmnremoteops1_6.ContractType),
81+
Version: semver.MustParse("1.6.0"),
82+
ChainSelector: chain2,
83+
Address: deployRMNRemoteOp.Output.Address,
84+
}))
85+
// deploy router in both chains
86+
for _, sel := range []uint64{chain1, chain2} {
87+
evmChain := env.BlockChains.EVMChains()[sel]
88+
// mock wrapped native and rmnproxy address
89+
wNative := utils.RandomAddress()
90+
rmnProxy := utils.RandomAddress()
91+
92+
deployRouterOp, err := cldf_ops.ExecuteOperation(bundle, routerops1_2.Deploy, evmChain, contract.DeployInput[routerops1_2.ConstructorArgs]{
93+
ChainSelector: evmChain.Selector,
94+
TypeAndVersion: deployment.NewTypeAndVersion(routerops1_2.ContractType, *semver.MustParse("1.2.0")),
95+
Args: routerops1_2.ConstructorArgs{
96+
WrappedNative: wNative,
97+
RMNProxy: rmnProxy,
98+
},
99+
})
100+
require.NoError(t, err)
101+
require.NoError(t, ds.Addresses().Add(datastore.AddressRef{
102+
Type: datastore.ContractType(routerops1_2.ContractType),
103+
Version: semver.MustParse("1.2.0"),
104+
ChainSelector: sel,
105+
Address: deployRouterOp.Output.Address,
106+
}))
107+
routerAddr := deployRouterOp.Output.Address
108+
// add some dummy onramps to the router so that chain is supported,
109+
// on chain1, add chain2 as supported dest chain and vice versa
110+
onRamp := utils.RandomAddress()
111+
offRamp := utils.RandomAddress()
112+
var destChainSelector uint64
113+
if sel == chain1 {
114+
destChainSelector = chain2
115+
} else {
116+
destChainSelector = chain1
117+
}
118+
_, err = cldf_ops.ExecuteOperation(bundle, routerops1_2.ApplyRampUpdates, evmChain, contract.FunctionInput[routerops1_2.ApplyRampsUpdatesArgs]{
119+
Address: common.HexToAddress(routerAddr),
120+
ChainSelector: evmChain.Selector,
121+
Args: routerops1_2.ApplyRampsUpdatesArgs{
122+
OnRampUpdates: []routerops1_2.OnRamp{
123+
{
124+
DestChainSelector: destChainSelector,
125+
OnRamp: onRamp,
126+
},
127+
},
128+
OffRampAdds: []routerops1_2.OffRamp{
129+
{
130+
SourceChainSelector: destChainSelector,
131+
OffRamp: offRamp,
132+
},
133+
},
134+
},
135+
})
136+
require.NoError(t, err)
137+
}
138+
139+
// deploy mcms
140+
evmDeployer := &adapters.EVMDeployer{}
141+
dReg := deploy.GetRegistry()
142+
dReg.RegisterDeployer(chainsel.FamilyEVM, deploy.MCMSVersion, evmDeployer)
143+
cs := deploy.DeployMCMS(dReg)
144+
evmChain1 := env.BlockChains.EVMChains()[chain1]
145+
evmChain2 := env.BlockChains.EVMChains()[chain2]
146+
output, err := cs.Apply(*env, deploy.MCMSDeploymentConfig{
147+
Version: semver.MustParse("1.0.0"),
148+
Chains: map[uint64]deploy.MCMSDeploymentConfigPerChain{
149+
chain1: {
150+
Canceller: testhelpers.SingleGroupMCMS(),
151+
Bypasser: testhelpers.SingleGroupMCMS(),
152+
Proposer: testhelpers.SingleGroupMCMS(),
153+
TimelockMinDelay: big.NewInt(0),
154+
Qualifier: ptr.String("test"),
155+
TimelockAdmin: evmChain1.DeployerKey.From,
156+
},
157+
chain2: {
158+
Canceller: testhelpers.SingleGroupMCMS(),
159+
Bypasser: testhelpers.SingleGroupMCMS(),
160+
Proposer: testhelpers.SingleGroupMCMS(),
161+
TimelockMinDelay: big.NewInt(0),
162+
Qualifier: ptr.String("test"),
163+
TimelockAdmin: evmChain2.DeployerKey.From,
164+
},
165+
},
166+
})
167+
require.NoError(t, err)
168+
// store addresses in ds
169+
allAddrRefs, err := output.DataStore.Addresses().Fetch()
170+
require.NoError(t, err)
171+
for _, addrRef := range allAddrRefs {
172+
require.NoError(t, ds.Addresses().Add(addrRef))
173+
}
174+
175+
env.DataStore = ds.Seal()
176+
}

chains/evm/deployment/go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ replace (
88

99
// Make sure we're working with the latest chainlink-ccip
1010
github.com/smartcontractkit/chainlink-ccip => ../../../
11-
12-
// Make sure we're working with the latest chainlink-ccip/deployment
13-
github.com/smartcontractkit/chainlink-ccip/deployment => ../../../deployment
1411
)
1512

13+
replace github.com/smartcontractkit/chainlink-ccip/deployment => ../../../deployment
14+
1615
require (
1716
github.com/Masterminds/semver/v3 v3.4.0
1817
github.com/aws/smithy-go v1.22.5

chains/evm/deployment/v1_0_0/deployer.go renamed to chains/evm/deployment/v1_0_0/adapters/deployer.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package v1_0_0
1+
package adapters
22

33
import (
44
"fmt"
@@ -9,12 +9,13 @@ import (
99
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
1010
cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations"
1111

12-
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/utils/operations/contract"
13-
ops "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/operations"
14-
seq "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/sequences"
1512
ccipapi "github.com/smartcontractkit/chainlink-ccip/deployment/deploy"
1613
"github.com/smartcontractkit/chainlink-ccip/deployment/utils"
1714
sequtil "github.com/smartcontractkit/chainlink-ccip/deployment/utils/sequences"
15+
16+
"github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/utils/operations/contract"
17+
ops "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/operations"
18+
seq "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/sequences"
1819
)
1920

2021
type EVMDeployer struct{}
@@ -36,6 +37,7 @@ func (d *EVMDeployer) DeployMCMS() *cldf_ops.Sequence[ccipapi.MCMSDeploymentConf
3637
}
3738
// deploy and configure the proposer MCM
3839
seqInput := seq.SeqMCMSDeploymentCfg{
40+
ChainSelector: in.ChainSelector,
3941
ContractType: utils.ProposerManyChainMultisig,
4042
MCMConfig: &in.Proposer,
4143
Qualifier: in.Qualifier,
@@ -53,6 +55,7 @@ func (d *EVMDeployer) DeployMCMS() *cldf_ops.Sequence[ccipapi.MCMSDeploymentConf
5355
proposerAddr := report.Output.Addresses[0]
5456
// deploy and configure the bypasser MCM
5557
seqInput = seq.SeqMCMSDeploymentCfg{
58+
ChainSelector: in.ChainSelector,
5659
ContractType: utils.BypasserManyChainMultisig,
5760
MCMConfig: &in.Bypasser,
5861
Qualifier: in.Qualifier,
@@ -70,6 +73,7 @@ func (d *EVMDeployer) DeployMCMS() *cldf_ops.Sequence[ccipapi.MCMSDeploymentConf
7073
bypasserAddr := report.Output.Addresses[0]
7174
// deploy and configure the canceller MCM
7275
seqInput = seq.SeqMCMSDeploymentCfg{
76+
ChainSelector: in.ChainSelector,
7377
ContractType: utils.CancellerManyChainMultisig,
7478
MCMConfig: &in.Canceller,
7579
Qualifier: in.Qualifier,
@@ -86,7 +90,7 @@ func (d *EVMDeployer) DeployMCMS() *cldf_ops.Sequence[ccipapi.MCMSDeploymentConf
8690
output.Addresses = append(output.Addresses, report.Output.Addresses...)
8791
cancellerAddr := report.Output.Addresses[0]
8892
// deploy timelock
89-
deployReport, err := cldf_ops.ExecuteOperation(b, ops.OpDeployTimelock, evmChain, contract.DeployInput[ops.OpDeployTimelockInput]{
93+
timelockAddr, err := contract.MaybeDeployContract(b, ops.OpDeployTimelock, evmChain, contract.DeployInput[ops.OpDeployTimelockInput]{
9094
ChainSelector: in.ChainSelector,
9195
Qualifier: in.Qualifier,
9296
TypeAndVersion: cldf.NewTypeAndVersion(utils.RBACTimelock, *semver.MustParse("1.0.0")),
@@ -99,36 +103,33 @@ func (d *EVMDeployer) DeployMCMS() *cldf_ops.Sequence[ccipapi.MCMSDeploymentConf
99103
// Add Executor later after call proxy is deployed
100104
Executors: []common.Address{},
101105
},
102-
})
106+
}, in.ExistingAddresses)
103107
if err != nil {
104108
return sequtil.OnChainOutput{}, fmt.Errorf("failed to deploy timelock on chain %d: %w", in.ChainSelector, err)
105109
}
106-
output.Addresses = append(output.Addresses, deployReport.Output)
107-
timelockAddr := deployReport.Output.Address
108110
b.Logger.Infof("Deployed Timelock at address %s on chain %s", timelockAddr, evmChain.Name)
109111
// deploy call proxy with timelock
110-
callProxyRep, err := cldf_ops.ExecuteOperation(b, ops.OpDeployCallProxy, evmChain, contract.DeployInput[ops.OpDeployCallProxyInput]{
112+
callProxyAddr, err := contract.MaybeDeployContract(b, ops.OpDeployCallProxy, evmChain, contract.DeployInput[ops.OpDeployCallProxyInput]{
111113
ChainSelector: in.ChainSelector,
112114
Qualifier: in.Qualifier,
113115
TypeAndVersion: cldf.NewTypeAndVersion(utils.CallProxy, *semver.MustParse("1.0.0")),
114116
Args: ops.OpDeployCallProxyInput{
115-
TimelockAddress: common.HexToAddress(timelockAddr),
117+
TimelockAddress: common.HexToAddress(timelockAddr.Address),
116118
},
117-
})
119+
}, in.ExistingAddresses)
118120
if err != nil {
119121
return sequtil.OnChainOutput{}, fmt.Errorf("failed to deploy call proxy on chain %d: %w", in.ChainSelector, err)
120122
}
121-
output.Addresses = append(output.Addresses, callProxyRep.Output)
122-
callProxyAddr := callProxyRep.Output.Address
123123
b.Logger.Infof("Deployed Call Proxy at address %s on chain %s", callProxyAddr, evmChain.Name)
124+
output.Addresses = append(output.Addresses, timelockAddr, callProxyAddr)
124125

125126
// now that call proxy is deployed, we can add it as executor to the timelock
126127
_, err = cldf_ops.ExecuteOperation(b, ops.OpGrantRoleTimelock, evmChain, contract.FunctionInput[ops.OpGrantRoleTimelockInput]{
127128
ChainSelector: in.ChainSelector,
128-
Address: common.HexToAddress(timelockAddr),
129+
Address: common.HexToAddress(timelockAddr.Address),
129130
Args: ops.OpGrantRoleTimelockInput{
130131
RoleID: ops.EXECUTOR_ROLE.ID,
131-
Account: common.HexToAddress(callProxyAddr),
132+
Account: common.HexToAddress(callProxyAddr.Address),
132133
},
133134
})
134135
if err != nil {

0 commit comments

Comments
 (0)