# ZivoeTranches.sol

## Introduction

This contract will facilitate ongoing liquidity provision to Zivoe tranches - Junior, Senior.

This contract will be permissioned by $zJTT and $zSTT to call mint().

This contract will support a whitelist for stablecoins to provide as liquidity.

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

#### State Variables

<table><thead><tr><th width="144.33333333333331">Type</th><th width="184">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>maxTrancheRatioBIPS</td><td>This ratio represents the maximum size allowed for junior tranche, relative to senior tranche. A value of 2,000 represent 20%, thus junior tranche at maximum can be 20% the size of senior tranche.</td></tr><tr><td>uint256</td><td>minZVEPerJTTMint</td><td>These two values control the min/max $ZVE minted per stablecoin deposited to ZivoeTranches.</td></tr><tr><td>uint256</td><td>maxZVEPerJTTMint</td><td>These two values control the min/max $ZVE minted per stablecoin deposited to ZivoeTranches.</td></tr><tr><td>uint256</td><td>lowerRatioIncentiveBIPS</td><td>Basis points ratio between zJTT.totalSupply():zSTT.totalSupply() for maximum rewards (affects above slope).</td></tr><tr><td>uint256</td><td>upperRatioIncentiveBIPS</td><td>Basis points ratio between zJTT.totalSupply():zSTT.totalSupply() for maximum rewards (affects above slope).</td></tr><tr><td>bool</td><td>tranchesUnlocked</td><td>Prevents contract from supporting functionality until unlocked.</td></tr><tr><td>bool</td><td>paused</td><td>Temporary mechanism for pausing deposits.</td></tr><tr><td>uint256</td><td>BIPS</td><td>Private constant, <code>10000</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")
* [#isjunioropen](#isjunioropen "mention") - Checks if stablecoins deposits into the Junior Tranche are open.
* [#rewardzvejuniordeposit](#rewardzvejuniordeposit "mention") - Returns the total rewards in $ZVE for a certain junior tranche deposit amount.
* [#rewardzveseniordeposit](#rewardzveseniordeposit "mention") - Returns the total rewards in $ZVE for a certain senior tranche deposit amount.

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

* [#pushtolocker](#pushtolocker "mention") - This pulls capital from the DAO, does any necessary pre-conversions, and escrows ZVE for incentives.
* [#depositjunior](#depositjunior "mention") - Deposit stablecoins into the junior tranche. Mints Zivoe Junior Tranche ($zJTT) tokens in 1:1 ratio.
* [#depositsenior](#depositsenior "mention") - Deposit stablecoins into the senior tranche. Mints Zivoe Senior Tranche ($zSTT) tokens in 1:1 ratio.
* [#switchpause](#switchpause "mention") - Pauses or unpauses the contract, enabling or disabling depositJunior() and depositSenior().
* [#updatelowerratioincentivebips](#updatelowerratioincentivebips "mention") - Updates the lower ratio between tranches for minting incentivization model.
* [#updatemaxtrancheratio](#updatemaxtrancheratio "mention") - Updates the maximum size of junior tranche, relative to senior tranche.
* [#updatemaxzveperjttmint](#updatemaxzveperjttmint "mention") - Updates the maximum $ZVE minted per stablecoin deposited to ZivoeTranches.
* [#updateminzveperjttmint](#updateminzveperjttmint "mention") - Updates the minimum $ZVE minted per stablecoin deposited to ZivoeTranches.
* [#updateupperratioincentivebips](#updateupperratioincentivebips "mention") - Updates the upper ratio between tranches for minting incentivization model.
* [#unlock](#unlock "mention") - Unlocks this contract for distributions, sets some initial variables.

[#events](#events "mention")

* [#juniordeposit](#juniordeposit "mention")
* [#seniordeposit](#seniordeposit "mention")
* [#updatedlowerratioincentivebips](#updatedlowerratioincentivebips "mention")
* [#updatedmaxtrancheratiobips](#updatedmaxtrancheratiobips "mention")
* [#updatedmaxzveperjttmint](#updatedmaxzveperjttmint "mention")
* [#updatedminzveperjttmint](#updatedminzveperjttmint "mention")
* [#updatedupperratioincentivebips](#updatedupperratioincentivebips "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; }
```

#### `isJuniorOpen()`

Checks if stablecoins deposits into the Junior Tranche are open.

```solidity
function isJuniorOpen(
    uint256 amount,
    address asset
) public view returns (bool open);
```

<table><thead><tr><th width="143.33333333333331">Type</th><th width="120">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>amount</td><td>The amount to deposit.</td></tr><tr><td>address</td><td>asset</td><td>The asset (stablecoin) to deposit.</td></tr></tbody></table>

*Returns*

<table><thead><tr><th width="148.33333333333331">Type</th><th width="121">Name</th><th>Description</th></tr></thead><tbody><tr><td>bool</td><td>open</td><td>Will return "true" if deposits into the Junior Tranche are open.</td></tr></tbody></table>

#### `rewardZVEJuniorDeposit()`

Returns the total rewards in $ZVE for a certain junior tranche deposit amount.

```solidity
function rewardZVEJuniorDeposit(
    uint256 deposit
) public view returns (uint256 reward);
```

<table><thead><tr><th width="143.33333333333331">Type</th><th width="120">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>deposit</td><td>The amount supplied to the junior tranche.</td></tr></tbody></table>

*Returns*

<table><thead><tr><th width="148.33333333333331">Type</th><th width="121">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>reward</td><td>The rewards in $ZVE to be received.</td></tr></tbody></table>

#### `rewardZVESeniorDeposit()`

Returns the total rewards in $ZVE for a certain senior tranche deposit amount.

```solidity
function rewardZVESeniorDeposit(
    uint256 deposit
) public view returns (uint256 reward);
```

<table><thead><tr><th width="143.33333333333331">Type</th><th width="120">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>deposit</td><td>The amount supplied to the senior tranche.</td></tr></tbody></table>

*Returns*

<table><thead><tr><th width="148.33333333333331">Type</th><th width="121">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>reward</td><td>The rewards in $ZVE to be received.</td></tr></tbody></table>

## Write Functions

#### `pushToLocker()`

This pulls capital from the DAO, does any necessary pre-conversions, and escrows ZVE for incentives.

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

<table><thead><tr><th width="178.33333333333331">Type</th><th width="177">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>asset</td><td>The asset to pull from the DAO.</td></tr><tr><td>address</td><td>amount</td><td>The amount of asset to pull from the DAO.</td></tr><tr><td>bytes</td><td>data</td><td>Accompanying transaction data.</td></tr></tbody></table>

#### `depositBoth()`

Deposit stablecoins to both tranches simultaneously

```solidity
function depositBoth(
    uint256 amountSenior, 
    address assetSenior, 
    uint256 amountJunior, 
    address assetJunior
) external;
```

<table><thead><tr><th width="122">Type</th><th width="173.66666666666669">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>amountSenior</td><td>The amount to deposit to senior tranche</td></tr><tr><td>address</td><td>assetSenior</td><td>The asset to deposit to senior tranche</td></tr><tr><td>uint256</td><td>amountJunior</td><td>The amount to deposit to senior tranche</td></tr><tr><td>address</td><td>assetJunior</td><td>The asset to deposit to senior tranche</td></tr></tbody></table>

#### `depositBothInverse()`

Deposit stablecoins to both tranches simultaneously, inverse order

```solidity
function depositBothInverse(
    uint256 amountSenior, 
    address assetSenior, 
    uint256 amountJunior, 
    address assetJunior
) external;
```

<table><thead><tr><th width="122">Type</th><th width="173.66666666666669">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>amountSenior</td><td>The amount to deposit to senior tranche</td></tr><tr><td>address</td><td>assetSenior</td><td>The asset to deposit to senior tranche</td></tr><tr><td>uint256</td><td>amountJunior</td><td>The amount to deposit to senior tranche</td></tr><tr><td>address</td><td>assetJunior</td><td>The asset to deposit to senior tranche</td></tr></tbody></table>

#### `depositJunior()`

Deposit stablecoins into the junior tranche. Mints Zivoe Junior Tranche ($zJTT) tokens in 1:1 ratio.

```solidity
function depositJunior(
    uint256 amount, 
    address asset
) external notPaused nonReentrant;
```

<table><thead><tr><th width="122">Type</th><th width="173.66666666666669">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>amount</td><td>The amount to deposit.</td></tr><tr><td>address</td><td>asset</td><td>The asset (stablecoin) to deposit.</td></tr></tbody></table>

Emits the [#juniordeposit](#juniordeposit "mention") event

#### `depositSenior()`

Deposit stablecoins into the senior tranche. Mints Zivoe Senior Tranche ($zSTT) tokens in 1:1 ratio.

```solidity
function depositSenior(
    uint256 amount, 
    address asset
) external notPaused nonReentrant;
```

<table><thead><tr><th width="127.66666666666669">Type</th><th width="147">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>amount</td><td>The amount to deposit.</td></tr><tr><td>asset</td><td>asset</td><td>The asset (stablecoin) to deposit.</td></tr></tbody></table>

Emits the [#seniordeposit](#seniordeposit "mention") event

#### `switchPause()`

Pauses or unpauses the contract, enabling or disabling depositJunior() and depositSenior().

```solidity
function switchPause() external;
```

#### `updateLowerRatioIncentiveBIPS()`

Updates the lower ratio between tranches for minting incentivization model.

```solidity
function updateLowerRatioIncentiveBIPS(
    uint256 _lowerRatioIncentiveBIPS
) external onlyGovernance;
```

<table><thead><tr><th width="127.66666666666669">Type</th><th width="235">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>_lowerRatioIncentiveBIPS</td><td>The lower ratio to incentivize minting.</td></tr></tbody></table>

Emits the [#updatedlowerratioincentivebips](#updatedlowerratioincentivebips "mention") event

#### `updateMaxTrancheRatio()`

Updates the maximum size of junior tranche, relative to senior tranche.

```solidity
function updateMaxTrancheRatio(uint256 ratio) external onlyGovernance;
```

<table><thead><tr><th width="127.66666666666669">Type</th><th width="147">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>ratio</td><td>The new ratio value.</td></tr></tbody></table>

Emits the [#updatedmaxtrancheratiobips](#updatedmaxtrancheratiobips "mention") event

#### `updateMaxZVEPerJTTMint()`

Updates the maximum $ZVE minted per stablecoin deposited to ZivoeTranches.

```solidity
function updateMaxZVEPerJTTMint(uint256 max) external onlyGovernance;
```

<table><thead><tr><th width="127.66666666666669">Type</th><th width="147">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>max</td><td>Maximum $ZVE minted per stablecoin.</td></tr></tbody></table>

Emits the [#updatedmaxzveperjttmint](#updatedmaxzveperjttmint "mention")

#### `updateMinZVEPerJTTMint()`

Updates the minimum $ZVE minted per stablecoin deposited to ZivoeTranches.

```solidity
function updateMinZVEPerJTTMint(uint256 min) external onlyGovernance;
```

<table><thead><tr><th width="127.66666666666669">Type</th><th width="147">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>min</td><td>Minimum $ZVE minted per stablecoin.</td></tr></tbody></table>

Emits the [#updatedminzveperjttmint](#updatedminzveperjttmint "mention") event

#### `updateUpperRatioIncentiveBIPS()`

Updates the upper ratio between tranches for minting incentivization model.

```solidity
function updateUpperRatioIncentiveBIPS(
    uint256 _upperRatioIncentiveBIPS
) external onlyGovernance;
```

<table><thead><tr><th width="127.66666666666669">Type</th><th width="227">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>_upperRatioIncentivBIPS</td><td>The upper ratio to incentivize minting.</td></tr></tbody></table>

Emits the [#updatedupperratioincentivebips](#updatedupperratioincentivebips "mention") event

#### `unlock()`

Unlocks this contract for distributions, sets some initial variables.

```solidity
function unlock() external;
```

## Events

#### **`JuniorDeposit()`**

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

```solidity
event JuniorDeposit(
    address indexed account, 
    address indexed asset, 
    uint256 amount, 
    uint256 incentives
);
```

<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>address</td><td>True</td><td>account</td><td>The account depositing stablecoins to junior tranche.</td></tr><tr><td>address</td><td>True</td><td>asset</td><td>The stablecoind deposited.</td></tr><tr><td>uint256</td><td>False</td><td>amount</td><td>The amount of stablecoins deposited.</td></tr><tr><td>uint256</td><td>False</td><td>incentives</td><td>The amount of incentives ($ZVE) distributed.</td></tr></tbody></table>

#### **`SeniorDeposit()`**

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

```solidity
event SeniorDeposit(
    address indexed account, 
    address indexed asset, 
    uint256 amount, 
    uint256 incentives
);
```

<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>address</td><td>True</td><td>account</td><td>The account depositing stablecoins to senior tranche.</td></tr><tr><td>address</td><td>True</td><td>asset</td><td>The stablecoind deposited.</td></tr><tr><td>uint256</td><td>False</td><td>amount</td><td>The amount of stablecoins deposited.</td></tr><tr><td>uint256</td><td>False</td><td>incentives</td><td>The amount of incentives ($ZVE) distributed.</td></tr></tbody></table>

#### **`UpdatedLowerRatioIncentiveBIPS()`**

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

```solidity
event UpdatedLowerRatioIncentiveBIPS(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 lowerRatioJTT.</td></tr><tr><td>uint256</td><td>False</td><td>newValue</td><td>The new value of lowerRatioJTT.</td></tr></tbody></table>

#### **`UpdatedMaxTrancheRatioBIPS()`**

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

```solidity
event UpdatedMaxTrancheRatioBIPS(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 maxTrancheRatioBIPS.</td></tr><tr><td>uint256</td><td>False</td><td>newValue</td><td>The new value of maxTrancheRatioBIPS.</td></tr></tbody></table>

#### **`UpdatedMaxZVEPerJTTMint()`**

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

```solidity
event UpdatedMaxZVEPerJTTMint(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 maxZVEPerJTTMint.</td></tr><tr><td>uint256</td><td>False</td><td>newValue</td><td>The new value of maxZVEPerJTTMint.</td></tr></tbody></table>

#### **`UpdatedMinZVEPerJTTMint()`**

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

```solidity
event UpdatedMinZVEPerJTTMint(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 minZVEPerJTTMint.</td></tr><tr><td>uint256</td><td>False</td><td>newValue</td><td>The new value of minZVEPerJTTMint.</td></tr></tbody></table>

#### **`UpdatedUpperRatioIncentiveBIPS()`**

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

```solidity
event UpdatedUpperRatioIncentiveBIPS(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 upperRatioJTT.</td></tr><tr><td>uint256</td><td>False</td><td>newValue</td><td>The new value of upperRatioJTT.</td></tr></tbody></table>
