mirror of
https://github.com/luxfi/dex.git
synced 2026-09-24 00:26:31 +00:00
the docs described an ordering the engine does not have
flare.mdx published an OrderTransactions that sorts by priority fee, highest first. No such function exists, nothing anywhere reads a priority fee, and the mempool says the opposite in as many words: ordering is arrival order, and a fee-priority mempool is a future concern the venue does not have. That matters more than an ordinary doc error. This repository is public, and a venue documented as selling position is a different venue from one where order ids are (height << 32) | txIndex and cannot be bid for. The page now describes the comparator that runs — price, then the id, FIFO within a level — and says plainly that fee priority is not it. Co-authored-by: Hanzo Dev <[email protected]>
This commit is contained in:
@@ -538,36 +538,32 @@ func (f *Flare) CreateBlock(
|
||||
|
||||
### Deterministic Transaction Order
|
||||
|
||||
Flare ensures deterministic transaction ordering within finalized blocks:
|
||||
Ordering is arrival order, and nothing buys a better place in it.
|
||||
|
||||
The mempool is a FIFO: the sequence a transaction is accepted in is the
|
||||
sequence the matcher consumes. Order ids are `(height << 32) | txIndex`, a
|
||||
function of position alone, so an id cannot be bid for. There is no priority
|
||||
fee, no tier, and no field in the comparator naming a sender — the matcher
|
||||
reads price, then the id:
|
||||
|
||||
```go
|
||||
// OrderTransactions provides deterministic ordering for DEX trades
|
||||
func (f *Flare) OrderTransactions(block *Block) []Transaction {
|
||||
txs := block.Transactions
|
||||
|
||||
// Sort by:
|
||||
// 1. Priority fee (highest first)
|
||||
// 2. Nonce (for same sender)
|
||||
// 3. Transaction hash (tiebreaker)
|
||||
sort.Slice(txs, func(i, j int) bool {
|
||||
// Priority fee
|
||||
if txs[i].PriorityFee() != txs[j].PriorityFee() {
|
||||
return txs[i].PriorityFee() > txs[j].PriorityFee()
|
||||
// pkg/dex/batch_match.go
|
||||
sort.SliceStable(idx, func(a, b int) bool {
|
||||
pa, pb := book[idx[a]].Price, book[idx[b]].Price
|
||||
if pa.Integer != pb.Integer {
|
||||
if takerSide == DEXSideBid {
|
||||
return pa.Integer < pb.Integer // best ask = lowest price first
|
||||
}
|
||||
|
||||
// Same sender: by nonce
|
||||
if txs[i].Sender() == txs[j].Sender() {
|
||||
return txs[i].Nonce() < txs[j].Nonce()
|
||||
}
|
||||
|
||||
// Tiebreaker: hash
|
||||
return bytes.Compare(txs[i].Hash(), txs[j].Hash()) < 0
|
||||
})
|
||||
|
||||
return txs
|
||||
}
|
||||
return pa.Integer > pb.Integer // best bid = highest price first
|
||||
}
|
||||
// ... fraction, then order id: price-time priority, FIFO within a level
|
||||
})
|
||||
```
|
||||
|
||||
Resting orders append to the tail and the best order is taken from the head,
|
||||
so within a price level the earlier order fills first. A fee-priority mempool
|
||||
would change that and is deliberately not what this is.
|
||||
|
||||
### MEV Protection
|
||||
|
||||
```go
|
||||
|
||||
Reference in New Issue
Block a user