# VaultExecutor

Executes all pToken mint/redeem operations on behalf of Dual Investment flows, tracks protocol‑supplied amounts, and orchestrates swaps and settlement payouts.

## Responsibilities

* Redeem user pTokens, supply underlying back into markets under the vault, and mint cTokens to recipients.
* Withdraw underlying for settlement (clamped to available balance).
* Swap between underlyings via `PancakeSwapAdapter`, then mint target cTokens.
* Track per‑market protocol balances and per‑user redeemed underlyings.

## Key Functions

* `redeemAndSupplyToProtocol(user, cToken, cTokenAmount)` \[onlyAuthorized]
  * Redeems to underlying (delta), tracks `userUnderlyingBalances`, then supplies to market; updates `protocolSuppliedAmounts`.
* `withdrawUnderlyingFromProtocol(cToken, underlyingAmount)` \[onlyAuthorized]
  * Redeems required cTokens (based on exchangeRate) up to available balance.
* `swapUnderlying(tokenIn, tokenOut, amountIn, minOut)` \[onlyAuthorized]
* `swapAndMintTo(cTokenIn, cTokenOut, recipient, underlyingInAmount, minUnderlyingOut)` \[onlyAuthorized]
  * Swaps underlyings and mints cTokenOut to recipient; pays out raw underlying if amount too small to mint ≥1 cToken.
* `mintCTokensTo(cToken, recipient, underlyingAmount)` \[onlyAuthorized]
* `pullUnderlyingAndMintTo(cToken, fromUser, recipient, underlyingAmount)` \[onlyAuthorized]
* Admin: `setAuthorizedManager`, `setProtocolAccount`, `setSwapAdapter`, `emergencyWithdraw`.

## Notes

* Uses `forceApprove` for safe allowance setting prior to mint.
* Swap path tries V3 first, falls back to V2.


---

# 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://peridot-finance.gitbook.io/peridot-protocol/technical-architecture/evm/dual-investment/vaultexecutor.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.
