Sandwich Bot and Arbitrage
FrostBit includes a native, proposer-local sandwich and arbitrage engine: miners who win stake-weighted VRF proposals can legally capture in-block spot and perpetual spreads without reordering public transactions, turning MEV into an open competition to hold and stake FB.
| Item | Value |
|---|---|
| Core flywheel | Higher FB stake share → higher VRF proposal rate → more sandwich/arbitrage opportunities (20% single-miner cap) |
| Markets covered | In-block spot and perpetual cross-order sandwiching + post-prefix 2–3 hop spot closed routes (best winner taken) |
| Order boundary | Public transactions keep their original relative order; private legs are ordinary limit orders |
| Key & fund isolation | Requires a separate arbitrage account distinct from the miner address; never touches miner stake |
| Private slot budget | Up to 100 reserved slots per block; every unused slot is backfilled with public transactions |
Why FrostBit supports sandwich bots natively: FB staking competition
On many chains, MEV leaks to opaque off-chain extraction networks without reinforcing native token demand. FrostBit brings orderly, rule-bounded in-block arbitrage directly into the validator client and ties execution rights to stake-weighted VRF block production, creating a transparent demand engine for FB.
- Stake share drives proposal probability: in each proposal window, VRF eligibility uses
threshold = min(ExpectedProposers × min(minerStake / totalMinerStake, 0.20), 1), with default window expectations of 5 / 15 / 30 / 50 proposers. After meeting the 32 FB minimum, an active miner can top up locked FB on its hot identity at any time to increase its win rate. - 20% single-miner weight cap prevents centralization: capping effective stake share at 20% rewards larger stakers with materially higher proposal frequency while keeping competition spread across at least five independent miners.
- Volume → arbitrage profit → FB accumulation flywheel: higher spot and perpetual trading volume generates more crossed limit quotes and temporary imbalances. Because only the winning block proposer can run the local sandwich strategy for that height, miners have a direct economic incentive to acquire and stake more FB.
Two built-in strategies and how execution works
The arbitrage engine runs strictly inside the local proposer process—it never submits transactions to the shared txpool and never broadcasts them independently. Once a miner becomes eligible to propose at a height, consensus builds the exact same ordered public prefix it would normally propose, runs one detached VM projection to record real orderbook traces, and pits two strategies against each other so only the global winner is signed:
- Strategy 1 — In-block cross-order sandwiching (spot and perpetuals): inspects public limit orders in the ordered prefix that actually execute and rest at the front of their book (ignoring market orders, cancels/closes, and self-trades). For an earlier low ask and a later crossed high bid, it schedules
public ask → private BUY → public bid → private SELL; for the reverse order,public bid → private SELL → public ask → private BUY. On perpetuals, leg one opens the position and leg two is an ordinaryis_close=trueIOC reduce-only order against the real book, leaving zero open position or resting order on success. Compatible opportunities across independent pairs are combined via a bounded 16-state beam search without overlapping one pair or reusing a maker. - Strategy 2 — Post-prefix multi-hop closed routes (2–3 hop spot cycles): scans the projected orderbook snapshot right after the public prefix for 2-hop or 3-hop closed spot cycles with no hardcoded token list, automatically supporting dynamically created tokens.
- No wasted block capacity: consensus temporarily withholds at most 100 slots for private legs during projection and restores every unused slot with the untouched public suffix during final assembly—so a 3-leg strategy in a 5,000-tx block still packs 4,997 public transactions plus 3 private transactions.
- Single full-block preflight and clean fallback: consensus weaves the winning batch into the block, recomputes commitments, and runs one complete VM preflight (including protocol hooks and conservation audits). The candidate is published only if every private leg succeeds, fills in full against its exact intended makers, and meets
minProfitBps; otherwise the proposer publishes the unchanged ordinary block.
Protocol boundaries: order-preserving and fail-closed
Native sandwich support is intentionally bounded by consensus rules. Every private leg is a standard limit-order transaction validated identically by all nodes—there is no special VM bundle privilege.
- Public order stays untouched: the engine never reorders, front-runs by reshuffling, or drops public prefix transactions. Private legs are inserted strictly between existing positions as limit orders bounded by each public maker’s signed limit price.
- Height and proposer binding: every private leg signs exact
target_heightandonly_proposer(the only field referencing the miner address). Once a block is broadcast, peers can observe the opportunity, but cannot validly replay those signed legs at another height or under another proposer. - Mandatory separate arbitrage account:
FromAddress, balance sizing, nonces, fees, and signatures all use the independent arbitrage account. Startup fails closed if the derived arbitrage address matches the miner address—it never falls back to miner stake or miner funds. - Closed public config schema: any private-key, seed, or password-like field placed under
Arbitrageinconfig.jsonis rejected at startup so secrets cannot leak into shared config files.
Configuration reference (config.json)
All strategy controls live under Arbitrage in the node-local config.json and contain no secrets. Omitted fields inherit defaults:
| Field | Default | Meaning |
|---|---|---|
enabled | false | Enables the engine by default; can remain false and be turned on per process via --enable-arbitrage |
txFee | "1000" | Per-leg runtime fee in FB smallest units (minimum "1000") |
capitalBps | 10000 | Max share of the arbitrage account’s spendable start-token balance per group in bps (10000 = 100%, 5000 = 50%) |
minProfitBps | 0 | Minimum net return threshold in bps (1 bps = 0.01%), checked at quote time and again after full-block VM preflight |
maxOrdersPerBook | 64 | Maximum orders analyzed per book (1..4096) |
maxCycleEvaluations | 4096 | Per-block comparison budget (1..1000000), consumed round-robin across pairs so one busy pair cannot stall proposal time |
{
"Arbitrage": {
"enabled": true,
"txFee": "1000",
"capitalBps": 5000,
"minProfitBps": 10,
"maxOrdersPerBook": 64,
"maxCycleEvaluations": 4096
}
}How to enable on a miner node
Generate a dedicated secp256k1 private key for the independent arbitrage account (never reuse the miner key), fund it with the starting trading assets you want the bot to deploy (such as ETH.DAI, FB, or target spot/perpetual quote tokens), and keep enough available FB to cover runtime fees for every leg.
- Pin the public address with
--expected-arbitrage-address: startup aborts if the key derives a different address or collides with--expected-address. - For official Docker image deployments, mount the separate arbitrage key read-only at
/run/secrets/dex-arbitrage/private_key(mode0600) and pass--enable-arbitrageplus--expected-arbitrage-address=<address>to the node arguments; the container entrypoint opens it on its own file descriptor so the key never enters argv or environment variables. - During coordinated protocol upgrades, keep
Arbitrage.enableddisabled (and omit--enable-arbitrage) until the rolling upgrade completes.
MINER_ADDRESS='REPLACE_WITH_REGISTERED_MINER_0X_ADDRESS'
ARBITRAGE_ADDRESS='REPLACE_WITH_INDEPENDENT_ARBITRAGE_0X_ADDRESS'
MINER_ENDPOINT='YOUR_PUBLIC_IPV4:19000'
exec 3</secure/miner.key
exec 4</secure/arbitrage-account.key
./dex \
--config-dir /etc/dex/miner \
--peers /etc/dex/miner/peers.json \
--bootstrap-mode latejoin \
--advertise-addr "$MINER_ENDPOINT" \
--expected-address "$MINER_ADDRESS" \
--data-dir "/var/lib/dex/$MINER_ADDRESS" \
--resume=true \
--private-key-fd 3 \
--enable-arbitrage \
--arbitrage-private-key-fd 4 \
--expected-arbitrage-address "$ARBITRAGE_ADDRESS" \
--no-simulatorAccounting, capital management, and risks
- Proceeds settle to the arbitrage account: once finalized, profits appear directly in the separate arbitrage account’s balances and explorer activity—there is no extra per-trade protocol subsidy.
- Account for FB fees on non-FB routes: routes can start and end in any token held by the arbitrage account. For FB routes,
minProfitBpsis net of leg runtime fees; for non-FB start tokens (such asETH.DAI),minProfitBpsmeasures native token ROI and does not convert the separate FB fee into that token—set a conservative threshold so thin spreads do not lose money after FB gas. - Consensus competition: multiple eligible miners may propose in the same window; only the block that reaches finality executes its arbitrage batch, while non-finalized candidates consume no chain assets.
- Hot-wallet sizing: because the arbitrage key signs automatically in memory, isolate it from your miner hot key and long-term reward payout address, fund it only with working capital you are comfortable keeping online, and sweep accumulated profits periodically to cold storage.