# Developer Info

{% embed url="<https://excalidraw.com/#json=gOPXWWCvf-xDjD9-cCaRu,euacqFooCXWS2G-VC6H9WQ>" %}
INTERACTIVE ARCHITECTURE DIAGRAM
{% endembed %}

## Source Code&#x20;

<https://github.com/Y2K-Finance/Earthquake>

## Protocol Contracts

### Controller

Used by Keepers to trigger the events that condition the Vaults.&#x20;

**TriggerEndEpoch** => function that if the epoch has ended, will transfer the Premium Vault deposit to Collateral Vault, and close that epoch.

**TriggerDepeg** => function that if the epoch has not ended and the oracle reports a price lower than the Vault Market strike price, will swap Collateral vault deposits with Premium vault, and close that epoch.

**TriggerNullEpoch** => function that if, after the insurance epoch has begun and one of the Vault Markets has zero deposits, will allow everyone to withdraw their deposits has there is no possibility to resolve this Market.

### VaultFactory

[VaultV2](https://github.com/Y2K-Finance/Earthquake/blob/main/src/v2/VaultV2.sol) is a [SemiFungibleVault](https://github.com/Y2K-Finance/Earthquake/blob/main/src/v2/SemiFungibleVault.sol) token based on the ERC1155 standard. The position Id or `epochId` is now a hash composed of `(marketId, epochBegin, epochEnd)`, which can be deterministically computed using the [`getEpochId`](https://github.com/Y2K-Finance/Earthquake/blob/5827f82c9e79a87da5fb673d83423a8d1e5eed17/src/v2/VaultFactoryV2.sol#L433-L442) function on the [VaultFactoryV2](https://github.com/Y2K-Finance/Earthquake/blob/main/src/v2/VaultFactoryV2.sol) contract.

### **Deposit**&#x20;

Shares are minted 1 to 1, while depositAsset can be any ERC20 token as defined by the [VaultFactoryV2](https://github.com/Y2K-Finance/Earthquake/blob/main/src/v2/VaultFactoryV2.sol).

### **Withdraw**

Withdraw fee in V2 is deducted when the vault is settled. The user's entitlement is then calculated based on the percentage of shares they had in the Vault before the insurance epoch began.

### Carousel

[Carousel](https://github.com/Y2K-Finance/Earthquake/blob/main/src/v2/Carousel/Carousel.sol) inherits the [VaultV2](https://github.com/Y2K-Finance/Earthquake/blob/main/src/v2/VaultV2.sol) contract and introduces new functionalities: Rollovers, Queue Deposits, and Linear Information Tax.

### Rollovers&#x20;

Users can opt to rollover existing positions into the next available epoch using the [`enlistInRollover`](https://github.com/Y2K-Finance/Earthquake/blob/5827f82c9e79a87da5fb673d83423a8d1e5eed17/src/v2/Carousel/Carousel.sol#L227C5-L269) function, specifying the epochId, shares, and receiver. To cease rollovers, users can invoke the [`delistInRollover`](https://github.com/Y2K-Finance/Earthquake/blob/5827f82c9e79a87da5fb673d83423a8d1e5eed17/src/v2/Carousel/Carousel.sol#L274-L292C6) function. Pending rollovers can be minted by anyone calling the [`mintRollovers`](https://github.com/Y2K-Finance/Earthquake/blob/5827f82c9e79a87da5fb673d83423a8d1e5eed17/src/v2/Carousel/Carousel.sol#L371C14-L479) function during an active deposit window.&#x20;

### CarouselFactory

[CarouselFactory](https://github.com/Y2K-Finance/Earthquake/blob/5827f82c9e79a87da5fb673d83423a8d1e5eed17/src/v2/Carousel/CarouselFactory.sol) is an extension of the VaultV2Factory contract. It differs in the creation of markets and configuration of epochs which are handled through [createNewCarouselMarket](https://github.com/Y2K-Finance/Earthquake/blob/5827f82c9e79a87da5fb673d83423a8d1e5eed17/src/v2/Carousel/CarouselFactory.sol#L42C5-L132) and [createEpochWithEmissions](https://github.com/Y2K-Finance/Earthquake/blob/5827f82c9e79a87da5fb673d83423a8d1e5eed17/src/v2/Carousel/CarouselFactory.sol#LL156C14-L156C38) respectively.&#x20;

A significant improvement is that y2k emissions can now be configured and distributed within each epoch, eliminating the need for deploying an extra [StakingRewards](https://y2k-finance.gitbook.io/y2k-finance/products/earthquake/contracts-and-audits/system-architecture#stakingrewards) contract.

### Queue Deposits

V2 permits users to deposit at any time using the deposit function with an **`id` of `0`**. A QueueItem is minted and later redeemed for a position in the next epoch deposit window. Any party can call the [`mintDepositInQueue`](https://github.com/Y2K-Finance/Earthquake/blob/5827f82c9e79a87da5fb673d83423a8d1e5eed17/src/v2/Carousel/Carousel.sol#L298C5-L365) function during an active deposit window to redeem all stored QueueItems.
