Skip to main content

AllPairVault Contract

The file AllPairVault.sol contains most of the implementation for Vaults. Rather than create unique contract instances for each Vault, the state for all Vaults is stored in a mapping. Each Vault has a unique id number created by hashing the metadata on the Vault: asset pair, strategy contract, start time, investment time, and duration of product.


The deposit function is called by Liquidity Providers to transfer an asset for a single tranche in a specific Vault. The assets are transferred to the underlying Strategy contract. However, the funds are not invested yet. Instead, we maintain a queue of deposits to determine, at the moment we invest, how many of these deposits we can use. It's likely we can use all of one side, but only some of the other.


A Strategist is allowed to call the invest function once the open period has expired for new depositors. The function calls the underlying strategy contract to put the funds into the AMM. This is where the protocol calculates what the ratio of senior and junior assets are for this Vault. This function determines how much of the deposits can be used, marking the excess as available to be reclaimed.


After the Vault has been invested, we now know how much of all the deposits got into the Vault. Liquidity Providers call claim to (1) reclaim deposits that didn't get in, and (2) get tranche tokens representing their deposits that did get in. (It's possible an investor put in $1000, but only $600 get in.)


After the pre-defined duration for the Vault has expired, the strategist can now call redeem to convert the LP tokens to assets and rebalance the 2 tranches. The expected senior tranche is simply the percent earnings owed to the senior tranche. The underlying redeem function on the strategy contract will handle the logic for balancing the tranches.


After the redeem function has executed, the contract will be in Withdraw state. Now Liquidity Providers can burn their tranche tokens to collect their share of the tranche asset pool. We compute the fraction of the initial deposit for the investor, and return that fraction of the redeemed pool for the tranche.

depositLp & withdrawLp

At any time after a Vault has started, Liquidity Providers can add/remove LP tokens from the Vault directly. Adding LP tokens results in an equivalent ratio of senior and junior tranche tokens. Similarly, by burning senior and junior tranche tokens in the right ratio, Liquidity Providers can remove LP tokens from the Vault. This allows arbitrageurs to monitor prices of tranche tokens in secondary markets. If they are too high, inject LP tokens and sell tranche tokens into the market. If they are too low, buy the tranche tokens and redeem for LP tokens.