From 452a99e6a282a5c75d978631754e69f69be92e94 Mon Sep 17 00:00:00 2001 From: Connor Stein Date: Fri, 15 Nov 2024 13:25:59 -0500 Subject: [PATCH] Common deploy helper (#15268) * Common deploy * Can remove interface * Helpers --- deployment/ccip/deploy.go | 169 +++++++++------------------ deployment/ccip/deploy_home_chain.go | 26 ++--- deployment/ccip/test_helpers.go | 25 ++-- deployment/go.mod | 1 + deployment/helpers.go | 44 +++++++ 5 files changed, 123 insertions(+), 142 deletions(-) diff --git a/deployment/ccip/deploy.go b/deployment/ccip/deploy.go index 77df3aab60f..8a33cf0d26d 100644 --- a/deployment/ccip/deploy.go +++ b/deployment/ccip/deploy.go @@ -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" @@ -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" ) @@ -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 @@ -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, } }) @@ -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 @@ -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, @@ -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, } }) @@ -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, } }) @@ -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, @@ -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, } }) @@ -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, } }) @@ -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, } }) @@ -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, } }) @@ -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, } }) @@ -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, } }) @@ -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, } }) @@ -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, } }) @@ -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, } }) @@ -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, @@ -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, } }) @@ -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, @@ -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, } }) @@ -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, @@ -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, } }) diff --git a/deployment/ccip/deploy_home_chain.go b/deployment/ccip/deploy_home_chain.go index c9c88d35328..d17a501783d 100644 --- a/deployment/ccip/deploy_home_chain.go +++ b/deployment/ccip/deploy_home_chain.go @@ -87,30 +87,30 @@ func MustABIEncode(abiString string, args ...interface{}) []byte { } // DeployCapReg deploys the CapabilitiesRegistry contract if it is not already deployed -// and returns a ContractDeploy struct with the address and contract instance. +// and returns a deployment.ContractDeploy struct with the address and contract instance. func DeployCapReg( lggr logger.Logger, state CCIPOnChainState, ab deployment.AddressBook, chain deployment.Chain, -) (*ContractDeploy[*capabilities_registry.CapabilitiesRegistry], error) { +) (*deployment.ContractDeploy[*capabilities_registry.CapabilitiesRegistry], error) { homeChainState, exists := state.Chains[chain.Selector] if exists { cr := homeChainState.CapabilityRegistry if cr != nil { lggr.Infow("Found CapabilitiesRegistry in chain state", "address", cr.Address().String()) - return &ContractDeploy[*capabilities_registry.CapabilitiesRegistry]{ + return &deployment.ContractDeploy[*capabilities_registry.CapabilitiesRegistry]{ Address: cr.Address(), Contract: cr, Tv: deployment.NewTypeAndVersion(CapabilitiesRegistry, deployment.Version1_0_0), }, nil } } - capReg, err := deployContract(lggr, chain, ab, - func(chain deployment.Chain) ContractDeploy[*capabilities_registry.CapabilitiesRegistry] { + capReg, err := deployment.DeployContract(lggr, chain, ab, + func(chain deployment.Chain) deployment.ContractDeploy[*capabilities_registry.CapabilitiesRegistry] { crAddr, tx, cr, err2 := capabilities_registry.DeployCapabilitiesRegistry( chain.DeployerKey, chain.Client, ) - return ContractDeploy[*capabilities_registry.CapabilitiesRegistry]{ + return deployment.ContractDeploy[*capabilities_registry.CapabilitiesRegistry]{ Address: crAddr, Contract: cr, Tv: deployment.NewTypeAndVersion(CapabilitiesRegistry, deployment.Version1_0_0), Tx: tx, Err: err2, } }) @@ -130,7 +130,7 @@ func DeployHomeChain( rmnHomeDynamic rmn_home.RMNHomeDynamicConfig, nodeOps []capabilities_registry.CapabilitiesRegistryNodeOperator, nodeP2PIDsPerNodeOpAdmin map[string][][32]byte, -) (*ContractDeploy[*capabilities_registry.CapabilitiesRegistry], error) { +) (*deployment.ContractDeploy[*capabilities_registry.CapabilitiesRegistry], error) { // load existing state state, err := LoadOnchainState(e) if err != nil { @@ -143,15 +143,15 @@ func DeployHomeChain( } lggr.Infow("deployed/connected to capreg", "addr", capReg.Address) - ccipHome, err := deployContract( + ccipHome, err := deployment.DeployContract( lggr, chain, ab, - func(chain deployment.Chain) ContractDeploy[*ccip_home.CCIPHome] { + func(chain deployment.Chain) deployment.ContractDeploy[*ccip_home.CCIPHome] { ccAddr, tx, cc, err2 := ccip_home.DeployCCIPHome( chain.DeployerKey, chain.Client, capReg.Address, ) - return ContractDeploy[*ccip_home.CCIPHome]{ + return deployment.ContractDeploy[*ccip_home.CCIPHome]{ Address: ccAddr, Tv: deployment.NewTypeAndVersion(CCIPHome, deployment.Version1_6_0_dev), Tx: tx, Err: err2, Contract: cc, } }) @@ -161,14 +161,14 @@ func DeployHomeChain( } lggr.Infow("deployed CCIPHome", "addr", ccipHome.Address) - rmnHome, err := deployContract( + rmnHome, err := deployment.DeployContract( lggr, chain, ab, - func(chain deployment.Chain) ContractDeploy[*rmn_home.RMNHome] { + func(chain deployment.Chain) deployment.ContractDeploy[*rmn_home.RMNHome] { rmnAddr, tx, rmn, err2 := rmn_home.DeployRMNHome( chain.DeployerKey, chain.Client, ) - return ContractDeploy[*rmn_home.RMNHome]{ + return deployment.ContractDeploy[*rmn_home.RMNHome]{ Address: rmnAddr, Tv: deployment.NewTypeAndVersion(RMNHome, deployment.Version1_6_0_dev), Tx: tx, Err: err2, Contract: rmn, } }, diff --git a/deployment/ccip/test_helpers.go b/deployment/ccip/test_helpers.go index f12a475bc2f..70be57b2f38 100644 --- a/deployment/ccip/test_helpers.go +++ b/deployment/ccip/test_helpers.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/pkg/errors" + cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" commonutils "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" @@ -360,7 +361,7 @@ var ( func DeployFeeds(lggr logger.Logger, ab deployment.AddressBook, chain deployment.Chain) (map[string]common.Address, error) { linkTV := deployment.NewTypeAndVersion(PriceFeed, deployment.Version1_0_0) - mockLinkFeed := func(chain deployment.Chain) ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface] { + mockLinkFeed := func(chain deployment.Chain) deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface] { linkFeed, tx, _, err1 := mock_v3_aggregator_contract.DeployMockV3Aggregator( chain.DeployerKey, chain.Client, @@ -369,12 +370,12 @@ func DeployFeeds(lggr logger.Logger, ab deployment.AddressBook, chain deployment ) aggregatorCr, err2 := aggregator_v3_interface.NewAggregatorV3Interface(linkFeed, chain.Client) - return ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface]{ + return deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface]{ Address: linkFeed, Contract: aggregatorCr, Tv: linkTV, Tx: tx, Err: multierr.Append(err1, err2), } } - mockWethFeed := func(chain deployment.Chain) ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface] { + mockWethFeed := func(chain deployment.Chain) deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface] { wethFeed, tx, _, err1 := mock_ethusd_aggregator_wrapper.DeployMockETHUSDAggregator( chain.DeployerKey, chain.Client, @@ -382,7 +383,7 @@ func DeployFeeds(lggr logger.Logger, ab deployment.AddressBook, chain deployment ) aggregatorCr, err2 := aggregator_v3_interface.NewAggregatorV3Interface(wethFeed, chain.Client) - return ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface]{ + return deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface]{ Address: wethFeed, Contract: aggregatorCr, Tv: linkTV, Tx: tx, Err: multierr.Append(err1, err2), } } @@ -409,11 +410,11 @@ func deploySingleFeed( lggr logger.Logger, ab deployment.AddressBook, chain deployment.Chain, - deployFunc func(deployment.Chain) ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface], + deployFunc func(deployment.Chain) deployment.ContractDeploy[*aggregator_v3_interface.AggregatorV3Interface], symbol TokenSymbol, ) (common.Address, string, error) { //tokenTV := deployment.NewTypeAndVersion(PriceFeed, deployment.Version1_0_0) - mockTokenFeed, err := deployContract(lggr, chain, ab, deployFunc) + mockTokenFeed, err := deployment.DeployContract(lggr, chain, ab, deployFunc) if err != nil { lggr.Errorw("Failed to deploy token feed", "err", err, "symbol", symbol) return common.Address{}, "", err @@ -677,8 +678,8 @@ func deployTransferTokenOneEnd( } } - tokenContract, err := deployContract(lggr, chain, addressBook, - func(chain deployment.Chain) ContractDeploy[*burn_mint_erc677.BurnMintERC677] { + tokenContract, err := deployment.DeployContract(lggr, chain, addressBook, + func(chain deployment.Chain) deployment.ContractDeploy[*burn_mint_erc677.BurnMintERC677] { USDCTokenAddr, tx, token, err2 := burn_mint_erc677.DeployBurnMintERC677( chain.DeployerKey, chain.Client, @@ -687,7 +688,7 @@ func deployTransferTokenOneEnd( 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]{ USDCTokenAddr, token, tx, deployment.NewTypeAndVersion(BurnMintToken, deployment.Version1_0_0), err2, } }) @@ -705,8 +706,8 @@ func deployTransferTokenOneEnd( return nil, nil, err } - tokenPool, err := deployContract(lggr, chain, addressBook, - func(chain deployment.Chain) ContractDeploy[*burn_mint_token_pool.BurnMintTokenPool] { + tokenPool, err := deployment.DeployContract(lggr, chain, addressBook, + func(chain deployment.Chain) deployment.ContractDeploy[*burn_mint_token_pool.BurnMintTokenPool] { tokenPoolAddress, tx, tokenPoolContract, err2 := burn_mint_token_pool.DeployBurnMintTokenPool( chain.DeployerKey, chain.Client, @@ -715,7 +716,7 @@ func deployTransferTokenOneEnd( common.HexToAddress(rmnAddress), common.HexToAddress(routerAddress), ) - return ContractDeploy[*burn_mint_token_pool.BurnMintTokenPool]{ + return deployment.ContractDeploy[*burn_mint_token_pool.BurnMintTokenPool]{ tokenPoolAddress, tokenPoolContract, tx, deployment.NewTypeAndVersion(BurnMintTokenPool, deployment.Version1_0_0), err2, } }) diff --git a/deployment/go.mod b/deployment/go.mod index 73e23aa83f3..ed05d136993 100644 --- a/deployment/go.mod +++ b/deployment/go.mod @@ -533,4 +533,5 @@ replace ( github.com/btcsuite/btcd/btcec/v2 => github.com/btcsuite/btcd/btcec/v2 v2.3.2 // replicating the replace directive on cosmos SDK github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 + github.com/sourcegraph/sourcegraph/lib => github.com/sourcegraph/sourcegraph-public-snapshot/lib v0.0.0-20240822153003-c864f15af264 ) diff --git a/deployment/helpers.go b/deployment/helpers.go index 420e9e03f06..1f0dc3064d6 100644 --- a/deployment/helpers.go +++ b/deployment/helpers.go @@ -15,6 +15,8 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/pkg/errors" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" ) // OCRSecrets are used to disseminate a shared secret to OCR nodes @@ -108,3 +110,45 @@ func ParseErrorFromABI(errorString string, contractABI string) (string, error) { } return "", errors.New("error not found in ABI") } + +// ContractDeploy represents the result of an EVM contract deployment +// via an abigen Go binding. It contains all the return values +// as they are useful in different ways. +type ContractDeploy[C any] struct { + Address common.Address // We leave this incase a Go binding doesn't have Address() + Contract C // Expected to be a Go binding + Tx *types.Transaction // Incase the caller needs for example tx hash info for + Tv TypeAndVersion + Err error +} + +// DeployContract deploys an EVM contract and +// records the address in the provided address book +// if the deployment was confirmed onchain. +// Deploying and saving the address is a very common pattern +// so this helps to reduce boilerplate. +// It returns an error if the deployment failed, the tx was not +// confirmed or the address could not be saved. +func DeployContract[C any]( + lggr logger.Logger, + chain Chain, + addressBook AddressBook, + deploy func(chain 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 +}