Skip to content

Trading and quotes ​

The router ​

HanokRouter is one entry point for a token's whole life. It reads the launch phase from the factory and sends the trade to the curve or the Uniswap V4 pool. If a curve is sold out but graduation was deferred, the router completes graduation first.

solidity
function buy(address token, uint256 quoteIn, uint256 minTokensOut, address recipient, address referrer, uint256 deadline)
    external payable returns (uint256 tokensOut);

function sell(address token, uint256 tokensIn, uint256 minQuoteOut, address recipient, address referrer, uint256 deadline)
    external returns (uint256 quoteOut);

function sellWithPermit(address token, uint256 tokensIn, uint256 minQuoteOut, address recipient, address referrer,
    uint256 deadline, uint8 v, bytes32 r, bytes32 s) external returns (uint256 quoteOut);
  • buy takes the ETH as msg.value, equal to quoteIn. Unspent ETH (a clamped final fill) is refunded to the caller.
  • sell requires a prior approval of the router; sellWithPermit takes an EIP-2612 signature instead, so a sale is one transaction.
  • referrer may be address(0). Self-referrals are ignored.

Quotes on the curve ​

The curve exposes exact quotes; there is no need to reproduce its math.

solidity
function quoteBuy(uint256 quoteIn, address recipient)
    external view returns (uint256 tokensOut, uint256 quoteSpent, uint256 fee, uint256 tax);
function quoteSell(uint256 tokensIn)
    external view returns (uint256 quoteOut, uint256 fee, uint256 tax);

quoteBuy applies the snipe tax for recipient and clamps to the sellable allocation: quoteSpent < quoteIn means the buy would sell the curve out and the remainder is refunded. fee is the platform fee; tax is the creator tax plus any snipe tax.

Both return zeros once the curve is closed.

Quotes on the pool ​

After graduation, simulate HanokRouter.buy with eth_call for an exact result, or use any Uniswap V4 quoter against the pool key. Remember the hook takes 1% + creatorTax on the ETH leg.

Slippage on the curve ​

Because the final fill of a launch can be clamped, minTokensOut on a curve buy bounds the rate: the trade succeeds if tokensOut / quoteSpent ≥ minTokensOut / quoteIn. Size it from the quoted rate, not from the total.

Trading the curve directly ​

You can bypass the router and call the curve; the signatures mirror the router's:

solidity
function buy(uint256 quoteIn, uint256 minTokensOut, address recipient, address referrer)
    external payable returns (uint256 tokensOut, uint256 quoteSpent);
function sell(uint256 tokensIn, uint256 minQuoteOut, address recipient, address referrer)
    external returns (uint256 quoteOut);

Sells revert with AwaitingGraduation between sell-out and graduation, and with CurveClosed after graduation. Route to the pool at that point.

Hanok is unaudited testnet software. Tokens can lose all value.