# Fund

It is a utility struct to easily know how many shares to issue/burn based on an underlying amount.

## Structs

### <mark style="color:blue;">**Account**</mark>

```rust
struct Fund has store, copy, drop {
    shares: u128,
    underlying: u128
 }
```

* **shares** - The amount of shares issued based on the underlying amount.
* **underlying** - The amount of assets in the fund.

## Interface

### <mark style="color:blue;">empty</mark>

**Creates an empty Fund.**

```rust
public fun empty(): Fund
```

* **@return** Fund.

### <mark style="color:blue;">underlying</mark>

**Returns the amount of underlying in the `self`.**

```rust
public fun underlying(self: &Fund): u64
```

* **@param self:** A Fund.
* **@return** u64. The amount of underlying.

### <mark style="color:blue;">shares</mark>

**Returns the amount of shares in the `self`.**

```rust
public fun shares(self: &Fund): u64
```

* **@param self:** A Fund.
* **@return** u64. The amount of shares.

### <mark style="color:blue;">to\_shares</mark>

**Returns the number of shares the `self` would issue if more `underlying` was deposited in it.**

```rust
public fun to_shares(self: &Fund, underlying: u64, round_up: bool): u64
```

* **@param self:** A Fund.
* **@param underlying:** The amount of underlying that the caller intends to add to the `self`.
* **@param round\_up:** If true we would round up the returned value.
* **@return u64**. The amount of shares the fund would issue.

### <mark style="color:blue;">to\_underlying</mark>

**Returns the number of shares the `self` would issue if more `underlying` was deposited in it.**

```rust
public fun to_underlying(rebase: &Fund, shares: u64, round_up: bool): u64
```

* **@param self:** A Fund.
* **@param shares:** The amount of shares that the caller intends to burn.
* **@param round\_up:** If true we would round up the returned value.
* **@return u64**. The amount underlying the fund would release.

### <mark style="color:blue;">sub\_shares</mark>

This function reduces the amount of underlying and shares in the fund.

```rust
public fun sub_shares(self: &mut Fund, shares: u64, round_up: bool): u64
```

* **@param self:** A Fund.
* **@param shares:** The amount of shares that the caller intends to burn.
* **@param round\_up:** If true we would round up the returned value.
* **@return u64**. The amount underlying the `shares` were worth.

### <mark style="color:blue;">add\_underlying</mark>

Adds `underlying` to the `self` and returns the additional shares issued. This function increases the amount of underlying and shares in the fund.

```rust
public fun add_underlying(rebase: &mut Fund, underlying: u64, round_up: bool): u64
```

* **@param self:** A Fund.
* **@param underlying:** The amount of underlying to deposit in the `self`.
* **@param round\_up:** If true we would round up the returned value.
* **@return u64.** The amount of shares the fund issued.

### <mark style="color:blue;">sub\_underlying</mark>

Removes `underlying` from the `self` and returns the burned shares. This function reduces the amount of underlying and shares in the fund.

```rust
public fun sub_underlying(rebase: &mut Fund, underlying: u64, round_up: bool): u64
```

* **@param self:** A Fund.
* **@param underlying:** The amount of underlying to remove from the `self`.
* **@param round\_up:** If true we would round up the returned value.
* **@return u64.** The amount of shares the fund burned.

### <mark style="color:blue;">add\_profit</mark>

Adds profits to the underlying. This is to add profits to the fund.

```rust
public fun add_profit(rebase: &mut Fund, profit: u64)
```

* **@param self:** A Fund.
* **@param profit:** The amount of underlying to add as profit to `self.underlying`.
