From bf3a7149e55b1ff85ea905863cfebd0d23c32af1 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:48:37 +0300 Subject: [PATCH] feat: deposit message fee amount --- x/house/keeper/deposit.go | 6 +++--- x/house/keeper/msg_server_deposit.go | 4 ++-- x/house/types/events.go | 1 + x/house/types/message_deposit.go | 3 ++- x/orderbook/keeper/bet_wager_test.go | 8 ++++---- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/x/house/keeper/deposit.go b/x/house/keeper/deposit.go index 17e192eb..c0a3857e 100644 --- a/x/house/keeper/deposit.go +++ b/x/house/keeper/deposit.go @@ -55,11 +55,11 @@ func (k Keeper) GetAllDeposits(ctx sdk.Context) (list []types.Deposit, err error // Deposit performs a deposit transaction and stores a new deposit in store. func (k Keeper) Deposit(ctx sdk.Context, creator, depositor string, marketUID string, amount sdkmath.Int, -) (participationIndex uint64, err error) { +) (participationIndex uint64, feeAmount sdkmath.Int, err error) { // Create the deposit object deposit := types.NewDeposit(creator, depositor, marketUID, amount, sdk.ZeroInt(), 0) - feeAmount := deposit.CalcHouseParticipationFeeAmount(k.GetHouseParticipationFee(ctx)) + feeAmount = deposit.CalcHouseParticipationFeeAmount(k.GetHouseParticipationFee(ctx)) depositorAddr, err := sdk.AccAddressFromBech32(depositor) if err != nil { @@ -79,5 +79,5 @@ func (k Keeper) Deposit(ctx sdk.Context, creator, depositor string, k.SetDeposit(ctx, deposit) - return participationIndex, err + return participationIndex, feeAmount, err } diff --git a/x/house/keeper/msg_server_deposit.go b/x/house/keeper/msg_server_deposit.go index 89c04e79..807783f5 100644 --- a/x/house/keeper/msg_server_deposit.go +++ b/x/house/keeper/msg_server_deposit.go @@ -37,7 +37,7 @@ func (k msgServer) Deposit(goCtx context.Context, return nil, sdkerrors.Wrapf(types.ErrInTicketPayloadValidation, "%s", err) } - participationIndex, err := k.Keeper.Deposit( + participationIndex, feeAmount, err := k.Keeper.Deposit( ctx, msg.Creator, depositorAddr, @@ -48,7 +48,7 @@ func (k msgServer) Deposit(goCtx context.Context, return nil, sdkerrors.Wrap(err, "failed to deposit") } - msg.EmitEvent(&ctx, depositorAddr, participationIndex) + msg.EmitEvent(&ctx, depositorAddr, participationIndex, feeAmount) return &types.MsgDepositResponse{ MarketUID: msg.MarketUID, diff --git a/x/house/types/events.go b/x/house/types/events.go index 16cad9fa..473ae2d1 100644 --- a/x/house/types/events.go +++ b/x/house/types/events.go @@ -5,6 +5,7 @@ const ( attributeKeyCreator = "creator" attributeKeyDepositor = "depositor" + attributeKeyDepositFee = "deposit_fee" attributeKeyWithdrawalID = "withdrawal_id" attributeKeyDepositMarketUIDParticipantIndex = "deposit_market_index" attributeKeyWithdrawMarketUIDParticipantIndex = "withdraw_market_index" diff --git a/x/house/types/message_deposit.go b/x/house/types/message_deposit.go index ec500605..4588d970 100644 --- a/x/house/types/message_deposit.go +++ b/x/house/types/message_deposit.go @@ -79,11 +79,12 @@ func (msg MsgDeposit) ValidateSanity(_ sdk.Context, p *Params) error { } // EmitEvent emits the event for the message success. -func (msg *MsgDeposit) EmitEvent(ctx *sdk.Context, depositor string, participationIndex uint64) { +func (msg *MsgDeposit) EmitEvent(ctx *sdk.Context, depositor string, participationIndex uint64, feeAmount sdkmath.Int) { emitter := utils.NewEventEmitter(ctx, attributeValueCategory) emitter.AddMsg(typeMsgDeposit, msg.Creator, sdk.NewAttribute(attributeKeyCreator, msg.Creator), sdk.NewAttribute(attributeKeyDepositor, depositor), + sdk.NewAttribute(attributeKeyDepositFee, feeAmount.String()), sdk.NewAttribute(attributeKeyDepositMarketUIDParticipantIndex, strings.Join([]string{msg.MarketUID, cast.ToString(participationIndex)}, "#"), ), diff --git a/x/orderbook/keeper/bet_wager_test.go b/x/orderbook/keeper/bet_wager_test.go index 10625988..96349ca8 100644 --- a/x/orderbook/keeper/bet_wager_test.go +++ b/x/orderbook/keeper/bet_wager_test.go @@ -86,7 +86,7 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) { require.NoError(ts.t, err) found := false - participationIndex, err := ts.tApp.HouseKeeper.Deposit( + participationIndex, _, err := ts.tApp.HouseKeeper.Deposit( ts.ctx, ts.deposits[0].DepositorAddress, ts.deposits[0].DepositorAddress, @@ -108,7 +108,7 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) { ) require.True(ts.t, found) - participationIndex, err = ts.tApp.HouseKeeper.Deposit( + participationIndex, _, err = ts.tApp.HouseKeeper.Deposit( ts.ctx, ts.deposits[1].DepositorAddress, ts.deposits[1].DepositorAddress, @@ -130,7 +130,7 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) { ) require.True(ts.t, found) - participationIndex, err = ts.tApp.HouseKeeper.Deposit( + participationIndex, _, err = ts.tApp.HouseKeeper.Deposit( ts.ctx, ts.deposits[2].DepositorAddress, ts.deposits[2].DepositorAddress, @@ -418,7 +418,7 @@ func (ts *testBetSuite) bulkDepositPlaceBetsAndTest() { for i := 0; i < len(ts.deposits); i++ { found := false - participationIndex, err := ts.tApp.HouseKeeper.Deposit( + participationIndex, _, err := ts.tApp.HouseKeeper.Deposit( ts.ctx, ts.deposits[i].DepositorAddress, ts.deposits[i].DepositorAddress,