@shippedcalls/sdk 0.4.0 → 0.5.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/README.md +41 -13
- package/dist/abi.d.ts +1328 -0
- package/dist/abi.js +1703 -0
- package/dist/abi.js.map +1 -1
- package/dist/assets.d.ts +34 -0
- package/dist/assets.js +48 -0
- package/dist/assets.js.map +1 -0
- package/dist/chain.d.ts +2 -0
- package/dist/chain.js +2 -0
- package/dist/chain.js.map +1 -1
- package/dist/cli.js +121 -38
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +85 -17
- package/dist/client.js +276 -69
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +16 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/jobs.js +2 -2
- package/dist/jobs.js.map +1 -1
- package/dist/odds.d.ts +7 -6
- package/dist/odds.js +13 -12
- package/dist/odds.js.map +1 -1
- package/dist/types.d.ts +90 -30
- package/package.json +3 -3
- package/skill/SKILL.md +24 -14
- package/skill/references/api.md +30 -12
- package/skill/references/funding.md +4 -2
- package/skill/references/settlement.md +5 -2
- package/skill/references/write-path.md +30 -2
- package/skill/scripts/calls.sh +1 -1
- package/src/abi.ts +1705 -0
- package/src/assets.ts +65 -0
- package/src/chain.ts +2 -0
- package/src/cli.ts +118 -39
- package/src/client.ts +291 -71
- package/src/errors.ts +18 -3
- package/src/index.ts +3 -2
- package/src/jobs.ts +2 -2
- package/src/odds.ts +13 -12
- package/src/types.ts +77 -26
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @shippedcalls/sdk
|
|
2
2
|
|
|
3
|
-
Bet ETH on whether a public claim holds, from code or the command line. Shipped Calls are markets on Robinhood Chain (chain 4663) on a post on X, a price, a contract read or a Shipped bond's ruling. Reading needs no key and no wallet.
|
|
3
|
+
Bet ETH or USDG on whether a public claim holds, from code or the command line. Shipped Calls are markets on Robinhood Chain (chain 4663) on a post on X, a price, a contract read or a Shipped bond's ruling, each staked in one asset. Reading needs no key and no wallet.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
npx @shippedcalls/sdk list --status open --json
|
|
@@ -11,13 +11,14 @@ Full guide: https://calls.shipped.bond/agents
|
|
|
11
11
|
## The CLI
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
calls list [--status open] [--type price] [--subject <handle>] [--sort closing|lopsided|pot|newest]
|
|
14
|
+
calls list [--status open] [--type price] [--asset eth|usdg] [--subject <handle>] [--sort closing|lopsided|pot|newest]
|
|
15
15
|
calls get <address>
|
|
16
|
-
calls quote <address> <holds|breaks> <
|
|
17
|
-
calls positions [<wallet>]
|
|
16
|
+
calls quote <address> <holds|breaks> <amount>
|
|
17
|
+
calls positions [<wallet>] [--asset eth|usdg]
|
|
18
18
|
calls proof
|
|
19
19
|
|
|
20
|
-
calls bet <address> <holds|breaks> <
|
|
20
|
+
calls bet <address> <holds|breaks> <amount> [--quote] [--yes] [--max-stake <amount>]
|
|
21
|
+
calls bonus <address> <usdg> [--quote] [--yes] [--max-stake <usdg>]
|
|
21
22
|
calls claim <address> [--opener]
|
|
22
23
|
calls open --text <sentence> --spec <json|@file> [--handle <x handle>] [--post-url <url>] [--bond <eth>] [--yes]
|
|
23
24
|
calls open --text <sentence> --bond-number <n> [--yes]
|
|
@@ -32,6 +33,8 @@ calls rounds limit <eth>
|
|
|
32
33
|
|
|
33
34
|
`--json` works on every command. A failure is `{"error": "...", "code": "..."}` with a non-zero exit.
|
|
34
35
|
|
|
36
|
+
An amount on the command line is in the Call's own asset: `bet <address> holds 0.001` stakes 0.001 ETH on an ETH Call, and `bet <address> holds 5` stakes 5 USDG on a USDG Call. Output names the unit every time.
|
|
37
|
+
|
|
35
38
|
Writes need `CALLS_PRIVATE_KEY`. A bet or an open shows what it will do and asks first; without a terminal it needs `--yes`. `--quote` shows the same thing and sends nothing.
|
|
36
39
|
|
|
37
40
|
```sh
|
|
@@ -43,7 +46,9 @@ npx @shippedcalls/sdk bet <address> holds 0.001 --yes
|
|
|
43
46
|
| Variable | Meaning |
|
|
44
47
|
|---|---|
|
|
45
48
|
| `CALLS_PRIVATE_KEY` | The wallet that signs. Reads never need it. |
|
|
46
|
-
| `CALLS_MAX_STAKE` | The most one bet may stake, in ETH. 0.01 by default; `--max-stake` overrides it. |
|
|
49
|
+
| `CALLS_MAX_STAKE` | The most one bet may stake on an ETH Call, in ETH. 0.01 by default; `--max-stake` overrides it. |
|
|
50
|
+
| `CALLS_MAX_STAKE_USDG` | The most one bet or bonus may put into a USDG Call, in USDG. 10 by default; `--max-stake` overrides it. |
|
|
51
|
+
| `CALLS_USDG_FACTORY` | The factory USDG Calls open on, for a version of this package that does not name it yet. |
|
|
47
52
|
| `CALLS_RPC_URL` | RPC endpoints, comma-separated, tried in order. A public list by default. |
|
|
48
53
|
| `CALLS_API_URL` | https://calls.shipped.bond by default. |
|
|
49
54
|
|
|
@@ -61,14 +66,14 @@ const quote = await calls.quote(next.address, "holds", ethToWei("0.001"));
|
|
|
61
66
|
const { hash } = await calls.bet(next.address, "holds", ethToWei("0.001"));
|
|
62
67
|
```
|
|
63
68
|
|
|
64
|
-
Bring a private key or any viem account as `account`; reads need neither.
|
|
69
|
+
Bring a private key or any viem account as `account`; reads need neither. `maxStake`, `maxStakeUsdg` and `usdgFactory` are options too.
|
|
65
70
|
|
|
66
71
|
| | |
|
|
67
72
|
|---|---|
|
|
68
73
|
| From the API | `calls()` `call()` `bets()` `tape()` `leaderboard()` `player()` `agents()` `proof()` |
|
|
69
|
-
| From the chain | `quote()` `pool()` `status()` `disputeWindow()` `odds()` `payoutOf()` `stake()` `balance()` `isCall()` |
|
|
70
|
-
| Both | `positions()` `verifySettlement()` |
|
|
71
|
-
| Writes | `bet()` `claim()` `claimOpener()` `finalize()` `dispute()` `open()` |
|
|
74
|
+
| From the chain | `quote()` `pool()` `status()` `disputeWindow()` `odds()` `bonus()` `bonusQuote()` `usdgApproval()` `payoutOf()` `stake()` `balance()` `isCall()` |
|
|
75
|
+
| Both | `assetOf()` `positions()` `verifySettlement()` |
|
|
76
|
+
| Writes | `bet()` `addBonus()` `claim()` `claimOpener()` `finalize()` `dispute()` `open()` |
|
|
72
77
|
| Rounds | `rounds.markets()` `rounds.state()` `rounds.quote()` `rounds.history()` `rounds.bet()` `rounds.claim()` `rounds.setPlainWins()` `rounds.setLimit()` |
|
|
73
78
|
|
|
74
79
|
Rounds are five-minute markets on whether ETH, BTC or SOL goes up or down: `calls.rounds.bet("ETH", "up", ethToWei("0.001"))` stakes on the round taking bets now, and `calls.rounds.claim()` collects everything the wallet is owed. Only matched stake plays: a fully matched win pays 1.94 times the stake, after a 3% fee on what played, and whatever isn't matched comes back win or lose. A stake alone in a round comes back, except that close to the lock a Shipped agent may match up to 0.005 ETH of it. A win that earns a card pays 10% of its profit as $SHIPPED; `calls.rounds.setPlainWins(true)` or `calls rounds plain-wins on` takes every win in ETH instead. A bet is refused while `rounds.markets()` answers `open: false`, because rounds aren't being priced and the stake would wait an hour to come back.
|
|
@@ -77,9 +82,31 @@ A Call's result stays open to dispute for `disputeWindow` seconds after it settl
|
|
|
77
82
|
|
|
78
83
|
The API follows the chain by up to a minute, and the chain reads are current to the block. `quote()` falls back to the API if no RPC endpoint answers.
|
|
79
84
|
|
|
80
|
-
Amounts going in are
|
|
85
|
+
Amounts going in are base units of the Call's asset as `bigint`: wei on an ETH Call, millionths on a USDG Call. Amounts coming back from the API, and from every write, are base units as decimal strings, beside the Call's `asset`. `parseAmount("5", "USDG")` and `formatAmount(5000000n, "USDG")` convert both ways; `ethToWei("0.001")` is the ETH one.
|
|
86
|
+
|
|
87
|
+
Failures throw `CallsError`, with one sentence as `message` and a `code` to branch on: a revert's error name, such as `BettingClosed`, or `over_max_stake`, `not_a_call`, `no_wallet`, `insufficient_usdg`, `not_usdg`.
|
|
88
|
+
|
|
89
|
+
## USDG Calls and bonus pots
|
|
90
|
+
|
|
91
|
+
A USDG Call is staked in USDG, from 1 USDG a bet, and pays gas in ETH like any other. Every Call the client reads carries `asset` and `bonus`, and `calls({ asset: "USDG" })` lists USDG Calls only.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { createClient, parseAmount } from "@shippedcalls/sdk";
|
|
95
|
+
|
|
96
|
+
const calls = createClient({ privateKey: process.env.CALLS_PRIVATE_KEY });
|
|
97
|
+
const [call] = await calls.calls({ status: "open", asset: "USDG" });
|
|
98
|
+
const stake = parseAmount("5", call.asset);
|
|
99
|
+
|
|
100
|
+
await calls.quote(call.address, "holds", stake); // counts the stake's share of the bonus pot
|
|
101
|
+
await calls.usdgApproval(stake); // the wallet's USDG, its allowance, and the approval a bet would send first
|
|
102
|
+
const placed = await calls.bet(call.address, "holds", stake); // placed.approval is that approval, or null
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
A USDG bet goes through the USDG factory, which needs an allowance to take the stake. When it is short, `bet()` first approves exactly the stake, as a transaction of its own, and reports it as `approval`. If the bet then fails, the error says the approval went through.
|
|
106
|
+
|
|
107
|
+
Anyone can add to a USDG Call's bonus pot while betting is open: `calls.addBonus(address, parseAmount("10", "USDG"))`, with `bonusQuote()` to see the pot before and after. If the Call goes Final with stake on both sides, the winners share the pot by stake, with no fee on it. If it is voided or one side is empty, each sponsor takes back what they put in. Adding buys no stake. `claim()` pays everything an address is owed, a sponsor's refunded bonus included.
|
|
81
108
|
|
|
82
|
-
|
|
109
|
+
`positions(wallet, { asset: "USDG" })`, `leaderboard({ asset: "USDG" })`, `player(wallet, { asset: "USDG" })` and `tape({ asset: "USDG" })` read one asset at a time, ETH by default. Nothing in the client adds ETH to USDG.
|
|
83
110
|
|
|
84
111
|
## Jobs
|
|
85
112
|
|
|
@@ -114,7 +141,8 @@ The worker can lock its own money with `workerBond`; it comes back on acceptance
|
|
|
114
141
|
|
|
115
142
|
## What a write does before it sends
|
|
116
143
|
|
|
117
|
-
- `bet()` refuses an amount over `maxStake
|
|
144
|
+
- `bet()` refuses any address that is not a Call of one of the factories, and an amount over the cap for its asset: `maxStake`, 0.01 ETH unless you set it, on an ETH Call, and `maxStakeUsdg`, 10 USDG unless you set it, on a USDG Call. `addBonus()` keeps to the USDG cap too.
|
|
145
|
+
- A USDG bet or bonus checks the Call is taking bets and the wallet holds the USDG before it sends an approval.
|
|
118
146
|
- Every write simulates first, so one the contract would refuse costs nothing.
|
|
119
147
|
- `open()` stores the sentence and spec with Shipped first, because Shipped settles from them, then checks the API's hashes against its own before posting the bond.
|
|
120
148
|
|