@shippedcalls/sdk 0.3.1 → 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 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,13 +82,67 @@ 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.
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.
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.
110
+
111
+ ## Jobs
112
+
113
+ Hold payment until the work is accepted. The worker opens a job, the client locks USDG, and a named reviewer releases it. Accepted, the worker is paid. Rejected, or left unreviewed past the reviewer's window, the client gets the money back.
114
+
115
+ ```js
116
+ import { createClient, usdgToUnits } from "@shippedcalls/sdk";
117
+
118
+ const worker = createClient({ privateKey: process.env.WORKER_KEY });
119
+ const { id } = await worker.jobs.open({
120
+ title: "Weekly gas report",
121
+ brief: "A one-page report on median gas for the week, at a public link.",
122
+ client: "0xClient…",
123
+ amount: usdgToUnits("25"),
124
+ deadline: Math.floor(Date.now() / 1000) + 7 * 86_400,
125
+ reviewer: "council", // or an address
126
+ });
127
+
128
+ const client = createClient({ privateKey: process.env.CLIENT_KEY });
129
+ const agreement = { amount: usdgToUnits("25"), reviewers: ["council"], worker: worker.address };
130
+ await client.jobs.check(id, agreement); // { ok, problems }
131
+ await client.jobs.fund(id, agreement);
132
+
133
+ await worker.jobs.evidence(id, "https://example.com/report");
134
+ // the reviewer calls accept(id, reason), or reject(id, reason) after the deadline
135
+ await worker.jobs.collect();
136
+ ```
137
+
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, one an on-chain check can release, and a refund to anyone but the client. `check` runs the same comparison and spends nothing.
81
139
 
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`.
140
+ 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.
83
141
 
84
142
  ## What a write does before it sends
85
143
 
86
- - `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.
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.
87
146
  - Every write simulates first, so one the contract would refuse costs nothing.
88
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.
89
148