-
Notifications
You must be signed in to change notification settings - Fork 559
/
emit.go
36 lines (31 loc) · 1.58 KB
/
emit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package keeper
import (
"encoding/hex"
"strconv"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cometbft/cometbft/crypto/tmhash"
"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v25/x/protorev/types"
)
// EmitBackrunEvent updates and emits a backrunEvent
func EmitBackrunEvent(ctx sdk.Context, pool SwapToBackrun, inputCoin sdk.Coin, profit, tokenOutAmount osmomath.Int, remainingTxPoolPoints, remainingBlockPoolPoints uint64) {
// Get tx hash
txHash := strings.ToUpper(hex.EncodeToString(tmhash.Sum(ctx.TxBytes())))
// Update the backrun event and add it to the context
backrunEvent := sdk.NewEvent(
types.TypeEvtBackrun,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(types.AttributeKeyTxHash, txHash),
sdk.NewAttribute(types.AttributeKeyUserPoolId, strconv.FormatUint(pool.PoolId, 10)),
sdk.NewAttribute(types.AttributeKeyUserDenomIn, pool.TokenInDenom),
sdk.NewAttribute(types.AttributeKeyUserDenomOut, pool.TokenOutDenom),
sdk.NewAttribute(types.AttributeKeyTxPoolPointsRemaining, strconv.FormatUint(remainingTxPoolPoints, 10)),
sdk.NewAttribute(types.AttributeKeyBlockPoolPointsRemaining, strconv.FormatUint(remainingBlockPoolPoints, 10)),
sdk.NewAttribute(types.AttributeKeyProtorevProfit, profit.String()),
sdk.NewAttribute(types.AttributeKeyProtorevAmountIn, inputCoin.Amount.String()),
sdk.NewAttribute(types.AttributeKeyProtorevAmountOut, tokenOutAmount.String()),
sdk.NewAttribute(types.AttributeKeyProtorevArbDenom, inputCoin.Denom),
)
ctx.EventManager().EmitEvent(backrunEvent)
}