@dcasegr/amm-client 0.39.0 → 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 +63 -30
- package/dist/client.d.ts +157 -61
- package/dist/client.js +339 -320
- 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 +132 -50
- package/dist/lib/overlay.js +169 -160
- 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/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
|
@@ -1,49 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The active swap basket (skein-amm 0.12.0, David Case 2026-10-21/22; 0.
|
|
3
|
-
* 2026-11-
|
|
4
|
-
* in the exchange's own basket `amm-swap` (src/wallet/color.ts)
|
|
5
|
-
*
|
|
2
|
+
* The active swap basket (skein-amm 0.12.0, David Case 2026-10-21/22; 0.40.0, agent-env
|
|
3
|
+
* plans/swap-balance-build-2026-11-05.md §0 7, Builder 2 item 2): what a swap stages for its legs,
|
|
4
|
+
* held outside the BRC-207 module in the exchange's own basket `amm-swap` (src/wallet/color.ts).
|
|
5
|
+
* No deposit, no withdraw, no balance the user manages.
|
|
6
6
|
*
|
|
7
|
-
* - **
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `amm-swap`
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `
|
|
26
|
-
* wallet marks them spent when it takes the accepted swap in (0.29.0: no
|
|
27
|
-
* relinquishOutput). An output a failed leg did not spend stays for a
|
|
28
|
-
* later swap.
|
|
29
|
-
* - **Move back** (`moveBack`, the recovery path; 0.29.3: a module plan,
|
|
30
|
-
* David Case 2026-11-02): ONE createAction through the wallet's BRC-207
|
|
31
|
-
* module, a `p color plan` transfer: every `amm-swap` token output of the
|
|
32
|
-
* token and (0.29.1) the sats rows staged for its legs (their `assetId`)
|
|
33
|
-
* as explicit inputs (their source transactions in `inputBEEF`) — to the
|
|
34
|
-
* module FOREIGN inputs (not in a `p color` basket): the token rows
|
|
35
|
-
* checked admitted and unspent on the token's overlay, the sats rows
|
|
36
|
-
* adding nothing; one output, the whole amount to a NEW module receiving
|
|
37
|
-
* key of the user's own, the plan's owned output 0 (the module checks it
|
|
38
|
-
* pays the remittance's key and files it in `p color <assetTag>` with its
|
|
39
|
-
* custody in the same call). The page unlocks its inputs at signAction;
|
|
40
|
-
* the wallet funds the fee and takes the sats rows into its change; the
|
|
41
|
-
* module approves and submits, the wallet broadcasts. The page submits it
|
|
42
|
-
* to this skein's token topic too. Nothing is taken in afterwards and
|
|
43
|
-
* nothing is kept in the browser. * (0.29.6) With no token row and only sats rows staged for the token
|
|
44
|
-
* (a sats-in leg that failed): one plain createAction (no `p color`
|
|
45
|
-
* labels), the sats rows as explicit inputs and no outputs — the wallet
|
|
46
|
-
* keeps them as its change and pays the fee (`moveBackSats`).
|
|
7
|
+
* - **Staging** (`stage`): at Swap, ONE wallet action. Sats only (a buy, or a sell whose tokens
|
|
8
|
+
* the basket holds): a plain createAction, ONE P2PKH output to a fresh key under `SWAP_PROTOCOL`
|
|
9
|
+
* (self, keyID random, `amm-swap-<hex>`), filed in `amm-swap` by the action with its
|
|
10
|
+
* customInstructions (`{sats: true, protocolID, keyID, counterparty}`: no token tag). With
|
|
11
|
+
* tokens: the module transfer plan — ONE token output to a fresh key and the ONE sats output in
|
|
12
|
+
* the same action, the token key's id ALSO in that output's description (`… · amm-swap <hex>`,
|
|
13
|
+
* as the LP key's `amm-lp <hex>`), the action labelled `SWAP_STAGE_LABEL`; the module selects
|
|
14
|
+
* the token inputs, adds change, signs and submits; the page submits it too, then files the
|
|
15
|
+
* token output in `amm-swap` (basket insertion, `{assetId, amount, protocolID, keyID,
|
|
16
|
+
* counterparty}`). A labelled staged token output the basket lacks (the page died before the
|
|
17
|
+
* filing) is filed on load from the action's description (`unfiledStagedTokens`).
|
|
18
|
+
* - **Spent** by the legs (src/market/swapAction.ts), their change kept here between legs.
|
|
19
|
+
* - **Move back** (`moveBack`, as 0.29.3): ONE createAction through the wallet's BRC-207 module,
|
|
20
|
+
* a `p color plan` transfer: every `amm-swap` token row of the token and every sats row as
|
|
21
|
+
* explicit inputs (their source transactions in `inputBEEF`), one output — the whole amount to
|
|
22
|
+
* a NEW module receiving key of the user's own, the plan's owned output 0. The page unlocks its
|
|
23
|
+
* inputs at signAction; the wallet funds the fee and takes the sats into its change. With no
|
|
24
|
+
* token row and sats rows staged: one plain createAction, the sats rows as explicit inputs and
|
|
25
|
+
* no outputs (`moveBackSats`).
|
|
47
26
|
*/
|
|
48
27
|
import { Beef, Transaction, type WalletInterface } from "@bsv/sdk";
|
|
49
28
|
import { type Steak } from "../lp/close.js";
|
|
@@ -51,83 +30,76 @@ import { type Spends } from "../wallet/action.js";
|
|
|
51
30
|
import { type SatsInput, type TokenInput } from "./swapAction.js";
|
|
52
31
|
/** The keyID prefix of an `amm-swap` key (`SWAP_PROTOCOL`, counterparty self). */
|
|
53
32
|
export declare const SWAP_KEY_PREFIX = "amm-swap-";
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
export declare function
|
|
33
|
+
/** The label of a staging action that carries tokens (0.40.0): the staged token output's key id is in its output description. */
|
|
34
|
+
export declare const SWAP_STAGE_LABEL = "amm-swap-stage";
|
|
35
|
+
/** The marker a staged token output's description ends with (` · amm-swap <hex>`, 0.40.0): it names the key id. */
|
|
36
|
+
export declare const SWAP_KEY_MARK = " \u00B7 amm-swap ";
|
|
37
|
+
/** A staged row's keyID (0.40.0): `amm-swap-<16 random bytes, hex>`. */
|
|
38
|
+
export declare function newSwapKeyID(): string;
|
|
39
|
+
/** A staged token output's description: the readable text (at most 50 characters), then `SWAP_KEY_MARK` and the keyID's hex. */
|
|
40
|
+
export declare function swapKeyDescription(readable: string, keyID: string): string;
|
|
41
|
+
/** The keyID a staged token output's description names (`swapKeyDescription`), or null. */
|
|
42
|
+
export declare function swapKeyIdOfDescription(description: string | undefined): string | null;
|
|
62
43
|
/** The `amm-swap` outputs of `tokenId` the legs can spend. */
|
|
63
44
|
export declare function swapHoldings(wallet: WalletInterface, tokenId: string): Promise<TokenInput[]>;
|
|
64
45
|
/** The `amm-swap` sats outputs the legs can spend (0.29.0). */
|
|
65
46
|
export declare function swapSatsHoldings(wallet: WalletInterface): Promise<SatsInput[]>;
|
|
66
|
-
/**
|
|
67
|
-
* What `amm-swap` holds, per token id: the token amount and the number of token outputs, and
|
|
68
|
-
* (0.29.6) the sats staged for the token's legs (the sats rows whose customInstructions name its
|
|
69
|
-
* `assetId`). A token with only sats staged has amount 0n and outputs 0.
|
|
70
|
-
*/
|
|
47
|
+
/** What `amm-swap` holds, per token id: the token amount and the number of token outputs (0.40.0: the sats rows are no token's, `swapSatsTotal`). */
|
|
71
48
|
export declare function swapTotals(wallet: WalletInterface): Promise<Map<string, {
|
|
72
49
|
amount: bigint;
|
|
73
50
|
outputs: number;
|
|
74
|
-
sats: number;
|
|
75
51
|
}>>;
|
|
52
|
+
/** The sats `amm-swap` holds (0.40.0: shown once, not per token). */
|
|
53
|
+
export declare function swapSatsTotal(wallet: WalletInterface): Promise<number>;
|
|
76
54
|
/** The source transactions of `amm-swap`'s outputs (a leg's BEEF), with `extra` merged in. */
|
|
77
55
|
export declare function swapHoldingBeef(wallet: WalletInterface, extra?: number[]): Promise<Beef>;
|
|
78
|
-
|
|
56
|
+
/** What a staging action made (0.40.0): the sats row and, with tokens, the token row. */
|
|
57
|
+
export interface Staged {
|
|
79
58
|
txid: string;
|
|
80
|
-
/** The
|
|
59
|
+
/** The action as the wallet's AtomicBEEF. */
|
|
81
60
|
tx: number[];
|
|
82
|
-
/** The
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
61
|
+
/** The sats row (absent: tokens staged with no sats lacking). */
|
|
62
|
+
sats?: SatsInput;
|
|
63
|
+
tokens?: TokenInput;
|
|
64
|
+
/** The token row filed in `amm-swap` (with tokens). */
|
|
86
65
|
filed: boolean;
|
|
87
66
|
submitted: string;
|
|
88
67
|
errors: string[];
|
|
89
68
|
}
|
|
90
|
-
/**
|
|
91
|
-
export interface
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
/** What one send stages: a token output per leg (its amount in), then a sats output per leg. */
|
|
97
|
-
export interface SwapStage {
|
|
98
|
-
tokens: {
|
|
69
|
+
/** What one staging action puts into `amm-swap` (0.40.0): sats, and (a sell the basket does not cover) tokens of one token. */
|
|
70
|
+
export interface StageRequest {
|
|
71
|
+
sats: number;
|
|
72
|
+
tokens?: {
|
|
73
|
+
tokenId: string;
|
|
99
74
|
amount: bigint;
|
|
100
|
-
|
|
101
|
-
}[];
|
|
102
|
-
sats: StagedSats[];
|
|
75
|
+
};
|
|
103
76
|
}
|
|
104
77
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* (each one output) after them. Throws when the wallet refuses or fails the
|
|
108
|
-
* send; filing and the page's own submit are reported in `errors`.
|
|
78
|
+
* Staging (see the module comment): ONE wallet action. Throws when the wallet refuses or fails it;
|
|
79
|
+
* the token row's filing and the page's own submit are reported in `errors`.
|
|
109
80
|
*/
|
|
110
|
-
export declare function
|
|
81
|
+
export declare function stage(wallet: WalletInterface, req: StageRequest, o?: {
|
|
111
82
|
sym?: string;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
83
|
+
submit?: (topic: string, beef: number[]) => Promise<{
|
|
84
|
+
steak?: Steak;
|
|
85
|
+
}>;
|
|
86
|
+
}): Promise<Staged>;
|
|
87
|
+
/** A staged token output the basket lacks (0.40.0): its outpoint, token, amount and the key its description names. */
|
|
88
|
+
export interface UnfiledStaged {
|
|
116
89
|
txid: string;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
errors: string[];
|
|
90
|
+
vout: number;
|
|
91
|
+
tokenId: string;
|
|
92
|
+
amount: bigint;
|
|
93
|
+
keyID: string;
|
|
122
94
|
}
|
|
123
95
|
/**
|
|
124
|
-
* The
|
|
125
|
-
*
|
|
126
|
-
*
|
|
96
|
+
* The labelled staging actions' token outputs not in `amm-swap` (0.40.0): every output of an action
|
|
97
|
+
* labelled `SWAP_STAGE_LABEL` whose description names a staged key and whose script is a 1Color
|
|
98
|
+
* value output, its basket not `amm-swap`. A wallet that refuses the read: none.
|
|
127
99
|
*/
|
|
128
|
-
export declare function
|
|
129
|
-
|
|
130
|
-
|
|
100
|
+
export declare function unfiledStagedTokens(wallet: WalletInterface): Promise<UnfiledStaged[]>;
|
|
101
|
+
/** One unfiled staged token output filed in `amm-swap` from its transaction's BEEF (basket insertion, as `stage` files it). */
|
|
102
|
+
export declare function fileStagedToken(wallet: WalletInterface, u: UnfiledStaged, beef: number[]): Promise<boolean>;
|
|
131
103
|
export interface MovedBack {
|
|
132
104
|
txid: string;
|
|
133
105
|
amount: bigint;
|
|
@@ -156,3 +128,12 @@ export declare function moveBack(i: {
|
|
|
156
128
|
steak?: Steak;
|
|
157
129
|
}>;
|
|
158
130
|
}): Promise<MovedBack>;
|
|
131
|
+
/**
|
|
132
|
+
* Move back with only sats in the swap basket (0.29.6, David Case 2026-11-03; 0.40.0: every sats
|
|
133
|
+
* row, `satsRows` default the basket's): ONE plain wallet createAction (no `p color` labels, the module
|
|
134
|
+
* is not in the path) with the token's `amm-swap` sats rows as explicit inputs (their sources in
|
|
135
|
+
* `inputBEEF`) and NO outputs: the wallet keeps everything as its change and pays the fee from it.
|
|
136
|
+
* The page unlocks the rows at signAction; the wallet broadcasts and marks the rows spent itself
|
|
137
|
+
* (no relinquish, no take-in, nothing kept). Nothing is submitted to an overlay (no token moves).
|
|
138
|
+
*/
|
|
139
|
+
export declare function moveBackSats(wallet: WalletInterface, sym?: string, satsRows?: SatsInput[]): Promise<MovedBack>;
|