Skip to content

Commit

Permalink
feat: deposit amount fee event
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Nov 17, 2023
1 parent 5a969e3 commit 1376e82
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions x/house/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions x/house/keeper/msg_server_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions x/house/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (

attributeKeyCreator = "creator"
attributeKeyDepositor = "depositor"
attributeKeyDepositFee = "deposit_fee"
attributeKeyWithdrawalID = "withdrawal_id"
attributeKeyDepositMarketUIDParticipantIndex = "deposit_market_index"
attributeKeyWithdrawMarketUIDParticipantIndex = "withdraw_market_index"
Expand Down
3 changes: 2 additions & 1 deletion x/house/types/message_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}, "#"),
),
Expand Down
8 changes: 4 additions & 4 deletions x/orderbook/keeper/bet_wager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion x/subaccount/keeper/msg_server_house.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion x/subaccount/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 1376e82

Please sign in to comment.