Skip to content

Commit

Permalink
Common deploy helper (#15268)
Browse files Browse the repository at this point in the history
* Common deploy

* Can remove interface

* Helpers
  • Loading branch information
connorwstein authored Nov 15, 2024
1 parent d691d59 commit 452a99e
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 142 deletions.
169 changes: 52 additions & 117 deletions deployment/ccip/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/smartcontractkit/ccip-owner-contracts/pkg/config"
owner_helpers "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers"

"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/registry_module_owner_custom"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_home"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/aggregator_v3_interface"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/erc20"

"github.com/smartcontractkit/chainlink/deployment"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/burn_mint_token_pool"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/maybe_revert_message_receiver"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/nonce_manager"
Expand All @@ -32,7 +27,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/weth9"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/burn_mint_erc677"
)

Expand Down Expand Up @@ -66,65 +60,6 @@ var (
BurnMintTokenPool deployment.ContractType = "BurnMintTokenPool"
)

type Contracts interface {
*capabilities_registry.CapabilitiesRegistry |
*rmn_proxy_contract.RMNProxyContract |
*ccip_home.CCIPHome |
*rmn_home.RMNHome |
*nonce_manager.NonceManager |
*fee_quoter.FeeQuoter |
*router.Router |
*token_admin_registry.TokenAdminRegistry |
*registry_module_owner_custom.RegistryModuleOwnerCustom |
*weth9.WETH9 |
*rmn_remote.RMNRemote |
*owner_helpers.ManyChainMultiSig |
*owner_helpers.RBACTimelock |
*offramp.OffRamp |
*onramp.OnRamp |
*burn_mint_erc677.BurnMintERC677 |
*burn_mint_token_pool.BurnMintTokenPool |
*maybe_revert_message_receiver.MaybeRevertMessageReceiver |
*aggregator_v3_interface.AggregatorV3Interface |
*erc20.ERC20
}

type ContractDeploy[C Contracts] struct {
// We just keep all the deploy return values
// since some will be empty if there's an error.
Address common.Address
Contract C
Tx *types.Transaction
Tv deployment.TypeAndVersion
Err error
}

// TODO: pull up to general deployment pkg somehow
// without exposing all product specific contracts?
func deployContract[C Contracts](
lggr logger.Logger,
chain deployment.Chain,
addressBook deployment.AddressBook,
deploy func(chain deployment.Chain) ContractDeploy[C],
) (*ContractDeploy[C], error) {
contractDeploy := deploy(chain)
if contractDeploy.Err != nil {
lggr.Errorw("Failed to deploy contract", "err", contractDeploy.Err)
return nil, contractDeploy.Err
}
_, err := chain.Confirm(contractDeploy.Tx)
if err != nil {
lggr.Errorw("Failed to confirm deployment", "err", err)
return nil, err
}
err = addressBook.Save(chain.Selector, contractDeploy.Address.String(), contractDeploy.Tv)
if err != nil {
lggr.Errorw("Failed to save contract address", "err", err)
return nil, err
}
return &contractDeploy, nil
}

type DeployCCIPContractConfig struct {
HomeChainSel uint64
FeedChainSel uint64
Expand Down Expand Up @@ -268,15 +203,15 @@ func DeployMCMSWithConfig(
chain deployment.Chain,
ab deployment.AddressBook,
mcmConfig config.Config,
) (*ContractDeploy[*owner_helpers.ManyChainMultiSig], error) {
) (*deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig], error) {
groupQuorums, groupParents, signerAddresses, signerGroups := mcmConfig.ExtractSetConfigInputs()
mcm, err := deployContract(lggr, chain, ab,
func(chain deployment.Chain) ContractDeploy[*owner_helpers.ManyChainMultiSig] {
mcm, err := deployment.DeployContract(lggr, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig] {
mcmAddr, tx, mcm, err2 := owner_helpers.DeployManyChainMultiSig(
chain.DeployerKey,
chain.Client,
)
return ContractDeploy[*owner_helpers.ManyChainMultiSig]{
return deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig]{
mcmAddr, mcm, tx, deployment.NewTypeAndVersion(contractType, deployment.Version1_0_0), err2,
}
})
Expand All @@ -299,11 +234,11 @@ func DeployMCMSWithConfig(
}

type MCMSContracts struct {
Admin *ContractDeploy[*owner_helpers.ManyChainMultiSig]
Canceller *ContractDeploy[*owner_helpers.ManyChainMultiSig]
Bypasser *ContractDeploy[*owner_helpers.ManyChainMultiSig]
Proposer *ContractDeploy[*owner_helpers.ManyChainMultiSig]
Timelock *ContractDeploy[*owner_helpers.RBACTimelock]
Admin *deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig]
Canceller *deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig]
Bypasser *deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig]
Proposer *deployment.ContractDeploy[*owner_helpers.ManyChainMultiSig]
Timelock *deployment.ContractDeploy[*owner_helpers.RBACTimelock]
}

// DeployMCMSContracts deploys the MCMS contracts for the given configuration
Expand Down Expand Up @@ -331,8 +266,8 @@ func DeployMCMSContracts(
return nil, err
}

timelock, err := deployContract(lggr, chain, ab,
func(chain deployment.Chain) ContractDeploy[*owner_helpers.RBACTimelock] {
timelock, err := deployment.DeployContract(lggr, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*owner_helpers.RBACTimelock] {
timelock, tx2, cc, err2 := owner_helpers.DeployRBACTimelock(
chain.DeployerKey,
chain.Client,
Expand All @@ -343,7 +278,7 @@ func DeployMCMSContracts(
[]common.Address{canceller.Address}, // cancellers
[]common.Address{bypasser.Address}, // bypassers
)
return ContractDeploy[*owner_helpers.RBACTimelock]{
return deployment.ContractDeploy[*owner_helpers.RBACTimelock]{
timelock, cc, tx2, deployment.NewTypeAndVersion(RBACTimelock, deployment.Version1_0_0), err2,
}
})
Expand Down Expand Up @@ -374,13 +309,13 @@ func DeployFeeTokensToChains(lggr logger.Logger, ab deployment.AddressBook, chai
// DeployFeeTokens deploys link and weth9. This is _usually_ for test environments only,
// real environments they tend to already exist, but sometimes we still have to deploy them to real chains.
func DeployFeeTokens(lggr logger.Logger, chain deployment.Chain, ab deployment.AddressBook) (FeeTokenContracts, error) {
weth9, err := deployContract(lggr, chain, ab,
func(chain deployment.Chain) ContractDeploy[*weth9.WETH9] {
weth9, err := deployment.DeployContract(lggr, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*weth9.WETH9] {
weth9Addr, tx2, weth9c, err2 := weth9.DeployWETH9(
chain.DeployerKey,
chain.Client,
)
return ContractDeploy[*weth9.WETH9]{
return deployment.ContractDeploy[*weth9.WETH9]{
weth9Addr, weth9c, tx2, deployment.NewTypeAndVersion(WETH9, deployment.Version1_0_0), err2,
}
})
Expand All @@ -390,8 +325,8 @@ func DeployFeeTokens(lggr logger.Logger, chain deployment.Chain, ab deployment.A
}
lggr.Infow("deployed weth9", "addr", weth9.Address)

linkToken, err := deployContract(lggr, chain, ab,
func(chain deployment.Chain) ContractDeploy[*burn_mint_erc677.BurnMintERC677] {
linkToken, err := deployment.DeployContract(lggr, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*burn_mint_erc677.BurnMintERC677] {
linkTokenAddr, tx2, linkToken, err2 := burn_mint_erc677.DeployBurnMintERC677(
chain.DeployerKey,
chain.Client,
Expand All @@ -400,7 +335,7 @@ func DeployFeeTokens(lggr logger.Logger, chain deployment.Chain, ab deployment.A
uint8(18),
big.NewInt(0).Mul(big.NewInt(1e9), big.NewInt(1e18)),
)
return ContractDeploy[*burn_mint_erc677.BurnMintERC677]{
return deployment.ContractDeploy[*burn_mint_erc677.BurnMintERC677]{
linkTokenAddr, linkToken, tx2, deployment.NewTypeAndVersion(LinkToken, deployment.Version1_0_0), err2,
}
})
Expand Down Expand Up @@ -432,14 +367,14 @@ func DeployChainContracts(
if err != nil {
return err
}
ccipReceiver, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver] {
ccipReceiver, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver] {
receiverAddr, tx, receiver, err2 := maybe_revert_message_receiver.DeployMaybeRevertMessageReceiver(
chain.DeployerKey,
chain.Client,
false,
)
return ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver]{
return deployment.ContractDeploy[*maybe_revert_message_receiver.MaybeRevertMessageReceiver]{
receiverAddr, receiver, tx, deployment.NewTypeAndVersion(CCIPReceiver, deployment.Version1_0_0), err2,
}
})
Expand All @@ -450,14 +385,14 @@ func DeployChainContracts(
e.Logger.Infow("deployed receiver", "addr", ccipReceiver.Address)

// TODO: Correctly configure RMN remote.
rmnRemote, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*rmn_remote.RMNRemote] {
rmnRemote, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*rmn_remote.RMNRemote] {
rmnRemoteAddr, tx, rmnRemote, err2 := rmn_remote.DeployRMNRemote(
chain.DeployerKey,
chain.Client,
chain.Selector,
)
return ContractDeploy[*rmn_remote.RMNRemote]{
return deployment.ContractDeploy[*rmn_remote.RMNRemote]{
rmnRemoteAddr, rmnRemote, tx, deployment.NewTypeAndVersion(RMNRemote, deployment.Version1_6_0_dev), err2,
}
})
Expand Down Expand Up @@ -486,14 +421,14 @@ func DeployChainContracts(
return err
}

rmnProxy, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*rmn_proxy_contract.RMNProxyContract] {
rmnProxy, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract] {
rmnProxyAddr, tx2, rmnProxy, err2 := rmn_proxy_contract.DeployRMNProxyContract(
chain.DeployerKey,
chain.Client,
rmnRemote.Address,
)
return ContractDeploy[*rmn_proxy_contract.RMNProxyContract]{
return deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract]{
rmnProxyAddr, rmnProxy, tx2, deployment.NewTypeAndVersion(ARMProxy, deployment.Version1_0_0), err2,
}
})
Expand All @@ -503,15 +438,15 @@ func DeployChainContracts(
}
e.Logger.Infow("deployed rmnProxy", "addr", rmnProxy.Address)

routerContract, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*router.Router] {
routerContract, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*router.Router] {
routerAddr, tx2, routerC, err2 := router.DeployRouter(
chain.DeployerKey,
chain.Client,
contractConfig.Weth9.Address(),
rmnProxy.Address,
)
return ContractDeploy[*router.Router]{
return deployment.ContractDeploy[*router.Router]{
routerAddr, routerC, tx2, deployment.NewTypeAndVersion(Router, deployment.Version1_2_0), err2,
}
})
Expand All @@ -521,15 +456,15 @@ func DeployChainContracts(
}
e.Logger.Infow("deployed router", "addr", routerContract.Address)

testRouterContract, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*router.Router] {
testRouterContract, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*router.Router] {
routerAddr, tx2, routerC, err2 := router.DeployRouter(
chain.DeployerKey,
chain.Client,
contractConfig.Weth9.Address(),
rmnProxy.Address,
)
return ContractDeploy[*router.Router]{
return deployment.ContractDeploy[*router.Router]{
routerAddr, routerC, tx2, deployment.NewTypeAndVersion(TestRouter, deployment.Version1_2_0), err2,
}
})
Expand All @@ -539,12 +474,12 @@ func DeployChainContracts(
}
e.Logger.Infow("deployed test router", "addr", testRouterContract.Address)

tokenAdminRegistry, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*token_admin_registry.TokenAdminRegistry] {
tokenAdminRegistry, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*token_admin_registry.TokenAdminRegistry] {
tokenAdminRegistryAddr, tx2, tokenAdminRegistry, err2 := token_admin_registry.DeployTokenAdminRegistry(
chain.DeployerKey,
chain.Client)
return ContractDeploy[*token_admin_registry.TokenAdminRegistry]{
return deployment.ContractDeploy[*token_admin_registry.TokenAdminRegistry]{
tokenAdminRegistryAddr, tokenAdminRegistry, tx2, deployment.NewTypeAndVersion(TokenAdminRegistry, deployment.Version1_5_0), err2,
}
})
Expand All @@ -554,13 +489,13 @@ func DeployChainContracts(
}
e.Logger.Infow("deployed tokenAdminRegistry", "addr", tokenAdminRegistry)

customRegistryModule, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*registry_module_owner_custom.RegistryModuleOwnerCustom] {
customRegistryModule, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*registry_module_owner_custom.RegistryModuleOwnerCustom] {
regModAddr, tx2, regMod, err2 := registry_module_owner_custom.DeployRegistryModuleOwnerCustom(
chain.DeployerKey,
chain.Client,
tokenAdminRegistry.Address)
return ContractDeploy[*registry_module_owner_custom.RegistryModuleOwnerCustom]{
return deployment.ContractDeploy[*registry_module_owner_custom.RegistryModuleOwnerCustom]{
regModAddr, regMod, tx2, deployment.NewTypeAndVersion(RegistryModule, deployment.Version1_5_0), err2,
}
})
Expand All @@ -584,14 +519,14 @@ func DeployChainContracts(

e.Logger.Infow("assigned registry module on token admin registry")

nonceManager, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*nonce_manager.NonceManager] {
nonceManager, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*nonce_manager.NonceManager] {
nonceManagerAddr, tx2, nonceManager, err2 := nonce_manager.DeployNonceManager(
chain.DeployerKey,
chain.Client,
[]common.Address{}, // Need to add onRamp after
)
return ContractDeploy[*nonce_manager.NonceManager]{
return deployment.ContractDeploy[*nonce_manager.NonceManager]{
nonceManagerAddr, nonceManager, tx2, deployment.NewTypeAndVersion(NonceManager, deployment.Version1_6_0_dev), err2,
}
})
Expand All @@ -601,8 +536,8 @@ func DeployChainContracts(
}
e.Logger.Infow("Deployed nonce manager", "addr", nonceManager.Address)

feeQuoter, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*fee_quoter.FeeQuoter] {
feeQuoter, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*fee_quoter.FeeQuoter] {
prAddr, tx2, pr, err2 := fee_quoter.DeployFeeQuoter(
chain.DeployerKey,
chain.Client,
Expand All @@ -627,7 +562,7 @@ func DeployChainContracts(
},
[]fee_quoter.FeeQuoterDestChainConfigArgs{},
)
return ContractDeploy[*fee_quoter.FeeQuoter]{
return deployment.ContractDeploy[*fee_quoter.FeeQuoter]{
prAddr, pr, tx2, deployment.NewTypeAndVersion(FeeQuoter, deployment.Version1_6_0_dev), err2,
}
})
Expand All @@ -637,8 +572,8 @@ func DeployChainContracts(
}
e.Logger.Infow("Deployed fee quoter", "addr", feeQuoter.Address)

onRamp, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*onramp.OnRamp] {
onRamp, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*onramp.OnRamp] {
onRampAddr, tx2, onRamp, err2 := onramp.DeployOnRamp(
chain.DeployerKey,
chain.Client,
Expand All @@ -654,7 +589,7 @@ func DeployChainContracts(
},
[]onramp.OnRampDestChainConfigArgs{},
)
return ContractDeploy[*onramp.OnRamp]{
return deployment.ContractDeploy[*onramp.OnRamp]{
onRampAddr, onRamp, tx2, deployment.NewTypeAndVersion(OnRamp, deployment.Version1_6_0_dev), err2,
}
})
Expand All @@ -664,8 +599,8 @@ func DeployChainContracts(
}
e.Logger.Infow("Deployed onramp", "addr", onRamp.Address)

offRamp, err := deployContract(e.Logger, chain, ab,
func(chain deployment.Chain) ContractDeploy[*offramp.OffRamp] {
offRamp, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*offramp.OffRamp] {
offRampAddr, tx2, offRamp, err2 := offramp.DeployOffRamp(
chain.DeployerKey,
chain.Client,
Expand All @@ -682,7 +617,7 @@ func DeployChainContracts(
},
[]offramp.OffRampSourceChainConfigArgs{},
)
return ContractDeploy[*offramp.OffRamp]{
return deployment.ContractDeploy[*offramp.OffRamp]{
offRampAddr, offRamp, tx2, deployment.NewTypeAndVersion(OffRamp, deployment.Version1_6_0_dev), err2,
}
})
Expand Down
Loading

0 comments on commit 452a99e

Please sign in to comment.