-
Notifications
You must be signed in to change notification settings - Fork 18
/
mempool.go
63 lines (50 loc) 路 1.28 KB
/
mempool.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package mev
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/skip-mev/block-sdk/block/base"
)
// TxPriority returns a TxPriority over mev lane transactions only. It
// is to be used in the mev index only.
func TxPriority(config Factory) base.TxPriority[string] {
return base.TxPriority[string]{
GetTxPriority: func(goCtx context.Context, tx sdk.Tx) string {
bidInfo, err := config.GetAuctionBidInfo(tx)
if err != nil || bidInfo == nil || bidInfo.Bid.IsNil() {
return ""
}
return bidInfo.Bid.String()
},
Compare: func(a, b string) int {
aCoins, _ := sdk.ParseCoinsNormalized(a)
bCoins, _ := sdk.ParseCoinsNormalized(b)
switch {
case aCoins == nil && bCoins == nil:
return 0
case aCoins == nil:
return -1
case bCoins == nil:
return 1
default:
switch {
case aCoins.IsAllGT(bCoins):
return 1
case aCoins.IsAllLT(bCoins):
return -1
default:
return 0
}
}
},
MinValue: "",
}
}
// GetTopAuctionTx returns the highest bidding transaction in the auction mempool.
// This is primarily a helper function for the x/auction module.
func (l *MEVLane) GetTopAuctionTx(ctx context.Context) sdk.Tx {
iterator := l.Select(ctx, nil)
if iterator == nil {
return nil
}
return iterator.Tx()
}