Skip to content

Commit

Permalink
Merge branch 'develop' into refactor-core-params
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored Oct 16, 2023
2 parents b58c12a + 7b6e305 commit 412602b
Show file tree
Hide file tree
Showing 37 changed files with 1,276 additions and 366 deletions.
7 changes: 3 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
emissionsModule "github.com/zeta-chain/zetacore/x/emissions"
emissionsModuleKeeper "github.com/zeta-chain/zetacore/x/emissions/keeper"
emissionsModuleTypes "github.com/zeta-chain/zetacore/x/emissions/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -97,10 +100,6 @@ import (
zetaCoreModuleKeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper"
zetaCoreModuleTypes "github.com/zeta-chain/zetacore/x/crosschain/types"

emissionsModule "github.com/zeta-chain/zetacore/x/emissions"
emissionsModuleKeeper "github.com/zeta-chain/zetacore/x/emissions/keeper"
emissionsModuleTypes "github.com/zeta-chain/zetacore/x/emissions/types"

fungibleModule "github.com/zeta-chain/zetacore/x/fungible"
fungibleModuleKeeper "github.com/zeta-chain/zetacore/x/fungible/keeper"
fungibleModuleTypes "github.com/zeta-chain/zetacore/x/fungible/types"
Expand Down
3 changes: 2 additions & 1 deletion common/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package common
// commands for the zetaclient; mostly administrative commands/txs

const (
CmdWhitelistERC20 = "cmd_whitelist_erc20"
CmdWhitelistERC20 = "cmd_whitelist_erc20"
CmdMigrateTssFunds = "cmd_migrate_tss_funds"
)
7 changes: 7 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26841,6 +26841,11 @@ paths:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: tss_pub_key
in: query
required: false
type: string
tags:
- Query
/zeta-chain/crosschain/in_tx_hash_to_cctx_data/{inTxHash}:
Expand Down Expand Up @@ -50560,6 +50565,8 @@ definitions:
type: object
crosschainMsgGasPriceVoterResponse:
type: object
crosschainMsgMigrateTssFundsResponse:
type: object
crosschainMsgNonceVoterResponse:
type: object
crosschainMsgRemoveFromOutTxTrackerResponse:
Expand Down
10 changes: 10 additions & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,13 @@ message MsgUpdateTssAddress {
}
```

## MsgMigrateTssFunds

```proto
message MsgMigrateTssFunds {
string creator = 1;
int64 chain_id = 2;
string amount = 3;
}
```

4 changes: 3 additions & 1 deletion proto/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ message QueryAllInTxHashToCctxResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetTssAddressRequest {}
message QueryGetTssAddressRequest {
string tss_pub_key = 1;
}

message QueryGetTssAddressResponse {
string eth = 1;
Expand Down
11 changes: 11 additions & 0 deletions proto/crosschain/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ service Msg {
rpc VoteOnObservedInboundTx(MsgVoteOnObservedInboundTx) returns (MsgVoteOnObservedInboundTxResponse);
rpc WhitelistERC20(MsgWhitelistERC20) returns (MsgWhitelistERC20Response);
rpc UpdateTssAddress(MsgUpdateTssAddress) returns (MsgUpdateTssAddressResponse);
rpc MigrateTssFunds(MsgMigrateTssFunds) returns (MsgMigrateTssFundsResponse);
// rpc ProveOutboundTx(MsgProveOutboundTx) returns (MsgProveOutboundTxResponse);
}

message MsgMigrateTssFunds {
string creator = 1;
int64 chain_id = 2;
string amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
}
message MsgMigrateTssFundsResponse {}

message MsgUpdateTssAddress {
string creator = 1;
string tss_pubkey = 2;
Expand Down
24 changes: 12 additions & 12 deletions testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
emissionsmodule "github.com/zeta-chain/zetacore/x/emissions"
emissionskeeper "github.com/zeta-chain/zetacore/x/emissions/keeper"
emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types"
types2 "github.com/zeta-chain/zetacore/x/emissions/types"
fungiblemodule "github.com/zeta-chain/zetacore/x/fungible"
fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper"
fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types"
Expand Down Expand Up @@ -94,16 +94,16 @@ type ZetaKeepers struct {
}

var moduleAccountPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionstypes.ModuleName: nil,
emissionstypes.UndistributedObserverRewardsPool: nil,
emissionstypes.UndistributedTssRewardsPool: nil,
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
types2.ModuleName: nil,
types2.UndistributedObserverRewardsPool: nil,
types2.UndistributedTssRewardsPool: nil,
}

// ModuleAccountAddrs returns all the app's module account addresses.
Expand Down Expand Up @@ -363,7 +363,7 @@ func (zk ZetaKeepers) InitGenesis(ctx sdk.Context) {
crosschainmodule.InitGenesis(ctx, *zk.CrosschainKeeper, *crosschaintypes.DefaultGenesis())
}
if zk.EmissionsKeeper != nil {
emissionsmodule.InitGenesis(ctx, *zk.EmissionsKeeper, *emissionstypes.DefaultGenesis())
emissionsmodule.InitGenesis(ctx, *zk.EmissionsKeeper, *types2.DefaultGenesis())
}
if zk.FungibleKeeper != nil {
fungiblemodule.InitGenesis(ctx, *zk.FungibleKeeper, *fungibletypes.DefaultGenesis())
Expand Down
8 changes: 4 additions & 4 deletions testutil/simapp/simapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
emissionsModuleTypes "github.com/zeta-chain/zetacore/x/emissions/types"
types2 "github.com/zeta-chain/zetacore/x/emissions/types"

//"github.com/ignite-hq/cli/ignite/pkg/cosmoscmd"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -58,7 +58,7 @@ func setup(withGenesis bool, invCheckPeriod uint) (*app.App, app.GenesisState) {
return a, app.GenesisState{}
}

func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genDelAccs []authtypes.GenesisAccount, bondAmt sdk.Int, emissionParams emissionsModuleTypes.Params, genDelBalances []banktypes.Balance, genBalances []banktypes.Balance) *app.App {
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genDelAccs []authtypes.GenesisAccount, bondAmt sdk.Int, emissionParams types2.Params, genDelBalances []banktypes.Balance, genBalances []banktypes.Balance) *app.App {
app, genesisState := setup(true, 5)
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genDelAccs)
Expand Down Expand Up @@ -90,9 +90,9 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genDelAc
delegations = append(delegations, stakingtypes.NewDelegation(genDelAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
}

emissionsGenesis := emissionsModuleTypes.DefaultGenesis()
emissionsGenesis := types2.DefaultGenesis()
emissionsGenesis.Params = emissionParams
genesisState[emissionsModuleTypes.ModuleName] = app.AppCodec().MustMarshalJSON(emissionsGenesis)
genesisState[types2.ModuleName] = app.AppCodec().MustMarshalJSON(emissionsGenesis)
// set validators and delegations
params := stakingtypes.DefaultParams()
params.BondDenom = config.BaseDenom
Expand Down
31 changes: 31 additions & 0 deletions x/crosschain/client/cli/cli_cctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ func CmdListSend() *cobra.Command {
return cmd
}

func CmdPendingCctx() *cobra.Command {
cmd := &cobra.Command{
Use: "list-pending-cctx [chain-id]",
Short: "shows pending CCTX",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)
chainID, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}
params := &types.QueryAllCctxPendingRequest{
ChainId: chainID,
}

res, err := queryClient.CctxAllPending(context.Background(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdShowSend() *cobra.Command {
cmd := &cobra.Command{
Use: "show-cctx [index]",
Expand Down
26 changes: 26 additions & 0 deletions x/crosschain/client/cli/cli_chain_nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ func CmdShowChainNonces() *cobra.Command {
return cmd
}

func CmdListPendingNonces() *cobra.Command {
cmd := &cobra.Command{
Use: "list-pending-nonces",
Short: "shows a chainNonces",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryAllPendingNoncesRequest{}

res, err := queryClient.PendingNoncesAll(context.Background(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// Transaction CLI /////////////////////////

func CmdNonceVoter() *cobra.Command {
Expand Down
30 changes: 30 additions & 0 deletions x/crosschain/client/cli/cli_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strconv"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cast"
"github.com/zeta-chain/zetacore/common"
Expand Down Expand Up @@ -137,3 +138,32 @@ func CmdUpdateTss() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)
return cmd
}

func CmdMigrateTssFunds() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate-tss-funds [chainID] [amount]",
Short: "Migrate TSS funds to the latest TSS address",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {

argsChainID, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}
argsAmount := math.NewUintFromString(args[1])
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgMigrateTssFunds(clientCtx.GetFromAddress().String(), argsChainID, argsAmount)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}
2 changes: 2 additions & 0 deletions x/crosschain/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func GetQueryCmd(_ string) *cobra.Command {
CmdQueryParams(),
CmdGetTssAddress(),
CmdListTssHistory(),
CmdListPendingNonces(),
CmdPendingCctx(),
)

return cmd
Expand Down
12 changes: 9 additions & 3 deletions x/crosschain/client/cli/query_get_tss_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ import (

func CmdGetTssAddress() *cobra.Command {
cmd := &cobra.Command{
Use: "get-tss-address",
Use: "get-tss-address [tss-pubkey]",
Short: "Query current tss address",
Args: cobra.NoArgs,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
tssPubKey := ""
if len(args) == 1 {
tssPubKey = args[0]
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryGetTssAddressRequest{}
params := &types.QueryGetTssAddressRequest{
TssPubKey: tssPubKey,
}

res, err := queryClient.GetTssAddress(cmd.Context(), params)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/crosschain/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func GetTxCmd() *cobra.Command {
CmdCCTXInboundVoter(),
CmdRemoveFromWatchList(),
CmdUpdateTss(),
CmdMigrateTssFunds(),
)

return cmd
Expand Down
9 changes: 7 additions & 2 deletions x/crosschain/keeper/gas_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ func (k Keeper) PayGasInERC20AndUpdateCctx(
)
gasObtained := amounts[2]

// FIXME: investigate small mismatches between gasObtained and outTxGasFee
// https://github.com/zeta-chain/node/issues/1303
// check if the final gas received after swap matches the gas fee defined
// if not there might be issues with the pool liquidity and it is safer from an accounting perspective to return an error
if gasObtained.Cmp(outTxGasFee.BigInt()) != 0 {
return cosmoserrors.Wrapf(types.ErrInvalidGasAmount, "gas obtained for burn (%s) not equal to gas fee(%s)", gasObtained, outTxGasFee)
if gasObtained.Cmp(outTxGasFee.BigInt()) == -1 {
return cosmoserrors.Wrapf(types.ErrInvalidGasAmount, "gas obtained for burn (%s) is lower than gas fee(%s)", gasObtained, outTxGasFee)
}

// burn the gas ZRC20
Expand Down Expand Up @@ -333,6 +335,9 @@ func (k Keeper) PayGasInZetaAndUpdateCctx(
"zetaAmountIn", amounts[0],
"zrc20AmountOut", amounts[1],
)

// FIXME: investigate small mismatches between amounts[1] and outTxGasFee
// https://github.com/zeta-chain/node/issues/1303
err = k.fungibleKeeper.CallZRC20Burn(ctx, types.ModuleAddressEVM, gasZRC20, amounts[1], noEthereumTxEvent)
if err != nil {
return cosmoserrors.Wrap(err, "PayGasInZetaAndUpdateCctx: unable to CallZRC20Burn")
Expand Down
23 changes: 17 additions & 6 deletions x/crosschain/keeper/grpc_query_get_tss_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@ func (k Keeper) GetTssAddress(goCtx context.Context, req *types.QueryGetTssAddre
}

ctx := sdk.UnwrapSDKContext(goCtx)

tss, found := k.GetTSS(ctx)
if !found {
return nil, status.Error(codes.NotFound, "not found")
var tssPubKey string
if req.TssPubKey == "" {
tss, found := k.GetTSS(ctx)
if !found {
return nil, status.Error(codes.NotFound, "current tss not set")
}
tssPubKey = tss.TssPubkey
} else {
tssList := k.GetAllTSS(ctx)
for _, t := range tssList {
if t.TssPubkey == req.TssPubKey {
tssPubKey = t.TssPubkey
break
}
}
}
ethAddress, err := getTssAddrEVM(tss.TssPubkey)
ethAddress, err := getTssAddrEVM(tssPubKey)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
btcAddress, err := getTssAddrBTC(tss.TssPubkey)
btcAddress, err := getTssAddrBTC(tssPubKey)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
Loading

0 comments on commit 412602b

Please sign in to comment.