> For the complete documentation index, see [llms.txt](https://fluxion-network.gitbook.io/fluxion-network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fluxion-network.gitbook.io/fluxion-network/developer-resources/technical-overview-and-api/amm-v2-pool-implementation.md).

# amm v2 pool implementation

## Overview

Core AMM V2 pool implementation for stable and volatile token pairs.

* Contract name: `Pool`
* Address: `0x8D4b46B6ce7C59Ec42eea9e67b0eeFFd29D921E6`
* Network: Mantle Mainnet (`chainId 5000`)
* Explorer: [`Mantle Explorer`](https://explorer.mantle.xyz/address/0x8D4b46B6ce7C59Ec42eea9e67b0eeFFd29D921E6)
* Explorer API: [`smart-contract payload`](https://explorer.mantle.xyz/api/v2/smart-contracts/0x8D4b46B6ce7C59Ec42eea9e67b0eeFFd29D921E6)
* Sourcify metadata: [`metadata.json`](https://repo.sourcify.dev/contracts/full_match/5000/0x8D4b46B6ce7C59Ec42eea9e67b0eeFFd29D921E6/metadata.json)
* Sourcify source: [`contracts/Pool.sol`](https://repo.sourcify.dev/contracts/full_match/5000/0x8D4b46B6ce7C59Ec42eea9e67b0eeFFd29D921E6/sources/contracts/Pool.sol)

## Read Functions

### DOMAIN\_SEPARATOR

```solidity
function DOMAIN_SEPARATOR() external view returns (bytes32 return0)
```

Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `bytes32` | Not documented in NatSpec. |

***

### allowance

```solidity
function allowance(address owner, address spender) external view returns (uint256 return0)
```

Returns the remaining number of tokens that `spender` will be allowed to spend on behalf of `owner` through {transferFrom}. This is zero by default. This value changes when {approve} or {transferFrom} are called.

Parameters

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `owner`   | `address` | Not documented in NatSpec. |
| `spender` | `address` | Not documented in NatSpec. |

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### balanceOf

```solidity
function balanceOf(address account) external view returns (uint256 return0)
```

Returns the value of tokens owned by `account`.

Parameters

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `account` | `address` | Not documented in NatSpec. |

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### blockTimestampLast

```solidity
function blockTimestampLast() external view returns (uint256 return0)
```

Timestamp of last update to pool

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### claimable0

```solidity
function claimable0(address arg0) external view returns (uint256 return0)
```

Amount of unclaimed, but claimable tokens from fees of token0 for an LP

Parameters

| Name   | Type      | Description                |
| ------ | --------- | -------------------------- |
| `arg0` | `address` | Not documented in NatSpec. |

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### claimable1

```solidity
function claimable1(address arg0) external view returns (uint256 return0)
```

Amount of unclaimed, but claimable tokens from fees of token1 for an LP

Parameters

| Name   | Type      | Description                |
| ------ | --------- | -------------------------- |
| `arg0` | `address` | Not documented in NatSpec. |

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### currentCumulativePrices

```solidity
function currentCumulativePrices() external view returns (uint256 reserve0Cumulative, uint256 reserve1Cumulative, uint256 blockTimestamp)
```

Produces the cumulative price using counterfactuals to save gas and avoid a call to sync.

This function does not take parameters.

Return Values

| Name                 | Type      | Description                |
| -------------------- | --------- | -------------------------- |
| `reserve0Cumulative` | `uint256` | Not documented in NatSpec. |
| `reserve1Cumulative` | `uint256` | Not documented in NatSpec. |
| `blockTimestamp`     | `uint256` | Not documented in NatSpec. |

***

### decimals

```solidity
function decimals() external view returns (uint8 return0)
```

Returns the number of decimals used to get its user representation. For example, if `decimals` equals `2`, a balance of `505` tokens should be displayed to a user as `5.05` (`505 / 10 ** 2`). Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. This is the default value returned by this function, unless it's overridden. NOTE: This information is only used for *display* purposes: it in no way affects any of the arithmetic of the contract, including {IERC20-balanceOf} and {IERC20-transfer}.

This function does not take parameters.

Return Values

| Name      | Type    | Description                |
| --------- | ------- | -------------------------- |
| `return0` | `uint8` | Not documented in NatSpec. |

***

### eip712Domain

```solidity
function eip712Domain() external view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions)
```

returns the fields and values that describe the domain separator used by this contract for EIP-712 signature.

This function does not take parameters.

Return Values

| Name                | Type        | Description                |
| ------------------- | ----------- | -------------------------- |
| `fields`            | `bytes1`    | Not documented in NatSpec. |
| `name`              | `string`    | Not documented in NatSpec. |
| `version`           | `string`    | Not documented in NatSpec. |
| `chainId`           | `uint256`   | Not documented in NatSpec. |
| `verifyingContract` | `address`   | Not documented in NatSpec. |
| `salt`              | `bytes32`   | Not documented in NatSpec. |
| `extensions`        | `uint256[]` | Not documented in NatSpec. |

***

### factory

```solidity
function factory() external view returns (address return0)
```

Address of PoolFactory that created this contract

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### getAmountOut

```solidity
function getAmountOut(uint256 amountIn, address tokenIn) external view returns (uint256 return0)
```

Get the amount of tokenOut given the amount of tokenIn

Parameters

| Name       | Type      | Description        |
| ---------- | --------- | ------------------ |
| `amountIn` | `uint256` | Amount of token in |
| `tokenIn`  | `address` | Address of token   |

Return Values

| Name      | Type      | Description |
| --------- | --------- | ----------- |
| `return0` | `uint256` | Amount out  |

***

### getReserves

```solidity
function getReserves() external view returns (uint256 _reserve0, uint256 _reserve1, uint256 _blockTimestampLast)
```

Update reserves and, on the first call per block, price accumulators

This function does not take parameters.

Return Values

| Name                  | Type      | Description |
| --------------------- | --------- | ----------- |
| `_reserve0`           | `uint256` | .           |
| `_reserve1`           | `uint256` | .           |
| `_blockTimestampLast` | `uint256` | .           |

***

### index0

```solidity
function index0() external view returns (uint256 return0)
```

Accumulated fees of token0 (global)

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### index1

```solidity
function index1() external view returns (uint256 return0)
```

Accumulated fees of token1 (global)

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### lastObservation

```solidity
function lastObservation() external view returns (tuple(uint256 timestamp, uint256 reserve0Cumulative, uint256 reserve1Cumulative) return0)
```

Get the value of the most recent observation

This function does not take parameters.

Return Values

| Name      | Type                                                                               | Description                |
| --------- | ---------------------------------------------------------------------------------- | -------------------------- |
| `return0` | `tuple(uint256 timestamp, uint256 reserve0Cumulative, uint256 reserve1Cumulative)` | Not documented in NatSpec. |

***

### metadata

```solidity
function metadata() external view returns (uint256 dec0, uint256 dec1, uint256 r0, uint256 r1, bool st, address t0, address t1)
```

Returns the decimal (dec), reserves (r), stable (st), and tokens (t) of token0 and token1

This function does not take parameters.

Return Values

| Name   | Type      | Description                |
| ------ | --------- | -------------------------- |
| `dec0` | `uint256` | Not documented in NatSpec. |
| `dec1` | `uint256` | Not documented in NatSpec. |
| `r0`   | `uint256` | Not documented in NatSpec. |
| `r1`   | `uint256` | Not documented in NatSpec. |
| `st`   | `bool`    | Not documented in NatSpec. |
| `t0`   | `address` | Not documented in NatSpec. |
| `t1`   | `address` | Not documented in NatSpec. |

***

### name

```solidity
function name() external view returns (string return0)
```

Returns the name of the token.

This function does not take parameters.

Return Values

| Name      | Type     | Description                |
| --------- | -------- | -------------------------- |
| `return0` | `string` | Not documented in NatSpec. |

***

### nonces

```solidity
function nonces(address owner) external view returns (uint256 return0)
```

Returns the current nonce for `owner`. This value must be included whenever a signature is generated for {permit}. Every successful call to {permit} increases `owner`'s nonce by one. This prevents a signature from being used multiple times.

Parameters

| Name    | Type      | Description                |
| ------- | --------- | -------------------------- |
| `owner` | `address` | Not documented in NatSpec. |

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### observationLength

```solidity
function observationLength() external view returns (uint256 return0)
```

Get the number of observations recorded

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### observations

```solidity
function observations(uint256 arg0) external view returns (uint256 timestamp, uint256 reserve0Cumulative, uint256 reserve1Cumulative)
```

Reads contract state.

Parameters

| Name   | Type      | Description                |
| ------ | --------- | -------------------------- |
| `arg0` | `uint256` | Not documented in NatSpec. |

Return Values

| Name                 | Type      | Description                |
| -------------------- | --------- | -------------------------- |
| `timestamp`          | `uint256` | Not documented in NatSpec. |
| `reserve0Cumulative` | `uint256` | Not documented in NatSpec. |
| `reserve1Cumulative` | `uint256` | Not documented in NatSpec. |

***

### periodSize

```solidity
function periodSize() external view returns (uint256 return0)
```

Capture oracle reading every 30 minutes (1800 seconds)

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### poolFees

```solidity
function poolFees() external view returns (address return0)
```

Address of linked PoolFees.sol

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### prices

```solidity
function prices(address tokenIn, uint256 amountIn, uint256 points) external view returns (uint256[] return0)
```

Returns a memory set of TWAP prices Same as calling sample(tokenIn, amountIn, points, 1)

Parameters

| Name       | Type      | Description                |
| ---------- | --------- | -------------------------- |
| `tokenIn`  | `address` | .                          |
| `amountIn` | `uint256` | .                          |
| `points`   | `uint256` | Number of points to return |

Return Values

| Name      | Type        | Description          |
| --------- | ----------- | -------------------- |
| `return0` | `uint256[]` | Array of TWAP prices |

***

### quote

```solidity
function quote(address tokenIn, uint256 amountIn, uint256 granularity) external view returns (uint256 amountOut)
```

Provides twap price with user configured granularity, up to the full window size

Parameters

| Name          | Type      | Description |
| ------------- | --------- | ----------- |
| `tokenIn`     | `address` | .           |
| `amountIn`    | `uint256` | .           |
| `granularity` | `uint256` | .           |

Return Values

| Name        | Type      | Description |
| ----------- | --------- | ----------- |
| `amountOut` | `uint256` | .           |

***

### reserve0

```solidity
function reserve0() external view returns (uint256 return0)
```

Amount of token0 in pool

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### reserve0CumulativeLast

```solidity
function reserve0CumulativeLast() external view returns (uint256 return0)
```

Cumulative of reserve0 factoring in time elapsed

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### reserve1

```solidity
function reserve1() external view returns (uint256 return0)
```

Amount of token1 in pool

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### reserve1CumulativeLast

```solidity
function reserve1CumulativeLast() external view returns (uint256 return0)
```

Cumulative of reserve1 factoring in time elapsed

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### sample

```solidity
function sample(address tokenIn, uint256 amountIn, uint256 points, uint256 window) external view returns (uint256[] return0)
```

Same as prices with with an additional window argument. Window = 2 means 2 \* 30min (or 1 hr) between observations

Parameters

| Name       | Type      | Description |
| ---------- | --------- | ----------- |
| `tokenIn`  | `address` | .           |
| `amountIn` | `uint256` | .           |
| `points`   | `uint256` | .           |
| `window`   | `uint256` | .           |

Return Values

| Name      | Type        | Description          |
| --------- | ----------- | -------------------- |
| `return0` | `uint256[]` | Array of TWAP prices |

***

### stable

```solidity
function stable() external view returns (bool return0)
```

True if pool is stable, false if volatile

This function does not take parameters.

Return Values

| Name      | Type   | Description                |
| --------- | ------ | -------------------------- |
| `return0` | `bool` | Not documented in NatSpec. |

***

### supplyIndex0

```solidity
function supplyIndex0(address arg0) external view returns (uint256 return0)
```

Get an LP's relative index0 to index0

Parameters

| Name   | Type      | Description                |
| ------ | --------- | -------------------------- |
| `arg0` | `address` | Not documented in NatSpec. |

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### supplyIndex1

```solidity
function supplyIndex1(address arg0) external view returns (uint256 return0)
```

Get an LP's relative index1 to index1

Parameters

| Name   | Type      | Description                |
| ------ | --------- | -------------------------- |
| `arg0` | `address` | Not documented in NatSpec. |

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### symbol

```solidity
function symbol() external view returns (string return0)
```

Returns the symbol of the token, usually a shorter version of the name.

This function does not take parameters.

Return Values

| Name      | Type     | Description                |
| --------- | -------- | -------------------------- |
| `return0` | `string` | Not documented in NatSpec. |

***

### token0

```solidity
function token0() external view returns (address return0)
```

Address of token in the pool with the lower address value

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### token1

```solidity
function token1() external view returns (address return0)
```

Address of token in the poool with the higher address value

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |

***

### tokens

```solidity
function tokens() external view returns (address return0, address return1)
```

Returns \[token0, token1]

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `address` | Not documented in NatSpec. |
| `return1` | `address` | Not documented in NatSpec. |

***

### totalSupply

```solidity
function totalSupply() external view returns (uint256 return0)
```

Returns the value of tokens in existence.

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

## Write Functions

### approve

```solidity
function approve(address spender, uint256 value) external returns (bool return0)
```

See {IERC20-approve}. NOTE: If `value` is the maximum `uint256`, the allowance is not updated on `transferFrom`. This is semantically equivalent to an infinite approval. Requirements: - `spender` cannot be the zero address.

Parameters

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `spender` | `address` | Not documented in NatSpec. |
| `value`   | `uint256` | Not documented in NatSpec. |

Return Values

| Name      | Type   | Description                |
| --------- | ------ | -------------------------- |
| `return0` | `bool` | Not documented in NatSpec. |

***

### burn

```solidity
function burn(address to) external returns (uint256 amount0, uint256 amount1)
```

This low-level function should be called from a contract which performs important safety checks standard uniswap v2 implementation

Parameters

| Name | Type      | Description                                                      |
| ---- | --------- | ---------------------------------------------------------------- |
| `to` | `address` | Address to receive token0 and token1 from burning the pool token |

Return Values

| Name      | Type      | Description               |
| --------- | --------- | ------------------------- |
| `amount0` | `uint256` | Amount of token0 returned |
| `amount1` | `uint256` | Amount of token1 returned |

***

### claimFees

```solidity
function claimFees() external returns (uint256 claimed0, uint256 claimed1)
```

Claim accumulated but unclaimed fees (claimable0 and claimable1)

This function does not take parameters.

Return Values

| Name       | Type      | Description                |
| ---------- | --------- | -------------------------- |
| `claimed0` | `uint256` | Not documented in NatSpec. |
| `claimed1` | `uint256` | Not documented in NatSpec. |

***

### getK

```solidity
function getK() external returns (uint256 return0)
```

Returns the value of K in the Pool, based on its reserves.

This function does not take parameters.

Return Values

| Name      | Type      | Description                |
| --------- | --------- | -------------------------- |
| `return0` | `uint256` | Not documented in NatSpec. |

***

### initialize

```solidity
function initialize(address _token0, address _token1, bool _stable) external
```

Called on pool creation by PoolFactory

Parameters

| Name      | Type      | Description                       |
| --------- | --------- | --------------------------------- |
| `_token0` | `address` | Address of token0                 |
| `_token1` | `address` | Address of token1                 |
| `_stable` | `bool`    | True if stable, false if volatile |

This function does not return a value.

***

### mint

```solidity
function mint(address to) external returns (uint256 liquidity)
```

This low-level function should be called by addLiquidity functions in Router.sol, which performs important safety checks standard uniswap v2 implementation

Parameters

| Name | Type      | Description                            |
| ---- | --------- | -------------------------------------- |
| `to` | `address` | Address to receive the minted LP token |

Return Values

| Name        | Type      | Description               |
| ----------- | --------- | ------------------------- |
| `liquidity` | `uint256` | Amount of LP token minted |

***

### permit

```solidity
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external
```

Sets `value` as the allowance of `spender` over `owner`'s tokens, given `owner`'s signed approval. IMPORTANT: The same issues {IERC20-approve} has related to transaction ordering also apply here. Emits an {Approval} event. Requirements: - `spender` cannot be the zero address. - `deadline` must be a timestamp in the future. - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` over the EIP712-formatted function arguments. - the signature must use `owner`'s current nonce (see {nonces}). For more information on the signature format, see the <https://eips.ethereum.org/EIPS/eip-2612#specification\\[relevant> EIP section]. CAUTION: See Security Considerations above.

Parameters

| Name       | Type      | Description                |
| ---------- | --------- | -------------------------- |
| `owner`    | `address` | Not documented in NatSpec. |
| `spender`  | `address` | Not documented in NatSpec. |
| `value`    | `uint256` | Not documented in NatSpec. |
| `deadline` | `uint256` | Not documented in NatSpec. |
| `v`        | `uint8`   | Not documented in NatSpec. |
| `r`        | `bytes32` | Not documented in NatSpec. |
| `s`        | `bytes32` | Not documented in NatSpec. |

This function does not return a value.

***

### setName

```solidity
function setName(string __name) external
```

Set pool name Only callable by Voter.emergencyCouncil()

Parameters

| Name     | Type     | Description        |
| -------- | -------- | ------------------ |
| `__name` | `string` | String of new name |

This function does not return a value.

***

### setPoolFees

```solidity
function setPoolFees(address _poolFees) external
```

Set the poolFees address (only callable by factory during initialization)

Parameters

| Name        | Type      | Description                |
| ----------- | --------- | -------------------------- |
| `_poolFees` | `address` | Not documented in NatSpec. |

This function does not return a value.

***

### setSymbol

```solidity
function setSymbol(string __symbol) external
```

Set pool symbol Only callable by Voter.emergencyCouncil()

Parameters

| Name       | Type     | Description          |
| ---------- | -------- | -------------------- |
| `__symbol` | `string` | String of new symbol |

This function does not return a value.

***

### skim

```solidity
function skim(address to) external
```

Force balances to match reserves

Parameters

| Name | Type      | Description                            |
| ---- | --------- | -------------------------------------- |
| `to` | `address` | Address to receive any skimmed rewards |

This function does not return a value.

***

### swap

```solidity
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes data) external
```

This low-level function should be called from a contract which performs important safety checks

Parameters

| Name         | Type      | Description                           |
| ------------ | --------- | ------------------------------------- |
| `amount0Out` | `uint256` | Amount of token0 to send to `to`      |
| `amount1Out` | `uint256` | Amount of token1 to send to `to`      |
| `to`         | `address` | Address to recieve the swapped output |
| `data`       | `bytes`   | Additional calldata for flashloans    |

This function does not return a value.

***

### sync

```solidity
function sync() external
```

Force reserves to match balances

This function does not take parameters.

This function does not return a value.

***

### transfer

```solidity
function transfer(address to, uint256 value) external returns (bool return0)
```

See {IERC20-transfer}. Requirements: - `to` cannot be the zero address. - the caller must have a balance of at least `value`.

Parameters

| Name    | Type      | Description                |
| ------- | --------- | -------------------------- |
| `to`    | `address` | Not documented in NatSpec. |
| `value` | `uint256` | Not documented in NatSpec. |

Return Values

| Name      | Type   | Description                |
| --------- | ------ | -------------------------- |
| `return0` | `bool` | Not documented in NatSpec. |

***

### transferFrom

```solidity
function transferFrom(address from, address to, uint256 value) external returns (bool return0)
```

See {IERC20-transferFrom}. Skips emitting an {Approval} event indicating an allowance update. This is not required by the ERC. See {xref-ERC20-\_approve-address-address-uint256-bool-}\[\_approve]. NOTE: Does not update the allowance if the current allowance is the maximum `uint256`. Requirements: - `from` and `to` cannot be the zero address. - `from` must have a balance of at least `value`. - the caller must have allowance for `from`'s tokens of at least `value`.

Parameters

| Name    | Type      | Description                |
| ------- | --------- | -------------------------- |
| `from`  | `address` | Not documented in NatSpec. |
| `to`    | `address` | Not documented in NatSpec. |
| `value` | `uint256` | Not documented in NatSpec. |

Return Values

| Name      | Type   | Description                |
| --------- | ------ | -------------------------- |
| `return0` | `bool` | Not documented in NatSpec. |
