Skip to content

Commit

Permalink
Merge pull request #648 from neutron-org/chore/dex_event_cleanup
Browse files Browse the repository at this point in the history
Chore: dex event cleanup #NTRN-367
  • Loading branch information
pr0n00gler authored Aug 20, 2024
2 parents fe3e338 + 61ca7ce commit e109821
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 183 deletions.
4 changes: 2 additions & 2 deletions x/dex/keeper/limit_order_expiration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (s *DexTestSuite) TestPurgeExpiredLimitOrders() {
updateEvent := s.FindEvent(ctx.EventManager().Events(), types.TickUpdateEventKey)
eventAttrs := s.ExtractAttributes(updateEvent)
// Event has Reserves == 0
s.Equal(eventAttrs[types.TickUpdateEventReserves], "0")
s.Equal(eventAttrs[types.AttributeReserves], "0")
}

func (s *DexTestSuite) TestPurgeExpiredLimitOrdersAtBlockGasLimit() {
Expand Down Expand Up @@ -230,5 +230,5 @@ func (s *DexTestSuite) TestPurgeExpiredLimitOrdersAtBlockGasLimitOnlyJIT() {
s.Equal(0, len(expList))

// AND GoodTilPurgeHitGasLimit event is not been emitted
s.AssertEventValueNotEmitted(types.GoodTilPurgeHitGasLimitEventGas, "Hit gas limit purging JIT expirations")
s.AssertEventValueNotEmitted(types.EventTypeGoodTilPurgeHitGasLimit, "Hit gas limit purging JIT expirations")
}
185 changes: 121 additions & 64 deletions x/dex/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,61 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Shared Attributes
const (
AttributeCreator = "Creator"
AttributeReceiver = "Receiver"
AttributeToken0 = "TokenZero"
AttributeToken1 = "TokenOne"
AttributeTokenIn = "TokenIn"
AttributeTokenOut = "TokenOut"
AttributeAmountIn = "AmountIn"
AttributeAmountOut = "AmountOut"
AttributeTokenInAmountOut = "TokenInAmountOut"
AttributeTokenOutAmountOut = "TokenOutAmountOut"
AttributeTickIndex = "TickIndex"
AttributeFee = "Fee"
AttributeTrancheKey = "TrancheKey"
AttributeSharesMinted = "SharesMinted"
AttributeReserves0Deposited = "ReservesZeroDeposited"
AttributeReserves1Deposited = "ReservesOneDeposited"
AttributeReserves0Withdrawn = "ReservesZeroWithdrawn"
AttributeReserves1Withdrawn = "ReservesOneWithdrawn"
AttributeSharesRemoved = "SharesRemoved"
AttributeRoute = "Route"
AttributeDust = "Dust"
AttributeLimitTick = "LimitTick"
AttributeOrderType = "OrderType"
AttributeShares = "Shares"
AttributeReserves = "Reserves"
AttributeGas = "Gas"
AttributeDenom = "denom"
AttributeWithdrawn = "total_withdrawn"
AttributeGasConsumed = "gas_consumed"
AttributeLiquidityTickType = "liquidity_tick_type"
AttributeLp = "lp"
AttributeLimitOrder = "limit_order"
AttributeIsExpiringLimitOrder = "is_expiring_limit_order"
AttributeInc = "inc"
AttributeDec = "dec"
AttributePairID = "pair_id"
)

// Event Keys
const (
DepositEventKey = "DepositLP"
WithdrawEventKey = "WithdrawLP"
MultihopSwapEventKey = "MultihopSwap"
PlaceLimitOrderEventKey = "PlaceLimitOrder"
WithdrawFilledLimitOrderEventKey = "WithdrawLimitOrder"
CancelLimitOrderEventKey = "CancelLimitOrder"
EventTypeTickUpdate = "TickUpdate"
TickUpdateEventKey = "TickUpdate"
EventTypeGoodTilPurgeHitGasLimit = "GoodTilPurgeHitGasLimit"
// EventTypeNeutronMessage defines the event type used by the Interchain Queries module events.
EventTypeNeutronMessage = "neutron"
)

func CreateDepositEvent(
creator sdk.AccAddress,
receiver sdk.AccAddress,
Expand All @@ -23,15 +78,15 @@ func CreateDepositEvent(
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(sdk.AttributeKeyAction, DepositEventKey),
sdk.NewAttribute(DepositEventCreator, creator.String()),
sdk.NewAttribute(DepositEventReceiver, receiver.String()),
sdk.NewAttribute(DepositEventToken0, token0),
sdk.NewAttribute(DepositEventToken1, token1),
sdk.NewAttribute(DepositEventPrice, strconv.FormatInt(tickIndex, 10)),
sdk.NewAttribute(DepositEventFee, strconv.FormatUint(fee, 10)),
sdk.NewAttribute(DepositEventReserves0Deposited, depositAmountReserve0.String()),
sdk.NewAttribute(DepositEventReserves1Deposited, depositAmountReserve1.String()),
sdk.NewAttribute(DepositEventSharesMinted, sharesMinted.String()),
sdk.NewAttribute(AttributeCreator, creator.String()),
sdk.NewAttribute(AttributeReceiver, receiver.String()),
sdk.NewAttribute(AttributeToken0, token0),
sdk.NewAttribute(AttributeToken1, token1),
sdk.NewAttribute(AttributeTickIndex, strconv.FormatInt(tickIndex, 10)),
sdk.NewAttribute(AttributeFee, strconv.FormatUint(fee, 10)),
sdk.NewAttribute(AttributeReserves0Deposited, depositAmountReserve0.String()),
sdk.NewAttribute(AttributeReserves1Deposited, depositAmountReserve1.String()),
sdk.NewAttribute(AttributeSharesMinted, sharesMinted.String()),
}

return sdk.NewEvent(sdk.EventTypeMessage, attrs...)
Expand All @@ -51,15 +106,15 @@ func CreateWithdrawEvent(
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(sdk.AttributeKeyAction, WithdrawEventKey),
sdk.NewAttribute(WithdrawEventCreator, creator.String()),
sdk.NewAttribute(WithdrawEventReceiver, receiver.String()),
sdk.NewAttribute(WithdrawEventToken0, token0),
sdk.NewAttribute(WithdrawEventToken1, token1),
sdk.NewAttribute(WithdrawEventPrice, strconv.FormatInt(tickIndex, 10)),
sdk.NewAttribute(WithdrawEventFee, strconv.FormatUint(fee, 10)),
sdk.NewAttribute(WithdrawEventReserves0Withdrawn, withdrawAmountReserve0.String()),
sdk.NewAttribute(WithdrawEventReserves1Withdrawn, withdrawAmountReserve1.String()),
sdk.NewAttribute(WithdrawEventSharesRemoved, sharesRemoved.String()),
sdk.NewAttribute(AttributeCreator, creator.String()),
sdk.NewAttribute(AttributeReceiver, receiver.String()),
sdk.NewAttribute(AttributeToken0, token0),
sdk.NewAttribute(AttributeToken1, token1),
sdk.NewAttribute(AttributeTickIndex, strconv.FormatInt(tickIndex, 10)),
sdk.NewAttribute(AttributeFee, strconv.FormatUint(fee, 10)),
sdk.NewAttribute(AttributeReserves0Withdrawn, withdrawAmountReserve0.String()),
sdk.NewAttribute(AttributeReserves1Withdrawn, withdrawAmountReserve1.String()),
sdk.NewAttribute(AttributeSharesRemoved, sharesRemoved.String()),
}

return sdk.NewEvent(sdk.EventTypeMessage, attrs...)
Expand All @@ -82,14 +137,14 @@ func CreateMultihopSwapEvent(
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(sdk.AttributeKeyAction, MultihopSwapEventKey),
sdk.NewAttribute(MultihopSwapEventCreator, creator.String()),
sdk.NewAttribute(MultihopSwapEventReceiver, receiver.String()),
sdk.NewAttribute(MultihopSwapEventTokenIn, makerDenom),
sdk.NewAttribute(MultihopSwapEventTokenOut, tokenOut),
sdk.NewAttribute(MultihopSwapEventAmountIn, amountIn.String()),
sdk.NewAttribute(MultihopSwapEventAmountOut, amountOut.String()),
sdk.NewAttribute(MultihopSwapEventRoute, strings.Join(route, ",")),
sdk.NewAttribute(MultihopSwapEventDust, strings.Join(dustStrings, ",")),
sdk.NewAttribute(AttributeCreator, creator.String()),
sdk.NewAttribute(AttributeReceiver, receiver.String()),
sdk.NewAttribute(AttributeTokenIn, makerDenom),
sdk.NewAttribute(AttributeTokenOut, tokenOut),
sdk.NewAttribute(AttributeAmountIn, amountIn.String()),
sdk.NewAttribute(AttributeAmountOut, amountOut.String()),
sdk.NewAttribute(AttributeRoute, strings.Join(route, ",")),
sdk.NewAttribute(AttributeDust, strings.Join(dustStrings, ",")),
}

return sdk.NewEvent(sdk.EventTypeMessage, attrs...)
Expand All @@ -111,17 +166,17 @@ func CreatePlaceLimitOrderEvent(
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(sdk.AttributeKeyAction, PlaceLimitOrderEventKey),
sdk.NewAttribute(PlaceLimitOrderEventCreator, creator.String()),
sdk.NewAttribute(PlaceLimitOrderEventReceiver, receiver.String()),
sdk.NewAttribute(PlaceLimitOrderEventToken0, token0),
sdk.NewAttribute(PlaceLimitOrderEventToken1, token1),
sdk.NewAttribute(PlaceLimitOrderEventTokenIn, makerDenom),
sdk.NewAttribute(PlaceLimitOrderEventTokenOut, tokenOut),
sdk.NewAttribute(PlaceLimitOrderEventAmountIn, amountIn.String()),
sdk.NewAttribute(PlaceLimitOrderEventLimitTick, strconv.FormatInt(limitTick, 10)),
sdk.NewAttribute(PlaceLimitOrderEventOrderType, orderType),
sdk.NewAttribute(PlaceLimitOrderEventShares, shares.String()),
sdk.NewAttribute(PlaceLimitOrderEventTrancheKey, trancheKey),
sdk.NewAttribute(AttributeCreator, creator.String()),
sdk.NewAttribute(AttributeReceiver, receiver.String()),
sdk.NewAttribute(AttributeToken0, token0),
sdk.NewAttribute(AttributeToken1, token1),
sdk.NewAttribute(AttributeTokenIn, makerDenom),
sdk.NewAttribute(AttributeTokenOut, tokenOut),
sdk.NewAttribute(AttributeAmountIn, amountIn.String()),
sdk.NewAttribute(AttributeLimitTick, strconv.FormatInt(limitTick, 10)),
sdk.NewAttribute(AttributeOrderType, orderType),
sdk.NewAttribute(AttributeShares, shares.String()),
sdk.NewAttribute(AttributeTrancheKey, trancheKey),
}

return sdk.NewEvent(sdk.EventTypeMessage, attrs...)
Expand All @@ -139,13 +194,14 @@ func WithdrawFilledLimitOrderEvent(
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(sdk.AttributeKeyAction, WithdrawFilledLimitOrderEventKey),
sdk.NewAttribute(WithdrawFilledLimitOrderEventCreator, creator.String()),
sdk.NewAttribute(WithdrawFilledLimitOrderEventToken0, token0),
sdk.NewAttribute(WithdrawFilledLimitOrderEventToken1, token1),
sdk.NewAttribute(WithdrawFilledLimitOrderEventTokenIn, makerDenom),
sdk.NewAttribute(WithdrawFilledLimitOrderEventTokenOut, tokenOut),
sdk.NewAttribute(WithdrawFilledLimitOrderEventTrancheKey, trancheKey),
sdk.NewAttribute(WithdrawFilledLimitOrderEventAmountOut, amountOut.String()),
sdk.NewAttribute(AttributeCreator, creator.String()),
sdk.NewAttribute(AttributeReceiver, creator.String()),
sdk.NewAttribute(AttributeToken0, token0),
sdk.NewAttribute(AttributeToken1, token1),
sdk.NewAttribute(AttributeTokenIn, makerDenom),
sdk.NewAttribute(AttributeTokenOut, tokenOut),
sdk.NewAttribute(AttributeTrancheKey, trancheKey),
sdk.NewAttribute(AttributeAmountOut, amountOut.String()),
}

return sdk.NewEvent(sdk.EventTypeMessage, attrs...)
Expand All @@ -156,22 +212,23 @@ func CancelLimitOrderEvent(
token0 string,
token1 string,
makerDenom string,
takerDenom string,
makerAmountOut math.Int,
takerAmountOut math.Int,
tokenOut string,
amountOutMaker math.Int,
amountOutTaker math.Int,
trancheKey string,
) sdk.Event {
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(sdk.AttributeKeyAction, CancelLimitOrderEventKey),
sdk.NewAttribute(CancelLimitOrderEventCreator, creator.String()),
sdk.NewAttribute(CancelLimitOrderEventToken0, token0),
sdk.NewAttribute(CancelLimitOrderEventToken1, token1),
sdk.NewAttribute(CancelLimitOrderEventTokenIn, makerDenom),
sdk.NewAttribute(CancelLimitOrderEventTokenOut, takerDenom),
sdk.NewAttribute(CancelLimitOrderEventTokenInAmountOut, makerAmountOut.String()),
sdk.NewAttribute(CancelLimitOrderEventTokenOutAmountOut, takerAmountOut.String()),
sdk.NewAttribute(CancelLimitOrderEventTrancheKey, trancheKey),
sdk.NewAttribute(AttributeCreator, creator.String()),
sdk.NewAttribute(AttributeReceiver, creator.String()),
sdk.NewAttribute(AttributeToken0, token0),
sdk.NewAttribute(AttributeToken1, token1),
sdk.NewAttribute(AttributeTokenIn, makerDenom),
sdk.NewAttribute(AttributeTokenOut, tokenOut),
sdk.NewAttribute(AttributeTokenInAmountOut, amountOutMaker.String()),
sdk.NewAttribute(AttributeTokenOutAmountOut, amountOutTaker.String()),
sdk.NewAttribute(AttributeTrancheKey, trancheKey),
}

return sdk.NewEvent(sdk.EventTypeMessage, attrs...)
Expand All @@ -188,11 +245,11 @@ func TickUpdateEvent(
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(sdk.AttributeKeyAction, TickUpdateEventKey),
sdk.NewAttribute(TickUpdateEventToken0, token0),
sdk.NewAttribute(TickUpdateEventToken1, token1),
sdk.NewAttribute(TickUpdateEventTokenIn, makerDenom),
sdk.NewAttribute(TickUpdateEventTickIndex, strconv.FormatInt(tickIndex, 10)),
sdk.NewAttribute(TickUpdateEventReserves, reserves.String()),
sdk.NewAttribute(AttributeToken0, token0),
sdk.NewAttribute(AttributeToken1, token1),
sdk.NewAttribute(AttributeTokenIn, makerDenom),
sdk.NewAttribute(AttributeTickIndex, strconv.FormatInt(tickIndex, 10)),
sdk.NewAttribute(AttributeReserves, reserves.String()),
}
attrs = append(attrs, otherAttrs...)

Expand All @@ -208,7 +265,7 @@ func CreateTickUpdatePoolReserves(tick PoolReserves) sdk.Event {
tradePairID.MakerDenom,
tick.Key.TickIndexTakerToMaker,
tick.ReservesMakerDenom,
sdk.NewAttribute(TickUpdateEventFee, strconv.FormatUint(tick.Key.Fee, 10)),
sdk.NewAttribute(AttributeFee, strconv.FormatUint(tick.Key.Fee, 10)),
)
}

Expand All @@ -221,7 +278,7 @@ func CreateTickUpdateLimitOrderTranche(tranche *LimitOrderTranche) sdk.Event {
tradePairID.MakerDenom,
tranche.Key.TickIndexTakerToMaker,
tranche.ReservesMakerDenom,
sdk.NewAttribute(TickUpdateEventTrancheKey, tranche.Key.TrancheKey),
sdk.NewAttribute(AttributeTrancheKey, tranche.Key.TrancheKey),
)
}

Expand All @@ -234,14 +291,14 @@ func CreateTickUpdateLimitOrderTranchePurge(tranche *LimitOrderTranche) sdk.Even
tradePairID.MakerDenom,
tranche.Key.TickIndexTakerToMaker,
math.ZeroInt(),
sdk.NewAttribute(TickUpdateEventTrancheKey, tranche.Key.TrancheKey),
sdk.NewAttribute(AttributeTrancheKey, tranche.Key.TrancheKey),
)
}

func GoodTilPurgeHitLimitEvent(gas types.Gas) sdk.Event {
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyModule, "dex"),
sdk.NewAttribute(GoodTilPurgeHitGasLimitEventGas, strconv.FormatUint(gas, 10)),
sdk.NewAttribute(AttributeGas, strconv.FormatUint(gas, 10)),
}

return sdk.NewEvent(EventTypeGoodTilPurgeHitGasLimit, attrs...)
Expand Down
100 changes: 0 additions & 100 deletions x/dex/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,106 +194,6 @@ func PoolIDKey(
return key
}

// Deposit Event Attributes
const (
DepositEventKey = "DepositLP"
DepositEventCreator = "Creator"
DepositEventToken0 = "TokenZero"
DepositEventToken1 = "TokenOne"
DepositEventPrice = "TickIndex"
DepositEventFee = "Fee"
DepositEventReceiver = "Receiver"
DepositEventReserves0Deposited = "ReservesZeroDeposited"
DepositEventReserves1Deposited = "ReservesOneDeposited"
DepositEventSharesMinted = "SharesMinted"
)

// Withdraw Event Attributes
const (
WithdrawEventKey = "WithdrawLP"
WithdrawEventCreator = "Creator"
WithdrawEventToken0 = "TokenZero"
WithdrawEventToken1 = "TokenOne"
WithdrawEventPrice = "TickIndex"
WithdrawEventFee = "Fee"
WithdrawEventReceiver = "Receiver"
WithdrawEventReserves0Withdrawn = "ReservesZeroWithdrawn"
WithdrawEventReserves1Withdrawn = "ReservesOneWithdrawn"
WithdrawEventSharesRemoved = "SharesRemoved"
)

// Multihop-Swap Event Attributes
const (
MultihopSwapEventKey = "MultihopSwap"
MultihopSwapEventCreator = "Creator"
MultihopSwapEventReceiver = "Receiver"
MultihopSwapEventTokenIn = "TokenIn"
MultihopSwapEventTokenOut = "TokenOut"
MultihopSwapEventAmountIn = "AmountIn"
MultihopSwapEventAmountOut = "AmountOut"
MultihopSwapEventRoute = "Route"
MultihopSwapEventDust = "Dust"
)

// Place LimitOrder Event Attributes
const (
PlaceLimitOrderEventKey = "PlaceLimitOrder"
PlaceLimitOrderEventCreator = "Creator"
PlaceLimitOrderEventReceiver = "Receiver"
PlaceLimitOrderEventToken0 = "TokenZero"
PlaceLimitOrderEventToken1 = "TokenOne"
PlaceLimitOrderEventTokenIn = "TokenIn"
PlaceLimitOrderEventTokenOut = "TokenOut"
PlaceLimitOrderEventAmountIn = "AmountIn"
PlaceLimitOrderEventLimitTick = "LimitTick"
PlaceLimitOrderEventOrderType = "OrderType"
PlaceLimitOrderEventShares = "Shares"
PlaceLimitOrderEventTrancheKey = "TrancheKey"
)

// Withdraw LimitOrder Event Attributes
const (
WithdrawFilledLimitOrderEventKey = "WithdrawLimitOrder"
WithdrawFilledLimitOrderEventCreator = "Creator"
WithdrawFilledLimitOrderEventToken0 = "TokenZero"
WithdrawFilledLimitOrderEventToken1 = "TokenOne"
WithdrawFilledLimitOrderEventTokenIn = "TokenIn"
WithdrawFilledLimitOrderEventTokenOut = "TokenOut"
WithdrawFilledLimitOrderEventTrancheKey = "TrancheKey"
WithdrawFilledLimitOrderEventAmountOut = "AmountOut"
)

// Cancel LimitOrder Event Attributes
const (
CancelLimitOrderEventKey = "CancelLimitOrder"
CancelLimitOrderEventCreator = "Creator"
CancelLimitOrderEventToken0 = "TokenZero"
CancelLimitOrderEventToken1 = "TokenOne"
CancelLimitOrderEventTokenIn = "TokenIn"
CancelLimitOrderEventTokenOut = "TokenOut"
CancelLimitOrderEventTrancheKey = "TrancheKey"
CancelLimitOrderEventTokenInAmountOut = "TokenInAmountOut"
CancelLimitOrderEventTokenOutAmountOut = "TokenOutAmountOut"
)

// Tick Update Event Attributes
const (
EventTypeTickUpdate = "TickUpdate"
TickUpdateEventKey = "TickUpdate"
TickUpdateEventToken0 = "TokenZero"
TickUpdateEventToken1 = "TokenOne"
TickUpdateEventTokenIn = "TokenIn"
TickUpdateEventTickIndex = "TickIndex"
TickUpdateEventFee = "Fee"
TickUpdateEventTrancheKey = "TrancheKey"
TickUpdateEventReserves = "Reserves"
)

const (
EventTypeGoodTilPurgeHitGasLimit = "GoodTilPurgeHitGasLimit"
GoodTilPurgeHitGasLimitEventGas = "Gas"
)

const (
// NOTE: have to add letter so that LP deposits are indexed ahead of LimitOrders
LiquidityTypePoolReserves = "A_PoolDeposit"
Expand Down
Loading

0 comments on commit e109821

Please sign in to comment.