Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature / Deposit amount fee message event #304

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions 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, feeAmount, err := k.keeper.houseKeeper.Deposit(
ctx,
msg.Msg.Creator,
subAccAddr.String(),
Expand All @@ -51,7 +51,7 @@ func (k msgServer) HouseDeposit(goCtx context.Context, msg *types.MsgHouseDeposi
k.keeper.SetBalance(ctx, subAccAddr, balance)

// emit event
msg.EmitEvent(&ctx, subAccAddr.String(), participationIndex)
msg.EmitEvent(&ctx, subAccAddr.String(), participationIndex, feeAmount)

return &types.MsgHouseDepositResponse{
Response: &housetypes.MsgDepositResponse{
Expand Down
1 change: 1 addition & 0 deletions x/subaccount/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
const (
attributeKeyDepositCreator = "creator"
attributeKeySubAccDepositor = "subacc_depositor"
attributeKeySubAccDepositFee = "subacc_deposit_fee"
attributeKeyWithdrawalID = "withdrawal_id"
attributeKeyDepositMarketUIDParticipantIndex = "deposit_market_index"
attributeKeyWithdrawMarketUIDParticipantIndex = "withdraw_market_index"
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
4 changes: 3 additions & 1 deletion x/subaccount/types/messages_house.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"strings"

sdkmath "cosmossdk.io/math"
"github.com/spf13/cast"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -47,11 +48,12 @@ func (msg *MsgHouseDeposit) ValidateBasic() error {
}

// EmitEvent emits the event for the message success.
func (msg *MsgHouseDeposit) EmitEvent(ctx *sdk.Context, subAccAddr string, participationIndex uint64) {
func (msg *MsgHouseDeposit) EmitEvent(ctx *sdk.Context, subAccAddr string, participationIndex uint64, feeAmount sdkmath.Int) {
emitter := utils.NewEventEmitter(ctx, attributeValueCategory)
emitter.AddMsg(typeMsgHouseDeposit, msg.Msg.Creator,
sdk.NewAttribute(attributeKeyDepositCreator, msg.Msg.Creator),
sdk.NewAttribute(attributeKeySubAccDepositor, subAccAddr),
sdk.NewAttribute(attributeKeySubAccDepositFee, feeAmount.String()),
sdk.NewAttribute(attributeKeyDepositMarketUIDParticipantIndex,
strings.Join([]string{msg.Msg.MarketUID, cast.ToString(participationIndex)}, "#"),
),
Expand Down
Loading