feat(flowstate): add FlowState C1 pools as a liquidity source - #1208
Open
danielthefoe wants to merge 2 commits into
Open
feat(flowstate): add FlowState C1 pools as a liquidity source#1208danielthefoe wants to merge 2 commits into
danielthefoe wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ac85b3c. Configure here.
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.

PR title
feat: add FlowState (C1 pools) as a liquidity source
PR description
FlowState - C1 pools as a liquidity source
Adds FlowState as a V6 DEX integration. FlowState runs on-chain "C1 pools"
that let buyers spend native ETH to buy an ERC-20 out of a pool at the
on-chain 1inch spot price. This PR lets Velora route ETH→token buys into them.
How it works
case (BUY, non-ETH src, ETH dest, token→token) returns
[]/null, so theintegration is strictly additive - it can only contribute a new source on
the one shape it serves, never alter or break an existing route.
getRateToEth) - the exact ratethe pool's on-chain
checkAmountsuses - flat/zero-slippage, capped by thepool's live token balance.
getPricesVolumereads rate + balances viatryAggregate, so an unpriceable token (oracle revert) or a brokenbalanceOfdegrades to "no quote" instead of disrupting the pricing batch.getDexParamencodesbuyFromPool(pool, amount, resellerCode, recipient)(payable). The tokenamountis re-derived fromsrcAmountatthe quoted rate so it lands centered in the contract's ±1%
checkAmountsband. Native ETH is consumed directly (
needWrapNative: false,dexFuncHasRecipient: true, Flag 9 - noinsertFromAmount).Chains
Ethereum, BSC, Base, Arbitrum. The 1inch oracle (
0x…6786) and theCREATE2 router (
0x93B7C8…) are identical across all four (verified against thecontract's own
PriceOracleAddresses).Tests
buyFromPoolcalldataencoding + V6 flags.
module's multicall pricing is byte-identical to an independent on-chain
recompute of the contract formula, capped by inventory.
Run:
npx jest src/dex/flowstateKnown limitation (documented in
getDexParam)The pool takes native ETH via
msg.value+ a static tokenamount. As anon-first hop consuming intermediate native ETH,
msg.valueis the priorhop's runtime output and can drift >1% from the quote, tripping
checkAmountsand reverting that route only - fail-closed (no fund loss, no effect on
other DEXes). The single-hop ETH-buy path (the primary use case) is unaffected.
getPricesVolumedeclines whenisFirstSwap === false.Open question for maintainers: does the production pricing engine pass
isFirstSwaptogetPricesVolume? The open-sourcepricing-helperpasses 7args (no
isFirstSwap); if production passes it, the guard fully prevents thenon-first-hop case. If not, is there a preferred way for a payable/fixed-amount
source to opt out of intermediate placement? The clean long-term fix is
contract-side (a
buyFromPoolvariant that derives the token amount frommsg.valueon-chain, making anymsg.valuesafe).Notes
-e2e.test.tsnot included: it simulates swaps via a fork/Tenderly, which wevalidated manually instead. Happy to add it in-repo if you'd prefer.
Note
Medium Risk
New routing path for native-ETH swaps with payable execution and contract ±1% amount checks; mis-pricing or multi-hop placement could cause route reverts, though guards and fail-closed behavior limit blast radius.
Overview
Adds a new FlowState V6 DEX that routes native ETH → ERC-20 exact-input buys through on-chain C1 pools via payable
buyFromPool, and registers it on Ethereum, BSC, Base, and Arbitrum.Discovery & pricing: Active pools come from FlowState’s Hasura GraphQL indexer (short TTL cache, stale snapshot on errors). Quotes use the on-chain 1inch
getRateToEthrate plus live poolbalanceOf, withtryAggregateso oracle/token failures drop to “no quote” instead of breaking the batch. Output is flat at the oracle rate and capped at inventory (over-size amounts price to0).Additive routing: Every path except SELL with native ETH source and ERC-20 dest returns
[]/null;getPricesVolumealso returnsnullwhenisFirstSwap === falseso the source is not used as a middle hop where static calldata vs runtimemsg.valuecould revert.Execution:
getDexParamencodesbuyFromPoolwith tokenamountrecomputed fromsrcAmountand the quoted rate (not min-out), native ETH (Flag 9, noinsertFromAmount), and tokens sent to the route recipient.Unit tests lock additivity guards and calldata/flags; a live integration test checks discovery, pricing vs an independent on-chain formula, and
getTopPoolsForToken.Reviewed by Cursor Bugbot for commit f88b2bb. Bugbot is set up for automated code reviews on this repo. Configure here.