Skip to content

Commit

Permalink
Deploy arbitrary teleporter contracts (#1959)
Browse files Browse the repository at this point in the history
* add skel

* add missing files

* check for forge to have been installed

* add comments

* start automating foundry install

* added automated froundry install

* start working agains teleporter repo

* deploying contract given abi and bin files

* adding destination deploy

* deploying the destination

* ux design 2 for bridge deploy of fuji

* add popular token info list

* move to new file

* add blockchain alias to popular tokens json

* start using teleporter bridge deploy

* adddress suggestions

* fix recommended

* update to latest esp

* start obtaining erc20 token balances

* add key list for erc20 tokens

* enable local network and filter inputs subnets by network

* refactor obtaining chain info into a separate function

* use flags for hub chain def

* add flags for the different hub options

* validate and prompt hub options

* nit

* add validation for subnet name

* nits

* validate erc20 token

* start adding helpers for deploy

* bridge hub deployed

* erc20 hub deployed on local network c-chain

* nit

* nit

* if given hub, get erc20 address from hub, then token details from erc20

* ready to deploy spoke

* add spoke deploy

* nit

* nits

* add registration

* added hub deploy for native tokens

* add contract indicator to key list

* refactor into lib

* add foundry install stuff

* add foundry install to flow

* add bridge contracts download

* nits

* added bridge contracts download + compilation

* nit

* add explanations

* nit

* started working simple contract method call

* this is beauty

* added native transfer

* avoid passing in field names

* added contract call

* add contract file

* check hub kind

* add send function for bridge hubs

* cleanup of key transfer

* full go and back for erc20 - erc20

* fix symbol on key list

* remove all abi file ref

* do not compile abi anymore

* lint

* add prompts to key transfer

* lint

* add subnets flag to list to select different subnet balances

* nit

* fix e2e

* fix key e2e

* fix recommended tags

* enable filtering out native token on key list

* make transaction commit to wait for tx acceptance

* download registry bytecode

* deploy registry binary

* nit

* add methods to set the contracts by file

* add asset stuff to lib

* remove unneded version param from deploy

* asset download reincorporated into deploy cmd

* added arbitrary teleporter binaries to local deploy

* add automatic download of assets if no files are specified

* lint

* add back again a flag to be deprecated

* Use registry release (#1958)

* download registry bytecode

* deploy registry binary

* nit

* Teleporter msg using contract (#1979)

* add skel to send cross chain message and to check if message was received

* add function to check if message was received on destination

* remove unneded send cross chain message param

* add options to better encode the message, and to set the destination address

* start adding private key control

* add private key options

* refactor private key digging into separate functions

* use new privatekey gattering functions in teleporter deploy

* improving

* msg working

* pass slice example if [()]

* using contract method

* working

* lint

---------

Signed-off-by: sukantoraymond <rsukanto@umich.edu>
Co-authored-by: sukantoraymond <rsukanto@umich.edu>
  • Loading branch information
felipemadero and sukantoraymond authored Jun 20, 2024
1 parent 6830789 commit d8f684e
Show file tree
Hide file tree
Showing 14 changed files with 799 additions and 333 deletions.
63 changes: 41 additions & 22 deletions cmd/nodecmd/wiz.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,33 @@ const (
)

var (
forceSubnetCreate bool
subnetGenesisFile string
useEvmSubnet bool
useCustomSubnet bool
evmVersion string
evmChainID uint64
evmToken string
evmDefaults bool
useLatestEvmReleasedVersion bool
useLatestEvmPreReleasedVersion bool
customVMRepoURL string
customVMBranch string
customVMBuildScript string
nodeConf string
subnetConf string
chainConf string
validators []string
customGrafanaDashboardPath string
teleporterReady bool
runRelayer bool
forceSubnetCreate bool
subnetGenesisFile string
useEvmSubnet bool
useCustomSubnet bool
evmVersion string
evmChainID uint64
evmToken string
evmDefaults bool
useLatestEvmReleasedVersion bool
useLatestEvmPreReleasedVersion bool
customVMRepoURL string
customVMBranch string
customVMBuildScript string
nodeConf string
subnetConf string
chainConf string
validators []string
customGrafanaDashboardPath string
teleporterReady bool
runRelayer bool
teleporterVersion string
teleporterMessengerContractAddressPath string
teleporterMessengerDeployerAddressPath string
teleporterMessengerDeployerTxPath string
teleporterRegistryBydecodePath string
deployTeleporterMessenger bool
deployTeleporterRegistry bool
)

func newWizCmd() *cobra.Command {
Expand Down Expand Up @@ -124,6 +131,13 @@ The node wiz command creates a devnet and deploys, sync and validate a subnet in
cmd.Flags().StringVar(&volumeType, "aws-volume-type", "gp3", "AWS volume type")
cmd.Flags().IntVar(&volumeSize, "aws-volume-size", constants.CloudServerStorageSize, "AWS volume size in GB")
cmd.Flags().StringVar(&grafanaPkg, "grafana-pkg", "", "use grafana pkg instead of apt repo(by default), for example https://dl.grafana.com/oss/release/grafana_10.4.1_amd64.deb")
cmd.Flags().StringVar(&teleporterVersion, "teleporter-version", "latest", "teleporter version to deploy")
cmd.Flags().StringVar(&teleporterMessengerContractAddressPath, "teleporter-messenger-contract-address-path", "", "path to a teleporter messenger contract address file")
cmd.Flags().StringVar(&teleporterMessengerDeployerAddressPath, "teleporter-messenger-deployer-address-path", "", "path to a teleporter messenger deployer address file")
cmd.Flags().StringVar(&teleporterMessengerDeployerTxPath, "teleporter-messenger-deployer-tx-path", "", "path to a teleporter messenger deployer tx file")
cmd.Flags().StringVar(&teleporterRegistryBydecodePath, "teleporter-registry-bytecode-path", "", "path to a teleporter registry bytecode file")
cmd.Flags().BoolVar(&deployTeleporterMessenger, "deploy-teleporter-messenger", true, "deploy Teleporter Messenger")
cmd.Flags().BoolVar(&deployTeleporterRegistry, "deploy-teleporter-registry", true, "deploy Teleporter Registry")
return cmd
}

Expand Down Expand Up @@ -350,8 +364,13 @@ func wiz(cmd *cobra.Command, args []string) error {
Network: networkoptions.NetworkFlags{
ClusterName: clusterName,
},
DeployMessenger: true,
DeployRegistry: true,
DeployMessenger: deployTeleporterMessenger,
DeployRegistry: deployTeleporterRegistry,
Version: teleporterVersion,
MessengerContractAddressPath: teleporterMessengerContractAddressPath,
MessengerDeployerAddressPath: teleporterMessengerDeployerAddressPath,
MessengerDeployerTxPath: teleporterMessengerDeployerTxPath,
RegistryBydecodePath: teleporterRegistryBydecodePath,
}
if err := teleportercmd.CallDeploy([]string{}, flags); err != nil {
return err
Expand Down
18 changes: 15 additions & 3 deletions cmd/subnetcmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ var (
mainnetChainID uint32
skipCreatePrompt bool
avagoBinaryPath string
skipLocalTeleporter bool
subnetOnly bool
teleporterEsp subnet.TeleporterEsp

errMutuallyExlusiveControlKeys = errors.New("--control-keys and --same-control-key are mutually exclusive")
ErrMutuallyExlusiveKeyLedger = errors.New("key source flags --key, --ledger/--ledger-addrs are mutually exclusive")
Expand Down Expand Up @@ -95,8 +95,14 @@ so you can take your locally tested Subnet and deploy it on Fuji or Mainnet.`,
cmd.Flags().StringVarP(&subnetIDStr, "subnet-id", "u", "", "do not create a subnet, deploy the blockchain into the given subnet id")
cmd.Flags().Uint32Var(&mainnetChainID, "mainnet-chain-id", 0, "use different ChainID for mainnet deployment")
cmd.Flags().StringVar(&avagoBinaryPath, "avalanchego-path", "", "use this avalanchego binary path")
cmd.Flags().BoolVar(&skipLocalTeleporter, "skip-local-teleporter", false, "skip local teleporter deploy to a local network")
cmd.Flags().BoolVar(&subnetOnly, "subnet-only", false, "only create a subnet")
cmd.Flags().BoolVar(&teleporterEsp.SkipDeploy, "skip-local-teleporter", false, "skip automatic teleporter deploy on local networks [to be deprecated]")
cmd.Flags().BoolVar(&teleporterEsp.SkipDeploy, "skip-teleporter-deploy", false, "skip automatic teleporter deploy")
cmd.Flags().StringVar(&teleporterEsp.Version, "teleporter-version", "latest", "teleporter version to deploy")
cmd.Flags().StringVar(&teleporterEsp.MessengerContractAddressPath, "teleporter-messenger-contract-address-path", "", "path to a teleporter messenger contract address file")
cmd.Flags().StringVar(&teleporterEsp.MessengerDeployerAddressPath, "teleporter-messenger-deployer-address-path", "", "path to a teleporter messenger deployer address file")
cmd.Flags().StringVar(&teleporterEsp.MessengerDeployerTxPath, "teleporter-messenger-deployer-tx-path", "", "path to a teleporter messenger deployer tx file")
cmd.Flags().StringVar(&teleporterEsp.RegistryBydecodePath, "teleporter-registry-bytecode-path", "", "path to a teleporter registry bytecode file")
return cmd
}

Expand Down Expand Up @@ -265,6 +271,12 @@ func deploySubnet(cmd *cobra.Command, args []string) error {
return err
}

if teleporterEsp.MessengerContractAddressPath != "" || teleporterEsp.MessengerDeployerAddressPath != "" || teleporterEsp.MessengerDeployerTxPath != "" || teleporterEsp.RegistryBydecodePath != "" {
if teleporterEsp.MessengerContractAddressPath == "" || teleporterEsp.MessengerDeployerAddressPath == "" || teleporterEsp.MessengerDeployerTxPath == "" || teleporterEsp.RegistryBydecodePath == "" {
return fmt.Errorf("if setting any teleporter asset path, you must set all teleporter asset paths")
}
}

chain := chains[0]

sidecar, err := app.LoadSidecar(chain)
Expand Down Expand Up @@ -358,7 +370,7 @@ func deploySubnet(cmd *cobra.Command, args []string) error {
}

deployer := subnet.NewLocalDeployer(app, userProvidedAvagoVersion, avagoBinaryPath, vmBin)
deployInfo, err := deployer.DeployToLocalNetwork(chain, chainGenesis, genesisPath, skipLocalTeleporter, subnetIDStr)
deployInfo, err := deployer.DeployToLocalNetwork(chain, chainGenesis, genesisPath, teleporterEsp, subnetIDStr)
if err != nil {
if deployer.BackendStartedHere() {
if innerErr := binutils.KillgRPCServerProcess(app); innerErr != nil {
Expand Down
142 changes: 64 additions & 78 deletions cmd/teleportercmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@ import (
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
"github.com/ava-labs/avalanche-cli/pkg/prompts"
"github.com/ava-labs/avalanche-cli/pkg/subnet"
"github.com/ava-labs/avalanche-cli/pkg/teleporter"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanchego/ids"

"github.com/spf13/cobra"
)

type DeployFlags struct {
Network networkoptions.NetworkFlags
SubnetName string
BlockchainID string
CChain bool
PrivateKey string
KeyName string
GenesisKey bool
DeployMessenger bool
DeployRegistry bool
TeleporterVersion string
RPCURL string
Network networkoptions.NetworkFlags
SubnetName string
BlockchainID string
CChain bool
PrivateKey string
KeyName string
GenesisKey bool
DeployMessenger bool
DeployRegistry bool
RPCURL string
Version string
MessengerContractAddressPath string
MessengerDeployerAddressPath string
MessengerDeployerTxPath string
RegistryBydecodePath string
PrivateKeyFlags PrivateKeyFlags
}

const (
Expand Down Expand Up @@ -60,13 +63,17 @@ func newDeployCmd() *cobra.Command {
cmd.Flags().StringVar(&deployFlags.SubnetName, "subnet", "", "deploy teleporter into the given CLI subnet")
cmd.Flags().StringVar(&deployFlags.BlockchainID, "blockchain-id", "", "deploy teleporter into the given blockchain ID/Alias")
cmd.Flags().BoolVar(&deployFlags.CChain, "c-chain", false, "deploy teleporter into C-Chain")
cmd.Flags().StringVar(&deployFlags.PrivateKey, "private-key", "", "private key to use to fund teleporter deploy)")
cmd.Flags().StringVar(&deployFlags.KeyName, "key", "", "CLI stored key to use to fund teleporter deploy)")
cmd.Flags().BoolVar(&deployFlags.GenesisKey, "genesis-key", false, "use genesis aidrop key to fund teleporter deploy")
cmd.Flags().StringVar(&deployFlags.PrivateKeyFlags.PrivateKey, "private-key", "", "private key to use to fund teleporter deploy)")
cmd.Flags().StringVar(&deployFlags.PrivateKeyFlags.KeyName, "key", "", "CLI stored key to use to fund teleporter deploy)")
cmd.Flags().BoolVar(&deployFlags.PrivateKeyFlags.GenesisKey, "genesis-key", false, "use genesis aidrop key to fund teleporter deploy")
cmd.Flags().BoolVar(&deployFlags.DeployMessenger, "deploy-messenger", true, "deploy Teleporter Messenger")
cmd.Flags().BoolVar(&deployFlags.DeployRegistry, "deploy-registry", true, "deploy Teleporter Registry")
cmd.Flags().StringVar(&deployFlags.TeleporterVersion, "version", "latest", "version to deploy")
cmd.Flags().StringVar(&deployFlags.RPCURL, "rpc-url", "", "use the given RPC URL to connect to the subnet")
cmd.Flags().StringVar(&deployFlags.Version, "version", "latest", "version to deploy")
cmd.Flags().StringVar(&deployFlags.MessengerContractAddressPath, "messenger-contract-address-path", "", "path to a messenger contract address file")
cmd.Flags().StringVar(&deployFlags.MessengerDeployerAddressPath, "messenger-deployer-address-path", "", "path to a messenger deployer address file")
cmd.Flags().StringVar(&deployFlags.MessengerDeployerTxPath, "messenger-deployer-tx-path", "", "path to a messenger deployer tx file")
cmd.Flags().StringVar(&deployFlags.RegistryBydecodePath, "registry-bytecode-path", "", "path to a registry bytecode file")
return cmd
}

Expand Down Expand Up @@ -133,7 +140,7 @@ func CallDeploy(_ []string, flags DeployFlags) error {
var (
blockchainID string
teleporterSubnetDesc string
privateKey = flags.PrivateKey
privateKey string
teleporterVersion string
)
switch {
Expand Down Expand Up @@ -169,74 +176,40 @@ func CallDeploy(_ []string, flags DeployFlags) error {
teleporterSubnetDesc = cChainName
blockchainID = cChainAlias
}
var chainID ids.ID
if flags.CChain || !network.StandardPublicEndpoint() {
chainID, err = utils.GetChainID(network.Endpoint, blockchainID)
if err != nil {
return err
}
} else {
chainID, err = ids.FromString(blockchainID)
if err != nil {
return err
}
}
createChainTx, err := utils.GetBlockchainTx(network.Endpoint, chainID)
if err != nil {
return err
}
if !utils.ByteSliceIsSubnetEvmGenesis(createChainTx.GenesisData) {
return fmt.Errorf("teleporter can only be deployed to Subnet-EVM based vms")
}
if flags.KeyName != "" {
k, err := app.GetKey(flags.KeyName, network, false)
if err != nil {
return err
}
privateKey = k.PrivKeyHex()
}
_, genesisAddress, genesisPrivateKey, err := subnet.GetSubnetAirdropKeyInfo(app, network, flags.SubnetName, createChainTx.GenesisData)
genesisAddress, genesisPrivateKey, err := getEVMSubnetPrefundedKey(
network,
flags.SubnetName,
flags.CChain,
flags.BlockchainID,
)
if err != nil {
return err
}
if flags.GenesisKey {
privateKey = genesisPrivateKey
}
if privateKey == "" {
cliKeyOpt := "Get private key from an existing stored key (created from avalanche key create or avalanche key import)"
customKeyOpt := "Custom"
genesisKeyOpt := fmt.Sprintf("Use the private key of the Genesis Aidrop address %s", genesisAddress)
keyOptions := []string{cliKeyOpt, customKeyOpt}
if genesisPrivateKey != "" {
keyOptions = []string{genesisKeyOpt, cliKeyOpt, customKeyOpt}
}
keyOption, err := app.Prompt.CaptureList("Which private key do you want to use to pay fees?", keyOptions)
privateKey, err = getPrivateKeyFromFlags(
deployFlags.PrivateKeyFlags,
genesisPrivateKey,
)
if err != nil {
return err
}
switch keyOption {
case cliKeyOpt:
keyName, err := prompts.CaptureKeyName(app.Prompt, "pay fees", app.GetKeyDir(), true)
if privateKey == "" {
privateKey, err = promptPrivateKey("deploy teleporter", genesisAddress, genesisPrivateKey)
if err != nil {
return err
}
k, err := app.GetKey(keyName, network, false)
if err != nil {
return err
}
privateKey = k.PrivKeyHex()
case customKeyOpt:
privateKey, err = app.Prompt.CaptureString("Private Key")
if err != nil {
return err
}
case genesisKeyOpt:
privateKey = genesisPrivateKey
}
}
if flags.TeleporterVersion != "" && flags.TeleporterVersion != "latest" {
teleporterVersion = flags.TeleporterVersion
} else if teleporterVersion == "" {
switch {
case flags.MessengerContractAddressPath != "" || flags.MessengerDeployerAddressPath != "" || flags.MessengerDeployerTxPath != "" || flags.RegistryBydecodePath != "":
teleporterVersion = ""
if flags.MessengerContractAddressPath == "" || flags.MessengerDeployerAddressPath == "" || flags.MessengerDeployerTxPath == "" || flags.RegistryBydecodePath == "" {
return fmt.Errorf("if setting any teleporter asset path, you must set all teleporter asset paths")
}
case flags.Version != "" && flags.Version != "latest":
teleporterVersion = flags.Version
case teleporterVersion != "":
default:
teleporterInfo, err := teleporter.GetInfo(app)
if err != nil {
return err
Expand All @@ -249,9 +222,24 @@ func CallDeploy(_ []string, flags DeployFlags) error {
rpcURL = flags.RPCURL
}
td := teleporter.Deployer{}
if flags.MessengerContractAddressPath != "" {
if err := td.SetAssetsFromPaths(
flags.MessengerContractAddressPath,
flags.MessengerDeployerAddressPath,
flags.MessengerDeployerTxPath,
flags.RegistryBydecodePath,
); err != nil {
return err
}
} else {
if err := td.DownloadAssets(
app.GetTeleporterBinDir(),
teleporterVersion,
); err != nil {
return err
}
}
alreadyDeployed, teleporterMessengerAddress, teleporterRegistryAddress, err := td.Deploy(
app.GetTeleporterBinDir(),
teleporterVersion,
teleporterSubnetDesc,
rpcURL,
privateKey,
Expand Down Expand Up @@ -288,8 +276,6 @@ func CallDeploy(_ []string, flags DeployFlags) error {
return err
}
alreadyDeployed, teleporterMessengerAddress, teleporterRegistryAddress, err := td.Deploy(
app.GetTeleporterBinDir(),
teleporterVersion,
cChainName,
network.BlockchainEndpoint(cChainAlias),
ewoq.PrivKeyHex(),
Expand Down
Loading

0 comments on commit d8f684e

Please sign in to comment.