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

Chore: more dex event attributes #707

Merged
merged 7 commits into from
Sep 24, 2024
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
2 changes: 1 addition & 1 deletion x/dex/keeper/cancel_limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (k Keeper) CancelLimitOrderCore(
pairID.Token1,
makerDenom,
takerDenom,
makerCoinOut.Amount,
takerCoinOut.Amount,
makerCoinOut.Amount,
trancheKey,
))

Expand Down
1 change: 1 addition & 0 deletions x/dex/keeper/limit_order_tranche_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (k Keeper) SaveTrancheUser(ctx sdk.Context, trancheUser *types.LimitOrderTr
} else {
k.SetLimitOrderTrancheUser(ctx, trancheUser)
}
ctx.EventManager().EmitEvent(types.TrancheUserUpdateEvent(*trancheUser))
}

// GetAllLimitOrderTrancheUser returns all LimitOrderTrancheUser
Expand Down
2 changes: 2 additions & 0 deletions x/dex/keeper/place_limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func (k Keeper) PlaceLimitOrderCore(
orderType.String(),
sharesIssued,
trancheKey,
swapInCoin.Amount,
swapOutCoin.Amount,
))

return trancheKey, totalInCoin, swapInCoin, swapOutCoin, nil
Expand Down
1 change: 1 addition & 0 deletions x/dex/keeper/withdraw_filled_limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (k Keeper) WithdrawFilledLimitOrderCore(
makerDenom,
takerDenom,
takerCoinOut.Amount,
makerCoinOut.Amount,
trancheKey,
))

Expand Down
39 changes: 36 additions & 3 deletions x/dex/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
AttributeTokenOut = "TokenOut"
AttributeAmountIn = "AmountIn"
AttributeAmountOut = "AmountOut"
AttributeSwapAmountIn = "SwapAmountIn"
AttributeSwapAmountOut = "SwapAmountOut"
AttributeTokenInAmountOut = "TokenInAmountOut"
AttributeTokenOutAmountOut = "TokenOutAmountOut"
AttributeTickIndex = "TickIndex"
Expand Down Expand Up @@ -47,6 +49,10 @@ const (
AttributeInc = "inc"
AttributeDec = "dec"
AttributePairID = "pair_id"
AttributeMakerDenom = "MakerDenom"
AttributeTakerDenom = "TakerDenom"
AttributeSharesOwned = "SharesOwned"
AttributeSharesWithdrawn = "SharesWithdrawn"
)

// Event Keys
Expand All @@ -60,6 +66,8 @@ const (
EventTypeTickUpdate = "TickUpdate"
TickUpdateEventKey = "TickUpdate"
EventTypeGoodTilPurgeHitGasLimit = "GoodTilPurgeHitGasLimit"
TrancheUserUpdateEventKey = "TrancheUserUpdate"
EventTypeTrancheUserUpdate = "TrancheUserUpdate"
// EventTypeNeutronMessage defines the event type used by the Interchain Queries module events.
EventTypeNeutronMessage = "neutron"
)
Expand Down Expand Up @@ -162,6 +170,8 @@ func CreatePlaceLimitOrderEvent(
orderType string,
shares math.Int,
trancheKey string,
swapAmountIn math.Int,
swapAmountOut math.Int,
) sdk.Event {
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
Expand All @@ -177,6 +187,8 @@ func CreatePlaceLimitOrderEvent(
sdk.NewAttribute(AttributeOrderType, orderType),
sdk.NewAttribute(AttributeShares, shares.String()),
sdk.NewAttribute(AttributeTrancheKey, trancheKey),
sdk.NewAttribute(AttributeSwapAmountIn, swapAmountIn.String()),
sdk.NewAttribute(AttributeSwapAmountOut, swapAmountOut.String()),
}

return sdk.NewEvent(sdk.EventTypeMessage, attrs...)
Expand All @@ -188,7 +200,8 @@ func WithdrawFilledLimitOrderEvent(
token1 string,
makerDenom string,
tokenOut string,
amountOut math.Int,
amountOutTaker math.Int,
amountOutMaker math.Int,
trancheKey string,
) sdk.Event {
attrs := []sdk.Attribute{
Expand All @@ -201,7 +214,10 @@ func WithdrawFilledLimitOrderEvent(
sdk.NewAttribute(AttributeTokenIn, makerDenom),
sdk.NewAttribute(AttributeTokenOut, tokenOut),
sdk.NewAttribute(AttributeTrancheKey, trancheKey),
sdk.NewAttribute(AttributeAmountOut, amountOut.String()),
// DEPRECATED: `AmountOut` will be removed in the next release
sdk.NewAttribute(AttributeAmountOut, amountOutTaker.String()),
sdk.NewAttribute(AttributeTokenOutAmountOut, amountOutTaker.String()),
sdk.NewAttribute(AttributeTokenInAmountOut, amountOutMaker.String()),
}

return sdk.NewEvent(sdk.EventTypeMessage, attrs...)
Expand All @@ -213,8 +229,8 @@ func CancelLimitOrderEvent(
token1 string,
makerDenom string,
tokenOut string,
amountOutMaker math.Int,
amountOutTaker math.Int,
amountOutMaker math.Int,
trancheKey string,
) sdk.Event {
attrs := []sdk.Attribute{
Expand Down Expand Up @@ -405,3 +421,20 @@ func GetEventsDecTotalPoolReserves(pairID PairID) sdk.Events {
),
}
}

func TrancheUserUpdateEvent(trancheUser LimitOrderTrancheUser) sdk.Event {
pairID := trancheUser.TradePairId.MustPairID()
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(sdk.AttributeKeyAction, TrancheUserUpdateEventKey),
sdk.NewAttribute(AttributeTrancheKey, trancheUser.TrancheKey),
sdk.NewAttribute(AttributeCreator, trancheUser.Address),
sdk.NewAttribute(AttributeTickIndex, strconv.Itoa(int(trancheUser.TickIndexTakerToMaker))),
sdk.NewAttribute(AttributeToken0, pairID.Token0),
sdk.NewAttribute(AttributeToken1, pairID.Token1),
sdk.NewAttribute(AttributeTokenIn, trancheUser.TradePairId.MakerDenom),
sdk.NewAttribute(AttributeSharesOwned, trancheUser.SharesOwned.String()),
sdk.NewAttribute(AttributeSharesWithdrawn, trancheUser.SharesWithdrawn.String()),
}
return sdk.NewEvent(EventTypeTrancheUserUpdate, attrs...)
}
Loading