bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 15쪽 중 8쪽
led. Emits `SetDepositCap`.
***
#### `whitelisted(address _user)`
```solidity
function whitelisted(address _user) external view returns (bool isWhitelisted);
```
Returns `true` if `_user` is whitelisted (fee-exempt).
***
#### `depositCap(address _asset)`
```solidity
function depositCap(address _asset) external view returns (uint256 cap);
```
Returns the deposit cap for `_asset` in asset-native units.
***
### Data Structures
#### `MinterStorage`
Internal ERC-7201 namespaced storage layout for the Minter module.
```solidity
struct MinterStorage {
address oracle;
uint256 redeemFee;
mapping(address => FeeData) fees;
mapping(address => bool) whitelist;
mapping(address => uint256) depositCap;
}
```
| Field | Type | Description |
| ------------ | ----------------------------- | -------------------------------------------------------------- |
| `oracle` | `address` | Address of the price oracle used to value assets and cUSD |
| `redeemFee` | `uint256` | Flat fee applied on redeem, in ray format (`1e27 = 100%`) |
| `fees` | `mapping(address => FeeData)` | Fee schedule per backing asset |
| `whitelist` | `mapping(address => bool)` | Fee-exempt addresses |
| `depositCap` | `mapping(address => uint256)` | Maximum asset deposit per backing asset, in asset-native units |
***
#### `FeeData`
Fee schedule for a single backing asset. All ratio and rate fields are in ray format (`1e27 = 100%`).
```solidity
struct FeeData {
uint256 minMintFee;
uint256 slope0;
uint256 slope1;
uint256 mintKinkRatio;
uint256 burnKinkRatio;
uint256 optimalRatio;
}
```
| Field | Type | Description |
| --------------- | --------- | -------------------------------------------------------------------------------------------------------- |
| `minMintFee` | `uint256` | Floor mint fee, always applied regardless of ratio. Max `0.05e27` (5%). Typical value: `1e24` (0.1%). |
| `slope0` | `uint256` | Rate of fee increase between `optimalRatio` and the kink ratio. |
| `slope1` | `uint256` | Rate of fee increase beyond the kink ratio — steeper than `slope0`. |
| `mintKinkRatio` | `uint256` | Ratio above which `slope1` activates for mints. Must be in `(0, 1e27)`. |
| `burnKinkRatio` | `uint256` | Ratio below which `slope1` activates for burns. Must be in `(0, 1e27)`. |
| `optimalRatio` | `uint256` | Target allocation ratio for the asset in the basket. Minting below this is cheap; burning above is free. |
***
### Events
| Event | Parameters | Emitted when |
| --------------- | -------------------------------- | --------------------------------------- |
| `SetFeeData` | `address asset, FeeData feeData` | Fee schedule updated for an asset |
| `SetRedeemFee` | `uint256 redeemFee` | Flat redeem fee updated |
| `SetWhitelist` | `address user, bool whitelisted` | Whitelist status changed for an address |
| `SetDepositCap` | `address asset, uint256 cap` | Deposit cap updated for an asset |
***
### Errors
| Error | Condition |
| ---------------------- | ------------------------------------------------------------------------- |
| `InvalidMinMintFee` | `minMintFee >= 0.05e27` (5%) |
| `InvalidMintKinkRatio` | `mintKinkRatio == 0` or `>= 1e27` |
| `InvalidBurnKinkRatio` | `burnKinkRatio == 0` or `>= 1e27` |
| `InvalidOptimalRatio` | `optimalRatio == 0`, `>= 1e27`, or equals `mintKinkRatio`/`burnKinkRatio` |
***
## Usage Examples
### 1. Quoting a mint before transacting
```solidity
interface IMinter {
function getMintAmount(address _user, address _asset, uint256 _amountIn)
external
view
returns (uint256 amountOut, uint256 fee);
}
address vault = 0x...; // Cap vault proxy
address usdc = 0x...;
address alice = 0x...;
uint256 amountIn = 1000e6; // 1,000 USDC (6 decimals)
(uint256 cusdOut, uint256 feePaid) = IMinter(vault).getMintAmount(alice, usdc, amountIn);
// cusdOut — cUSD minted after dynamic fee
// feePaid — cUSD equivalent of the fee charged (goes to insurance fund)
```
### 2. Checking whitelist status before routing
```solidity
interface IMinter {
function whitelisted(address _user) external view returns (bool);
function getMintAmount(address _user, address _asset, uint256 _amountIn)
external
view
returns (uint256 amountOut, uint256 fee);
}
function quoteMint(address vault, address user, address asset, uint256 amountIn)
external
view
returns (uint256 amountOut, uint256 fee, bool isFeeExempt)
{
isFeeExempt = IMinter(vault).whitelisted(user);
(amountOut, fee) = IMinter(vault).getMintAmount(user, asset, amountIn);
}
```
### 3. Simulating a redeem across all basket assets
```solidity
interface IMinter {
function getRedeemAmount(address _user, uint256 _amountIn)
external
view
returns (uint256[] memory amountsOut, uint256[] memory redeemFees);
}
interface IVault {
function assets() external view returns (address[] memory);
}
function previewRedeem(address vault, address user, uint256 cusdAmount)
external
view
returns (address[] memory assetAddresses, uint256[] memory amounts, uint256[] memory fees)
{
assetAddresses = IVault(vault).assets();
(amounts, fees) = IMinter(vault).getRedeemAmount(user, cusdAmount);
// amounts[i] and fees[i] correspond to assetAddresses[i]
}
```
# Fractional Reserve
The Fractional Reserve layer sits inside the cUSD vault and puts idle backing assets to work in external ERC4626 yield vaults (e.g. Yearn, Aave, TokenizedStrategy vaults) while keeping a configurable liquid reserve on hand to service borrows and withdrawals without delay. When the vault needs liquidity — for a burn, redeem, or Operator borrow — it automatically divests from the yield vault before transferring funds. Any yield above principal is forwarded to the `interestReceiver` (the FeeAuction).
## Mechanics
### Invest Flow
Idle capital above the configured reserve floor is deposited into the ERC4626 yield vault:
1. **Balance check**: The vault's current `balanceOf(asset)` is compared against `reserve[asset]`.
2. **Invest**: If balance exceeds the reserve, `balance - reserve` is deposited into the ERC4626 vault via `deposit()`. The invested amount is tracked in `loaned[asset]`.
3. **Access-controlled**: `investAll` requires the `checkAccess` modifier — typically called by an admin or keeper after new deposits accumulate.
### Partial Divest Flow
When a withdrawal, redemption, or borrow needs assets that aren't in the reserve:
1. **Balance check**: If `withdrawAmount > balanceOf(asset)`, a divest is triggered.
2. **Divest amount**: The logic withdraws `withdrawAmount + reserve[asset] - balanceOf(asset)` — enough to cover the request *and* refill the buffer reserve.
3. **Share cap**: If the required shares exceed what the vault holds, the full vault balance is redeemed instead.
4. **Interest pass-through**: If `divestAmount > loaned[asset]`, the excess is forwarded to `interestReceiver` and `loaned[asset]` is reduced only by principal.
### Full Divest Flow
Used when migrating to a new yield vault or during emergency divestment:
1. All ERC4626 shares held by the contract are redeemed.
2. If `redeemedAssets > loaned[asset]`: surplus forwarded to `interestReceiver`.
3. If `redeemedAssets < loaned[asset]`: reverts with `FullDivestRequired` — a loss in the strategy, requiring human intervention.
### Interest Realization
Interest accrues passively as the ERC4626 vault appreciates. It can be realized at any time — permissionlessly via `realizeInterest`:
1. `claimableInterest` is computed: `vaultShares - sharesRequiredToWithdrawLoaned`.
2. The excess shares are redeemed and sent directly to `interestReceiver`.
The Harvester contract automates this flow: it calls `report()` on each strategy in the vault's queue, processes each report via `process_report`, then calls `realizeInterest`.
### Reserve Buffer
`reserve[asset]` is a minimum floor of liquid assets the vault always keeps on hand. Setting it higher improves withdrawal UX (fewer divestments) at the cost of yield. Setting it to 0 means all idle capital is deployed.
### LimitModule
The `LimitModule` is a companion contract deployed alongside each ERC4626 vault. It enforces that only the cUSD vault can deposit or withdraw from the fractional reserve vault, preventing external actors from interfering with the strategy.
### TokenHolder
`TokenHolder` is a minimal ERC4626-compatible strategy (built on Yearn's `BaseStrategy`) that simply holds tokens without deploying them. It is used when a strategy slot is needed but no external yield is desired — for example, holding a stablecoin in reserve during an audit or migration period.
***
## Architecture
### Core Functions
#### `investAll(address _asset)`
```solidity
function investAll(address _asset) external;
```
Access-controlled. Deposits all idle balance above `reserve[asset]` into the configured ERC4626 vault for `_asset`. No-ops if no vault is set or if balance ≤ reserve.
***
#### `divestAll(address _asset)`
```solidity
function divestAll(address _asset) external;
```
Access-controlled. Fully redeems all shares from the ERC4626 vault for `_asset`. Surplus above `loaned[asset]` is forwarded to `interestReceiver`. Reverts with `FullDivestRequired` if a loss has occurred.
***
#### `setFractionalReserveVault(address _asset, address _vault)`
```solidity
function setFractionalReserveVault(address _asset, address _vault) external;
```
Access-controlled. Migrates `_asset` to a new ERC4626 vault. The existing vault is fully divested first. Reverts if `_vault` is already registered for another asset.
***
#### `setReserve(address _asset, uint256 _reserve)`
```solidity
function setReserve(address _asset, uint256 _reserve) external;
```
Access-controlled. Sets the minimum liquid buffer for `_asset` in asset-native units. Funds above this threshold are eligible for investment.
***
#### `realizeInterest(address _asset)`
```solidity
function realizeInterest(address _asset) external;
```
Permissionless. Withdraws accrued yield (ERC4626 appreciation above `loaned[asset]`) and sends it to `interestReceiver`. No-ops if no yield has accrued or no vault is set.
***
#### `claimableInterest(address _asset)`
```solidity
function claimableInterest(address _asset) external view returns (uint256 interest);
```
Returns the amount of `_asset` that can currently be claimed as yield. Computed as the asset value of the shares held in excess of those needed to recover `loaned[asset]`.
***
#### View Functions
| Function | Returns | Description |
| ---------------------------------------- | ----------- | ------------------------------------------------------------- |
| `fractionalReserveVault(address _asset)` | `address` | ERC4626 vault address configured for `_asset` |
| `fractionalReserveVaults()` | `address[]` | All registered ERC4626 vault addresses |
| `reserve(address _asset)` | `uint256` | Configured liquid reserve floor for `_asset` |
| `loaned(address _asset)` | `uint256` | Principal currently deposited in the yield vault for `_asset` |
| `interestReceiver()` | `address` | Address that receives realized yield (FeeAuction) |
***
### Harvester
The `Harvester` is a stateless keeper contract. A keeper (e.g. Gelato) calls `harvest` periodically to report strategy performance and realize interest.
#### `harvest(address _cusd, address _asset)`
```solidity
function harvest(address _cusd, address _asset)
external
returns (uint256 profit, uint256 loss, uint256 interest);
```
| Parameter | Type | Description |
| --------- | --------- | -------------------------------- |
| `_cusd` | `address` | The cUSD vault proxy address |
| `_asset` | `address` | The backing asset to harvest for |
**Returns**:
* `profit` — cumulative profit across all strategies in the vault queue
* `loss` — cumulative loss across all strategies
* `interest` — amount of interest realized and sent to the fee auction
**Process flow**:
1. Fetches the ERC4626 vault's `default_queue` (ordered list of strategies).
2. For each strategy: calls `strategy.report()` then `vault.process_report(strategy)`.
3. Calls `realizeInterest(_asset)` if any claimable interest exists.
***
### LimitModule
A deployment-time immutable contract that gates deposits and withdrawals in the ERC4626 vault to the cUSD vault only.
#### `available_deposit_limit(address receiver)`
```solidity
function available_deposit_limit(address receiver) external view returns (uint256 limit);
```
Returns `type(uint256).max` if `receiver == vault`, otherwise 0.
#### `available_withdraw_limit(address owner, uint256, address[] calldata)`
```solidity
function available_withdraw_limit(address owner, uint256, address[] calldata)
external view returns (uint256 limit);
```
Returns `type(uint256).max` if `owner == vault`, otherwise 0.
***
### TokenHolder
A minimal Yearn `BaseStrategy` that holds tokens in place without deploying them to an external yield source. `_deployFunds` and `_freeFunds` are intentionally empty. Deposit and withdrawal are restricted to `vault`.
***
### Data Structures
#### `FractionalReserveStorage`
```solidity
struct FractionalReserveStorage {
address interestReceiver;
mapping(address => uint256) loaned;
mapping(address => uint256) reserve;
mapping(address => address) vault;
EnumerableSet.AddressSet vaults;
}
```
| Field | Type | Description |
| ------------------ | ----------------------------- | ------------------------------------------------------------------- |
| `interestReceiver` | `address` | Receives yield forwarded from the fractional reserve (FeeAuction) |
| `loaned` | `mapping(address => uint256)` | Principal deposited into each asset's yield vault |
| `reserve` | `mapping(address => uint256)` | Minimum liquid buffer to maintain per asset (in asset units) |
| `vault` | `mapping(address => address)` | ERC4626 yield vault address per backing asset |
| `vaults` | `EnumerableSet.AddressSet` | Set of all registered yield vault addresses (for uniqueness checks) |
***
### Events
| Event | Parameters | Emitted when |
| ----------------------------------- | ---------------- | ---------------------------------------------- |
| `FractionalReserveInvested` | `asset, amount` | Assets deposited into the yield vault |
| `FractionalReserveDivested` | `asset, amount` | Assets withdrawn from the yield vault |
| `FractionalReserveVaultUpdated` | `asset, vault` | Yield vault configured or changed for an asset |
| `FractionalReserveReserveUpdated` | `asset, reserve` | Reserve buffer updated for an asset |
| `FractionalReserveInterestRealized` | `asset, amount` | Yield forwarded to `interestReceiver` |
***
### Errors
| Error | Condition |
| ---------------------------------- | ------------------------------------------------------------------ |
| `FullDivestRequired` | Full divest resulted in fewer assets than `loaned` — strategy loss |
| `FractionalReserveVaultAlreadySet` | `_vault` is already registered for a different asset |
***
## Usage Examples
### 1. Keeper harvest job
```solidity
interface IHarvester {
function harvest(address _cusd, address _asset)
external
returns (uint256 profit, uint256 loss, uint256 interest);
}
address harvester = 0x...;
address cusd = 0x...; // cUSD vault proxy
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
// Called by a Gelato task or cron keeper
(uint256 profit, uint256 loss, uint256 interest) = IHarvester(harvester).harvest(cusd, usdc);
// interest is now in the FeeAuction, available for stcUSD holders to bid on
```
### 2. Checking available liquidity before a large redemption
```solidity
interface IFractionalReserve {
function loaned(address _asset) external view returns (uint256);
function claimableInterest(address _asset) external view returns (uint256);
}
interface IVault {
function availableBalance(address _asset) external view returns (uint256);
}
function checkLiquidity(address vault, address asset)
external
view
returns (uint256 liquid, uint256 investedPrincipal, uint256 pendingYield)
{
liquid = IVault(vault).availableBalance(asset); // on-hand balance
investedPrincipal = IFractionalReserve(vault).loaned(asset); // in yield vault
pendingYield = IFractionalReserve(vault).claimableInterest(asset);
}
```
### 3. Admin: onboarding a new yield vault for USDC
```solidity
interface IFractionalReserve {
function setFractionalReserveVault(address _asset, address _vault) external;
function setReserve(address _asset, uint256 _reserve) external;
function investAll(address _asset) external;
}
address vault = 0x...; // cUSD vault proxy
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address yvUSDC = 0x...; // New ERC4626 vault
// 1. Set the new yield vault (automatically divests old one if set)
IFractionalReserve(vault).setFractionalReserveVault(usdc, yvUSDC);
// 2. Set a 500,000 USDC liquid reserve floor
IFractionalReserve(vault).setReserve(usdc, 500_000e6);
// 3. Deploy idle balance into the new vault
IFractionalReserve(vault).investAll(usdc);
```
# Lender
The Lender is the lending pool that allows whitelisted Operators to borrow backing assets from the cUSD vault against delegated collateral. It tracks debt per Operator per asset, accrues two separate interest streams (vault interest paid to stcUSD holders, restaker interest paid to Delegators), and manages a liquidation system with a time-windowed grace period and linearly increasing bonus. All health factors, LTV ratios, and rates are in ray format where `1e27 = 100%`.
## Mechanics
### Borrow Flow
1. **Realize restaker interest**: Any accrued restaker interest for the Operator is realized first, updating their debt balance before new principal is added.
2. **Max borrow calculation** (if `maxBorrow = true`): `ViewLogic.maxBorrowable` computes remaining capacity based on the Operator's delegation coverage and current LTV.
3. **Validation**: `ValidationLogic.validateBorrow` checks that the Operator is whitelisted, not paused, the asset is not paused, minimum borrow is met, and vault liquidity is sufficient.
4. **State updates**: `IDelegation.setLastBorrow` is called; the Operator is marked as borrowing the reserve.
5. **Asset transfer**: The vault borrows the asset and sends it to `_receiver`; a debt token is minted to the Operator; `reserve.debt` is incremented.
### Repay Flow
1. **Realize restaker interest**: Accrued restaker interest is settled first.
2. **Amount cap**: Repayment is silently capped at the Operator's total debt. If the remaining debt after repayment would fall below `minBorrow`, the repayment is reduced to leave exactly `minBorrow` outstanding.
3. **Repayment allocation** (in priority order):
* **Vault interest** (`interestRepaid`): Any excess above `reserve.debt + unrealizedInterest` goes to `interestReceiver`.
* **Restaker interest** (`restakerRepaid`): Settled unrealized restaker interest is sent to the Delegation contract and distributed to Delegators.
* **Vault principal** (`vaultRepaid`): Repays `reserve.debt` and returns assets to the vault.
4. **Debt token burn**: The debt token is burned for the full `repaid` amount.
### Interest Accrual
Cap uses two separate interest streams, both accrued continuously but realized discretely:
**Vault interest** — paid to stcUSD holders via the FeeAuction:
* Accrual is tracked by the RateOracle's utilization index (time-weighted borrow rate).
* Realized by calling `realizeInterest(_asset)` — permissionless.
* The Lender borrows the interest amount from the vault and sends it directly to `interestReceiver`.
**Restaker interest** — paid to Delegators:
* Accrues per-Operator per-asset: `debtBalance × restakerRate × elapsedTime / SECONDS_IN_YEAR`.
* `restakerRate` is set per-Operator by admin via the oracle.
* Realized on every borrow and repay, or permissionlessly via `realizeRestakerInterest`.
* If vault liquidity is insufficient, the shortfall becomes **unrealized interest** — added to the Operator's debt balance and settled during future repayments.
### Liquidation Flow
Liquidation is a two-step process:
**Step 1 — Open liquidation window:*프로젝트로 돌아가기