@dcasegr/amm-client 0.0.0-stage → 0.38.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 +107 -2
- package/dist/client.d.ts +534 -0
- package/dist/client.js +1319 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.js +75 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +53 -0
- package/dist/lib/config.d.ts +42 -0
- package/dist/lib/config.js +64 -0
- package/dist/lib/keys.d.ts +42 -0
- package/dist/lib/keys.js +48 -0
- package/dist/lib/overlay.d.ts +190 -0
- package/dist/lib/overlay.js +302 -0
- package/dist/lib/skein.d.ts +82 -0
- package/dist/lib/skein.js +142 -0
- package/dist/lib/tokenId.d.ts +72 -0
- package/dist/lib/tokenId.js +121 -0
- package/dist/lp/amounts.d.ts +12 -0
- package/dist/lp/amounts.js +38 -0
- package/dist/lp/close.d.ts +90 -0
- package/dist/lp/close.js +140 -0
- package/dist/lp/images.d.ts +11 -0
- package/dist/lp/images.js +45 -0
- package/dist/lp/inventory.d.ts +68 -0
- package/dist/lp/inventory.js +84 -0
- package/dist/lp/poolDeploy.d.ts +220 -0
- package/dist/lp/poolDeploy.js +291 -0
- package/dist/lp/poolRows.d.ts +13 -0
- package/dist/lp/poolRows.js +19 -0
- package/dist/lp/positions.d.ts +81 -0
- package/dist/lp/positions.js +144 -0
- package/dist/lp/rebalance.d.ts +101 -0
- package/dist/lp/rebalance.js +168 -0
- package/dist/lp/wallet.d.ts +12 -0
- package/dist/lp/wallet.js +19 -0
- package/dist/market/activeSwap.d.ts +158 -0
- package/dist/market/activeSwap.js +320 -0
- package/dist/market/plan.d.ts +85 -0
- package/dist/market/plan.js +149 -0
- package/dist/market/prices.d.ts +13 -0
- package/dist/market/prices.js +14 -0
- package/dist/market/relay.d.ts +84 -0
- package/dist/market/relay.js +201 -0
- package/dist/market/swapAction.d.ts +306 -0
- package/dist/market/swapAction.js +508 -0
- package/dist/market/swapFlow.d.ts +58 -0
- package/dist/market/swapFlow.js +86 -0
- package/dist/market/view.d.ts +58 -0
- package/dist/market/view.js +63 -0
- package/dist/pool/artifact.d.ts +23 -0
- package/dist/pool/artifact.js +38 -0
- package/dist/pool/index.d.ts +8 -0
- package/dist/pool/index.js +8 -0
- package/dist/pool/oneColor.d.ts +19 -0
- package/dist/pool/oneColor.js +39 -0
- package/dist/pool/pool.artifact.json +5069 -0
- package/dist/pool/runar-ir-schema.d.ts +21 -0
- package/dist/pool/runar-ir-schema.js +18 -0
- package/dist/pool/template.d.ts +295 -0
- package/dist/pool/template.js +715 -0
- package/dist/vendor/runar/LICENSE +21 -0
- package/dist/vendor/runar/NOTICE +15 -0
- package/dist/vendor/runar/runar-ir-schema/src/abi-type-encoding.d.ts +42 -0
- package/dist/vendor/runar/runar-ir-schema/src/abi-type-encoding.js +53 -0
- package/dist/vendor/runar/runar-ir-schema/src/anf-ir.d.ts +221 -0
- package/dist/vendor/runar/runar-ir-schema/src/anf-ir.js +33 -0
- package/dist/vendor/runar/runar-ir-schema/src/artifact.d.ts +288 -0
- package/dist/vendor/runar/runar-ir-schema/src/artifact.js +8 -0
- package/dist/vendor/runar/runar-ir-schema/src/canonical-json.d.ts +43 -0
- package/dist/vendor/runar/runar-ir-schema/src/canonical-json.js +204 -0
- package/dist/vendor/runar/runar-ir-schema/src/input-limits.d.ts +89 -0
- package/dist/vendor/runar/runar-ir-schema/src/input-limits.js +100 -0
- package/dist/vendor/runar/runar-ir-schema/src/stack-ir.d.ts +118 -0
- package/dist/vendor/runar/runar-ir-schema/src/stack-ir.js +8 -0
- package/dist/vendor/runar/runar-ir-schema/src/state-layout.d.ts +56 -0
- package/dist/vendor/runar/runar-ir-schema/src/state-layout.js +145 -0
- package/dist/vendor/runar/runar-ir-schema/src/unknown-anf-kind-error.d.ts +18 -0
- package/dist/vendor/runar/runar-ir-schema/src/unknown-anf-kind-error.js +25 -0
- package/dist/vendor/runar/runar-sdk/src/anf-interpreter.d.ts +160 -0
- package/dist/vendor/runar/runar-sdk/src/anf-interpreter.js +1149 -0
- package/dist/vendor/runar/runar-sdk/src/calling.d.ts +98 -0
- package/dist/vendor/runar/runar-sdk/src/calling.js +209 -0
- package/dist/vendor/runar/runar-sdk/src/contract.d.ts +443 -0
- package/dist/vendor/runar/runar-sdk/src/contract.js +2516 -0
- package/dist/vendor/runar/runar-sdk/src/deployment.d.ts +36 -0
- package/dist/vendor/runar/runar-sdk/src/deployment.js +119 -0
- package/dist/vendor/runar/runar-sdk/src/errors.d.ts +46 -0
- package/dist/vendor/runar/runar-sdk/src/errors.js +59 -0
- package/dist/vendor/runar/runar-sdk/src/oppushtx.d.ts +23 -0
- package/dist/vendor/runar/runar-sdk/src/oppushtx.js +95 -0
- package/dist/vendor/runar/runar-sdk/src/ordinals/envelope.d.ts +31 -0
- package/dist/vendor/runar/runar-sdk/src/ordinals/envelope.js +272 -0
- package/dist/vendor/runar/runar-sdk/src/ordinals/types.d.ts +21 -0
- package/dist/vendor/runar/runar-sdk/src/ordinals/types.js +4 -0
- package/dist/vendor/runar/runar-sdk/src/providers/provider.d.ts +65 -0
- package/dist/vendor/runar/runar-sdk/src/providers/provider.js +59 -0
- package/dist/vendor/runar/runar-sdk/src/providers/wallet-provider.d.ts +94 -0
- package/dist/vendor/runar/runar-sdk/src/providers/wallet-provider.js +297 -0
- package/dist/vendor/runar/runar-sdk/src/script-utils.d.ts +54 -0
- package/dist/vendor/runar/runar-sdk/src/script-utils.js +252 -0
- package/dist/vendor/runar/runar-sdk/src/signers/signer.d.ts +17 -0
- package/dist/vendor/runar/runar-sdk/src/signers/signer.js +4 -0
- package/dist/vendor/runar/runar-sdk/src/spend-safety.d.ts +31 -0
- package/dist/vendor/runar/runar-sdk/src/spend-safety.js +35 -0
- package/dist/vendor/runar/runar-sdk/src/state.d.ts +54 -0
- package/dist/vendor/runar/runar-sdk/src/state.js +584 -0
- package/dist/vendor/runar/runar-sdk/src/types.d.ts +227 -0
- package/dist/vendor/runar/runar-sdk/src/types.js +4 -0
- package/dist/vendor/runar/runar-sdk/src/unsound-primitives.d.ts +30 -0
- package/dist/vendor/runar/runar-sdk/src/unsound-primitives.js +42 -0
- package/dist/vendor/runar/runar-sdk.d.ts +9 -0
- package/dist/vendor/runar/runar-sdk.js +8 -0
- package/dist/wallet/action.d.ts +28 -0
- package/dist/wallet/action.js +42 -0
- package/dist/wallet/brc29.d.ts +83 -0
- package/dist/wallet/brc29.js +80 -0
- package/dist/wallet/color.d.ts +110 -0
- package/dist/wallet/color.js +134 -0
- package/dist/wallet/swapPayouts.d.ts +35 -0
- package/dist/wallet/swapPayouts.js +146 -0
- package/package.json +39 -4
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SwapOutcome } from "./market/swapFlow.js";
|
|
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"];
|
|
4
|
+
export type ClientErrorKind = (typeof CLIENT_ERROR_KINDS)[number];
|
|
5
|
+
/** An error of a named kind; `message` is the text the pages show. */
|
|
6
|
+
export declare class ClientError extends Error {
|
|
7
|
+
readonly kind: ClientErrorKind;
|
|
8
|
+
constructor(kind: ClientErrorKind, message: string, options?: {
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/** The kind of `e`, when it is one of `CLIENT_ERROR_KINDS`; undefined otherwise. */
|
|
13
|
+
export declare function errorKind(e: unknown): ClientErrorKind | undefined;
|
|
14
|
+
/** `e` as a `ClientError` of its kind (its message unchanged, `e` the cause) when it has one; else `e` itself. */
|
|
15
|
+
export declare function toClientError(e: unknown): unknown;
|
|
16
|
+
/** The kind of a relay outcome that did not fill (D13): undefined for an accepted one. */
|
|
17
|
+
export declare function kindOfOutcome(o: SwapOutcome): ClientErrorKind | undefined;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client's named error kinds (0.38.0, D13): a `ClientError` carries one of `CLIENT_ERROR_KINDS`
|
|
3
|
+
* and the message the pages showed before (unchanged: the pages keep their texts). Thrown by the
|
|
4
|
+
* client's functions where the error is of one of these kinds; a swap leg's result carries the
|
|
5
|
+
* kind beside its text (`LegResult.kind`). Other errors (a missing wallet, a malformed answer…)
|
|
6
|
+
* stay plain `Error`s.
|
|
7
|
+
*
|
|
8
|
+
* stale_pool the pool moved since the quote or the read (the builder's `stale_pool`; a leg
|
|
9
|
+
* whose lookup tip is not the planned outpoint)
|
|
10
|
+
* fee_mismatch the pool's fees are not the ones quoted (the builder's `fee_mismatch`)
|
|
11
|
+
* quote_mismatch the pool's math does not give the quoted amounts (the builder's `quote_mismatch`)
|
|
12
|
+
* slippage the amount out fell below the order's minimum (the builder's `slippage`; a
|
|
13
|
+
* repriced leg below the order's bound)
|
|
14
|
+
* pool_spent the pool was spent since the quote (the quote's freshness read; the validator's
|
|
15
|
+
* `pool_spent` refusal)
|
|
16
|
+
* user_rejected the user declined in the wallet (the wallet's `ERR_PERMISSION_DENIED`, "denied")
|
|
17
|
+
* no_answer the relay gave no settled answer yet ("no answer yet"; a timed-out swap record)
|
|
18
|
+
* refused the validator, the relay or the host refused it (a refusal other than pool_spent)
|
|
19
|
+
* network the request did not get through (fetch threw)
|
|
20
|
+
*/
|
|
21
|
+
import { PoolBuildError } from "./pool/index.js";
|
|
22
|
+
import { RelayError } from "./market/relay.js";
|
|
23
|
+
/** 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"];
|
|
25
|
+
/** An error of a named kind; `message` is the text the pages show. */
|
|
26
|
+
export class ClientError extends Error {
|
|
27
|
+
kind;
|
|
28
|
+
constructor(kind, message, options) {
|
|
29
|
+
super(message, options);
|
|
30
|
+
this.kind = kind;
|
|
31
|
+
this.name = "ClientError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const BUILD_KINDS = new Set(["stale_pool", "fee_mismatch", "quote_mismatch", "slippage"]);
|
|
35
|
+
/** The kind of `e`, when it is one of `CLIENT_ERROR_KINDS`; undefined otherwise. */
|
|
36
|
+
export function errorKind(e) {
|
|
37
|
+
if (e instanceof ClientError)
|
|
38
|
+
return e.kind;
|
|
39
|
+
if (e instanceof PoolBuildError)
|
|
40
|
+
return BUILD_KINDS.has(e.code) ? e.code : undefined;
|
|
41
|
+
if (e instanceof RelayError)
|
|
42
|
+
return e.httpStatus === 503 ? "no_answer" : "refused";
|
|
43
|
+
const msg = e instanceof Error ? e.message : typeof e === "string" ? e : "";
|
|
44
|
+
const code = e && typeof e === "object" && "code" in e ? String(e.code) : "";
|
|
45
|
+
if (code === "ERR_PERMISSION_DENIED" || /user has denied|permission denied|user rejected|denied by the user/i.test(msg))
|
|
46
|
+
return "user_rejected";
|
|
47
|
+
if (e instanceof TypeError && /fetch|network/i.test(msg))
|
|
48
|
+
return "network";
|
|
49
|
+
if (/^the pool moved\b/.test(msg))
|
|
50
|
+
return "stale_pool";
|
|
51
|
+
if (/^no answer yet\b/.test(msg))
|
|
52
|
+
return "no_answer";
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
/** `e` as a `ClientError` of its kind (its message unchanged, `e` the cause) when it has one; else `e` itself. */
|
|
56
|
+
export function toClientError(e) {
|
|
57
|
+
if (e instanceof ClientError)
|
|
58
|
+
return e;
|
|
59
|
+
const kind = errorKind(e);
|
|
60
|
+
return kind ? new ClientError(kind, e instanceof Error ? e.message : String(e), { cause: e }) : e;
|
|
61
|
+
}
|
|
62
|
+
/** The kind of a relay outcome that did not fill (D13): undefined for an accepted one. */
|
|
63
|
+
export function kindOfOutcome(o) {
|
|
64
|
+
switch (o.status) {
|
|
65
|
+
case "accepted":
|
|
66
|
+
return undefined;
|
|
67
|
+
case "refused":
|
|
68
|
+
return o.reason.startsWith("pool_spent") ? "pool_spent" : "refused";
|
|
69
|
+
case "timeout":
|
|
70
|
+
case "unknown":
|
|
71
|
+
return "no_answer";
|
|
72
|
+
case "failed":
|
|
73
|
+
return "refused";
|
|
74
|
+
}
|
|
75
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@dcasegr/amm-client` (skein-amm 0.38.0, D8): the Open Exchange client without the pages —
|
|
3
|
+
* `createClient` (src/client.ts) and the names two sites must share to file identical wallet rows
|
|
4
|
+
* (D10). ESM + types, no React, no styles, no wallet provider: the caller connects a BRC-100 wallet
|
|
5
|
+
* and passes it in. README "The packages".
|
|
6
|
+
*/
|
|
7
|
+
export * from "./client.js";
|
|
8
|
+
export { CLIENT_ERROR_KINDS, ClientError, errorKind, toClientError, type ClientErrorKind } from "./errors.js";
|
|
9
|
+
export { DEFAULT_FEE_RATE_SATS_PER_KB, exchangeBase, tokenBase } from "./lib/config.js";
|
|
10
|
+
/** The basket of the LP's position rows (`amm-pools`): one pool output per deploy, filed by basket insertion. */
|
|
11
|
+
export { POOLS_BASKET } from "./wallet/color.js";
|
|
12
|
+
/** The active swap basket (`amm-swap`): the token outputs and the sats each swap leg spends. */
|
|
13
|
+
export { SWAP_BASKET } from "./wallet/color.js";
|
|
14
|
+
/** The key protocol of every `amm-swap` row (`[2, "amm swap"]`, counterparty self). */
|
|
15
|
+
export { SWAP_PROTOCOL } from "./wallet/color.js";
|
|
16
|
+
/** The keyID prefix of an `amm-swap` row's key (`amm-swap-`). */
|
|
17
|
+
export { SWAP_KEY_PREFIX } from "./market/activeSwap.js";
|
|
18
|
+
/** The keyID of a staged `amm-swap` row: `amm-swap-<pool txid>.<vout>` (token row) or `…:sats` (its sats row). */
|
|
19
|
+
export { swapKeyID } from "./market/activeSwap.js";
|
|
20
|
+
/** customInstructions of an `amm-swap` token row (asset, amount and the key that spends it). */
|
|
21
|
+
export { swapInstructions } from "./wallet/color.js";
|
|
22
|
+
/** customInstructions of an `amm-swap` sats row (`sats: true`, the token it was staged for, its key). */
|
|
23
|
+
export { swapSatsInstructions } from "./wallet/color.js";
|
|
24
|
+
/** The key protocol of a pool's LP key (BRC-29, to self): the `amm-pools` row's protocolID. */
|
|
25
|
+
export { LP_KEY_PROTOCOL } from "./lp/poolDeploy.js";
|
|
26
|
+
/** The marker a deploy's pool output description ends with (` · amm-lp <hex>`): it names the LP keyID. */
|
|
27
|
+
export { LP_KEY_MARK } from "./lp/poolDeploy.js";
|
|
28
|
+
/** A deploy's pool output description: the readable text, then `LP_KEY_MARK` and the LP keyID's suffix. */
|
|
29
|
+
export { lpKeyDescription } from "./lp/poolDeploy.js";
|
|
30
|
+
/** The LP keyID a deploy's pool output description names, or null. */
|
|
31
|
+
export { lpKeyIdOfDescription } from "./lp/poolDeploy.js";
|
|
32
|
+
/** The tag (`amm-pool`) of an `amm-pools` row. */
|
|
33
|
+
export { POOL_TAG } from "./lp/poolDeploy.js";
|
|
34
|
+
/** The `op` (`amm-pool`) in an `amm-pools` row's customInstructions. */
|
|
35
|
+
export { POOL_OP } from "./lp/poolDeploy.js";
|
|
36
|
+
/** Whether a basket row is an `amm-pools` position row (its tag or its customInstructions `op`). */
|
|
37
|
+
export { isPoolRow } from "./lp/poolDeploy.js";
|
|
38
|
+
/** customInstructions of an `amm-pools` row: the token, the LP key, the validator, its fees and nonce. */
|
|
39
|
+
export { poolCustomInstructions } from "./lp/poolDeploy.js";
|
|
40
|
+
/** The label of a pool deploy's action (`amm-pool-deploy`): the positions reader's history. */
|
|
41
|
+
export { POOL_DEPLOY_LABEL } from "./lp/positions.js";
|
|
42
|
+
/** How long the relay may take a swap leg (the swap's `expires`), ms. */
|
|
43
|
+
export { SWAP_TTL_MS } from "./market/swapAction.js";
|
|
44
|
+
/** The `p color plan` labels of a transfer of one asset (BRC-207 plan version 1): every token action's. */
|
|
45
|
+
export { transferPlanLabels } from "./wallet/color.js";
|
|
46
|
+
/** A module receiving key for one output of an asset from a sender: its receipt, key and hash160. */
|
|
47
|
+
export { newReceivingKey, type ReceivingKey } from "./wallet/color.js";
|
|
48
|
+
/** A receipt's `basket insertion` into the asset's value basket (`p color <assetTag>`), for `internalizeAction`. */
|
|
49
|
+
export { receiptOutput } from "./wallet/color.js";
|
|
50
|
+
/** The `x-topics` header of a BRC-22 submit: the topics as a JSON array (D14). */
|
|
51
|
+
export { xTopics } from "./lp/close.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@dcasegr/amm-client` (skein-amm 0.38.0, D8): the Open Exchange client without the pages —
|
|
3
|
+
* `createClient` (src/client.ts) and the names two sites must share to file identical wallet rows
|
|
4
|
+
* (D10). ESM + types, no React, no styles, no wallet provider: the caller connects a BRC-100 wallet
|
|
5
|
+
* and passes it in. README "The packages".
|
|
6
|
+
*/
|
|
7
|
+
// The client (D9, D11–D13).
|
|
8
|
+
export * from "./client.js";
|
|
9
|
+
export { CLIENT_ERROR_KINDS, ClientError, errorKind, toClientError } from "./errors.js";
|
|
10
|
+
export { DEFAULT_FEE_RATE_SATS_PER_KB, exchangeBase, tokenBase } from "./lib/config.js";
|
|
11
|
+
// The shared names (D10): what each names in the wallet.
|
|
12
|
+
/** The basket of the LP's position rows (`amm-pools`): one pool output per deploy, filed by basket insertion. */
|
|
13
|
+
export { POOLS_BASKET } from "./wallet/color.js";
|
|
14
|
+
/** The active swap basket (`amm-swap`): the token outputs and the sats each swap leg spends. */
|
|
15
|
+
export { SWAP_BASKET } from "./wallet/color.js";
|
|
16
|
+
/** The key protocol of every `amm-swap` row (`[2, "amm swap"]`, counterparty self). */
|
|
17
|
+
export { SWAP_PROTOCOL } from "./wallet/color.js";
|
|
18
|
+
/** The keyID prefix of an `amm-swap` row's key (`amm-swap-`). */
|
|
19
|
+
export { SWAP_KEY_PREFIX } from "./market/activeSwap.js";
|
|
20
|
+
/** The keyID of a staged `amm-swap` row: `amm-swap-<pool txid>.<vout>` (token row) or `…:sats` (its sats row). */
|
|
21
|
+
export { swapKeyID } from "./market/activeSwap.js";
|
|
22
|
+
/** customInstructions of an `amm-swap` token row (asset, amount and the key that spends it). */
|
|
23
|
+
export { swapInstructions } from "./wallet/color.js";
|
|
24
|
+
/** customInstructions of an `amm-swap` sats row (`sats: true`, the token it was staged for, its key). */
|
|
25
|
+
export { swapSatsInstructions } from "./wallet/color.js";
|
|
26
|
+
/** The key protocol of a pool's LP key (BRC-29, to self): the `amm-pools` row's protocolID. */
|
|
27
|
+
export { LP_KEY_PROTOCOL } from "./lp/poolDeploy.js";
|
|
28
|
+
/** The marker a deploy's pool output description ends with (` · amm-lp <hex>`): it names the LP keyID. */
|
|
29
|
+
export { LP_KEY_MARK } from "./lp/poolDeploy.js";
|
|
30
|
+
/** A deploy's pool output description: the readable text, then `LP_KEY_MARK` and the LP keyID's suffix. */
|
|
31
|
+
export { lpKeyDescription } from "./lp/poolDeploy.js";
|
|
32
|
+
/** The LP keyID a deploy's pool output description names, or null. */
|
|
33
|
+
export { lpKeyIdOfDescription } from "./lp/poolDeploy.js";
|
|
34
|
+
/** The tag (`amm-pool`) of an `amm-pools` row. */
|
|
35
|
+
export { POOL_TAG } from "./lp/poolDeploy.js";
|
|
36
|
+
/** The `op` (`amm-pool`) in an `amm-pools` row's customInstructions. */
|
|
37
|
+
export { POOL_OP } from "./lp/poolDeploy.js";
|
|
38
|
+
/** Whether a basket row is an `amm-pools` position row (its tag or its customInstructions `op`). */
|
|
39
|
+
export { isPoolRow } from "./lp/poolDeploy.js";
|
|
40
|
+
/** customInstructions of an `amm-pools` row: the token, the LP key, the validator, its fees and nonce. */
|
|
41
|
+
export { poolCustomInstructions } from "./lp/poolDeploy.js";
|
|
42
|
+
/** The label of a pool deploy's action (`amm-pool-deploy`): the positions reader's history. */
|
|
43
|
+
export { POOL_DEPLOY_LABEL } from "./lp/positions.js";
|
|
44
|
+
/** How long the relay may take a swap leg (the swap's `expires`), ms. */
|
|
45
|
+
export { SWAP_TTL_MS } from "./market/swapAction.js";
|
|
46
|
+
/** The `p color plan` labels of a transfer of one asset (BRC-207 plan version 1): every token action's. */
|
|
47
|
+
export { transferPlanLabels } from "./wallet/color.js";
|
|
48
|
+
/** A module receiving key for one output of an asset from a sender: its receipt, key and hash160. */
|
|
49
|
+
export { newReceivingKey } from "./wallet/color.js";
|
|
50
|
+
/** A receipt's `basket insertion` into the asset's value basket (`p color <assetTag>`), for `internalizeAction`. */
|
|
51
|
+
export { receiptOutput } from "./wallet/color.js";
|
|
52
|
+
/** The `x-topics` header of a BRC-22 submit: the topics as a JSON array (D14). */
|
|
53
|
+
export { xTopics } from "./lp/close.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The skein instances the client talks to (Open Exchange, shruggr/open-exchange#1): the SWAP
|
|
3
|
+
* instance whose app base the client is given (`createClient({origin})`, `exchangeBase`: the
|
|
4
|
+
* token list `GET <base>/tokens`, the defaults, root's enable / disable / defaults / discovery
|
|
5
|
+
* messages) and, per enabled token, that token's own instance (`tokenBase`:
|
|
6
|
+
* `<origin>/@<tokenId>/amm`, its pools, prices, liveness, `/call`, `/submit`, `/spends`). Every
|
|
7
|
+
* request goes to one of those (a GET by plain `fetch`; every POST through the connected
|
|
8
|
+
* wallet's BRC-104 `AuthFetch`, since a skein takes no unsigned POST; src/lib/overlay.ts), or to
|
|
9
|
+
* the connected BRC-100 wallet.
|
|
10
|
+
*
|
|
11
|
+
* 0.38.0 (D9): pure — no `import.meta.env`, no `location`. The pages compute their base and fee
|
|
12
|
+
* rate from their URL and env (src/ox/env.ts: `VITE_AMM_OVERLAY`, `VITE_FEE_RATE`, `appBaseOf`)
|
|
13
|
+
* and pass them to `createClient`.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The app's base URL from the page's own URL: the directory the page is
|
|
17
|
+
* served from (`https://alice.skein.nexus/amm/` → `https://alice.skein.nexus/amm`,
|
|
18
|
+
* `http://127.0.0.1:8100/@alice/amm/index.html` → `http://127.0.0.1:8100/@alice/amm`).
|
|
19
|
+
* At the origin's root (the instance's root route `/` serving this app's www/,
|
|
20
|
+
* shruggr/skein#147: `https://alice.skein.nexus/`, or a host's dev form
|
|
21
|
+
* `http://127.0.0.1:8100/@alice/`) the page names no app, and the app is the
|
|
22
|
+
* same skein's `amm`: `<origin>/amm` (`…/@alice/amm`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function appBaseOf(href: string): string | undefined;
|
|
25
|
+
/** The app the pages are at the origin's root (skein#147): this one, installed as `amm`. */
|
|
26
|
+
export declare const ROOT_APP = "amm";
|
|
27
|
+
/** The app's name: the last segment of its base URL (`…/amm` → `amm`); undefined for an origin. */
|
|
28
|
+
export declare function appName(base: string): string | undefined;
|
|
29
|
+
/** The miner fee rate a client sizes a swap with when none is given, sats per 1000 bytes (D9: today's value). */
|
|
30
|
+
export declare const DEFAULT_FEE_RATE_SATS_PER_KB = 100;
|
|
31
|
+
/**
|
|
32
|
+
* The swap app's base URL of an exchange (`createClient({origin})`): an origin alone
|
|
33
|
+
* (`https://swap.skein.nexus`) is the app at its root, `<origin>/amm` (skein#147, as `appBaseOf`
|
|
34
|
+
* reads a page at the origin's root); a URL with a path is the base as given. No trailing slash.
|
|
35
|
+
*/
|
|
36
|
+
export declare function exchangeBase(origin: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* A token instance's AMM base (Open Exchange, shruggr/open-exchange#1): `<origin>/@<tokenId>/amm` on the
|
|
39
|
+
* origin the swap instance's base is on — the host makes each enabled token's instance at that path
|
|
40
|
+
* (skein#161: a token id is a path-only handle).
|
|
41
|
+
*/
|
|
42
|
+
export declare function tokenBase(tokenId: string, from: string): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The skein instances the client talks to (Open Exchange, shruggr/open-exchange#1): the SWAP
|
|
3
|
+
* instance whose app base the client is given (`createClient({origin})`, `exchangeBase`: the
|
|
4
|
+
* token list `GET <base>/tokens`, the defaults, root's enable / disable / defaults / discovery
|
|
5
|
+
* messages) and, per enabled token, that token's own instance (`tokenBase`:
|
|
6
|
+
* `<origin>/@<tokenId>/amm`, its pools, prices, liveness, `/call`, `/submit`, `/spends`). Every
|
|
7
|
+
* request goes to one of those (a GET by plain `fetch`; every POST through the connected
|
|
8
|
+
* wallet's BRC-104 `AuthFetch`, since a skein takes no unsigned POST; src/lib/overlay.ts), or to
|
|
9
|
+
* the connected BRC-100 wallet.
|
|
10
|
+
*
|
|
11
|
+
* 0.38.0 (D9): pure — no `import.meta.env`, no `location`. The pages compute their base and fee
|
|
12
|
+
* rate from their URL and env (src/ox/env.ts: `VITE_AMM_OVERLAY`, `VITE_FEE_RATE`, `appBaseOf`)
|
|
13
|
+
* and pass them to `createClient`.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The app's base URL from the page's own URL: the directory the page is
|
|
17
|
+
* served from (`https://alice.skein.nexus/amm/` → `https://alice.skein.nexus/amm`,
|
|
18
|
+
* `http://127.0.0.1:8100/@alice/amm/index.html` → `http://127.0.0.1:8100/@alice/amm`).
|
|
19
|
+
* At the origin's root (the instance's root route `/` serving this app's www/,
|
|
20
|
+
* shruggr/skein#147: `https://alice.skein.nexus/`, or a host's dev form
|
|
21
|
+
* `http://127.0.0.1:8100/@alice/`) the page names no app, and the app is the
|
|
22
|
+
* same skein's `amm`: `<origin>/amm` (`…/@alice/amm`).
|
|
23
|
+
*/
|
|
24
|
+
export function appBaseOf(href) {
|
|
25
|
+
const u = new URL(href);
|
|
26
|
+
const path = u.pathname.replace(/[^/]*$/, "").replace(/\/+$/, "");
|
|
27
|
+
const segs = path.split("/").filter((x) => x !== "");
|
|
28
|
+
if (segs.length === 0 || (segs.length === 1 && segs[0].startsWith("@")))
|
|
29
|
+
return `${u.origin}${path}/${ROOT_APP}`;
|
|
30
|
+
return u.origin + path;
|
|
31
|
+
}
|
|
32
|
+
/** The app the pages are at the origin's root (skein#147): this one, installed as `amm`. */
|
|
33
|
+
export const ROOT_APP = "amm";
|
|
34
|
+
/** The app's name: the last segment of its base URL (`…/amm` → `amm`); undefined for an origin. */
|
|
35
|
+
export function appName(base) {
|
|
36
|
+
try {
|
|
37
|
+
const segs = new URL(base).pathname.split("/").filter((x) => x !== "");
|
|
38
|
+
const last = segs[segs.length - 1];
|
|
39
|
+
return last && !last.startsWith("@") ? decodeURIComponent(last) : undefined;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** The miner fee rate a client sizes a swap with when none is given, sats per 1000 bytes (D9: today's value). */
|
|
46
|
+
export const DEFAULT_FEE_RATE_SATS_PER_KB = 100;
|
|
47
|
+
/**
|
|
48
|
+
* The swap app's base URL of an exchange (`createClient({origin})`): an origin alone
|
|
49
|
+
* (`https://swap.skein.nexus`) is the app at its root, `<origin>/amm` (skein#147, as `appBaseOf`
|
|
50
|
+
* reads a page at the origin's root); a URL with a path is the base as given. No trailing slash.
|
|
51
|
+
*/
|
|
52
|
+
export function exchangeBase(origin) {
|
|
53
|
+
const u = new URL(origin);
|
|
54
|
+
const path = u.pathname.replace(/\/+$/, "");
|
|
55
|
+
return path === "" ? `${u.origin}/${ROOT_APP}` : `${u.origin}${path}`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A token instance's AMM base (Open Exchange, shruggr/open-exchange#1): `<origin>/@<tokenId>/amm` on the
|
|
59
|
+
* origin the swap instance's base is on — the host makes each enabled token's instance at that path
|
|
60
|
+
* (skein#161: a token id is a path-only handle).
|
|
61
|
+
*/
|
|
62
|
+
export function tokenBase(tokenId, from) {
|
|
63
|
+
return `${new URL(from).origin}/@${tokenId}/${ROOT_APP}`;
|
|
64
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type WalletProtocol } from "@bsv/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Validator key derivation (docs/notes.md, "Validator derivation" and
|
|
4
|
+
* "Overlay and communication layer on skein" / "Identity"):
|
|
5
|
+
*
|
|
6
|
+
* BRC-43 security level 1, protocol "amm pool" (BRC-43 needs >= 5
|
|
7
|
+
* characters, so not "amm"), key ID `<txid display hex>_<vout>`, anyone
|
|
8
|
+
* counterparty: invoice `1-amm pool-<txid>_<vout>`.
|
|
9
|
+
*
|
|
10
|
+
* The pool's rotating `ValidatorPubKey` is always a child of the
|
|
11
|
+
* validator's own stable `ValidatorIdentity`. The first (a deploy's,
|
|
12
|
+
* skein-amm 0.13.0) is keyed by the validator's nonce, 64 lowercase hex
|
|
13
|
+
* digits (`deriveFirstValidatorPubKey`): the validator picks it at
|
|
14
|
+
* `amm.pool.affirm` and the pool's state carries it. Each Swap's next key is
|
|
15
|
+
* keyed by the pool outpoint the Swap spends (`deriveValidatorPubKey`).
|
|
16
|
+
* (Before 0.13.0 the first key was keyed by the deploy's first token input.)
|
|
17
|
+
*
|
|
18
|
+
* Because the counterparty is "anyone", this is a public one-way function
|
|
19
|
+
* of the validator's identity public key and the key ID: anyone holding
|
|
20
|
+
* `validatorIdentity` (published, part of every pool's state) can compute
|
|
21
|
+
* the derived child public key without the validator's private key: the
|
|
22
|
+
* page checks the validator's answer with it, and the lookup lists a pool
|
|
23
|
+
* only when it holds.
|
|
24
|
+
*/
|
|
25
|
+
export declare const AMM_POOL_PROTOCOL: WalletProtocol;
|
|
26
|
+
/** `<txid display hex>_<vout>` key ID for a spent outpoint, per the convention above. */
|
|
27
|
+
export declare function validatorKeyId(outpoint: {
|
|
28
|
+
txid: string;
|
|
29
|
+
vout: number;
|
|
30
|
+
}): string;
|
|
31
|
+
/**
|
|
32
|
+
* Derives the rotating validator signing public key (hex, compressed) as a
|
|
33
|
+
* child of `validatorIdentityHex`, keyed by the outpoint the validator is
|
|
34
|
+
* about to sign for (or, at deploy, the LP's first token-deposit input).
|
|
35
|
+
* Callable by anyone: only `validatorIdentityHex` (public) is needed.
|
|
36
|
+
*/
|
|
37
|
+
export declare function deriveValidatorPubKey(validatorIdentityHex: string, outpoint: {
|
|
38
|
+
txid: string;
|
|
39
|
+
vout: number;
|
|
40
|
+
}): string;
|
|
41
|
+
/** A pool's first validator key (0.13.0): the identity's anyone-child keyed by the nonce (64 hex digits). */
|
|
42
|
+
export declare function deriveFirstValidatorPubKey(validatorIdentityHex: string, nonceHex: string): string;
|
package/dist/lib/keys.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { KeyDeriver, PublicKey } from "@bsv/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Validator key derivation (docs/notes.md, "Validator derivation" and
|
|
4
|
+
* "Overlay and communication layer on skein" / "Identity"):
|
|
5
|
+
*
|
|
6
|
+
* BRC-43 security level 1, protocol "amm pool" (BRC-43 needs >= 5
|
|
7
|
+
* characters, so not "amm"), key ID `<txid display hex>_<vout>`, anyone
|
|
8
|
+
* counterparty: invoice `1-amm pool-<txid>_<vout>`.
|
|
9
|
+
*
|
|
10
|
+
* The pool's rotating `ValidatorPubKey` is always a child of the
|
|
11
|
+
* validator's own stable `ValidatorIdentity`. The first (a deploy's,
|
|
12
|
+
* skein-amm 0.13.0) is keyed by the validator's nonce, 64 lowercase hex
|
|
13
|
+
* digits (`deriveFirstValidatorPubKey`): the validator picks it at
|
|
14
|
+
* `amm.pool.affirm` and the pool's state carries it. Each Swap's next key is
|
|
15
|
+
* keyed by the pool outpoint the Swap spends (`deriveValidatorPubKey`).
|
|
16
|
+
* (Before 0.13.0 the first key was keyed by the deploy's first token input.)
|
|
17
|
+
*
|
|
18
|
+
* Because the counterparty is "anyone", this is a public one-way function
|
|
19
|
+
* of the validator's identity public key and the key ID: anyone holding
|
|
20
|
+
* `validatorIdentity` (published, part of every pool's state) can compute
|
|
21
|
+
* the derived child public key without the validator's private key: the
|
|
22
|
+
* page checks the validator's answer with it, and the lookup lists a pool
|
|
23
|
+
* only when it holds.
|
|
24
|
+
*/
|
|
25
|
+
export const AMM_POOL_PROTOCOL = [1, "amm pool"];
|
|
26
|
+
/** `<txid display hex>_<vout>` key ID for a spent outpoint, per the convention above. */
|
|
27
|
+
export function validatorKeyId(outpoint) {
|
|
28
|
+
return `${outpoint.txid}_${outpoint.vout}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Derives the rotating validator signing public key (hex, compressed) as a
|
|
32
|
+
* child of `validatorIdentityHex`, keyed by the outpoint the validator is
|
|
33
|
+
* about to sign for (or, at deploy, the LP's first token-deposit input).
|
|
34
|
+
* Callable by anyone: only `validatorIdentityHex` (public) is needed.
|
|
35
|
+
*/
|
|
36
|
+
export function deriveValidatorPubKey(validatorIdentityHex, outpoint) {
|
|
37
|
+
const anyone = new KeyDeriver("anyone");
|
|
38
|
+
const identity = PublicKey.fromString(validatorIdentityHex);
|
|
39
|
+
const keyId = validatorKeyId(outpoint);
|
|
40
|
+
return anyone
|
|
41
|
+
.derivePublicKey(AMM_POOL_PROTOCOL, keyId, identity, false)
|
|
42
|
+
.toString();
|
|
43
|
+
}
|
|
44
|
+
/** A pool's first validator key (0.13.0): the identity's anyone-child keyed by the nonce (64 hex digits). */
|
|
45
|
+
export function deriveFirstValidatorPubKey(validatorIdentityHex, nonceHex) {
|
|
46
|
+
const anyone = new KeyDeriver("anyone");
|
|
47
|
+
return anyone.derivePublicKey(AMM_POOL_PROTOCOL, nonceHex.toLowerCase(), PublicKey.fromString(validatorIdentityHex), false).toString();
|
|
48
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { PoolState } from "@dcasegr/amm-engine";
|
|
2
|
+
export interface TokenTopic {
|
|
3
|
+
/** `tm_color_<txid>_<vout>` (`tm_color_<txid>_0` at output 0). */
|
|
4
|
+
topic: string;
|
|
5
|
+
/** Deploy txid, 64 lowercase hex, display order. */
|
|
6
|
+
txid: string;
|
|
7
|
+
vout: number;
|
|
8
|
+
kind: "native" | "legacy";
|
|
9
|
+
/** The token id, `<txid>_<vout>` (src/lib/tokenId.ts, BRC-162 "Token identification"). */
|
|
10
|
+
tokenId: string;
|
|
11
|
+
}
|
|
12
|
+
/** The AMM pool lookup service of a token (programs/amm-lookup; 0.21.0): `ls_amm_<assetId>`. A name only: the pages send it no query. */
|
|
13
|
+
export declare function ammLookupService(tokenId: string): string;
|
|
14
|
+
/** A token topic name, `tm_color_<txid>_<vout>` (BRC-207), or null for anything else. */
|
|
15
|
+
export declare function parseTokenTopic(name: string): TokenTopic | null;
|
|
16
|
+
/** A pool row on the wire (P2, P3, P4's `current`): JSON numbers, bigints here. */
|
|
17
|
+
interface WirePool {
|
|
18
|
+
lpPubKey?: string;
|
|
19
|
+
outpoint: string;
|
|
20
|
+
bsvReserve: number | string;
|
|
21
|
+
tokenReserve: number | string;
|
|
22
|
+
liquidityFeeBps: number | string;
|
|
23
|
+
validationFeeBps: number | string;
|
|
24
|
+
commissionBps?: number | string;
|
|
25
|
+
validatorIdentityKey: string;
|
|
26
|
+
validatorPeerId?: string;
|
|
27
|
+
tokenId?: string;
|
|
28
|
+
}
|
|
29
|
+
/** The engine's PoolState from a wire row (the reserves and fees as bigints). */
|
|
30
|
+
export declare function toPoolState(raw: WirePool): PoolState;
|
|
31
|
+
/** A pool of the pools routes: the engine's PoolState, its LP key (the pool's id, D2), and (P2) its validator's peer ID. */
|
|
32
|
+
export interface PoolRow extends PoolState {
|
|
33
|
+
lpPubKey: string;
|
|
34
|
+
/** P2: the validator's libp2p peer ID, from its beat (what the relay dials). */
|
|
35
|
+
validatorPeerId?: string;
|
|
36
|
+
/** P1: the token. */
|
|
37
|
+
tokenId?: string;
|
|
38
|
+
}
|
|
39
|
+
/** One pool row, or null when it is not one. */
|
|
40
|
+
export declare function toPoolRow(raw: unknown): PoolRow | null;
|
|
41
|
+
/** The market of a token instance, as P2 carries it: where its relay takes the commission (hash160 hex), its minimum commission. */
|
|
42
|
+
export interface Market {
|
|
43
|
+
commissionPkh: string | null;
|
|
44
|
+
minCommissionBps: number;
|
|
45
|
+
}
|
|
46
|
+
/** A validator beating on the token's topic now (P2's `validators`, 0.34.1): its identity key and libp2p peer ID. */
|
|
47
|
+
export interface BeatingValidator {
|
|
48
|
+
identity: string;
|
|
49
|
+
peerId: string;
|
|
50
|
+
}
|
|
51
|
+
/** 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
|
+
export interface PoolsAnswer {
|
|
53
|
+
market: Market;
|
|
54
|
+
pools: PoolRow[];
|
|
55
|
+
validators: BeatingValidator[];
|
|
56
|
+
}
|
|
57
|
+
/** P2's JSON. */
|
|
58
|
+
export declare function parsePools(x: unknown): PoolsAnswer;
|
|
59
|
+
/** P1's JSON: every enabled token's rows, each naming its `tokenId`. */
|
|
60
|
+
export declare function parseAllPools(x: unknown): PoolRow[];
|
|
61
|
+
/** A validator seen beating (the pages take it from the pools route's rows: the host joined the beats, D11). */
|
|
62
|
+
export interface LiveValidator {
|
|
63
|
+
identityKey: string;
|
|
64
|
+
/** libp2p peer ID, text (base58): what the swap names for the relay to dial. */
|
|
65
|
+
peerId: string;
|
|
66
|
+
/** The beat's time, ms epoch (0: not told). */
|
|
67
|
+
at: number;
|
|
68
|
+
ageMs: number;
|
|
69
|
+
live: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface LiveAnswer {
|
|
72
|
+
now: number;
|
|
73
|
+
validators: LiveValidator[];
|
|
74
|
+
/** False when nothing about liveness is known. */
|
|
75
|
+
kept: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** The validators of the pools route's rows (every one live: the host listed only those), as the plan reads liveness. */
|
|
78
|
+
export declare function liveOfPools(rows: Pick<PoolRow, "validatorIdentityKey" | "validatorPeerId">[], now?: number): LiveAnswer;
|
|
79
|
+
/** The connected wallet's BRC-104 client (`@bsv/sdk` `AuthFetch`, or a test's fake): the signed writes. */
|
|
80
|
+
export interface SignedFetch {
|
|
81
|
+
fetch(url: string, config?: {
|
|
82
|
+
method?: string;
|
|
83
|
+
headers?: Record<string, string>;
|
|
84
|
+
body?: unknown;
|
|
85
|
+
}): Promise<Response>;
|
|
86
|
+
}
|
|
87
|
+
type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
|
|
88
|
+
/** P1 / P2's URL: `<base>/pools` (the swap instance's app base: every token; a token instance's: that token). */
|
|
89
|
+
export declare function poolsUrl(base: string): string;
|
|
90
|
+
/** P2 once (a one-shot reader; the Swap page holds the stream, `watchPools`). */
|
|
91
|
+
export declare function readPools(base: string, fetchFn?: FetchFn): Promise<PoolsAnswer>;
|
|
92
|
+
/** What `watchPools` needs of the browser's `EventSource` (tests pass a fake). */
|
|
93
|
+
export interface EventSourceLike {
|
|
94
|
+
addEventListener(type: string, fn: (e: {
|
|
95
|
+
data?: unknown;
|
|
96
|
+
}) => void): void;
|
|
97
|
+
close(): void;
|
|
98
|
+
onerror?: ((e: unknown) => void) | null;
|
|
99
|
+
onopen?: ((e: unknown) => void) | null;
|
|
100
|
+
}
|
|
101
|
+
export type EventSourceCtor = new (url: string) => EventSourceLike;
|
|
102
|
+
/**
|
|
103
|
+
* Holds a pools route (P1 or P2) as an event stream (D16, D22): `GET <url>` with `Accept:
|
|
104
|
+
* text/event-stream` (the browser's EventSource sends it), the event `pools` carrying the answer,
|
|
105
|
+
* first the current one, then again each time it changes; `onAnswer` gets each. Without an
|
|
106
|
+
* EventSource (an old browser, a test): ONE plain GET, no poll. → the unsubscribe.
|
|
107
|
+
*/
|
|
108
|
+
export declare function watchPools<T>(url: string, parse: (x: unknown) => T, onAnswer: (a: T) => void, o?: {
|
|
109
|
+
onError?: (e: unknown) => void;
|
|
110
|
+
onOpen?: () => void;
|
|
111
|
+
EventSource?: EventSourceCtor | null;
|
|
112
|
+
fetch?: FetchFn;
|
|
113
|
+
}): () => void;
|
|
114
|
+
/** P3's answer: the LP keys' current pools and one BEEF of their transactions. */
|
|
115
|
+
export interface PoolsBeef {
|
|
116
|
+
pools: PoolRow[];
|
|
117
|
+
beef: number[];
|
|
118
|
+
}
|
|
119
|
+
/** P3: `GET <base>/pools/beef?lp=k1,k2` (no `lpKeys`: every live pool). */
|
|
120
|
+
export declare function readPoolsBeef(base: string, lpKeys?: string[], fetchFn?: FetchFn): Promise<PoolsBeef>;
|
|
121
|
+
/** One output of a pool transaction with its BEEF (Atomic, the transaction its subject): what a spend of the pool is built from. */
|
|
122
|
+
export interface LookupOutput {
|
|
123
|
+
beef: number[];
|
|
124
|
+
outputIndex: number;
|
|
125
|
+
}
|
|
126
|
+
/** The pool `outpoint` (`<txid>_<vout>`) out of P3's BEEF, as an Atomic BEEF of its transaction; null when the BEEF lacks it. */
|
|
127
|
+
export declare function poolOutputOf(pb: PoolsBeef, outpoint: string): LookupOutput | null;
|
|
128
|
+
/** One LP key's pool and fees (P4): `live` (its live pool), `rescinded` (the validator's Rescind wrote `outpoint`: the LP's Close takes it back), `closed`. */
|
|
129
|
+
export interface LpPool {
|
|
130
|
+
lpPubKey: string;
|
|
131
|
+
status: "live" | "rescinded" | "closed";
|
|
132
|
+
/** The output a Close acts on, `<txid>_<vout>` (live and rescinded). */
|
|
133
|
+
outpoint: string | null;
|
|
134
|
+
/** That output's pool state (live and rescinded). */
|
|
135
|
+
current: PoolState | null;
|
|
136
|
+
/** The LP fees of sats-in swaps. */
|
|
137
|
+
sats: bigint;
|
|
138
|
+
/** The LP fees of token-in swaps, token base units. */
|
|
139
|
+
tokens: bigint;
|
|
140
|
+
swaps: number;
|
|
141
|
+
}
|
|
142
|
+
/** P4: `GET <base>/positions?lp=k1,k2` → one record per key in the same order. */
|
|
143
|
+
export declare function readPositions(base: string, lpPubKeys: string[], fetchFn?: FetchFn): Promise<LpPool[]>;
|
|
144
|
+
/** P7's answer: this instance's validator terms (null: none set, a market only) and its market. */
|
|
145
|
+
export interface InstanceTerms {
|
|
146
|
+
validator: {
|
|
147
|
+
identity: string;
|
|
148
|
+
peerId: string | null;
|
|
149
|
+
lpFeeBps: number;
|
|
150
|
+
validatorFeeBps: number;
|
|
151
|
+
commissionBps: number;
|
|
152
|
+
} | null;
|
|
153
|
+
market: Market;
|
|
154
|
+
}
|
|
155
|
+
/** P7: `GET <base>/terms`, unsigned. */
|
|
156
|
+
export declare function readTerms(base: string, fetchFn?: FetchFn): Promise<InstanceTerms>;
|
|
157
|
+
/** The chain state of an outpoint (P8; amm-p2p reads.zig `spendOf`). */
|
|
158
|
+
export interface Spend {
|
|
159
|
+
/** `<txid>.<vout>` */
|
|
160
|
+
outpoint: string;
|
|
161
|
+
spentBy?: string;
|
|
162
|
+
/** Followed from a pool output: its current output, `<txid>.<vout>`. */
|
|
163
|
+
current?: string;
|
|
164
|
+
hops: number;
|
|
165
|
+
closed: boolean;
|
|
166
|
+
}
|
|
167
|
+
/** P8: `GET <base>/spends?outpoint=a,b` → one record per outpoint in query order (one outpoint: its object, wrapped). */
|
|
168
|
+
export declare function readSpends(base: string, outpoints: string[], fetchFn?: FetchFn): Promise<Spend[]>;
|
|
169
|
+
/** P9: `GET <base>/tx?id=<txid>`: the transaction's BEEF (every input's source with it); null when the instance does not hold it. */
|
|
170
|
+
export declare function readTx(base: string, txid: string, fetchFn?: FetchFn): Promise<number[] | null>;
|
|
171
|
+
/** P10: `GET <base>/swaps?id=<id>`: the relay record (dag-json, as `amm.swap.status` answers it); null when unknown. */
|
|
172
|
+
export declare function readSwap(base: string, id: string, fetchFn?: FetchFn): Promise<unknown | null>;
|
|
173
|
+
/** A token on discovery (P13, P14): its metadata; `iconUrl` absolute (P13 gives it relative to the list). */
|
|
174
|
+
export interface DiscoveryRow {
|
|
175
|
+
tokenId: string;
|
|
176
|
+
listed: boolean;
|
|
177
|
+
topic?: string;
|
|
178
|
+
sym?: string;
|
|
179
|
+
dec?: number;
|
|
180
|
+
iconUrl?: string;
|
|
181
|
+
txid?: string;
|
|
182
|
+
vout?: number;
|
|
183
|
+
}
|
|
184
|
+
/** P13 with `ids`: `GET <discovery>/tokens?ids=a,b` → one row per id in query order (`listed: false` for one not on discovery). */
|
|
185
|
+
export declare function readDiscoveryIds(discovery: string, ids: string[], fetchFn?: FetchFn): Promise<DiscoveryRow[]>;
|
|
186
|
+
/** P13 paged: discovery's whole token list, newest first, a page at a time. */
|
|
187
|
+
export declare function readDiscoveryList(discovery: string, fetchFn?: FetchFn): Promise<DiscoveryRow[]>;
|
|
188
|
+
/** P16: `GET <discovery>/<token>/deploy`: the deploy's BEEF; null when discovery does not hold it. */
|
|
189
|
+
export declare function readDiscoveryDeploy(discovery: string, tokenId: string, fetchFn?: FetchFn): Promise<number[] | null>;
|
|
190
|
+
export {};
|