@thetanuts-finance/odette-sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE.md +65 -0
- package/README.md +156 -2
- package/dist/index.cjs +2079 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2070 -0
- package/dist/index.d.ts +2070 -0
- package/dist/index.js +2017 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thetanuts Finance
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# NOTICE
|
|
2
|
+
|
|
3
|
+
This repository adapts code from **thetanuts-sdk**
|
|
4
|
+
(<https://github.com/Thetanuts-Finance/thetanuts-sdk>), MIT License,
|
|
5
|
+
Copyright (c) 2026 Thetanuts Finance. Source commit:
|
|
6
|
+
`9e72aef1ab5c008ccc92352fa5048bd08c452ede`.
|
|
7
|
+
|
|
8
|
+
Each file below keeps the Thetanuts Finance MIT notice in its header, and the
|
|
9
|
+
header lists what changed.
|
|
10
|
+
|
|
11
|
+
## SDK (`packages/sdk/src`)
|
|
12
|
+
|
|
13
|
+
| File | Source in thetanuts-sdk | How |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `abi/optionBook.ts` | `src/abis/optionBook.ts` | Copied as-is |
|
|
16
|
+
| `abi/erc20.ts` | `src/abis/erc20.ts` | Copied as-is |
|
|
17
|
+
| `chain.ts` | `src/chains/index.ts` (Base block) | Addresses only |
|
|
18
|
+
| `client.ts` | `src/client/ThetanutsClient.ts` | Trimmed; fixed referrer; Base only |
|
|
19
|
+
| `errors.ts` | `src/types/errors.ts`, `src/utils/errors.ts` | Trimmed; renamed to `OdetteError` |
|
|
20
|
+
| `logger.ts` | `src/utils/logger.ts`, `src/types/logger.ts` | Renamed to `OdetteLogger` |
|
|
21
|
+
| `types.ts` | `src/types/optionBook.ts`, `src/types/api.ts` | Trimmed to the feed order shape |
|
|
22
|
+
| `feed.ts` | `src/modules/api.ts` (`fetchOrders`) | Rewritten on `fetch`, strict field checks |
|
|
23
|
+
| `normalize.ts` | `src/modules/api.ts` (`normalizeOdetteOrder`) | Typed input; no 0 / "" fallbacks |
|
|
24
|
+
| `modules/optionBook.ts` | `src/modules/optionBook.ts` | Trimmed; fixed referrer; Odette sizing and checks |
|
|
25
|
+
| `modules/erc20.ts` | `src/modules/erc20.ts` | Trimmed (no transfer, no callStatic) |
|
|
26
|
+
| `modules/utils.ts` | `src/modules/utils.ts` | `toBigInt`, `fromBigInt` only |
|
|
27
|
+
| `utils/decimals.ts` | `src/utils/decimals.ts` | `toBigInt`, `fromBigInt` only |
|
|
28
|
+
| `utils/validation.ts` | `src/utils/validation.ts` | `validateAddress` only |
|
|
29
|
+
|
|
30
|
+
## CLI (`packages/cli/src`)
|
|
31
|
+
|
|
32
|
+
| File | Source in thetanuts-sdk | How |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `index.ts` | `cli/src/index.ts` | Name and description |
|
|
35
|
+
| `options.ts` | `cli/src/options.ts` | No `--chain`, no `--referrer` |
|
|
36
|
+
| `client.ts` | `cli/src/client.ts` | `OdetteClient`; no referrer resolution; no RFQ keystore |
|
|
37
|
+
| `config.ts` | `cli/src/config.ts` | `~/.config/odette`; a `referrer` key is an error |
|
|
38
|
+
| `confirm.ts` | `cli/src/confirm.ts` | Unchanged |
|
|
39
|
+
| `defaults.ts` | `cli/src/defaults.ts` | Comments |
|
|
40
|
+
| `output.ts` | `cli/src/output.ts` | Comments |
|
|
41
|
+
| `format.ts` | `cli/src/format.ts` | Unchanged |
|
|
42
|
+
| `bookEligibility.ts` | `cli/src/bookEligibility.ts` | Import only |
|
|
43
|
+
| `bookMatch.ts` | `cli/src/bookMatch.ts` | Import only |
|
|
44
|
+
| `bookOrderIdentity.ts` | `cli/src/bookOrderIdentity.ts` | Adds `findSameInstrument` (Odette re-signs orders) |
|
|
45
|
+
| `bookPreview.ts` | `cli/src/bookPreview.ts` | Unchanged |
|
|
46
|
+
| `bookCheck.ts` | `cli/src/bookCheck.ts` | No RFQ recommendation |
|
|
47
|
+
| `commands/book.ts` | `cli/src/commands/book.ts` | Top-level commands; no payout block; pre-send checks |
|
|
48
|
+
| `commands/wallet.ts` | `cli/src/commands/wallet.ts` | No `transfer`; approve is USDC to the OptionBook only |
|
|
49
|
+
| `commands/setup.ts` | `cli/src/commands/setup.ts` | No referrer prompt |
|
|
50
|
+
| `commands/config.ts` | `cli/src/commands/config.ts` | `referrer` refused |
|
|
51
|
+
| `commands/registry.ts` | `cli/src/commands/registry.ts` | Odette commands only |
|
|
52
|
+
|
|
53
|
+
Test patterns (not copied code): `cli/tests/exitCodes.test.ts`.
|
|
54
|
+
|
|
55
|
+
## Ported from the Odette web app
|
|
56
|
+
|
|
57
|
+
These files port rules from `thetaverse/odette` (Thetanuts' Odette web app) at
|
|
58
|
+
`origin/dev` `5c3f2b0639ce07a134a0f82b7df8113dea1e744b`, checked against the
|
|
59
|
+
OptionBook and option contracts in `thetanuts_rfq` at
|
|
60
|
+
`2c830620861eefcca895fb8e2a60b8f3fa915e7f`. They carry the same MIT notice.
|
|
61
|
+
|
|
62
|
+
| File | Source |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `packages/sdk/src/whitelist.ts` | `odette/config.js`: implementation constants, `isSpreadOrder`, `isDirectionalOrder`, `isRangerOrder`, `CANONICAL_ASSETS`, `COLLATERAL_TOKENS`, `filterOrdersForDailyBook`, `EXPIRY_FILTER_LIMITS`, `isAssetAvailableOnDay`; `ui_interactions.js` `isOrderExpiringSoon` |
|
|
65
|
+
| `packages/sdk/src/sizing.ts` | `odette/config.js`: `getContractQuantumStrike`, `getMaxRawContracts`, `validateNumContractsForContract`, `calculateMaxContracts`, `getMinimumPercentage`, `MIN_PREMIUM_USD` |
|
package/README.md
CHANGED
|
@@ -1,3 +1,157 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Odette SDK and CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Buy Odette options on Base from your terminal or your own code.
|
|
4
|
+
|
|
5
|
+
- **`odette`**, the command-line tool: `@thetanuts-finance/odette-cli`
|
|
6
|
+
- **The SDK**, a TypeScript library: `@thetanuts-finance/odette-sdk`
|
|
7
|
+
|
|
8
|
+
Odette runs on Thetanuts Finance contracts on Base. You sign every trade with your
|
|
9
|
+
own wallet. No trade goes through a server: `odette` only reads the public order
|
|
10
|
+
list and sends your signed transaction straight to Base.
|
|
11
|
+
|
|
12
|
+
## What you can do
|
|
13
|
+
|
|
14
|
+
- See the options Odette lists right now: PUT, CALL (LINEAR_CALL) and RANGER.
|
|
15
|
+
- Check a trade before you make it.
|
|
16
|
+
- Buy an option with USDC.
|
|
17
|
+
|
|
18
|
+
The tools only **buy**. They do not sell or close positions. Odette options are
|
|
19
|
+
cash-settled in USDC at expiry, so there is nothing to close.
|
|
20
|
+
|
|
21
|
+
## Before you start
|
|
22
|
+
|
|
23
|
+
- [Node.js](https://nodejs.org) 20 or newer
|
|
24
|
+
- A wallet on **Base** with:
|
|
25
|
+
- **USDC**, to pay for the option (the minimum trade is 0.50 USDC)
|
|
26
|
+
- a little **ETH**, for gas (a trade costs a few cents)
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm install -g @thetanuts-finance/odette-cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Set up your wallet (once)
|
|
35
|
+
|
|
36
|
+
Use the wallet you already have:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
odette wallet import
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Paste your private key when asked. You won't see it as you paste, and that's expected.
|
|
43
|
+
|
|
44
|
+
Don't have one? `odette wallet create` makes a new wallet. Then send it USDC and some ETH on Base.
|
|
45
|
+
|
|
46
|
+
Your key is saved only on your computer, in `~/.config/odette/config.json`, and only you
|
|
47
|
+
can read that file. **Never share your private key or paste it into a chat.**
|
|
48
|
+
|
|
49
|
+
Check it worked:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
odette wallet show # your address
|
|
53
|
+
odette wallet balance # your ETH and USDC
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Make a trade
|
|
57
|
+
|
|
58
|
+
**1. See what's on offer.**
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
odette orders --underlying ETH --type PUT
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Each row is one option: its strike price, the expiry date and time, and the price of one contract.
|
|
65
|
+
`--type` can be `PUT`, `CALL` or `RANGER`.
|
|
66
|
+
|
|
67
|
+
**2. Check the trade.** Pick a strike and expiry from the list. `--collateral` is how
|
|
68
|
+
much USDC you want to spend. (The strike and expiry below are examples: copy real
|
|
69
|
+
ones from `odette orders`, because options expire every day.)
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
odette preview --underlying ETH --type PUT --strike 2200 --expiry 1793174400 --collateral 5
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This shows how many contracts you get, and runs safety checks:
|
|
76
|
+
does the seller have the funds, do you have enough USDC, is the quote still live.
|
|
77
|
+
Nothing is sent.
|
|
78
|
+
|
|
79
|
+
**3. Buy.**
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
odette fill --underlying ETH --type PUT --strike 2200 --expiry 1793174400 --collateral 5
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The first time, `odette` asks you to let the Odette contract take your USDC. That
|
|
86
|
+
permission is called an approval. Then it asks you to confirm the trade. Answer `y`
|
|
87
|
+
to both. When it's done, it prints the transaction link.
|
|
88
|
+
|
|
89
|
+
Prices update about once a minute. If the price moves while you're deciding, `odette`
|
|
90
|
+
shows the new price and asks you again.
|
|
91
|
+
|
|
92
|
+
Want to see the transaction without sending it? Add `--dry-run`. With `--yes` (no
|
|
93
|
+
questions), `--collateral` is required, so `odette` never buys a maximum size by itself.
|
|
94
|
+
|
|
95
|
+
**Buying a RANGER.** A RANGER pays out if the price ends inside a range. It has
|
|
96
|
+
four strikes, so use `--type RANGER` with `--strikes`:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
odette orders --underlying BTC --type RANGER
|
|
100
|
+
odette preview --underlying BTC --type RANGER --strikes 78500,79000,80000,80500 --expiry 1793174400 --collateral 5
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`preview` shows what you pay (`premium`) and the most you can be paid at expiry (`maxPayout`). In `-o json`
|
|
104
|
+
output the premium is the `totalCollateral` field (the name upstream uses).
|
|
105
|
+
|
|
106
|
+
## Useful flags
|
|
107
|
+
|
|
108
|
+
| Flag | What it does |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `--dry-run` | Show what would happen. Send nothing. |
|
|
111
|
+
| `--yes` | Skip the questions (the safety checks still run). |
|
|
112
|
+
| `-o json` | Print JSON, for scripts. |
|
|
113
|
+
| `--rpc-url <url>` | Use your own Base RPC instead of the public one. |
|
|
114
|
+
|
|
115
|
+
Exit codes for scripts: `0` ok, `1` the trade or a check failed, `2` a wrong command or flag,
|
|
116
|
+
`3` you said no, `4` a wallet or config problem.
|
|
117
|
+
|
|
118
|
+
## For developers: the SDK
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
npm install @thetanuts-finance/odette-sdk ethers
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { JsonRpcProvider, Wallet } from 'ethers';
|
|
126
|
+
import { OdetteClient } from '@thetanuts-finance/odette-sdk';
|
|
127
|
+
|
|
128
|
+
const provider = new JsonRpcProvider('https://mainnet.base.org');
|
|
129
|
+
const signer = new Wallet(process.env.ODETTE_PRIVATE_KEY!, provider);
|
|
130
|
+
const client = new OdetteClient({ provider, signer });
|
|
131
|
+
|
|
132
|
+
const orders = await client.api.fetchOrders();
|
|
133
|
+
const order = orders.find((o) => o.product === 'PUT' && o.underlying === 'ETH')!;
|
|
134
|
+
|
|
135
|
+
const usdc = 5_000000n; // 5 USDC (USDC has 6 decimals)
|
|
136
|
+
const preview = client.optionBook.previewFillOrder(order, usdc);
|
|
137
|
+
const checks = await client.optionBook.checkFill(order, usdc); // reads only, never sends
|
|
138
|
+
|
|
139
|
+
await client.erc20.ensureAllowance(preview.collateralToken, preview.optionBook, preview.totalCollateral);
|
|
140
|
+
const receipt = await client.optionBook.fillOrder(order, usdc); // refuses if a check fails
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Amounts: USDC and contract sizes have 6 decimals. Prices and strikes are in USD with 8 decimals.
|
|
144
|
+
The amount you pass is the USDC you want to spend, not a number of contracts.
|
|
145
|
+
|
|
146
|
+
## Good to know
|
|
147
|
+
|
|
148
|
+
- **Base only** (chain 8453).
|
|
149
|
+
- **Found a security problem?** Don't open a public issue. See `SECURITY.md`.
|
|
150
|
+
- **Every trade is tagged with Odette's referrer**, `0x94D784e81A5c8cA6E19629C73217b61a256Ea1c7`.
|
|
151
|
+
You can't change it in these tools. The contract itself does not enforce the tag.
|
|
152
|
+
- Orders and contracts come from Thetanuts Finance. Odette is the app on top.
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT, Copyright (c) 2026 Thetanuts Finance. Parts are adapted from
|
|
157
|
+
[thetanuts-sdk](https://github.com/Thetanuts-Finance/thetanuts-sdk); see `NOTICE.md`.
|