# OCE\_ZVE.sol

## Introduction

This contract facilitates an exponential decay emissions schedule for $ZVE.

This contract has the following responsibilities:

* Handles accounting (with governable variables) to support emissions schedule.
* Forwards $ZVE to all ZivoeRewards contracts at will (stZVE, stSTT, stJTT).

{% embed url="<https://www.figma.com/board/qjuQ0uGQl9QD7KeBwyf73d/Zivoe-Visualization?node-id=207-555&t=PV4UgJW2ZCG870d3-4>" %}

#### State Variables

<table><thead><tr><th width="144.33333333333331">Type</th><th width="195">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>GBL</td><td>The ZivoeGlobals contract.</td></tr><tr><td>uint256</td><td>exponentialDecayPerSecond</td><td>The rate of decay per second.</td></tr><tr><td>uint256</td><td>lastDistribution</td><td>The block.timestamp value of last distribution.</td></tr><tr><td>uint256[3]</td><td>distributionRatioBIPS</td><td>Determines distribution between rewards contract, in BIPS.<br><code>distributionRatioBIPS[0] => stZVE</code><br><code>distributionRatioBIPS[1] => stSTT</code><br><code>distributionRatioBIPS[2] => stJTT</code></td></tr><tr><td>uint256</td><td>BIPS</td><td>Private constant, <code>10000</code></td></tr><tr><td>uint256</td><td>RAY</td><td>Private constant, <code>10**27</code></td></tr></tbody></table>

## **Sections**

[#read-functions](#read-functions "mention")

* [#canpush](#canpush "mention") - Permission for owner to call `pushToLocker()`. See [zivoelocker.sol](https://docs.zivoe.com/developer-docs/core-contracts/zivoelocker.sol "mention")
* [#canpull](#canpull "mention") - Permission for owner to call `pullFromLocker()`. See [zivoelocker.sol](https://docs.zivoe.com/developer-docs/core-contracts/zivoelocker.sol "mention")
* [#canpullpartial](#canpullpartial "mention") - Permission for owner to call `pullFromLockerPartial()`. See [zivoelocker.sol](https://docs.zivoe.com/developer-docs/core-contracts/zivoelocker.sol "mention")
* [#decay](#decay "mention") - Returns the amount remaining after a decay.
* [#rmul](#rmul "mention") - Multiplies two variables and returns value, truncated by RAY precision.
* [#rpow](#rpow "mention") - `rpow(uint256 x, uint256 n, uint256 b)`, used for exponentiation in drip

[#write-functions](#write-functions "mention")

* [#pushtolocker](#pushtolocker "mention") - Allocates ZVE from the DAO to this locker for emissions.
* [#forwardemissions](#forwardemissions "mention") - Forwards $ZVE available for distribution.
* [#updatedistributionratiobips](#updatedistributionratiobips "mention") - Updates the distribution between rewards contract, in BIPS.
* [#updateexponentialdecaypersecond](#updateexponentialdecaypersecond "mention") - Updates the exponentialDecayPerSecond variable with provided input.

[#events](#events "mention")

* [#updateddistributionratiobips](#updateddistributionratiobips "mention")
* [#emissionsforwarded](#emissionsforwarded "mention")
* [#updatedexponentialdecaypersecond](#updatedexponentialdecaypersecond "mention")

## Read Functions

#### `canPush()`

Permission for owner to call `pushToLocker()`. See [zivoelocker.sol](https://docs.zivoe.com/developer-docs/core-contracts/zivoelocker.sol "mention")

```solidity
 function canPush() public override pure returns (bool) { return true; }
```

#### `canPull()`

Permission for owner to call `pullFromLocker()`. See [zivoelocker.sol](https://docs.zivoe.com/developer-docs/core-contracts/zivoelocker.sol "mention")

```solidity
function canPull() public override pure returns (bool) { return true; }
```

#### `canPullPartial()`

Permission for owner to call `pullFromLockerPartial()`. See [zivoelocker.sol](https://docs.zivoe.com/developer-docs/core-contracts/zivoelocker.sol "mention")

```solidity
function canPullPartial() public override pure returns (bool) { return true; }
```

#### `decay()`

Returns the amount remaining after a decay.

```solidity
function decay(
    uint256 top, 
    uint256 dur
) public view returns (uint256);
```

<table><thead><tr><th width="170.33333333333331">Type</th><th width="204">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>top</td><td>The amount decaying.</td></tr><tr><td>uint256</td><td>dur</td><td>The seconds of decay.</td></tr></tbody></table>

*Returns*

<table><thead><tr><th width="170.33333333333331">Type</th><th width="204">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td><code>n/a</code></td><td>The amount remaining after a decay.</td></tr></tbody></table>

#### `rmul()`

Multiplies two variables and returns value, truncated by RAY precision.

```solidity
function rmul(
    uint256 x, 
    uint256 y
) internal pure returns (uint256 z);
```

<table><thead><tr><th width="170.33333333333331">Type</th><th width="204">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>x</td><td>First value to multiply.</td></tr><tr><td>uint256</td><td>y</td><td>Second value to multiply.</td></tr></tbody></table>

*Returns*

<table><thead><tr><th width="170.33333333333331">Type</th><th width="204">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>z</td><td>Resulting value of x * y, truncated by RAY precision.</td></tr></tbody></table>

#### `rpow()`

`rpow(uint256 x, uint256 n, uint256 b)`, used for exponentiation in drip, is a fixed-point arithmetic function that raises x to the power n. It is implemented in Solidity assembly as a repeated squaring algorithm. x and the returned value are to be interpreted as fixed-point integers with scaling factor b. For example, if b == 100, this specifies two decimal digits of precision and the normal decimal value 2.1 would be represented as 210; rpow(210, 2, 100) returns 441 (the two-decimal digit fixed-point representation of 2.1^2 = 4.41). In the current implementation, 10^27 is passed for b, making x and the rpow result both of type RAY in standard MCD fixed-point terminology. rpow's formal invariants include "no overflow" as well as constraints on gas usage.

```solidity
function rpow(
    uint256 x, 
    uint256 n, 
    uint256 b
) internal pure returns (uint256 z);
```

<table><thead><tr><th width="170.33333333333331">Type</th><th width="128">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>x</td><td>The base value.</td></tr><tr><td>uint256</td><td>n</td><td>The power to raise "x" by.</td></tr><tr><td>uint256</td><td>b</td><td>The scaling factor, a.k.a. resulting precision of "z".</td></tr></tbody></table>

*Returns*

<table><thead><tr><th width="170.33333333333331">Type</th><th width="134">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>z</td><td>Resulting value of x^n, scaled by factor b.</td></tr></tbody></table>

## Write Functions

#### `pushToLocker()`

Allocates ZVE from the DAO to this locker for emissions.

```solidity
function pushToLocker(
    address asset, 
    uint256 amount, 
    bytes calldata data
) external override onlyOwner;
```

<table><thead><tr><th width="156.33333333333331">Type</th><th width="160">Name</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>asset</td><td>The asset to push to this locker (in this case $ZVE).</td></tr><tr><td>uint256</td><td>amount</td><td>The amount of $ZVE to push to this locker.</td></tr><tr><td>bytes</td><td>data</td><td>Accompanying transaction data.</td></tr></tbody></table>

#### `forwardEmissions()`

Forwards $ZVE available for distribution.

```solidity
function forwardEmissions() external nonReentrant;
```

Emits the [#emissionsforwarded](#emissionsforwarded "mention") event.

#### `updateDistributionRatioBIPS()`

Updates the distribution between rewards contract, in BIPS.

```solidity
function updateDistributionRatioBIPS(
    uint256[3] calldata _distributionRatioBIPS
) external;
```

<table><thead><tr><th width="156.33333333333331">Type</th><th width="200">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256[3]</td><td>_distributionRatioBIPS</td><td>The updated values for the state variable distributionRatioBIPS.</td></tr></tbody></table>

Emits the [#updateddistributionratiobips](#updateddistributionratiobips "mention") event.

#### `updateExponentialDecayPerSecond()`

Updates the exponentialDecayPerSecond variable with provided input.

```solidity
function updateExponentialDecayPerSecond(
    uint256 _exponentialDecayPerSecond
) external;
```

<table><thead><tr><th width="156.33333333333331">Type</th><th width="177">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>_exponentialDecayPerSecond</td><td>The updated value for exponentialDecayPerSecond state variable.</td></tr></tbody></table>

Emits the [#updatedexponentialdecaypersecond](#updatedexponentialdecaypersecond "mention") event.

## Events

#### **`UpdatedDistributionRatioBIPS()`**

Emitted during [#updatedistributionratiobips](#updatedistributionratiobips "mention")

```solidity
event UpdatedDistributionRatioBIPS(
    uint256[3] oldRatios, 
    uint256[3] newRatios
);
```

<table><thead><tr><th width="133.33333333333331">Type</th><th width="98">Indexed</th><th width="132">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256[3]</td><td>False</td><td>oldRatios</td><td>The old distribution ratios.</td></tr><tr><td>uint256[3]</td><td>False</td><td>newRatios</td><td>The new distribution ratios.</td></tr></tbody></table>

#### **`EmissionsForwarded()`**

Emitted during [#forwardemissions](#forwardemissions "mention")

```solidity
event EmissionsForwarded(uint256 stZVE, uint256 stJTT, uint256 stSTT);
```

<table><thead><tr><th width="127.33333333333331">Type</th><th width="98">Indexed</th><th width="132">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>False</td><td>stZVE</td><td>The amount of $ZVE emitted to the $ZVE rewards contract.</td></tr><tr><td>uint256</td><td>False</td><td>stJTT</td><td>The amount of $ZVE emitted to the $zJTT rewards contract.</td></tr><tr><td>uint256</td><td>False</td><td>stSTT</td><td>The amount of $ZVE emitted to the $zSTT rewards contract.</td></tr></tbody></table>

#### **`UpdatedExponentialDecayPerSecond()`**

Emitted during [#updateexponentialdecaypersecond](#updateexponentialdecaypersecond "mention")

```solidity
event UpdatedExponentialDecayPerSecond(uint256 oldValue, uint256 newValue);
```

<table><thead><tr><th width="127.33333333333331">Type</th><th width="98">Indexed</th><th width="132">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>False</td><td>oldValue</td><td>The old value of exponentialDecayPerSecond.</td></tr><tr><td>uint256</td><td>False</td><td>newValue</td><td>The new value of exponentialDecayPerSecond.</td></tr></tbody></table>
