feat(pools): Balancer V2 pool pricing via queryBatchSwap (Phase 1, draft) - #10
Draft
jenish-25 wants to merge 9 commits into
Draft
feat(pools): Balancer V2 pool pricing via queryBatchSwap (Phase 1, draft)#10jenish-25 wants to merge 9 commits into
jenish-25 wants to merge 9 commits into
Conversation
Author
|
Design discussion and open questions: #11 |
Author
|
Heads up on the failing checks — they're pre-existing on
For reference, the README-only PR #88 fails the same four jobs, and |
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.
Summary
Adds a
BalancerV2Poolthat implements thePooltrait and prices swaps by simulating the Balancer Vault'squeryBatchSwapinside revm — modeled on the existingCurvePool(EVM-simulation) pattern rather than porting Balancer's weighted/stable math to Rust.PoolProtocol::BalancerV2/PoolClass::BalancerV2already existed and the Vault ABI was already vendored (used for flash loans); this wires them up for pricing.Scope: Phase 1 (pricing & detection) only. Execution (multicaller opcode encoder + on-chain Vault routing) is intentionally deferred —
get_abi_encoderreturnsNonefor now.What's included
crates/defi/pools/src/balancerv2pool.rs—BalancerV2Pool+Poolimplcalculate_out_amount/calculate_in_amountbuild a single-hopqueryBatchSwap(GIVEN_IN/GIVEN_OUT) and run it against the state DB viaevm_call, decoding theint256[]deltasget_state_requiredadds a representativequeryBatchSwapper direction so the prestate tracer captures Vault + pool storage (singleton-Vault layout)crates/defi/abi/src/balancer/pool.rs— minimalIBalancerV2Poolinterface (getPoolId,getSwapFeePercentage);#[sol(rpc)]added to the Vault interface forfetch_pool_datacrates/defi/address-book— Balancer V2 Vault address constantStatus — draft, not yet ready to merge
Opening as a draft for early feedback on the approach. Two things outstanding:
test_balancer_v2_pool,#[ignore]) is compile-checked but hasn't been run against an archive node yet. The open question is whetherqueryBatchSwapreturnsint256[]cleanly underevm_callor reverts-with-data in query mode — the decode may need adjusting once run.BalancerV2Poolis constructible and priceable, but I deferred the discovery mechanism (dedicated loader vs. config-based) pending a preference.Happy to adjust the approach, split it up, or hold it — feedback welcome.
Test Plan
cargo buildon affected cratesqueryBatchSwapcalldata roundtrip + delta-sign decodingclippyclean on the new file; formatting cleantest_balancer_v2_poolagainst a mainnet archive node (MAINNET_WS) to confirm the pricing path end-to-end