# VChainMinter

On VirtuSwap v1, distribution protocol inflation between pools is facilitated by the Minerva Liquidity Optimization Engine. Every epoch, Minerva calculates the optimal distribution of liquidity between the pools, and distributes the protocol reward allocation points between pools with the goal of achieving such distribution of liquidity.

Minerva calculations are done in a centralized way off-chain, and will be gradually moved a to a decentralized solution in later versions. Read more about Minerva [here](https://medium.com/virtuswap/introducing-minerva-virtuswap-ai-for-liquidity-optimization-5bf86b29c1f0).

vChainMinter contract receives VRSW tokens minted by vGlobalMinter, and distributes them between vStaker instances (each representing a VirtuSwap pool) according to allocation points.

### Events

#### event NewStaker

```solidity
event NewStaker(
    address staker
);
```

Emitted when a new Staker instance is set.

#### event TransferRewards

```solidity
event TransferRewards(
    address indexed to, 
    address indexed lpToken,
    uint256 amount
);
```

Emitted when pool rewards are transferred to an address

### State-Changing Functions

#### function setEpochParams

```solidity
function setEpochParams(
        uint32 _epochDuration,
        uint32 _epochPreparationTime
 ) external override onlyOwner
```

Changes minting epoch duration and preparation time. A minting epoch is the time period between changes in distribution of rewards between VirtuSwap pools. Default is 4 weeks.

The Epoch Preparation Time is the time window before the start of the epoch in which it is allowed to transfer the rewards for the upcoming epoch. Default is 1 week.

✏️Can only be called by the owner

✏️Should be in sync with Epoch Params set to vGlobalMinter

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>_epochDuration</td><td><code>uint32</code></td><td>Epoch duration (in seconds)</td></tr><tr><td>_epochPreparationTime</td><td><code>uint32</code></td><td>Amount to transfer</td></tr></tbody></table>

#### function prepareForNextEpoch

```solidity
function prepareForNextEpoch(
    uint256 nextBalance
) external;
```

Accepts transfer of necessary amount of VRSW tokens for the next epoch according to the [Emission Schedule](https://docs.virtuswap.io/virtuswap-documentation/virtuswap-basics/usdvrsw-token/vrsw-tokenomics#emission-schedule).  Currently the transfers are done manually using intermediary wallet (contracts owner).

✏️Can only be called by the owner

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>nextBalance</td><td><code>uint256</code></td><td>Amount transferred to be distributed to vStaker contracts during the next epoch</td></tr></tbody></table>

### function transferRewards

```solidity
function transferRewards(
    address to, 
    address lpToken,
    uint256 amount) 
external override
```

Allows a the Staker to transfer a specified amount of  rewards tokens to a recipient address. The recipient is an LP in the pool that is identified by address of its LP token.

Can only be called by the Staker.

Emits the [TransferRewards](#event-transferrewards) event.

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>to</td><td><code>address</code></td><td>Address of the recipient LP</td></tr><tr><td>lpToken</td><td><code>address</code></td><td>Address of the LP token of the pool </td></tr><tr><td>amount</td><td><code>uint256</code></td><td>Amount to be transferred</td></tr></tbody></table>

#### function setAllocationPoints

```solidity
function setAllocationPoints(
  address[] calldata _lpTokens,
  uint256[] calldata _allocationPoints
) external override onlyOwner
```

Defines the proportion in which the protocol emission is distributed between VirtuSwap pools contracts.

✏️Can only be called by the owner

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>_lpTokens</td><td><code>address</code></td><td>Array of addresses of the LP Tokens of pools to which allocation points are assigned</td></tr><tr><td>_allocationPoints</td><td><code>uint256</code></td><td>Array of allocatoin points assigned to the corresponding pool in _lpTokens array</td></tr></tbody></table>

#### function mintVeVrsw

```solidity
function mintVeVrsw(address to, uint256 amount) external override
```

Mint a given amount of veVrsw tokens to the specified to address.

✏️Can only be called by the Staker

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>to</td><td><code>address</code></td><td>Address of the recipient </td></tr><tr><td>amount</td><td><code>uint256</code></td><td>Amount to be transferred</td></tr></tbody></table>

#### function burnVeVrsw

```solidity
function burnVeVrsw(address from, uint256 amount) external override
```

Burn a given amount of veVrsw tokens from the specified to address

✏️Can only be called by a Staker

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>from</td><td><code>address</code></td><td>Address to transfer veVRSW to be burned </td></tr><tr><td>amount</td><td><code>uint256</code></td><td>Amount to be transferred</td></tr></tbody></table>

#### function setStaker

```solidity
function setStaker(
        address _newStaker) 
external override onlyOwner
```

Sets the Staker instance.

Emits NewStaker event

✏️Can only be called by a Owner

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>from</td><td><code>address</code></td><td>Address to transfer veVRSW to be burned </td></tr><tr><td>amount</td><td><code>uint256</code></td><td>Amount to be transferred</td></tr></tbody></table>

#### function calculateTokensForPool

```solidity
function calculateTokensForPool(
      address lpToken
  ) external view returns (uint256)
```

Calculates the total amount of tokens available for a pool represented by the LP Token address

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>lpToken</td><td><code>address</code></td><td>address of the LP Token belonging to the target pool</td></tr></tbody></table>

### Read-only Functions

#### emissionStartTs

```solidity
function emissionStartTs() 
external view returns (uint32); 
```

Returns the timestamp when VRSW emission began.
