# SwapPool

Swap pool contract. May or may not be covered by a backstop pool. Conceptionally, there are two ways to temporarily disable a pool: The owner can either pause the pool, disabling deposits, swaps & backstop, or the owner can set the pool cap to zero which only prevents deposits. The former is for security incidents, the latter for phasing out a pool.

***

### SwapFees

```solidity
struct SwapFees {
  uint32 lpFee;
  uint32 backstopFee;
  uint32 protocolFee;
}
```

***

### totalLiabilities

```solidity
uint256 totalLiabilities
```

The liabilities of the pool Cannot just use totalSupply() as the totalLiabilities will accumulate also the LP fees from swaps. This is fixed point number using the decimals of this pool

***

### reserve

```solidity
uint256 reserve
```

The amount of pool tokens usable for swaps This is fixed point number using the decimals of this pool

***

### reserveWithSlippage

```solidity
uint256 reserveWithSlippage
```

The amount of pool tokens plus the slippage The relationship with reserve is: reserveWithSlippage = slippageCurve.psi(reserve, totalLiabilities) However this relationship will never hold precisely and will deviate slightly for numerical reasons!! All code needs to work even if this relationship does not hold This is fixed point number using the decimals of this pool

***

### maxCoverageRatioForSwapIn

```solidity
uint256 maxCoverageRatioForSwapIn
```

***

### safeRedeemPercentage

```solidity
uint256 safeRedeemPercentage
```

***

### safeRedeemInterval

```solidity
uint256 safeRedeemInterval
```

***

### lastBackstopBurnTimestamp

```solidity
uint256 lastBackstopBurnTimestamp
```

***

### lastAvailableAmountForSafeRedeem

```solidity
uint256 lastAvailableAmountForSafeRedeem
```

***

### protocolTreasury

```solidity
address protocolTreasury
```

***

### lastDepositAt

```solidity
mapping(address => uint256) lastDepositAt
```

***

### lastDepositAmount

```solidity
mapping(address => uint256) lastDepositAmount
```

***

### backstop

```solidity
contract IBackstopPool backstop
```

***

### router

```solidity
contract IRouter router
```

router instance for this swap pool

***

### slippageCurve

```solidity
contract ISlippageCurve slippageCurve
```

***

### deposit

```solidity
function deposit(uint256 _depositAmount, uint256 _minLPAmountOut, uint256 _deadline) external returns (uint256 sharesToMint_, int256 fee_)
```

Deposits amount of tokens into pool Will change cov ratio of pool, will increase delta to 0

#### **Parameters**

| Name             | Type    | Description                                            |
| ---------------- | ------- | ------------------------------------------------------ |
| \_depositAmount  | uint256 | The amount to be deposited, an amount of pool tokens   |
| \_minLPAmountOut | uint256 | Minimum amount of pool lp tokens to mint               |
| \_deadline       | uint256 | Unix timestamp after which the transaction will revert |

#### **Return Values**

| Name           | Type    | Description                                                                      |
| -------------- | ------- | -------------------------------------------------------------------------------- |
| sharesToMint\_ | uint256 | Total number of pool lp tokens minted                                            |
| fee\_          | int256  | The slippage reward (a negative fee), fixed point number using the pool decimals |

***

### quoteDeposit

```solidity
function quoteDeposit(uint256 _depositAmount) external view returns (uint256 sharesToMint_, uint256 slippageReward_)
```

Get a quote for the effective amount of tokens for a deposit

#### **Parameters**

| Name            | Type    | Description                |
| --------------- | ------- | -------------------------- |
| \_depositAmount | uint256 | The amount to be deposited |

#### **Return Values**

| Name             | Type    | Description                                                            |
| ---------------- | ------- | ---------------------------------------------------------------------- |
| sharesToMint\_   | uint256 | Total number of pool LP tokens to be minted (incl. slippage)           |
| slippageReward\_ | uint256 | The reward due to slippage, fixed point number using the pool decimals |

***

### withdraw

```solidity
function withdraw(uint256 _sharesToBurn, uint256 _minimumAmount, uint256 _deadline) external returns (uint256 payoutAmount_, int256 fee_)
```

Withdraws liquidity amount of asset ensuring minimum amount required

#### **Parameters**

| Name            | Type    | Description                                                              |
| --------------- | ------- | ------------------------------------------------------------------------ |
| \_sharesToBurn  | uint256 | The liquidity to be withdrawn, an amount of LP tokens                    |
| \_minimumAmount | uint256 | The minimum amount of returned pool tokens that will be accepted by user |
| \_deadline      | uint256 | Unix timestamp after which the transaction will revert                   |

#### **Return Values**

| Name           | Type    | Description                                                                              |
| -------------- | ------- | ---------------------------------------------------------------------------------------- |
| payoutAmount\_ | uint256 | Amount of pool tokens withdrawn after applying withdrawal fee                            |
| fee\_          | int256  | The penalty due to slippage (a positive fee), fixed point number using the pool decimals |

***

### quoteWithdraw

```solidity
function quoteWithdraw(uint256 _sharesToBurn) external view returns (uint256 payoutAmount_, uint256 slippagePenalty_)
```

Get a quote for the effective amount of tokens for a withdrawal

#### **Parameters**

| Name           | Type    | Description                                 |
| -------------- | ------- | ------------------------------------------- |
| \_sharesToBurn | uint256 | Total number of pool LP tokens to be burned |

#### **Return Values**

| Name              | Type    | Description                                 |
| ----------------- | ------- | ------------------------------------------- |
| payoutAmount\_    | uint256 | The amount to be withdrawn (incl. slippage) |
| slippagePenalty\_ | uint256 | The penalty due to slippage                 |

***

### backstopBurn

```solidity
function backstopBurn(address _owner, uint256 _sharesToBurn) external returns (uint256 amount_)
```

Burns swap pool LP tokens of owner, will get compensated using backstop liquidity (reedem swap pool shares) Can only be invoked by backstop pool, disabled when pool is paused

#### **Parameters**

| Name           | Type    | Description                                       |
| -------------- | ------- | ------------------------------------------------- |
| \_owner        | address | The LP's address whose LP tokens should be burned |
| \_sharesToBurn | uint256 | The number of LP tokens of this pool to burn      |

#### **Return Values**

| Name     | Type    | Description                                                      |
| -------- | ------- | ---------------------------------------------------------------- |
| amount\_ | uint256 | The amount of `asset()` tokens that the burned shares were worth |

***

### getMaxRedeemSwapPoolShares

```solidity
function getMaxRedeemSwapPoolShares() external view returns (uint256 maxShares_)
```

Get the maximum amount of swap pool LP tokens that can be burned (CR <= 100%)

#### **Return Values**

| Name        | Type    | Description                                        |
| ----------- | ------- | -------------------------------------------------- |
| maxShares\_ | uint256 | The maximum amount of LP tokens that can be burned |

***

### backstopDrain

```solidity
function backstopDrain(uint256 _amount, address _recipient) external returns (uint256 swapAmount_)
```

For backstop pool to withdraw liquidity if swap pool's coverage ratio > 100% Can only be invoked by backstop pool

#### **Parameters**

| Name        | Type    | Description                                                 |
| ----------- | ------- | ----------------------------------------------------------- |
| \_amount    | uint256 | The amount of `asset()` tokens to be moved out of swap pool |
| \_recipient | address | Address to send the funds to                                |

#### **Return Values**

| Name         | Type    | Description                                                       |
| ------------ | ------- | ----------------------------------------------------------------- |
| swapAmount\_ | uint256 | The amount of `asset()` tokens that are transfered to \_recipient |

***

### quoteBackstopDrain

```solidity
function quoteBackstopDrain(uint256 _amount) external view returns (uint256 swapAmount_)
```

Get a quote for the effective amount of tokens for a backstop drain

#### **Parameters**

| Name     | Type    | Description                                                 |
| -------- | ------- | ----------------------------------------------------------- |
| \_amount | uint256 | The amount of tokens to be withdrawn for backstop liquidity |

#### **Return Values**

| Name         | Type    | Description                                 |
| ------------ | ------- | ------------------------------------------- |
| swapAmount\_ | uint256 | The amount to be withdrawn (incl. slippage) |

***

### quoteSwapInto

```solidity
function quoteSwapInto(uint256 _amount) public view returns (uint256 effectiveAmount_)
```

Get a quote for the effective amount of tokens for a swap into

#### **Parameters**

| Name     | Type    | Description                                     |
| -------- | ------- | ----------------------------------------------- |
| \_amount | uint256 | The amount of pool tokens to swap into the pool |

#### **Return Values**

| Name              | Type    | Description                                           |
| ----------------- | ------- | ----------------------------------------------------- |
| effectiveAmount\_ | uint256 | Effective amount, incl. slippage (penalty or rewards) |

***

### quoteSwapOut

```solidity
function quoteSwapOut(uint256 _amount) public view returns (uint256 effectiveAmount_, uint256 protocolFeeWithSlippage_, uint256 effectiveLpFee_, uint256 backstopFee_)
```

Get a quote for the effective amount of tokens, incl. slippage and fees

#### **Parameters**

| Name     | Type    | Description                                      |
| -------- | ------- | ------------------------------------------------ |
| \_amount | uint256 | The amount of pool asset to swap out of the pool |

#### **Return Values**

| Name                      | Type    | Description                                                              |
| ------------------------- | ------- | ------------------------------------------------------------------------ |
| effectiveAmount\_         | uint256 | Effective amount, incl. slippage and fees                                |
| protocolFeeWithSlippage\_ | uint256 | The protocol fee that is to be sent to the treasury                      |
| effectiveLpFee\_          | uint256 | The actual LP fee – totalLiabilities should be incremented by this value |
| backstopFee\_             | uint256 | The effective backstop fee                                               |

***

### coverage

```solidity
function coverage() external view returns (uint256 reserves_, uint256 liabilities_)
```

returns pool coverage ratio

#### **Return Values**

| Name          | Type    | Description                                                  |
| ------------- | ------- | ------------------------------------------------------------ |
| reserves\_    | uint256 | Current amount of usable `asset()` tokens (without slippage) |
| liabilities\_ | uint256 | total amount of `asset` deposited by liquidity providers     |

***

### getExcessLiquidity

```solidity
function getExcessLiquidity() external view returns (int256 excessLiquidity_)
```

Computes the excess liquidity that forms that valuation of the backstop pool is defined as b + C - B - L where

* b is reserve
* C is the amount of `asset()` tokens in the pool
* B is reserveWithSlippage
* L is totalLiabilities The excess liquidity is a fixed point number using the decimals of this pool

#### **Return Values**

| Name              | Type   | Description                                              |
| ----------------- | ------ | -------------------------------------------------------- |
| excessLiquidity\_ | int256 | The total excess liquidity of this pool, can be negative |

***

### sharesTargetWorth

```solidity
function sharesTargetWorth(uint256 _sharesToBurn) public view returns (uint256 amount_)
```

Returns the worth of an amount of pool shares (LP tokens) in underlying principle

#### **Parameters**

| Name           | Type    | Description                     |
| -------------- | ------- | ------------------------------- |
| \_sharesToBurn | uint256 | The number of LP tokens to burn |

#### **Return Values**

| Name     | Type    | Description                                              |
| -------- | ------- | -------------------------------------------------------- |
| amount\_ | uint256 | The amount of `asset()` tokens that the shares are worth |

***

### swapFees

```solidity
function swapFees() public view returns (uint256 lpFee_, uint256 backstopFee_, uint256 protocolFee_)
```

Return the configured swap fees for this pool

#### **Return Values**

| Name          | Type    | Description                                                           |
| ------------- | ------- | --------------------------------------------------------------------- |
| lpFee\_       | uint256 | Fee that benefits the pool's LPers, in 0.0001% (e.g. 300 -> 0.0300%)  |
| backstopFee\_ | uint256 | Fee that benefits the backstop pool, in 0.0001% (e.g. 150 -> 0.0150%) |
| protocolFee\_ | uint256 | Fee that benefits the protocol, in 0.0001% (e.g. 50 -> 0.0050%)       |

***

### depositingUnfreezesAt

```solidity
function depositingUnfreezesAt() public view returns (uint256 depositingUnfreezesAt_)
```


---

# 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.nabla.fi/developers/contract-interfaces/swappool.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.
