# Redemption Pipe

The RedemptionPipe handle the whole redemption process and implement ERC4626 compatibility., It supports two redemption types with different speed/fee tradeoffs. There is only one RedemptionPipe per xToken, meaning that only a single asset can be redeemed.

### **Redemption Types**

| Type         | Speed     | Fee  | Settlement         | Use Case                   |
| ------------ | --------- | ---- | ------------------ | -------------------------- |
| **Instant**  | Immediate | 0.3% | On-chain liquidity | Time-sensitive redemptions |
| **Standard** | 1-3 days  | 0    | Request/fulfill    | Large redemptions, no rush |

**Instant Redemption**

**`redeem(uint256 shares, address receiver, address controller)`**

Instantly redeem shares for assets using liquidity provider.

```solidity
/**
 * @param shares Amount of shares to redeem (18 decimals)
 * @param receiver Address to receive assets
 * @param controller Address that owns the shares
 * @return assets Amount of assets received (underlying decimals, after fees)
 */
function redeem(
    uint256 shares,
    address receiver,
    address controller
) external returns (uint256 assets);
```

**`withdraw(uint256 assets, address receiver, address controller)`**

Instantly withdraw specific asset amount by burning shares.

```solidity
/**
 * @param assets Amount of assets to withdraw (underlying decimals)
 * @param receiver Address to receive assets
 * @param controller Address that owns shares
 * @return shares Amount of shares burned (18 decimals)
 */
function withdraw(
    uint256 assets,
    address receiver,
    address controller
) external returns (uint256 shares);
```

**Standard Redemption**

Two-step process: request, then fulfill (no fee).

**`requestRedeem(uint256 shares, address controller, address owner)`**

Submit a standard redemption request.

```solidity
/**
 * @param shares Amount of shares to redeem (18 decimals)
 * @param controller Address that will control the redemption
 * @param owner Address that owns shares
 * @return requestId Always returns 0
 */
function requestRedeem(
    uint256 shares,
    address controller,
    address owner
) external returns (uint256 requestId);
```

**Check Pending Request**

```solidity
/**
 * @param owner Owner address
 * @return shares Amount of pending shares
 */
function pendingRedeemRequest(address owner)
    external
    view
    returns (uint256 shares);
```

**Preview Functions**

```solidity
// Convert shares to underlying assets
function convertToAssets(uint256 shares) external view returns (uint256);

// Convert assets to shares
function convertToShares(uint256 assets) external view returns (uint256);

// Preview withdraw - calculates required shares for net asset amount
function previewWithdraw(uint256 assets) public view returns (uint256)

// Preview redeem - converts shares to underlying assets after fees
function previewRedeem(uint256 shares) public view returns (uint256)
```

**Fee Information**

```solidity
// Get fee basis points (10000 = 100%)
function instantRedeemFeeBps() external view returns (uint256);
```
