> ## Documentation Index
> Fetch the complete documentation index at: https://pons-labs-llc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quoting a trade

> How the v3 hook fee applies to each type of swap, the hook's own buyback swaps, and reading the price oracle.

v3 pools are regular Uniswap v4 pools with the Pons hook attached, so you trade
them through the PoolManager as usual. The difference is how fees are charged.
The pool fee is zero, and the hook takes its own fee on the quote side through
the swap deltas, outside the pool's math. To quote a trade, apply the fee on the
quote side as shown below. When you specify the quote amount, take the fee off
first and run the rest through the curve. When you specify the token amount, run
the curve first and apply the fee to the quote it gives.

```text Where the fee lands theme={null}
feeBps below is hookFeeBps plus any live snipe tax plus the creator's
creatorTaxBps, all charged on the same leg. The grossed-up cases gross up
that combined rate once.

  exact-input buy    quote in specified    taken from the input, so the
                                           pool swaps input - fee
  exact-output buy   memecoin out spec.    grossed up: the buyer pays
                                           feeBps of its whole spend
  exact-input sell   memecoin in spec.     skimmed from the quote the
                                           pool pays out
  exact-output sell  quote out specified   grossed up: feeBps of what
                                           the pool pays out is fee

  gross-up = ceil(amount × 10000 / (10000 - feeBps)) - amount
```

> [!WARNING]
>
> Swaps that specify the quote amount can't be partially filled. The fee is charged
> before the pool knows how much it can fill, so if it can't fill the whole amount,
> the swap reverts instead of overcharging. If that happens, send a smaller swap or
> specify the token amount instead. Retrying the same swap will fail again.

## No price impact limit

The launch record has `maxInternalPriceImpactBps` set to 300, which looks like a
3% price impact limit on trades. It only applies to the hook's own buyback swaps,
which use a price limit set to a third of it. User swaps have no impact limit,
and the creator's opening buy has no price limit at all.

## Buyback swaps

When buyback is on for a launch, the buyback budget builds up in the quote asset
and is spent buying the token in the pool when the pool is swept. Sweeps are run
by allowlisted callers, at most once per pool per parent-chain block, since
`block.number` on this chain follows the parent chain. A regular sweep is
skipped if the price guard rejects the price. A trusted sweeper can instead sweep
with its own minimums, which skips some of the guard's checks but still has to
meet minimums the relay sets from the current price and, when it's ready, the
TWAP. If the swap's price limit can't be reached, the
budget is kept for a later sweep, so it accumulates instead of expiring. These
swaps are made by the hook itself, so they don't pay the hook fee and don't
trigger the swap callbacks.

## Oracle

```ts Reading the TWAP theme={null}
// The price oracle lives in the hook. There's no separate oracle contract.
const hookAbi = parseAbi([
  "function consult(bytes32 poolId, uint32 window) view returns (int24 arithmeticMeanTick, bool ready, uint32 coveredSeconds)",
  "function maxCoveredSeconds() view returns (uint32)",
  "function twapWindow() view returns (uint32)",
  "function currentSnipeTaxBps(bytes32 poolId, bool zeroForOne) view returns (uint256)",
]);

const window = 300;
const [reading, maxCovered] = await Promise.all([
  client.readContract({
    address: memeHook,
    abi: hookAbi,
    functionName: "consult",
    args: [poolId, window],
  }),
  client.readContract({
    address: memeHook,
    abi: hookAbi,
    functionName: "maxCoveredSeconds",
  }),
]);

const [meanTick, ready, coveredSeconds] = reading;

// ready needs an observation old enough to cover the window and at least one
// swap or liquidity change inside it, so a pool with neither inside the window
// reads not ready. coveredSeconds is the span actually averaged. It's never shorter than the
// window and can be much longer on a quiet pool, so cap it like the sweep
// guard does.
const usable = ready && coveredSeconds <= maxCovered;
```

`ready` means the oracle has an observation old enough to cover the window you
asked for and at least one newer observation inside it. Observations are written
on swaps and liquidity changes, so a pool with neither inside the window reads
not ready. `coveredSeconds` is the
time span that was averaged, and it's never shorter than your window. If
the pool was quiet before the window started, the closest older observation can be far back,
so the average covers a much longer and older span than you asked for. Compare it
against `maxCoveredSeconds()` and reject anything wider, which is what the
protocol's sweep guard does before setting a minimum price. The guard has its own
`twapWindow()` setting on the guard contract, separate from the hook's
`twapWindow()`. Both are 3600 seconds today, and `maxCoveredSeconds()` is 14,400.

When a pool has been quiet, the hook brings the reading up to the present by
moving the last tick toward the current price, with a cap on how much it can move
per second, instead of leaving it where it was. An old average moves gradually
toward the current price as a result. This limits how much a single trade can
move the average, and it's another reason to wait when `coveredSeconds` is large
instead of using the price.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.