> ## Documentation Index
> Fetch the complete documentation index at: https://whitepaper.flowstate.exchange/llms.txt
> Use this file to discover all available pages before exploring further.

# Contract Interface

> The Market contract, discovery, quoting and execution

The Market contract is the single entry point. Integrators do not call pools directly.

## Discovery

```solidity theme={null}
mapping(address token => mapping(address quoteAsset => address pool)) public poolByPair;
```

One pool per (token, quote asset) pair, so pair resolution is deterministic. Pool creation emits:

```solidity theme={null}
event PoolCreated(
    address indexed token,
    address indexed quoteAsset,
    address indexed pool,
    address creator,
    uint256 amount,
    uint16 anchorBandBps,
    uint192 seedRate
);
```

Indexing that single event is sufficient to discover the full pool set.

## Quoting

```solidity theme={null}
function quoteBuyFromPool(address pool, uint256 amount)
    external view returns (Quote memory);

struct Quote {
    bool available;
    uint256 fillableAmount;
    uint256 quoteAmount;
    uint256 feeAmount;
    uint16 feeBps;
    address quoteAsset;
}
```

Two properties are deliberate and worth relying on.

**The quoter does not revert.** An unavailable pool, a failed oracle read, a paused market or an empty pool all return `available: false` rather than reverting. Oracle calls are wrapped so that an oracle failure degrades to an empty quote.

**It is simulatable by anyone.** It is a plain view with no caller requirement, so any indexer, router backend or solver can simulate it with `eth_call` without privileges, allowances or state.

`quoteSellToPool` mirrors it for the sell side where enabled. The sell side ships disabled, see [How C1 Pools Work](/integration/how-c1-pools-work#the-sell-side).

## Execution

```solidity theme={null}
function buyFromPool(address pool, uint256 amount, string calldata resellerCode, address buyer)
    external returns (uint256 tokensFilled, uint256 quotePaid);

function buyFromPoolExactQuote(address pool, uint256 quoteIn, string calldata resellerCode, address buyer)
    external returns (uint256 tokensFilled, uint256 quotePaid);

function buyFromPoolExactOut(address pool, uint256 tokenAmountOut, string calldata resellerCode, address buyer)
    external returns (uint256 tokensFilled, uint256 quotePaid);
```

`buyFromPool` is exact-output in token terms. Name a token amount and the market computes and pulls the cost.

`buyFromPoolExactQuote` is exact-input in quote-asset terms. Name the quote amount you are spending. The cost pulled never exceeds the amount offered.

`buyFromPoolExactOut` is exact-output with an optional funding callback, for callers that source the quote asset during the call rather than holding it beforehand. It invokes `IFlowstateBuyFunder.fundBuy(quoteAsset, cost)` on the caller only when the caller is a contract and its balance or allowance is short. Callers that pre-fund are unaffected and need not implement the interface. The callback semantics for intent fillers are covered in [Settlement Patterns](/integration/settlement-patterns#pattern-2-intent-based-settlement).

## Settlement

Settlement is quote-asset only. The buyer leg is an ERC-20 `transferFrom` with `msg.value == 0`. There is no native-ETH path.

Integrators approve the Market as spender. The Market pulls exactly the computed cost and forwards it to the pool.

## Attribution

`resellerCode` is an optional attribution string. Pass an empty string if unused. Attribution is what links settled volume to an integration partner.

## Depositor interface

Deposit through `createPool` for a new pair or `contributeTokens` for an existing pool. Positions are withdrawable via `withdrawTokens`, and proceeds are claimable from the pool via `claimQuote` and `claimTokens`.

## Summary for an integrating router

* One entry point, one pool per pair, one event to index for discovery.
* A non-reverting view quoter that anyone can simulate without privileges.
* Quote and execution read the same rate through the same path in the same block.
