> For the complete documentation index, see [llms.txt](https://kerneldao.gitbook.io/kernel/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kerneldao.gitbook.io/kernel/getting-started/kernel-deprecated/smart-contracts/technical-overview.md).

# Technical Overview

This document provides a technical overview of the **Kernel** smart contract system, which facilitates token deposits and withdrawals to BEP20 asset-specific vaults.

The system is designed to manage user balances securely and efficiently via a **StakerGateway** acting as a mediator between the users and the **Vaults**.

This architecture supports a wide range of assets and ensures flexibility and security for all interactions.

**Table of Contents**

* [Actors](https://github.com/Kelp-DAO/kernel-smart-contracts-public#actors)
* [Contracts](https://github.com/Kelp-DAO/kernel-smart-contracts-public#contracts)

***

## Actors

1. **User**: Can stake and unstake suported assets
2. **StakerGateway**: User's entrypoint, permits staking and unstaking
3. **KernelVault**: Manages users' deposits for each asset handled by the protocol

***

## Contracts

#### **1. StakerGateway.sol**

The `StakerGateway` is the contract that interfaces directly with users, enabling them to stake and unstake tokens to and from the protocol. It acts as the intermediary that ensures proper authorization and routing of transactions between users and vaults.

**Key Features**

* **Stake**: User can stake an asset by depositing tokens into the related Vault
* **Unstake**: Facilitates the unstaking of an asset by withdrawing tokens from the vault, ensures user eligibility and transfers tokens back to the user

**Flows**

1. **Staking**
   1. User calls `stake()` function to stake an asset
   2. The `StakerGateway` transfers the tokens from `User` to the `KernelVault` responsible for the specific asset
   3. `KernelVault` increases `User`'s balance
2. **Untaking**
   1. User calls `unstake()` function to stake an asset
   2. The `StakerGateway` transfers the tokens from the `KernelVault` responsible for the specific asset to `User`
   3. `KernelVault` decreases `User`'s balance

### **2. KernelVault.sol**

The `KernelVault` is responsible for tracking the token balance of users within the system. It offers functionality for deposits and withdrawals and ensures that only `StakerGateway` can interact with the vaults.

One **KernelVault** is deployed for each asset. Vaults are deployed using the Beacon proxy pattern.

**Key Features**

* **Deposit**: User can deposit tokens until the vault reaches a pre-defined limit, increasing his balance
* **Withdraw**: User can withdraw tokens from the Vault, decreasing his balance

**Security Considerations**

* Only `StakerGateway` can call `KernelVault.sol`'s functions, ensuring secure and controlled access
* User balances are securely stored within the vault, preventing unauthorized access or manipulation

#### **3. AssetRegistry.sol**

`AssetRegistry` manages the mapping of assets to their respective vaults. It stores information on supported assets and ensures that the system only processes transactions for valid asset-vault pairs.

**Key Features**

* **Asset-to-Vault Mapping**: Keeps track of the vault associated with each supported asset
* **Asset Validation**: Ensures that only supported assets are processed in the system

#### **4. KernelConfig.sol**

`KernelConfig` handles the overall configuration of the protocol, including role-based access control and functionalities pausing.

The contract allows pausing of `Deposits to all Vaults` or `Withdrawals from all Vaults` independently, or pausing `all users' functions at the same time at protocol level`.

**Key Roles**

* **Admin**: Manages roles and perform critical tasks
* **Manager**: Responsible for managing system configurations, such as adding vaults and assets
* **Pauser**: Has the ability to pause the entire protocol or some specific features like deposit and withdrawa in case of emergency


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://kerneldao.gitbook.io/kernel/getting-started/kernel-deprecated/smart-contracts/technical-overview.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
