Skip to content

Commit

Permalink
Merge branch 'develop' into feat-inbound-memo
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie authored Oct 15, 2024
2 parents d022be1 + ae6ab23 commit 9bee20b
Show file tree
Hide file tree
Showing 50 changed files with 4,316 additions and 350 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ var (
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionstypes.ModuleName: nil,
emissionstypes.UndistributedObserverRewardsPool: nil,
emissionstypes.UndistributedTssRewardsPool: nil,
emissionstypes.UndistributedTSSRewardsPool: nil,
}

// module accounts that are NOT allowed to receive tokens
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* [2842](https://github.com/zeta-chain/node/pull/2842) - fix: move interval assignment out of cctx loop in EVM outbound tx scheduler
* [2853](https://github.com/zeta-chain/node/pull/2853) - calling precompile through sc with sc state update
* [2925](https://github.com/zeta-chain/node/pull/2925) - add recover to init chainer to diplay informative message when starting a node from block 1
* [2909](https://github.com/zeta-chain/node/pull/2909) - add legacy messages back to codec for querier backward compatibility

## v20.0.0

Expand Down
14 changes: 7 additions & 7 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
flagTestV2Migration = "test-v2-migration"
flagSkipTrackerCheck = "skip-tracker-check"
flagSkipPrecompiles = "skip-precompiles"
flagUpgradeGateways = "upgrade-gateways"
flagUpgradeContracts = "upgrade-contracts"
)

var (
Expand Down Expand Up @@ -84,7 +84,8 @@ func NewLocalCmd() *cobra.Command {
cmd.Flags().Bool(flagTestV2Migration, false, "set to true to run tests for v2 contracts migration test")
cmd.Flags().Bool(flagSkipTrackerCheck, false, "set to true to skip tracker check at the end of the tests")
cmd.Flags().Bool(flagSkipPrecompiles, false, "set to true to skip stateful precompiled contracts test")
cmd.Flags().Bool(flagUpgradeGateways, false, "set to true to upgrade gateways during setup for ZEVM and EVM")
cmd.Flags().
Bool(flagUpgradeContracts, false, "set to true to upgrade Gateways and ERC20Custody contracts during setup for ZEVM and EVM")

return cmd
}
Expand Down Expand Up @@ -114,7 +115,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
testV2 = must(cmd.Flags().GetBool(flagTestV2))
testV2Migration = must(cmd.Flags().GetBool(flagTestV2Migration))
skipPrecompiles = must(cmd.Flags().GetBool(flagSkipPrecompiles))
upgradeGateways = must(cmd.Flags().GetBool(flagUpgradeGateways))
upgradeContracts = must(cmd.Flags().GetBool(flagUpgradeContracts))
)

logger := runner.NewLogger(verbose, color.FgWhite, "setup")
Expand Down Expand Up @@ -226,7 +227,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
deployerRunner.ERC20CustodyAddr = deployerRunner.ERC20CustodyV2Addr

if testSolana {
deployerRunner.SetSolanaContracts(conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String())
deployerRunner.SetupSolana(conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String())
}
noError(deployerRunner.FundEmissionsPool())

Expand Down Expand Up @@ -413,9 +414,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
eg.Go(tonTestRoutine(conf, deployerRunner, verbose, tonTests...))
}

// upgrade gateways
if upgradeGateways {
deployerRunner.UpgradeGateways()
if upgradeContracts {
deployerRunner.UpgradeGatewaysAndERC20Custody()
}

if testV2 || testV2Migration {
Expand Down
4 changes: 2 additions & 2 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then
# When the upgrade height is greater than 100 for upgrade test, the Bitcoin tests have been run once, therefore the Bitcoin wallet is already set up
# Use light flag to skip advanced tests
if [ "$UPGRADE_HEIGHT" -lt 100 ]; then
zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --light --test-v2 --upgrade-gateways ${COMMON_ARGS}
zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --light --test-v2 --upgrade-contracts ${COMMON_ARGS}
else
zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --skip-bitcoin-setup --light --test-v2 --upgrade-gateways ${COMMON_ARGS}
zetae2e local $E2E_ARGS --skip-setup --config "$deployed_config_path" --skip-bitcoin-setup --light --test-v2 --upgrade-contracts ${COMMON_ARGS}
fi

ZETAE2E_EXIT_CODE=$?
Expand Down
9 changes: 0 additions & 9 deletions docs/releases/v20_breaking_changes.md

This file was deleted.

9 changes: 8 additions & 1 deletion docs/releases/v21_breaking_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@
* If the chain already exists, the details will be updated.
* If the chain does not exist, it will be added to the list of chains and saved to the store.
* A new transaction type `RemoveChainInfo` has also been added to remove a chain from the list of chains.
* It accepts the chain-id of the chain to be removed as a parameter.
* It accepts the chain-id of the chain to be removed as a parameter.

### Emissions factors deprecated

* `EmissionsFactors` have been deprecated and removed from the `emissions` module.
- This results in the removal of the query `/zeta-chain/emissions/get_emissions_factors`.
- The fixed block reward amount can now be queried via `/zeta-chain/emissions/params`. This is constant for every block and does not depend on any factors.

1 change: 1 addition & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ message MsgVoteGasPrice {
uint64 price = 3;
uint64 priority_fee = 6;
uint64 block_number = 4;
string supply = 5;
}
```

Expand Down
7 changes: 5 additions & 2 deletions e2e/e2etests/test_solana_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ import (
func TestSolanaWithdraw(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

withdrawAmount := parseBigInt(r, args[0])

// get ERC20 SOL balance before withdraw
balanceBefore, err := r.SOLZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress())
require.NoError(r, err)
r.Logger.Info("runner balance of SOL before withdraw: %d", balanceBefore)

require.Equal(r, 1, balanceBefore.Cmp(withdrawAmount), "Insufficient balance for withdrawal")

// parse withdraw amount (in lamports), approve amount is 1 SOL
approvedAmount := new(big.Int).SetUint64(solana.LAMPORTS_PER_SOL)
withdrawAmount := parseBigInt(r, args[0])
require.Equal(
r,
-1,
withdrawAmount.Cmp(approvedAmount),
"Withdrawal amount must be less than the approved amount (1e9).",
"Withdrawal amount must be less than the approved amount (1e9)",
)

// load deployer private key
Expand Down
5 changes: 3 additions & 2 deletions e2e/runner/admin_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ func (r *E2ERunner) UpdateTssAddressForConnector() {
func (r *E2ERunner) UpdateTssAddressForErc20custody() {
require.NoError(r, r.SetTSSAddresses())

tx, err := r.ERC20Custody.UpdateTSSAddress(r.EVMAuth, r.TSSAddress)
tx, err := r.ERC20CustodyV2.UpdateTSSAddress(r.EVMAuth, r.TSSAddress)
require.NoError(r, err)
r.Logger.Info(fmt.Sprintf("TSS ERC20 Address Update Tx: %s", tx.Hash().String()))
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)

tssAddressOnCustody, err := r.ERC20Custody.TSSAddress(&bind.CallOpts{Context: r.Ctx})
// we have to reference ERC20CustodyV2 since it's `TssAddress` on v2 and `TSSAddress` on v1
tssAddressOnCustody, err := r.ERC20CustodyV2.TssAddress(&bind.CallOpts{Context: r.Ctx})
require.NoError(r, err)
require.Equal(r, r.TSSAddress, tssAddressOnCustody)
}
70 changes: 68 additions & 2 deletions e2e/runner/setup_solana.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package runner

import (
"time"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
"github.com/near/borsh-go"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/utils"
"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/pkg/constant"
solanacontracts "github.com/zeta-chain/node/pkg/contracts/solana"
observertypes "github.com/zeta-chain/node/x/observer/types"
)

// SetupSolanaAccount imports the deployer's private key
Expand All @@ -20,8 +26,8 @@ func (r *E2ERunner) SetupSolanaAccount() {
r.Logger.Info("SolanaDeployerAddress: %s", r.SolanaDeployerAddress)
}

// SetSolanaContracts set Solana contracts
func (r *E2ERunner) SetSolanaContracts(deployerPrivateKey string) {
// SetupSolana sets Solana contracts and params
func (r *E2ERunner) SetupSolana(deployerPrivateKey string) {
r.Logger.Print("⚙️ initializing gateway program on Solana")

// set Solana contracts
Expand Down Expand Up @@ -78,4 +84,64 @@ func (r *E2ERunner) SetSolanaContracts(deployerPrivateKey string) {
balance, err := r.SolanaClient.GetBalance(r.Ctx, pdaComputed, rpc.CommitmentConfirmed)
require.NoError(r, err)
r.Logger.Info("initial PDA balance: %d lamports", balance.Value)

err = r.ensureSolanaChainParams()
require.NoError(r, err)
}

func (r *E2ERunner) ensureSolanaChainParams() error {
if r.ZetaTxServer == nil {
return errors.New("ZetaTxServer is not initialized")
}

creator := r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName)

chainID := chains.SolanaLocalnet.ChainId

chainParams := &observertypes.ChainParams{
ChainId: chainID,
ConfirmationCount: 32,
ZetaTokenContractAddress: constant.EVMZeroAddress,
ConnectorContractAddress: constant.EVMZeroAddress,
Erc20CustodyContractAddress: constant.EVMZeroAddress,
GasPriceTicker: 5,
WatchUtxoTicker: 0,
InboundTicker: 2,
OutboundTicker: 2,
OutboundScheduleInterval: 2,
OutboundScheduleLookahead: 5,
BallotThreshold: observertypes.DefaultBallotThreshold,
MinObserverDelegation: observertypes.DefaultMinObserverDelegation,
IsSupported: true,
GatewayAddress: solanacontracts.SolanaGatewayProgramID,
}

updateMsg := observertypes.NewMsgUpdateChainParams(creator, chainParams)

if _, err := r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, updateMsg); err != nil {
return errors.Wrap(err, "unable to broadcast solana chain params tx")
}

resetMsg := observertypes.NewMsgResetChainNonces(creator, chainID, 0, 0)
if _, err := r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, resetMsg); err != nil {
return errors.Wrap(err, "unable to broadcast solana chain nonce reset tx")
}

r.Logger.Print("⚙️ voted for adding solana chain params (localnet). Waiting for confirmation")

query := &observertypes.QueryGetChainParamsForChainRequest{ChainId: chainID}

const duration = 2 * time.Second

for i := 0; i < 10; i++ {
_, err := r.ObserverClient.GetChainParamsForChain(r.Ctx, query)
if err == nil {
r.Logger.Print("⚙️ solana chain params are set")
return nil
}

time.Sleep(duration)
}

return errors.New("unable to set Solana chain params")
}
4 changes: 2 additions & 2 deletions e2e/runner/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *E2ERunner) WithdrawSOLZRC20(
tx, err := r.SOLZRC20.Approve(r.ZEVMAuth, r.SOLZRC20Addr, approveAmount)
require.NoError(r, err)
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)
utils.RequireTxSuccessful(r, receipt, "approve")

// withdraw
tx, err = r.SOLZRC20.Withdraw(r.ZEVMAuth, []byte(to.String()), amount)
Expand All @@ -162,7 +162,7 @@ func (r *E2ERunner) WithdrawSOLZRC20(

// wait for tx receipt
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequireTxSuccessful(r, receipt)
utils.RequireTxSuccessful(r, receipt, "withdraw")
r.Logger.Info("Receipt txhash %s status %d", receipt.TxHash, receipt.Status)

// wait for the cctx to be mined
Expand Down
41 changes: 28 additions & 13 deletions e2e/runner/v2_setup_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,56 @@ func (r *E2ERunner) SetupEVMV2() {
initializerData, err := gatewayEVMABI.Pack("initialize", r.TSSAddress, r.ZetaEthAddr, r.Account.EVMAddress())
require.NoError(r, err)

// Deploy the proxy contract
proxyAddress, txProxy, _, err := erc1967proxy.DeployERC1967Proxy(
// Deploy gateway proxy contract
gatewayProxyAddress, gatewayProxyTx, _, err := erc1967proxy.DeployERC1967Proxy(
r.EVMAuth,
r.EVMClient,
gatewayEVMAddr,
initializerData,
)
require.NoError(r, err)

r.GatewayEVMAddr = proxyAddress
r.GatewayEVM, err = gatewayevm.NewGatewayEVM(proxyAddress, r.EVMClient)
r.GatewayEVMAddr = gatewayProxyAddress
r.GatewayEVM, err = gatewayevm.NewGatewayEVM(gatewayProxyAddress, r.EVMClient)
require.NoError(r, err)
r.Logger.Info("Gateway EVM contract address: %s, tx hash: %s", gatewayEVMAddr.Hex(), txGateway.Hash().Hex())

// Deploy erc20custody proxy contract
r.Logger.Info("Deploying ERC20Custody contract")
erc20CustodyNewAddr, txCustody, erc20CustodyNew, err := erc20custodyv2.DeployERC20Custody(
erc20CustodyAddr, txCustody, _, err := erc20custodyv2.DeployERC20Custody(r.EVMAuth, r.EVMClient)
require.NoError(r, err)

ensureTxReceipt(txCustody, "ERC20Custody deployment failed")

erc20CustodyABI, err := erc20custodyv2.ERC20CustodyMetaData.GetAbi()
require.NoError(r, err)

// Encode the initializer data
initializerData, err = erc20CustodyABI.Pack("initialize", r.GatewayEVMAddr, r.TSSAddress, r.Account.EVMAddress())
require.NoError(r, err)

// Deploy erc20custody proxy contract
erc20CustodyProxyAddress, erc20ProxyTx, _, err := erc1967proxy.DeployERC1967Proxy(
r.EVMAuth,
r.EVMClient,
r.GatewayEVMAddr,
r.TSSAddress,
r.Account.EVMAddress(),
erc20CustodyAddr,
initializerData,
)
require.NoError(r, err)

r.ERC20CustodyV2Addr = erc20CustodyNewAddr
r.ERC20CustodyV2 = erc20CustodyNew
r.ERC20CustodyV2Addr = erc20CustodyProxyAddress
r.ERC20CustodyV2, err = erc20custodyv2.NewERC20Custody(erc20CustodyProxyAddress, r.EVMClient)
require.NoError(r, err)
r.Logger.Info(
"ERC20CustodyV2 contract address: %s, tx hash: %s",
erc20CustodyNewAddr.Hex(),
erc20CustodyAddr.Hex(),
txCustody.Hash().Hex(),
)

ensureTxReceipt(txCustody, "ERC20CustodyV2 deployment failed")

// set custody contract in gateway
txSetCustody, err := r.GatewayEVM.SetCustody(r.EVMAuth, erc20CustodyNewAddr)
txSetCustody, err := r.GatewayEVM.SetCustody(r.EVMAuth, erc20CustodyProxyAddress)
require.NoError(r, err)

// deploy test dapp v2
Expand All @@ -96,7 +110,8 @@ func (r *E2ERunner) SetupEVMV2() {

// check contract deployment receipt
ensureTxReceipt(txDonation, "EVM donation tx failed")
ensureTxReceipt(txProxy, "Gateway proxy deployment failed")
ensureTxReceipt(gatewayProxyTx, "Gateway proxy deployment failed")
ensureTxReceipt(erc20ProxyTx, "ERC20Custody proxy deployment failed")
ensureTxReceipt(txSetCustody, "Set custody in Gateway failed")
ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed")

Expand Down
27 changes: 24 additions & 3 deletions e2e/runner/v2_gateway.go → e2e/runner/v2_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package runner
import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayzevm.sol"

"github.com/zeta-chain/node/e2e/utils"
)

// UpgradeGateways upgrades the GatewayEVM and GatewayZEVM contracts
// It deploy new gateway contract implementation with the current imported artifacts and upgrade the gateway contract
func (r *E2ERunner) UpgradeGateways() {
// UpgradeGatewaysAndERC20Custody upgrades gateways and ERC20Custody contracts
// It deploys new contract implementation with the current imported artifacts and upgrades the contract
func (r *E2ERunner) UpgradeGatewaysAndERC20Custody() {
r.UpgradeGatewayZEVM()
r.UpgradeGatewayEVM()
r.UpgradeERC20Custody()
}

// UpgradeGatewayZEVM upgrades the GatewayZEVM contract
Expand Down Expand Up @@ -53,3 +55,22 @@ func (r *E2ERunner) UpgradeGatewayEVM() {
require.NoError(r, err)
ensureTxReceipt(txUpgrade, "GatewayEVM upgrade failed")
}

// UpgradeERC20CustodyZEVM upgrades the ERC20Custody contract
func (r *E2ERunner) UpgradeERC20Custody() {
ensureTxReceipt := func(tx *ethtypes.Transaction, failMessage string) {
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)
r.requireTxSuccessful(receipt, failMessage+" tx hash: "+tx.Hash().Hex())
}

r.Logger.Info("Upgrading ERC20Custody contract")
// Deploy the new erc20Custody contract implementation
newImplementationAddress, txDeploy, _, err := erc20custody.DeployERC20Custody(r.EVMAuth, r.EVMClient)
require.NoError(r, err)
ensureTxReceipt(txDeploy, "New ERC20Custody implementation deployment failed")

// Upgrade
txUpgrade, err := r.ERC20CustodyV2.UpgradeToAndCall(r.EVMAuth, newImplementationAddress, []byte{})
require.NoError(r, err)
ensureTxReceipt(txUpgrade, "ERC20Custody upgrade failed")
}
Loading

0 comments on commit 9bee20b

Please sign in to comment.