Skip to content

Commit

Permalink
Common deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Nov 15, 2024
1 parent cb9c185 commit a4e1d3d
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 101 deletions.
139 changes: 51 additions & 88 deletions deployment/ccip/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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"

Expand Down Expand Up @@ -89,42 +88,6 @@ type Contracts interface {
*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 +231,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 +262,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 +294,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 +306,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 +337,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 +353,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 +363,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 +395,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 +413,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 +449,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 +466,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 +484,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 +502,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 +517,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 +547,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 +564,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 +590,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 +600,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 +617,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 +627,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 +645,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 a4e1d3d

Please sign in to comment.