From 1376e828709e5482123251a11f9d6386b02313d7 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:21:19 +0300 Subject: [PATCH] feat: deposit amount fee event --- 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 ++++---- x/subaccount/keeper/msg_server_house.go | 2 +- x/subaccount/types/expected_keepers.go | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/x/house/keeper/deposit.go b/x/house/keeper/deposit.go index 8814a8ad..28246c99 100644 --- a/x/house/keeper/deposit.go +++ b/x/house/keeper/deposit.go @@ -56,11 +56,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 { @@ -80,5 +80,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 715ca4f7..4360fb3d 100644 --- a/x/house/keeper/msg_server_deposit.go +++ b/x/house/keeper/msg_server_deposit.go @@ -21,7 +21,7 @@ func (k msgServer) Deposit(goCtx context.Context, return nil, err } - participationIndex, err := k.Keeper.Deposit( + participationIndex, feeAmount, err := k.Keeper.Deposit( ctx, msg.Creator, depositorAddr, @@ -32,7 +32,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 300d4bc0..65dae2b3 100644 --- a/x/house/types/message_deposit.go +++ b/x/house/types/message_deposit.go @@ -81,11 +81,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 207e20c1..68b6d80d 100644 --- a/x/orderbook/keeper/bet_wager_test.go +++ b/x/orderbook/keeper/bet_wager_test.go @@ -88,7 +88,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, @@ -110,7 +110,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, @@ -132,7 +132,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, @@ -420,7 +420,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, diff --git a/x/subaccount/keeper/msg_server_house.go b/x/subaccount/keeper/msg_server_house.go index ba377e88..7cafa029 100644 --- a/x/subaccount/keeper/msg_server_house.go +++ b/x/subaccount/keeper/msg_server_house.go @@ -36,7 +36,7 @@ func (k msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposi } // send house deposit from subaccount on behalf of the owner - participationIndex, err := k.keeper.houseKeeper.Deposit( + participationIndex, _, err := k.keeper.houseKeeper.Deposit( ctx, msg.Msg.Creator, subAccAddr.String(), diff --git a/x/subaccount/types/expected_keepers.go b/x/subaccount/types/expected_keepers.go index e1aa8355..3e7ca276 100644 --- a/x/subaccount/types/expected_keepers.go +++ b/x/subaccount/types/expected_keepers.go @@ -33,7 +33,7 @@ type BankKeeper interface { type HouseKeeper interface { GetParams(ctx sdk.Context) housetypes.Params ParseDepositTicketAndValidate(goCtx context.Context, ctx sdk.Context, msg *housetypes.MsgDeposit, authzAllowed bool) (string, error) - Deposit(ctx sdk.Context, creator, depositor, marketUID string, amount sdkmath.Int) (participationIndex uint64, err error) + Deposit(ctx sdk.Context, creator, depositor string, marketUID string, amount sdkmath.Int) (participationIndex uint64, feeAmount sdkmath.Int, err error) ParseWithdrawTicketAndValidate(goCtx context.Context, ctx sdk.Context, msg *housetypes.MsgWithdraw, authzAllowed bool) (string, bool, error) CalcAndWithdraw(ctx sdk.Context, msg *housetypes.MsgWithdraw, depositorAddr string, isOnBehalf bool) (uint64, error) }