Feat/fibrous add Fibrous DEX aggregator router connector - #669
Open
Canowar1 wants to merge 1 commit into
Open
Conversation
Adds Fibrous as a router-type connector on Base, HyperEVM and Monad, following the existing 0x aggregator pattern. The Fibrous API returns swap arguments as structured objects rather than pre-encoded calldata, so the connector ABI-encodes the router's `swap` entrypoint itself using the published contract ABI (https://github.com/Fibrous-Finance/router-contract-abi). The fibrous-router-sdk is intentionally not used: it depends on ethers v6 and starknet, while Gateway is on ethers v5, and its bundled ABI is out of date relative to the deployed router. The Fibrous EVM API is ExactIn-only, so BUY orders go through the shared approximateBuyViaSellLeg helper and are flagged with `approximation: true`, matching the DFlow/OKX/Titan connectors. Gas is not taken from the API: `estimatedGasUsed` is zero on Base and reports the fee in native wei rather than a gas unit count on HyperEVM and Monad, so using it as a gas limit would produce unusable transactions. Price impact is not exposed by the API either, and deriving it from the per-token USD reference prices does not scale with trade size. It is instead measured against the rate of a much smaller reference trade on the same pair. Also adds the HyperEVM (chain ID 999) and Monad (chain ID 143) networks to the Ethereum chain, including token lists, wrapped-native addresses and EIP-1559 support.
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.
Before submitting this PR, please make sure:
A description of the changes proposed in the pull request:
Adds Fibrous as a router-type connector on Base, HyperEVM and Monad, following the existing 0x aggregator pattern.
Endpoints
GET /connectors/fibrous/router/quote-swap
POST /connectors/fibrous/router/execute-quote
POST /connectors/fibrous/router/execute-swap
Also wired into the unified /trading/swap routes via the fibrous/router provider key.
Implementation notes
Three characteristics of the Fibrous API drove design decisions worth calling out for review.
Unlike 0x, POST /{network}/v2/calldata returns route / swap_parameters / router_address objects, so the connector ABI-encodes the router's swap entrypoint itself. The ABI is taken from the published contract ABI at Fibrous-Finance/router-contract-abi and kept minimal (swap only) in fibrous.abi.ts.
fibrous-router-sdk is intentionally not used:
it depends on ethers v6 and starknet, while Gateway is on ethers v5;
its bundled ABI is out of date relative to the deployed router (it declares extra_data as uint256[] and protocol_id as uint256, and omits amount_out from the route tuple). The published ABI — bytes, int24, and amount_out present — matches the live V2 API response exactly.
A unit test decodes the generated calldata and asserts it round-trips back to the API's arguments.
There is no exact-output mode (the reverse flag does not provide one on EVM — verified against the live API). BUY orders therefore go through the shared approximateBuyViaSellLeg helper and are flagged with approximation: true, consistent with the DFlow / OKX / Titan connectors. approximateIfNoExactOut=false makes BUY fail with an explicit error instead.
Measured against the live API, the approximation lands within ~0.01–0.03% of the requested base amount on all three networks.
It is 0 on Base, and on HyperEVM and Monad it reports the fee in native wei rather than gas units — e.g. Monad returns 169452577555850000 (0.169 MON), which is consistent with the API's own estimatedGasUsedInUsd of $0.0039. Using it as a gasLimit would produce unusable transactions, so the connector uses a fixed default that callers can override with maxGas.
Price impact. The API does not expose price impact. Deriving it from the per-token USD reference prices was tried and rejected: the resulting figure is dominated by feed noise and does not grow with trade size (a 0.001 WETH trade implied more impact than a 100 WETH one). It is instead measured against the rate of a much smaller reference trade on the same pair, which is monotonic in size and degrades gracefully to 0 when the reference leg cannot be routed.
New networks
Adds HyperEVM (chain ID 999) and Monad (chain ID 143) to the Ethereum chain: network configs, token lists, wrapped-native addresses, and inclusion in EIP1559_NETWORKS (both were confirmed to return baseFeePerGas).
Note that the Fibrous docs list HyperEVM as chain ID 998; the live RPC reports 0x3e7 (999), which is what this PR uses — 998 is the testnet.
fibrous/router is also added to the swapProvider enum in ethereum-network-schema.json so the new networks can default to it.
Tests performed by the developer:
Testing
28 new unit tests across test/connectors/fibrous/, with mocks in test/mocks/fibrous/
Diff coverage for src/connectors/fibrous/ is ~86% statements (above the 75% requirement)
Full suite green: 128 suites / 1168 tests
pnpm typecheck, pnpm build and pnpm lint clean (0 errors)
Manually verified against the live Fibrous API on all three networks, both sides, indicative and firm quotes, plus the unified /trading/swap/quote route
Tips for QA testing: