Skip to content

Commit

Permalink
feat(fungible): add Gateway address in protocol contract list (#2578)
Browse files Browse the repository at this point in the history
* new gateway field

* initialize new message

* implement message

* cli

* add authorization

* make generate

* update changelogs

* Update x/fungible/client/cli/tx_update_gateway_contract.go

Co-authored-by: Dmitry S <[email protected]>

---------

Co-authored-by: Dmitry S <[email protected]>
  • Loading branch information
lumtis and swift1337 authored Jul 30, 2024
1 parent 571e3a4 commit 5771df3
Show file tree
Hide file tree
Showing 23 changed files with 1,430 additions and 120 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

* [2578](https://github.com/zeta-chain/node/pull/2578) - Add Gateway address in protocol contract list

## v19.0.0

### Breaking Changes
Expand Down
1 change: 1 addition & 0 deletions docs/cli/zetacored/zetacored_tx_fungible.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ zetacored tx fungible [flags]
* [zetacored tx fungible remove-foreign-coin](zetacored_tx_fungible_remove-foreign-coin.md) - Broadcast message RemoveForeignCoin
* [zetacored tx fungible unpause-zrc20](zetacored_tx_fungible_unpause-zrc20.md) - Broadcast message UnpauseZRC20
* [zetacored tx fungible update-contract-bytecode](zetacored_tx_fungible_update-contract-bytecode.md) - Broadcast message UpdateContractBytecode
* [zetacored tx fungible update-gateway-contract](zetacored_tx_fungible_update-gateway-contract.md) - Broadcast message UpdateGatewayContract to update the gateway contract address
* [zetacored tx fungible update-system-contract](zetacored_tx_fungible_update-system-contract.md) - Broadcast message UpdateSystemContract
* [zetacored tx fungible update-zrc20-liquidity-cap](zetacored_tx_fungible_update-zrc20-liquidity-cap.md) - Broadcast message UpdateZRC20LiquidityCap
* [zetacored tx fungible update-zrc20-withdraw-fee](zetacored_tx_fungible_update-zrc20-withdraw-fee.md) - Broadcast message UpdateZRC20WithdrawFee
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# tx fungible update-gateway-contract

Broadcast message UpdateGatewayContract to update the gateway contract address

```
zetacored tx fungible update-gateway-contract [contract-address] [flags]
```

### Options

```
-a, --account-number uint The account number of the signing account (offline mode only)
--aux Generate aux signer data instead of sending a tx
-b, --broadcast-mode string Transaction broadcasting mode (sync|async)
--chain-id string The network chain ID
--dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)
--fee-granter string Fee granter grants fees for the transaction
--fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer
--fees string Fees to pay along with transaction; eg: 10uatom
--from string Name or address of private key with which to sign
--gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000)
--gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1)
--gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)
--generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name)
-h, --help help for update-gateway-contract
--keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory)
--keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used
--ledger Use a connected Ledger device
--node string [host]:[port] to tendermint rpc interface for this chain
--note string Note to add a description to the transaction (previously --memo)
--offline Offline mode (does not allow any online functionality)
-o, --output string Output format (text|json)
-s, --sequence uint The sequence number of the signing account (offline mode only)
--sign-mode string Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature
--timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height
--tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator
-y, --yes Skip tx broadcasting prompt confirmation
```

### Options inherited from parent commands

```
--home string directory for config and data
--log_format string The logging format (json|plain)
--log_level string The logging level (trace|debug|info|warn|error|fatal|panic)
--log_no_color Disable colored logs
--trace print out full stack trace on errors
```

### SEE ALSO

* [zetacored tx fungible](zetacored_tx_fungible.md) - fungible transactions subcommands

4 changes: 4 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57653,6 +57653,8 @@ definitions:
type: object
fungibleMsgUpdateContractBytecodeResponse:
type: object
fungibleMsgUpdateGatewayContractResponse:
type: object
fungibleMsgUpdateSystemContractResponse:
type: object
fungibleMsgUpdateZRC20LiquidityCapResponse:
Expand Down Expand Up @@ -57711,6 +57713,8 @@ definitions:
type: string
connector_zevm:
type: string
gateway:
type: string
googlerpcStatus:
type: object
properties:
Expand Down
11 changes: 11 additions & 0 deletions docs/spec/fungible/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,14 @@ message MsgUnpauseZRC20 {
}
```

## MsgUpdateGatewayContract

UpdateGatewayContract updates the zevm gateway contract used by the ZetaChain protocol to read inbounds and process outbounds

```proto
message MsgUpdateGatewayContract {
string creator = 1;
string new_gateway_contract_address = 2;
}
```

7 changes: 7 additions & 0 deletions proto/zetachain/zetacore/fungible/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ message EventBytecodeUpdated {
string old_bytecode_hash = 4;
string signer = 5;
}

message EventGatewayContractUpdated {
string msg_type_url = 1;
string new_contract_address = 2;
string old_contract_address = 3;
string signer = 4;
}
1 change: 1 addition & 0 deletions proto/zetachain/zetacore/fungible/system_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ option go_package = "github.com/zeta-chain/zetacore/x/fungible/types";
message SystemContract {
string system_contract = 1;
string connector_zevm = 2;
string gateway = 3;
}
11 changes: 10 additions & 1 deletion proto/zetachain/zetacore/fungible/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ service Msg {
returns (MsgUpdateZRC20LiquidityCapResponse);
rpc PauseZRC20(MsgPauseZRC20) returns (MsgPauseZRC20Response);
rpc UnpauseZRC20(MsgUnpauseZRC20) returns (MsgUnpauseZRC20Response);
rpc UpdateGatewayContract(MsgUpdateGatewayContract)
returns (MsgUpdateGatewayContractResponse);
}

message MsgDeploySystemContracts { string creator = 1; }
Expand Down Expand Up @@ -109,4 +111,11 @@ message MsgUnpauseZRC20 {
repeated string zrc20_addresses = 2;
}

message MsgUnpauseZRC20Response {}
message MsgUnpauseZRC20Response {}

message MsgUpdateGatewayContract {
string creator = 1;
string new_gateway_contract_address = 2;
}

message MsgUpdateGatewayContractResponse {}
39 changes: 39 additions & 0 deletions typescript/zetachain/zetacore/fungible/events_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,42 @@ export declare class EventBytecodeUpdated extends Message<EventBytecodeUpdated>
static equals(a: EventBytecodeUpdated | PlainMessage<EventBytecodeUpdated> | undefined, b: EventBytecodeUpdated | PlainMessage<EventBytecodeUpdated> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.fungible.EventGatewayContractUpdated
*/
export declare class EventGatewayContractUpdated extends Message<EventGatewayContractUpdated> {
/**
* @generated from field: string msg_type_url = 1;
*/
msgTypeUrl: string;

/**
* @generated from field: string new_contract_address = 2;
*/
newContractAddress: string;

/**
* @generated from field: string old_contract_address = 3;
*/
oldContractAddress: string;

/**
* @generated from field: string signer = 4;
*/
signer: string;

constructor(data?: PartialMessage<EventGatewayContractUpdated>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.fungible.EventGatewayContractUpdated";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): EventGatewayContractUpdated;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): EventGatewayContractUpdated;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): EventGatewayContractUpdated;

static equals(a: EventGatewayContractUpdated | PlainMessage<EventGatewayContractUpdated> | undefined, b: EventGatewayContractUpdated | PlainMessage<EventGatewayContractUpdated> | undefined): boolean;
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export declare class SystemContract extends Message<SystemContract> {
*/
connectorZevm: string;

/**
* @generated from field: string gateway = 3;
*/
gateway: string;

constructor(data?: PartialMessage<SystemContract>);

static readonly runtime: typeof proto3;
Expand Down
48 changes: 48 additions & 0 deletions typescript/zetachain/zetacore/fungible/tx_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,51 @@ export declare class MsgUnpauseZRC20Response extends Message<MsgUnpauseZRC20Resp
static equals(a: MsgUnpauseZRC20Response | PlainMessage<MsgUnpauseZRC20Response> | undefined, b: MsgUnpauseZRC20Response | PlainMessage<MsgUnpauseZRC20Response> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.fungible.MsgUpdateGatewayContract
*/
export declare class MsgUpdateGatewayContract extends Message<MsgUpdateGatewayContract> {
/**
* @generated from field: string creator = 1;
*/
creator: string;

/**
* @generated from field: string new_gateway_contract_address = 2;
*/
newGatewayContractAddress: string;

constructor(data?: PartialMessage<MsgUpdateGatewayContract>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.fungible.MsgUpdateGatewayContract";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MsgUpdateGatewayContract;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): MsgUpdateGatewayContract;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): MsgUpdateGatewayContract;

static equals(a: MsgUpdateGatewayContract | PlainMessage<MsgUpdateGatewayContract> | undefined, b: MsgUpdateGatewayContract | PlainMessage<MsgUpdateGatewayContract> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.fungible.MsgUpdateGatewayContractResponse
*/
export declare class MsgUpdateGatewayContractResponse extends Message<MsgUpdateGatewayContractResponse> {
constructor(data?: PartialMessage<MsgUpdateGatewayContractResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.fungible.MsgUpdateGatewayContractResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): MsgUpdateGatewayContractResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): MsgUpdateGatewayContractResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): MsgUpdateGatewayContractResponse;

static equals(a: MsgUpdateGatewayContractResponse | PlainMessage<MsgUpdateGatewayContractResponse> | undefined, b: MsgUpdateGatewayContractResponse | PlainMessage<MsgUpdateGatewayContractResponse> | undefined): boolean;
}

1 change: 1 addition & 0 deletions x/authority/types/authorization_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
"/zetachain.zetacore.crosschain.MsgWhitelistERC20",
"/zetachain.zetacore.fungible.MsgUpdateContractBytecode",
"/zetachain.zetacore.fungible.MsgUpdateSystemContract",
"/zetachain.zetacore.fungible.MsgUpdateGatewayContract",
"/zetachain.zetacore.fungible.MsgRemoveForeignCoin",
"/zetachain.zetacore.fungible.MsgDeployFungibleCoinZRC20",
"/zetachain.zetacore.observer.MsgUpdateObserver",
Expand Down
1 change: 1 addition & 0 deletions x/authority/types/authorization_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ func TestDefaultAuthorizationsList(t *testing.T) {
sdk.MsgTypeURL(&fungibletypes.MsgDeployFungibleCoinZRC20{}),
sdk.MsgTypeURL(&fungibletypes.MsgUpdateContractBytecode{}),
sdk.MsgTypeURL(&fungibletypes.MsgUpdateSystemContract{}),
sdk.MsgTypeURL(&fungibletypes.MsgUpdateGatewayContract{}),
sdk.MsgTypeURL(&fungibletypes.MsgRemoveForeignCoin{}),
sdk.MsgTypeURL(&observertypes.MsgUpdateObserver{}),
sdk.MsgTypeURL(&observertypes.MsgAddObserver{}),
Expand Down
1 change: 1 addition & 0 deletions x/fungible/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func GetTxCmd() *cobra.Command {
CmdPauseZRC20(),
CmdUnpauseZRC20(),
CmdUpdateZRC20WithdrawFee(),
CmdUpdateGatewayContract(),
)

return cmd
Expand Down
35 changes: 35 additions & 0 deletions x/fungible/client/cli/tx_update_gateway_contract.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"

"github.com/zeta-chain/zetacore/x/fungible/types"
)

func CmdUpdateGatewayContract() *cobra.Command {
cmd := &cobra.Command{
Use: "update-gateway-contract [contract-address]",
Short: "Broadcast message UpdateGatewayContract to update the gateway contract address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgUpdateGatewayContract(clientCtx.GetFromAddress().String(), args[0])
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
53 changes: 53 additions & 0 deletions x/fungible/keeper/msg_server_update_gateway_contract.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package keeper

import (
"context"

cosmoserrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
"github.com/zeta-chain/zetacore/x/fungible/types"
)

// UpdateGatewayContract updates the zevm gateway contract used by the ZetaChain protocol to read inbounds and process outbounds
func (k msgServer) UpdateGatewayContract(
goCtx context.Context,
msg *types.MsgUpdateGatewayContract,
) (*types.MsgUpdateGatewayContractResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
err := k.GetAuthorityKeeper().CheckAuthorization(ctx, msg)
if err != nil {
return nil, cosmoserrors.Wrap(authoritytypes.ErrUnauthorized, err.Error())
}

// The SystemContract state variable tracks the contract addresses used by the protocol
// This variable is planned to be renamed ProtocolContracts in the future:
// https://github.com/zeta-chain/node/issues/2576
var protocolContracts types.SystemContract
protocolContracts, found := k.GetSystemContract(ctx)
if !found {
// protocolContracts has never been set before, set an empty structure
protocolContracts = types.SystemContract{}
}
oldGateway := protocolContracts.Gateway

// update address and save
protocolContracts.Gateway = msg.NewGatewayContractAddress
k.SetSystemContract(ctx, protocolContracts)

err = ctx.EventManager().EmitTypedEvent(
&types.EventGatewayContractUpdated{
MsgTypeUrl: sdk.MsgTypeURL(&types.MsgUpdateGatewayContract{}),
NewContractAddress: msg.NewGatewayContractAddress,
OldContractAddress: oldGateway,
Signer: msg.Creator,
},
)
if err != nil {
k.Logger(ctx).Error("failed to emit event", "error", err.Error())
return nil, cosmoserrors.Wrapf(types.ErrEmitEvent, "failed to emit event (%s)", err.Error())
}

return &types.MsgUpdateGatewayContractResponse{}, nil
}
Loading

0 comments on commit 5771df3

Please sign in to comment.