Chapter 09
Integration
Everything here is on-chain and most of it is Uniswap V2 code you have already written. The parts specific to INFERNO are one getter on the token, one vault call, and the router that takes the fee.
Reading a token
interface IModelToken {
function modelId() external view returns (string memory);
function vault() external view returns (address);
function totalSupply() external view returns (uint256);
}
interface IRevenueVault {
function token() external view returns (address);
function pending() external view returns (uint256); // ETH awaiting a buyback
function burned() external view returns (uint256); // tokens destroyed, cumulative
}Circulating supply is totalSupply minus the balance of the burn address — not totalSupply minus burned(), in case somebody has burned tokens by sending them there directly. Read the balance; it is the ground truth.
Quoting a swap
Ordinary V2. Find the pair through the Uniswap factory, read reserves, apply the constant-product formula with the 30 bps fee, and route through the router with a deadline and a minimum out.
- Quote against reserves read in the same block you submit, or accept that your quote is stale by the time it lands.
- Never assume a pair exists. The factory returns the zero address for a token nobody has seeded, and rendering a price for it is a bug.
- The token has no transfer hook, so
balanceOfafter a transfer equals what you expect. You do not need fee-on-transfer variants of the router functions.
The trade router
interface ITradeRouter {
function feeBps() external view returns (uint256);
function quoteBuy(address token, uint256 ethIn)
external view returns (uint256 amountOut, uint256 fee);
function quoteSell(address token, uint256 amountIn)
external view returns (uint256 ethOut, uint256 fee);
function buy(address token, uint256 minOut, uint256 deadline)
external payable returns (uint256 amountOut);
function sell(address token, uint256 amountIn, uint256 minOut, uint256 deadline)
external returns (uint256 ethOut);
}Quote through this rather than through Uniswap. quoteSell returns what the seller is paid, after the fee — quoting the pool and subtracting afterwards is how an interface ends up showing a figure nobody receives.
Every trade emits Traded(token, trader, isBuy, ethIn, amountOut, feeToVault), which is enough to reconstruct volume and the fee paid into each vault without touching the pair's own logs.
Errors you will meet
UnknownToken— the trade router was pointed at a token this factory did not deploy. Check the chain id before checking anything else.BelowMinimum— a sell whose net proceeds fell underminOut. Re-quote; do not widen the tolerance by reflex.no_pair— returned by quoting helpers when the token has no Uniswap pair. Render the token without a price rather than with a zero.INSUFFICIENT_OUTPUT_AMOUNT— the router's own revert, when the pool moved past your minimum. Re-quote; do not retry with a wider tolerance by default.