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 1 commit
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 @@ -41,8 +41,8 @@ func (k Keeper) CancelLimitOrderCore(
pairID.Token1,
tradePairID.MakerDenom,
tradePairID.TakerDenom,
makerCoinOut.Amount,
takerCoinOut.Amount,
makerCoinOut.Amount,
trancheKey,
))

Expand Down
31 changes: 18 additions & 13 deletions x/dex/keeper/place_limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,24 @@ func (k Keeper) PlaceLimitOrderCore(

// This will never panic because we've already successfully constructed a TradePairID above
pairID := takerTradePairID.MustPairID()
ctx.EventManager().EmitEvent(types.CreatePlaceLimitOrderEvent(
callerAddr,
receiverAddr,
pairID.Token0,
pairID.Token1,
tokenIn,
tokenOut,
totalIn,
tickIndexInToOut,
orderType.String(),
sharesIssued,
trancheKey,
))
types.EmitEventWithTimestamp(
ctx,
types.CreatePlaceLimitOrderEvent(
callerAddr,
receiverAddr,
pairID.Token0,
pairID.Token1,
tokenIn,
tokenOut,
totalIn,
tickIndexInToOut,
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(
tradePairID.MakerDenom,
tradePairID.TakerDenom,
amountOutTokenOut,
remainingTokenIn,
trancheKey,
))

Expand Down
26 changes: 22 additions & 4 deletions x/dex/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"strconv"
"strings"
"time"

"cosmossdk.io/math"
"cosmossdk.io/store/types"
Expand All @@ -19,6 +20,8 @@ const (
AttributeTokenOut = "TokenOut"
AttributeAmountIn = "AmountIn"
AttributeAmountOut = "AmountOut"
AttributeSwapAmountIn = "SwapAmountIn"
AttributeSwapAmountOut = "SwapAmountOut"
AttributeTokenInAmountOut = "TokenInAmountOut"
AttributeTokenOutAmountOut = "TokenOutAmountOut"
AttributeTickIndex = "TickIndex"
Expand Down Expand Up @@ -47,6 +50,7 @@ const (
AttributeInc = "inc"
AttributeDec = "dec"
AttributePairID = "pair_id"
AttributeTimestamp = "Timestamp"
)

// Event Keys
Expand All @@ -64,6 +68,12 @@ const (
EventTypeNeutronMessage = "neutron"
)

func EmitEventWithTimestamp(ctx sdk.Context, event sdk.Event) {
timestamp := sdk.NewAttribute(AttributeTimestamp, ctx.BlockTime().Format(time.RFC3339))
event = event.AppendAttributes(timestamp)
ctx.EventManager().EmitEvent(event)
}

func CreateDepositEvent(
creator sdk.AccAddress,
receiver sdk.AccAddress,
Expand Down Expand Up @@ -162,6 +172,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 +189,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 +202,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 +216,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 +231,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 All @@ -226,8 +244,8 @@ func CancelLimitOrderEvent(
sdk.NewAttribute(AttributeToken1, token1),
sdk.NewAttribute(AttributeTokenIn, makerDenom),
sdk.NewAttribute(AttributeTokenOut, tokenOut),
sdk.NewAttribute(AttributeTokenInAmountOut, amountOutMaker.String()),
sdk.NewAttribute(AttributeTokenOutAmountOut, amountOutTaker.String()),
sdk.NewAttribute(AttributeTokenInAmountOut, amountOutMaker.String()),
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
sdk.NewAttribute(AttributeTrancheKey, trancheKey),
}

Expand Down
Loading