@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,50 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One swap leg through the user's BRC-100 wallet (docs/notes.md, "Swap
|
|
3
|
-
*
|
|
4
|
-
* comes from the wallet (`getPublicKey`, `
|
|
2
|
+
* One swap leg through the user's BRC-100 wallet (docs/notes.md, "Swap funding and signing";
|
|
3
|
+
* 0.40.0, agent-env plans/swap-balance-build-2026-11-05.md §0 7, Builder 2 item 3). The page holds
|
|
4
|
+
* no keys: every key and signature comes from the wallet (`getPublicKey`, `createSignature`).
|
|
5
5
|
*
|
|
6
|
-
* 1.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* the
|
|
14
|
-
*
|
|
15
|
-
* (
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* the
|
|
21
|
-
*
|
|
22
|
-
* `
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* pool's is checked with `Spend`.
|
|
30
|
-
* 4. The relay (src/market/relay.ts) carries it to the validator, with the
|
|
31
|
-
* sats output's transaction as the swap's funding transaction (its
|
|
32
|
-
* AtomicBEEF, from the wallet).
|
|
33
|
-
* 5. Accepted: `completeSwap` internalizes the payout (sats: BRC-29 wallet
|
|
34
|
-
* payment; tokens, 0.12.0: the output is locked to a BRC-207 module
|
|
35
|
-
* receiving key whose sender is the pool's validator, taken in with a
|
|
36
|
-
* basket insertion into `p color <assetTag>` and the receipt,
|
|
37
|
-
* src/wallet/color.ts), and the commission when it is the taker's own
|
|
38
|
-
* (same two forms). No relinquishOutput (0.29.0): the wallet marks the
|
|
39
|
-
* `amm-swap` outputs the swap spends spent when it takes the swap in.
|
|
40
|
-
* Refused / timed out: nothing to undo; the leg's outputs stay in
|
|
41
|
-
* `amm-swap` for a later swap.
|
|
6
|
+
* 1. **The leg's inputs** (`selectLegInputs`): every one an `amm-swap` row (src/market/activeSwap.ts)
|
|
7
|
+
* — the pool, then as many sats rows as cover the leg's sats (largest first), then (a sell) as
|
|
8
|
+
* many token rows as cover `amountIn` (largest first). The leg's sats (`legNeed`): what the
|
|
9
|
+
* contract's outputs take beyond the pool's and the token inputs' sats, plus the miner fee of
|
|
10
|
+
* the final transaction at the rate (`swapTxSize`, the sats change output counted).
|
|
11
|
+
* 2. **The outputs**: the contract's (pool, payout, LP fee, validator fee, commission, then the
|
|
12
|
+
* token change = token inputs − `amountIn` when > 0), then Rúnar's sats change = sats inputs −
|
|
13
|
+
* the need when ≥ 1 (`_changePKH`, `_changeAmount`); under 1, no change output.
|
|
14
|
+
* 3. **The keys** (`prepareSwap`): the payout (and the taker's own commission) under ONE
|
|
15
|
+
* derivation per ORDER (`legDerivation` of the order's key input: the first leg's first token
|
|
16
|
+
* input on a sell, its first sats input on a buy), every leg of the order the same; a token
|
|
17
|
+
* payout to a module receiving key for SELF (sender the user's identity). The change: a leg
|
|
18
|
+
* that is not the order's last → keys under `SWAP_PROTOCOL` (self), keyID
|
|
19
|
+
* `amm-swap-<txid>.<vout>:change` of the leg's first input of that kind (`changeKeyID`), taken
|
|
20
|
+
* into `amm-swap` with the order's key input in its customInstructions; the LAST leg (it takes
|
|
21
|
+
* all that remains) → the WALLET: sats to a BRC-29 key of the user's, tokens to a module
|
|
22
|
+
* receiving key for self, both `legDerivation(order, "change")`.
|
|
23
|
+
* 4. The relay (src/market/relay.ts) carries it to the validator with the first sats input's
|
|
24
|
+
* transaction as the swap's funding transaction: ONE BEEF of every staged input's source,
|
|
25
|
+
* its subject that transaction (0.40.1, `fundingBeef`).
|
|
26
|
+
* 5. Accepted: `completeSwap` takes in, in ONE `internalizeAction`, the payout, the commission
|
|
27
|
+
* when it is the taker's own, and the change. No relinquishOutput: taking the swap in marks the
|
|
28
|
+
* `amm-swap` rows it spends spent.
|
|
42
29
|
*/
|
|
43
|
-
import { Beef, Transaction, UnlockingScript, type WalletInterface, type WalletProtocol } from "@bsv/sdk";
|
|
30
|
+
import { Beef, Transaction, UnlockingScript, type InternalizeOutput, type WalletInterface, type WalletProtocol } from "@bsv/sdk";
|
|
44
31
|
import type { Direction, Leg, PoolState } from "@dcasegr/amm-engine";
|
|
45
32
|
import { type CallPlan, type PoolUtxo } from "../pool/index.js";
|
|
46
33
|
import type { LookupOutput } from "../lib/overlay.js";
|
|
47
|
-
import { type
|
|
34
|
+
import { type PaymentRemittance } from "../wallet/brc29.js";
|
|
48
35
|
import { type ColorReceipt } from "../wallet/color.js";
|
|
49
36
|
/** A P2PKH unlocking script's upper bound: push(DER ≤ 72 + sighash byte) + push(33-byte key). */
|
|
50
37
|
export declare const P2PKH_UNLOCK_LENGTH = 108;
|
|
@@ -68,29 +55,25 @@ export interface TokenInput {
|
|
|
68
55
|
protocolID: WalletProtocol;
|
|
69
56
|
keyID: string;
|
|
70
57
|
counterparty: string;
|
|
58
|
+
/** 0.40.0: the order whose change it is (its key input, `<txid>.<vout>`); a staged row has none. */
|
|
59
|
+
order?: string;
|
|
71
60
|
}
|
|
72
61
|
/** The token's 32-byte wire id (internal byte order) for a token with a 32-byte id (`<txid>_0`; `<txid>` and `<txid>.0` read the same). */
|
|
73
62
|
export declare function assetIdOf(tokenId: string): string;
|
|
74
|
-
|
|
75
|
-
* The basket rows usable as token inputs for `tokenId`: 1Color value outputs
|
|
76
|
-
* with this 32-byte id (the pool template counts only those) whose
|
|
77
|
-
* customInstructions name the key (protocolID, keyID).
|
|
78
|
-
*/
|
|
79
|
-
export declare function tokenInputsOf(rows: {
|
|
63
|
+
type Row = {
|
|
80
64
|
outpoint: string;
|
|
81
65
|
satoshis: number;
|
|
82
66
|
lockingScript?: string;
|
|
83
67
|
tags?: string[];
|
|
84
68
|
customInstructions?: string;
|
|
85
|
-
}
|
|
69
|
+
};
|
|
86
70
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* outputs first; a bounded search.
|
|
71
|
+
* The basket rows usable as token inputs for `tokenId`: 1Color value outputs
|
|
72
|
+
* with this 32-byte id (the pool template counts only those) whose
|
|
73
|
+
* customInstructions name the key (protocolID, keyID).
|
|
91
74
|
*/
|
|
92
|
-
export declare function
|
|
93
|
-
/** An `amm-swap` sats output (customInstructions `{sats: true,
|
|
75
|
+
export declare function tokenInputsOf(rows: Row[], tokenId: string): TokenInput[];
|
|
76
|
+
/** An `amm-swap` sats output (customInstructions `{sats: true, protocolID, keyID, counterparty, order?}`): a plain P2PKH to an "amm swap" key. */
|
|
94
77
|
export interface SatsInput {
|
|
95
78
|
/** `txid.vout` */
|
|
96
79
|
outpoint: string;
|
|
@@ -101,18 +84,11 @@ export interface SatsInput {
|
|
|
101
84
|
protocolID: WalletProtocol;
|
|
102
85
|
keyID: string;
|
|
103
86
|
counterparty: string;
|
|
104
|
-
/**
|
|
105
|
-
|
|
87
|
+
/** 0.40.0: the order whose change it is (its key input); a staged row has none. */
|
|
88
|
+
order?: string;
|
|
106
89
|
}
|
|
107
90
|
/** The basket rows usable as a leg's sats: plain P2PKH outputs whose customInstructions say `sats: true` and name the key. */
|
|
108
|
-
export declare function satsInputsOf(rows:
|
|
109
|
-
outpoint: string;
|
|
110
|
-
satoshis: number;
|
|
111
|
-
lockingScript?: string;
|
|
112
|
-
customInstructions?: string;
|
|
113
|
-
}[]): SatsInput[];
|
|
114
|
-
/** The sats twin of `selectExactTokenInputs`: one output of exactly `satoshis` (the leg has no change), or null. */
|
|
115
|
-
export declare function selectExactSatsInput(candidates: SatsInput[], satoshis: number): SatsInput | null;
|
|
91
|
+
export declare function satsInputsOf(rows: Row[]): SatsInput[];
|
|
116
92
|
/** The pool output from the lookup's BEEF, as the template's PoolUtxo. */
|
|
117
93
|
export declare function poolUtxoFrom(poolOutput: LookupOutput): PoolUtxo;
|
|
118
94
|
/**
|
|
@@ -130,28 +106,56 @@ export declare function signP2pkhWithWallet(wallet: WalletInterface, tx: Transac
|
|
|
130
106
|
/**
|
|
131
107
|
* The final swap's size in bytes: the pool input at `maxCallUnlockLength`
|
|
132
108
|
* (validator's signature in), `takerInputs` P2PKH inputs (the sats, tokens)
|
|
133
|
-
* at 108 bytes of unlocking script, the contract's outputs,
|
|
109
|
+
* at 108 bytes of unlocking script, the contract's outputs, and (0.40.0) the
|
|
110
|
+
* sats change output when `withChange`.
|
|
134
111
|
*/
|
|
135
|
-
export declare function swapTxSize(plan: CallPlan, takerInputs: number): number;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
satoshis: number;
|
|
112
|
+
export declare function swapTxSize(plan: CallPlan, takerInputs: number, withChange?: boolean): number;
|
|
113
|
+
/** What a leg's sats inputs must cover (0.40.0). */
|
|
114
|
+
export interface LegNeed {
|
|
139
115
|
/** What the contract's outputs take beyond the pool's and the token inputs' sats. */
|
|
140
116
|
outputs: number;
|
|
117
|
+
/** The miner fee with no change output, and its need (outputs + fee): what the sats inputs must cover. */
|
|
141
118
|
fee: number;
|
|
142
|
-
|
|
119
|
+
need: number;
|
|
120
|
+
/** The miner fee and need with the sats change output counted. */
|
|
121
|
+
feeWithChange: number;
|
|
122
|
+
needWithChange: number;
|
|
143
123
|
satsPerKb: number;
|
|
144
124
|
}
|
|
145
125
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* − the token inputs' sats), plus
|
|
150
|
-
* ceil(size × rate / 1000) for the final swap.
|
|
126
|
+
* A leg's sats need: Σ contract outputs − pool sats − token inputs' sats, plus ceil(size × rate /
|
|
127
|
+
* 1000) for the final swap with `inputs` taker inputs (sats and tokens), without and with the sats
|
|
128
|
+
* change output.
|
|
151
129
|
*/
|
|
152
|
-
export declare function
|
|
130
|
+
export declare function legNeed(plan: CallPlan, tokenInputs: {
|
|
153
131
|
satoshis: number;
|
|
154
|
-
}[], satsPerKb: number):
|
|
132
|
+
}[], inputs: number, satsPerKb: number): LegNeed;
|
|
133
|
+
/** BRC-29 / BRC-207 derivationPrefix of a leg's payout (0.29.1): base64 of the UTF-8 text "amm swap". */
|
|
134
|
+
export declare const LEG_PAYOUT_PREFIX: string;
|
|
135
|
+
/** derivationPrefix of the taker's own commission output (0.29.1): base64 of "amm swap commission". */
|
|
136
|
+
export declare const LEG_COMMISSION_PREFIX: string;
|
|
137
|
+
/** derivationPrefix of an order's last leg's change to the wallet (0.40.0): base64 of "amm swap change". */
|
|
138
|
+
export declare const LEG_CHANGE_PREFIX: string;
|
|
139
|
+
/**
|
|
140
|
+
* The derivation of an order's payout keys (0.29.1; 0.40.0: ONE per ORDER). `keyInput` is the
|
|
141
|
+
* order's key input, `<txid>.<vout>` (txid in display hex, lowercase): the first leg's first token
|
|
142
|
+
* input on a sell, its first sats input on a buy. derivationSuffix = base64(sha256(UTF-8 of that
|
|
143
|
+
* text)); derivationPrefix `LEG_PAYOUT_PREFIX` for the payout, `LEG_COMMISSION_PREFIX` for the
|
|
144
|
+
* taker's own commission, `LEG_CHANGE_PREFIX` for the last leg's change to the wallet. The same
|
|
145
|
+
* pair keys the BRC-29 payment (keyID "<prefix> <suffix>", sender the user) and the BRC-207 receipt
|
|
146
|
+
* (`p color <assetTag> <prefixHex> <suffixHex>`, sender the user: a receipt for self).
|
|
147
|
+
*/
|
|
148
|
+
export declare function legDerivation(keyInput: string, which: "payout" | "commission" | "change"): {
|
|
149
|
+
derivationPrefix: string;
|
|
150
|
+
derivationSuffix: string;
|
|
151
|
+
};
|
|
152
|
+
/** The keyID of a leg's change kept in `amm-swap` (0.40.0): `amm-swap-<txid>.<vout>:change`, the leg's first input of that kind. */
|
|
153
|
+
export declare function changeKeyID(firstInput: string): string;
|
|
154
|
+
/** A swap transaction's taker inputs (every input after the pool's), each told sats or tokens by its source output (0.40.0). */
|
|
155
|
+
export declare function legInputsOf(tx: Transaction): {
|
|
156
|
+
sats: string[];
|
|
157
|
+
tokens: string[];
|
|
158
|
+
};
|
|
155
159
|
export interface PlanLegInput {
|
|
156
160
|
wallet: WalletInterface;
|
|
157
161
|
/** `<txid>_0` (src/lib/tokenId.ts). */
|
|
@@ -163,45 +167,38 @@ export interface PlanLegInput {
|
|
|
163
167
|
direction: Direction;
|
|
164
168
|
leg: Leg;
|
|
165
169
|
pool: PoolState;
|
|
166
|
-
/** The
|
|
170
|
+
/** The pools read's `{beef, outputIndex}` for `leg.outpoint`. */
|
|
167
171
|
poolOutput: LookupOutput;
|
|
168
172
|
/**
|
|
169
|
-
* The relay's commission address (
|
|
170
|
-
*
|
|
171
|
-
* the commission to a fresh key of the taker's own.
|
|
173
|
+
* The relay's commission address (hash160 hex), or null when the relay names none: a pool with
|
|
174
|
+
* a nonzero CommissionBps then pays the commission to a key of the taker's own.
|
|
172
175
|
*/
|
|
173
176
|
commissionPkh: string | null;
|
|
174
|
-
/**
|
|
175
|
-
* token → sats: the token inputs carrying exactly `leg.amountIn`, or (0.29.0) what they will be
|
|
176
|
-
* once staged: one output of 1 sat per leg (`sendToSwapBasket`). Their count and sats size the
|
|
177
|
-
* leg's sats.
|
|
178
|
-
*/
|
|
179
|
-
tokenInputs?: Pick<TokenInput, "satoshis" | "amount">[];
|
|
180
177
|
/** sats per 1000 bytes (`VITE_FEE_RATE`). */
|
|
181
178
|
satsPerKb: number;
|
|
182
179
|
}
|
|
183
|
-
/**
|
|
184
|
-
export interface
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
bsvIn: boolean;
|
|
189
|
-
poolUtxo: PoolUtxo;
|
|
190
|
-
/** Sized with placeholder payout and commission addresses (prepareSwap re-plans with the derived keys). */
|
|
191
|
-
plan: CallPlan;
|
|
192
|
-
funding: SwapFunding;
|
|
193
|
-
commissionAmount: bigint;
|
|
194
|
-
commissionTo: SwapCommission["to"];
|
|
180
|
+
/** The leg's inputs (`selectLegInputs`): its sats rows and token rows, and what the sats cover. */
|
|
181
|
+
export interface LegInputs {
|
|
182
|
+
sats: SatsInput[];
|
|
183
|
+
tokens: TokenInput[];
|
|
184
|
+
need: LegNeed;
|
|
195
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Item 3's inputs: (a sell) as many token rows as cover `leg.amountIn`, largest first; then as many
|
|
188
|
+
* sats rows as cover the leg's sats need, largest first (each sats row added grows the size). Null
|
|
189
|
+
* when the rows cannot cover the leg (the staged sats or tokens ran out). The need is planned with
|
|
190
|
+
* placeholder addresses (20 bytes each: the sizes are the same).
|
|
191
|
+
*/
|
|
192
|
+
export declare function selectLegInputs(i: PlanLegInput, sats: SatsInput[], tokens: TokenInput[]): LegInputs | null;
|
|
196
193
|
export interface PrepareSwapInput extends PlanLegInput {
|
|
197
|
-
/**
|
|
198
|
-
|
|
199
|
-
/** The
|
|
200
|
-
|
|
201
|
-
/**
|
|
194
|
+
/** The leg's `amm-swap` rows (`selectLegInputs`). */
|
|
195
|
+
inputs: LegInputs;
|
|
196
|
+
/** The order's key input (`<txid>.<vout>`); absent: this is the order's first leg, its own key input. */
|
|
197
|
+
order?: string;
|
|
198
|
+
/** This leg takes all that remains of the order: its change goes to the wallet. */
|
|
199
|
+
last: boolean;
|
|
200
|
+
/** The swap basket's source transactions: the rows' (default: `amm-swap`'s, from the wallet). */
|
|
202
201
|
holdingBeef?: Beef;
|
|
203
|
-
/** Step 1 already done (`planSwapLeg` over the same input); planned here when absent. */
|
|
204
|
-
planned?: PlannedLeg;
|
|
205
202
|
now?: number;
|
|
206
203
|
ttlMs?: number;
|
|
207
204
|
}
|
|
@@ -211,29 +208,49 @@ export type SwapPayout = {
|
|
|
211
208
|
satoshis: number;
|
|
212
209
|
lockingScript: string;
|
|
213
210
|
receipt: ColorReceipt;
|
|
214
|
-
} |
|
|
211
|
+
} | {
|
|
215
212
|
kind: "brc29";
|
|
216
|
-
|
|
213
|
+
outputIndex: number;
|
|
214
|
+
satoshis: number;
|
|
215
|
+
lockingScript: string;
|
|
216
|
+
remittance: PaymentRemittance;
|
|
217
|
+
}
|
|
218
|
+
/** 0.40.0: a change output kept in `amm-swap` (basket insertion with its customInstructions). */
|
|
219
|
+
| {
|
|
220
|
+
kind: "basket";
|
|
221
|
+
outputIndex: number;
|
|
222
|
+
satoshis: number;
|
|
223
|
+
lockingScript: string;
|
|
224
|
+
customInstructions: string;
|
|
225
|
+
};
|
|
217
226
|
export interface PreparedSwap {
|
|
218
227
|
/** The pool outpoint `<txid>_<vout>`. */
|
|
219
228
|
pool: string;
|
|
220
229
|
validator: string;
|
|
230
|
+
bsvIn: boolean;
|
|
221
231
|
expires: number;
|
|
222
232
|
plan: CallPlan;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
233
|
+
/** The order's key input (`<txid>.<vout>`): what the payout keys are derived from. */
|
|
234
|
+
order: string;
|
|
235
|
+
/** Whether this leg's change went to the wallet. */
|
|
236
|
+
last: boolean;
|
|
237
|
+
funding: {
|
|
238
|
+
/** What the relay is sent as `funding` (0.40.1, `fundingBeef`): every staged input's source with its ancestry, the subject the first sats input's transaction. */
|
|
227
239
|
atomicBeef: number[];
|
|
228
240
|
txid: string;
|
|
229
|
-
|
|
230
|
-
|
|
241
|
+
fee: number;
|
|
242
|
+
need: number;
|
|
231
243
|
};
|
|
232
244
|
/** Every input signed except the pool's validator slot. */
|
|
233
245
|
swap: Transaction;
|
|
246
|
+
satsInputs: SatsInput[];
|
|
234
247
|
tokenInputs: TokenInput[];
|
|
235
248
|
payout: SwapPayout;
|
|
236
249
|
commission: SwapCommission;
|
|
250
|
+
/** The token change output (a sell whose token rows exceed amountIn). */
|
|
251
|
+
tokenChange?: SwapPayout;
|
|
252
|
+
/** The sats change output (≥ 1 sat). */
|
|
253
|
+
satsChange?: SwapPayout;
|
|
237
254
|
}
|
|
238
255
|
/** The leg's commission (the pool's CommissionBps of amount in, in the input asset). */
|
|
239
256
|
export interface SwapCommission {
|
|
@@ -246,34 +263,19 @@ export interface SwapCommission {
|
|
|
246
263
|
/** "own" only: the wallet's record of the commission output. */
|
|
247
264
|
payout?: SwapPayout;
|
|
248
265
|
}
|
|
249
|
-
/**
|
|
250
|
-
export declare
|
|
251
|
-
/** derivationPrefix of the taker's own commission output (0.29.1): base64 of "amm swap commission". */
|
|
252
|
-
export declare const LEG_COMMISSION_PREFIX: string;
|
|
253
|
-
/**
|
|
254
|
-
* The derivation of a leg's payout keys (0.29.1, David Case 2026-11-02: deterministic from what
|
|
255
|
-
* the leg spends). `keyInput` is the leg's first staged `amm-swap` input, `<txid>.<vout>` (txid in
|
|
256
|
-
* display hex, lowercase): tokens in, its first token input (the swap's input 2); sats in, its sats
|
|
257
|
-
* input (input 1). derivationSuffix = base64(sha256(UTF-8 of that text)); derivationPrefix
|
|
258
|
-
* `LEG_PAYOUT_PREFIX` for the payout, `LEG_COMMISSION_PREFIX` for the taker's own commission. The
|
|
259
|
-
* same pair keys the BRC-29 payment (keyID "<prefix> <suffix>", sender the user) and the BRC-207
|
|
260
|
-
* receipt (`p color <assetTag> <prefixHex> <suffixHex>`, sender the pool's validator). A staged
|
|
261
|
-
* output is spent by one transaction only, so the keys are the leg's alone.
|
|
262
|
-
*/
|
|
263
|
-
export declare function legDerivation(keyInput: string, which: "payout" | "commission"): {
|
|
264
|
-
derivationPrefix: string;
|
|
265
|
-
derivationSuffix: string;
|
|
266
|
-
};
|
|
267
|
-
/** The leg's key input in a swap transaction (see `legDerivation`): input 2 when it spends tokens, else input 1. */
|
|
268
|
-
export declare function legKeyInputOf(swap: Transaction, bsvIn: boolean): string;
|
|
266
|
+
/** The leg's own key input: its first token input on a sell, its first sats input on a buy. */
|
|
267
|
+
export declare function keyInputOf(inputs: Pick<LegInputs, "sats" | "tokens">, bsvIn: boolean): string;
|
|
269
268
|
/**
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
269
|
+
* The relay's `funding` (0.40.1): ONE BEEF holding the source transaction of every staged input
|
|
270
|
+
* the leg spends (sats and token rows alike, each with its ancestry as the wallet gives it), its
|
|
271
|
+
* subject the funding transaction (the first sats input's). The form: an Atomic BEEF envelope
|
|
272
|
+
* (the prefix and the subject's txid, as the sdk writes one) around the sdk's V2 BEEF of them all
|
|
273
|
+
* — the relay's `given()` reads the envelope's subject and keeps every transaction in it; the
|
|
274
|
+
* sdk's own `toBinaryAtomic` would drop the sources the subject does not descend from. The
|
|
275
|
+
* relay's request BEEF to the validator is its own V2 (relay.zig `requestBeef`).
|
|
274
276
|
*/
|
|
275
|
-
export declare function
|
|
276
|
-
/**
|
|
277
|
+
export declare function fundingBeef(beef: Beef, fundingTxid: string, sources: string[]): number[];
|
|
278
|
+
/** Builds and signs the leg (see the module comment). Throws `PoolBuildError` / `LegShapeError`; the wallet is left as it was. */
|
|
277
279
|
export declare function prepareSwap(i: PrepareSwapInput): Promise<PreparedSwap>;
|
|
278
280
|
/** @bsv/sdk's `Spend` over input `n` of `tx` (its source output from `sourceTransaction`). */
|
|
279
281
|
export declare function spendValid(tx: Transaction, n: number): boolean;
|
|
@@ -296,11 +298,14 @@ export interface CompletedSwap {
|
|
|
296
298
|
/** Internalize errors (the swap itself is final). */
|
|
297
299
|
errors: string[];
|
|
298
300
|
}
|
|
301
|
+
/** The leg's outputs the wallet takes in (0.40.0): the payout, the taker's own commission, the token change, the sats change. */
|
|
302
|
+
export declare function takeInOutputs(p: Pick<PreparedSwap, "payout" | "commission" | "tokenChange" | "satsChange">): InternalizeOutput[];
|
|
299
303
|
/**
|
|
300
|
-
* Accepted: the wallet takes the
|
|
301
|
-
* relinquishOutput (0.29.0, David Case 2026-11-02: "Anything we
|
|
302
|
-
* should relinquish outputs itself"): taking the swap in marks the wallet's
|
|
303
|
-
*
|
|
304
|
-
* (wallet-toolbox `markUserInputsSpent`).
|
|
304
|
+
* Accepted: the wallet takes the leg in, ONE `internalizeAction` (0.40.0: the payout, the taker's
|
|
305
|
+
* own commission, the change). No relinquishOutput (0.29.0, David Case 2026-11-02: "Anything we
|
|
306
|
+
* internalize should relinquish outputs itself"): taking the swap in marks the wallet's outputs
|
|
307
|
+
* it spends — the `amm-swap` sats and token rows — spent (wallet-toolbox `markUserInputsSpent`).
|
|
305
308
|
*/
|
|
306
309
|
export declare function completeSwap(wallet: WalletInterface, p: PreparedSwap, raw: number[], txid?: string): Promise<CompletedSwap>;
|
|
310
|
+
export declare function internalizeOutputOf(o: SwapPayout): InternalizeOutput;
|
|
311
|
+
export {};
|