Metadata-Version: 2.4
Name: yiedl-ai
Version: 0.3.1
Summary: Programmaticaly interact with the yiedl machine learning competition
License: MIT License
        
        Copyright (c) 2022 Rocket Capital Investment
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/rocketcapital-ai/competition_submission
Project-URL: Documentation, https://docs.yiedl.ai/rci-competition
Project-URL: Changelog, https://github.com/rocketcapital-ai/competition_submission/CHANGELOG.md
Project-URL: Releases, https://github.com/rocketcapital-ai/competition_submission/releases
Project-URL: Discord, https://discord.com/invite/r6NbnCSrzn
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: base58>=2.1.1
Requires-Dist: requests>=2.32.3
Requires-Dist: web3>=7.7.0
Requires-Dist: pandas>=2.2.3
Requires-Dist: tqdm>=4.67.1
Requires-Dist: pyarrow>=23.0.0
Requires-Dist: fastparquet>=2025.12.0
Provides-Extra: test
Requires-Dist: pylint; extra == "test"
Requires-Dist: pytest; extra == "test"
Provides-Extra: v3
Requires-Dist: eciespy>=0.4.4; extra == "v3"
Requires-Dist: pycryptodome>=3.19; extra == "v3"
Dynamic: license-file


# Submission Script

 Please refer to `quickstart.ipynb` and this [accompanying guide](https://docs.yiedl.ai/rci-competition/data-scientists/getting-started-via-automated-submissions) as the main tutorial on submitting predictions programmatically.

## Python Version Requirement
```>= 3.11```

## Installation

    pip install yiedl-ai
# Daily competition (`yiedl.v3`)

The daily competition runs on HyperEVM. You stake YIEDL on a sealed prediction, and the SDK seals, submits and checks from your machine. The weekly competition above is separate and unchanged.

The **production daily competitions** are built in (deployed on HyperEVM on 27 Nov 2026): you stake real YIEDL. A key is all you set; `status()` shows `"network": "production"`. A round opens every day at 05:05 UTC and takes submissions until 00:00 UTC; it is scored on the prices of the 7 days from 05:00 UTC that day.

## How it fits together

- Your stake is held by a **subaccount**, a contract that belongs to you, the **owner** (your wallet). You create subaccounts, fund them and withdraw from them on the website's Daily page. An owner can have several subaccounts, one per model, numbered 1, 2, 3 in the order they were created.
- The SDK holds a **delegate** key, a separate key made on your machine. You give the SDK only that key: nothing else, not even your wallet's address.
- You link the key to your owner wallet once, with a **link string**: the SDK prints it, you paste it on the website's Daily page, and nothing goes back into the SDK. From then on the SDK reads from the chain which owner its key is linked to, and shows that owner's subaccounts only.
- The delegate key can submit, and take a submission back, through any of your subaccounts, choosing the stake up to the subaccount's free balance. It can never take tokens out: deposits and withdrawals are only done by the owner, on the website. With the registry's program of the subaccount additions (see "Creating subaccounts and moving balance"), it can also create subaccounts for you and move free balance between your own subaccounts.
- The delegate key pays the gas of what it sends, so its address needs some HYPE on HyperEVM. Before each transaction the node asks it to hold the gas limit times the top price, more than twice what it pays; the SDK checks this first and says "not enough HYPE for gas" with what it needs. `get_account()` shows how many submissions the gas covers (`gas_covers`).

## Quickstart

> Once installed, `python -m yiedl.v3.example` writes a ready script, `main.py`, with each step below as a small function to run one at a time (it never replaces a file already there).

**1. Install**

The SDK needs Python 3.11 or later. Check yours with `python3 --version`. On a Mac the built-in `python3` is 3.9, which is too old, and `python` and `pip` may not exist at all. Install into an environment, by either route:

With [uv](https://docs.astral.sh/uv/), which fetches the right Python itself:

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh    # once, if you do not have uv
uv venv --python 3.12
source .venv/bin/activate
uv pip install "yiedl-ai[v3]"
```

With pip, if you already have Python 3.11 or later:

```bash
python3.12 -m venv .venv
source .venv/bin/activate
pip install "yiedl-ai[v3]"
```

Run every step below in that same activated environment (on Windows: `.venv\Scripts\activate`). The Python you installed into must be the one you run with.

**2. Make the delegate key**

```bash
python -m yiedl.v3.keystore new my-delegate --save-password
```

`my-delegate` is a name of your choosing for this key. It asks for a new password twice, without showing it (choose a non-empty one), makes a new random key on your machine, locks it with the password in the SDK's own folder (`~/.yiedl/delegates`), and prints `delegate 1 (my-delegate)` and the key's address. The key itself is never shown. You never need the file's path: the SDK finds the key by its name.

Use `--save-password` so that your scripts do not have to type the password: it is for automation, such as a daily submission from cron, a scheduler or a server. The password is saved in `~/.yiedl/delegates`, next to the key (`1.password` for your first key), and works from any folder. `YiedlAPI(delegate="my-delegate", ...)` says in one line that it used it. Nothing is written to your project. With its password saved, the key is as good as unlocked for anyone who can read `~/.yiedl/delegates` (it still cannot take tokens out).

> To type the password at every run instead, leave out `--save-password`. Then each script asks for it, and none can start on its own. See "The key's password".

Run it in a real terminal. An IDE's Run window (PyCharm and others) cannot hide what you type, so there the command stops with "this needs a terminal that can hide what is typed": use the IDE's Terminal tab, or in PyCharm tick "Emulate terminal in output console" in the run configuration. The same applies whenever the SDK asks for the key's password.

Send a little HYPE to the address it printed: the key pays the gas of what it sends.

More than one delegate key, for example one per owner: run `new` again, and it makes delegate 2, and so on. A key can also have a name of your choice, `python -m yiedl.v3.keystore new alice --save-password`: 1 to 32 letters, digits, dashes and underscores, not a number, and not a name another key has (that is refused and nothing is written). `python -m yiedl.v3.keystore list` shows every key's number, name and address. Every command and `YiedlAPI` use delegate 1 unless told otherwise: `--delegate alice` (or `--delegate 2`) on a command, `delegate="alice"` (or `delegate=2`) in `YiedlAPI(...)`.

A key file made with an earlier version, at a path such as `~/yiedl-delegate.json`, can be brought in, with the SDK's note of its owner: `python -m yiedl.v3.keystore import ~/yiedl-delegate.json` (optionally with a name after the path). It asks for that file's password once, and keeps the same password. The file itself is left where it is.

**3. Make the link string**

```bash
python -m yiedl.v3.link make --delegate my-delegate
```

It prints the delegate key's address, until when the string is valid (one hour; `--minutes` sets another time, at most 7 days), and the string itself, which starts with `yiedl-secret-delegate-link:v1:`. By default the string is for both competitions, UpDown and Neutral; `--competition updown` or `--competition neutral` makes it for one only.

The string is a **secret** until it is used or expires: whoever holds it can link your key to an owner of their choosing. Paste it only on the website's Daily page, in your own browser, and do not send, save or share it. A new string, with a new one-time key inside, is made every time you run the command. If a string went anywhere else, cancel every string of this key that was not used with `python -m yiedl.v3.link revoke --delegate my-delegate` (this needs HYPE on the key's address for gas).

From code: `api.make_link_string().text` (see step 5 for `api`).

**4. Paste it on the website's Daily page**

Paste the string on the website's Daily page. Nothing goes back into the SDK.

**5. Run the status, for a subaccount**

```python
from yiedl.v3 import CompetitionType, YiedlAPI

api = YiedlAPI(delegate="my-delegate", subaccount=1, competition_type=CompetitionType.UPDOWN)
print(api.status())          # linked or not, your owner, your subaccounts and their balances
print(api.get_account())     # subaccount 1, your owner, its balances, your key's gas
```

The key is unlocked with its saved password, and `subaccount=1` is the subaccount to submit for, by its number.

Every `YiedlAPI` is for one competition, and you always say which: `CompetitionType.UPDOWN` or `CompetitionType.NEUTRAL` (the texts `"updown"` and `"neutral"` are the same). Left out, it is refused; none is chosen for you.

> Without a saved password, `YiedlAPI(...)` asks for the key's password instead, once per run.

`status()` says whether the key is linked yet (`linked`). If not, it says so and how to make a link string; it is cheap to call again while you wait. Once linked it shows your owner number and wallet, and every one of your subaccounts the key may submit for: its number, address, `free` and `locked` balance, and whether it has a submission in the open round. `python -m yiedl.v3.link status --delegate my-delegate` prints the same for both competitions.

The first time the SDK finds the owner its key is linked to, it writes that owner's number down in a small note beside the key's file (in the same folder; each delegate key has its own), and prints a line naming the owner's wallet. The note holds nothing secret. If the chain ever says the key is linked to another owner, the SDK stops (`OwnerChanged`) and signs nothing: the string or the key may have been taken. If you linked the key to another owner yourself, on purpose, clear the note with `python -m yiedl.v3.link forget-owner --delegate my-delegate` (or `api.forget_owner()`). If your owner moves to a new wallet on the website, the SDK prints a notice and goes on.

With only one subaccount the number can be left out; with several and none chosen, the SDK refuses and lists them; a number past the last is refused with the count. `api.for_subaccount(2)` gives the same object for subaccount 2, with the same key, already unlocked. Before anything is signed the SDK reads again which owner the key is linked to and holds it to the note, takes the subaccount's address from that owner's list on chain, and checks that it is one of this competition's and that your key may submit for it; otherwise it refuses, saying why.

For the Neutral competition, give `competition_type=CompetitionType.NEUTRAL` to `YiedlAPI(...)`; its subaccounts are its own. Use predictions whose longs and shorts cancel out there, for example BTC 0.2 and ETH -0.2: the Neutral scoring engine scores 0 any prediction whose sum is further from zero than 0.1% of its total size (the sum of the absolute values, `MISSING` left out), so the SDK refuses such a prediction before anything is sealed or sent, saying the sum, the total size and the sum allowed. The example file in step 7 does not cancel out and is refused there.

**6. Get the data**

Download the rolling weekly dataset, which is rebuilt every day:

```python
from yiedl.v3 import Datasets

dataset = Datasets.ROLLING_WEEKLY.download("data")   # suitable for the new daily competition; rebuilt every day, approx. 1 GB
```

Every file is checked against the server's checksum before you get it. If a download is interrupted, run the same call again: it continues where it stopped. A call whose data is already current says so and returns at once. The historical download needs over 23 GB free the first time (the zip and its unpacked copy side by side; the zip is deleted after).

**7. Submit**

Put your model's predictions in a CSV file with a `symbol` and a `prediction` column, one row for each asset you take a position in. An asset you leave out counts as 0. Only the assets you hold (values that are not 0) are sent, and the competition takes at most a set number of them per submission (`maxHeldAssets`, read from the chain); a prediction holding more is refused before anything is sent. To mark an asset as "no prediction" rather than 0, give the value `yiedl.v3.MISSING` (in a CSV, the number `-170141183460469231731687303715884105728`, which is -2^127); it is sent, and counts as held. The scores treat it as 0. A prediction that takes no position at all (every value 0 or `MISSING`, once written with 18 decimals) can never earn or lose anything, so it is refused in both competitions before anything is sent; to take a submission back, use `withdraw_submission()`:

```text
symbol,prediction
BTC,0.2
ETH,-0.1
```

Then submit the file. So that this step runs as it is, it waits for a round to open and writes a small demo file first:

```python
import time
from pathlib import Path

while not api.check_round_open():              # wait until a round is taking submissions
    print("no round open yet; checking again in 30 s")
    time.sleep(30)

round_num = api.get_current_round()            # the round that is open
print(api.round_details(round_num).symbols)    # the assets of this round, in order

# --- DEMO ONLY: this file stands in for your model's output. ---
# --- Replace it with your own predictions.csv.               ---
Path("predictions.csv").write_text("symbol,prediction\nBTC,0.2\nETH,-0.1\n")

api.upload_predictions("predictions.csv", stake=10)   # 10 YIEDL from the subaccount's free balance
print(api.submission_status())
```

The prediction is sealed for the subaccount's address, which is the staker, and the transaction goes to the subaccount, signed by the delegate key. `submission_status()` shows the round's number; keep it for step 8. Submitting again to the same round replaces your earlier submission, stake included; `withdraw_submission()` takes it back while the round is open.

A stake does not carry over to the next round. When its round settles, about seven days later, it goes back to the subaccount's free balance with its gain or loss, and is in play again only when a new submission stakes it. Until then it stays locked, so submitting every day keeps up to eight rounds' stake locked at once: to stake 10 a day, the subaccount needs about 80 YIEDL.

**8. Seven days later: check the result**

Run this once the round has been evaluated, about seven days after it opened. Until then `verify_round` says the round's key is not published yet.

```python
from yiedl.v3 import CompetitionType, YiedlAPI

api = YiedlAPI(delegate="my-delegate", subaccount=1, competition_type=CompetitionType.UPDOWN)
round_num = 1                          # replace 1 with the round number step 7 showed
print(api.verify_round(round_num))     # opens your submission and checks it against the contract
print(api.get_balance())               # free and locked
```

To take tokens out of a subaccount, use the website's Daily page: the SDK cannot.

## The datasets

Every Yiedl dataset is one fixed object in `Datasets`, described with no network call:

```python
from yiedl.v3 import Datasets

Datasets.show()                            # prints all six
Datasets.ROLLING_WEEKLY.description        # its text
Datasets.ROLLING_WEEKLY.published          # "Every day"
Datasets.ROLLING_WEEKLY.download("data")   # data/rolling_weekly_dataset/
```

The six are `LATEST`, `HISTORICAL`, `WEEKLY`, `DAILY`, `ROLLING_WEEKLY` and `ROLLING_DAILY`. Each `download` is checked against the server's checksum, resumes if interrupted, and unpacks a zip into a folder named after it (`unzip=False` keeps the zip). If the server does not offer a dataset when you call, `download` stops with a `DatasetDownloadError` that says so, and downloads nothing.

## Submitting a weekly prediction

A weekly competition prediction file (lines `symbol,prediction`, with or without that header) can be submitted to the daily competition as it is:

```python
from yiedl.v3 import convert_weekly

predictions = convert_weekly(api, "weekly.csv")
api.upload_predictions(predictions=predictions)
```

`convert_weekly` keeps the round's assets, at most the competition's cap of them (`maxHeldAssets`), and rescales them. UpDown: each value divided by the sum of their sizes. Neutral: the values ranked and centred, the longs scaled to +0.5 and the shorts to -0.5. Weekly symbols not in the round are left out. A warning names the round's assets with no weekly value, which are not held (a symbol to rename, or a gap in your model), and any symbol given twice. It sends nothing; a prediction that cannot be converted raises `ConversionError` with the reason.

## Creating subaccounts and moving balance

These need the registry's program of the subaccount additions, which production runs. On a registry with an earlier program the SDK refuses both before sending anything, saying so.

```python
from yiedl.v3 import CompetitionType, YiedlAPI

api = YiedlAPI(delegate="my-delegate", subaccount=1, competition_type=CompetitionType.UPDOWN)
print(api.create_subaccount())            # a new subaccount of yours: its number and address
api.move(1, 2, 30)                        # 30 YIEDL of free balance from subaccount 1 to 2
api.move_many([(1, 3, 10), (3, 2, 5)])    # several, in order: up to 15 per transaction
```

The delegate key sends them (it needs a little HYPE for gas). A new subaccount is yours exactly as one you create on the website. A move takes only free balance, never a locked stake, and only between your own subaccounts: the tokens stay yours. A move changes what each model can stake; `max_stake` does not apply to moves. Before sending, the SDK refuses a key that is not linked, an owner already at the registry's cap of subaccounts, a number that is not one of yours, a subaccount moved to itself, and an amount above the source's free balance at that point of the list. It checks each subaccount on chain to be yours, as before a submission. A long list of moves goes in transactions of at most 15 moves each, and the SDK says how many before sending the first. Once you have more than one subaccount, choose one with `subaccount=` to submit. `status()` shows how many subaccounts you have (`subaccounts_created`) and the cap (`max_subaccounts`).

## A round's prices, and the round of a day

The prices a round is scored with are the ones the competition's price oracle recorded at the round's price reference start and end. The SDK reads them for you. These reads need no key, and send nothing:

```python
import pandas
from yiedl.v3 import CompetitionType, YiedlAPI

api = YiedlAPI(delegate="my-delegate", subaccount=1, competition_type=CompetitionType.UPDOWN)
prices = api.round_prices(51)                 # or day="2026-11-24", or neither: the open round, else the latest
print(prices["end_recorded"], prices["end_final"])
table = pandas.DataFrame.from_dict(prices["prices"], orient="index")   # one row per symbol: start, end
```

`prices` holds, for each symbol of the round in its order, the `start` and `end` price as exact `Decimal`s, or `None` for a price the oracle holds as unavailable. Until the end prices are recorded, `end_recorded` is False, every end price is `None` and `message` says when the round's price window ends. Recorded end prices are final once the oracle locks them (`end_final`); until then the operator may still change them. The oracle read is the one the competition names, and for a built-in competition it must be the one built into the SDK.

`api.rounds_for_day("2026-11-24")` lists the rounds whose price reference start falls on that UTC day (a `date`, a `datetime`, or `"YYYY-MM-DD"`; a `datetime` without a time zone is read as UTC), oldest first. The list is empty if no round starts that day, and an aborted round is listed. `api.round_for_day(day)` gives the one round of that day; it raises a `ValueError` if there is none, or if there are several, naming them. Staging4 opens several a day. Both find the day in a few reads: rounds are opened in the order of their start, and the SDK checks that order in what it reads and stops rather than guess.

## Settings

The key is `delegate=` (a number or name from `python -m yiedl.v3.keystore list`; delegate 1 if left out), or `signer=` (a key already unlocked with `keystore.load(...)`, which takes the same number or name). Nothing needs to be set in the environment.

Each setting below is an argument of `YiedlAPI(...)` (`subaccount`, `rpc_url`, `max_fee`, `max_stake`, `pin_file`) and can be set in the environment instead. The competitions' addresses, their subaccount registries, the token and its decimals, the scoring engines and the price oracle are built into the SDK. Your owner is never a setting: the SDK reads it from the chain.

| Setting | What it is | Default |
| --- | --- | --- |
| `YIEDL_KEYSTORE` | For tests and servers: the path of a password-locked key file elsewhere, used instead of delegate 1; the password is asked for, hidden | none |
| `YIEDL_PRIVATE_KEY` | For tests, or a server whose secrets manager injects the key: the bare key, unprotected (see "The bare key"). Not together with `YIEDL_KEYSTORE` | none |
| `YIEDL_SUBACCOUNT` | The number of the subaccount to submit for (1, 2, ...) | the only one, if there is one |
| `YIEDL_RPC_URL` | Another JSON-RPC endpoint | HyperEVM's public one |
| `YIEDL_MAX_FEE` | The most one transaction may cost in fees, in HYPE | 0.01 |
| `YIEDL_MAX_STAKE` | Optional: the most one submission may stake | none |
| `YIEDL_PIN_FILE` | Where the SDK keeps its note of your owner, for a key given without a key file | `~/.yiedl/delegate-<address>.owner.json` |

The order: `signer=`, then `delegate=`, then `YIEDL_PRIVATE_KEY` or `YIEDL_KEYSTORE`, then delegate 1. With no key at all, the SDK can still read rounds, and whatever needs the key says to run `python -m yiedl.v3.keystore new`. Once a key exists, every `YiedlAPI()` without a `signer` unlocks it, even one that only reads: with its saved password if there is one (see "The key's password"), else by asking for its password.

One script can hold several `YiedlAPI` objects, one per key: for example two delegate keys for two owners, `YiedlAPI(delegate=1)` and `YiedlAPI(delegate=2)`. Each key finds its own owner, sees that owner's subaccounts only, and keeps its own note. `YIEDL_PIN_FILE` names one file, so do not set it for a script that holds several keys given without a key file; give each its own `pin_file=` instead.

The key commands:

| Command | What it does |
| --- | --- |
| `python -m yiedl.v3.keystore new [NAME] [--save-password]` | Makes a new delegate key, the next number, with a name if given; with the flag, keeps its password beside it (`~/.yiedl/delegates/N.password`) |
| `python -m yiedl.v3.keystore save-password [NAME_OR_NUMBER]` | Keeps a key's password beside it, once it unlocks the key |
| `python -m yiedl.v3.keystore forget-password [NAME_OR_NUMBER]` | Deletes a key's saved password; the key is then asked for |
| `python -m yiedl.v3.keystore list` | Every key's number, name and address |
| `python -m yiedl.v3.keystore create [NAME]` | Locks a key made elsewhere (asked for, hidden) as the next number |
| `python -m yiedl.v3.keystore import PATH [NAME]` | Brings in a key file made before, with the SDK's note of its owner |
| `python -m yiedl.v3.keystore send-hype NAME_OR_NUMBER TO AMOUNT` | Sends the key's own HYPE (its gas, never your tokens) to the wallet `TO`, which must be a checksummed address (with its capital letters, as your wallet or the explorer shows it, so that a typo is caught); `all` for everything less the fee, and at most 18 decimals otherwise. Asks for the key's password every time, shows what it will send and the most the fee can be, and sends only after you type `yes`. Only to a plain wallet, never a contract |
| `python -m yiedl.v3.keystore export [NAME_OR_NUMBER]` | Prints the key's private key, for a wallet of your own. Asks for its password every time, never from a saved file; whoever has the printed key controls that wallet |

The link commands, each for both competitions unless `--competition updown` or `--competition neutral` is given, and for delegate 1 unless `--delegate NAME_OR_NUMBER` is given:

| Command | What it does |
| --- | --- |
| `python -m yiedl.v3.link make` | Prints a new link string for this key, to paste on the website's Daily page |
| `python -m yiedl.v3.link status` | Whether the key is linked, to which owner, and that owner's subaccounts |
| `python -m yiedl.v3.link revoke` | Cancels every link string of this key not used yet, and checks that the chain did (needs HYPE) |
| `python -m yiedl.v3.link leave` | Unlinks the key from its owner (needs HYPE) |
| `python -m yiedl.v3.link forget-owner` | Clears the SDK's note of your owner, after you linked the key to another owner on purpose |

The example script: `python -m yiedl.v3.example [PATH]` writes it to `main.py` in the current folder (or to `PATH`), never over a file already there.

The upgrade command (see "What to know before staking real funds"):

| Command | What it does |
| --- | --- |
| `python -m yiedl.v3.upgrades show` | What differs on chain from the upgrade settings this version carries (in code: `api.upgrades()`) |

For a competition that is not built in (staging, tests), the upgrade settings are given with `upgrade_state=` (`yiedl.v3.upgrades.parse_upgrade_state` reads the same line the website carries); without it, the SDK prints that the upgrade checks were not made.

## The key's password

The quickstart saves the key's password (`--save-password`), so that a script starts with nobody there to type. It sits beside the key in the SDK's folder, `~/.yiedl/delegates/2.password` for delegate 2, readable by you only. `YiedlAPI()`, `YiedlAPI(delegate="my-delegate")` and the link commands use it from any folder, cron included, and print one line saying which file unlocked the key. `python -m yiedl.v3.keystore list` marks the keys whose password is saved. A saved password that does not unlock its key is an error naming the file: the SDK never falls back to asking, so a run with nobody there stops instead of waiting.

**With its password saved, the key is as good as unlocked for anyone who can read `~/.yiedl/delegates`.** Such a person could submit, create subaccounts and move free balance between your subaccounts with it, and spend the HYPE on it; never take tokens out. Keep that folder to yourself, and never write a key or a password into code or a notebook.

For a key made without the flag, `python -m yiedl.v3.keystore save-password my-delegate` asks for its password without showing it, checks that it unlocks the key, and saves it the same way. `python -m yiedl.v3.keystore forget-password my-delegate` deletes it. A saved password is never replaced: forget it first.

`signer=` always wins over the saved password, and `YIEDL_KEYSTORE` and `YIEDL_PRIVATE_KEY` work as before. `keystore.load("my-delegate", password=...)` unlocks with the password given; `keystore.load("my-delegate")` always asks. `keystore export` and `keystore send-hype` always ask too.

> To type the password at each run instead, do not save it (or forget it): `YiedlAPI()` then asks for it, hidden, once per object. Make one `YiedlAPI` and use `for_subaccount(n)` for others, or unlock once with `signer = keystore.load(1)` and pass that `signer` to each.

### The bare key (not recommended)

`YIEDL_PRIVATE_KEY` gives the SDK the bare key, with no key file and no password. It is for tests, or a server whose secrets manager already injects the key. It leaves the key unprotected: anyone who can read that environment can submit with it (the key cannot take money out; the owner removes it on the website). Never set it together with `YIEDL_KEYSTORE`. A bare key made elsewhere can be locked with a password instead: `python -m yiedl.v3.keystore create` asks for it, hidden, and keeps it as the next delegate number.

A key given this way has no key file to keep the SDK's note of your owner beside, so the note goes to `~/.yiedl/`, named after the key's address. On a server whose home folder does not survive a restart, set `YIEDL_PIN_FILE` to a file that does: without its note, the SDK cannot tell that the key was linked to another owner in between.

## SDK reference

Everything a participant uses, by task. `api` is a `YiedlAPI` object; every name is imported from `yiedl.v3` unless said otherwise. The commands (`keystore`, `link`, `example`, `upgrades`) and the environment settings are in "Settings" above.

### Making the object

```python
from yiedl.v3 import CompetitionType, YiedlAPI

api = YiedlAPI(delegate="my-delegate", subaccount=1, competition_type=CompetitionType.UPDOWN)
```

| Argument | What it is |
| --- | --- |
| `competition_type` | `CompetitionType.UPDOWN` or `CompetitionType.NEUTRAL` (or `"updown"`, `"neutral"`); required |
| `delegate` | The key: its number or name from `python -m yiedl.v3.keystore list` (delegate 1 if left out) |
| `signer` | A key already unlocked with `keystore.load(...)`, instead of `delegate` |
| `subaccount` | The subaccount to submit for, by number (1, 2, ...); the only one if left out and there is one |
| `rpc_url`, `max_fee`, `max_stake`, `pin_file` | As in "Settings" |
| `competition_address`, `registry_address`, `token_address`, `token_decimals`, `chain_id`, `upgrade_state` | Only for a competition that is not built in (tests); left out, the built-in production competition is used |

### The key and its link

| Call | What it does or returns |
| --- | --- |
| `api.status()` | Whether the key is linked to an owner and, if so, the owner and its subaccounts with their balances; cheap to call again while waiting for the link |
| `api.get_account()` | The chosen subaccount: its number, the owner, and its address, checked on chain |
| `api.get_subaccounts()` | The owner's subaccounts the key may submit for, numbered from 1, with `created` and `max_subaccounts` |
| `api.for_subaccount(n)` | The same object for subaccount `n`, with the same key and settings |
| `api.get_balance()` | The subaccount's `free` and `locked` tokens |
| `api.stake_threshold()` | The smallest stake a submission may carry |
| `api.make_link_string(valid_seconds=3600)` | A link string for this key (`.text` to paste on the website's Daily page); `make_link_string(api_updown, api_neutral)` makes one for both |
| `api.revoke_link_offers()` | Cancels every link string of the key not used yet (sent by the key: needs HYPE) |
| `api.remove_self_as_delegate()` | Unlinks the key from its owner (needs HYPE) |
| `api.forget_owner()` | Clears the SDK's note of the owner, after linking the key to another owner on purpose |
| `api.sender`, `api.subaccount` | The key's address, and the chosen subaccount's address |

### Rounds

| Call | What it returns |
| --- | --- |
| `api.get_current_round()` | The round taking submissions now, or `None` |
| `api.check_round_open()` | Whether a round is taking submissions now |
| `api.get_open_rounds()` | The rounds taking submissions now, as `Round` objects |
| `api.round_details(n)` | Round `n`: its assets (`symbols`) in order, its times and its phase |
| `api.rounds_for_day(day)`, `api.round_for_day(day)` | The rounds whose price window starts on a UTC day (`"YYYY-MM-DD"`, a `date` or a `datetime`) |
| `api.round_prices(n)` or `api.round_prices(day=...)` | The start and end price of each asset, as the oracle recorded them |

### Submitting

| Call | What it does |
| --- | --- |
| `api.upload_predictions("predictions.csv", stake=10)` | Seals the predictions and submits them to the current round. Give one of a CSV path (`symbol`, `prediction` columns), `df=` a DataFrame, or `predictions=` values by symbol; `round_num=` another open round; `dry_run=True` sends nothing. Returns the transaction hash |
| `api.withdraw_submission()` | Takes back the submission to the open round; its stake becomes free |
| `api.release_stake(n)` | Frees the stake still locked on round `n` if that round was aborted |
| `convert_weekly(api, "weekly.csv")` | Turns a weekly-competition prediction into values by symbol for `upload_predictions(predictions=...)` (see "Submitting a weekly prediction"); `ConversionError` if it cannot |

### Results

| Call | What it returns |
| --- | --- |
| `api.submission_status(n)` | The subaccount's submission to round `n` (the current one if left out): stake, whether evaluated and settled, score, settlement; `None` if there is none |
| `api.round_model_performances(last=10)` | The same for each submission among the last `last` rounds, newest first |
| `api.verify_round(n)` | After round `n`'s key is published: opens your sealed submission and checks it against what the contract holds (`opens`, `predictions`, `score`, `settlement`, `invalidated`) |

### Subaccounts

| Call | What it does |
| --- | --- |
| `api.create_subaccount()` | Creates a new subaccount for the owner (needs HYPE); its number and address |
| `api.move(from_number, to_number, amount)` | Moves free balance between two of the owner's subaccounts (needs HYPE) |
| `api.move_many([(1, 2, 10), (3, 2, 5)])` | Several moves, in order, up to 15 per transaction |

### Datasets

`Datasets` holds the six datasets: `LATEST`, `HISTORICAL`, `WEEKLY`, `DAILY`, `ROLLING_WEEKLY` and `ROLLING_DAILY`. Each has `name`, `description`, `published` and `file`.

| Call | What it does |
| --- | --- |
| `Datasets.show()` | Prints every dataset |
| `Datasets.ROLLING_WEEKLY.download("data")` | Downloads it, checked against the server's checksum and resumed if interrupted; returns the file or the folder it was unpacked into. Options: `unzip=False` (keep a zip), `force=True` (download again), `verify=True` (hash every file again), `show_progress=False` |
| `download_latest_dataset("data")`, `download_historical_dataset("data")` | The same as `Datasets.LATEST.download` and `Datasets.HISTORICAL.download` |

### Keys in Python (`from yiedl.v3 import keystore`)

| Call | What it does |
| --- | --- |
| `keystore.load(which, password=None)` | Unlocks a key by number, name or file path (asks for the password if not given); pass it as `signer=` |
| `keystore.delegates()`, `keystore.find(which)` | The keys in the SDK's folder; one of them by number or name |
| `keystore.new_delegate(name)`, `keystore.create_delegate(name)`, `keystore.import_delegate(path, name)` | A new key, an existing key locked with a password, or a key file made before, kept as the next number |
| `keystore.save_password(which)`, `keystore.forget_password(which)` | Saves or deletes a key's password beside it (see "The key's password") |
| `keystore.folder()` | The folder the keys are kept in, `~/.yiedl/delegates` |

### Upgrades

`api.upgrades()` says what differs on chain from the upgrade settings this version carries (the same as `python -m yiedl.v3.upgrades show`).

### Errors

Each says why in plain words. Those raised before anything is signed or sent:

| Error | When |
| --- | --- |
| `NotLinked` | The key is not linked to an owner in this competition |
| `OwnerChanged` | The chain links the key to another owner than the one the SDK recorded |
| `SubaccountRefused` | The subaccount is not one this key may submit for |
| `SigningRefused` | The SDK refused to sign: another chain, recipient or fields than it meant, or a fee past the limit |
| `NotEnoughGas` | The key holds too little HYPE for the transaction's fee |
| `UpgradeChanged` | The upgrade settings on chain differ from what this version carries; submissions stop until you update the SDK |
| `SealCheckFailed` | The sealed submission would be invalidated |
| `LinkRefused` | The SDK refused to make a link string |
| `ConversionError` | A weekly prediction cannot be converted |
| `DatasetDownloadError` | A dataset could not be downloaded, checked or unpacked, or the server does not offer it |

And those after sending: `ContractRefused` (the contract refused the call; `error` is its reason), `TransactionFailed` (mined and failed), `NotConfirmed` (sent, but no receipt in time: it may still be mined), and `RPCUnavailable` (the RPC did not answer).

### Lower level

`seal`, `open_sealed` and `submission_hash` seal, open and hash a submission as the contract does; `SealedSubmission` is what is submitted. `Round` is one round as the contract describes it. `MISSING` (-2^127) marks an asset as "no prediction". `Competition` is the contract itself, as `api.competition`. `Signer` and `LocalKeySigner` are what signs; `QuietHTTPProvider` is the RPC provider the SDK uses.

## Releasing (maintainers)

The built-in table (`yiedl/v3/deployments.py`) holds one deployment, named by the marker beside it, `NETWORK`: `"staging"` while it is a test deployment, updated whenever staging is redeployed, and `"production"` with production's addresses. Replace the table (`BUILT_IN`), its upgrade record (`UPGRADE_RECORDS`) and the marker together, in one change, each address checked on chain first. The tests refuse a release (a version that is not a `.devN` version) unless the marker is `"production"`, no staging address or rehearsal token remains anywhere in the table or the record, and the token has 6 decimals. A staging table ships only in a development version.

## What to know before staking real funds

- **The RPC provider is trusted for what the SDK reads**: rounds, the encryption key, the asset list, balances, the minimum stake, which owner the key is linked to, and the subaccount checks. The default is HyperEVM's own public endpoint.
- **What the SDK always enforces**, whatever the provider says: it signs only for HyperEVM; a submission or its withdrawal goes only to a subaccount of the owner its key is linked to, with no value and exactly the call it built; it stops if the chain names another owner than the one in its note; it takes the competitions, their registries, the token and its decimals, the scoring engines and the oracle from what is built in, and refuses to submit if the competition uses another scoring engine or oracle; and it refuses a transaction whose fee could exceed `YIEDL_MAX_FEE`. The only transaction that carries coin is `keystore send-hype`, the key's own HYPE to a wallet you type, after its password and a typed `yes`.
- **A link string is built and checked by the SDK itself**: the SDK writes the statement its key signs from the chain id and registry addresses it carries, compares it with the registry's own, and signs nothing on any difference. It never signs anything a node or a website hands it.
- **The delegate key chooses the stake**, up to the subaccount's whole free balance, and can replace or cancel any submission of your subaccounts. It cannot take tokens out of them. With the registry's program of the subaccount additions (staging4's) it can also move free balance between your subaccounts (gathering it into one, say) and create subaccounts up to the cap. You limit what is at risk by how much each subaccount holds. If the key may have leaked, remove it as your delegate on the website's Daily page first, then withdraw.
- **A stake goes back to the free balance when its round settles**, with its gain or loss, and must be staked again on a new submission to stay in play.
- **If a round is never settled**: from its evaluation deadline, a round that is fully evaluated can no longer be cancelled, and anyone may send the steps that finish its settlement; a round that is not fully evaluated can be cancelled only by the operator or by one of its own participants, that is by the owner of a subaccount that submitted to it, through that subaccount (the SDK does neither). Then any key can return the stake still locked on it to the subaccount's free balance: `api.release_stake(n)`. A stake already returned is not sent for again: the SDK says there is nothing locked and sends nothing.
- **Upgrades take effect at once, and the SDK stops submitting after one until you update it.** Yiedl's Safe (a shared wallet with several owners) holds the rights to upgrade the competitions, their subaccount registries and the subaccounts, and an upgrade is one Safe transaction that takes effect immediately. The SDK carries, built in, the programs the contracts run, who holds each upgrade right, and the Safe's owners. Before every submission it reads all of this from the chain and refuses to submit, naming what changed, when the programs, the upgrade rights or the Safe's owners differ from what this version carries (also when the Safe has a module or a guard). Submissions stay stopped until you install a release that carries the change (`pip install -U "yiedl-ai[v3]"`). `python -m yiedl.v3.upgrades show` lists what differs. After the upgrade rights are given up for good, a release carries that state and the SDK then expects nobody to hold them. Taking a submission back is never stopped by these checks: it goes on, and prints what they found. Releasing a stake, revoking link strings and leaving the owner are not checked at all.
- **What the upgrade checks cannot see**: a node that lies the same way on every read, and a change made between the checks and the moment your submission is mined.
- **A key file protects the key at rest**, not while a script is running with it unlocked.
