Skip to content

Feat/fibrous add Fibrous DEX aggregator router connector - #669

Open
Canowar1 wants to merge 1 commit into
hummingbot:developmentfrom
Canowar1:feat/fibrous-connector
Open

Feat/fibrous add Fibrous DEX aggregator router connector#669
Canowar1 wants to merge 1 commit into
hummingbot:developmentfrom
Canowar1:feat/fibrous-connector

Conversation

@Canowar1

Copy link
Copy Markdown

Before submitting this PR, please make sure:

  • [👍 ] Your code builds clean without any errors or warnings
  • [ 👍 ] You are using approved title ("feat/", "fix/", "docs/", "refactor/")

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.

  1. The API returns structured swap arguments, not pre-encoded calldata.

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.

  1. The EVM API is ExactIn-only.

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.

  1. estimatedGasUsed is not a gas unit count.

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:

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.
@fengtality
fengtality changed the base branch from main to development August 5, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant