Skip to content

Commit

Permalink
remove checks for unsupported chains, which allows refunds to sender …
Browse files Browse the repository at this point in the history
…chains which become unsupported
  • Loading branch information
kingpinXD committed Feb 8, 2024
1 parent 4b41800 commit 191f876
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions x/crosschain/keeper/msg_server_vote_inbound_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (k msgServer) VoteOnObservedInboundTx(goCtx context.Context, msg *types.Msg
// gas payment for erc20 type might fail because no liquidity pool is defined to swap the zrc20 token into the gas token
// in this gas we should refund the sender on ZetaChain
if cctx.InboundTxParams.CoinType == common.CoinType_ERC20 && ethcommon.IsHexAddress(cctx.InboundTxParams.Sender) {
// Sender is verified to be a valid ethereum address
if err := k.RefundAbortedAmountOnZetaChain(ctx, cctx, ethcommon.HexToAddress(cctx.InboundTxParams.Sender)); err != nil {
// log the error
k.Logger(ctx).Error("failed to refund amount of aborted cctx on ZetaChain",
Expand Down
12 changes: 3 additions & 9 deletions x/crosschain/keeper/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/x/crosschain/types"
zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types"
)

func (k Keeper) RefundAbortedAmountOnZetaChain(ctx sdk.Context, cctx types.CrossChainTx, refundAddress ethcommon.Address) error {
Expand All @@ -34,10 +33,6 @@ func (k Keeper) RefundAmountOnZetaChainGas(ctx sdk.Context, cctx types.CrossChai
}
chainID := cctx.InboundTxParams.SenderChainId
amountOfGasTokenLocked := cctx.InboundTxParams.Amount
// check if chain is supported
if chain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, chainID); chain == nil {
return zetaObserverTypes.ErrSupportedChains
}
// get the zrc20 contract address
fcSenderChain, found := k.fungibleKeeper.GetGasCoinForForeignCoin(ctx, chainID)
if !found {
Expand All @@ -57,11 +52,10 @@ func (k Keeper) RefundAmountOnZetaChainGas(ctx sdk.Context, cctx types.CrossChai
// RefundAmountOnZetaChainGas refunds the amount of the cctx on ZetaChain in case of aborted cctx with cointype zeta
func (k Keeper) RefundAmountOnZetaChainZeta(ctx sdk.Context, cctx types.CrossChainTx, refundAddress ethcommon.Address) error {
// if coin type is Zeta, handle this as a deposit ZETA to zEVM.
// deposit the amount to the tx origin instead of receiver as this is a refund
chainID := cctx.InboundTxParams.SenderChainId
// check if chain is supported
if chain := k.zetaObserverKeeper.GetSupportedChainFromChainID(ctx, chainID); chain == nil {
return zetaObserverTypes.ErrSupportedChains
// check if chain is an EVM chain
if !common.IsEVMChain(chainID) {
return errors.New("only EVM chains are supported for refund when coin type is Zeta")
}
if cctx.InboundTxParams.Amount.IsNil() || cctx.InboundTxParams.Amount.IsZero() {
return errors.New("no amount to refund")
Expand Down

0 comments on commit 191f876

Please sign in to comment.