# Withdraw

With this function, the user can redeem its funds plus the yield that has been accumulated. The user will need to call the function, send the LP tokens it has and receive the funds it is entitled to. Because most funds are locked up in different protocols on different chains and layer 2s a full withdrawal is not always possible immediately. There is a parameter `liquidityPerc` controlled by the DAO which reserves a percentage of all underlying funds on a particular chain/ layer 2 (apart from earlier deposits during the same period) to make immediate withdrawals possible. There are 2 scenarios:

1. The full amount the user wants to withdraw is available in the vault due to earlier deposits or the `liquidityPerc`.
2. The full amount is not available on the chain/ layer 2 the user wants to perform the withdraw.&#x20;

In scenario 1 the user can withdraw its funds by calling the following function in one of our deployed vaults:

`function withdraw(uint256 _amount) external nonReentrant returns(uint256 value)`

Where `_amount` is the amount of LP tokens in the correct scale (always the same scale as the underlying vault currency scale, 10^6 in the case of the USDC vault).&#x20;

In the 2nd scenario, the user can make a `withdrawalRequest`. In this case the user sends the LP tokens and gets an allowance which can be withdrawn after the next rebalance. To do this the user has to call the function in one of our deployed vaults:

`function withdrawalRequest(uint256 _amount) external nonReentrant returns(uint256 value)`

Where `_amount` is the amount of LP tokens in the correct scale (always the same scale as the underlying vault currency scale, 10^6 in the case of the USDC vault). After rebalancing the user can call the following function to withdraw its funds:

`function withdrawAllowance() external nonReentrant returns(uint256 value)`

The value the user receives depends on the `exchangeRate` and is calculated accordingly:

`value = _amount * exchangeRate / LPScale;`

Where the `exchangeRate` is expressed in underlying/ LPtoken in the scale of the underlying vault currency and LPScale is the amount of decimals of the LP token in the same scale (10^6).

The `exchangeRate` is calculated based on the exposures on all the underlyings on all the different chains and layer 2s. Therefore, it's not feasible to calculate the actual `exchangeRate` every time a withdrawal is made. Instead, the `exchangeRate` is calculated and stored during rebalancing and the last known `exchangeRate` is used during withdrawal.


---

# 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://derby-finance.gitbook.io/derby-finance-docs/products/vaults/user-interactions/withdraw.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.
