@dcasegr/amm-client 0.38.2 → 0.41.1
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 +64 -24
- package/dist/client.d.ts +206 -62
- package/dist/client.js +388 -333
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +6 -3
- package/dist/index.d.ts +16 -4
- package/dist/index.js +16 -4
- package/dist/lib/overlay.d.ts +226 -19
- package/dist/lib/overlay.js +278 -49
- package/dist/lib/skein.d.ts +2 -0
- package/dist/lib/skein.js +1 -1
- package/dist/market/activeSwap.d.ts +77 -96
- package/dist/market/activeSwap.js +146 -166
- package/dist/market/plan.d.ts +2 -1
- package/dist/market/plan.js +1 -1
- package/dist/market/prices.d.ts +4 -4
- package/dist/market/prices.js +4 -4
- package/dist/market/swapAction.d.ts +150 -145
- package/dist/market/swapAction.js +292 -213
- package/dist/market/swapFlow.d.ts +3 -6
- package/dist/market/swapFlow.js +4 -22
- package/dist/pool/pool.artifact.json +760 -528
- package/dist/pool/template.d.ts +10 -2
- package/dist/pool/template.js +16 -6
- package/dist/wallet/color.d.ts +13 -9
- package/dist/wallet/color.js +13 -10
- package/dist/wallet/swapPayouts.d.ts +45 -28
- package/dist/wallet/swapPayouts.js +129 -117
- package/package.json +2 -2
package/dist/errors.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SwapOutcome } from "./market/swapFlow.js";
|
|
2
2
|
/** Every kind a `ClientError` names (D13). */
|
|
3
|
-
export declare const CLIENT_ERROR_KINDS: readonly ["stale_pool", "fee_mismatch", "quote_mismatch", "slippage", "pool_spent", "user_rejected", "no_answer", "refused", "network"];
|
|
3
|
+
export declare const CLIENT_ERROR_KINDS: readonly ["stale_pool", "fee_mismatch", "quote_mismatch", "slippage", "pool_spent", "user_rejected", "no_answer", "below_minimum", "refused", "network"];
|
|
4
4
|
export type ClientErrorKind = (typeof CLIENT_ERROR_KINDS)[number];
|
|
5
5
|
/** An error of a named kind; `message` is the text the pages show. */
|
|
6
6
|
export declare class ClientError extends Error {
|
package/dist/errors.js
CHANGED
|
@@ -15,13 +15,16 @@
|
|
|
15
15
|
* `pool_spent` refusal)
|
|
16
16
|
* user_rejected the user declined in the wallet (the wallet's `ERR_PERMISSION_DENIED`, "denied")
|
|
17
17
|
* no_answer the relay gave no settled answer yet ("no answer yet"; a timed-out swap record)
|
|
18
|
-
*
|
|
18
|
+
* below_minimum (0.40.0) under a validator's minimum leg (its `below_minimum` refusal; a quote no
|
|
19
|
+
* pool takes for its size)
|
|
20
|
+
* refused the validator, the relay or the host refused it (a refusal other than pool_spent
|
|
21
|
+
* and below_minimum)
|
|
19
22
|
* network the request did not get through (fetch threw)
|
|
20
23
|
*/
|
|
21
24
|
import { PoolBuildError } from "./pool/index.js";
|
|
22
25
|
import { RelayError } from "./market/relay.js";
|
|
23
26
|
/** Every kind a `ClientError` names (D13). */
|
|
24
|
-
export const CLIENT_ERROR_KINDS = ["stale_pool", "fee_mismatch", "quote_mismatch", "slippage", "pool_spent", "user_rejected", "no_answer", "refused", "network"];
|
|
27
|
+
export const CLIENT_ERROR_KINDS = ["stale_pool", "fee_mismatch", "quote_mismatch", "slippage", "pool_spent", "user_rejected", "no_answer", "below_minimum", "refused", "network"];
|
|
25
28
|
/** An error of a named kind; `message` is the text the pages show. */
|
|
26
29
|
export class ClientError extends Error {
|
|
27
30
|
kind;
|
|
@@ -65,7 +68,7 @@ export function kindOfOutcome(o) {
|
|
|
65
68
|
case "accepted":
|
|
66
69
|
return undefined;
|
|
67
70
|
case "refused":
|
|
68
|
-
return o.reason.startsWith("pool_spent") ? "pool_spent" : "refused";
|
|
71
|
+
return o.reason.startsWith("pool_spent") ? "pool_spent" : o.reason.startsWith("below_minimum") ? "below_minimum" : "refused";
|
|
69
72
|
case "timeout":
|
|
70
73
|
case "unknown":
|
|
71
74
|
return "no_answer";
|
package/dist/index.d.ts
CHANGED
|
@@ -15,11 +15,23 @@ export { SWAP_BASKET } from "./wallet/color.js";
|
|
|
15
15
|
export { SWAP_PROTOCOL } from "./wallet/color.js";
|
|
16
16
|
/** The keyID prefix of an `amm-swap` row's key (`amm-swap-`). */
|
|
17
17
|
export { SWAP_KEY_PREFIX } from "./market/activeSwap.js";
|
|
18
|
-
/**
|
|
19
|
-
export {
|
|
20
|
-
/**
|
|
18
|
+
/** A staged `amm-swap` row's keyID (0.40.0): `amm-swap-<16 random bytes, hex>`. */
|
|
19
|
+
export { newSwapKeyID } from "./market/activeSwap.js";
|
|
20
|
+
/** The label of a staging action that carries tokens (`amm-swap-stage`, 0.40.0). */
|
|
21
|
+
export { SWAP_STAGE_LABEL } from "./market/activeSwap.js";
|
|
22
|
+
/** The marker a staged token output's description ends with (` · amm-swap <hex>`): it names the key id. */
|
|
23
|
+
export { SWAP_KEY_MARK } from "./market/activeSwap.js";
|
|
24
|
+
/** A staged token output's description: the readable text, then `SWAP_KEY_MARK` and the keyID's hex. */
|
|
25
|
+
export { swapKeyDescription } from "./market/activeSwap.js";
|
|
26
|
+
/** The keyID a staged token output's description names, or null. */
|
|
27
|
+
export { swapKeyIdOfDescription } from "./market/activeSwap.js";
|
|
28
|
+
/** The keyID of a leg's change kept in `amm-swap`: `amm-swap-<txid>.<vout>:change`, the leg's first input of that kind. */
|
|
29
|
+
export { changeKeyID } from "./market/swapAction.js";
|
|
30
|
+
/** An order's payout, own-commission and last-leg change derivation: from the order's key input. */
|
|
31
|
+
export { legDerivation } from "./market/swapAction.js";
|
|
32
|
+
/** customInstructions of an `amm-swap` token row (asset, amount, the key that spends it; a change row's `order`). */
|
|
21
33
|
export { swapInstructions } from "./wallet/color.js";
|
|
22
|
-
/** customInstructions of an `amm-swap` sats row (`sats: true`,
|
|
34
|
+
/** customInstructions of an `amm-swap` sats row (`sats: true`, its key; a change row's `order`). */
|
|
23
35
|
export { swapSatsInstructions } from "./wallet/color.js";
|
|
24
36
|
/** The key protocol of a pool's LP key (BRC-29, to self): the `amm-pools` row's protocolID. */
|
|
25
37
|
export { LP_KEY_PROTOCOL } from "./lp/poolDeploy.js";
|
package/dist/index.js
CHANGED
|
@@ -17,11 +17,23 @@ export { SWAP_BASKET } from "./wallet/color.js";
|
|
|
17
17
|
export { SWAP_PROTOCOL } from "./wallet/color.js";
|
|
18
18
|
/** The keyID prefix of an `amm-swap` row's key (`amm-swap-`). */
|
|
19
19
|
export { SWAP_KEY_PREFIX } from "./market/activeSwap.js";
|
|
20
|
-
/**
|
|
21
|
-
export {
|
|
22
|
-
/**
|
|
20
|
+
/** A staged `amm-swap` row's keyID (0.40.0): `amm-swap-<16 random bytes, hex>`. */
|
|
21
|
+
export { newSwapKeyID } from "./market/activeSwap.js";
|
|
22
|
+
/** The label of a staging action that carries tokens (`amm-swap-stage`, 0.40.0). */
|
|
23
|
+
export { SWAP_STAGE_LABEL } from "./market/activeSwap.js";
|
|
24
|
+
/** The marker a staged token output's description ends with (` · amm-swap <hex>`): it names the key id. */
|
|
25
|
+
export { SWAP_KEY_MARK } from "./market/activeSwap.js";
|
|
26
|
+
/** A staged token output's description: the readable text, then `SWAP_KEY_MARK` and the keyID's hex. */
|
|
27
|
+
export { swapKeyDescription } from "./market/activeSwap.js";
|
|
28
|
+
/** The keyID a staged token output's description names, or null. */
|
|
29
|
+
export { swapKeyIdOfDescription } from "./market/activeSwap.js";
|
|
30
|
+
/** The keyID of a leg's change kept in `amm-swap`: `amm-swap-<txid>.<vout>:change`, the leg's first input of that kind. */
|
|
31
|
+
export { changeKeyID } from "./market/swapAction.js";
|
|
32
|
+
/** An order's payout, own-commission and last-leg change derivation: from the order's key input. */
|
|
33
|
+
export { legDerivation } from "./market/swapAction.js";
|
|
34
|
+
/** customInstructions of an `amm-swap` token row (asset, amount, the key that spends it; a change row's `order`). */
|
|
23
35
|
export { swapInstructions } from "./wallet/color.js";
|
|
24
|
-
/** customInstructions of an `amm-swap` sats row (`sats: true`,
|
|
36
|
+
/** customInstructions of an `amm-swap` sats row (`sats: true`, its key; a change row's `order`). */
|
|
25
37
|
export { swapSatsInstructions } from "./wallet/color.js";
|
|
26
38
|
/** The key protocol of a pool's LP key (BRC-29, to self): the `amm-pools` row's protocolID. */
|
|
27
39
|
export { LP_KEY_PROTOCOL } from "./lp/poolDeploy.js";
|
package/dist/lib/overlay.d.ts
CHANGED
|
@@ -15,7 +15,9 @@ export declare function ammLookupService(tokenId: string): string;
|
|
|
15
15
|
export declare function parseTokenTopic(name: string): TokenTopic | null;
|
|
16
16
|
/** A pool row on the wire (P2, P3, P4's `current`): JSON numbers, bigints here. */
|
|
17
17
|
interface WirePool {
|
|
18
|
+
poolId?: string;
|
|
18
19
|
lpPubKey?: string;
|
|
20
|
+
swaps?: number | string;
|
|
19
21
|
outpoint: string;
|
|
20
22
|
bsvReserve: number | string;
|
|
21
23
|
tokenReserve: number | string;
|
|
@@ -28,9 +30,13 @@ interface WirePool {
|
|
|
28
30
|
}
|
|
29
31
|
/** The engine's PoolState from a wire row (the reserves and fees as bigints). */
|
|
30
32
|
export declare function toPoolState(raw: WirePool): PoolState;
|
|
31
|
-
/** A pool of the pools routes: the engine's PoolState, its
|
|
33
|
+
/** A pool of the pools routes: the engine's PoolState, its id (0.40.0: the deploy outpoint `<txid>_<vout>`), its LP key, its swap count, and (P2) its validator's peer ID. */
|
|
32
34
|
export interface PoolRow extends PoolState {
|
|
35
|
+
/** The pool's id: its deploy outpoint, `<txid>_<vout>` (0.40.0). */
|
|
36
|
+
poolId: string;
|
|
33
37
|
lpPubKey: string;
|
|
38
|
+
/** The pool's swaps so far (0 at the deploy). */
|
|
39
|
+
swaps: number;
|
|
34
40
|
/** P2: the validator's libp2p peer ID, from its beat (what the relay dials). */
|
|
35
41
|
validatorPeerId?: string;
|
|
36
42
|
/** P1: the token. */
|
|
@@ -43,10 +49,11 @@ export interface Market {
|
|
|
43
49
|
commissionPkh: string | null;
|
|
44
50
|
minCommissionBps: number;
|
|
45
51
|
}
|
|
46
|
-
/** A validator beating on the token's topic now (P2's `validators`, 0.34.1): its identity key and libp2p peer ID. */
|
|
52
|
+
/** A validator beating on the token's topic now (P2's `validators`, 0.34.1): its identity key and libp2p peer ID; 0.40.0, the minimum leg its terms announce (sats on the leg's sats side; absent: none). */
|
|
47
53
|
export interface BeatingValidator {
|
|
48
54
|
identity: string;
|
|
49
55
|
peerId: string;
|
|
56
|
+
minLegSats?: bigint;
|
|
50
57
|
}
|
|
51
58
|
/** P2's answer: the market, the pools a swap may use now, and (0.34.1) the validators beating on the token's topic now. */
|
|
52
59
|
export interface PoolsAnswer {
|
|
@@ -87,37 +94,35 @@ export interface SignedFetch {
|
|
|
87
94
|
type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
|
|
88
95
|
/** P1 / P2's URL: `<base>/pools` (the swap instance's app base: every token; a token instance's: that token). */
|
|
89
96
|
export declare function poolsUrl(base: string): string;
|
|
90
|
-
/** P2
|
|
97
|
+
/** P2: the token's pools as the host lists them now (0.41.0: a plain read only). */
|
|
91
98
|
export declare function readPools(base: string, fetchFn?: FetchFn): Promise<PoolsAnswer>;
|
|
92
|
-
/** What `
|
|
99
|
+
/** What `watchPoolEvents` needs of the browser's `EventSource` (tests pass a fake). */
|
|
93
100
|
export interface EventSourceLike {
|
|
94
101
|
addEventListener(type: string, fn: (e: {
|
|
95
102
|
data?: unknown;
|
|
96
103
|
}) => void): void;
|
|
97
104
|
close(): void;
|
|
98
105
|
onerror?: ((e: unknown) => void) | null;
|
|
99
|
-
onopen?: ((e: unknown) => void) | null;
|
|
100
106
|
}
|
|
101
107
|
export type EventSourceCtor = new (url: string) => EventSourceLike;
|
|
108
|
+
/** E1's URL: `<base>/events` (a token instance's app base: that token's; the swap app's: every token's). */
|
|
109
|
+
export declare function eventsUrl(base: string): string;
|
|
102
110
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* EventSource (an old browser, a test): ONE plain GET, no poll. → the unsubscribe.
|
|
111
|
+
* Listens to a host's pool event feed (E1, 0.41.0): each `pool` message parsed
|
|
112
|
+
* (`parsePoolEventMessage`) to `onEvent`; one it cannot parse is passed over. Reconnecting is the
|
|
113
|
+
* browser's EventSource's. Without an EventSource: nothing. → the unsubscribe.
|
|
107
114
|
*/
|
|
108
|
-
export declare function
|
|
115
|
+
export declare function watchPoolEvents(url: string, onEvent: (e: PoolEventMessage) => void, o?: {
|
|
109
116
|
onError?: (e: unknown) => void;
|
|
110
|
-
onOpen?: () => void;
|
|
111
117
|
EventSource?: EventSourceCtor | null;
|
|
112
|
-
fetch?: FetchFn;
|
|
113
118
|
}): () => void;
|
|
114
|
-
/** P3's answer: the
|
|
119
|
+
/** P3's answer: the pools' current outputs and one BEEF of their transactions. */
|
|
115
120
|
export interface PoolsBeef {
|
|
116
121
|
pools: PoolRow[];
|
|
117
122
|
beef: number[];
|
|
118
123
|
}
|
|
119
|
-
/** P3: `GET <base>/pools/beef?
|
|
120
|
-
export declare function readPoolsBeef(base: string,
|
|
124
|
+
/** P3: `GET <base>/pools/beef?pool=id1,id2` (0.40.0: by pool id; no `poolIds`: every live pool). */
|
|
125
|
+
export declare function readPoolsBeef(base: string, poolIds?: string[], fetchFn?: FetchFn): Promise<PoolsBeef>;
|
|
121
126
|
/** One output of a pool transaction with its BEEF (Atomic, the transaction its subject): what a spend of the pool is built from. */
|
|
122
127
|
export interface LookupOutput {
|
|
123
128
|
beef: number[];
|
|
@@ -125,9 +130,12 @@ export interface LookupOutput {
|
|
|
125
130
|
}
|
|
126
131
|
/** The pool `outpoint` (`<txid>_<vout>`) out of P3's BEEF, as an Atomic BEEF of its transaction; null when the BEEF lacks it. */
|
|
127
132
|
export declare function poolOutputOf(pb: PoolsBeef, outpoint: string): LookupOutput | null;
|
|
128
|
-
/** One
|
|
133
|
+
/** One pool's state and fees (P4, 0.40.0: by pool id): `live` (its live output), `rescinded` (the validator's Rescind wrote `outpoint`: the LP's Close takes it back), `closed`. */
|
|
129
134
|
export interface LpPool {
|
|
130
|
-
|
|
135
|
+
/** The pool's id, `<txid>_<vout>` (its deploy outpoint). */
|
|
136
|
+
poolId: string;
|
|
137
|
+
/** Its LP key (null for an id this instance does not know). */
|
|
138
|
+
lpPubKey: string | null;
|
|
131
139
|
status: "live" | "rescinded" | "closed";
|
|
132
140
|
/** The output a Close acts on, `<txid>_<vout>` (live and rescinded). */
|
|
133
141
|
outpoint: string | null;
|
|
@@ -139,16 +147,18 @@ export interface LpPool {
|
|
|
139
147
|
tokens: bigint;
|
|
140
148
|
swaps: number;
|
|
141
149
|
}
|
|
142
|
-
/** P4: `GET <base>/positions?
|
|
143
|
-
export declare function readPositions(base: string,
|
|
150
|
+
/** P4: `GET <base>/positions?pool=id1,id2` (0.40.0) → one record per pool id in the same order. */
|
|
151
|
+
export declare function readPositions(base: string, poolIds: string[], fetchFn?: FetchFn): Promise<LpPool[]>;
|
|
144
152
|
/** P7's answer: this instance's validator terms (null: none set, a market only) and its market. */
|
|
145
153
|
export interface InstanceTerms {
|
|
154
|
+
/** 0.40.0: `minLegSats` the minimum leg (sats on the leg's sats side), 0 = none. */
|
|
146
155
|
validator: {
|
|
147
156
|
identity: string;
|
|
148
157
|
peerId: string | null;
|
|
149
158
|
lpFeeBps: number;
|
|
150
159
|
validatorFeeBps: number;
|
|
151
160
|
commissionBps: number;
|
|
161
|
+
minLegSats: number;
|
|
152
162
|
} | null;
|
|
153
163
|
market: Market;
|
|
154
164
|
}
|
|
@@ -187,4 +197,201 @@ export declare function readDiscoveryIds(discovery: string, ids: string[], fetch
|
|
|
187
197
|
export declare function readDiscoveryList(discovery: string, fetchFn?: FetchFn): Promise<DiscoveryRow[]>;
|
|
188
198
|
/** P16: `GET <discovery>/<token>/deploy`: the deploy's BEEF; null when discovery does not hold it. */
|
|
189
199
|
export declare function readDiscoveryDeploy(discovery: string, tokenId: string, fetchFn?: FetchFn): Promise<number[] | null>;
|
|
200
|
+
/** A price, exact (H1–H4): `sats` satoshis per `tokens` token base units (divide in the caller). */
|
|
201
|
+
export interface Price {
|
|
202
|
+
sats: bigint;
|
|
203
|
+
tokens: bigint;
|
|
204
|
+
}
|
|
205
|
+
/** A Swap's trade row (H1; the `swap` change's `trade`): amounts in base units, fees in the input asset, the pool's reserves after it. */
|
|
206
|
+
export interface Trade {
|
|
207
|
+
txid: string;
|
|
208
|
+
/** The pool's id, `<txid>_<vout>` (0.40.0). */
|
|
209
|
+
poolId: string;
|
|
210
|
+
lpPubKey: string;
|
|
211
|
+
/** The hash160 (hex) the payout went to (the call's `userPkh`, 0.40.0): an order's legs share it. */
|
|
212
|
+
payoutPkh: string;
|
|
213
|
+
/** `buy`: sats in, tokens out; `sell`: tokens in. */
|
|
214
|
+
side: "buy" | "sell";
|
|
215
|
+
amountIn: bigint;
|
|
216
|
+
amountOut: bigint;
|
|
217
|
+
feeLp: bigint;
|
|
218
|
+
feeValidator: bigint;
|
|
219
|
+
feeCommission: bigint;
|
|
220
|
+
bsvReserve: bigint;
|
|
221
|
+
tokenReserve: bigint;
|
|
222
|
+
/** The admitting step's time, ms. */
|
|
223
|
+
at: number;
|
|
224
|
+
/** The block height where the overlay has the transaction placed, else null. */
|
|
225
|
+
height: number | null;
|
|
226
|
+
}
|
|
227
|
+
/** H1's page: the trades newest first, `next` the cursor of the page after (null: the last page). */
|
|
228
|
+
export interface TradesPage {
|
|
229
|
+
trades: Trade[];
|
|
230
|
+
next: string | null;
|
|
231
|
+
}
|
|
232
|
+
/** One non-empty bucket (H2): its start (ms), the first, highest, lowest and last trade's prices, each side's amounts summed, the trade count. */
|
|
233
|
+
export interface Candle {
|
|
234
|
+
t: number;
|
|
235
|
+
o: Price;
|
|
236
|
+
h: Price;
|
|
237
|
+
l: Price;
|
|
238
|
+
c: Price;
|
|
239
|
+
volumeSats: bigint;
|
|
240
|
+
volumeTokens: bigint;
|
|
241
|
+
n: number;
|
|
242
|
+
}
|
|
243
|
+
/** A candle's resolution (H2). */
|
|
244
|
+
export type CandleTf = "1m" | "5m" | "15m" | "1h" | "4h" | "1d";
|
|
245
|
+
/** A token at the read's time (H3, H4): the changes in bps (null without a trade at or before the window's start). */
|
|
246
|
+
export interface TokenStats {
|
|
247
|
+
tokenId: string;
|
|
248
|
+
/**
|
|
249
|
+
* 0.40.0 (the host's): the midpoint of what a buy and a sell of 1% of the pooled sats would pay
|
|
250
|
+
* now (the engine's `priceOf(listed pools).mid`), null with no pool.
|
|
251
|
+
*/
|
|
252
|
+
price: Price | null;
|
|
253
|
+
/** What that buy would pay (sats per tokens), null with no pool. */
|
|
254
|
+
buyPrice: Price | null;
|
|
255
|
+
/** What that sell would pay, null with no pool. */
|
|
256
|
+
sellPrice: Price | null;
|
|
257
|
+
/** The last trade's price, null without one. */
|
|
258
|
+
lastTradePrice: Price | null;
|
|
259
|
+
change1h: number | null;
|
|
260
|
+
change24h: number | null;
|
|
261
|
+
volume24hSats: bigint;
|
|
262
|
+
volume24hTokens: bigint;
|
|
263
|
+
buys24h: number;
|
|
264
|
+
sells24h: number;
|
|
265
|
+
lastTradeAt: number | null;
|
|
266
|
+
tvlSats: bigint;
|
|
267
|
+
tvlTokens: bigint;
|
|
268
|
+
pools: number;
|
|
269
|
+
}
|
|
270
|
+
/** A token's holders (H6): `count` the addresses with a balance, `rows` largest balance first. */
|
|
271
|
+
export interface Holders {
|
|
272
|
+
count: number;
|
|
273
|
+
rows: {
|
|
274
|
+
address: string;
|
|
275
|
+
balance: bigint;
|
|
276
|
+
}[];
|
|
277
|
+
}
|
|
278
|
+
/** One LP key's position on one token (H5): P4's record with its token. */
|
|
279
|
+
export interface TokenPosition extends LpPool {
|
|
280
|
+
tokenId: string;
|
|
281
|
+
}
|
|
282
|
+
/** A trade row, or null when it is not one. */
|
|
283
|
+
export declare function toTrade(x: unknown): Trade | null;
|
|
284
|
+
/** A stats record (H3), or null when it is not one. */
|
|
285
|
+
export declare function toStats(x: unknown): TokenStats | null;
|
|
286
|
+
/** H1: `GET <base>/trades?from=&to=&limit=&before=&pool=` (0.40.0: `pool` one pool's) → the page, newest first. */
|
|
287
|
+
export declare function readTrades(base: string, o?: {
|
|
288
|
+
from?: number;
|
|
289
|
+
to?: number;
|
|
290
|
+
limit?: number;
|
|
291
|
+
before?: string;
|
|
292
|
+
pool?: string;
|
|
293
|
+
}, fetchFn?: FetchFn): Promise<TradesPage>;
|
|
294
|
+
/** H1 with `txid`: one Swap's trade row; null when the transaction has none (404). */
|
|
295
|
+
export declare function readTrade(base: string, txid: string, fetchFn?: FetchFn): Promise<Trade | null>;
|
|
296
|
+
/** The candle series (0.40.0): `fill` the trades' prices (the instance's), `market` the price after each pool event (the host's). */
|
|
297
|
+
export type CandleSeries = "fill" | "market";
|
|
298
|
+
/** H2: `GET <base>/candles?tf=&from=&to=&series=` → one candle per non-empty bucket, oldest first. */
|
|
299
|
+
export declare function readCandles(base: string, o: {
|
|
300
|
+
tf: CandleTf;
|
|
301
|
+
from: number;
|
|
302
|
+
to: number;
|
|
303
|
+
series?: CandleSeries;
|
|
304
|
+
}, fetchFn?: FetchFn): Promise<Candle[]>;
|
|
305
|
+
/** H3: `GET <base>/stats`. */
|
|
306
|
+
export declare function readStats(base: string, fetchFn?: FetchFn): Promise<TokenStats>;
|
|
307
|
+
/** H4: `GET <swap base>/stats` (`ids`: those enabled tokens only, in that order) → every enabled token's stats. */
|
|
308
|
+
export declare function readAllStats(swapBase: string, ids?: string[], fetchFn?: FetchFn): Promise<TokenStats[]>;
|
|
309
|
+
/** H6: `GET <token base>/color/<token>/holders?limit=&skip=` → the count and the rows, largest first. */
|
|
310
|
+
export declare function readHolders(base: string, tokenId: string, o?: {
|
|
311
|
+
limit?: number;
|
|
312
|
+
skip?: number;
|
|
313
|
+
}, fetchFn?: FetchFn): Promise<Holders>;
|
|
314
|
+
/** H5: `GET <swap base>/positions?pool=id1,id2` (0.40.0) → every enabled token's rows for the pools, each with its token. */
|
|
315
|
+
export declare function readAllPositions(swapBase: string, poolIds: string[], fetchFn?: FetchFn): Promise<TokenPosition[]>;
|
|
316
|
+
/** A pool as it was listed at a time (H7): its id, output, reserves, keys, rates, the event's time and its swap count. */
|
|
317
|
+
export interface PoolAt extends PoolRow {
|
|
318
|
+
/** The time of the pool's last event at or before the read's `t`, ms. */
|
|
319
|
+
at: number;
|
|
320
|
+
}
|
|
321
|
+
/** H7: `GET <base>/pools/at?t=<ms>` → every pool listed at `t`. */
|
|
322
|
+
export declare function readPoolsAt(base: string, t: number, fetchFn?: FetchFn): Promise<PoolAt[]>;
|
|
323
|
+
/** One event of a pool's history (H8): a deploy, a swap (with its trade fields), a close or a rescind, at the admitting step's time. */
|
|
324
|
+
export interface PoolEvent {
|
|
325
|
+
kind: "deploy" | "swap" | "close" | "rescind";
|
|
326
|
+
txid: string;
|
|
327
|
+
poolId: string;
|
|
328
|
+
/** The pool's output after the event (deploy, swap, rescind), `<txid>_<vout>`. */
|
|
329
|
+
outpoint?: string;
|
|
330
|
+
bsvReserve?: bigint;
|
|
331
|
+
tokenReserve?: bigint;
|
|
332
|
+
lpPubKey: string;
|
|
333
|
+
liquidityFeeBps: bigint;
|
|
334
|
+
validationFeeBps: bigint;
|
|
335
|
+
commissionBps: bigint;
|
|
336
|
+
validatorIdentityKey: string;
|
|
337
|
+
at: number;
|
|
338
|
+
swaps: number;
|
|
339
|
+
/** A swap's trade. */
|
|
340
|
+
side?: "buy" | "sell";
|
|
341
|
+
amountIn?: bigint;
|
|
342
|
+
amountOut?: bigint;
|
|
343
|
+
feeLp?: bigint;
|
|
344
|
+
feeValidator?: bigint;
|
|
345
|
+
feeCommission?: bigint;
|
|
346
|
+
commissionPkh?: string;
|
|
347
|
+
payoutPkh?: string;
|
|
348
|
+
}
|
|
349
|
+
/** H8's page: the events oldest first, `next` the cursor to pass as `after` for the page after (null: none left). */
|
|
350
|
+
export interface PoolHistoryPage {
|
|
351
|
+
events: PoolEvent[];
|
|
352
|
+
next: string | null;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* A revert (0.41.0): an admitted transaction later rejected — `txid` the rejected transaction, `at`
|
|
356
|
+
* the step's time, and the pool as it stands after the undo (its outpoint, reserves, fields,
|
|
357
|
+
* `swaps`), or none of those when the pool no longer exists.
|
|
358
|
+
*/
|
|
359
|
+
export interface PoolRevert {
|
|
360
|
+
kind: "revert";
|
|
361
|
+
txid: string;
|
|
362
|
+
poolId: string;
|
|
363
|
+
at: number;
|
|
364
|
+
outpoint?: string;
|
|
365
|
+
bsvReserve?: bigint;
|
|
366
|
+
tokenReserve?: bigint;
|
|
367
|
+
lpPubKey?: string;
|
|
368
|
+
liquidityFeeBps?: bigint;
|
|
369
|
+
validationFeeBps?: bigint;
|
|
370
|
+
commissionBps?: bigint;
|
|
371
|
+
validatorIdentityKey?: string;
|
|
372
|
+
swaps?: number;
|
|
373
|
+
}
|
|
374
|
+
/** One message of a pool event feed (E1, 0.41.0): `{tokenId, …row}`, the row an H8 event or a revert. */
|
|
375
|
+
export type PoolEventMessage = {
|
|
376
|
+
tokenId: string;
|
|
377
|
+
} & (PoolEvent | PoolRevert);
|
|
378
|
+
/** A pool event feed message's data, or null when it is not one. */
|
|
379
|
+
export declare function parsePoolEventMessage(x: unknown): PoolEventMessage | null;
|
|
380
|
+
/** H8: `GET <base>/pools/history?from=&to=&pool=&limit=&after=` → the page, oldest first. */
|
|
381
|
+
export declare function readPoolHistory(base: string, o?: {
|
|
382
|
+
from?: number;
|
|
383
|
+
to?: number;
|
|
384
|
+
pool?: string;
|
|
385
|
+
limit?: number;
|
|
386
|
+
after?: string;
|
|
387
|
+
}, fetchFn?: FetchFn): Promise<PoolHistoryPage>;
|
|
388
|
+
/** One outpoint's spender as the host's H9 answers it: the token whose instance named it. */
|
|
389
|
+
export interface SpendAll {
|
|
390
|
+
/** `<txid>.<vout>` */
|
|
391
|
+
outpoint: string;
|
|
392
|
+
tokenId?: string;
|
|
393
|
+
spentBy?: string;
|
|
394
|
+
}
|
|
395
|
+
/** H9: `GET <swap base>/spends?outpoint=a,b` (the host's: every enabled token's `/spends`, the first naming a spender) → one record per outpoint. */
|
|
396
|
+
export declare function readSpendsAll(swapBase: string, outpoints: string[], fetchFn?: FetchFn): Promise<SpendAll[]>;
|
|
190
397
|
export {};
|