baseline integration - #1203
Open
zaqk wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
getQuoteStatesnapshots plus locally ported bigint curve math (block-batched quotes, same-block flow, BLV floor, safety-regime behavior).Baselinewires discovery (GraphQL + configured on-chain fallbacks), lazy per–bToken event subscribers,getPricesVolumewithout 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.BaselineEventPoolappliesSwaplogs, 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.