> 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/transmuterv2cover/transmuterv2.md).

# Functions

A contract which facilitates the exchange of synthetic assets for their underlying

## Structs

### Account

| Field                | Type    |
| -------------------- | ------- |
| `unexchangedBalance` | uint256 |
| `exchangedBalance`   | uint256 |
| `occupiedTick`       | uint256 |

### UpdateAccountParams

| Field              | Type    |
| ------------------ | ------- |
| `owner`            | address |
| `unexchangedDelta` | int256  |
| `exchangedDelta`   | int256  |

### ExchangeCache

| Field              | Type    |
| ------------------ | ------- |
| `totalUnexchanged` | uint256 |
| `satisfiedTick`    | uint256 |
| `ticksHead`        | uint256 |

### ExchangeState

| Field               | Type                         |
| ------------------- | ---------------------------- |
| `examineTick`       | uint256                      |
| `totalUnexchanged`  | uint256                      |
| `satisfiedTick`     | uint256                      |
| `distributeAmount`  | uint256                      |
| `accumulatedWeight` | struct FixedPointMath.Number |
| `maximumWeight`     | struct FixedPointMath.Number |
| `dustedWeight`      | struct FixedPointMath.Number |

### UpdateAccountCache

| Field                | Type    |
| -------------------- | ------- |
| `unexchangedBalance` | uint256 |
| `exchangedBalance`   | uint256 |
| `occupiedTick`       | uint256 |
| `totalUnexchanged`   | uint256 |
| `currentTick`        | uint256 |

### UpdateAccountState

| Field                | Type    |
| -------------------- | ------- |
| `unexchangedBalance` | uint256 |
| `exchangedBalance`   | uint256 |
| `totalUnexchanged`   | uint256 |

## Functions

### constructor

```solidity
    function constructor() public;
```

### initialize

```solidity
    function initialize() external;
```

### \_onlyAdmin

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

### setCollateralSource

```solidity
    function setCollateralSource() external;
```

### setPause

```solidity
    function setPause() external;
```

### deposit

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

Deposits tokens to be exchanged into an account.

#### Parameters:

| Name     | Type    | Description                                          |
| -------- | ------- | ---------------------------------------------------- |
| `amount` | uint256 | The amount of tokens to deposit.                     |
| `owner`  | address | The owner of the account to deposit the tokens into. |

### withdraw

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

Withdraws tokens from the caller's account that were previously deposited to be exchanged.

#### Parameters:

| Name        | Type    | Description                                          |
| ----------- | ------- | ---------------------------------------------------- |
| `amount`    | uint256 | The amount of tokens to withdraw.                    |
| `recipient` | address | The address which will receive the withdrawn tokens. |

### claim

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

Claims exchanged tokens.

#### Parameters:

| Name        | Type    | Description                                        |
| ----------- | ------- | -------------------------------------------------- |
| `amount`    | uint256 | The amount of tokens to claim.                     |
| `recipient` | address | The address which will receive the claimed tokens. |

### exchange

```solidity
    function exchange(uint256 amount) external;
```

Exchanges `amount` underlying tokens for `amount` synthetic tokens staked in the system.

#### Parameters:

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

### getUnexchangedBalance

```solidity
    function getUnexchangedBalance(address owner) external returns (uint256);
```

Gets the unexchanged balance of an account.

#### Parameters:

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

#### Return Values:

| Name  | Type    | Description          |
| ----- | ------- | -------------------- |
| `The` | uint256 | unexchanged balance. |

### getExchangedBalance

```solidity
    function getExchangedBalance(address owner) external returns (uint256 exchangedBalance);
```

Gets the exchanged balance of an account, in units of `debtToken`.

#### Parameters:

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

#### Return Values:

| Name  | Type    | Description        |
| ----- | ------- | ------------------ |
| `The` | uint256 | exchanged balance. |

### getClaimableBalance

```solidity
    function getClaimableBalance() external returns (uint256 claimableBalance);
```

### \_updateAccount

```solidity
    function _updateAccount(struct TransmuterV2.UpdateAccountParams params) internal;
```

Updates an account.

#### Parameters:

| Name     | Type                                    | Description          |
| -------- | --------------------------------------- | -------------------- |
| `params` | struct TransmuterV2.UpdateAccountParams | The call parameters. |

### \_onlyWhitelisted

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

Reverts if msg.sender is not in the whitelist. Checks the whitelist for msg.sender.

### \_normalizeUnderlyingTokensToDebt

```solidity
    function _normalizeUnderlyingTokensToDebt(uint256 amount) internal returns (uint256);
```

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

#### Parameters:

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

#### Return Values:

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

### \_normalizeDebtTokensToUnderlying

```solidity
    function _normalizeDebtTokensToUnderlying(uint256 amount) internal 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                   |
| -------- | ------- | ----------------------------- |
| `amount` | uint256 | The amount of the debt token. |

#### Return Values:

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

### \_getExchangedBalance

```solidity
    function _getExchangedBalance() internal returns (uint256 exchangedBalance);
```
