---
description: How vaults work from infrastructure point of view
---

# Vaults Infrastructure

Two vaults (JLP and USDC) under Adrastea protocol have been developed in tandem. \
\
Core accounts:\
Program [BgFH1pBWFzbkDARiJPYDMMwTTzAyTGB7DFJBxfbQWYub](https://solscan.io/account/BgFH1pBWFzbkDARiJPYDMMwTTzAyTGB7DFJBxfbQWYub)\
mainAccount [3EGAW8esSxjeA2CGfjj6wPhY85ruiQ31ZXbqKuQ7yqYF](https://solscan.io/account/3EGAW8esSxjeA2CGfjj6wPhY85ruiQ31ZXbqKuQ7yqYF)\
protocolVault [5UdVUMca5sufDcZukjXFK1mACamiPeTwEagSjaR75M3C](https://solscan.io/account/5UdVUMca5sufDcZukjXFK1mACamiPeTwEagSjaR75M3C)\
revenueVault [6NLwik12ShL2Sm54zFTBa64MUPoHNbAdiebXVg8BS4TL](https://solscan.io/account/6NLwik12ShL2Sm54zFTBa64MUPoHNbAdiebXVg8BS4TL)

Core instructions of leverage strategy:\
\- Deposit JLP\
\- Deposit USDC\
\- Profit fixing and redistribution\
\- Withdraw JLP\
\- Withdraw USDC\
\- Liquidations\
\
Let's start going one by one:

#### 1. Deposit JLP

When a user connects their wallet to the Adrastea website and links their social accounts during the beta phase, Adrastea verifies the presence of specific ‘allow’ roles in Discord to authorize deposits. Upon successful verification, the user is permitted to deposit JLP.

_This entire process is seamlessly executed in a single transaction:_

* The deposited JLP tokens are transferred to the ‘main\_account.’
* The program records this deposit as collateral and, based on a target leverage of 2x, calculates the maximum leverage available for borrowing.
* The program then deploys liquidity from the USDC pool to purchase JLP via an on-chain swap on Meteora, adhering to the maximum allowable slippage parameters.
* The protocol stores the final actual swap price on-chain in the ‘jlp\_ledger,’ where the user’s ‘position entry price’ is represented as one of the holders record.\
  \
  This completes the JLP deposit process.

<figure><img src="https://4012794114-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrTRqEWBPVZMIlDFMDkcf%2Fuploads%2FaiX002s0cgWPVt4Si5eT%2FBrainstorming%20-%20Frame%201%20(1).jpg?alt=media&#x26;token=b16d90bc-4391-4778-9ff5-3b6238f673aa" alt=""><figcaption><p>diagram for deposit JLP process </p></figcaption></figure>

#### 2. Deposit USDC

When a user connects their wallet to the Adrastea website and links their social accounts during the beta phase, Adrastea verifies the presence of specific ‘allow’ roles in Discord to authorize deposits. Upon successful verification, the user is permitted to deposit USDC.\
\
&#xNAN;_&#x54;his entire process is seamlessly executed in a single transaction:_

* The program transfers USDC to the ‘main\_account.’
* The user’s USDC deposit is recorded in the ‘USDC\_ledger.’
* The main program checks the “JLP\_Ledger” and reviews user records to identify if any user requires leverage to be bought and the amount needed.

If **no** leverage is needed, the USDC deposit process completes.

If leverage is needed:

*   The program initiates a swap for the total amount of leverage required for the user.\
    To identify the leverage needed, the program uses specific variables and a formula.\
    \
    Variables:\


    ```
    P_i : The current position in JLP of the i-th user.
    \lambda_t : The target leverage ratio. (2x as of current protocol setup)
    \lambda_{c,i} : The current leverage amount in JLP for the i-th user.
    N : The total number of users in the JLP ledger.
    ```

Formula:

$$
\sum_{i=1}^{N} \Delta L_i = \sum_{i=1}^{N} \left( \left( P_i \cdot \lambda_t \right) - \lambda_{c,i} \right)
$$

* The swap is performed through the Meteora on-chain program under ‘acceptable’ slippage terms.
* The received JLP after the swap is distributed and recorded in the ‘jlp\_ledger’ by the program according to each user’s JLP needs to reach the target leverage.

The USDC deposit process then completes.

<figure><img src="https://4012794114-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrTRqEWBPVZMIlDFMDkcf%2Fuploads%2FHoZVJ0WPgIGJh30UE88q%2FBrainstorming%20-%20Frame%202.jpg?alt=media&#x26;token=1630aaee-8e2b-4870-b3f8-95b4a18742f1" alt=""><figcaption><p>diagram for deposit USDC process </p></figcaption></figure>

#### 3. Profit fixing and redistribution

When the JLP price grows, profits are established on the leverage position and are ready to be distributed among JLP depositors, USDC depositors, and the Protocol.

*   The program reviews the jlp\_ledger and checks the delta between the last dynamic benchmark price or the position open price and the current JLP price for the leveraged JLP. If the delta is positive, the program sums up the total positive delta for all users.\
    \
    Variables:\


    ```
    P_{\text{current}}  be the current JLP price.
    P_{\text{benchmark}, i}  be the last dynamic benchmark price or position open price. for user  i .
    \Delta_i  be the delta for user i in jlp_ledger.
    \Delta_{\text{total}}  be the total positive delta for all users in jlp ledger.
    ```

For each user i :

$$
\Delta_i = P_{\text{current}} - P_{\text{benchmark}, i}
$$

If \Delta\_i > 0 , it is included in the total delta:

$$
\Delta_{\text{total}} = \sum_{i=1}^{n} \max(\Delta_i, 0)
$$

* The program virtually converts the sum of the positive delta into USDC value. Based on the protocol’s utilization, the exact yield share is determined for the USDC vault and the JLP vault. A portion of the yield share goes to the protocol itself.

```
Total Yield - USDC Yield Share - Protocol Yield Share = JLP Yield Share
```

During the beta phase, the protocol does not earn any yield share.

* The program then virtually converts the positive delta back into JLP from the USDC value.
* The JLP to USDC swap is performed through the Meteora on-chain program under ‘acceptable’ slippage terms.
* The received tokens are redistributed / recorded in the jlp\_ledger and usdc\_ledger according to the protocol’s yield share distribution.
* JLP holders who generated profits are updated with a new dynamic benchmark price based on the swap price.

Profit fixing and redistribution completes.

<figure><img src="https://4012794114-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrTRqEWBPVZMIlDFMDkcf%2Fuploads%2FpmKhKPVDbXtXm4Ppscpu%2FBrainstorming%20-%20Frame%203.jpg?alt=media&#x26;token=8f7e488c-6b39-4f83-b521-d664c71bf592" alt=""><figcaption><p>diagram for profit fixing and redistribution process </p></figcaption></figure>

#### 4. Withdraw JLP

_This entire process is seamlessly executed in a single transaction._\
\
During a withdrawal request by a user, the program checks if the user has enough leverage value to close the position without incurring a loss. Losses can occur due to two main reasons:\
\
1\. The leverage value has decreased since the position was opened or new leverage was bought.\
2\. Slippage on the swap of leverage to return funds to the USDC vault.\
\
If a loss is identified, a portion of the user’s collateral must be sold to compensate USDC providers for the loss on their supplied funds.

{% hint style="info" %}
If the user’s position has earned enough profit to cover the losses, the program will use the profits to compensate for the losses. However, if the profits are insufficient, the program will sell part of the user’s collateral to cover the losses.
{% endhint %}

The JLP to USDC swap is performed through the Meteora on-chain program under ‘acceptable’ slippage terms.\
\
After covering the position loss, the remaining JLP collateral is sent back to the user. If profits are still available to claim, the 'jlp\_ledger' record remains until the user claims the profits. If no profits are left, the 'jlp\_ledger' record of the user’s position is deleted.\
\
The JLP withdrawal process is then complete.

<figure><img src="https://4012794114-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrTRqEWBPVZMIlDFMDkcf%2Fuploads%2F8ZDs2qiXlJ8PL81Z3ARh%2FBrainstorming%20-%20Frame%204.jpg?alt=media&#x26;token=3b26005a-2254-4d74-85e1-85874226c2a9" alt=""><figcaption><p>diagram for JLP withdrawal process</p></figcaption></figure>



#### 5. Withdraw USDC

_This entire process is seamlessly executed in a single transaction._

The program checks if there is sufficient USDC liquidity available for withdrawal.

{% hint style="info" %}
Depending on the pool’s utilization ratio, not all liquidity may be withdrawable at once if the utilization is high. We have designed a 70% target utilization rate to ensure 30% of liquidity is available for withdrawal. This doesn’t indicate that the protocol has lost money or is insolvent; it simply means the liquidity is being utilized in the Leverage Vault. When available liquidity is low, the APY increases to attract more capital providers and achieve equilibrium. This mechanism is standard among lending protocols like Compound and Aave. Adrastea DAO will be able to adjust the utilization curve parameters to influence protocol behavior in unusual situations.
{% endhint %}

If Yes:

* The requested amount is transferred to the user.
* If the user has profits yet to claim, their record remains in the usdc\_ledger.
* If there are no profits to claim, the user’s record is deleted from the usdc\_ledger.

If no:

* The user cannot withdraw USDC at this moment, and the program will not allow the withdrawal.

<figure><img src="https://4012794114-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrTRqEWBPVZMIlDFMDkcf%2Fuploads%2Ffwjbm14YqvfxY51ra9GL%2FBrainstorming%20-%20Frame%205.jpg?alt=media&#x26;token=43e8ca5d-cfe5-4f84-92a4-9aa539084c45" alt=""><figcaption><p>diagram for USDC withdrawal process</p></figcaption></figure>

#### 6. Liquidations&#x20;

To ensure the security of USDC depositors, the protocol has developed liquidation scenarios.\
\
There are two types of liquidations:

1. Initiated by JLP User
2. Initiated by Protocol

Initiated by JLP User:

If a **user decides to close their position** while the JLP price has decreased, the protocol executes a partial liquidation of the collateral equivalent to the loss incurred on the leveraged position. This is done to return the full amount of debt to the USDC vault. A user **may choose to wait** for the JLP price to rise to avoid liquidating part of their collateral by closing the position at a specific time.\
\
Initiated by Protocol:

The protocol ensures that the debt owed to USDC depositors equals the JLP value held by the protocol. The team has conducted market back tests on the assets’ volatility in the JLP index, creating a virtual index and analyzing historical volatility and black swan events. Based on these tests, a target leverage of 2x was selected to minimize the risks of full liquidation. The protocol’s safe margin is set at 5% and will be reevaluated based on community and market feedback. In the event of a significant price drop in JLP that triggers a protocol-initiated liquidation, all collateral positions will be liquidated, and funds will be transferred to the USDC main account for depositors to claim.\
\


<figure><img src="https://4012794114-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrTRqEWBPVZMIlDFMDkcf%2Fuploads%2FHiYLWD3KJjVE3VyJMNMm%2FBrainstorming%20-%20Frame%205%20(1).jpg?alt=media&#x26;token=4ca6c649-c736-46c0-89a4-1f14335f1b4c" alt=""><figcaption><p>diagram for Liquidation process</p></figcaption></figure>



