> For the complete documentation index, see [llms.txt](https://alchemix-finance.gitbook.io/v2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alchemix-finance.gitbook.io/v2/docs/alchemistv2.md).

# Functions

## Structs

### Account

| Field                | Type                                            |
| -------------------- | ----------------------------------------------- |
| `debt`               | int256                                          |
| `balances`           | mapping(address => uint256)                     |
| `lastAccruedWeights` | mapping(address => uint256)                     |
| `depositedTokens`    | struct Sets.AddressSet                          |
| `mintAllowances`     | mapping(address => uint256)                     |
| `withdrawAllowances` | mapping(address => mapping(address => uint256)) |

## Functions

### getYieldTokensPerShare

```solidity
    function getYieldTokensPerShare(address yieldToken) external returns (uint256);
```

Gets the conversion rate of yield tokens per share.

#### Parameters:

| Name         | Type    | Description                                                    |
| ------------ | ------- | -------------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to get the conversion rate for. |

#### Return Values:

| Name   | Type    | Description                         |
| ------ | ------- | ----------------------------------- |
| `rate` | uint256 | The rate of yield tokens per share. |

### getUnderlyingTokensPerShare

```solidity
    function getUnderlyingTokensPerShare(address yieldToken) external returns (uint256);
```

Gets the conversion rate of underlying tokens per share.

#### Parameters:

| Name         | Type    | Description                                                    |
| ------------ | ------- | -------------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to get the conversion rate for. |

#### Return Values:

| Name   | Type    | Description                              |
| ------ | ------- | ---------------------------------------- |
| `rate` | uint256 | The rate of underlying tokens per share. |

### getSupportedUnderlyingTokens

```solidity
    function getSupportedUnderlyingTokens() external returns (address[]);
```

Gets the supported underlying tokens.

The order of the entries returned by this function is not guaranteed to be consistent between calls.

### getSupportedYieldTokens

```solidity
    function getSupportedYieldTokens() external returns (address[]);
```

Gets the supported yield tokens.

The order of the entries returned by this function is not guaranteed to be consistent between calls.

### isSupportedUnderlyingToken

```solidity
    function isSupportedUnderlyingToken(address underlyingToken) external returns (bool);
```

Gets if an underlying token is supported.

#### Parameters:

| Name              | Type    | Description                                   |
| ----------------- | ------- | --------------------------------------------- |
| `underlyingToken` | address | The address of the underlying token to check. |

#### Return Values:

| Name          | Type | Description                           |
| ------------- | ---- | ------------------------------------- |
| `isSupported` | bool | If the underlying token is supported. |

### isSupportedYieldToken

```solidity
    function isSupportedYieldToken(address yieldToken) external returns (bool);
```

Gets if a yield token is supported.

#### Parameters:

| Name         | Type    | Description                              |
| ------------ | ------- | ---------------------------------------- |
| `yieldToken` | address | The address of the yield token to check. |

#### Return Values:

| Name          | Type | Description                      |
| ------------- | ---- | -------------------------------- |
| `isSupported` | bool | If the yield token is supported. |

### accounts

```solidity
    function accounts(address owner) external returns (int256 debt, address[] depositedTokens);
```

Gets information about the account owned by `owner`.

#### Parameters:

| Name    | Type    | Description                        |
| ------- | ------- | ---------------------------------- |
| `owner` | address | The address that owns the account. |

#### Return Values:

| Name              | Type       | Description                                                  |
| ----------------- | ---------- | ------------------------------------------------------------ |
| `debt`            | int256     | The unrealized amount of debt that the account had incurred. |
| `depositedTokens` | address\[] | The yield tokens that the owner has deposited.               |

### positions

```solidity
    function positions(
        address owner,
        address yieldToken
    ) external returns (uint256 shares, uint256 lastAccruedWeight);
```

Gets information about a yield token position for the account owned by `owner`.

#### Parameters:

| Name         | Type    | Description                                            |
| ------------ | ------- | ------------------------------------------------------ |
| `owner`      | address | The address that owns the account.                     |
| `yieldToken` | address | The address of the yield token to get the position of. |

#### Return Values:

| Name                | Type    | Description                                                   |
| ------------------- | ------- | ------------------------------------------------------------- |
| `shares`            | uint256 | The amount of shares of that `owner` owns of the yield token. |
| `lastAccruedWeight` | uint256 | The last recorded accrued weight of the yield token.          |

### mintAllowance

```solidity
    function mintAllowance(
        address owner,
        address spender
    ) external returns (uint256);
```

Gets the amount of debt tokens `spender` is allowed to mint on behalf of `owner`.

#### Parameters:

| Name      | Type    | Description                                                |
| --------- | ------- | ---------------------------------------------------------- |
| `owner`   | address | The owner of the account.                                  |
| `spender` | address | The address which is allowed to mint on behalf of `owner`. |

#### Return Values:

| Name        | Type    | Description                                                             |
| ----------- | ------- | ----------------------------------------------------------------------- |
| `allowance` | uint256 | The amount of debt tokens that `spender` can mint on behalf of `owner`. |

### withdrawAllowance

```solidity
    function withdrawAllowance(
        address owner,
        address spender,
        address yieldToken
    ) external returns (uint256);
```

Gets the amount of shares of `yieldToken` that `spender` is allowed to withdraw on behalf of `owner`.

#### Parameters:

| Name         | Type    | Description                                                    |
| ------------ | ------- | -------------------------------------------------------------- |
| `owner`      | address | The owner of the account.                                      |
| `spender`    | address | The address which is allowed to withdraw on behalf of `owner`. |
| `yieldToken` | address | The address of the yield token.                                |

#### Return Values:

| Name        | Type    | Description                                                            |
| ----------- | ------- | ---------------------------------------------------------------------- |
| `allowance` | uint256 | The amount of shares that `spender` can withdraw on behalf of `owner`. |

### getUnderlyingTokenParameters

```solidity
    function getUnderlyingTokenParameters(address underlyingToken) external returns (struct IAlchemistV2State.UnderlyingTokenParams);
```

Gets the parameters of an underlying token.

#### Parameters:

| Name              | Type    | Description                          |
| ----------------- | ------- | ------------------------------------ |
| `underlyingToken` | address | The address of the underlying token. |

#### Return Values:

| Name     | Type                                           | Description                      |
| -------- | ---------------------------------------------- | -------------------------------- |
| `params` | struct IAlchemistV2State.UnderlyingTokenParams | The underlying token parameters. |

### getYieldTokenParameters

```solidity
    function getYieldTokenParameters(address yieldToken) external returns (struct IAlchemistV2State.YieldTokenParams);
```

Get the parameters and state of a yield-token.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |

#### Return Values:

| Name     | Type                                      | Description                 |
| -------- | ----------------------------------------- | --------------------------- |
| `params` | struct IAlchemistV2State.YieldTokenParams | The yield token parameters. |

### getMintLimitInfo

```solidity
    function getMintLimitInfo() external returns (uint256 currentLimit, uint256 rate, uint256 maximum);
```

Gets current limit, maximum, and rate of the minting limiter.

### getRepayLimitInfo

```solidity
    function getRepayLimitInfo(address underlyingToken) external returns (uint256 currentLimit, uint256 rate, uint256 maximum);
```

Gets current limit, maximum, and rate of a repay limiter for `underlyingToken`.

#### Parameters:

| Name              | Type    | Description                          |
| ----------------- | ------- | ------------------------------------ |
| `underlyingToken` | address | The address of the underlying token. |

#### Return Values:

| Name           | Type    | Description                                                                                |
| -------------- | ------- | ------------------------------------------------------------------------------------------ |
| `currentLimit` | uint256 | The current amount of underlying tokens that can be repaid.                                |
| `rate`         | uint256 | The rate at which the the current limit increases back to its maximum in tokens per block. |
| `maximum`      | uint256 | The maximum possible amount of tokens that can be repaid at a time.                        |

### getLiquidationLimitInfo

```solidity
    function getLiquidationLimitInfo(address underlyingToken) external returns (uint256 currentLimit, uint256 rate, uint256 maximum);
```

Gets current limit, maximum, and rate of the liquidation limiter for `underlyingToken`.

#### Parameters:

| Name              | Type    | Description                          |
| ----------------- | ------- | ------------------------------------ |
| `underlyingToken` | address | The address of the underlying token. |

#### Return Values:

| Name           | Type    | Description                                                                          |
| -------------- | ------- | ------------------------------------------------------------------------------------ |
| `currentLimit` | uint256 | The current amount of underlying tokens that can be liquidated.                      |
| `rate`         | uint256 | The rate at which the function increases back to its maximum limit (tokens / block). |
| `maximum`      | uint256 | The highest possible maximum amount of debt tokens that can be liquidated at a time. |

### initialize

```solidity
    function initialize(struct IAlchemistV2AdminActions.InitializationParams params) external;
```

Initialize the contract.

`params.protocolFee` must be in range or this call will with an {IllegalArgument} error. The minting growth limiter parameters must be valid or this will revert with an {IllegalArgument} error. For more information, see the {Limiters} library.

Emits an {AdminUpdated} event. Emits a {TransmuterUpdated} event. Emits a {MinimumCollateralizationUpdated} event. Emits a {ProtocolFeeUpdated} event. Emits a {ProtocolFeeReceiverUpdated} event. Emits a {MintingLimitUpdated} event.

#### Parameters:

| Name     | Type                                                 | Description                             |
| -------- | ---------------------------------------------------- | --------------------------------------- |
| `params` | struct IAlchemistV2AdminActions.InitializationParams | The contract initialization parameters. |

### setPendingAdmin

```solidity
    function setPendingAdmin(address value) external;
```

Sets the pending administrator.

`msg.sender` must be the admin or this call will will revert with an {Unauthorized} error.

Emits a {PendingAdminUpdated} event.

This is the first step in the two-step process of setting a new administrator. After this function is called, the pending administrator will then need to call {acceptAdmin} to complete the process.

#### Parameters:

| Name    | Type    | Description                              |
| ------- | ------- | ---------------------------------------- |
| `value` | address | the address to set the pending admin to. |

### acceptAdmin

```solidity
    function acceptAdmin() external;
```

Allows for `msg.sender` to accepts the role of administrator.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. The current pending administrator must be non-zero or this call will revert with an {IllegalState} error.

Emits a {AdminUpdated} event. Emits a {PendingAdminUpdated} event. This is the second step in the two-step process of setting a new administrator. After this function is successfully called, this pending administrator will be reset and the new administrator will be set.

### setSentinel

```solidity
    function setSentinel(
        address sentinel,
        bool flag
    ) external;
```

Sets an address as a sentinel.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error.

#### Parameters:

| Name       | Type    | Description                                                            |
| ---------- | ------- | ---------------------------------------------------------------------- |
| `sentinel` | address | The address to set or unset as a sentinel.                             |
| `flag`     | bool    | A flag indicating of the address should be set or unset as a sentinel. |

### setKeeper

```solidity
    function setKeeper(
        address keeper,
        bool flag
    ) external;
```

Sets an address as a keeper.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error.

#### Parameters:

| Name     | Type    | Description                                                          |
| -------- | ------- | -------------------------------------------------------------------- |
| `keeper` | address | The address to set or unset as a keeper.                             |
| `flag`   | bool    | A flag indicating of the address should be set or unset as a keeper. |

### addUnderlyingToken

```solidity
    function addUnderlyingToken(
        address underlyingToken,
        struct IAlchemistV2AdminActions.UnderlyingTokenConfig config
    ) external;
```

Adds an underlying token to the system.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error.

#### Parameters:

| Name              | Type                                                  | Description                                 |
| ----------------- | ----------------------------------------------------- | ------------------------------------------- |
| `underlyingToken` | address                                               | The address of the underlying token to add. |
| `config`          | struct IAlchemistV2AdminActions.UnderlyingTokenConfig | The initial underlying token configuration. |

### addYieldToken

```solidity
    function addYieldToken(
        address yieldToken,
        struct IAlchemistV2AdminActions.YieldTokenConfig config
    ) external;
```

Adds a yield token to the system.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error.

Emits a {AddYieldToken} event. Emits a {TokenAdapterUpdated} event. Emits a {MaximumLossUpdated} event.

#### Parameters:

| Name         | Type                                             | Description                            |
| ------------ | ------------------------------------------------ | -------------------------------------- |
| `yieldToken` | address                                          | The address of the yield token to add. |
| `config`     | struct IAlchemistV2AdminActions.YieldTokenConfig | The initial yield token configuration. |

### setUnderlyingTokenEnabled

```solidity
    function setUnderlyingTokenEnabled(
        address underlyingToken,
        bool enabled
    ) external;
```

Sets an underlying token as either enabled or disabled.

`msg.sender` must be either the admin or a sentinel or this call will revert with an {Unauthorized} error. `underlyingToken` must be registered or this call will revert with a {UnsupportedToken} error.

Emits an {UnderlyingTokenEnabled} event.

#### Parameters:

| Name              | Type    | Description                                               |
| ----------------- | ------- | --------------------------------------------------------- |
| `underlyingToken` | address | The address of the underlying token to enable or disable. |
| `enabled`         | bool    | If the underlying token should be enabled or disabled.    |

### setYieldTokenEnabled

```solidity
    function setYieldTokenEnabled(
        address yieldToken,
        bool enabled
    ) external;
```

Sets a yield token as either enabled or disabled.

`msg.sender` must be either the admin or a sentinel or this call will revert with an {Unauthorized} error. `yieldToken` must be registered or this call will revert with a {UnsupportedToken} error.

Emits a {YieldTokenEnabled} event.

#### Parameters:

| Name         | Type    | Description                                            |
| ------------ | ------- | ------------------------------------------------------ |
| `yieldToken` | address | The address of the yield token to enable or disable.   |
| `enabled`    | bool    | If the underlying token should be enabled or disabled. |

### configureRepayLimit

```solidity
    function configureRepayLimit(
        address underlyingToken,
        uint256 maximum,
        uint256 blocks
    ) external;
```

Configures the the repay limit of `underlyingToken`.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `underlyingToken` must be registered or this call will revert with a {UnsupportedToken} error.

Emits a {ReplayLimitUpdated} event.

#### Parameters:

| Name              | Type    | Description                                                                                                          |
| ----------------- | ------- | -------------------------------------------------------------------------------------------------------------------- |
| `underlyingToken` | address | The address of the underlying token to configure the repay limit of.                                                 |
| `maximum`         | uint256 | The maximum repay limit.                                                                                             |
| `blocks`          | uint256 | The number of blocks it will take for the maximum repayment limit to be replenished when it is completely exhausted. |

### configureLiquidationLimit

```solidity
    function configureLiquidationLimit(
        address underlyingToken,
        uint256 maximum,
        uint256 blocks
    ) external;
```

Configure the liquidation limiter of `underlyingToken`.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `underlyingToken` must be registered or this call will revert with a {UnsupportedToken} error.

Emits a {LiquidationLimitUpdated} event.

#### Parameters:

| Name              | Type    | Description                                                                                                            |
| ----------------- | ------- | ---------------------------------------------------------------------------------------------------------------------- |
| `underlyingToken` | address | The address of the underlying token to configure the liquidation limit of.                                             |
| `maximum`         | uint256 | The maximum liquidation limit.                                                                                         |
| `blocks`          | uint256 | The number of blocks it will take for the maximum liquidation limit to be replenished when it is completely exhausted. |

### setTransmuter

```solidity
    function setTransmuter(address value) external;
```

Set the address of the transmuter.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `value` must be non-zero or this call will revert with an {IllegalArgument} error.

Emits a {TransmuterUpdated} event.

#### Parameters:

| Name    | Type    | Description                    |
| ------- | ------- | ------------------------------ |
| `value` | address | The address of the transmuter. |

### setMinimumCollateralization

```solidity
    function setMinimumCollateralization(uint256 value) external;
```

Set the minimum collateralization ratio.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error.

Emits a {MinimumCollateralizationUpdated} event.

#### Parameters:

| Name    | Type    | Description                              |
| ------- | ------- | ---------------------------------------- |
| `value` | uint256 | The new minimum collateralization ratio. |

### setProtocolFee

```solidity
    function setProtocolFee(uint256 value) external;
```

Sets the fee that the protocol will take from harvests.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `value` must be in range or this call will with an {IllegalArgument} error.

Emits a {ProtocolFeeUpdated} event.

#### Parameters:

| Name    | Type    | Description                                                    |
| ------- | ------- | -------------------------------------------------------------- |
| `value` | uint256 | The value to set the protocol fee to measured in basis points. |

### setProtocolFeeReceiver

```solidity
    function setProtocolFeeReceiver(address value) external;
```

Sets the address which will receive protocol fees.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `value` must be non-zero or this call will revert with an {IllegalArgument} error.

Emits a {ProtocolFeeReceiverUpdated} event.

#### Parameters:

| Name    | Type    | Description                                      |
| ------- | ------- | ------------------------------------------------ |
| `value` | address | The address to set the protocol fee receiver to. |

### configureMintingLimit

```solidity
    function configureMintingLimit(
        uint256 maximum,
        uint256 blocks
    ) external;
```

Configures the minting limiter.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error.

Emits a {MintingLimitUpdated} event.

#### Parameters:

| Name      | Type    | Description                                                                                                        |
| --------- | ------- | ------------------------------------------------------------------------------------------------------------------ |
| `maximum` | uint256 | The maximum minting limit.                                                                                         |
| `blocks`  | uint256 | The number of blocks it will take for the maximum minting limit to be replenished when it is completely exhausted. |

### configureCreditUnlockRate

```solidity
    function configureCreditUnlockRate(
        address yieldToken,
        uint256 blocks
    ) external;
```

Sets the rate at which credit will be completely available to depositors after it is harvested.

Emits a {CreditUnlockRateUpdated} event.

#### Parameters:

| Name         | Type    | Description                                                                |
| ------------ | ------- | -------------------------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to set the credit unlock rate for.          |
| `blocks`     | uint256 | The number of blocks that it will take before the credit will be unlocked. |

### setTokenAdapter

```solidity
    function setTokenAdapter(
        address yieldToken,
        address adapter
    ) external;
```

Sets the token adapter of a yield token.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. The token that `adapter` supports must be `yieldToken` or this call will revert with a {IllegalState} error.

Emits a {TokenAdapterUpdated} event.

#### Parameters:

| Name         | Type    | Description                                            |
| ------------ | ------- | ------------------------------------------------------ |
| `yieldToken` | address | The address of the yield token to set the adapter for. |
| `adapter`    | address | The address to set the token adapter to.               |

### setMaximumExpectedValue

```solidity
    function setMaximumExpectedValue(
        address yieldToken,
        uint256 value
    ) external;
```

Sets the maximum expected value of a yield token that the system can hold.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `yieldToken` must be registered or this call will revert with a {UnsupportedToken} error.

#### Parameters:

| Name         | Type    | Description                                                                             |
| ------------ | ------- | --------------------------------------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to set the maximum expected value for.                   |
| `value`      | uint256 | The maximum expected value of the yield token denoted measured in its underlying token. |

### setMaximumLoss

```solidity
    function setMaximumLoss(
        address yieldToken,
        uint256 value
    ) external;
```

Sets the maximum loss that a yield bearing token will permit before restricting certain actions.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `yieldToken` must be registered or this call will revert with a {UnsupportedToken} error.

There are two types of loss of value for yield bearing assets: temporary or permanent. The system will automatically restrict actions which are sensitive to both forms of loss when detected. For example, deposits must be restricted when an excessive loss is encountered to prevent users from having their collateral harvested from them. While the user would receive credit, which then could be exchanged for value equal to the collateral that was harvested from them, it is seen as a negative user experience because the value of their collateral should have been higher than what was originally recorded when they made their deposit.

#### Parameters:

| Name         | Type    | Description                                                             |
| ------------ | ------- | ----------------------------------------------------------------------- |
| `yieldToken` | address | The address of the yield bearing token to set the maximum loss for.     |
| `value`      | uint256 | The value to set the maximum loss to. This is in units of basis points. |

### snap

```solidity
    function snap(address yieldToken) external;
```

Snap the expected value `yieldToken` to the current value.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `yieldToken` must be registered or this call will revert with a {UnsupportedToken} error.

This function should only be used in the event of a loss in the target yield-token. For example, say a third-party protocol experiences a fifty percent loss. The expected value (amount of underlying tokens) of the yield tokens being held by the system would be two times the real value that those yield tokens could be redeemed for. This function gives governance a way to realize those losses so that users can continue using the token as normal.

#### Parameters:

| Name         | Type    | Description                             |
| ------------ | ------- | --------------------------------------- |
| `yieldToken` | address | The address of the yield token to snap. |

### sweepTokens

```solidity
    function sweepTokens(
        address rewardToken,
        uint256 amount
    ) external;
```

Sweep all of 'rewardtoken' from the alchemist into the admin.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error. `rewardToken` must not be a yield or underlying token or this call will revert with a {UnsupportedToken} error.

#### Parameters:

| Name          | Type    | Description                                        |
| ------------- | ------- | -------------------------------------------------- |
| `rewardToken` | address | The address of the reward token to snap.           |
| `amount`      | uint256 | The amount of 'rewardToken' to sweep to the admin. |

### setTransferAdapterAddress

```solidity
    function setTransferAdapterAddress(address transferAdapterAddress) external;
```

Set the address of the V1 transfer adapter.

`msg.sender` must be the admin or this call will revert with an {Unauthorized} error.

#### Parameters:

| Name                     | Type    | Description                                                        |
| ------------------------ | ------- | ------------------------------------------------------------------ |
| `transferAdapterAddress` | address | The address of the V1 transfer adapter to be set in the alchemist. |

### transferDebtV1

```solidity
    function transferDebtV1(
        address owner,
        int256 debt
    ) external;
```

Accept debt from the V1 transfer vault adapter.

`msg.sender` must be a sentinal or the admin or this call will revert with an {Unauthorized} error.

#### Parameters:

| Name    | Type    | Description                                              |
| ------- | ------- | -------------------------------------------------------- |
| `owner` | address | The owner of the account whos debt to increase.          |
| `debt`  | int256  | The amount of debt incoming from the V1 tranfer adapter. |

### approveMint

```solidity
    function approveMint(
        address spender,
        uint256 amount
    ) external;
```

Approve `spender` to mint `amount` debt tokens.

***NOTE:*** This function is WHITELISTED.

#### Parameters:

| Name      | Type    | Description                                                  |
| --------- | ------- | ------------------------------------------------------------ |
| `spender` | address | The address that will be approved to mint.                   |
| `amount`  | uint256 | The amount of tokens that `spender` will be allowed to mint. |

### approveWithdraw

```solidity
    function approveWithdraw(
        address spender,
        address yieldToken,
        uint256 shares
    ) external;
```

Approve `spender` to withdraw `amount` shares of `yieldToken`.

***NOTE:*** This function is WHITELISTED.

#### Parameters:

| Name         | Type    | Description                                                                |
| ------------ | ------- | -------------------------------------------------------------------------- |
| `spender`    | address | The address that will be approved to withdraw.                             |
| `yieldToken` | address | The address of the yield token that `spender` will be allowed to withdraw. |
| `shares`     | uint256 | The amount of shares that `spender` will be allowed to withdraw.           |

### poke

```solidity
    function poke(address owner) external;
```

Synchronizes the state of the account owned by `owner`.

#### Parameters:

| Name    | Type    | Description                              |
| ------- | ------- | ---------------------------------------- |
| `owner` | address | The owner of the account to synchronize. |

### deposit

```solidity
    function deposit(
        address yieldToken,
        uint256 amount,
        address recipient
    ) external returns (uint256);
```

Deposit a yield token into a user's account.

An approval must be set for `yieldToken` which is greater than `amount`.

`yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. `yieldToken` must be enabled or this call will revert with a {TokenDisabled} error. `yieldToken` underlying token must be enabled or this call will revert with a {TokenDisabled} error. `recipient` must be non-zero or this call will revert with an {IllegalArgument} error. `amount` must be greater than zero or the call will revert with an {IllegalArgument} error.

Emits a {Deposit} event.

***NOTE:*** This function is WHITELISTED.

***NOTE:*** When depositing, the `AlchemistV2` contract must have **allowance()** to spend funds on behalf of **msg.sender** for at least **amount** of the **yieldToken** being deposited. This can be done via the standard `ERC20.approve()` method.

**Example:**

```
address ydai = 0xdA816459F1AB5631232FE5e97a05BBBb94970c95;
uint256 amount = 50000;
IERC20(ydai).approve(alchemistAddress, amount);
AlchemistV2(alchemistAddress).deposit(ydai, amount, msg.sender);
```

#### Parameters:

| Name         | Type    | Description                                                      |
| ------------ | ------- | ---------------------------------------------------------------- |
| `yieldToken` | address | The yield-token to deposit.                                      |
| `amount`     | uint256 | The amount of yield tokens to deposit.                           |
| `recipient`  | address | The owner of the account that will receive the resulting shares. |

#### Return Values:

| Name           | Type    | Description                                 |
| -------------- | ------- | ------------------------------------------- |
| `sharesIssued` | uint256 | The number of shares issued to `recipient`. |

### depositUnderlying

```solidity
    function depositUnderlying(
        address yieldToken,
        uint256 amount,
        address recipient,
        uint256 minimumAmountOut
    ) external returns (uint256);
```

Deposit an underlying token into the account of `recipient` as `yieldToken`.

An approval must be set for the underlying token of `yieldToken` which is greater than `amount`.

`yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. `recipient` must be non-zero or this call will revert with an {IllegalArgument} error. `amount` must be greater than zero or the call will revert with an {IllegalArgument} error.

Emits a {Deposit} event.

***NOTE:*** This function is WHITELISTED. ***NOTE:*** When depositing, the `AlchemistV2` contract must have **allowance()** to spend funds on behalf of **msg.sender** for at least **amount** of the **underlyingToken** being deposited. This can be done via the standard `ERC20.approve()` method.

**Example:**

```
address ydai = 0xdA816459F1AB5631232FE5e97a05BBBb94970c95;
uint256 amount = 50000;
AlchemistV2(alchemistAddress).depositUnderlying(ydai, amount, msg.sender, 1);
```

#### Parameters:

| Name               | Type    | Description                                                                          |
| ------------------ | ------- | ------------------------------------------------------------------------------------ |
| `yieldToken`       | address | The address of the yield token to wrap the underlying tokens into.                   |
| `amount`           | uint256 | The amount of the underlying token to deposit.                                       |
| `recipient`        | address | The address of the recipient.                                                        |
| `minimumAmountOut` | uint256 | The minimum amount of yield tokens that are expected to be deposited to `recipient`. |

#### Return Values:

| Name           | Type    | Description                                 |
| -------------- | ------- | ------------------------------------------- |
| `sharesIssued` | uint256 | The number of shares issued to `recipient`. |

### withdraw

```solidity
    function withdraw(
        address yieldToken,
        uint256 shares,
        address recipient
    ) external returns (uint256);
```

Withdraw yield tokens to `recipient` by burning `share` shares. The number of yield tokens withdrawn to `recipient` will depend on the value of shares for that yield token at the time of the call.

`yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. `recipient` must be non-zero or this call will revert with an {IllegalArgument} error.

Emits a {Withdraw} event.

***NOTE:*** This function is WHITELISTED.

**Example:**

```
address ydai = 0xdA816459F1AB5631232FE5e97a05BBBb94970c95;
uint256 pps = AlchemistV2(alchemistAddress).getYieldTokensPerShare(ydai);
uint256 amtYieldTokens = 5000;
AlchemistV2(alchemistAddress).withdraw(ydai, amtYieldTokens / pps, msg.sender);
```

#### Parameters:

| Name         | Type    | Description                                 |
| ------------ | ------- | ------------------------------------------- |
| `yieldToken` | address | The address of the yield token to withdraw. |
| `shares`     | uint256 | The number of shares to burn.               |
| `recipient`  | address | The address of the recipient.               |

#### Return Values:

| Name              | Type    | Description                                                    |
| ----------------- | ------- | -------------------------------------------------------------- |
| `amountWithdrawn` | uint256 | The number of yield tokens that were withdrawn to `recipient`. |

### withdrawFrom

```solidity
    function withdrawFrom(
        address owner,
        address yieldToken,
        uint256 shares,
        address recipient
    ) external returns (uint256);
```

Withdraw yield tokens to `recipient` by burning `share` shares from the account of `owner`

`owner` must have an withdrawal allowance which is greater than `amount` for this call to succeed.

`yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. `recipient` must be non-zero or this call will revert with an {IllegalArgument} error.

Emits a {Withdraw} event.

***NOTE:*** This function is WHITELISTED.

**Example:**

```
address ydai = 0xdA816459F1AB5631232FE5e97a05BBBb94970c95;
uint256 pps = AlchemistV2(alchemistAddress).getYieldTokensPerShare(ydai);
uint256 amtYieldTokens = 5000;
AlchemistV2(alchemistAddress).withdrawFrom(msg.sender, ydai, amtYieldTokens / pps, msg.sender);
```

#### Parameters:

| Name         | Type    | Description                                        |
| ------------ | ------- | -------------------------------------------------- |
| `owner`      | address | The address of the account owner to withdraw from. |
| `yieldToken` | address | The address of the yield token to withdraw.        |
| `shares`     | uint256 | The number of shares to burn.                      |
| `recipient`  | address | The address of the recipient.                      |

#### Return Values:

| Name              | Type    | Description                                                    |
| ----------------- | ------- | -------------------------------------------------------------- |
| `amountWithdrawn` | uint256 | The number of yield tokens that were withdrawn to `recipient`. |

### withdrawUnderlying

```solidity
    function withdrawUnderlying(
        address yieldToken,
        uint256 shares,
        address recipient,
        uint256 minimumAmountOut
    ) external returns (uint256);
```

Withdraw underlying tokens to `recipient` by burning `share` shares and unwrapping the yield tokens that the shares were redeemed for.

`yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. `recipient` must be non-zero or this call will revert with an {IllegalArgument} error. The loss in expected value of `yieldToken` must be less than the maximum permitted by the system or this call will revert with a {LossExceeded} error.

Emits a {Withdraw} event.

***NOTE:*** This function is WHITELISTED. ***NOTE:*** The caller of `withdrawFrom()` must have **withdrawAllowance()** to withdraw funds on behalf of **owner** for at least the amount of `yieldTokens` that **shares** will be converted to. This can be done via the `approveWithdraw()` or `permitWithdraw()` methods.

**Example:**

```
address ydai = 0xdA816459F1AB5631232FE5e97a05BBBb94970c95;
uint256 pps = AlchemistV2(alchemistAddress).getUnderlyingTokensPerShare(ydai);
uint256 amountUnderlyingTokens = 5000;
AlchemistV2(alchemistAddress).withdrawUnderlying(ydai, amountUnderlyingTokens / pps, msg.sender, 1);
```

#### Parameters:

| Name               | Type    | Description                                                                               |
| ------------------ | ------- | ----------------------------------------------------------------------------------------- |
| `yieldToken`       | address | The address of the yield token to withdraw.                                               |
| `shares`           | uint256 | The number of shares to burn.                                                             |
| `recipient`        | address | The address of the recipient.                                                             |
| `minimumAmountOut` | uint256 | The minimum amount of underlying tokens that are expected to be withdrawn to `recipient`. |

#### Return Values:

| Name              | Type    | Description                                                         |
| ----------------- | ------- | ------------------------------------------------------------------- |
| `amountWithdrawn` | uint256 | The number of underlying tokens that were withdrawn to `recipient`. |

### withdrawUnderlyingFrom

```solidity
    function withdrawUnderlyingFrom(
        address owner,
        address yieldToken,
        uint256 shares,
        address recipient,
        uint256 minimumAmountOut
    ) external returns (uint256);
```

Withdraw underlying tokens to `recipient` by burning `share` shares from the account of `owner` and unwrapping the yield tokens that the shares were redeemed for.

`yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. `recipient` must be non-zero or this call will revert with an {IllegalArgument} error. The loss in expected value of `yieldToken` must be less than the maximum permitted by the system or this call will revert with a {LossExceeded} error.

Emits a {Withdraw} event.

***NOTE:*** This function is WHITELISTED. ***NOTE:*** The caller of `withdrawFrom()` must have **withdrawAllowance()** to withdraw funds on behalf of **owner** for at least the amount of `yieldTokens` that **shares** will be converted to. This can be done via the `approveWithdraw()` or `permitWithdraw()` methods.

**Example:**

```
address ydai = 0xdA816459F1AB5631232FE5e97a05BBBb94970c95;
uint256 pps = AlchemistV2(alchemistAddress).getUnderlyingTokensPerShare(ydai);
uint256 amtUnderlyingTokens = 5000 * 10**ydai.decimals();
AlchemistV2(alchemistAddress).withdrawUnderlying(msg.sender, ydai, amtUnderlyingTokens / pps, msg.sender, 1);
```

#### Parameters:

| Name               | Type    | Description                                                                               |
| ------------------ | ------- | ----------------------------------------------------------------------------------------- |
| `owner`            | address | The address of the account owner to withdraw from.                                        |
| `yieldToken`       | address | The address of the yield token to withdraw.                                               |
| `shares`           | uint256 | The number of shares to burn.                                                             |
| `recipient`        | address | The address of the recipient.                                                             |
| `minimumAmountOut` | uint256 | The minimum amount of underlying tokens that are expected to be withdrawn to `recipient`. |

#### Return Values:

| Name              | Type    | Description                                                         |
| ----------------- | ------- | ------------------------------------------------------------------- |
| `amountWithdrawn` | uint256 | The number of underlying tokens that were withdrawn to `recipient`. |

### mint

```solidity
    function mint(
        uint256 amount,
        address recipient
    ) external;
```

Mint `amount` debt tokens.

`recipient` must be non-zero or this call will revert with an {IllegalArgument} error. `amount` must be greater than zero or this call will revert with a {IllegalArgument} error.

Emits a {Mint} event.

***NOTE:*** This function is WHITELISTED.

**Example:**

```
uint256 amtDebt = 5000;
AlchemistV2(alchemistAddress).mint(amtDebt, msg.sender);
```

#### Parameters:

| Name        | Type    | Description                   |
| ----------- | ------- | ----------------------------- |
| `amount`    | uint256 | The amount of tokens to mint. |
| `recipient` | address | The address of the recipient. |

### mintFrom

```solidity
    function mintFrom(
        address owner,
        uint256 amount,
        address recipient
    ) external;
```

Mint `amount` debt tokens from the account owned by `owner` to `recipient`.

`recipient` must be non-zero or this call will revert with an {IllegalArgument} error. `amount` must be greater than zero or this call will revert with a {IllegalArgument} error.

Emits a {Mint} event.

***NOTE:*** This function is WHITELISTED. ***NOTE:*** The caller of `mintFrom()` must have **mintAllowance()** to mint debt from the `Account` controlled by **owner** for at least the amount of **yieldTokens** that **shares** will be converted to. This can be done via the `approveMint()` or `permitMint()` methods.

**Example:**

```
uint256 amtDebt = 5000;
AlchemistV2(alchemistAddress).mintFrom(msg.sender, amtDebt, msg.sender);
```

#### Parameters:

| Name        | Type    | Description                                           |
| ----------- | ------- | ----------------------------------------------------- |
| `owner`     | address | The address of the owner of the account to mint from. |
| `amount`    | uint256 | The amount of tokens to mint.                         |
| `recipient` | address | The address of the recipient.                         |

### burn

```solidity
    function burn(
        uint256 amount,
        address recipient
    ) external returns (uint256);
```

Burn `amount` debt tokens to credit the account owned by `recipient`.

`amount` will be limited up to the amount of debt that `recipient` currently holds.

`recipient` must be non-zero or this call will revert with an {IllegalArgument} error. `amount` must be greater than zero or this call will revert with a {IllegalArgument} error. `recipient` must have non-zero debt or this call will revert with an {IllegalState} error.

Emits a {Burn} event.

***NOTE:*** This function is WHITELISTED.

**Example:**

```
uint256 amtBurn = 5000;
AlchemistV2(alchemistAddress).burn(amtBurn, msg.sender);
```

#### Parameters:

| Name        | Type    | Description                   |
| ----------- | ------- | ----------------------------- |
| `amount`    | uint256 | The amount of tokens to burn. |
| `recipient` | address | The address of the recipient. |

#### Return Values:

| Name           | Type    | Description                            |
| -------------- | ------- | -------------------------------------- |
| `amountBurned` | uint256 | The amount of tokens that were burned. |

### repay

```solidity
    function repay(
        address underlyingToken,
        uint256 amount,
        address recipient
    ) external returns (uint256);
```

Repay `amount` debt using `underlyingToken` to credit the account owned by `recipient`.

`amount` will be limited up to the amount of debt that `recipient` currently holds.

`amount` must be greater than zero or this call will revert with a {IllegalArgument} error. `recipient` must be non-zero or this call will revert with an {IllegalArgument} error. `underlyingToken` must be enabled or this call will revert with a {TokenDisabled} error. `amount` must be less than or equal to the current available repay limit or this call will revert with a {ReplayLimitExceeded} error.

Emits a {Repay} event. ***NOTE:*** This function is WHITELISTED.

**Example:**

```
address dai = 0x6b175474e89094c44da98b954eedeac495271d0f;
uint256 amtRepay = 5000;
AlchemistV2(alchemistAddress).repay(dai, amtRepay, msg.sender);
```

#### Parameters:

| Name              | Type    | Description                                             |
| ----------------- | ------- | ------------------------------------------------------- |
| `underlyingToken` | address | The address of the underlying token to repay.           |
| `amount`          | uint256 | The amount of the underlying token to repay.            |
| `recipient`       | address | The address of the recipient which will receive credit. |

#### Return Values:

| Name           | Type    | Description                            |
| -------------- | ------- | -------------------------------------- |
| `amountRepaid` | uint256 | The amount of tokens that were repaid. |

### liquidate

```solidity
    function liquidate(
        address yieldToken,
        uint256 shares,
        uint256 minimumAmountOut
    ) external returns (uint256);
```

@notice

`shares` will be limited up to an equal amount of debt that `recipient` currently holds.

`shares` must be greater than zero or this call will revert with a {IllegalArgument} error. `yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. `yieldToken` must be enabled or this call will revert with a {TokenDisabled} error. `yieldToken` underlying token must be enabled or this call will revert with a {TokenDisabled} error. The loss in expected value of `yieldToken` must be less than the maximum permitted by the system or this call will revert with a {LossExceeded} error. `amount` must be less than or equal to the current available liquidation limit or this call will revert with a {LiquidationLimitExceeded} error.

Emits a {Liquidate} event.

***NOTE:*** This function is WHITELISTED.

**Example:**

```
address ydai = 0xdA816459F1AB5631232FE5e97a05BBBb94970c95;
uint256 amtSharesLiquidate = 5000 * 10**ydai.decimals();
AlchemistV2(alchemistAddress).liquidate(ydai, amtSharesLiquidate, 1);
```

#### Parameters:

| Name               | Type    | Description                                                                 |
| ------------------ | ------- | --------------------------------------------------------------------------- |
| `yieldToken`       | address | The address of the yield token to liquidate.                                |
| `shares`           | uint256 | The number of shares to burn for credit.                                    |
| `minimumAmountOut` | uint256 | The minimum amount of underlying tokens that are expected to be liquidated. |

#### Return Values:

| Name               | Type    | Description                                |
| ------------------ | ------- | ------------------------------------------ |
| `sharesLiquidated` | uint256 | The amount of shares that were liquidated. |

### donate

```solidity
    function donate(
        address yieldToken,
        uint256 amount
    ) external;
```

Burns `amount` debt tokens to credit accounts which have deposited `yieldToken`.

`amount` must be greater than zero or this call will revert with a {IllegalArgument} error. `yieldToken` must be registered or this call will revert with a {UnsupportedToken} error.

Emits a {Donate} event.

***NOTE:*** This function is WHITELISTED.

**Example:**

```
address ydai = 0xdA816459F1AB5631232FE5e97a05BBBb94970c95;
uint256 amtSharesLiquidate = 5000;
AlchemistV2(alchemistAddress).liquidate(dai, amtSharesLiquidate, 1);
```

#### Parameters:

| Name         | Type    | Description                                            |
| ------------ | ------- | ------------------------------------------------------ |
| `yieldToken` | address | The address of the yield token to credit accounts for. |
| `amount`     | uint256 | The amount of debt tokens to burn.                     |

### harvest

```solidity
    function harvest(
        address yieldToken,
        uint256 minimumAmountOut
    ) external;
```

Harvests outstanding yield that a yield token has accumulated and distributes it as credit to holders.

`msg.sender` must be a keeper or this call will revert with an {Unauthorized} error. `yieldToken` must be registered or this call will revert with a {UnsupportedToken} error. The amount being harvested must be greater than zero or else this call will revert with an {IllegalState} error.

Emits a {Harvest} event.

#### Parameters:

| Name               | Type    | Description                                                                               |
| ------------------ | ------- | ----------------------------------------------------------------------------------------- |
| `yieldToken`       | address | The address of the yield token to harvest.                                                |
| `minimumAmountOut` | uint256 | The minimum amount of underlying tokens that are expected to be withdrawn to `recipient`. |

### \_onlyAdmin

```solidity
    function _onlyAdmin() internal;
```

Checks that the `msg.sender` is the administrator.

`msg.sender` must be the administrator or this call will revert with an {Unauthorized} error.

### \_onlySentinelOrAdmin

```solidity
    function _onlySentinelOrAdmin() internal;
```

Checks that the `msg.sender` is the administrator or a sentinel.

`msg.sender` must be either the administrator or a sentinel or this call will revert with an {Unauthorized} error.

### \_onlyKeeper

```solidity
    function _onlyKeeper() internal;
```

Checks that the `msg.sender` is a keeper.

`msg.sender` must be a keeper or this call will revert with an {Unauthorized} error.

### \_onlyTransferAdapter

```solidity
    function _onlyTransferAdapter() internal;
```

Checks that the `msg.sender` is the V1 transfer adapter.

`msg.sender` must be the administrator or this call will revert with an {Unauthorized} error.

### \_preemptivelyHarvestDeposited

```solidity
    function _preemptivelyHarvestDeposited(address owner) internal;
```

Preemptively harvests all of the yield tokens that have been deposited into an account.

#### Parameters:

| Name    | Type    | Description                         |
| ------- | ------- | ----------------------------------- |
| `owner` | address | The address which owns the account. |

### \_preemptivelyHarvest

```solidity
    function _preemptivelyHarvest(address yieldToken) internal;
```

Preemptively harvests `yieldToken`.

This will earmark yield tokens to be harvested at a future time when the current value of the token is greater than the expected value. The purpose of this function is to synchronize the balance of the yield token which is held by users versus tokens which will be seized by the protocol.

#### Parameters:

| Name         | Type    | Description                                             |
| ------------ | ------- | ------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to preemptively harvest. |

### \_checkYieldTokenEnabled

```solidity
    function _checkYieldTokenEnabled(address yieldToken) internal;
```

Checks if a yield token is enabled.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |

### \_checkUnderlyingTokenEnabled

```solidity
    function _checkUnderlyingTokenEnabled(address underlyingToken) internal;
```

Checks if an underlying token is enabled.

#### Parameters:

| Name              | Type    | Description                          |
| ----------------- | ------- | ------------------------------------ |
| `underlyingToken` | address | The address of the underlying token. |

### \_checkSupportedYieldToken

```solidity
    function _checkSupportedYieldToken(address yieldToken) internal;
```

Checks if an address is a supported yield token.

If the address is not a supported yield token, this function will revert using a {UnsupportedToken} error.

#### Parameters:

| Name         | Type    | Description           |
| ------------ | ------- | --------------------- |
| `yieldToken` | address | The address to check. |

### \_checkSupportedUnderlyingToken

```solidity
    function _checkSupportedUnderlyingToken(address underlyingToken) internal;
```

Checks if an address is a supported underlying token.

If the address is not a supported yield token, this function will revert using a {UnsupportedToken} error.

#### Parameters:

| Name              | Type    | Description           |
| ----------------- | ------- | --------------------- |
| `underlyingToken` | address | The address to check. |

### \_checkMintingLimit

```solidity
    function _checkMintingLimit(uint256 amount) internal;
```

Checks if `amount` of debt tokens can be minted.

`amount` must be less than the current minting limit or this call will revert with a {MintingLimitExceeded} error.

#### Parameters:

| Name     | Type    | Description          |
| -------- | ------- | -------------------- |
| `amount` | uint256 | The amount to check. |

### \_checkLoss

```solidity
    function _checkLoss(address yieldToken) internal;
```

Checks if the current loss of `yieldToken` has exceeded its maximum acceptable loss.

The loss that `yieldToken` has incurred must be less than its maximum accepted value or this call will revert with a {LossExceeded} error.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |

### \_deposit

```solidity
    function _deposit(
        address yieldToken,
        uint256 amount,
        address recipient
    ) internal returns (uint256);
```

Deposits `amount` yield tokens into the account of `recipient`.

Emits a {Deposit} event.

#### Parameters:

| Name         | Type    | Description                                |
| ------------ | ------- | ------------------------------------------ |
| `yieldToken` | address | The address of the yield token to deposit. |
| `amount`     | uint256 | The amount of yield tokens to deposit.     |
| `recipient`  | address | The recipient of the yield tokens.         |

#### Return Values:

| Name  | Type    | Description                             |
| ----- | ------- | --------------------------------------- |
| `The` | uint256 | number of shares minted to `recipient`. |

### \_withdraw

```solidity
    function _withdraw(
        address yieldToken,
        address owner,
        uint256 shares,
        address recipient
    ) internal returns (uint256);
```

Withdraw `yieldToken` from the account owned by `owner` by burning shares and receiving yield tokens of equivalent value.

Emits a {Withdraw} event.

#### Parameters:

| Name         | Type    | Description                                                                     |
| ------------ | ------- | ------------------------------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to withdraw.                                     |
| `owner`      | address | The address of the account owner to withdraw from.                              |
| `shares`     | uint256 | The number of shares to burn.                                                   |
| `recipient`  | address | The recipient of the withdrawn shares. This parameter is only used for logging. |

#### Return Values:

| Name  | Type    | Description                                                       |
| ----- | ------- | ----------------------------------------------------------------- |
| `The` | uint256 | amount of yield tokens that the burned shares were exchanged for. |

### \_mint

```solidity
    function _mint(
        address owner,
        uint256 amount,
        address recipient
    ) internal;
```

Mints debt tokens to `recipient` using the account owned by `owner`.

Emits a {Mint} event.

#### Parameters:

| Name        | Type    | Description                              |
| ----------- | ------- | ---------------------------------------- |
| `owner`     | address | The owner of the account to mint from.   |
| `amount`    | uint256 | The amount to mint.                      |
| `recipient` | address | The recipient of the minted debt tokens. |

### \_sync

```solidity
    function _sync(
        address yieldToken,
        uint256 amount,
        function (uint256,uint256) pure returns (uint256) operation
    ) internal;
```

Synchronizes the active balance and expected value of `yieldToken`.

#### Parameters:

| Name         | Type                                              | Description                                                                               |
| ------------ | ------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| `yieldToken` | address                                           | The address of the yield token.                                                           |
| `amount`     | uint256                                           | The amount to add or subtract from the debt.                                              |
| `operation`  | function (uint256,uint256) pure returns (uint256) | The mathematical operation to perform for the update. Either one of {\_uadd} or {\_usub}. |

### \_loss

```solidity
    function _loss(address yieldToken) internal returns (uint256);
```

Gets the amount of loss that `yieldToken` has incurred measured in basis points. When the expected underlying value is less than the actual value, this will return zero.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |

#### Return Values:

| Name  | Type    | Description           |
| ----- | ------- | --------------------- |
| `The` | uint256 | loss in basis points. |

### \_distributeCredit

```solidity
    function _distributeCredit(
        address yieldToken,
        uint256 amount
    ) internal;
```

Distributes `amount` credit to all depositors of `yieldToken`.

#### Parameters:

| Name         | Type    | Description                                              |
| ------------ | ------- | -------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to distribute credit for. |
| `amount`     | uint256 | The amount of credit to distribute in debt tokens.       |

### \_distributeUnlockedCreditDeposited

```solidity
    function _distributeUnlockedCreditDeposited(address owner) internal;
```

Distributes unlocked credit for all of the yield tokens that have been deposited into the account owned by `owner`.

#### Parameters:

| Name    | Type    | Description                       |
| ------- | ------- | --------------------------------- |
| `owner` | address | The address of the account owner. |

### \_distributeUnlockedCredit

```solidity
    function _distributeUnlockedCredit(address yieldToken) internal;
```

Distributes unlocked credit of `yieldToken` to all depositors.

#### Parameters:

| Name         | Type    | Description                                                       |
| ------------ | ------- | ----------------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to distribute unlocked credit for. |

### \_wrap

```solidity
    function _wrap(
        address yieldToken,
        uint256 amount,
        uint256 minimumAmountOut
    ) internal returns (uint256);
```

Wraps `amount` of an underlying token into its `yieldToken`.

#### Parameters:

| Name               | Type    | Description                                                                             |
| ------------------ | ------- | --------------------------------------------------------------------------------------- |
| `yieldToken`       | address | The address of the yield token to wrap the underlying tokens into.                      |
| `amount`           | uint256 | The amount of the underlying token to wrap.                                             |
| `minimumAmountOut` | uint256 | The minimum amount of yield tokens that are expected to be received from the operation. |

#### Return Values:

| Name  | Type    | Description                                              |
| ----- | ------- | -------------------------------------------------------- |
| `The` | uint256 | amount of yield tokens that resulted from the operation. |

### \_unwrap

```solidity
    function _unwrap(
        address yieldToken,
        uint256 amount,
        address recipient,
        uint256 minimumAmountOut
    ) internal returns (uint256);
```

Unwraps `amount` of `yieldToken` into its underlying token.

#### Parameters:

| Name               | Type    | Description                                                                                  |
| ------------------ | ------- | -------------------------------------------------------------------------------------------- |
| `yieldToken`       | address | The address of the yield token to unwrap.                                                    |
| `amount`           | uint256 | The amount of the underlying token to wrap.                                                  |
| `recipient`        | address | The recipient of the tokens after they are unwrapped.                                        |
| `minimumAmountOut` | uint256 | The minimum amount of underlying tokens that are expected to be received from the operation. |

#### Return Values:

| Name  | Type    | Description                                                   |
| ----- | ------- | ------------------------------------------------------------- |
| `The` | uint256 | amount of underlying tokens that resulted from the operation. |

### \_poke

```solidity
    function _poke(address owner) internal;
```

Synchronizes the state for all of the tokens deposited in the account owned by `owner`.

#### Parameters:

| Name    | Type    | Description                       |
| ------- | ------- | --------------------------------- |
| `owner` | address | The address of the account owner. |

### \_poke

```solidity
    function _poke(
        address owner,
        address yieldToken
    ) internal;
```

Synchronizes the state of `yieldToken` for the account owned by `owner`.

#### Parameters:

| Name         | Type    | Description                                                  |
| ------------ | ------- | ------------------------------------------------------------ |
| `owner`      | address | The address of the account owner.                            |
| `yieldToken` | address | The address of the yield token to synchronize the state for. |

### \_updateDebt

```solidity
    function _updateDebt(
        address owner,
        int256 amount
    ) internal;
```

Increases the debt by `amount` for the account owned by `owner`.

#### Parameters:

| Name     | Type    | Description                         |
| -------- | ------- | ----------------------------------- |
| `owner`  | address | The address of the account owner.   |
| `amount` | int256  | The amount to increase the debt by. |

### \_approveMint

```solidity
    function _approveMint(
        address owner,
        address spender,
        uint256 amount
    ) internal;
```

Set the mint allowance for `spender` to `amount` for the account owned by `owner`.

#### Parameters:

| Name      | Type    | Description                                             |
| --------- | ------- | ------------------------------------------------------- |
| `owner`   | address | The address of the account owner.                       |
| `spender` | address | The address of the spender.                             |
| `amount`  | uint256 | The amount of debt tokens to set the mint allowance to. |

### \_decreaseMintAllowance

```solidity
    function _decreaseMintAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal;
```

Decrease the mint allowance for `spender` by `amount` for the account owned by `owner`.

#### Parameters:

| Name      | Type    | Description                                                  |
| --------- | ------- | ------------------------------------------------------------ |
| `owner`   | address | The address of the account owner.                            |
| `spender` | address | The address of the spender.                                  |
| `amount`  | uint256 | The amount of debt tokens to decrease the mint allowance by. |

### \_approveWithdraw

```solidity
    function _approveWithdraw(
        address owner,
        address spender,
        address yieldToken,
        uint256 shares
    ) internal;
```

Set the withdraw allowance of `yieldToken` for `spender` to `shares` for the account owned by `owner`.

#### Parameters:

| Name         | Type    | Description                                                       |
| ------------ | ------- | ----------------------------------------------------------------- |
| `owner`      | address | The address of the account owner.                                 |
| `spender`    | address | The address of the spender.                                       |
| `yieldToken` | address | The address of the yield token to set the withdraw allowance for. |
| `shares`     | uint256 | The amount of shares to set the withdraw allowance to.            |

### \_decreaseWithdrawAllowance

```solidity
    function _decreaseWithdrawAllowance(
        address owner,
        address spender,
        address yieldToken,
        uint256 amount
    ) internal;
```

Decrease the withdraw allowance of `yieldToken` for `spender` by `amount` for the account owned by `owner`.

#### Parameters:

| Name         | Type    | Description                                                            |
| ------------ | ------- | ---------------------------------------------------------------------- |
| `owner`      | address | The address of the account owner.                                      |
| `spender`    | address | The address of the spender.                                            |
| `yieldToken` | address | The address of the yield token to decrease the withdraw allowance for. |
| `amount`     | uint256 | The amount of shares to decrease the withdraw allowance by.            |

### \_validate

```solidity
    function _validate(address owner) internal;
```

Checks that the account owned by `owner` is properly collateralized.

If the account is undercollateralized then this will revert with an {Undercollateralized} error.

#### Parameters:

| Name    | Type    | Description                       |
| ------- | ------- | --------------------------------- |
| `owner` | address | The address of the account owner. |

### totalValue

```solidity
    function totalValue(address owner) public returns (uint256);
```

Gets the total value of the deposit collateral measured in debt tokens of the account owned by `owner`.

#### Parameters:

| Name    | Type    | Description                       |
| ------- | ------- | --------------------------------- |
| `owner` | address | The address of the account owner. |

#### Return Values:

| Name  | Type    | Description  |
| ----- | ------- | ------------ |
| `The` | uint256 | total value. |

### \_issueSharesForAmount

```solidity
    function _issueSharesForAmount(
        address recipient,
        address yieldToken,
        uint256 amount
    ) internal returns (uint256);
```

Issues shares of `yieldToken` for `amount` of its underlying token to `recipient`.

IMPORTANT: `amount` must never be 0.

#### Parameters:

| Name         | Type    | Description                         |
| ------------ | ------- | ----------------------------------- |
| `recipient`  | address | The address of the recipient.       |
| `yieldToken` | address | The address of the yield token.     |
| `amount`     | uint256 | The amount of the underlying token. |

#### Return Values:

| Name  | Type    | Description                             |
| ----- | ------- | --------------------------------------- |
| `The` | uint256 | amount of shares issued to `recipient`. |

### \_burnShares

```solidity
    function _burnShares(
        address owner,
        address yieldToken,
        uint256 shares
    ) internal;
```

Burns `share` shares of `yieldToken` from the account owned by `owner`.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `owner`      | address | The address of the owner.       |
| `yieldToken` | address | The address of the yield token. |
| `shares`     | uint256 | The amount of shares to burn.   |

### \_calculateUnrealizedDebt

```solidity
    function _calculateUnrealizedDebt(address owner) internal returns (int256);
```

Gets the amount of debt that the account owned by `owner` will have after an update occurs.

#### Parameters:

| Name    | Type    | Description                       |
| ------- | ------- | --------------------------------- |
| `owner` | address | The address of the account owner. |

#### Return Values:

| Name  | Type   | Description                                                                 |
| ----- | ------ | --------------------------------------------------------------------------- |
| `The` | int256 | amount of debt that the account owned by `owner` will have after an update. |

### \_calculateUnrealizedActiveBalance

```solidity
    function _calculateUnrealizedActiveBalance(address yieldToken) internal returns (uint256);
```

Gets the virtual active balance of `yieldToken`.

The virtual active balance is the active balance minus any harvestable tokens which have yet to be realized.

#### Parameters:

| Name         | Type    | Description                                                          |
| ------------ | ------- | -------------------------------------------------------------------- |
| `yieldToken` | address | The address of the yield token to get the virtual active balance of. |

#### Return Values:

| Name  | Type    | Description             |
| ----- | ------- | ----------------------- |
| `The` | uint256 | virtual active balance. |

### \_calculateUnlockedCredit

```solidity
    function _calculateUnlockedCredit(address yieldToken) internal returns (uint256);
```

Calculates the amount of unlocked credit for `yieldToken` that is available for distribution.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |

#### Return Values:

| Name  | Type    | Description                          |
| ----- | ------- | ------------------------------------ |
| `The` | uint256 | amount of unlocked credit available. |

### convertYieldTokensToShares

```solidity
    function convertYieldTokensToShares(
        address yieldToken,
        uint256 amount
    ) public returns (uint256);
```

Gets the amount of shares that `amount` of `yieldToken` is exchangeable for.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |
| `amount`     | uint256 | The amount of yield tokens.     |

#### Return Values:

| Name  | Type    | Description       |
| ----- | ------- | ----------------- |
| `The` | uint256 | number of shares. |

### convertSharesToYieldTokens

```solidity
    function convertSharesToYieldTokens(
        address yieldToken,
        uint256 shares
    ) public returns (uint256);
```

Gets the amount of yield tokens that `shares` shares of `yieldToken` is exchangeable for.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |
| `shares`     | uint256 | The amount of shares.           |

#### Return Values:

| Name  | Type    | Description             |
| ----- | ------- | ----------------------- |
| `The` | uint256 | amount of yield tokens. |

### convertSharesToUnderlyingTokens

```solidity
    function convertSharesToUnderlyingTokens(
        address yieldToken,
        uint256 shares
    ) public returns (uint256);
```

Gets the amount of underlying tokens that `shares` shares of `yieldToken` is exchangeable for.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |
| `shares`     | uint256 | The amount of shares.           |

#### Return Values:

| Name  | Type    | Description                  |
| ----- | ------- | ---------------------------- |
| `The` | uint256 | amount of underlying tokens. |

### convertYieldTokensToUnderlying

```solidity
    function convertYieldTokensToUnderlying(
        address yieldToken,
        uint256 amount
    ) public returns (uint256);
```

Gets the amount of an underlying token that `amount` of `yieldToken` is exchangeable for.

#### Parameters:

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| `yieldToken` | address | The address of the yield token. |
| `amount`     | uint256 | The amount of yield tokens.     |

#### Return Values:

| Name  | Type    | Description                  |
| ----- | ------- | ---------------------------- |
| `The` | uint256 | amount of underlying tokens. |

### convertUnderlyingTokensToYield

```solidity
    function convertUnderlyingTokensToYield(
        address yieldToken,
        uint256 amount
    ) public returns (uint256);
```

Gets the amount of `yieldToken` that `amount` of its underlying token is exchangeable for.

#### Parameters:

| Name         | Type    | Description                      |
| ------------ | ------- | -------------------------------- |
| `yieldToken` | address | The address of the yield token.  |
| `amount`     | uint256 | The amount of underlying tokens. |

#### Return Values:

| Name  | Type    | Description             |
| ----- | ------- | ----------------------- |
| `The` | uint256 | amount of yield tokens. |

### convertUnderlyingTokensToShares

```solidity
    function convertUnderlyingTokensToShares(
        address yieldToken,
        uint256 amount
    ) public returns (uint256);
```

Gets the amount of shares of `yieldToken` that `amount` of its underlying token is exchangeable for.

#### Parameters:

| Name         | Type    | Description                      |
| ------------ | ------- | -------------------------------- |
| `yieldToken` | address | The address of the yield token.  |
| `amount`     | uint256 | The amount of underlying tokens. |

#### Return Values:

| Name  | Type    | Description       |
| ----- | ------- | ----------------- |
| `The` | uint256 | amount of shares. |

### normalizeUnderlyingTokensToDebt

```solidity
    function normalizeUnderlyingTokensToDebt(
        address underlyingToken,
        uint256 amount
    ) public returns (uint256);
```

Normalize `amount` of `underlyingToken` to a value which is comparable to units of the debt token.

#### Parameters:

| Name              | Type    | Description                          |
| ----------------- | ------- | ------------------------------------ |
| `underlyingToken` | address | The address of the underlying token. |
| `amount`          | uint256 | The amount of the debt token.        |

#### Return Values:

| Name  | Type    | Description        |
| ----- | ------- | ------------------ |
| `The` | uint256 | normalized amount. |

### normalizeDebtTokensToUnderlying

```solidity
    function normalizeDebtTokensToUnderlying(
        address underlyingToken,
        uint256 amount
    ) public returns (uint256);
```

Normalize `amount` of the debt token to a value which is comparable to units of `underlyingToken`.

This operation will result in truncation of some of the least significant digits of `amount`. This truncation amount will be the least significant N digits where N is the difference in decimals between the debt token and the underlying token.

#### Parameters:

| Name              | Type    | Description                          |
| ----------------- | ------- | ------------------------------------ |
| `underlyingToken` | address | The address of the underlying token. |
| `amount`          | uint256 | The amount of the debt token.        |

#### Return Values:

| Name  | Type    | Description        |
| ----- | ------- | ------------------ |
| `The` | uint256 | normalized amount. |

### \_onlyWhitelisted

```solidity
    function _onlyWhitelisted() internal;
```

Checks the whitelist for msg.sender.

Reverts if msg.sender is not in the whitelist.

### \_checkArgument

```solidity
    function _checkArgument(bool expression) internal;
```

Checks an expression and reverts with an {IllegalArgument} error if the expression is {false}.

#### Parameters:

| Name         | Type | Description              |
| ------------ | ---- | ------------------------ |
| `expression` | bool | The expression to check. |

### \_checkState

```solidity
    function _checkState(bool expression) internal;
```

Checks an expression and reverts with an {IllegalState} error if the expression is {false}.

#### Parameters:

| Name         | Type | Description              |
| ------------ | ---- | ------------------------ |
| `expression` | bool | The expression to check. |

### \_uadd

```solidity
    function _uadd(
        uint256 x,
        uint256 y
    ) internal returns (uint256 z);
```

Adds two unsigned 256 bit integers together and returns the result.

This operation is checked and will fail if the result overflows.

#### Parameters:

| Name | Type    | Description         |
| ---- | ------- | ------------------- |
| `x`  | uint256 | The first operand.  |
| `y`  | uint256 | The second operand. |

#### Return Values:

| Name | Type    | Description |
| ---- | ------- | ----------- |
| `z`  | uint256 | The result. |

### \_usub

```solidity
    function _usub(
        uint256 x,
        uint256 y
    ) internal returns (uint256 z);
```

Subtracts two unsigned 256 bit integers together and returns the result.

This operation is checked and will fail if the result overflows.

#### Parameters:

| Name | Type    | Description         |
| ---- | ------- | ------------------- |
| `x`  | uint256 | The first operand.  |
| `y`  | uint256 | The second operand. |

#### Return Values:

| Name | Type    | Description |
| ---- | ------- | ----------- |
| `z`  | uint256 | the result. |
