# Quoter

### tradeCallback

Callback function that handles the result of a trade. It reverts with the trade amounts.

```javascript
function tradeCallback(uint256 cAmount, uint256 sAmount, bytes calldata data) external pure override 
```

**Params:**

| **Name** | **Type** | **Description**                                                     |
| -------- | -------- | ------------------------------------------------------------------- |
| cAmount  | uint256  | Amount of collateral token input spent to be spent for the trade    |
| sAmount  | uint256  | Amount of Spear or Shield token output to be received for the trade |
| data     | bytes    | Data passed through by the caller                                   |

### parseRevertReason

Parses a revert reason that should contain the numeric quote

```javascript
function parseRevertReason(bytes memory reason) private pure returns (uint256, uint256)  
```

**Params:**

| **Name** | **Type** | **Description**         |
| -------- | -------- | ----------------------- |
| reason   | bytes    | The revert reason bytes |

**Returns:**

| **Type** | **Description**         |
| -------- | ----------------------- |
| uint256  | The first parsed value  |
| uint256  | The second parsed value |

### quoteExactInput

Returns the amounts to spend or receive for a given exact input swap without executing the swap

```javascript
function quoteExactInput(BattleTradeParams memory params, address battleAddr) public returns (uint256 spend, uint256 get) 
```

**Params:**

| **Name**          | **Type** | **Description**                                                                                                                     |
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| BattleTradeParams | memory   | Parameters for a trade action. See [Params](https://docs.divergence-protocol.com/technical-reference/core/params#battletradeparams) |
| battleAddr        | address  | The address of the battle contract                                                                                                  |

**Returns:**

| **Name** | **Type** | **Description**                          |
| -------- | -------- | ---------------------------------------- |
| spend    | uint256  | The amount of collateral to spend        |
| get      | uint256  | The amount of Spear or shield to receive |

### getSTokenByLiquidity

Calculates the amount of Spear or shield tokens based on the given liquidity

```javascript
function getSTokenByLiquidity(AddLiqParams calldata params) external view returns (uint256)
```

**Params:**

| **Name**     | **Type** | **Description**                                                                                                                                  |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| AddLiqParams | params   | Params required for adding liquidity. See [Params](https://docs.divergence-protocol.com/technical-reference/periphery/params#addliquidityparams) |

**Returns:**

| **Name** | **Type** | **Description**                                                             |
| -------- | -------- | --------------------------------------------------------------------------- |
| SToken   | uint256  | The amount of Spear or Shield token calculated based on the given liquidity |

### getSTokenByLiquidityWhenCreate

Calculates the amount of Spear or shield tokens based on the given amount of seed collateral when a liquidity position is created

```javascript
function getSTokenByLiquidityWhenCreate(uint160 sqrtPriceX96, int24 tickLower, int24 tickUpper, uint256 amount) public pure returns (uint256)
```

**Params:**

| **Name**     | **Type** | **Description**                                               |
| ------------ | -------- | ------------------------------------------------------------- |
| sqrtPriceX96 | uint160  | The current sqrt price                                        |
| tickLower    | int24    | The lower tick boundary of the position                       |
| tickUpper    | int24    | The upper tick boundary of the position                       |
| amount       | uint256  | The seed collateral amount for minting the liquidity position |

**Returns:**

| **Type** | **Description**                                                             |
| -------- | --------------------------------------------------------------------------- |
| uint256  | The amount of Spear or Shield token calculated based on the given liquidity |

### positions

Gets the position information for the given token ID

```javascript
function positions(uint256 tokenId) external view override returns (Position memory)
```

**Params:**

| **Name** | **Type** | **Description**                                          |
| -------- | -------- | -------------------------------------------------------- |
| tokenId  | uint256  | The ID of the NFT that represents the liquidity position |

**Returns:**

| **Type** | **Description**   |
| -------- | ----------------- |
| Position | The position data |

### handlePosition

Gets the position information for the given token ID

```javascript
function handlePosition(uint256 tokenId) private view returns (Position memory p)
```

**Params:**

| **Name** | **Type** | **Description**                                          |
| -------- | -------- | -------------------------------------------------------- |
| tokenId  | uint256  | The ID of the NFT that represents the liquidity position |

**Returns:**

| **Type** | **Description**   |
| -------- | ----------------- |
| Position | The position data |

### accountPositions

Gets the positions for the given account

```javascript
function accountPositions(address account) external view override returns (Position[] memory)
```

**Params:**

| **Name** | **Type** | **Description**     |
| -------- | -------- | ------------------- |
| account  | address  | The account address |

**Returns:**

| **Name** | **Type** | **Description**  |
| -------- | -------- | ---------------- |
| Position | memory   | Position details |


---

# 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.divergence-protocol.com/technical-reference/periphery/quoter.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.
