How FlatEx Works: 1inch Routing + Flat Fees

FlatEx is a DEX aggregator on Base with one unusual property: it charges a flat dollar fee instead of a percentage. Understanding how it works takes three pieces - routing, the fee layer, and the security model.

What a DEX aggregator does

No single liquidity pool has the best price for every trade. DEX aggregators query many pools - Uniswap v3, Aerodrome, BaseSwap and others - and split or route your trade across whichever path yields the most output tokens. The aggregator's job is price discovery and execution; it never holds your funds longer than a single transaction.

The 1inch routing engine

FlatEx does not reinvent routing. Every quote and swap is powered by 1inch, the most battle-tested aggregator API in DeFi. When you type an amount on flatex.trade, the frontend calls the 1inch API (proxied through a Cloudflare Worker so no API key is exposed), receives the optimal route and calldata, and displays the expected output.

When you confirm, that 1inch calldata is passed into the FlatExRouter contract, which executes it on-chain against the whitelisted 1inch aggregation router. In other words: same routing quality as 1inch itself, different fee structure on top.

The flat fee layer

The FlatExRouter contract enforces the fee on-chain, not in the UI. Fees are denominated in USD but paid in ETH as msg.value with the swap transaction:

Trade size (USD)Fee
Under $1,000$0.01
$1,000 - $10,000$0.99
$10,000 - $100,000$2.99
$100,000 - $1,000,000$9.99
Over $1,000,000$29.99

The frontend computes your trade's USD value from the live quote, selects the tier, converts it to ETH at the current price, and attaches it to the transaction. The contract verifies msg.value >= tierFees[tier] - so the fee cannot be skipped or inflated by either side.

Collected fees sit in a separate FeeCollector contract. An autoSweep function lets anyone trigger a payout to the operator once the balance exceeds 0.05 ETH - it can only ever send to the owner address, so it is safe to leave permissionless.

Approvals and Permit2

To swap, your token needs an allowance. FlatEx supports the standard ERC-20 approve flow plus Permit2 (0x000000000022D473030F116dDEE9F6B43aC78BA3) for gasless signature approvals where the wallet supports it. Approvals go to the FlatExRouter contract itself; the router then pulls exactly the swap amount via transferFrom and forwards it to 1inch for execution.

Security model

What FlatEx is not

FlatEx has no token, no points program, and no custody of user funds. It is a thin, auditable fee layer over the best routing available on Base - nothing more.

The transaction lifecycle, step by step

Concretely, one swap works like this:

If any step fails the entire transaction reverts - there is no partial state where your tokens are stuck in the contract. That is the advantage of doing everything in a single atomic call.

Make a swap