> For the complete documentation index, see [llms.txt](https://docs.nabla.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nabla.fi/developers/contract-interfaces/nablabackstoppool.md).

# NablaBackstopPool

The backstop pool takes most of the risk of a set of swap pools backed by it. Whenever a swap pool is low on reserves and a LPer wants to withdraw some liquidity, they can conduct an insurance withdrawal (burn swap pool shares, reimbursed in backstop liquidity) to avoid paying a high slippage. The backstop pool owns all excess liquidity in its swap pools, but is also liable for potential liquidity gaps. In return, the backstop pool receives a cut of the swap fees.

***

### Withdrawal

```solidity
struct Withdrawal {
  uint128 startClaimPeriod;
  uint128 endClaimPeriod;
  uint256 sharesToBurn;
}
```

***

### SwapPoolConfig

```solidity
struct SwapPoolConfig {
  uint128 insuranceFeeBps;
  bool isCovered;
}
```

***

### router

```solidity
contract IRouter router
```

router instance for this backstop pool

***

### getBackedPool

```solidity
function getBackedPool(uint256 _index) external view returns (address swapPool_)
```

enumerate swap pools backed by this backstop pool

#### **Parameters**

| Name    | Type    | Description                                        |
| ------- | ------- | -------------------------------------------------- |
| \_index | uint256 | index of the swap pool in `coveredSwapPools` array |

#### **Return Values**

| Name       | Type    | Description       |
| ---------- | ------- | ----------------- |
| swapPool\_ | address | swap pool address |

***

### getBackedPoolCount

```solidity
function getBackedPoolCount() external view returns (uint256 count_)
```

get swap pool count backed by this backstop pool

#### **Return Values**

| Name    | Type    | Description          |
| ------- | ------- | -------------------- |
| count\_ | uint256 | number of swap pools |

***

### getInsuranceFee

```solidity
function getInsuranceFee(address _swapPool) external view returns (uint256 feeBps_)
```

get insurance withdrawal fee for a given swap pool

#### **Parameters**

| Name       | Type    | Description              |
| ---------- | ------- | ------------------------ |
| \_swapPool | address | address of the swap pool |

#### **Return Values**

| Name     | Type    | Description                                      |
| -------- | ------- | ------------------------------------------------ |
| feeBps\_ | uint256 | insurance witdrawal fee, in basis points (0.01%) |

***

### deposit

```solidity
function deposit(uint256 _depositAmount, uint256 _minLPAmountOut, uint256 _deadline, bytes[] _priceUpdateData) external payable returns (uint256 sharesToMint_)
```

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

*By calling this function the price feeds get updated (IPriceOracleAdapter.updatePriceFeeds)*

#### **Parameters**

| Name              | Type     | Description                                                                                                       |
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------- |
| \_depositAmount   | uint256  | The amount of backstop pool tokens to be deposited                                                                |
| \_minLPAmountOut  | uint256  | The minimum amount of backstop pool LP tokens to mint                                                             |
| \_deadline        | uint256  | Unix timestamp after which the transaction will revert                                                            |
| \_priceUpdateData | bytes\[] | Array of price update data of all assets involved (backstop pool and all swapPools as within coveredSwapPools\[]) |

#### **Return Values**

| Name           | Type    | Description                                    |
| -------------- | ------- | ---------------------------------------------- |
| sharesToMint\_ | uint256 | Total number of backstop pool LP tokens minted |

***

### initiateWithdraw

```solidity
function initiateWithdraw(uint256 _sharesToBurn) external returns (bool success_)
```

Starts the withdrawal process or overrides an existing one The user must finalize the withdrawal after the delay period has passed but before the claim period ends through `finalizeWithdrawBackstopLiquidity()` or `finalizeWithdrawExcessSwapLiquidity()`

#### **Parameters**

| Name           | Type    | Description                                                         |
| -------------- | ------- | ------------------------------------------------------------------- |
| \_sharesToBurn | uint256 | The liquidity to be withdrawn, an amount of backstop pool LP tokens |

#### **Return Values**

| Name      | Type | Description             |
| --------- | ---- | ----------------------- |
| success\_ | bool | Confirmation of success |

***

### cancelWithdraw

```solidity
function cancelWithdraw() external returns (bool success_)
```

Cancels an initiated withdrawal

#### **Return Values**

| Name      | Type | Description             |
| --------- | ---- | ----------------------- |
| success\_ | bool | Confirmation of success |

***

### finalizeWithdrawBackstopLiquidity

```solidity
function finalizeWithdrawBackstopLiquidity(uint256 _minimumAmount, uint256 _deadline, bytes[] _priceUpdateData) external payable returns (uint256 payoutAmount_)
```

Finalizes the withdrawal process after the delay period has passed but before the claim period ends Withdraws backstop liquidity amount of asset ensuring minimum amount required

*By calling this function the price feeds get updated (IPriceOracleAdapter.updatePriceFeeds)*

#### **Parameters**

| Name              | Type     | Description                                                                                                       |
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------- |
| \_minimumAmount   | uint256  | Reject withdrawal if resulting amount is below                                                                    |
| \_deadline        | uint256  | Unix timestamp after which the transaction will revert                                                            |
| \_priceUpdateData | bytes\[] | Array of price update data of all assets involved (backstop pool and all swapPools as within coveredSwapPools\[]) |

#### **Return Values**

| Name           | Type    | Description                          |
| -------------- | ------- | ------------------------------------ |
| payoutAmount\_ | uint256 | Amount of `asset()` tokens withdrawn |

***

### redeemSwapPoolShares

```solidity
function redeemSwapPoolShares(address _swapPool, uint256 _shares, uint256 _minAmountOut, uint256 _deadline, bytes[] _priceUpdateData) external payable returns (uint256 amountOut_)
```

Withdraw from a swap pool using backstop liquidity without slippage (backstop burn) only possible if swap pool's coverage ratio < 100%

*By calling this function the price feeds get updated (IPriceOracleAdapter.updatePriceFeeds)*

#### **Parameters**

| Name              | Type     | Description                                                                         |
| ----------------- | -------- | ----------------------------------------------------------------------------------- |
| \_swapPool        | address  | swap pool address                                                                   |
| \_shares          | uint256  | number of swap pool LP tokens to redeem, uses decimals of swap pool                 |
| \_minAmountOut    | uint256  | minimum amount of backstop liquidity to receive, uses decimals of backstop pool     |
| \_deadline        | uint256  | Unix timestamp after which the transaction will revert                              |
| \_priceUpdateData | bytes\[] | Array of price update data of all assets involved (backstop pool and this swapPool) |

#### **Return Values**

| Name        | Type    | Description                                                           |
| ----------- | ------- | --------------------------------------------------------------------- |
| amountOut\_ | uint256 | amount of backstop liquidity paid-out, uses decimals of backstop pool |

***

### finalizeWithdrawExcessSwapLiquidity

```solidity
function finalizeWithdrawExcessSwapLiquidity(address _swapPool, uint256 _minAmount, uint256 _deadline, bytes[] _priceUpdateData) external payable returns (uint256 swapAmount_)
```

Finalizes the withdrawal process after the delay period has passed but before the claim period ends Withdraw from backstop pool, but receive excess liquidity of a swap pool instead of backstop liquidity

*By calling this function the price feeds get updated (IPriceOracleAdapter.updatePriceFeeds)*

#### **Parameters**

| Name              | Type     | Description                                                                                                       |
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------- |
| \_swapPool        | address  | swap pool address, must have a coverage ratio > 100%                                                              |
| \_minAmount       | uint256  | minimum amount of swap pool liquidity to receive, uses decimals of swap pool                                      |
| \_deadline        | uint256  | Unix timestamp after which the transaction will revert                                                            |
| \_priceUpdateData | bytes\[] | Array of price update data of all assets involved (backstop pool and all swapPools as within coveredSwapPools\[]) |

#### **Return Values**

| Name         | Type    | Description                                                        |
| ------------ | ------- | ------------------------------------------------------------------ |
| swapAmount\_ | uint256 | amount of swap pool liquidity paid-out, uses decimals of swap pool |

***

### redeemCrossSwapPoolShares

```solidity
function redeemCrossSwapPoolShares(address _swapPool, address _targetSwapPool, uint256 _shares, uint256 _minAmount, uint256 _deadline, bytes[] _priceUpdateData) external payable returns (uint256 finalAmount_)
```

***

### getTotalPoolWorth

```solidity
function getTotalPoolWorth(uint256[] _allTokenPrices) public view returns (int256 value_, int256 totalExcessLiquidity_)
```

return worth of the whole backstop pool in `asset()`, incl. all swap pools' excess liquidity and the backstop pool's liabilities this is a fixed point number, using the backstop pool decimals

*ignoring if pools are paused or not, since liabilities still apply and we don't want the backstop pool worth to jump*

#### **Parameters**

| Name             | Type       | Description                                                                                                                                                         |
| ---------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_allTokenPrices | uint256\[] | array of all token prices (\[0] backstop pool token, \[1] swap pool token\_i, \[2] swap pool token\_i+1, ... \[n] swap pool token\_n) as within coveredSwapPools\[] |

#### **Return Values**

| Name                   | Type   | Description                                            |
| ---------------------- | ------ | ------------------------------------------------------ |
| value\_                | int256 | total value of all backstop pool shares, in `asset()`  |
| totalExcessLiquidity\_ | int256 | total excess liquidity of all swap pools, in `asset()` |

***

### sharesTargetWorth

```solidity
function sharesTargetWorth(uint256 _sharesToBurn, uint256[] _allTokenPrices) 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                                                                                                                                     |
| \_allTokenPrices | uint256\[] | array of all token prices (\[0] backstop pool token, \[1] swap pool token\_i, \[2] swap pool token\_i+1, ... \[n] swap pool token\_n) as within coveredSwapPools\[] |

#### **Return Values**

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

***

### getPoolState

```solidity
function getPoolState(uint256[] _allTokenPrices) external view returns (uint256 reserves_, int256 totalPoolWorth_, uint256 totalSupply_)
```

returns the backstop pool state

#### **Parameters**

| Name             | Type       | Description                                                                                                                                                         |
| ---------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_allTokenPrices | uint256\[] | array of all token prices (\[0] backstop pool token, \[1] swap pool token\_i, \[2] swap pool token\_i+1, ... \[n] swap pool token\_n) as within coveredSwapPools\[] |

#### **Return Values**

| Name             | Type    | Description                            |
| ---------------- | ------- | -------------------------------------- |
| reserves\_       | uint256 | current amount of `asset` in this pool |
| totalPoolWorth\_ | int256  | total worth of the pool in `asset()`   |
| totalSupply\_    | uint256 | total amount of LP tokens minted       |

***

### getWithdrawal

```solidity
function getWithdrawal(address _sender) external view returns (uint128 startClaimPeriod_, uint128 endClaimPeriod_, uint256 sharesToBurn_)
```

Get information about a user's initiated withdrawal

#### **Parameters**

| Name     | Type    | Description                           |
| -------- | ------- | ------------------------------------- |
| \_sender | address | The user who initiated the withdrawal |

#### **Return Values**

| Name               | Type    | Description                                                               |
| ------------------ | ------- | ------------------------------------------------------------------------- |
| startClaimPeriod\_ | uint128 | The time when the withdrawal can be finalized, a unix timestamp           |
| endClaimPeriod\_   | uint128 | The time when the withdrawal can no longer be finalized, a unix timestamp |
| sharesToBurn\_     | uint256 | The amount of LP tokens to burn                                           |

***

### getWithdrawalDelayAndClaimPeriod

```solidity
function getWithdrawalDelayAndClaimPeriod() external view returns (uint128 delay_, uint128 claimPeriod_)
```

Get the delay and claim period for withdrawals

#### **Return Values**

| Name          | Type    | Description                                                              |
| ------------- | ------- | ------------------------------------------------------------------------ |
| delay\_       | uint128 | The delay before initiated withdrawals can be finalized, in seconds      |
| claimPeriod\_ | uint128 | The period within which initiated withdrawals can be claimed, in seconds |
