Skip to content

Commit

Permalink
more changes to support solana
Browse files Browse the repository at this point in the history
  • Loading branch information
pablolagreca committed Nov 26, 2024
1 parent cc8ef61 commit 62c4d4b
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 224 deletions.
242 changes: 25 additions & 217 deletions deployment/ccip/changeset/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package changeset

import (
"fmt"
chain_selectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/evm"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -16,19 +18,13 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/maybe_revert_message_receiver"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_rmn_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/nonce_manager"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp"
"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/ccip/generated/rmn_proxy_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/rmn_remote"
"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/shared/generated/burn_mint_erc677"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/multicall3"
)

var (
Expand Down Expand Up @@ -119,218 +115,18 @@ func deployPrerequisiteContracts(e deployment.Environment, ab deployment.Address
}
}
lggr := e.Logger
chainState, chainExists := state.EVMState.Chains[chain.Selector]
var weth9Contract *weth9.WETH9
var linkTokenContract *burn_mint_erc677.BurnMintERC677
var tokenAdminReg *token_admin_registry.TokenAdminRegistry
var registryModule *registry_module_owner_custom.RegistryModuleOwnerCustom
var rmnProxy *rmn_proxy_contract.RMNProxyContract
var r *router.Router
var mc3 *multicall3.Multicall3
if chainExists {
weth9Contract = chainState.Weth9
linkTokenContract = chainState.LinkToken
tokenAdminReg = chainState.TokenAdminRegistry
registryModule = chainState.RegistryModule
rmnProxy = chainState.RMNProxyExisting
r = chainState.Router
mc3 = chainState.Multicall3
}
if rmnProxy == nil {
// we want to replicate the mainnet scenario where RMNProxy is already deployed with some existing RMN
// This will need us to use two different RMNProxy contracts
// 1. RMNProxyNew with RMNRemote - ( deployed later in chain contracts)
// 2. RMNProxyExisting with mockRMN - ( deployed here, replicating the behavior of existing RMNProxy with already set RMN)
rmn, err := deployment.DeployContract(lggr, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*mock_rmn_contract.MockRMNContract] {
rmnAddr, tx2, rmn, err2 := mock_rmn_contract.DeployMockRMNContract(
chain.EVMChain.DeployerKey,
chain.EVMChain.Client,
)
return deployment.ContractDeploy[*mock_rmn_contract.MockRMNContract]{
rmnAddr, rmn, tx2, deployment.NewTypeAndVersion(MockRMN, deployment.Version1_0_0), err2,
}
})
if err != nil {
lggr.Errorw("Failed to deploy mock RMN", "err", err)
return err
switch chain.Family {
case chain_selectors.FamilyEVM:
{
return evm.DeployPrerequisitesEVM(e, ab, state, chain, lggr, deployOpts, isUSDC)
}
lggr.Infow("deployed mock RMN", "addr", rmn.Address)
rmnProxyContract, err := deployment.DeployContract(lggr, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract] {
rmnProxyAddr, tx2, rmnProxy, err2 := rmn_proxy_contract.DeployRMNProxyContract(
chain.EVMChain.DeployerKey,
chain.EVMChain.Client,
rmn.Address,
)
return deployment.ContractDeploy[*rmn_proxy_contract.RMNProxyContract]{
rmnProxyAddr, rmnProxy, tx2, deployment.NewTypeAndVersion(ARMProxy, deployment.Version1_0_0), err2,
}
})
if err != nil {
lggr.Errorw("Failed to deploy RMNProxyNew", "err", err)
return err
}
lggr.Infow("deployed RMNProxyNew", "addr", rmnProxyContract.Address)
rmnProxy = rmnProxyContract.Contract
}
if tokenAdminReg == nil {
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.EVMChain.DeployerKey,
chain.EVMChain.Client)
return deployment.ContractDeploy[*token_admin_registry.TokenAdminRegistry]{
tokenAdminRegistryAddr, tokenAdminRegistry, tx2, deployment.NewTypeAndVersion(TokenAdminRegistry, deployment.Version1_5_0), err2,
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy token admin registry", "err", err)
return err
case chain_selectors.FamilySolana:
{
panic("Not implemented")
}
e.Logger.Infow("deployed tokenAdminRegistry", "addr", tokenAdminRegistry)
tokenAdminReg = tokenAdminRegistry.Contract
} else {
e.Logger.Infow("tokenAdminRegistry already deployed", "addr", tokenAdminReg.Address)
default:
panic("Not implemented")
}
if registryModule == nil {
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.EVMChain.DeployerKey,
chain.EVMChain.Client,
tokenAdminReg.Address())
return deployment.ContractDeploy[*registry_module_owner_custom.RegistryModuleOwnerCustom]{
regModAddr, regMod, tx2, deployment.NewTypeAndVersion(RegistryModule, deployment.Version1_5_0), err2,
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy custom registry module", "err", err)
return err
}
e.Logger.Infow("deployed custom registry module", "addr", customRegistryModule)
registryModule = customRegistryModule.Contract
} else {
e.Logger.Infow("custom registry module already deployed", "addr", registryModule.Address)
}
isRegistryAdded, err := tokenAdminReg.IsRegistryModule(nil, registryModule.Address())
if err != nil {
e.Logger.Errorw("Failed to check if registry module is added on token admin registry", "err", err)
return fmt.Errorf("failed to check if registry module is added on token admin registry: %w", err)
}
if !isRegistryAdded {
tx, err := tokenAdminReg.AddRegistryModule(chain.EVMChain.DeployerKey, registryModule.Address())
if err != nil {
e.Logger.Errorw("Failed to assign registry module on token admin registry", "err", err)
return fmt.Errorf("failed to assign registry module on token admin registry: %w", err)
}

_, err = chain.EVMChain.Confirm(tx)
if err != nil {
e.Logger.Errorw("Failed to confirm assign registry module on token admin registry", "err", err)
return fmt.Errorf("failed to confirm assign registry module on token admin registry: %w", err)
}
e.Logger.Infow("assigned registry module on token admin registry")
}
if weth9Contract == nil {
weth, err := deployment.DeployContract(lggr, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*weth9.WETH9] {
weth9Addr, tx2, weth9c, err2 := weth9.DeployWETH9(
chain.EVMChain.DeployerKey,
chain.EVMChain.Client,
)
return deployment.ContractDeploy[*weth9.WETH9]{
weth9Addr, weth9c, tx2, deployment.NewTypeAndVersion(WETH9, deployment.Version1_0_0), err2,
}
})
if err != nil {
lggr.Errorw("Failed to deploy weth9", "err", err)
return err
}
lggr.Infow("deployed weth9", "addr", weth.Address)
weth9Contract = weth.Contract
} else {
lggr.Infow("weth9 already deployed", "addr", weth9Contract.Address)
}
if linkTokenContract == nil {
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.EVMChain.DeployerKey,
chain.EVMChain.Client,
"Link Token",
"LINK",
uint8(18),
big.NewInt(0).Mul(big.NewInt(1e9), big.NewInt(1e18)),
)
return deployment.ContractDeploy[*burn_mint_erc677.BurnMintERC677]{
linkTokenAddr, linkToken, tx2, deployment.NewTypeAndVersion(LinkToken, deployment.Version1_0_0), err2,
}
})
if err != nil {
lggr.Errorw("Failed to deploy linkToken", "err", err)
return err
}
lggr.Infow("deployed linkToken", "addr", linkToken.Address)
} else {
lggr.Infow("linkToken already deployed", "addr", linkTokenContract.Address)
}
// if router is not already deployed, we deploy it
if r == nil {
routerContract, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*router.Router] {
routerAddr, tx2, routerC, err2 := router.DeployRouter(
chain.EVMChain.DeployerKey,
chain.EVMChain.Client,
weth9Contract.Address(),
rmnProxy.Address(),
)
return deployment.ContractDeploy[*router.Router]{
routerAddr, routerC, tx2, deployment.NewTypeAndVersion(Router, deployment.Version1_2_0), err2,
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy router", "err", err)
return err
}
e.Logger.Infow("deployed router", "addr", routerContract.Address)
r = routerContract.Contract
} else {
e.Logger.Infow("router already deployed", "addr", chainState.Router.Address)
}
if deployOpts.Multicall3Enabled && mc3 == nil {
multicall3Contract, err := deployment.DeployContract(e.Logger, chain, ab,
func(chain deployment.Chain) deployment.ContractDeploy[*multicall3.Multicall3] {
multicall3Addr, tx2, multicall3Wrapper, err2 := multicall3.DeployMulticall3(
chain.EVMChain.DeployerKey,
chain.EVMChain.Client,
)
return deployment.ContractDeploy[*multicall3.Multicall3]{
multicall3Addr, multicall3Wrapper, tx2, deployment.NewTypeAndVersion(Multicall3, deployment.Version1_0_0), err2,
}
})
if err != nil {
e.Logger.Errorw("Failed to deploy ccip multicall", "err", err)
return err
}
e.Logger.Infow("deployed ccip multicall", "addr", multicall3Contract.Address)
} else {
e.Logger.Info("ccip multicall already deployed", "addr", mc3.Address)
}
if isUSDC {
token, pool, messenger, transmitter, err1 := DeployUSDC(e.Logger, chain, ab, rmnProxy.Address(), r.Address())
if err1 != nil {
return err1
}
e.Logger.Infow("Deployed USDC contracts",
"chainSelector", chain.Selector,
"token", token.Address(),
"pool", pool.Address(),
"transmitter", transmitter.Address(),
"messenger", messenger.Address(),
)
}
return nil
}

// configureChain assumes the all the Home chain contracts and CCIP contracts are deployed
Expand Down Expand Up @@ -373,6 +169,16 @@ func configureChain(

for _, chainSel := range c.ChainsToDeploy {
chain, _ := e.Chains[chainSel]

switch chain.Family {
case chain_selectors.FamilyEVM:
{

}
default:
panic("Not implemented")
}

chainState, ok := existingState.EVMState.Chains[chain.Selector]
if !ok {
return fmt.Errorf("chain state not found for chain %d", chain.Selector)
Expand Down Expand Up @@ -432,7 +238,8 @@ func configureChain(
func deployCCIPContracts(
e deployment.Environment,
ab deployment.AddressBook,
c NewChainsConfig) error {
c NewChainsConfig,
) error {
err := deployChainContractsForChains(e, ab, c.HomeChainSel, c.ChainsToDeploy)
if err != nil {
e.Logger.Errorw("Failed to deploy chain contracts", "err", err)
Expand All @@ -456,7 +263,8 @@ func deployChainContractsForChains(
e deployment.Environment,
ab deployment.AddressBook,
homeChainSel uint64,
chainsToDeploy []uint64) error {
chainsToDeploy []uint64,
) error {
existingState, err := LoadOnchainState(e)
if err != nil {
e.Logger.Errorw("Failed to load existing onchain state", "err")
Expand Down
Loading

0 comments on commit 62c4d4b

Please sign in to comment.