Skip to content

Commit

Permalink
Merge branch 'develop' into blame-index-update
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinssgh authored Oct 10, 2023
2 parents 2bcbde3 + ed35305 commit 4f66489
Show file tree
Hide file tree
Showing 33 changed files with 642 additions and 257 deletions.
1 change: 1 addition & 0 deletions docs/spec/fungible/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ message MsgUpdateZRC20WithdrawFee {
string creator = 1;
string zrc20_address = 2;
string new_withdraw_fee = 6;
string new_gas_limit = 7;
}
```

Expand Down
2 changes: 2 additions & 0 deletions proto/fungible/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ message EventZRC20WithdrawFeeUpdated {
string old_withdraw_fee = 5;
string new_withdraw_fee = 6;
string signer = 7;
string old_gas_limit = 8;
string new_gas_limit = 9;
}

message EventZRC20PausedStatusUpdated {
Expand Down
4 changes: 4 additions & 0 deletions proto/fungible/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ message MsgUpdateZRC20WithdrawFee {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
string new_gas_limit = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
}

message MsgUpdateZRC20WithdrawFeeResponse {}
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/bank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/fungible.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 3 additions & 13 deletions testutil/keeper/mocks/crosschain/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/crosschain/staking.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/bank.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/evm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testutil/keeper/mocks/fungible/observer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions x/crosschain/keeper/gas_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) {
zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar")
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) {
zrc20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "foobar")
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) {
)
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -497,7 +497,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) {
gasZRC20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foo", "foo")
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -551,7 +551,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) {
)
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down Expand Up @@ -605,7 +605,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) {
)
_, err := zk.FungibleKeeper.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee)),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}),
)
require.NoError(t, err)
k.SetGasPrice(ctx, types.GasPrice{
Expand Down
10 changes: 4 additions & 6 deletions x/crosschain/keeper/keeper_chain_nonces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"fmt"

zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -108,12 +107,11 @@ func (k msgServer) NonceVoter(goCtx context.Context, msg *types.MsgNonceVoter) (
ctx := sdk.UnwrapSDKContext(goCtx)
chain := k.zetaObserverKeeper.GetParams(ctx).GetChainFromChainID(msg.ChainId)
if chain == nil {
return nil, zetaObserverTypes.ErrSupportedChains
return nil, observertypes.ErrSupportedChains
}

ok, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain)
if !ok {
return nil, err
if ok := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain); !ok {
return nil, observertypes.ErrNotAuthorizedPolicy
}
chainNonce, isFound := k.GetChainNonces(ctx, chain.ChainName.String())

Expand Down
5 changes: 2 additions & 3 deletions x/crosschain/keeper/keeper_cross_chain_tx_vote_inbound_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ func (k msgServer) VoteOnObservedInboundTx(goCtx context.Context, msg *types.Msg
tssPub = tss.TssPubkey
}
// IsAuthorized does various checks against the list of observer mappers
ok, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, observationChain)
if !ok {
return nil, err
if ok := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, observationChain); !ok {
return nil, observerTypes.ErrNotAuthorizedPolicy
}

index := msg.Digest()
Expand Down
5 changes: 2 additions & 3 deletions x/crosschain/keeper/keeper_cross_chain_tx_vote_outbound_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ func (k msgServer) VoteOnObservedOutboundTx(goCtx context.Context, msg *types.Ms
return nil, err
}
//Check is msg.Creator is authorized to vote
ok, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, observationChain)
if !ok {
return nil, err
if ok := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, observationChain); !ok {
return nil, observerTypes.ErrNotAuthorizedPolicy
}

// Check if CCTX exists
Expand Down
9 changes: 4 additions & 5 deletions x/crosschain/keeper/keeper_gas_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/zeta-chain/zetacore/x/crosschain/types"
zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -127,11 +127,10 @@ func (k msgServer) GasPriceVoter(goCtx context.Context, msg *types.MsgGasPriceVo

chain := k.zetaObserverKeeper.GetParams(ctx).GetChainFromChainID(msg.ChainId)
if chain == nil {
return nil, zetaObserverTypes.ErrSupportedChains
return nil, observertypes.ErrSupportedChains
}
ok, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain)
if !ok {
return nil, err
if ok := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain); !ok {
return nil, observertypes.ErrNotAuthorizedPolicy
}
if chain == nil {
return nil, sdkerrors.Wrap(types.ErrUnsupportedChain, fmt.Sprintf("ChainID : %d ", msg.ChainId))
Expand Down
7 changes: 2 additions & 5 deletions x/crosschain/keeper/keeper_out_tx_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,8 @@ func (k msgServer) AddToOutTxTracker(goCtx context.Context, msg *types.MsgAddToO
adminPolicyAccount := k.zetaObserverKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_group1)
isAdmin := msg.Creator == adminPolicyAccount

isObserver, err := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain)
if err != nil {
ctx.Logger().Error("Error while checking if the account is an observer", err)
return nil, cosmoserrors.Wrap(observertypes.ErrNotAuthorized, fmt.Sprintf("error IsAuthorized %s", msg.Creator))
}
isObserver := k.zetaObserverKeeper.IsAuthorized(ctx, msg.Creator, chain)

// Sender needs to be either the admin policy account or an observer
if !(isAdmin || isObserver) {
return nil, cosmoserrors.Wrap(observertypes.ErrNotAuthorized, fmt.Sprintf("Creator %s", msg.Creator))
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ var (
ErrNotEnoughZetaBurnt = errorsmod.Register(ModuleName, 1109, "not enough zeta burnt")
ErrCannotFindReceiverNonce = errorsmod.Register(ModuleName, 1110, "cannot find receiver chain nonce")

ErrGasCoinNotFound = errorsmod.Register(ModuleName, 1113, "gas coin not found for SenderChain")
ErrGasCoinNotFound = errorsmod.Register(ModuleName, 1113, "gas coin not found for sender chain")
ErrUnableToParseAddress = errorsmod.Register(ModuleName, 1115, "cannot parse address and data")
ErrCannotProcessWithdrawal = errorsmod.Register(ModuleName, 1116, "cannot process withdrawal event")
ErrForeignCoinNotFound = errorsmod.Register(ModuleName, 1118, "gas coin not found for SenderChain")
ErrForeignCoinNotFound = errorsmod.Register(ModuleName, 1118, "foreign coin not found for sender chain")
ErrNotEnoughPermissions = errorsmod.Register(ModuleName, 1119, "not enough permissions for current actions")

ErrCannotFindPendingNonces = errorsmod.Register(ModuleName, 1121, "cannot find pending nonces")
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type ZetaObserverKeeper interface {
SetLastObserverCount(ctx sdk.Context, lbc *zetaObserverTypes.LastObserverCount)
AddVoteToBallot(ctx sdk.Context, ballot zetaObserverTypes.Ballot, address string, observationType zetaObserverTypes.VoteType) (zetaObserverTypes.Ballot, error)
CheckIfFinalizingVote(ctx sdk.Context, ballot zetaObserverTypes.Ballot) (zetaObserverTypes.Ballot, bool)
IsAuthorized(ctx sdk.Context, address string, chain *common.Chain) (bool, error)
IsAuthorized(ctx sdk.Context, address string, chain *common.Chain) bool
FindBallot(ctx sdk.Context, index string, chain *common.Chain, observationType zetaObserverTypes.ObservationType) (ballot zetaObserverTypes.Ballot, isNew bool, err error)
AddBallotToList(ctx sdk.Context, ballot zetaObserverTypes.Ballot)
GetBlockHeader(ctx sdk.Context, hash []byte) (val common.BlockHeader, found bool)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"math/big"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/zeta-chain/zetacore/common"
Expand Down Expand Up @@ -146,7 +148,12 @@ func (k Keeper) TestUpdateZRC20WithdrawFee(goCtx context.Context) error {
creator := k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(observertypes.Policy_Type_group1)

for _, foreignCoin := range foreignCoins {
msg := types.NewMsgUpdateZRC20WithdrawFee(creator, foreignCoin.Zrc20ContractAddress, sdk.NewUint(uint64(foreignCoin.ForeignChainId)))
msg := types.NewMsgUpdateZRC20WithdrawFee(
creator,
foreignCoin.Zrc20ContractAddress,
sdk.NewUint(uint64(foreignCoin.ForeignChainId)),
math.Uint{},
)
_, err := k.UpdateZRC20WithdrawFee(ctx, msg)
if err != nil {
return err
Expand Down
62 changes: 61 additions & 1 deletion x/fungible/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,67 @@ func (k Keeper) DepositZRC20(
if err != nil {
return nil, err
}
return k.CallEVM(ctx, *zrc20ABI, types.ModuleAddressEVM, contract, BigIntZero, nil, true, false, "deposit", to, amount)
return k.CallEVM(
ctx,
*zrc20ABI,
types.ModuleAddressEVM,
contract,
BigIntZero,
nil,
true,
false,
"deposit",
to,
amount,
)
}

// UpdateZRC20ProtocolFlatFee updates the protocol flat fee for a given ZRC20 contract
func (k Keeper) UpdateZRC20ProtocolFlatFee(
ctx sdk.Context,
zrc20Addr common.Address,
newFee *big.Int,
) (*evmtypes.MsgEthereumTxResponse, error) {
zrc20ABI, err := zrc20.ZRC20MetaData.GetAbi()
if err != nil {
return nil, err
}
return k.CallEVM(
ctx,
*zrc20ABI,
types.ModuleAddressEVM,
zrc20Addr,
BigIntZero,
nil,
true,
false,
"updateProtocolFlatFee",
newFee,
)
}

// UpdateZRC20GasLimit updates the gas limit for a given ZRC20 contract
func (k Keeper) UpdateZRC20GasLimit(
ctx sdk.Context,
zrc20Addr common.Address,
newGasLimit *big.Int,
) (*evmtypes.MsgEthereumTxResponse, error) {
zrc20ABI, err := zrc20.ZRC20MetaData.GetAbi()
if err != nil {
return nil, err
}
return k.CallEVM(
ctx,
*zrc20ABI,
types.ModuleAddressEVM,
zrc20Addr,
BigIntZero,
nil,
true,
false,
"updateGasLimit",
newGasLimit,
)
}

// DepositZRC20AndCallContract deposits into ZRC4 and call contract function in a single tx
Expand Down
9 changes: 8 additions & 1 deletion x/fungible/keeper/foreign_coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/fungible/types"
)
Expand Down Expand Up @@ -93,9 +94,15 @@ func (k Keeper) GetGasCoinForForeignCoin(ctx sdk.Context, chainID int64) (types.

// GetForeignCoinFromAsset returns the foreign coin for a given asset for a given chain
func (k Keeper) GetForeignCoinFromAsset(ctx sdk.Context, asset string, chainID int64) (types.ForeignCoins, bool) {
if !ethcommon.IsHexAddress(asset) {
return types.ForeignCoins{}, false
}
assetAddr := ethcommon.HexToAddress(asset)

foreignCoinList := k.GetAllForeignCoinsForChain(ctx, chainID)
for _, coin := range foreignCoinList {
if coin.Asset == asset && coin.ForeignChainId == chainID {
coinAssetAddr := ethcommon.HexToAddress(coin.Asset)
if coinAssetAddr == assetAddr && coin.ForeignChainId == chainID {
return coin, true
}
}
Expand Down
Loading

0 comments on commit 4f66489

Please sign in to comment.