Skip to content

Commit

Permalink
Start on more contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Aug 1, 2024
1 parent d9729c3 commit 75916f8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 22 deletions.
99 changes: 81 additions & 18 deletions core/capabilities/ccip/deployment/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,117 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/v2/core/environment"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/arm_proxy_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_arm_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry"
)

// TODO: pull up to environment pkg
func deployContract(
lggr logger.Logger,
deploy func() (string, common.Hash, error),
deploy func() (common.Address, common.Hash, error),
confirm func(common.Hash) error,
save func(string) error,
) error {
save func(address common.Address) error,
) (common.Address, error) {
contractAddr, tx, err := deploy()
if err != nil {
lggr.Errorw("Failed to deploy contract", "err", err)
return err
return common.Address{}, err
}
err = confirm(tx)
if err != nil {
lggr.Errorw("Failed to confirm deployment", "err", err)
return err
return common.Address{}, err
}
err = save(contractAddr)
if err != nil {
lggr.Errorw("Failed to save contract address", "err", err)
return err
return common.Address{}, err
}
return nil
return contractAddr, nil
}

// TODO: Likely we'll want to further parameterize the deployment
// For example a list of contracts to skip deploying if they already exist.
// Or mock vs real RMN.
func DeployCCIPContracts(e environment.Environment) error {
for _, chain := range e.Chains {
// For example deploy token admin registry to all chains
// And save the address
err := deployContract(e.Logger,
func() (string, common.Hash, error) {
saveToChain := func(addr common.Address) error {
return e.AddressBook.Save(chain.Selector, addr.String())
}

// TODO: Still waiting for RMNRemote/RMNHome contracts etc.
mockARM, err := deployContract(e.Logger,
func() (common.Address, common.Hash, error) {
mockARM, tx, _, err := mock_arm_contract.DeployMockARMContract(
chain.DeployerKey,
chain.Client,
)
return mockARM, tx.Hash(), err
}, chain.Confirm, saveToChain)
if err != nil {
e.Logger.Errorw("Failed to deploy mockARM", "err", err)
return err
}
e.Logger.Infow("deployed mockARM", "addr", mockARM)

armProxy, err := deployContract(e.Logger,
func() (common.Address, common.Hash, error) {
mockARM, tx, _, err := arm_proxy_contract.DeployARMProxyContract(
chain.DeployerKey,
chain.Client,
mockARM,
)
return mockARM, tx.Hash(), err
}, chain.Confirm, saveToChain)
if err != nil {
e.Logger.Errorw("Failed to deploy armProxy", "err", err)
return err
}
e.Logger.Infow("deployed armProxy", "addr", armProxy)

//weth9, err := deployContract(e.Logger,
// func() (common.Address, common.Hash, error) {
// weth9, tx, _, err := weth9.DeployWETH9(
// chain.DeployerKey,
// chain.Client,
// )
// return weth9, tx.Hash(), err
// }, chain.Confirm, saveToChain)
//if err != nil {
// e.Logger.Errorw("Failed to deploy weth9", "err", err)
// return err
//}

routerAddr, err := deployContract(e.Logger,
func() (common.Address, common.Hash, error) {
router, tx, _, err := router.DeployRouter(
chain.DeployerKey,
chain.Client,
common.HexToAddress("0x0"),
armProxy,
)
return router, tx.Hash(), err
}, chain.Confirm, saveToChain)
if err != nil {
e.Logger.Errorw("Failed to deploy router", "err", err)
return err
}
e.Logger.Infow("deployed router", "addr", routerAddr)

tokenAdminRegistry, err := deployContract(e.Logger,
func() (common.Address, common.Hash, error) {
tokenAdminRegistry, tx, _, err := token_admin_registry.DeployTokenAdminRegistry(
chain.DeployerKey,
chain.Client)
return tokenAdminRegistry.String(), tx.Hash(), err
},
chain.Confirm,
func(addr string) error {
return e.AddressBook.Save(chain.Selector, addr)
},
)
return tokenAdminRegistry, tx.Hash(), err
}, chain.Confirm, saveToChain)
if err != nil {
e.Logger.Errorw("Failed to deploy token admin registry", "err", err)
return err
}
e.Logger.Infow("deployed tokenAdminRegistry", "addr", tokenAdminRegistry)
}
return nil
}
10 changes: 6 additions & 4 deletions core/capabilities/ccip/deployment/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/price_registry"
"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"
type_and_version "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/type_and_version_interface_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
)
Expand All @@ -33,6 +34,7 @@ type CCIPOnChainState struct {
NonceManagers map[uint64]*nonce_manager.NonceManager
TokenAdminRegistries map[uint64]*token_admin_registry.TokenAdminRegistry
Routers map[uint64]*router.Router
Weth9s map[uint64]*weth9.WETH9

// Only lives on the home chain.
CapabilityRegistry *capabilities_registry.CapabilitiesRegistry
Expand Down Expand Up @@ -77,6 +79,7 @@ func GenerateOnchainState(e environment.Environment) (CCIPOnChainState, error) {
NonceManagers: make(map[uint64]*nonce_manager.NonceManager),
TokenAdminRegistries: make(map[uint64]*token_admin_registry.TokenAdminRegistry),
Routers: make(map[uint64]*router.Router),
Weth9s: make(map[uint64]*weth9.WETH9),
}
// Get all the onchain state
addresses, err := e.AddressBook.Addresses()
Expand All @@ -87,13 +90,12 @@ func GenerateOnchainState(e environment.Environment) (CCIPOnChainState, error) {
for address := range addresses {
tv, err := type_and_version.NewTypeAndVersionInterface(common.HexToAddress(address), e.Chains[chainSelector].Client)
if err != nil {
return state, err
return state, errors.Wrap(err, "could not create tv interface")
}
tvStr, err := tv.TypeAndVersion(nil)
if err != nil {
// TODO: there are some contracts which dont like the link token
// Handle here.
return state, err
// TODO: there are some contracts which dont like the link token/weth9
return state, errors.Wrap(err, fmt.Sprintf("could not call tv version, does the contract %s implement it?", address))
}
switch tvStr {
case "CapabilitiesRegistry 1.0.0":
Expand Down
1 change: 1 addition & 0 deletions core/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

type AddressBook interface {
// TODO: Need manualTV override
Save(chainSelector uint64, address string) error
Addresses() (map[uint64]map[string]struct{}, error)
}
Expand Down

0 comments on commit 75916f8

Please sign in to comment.