Skip to content

Commit

Permalink
changed to GT profitable batch & added batch fees packet recv
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamle2 committed May 1, 2023
1 parent 6d58c64 commit 36178fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion module/x/gravity/keeper/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
9 changes: 8 additions & 1 deletion module/x/gravity/keeper/ibc_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
5 changes: 3 additions & 2 deletions module/x/gravity/keeper/ibc_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestOnRecvPacket(t *testing.T) {
},
Erc20Fee: types.ERC20Token{
Contract: tokenContractAddr,
Amount: sdk.NewInt(0),
Amount: sdk.NewInt(int64(params.MinChainFeeBasisPoints)),
},
},
},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 36178fd

Please sign in to comment.