From 36178fdeb01aa955e2832234b62b5b02160da968 Mon Sep 17 00:00:00 2001 From: ducphamle2 Date: Mon, 1 May 2023 10:17:07 -0700 Subject: [PATCH] changed to GT profitable batch & added batch fees packet recv --- module/x/gravity/keeper/batch.go | 2 +- module/x/gravity/keeper/ibc_callback.go | 9 ++++++++- module/x/gravity/keeper/ibc_callback_test.go | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/module/x/gravity/keeper/batch.go b/module/x/gravity/keeper/batch.go index 5eb597c29..5efbf2962 100644 --- a/module/x/gravity/keeper/batch.go +++ b/module/x/gravity/keeper/batch.go @@ -52,7 +52,7 @@ func (k Keeper) BuildOutgoingTxBatch( } lastFees := lastBatch.ToExternal().GetFees() - if lastFees.GTE(currentFees.TotalFees) { + if lastFees.GT(currentFees.TotalFees) { return nil, sdkerrors.Wrap(types.ErrInvalid, "new batch would not be more profitable") } } diff --git a/module/x/gravity/keeper/ibc_callback.go b/module/x/gravity/keeper/ibc_callback.go index 45745e264..c8d7ec759 100644 --- a/module/x/gravity/keeper/ibc_callback.go +++ b/module/x/gravity/keeper/ibc_callback.go @@ -132,8 +132,15 @@ func (k Keeper) OnRecvPacket( return channeltypes.NewErrorAcknowledgement(sdkerrors.Wrap(types.ErrInvalid, "destination address is invalid or blacklisted").Error()) } + batchFees := sdk.ZeroInt() + params, err := k.GetParamsIfSet(ctx) + if err == nil { + // The params have been set, get the min send to eth fee + batchFees = sdk.NewInt(int64(params.MinChainFeeBasisPoints)) + } + // finally add to outgoing pool and waiting for gbt to submit it via MsgRequestBatch - txID, err := k.AddToOutgoingPool(ctx, evmChainPrefix, sender, *dest, coin, sdk.Coin{Denom: coin.Denom, Amount: sdk.ZeroInt()}) + txID, err := k.AddToOutgoingPool(ctx, evmChainPrefix, sender, *dest, coin, sdk.Coin{Denom: coin.Denom, Amount: batchFees}) if err != nil { return channeltypes.NewErrorAcknowledgement(err.Error()) } diff --git a/module/x/gravity/keeper/ibc_callback_test.go b/module/x/gravity/keeper/ibc_callback_test.go index 4c9e883d4..540076f86 100644 --- a/module/x/gravity/keeper/ibc_callback_test.go +++ b/module/x/gravity/keeper/ibc_callback_test.go @@ -46,6 +46,7 @@ func TestOnRecvPacket(t *testing.T) { timeoutHeight := clienttypes.NewHeight(0, 100) expAck := ibcmock.MockAcknowledgement + params := input.GravityKeeper.GetParams(ctx) // add it to the ERC20 registry // because this is one way from Oraichain to Gravity Bridge so just use the ibc token as default native token and mint some @@ -93,7 +94,7 @@ func TestOnRecvPacket(t *testing.T) { }, Erc20Fee: types.ERC20Token{ Contract: tokenContractAddr, - Amount: sdk.NewInt(0), + Amount: sdk.NewInt(int64(params.MinChainFeeBasisPoints)), }, }, }, @@ -133,7 +134,7 @@ func TestOnRecvPacket(t *testing.T) { input.Context, types.ModuleName, gravityAddr, - sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(100)))) + sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(102)))) ack := input.GravityKeeper.OnRecvPacket(ctx, packet, expAck) // Check acknowledgement