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