# Smart Contract

The smart contracts are deployed in an **EVM environment** and can only be called by Sequencers.

<figure><img src="/files/YXgoeoIcf4FCtHndBm0r" alt=""><figcaption></figcaption></figure>

### **Key Components**

**Relay Contract**

* The relay contract is responsible for handling sequencer requests.
* It stores these requests separately and ensures that consensus is reached.
* Once consensus is achieved, the relay contract forwards the request to the Bitcoinstate contract.

**Bitcoinstate Contract**

* This contract tracks user data, specifically the **liquidity provider (LP) positions** of each user.
* It parses the request data into a **Uniswap-compatible format**.
* The contract then interacts with Uniswap V3 by calling the appropriate functions and handling the response.

**Uniswap V3 Contract**

* The final contract in the flow is the Uniswap V3 contract, which processes the request sent from the Bitcoinstate contract.
* It executes the necessary actions related to liquidity provisioning or trading.

The contract is the core of the Sequencer node, responsible for validating and storing protocol state. Below is the `calldata` structure for the **Relay contract**.

```solidity
struct CSMessageRequestV2 {
    string from; // bitcoin address
    string to; // bitcoin state contract address
    uint256 sn; // sequence number
    int messageType; // message type
    bytes data; // uniswap v3 calldata
    string[] protocols; // validator addresses 
}

```

The contract is triggered at step (3) in [**RadFi Sequencer Interaction**](/sequencer.md), which will verify and update the contract state based on a user request.

### **Flow Overview**

The **Relay Contract** forwards requests → **Bitcoinstate Contract** processes & formats data → Calls **Uniswap V3 Contract** for execution.

This setup ensures a structured, validated, and efficient interaction between Bitcoin state tracking and Uniswap V3 liquidity operations.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.radfi.co/smart-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
