From 7a5124d9ebf57fb4fb4dfc7c4fdf7f635be9c947 Mon Sep 17 00:00:00 2001 From: waaiifu Date: Fri, 17 Nov 2023 13:57:55 +0530 Subject: [PATCH] Adds deposit 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 | 4 +++- x/orderbook/keeper/bet_wager_test.go | 8 ++++---- 5 files changed, 13 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..a119cac1 100644 --- a/x/house/types/events.go +++ b/x/house/types/events.go @@ -7,5 +7,6 @@ const ( attributeKeyDepositor = "depositor" attributeKeyWithdrawalID = "withdrawal_id" attributeKeyDepositMarketUIDParticipantIndex = "deposit_market_index" + attributeKeyDepositFee = "deposit_fee" attributeKeyWithdrawMarketUIDParticipantIndex = "withdraw_market_index" ) diff --git a/x/house/types/message_deposit.go b/x/house/types/message_deposit.go index ec500605..4253a058 100644 --- a/x/house/types/message_deposit.go +++ b/x/house/types/message_deposit.go @@ -1,6 +1,7 @@ package types import ( + "strconv" "strings" sdkmath "cosmossdk.io/math" @@ -79,7 +80,7 @@ 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), @@ -87,6 +88,7 @@ func (msg *MsgDeposit) EmitEvent(ctx *sdk.Context, depositor string, participati sdk.NewAttribute(attributeKeyDepositMarketUIDParticipantIndex, strings.Join([]string{msg.MarketUID, cast.ToString(participationIndex)}, "#"), ), + sdk.NewAttribute(attributeKeyDepositFee, strconv.Itoa(int(feeAmount.Int64()))), ) emitter.Emit() } 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,