# Settlement

Since the payoff is computed directly from the oracle price, lag needs to introduced into the settlement system so that entering and exiting positions cannot be timed to arbitrage the market.

Time in Perennial markets is split into units called *oracle versions*. **Settlement only occurs on the transition of one oracle version to another.** When a user requests to open or close a new position, that position delta sits in a pending state until the next oracle version update, after which it takes effect.

For underlying oracles based on the provided `ChainlinkOracle` bridge contract, oracle versions directly coincide 1:1 with Chainlink rounds.

### Example Settlement Flow

In this example the user calls open(10) at during oracle version 1, and close(10) during oracle version 3. The user's position opens at the start of version 2 and closes at the start of version 4, meaning they are exposed to the price difference between versions 2 and 4.

<table><thead><tr><th width="117">Oracle Version</th><th width="157">User Action</th><th width="161">Pending</th><th width="153">Oracle Price</th><th width="162">Position (Profit/loss)</th></tr></thead><tbody><tr><td>1</td><td>Open 1 ETH</td><td><p>Opening: 10</p><p>Closing: 0</p></td><td>$1000</td><td>-<br>(0)</td></tr><tr><td>2</td><td></td><td><p>Opening: 0</p><p>Closing: 0</p></td><td>$1025</td><td>1 ETH <br>(0)</td></tr><tr><td>3</td><td>Close 1 ETH</td><td><p>Opening: 0</p><p>Closing: 10</p></td><td>$1075</td><td>1 ETH <br>(+$50)</td></tr><tr><td>4</td><td></td><td><p>Opening: 0</p><p>Closing: 0</p></td><td>$1050</td><td>-<br>(+$25)</td></tr></tbody></table>

Note that this settlement flow happens entirely on-chain, giving Perennial strong guauntees for projects building on top. Perennial smart contracts store the current version for position adjustments, allowing for the positions opening price & PnL to be retroactively calculated at the next on-chain settlement period (when the contracts are interacted with again), avoiding the need for a second interaction during opens/closing (or the need for a keeper).&#x20;

In the example above, when opening a positions, the user interacted with Perennial only once. After the user has called open position, when the next oracle version occurs,&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-v1.perennial.finance/mechanism/settlement.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
