diff --git a/e2e/txserver/zeta_tx_server.go b/e2e/txserver/zeta_tx_server.go index a6aea77fed..2c7a1d8a08 100644 --- a/e2e/txserver/zeta_tx_server.go +++ b/e2e/txserver/zeta_tx_server.go @@ -39,6 +39,7 @@ import ( "github.com/zeta-chain/zetacore/app" "github.com/zeta-chain/zetacore/cmd/zetacored/config" + "github.com/zeta-chain/zetacore/e2e/utils" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" authoritytypes "github.com/zeta-chain/zetacore/x/authority/types" @@ -441,7 +442,7 @@ func (zts ZetaTxServer) DeployZRC20s( } // deploy eth zrc20 - _, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20( + res, err := zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20( deployerAddr, "", chains.GoerliLocalnet.ChainId, @@ -454,9 +455,16 @@ func (zts ZetaTxServer) DeployZRC20s( if err != nil { return "", fmt.Errorf("failed to deploy eth zrc20: %s", err.Error()) } + zrc20, err := fetchZRC20FromDeployResponse(res) + if err != nil { + return "", err + } + if err := zts.initializeLiquidityCap(zrc20); err != nil { + return "", err + } // deploy btc zrc20 - _, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20( + res, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20( deployerAddr, "", chains.BitcoinRegtest.ChainId, @@ -469,9 +477,16 @@ func (zts ZetaTxServer) DeployZRC20s( if err != nil { return "", fmt.Errorf("failed to deploy btc zrc20: %s", err.Error()) } + zrc20, err = fetchZRC20FromDeployResponse(res) + if err != nil { + return "", err + } + if err := zts.initializeLiquidityCap(zrc20); err != nil { + return "", err + } // deploy sol zrc20 - _, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20( + res, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20( deployerAddr, "", chains.SolanaLocalnet.ChainId, @@ -484,9 +499,16 @@ func (zts ZetaTxServer) DeployZRC20s( if err != nil { return "", fmt.Errorf("failed to deploy sol zrc20: %s", err.Error()) } + zrc20, err = fetchZRC20FromDeployResponse(res) + if err != nil { + return "", err + } + if err := zts.initializeLiquidityCap(zrc20); err != nil { + return "", err + } // deploy erc20 zrc20 - res, err := zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20( + res, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20( deployerAddr, erc20Addr, chains.GoerliLocalnet.ChainId, @@ -501,12 +523,12 @@ func (zts ZetaTxServer) DeployZRC20s( } // fetch the erc20 zrc20 contract address and remove the quotes - erc20zrc20Addr, err := FetchAttributeFromTxResponse(res, "Contract") + erc20zrc20Addr, err := fetchZRC20FromDeployResponse(res) if err != nil { - return "", fmt.Errorf("failed to fetch erc20 zrc20 contract address: %s, %s", err.Error(), res.String()) + return "", err } - if !ethcommon.IsHexAddress(erc20zrc20Addr) { - return "", fmt.Errorf("invalid address in event: %s", erc20zrc20Addr) + if err := zts.initializeLiquidityCap(erc20zrc20Addr); err != nil { + return "", err } return erc20zrc20Addr, nil @@ -557,6 +579,33 @@ func (zts *ZetaTxServer) SetAuthorityClient(authorityClient authoritytypes.Query zts.authorityClient = authorityClient } +// initializeLiquidityCap initializes the liquidity cap for the given coin with a large value +func (zts ZetaTxServer) initializeLiquidityCap(zrc20 string) error { + liquidityCap := sdktypes.NewUint(1e18).MulUint64(1e12) + + msg := fungibletypes.NewMsgUpdateZRC20LiquidityCap( + zts.MustGetAccountAddressFromName(utils.OperationalPolicyName), + zrc20, + liquidityCap, + ) + _, err := zts.BroadcastTx(utils.OperationalPolicyName, msg) + return err +} + +// fetchZRC20FromDeployResponse fetches the zrc20 address from the response +func fetchZRC20FromDeployResponse(res *sdktypes.TxResponse) (string, error) { + // fetch the erc20 zrc20 contract address and remove the quotes + zrc20Addr, err := FetchAttributeFromTxResponse(res, "Contract") + if err != nil { + return "", fmt.Errorf("failed to fetch zrc20 contract address: %s, %s", err.Error(), res.String()) + } + if !ethcommon.IsHexAddress(zrc20Addr) { + return "", fmt.Errorf("invalid address in event: %s", zrc20Addr) + } + + return zrc20Addr, nil +} + // fetchMessagePermissions fetches the message permissions for a given message // return a bool preV19 to indicate the node is preV19 and the query doesn't exist func (zts ZetaTxServer) fetchMessagePermissions(msg sdktypes.Msg) (authoritytypes.PolicyType, bool, error) {