bitflow-market-maker-public/.env.example
Bought 6bf5f337bb Gate ticks on engine tip freshness and resolve bin shares on-chain
Two gaps the v2 engine docs surfaced.

Quote v2 serves from in-memory AMM state at the applied tip and has no
stale-DB fallback, so nothing was stopping us sizing an add against
reserves that trail the chain. Every tick now checks quotes/v2/status and
holds unless tip_lag is within BFF_MAX_TIP_LAG (default 0). A null lag
means the tip is unknown, which is not the same as caught up and is
treated as stale. v1 has no such surface and skips the gate.

Quote v2 also documents the bin ladder's `liquidity` as always null.
Today it is only null in the dust tail, well away from the curve, but
sizing must not depend on that: bin shares are the denominator for
minDlp, and defaulting a missing one to zero takes calcAddSlippage down
its empty-bin sqrt branch. That misprices minDlp in either direction --
it over-demands DLP on small adds, which aborts the transaction after
gas is spent, and under-demands on large ones, which quietly forfeits
the slippage protection the post-condition exists to provide. Missing
shares are now read from the pool's get-total-supply, which was verified
to match the inventory endpoint's binShares exactly on mainnet.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-15 20:20:44 -07:00

81 lines
2.7 KiB
Text

ENVIRONMENT_TYPE=dev
# dry_run = read + log decisions only (no signing). live = sign + broadcast txs.
EXECUTION_MODE=dry_run
TICK_INTERVAL_MS=30000
# Copy a pair file instead of filling this one:
# cp .env.sbtc.example .env.sbtc
# cp .env.stx.example .env.stx
# Then run: npm run tick -- --pool sbtc
# npm run tick -- --pool stx
# Wallet we market-make from. SIGNER_ADDRESS works in dry_run for balance/LP
# lookups. SIGNER_KEY (hex private key) is required for EXECUTION_MODE=live --
# startup asserts it derives to SIGNER_ADDRESS.
SIGNER_ADDRESS=
SIGNER_KEY=
# Bitflow BFF API (pool/bin reads). prod: https://bff.bitflowapis.finance/api
BFF_API_BASE_URL=https://bff.bitflowapis.finance/api
# No key needed for the default 50 req/s per-IP tier (a tick uses ~4 calls).
# Ask Bitflow via Intercom for a key if you need a higher quota.
BFF_API_KEY=
# v2 (default) or v1. v2 is the engine API: it serves market-maker inventory from
# a tip-checked endpoint and returns an empty book (not a 404) for a wallet with
# no position. v1 is a fallback if v2 misbehaves; do not mix the two.
BFF_API_VERSION=v2
# Max blocks the v2 engine may trail the chain tip before a tick holds. v2 quotes
# come from in-memory state at the applied tip with no stale-DB fallback, so 0
# (only trade on a caught-up view) is Bitflow's guidance. v1 has no tip surface.
BFF_MAX_TIP_LAG=0
# Stacks node for read-only contract calls + native STX balance
STACKS_NODE_URL=
STACKS_NODE_KEY=
STACKS_NETWORK_VERSION=mainnet
# Master kill switch. KILL_SWITCH=true halts the automated loop at startup.
KILL_SWITCH=false
# Optional path to a file that, if present, halts the loop at the next tick.
KILL_SWITCH_FILE=
# Hard cap on deployed position value (x*price + y, in quote-micro). 0 = off.
MAX_POSITION_USTX=0
# Circuit breaker after this many consecutive data-fetch failures. 0 = off.
MAX_CONSECUTIVE_API_ERRORS=5
BREAKER_WITHDRAW_ALL=false
ENABLE_SWAP=true
ENABLE_ADD_LIQUIDITY=true
ENABLE_WITHDRAW_LIQUIDITY=true
# Transaction execution (live mode). Fees are in micro-STX (1 STX = 1_000_000).
MIN_TX_FEE_USTX=10000
MAX_TX_FEE_USTX=150000
DEFAULT_TX_FEE_USTX=60000
FEE_MEMPOOL_PERCENTILE=p50
FEE_OUTLIER_MULTIPLE=4
STX_GAS_RESERVE_USTX=5000000
TX_CONFIRMATION_TIMEOUT_MS=120000
TX_POLL_INTERVAL_MS=5000
TX_FEE_BUMP_MULTIPLIER=1.5
TX_MAX_FEE_BUMPS=3
# CoinGecko (volatility + safety only -- never the quoted price).
# Leave the key blank to use the free endpoint (slower poll).
COINGECKO_API_KEY=
COINGECKO_VS_CURRENCY=usd
METRICS_ENABLED=true
METRICS_HTTP_ENABLED=true
METRICS_HTTP_HOST=127.0.0.1
METRICS_HTTP_PORT=8080
METRICS_HISTORY_SIZE=200
METRICS_LOG_FILE=data/metrics.jsonl
METRICS_BASELINE_FILE=data/metrics-baseline.json
METRICS_RESET_BASELINE=false
LOG_LEVEL=info
LOG_PRETTY=true