@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/dist/client.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type Account, type Address, type Hash, type Transport } from "viem";
2
+ import { type Asset, type AssetSymbol } from "./assets.js";
2
3
  import { type Side } from "./odds.js";
3
- import type { CallDetail, CallRow, CallStatus, CallType, Leaderboard, Opened, OpenInput, Player, Positions, Prepared, Proof, Quote, RecentBet, RoundsAccount, RoundsFloor, RoundSide, RoundsMarket, Settlement, ShippedAgent, TapeItem, Tx } from "./types.js";
4
+ import type { Approval, BonusQuote, CallDetail, CallRow, CallStatus, CallType, Leaderboard, Opened, OpenInput, Player, Positions, Prepared, Proof, Quote, RecentBet, RoundsAccount, RoundsFloor, RoundSide, RoundsMarket, Settlement, ShippedAgent, TapeItem, Tx } from "./types.js";
4
5
  export interface ClientOptions {
5
6
  /** The API's origin. https://calls.shipped.bond by default. */
6
7
  api?: string;
@@ -9,14 +10,18 @@ export interface ClientOptions {
9
10
  /** A private key, or `account` for any viem account. Reads need neither. */
10
11
  privateKey?: string;
11
12
  account?: Account;
12
- /** The most one bet may stake, wei. 0.01 ETH by default. */
13
+ /** The most one bet may stake on an ETH Call, wei. 0.01 ETH by default. */
13
14
  maxStake?: bigint;
15
+ /** The most one bet or bonus may put into a USDG Call, USDG units. 10 USDG by default. */
16
+ maxStakeUsdg?: bigint;
14
17
  /** The most one job call may lock, USDG units. 25 USDG by default. */
15
18
  maxJobFund?: bigint;
16
19
  chainId?: number;
17
20
  factory?: Address;
18
21
  /** Earlier factories whose Calls this client still treats as Calls. The published ones unless `factory` is set. */
19
22
  previousFactories?: readonly Address[];
23
+ /** The factory USDG Calls open on. The published one unless `factory` is set; null leaves USDG Calls out. */
24
+ usdgFactory?: Address | null;
20
25
  fetch?: typeof fetch;
21
26
  /** A viem transport in place of `rpc`. */
22
27
  transport?: Transport;
@@ -35,6 +40,8 @@ export declare function createClient(options?: ClientOptions): {
35
40
  address: `0x${string}` | null;
36
41
  chainId: number;
37
42
  factory: `0x${string}`;
43
+ /** The factory USDG Calls open on, or null when this client knows none. */
44
+ usdgFactory: `0x${string}` | null;
38
45
  /** Hold payment until the work is accepted: the worker opens a job, the client funds it, a named reviewer releases it. */
39
46
  jobs: {
40
47
  get: (jobId: unknown) => Promise<import("./jobs.js").Job>;
@@ -50,6 +57,11 @@ export declare function createClient(options?: ClientOptions): {
50
57
  }) => Promise<import("./jobs.js").JobTx & {
51
58
  amount: string;
52
59
  }>;
60
+ postBond: (jobId: unknown, { maxFund: limit }?: {
61
+ maxFund?: bigint;
62
+ }) => Promise<import("./jobs.js").JobTx & {
63
+ amount: string;
64
+ }>;
53
65
  evidence: (jobId: unknown, uri: string, contentHash?: Hash) => Promise<import("./jobs.js").JobTx>;
54
66
  accept: (jobId: unknown, reason?: string) => Promise<import("./jobs.js").JobTx>;
55
67
  reject: (jobId: unknown, reason: string) => Promise<import("./jobs.js").JobTx>;
@@ -60,10 +72,12 @@ export declare function createClient(options?: ClientOptions): {
60
72
  tx: Tx;
61
73
  }>;
62
74
  };
75
+ /** Every asset by default; `asset` keeps to Calls staked in one. */
63
76
  calls(filters?: {
64
77
  status?: CallStatus;
65
78
  type?: CallType;
66
79
  subject?: string;
80
+ asset?: AssetSymbol;
67
81
  sort?: "closing" | "lopsided" | "pot" | "newest";
68
82
  limit?: number;
69
83
  offset?: number;
@@ -74,31 +88,45 @@ export declare function createClient(options?: ClientOptions): {
74
88
  call?: string;
75
89
  limit?: number;
76
90
  }): Promise<RecentBet[] | CallDetail["bets"]>;
77
- tape({ limit }?: {
91
+ tape({ limit, asset }?: {
78
92
  limit?: number;
93
+ asset?: AssetSymbol;
79
94
  }): Promise<TapeItem[]>;
80
95
  leaderboard: (filters?: {
81
96
  window?: "week" | "all";
82
97
  board?: "profit" | "best" | "streak" | "openers";
83
98
  limit?: number;
84
99
  me?: string;
100
+ asset?: AssetSymbol;
85
101
  }) => Promise<Leaderboard>;
86
- player: (address?: string) => Promise<Player>;
102
+ player: (address?: string, { asset }?: {
103
+ asset?: AssetSymbol;
104
+ }) => Promise<Player>;
87
105
  /** Shipped agents: name, rule and wallet. */
88
106
  agents(): Promise<ShippedAgent[]>;
89
107
  proof: () => Promise<Proof>;
90
108
  /**
91
- * What `amount` wei on `side` pays with the pools as they stand. Reads the pools from the chain, and from the API if
92
- * no endpoint answers. Later bets move the payout until betting closes.
109
+ * What `amount` on `side` pays with the pools as they stand, in base units of the Call's asset, its share of any
110
+ * bonus included. Reads the pools from the chain, and from the API if no endpoint answers. Later bets move the
111
+ * payout until betting closes.
93
112
  */
94
113
  quote(address: string, side: Side | string, amount: bigint): Promise<Quote>;
95
- /** One wallet's open positions and settled Calls from the API, with its balance and what it can claim from the chain. */
96
- positions(address?: string): Promise<Positions>;
114
+ /** What a Call is staked in, from the chain, or from the API if no endpoint answers. */
115
+ assetOf(address: string): Promise<Asset>;
116
+ /**
117
+ * One wallet's open positions and settled Calls in one asset, ETH unless `asset` asks for USDG, from the API, with
118
+ * its balance and what it can claim from the chain. `gas` is its ETH, which pays the gas either way.
119
+ */
120
+ positions(address?: string, { asset }?: {
121
+ asset?: AssetSymbol;
122
+ }): Promise<Positions>;
97
123
  isCall: (address: string) => Promise<boolean>;
98
124
  pool: (address: string, side: Side | string) => Promise<bigint>;
99
125
  status: (address: string) => Promise<CallStatus>;
100
126
  /** Seconds this Call's result stays open to dispute after it settles. A Call of an earlier factory has no such read, and ran 24 hours. */
101
127
  disputeWindow: (address: string) => Promise<number>;
128
+ /** The bonus pot sponsors added to a USDG Call, USDG units. 0 on an ETH Call, which has none. */
129
+ bonus: (address: string) => Promise<bigint>;
102
130
  odds(address: string): Promise<{
103
131
  holdsBps: number;
104
132
  breaksBps: number;
@@ -108,20 +136,27 @@ export declare function createClient(options?: ClientOptions): {
108
136
  holds: bigint;
109
137
  breaks: bigint;
110
138
  };
139
+ bonus: bigint;
111
140
  }>;
112
141
  payoutOf: (address: string, who?: string) => Promise<bigint>;
113
142
  stake: (address: string, side: Side | string, who?: string) => Promise<bigint>;
114
143
  balance: (who?: string) => Promise<bigint>;
115
144
  /**
116
- * Stakes `amount` wei on `side`. Refuses an amount over `maxStake` and an address that is not one of the factory's
117
- * Calls before anything goes out; simulates first, so a bet the contract would refuse costs nothing.
145
+ * Stakes `amount` on `side`, in base units of the Call's asset. Refuses an address that is not a Call of one of the
146
+ * factories, and an amount over the cap for its asset (`maxStake` in wei on an ETH Call, `maxStakeUsdg` in USDG
147
+ * units on a USDG Call), before anything goes out. A USDG bet goes through the USDG factory, and when the factory's
148
+ * allowance is short it first approves exactly `amount` in a transaction of its own, reported as `approval`. Every
149
+ * transaction simulates first, so one the contract would refuse costs nothing.
118
150
  */
119
- bet(address: string, side: Side | string, amount: bigint, { maxStake: cap }?: {
151
+ bet(address: string, side: Side | string, amount: bigint, { maxStake: cap, maxStakeUsdg: usdgCap }?: {
120
152
  maxStake?: bigint;
153
+ maxStakeUsdg?: bigint;
121
154
  }): Promise<{
122
155
  call: `0x${string}`;
123
156
  side: Side;
124
157
  amount: string;
158
+ asset: Asset;
159
+ approval: Tx | null;
125
160
  pools: {
126
161
  holds: string;
127
162
  breaks: string;
@@ -132,6 +167,33 @@ export declare function createClient(options?: ClientOptions): {
132
167
  fee: import("./types.js").Wei;
133
168
  explorerUrl: string | null;
134
169
  }>;
170
+ /**
171
+ * What adding `amount` USDG units to a USDG Call's bonus pot does, with the pot as it stands. Winners share the pot
172
+ * by stake on top of the losing pool, with no fee on it; if the Call is voided or one side is empty, each sponsor
173
+ * takes back what they put in. Sends nothing.
174
+ */
175
+ bonusQuote: (address: string, amount: bigint) => Promise<BonusQuote>;
176
+ /**
177
+ * Adds `amount` USDG units to a USDG Call's bonus pot while betting is open, through the USDG factory, approving
178
+ * exactly `amount` first when the allowance is short. Counts against the same cap as a USDG bet. Adding to the pot
179
+ * buys no stake: to share in it, bet.
180
+ */
181
+ addBonus(address: string, amount: bigint, { maxStakeUsdg: usdgCap }?: {
182
+ maxStakeUsdg?: bigint;
183
+ }): Promise<{
184
+ call: `0x${string}`;
185
+ amount: string;
186
+ asset: Asset;
187
+ approval: Tx | null;
188
+ bonus: string | null;
189
+ hash: Hash;
190
+ block: number;
191
+ gasUsed: string;
192
+ fee: import("./types.js").Wei;
193
+ explorerUrl: string | null;
194
+ }>;
195
+ /** The wallet's USDG, what it has allowed the USDG factory, and the approval a bet or bonus of `amount` would send first. */
196
+ usdgApproval: (amount: bigint, who?: string) => Promise<Approval>;
135
197
  /** Five minutes, up or down. The contract's address comes from the API, so a new deployment needs no new client. */
136
198
  rounds: {
137
199
  /** Every market's round taking bets, the round running and its latest results, in one read. */
@@ -198,9 +260,13 @@ export declare function createClient(options?: ClientOptions): {
198
260
  explorerUrl: string | null;
199
261
  }>;
200
262
  };
201
- /** Collects winnings or a refund once the Call is Final or Voided. The money only ever goes to the wallet that sends this. */
202
- claim: (address: string) => Promise<{
263
+ /**
264
+ * Collects winnings or a refund once the Call is Final or Voided, in the Call's asset, a sponsor's bonus coming back
265
+ * with it when the bonus refunds. The money only ever goes to the wallet that sends this.
266
+ */
267
+ claim(address: string): Promise<{
203
268
  call: `0x${string}`;
269
+ asset: Asset;
204
270
  amount: string | null;
205
271
  hash: Hash;
206
272
  block: number;
@@ -209,8 +275,9 @@ export declare function createClient(options?: ClientOptions): {
209
275
  explorerUrl: string | null;
210
276
  }>;
211
277
  /** Pays the opener's bond and fee share. Anyone can send it; the money only ever goes to the opener. */
212
- claimOpener: (address: string) => Promise<{
278
+ claimOpener(address: string): Promise<{
213
279
  call: `0x${string}`;
280
+ asset: Asset;
214
281
  opener: `0x${string}` | null;
215
282
  amount: string | null;
216
283
  hash: Hash;
@@ -220,7 +287,7 @@ export declare function createClient(options?: ClientOptions): {
220
287
  explorerUrl: string | null;
221
288
  }>;
222
289
  /** Makes a Settled Call Final once its dispute window has passed. Anyone can send it. */
223
- finalize: (address: string) => Promise<{
290
+ finalize(address: string): Promise<{
224
291
  call: `0x${string}`;
225
292
  hash: Hash;
226
293
  block: number;
@@ -228,10 +295,16 @@ export declare function createClient(options?: ClientOptions): {
228
295
  fee: import("./types.js").Wei;
229
296
  explorerUrl: string | null;
230
297
  }>;
231
- /** Disputes a settled result inside its window, posting the dispute bond (0.02 ETH). The court rules; the bond comes back if it flips the result. */
232
- dispute: (address: string) => Promise<{
298
+ /**
299
+ * Disputes a settled result inside its window, posting the dispute bond: 0.02 ETH on an ETH Call, 20 USDG on a USDG
300
+ * Call, which pulls it after an approval of exactly the bond to the Call. The court rules; the bond comes back if it
301
+ * flips the result.
302
+ */
303
+ dispute(address: string): Promise<{
233
304
  call: `0x${string}`;
305
+ asset: Asset;
234
306
  bond: string;
307
+ approval: Tx | null;
235
308
  hash: Hash;
236
309
  block: number;
237
310
  gasUsed: string;