Skip to content

baseline integration - #1203

Open
zaqk wants to merge 2 commits into
VeloraDEX:masterfrom
zaqk:feature/baseline
Open

baseline integration#1203
zaqk wants to merge 2 commits into
VeloraDEX:masterfrom
zaqk:feature/baseline

Conversation

@zaqk

@zaqk zaqk commented Jul 2, 2026

Copy link
Copy Markdown

Add Baseline (Mercury) DEX integration

Baseline is a bonding-curve AMM on Ethereum and Base. All markets trade against a singleton (0xc81fd894c0ace037d133af4886550ac8133568e8, same address on both chains). Pricing is block-batched, so the integration is event-based with the curve math ported to local bigint. Integration tests assert wei-exact equality against the singleton's own quote views on live pools, including edge-case pools and pinned historical launch blocks. Pools are discovered from Baseline's GraphQL API, with configured fallbacks resolved on-chain.

Two caveats: (1) BUY with the bToken as input is declined. The exact-out function slightly over-delivers the reserve token, then pulls the excess back from the caller via transferFrom, so the caller must have approved the singleton for the token it is receiving. Augustus only approves the token being sold, so the pull-back reverts (more detail in the resolvePool comment). (2) Pool state changes once per block without an event. We derive it locally in the common case, but a few rare states aren't worth replicating: the math is intricate enough that a refetch is safer than getting it subtly wrong.


Note

High Risk
New swap pricing and execution path with intricate fixed-point math; incorrect quotes or snapshot roll-forward could misprice trades or cause reverts at execution.

Overview
Adds a new Baseline DEX on Ethereum and Base, routing all markets through a shared relay and pricing from cached getQuoteState snapshots plus locally ported bigint curve math (block-batched quotes, same-block flow, BLV floor, safety-regime behavior).

Baseline wires discovery (GraphQL + configured on-chain fallbacks), lazy per–bToken event subscribers, getPricesVolume without per-quote RPC, Augustus V6 swap encoding, and liquidity ranking. BUY with the bToken as input (exact reserve out) is intentionally not routed because the relay’s clawback needs reserve approval Augustus does not grant.

BaselineEventPool applies Swap logs, rolls snapshots across block boundaries when possible, and refetches when local re-derivation is unsafe (e.g. safety threshold or non-target convexity) so stale state cannot over-quote.

The DEX is registered in the dex index; tests add unit coverage for math/curve, relay differential checks (including edge pools and pinned launch blocks), event replay, pool boundary logic, and optional fork e2e on Base REPPO/VIRTUAL.

Reviewed by Cursor Bugbot for commit 7c2ba70. Bugbot is set up for automated code reviews on this repo. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant