# Bittery Integration

## Bittery Action Widget

```
https://partner.b14g.xyz/ibittery
```

## Bittery Stats API

This part outlines the API endpoints and data structures for retrieving information related to the current Bittery staking round.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfUmd9z-KU8AEn1uIJV2EG-5BjzJn1o9FPLGMn4nHHN5q1xRkRJWcPoALbVYBo6Rs87WvXbN8dFn9FRg2-9WRmdckjhzdUe5xl5OXUDXKl9WFG2hk8Ia4Ja3X88YxKCG7Y4DxpkqQ?key=AK1VBLgdFStfsKG5ay5BgA" alt=""><figcaption></figcaption></figure>

### 1. Get Total BTC Deposited

**API:**

```
https://api-staging.b14g.xyz/restake/middleware/lottery/current-round
```

**Example Response:**

```
{
  "timestamp": "1744380781",
  "round": "2",
  "startDate": "1744603223",
  "users": [
    {
      "address": "0x8a9570448d28d24219f83cc2f87ab55ccf35e437",
      "totalReward": "0",
      "totalBtc": "500000"
    },
    {
      "address": "0x83b7a3930b509a2f0c9e9de4e39ceefc4ac08e47",
      "totalReward": "0",
      "totalBtc": "1000"
    }
  ],
  "receivers": [
     ],
  "totalReward": "24953207489908548"
}
```

The users array contains a list of participants. Each user object includes:

* `address`: The Ethereum address of the user.
* `totalBtc`: The total amount of BTC deposited by the user in this round (unit: wei).

To calculate the total BTC deposited across all participants in the current round, sum the totalBtc values from each element within the users array.

Based on the example response above:

```
Total BTC Deposited (wei) = 500000 + 1000 = 501000
Total BTC Deposited = 501000 / 1e8 = 0.00501 BTC
```

### 2. Get Total Reward

**API:**

```
https://api-staging.b14g.xyz/restake/middleware/lottery/current-round
```

**Example Response:**

```
{
  "timestamp": "1744380781",
  "round": "2",
  "startDate": "1744603223",
  "users": [
  ],
  "receivers": [
  ],
  "totalReward": "24953207489908548"
}
```

The `totalReward` field represents the estimated total reward for the current round (unit: wei).

Based on the example response above:

```
Total Reward (wei) = 24953207489908548
Total Reward = 24953207489908548 / 1e18 = 0.0224953207489908548 CORE
```

### 3. Get User Reward Contributions

**API:**

```
https://api-staging.b14g.xyz/restake/middleware/lottery/list-yieldBtc/${address}
```

**Example Response:**

```
{
  "yieldBtcs": [],
  "depositedYieldBtcs": [
    {
      "isDeposited": true,
      "tokenId": "25",
      "order": {
        "btcAmount": "100000",
        "roundReward": "10297279194593749",
         ...
      }
    },
    {
      "isDeposited": true,
      "tokenId": "28",
      "order": {
        "btcAmount": "100000",
        "roundReward": "10297279194593749",
        ...
      }
    },
     ],
 "pendingReceivers": [],
  "totalBtcDeposited": "500000"
}
```

This API returns a list of the user's deposited BTC contributions (depositedYieldBtcs). Each element in the `depositedYieldBtcs` array represents a deposit and includes details such as the deposited `btcAmount` and the corresponding `roundReward` for that deposit (unit: wei).

To calculate the total reward contributions for a specific user, sum the `roundReward` values from each element within the `depositedYieldBtcs` array.

Based on the example response above:

```
User Reward Contributions (wei) = 10297279194593749 + 10297279194593749 = 20594558389187498
User Reward Contributions = 20594558389187498 / 1e18 = 0.02059455838 CORE
```

### 4. Calculate Win Chance

The win chance can be estimated by dividing the `Total Reward` by the `User Reward Contributions`.

**Formula:**

```
Win Chance = Total Reward / User Reward Contributions
```

Using the example values from above:

```
Win Chance ≈ 0.0224953207489908548 CORE / 0.02059455838 CORE ≈ 1.09
```

This can be interpreted as approximately a **1 in 1.09** chance.

### 5. Get User BTC Deposited

**API:**

```
https://api-staging.b14g.xyz/restake/middleware/lottery/list-yieldBtc/${address}
```

**Example Response:**

```
{
  "yieldBtcs": [],
  "depositedYieldBtcs": [],
  "pendingReceivers": [],
  "totalBtcDeposited": "500000"
}
```

This API returns details of a specific user's BTC deposits. The `totalBtcDeposited` field represents the total amount of BTC deposited by the user across all their contributions in the current round (unit: wei).

Based on the response above:

```
User BTC Deposited (wei) = 500000
User BTC Deposited = 500000 / 1e8 = 0.005 BTC
```


---

# 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.b14g.xyz/bittery-integration.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.
