feat: add events to MsgAuctionBid handler (#111)
This commit is contained in:
parent
9fa85244b9
commit
14827d56f8
@ -2,7 +2,10 @@ package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/skip-mev/pob/x/builder/types"
|
||||
@ -51,6 +54,7 @@ func (m MsgServer) AuctionBid(goCtx context.Context, msg *types.MsgAuctionBid) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var proposerReward sdk.Coins
|
||||
if proposerFee.IsZero() {
|
||||
// send the entire bid to the escrow account when no proposer fee is set
|
||||
if err := m.bankKeeper.SendCoins(ctx, bidder, escrow, sdk.NewCoins(msg.Bid)); err != nil {
|
||||
@ -62,7 +66,7 @@ func (m MsgServer) AuctionBid(goCtx context.Context, msg *types.MsgAuctionBid) (
|
||||
|
||||
// determine the amount of the bid that goes to the (previous) proposer
|
||||
bid := sdk.NewDecCoinsFromCoins(msg.Bid)
|
||||
proposerReward, _ := bid.MulDecTruncate(proposerFee).TruncateDecimal()
|
||||
proposerReward, _ = bid.MulDecTruncate(proposerFee).TruncateDecimal()
|
||||
|
||||
if err := m.bankKeeper.SendCoins(ctx, bidder, sdk.AccAddress(prevProposer.GetOperator()), proposerReward); err != nil {
|
||||
return nil, err
|
||||
@ -78,6 +82,22 @@ func (m MsgServer) AuctionBid(goCtx context.Context, msg *types.MsgAuctionBid) (
|
||||
}
|
||||
}
|
||||
|
||||
bundledTxHashes := make([]string, len(msg.Transactions))
|
||||
for i, refTxRaw := range msg.Transactions {
|
||||
hash := sha256.Sum256(refTxRaw)
|
||||
bundledTxHashes[i] = hex.EncodeToString(hash[:])
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvent(
|
||||
sdk.NewEvent(
|
||||
types.EventTypeAuctionBid,
|
||||
sdk.NewAttribute(types.EventAttrBidder, msg.Bidder),
|
||||
sdk.NewAttribute(types.EventAttrBid, msg.Bid.String()),
|
||||
sdk.NewAttribute(types.EventAttrProposerReward, proposerReward.String()),
|
||||
sdk.NewAttribute(types.EventAttrBundledTxs, strings.Join(bundledTxHashes, ",")),
|
||||
),
|
||||
)
|
||||
|
||||
return &types.MsgAuctionBidResponse{}, nil
|
||||
}
|
||||
|
||||
|
||||
11
x/builder/types/events.go
Normal file
11
x/builder/types/events.go
Normal file
@ -0,0 +1,11 @@
|
||||
package types
|
||||
|
||||
// Event types and attributes
|
||||
const (
|
||||
EventTypeAuctionBid = "auction_bid"
|
||||
|
||||
EventAttrBidder = "bidder"
|
||||
EventAttrBid = "bid"
|
||||
EventAttrProposerReward = "proposer_reward"
|
||||
EventAttrBundledTxs = "bundled_txs"
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user