# API related docs

##

## <mark style="background-color:blue;">FundV2</mark>

Holds a portfolio of tokens and allows a fund manager to trade and rebalance tokens

#### Rebalance

```
function Rebalance(address[] _toAddr, uint256[] _targets) external
```

Rebalance the Portfolio Vault and redistribute the funds new tokens and weights

**Parameters**

| Name      | Type       | Description               |
| --------- | ---------- | ------------------------- |
| \_toAddr  | address\[] | Token Addresses           |
| \_targets | uint256\[] | Target Weights for tokens |

#### Rebalance

```
function Rebalance(address[] _toAddr, uint256[] _targets, uint32 _slippage) public
```

Rebalance the Portfolio Vault and redistribute the funds new tokens and weights

**Parameters**

| Name       | Type       | Description               |
| ---------- | ---------- | ------------------------- |
| \_toAddr   | address\[] | Token Addresses           |
| \_targets  | uint256\[] | Target Weights for tokens |
| \_slippage | uint32     | DEX slippage for swaps    |

#### deposit

```
function deposit(uint256 amount) external returns (uint256)
```

Buy fund shares by depositing baseToken

*Swaps will be done before shares are created*

**Parameters**

| Name   | Type    | Description                    |
| ------ | ------- | ------------------------------ |
| amount | uint256 | Amount of baseToken to deposit |

**Return Values**

| Name   | Type    | Description               |
| ------ | ------- | ------------------------- |
| shares | uint256 | Amount of shares received |

#### deposit

```
function deposit(uint256 amount, uint32 _slippage) public returns (uint256)
```

Buy fund shares by depositing baseToken

*Swaps will be done before shares are created*

**Parameters**

| Name       | Type    | Description                    |
| ---------- | ------- | ------------------------------ |
| amount     | uint256 | Amount of baseToken to deposit |
| \_slippage | uint32  | DEX slippage for swaps         |

**Return Values**

| Name   | Type    | Description               |
| ------ | ------- | ------------------------- |
| shares | uint256 | Amount of shares received |

#### withdraw

```
function withdraw(uint256 amount) external returns (uint256)
```

Exchange Portfolio vault shares for baseToken

*Performance fee will be charged if a profit is made, if no deposit the entire withdraw amount will be treated as profit*

**Parameters**

| Name   | Type    | Description                  |
| ------ | ------- | ---------------------------- |
| amount | uint256 | Amount of shares to withdraw |

**Return Values**

| Name     | Type    | Description                  |
| -------- | ------- | ---------------------------- |
| tokenAmt | uint256 | Amount of baseToken received |

#### withdraw

```
function withdraw(uint256 amount, uint32 _slippage) public returns (uint256)
```

Exchange Portfolio vault shares for baseToken

*Performance fee will be charged if a profit is made, if no deposit the entire withdraw amount will be treated as profit*

**Parameters**

| Name       | Type    | Description                  |
| ---------- | ------- | ---------------------------- |
| amount     | uint256 | Amount of shares to withdraw |
| \_slippage | uint32  | DEX slippage for swaps       |

**Return Values**

| Name     | Type    | Description                  |
| -------- | ------- | ---------------------------- |
| tokenAmt | uint256 | Amount of baseToken received |

## <mark style="background-color:blue;">FundV2Factory</mark>

Deploys New Portfolio Fund Contracts

#### createFundPrivate

```
function createFundPrivate(string name, string symbol, address[] _toAddresses, uint256[] _targetWeight) external
```

Deploys a new ERC20 Private Portfolio Fund

**Parameters**

| Name           | Type       | Description                        |
| -------------- | ---------- | ---------------------------------- |
| name           | string     | Name of the Portfolio Fund         |
| symbol         | string     | Symbol of the Portfolio Fund token |
| \_toAddresses  | address\[] | Initial allocation token addresses |
| \_targetWeight | uint256\[] | Initial allocation target weights  |

#### massProcessPlatformFee

```
function massProcessPlatformFee() external
```

Process platform fee on all funds

#### processPlatformFee

```
function processPlatformFee(address _fundAddr) external
```

Process platform fee on input fund address

**Parameters**

| Name       | Type    | Description                    |
| ---------- | ------- | ------------------------------ |
| \_fundAddr | address | Address of fund to collect fee |

#### processManagerFee

```
function processManagerFee(address _fundAddr) external
```

Process manager fee on input fund address

**Parameters**

| Name       | Type    | Description                    |
| ---------- | ------- | ------------------------------ |
| \_fundAddr | address | Address of fund to collect fee |

#### massProcessManagerFee

```
function massProcessManagerFee() external
```

Process manager fee on all funds

#### getLatestFundID

```
function getLatestFundID() public view returns (uint256)
```

Gets the ID of the lastest fund created

#### getFundfromIndex

```
function getFundfromIndex(uint256 _index) public view returns (address)
```

Get Portfolio Fund address from fund ID

**Parameters**

| Name    | Type    | Description    |
| ------- | ------- | -------------- |
| \_index | uint256 | id of the fund |

**Return Values**

| Name    | Type    | Description              |
| ------- | ------- | ------------------------ |
| address | address | Address of input fund ID |


---

# 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://doc.xwin.finance/v1.1-docs/technical/api-related-docs.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.
