# SyncSynthVault

## Solidity version

```solidity
0.8.21
```

***

## Inheritance

* `Ownable2StepUpgradeable` of [OpenZeppelin](https://github.com/OpenZeppelin/openzeppelin-contracts).
* `ERC20PermitUpgradeable` of [OpenZeppelin](https://github.com/OpenZeppelin/openzeppelin-contracts).
* `ERC20PausableUpgradeable` of [OpenZeppelin](https://github.com/OpenZeppelin/openzeppelin-contracts).
* `IERC4626` of [OpenZeppelin](https://github.com/OpenZeppelin/openzeppelin-contracts).

***

## Global Variables

### PermitParams

```solidity
struct PermitParams {
    uint256 value;
    uint256 deadline;
    uint8 v;
    bytes32 r;
    bytes32 s;
}
```

### BPS\_DIVIDER

```solidity
uint256 constant BPS_DIVIDER = 10_000;
```

### MAX\_FEES

```solidity
uint16 constant MAX_FEES = 3000; // 30%
```

## State Variables

### feesInBps

```solidity
uint16 public feesInBps;
```

<table><thead><tr><th width="118.33333333333331">Type</th><th width="196">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>uint16</code></td><td><code>public</code></td><td>Performance fees are applied on the absolute returns of the underlying strategy.</td></tr></tbody></table>

### vaultIsOpen

```solidity
bool public vaultIsOpen; // vault is open or closed
```

<table><thead><tr><th width="130.33333333333331">Type</th><th width="105">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>bool</code></td><td><code>public</code></td><td>The locking status of the vault.</td></tr></tbody></table>

## lastSavedBalance

```solidity
uint256 public lastSavedBalance; // last saved balance
```

<table><thead><tr><th width="118.33333333333331">Type</th><th width="196">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>uint16</code></td><td><code>public</code></td><td>Performance fees are applied on the absolute returns of the underlying strategy.</td></tr></tbody></table>

***

## Events

### EpochStart

```solidity
event EpochStart(
    uint256 indexed timestamp,
    uint256 lastSavedBalance,
    uint256 totalShares
)
```

Emitted when an epoch starts.

<table><thead><tr><th width="210.33333333333331">Name</th><th width="186">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>timestamp</code></td><td><code>uint256 indexed</code></td><td>The block timestamp of the epoch starts.</td></tr><tr><td><code>lastSavedBalance</code></td><td><code>uint256</code></td><td>The <code>lastSavedBalance</code> when the vault starts.</td></tr><tr><td><code>totalShares</code></td><td><code>uint256</code></td><td>The total number of shares when the vault starts.</td></tr></tbody></table>

### EpochEnd

```solidity
event EpochEnd(
    uint256 indexed timestamp,
    uint256 lastSavedBalance,
    uint256 returnedAssets,
    uint256 fees,
    uint256 totalShares
)
```

Emitted when an epoch ends.

<table><thead><tr><th width="210.33333333333331">Name</th><th width="186">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>timestamp</code></td><td><code>uint256 indexed</code></td><td>The block timestamp of the epoch terminates.</td></tr><tr><td><code>lastSavedBalance</code></td><td><code>uint256</code></td><td>The <code>lastSavedBalance</code> from the current epoch starts.</td></tr><tr><td><code>returnedAssets</code></td><td><code>uint256</code></td><td>The total amount of underlying assets returned to the vault before collecting fees.</td></tr><tr><td><code>fees</code></td><td><code>uint256</code></td><td>The amount of fees collected.</td></tr><tr><td><code>totalShares</code></td><td><code>uint256</code></td><td>The total amount of shares when the vault terminates.</td></tr></tbody></table>

### FeesChanged

```solidity
event FeesChanged(uint16 oldFees, uint16 newFees)
```

Emitted when fees are changed.

<table><thead><tr><th width="191.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>oldFees</code></td><td><code>uint16</code></td><td>The previous performance fees (in bps).</td></tr><tr><td><code>newFees</code></td><td><code>uint16</code></td><td>The newly applied performance fees (in bps).</td></tr><tr><td><code>returnedAssets</code></td><td><code>uint256</code></td><td>The total amount of underlying assets returned to the vault before collecting fees.</td></tr></tbody></table>

***

## Errors

### VaultIsClosed

```solidity
error VaultIsClosed();
```

The vault is in a locked state. Emitted if the transaction cannot happen in this state.

### VaultIsOpen

```solidity
error VaultIsOpen()
```

The vault is in an open state. Emitted if the transaction cannot happen in this state.

### CannotClaimAsset

```solidity
error CannotClaimAsset()
```

Claiming the underlying assets is not allowed.

### ERC4626ExceededMaxDeposit

```solidity
error ERC4626ExceededMaxDeposit(
    address receiver,
    uint256 assets,
    uint256 max
)
```

Attempt to deposit more underlying assets than the maximum allowed amount for `receiver`.

<table><thead><tr><th width="134.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>receiver</code></td><td><code>address</code></td><td>The <code>address</code> of the <code>receiver</code>.</td></tr><tr><td><code>assets</code></td><td><code>uint256</code></td><td>The amount of underlying assets asked for deposit.</td></tr><tr><td><code>max</code></td><td><code>uint256</code></td><td>Number of shares  (LP tokens) received in exchange for the specified amount of underlying assets.</td></tr></tbody></table>

### ERC4626ExceededMaxMint

```solidity
error ERC4626ExceededMaxMint(address receiver, uint256 shares, uint256 max)
```

Attempt to mint more shares (LP tokens) than the maximum allowed amount for `receiver`.

<table><thead><tr><th width="117.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>owner</code></td><td><code>address</code></td><td>The <code>address</code> of the <code>owner</code>.</td></tr><tr><td><code>shares</code></td><td><code>uint256</code></td><td>The amount of underlying assets asked to mint shares (LP tokens).</td></tr><tr><td><code>max</code></td><td><code>uint256</code></td><td>The maximum number of withdrawable shares (LP tokens).</td></tr></tbody></table>

### ERC4626ExceededMaxWithdraw

```solidity
error ERC4626ExceededMaxWithdraw(
    address owner,
    uint256 assets,
    uint256 max
)
```

Attempt to withdraw more underlying assets than the maximum allowed amount for `receiver`.

<table><thead><tr><th width="117.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>owner</code></td><td><code>address</code></td><td>The <code>address</code> of the <code>owner</code>.</td></tr><tr><td><code>assets</code></td><td><code>uint256</code></td><td>The number of underlying assets asked for withdrawal.</td></tr><tr><td><code>max</code></td><td><code>uint256</code></td><td>The maximum amount of withdrawable underlying assets.</td></tr></tbody></table>

### ERC4626ExceededMaxRedeem

```solidity
 error ERC4626ExceededMaxRedeem(address owner, uint256 shares, uint256 max)
```

Attempt to redeem more shares(LP tokens) than the maximum allowed amount for `receiver`.

<table><thead><tr><th width="114.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>owner</code></td><td><code>address</code></td><td>The <code>address</code> of the <code>owner</code>.</td></tr><tr><td><code>shares</code></td><td><code>uint256</code></td><td>The number of shares (LP tokens) asked to be redeemed.</td></tr><tr><td><code>max</code></td><td><code>uint256</code></td><td>The maximum number of redeemable shares (LP tokens).</td></tr></tbody></table>

***

## Functions

### asset

```solidity
function asset() public view returns (address)
```

The `asset` function is used to return the `address` of the underlying asset.

{% tabs %}
{% tab title="Returned Value" %}

<table><thead><tr><th width="125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>address</code></td><td><code>address</code> of the underlying asset.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### decimals

```solidity
function decimals() public view override(ERC20, IERC20Metadata) returns (uint8)
```

See `{IERC20-decimals}`. The `_decimalShares` is equal to underlying asset decimals + `decimalsOffset`. See Constructor for more details about this.

{% tabs %}
{% tab title="Returned value" %}

<table><thead><tr><th width="104">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint8</code></td><td>Amount of decimals of the share (LP) token.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### totalAssets

```solidity
function totalAssets() public view returns (uint256)
```

The `totalAssets` function is used to calculate the theoretical total underlying assets owned by the vault. If the vault is locked, the last saved balance is added to the current balance.

{% tabs %}
{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Amount of the total underlying assets in the vault.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### convertToShares

```solidity
function convertToShares(uint256 assets) public view returns (uint256)
```

See {IERC4626-convertToShares}.\
The `convertToShares` function is used to calculate the number of shares (LP tokens) received in exchange for the specified amount of underlying assets.

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="116.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>uint256</code></td><td>The amount of underlying assets to be converted into shares .</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="126">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Number of shares (LP tokens) received in exchange for the specified number of underlying assets.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### convertToAssets

```solidity
function convertToAssets(uint256 shares) public view returns (uint256)
```

See {IERC4626-convertToAssets}.\
The `convertToAssets` function is used to calculate the amount of underlying assets received in exchange for the specified number of shares (LP tokens).

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="116.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>shares</code></td><td><code>uint256</code></td><td>The number of shares (LP tokens) to be converted into underlying assets.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="126">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Amount of underlying assets received in exchange for the specified number of shares (LP tokens).</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### maxDeposit

```solidity
function maxMint(address) public view returns (uint256)
```

The `maxDeposit` function is used to calculate the maximum deposit.\
If the vault is locked or paused, users are not allowed to mint, the `maxMint` is `0`.

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="92.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td>_</td><td><code>address</code></td><td>The <code>address</code> of the shares (LP tokens) <code>receiver</code>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="126">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Amount of the maximum underlying assets deposit.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### maxMint

```solidity
function maxMint(address) public view returns (uint256)
```

The `maxMint` function is used to calculate the maximum number of shares (LP tokens) you can mint. If the vault is locked or paused, the `maxMint` is `0`.

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="94.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td>_</td><td><code>address</code></td><td>The <code>address</code> of the <code>receiver</code>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Maximum number of shares (LP tokens) mintable for the specified <code>address</code>.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### maxWithdraw

```solidity
function maxWithdraw(address owner) public view returns (uint256)
```

The `maxWithdraw` function is used to calculate the maximum amount of withdrawable underlying assets. If the function is called during the lock period the `maxWithdraw` is `0`.

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="105.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>owner</code></td><td><code>address</code></td><td>The <code>address</code> of the <code>owner</code>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>The maximum amount of withdrawable underlying assets.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### maxRedeem

```solidity
function maxRedeem(address owner) public view returns (uint256)
```

The `maxRedemm` function is used to calculate the maximum number of redeemable shares (LP tokens). If the function is called during the lock period, the `maxRedeem` is `0`.

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="104.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>owner</code></td><td><code>address</code></td><td>The <code>address</code> of the <code>owner</code>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>The maximum number of redeemable shares (LP tokens).</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### previewDeposit

```solidity
function previewDeposit(uint256 assets) public view returns (uint256)
```

The `previewDeposit` function is used to calculate the number of shares (LP tokens) received in exchange for the specified underlying asset.

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="114.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>uint256</code></td><td>The amount of underlying assets to be converted into shares (LP tokens).</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Number of shares (LP tokens) received in exchange for the specified amount of underlying assets.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### previewMint

```solidity
function previewMint(uint256 shares) public view returns (uint256)
```

The `previewMint` function is used to calculate the amount of underlying assets received in exchange for the specified number of shares (LP tokens).

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="114.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>shares</code></td><td><code>uint256</code></td><td>The number of shares (LP tokens) to be converted into underlying assets.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Amount of underlying assets received in exchange for the specified number of shares (LP tokens).</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### previewWithdraw

```solidity
function previewWithdraw(uint256 assets) public view returns (uint256)
```

The `previewWithdraw` function is used to calculate the number of shares (LP tokens) received in exchange for the specified underlying asset.

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="114.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>uint256</code></td><td>The amount of underlying assets to be converted into shares (LP tokens).</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Number of shares (LP tokens) received in exchange of the specified amount of underlying assets.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### previewRedeem

```solidity
function previewRedeem(uint256 shares) public view returns (uint256)
```

The `previewRedeem` function is used to calculate the amount of underlying assets received in exchange for the specified number of shares (LP token).

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="115.33333333333331">Name</th><th width="111">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>shares</code></td><td><code>uint256</code></td><td>The number of shares (LP tokens) to be converted into underlying assets.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Amount of underlying assets received in exchange for the specified number of shares (LP tokens).</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### sharesBalanceInAsset

```solidity
function sharesBalanceInAsset(address owner) public view returns (uint256)
```

Given the address of an owner, returns the amount of shares of an user, converted in assets.

The `previewRedeem` function is used to calculate the amount of underlying assets received in exchange for the specified number of shares (LP token).

{% tabs %}
{% tab title="Parameter" %}

<table><thead><tr><th width="115.33333333333331">Name</th><th width="111">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>owner</code></td><td><code>address</code></td><td>The owner <code>address</code>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Amount of shares converted to underlying assets owner by the user (LP tokens).</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### deposit

```solidity
function deposit(uint256 assets, address receiver) public returns (uint256)
```

The `deposit` function is used to deposit underlying assets into the vault.

{% tabs %}
{% tab title="Parameters" %}

<table><thead><tr><th width="144.33333333333331">Name</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>uint256</code></td><td>The amount of underlying assets to be converted into shares (LP tokens).</td></tr><tr><td><code>receiver</code></td><td><code>address</code></td><td>The <code>address</code> of the shares (LP tokens) <code>receiver</code>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Number of shares (LP tokens) received in exchange for the specified amount of underlying assets.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### depositWithPermit

```solidity
function depositWithPermit(
        uint256 assets,
        address receiver,
        PermitParams calldata permitParams
) external returns (uint256)
```

The `depositWithPermit` function is used to deposit underlying assets into the vault by using permit feature **if the underlying asset support it**.

{% tabs %}
{% tab title="Parameters" %}

<table><thead><tr><th width="174.33333333333331">Name</th><th width="157">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>uint256</code></td><td>The amount of underlying assets to be converted into shares (LP tokens).</td></tr><tr><td><code>receiver</code></td><td><code>address</code></td><td>The <code>address</code> of the shares (LP tokens) <code>receiver</code>.</td></tr><tr><td><code>permitParams</code></td><td><code>PermitParams</code></td><td>Permit functionality parameters.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Number of shares (LP tokens) received in exchange for the specified amount of underlying assets.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### depositWithPermit

### mint

```solidity
function mint(uint256 shares, address receiver) public returns (uint256)
```

The `mint` function is used to mint the specified number of shares (LP tokens) in exchange for the corresponding amount of underlying assets from `owner`.

{% tabs %}
{% tab title="Parameters" %}

<table><thead><tr><th width="134.33333333333331">Name</th><th width="111">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>shares</code></td><td><code>uint256</code></td><td>The number of shares (LP tokens) to be converted into underlying assets.</td></tr><tr><td><code>receiver</code></td><td><code>address</code></td><td>The <code>address</code> of the shares (LP tokens) <code>receiver</code>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Amount of underlying assets received in exchange of the specified number of shares (LP tokens).</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### withdraw

```solidity
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256)
```

The `withdraw` function is used to withdraw the specified amount of underlying assets in exchange for a proportional number of shares (LP tokens).

{% tabs %}
{% tab title="Parameters" %}

<table><thead><tr><th width="134.33333333333331">Name</th><th width="111">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>uint256</code></td><td>The amount of underlying assets to be withdrawn.</td></tr><tr><td><code>receiver</code></td><td><code>address</code></td><td>The <code>address</code> of the shares (LP tokens) <code>receiver</code>.</td></tr><tr><td><code>owner</code></td><td><code>address</code></td><td>The <code>address</code> of the <code>owner</code>.</td></tr></tbody></table>
{% endtab %}

{% tab title="Returned value" %}

<table><thead><tr><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>uint256</code></td><td>Number of shares received in exchange for the specified amount of underlying assets.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

### redeem

```solidity
function redeem(uint256 shares, address receiver, address owner) external returns (uint256)
```

The `redeem` function is used to redeem the specified number of shares (LP tokens) in exchange for the corresponding amount of underlying assets from `owner`.

<table><thead><tr><th width="134.33333333333331">Name</th><th width="111">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>shares</code></td><td><code>uint256</code></td><td>The amount of  shares to be redeemed.</td></tr><tr><td><code>receiver</code></td><td><code>address</code></td><td>The <code>address</code> of the shares (LP tokens) <code>receiver</code>.</td></tr><tr><td><code>owner</code></td><td><code>address</code></td><td>The <code>address</code> of the <code>owner</code>.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://defivaults.gitbook.io/amphor/technical/v1/syncsynthvault.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
