feat(adapter-integration): add BopAMM swap adapter#1082
Closed
tvinagre wants to merge 2 commits into
Closed
Conversation
Sell-side ISwapAdapter for BopAMM (Bebop's on-chain PMM) wrapping the BopAmmV2 settlement contract. Pool ids pack settlement (20 bytes) and assetId (12 bytes), matching the substreams component ids. Limits are found by bisecting quote(), which reverts InsufficientLiquidity above the committed lane size. Buy orders revert NotImplemented: the venue quotes exact-input only. Quotes are gated on block.timestamp equalling the book's committed update timestamp (StaleUpdate() otherwise); fork tests re-stamp the registry lane via vm.store, and simulation pins the timestamp via the override_block_timestamp component attribute. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The simulation engine deploys the adapter in a context where the settlement contract's code is injected at call time, not at construction. The constructor read settlement.pricing()/usdc() eagerly, so deployment reverted there (the protocol-testing harness caught this; the fork tests passed only because setUp forks mainnet where settlement already exists). Resolve both lazily via public view functions instead. Pin the test fork to a quote-commit block (25266710): the venue is operator-driven, so forking latest drifts (a third book was added, quotes go stale) and broke the limit/price/swap assertions. At the pinned block exactly two books exist and the block timestamp matches book 0's committed quote. Verified: adapter fork tests 14/14, and the protocol-testing harness builds and deploys the adapter and passes test_book_discovery 1/1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
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.
What
Sell-side
ISwapAdapterfor BopAMM (Bebop's on-chain PMM), wrapping the BopAmmV2 settlement contract (0xdB13ad0fcD134E9c48f2fDaEa8f6751a0F5349ca), plus manifest and Foundry fork tests.settlement (20 bytes) | assetId (12 bytes), matching thevm:bopammsubstreams component ids (feat(substreams): add BopAMM VM integration #1081).quote()view.quote()revertsInsufficientLiquidity()above the committed lane size, so limits are found by probing + bisection. The maker's inventory is not checked byquote()— limits can overestimate whatswap()settles (the interface prefers overestimation, and the operator sizes lanes to inventory).recipient = msg.sender, output measured by balance diff. Buy orders revertNotImplemented— the venue quotes exact-input only.SellOrder,PriceFunction,ConstantPrice(verified constant up to the lane cap),HardLimits.getAssetConfig(0..64)on the pricing module; every book isasset/USDC.Staleness gate
The update registry reverts
StaleUpdate()unlessblock.timestampequals the book's committed update timestamp (MAX_UPDATE_AGE == 0). Fork tests re-stamp the committed lane timestamp viavm.store(keccak256(abi.encode(module, bookId)), timestamp in the top 32 bits). At simulation runtime the timestamp is pinned via theoverride_block_timestampcomponent attribute (emitted by the substreams in #1081, consumed by tycho-simulation in #1034).Testing
14/14 fork tests pass against a mainnet fork (
ETH_RPC_URL): pool/token enumeration, capabilities, limits in both directions on both books, constant-price check up to the limit, sell swaps both directions with balance assertions, and revert cases (above limit, stale timestamp, paused venue, pool/token mismatch, foreign settlement pool id, buy order).BopAmmV2::swapmeasures ~120k gas (manifestprotocol_gas: 120000).Depends on #1081 (component id format) and #1034 (
override_block_timestampsupport) for end-to-end simulation; the files here are self-contained and the tests run on main.🤖 Generated with Claude Code