diff --git a/x/dex/keeper/cancel_limit_order.go b/x/dex/keeper/cancel_limit_order.go index 5abd22fc8..967ff5602 100644 --- a/x/dex/keeper/cancel_limit_order.go +++ b/x/dex/keeper/cancel_limit_order.go @@ -44,8 +44,8 @@ func (k Keeper) CancelLimitOrderCore( pairID.Token1, makerDenom, takerDenom, - makerCoinOut.Amount, takerCoinOut.Amount, + makerCoinOut.Amount, trancheKey, )) diff --git a/x/dex/keeper/limit_order_tranche_user.go b/x/dex/keeper/limit_order_tranche_user.go index 9df5c072e..ea2896a70 100644 --- a/x/dex/keeper/limit_order_tranche_user.go +++ b/x/dex/keeper/limit_order_tranche_user.go @@ -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 diff --git a/x/dex/keeper/place_limit_order.go b/x/dex/keeper/place_limit_order.go index 161707765..fcb562b5b 100644 --- a/x/dex/keeper/place_limit_order.go +++ b/x/dex/keeper/place_limit_order.go @@ -84,6 +84,8 @@ func (k Keeper) PlaceLimitOrderCore( orderType.String(), sharesIssued, trancheKey, + swapInCoin.Amount, + swapOutCoin.Amount, )) return trancheKey, totalInCoin, swapInCoin, swapOutCoin, nil diff --git a/x/dex/keeper/withdraw_filled_limit_order.go b/x/dex/keeper/withdraw_filled_limit_order.go index 01f93fd35..40ff3c6ec 100644 --- a/x/dex/keeper/withdraw_filled_limit_order.go +++ b/x/dex/keeper/withdraw_filled_limit_order.go @@ -42,6 +42,7 @@ func (k Keeper) WithdrawFilledLimitOrderCore( makerDenom, takerDenom, takerCoinOut.Amount, + makerCoinOut.Amount, trancheKey, )) diff --git a/x/dex/types/events.go b/x/dex/types/events.go index f24ebcb00..9b616e26f 100644 --- a/x/dex/types/events.go +++ b/x/dex/types/events.go @@ -19,6 +19,8 @@ const ( AttributeTokenOut = "TokenOut" AttributeAmountIn = "AmountIn" AttributeAmountOut = "AmountOut" + AttributeSwapAmountIn = "SwapAmountIn" + AttributeSwapAmountOut = "SwapAmountOut" AttributeTokenInAmountOut = "TokenInAmountOut" AttributeTokenOutAmountOut = "TokenOutAmountOut" AttributeTickIndex = "TickIndex" @@ -47,6 +49,10 @@ const ( AttributeInc = "inc" AttributeDec = "dec" AttributePairID = "pair_id" + AttributeMakerDenom = "MakerDenom" + AttributeTakerDenom = "TakerDenom" + AttributeSharesOwned = "SharesOwned" + AttributeSharesWithdrawn = "SharesWithdrawn" ) // Event Keys @@ -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" ) @@ -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"), @@ -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...) @@ -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{ @@ -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...) @@ -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{ @@ -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...) +}