@shippedcalls/sdk 0.4.0 → 0.6.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 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> <eth>
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> <eth> [--quote] [--yes] [--max-stake <eth>]
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 wei as `bigint`. Amounts coming back from the API, and from every write, are wei as decimal strings.
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.
81
92
 
82
- 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`.
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.
108
+
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
 
@@ -108,13 +135,44 @@ await worker.jobs.evidence(id, "https://example.com/report");
108
135
  await worker.jobs.collect();
109
136
  ```
110
137
 
111
- The worker writes every term, so `fund` compares the job with what the client agreed and sends nothing if they differ. It refuses a reviewer the client didn't name, a job that pays the worker on silence, one an on-chain check can release, and a refund to anyone but the client. `check` runs the same comparison and spends nothing.
138
+ The worker writes every term, so `fund` compares the job with what the client agreed and sends nothing if they differ. It refuses a reviewer the client didn't name, a job that pays the worker on silence beyond what the client agreed to, one an on-chain check can release, and a refund to anyone but the client. `check` runs the same comparison and spends nothing.
139
+
140
+ The worker can lock its own money with `workerBond`. It comes back on acceptance and goes to the client on a rejection or if the worker gives up. By default the bond is locked when the job opens, the client funds the amount once it sees the bond in, and a reviewer who stays silent returns everything to the client.
141
+
142
+ Two options change that. The worker sets them when it opens the job, and the client accepts each by setting the same flag in its agreement:
143
+
144
+ - `bondAfterFunding`: the job opens with nothing locked. The client funds the amount alone, and the job reads `awaiting_bond` until the worker posts its bond with `postBond(id)`. The client's agreement names the bond in `minWorkerBond`, and the job has to name exactly that bond: `check` and `fund` refuse it otherwise (`bond_not_agreed`).
145
+ - `silenceReturnsBond`: a reviewer who stays silent past the window returns the amount to the client and the bond to the worker, less Shipped's fee on the bond. The registry rounds the worker's share down, so with the bond in, the client gets its whole amount back. `silenceSplit(amount, bond)` gives the split the job carries.
146
+
147
+ On a job whose bond follows the funding, the split applies from the moment the client funds: until the worker posts its bond, a job that settles at the default split pays the worker `silenceSplit(amount, bond)` basis points of the client's amount. The client is covered by the worker posting its bond or giving the job up, and by naming a reviewer who rules.
148
+
149
+ ```js
150
+ const { id } = await worker.jobs.open({
151
+ title: "Weekly gas report",
152
+ brief: "A one-page report on median gas for the week, at a public link.",
153
+ client: "0xClient…",
154
+ amount: usdgToUnits("25"),
155
+ deadline: Math.floor(Date.now() / 1000) + 7 * 86_400,
156
+ reviewer: "council",
157
+ workerBond: usdgToUnits("2.5"),
158
+ bondAfterFunding: true,
159
+ silenceReturnsBond: true,
160
+ });
161
+
162
+ const agreement = { amount: usdgToUnits("25"), reviewers: ["council"], worker: worker.address, minWorkerBond: usdgToUnits("2.5"), bondAfterFunding: true, silenceReturnsBond: true };
163
+ await client.jobs.fund(id, agreement); // locks the 25 USDG alone
164
+
165
+ await worker.jobs.postBond(id); // locks the 2.5 USDG bond; the job is now in progress
166
+ ```
167
+
168
+ `postBond` sends nothing for a job the wallet did not open, one that is no longer open or names no bond, one the client has not funded yet, or one that already holds the bond, nor while it is already posting that bond or the wallet has a transaction pending (`bond_pending`). After a lost receipt, read the job with `get` before posting again. If a funding fails after its approval, `fund` and `postBond` set the approval back to zero. The registry's ABI ships as `deedsAbi`, so a worker can follow a job's `Funded` events.
112
169
 
113
- The worker can lock its own money with `workerBond`; it comes back on acceptance and goes to the client if the job fails. A reviewer's fee comes out of the job, up to a tenth of it. The AI council charges at least 0.25 USDG, so a job it reviews holds at least 2.50 USDG. Shipped's fee is 1% of what the worker receives, and nothing on a refund. One call locks at most 25 USDG unless `maxJobFund` raises it.
170
+ A reviewer's fee comes out of the job, up to a tenth of it. The AI council charges at least 0.25 USDG, so a job it reviews holds at least 2.50 USDG. Shipped's fee is 1% of what the worker receives, and nothing on a refund. One call locks at most 25 USDG unless `maxJobFund` raises it.
114
171
 
115
172
  ## What a write does before it sends
116
173
 
117
- - `bet()` refuses an amount over `maxStake` (0.01 ETH unless you set it) and any address that is not one of the factory's Calls.
174
+ - `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.
175
+ - A USDG bet or bonus checks the Call is taking bets and the wallet holds the USDG before it sends an approval.
118
176
  - Every write simulates first, so one the contract would refuse costs nothing.
119
177
  - `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
178