@dcasegr/amm-client 0.0.0-stage → 0.38.2
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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `runar-ir-schema`, minus its Ajv validators: what the vendored runar-sdk modules
|
|
3
|
+
* (src/vendor/runar, their `runar-ir-schema` import rewritten to this file) read. See
|
|
4
|
+
* README.md "runar-sdk, vendored".
|
|
5
|
+
*
|
|
6
|
+
* runar-ir-schema's own `index.ts` re-exports `validators.ts`, which reads its
|
|
7
|
+
* JSON schemas from disk at import time (`node:fs`, `fileURLToPath(import.meta.url)`)
|
|
8
|
+
* and imports `ajv`. Neither works in a browser bundle, and runar-sdk never
|
|
9
|
+
* calls the validators. Every other value export of that barrel (and the
|
|
10
|
+
* artifact, ANF and stack IR types runar-sdk uses) is re-exported
|
|
11
|
+
* here from the vendored copy of its sources (src/vendor/runar/runar-ir-schema).
|
|
12
|
+
*/
|
|
13
|
+
export * from "../vendor/runar/runar-ir-schema/src/state-layout.js";
|
|
14
|
+
export * from "../vendor/runar/runar-ir-schema/src/abi-type-encoding.js";
|
|
15
|
+
export * from "../vendor/runar/runar-ir-schema/src/canonical-json.js";
|
|
16
|
+
export * from "../vendor/runar/runar-ir-schema/src/input-limits.js";
|
|
17
|
+
export * from "../vendor/runar/runar-ir-schema/src/unknown-anf-kind-error.js";
|
|
18
|
+
export { MERGED_LOCAL_TEMP_PREFIX } from "../vendor/runar/runar-ir-schema/src/anf-ir.js";
|
|
19
|
+
export type * from "../vendor/runar/runar-ir-schema/src/artifact.js";
|
|
20
|
+
export type * from "../vendor/runar/runar-ir-schema/src/anf-ir.js";
|
|
21
|
+
export type * from "../vendor/runar/runar-ir-schema/src/stack-ir.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `runar-ir-schema`, minus its Ajv validators: what the vendored runar-sdk modules
|
|
3
|
+
* (src/vendor/runar, their `runar-ir-schema` import rewritten to this file) read. See
|
|
4
|
+
* README.md "runar-sdk, vendored".
|
|
5
|
+
*
|
|
6
|
+
* runar-ir-schema's own `index.ts` re-exports `validators.ts`, which reads its
|
|
7
|
+
* JSON schemas from disk at import time (`node:fs`, `fileURLToPath(import.meta.url)`)
|
|
8
|
+
* and imports `ajv`. Neither works in a browser bundle, and runar-sdk never
|
|
9
|
+
* calls the validators. Every other value export of that barrel (and the
|
|
10
|
+
* artifact, ANF and stack IR types runar-sdk uses) is re-exported
|
|
11
|
+
* here from the vendored copy of its sources (src/vendor/runar/runar-ir-schema).
|
|
12
|
+
*/
|
|
13
|
+
export * from "../vendor/runar/runar-ir-schema/src/state-layout.js";
|
|
14
|
+
export * from "../vendor/runar/runar-ir-schema/src/abi-type-encoding.js";
|
|
15
|
+
export * from "../vendor/runar/runar-ir-schema/src/canonical-json.js";
|
|
16
|
+
export * from "../vendor/runar/runar-ir-schema/src/input-limits.js";
|
|
17
|
+
export * from "../vendor/runar/runar-ir-schema/src/unknown-anf-kind-error.js";
|
|
18
|
+
export { MERGED_LOCAL_TEMP_PREFIX } from "../vendor/runar/runar-ir-schema/src/anf-ir.js";
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { LockingScript, PrivateKey, Transaction, UnlockingScript } from "@bsv/sdk";
|
|
2
|
+
import { type PoolMethod, type PoolVersion } from "./artifact.js";
|
|
3
|
+
/** The readonly constructor args (compiled into the code). */
|
|
4
|
+
export interface PoolArgs {
|
|
5
|
+
/** The token's 32-byte BRC-162 id, hex, wire (internal) byte order. */
|
|
6
|
+
assetId: string;
|
|
7
|
+
lpFeeBps: bigint;
|
|
8
|
+
validatorFeeBps: bigint;
|
|
9
|
+
/** The relay's commission (constructor param 7), bps of amountIn in the input asset, paid to Swap's `commissionPkh`. */
|
|
10
|
+
commissionBps: bigint;
|
|
11
|
+
}
|
|
12
|
+
/** The mutable state after OP_RETURN. Keys are 33-byte compressed hex. */
|
|
13
|
+
export interface PoolFields {
|
|
14
|
+
tokenReserve: bigint;
|
|
15
|
+
lpPubKey: string;
|
|
16
|
+
/** 33 zero bytes (hex) once rescinded (layout 2). */
|
|
17
|
+
validatorPubKey: string;
|
|
18
|
+
validatorIdentity: string;
|
|
19
|
+
/** Layout 2: the validator's nonce, 32 bytes hex. */
|
|
20
|
+
nonce?: string;
|
|
21
|
+
/** Layout 2: the validator's affirmation, DER hex ("" when the pool carries none). */
|
|
22
|
+
affirmation?: string;
|
|
23
|
+
}
|
|
24
|
+
/** A cleared ValidatorPubKey (Rescind, 0.13.0): 33 zero bytes. */
|
|
25
|
+
export declare const RESCINDED_KEY: string;
|
|
26
|
+
/** A decoded pool locking script. */
|
|
27
|
+
export interface Pool {
|
|
28
|
+
/** The layout (artifact.ts): 2. */
|
|
29
|
+
version: PoolVersion;
|
|
30
|
+
args: PoolArgs;
|
|
31
|
+
state: PoolFields;
|
|
32
|
+
/** The Rúnar code (hex): what a call pushes as `_codePart`. */
|
|
33
|
+
code: string;
|
|
34
|
+
/** `code || OP_RETURN || state` (hex): the script runar-sdk sees. */
|
|
35
|
+
contractScript: string;
|
|
36
|
+
}
|
|
37
|
+
/** A pool output being spent. */
|
|
38
|
+
export interface PoolUtxo {
|
|
39
|
+
txid: string;
|
|
40
|
+
vout: number;
|
|
41
|
+
satoshis: number;
|
|
42
|
+
script: string | LockingScript;
|
|
43
|
+
/** The pool's source transaction, when known (kept on the input for BEEF). */
|
|
44
|
+
sourceTransaction?: Transaction;
|
|
45
|
+
}
|
|
46
|
+
/** A non-pool input the builder adds after the pool (funding, token inputs). */
|
|
47
|
+
export interface BuilderInput {
|
|
48
|
+
txid: string;
|
|
49
|
+
vout: number;
|
|
50
|
+
satoshis: number;
|
|
51
|
+
lockingScript: string | LockingScript;
|
|
52
|
+
sourceTransaction?: Transaction;
|
|
53
|
+
/**
|
|
54
|
+
* Signs this input once the transaction is final (e.g. `new P2PKH().unlock(key,
|
|
55
|
+
* "all", false, satoshis, lockingScript)`; a 1Color token on P2PKH unlocks the
|
|
56
|
+
* same way). Omitted: the input is left unsigned for a wallet to sign, and
|
|
57
|
+
* `estimatedUnlockLength` (default 107, a P2PKH) sizes the fee.
|
|
58
|
+
*/
|
|
59
|
+
unlock?: {
|
|
60
|
+
sign(tx: Transaction, inputIndex: number): Promise<UnlockingScript>;
|
|
61
|
+
estimateLength(): Promise<number>;
|
|
62
|
+
};
|
|
63
|
+
estimatedUnlockLength?: number;
|
|
64
|
+
}
|
|
65
|
+
/** The miner fee: absolute sats, or a rate over the finished size. */
|
|
66
|
+
export type FeeSpec = {
|
|
67
|
+
sats: number;
|
|
68
|
+
} | {
|
|
69
|
+
satsPerKb: number;
|
|
70
|
+
};
|
|
71
|
+
interface CallCommon {
|
|
72
|
+
pool: PoolUtxo;
|
|
73
|
+
inputs: BuilderInput[];
|
|
74
|
+
/** Hash160 (hex) the change goes to. */
|
|
75
|
+
changePkh: string;
|
|
76
|
+
fee: FeeSpec;
|
|
77
|
+
}
|
|
78
|
+
export interface SwapParams extends CallCommon {
|
|
79
|
+
amountIn: bigint;
|
|
80
|
+
/** true: BSV in, tokens out. */
|
|
81
|
+
bsvIn: boolean;
|
|
82
|
+
/** Hash160 (hex) of the taker's payout. */
|
|
83
|
+
userPkh: string;
|
|
84
|
+
/** The validator key for the continuation. Default: derived from ValidatorIdentity and the pool outpoint (src/lib/keys.ts). */
|
|
85
|
+
nextValidatorPubKey?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Hash160 (hex) the commission goes to (Swap's `commissionPkh`): the relay's
|
|
88
|
+
* `amm.swap.terms` address, or the taker's own. Always pushed; an output
|
|
89
|
+
* only when the commission (ceil(amountIn·CommissionBps/10000)) is nonzero.
|
|
90
|
+
*/
|
|
91
|
+
commissionPkh: string;
|
|
92
|
+
/** What the caller priced the leg against; any mismatch is refused (see PoolBuildError). */
|
|
93
|
+
expect?: SwapExpectation;
|
|
94
|
+
}
|
|
95
|
+
/** `SwapParams` without the funding (inputs, change, fee): see `PoolTemplate.planSwap`. */
|
|
96
|
+
export type SwapPlanParams = Omit<SwapParams, "inputs" | "changePkh" | "fee">;
|
|
97
|
+
/** A pool call's required outputs and method arguments, before any funding is chosen. */
|
|
98
|
+
export interface CallPlan {
|
|
99
|
+
pool: Pool;
|
|
100
|
+
poolUtxo: PoolUtxo;
|
|
101
|
+
method: PoolMethod;
|
|
102
|
+
/** The outputs the contract requires, in order; change (if any) follows them. */
|
|
103
|
+
outputs: {
|
|
104
|
+
satoshis: bigint;
|
|
105
|
+
script: string;
|
|
106
|
+
}[];
|
|
107
|
+
/** The method arguments, signature slots `EMPTY_SIG`. */
|
|
108
|
+
args: unknown[];
|
|
109
|
+
sigSlots: Partial<Record<SigSlot, number>>;
|
|
110
|
+
next: {
|
|
111
|
+
pool: Pool;
|
|
112
|
+
satoshis: number;
|
|
113
|
+
script: LockingScript;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export interface SwapExpectation {
|
|
117
|
+
bsvReserve?: bigint;
|
|
118
|
+
tokenReserve?: bigint;
|
|
119
|
+
lpFeeBps?: bigint;
|
|
120
|
+
validatorFeeBps?: bigint;
|
|
121
|
+
commissionBps?: bigint;
|
|
122
|
+
lpFee?: bigint;
|
|
123
|
+
validatorFee?: bigint;
|
|
124
|
+
commission?: bigint;
|
|
125
|
+
amountOut?: bigint;
|
|
126
|
+
minAmountOut?: bigint;
|
|
127
|
+
}
|
|
128
|
+
export interface CloseParams extends CallCommon {
|
|
129
|
+
/** The outputs, the LP's choice (the contract leaves them free). */
|
|
130
|
+
outputs: {
|
|
131
|
+
satoshis: bigint;
|
|
132
|
+
script: string;
|
|
133
|
+
}[];
|
|
134
|
+
/** The LP's key; when given, the LP slot is signed here. */
|
|
135
|
+
lpKey?: PoolSigner;
|
|
136
|
+
}
|
|
137
|
+
/** Signs a 32-byte sighash, returning a DER signature (without the sighash byte). */
|
|
138
|
+
export type PoolSigner = PrivateKey | ((sighash: number[]) => Promise<number[]>);
|
|
139
|
+
export type SigSlot = "validator" | "lp";
|
|
140
|
+
/** A built pool call. */
|
|
141
|
+
export interface PoolCall {
|
|
142
|
+
tx: Transaction;
|
|
143
|
+
method: PoolMethod;
|
|
144
|
+
/** The spent pool. */
|
|
145
|
+
pool: Pool;
|
|
146
|
+
/** The continuation (output 0), or null for a Close (it ends the pool). */
|
|
147
|
+
next: {
|
|
148
|
+
pool: Pool;
|
|
149
|
+
satoshis: number;
|
|
150
|
+
script: LockingScript;
|
|
151
|
+
} | null;
|
|
152
|
+
/** BIP-143 preimage (hex) the pool's signatures are over. */
|
|
153
|
+
preimage: string;
|
|
154
|
+
/** sha256d(preimage), hex: what the validator / LP sign. */
|
|
155
|
+
sighash: string;
|
|
156
|
+
/** Signature slots still OP_0 in input 0. */
|
|
157
|
+
unsigned: SigSlot[];
|
|
158
|
+
change: number;
|
|
159
|
+
fee: number;
|
|
160
|
+
/** Swap only: the trade, as the contract computes it. */
|
|
161
|
+
swap?: SwapAmounts;
|
|
162
|
+
}
|
|
163
|
+
/** A swap's trade, as the contract computes it (each fee in the input asset). */
|
|
164
|
+
export interface SwapAmounts {
|
|
165
|
+
amountOut: bigint;
|
|
166
|
+
lpFee: bigint;
|
|
167
|
+
validatorFee: bigint;
|
|
168
|
+
commission: bigint;
|
|
169
|
+
}
|
|
170
|
+
export type PoolBuildErrorCode = "not_a_pool" | "stale_pool" | "fee_mismatch" | "quote_mismatch" | "slippage" | "token_mismatch" | "insufficient_funds" | "invalid";
|
|
171
|
+
/** A refusal by the builder's own checks: nothing was signed. */
|
|
172
|
+
export declare class PoolBuildError extends Error {
|
|
173
|
+
readonly code: PoolBuildErrorCode;
|
|
174
|
+
constructor(code: PoolBuildErrorCode, message: string);
|
|
175
|
+
}
|
|
176
|
+
export declare class PoolTemplate {
|
|
177
|
+
/**
|
|
178
|
+
* Decodes a pool locking script: a 1Color value prefix with a 32-byte id (no payload), then the Pool artifact
|
|
179
|
+
* (template bytes between the constructor slots), then the state. Also requires
|
|
180
|
+
* prefix id == assetId and prefix amount == TokenReserve (the admission check of
|
|
181
|
+
* Pool.runar.go's doc). Returns null for anything else.
|
|
182
|
+
*/
|
|
183
|
+
static decode(script: string | LockingScript | number[]): Pool | null;
|
|
184
|
+
/** Whether the pool was rescinded by its validator (layout 2: ValidatorPubKey 33 zero bytes). */
|
|
185
|
+
static rescinded(pool: Pick<Pool, "state">): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* A new pool's locking script (layout 2, 0.13.0): the 1Color prefix for TokenReserve (which
|
|
188
|
+
* the contract writes itself on every continuation, but nothing on chain writes for a deploy)
|
|
189
|
+
* in front of runar-sdk's locking script for the constructor args. `state` may leave the
|
|
190
|
+
* ValidatorPubKey, Nonce and Affirmation to come (33 zero bytes, absent, absent: the pool as
|
|
191
|
+
* `amm.pool.affirm` is asked about it); the deploy carries the validator's three.
|
|
192
|
+
*/
|
|
193
|
+
static lockDeploy(args: PoolArgs, state: PoolFields): LockingScript;
|
|
194
|
+
/**
|
|
195
|
+
* The bytes the validator's affirmation signs (0.13.0, message v2, docs/AMM.md "The deploy
|
|
196
|
+
* and the affirmation"; src/pool.zig `affirmMessage`): "skein-amm affirm 2" ‖ AssetId (32,
|
|
197
|
+
* wire order) ‖ LpFeeBps ‖ ValidatorFeeBps ‖ CommissionBps (int64 LE) ‖ TokenReserve ‖ the
|
|
198
|
+
* pool output's satoshis (uint64 LE) ‖ LpPubKey ‖ ValidatorPubKey ‖ ValidatorIdentity (33
|
|
199
|
+
* each) ‖ Nonce (32). 221 bytes.
|
|
200
|
+
*/
|
|
201
|
+
static affirmationMessage(pool: {
|
|
202
|
+
args: PoolArgs;
|
|
203
|
+
state: PoolFields;
|
|
204
|
+
}, satoshis: bigint): number[];
|
|
205
|
+
/**
|
|
206
|
+
* Whether the pool output (`script`, holding `satoshis`) attests itself (0.13.0, amm-lookup's
|
|
207
|
+
* deploy rule, src/pool.zig `affirmed`): layout 2, not rescinded, its ValidatorPubKey the
|
|
208
|
+
* ValidatorIdentity's child keyed by its Nonce (derived here), and its Affirmation that key's
|
|
209
|
+
* signature of `affirmationMessage`.
|
|
210
|
+
*/
|
|
211
|
+
static affirmed(script: string | LockingScript | number[], satoshis: bigint): boolean;
|
|
212
|
+
/** The continuation script: `code` kept byte for byte, prefix and state rewritten. */
|
|
213
|
+
static lockContinuation(pool: Pool, state: PoolFields): LockingScript;
|
|
214
|
+
/**
|
|
215
|
+
* Swap (method 0). Outputs: 0 pool, 1 the taker's payout, then the LP fee,
|
|
216
|
+
* the validator fee and the commission (each only when nonzero, each in
|
|
217
|
+
* the input asset), then change. Token payouts and token fees are 1-sat
|
|
218
|
+
* 1Color outputs; BSV ones are P2PKH. The validator's slot is left empty.
|
|
219
|
+
*/
|
|
220
|
+
static swap(p: SwapParams): Promise<PoolCall>;
|
|
221
|
+
/**
|
|
222
|
+
* The Swap call without its funding: the outputs the contract requires (in
|
|
223
|
+
* order: pool, payout, LP fee, validator fee, commission; no change) and
|
|
224
|
+
* the method arguments, with the validator's slot empty. For a builder that
|
|
225
|
+
* does not pick the funding itself (a BRC-100 wallet's `createAction` picks
|
|
226
|
+
* inputs and change): hand these outputs over, then fill input 0 with
|
|
227
|
+
* `callUnlock` over the transaction the wallet produced. Same checks and
|
|
228
|
+
* refusals as `swap` except the funding ones.
|
|
229
|
+
*/
|
|
230
|
+
static planSwap(p: SwapPlanParams): CallPlan & {
|
|
231
|
+
swap: SwapAmounts;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* The pool input's unlocking script for `plan` over a finished transaction
|
|
235
|
+
* `tx` whose input 0 spends `plan.poolUtxo` and whose outputs are
|
|
236
|
+
* `plan.outputs`, then (optionally) one P2PKH change output: `change` names
|
|
237
|
+
* it (`{pkh, satoshis}`), or `null` when there is none. Signature slots stay
|
|
238
|
+
* empty (`OP_0`), to be filled with `signPoolInput`. Throws when `tx` does
|
|
239
|
+
* not have that shape (the contract would refuse it).
|
|
240
|
+
*/
|
|
241
|
+
static callUnlock(plan: CallPlan, tx: Transaction, change: {
|
|
242
|
+
pkh: string;
|
|
243
|
+
satoshis: number;
|
|
244
|
+
} | null): {
|
|
245
|
+
unlockingScript: UnlockingScript;
|
|
246
|
+
preimage: string;
|
|
247
|
+
sighash: string;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* An upper bound on the length of `plan`'s pool unlocking script once every
|
|
251
|
+
* signature slot is filled: what a wallet's `createAction` is told as the
|
|
252
|
+
* pool input's `unlockingScriptLength` before the transaction exists (the
|
|
253
|
+
* fee is sized from it). The preimage's length depends only on the code, so
|
|
254
|
+
* it is exact; the change amount is bounded by 2^53.
|
|
255
|
+
*/
|
|
256
|
+
static maxCallUnlockLength(plan: CallPlan): number;
|
|
257
|
+
/**
|
|
258
|
+
* Close (method 1; skein-amm 0.9.0, David Case 2026-10-09: a position is deployed or closed,
|
|
259
|
+
* never resized in place), the LP's, built here: the outputs are the LP's (`outputs`), then
|
|
260
|
+
* change. No continuation.
|
|
261
|
+
*/
|
|
262
|
+
static close(p: CloseParams): Promise<PoolCall>;
|
|
263
|
+
/**
|
|
264
|
+
* The Close call without its funding (as `planSwap` for Swap), the LP's slot empty
|
|
265
|
+
* (`Close(lpSig)`, outputs free): `outputs` are the LP's choice, passed through (at least one).
|
|
266
|
+
*/
|
|
267
|
+
static planClose(p: {
|
|
268
|
+
pool: PoolUtxo;
|
|
269
|
+
outputs: {
|
|
270
|
+
satoshis: bigint;
|
|
271
|
+
script: string;
|
|
272
|
+
}[];
|
|
273
|
+
}): CallPlan;
|
|
274
|
+
/**
|
|
275
|
+
* The BIP-143 preimage of `tx`'s pool input (input 0), computed from the
|
|
276
|
+
* transaction itself. Needs the pool output being spent: `source`, or input
|
|
277
|
+
* 0's `sourceTransaction`.
|
|
278
|
+
*/
|
|
279
|
+
static preimage(tx: Transaction, source?: {
|
|
280
|
+
satoshis: number;
|
|
281
|
+
script: string | LockingScript;
|
|
282
|
+
}): string;
|
|
283
|
+
/**
|
|
284
|
+
* Fills signature slot `slot` of the pool input with `signer`'s signature
|
|
285
|
+
* over the preimage recomputed from `call.tx` (which must agree with the
|
|
286
|
+
* preimage pushed in the call). Every other push is kept byte for byte;
|
|
287
|
+
* no other input's signature is affected.
|
|
288
|
+
*/
|
|
289
|
+
static signPoolInput(call: Pick<PoolCall, "tx" | "pool" | "method" | "unsigned"> & {
|
|
290
|
+
sourceSatoshis?: number;
|
|
291
|
+
}, slot: SigSlot, signer: PoolSigner): Promise<void>;
|
|
292
|
+
}
|
|
293
|
+
/** A P2PKH unlocker for a builder input (also a 1Color token held on P2PKH). */
|
|
294
|
+
export declare function p2pkhUnlock(key: PrivateKey, satoshis: number, lockingScript: string | LockingScript): BuilderInput["unlock"];
|
|
295
|
+
export {};
|