# Architecture

Each daily “Lotry” cycle involves the deployment of a new token instance, open trading, and a fully on-chain winner selection process. All orchestrated through automated scripts and decentralized randomness.

***

#### **Daily Token Lifecycle**

* A new **Lotry token** is deployed **every 23 hours and 45 minutes**, marking the beginning of a fresh draw cycle.
* A **cron job** triggers the Lotry API, which interacts with the **Token Launchpad Contract** to deploy the new daily token.
* The newly deployed token has a **total supply of 1,000,000,000 (1B)**, made available on a **bonding curve** for trading.
* Users can **buy, hold, or sell** tokens anytime during the active draw period.
* Token trading remains open **until the draw cutoff**, after which no further transactions are allowed for that cycle.

***

#### **Winner Selection Process**

At the end of each cycle, a **second cron job** initiates the draw by calling the **Winner Selection Contract.**

This contract integrates with **Chainlink VRF (Verifiable Random Function)** to ensure an unbiased and tamper-proof random number generation process.

***

#### **Mathematical Logic of Winner Picking**

Let there be **n** wallets participating in the draw, where each wallet ( i ) holds ( W\_i ) tokens.

The **total circulating tokens** in the pool is:

$$
T = \sum\_{i=1}^{n} W\_i
$$

An **index array** is conceptually constructed to represent every token held in the system, arranged sequentially according to wallet ownership:

$$
\begin{aligned} \[0, 1, 2, \dots, W\_1 - 1] &\rightarrow \text{Wallet}\_1 \ \[W\_1, W\_1 + 1, \dots, W\_1 + W\_2 - 1] &\rightarrow \text{Wallet}2 \ &\vdots \ \left\[\sum{i=1}^{n-1} W\_i, \dots, T - 1\right] &\rightarrow \text{Wallet}\_n \end{aligned}
$$

#### **Example;**

If three wallets are holding 10, 25, and 50 tokens respectively:

| Wallet | Tokens Held | Assigned Range |
| ------ | ----------- | -------------- |
| W₁     | 10          | \[0 – 9]       |
| W₂     | 25          | \[10 – 34]     |
| W₃     | 50          | \[35 – 84]     |

A random number ( R ) is requested from **Chainlink VRF**.

The winner is determined as follows:

$$
\text{Winning Index} = R \bmod T
$$

The wallet whose assigned range contains the **Winning Index** is declared the **winner**.

For example, if ( R = 162 ) and ( T = 85 ):

$$
\text{Winning Index} = 162 \bmod 85 = 77
$$

Since **77** lies in W₃’s range, **Wallet 3** is the winner.

This ensures that **the probability of winning is directly proportional to the number of tokens held**, providing a fair, mathematically verifiable selection mechanism.

***

#### **Reward Distribution**

Once the winner is selected:

* **89%** of the total tax pool (accumulated from the 11% buy/sell tax) is distributed to the **winner**.
* The remaining 11\*\*%\*\* is allocated to the **protocol treasury** for sustainability, liquidity, and development.

The **remaining liquidity** in the bonding curve is proportionally distributed among all other token holders (excluding the winner) based on their holdings:

$$
\text{$LOTRY Received by User} = \text{Total Liquidity} \times \frac{\text{User Tokens}}{\text{Total Circulating Tokens}}
$$

***

#### **Automation Workflow**

All processes in the Lotry.fun ecosystems are **fully automated** and **executed sequentially**:

1. **Cron Job 1:** Deploys the daily Lotry token from the Launchpad Contract.
2. **Active Phase:** Users trade tokens on the bonding curve throughout the draw period.
3. **Cron Job 2:** Triggers the Winner Selection Contract post draw period.
4. **Randomness Request:** Fetches a verifiable random number from Chainlink VRF.
5. **Winner Determination:** Calculates the winning index and selects the winner.
6. **Reward Distribution:** Automatically disburses $LOTRY and liquidity according to the distribution logic.


---

# 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.lotry.fun/what-is-this-tech-anyways/architecture.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.
