> For the complete documentation index, see [llms.txt](https://y2k-finance.gitbook.io/y2k-finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://y2k-finance.gitbook.io/y2k-finance/products/earthquake-builder-program/builder-info/technical-overview-self-insured-vault-siv-contract.md).

# Technical Overview Self-Insured Vault (SIV) Contract

[Source Code<br>](https://github.com/Y2K-Finance/SelfInsuredVault)\
Self-Insured Vault - SIV

The Self Insured Vault (SIV) is a core contract of our system. When users deposit yield-bearing assets, they mint shares in the SIV while simultaneously transferring their assets to the specified YieldSource contract, which is the beneficiary of the yield generated by these assets.

During the deposit process into the subsequent epoch, the yield is harvested within the YieldSource contract and is then converted into the deposit asset of the Insurance provider.

### **Setup**:&#x20;

constructor args

| address \_paymentToken   | depositAsset of earthquake market, **note:** all added markets must have the same depositAsset                                                                          |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| address \_yieldSource    | prev deployed YieldSource contract that follows [`IYieldSource`](https://github.com/Y2K-Finance/SelfInsuredVault/blob/master/src/interfaces/IYieldSource.sol) interface |
| address \_emissionsToken | `InsuranceProviders` can emit additional Y2K emissions,                                                                                                                 |

**Role Assignment**: YieldSource should assign `SIV` as `owner`.&#x20;

### **Market Configuration**:&#x20;

The `addMarket` function lets the `owner` add new markets with weights. This directly influences how the SIV distributes the purchase amounts to various earthquake markets.

| address \_provider         | Address of Earthquake Insurance provider. V1, V2 and Carousel markets have different providers. |
| -------------------------- | ----------------------------------------------------------------------------------------------- |
| uint256 \_marketId         | MarketId of Earthquake market                                                                   |
| uint256 \_premiumWeight    | needs to be in ratio all weights (totalWeight)                                                  |
| uint256 \_collateralWeight | needs to be in ratio all weights (totalWeight)                                                  |

\*totalWeight = sum of all market weights (premium and collateral

### **Deposit Functionality**:&#x20;

The `deposit` function allows a user to deposit a **yield-bearing** **asset** into the SIV, which results in the minting of new shares for the user. The asset is then transferred to the YieldSource contract.

| uint256 amount   | amount of **yield-bearing** **asset** defined on YieldSource contract `sourceToken()` |
| ---------------- | ------------------------------------------------------------------------------------- |
| address receiver | receiver of shares minted                                                             |

### **Insurance Purchase**:&#x20;

The `purchaseInsuranceForNextEpoch` function can be called by the `owner` and is responsible for checking if there is an open deposit window, claiming yields from the Yield Source and finally initiating the insurance purchase process for all configured markets.&#x20;

### **Withdrawal Functionality**:&#x20;

The `withdraw` function lets a user withdraw their deposited `sourceToken`. It calculates the shares to be withdrawn based on the current total deposit and the user's share.

### **Claim Payouts**:&#x20;

The `claimPayouts` function lets a user claim their pending earthquake yield.

### **Claim Emission**:&#x20;

The `claimEmissions` function lets a user claim their pending earthquake emissions.

These functions serve as the backbone of the SIV contract and enable it to perform its role within the ecosystem. The ability to configure and purchase insurance epochs, manage market allocations, and handle deposits and withdrawals are all made possible through these functions.
