@thetanuts-finance/odette-sdk 0.0.0-stage → 0.1.1
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 +86 -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,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Odette SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Buy Odette options on Base from your own code: trading bots, apps, scripts and AI agents.
|
|
4
|
+
|
|
5
|
+
Just want to trade from a terminal? Use the CLI,
|
|
6
|
+
[`@thetanuts-finance/odette-cli`](https://www.npmjs.com/package/@thetanuts-finance/odette-cli).
|
|
7
|
+
|
|
8
|
+
The SDK reads the public order list, then calls the OptionBook contract on Base
|
|
9
|
+
(`fillOrder`) with your own signer. You don't need to know the contract: the SDK
|
|
10
|
+
handles the order format, sizing and units, safety checks and approvals.
|
|
11
|
+
**Every fill carries Odette's referrer**, `0x94D784e81A5c8cA6E19629C73217b61a256Ea1c7`.
|
|
12
|
+
It is fixed; no option changes it.
|
|
13
|
+
|
|
14
|
+
Products: PUT, CALL (LINEAR_CALL) and RANGER, paid in USDC. The SDK only **buys**.
|
|
15
|
+
Odette options are cash-settled in USDC at expiry.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @thetanuts-finance/odette-sdk ethers
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Node.js 20 or newer, ethers v6. ESM and CommonJS both work.
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { JsonRpcProvider, Wallet } from 'ethers';
|
|
29
|
+
import { OdetteClient } from '@thetanuts-finance/odette-sdk';
|
|
30
|
+
|
|
31
|
+
const provider = new JsonRpcProvider('https://mainnet.base.org');
|
|
32
|
+
const signer = new Wallet(process.env.ODETTE_PRIVATE_KEY!, provider);
|
|
33
|
+
const client = new OdetteClient({ provider, signer });
|
|
34
|
+
|
|
35
|
+
const orders = await client.api.fetchOrders();
|
|
36
|
+
const order = orders.find((o) => o.product === 'PUT' && o.underlying === 'ETH')!;
|
|
37
|
+
|
|
38
|
+
const usdc = 5_000000n; // 5 USDC (USDC has 6 decimals)
|
|
39
|
+
const preview = client.optionBook.previewFillOrder(order, usdc);
|
|
40
|
+
const checks = await client.optionBook.checkFill(order, usdc); // reads only, never sends
|
|
41
|
+
|
|
42
|
+
await client.erc20.ensureAllowance(preview.collateralToken, preview.optionBook, preview.totalCollateral);
|
|
43
|
+
const receipt = await client.optionBook.fillOrder(order, usdc, {
|
|
44
|
+
onSent: (hash) => console.log('sent', hash), // the tx hash, before it is mined
|
|
45
|
+
});
|
|
46
|
+
console.log(client.optionBook.decodeOrderFilled(receipt));
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Main methods
|
|
50
|
+
|
|
51
|
+
| Method | What it does |
|
|
52
|
+
|---|---|
|
|
53
|
+
| `new OdetteClient({ provider, signer? })` | Base (8453) only. Refuses a `referrer` option. |
|
|
54
|
+
| `client.api.fetchOrders()` | The orders the Odette app lists now (PUT, LINEAR_CALL, RANGER). |
|
|
55
|
+
| `client.optionBook.previewFillOrder(order, usdc?)` | Contracts, premium (`totalCollateral`), `maxPayout`, step, min, max. No network. |
|
|
56
|
+
| `client.optionBook.checkFill(order, usdc?)` | The pre-send checks against Base: chain, order, size, maker funds, your balance and allowance, simulation. Never sends. |
|
|
57
|
+
| `client.optionBook.encodeFillOrder(order, usdc?)` | `{ to, data }` for any wallet library (for example a smart wallet). |
|
|
58
|
+
| `client.optionBook.fillOrder(order, usdc?, { onSent? })` | Runs the checks, then sends `fillOrder`. Refuses to send if a check fails. |
|
|
59
|
+
| `client.optionBook.decodeOrderFilled(receipt)` | The `OrderFilled` event: option address, premium, fee, referrer. |
|
|
60
|
+
| `client.erc20.ensureAllowance(token, spender, amount)` | Approves USDC if needed. |
|
|
61
|
+
|
|
62
|
+
Without `usdc`, preview, encode and fill use the order's **maximum** size.
|
|
63
|
+
|
|
64
|
+
## Units
|
|
65
|
+
|
|
66
|
+
- USDC amounts and contract sizes have 6 decimals (`5_000000n` = 5 USDC).
|
|
67
|
+
- Prices and strikes are USD with 8 decimals.
|
|
68
|
+
- The amount you pass is the USDC premium you want to spend, not a number of
|
|
69
|
+
contracts. Sizes round down to the contract's step; the minimum premium is 0.50 USDC.
|
|
70
|
+
|
|
71
|
+
## Errors
|
|
72
|
+
|
|
73
|
+
Errors are `OdetteError` with a `code`, for example `CHECK_FAILED`, `SIGNER_REQUIRED`,
|
|
74
|
+
`INVALID_ORDER` or `TRANSACTION_CANCELLED`. A fill that was sent never reports as failed
|
|
75
|
+
because of a callback or a logger.
|
|
76
|
+
|
|
77
|
+
## Good to know
|
|
78
|
+
|
|
79
|
+
- **Base only** (chain 8453).
|
|
80
|
+
- The contracts and the order feed are Thetanuts Finance's. Odette is the app on top.
|
|
81
|
+
- The referrer tag is a default in this SDK, not enforced by the contract.
|
|
82
|
+
- **Found a security problem?** Don't open a public issue. See [SECURITY.md](https://github.com/Shawnchee/odette-sdk/blob/main/SECURITY.md).
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT, Copyright (c) 2026 Thetanuts Finance. Parts are adapted from
|
|
87
|
+
[thetanuts-sdk](https://github.com/Thetanuts-Finance/thetanuts-sdk); see [NOTICE.md](https://github.com/Shawnchee/odette-sdk/blob/main/NOTICE.md).
|