How to integrate Fermi Swap into a smart contract: wrapper flow
Route an Ethereum token swap through PropAMMRouter, with separate allowances for the user and wrapper.
The Blockheight Editors··2 min read
Fermi Swap smart contract integration uses PropAMMRouter: fund a wrapper, approve the router from that wrapper, then call swapViaVenueV1 with the verified venue. The router pulls input from its caller, so the wrapper’s allowance must cover its own token balance; a wallet approval cannot authorize the router to spend tokens held by the wrapper.
- Start with a funded user and wrapper, a verified router ABI, and a quote for cbBTC to WETH. A routed trade sends an exact input amount through a specified venue and returns both the output amount and the venue that executed. Bind the deployed router address and ABI, and use the verified Fermi venue address for the trade.
- Collect the input with SafeERC20, then approve the router from the wrapper. The wallet first authorizes the wrapper to collect cbBTC; the wrapper then authorizes PropAMMRouter to spend cbBTC held by the wrapper. These approvals have different owners and spenders. Approving the router from the wallet only covers tokens owned by that wallet, so the router cannot pull the wrapper’s balance until the wrapper itself approves it.
- Invoke swapViaVenueV1 with the venue, cbBTC, WETH, amountIn, amountOutMin, recipient and deadline. For a Solidity wrapper, the call follows this shape: router.swapViaVenueV1(fermiVenue, address(cbBTC), address(WETH), amountIn, minOut, recipient, deadline). The Fermi Swap service lets developers route and execute the trade through its contract route; this is the relevant path for an automated wrapper. The interface specifies the arguments, caller allowance and return values in IPropAMMRouter.
- Assert the recipient’s WETH balance delta meets amountOutMin, then record the returned executedVenue. PropAMMRouter can fall back to Uniswap V3 if the named proprietary venue fails to fill, so a successful swap does not by itself prove that Fermi filled it. Require executedVenue to equal the verified venue when the application must confirm a Fermi execution. FermiSwapper’s fermi() returns its pricing-engine address; treat that as pricing-engine data, not as the venue address without separate verification.
For an automated contract call, choose the service’s documented contract route; a wallet interface fits manual swaps initiated by a person. The final check is the recipient’s WETH balance delta against the minimum, plus the returned venue when execution source matters.