Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add begin block deployments to mock mainnet #1189

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func start(_ *cobra.Command, _ []string) error {
err := telemetryServer.Start()
if err != nil {
startLogger.Error().Err(err).Msg("telemetryServer error")
panic("telemetryServer error")
}
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,91 @@ package keeper

import (
"context"
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/zeta-chain/zetacore/common"
)

func (k Keeper) BlockOneDeploySystemContracts(_ context.Context) error {
func (k Keeper) BlockOneDeploySystemContracts(goCtx context.Context) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are code we could factorize with the other networks privnet, testnet.

I think we would benefit of having a single function BlockOneSetup that group the setup operations logic common to all network and implement tests for this function since an error here or an inconsistency can prevent the network from working.

Could be another PR

ctx := sdk.UnwrapSDKContext(goCtx)

// setup uniswap v2 factory
uniswapV2Factory, err := k.DeployUniswapV2Factory(ctx)
if err != nil {
return sdkerrors.Wrapf(err, "failed to DeployUniswapV2Factory")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still sdkerrors with errorsmod some places

}
ctx.EventManager().EmitEvent(
sdk.NewEvent(sdk.EventTypeMessage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using sdk.EventTypeMessage but this is not a message event
Same below

sdk.NewAttribute("UniswapV2Factory", uniswapV2Factory.String()),
),
)

// setup WZETA contract
wzeta, err := k.DeployWZETA(ctx)
if err != nil {
return sdkerrors.Wrapf(err, "failed to DeployWZetaContract")
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(sdk.EventTypeMessage,
sdk.NewAttribute("DeployWZetaContract", wzeta.String()),
),
)

router, err := k.DeployUniswapV2Router02(ctx, uniswapV2Factory, wzeta)
if err != nil {
return sdkerrors.Wrapf(err, "failed to DeployUniswapV2Router02")
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(sdk.EventTypeMessage,
sdk.NewAttribute("DeployUniswapV2Router02", router.String()),
),
)

connector, err := k.DeployConnectorZEVM(ctx, wzeta)
if err != nil {
return sdkerrors.Wrapf(err, "failed to DeployConnectorZEVM")
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(sdk.EventTypeMessage,
sdk.NewAttribute("DeployConnectorZEVM", connector.String()),
),
)
ctx.Logger().Info("Deployed Connector ZEVM at " + connector.String())

SystemContractAddress, err := k.DeploySystemContract(ctx, wzeta, uniswapV2Factory, router)
if err != nil {
return sdkerrors.Wrapf(err, "failed to SystemContractAddress")
}
ctx.EventManager().EmitEvent(
sdk.NewEvent(sdk.EventTypeMessage,
sdk.NewAttribute("SystemContractAddress", SystemContractAddress.String()),
),
)

// set the system contract
system, _ := k.GetSystemContract(ctx)
system.SystemContract = SystemContractAddress.String()
k.SetSystemContract(ctx, system)
//err = k.SetGasPrice(ctx, big.NewInt(1337), big.NewInt(1))
if err != nil {
return err
}
Comment on lines +76 to +79
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//err = k.SetGasPrice(ctx, big.NewInt(1337), big.NewInt(1))
if err != nil {
return err
}

We're handling the error but the method is commented out

_, err = k.SetupChainGasCoinAndPool(ctx, common.EthChain().ChainId, "ETH", "ETH", 18)
if err != nil {
return errorsmod.Wrapf(err, fmt.Sprintf("failed to setupChainGasCoinAndPool for %s", common.EthChain().ChainName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need fmt.Sprintf since Wrapf can already format strings

}

_, err = k.SetupChainGasCoinAndPool(ctx, common.BscMainnetChain().ChainId, "BNB", "BNB", 18)
if err != nil {
return errorsmod.Wrapf(err, fmt.Sprintf("failed to setupChainGasCoinAndPool for %s", common.BscMainnetChain().ChainName))
}
_, err = k.SetupChainGasCoinAndPool(ctx, common.BtcMainnetChain().ChainId, "BTC", "BTC", 8)
if err != nil {
return errorsmod.Wrapf(err, fmt.Sprintf("failed to setupChainGasCoinAndPool for %s", common.BtcMainnetChain().ChainName))
}
return nil
}
func (k Keeper) TestUpdateSystemContractAddress(_ context.Context) error {
Expand Down
Loading