@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/src/odds.ts
CHANGED
|
@@ -36,37 +36,38 @@ export interface Pools {
|
|
|
36
36
|
breaks: bigint;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function multiple(winners: bigint, losers: bigint): number | null {
|
|
39
|
+
function multiple(winners: bigint, losers: bigint, bonus: bigint): number | null {
|
|
40
40
|
if (winners === 0n) return losers === 0n ? 1 : null;
|
|
41
|
-
const paid = winners + (losers * (10000n - RAKE_BPS)) / 10000n;
|
|
41
|
+
const paid = winners + (losers * (10000n - RAKE_BPS)) / 10000n + (losers === 0n ? 0n : bonus);
|
|
42
42
|
return Number((paid * 10000n) / winners) / 10000;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Each side's share of the pot in bps, 0 on an empty pot as the contract's `odds()` does, and what one unit staked now
|
|
47
|
-
* would come back as if that side wins. A one-sided pot pays 1.0: winners get their stake
|
|
47
|
+
* would come back as if that side wins, with any bonus shared on top. A one-sided pot pays 1.0: winners get their stake
|
|
48
|
+
* back and the bonus goes back to its sponsors.
|
|
48
49
|
*/
|
|
49
|
-
export function odds({ holds, breaks }: Pools) {
|
|
50
|
+
export function odds({ holds, breaks }: Pools, bonus = 0n) {
|
|
50
51
|
const total = holds + breaks;
|
|
51
52
|
const holdsBps = total === 0n ? 0 : Number((holds * 10000n) / total);
|
|
52
53
|
return {
|
|
53
54
|
holdsBps,
|
|
54
55
|
breaksBps: total === 0n ? 0 : 10000 - holdsBps,
|
|
55
|
-
holdsMultiple: multiple(holds, breaks),
|
|
56
|
-
breaksMultiple: multiple(breaks, holds),
|
|
56
|
+
holdsMultiple: multiple(holds, breaks, bonus),
|
|
57
|
+
breaksMultiple: multiple(breaks, holds, bonus),
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
* The contract's claim maths. A winning stake comes back with its share of the losing pool after the rake
|
|
62
|
-
* the whole stake an account has on that side; a pot with an empty side refunds every stake.
|
|
62
|
+
* The contract's claim maths. A winning stake comes back with its share of the losing pool after the rake and of the
|
|
63
|
+
* bonus, floored on the whole stake an account has on that side; a pot with an empty side refunds every stake.
|
|
63
64
|
*/
|
|
64
|
-
export function payout(stake: bigint, side: Side, pools: Pools, outcome: Side): bigint {
|
|
65
|
+
export function payout(stake: bigint, side: Side, pools: Pools, outcome: Side, bonus = 0n): bigint {
|
|
65
66
|
if (stake <= 0n) return 0n;
|
|
66
67
|
if (pools.holds === 0n || pools.breaks === 0n) return stake;
|
|
67
68
|
if (side !== outcome) return 0n;
|
|
68
69
|
const losers = side === "holds" ? pools.breaks : pools.holds;
|
|
69
|
-
return stake + (stake * (losers - (losers * RAKE_BPS) / 10000n)) / pools[side];
|
|
70
|
+
return stake + (stake * (losers - (losers * RAKE_BPS) / 10000n + bonus)) / pools[side];
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
/** Payout over stake, floored to two decimals. */
|
|
@@ -81,9 +82,9 @@ const shareOf = (pools: Pools, side: Side) => {
|
|
|
81
82
|
* What `amount` on `side` pays if that side wins, with the pools as the bet leaves them. A parimutuel price is not
|
|
82
83
|
* fixed: this holds for the pools as they stand now, and later bets move it until betting closes.
|
|
83
84
|
*/
|
|
84
|
-
export function quoteOf(pools: Pools, side: Side, amount: bigint) {
|
|
85
|
+
export function quoteOf(pools: Pools, side: Side, amount: bigint, bonus = 0n) {
|
|
85
86
|
const poolsAfter = { ...pools, [side]: pools[side] + amount } as Pools;
|
|
86
|
-
const paid = payout(amount, side, poolsAfter, side);
|
|
87
|
+
const paid = payout(amount, side, poolsAfter, side, bonus);
|
|
87
88
|
return {
|
|
88
89
|
poolsAfter,
|
|
89
90
|
impliedBps: shareOf(pools, side),
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { Address, Hash, Hex } from "viem";
|
|
2
|
+
import type { Asset, AssetSymbol } from "./assets.js";
|
|
2
3
|
import type { Side } from "./odds.js";
|
|
3
4
|
|
|
4
|
-
// The API's answers as served: amounts are
|
|
5
|
-
// case: some routes checksum them and some
|
|
5
|
+
// The API's answers as served: amounts are base units of the Call's asset as decimal strings (wei on an ETH Call,
|
|
6
|
+
// millionths on a USDG Call), times unix seconds. Compare addresses without case: some routes checksum them and some
|
|
7
|
+
// lowercase them. GET /v1/openapi.json is the full description.
|
|
6
8
|
|
|
7
9
|
export type CallStatus = "open" | "settled" | "disputed" | "final" | "voided";
|
|
8
10
|
export type CallType = "posted" | "onchain" | "price" | "deed";
|
|
9
11
|
export type Wei = string;
|
|
12
|
+
/** Base units of the Call's own asset, as a decimal string: wei for ETH, millionths for USDG. */
|
|
13
|
+
export type Units = string;
|
|
10
14
|
|
|
11
15
|
export interface Post {
|
|
12
16
|
id: string | null;
|
|
@@ -36,9 +40,14 @@ export interface CallSummary {
|
|
|
36
40
|
closeAt: number;
|
|
37
41
|
deadline: number;
|
|
38
42
|
openedAt: number;
|
|
39
|
-
|
|
43
|
+
/** What the Call is staked in. Every amount on it is in base units of this asset. */
|
|
44
|
+
asset: Asset;
|
|
45
|
+
bond: Units;
|
|
46
|
+
/** The bonus pot sponsors added, shared by the winners on top of the losing pool. Always "0" on an ETH Call. */
|
|
47
|
+
bonus: Units;
|
|
40
48
|
deedId: string | null;
|
|
41
|
-
|
|
49
|
+
/** `eth` is the pot in ETH, null on a USDG Call; `amount` is the pot in whole units of the Call's asset. */
|
|
50
|
+
pools: { holds: Units; breaks: Units; total: Units; eth: number | null; amount: number };
|
|
42
51
|
odds: { holdsBps: number; breaksBps: number; holdsMultiple: number | null; breaksMultiple: number | null; lopsided: number };
|
|
43
52
|
betCount: number;
|
|
44
53
|
outcome: Side | null;
|
|
@@ -54,7 +63,7 @@ export interface CallSummary {
|
|
|
54
63
|
export interface CallRow extends CallSummary {
|
|
55
64
|
spark: number[];
|
|
56
65
|
change1h: number;
|
|
57
|
-
recentStake:
|
|
66
|
+
recentStake: Units;
|
|
58
67
|
recentBets15: number;
|
|
59
68
|
}
|
|
60
69
|
|
|
@@ -63,9 +72,9 @@ export interface Bet {
|
|
|
63
72
|
logIndex: number;
|
|
64
73
|
bettor: Address;
|
|
65
74
|
side: Side;
|
|
66
|
-
amount:
|
|
67
|
-
holdsPool:
|
|
68
|
-
breaksPool:
|
|
75
|
+
amount: Units;
|
|
76
|
+
holdsPool: Units;
|
|
77
|
+
breaksPool: Units;
|
|
69
78
|
block: number;
|
|
70
79
|
at: number;
|
|
71
80
|
tag: Tag;
|
|
@@ -79,20 +88,22 @@ export interface CallDetail extends CallSummary {
|
|
|
79
88
|
evidence: { hash: Hash; url: string; matchesChain: boolean | null } | null;
|
|
80
89
|
settledBy: Address | null;
|
|
81
90
|
disputer: Address | null;
|
|
82
|
-
disputeBond:
|
|
91
|
+
disputeBond: Units | null;
|
|
83
92
|
disputedAt: number | null;
|
|
84
93
|
resolvedAt: number | null;
|
|
85
|
-
winnersPool:
|
|
86
|
-
losersPool:
|
|
87
|
-
rake:
|
|
88
|
-
openerPaid:
|
|
89
|
-
treasuryPaid:
|
|
94
|
+
winnersPool: Units | null;
|
|
95
|
+
losersPool: Units | null;
|
|
96
|
+
rake: Units | null;
|
|
97
|
+
openerPaid: Units | null;
|
|
98
|
+
treasuryPaid: Units | null;
|
|
90
99
|
openerAtFault: boolean | null;
|
|
91
100
|
reasonHash: Hash | null;
|
|
92
101
|
openedBlock: number;
|
|
93
102
|
openedTx: Hash;
|
|
94
103
|
unresolvable: { reason: string; refundsAt: number } | null;
|
|
95
104
|
bets: Bet[];
|
|
105
|
+
/** Every addition to the bonus pot, newest first. Empty on an ETH Call. */
|
|
106
|
+
bonuses: { txHash: Hash; logIndex: number; sponsor: Address; amount: Units; bonus: Units; block: number; at: number }[];
|
|
96
107
|
records: { tokenId: number; account: Address; collection: Address | null; txHash: Hash; block: number; at: number }[] | null;
|
|
97
108
|
}
|
|
98
109
|
|
|
@@ -102,11 +113,13 @@ export interface RecentBet {
|
|
|
102
113
|
callAddress: Address;
|
|
103
114
|
bettor: Address;
|
|
104
115
|
side: Side;
|
|
105
|
-
amount:
|
|
116
|
+
amount: Units;
|
|
117
|
+
/** What the Call is staked in, and so what `amount` and `pools` are in. */
|
|
118
|
+
asset: AssetSymbol;
|
|
106
119
|
block: number;
|
|
107
120
|
at: number;
|
|
108
121
|
callTextHash: Hash;
|
|
109
|
-
pools: { holds:
|
|
122
|
+
pools: { holds: Units; breaks: Units };
|
|
110
123
|
tag: Tag;
|
|
111
124
|
}
|
|
112
125
|
|
|
@@ -203,18 +216,22 @@ export interface Proof {
|
|
|
203
216
|
export interface Quote {
|
|
204
217
|
call: Address;
|
|
205
218
|
side: Side;
|
|
206
|
-
amount:
|
|
219
|
+
amount: Units;
|
|
220
|
+
/** What the Call is staked in. Every amount in the quote is in base units of it. */
|
|
221
|
+
asset: Asset;
|
|
222
|
+
/** The bonus pot counted in `payout`. "0" on an ETH Call. */
|
|
223
|
+
bonus: Units;
|
|
207
224
|
status: CallStatus;
|
|
208
225
|
bettingOpen: boolean;
|
|
209
226
|
closeAt: number;
|
|
210
|
-
minBet:
|
|
211
|
-
pools: { holds:
|
|
212
|
-
poolsAfter: { holds:
|
|
227
|
+
minBet: Units;
|
|
228
|
+
pools: { holds: Units; breaks: Units };
|
|
229
|
+
poolsAfter: { holds: Units; breaks: Units };
|
|
213
230
|
impliedBps: number | null;
|
|
214
231
|
impliedBpsAfter: number;
|
|
215
|
-
/** If this side wins, with the pools as the bet leaves them. Later bets move it until betting closes. */
|
|
216
|
-
payout:
|
|
217
|
-
profit:
|
|
232
|
+
/** If this side wins, with the pools as the bet leaves them and its share of any bonus. Later bets move it until betting closes. */
|
|
233
|
+
payout: Units;
|
|
234
|
+
profit: Units;
|
|
218
235
|
multiple: number;
|
|
219
236
|
/** The other side is empty. If it stays empty every stake comes back and nobody wins. */
|
|
220
237
|
refund: boolean;
|
|
@@ -297,15 +314,49 @@ export interface Settlement {
|
|
|
297
314
|
|
|
298
315
|
export interface Positions {
|
|
299
316
|
address: Address;
|
|
300
|
-
/** The
|
|
301
|
-
|
|
317
|
+
/** The asset these positions are staked in. ETH unless asked for another; no figure adds one asset to another. */
|
|
318
|
+
asset: Asset;
|
|
319
|
+
/** The wallet's balance of `asset` on the chain, or null when no endpoint answered. */
|
|
320
|
+
balance: Units | null;
|
|
321
|
+
/** The wallet's ETH, which pays the gas whatever the stake is in. On an ETH read it is `balance`. */
|
|
322
|
+
gas: Wei | null;
|
|
302
323
|
positions: Player["positions"];
|
|
303
324
|
/** Newest 50 Final and Voided Calls, each with what `claim()` pays now (`owed`, null when no endpoint answered). */
|
|
304
|
-
settled: (Player["shelf"][number] & { owed:
|
|
325
|
+
settled: (Player["shelf"][number] & { owed: Units | null })[];
|
|
305
326
|
week: Player["week"];
|
|
306
327
|
all: Player["all"];
|
|
307
328
|
}
|
|
308
329
|
|
|
330
|
+
/** What a USDG write needs from the wallet before it goes, read from the chain. */
|
|
331
|
+
export interface Approval {
|
|
332
|
+
token: Address;
|
|
333
|
+
/** The contract the wallet lets take its USDG: the USDG factory for a bet or a bonus, the Call for a dispute. */
|
|
334
|
+
spender: Address;
|
|
335
|
+
owner: Address;
|
|
336
|
+
balance: Units;
|
|
337
|
+
allowance: Units;
|
|
338
|
+
amount: Units;
|
|
339
|
+
/** The allowance to set first, exactly `amount`, or null when the allowance already covers it. A separate transaction. */
|
|
340
|
+
approve: Units | null;
|
|
341
|
+
/** How much USDG the wallet lacks. "0" when it holds enough. */
|
|
342
|
+
short: Units;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** What adding to a USDG Call's bonus pot does, with the pot as it stands. */
|
|
346
|
+
export interface BonusQuote {
|
|
347
|
+
call: Address;
|
|
348
|
+
asset: Asset;
|
|
349
|
+
amount: Units;
|
|
350
|
+
status: CallStatus;
|
|
351
|
+
bettingOpen: boolean;
|
|
352
|
+
closeAt: number;
|
|
353
|
+
pools: { holds: Units; breaks: Units };
|
|
354
|
+
bonus: Units;
|
|
355
|
+
bonusAfter: Units;
|
|
356
|
+
/** What this wallet has put in the pot so far, or null without a wallet. */
|
|
357
|
+
sponsored: Units | null;
|
|
358
|
+
}
|
|
359
|
+
|
|
309
360
|
export type RoundOutcome = "up" | "down" | "refunded";
|
|
310
361
|
export type RoundSide = "up" | "down";
|
|
311
362
|
|