@secondlayer/stacks 2.14.1 → 2.15.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 +37 -0
- package/dist/shared/{stacks-f66v961k.js → stacks-1k0kmpcw.js} +2 -2
- package/dist/shared/{stacks-6mhsf8hk.cjs → stacks-1xk4wby6.cjs} +10 -21
- package/dist/shared/{stacks-6mhsf8hk.cjs.map → stacks-1xk4wby6.cjs.map} +5 -6
- package/dist/shared/{stacks-tswh2xav.js → stacks-2x04a6ss.js} +12 -26
- package/dist/shared/{stacks-tswh2xav.js.map → stacks-2x04a6ss.js.map} +5 -6
- package/dist/shared/stacks-3kj51c6p.cjs +16 -0
- package/dist/shared/stacks-3kj51c6p.cjs.map +10 -0
- package/dist/shared/{stacks-jcgvn5v5.cjs → stacks-70xxh5h1.cjs} +15 -6
- package/dist/shared/{stacks-dmrvk1mz.js.map → stacks-70xxh5h1.cjs.map} +3 -3
- package/dist/shared/stacks-f0hfqaj5.js +22 -0
- package/dist/shared/stacks-f0hfqaj5.js.map +10 -0
- package/dist/shared/{stacks-3vyvtahh.js → stacks-ggxnnph5.cjs} +2 -46
- package/dist/shared/stacks-ggxnnph5.cjs.map +10 -0
- package/dist/shared/stacks-pdcz1w1d.js +33 -0
- package/dist/shared/stacks-pdcz1w1d.js.map +10 -0
- package/dist/shared/{stacks-fjrpnkt3.cjs → stacks-q45x3389.js} +20 -15
- package/dist/shared/stacks-q45x3389.js.map +10 -0
- package/dist/shared/{stacks-hxp7v905.js → stacks-refg7hca.js} +7 -5
- package/dist/shared/{stacks-hxp7v905.js.map → stacks-refg7hca.js.map} +2 -2
- package/dist/shared/{stacks-dmrvk1mz.js → stacks-y9w78e2b.js} +15 -6
- package/dist/shared/{stacks-jcgvn5v5.cjs.map → stacks-y9w78e2b.js.map} +3 -3
- package/dist/shared/stacks-yetejw9x.cjs +16 -0
- package/dist/shared/stacks-yetejw9x.cjs.map +10 -0
- package/dist/src/actions/index.js +12 -8
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bns/index.js +5 -4
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/connect/index.cjs +47 -6
- package/dist/src/connect/index.cjs.map +8 -4
- package/dist/src/connect/index.js +47 -6
- package/dist/src/connect/index.js.map +8 -4
- package/dist/src/index.js +11 -7
- package/dist/src/index.js.map +2 -2
- package/dist/src/pox/index.js +5 -4
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/pox5/index.cjs +513 -0
- package/dist/src/pox5/index.cjs.map +16 -0
- package/dist/src/pox5/index.d.cts +646 -0
- package/dist/src/pox5/index.d.ts +646 -0
- package/dist/src/pox5/index.js +540 -0
- package/dist/src/pox5/index.js.map +16 -0
- package/dist/src/sbtc/index.js +5 -4
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/stackingdao/index.js +5 -4
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/tools/btc/index.cjs +6 -5
- package/dist/src/tools/btc/index.cjs.map +3 -3
- package/dist/src/tools/btc/index.d.cts +2 -1
- package/dist/src/tools/btc/index.d.ts +2 -1
- package/dist/src/tools/btc/index.js +6 -5
- package/dist/src/tools/btc/index.js.map +3 -3
- package/dist/src/tools/index.cjs +323 -43
- package/dist/src/tools/index.cjs.map +10 -9
- package/dist/src/tools/index.js +323 -46
- package/dist/src/tools/index.js.map +10 -9
- package/dist/src/x402/index.js +2 -2
- package/package.json +7 -2
- package/dist/shared/stacks-3vyvtahh.js.map +0 -11
- package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
- /package/dist/shared/{stacks-f66v961k.js.map → stacks-1k0kmpcw.js.map} +0 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
// src/pox5/index.ts
|
|
2
|
+
var exports_pox5 = {};
|
|
3
|
+
__export(exports_pox5, {
|
|
4
|
+
verifySignerGrant: () => verifySignerGrant,
|
|
5
|
+
stakerPreimage: () => stakerPreimage,
|
|
6
|
+
stakerConsensusBuff: () => stakerConsensusBuff,
|
|
7
|
+
signSignerGrant: () => signSignerGrant,
|
|
8
|
+
serializeCScriptNum: () => serializeCScriptNum,
|
|
9
|
+
rewardCycleToBurnHeight: () => rewardCycleToBurnHeight,
|
|
10
|
+
pushScriptBytes: () => pushScriptBytes,
|
|
11
|
+
pushCScriptNum: () => pushCScriptNum,
|
|
12
|
+
pox5ContractId: () => pox5ContractId,
|
|
13
|
+
pox5: () => pox5,
|
|
14
|
+
isPox5Active: () => isPox5Active,
|
|
15
|
+
isInPreparePhase: () => isInPreparePhase,
|
|
16
|
+
getPox5Activation: () => getPox5Activation,
|
|
17
|
+
computeSignerGrantHash: () => computeSignerGrantHash,
|
|
18
|
+
burnHeightToRewardCycle: () => burnHeightToRewardCycle,
|
|
19
|
+
burnHeightToDistributionIndex: () => burnHeightToDistributionIndex,
|
|
20
|
+
buildLockupScript: () => buildLockupScript,
|
|
21
|
+
buildLockupOutputScript: () => buildLockupOutputScript,
|
|
22
|
+
buildLockupAddress: () => buildLockupAddress,
|
|
23
|
+
buildDefaultStakerUnlockBytes: () => buildDefaultStakerUnlockBytes,
|
|
24
|
+
bondUnlockCycle: () => bondUnlockCycle,
|
|
25
|
+
bondPhaseAtHeight: () => bondPhaseAtHeight,
|
|
26
|
+
bondPeriodToRewardCycle: () => bondPeriodToRewardCycle,
|
|
27
|
+
bondPeriodToBurnHeight: () => bondPeriodToBurnHeight,
|
|
28
|
+
assertPox5Active: () => assertPox5Active,
|
|
29
|
+
POX5_SIGNER_DOMAIN: () => POX5_SIGNER_DOMAIN,
|
|
30
|
+
POX5_CONTRACT_NAME: () => POX5_CONTRACT_NAME,
|
|
31
|
+
POX5_ACTIVATION_BURN_HEIGHT_MAINNET: () => POX5_ACTIVATION_BURN_HEIGHT_MAINNET,
|
|
32
|
+
MAX_NUM_CYCLES: () => MAX_NUM_CYCLES,
|
|
33
|
+
C_SCRIPT_NUM_MAX: () => C_SCRIPT_NUM_MAX,
|
|
34
|
+
BOND_LENGTH_CYCLES: () => BOND_LENGTH_CYCLES,
|
|
35
|
+
BOND_GAP_CYCLES: () => BOND_GAP_CYCLES,
|
|
36
|
+
BITCOIN_LOCKTIME_THRESHOLD: () => BITCOIN_LOCKTIME_THRESHOLD
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(exports_pox5);
|
|
39
|
+
|
|
40
|
+
// src/pox5/constants.ts
|
|
41
|
+
var POX5_CONTRACT_NAME = "pox-5";
|
|
42
|
+
var POX5_ACTIVATION_BURN_HEIGHT_MAINNET = 960230;
|
|
43
|
+
var BOND_LENGTH_CYCLES = 12;
|
|
44
|
+
var BOND_GAP_CYCLES = 2;
|
|
45
|
+
var MAX_NUM_CYCLES = 96;
|
|
46
|
+
var POX5_SIGNER_DOMAIN = {
|
|
47
|
+
name: "pox-5-signer",
|
|
48
|
+
version: "1.0.0"
|
|
49
|
+
};
|
|
50
|
+
var C_SCRIPT_NUM_MAX = 549755813888n;
|
|
51
|
+
var BITCOIN_LOCKTIME_THRESHOLD = 500000000n;
|
|
52
|
+
|
|
53
|
+
// src/pox5/activation.ts
|
|
54
|
+
async function getPox5Activation(client) {
|
|
55
|
+
const info = await client.request("/v2/pox", {
|
|
56
|
+
method: "GET"
|
|
57
|
+
});
|
|
58
|
+
const entry = info.contract_versions?.find((v) => v.contract_id.endsWith(`.${POX5_CONTRACT_NAME}`));
|
|
59
|
+
if (!entry)
|
|
60
|
+
return;
|
|
61
|
+
return {
|
|
62
|
+
contractId: entry.contract_id,
|
|
63
|
+
activationBurnchainBlockHeight: entry.activation_burnchain_block_height,
|
|
64
|
+
firstRewardCycleId: entry.first_reward_cycle_id
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function isPox5Active(client) {
|
|
68
|
+
const info = await client.request("/v2/pox", {
|
|
69
|
+
method: "GET"
|
|
70
|
+
});
|
|
71
|
+
const entry = info.contract_versions?.find((v) => v.contract_id.endsWith(`.${POX5_CONTRACT_NAME}`));
|
|
72
|
+
if (!entry || typeof info.current_burnchain_block_height !== "number")
|
|
73
|
+
return false;
|
|
74
|
+
return info.current_burnchain_block_height >= entry.activation_burnchain_block_height;
|
|
75
|
+
}
|
|
76
|
+
async function assertPox5Active(client) {
|
|
77
|
+
if (!await isPox5Active(client)) {
|
|
78
|
+
throw new Error("pox-5 is not active on this chain yet (Epoch 4.0 activates at Bitcoin block 960,230 on mainnet, ~2026-07-29). " + "Check getPox5Activation(client) for this network's activation height.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// src/pox5/cycles.ts
|
|
82
|
+
function burnHeightToRewardCycle(burnHeight, params) {
|
|
83
|
+
if (burnHeight < params.firstBurnchainBlockHeight) {
|
|
84
|
+
throw new Error(`burnHeight ${burnHeight} precedes first burnchain block ${params.firstBurnchainBlockHeight}`);
|
|
85
|
+
}
|
|
86
|
+
return Math.floor((burnHeight - params.firstBurnchainBlockHeight) / params.rewardCycleLength);
|
|
87
|
+
}
|
|
88
|
+
function rewardCycleToBurnHeight(cycle, params) {
|
|
89
|
+
return params.firstBurnchainBlockHeight + cycle * params.rewardCycleLength;
|
|
90
|
+
}
|
|
91
|
+
function bondPeriodToRewardCycle(bondIndex, params) {
|
|
92
|
+
return params.firstBondPeriodCycle + bondIndex * BOND_GAP_CYCLES;
|
|
93
|
+
}
|
|
94
|
+
function bondPeriodToBurnHeight(bondIndex, params) {
|
|
95
|
+
return rewardCycleToBurnHeight(bondPeriodToRewardCycle(bondIndex, params), params);
|
|
96
|
+
}
|
|
97
|
+
function bondUnlockCycle(bondIndex, params) {
|
|
98
|
+
return bondPeriodToRewardCycle(bondIndex, params) + BOND_LENGTH_CYCLES;
|
|
99
|
+
}
|
|
100
|
+
function burnHeightToDistributionIndex(burnHeight, params) {
|
|
101
|
+
return Math.floor((burnHeight - params.firstBurnchainBlockHeight) / Math.floor(params.rewardCycleLength / 2));
|
|
102
|
+
}
|
|
103
|
+
function isInPreparePhase(burnHeight, params) {
|
|
104
|
+
const offset = (burnHeight - params.firstBurnchainBlockHeight) % params.rewardCycleLength;
|
|
105
|
+
return offset >= params.rewardCycleLength - params.prepareCycleLength;
|
|
106
|
+
}
|
|
107
|
+
function bondPhaseAtHeight(bondIndex, burnHeight, params) {
|
|
108
|
+
const cycle = burnHeightToRewardCycle(burnHeight, params);
|
|
109
|
+
const start = bondPeriodToRewardCycle(bondIndex, params);
|
|
110
|
+
const unlock = bondUnlockCycle(bondIndex, params);
|
|
111
|
+
if (cycle < start - BOND_GAP_CYCLES)
|
|
112
|
+
return "too-early";
|
|
113
|
+
if (cycle < start)
|
|
114
|
+
return "open";
|
|
115
|
+
if (cycle < unlock)
|
|
116
|
+
return "locked";
|
|
117
|
+
return "unlocked";
|
|
118
|
+
}
|
|
119
|
+
// src/pox5/script.ts
|
|
120
|
+
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
121
|
+
function serializeCScriptNum(n) {
|
|
122
|
+
const big = typeof n === "bigint" ? n : BigInt(n);
|
|
123
|
+
if (big < 0n)
|
|
124
|
+
throw new Error("serializeCScriptNum: negative value");
|
|
125
|
+
if (big >= C_SCRIPT_NUM_MAX) {
|
|
126
|
+
throw new Error("serializeCScriptNum: n >= 2^39 (contract rejects with ERR_INVALID_UNLOCK_HEIGHT)");
|
|
127
|
+
}
|
|
128
|
+
if (big === 0n)
|
|
129
|
+
return new Uint8Array(0);
|
|
130
|
+
const out = [];
|
|
131
|
+
let v = big;
|
|
132
|
+
while (v > 0n) {
|
|
133
|
+
out.push(Number(v & 0xffn));
|
|
134
|
+
v >>= 8n;
|
|
135
|
+
}
|
|
136
|
+
if (out[out.length - 1] & 128)
|
|
137
|
+
out.push(0);
|
|
138
|
+
return Uint8Array.from(out);
|
|
139
|
+
}
|
|
140
|
+
function pushScriptBytes(bytes) {
|
|
141
|
+
const len = bytes.length;
|
|
142
|
+
if (len > 65535)
|
|
143
|
+
throw new Error(`pushScriptBytes: payload too large (${len} > 65535)`);
|
|
144
|
+
let prefix;
|
|
145
|
+
if (len < 76)
|
|
146
|
+
prefix = Uint8Array.of(len);
|
|
147
|
+
else if (len < 256)
|
|
148
|
+
prefix = Uint8Array.of(76, len);
|
|
149
|
+
else
|
|
150
|
+
prefix = Uint8Array.of(77, len & 255, len >> 8);
|
|
151
|
+
return concatBytes(prefix, bytes);
|
|
152
|
+
}
|
|
153
|
+
function pushCScriptNum(n) {
|
|
154
|
+
const big = typeof n === "bigint" ? n : BigInt(n);
|
|
155
|
+
if (big === 0n)
|
|
156
|
+
return Uint8Array.of(0);
|
|
157
|
+
if (big >= 1n && big <= 16n)
|
|
158
|
+
return Uint8Array.of(80 + Number(big));
|
|
159
|
+
return pushScriptBytes(serializeCScriptNum(big));
|
|
160
|
+
}
|
|
161
|
+
function stakerConsensusBuff(stxAddress) {
|
|
162
|
+
return serializeCVBytes(Cl.principal(stxAddress));
|
|
163
|
+
}
|
|
164
|
+
function stakerPreimage(stxAddress) {
|
|
165
|
+
return import_sha2.sha256(stakerConsensusBuff(stxAddress));
|
|
166
|
+
}
|
|
167
|
+
function toBytes(input) {
|
|
168
|
+
return typeof input === "string" ? hexToBytes(input) : input;
|
|
169
|
+
}
|
|
170
|
+
function buildLockupScript(opts) {
|
|
171
|
+
const height = BigInt(opts.unlockBurnHeight);
|
|
172
|
+
if (height >= BITCOIN_LOCKTIME_THRESHOLD) {
|
|
173
|
+
throw new Error("unlockBurnHeight >= 500,000,000 would be read by Bitcoin as a timestamp (contract rejects it)");
|
|
174
|
+
}
|
|
175
|
+
const stakerHash = import_sha2.sha256(stakerPreimage(opts.stxAddress));
|
|
176
|
+
return concatBytes(Uint8Array.of(99), pushCScriptNum(height), Uint8Array.of(177, 103), hexToBytes("82012088a820"), stakerHash, Uint8Array.of(136), toBytes(opts.earlyUnlockBytes), Uint8Array.of(104, 105), toBytes(opts.stakerUnlockBytes));
|
|
177
|
+
}
|
|
178
|
+
function buildLockupOutputScript(opts) {
|
|
179
|
+
return concatBytes(Uint8Array.of(0, 32), import_sha2.sha256(buildLockupScript(opts)));
|
|
180
|
+
}
|
|
181
|
+
function buildLockupAddress(opts, network = "mainnet") {
|
|
182
|
+
const hash = import_sha2.sha256(buildLockupScript(opts));
|
|
183
|
+
return bech32.encode(BITCOIN_NETWORK_PARAMS[network].hrp, [
|
|
184
|
+
0,
|
|
185
|
+
...bech32.toWords(hash)
|
|
186
|
+
]);
|
|
187
|
+
}
|
|
188
|
+
function buildDefaultStakerUnlockBytes(publicKey) {
|
|
189
|
+
const pubkey = toBytes(publicKey);
|
|
190
|
+
if (pubkey.length !== 33)
|
|
191
|
+
throw new Error(`Expected 33-byte compressed pubkey, got ${pubkey.length}`);
|
|
192
|
+
return concatBytes(pushScriptBytes(pubkey), Uint8Array.of(172));
|
|
193
|
+
}
|
|
194
|
+
// src/pox5/grants.ts
|
|
195
|
+
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
196
|
+
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
197
|
+
var SIP018_PREFIX = hexToBytes("534950303138");
|
|
198
|
+
function computeSignerGrantHash(opts) {
|
|
199
|
+
const domain = serializeCVBytes(Cl.tuple({
|
|
200
|
+
name: Cl.stringAscii(POX5_SIGNER_DOMAIN.name),
|
|
201
|
+
version: Cl.stringAscii(POX5_SIGNER_DOMAIN.version),
|
|
202
|
+
"chain-id": Cl.uint(opts.chainId)
|
|
203
|
+
}));
|
|
204
|
+
const message = serializeCVBytes(Cl.tuple({
|
|
205
|
+
topic: Cl.stringAscii("grant-authorization"),
|
|
206
|
+
"signer-manager": Cl.principal(opts.signerManager),
|
|
207
|
+
"auth-id": Cl.uint(opts.authId)
|
|
208
|
+
}));
|
|
209
|
+
return import_sha22.sha256(concatBytes(SIP018_PREFIX, import_sha22.sha256(domain), import_sha22.sha256(message)));
|
|
210
|
+
}
|
|
211
|
+
async function signSignerGrant(account, opts) {
|
|
212
|
+
const vrs = await account.sign(computeSignerGrantHash(opts));
|
|
213
|
+
if (vrs.length !== 65)
|
|
214
|
+
throw new Error(`Expected 65-byte recoverable signature, got ${vrs.length}`);
|
|
215
|
+
return bytesToHex(concatBytes(vrs.slice(1), vrs.slice(0, 1)));
|
|
216
|
+
}
|
|
217
|
+
function verifySignerGrant(opts) {
|
|
218
|
+
try {
|
|
219
|
+
const sig = typeof opts.signature === "string" ? hexToBytes(opts.signature) : opts.signature;
|
|
220
|
+
if (sig.length !== 65)
|
|
221
|
+
return false;
|
|
222
|
+
const pubkey = typeof opts.publicKey === "string" ? hexToBytes(opts.publicKey) : opts.publicKey;
|
|
223
|
+
const hash = computeSignerGrantHash(opts);
|
|
224
|
+
const recovered = import_secp256k1.secp256k1.Signature.fromBytes(sig.slice(0, 64)).addRecoveryBit(sig[64]).recoverPublicKey(hash).toBytes(true);
|
|
225
|
+
return bytesToHex(recovered) === bytesToHex(pubkey);
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// src/pox5/actions.ts
|
|
231
|
+
function pox5ContractId(client) {
|
|
232
|
+
const boot = client.chain?.bootAddress;
|
|
233
|
+
if (!boot)
|
|
234
|
+
throw new Error("Client must have a chain with a bootAddress");
|
|
235
|
+
return `${boot}.${POX5_CONTRACT_NAME}`;
|
|
236
|
+
}
|
|
237
|
+
function call(client, functionName, functionArgs, options = {}) {
|
|
238
|
+
return callContract(client, {
|
|
239
|
+
contract: pox5ContractId(client),
|
|
240
|
+
functionName,
|
|
241
|
+
functionArgs,
|
|
242
|
+
...options
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function read(client, functionName, functionArgs = []) {
|
|
246
|
+
const [address, name] = pox5ContractId(client).split(".");
|
|
247
|
+
return readContract(client, {
|
|
248
|
+
contract: `${address}.${name}`,
|
|
249
|
+
functionName,
|
|
250
|
+
args: functionArgs
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function bufferCV(input) {
|
|
254
|
+
return typeof input === "string" ? Cl.bufferFromHex(input) : Cl.buffer(input);
|
|
255
|
+
}
|
|
256
|
+
function btcLockupCV(lockup) {
|
|
257
|
+
if ("sbtcSats" in lockup)
|
|
258
|
+
return Cl.error(Cl.uint(lockup.sbtcSats));
|
|
259
|
+
return Cl.ok(Cl.tuple({
|
|
260
|
+
outputs: Cl.list(lockup.l1Outputs.map((o) => Cl.tuple({
|
|
261
|
+
height: Cl.uint(o.height),
|
|
262
|
+
tx: bufferCV(o.tx),
|
|
263
|
+
"output-index": Cl.uint(o.outputIndex),
|
|
264
|
+
header: bufferCV(o.header),
|
|
265
|
+
"leaf-hashes": Cl.list(o.leafHashes.map(bufferCV)),
|
|
266
|
+
"tx-count": Cl.uint(o.txCount),
|
|
267
|
+
"tx-index": Cl.uint(o.txIndex),
|
|
268
|
+
amount: Cl.uint(o.amount),
|
|
269
|
+
"unlock-burn-height": Cl.uint(o.unlockBurnHeight)
|
|
270
|
+
}))),
|
|
271
|
+
"staker-unlock-bytes": bufferCV(lockup.stakerUnlockBytes)
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
function optionalBuffer(input) {
|
|
275
|
+
return input === undefined ? Cl.none() : Cl.some(bufferCV(input));
|
|
276
|
+
}
|
|
277
|
+
function setupBond(client, params) {
|
|
278
|
+
const {
|
|
279
|
+
bondIndex,
|
|
280
|
+
targetRate,
|
|
281
|
+
stxValueRatio,
|
|
282
|
+
minUstxRatio,
|
|
283
|
+
earlyUnlockBytes,
|
|
284
|
+
allowlist,
|
|
285
|
+
...tx
|
|
286
|
+
} = params;
|
|
287
|
+
return call(client, "setup-bond", [
|
|
288
|
+
Cl.uint(bondIndex),
|
|
289
|
+
Cl.uint(targetRate),
|
|
290
|
+
Cl.uint(stxValueRatio),
|
|
291
|
+
Cl.uint(minUstxRatio),
|
|
292
|
+
bufferCV(earlyUnlockBytes),
|
|
293
|
+
Cl.list(allowlist.map((a) => Cl.tuple({
|
|
294
|
+
staker: Cl.principal(a.staker),
|
|
295
|
+
"max-sats": Cl.uint(a.maxSats)
|
|
296
|
+
})))
|
|
297
|
+
], tx);
|
|
298
|
+
}
|
|
299
|
+
function registerForBond(client, params) {
|
|
300
|
+
const {
|
|
301
|
+
bondIndex,
|
|
302
|
+
signerManager,
|
|
303
|
+
amountUstx,
|
|
304
|
+
btcLockup,
|
|
305
|
+
signerCalldata,
|
|
306
|
+
...tx
|
|
307
|
+
} = params;
|
|
308
|
+
return call(client, "register-for-bond", [
|
|
309
|
+
Cl.uint(bondIndex),
|
|
310
|
+
Cl.principal(signerManager),
|
|
311
|
+
Cl.uint(amountUstx),
|
|
312
|
+
btcLockupCV(btcLockup),
|
|
313
|
+
optionalBuffer(signerCalldata)
|
|
314
|
+
], tx);
|
|
315
|
+
}
|
|
316
|
+
function updateBondRegistration(client, params) {
|
|
317
|
+
const { signerManager, oldSignerManager, signerCalldata, ...tx } = params;
|
|
318
|
+
return call(client, "update-bond-registration", [
|
|
319
|
+
Cl.principal(signerManager),
|
|
320
|
+
Cl.principal(oldSignerManager),
|
|
321
|
+
optionalBuffer(signerCalldata)
|
|
322
|
+
], tx);
|
|
323
|
+
}
|
|
324
|
+
function stake(client, params) {
|
|
325
|
+
const {
|
|
326
|
+
signerManager,
|
|
327
|
+
amountUstx,
|
|
328
|
+
numCycles,
|
|
329
|
+
startBurnHeight,
|
|
330
|
+
signerCalldata,
|
|
331
|
+
...tx
|
|
332
|
+
} = params;
|
|
333
|
+
return call(client, "stake", [
|
|
334
|
+
Cl.principal(signerManager),
|
|
335
|
+
Cl.uint(amountUstx),
|
|
336
|
+
Cl.uint(numCycles),
|
|
337
|
+
Cl.uint(startBurnHeight),
|
|
338
|
+
optionalBuffer(signerCalldata)
|
|
339
|
+
], tx);
|
|
340
|
+
}
|
|
341
|
+
function stakeUpdate(client, params) {
|
|
342
|
+
const {
|
|
343
|
+
signerManager,
|
|
344
|
+
oldSignerManager,
|
|
345
|
+
cyclesToExtend,
|
|
346
|
+
amountIncrease,
|
|
347
|
+
signerCalldata,
|
|
348
|
+
...tx
|
|
349
|
+
} = params;
|
|
350
|
+
return call(client, "stake-update", [
|
|
351
|
+
Cl.principal(signerManager),
|
|
352
|
+
Cl.principal(oldSignerManager),
|
|
353
|
+
Cl.uint(cyclesToExtend),
|
|
354
|
+
Cl.uint(amountIncrease),
|
|
355
|
+
optionalBuffer(signerCalldata)
|
|
356
|
+
], tx);
|
|
357
|
+
}
|
|
358
|
+
function unstake(client, params) {
|
|
359
|
+
const { oldSignerManager, ...tx } = params;
|
|
360
|
+
return call(client, "unstake", [Cl.principal(oldSignerManager)], tx);
|
|
361
|
+
}
|
|
362
|
+
function unstakeSbtc(client, params) {
|
|
363
|
+
const { signerManager, amountSats, ...tx } = params;
|
|
364
|
+
return call(client, "unstake-sbtc", [Cl.principal(signerManager), Cl.uint(amountSats)], tx);
|
|
365
|
+
}
|
|
366
|
+
function announceL1EarlyExit(client, params) {
|
|
367
|
+
const { staker, oldSignerManager, ...tx } = params;
|
|
368
|
+
return call(client, "announce-l1-early-exit", [Cl.principal(staker), Cl.principal(oldSignerManager)], tx);
|
|
369
|
+
}
|
|
370
|
+
function calculateRewards(client, params) {
|
|
371
|
+
const { bondPeriods, ...tx } = params;
|
|
372
|
+
return call(client, "calculate-rewards", [Cl.list(bondPeriods.map((p) => Cl.uint(p)))], tx);
|
|
373
|
+
}
|
|
374
|
+
function claimRewards(client, params) {
|
|
375
|
+
const { bondPeriods, rewardCycle, ...tx } = params;
|
|
376
|
+
return call(client, "claim-rewards", [Cl.list(bondPeriods.map((p) => Cl.uint(p))), Cl.uint(rewardCycle)], tx);
|
|
377
|
+
}
|
|
378
|
+
function claimStakerRewardsForSigner(client, params) {
|
|
379
|
+
const { staker, rewardCycle, bondIndex, ...tx } = params;
|
|
380
|
+
return call(client, "claim-staker-rewards-for-signer", [
|
|
381
|
+
Cl.principal(staker),
|
|
382
|
+
Cl.uint(rewardCycle),
|
|
383
|
+
bondIndex === undefined ? Cl.none() : Cl.some(Cl.uint(bondIndex))
|
|
384
|
+
], tx);
|
|
385
|
+
}
|
|
386
|
+
function grantSignerKey(client, params) {
|
|
387
|
+
const { signerKey, signerManager, authId, signerSig, ...tx } = params;
|
|
388
|
+
return call(client, "grant-signer-key", [
|
|
389
|
+
bufferCV(signerKey),
|
|
390
|
+
Cl.principal(signerManager),
|
|
391
|
+
Cl.uint(authId),
|
|
392
|
+
bufferCV(signerSig)
|
|
393
|
+
], tx);
|
|
394
|
+
}
|
|
395
|
+
function revokeSignerGrant(client, params) {
|
|
396
|
+
const { signerManager, signerKey, ...tx } = params;
|
|
397
|
+
return call(client, "revoke-signer-grant", [Cl.principal(signerManager), bufferCV(signerKey)], tx);
|
|
398
|
+
}
|
|
399
|
+
function getStakerInfo(client, staker) {
|
|
400
|
+
return read(client, "get-staker-info", [Cl.principal(staker)]);
|
|
401
|
+
}
|
|
402
|
+
function getBondMembership(client, staker) {
|
|
403
|
+
return read(client, "get-bond-membership", [Cl.principal(staker)]);
|
|
404
|
+
}
|
|
405
|
+
function getProtocolBond(client, bondIndex) {
|
|
406
|
+
return read(client, "get-protocol-bond", [Cl.uint(bondIndex)]);
|
|
407
|
+
}
|
|
408
|
+
function getBondAllowance(client, bondIndex, staker) {
|
|
409
|
+
return read(client, "get-bond-allowance", [
|
|
410
|
+
Cl.uint(bondIndex),
|
|
411
|
+
Cl.principal(staker)
|
|
412
|
+
]);
|
|
413
|
+
}
|
|
414
|
+
function getTotalSbtcStakedForBond(client, bondIndex) {
|
|
415
|
+
return read(client, "get-total-sbtc-staked-for-bond", [Cl.uint(bondIndex)]);
|
|
416
|
+
}
|
|
417
|
+
function getStakerCustodiedSbtc(client, staker) {
|
|
418
|
+
return read(client, "get-staker-custodied-sbtc", [Cl.principal(staker)]);
|
|
419
|
+
}
|
|
420
|
+
function hasAnnouncedL1EarlyExit(client, bondIndex, staker) {
|
|
421
|
+
return read(client, "has-announced-l1-early-exit", [
|
|
422
|
+
Cl.uint(bondIndex),
|
|
423
|
+
Cl.principal(staker)
|
|
424
|
+
]);
|
|
425
|
+
}
|
|
426
|
+
function getBondL1UnlockHeight(client, bondIndex) {
|
|
427
|
+
return read(client, "get-bond-l1-unlock-height", [Cl.uint(bondIndex)]);
|
|
428
|
+
}
|
|
429
|
+
function getSignerInfo(client, signer) {
|
|
430
|
+
return read(client, "get-signer-info", [Cl.principal(signer)]);
|
|
431
|
+
}
|
|
432
|
+
function verifySignerKeyGrantOnChain(client, signerManager, signerKey) {
|
|
433
|
+
return read(client, "verify-signer-key-grant", [
|
|
434
|
+
Cl.principal(signerManager),
|
|
435
|
+
bufferCV(signerKey)
|
|
436
|
+
]);
|
|
437
|
+
}
|
|
438
|
+
function getCurrentRewardCycle(client) {
|
|
439
|
+
return read(client, "current-pox-reward-cycle");
|
|
440
|
+
}
|
|
441
|
+
function getFirstPox5RewardCycle(client) {
|
|
442
|
+
return read(client, "get-first-pox-5-reward-cycle");
|
|
443
|
+
}
|
|
444
|
+
// src/pox5/extension.ts
|
|
445
|
+
async function getStakerState(client, staker) {
|
|
446
|
+
const contract = pox5ContractId(client);
|
|
447
|
+
const results = await multicall(client, {
|
|
448
|
+
allowFailure: false,
|
|
449
|
+
calls: [
|
|
450
|
+
{
|
|
451
|
+
contract,
|
|
452
|
+
functionName: "get-staker-info",
|
|
453
|
+
args: [Cl.principal(staker)]
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
contract,
|
|
457
|
+
functionName: "get-bond-membership",
|
|
458
|
+
args: [Cl.principal(staker)]
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
contract,
|
|
462
|
+
functionName: "get-staker-custodied-sbtc",
|
|
463
|
+
args: [Cl.principal(staker)]
|
|
464
|
+
},
|
|
465
|
+
{ contract, functionName: "current-pox-reward-cycle", args: [] }
|
|
466
|
+
]
|
|
467
|
+
});
|
|
468
|
+
const [stakerInfo, bondMembership, custodiedSbtc, currentCycle] = results;
|
|
469
|
+
return {
|
|
470
|
+
stakerInfo,
|
|
471
|
+
bondMembership,
|
|
472
|
+
custodiedSbtc,
|
|
473
|
+
currentCycle
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function pox5() {
|
|
477
|
+
return (client) => ({
|
|
478
|
+
pox5: {
|
|
479
|
+
isActive: () => isPox5Active(client),
|
|
480
|
+
getActivation: () => getPox5Activation(client),
|
|
481
|
+
contractId: () => pox5ContractId(client),
|
|
482
|
+
getStakerState: (staker) => getStakerState(client, staker),
|
|
483
|
+
getStakerInfo: (staker) => getStakerInfo(client, staker),
|
|
484
|
+
getBondMembership: (staker) => getBondMembership(client, staker),
|
|
485
|
+
getProtocolBond: (bondIndex) => getProtocolBond(client, bondIndex),
|
|
486
|
+
getBondAllowance: (bondIndex, staker) => getBondAllowance(client, bondIndex, staker),
|
|
487
|
+
getTotalSbtcStakedForBond: (bondIndex) => getTotalSbtcStakedForBond(client, bondIndex),
|
|
488
|
+
getStakerCustodiedSbtc: (staker) => getStakerCustodiedSbtc(client, staker),
|
|
489
|
+
hasAnnouncedL1EarlyExit: (bondIndex, staker) => hasAnnouncedL1EarlyExit(client, bondIndex, staker),
|
|
490
|
+
getBondL1UnlockHeight: (bondIndex) => getBondL1UnlockHeight(client, bondIndex),
|
|
491
|
+
getSignerInfo: (signer) => getSignerInfo(client, signer),
|
|
492
|
+
verifySignerKeyGrant: (signerManager, signerKey) => verifySignerKeyGrantOnChain(client, signerManager, signerKey),
|
|
493
|
+
getCurrentRewardCycle: () => getCurrentRewardCycle(client),
|
|
494
|
+
getFirstRewardCycle: () => getFirstPox5RewardCycle(client),
|
|
495
|
+
setupBond: (params) => setupBond(client, params),
|
|
496
|
+
registerForBond: (params) => registerForBond(client, params),
|
|
497
|
+
updateBondRegistration: (params) => updateBondRegistration(client, params),
|
|
498
|
+
stake: (params) => stake(client, params),
|
|
499
|
+
stakeUpdate: (params) => stakeUpdate(client, params),
|
|
500
|
+
unstake: (params) => unstake(client, params),
|
|
501
|
+
unstakeSbtc: (params) => unstakeSbtc(client, params),
|
|
502
|
+
announceL1EarlyExit: (params) => announceL1EarlyExit(client, params),
|
|
503
|
+
calculateRewards: (params) => calculateRewards(client, params),
|
|
504
|
+
claimRewards: (params) => claimRewards(client, params),
|
|
505
|
+
claimStakerRewardsForSigner: (params) => claimStakerRewardsForSigner(client, params),
|
|
506
|
+
grantSignerKey: (params) => grantSignerKey(client, params),
|
|
507
|
+
revokeSignerGrant: (params) => revokeSignerGrant(client, params)
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
//# debugId=9EC46D11CA68C21664756E2164756E21
|
|
513
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/pox5/constants.ts", "../src/pox5/activation.ts", "../src/pox5/cycles.ts", "../src/pox5/script.ts", "../src/pox5/grants.ts", "../src/pox5/actions.ts", "../src/pox5/extension.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * PoX-5 (SIP-045 Bitcoin Staking) constants, pinned against the final\n * contract shipped in stacks-core 4.0.0 (`stackslib/.../boot/pox-5.clar`).\n */\n\n/** Boot contract name; deployer is the chain's boot address. */\nexport const POX5_CONTRACT_NAME = \"pox-5\";\n\n/**\n * Epoch 4.0 hard-fork activation height on mainnet — Bitcoin block 960,230\n * (expected ~2026-07-29 03:00 UTC, per the stacks-core 4.0.0 release).\n * Prefer the runtime gate in `activation.ts` (`getPox5Activation`), which\n * reads the node's `/v2/pox` and needs no hardcoded height.\n */\nexport const POX5_ACTIVATION_BURN_HEIGHT_MAINNET = 960_230;\n\n/** Length of a paired-BTC bond, in reward cycles (`BOND_LENGTH_CYCLES`). */\nexport const BOND_LENGTH_CYCLES = 12;\n\n/** Gap between consecutive bond starts, in reward cycles (`BOND_GAP_CYCLES`). */\nexport const BOND_GAP_CYCLES = 2;\n\n/** Hard cap for STX-only stake duration, in cycles (`MAX_NUM_CYCLES`). */\nexport const MAX_NUM_CYCLES = 96;\n\n/** SIP-018 domain for signer-key grants (`POX_5_SIGNER_DOMAIN`). */\nexport const POX5_SIGNER_DOMAIN = {\n\tname: \"pox-5-signer\",\n\tversion: \"1.0.0\",\n} as const;\n\n/**\n * `serialize-c-script-num` rejects values at or above 2^39 — the ceiling of a\n * 5-byte minimally-encoded ScriptNum (`ERR_INVALID_UNLOCK_HEIGHT`).\n */\nexport const C_SCRIPT_NUM_MAX = 549_755_813_888n; // 2^39\n\n/**\n * Bitcoin treats CLTV values >= 500,000,000 as Unix timestamps (BIP-65); the\n * contract rejects unlock heights at or above this so a lockup can never\n * commit a height Bitcoin would reinterpret.\n */\nexport const BITCOIN_LOCKTIME_THRESHOLD = 500_000_000n;\n",
|
|
6
|
+
"import type { Client } from \"../clients/types.ts\";\nimport { POX5_CONTRACT_NAME } from \"./constants.ts\";\n\n/**\n * Chain-reported PoX-5 activation facts, read from the node's `/v2/pox`\n * `contract_versions[]`. Present the moment nodes run stacks-core >= 4.0.0 —\n * no hardcoded heights, works on any network.\n */\nexport type Pox5Activation = {\n\t/** Fully-qualified `pox-5` contract id (boot address differs per network). */\n\tcontractId: string;\n\t/** Bitcoin block height at which Epoch 4.0 (and pox-5) activates. */\n\tactivationBurnchainBlockHeight: number;\n\t/** First reward cycle in which pox-5 governs PoX. */\n\tfirstRewardCycleId: number;\n};\n\ntype PoxInfoResponse = {\n\tcurrent_burnchain_block_height?: number;\n\tcontract_versions?: Array<{\n\t\tcontract_id: string;\n\t\tactivation_burnchain_block_height: number;\n\t\tfirst_reward_cycle_id: number;\n\t}>;\n};\n\n/**\n * Read pox-5's activation entry from the node. Returns `undefined` when the\n * node doesn't know about pox-5 yet (pre-4.0.0 node software).\n */\nexport async function getPox5Activation(\n\tclient: Client,\n): Promise<Pox5Activation | undefined> {\n\tconst info = (await client.request(\"/v2/pox\", {\n\t\tmethod: \"GET\",\n\t})) as PoxInfoResponse;\n\tconst entry = info.contract_versions?.find((v) =>\n\t\tv.contract_id.endsWith(`.${POX5_CONTRACT_NAME}`),\n\t);\n\tif (!entry) return undefined;\n\treturn {\n\t\tcontractId: entry.contract_id,\n\t\tactivationBurnchainBlockHeight: entry.activation_burnchain_block_height,\n\t\tfirstRewardCycleId: entry.first_reward_cycle_id,\n\t};\n}\n\n/**\n * Whether pox-5 is live on the node's chain: the node software knows the\n * contract AND the burnchain has reached its activation height. One request.\n */\nexport async function isPox5Active(client: Client): Promise<boolean> {\n\tconst info = (await client.request(\"/v2/pox\", {\n\t\tmethod: \"GET\",\n\t})) as PoxInfoResponse;\n\tconst entry = info.contract_versions?.find((v) =>\n\t\tv.contract_id.endsWith(`.${POX5_CONTRACT_NAME}`),\n\t);\n\tif (!entry || typeof info.current_burnchain_block_height !== \"number\")\n\t\treturn false;\n\treturn (\n\t\tinfo.current_burnchain_block_height >=\n\t\tentry.activation_burnchain_block_height\n\t);\n}\n\n/** Throw a descriptive error unless pox-5 is active on the client's chain. */\nexport async function assertPox5Active(client: Client): Promise<void> {\n\tif (!(await isPox5Active(client))) {\n\t\tthrow new Error(\n\t\t\t\"pox-5 is not active on this chain yet (Epoch 4.0 activates at Bitcoin block 960,230 on mainnet, ~2026-07-29). \" +\n\t\t\t\t\"Check getPox5Activation(client) for this network's activation height.\",\n\t\t);\n\t}\n}\n",
|
|
7
|
+
"import { BOND_GAP_CYCLES, BOND_LENGTH_CYCLES } from \"./constants.ts\";\n\n/**\n * Pure cycle/height math, mirroring the pox-5 helper read-onlys byte-for-byte\n * (`burn-height-to-reward-cycle`, `reward-cycle-to-burn-height`,\n * `bond-period-to-reward-cycle`, `burn-height-to-distribution-index`).\n *\n * All functions anchor on chain-reported parameters — pass values from\n * `/v2/pox` (`first_burnchain_block_height`, `reward_cycle_length`,\n * `prepare_cycle_length`) and `getPox5Activation` (`firstRewardCycleId` =\n * the contract's `first-bond-period-cycle`). Nothing is hardcoded, so the\n * math is correct on mainnet, testnet, and devnet alike.\n */\nexport type PoxCycleParams = {\n\t/** `/v2/pox` `first_burnchain_block_height`. */\n\tfirstBurnchainBlockHeight: number;\n\t/** `/v2/pox` `reward_cycle_length` (mainnet 2100). */\n\trewardCycleLength: number;\n};\n\nexport type BondCycleParams = PoxCycleParams & {\n\t/** pox-5's first bond-period cycle (`getPox5Activation().firstRewardCycleId`). */\n\tfirstBondPeriodCycle: number;\n};\n\n/** Reward cycle containing `burnHeight`. Mirrors `burn-height-to-reward-cycle`. */\nexport function burnHeightToRewardCycle(\n\tburnHeight: number,\n\tparams: PoxCycleParams,\n): number {\n\tif (burnHeight < params.firstBurnchainBlockHeight) {\n\t\tthrow new Error(\n\t\t\t`burnHeight ${burnHeight} precedes first burnchain block ${params.firstBurnchainBlockHeight}`,\n\t\t);\n\t}\n\treturn Math.floor(\n\t\t(burnHeight - params.firstBurnchainBlockHeight) / params.rewardCycleLength,\n\t);\n}\n\n/** Burn height at the start of `cycle`. Mirrors `reward-cycle-to-burn-height`. */\nexport function rewardCycleToBurnHeight(\n\tcycle: number,\n\tparams: PoxCycleParams,\n): number {\n\treturn params.firstBurnchainBlockHeight + cycle * params.rewardCycleLength;\n}\n\n/** Reward cycle at which bond period `bondIndex` starts. Mirrors `bond-period-to-reward-cycle`. */\nexport function bondPeriodToRewardCycle(\n\tbondIndex: number,\n\tparams: BondCycleParams,\n): number {\n\treturn params.firstBondPeriodCycle + bondIndex * BOND_GAP_CYCLES;\n}\n\n/** Burn height at which bond period `bondIndex` starts. Mirrors `bond-period-to-burn-height`. */\nexport function bondPeriodToBurnHeight(\n\tbondIndex: number,\n\tparams: BondCycleParams,\n): number {\n\treturn rewardCycleToBurnHeight(\n\t\tbondPeriodToRewardCycle(bondIndex, params),\n\t\tparams,\n\t);\n}\n\n/** First reward cycle in which bond `bondIndex`'s STX unlock (start + 12 cycles). */\nexport function bondUnlockCycle(\n\tbondIndex: number,\n\tparams: BondCycleParams,\n): number {\n\treturn bondPeriodToRewardCycle(bondIndex, params) + BOND_LENGTH_CYCLES;\n}\n\n/**\n * Distribution-cycle index at `burnHeight` — distribution cycles are half a\n * reward cycle long. Mirrors `burn-height-to-distribution-index`.\n */\nexport function burnHeightToDistributionIndex(\n\tburnHeight: number,\n\tparams: PoxCycleParams,\n): number {\n\treturn Math.floor(\n\t\t(burnHeight - params.firstBurnchainBlockHeight) /\n\t\t\tMath.floor(params.rewardCycleLength / 2),\n\t);\n}\n\n/**\n * Whether `burnHeight` falls in a cycle's prepare phase (the final\n * `prepareCycleLength` blocks). pox-5 rejects `unstake-sbtc` and\n * `announce-l1-early-exit` during a prepare phase.\n */\nexport function isInPreparePhase(\n\tburnHeight: number,\n\tparams: PoxCycleParams & { prepareCycleLength: number },\n): boolean {\n\tconst offset =\n\t\t(burnHeight - params.firstBurnchainBlockHeight) % params.rewardCycleLength;\n\treturn offset >= params.rewardCycleLength - params.prepareCycleLength;\n}\n\nexport type BondPhase = \"too-early\" | \"open\" | \"locked\" | \"unlocked\";\n\n/**\n * Coarse lifecycle phase of bond `bondIndex` at `burnHeight`: `too-early`\n * (before the bond's start is registerable), `open`/`locked` while active,\n * `unlocked` after 12 cycles.\n */\nexport function bondPhaseAtHeight(\n\tbondIndex: number,\n\tburnHeight: number,\n\tparams: BondCycleParams,\n): BondPhase {\n\tconst cycle = burnHeightToRewardCycle(burnHeight, params);\n\tconst start = bondPeriodToRewardCycle(bondIndex, params);\n\tconst unlock = bondUnlockCycle(bondIndex, params);\n\tif (cycle < start - BOND_GAP_CYCLES) return \"too-early\";\n\tif (cycle < start) return \"open\";\n\tif (cycle < unlock) return \"locked\";\n\treturn \"unlocked\";\n}\n",
|
|
8
|
+
"import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { bech32 } from \"@scure/base\";\nimport { BITCOIN_NETWORK_PARAMS } from \"../bitcoin/address.ts\";\nimport type { BitcoinNetwork } from \"../bitcoin/constants.ts\";\nimport { serializeCVBytes } from \"../clarity/serialize.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport { concatBytes, hexToBytes } from \"../utils/encoding.ts\";\nimport { BITCOIN_LOCKTIME_THRESHOLD, C_SCRIPT_NUM_MAX } from \"./constants.ts\";\n\n/**\n * Byte-for-byte TypeScript mirrors of pox-5's Bitcoin-script helpers\n * (`serialize-c-script-num`, `push-c-script-num`, `push-script-bytes`,\n * `construct-lockup-script`, `construct-lockup-output-script`), pinned\n * against the final contract in stacks-core 4.0.0. The contract validates a\n * staker's L1 lockup output against exactly these bytes, so any divergence\n * means a rejected registration — the read-onlys on-chain double as a\n * cross-check oracle for these functions.\n */\n\n/**\n * Minimal little-endian ScriptNum encoding of a non-negative integer\n * (`0` → empty; a `0x00` sign byte is appended when the top byte's high bit\n * is set). Mirrors `serialize-c-script-num`, including its 2^39 ceiling.\n */\nexport function serializeCScriptNum(n: number | bigint): Uint8Array {\n\tconst big = typeof n === \"bigint\" ? n : BigInt(n);\n\tif (big < 0n) throw new Error(\"serializeCScriptNum: negative value\");\n\tif (big >= C_SCRIPT_NUM_MAX) {\n\t\tthrow new Error(\n\t\t\t\"serializeCScriptNum: n >= 2^39 (contract rejects with ERR_INVALID_UNLOCK_HEIGHT)\",\n\t\t);\n\t}\n\tif (big === 0n) return new Uint8Array(0);\n\tconst out: number[] = [];\n\tlet v = big;\n\twhile (v > 0n) {\n\t\tout.push(Number(v & 0xffn));\n\t\tv >>= 8n;\n\t}\n\tif ((out[out.length - 1] as number) & 0x80) out.push(0x00);\n\treturn Uint8Array.from(out);\n}\n\n/**\n * Push arbitrary bytes onto a Bitcoin script: direct length byte under 76,\n * `OP_PUSHDATA1` under 256, `OP_PUSHDATA2` otherwise. Mirrors\n * `push-script-bytes`.\n */\nexport function pushScriptBytes(bytes: Uint8Array): Uint8Array {\n\tconst len = bytes.length;\n\tif (len > 0xffff)\n\t\tthrow new Error(`pushScriptBytes: payload too large (${len} > 65535)`);\n\tlet prefix: Uint8Array;\n\tif (len < 76) prefix = Uint8Array.of(len);\n\telse if (len < 256) prefix = Uint8Array.of(0x4c, len);\n\telse prefix = Uint8Array.of(0x4d, len & 0xff, len >> 8);\n\treturn concatBytes(prefix, bytes);\n}\n\n/**\n * Push a numeric script value: `OP_0` for zero, the single-byte ops\n * `OP_1`..`OP_16` for 1–16, else a minimal ScriptNum push. Mirrors\n * `push-c-script-num`.\n */\nexport function pushCScriptNum(n: number | bigint): Uint8Array {\n\tconst big = typeof n === \"bigint\" ? n : BigInt(n);\n\tif (big === 0n) return Uint8Array.of(0x00);\n\tif (big >= 1n && big <= 16n) return Uint8Array.of(0x50 + Number(big));\n\treturn pushScriptBytes(serializeCScriptNum(big));\n}\n\n/** `to-consensus-buff?` of a principal — the staker identity the script commits to. */\nexport function stakerConsensusBuff(stxAddress: string): Uint8Array {\n\treturn serializeCVBytes(Cl.principal(stxAddress));\n}\n\n/**\n * The 32-byte witness item the early-exit branch must reveal:\n * `sha256(to-consensus-buff? staker)`. The script stores `sha256` of THIS,\n * so revealing it proves which staker the exit is for.\n */\nexport function stakerPreimage(stxAddress: string): Uint8Array {\n\treturn sha256(stakerConsensusBuff(stxAddress));\n}\n\nexport type BuildLockupScriptOptions = {\n\t/** Staker principal (standard or contract address). */\n\tstxAddress: string;\n\t/** Burn height at which the CLTV branch becomes spendable. */\n\tunlockBurnHeight: number | bigint;\n\t/** Staker-signature subscript, run last in BOTH branches. */\n\tstakerUnlockBytes: Uint8Array | string;\n\t/** Per-bond early-unlock subscript (from `protocol-bonds.early-unlock-bytes`). */\n\tearlyUnlockBytes: Uint8Array | string;\n};\n\nfunction toBytes(input: Uint8Array | string): Uint8Array {\n\treturn typeof input === \"string\" ? hexToBytes(input) : input;\n}\n\n/**\n * The L1 lockup witness script. Mirrors `construct-lockup-script`:\n *\n * ```\n * OP_IF\n * <unlockBurnHeight> OP_CHECKLOCKTIMEVERIFY\n * OP_ELSE\n * OP_SIZE <32> OP_EQUALVERIFY OP_SHA256\n * <sha256(sha256(consensus-buff(staker)))> OP_EQUALVERIFY\n * <earlyUnlockBytes>\n * OP_ENDIF\n * OP_VERIFY\n * <stakerUnlockBytes>\n * ```\n */\nexport function buildLockupScript(opts: BuildLockupScriptOptions): Uint8Array {\n\tconst height = BigInt(opts.unlockBurnHeight);\n\tif (height >= BITCOIN_LOCKTIME_THRESHOLD) {\n\t\tthrow new Error(\n\t\t\t\"unlockBurnHeight >= 500,000,000 would be read by Bitcoin as a timestamp (contract rejects it)\",\n\t\t);\n\t}\n\tconst stakerHash = sha256(stakerPreimage(opts.stxAddress));\n\treturn concatBytes(\n\t\tUint8Array.of(0x63), // OP_IF\n\t\tpushCScriptNum(height),\n\t\tUint8Array.of(0xb1, 0x67), // OP_CHECKLOCKTIMEVERIFY, OP_ELSE\n\t\t// OP_SIZE, <0x20>, OP_EQUALVERIFY, OP_SHA256, OP_PUSHBYTES_32\n\t\thexToBytes(\"82012088a820\"),\n\t\tstakerHash,\n\t\tUint8Array.of(0x88), // OP_EQUALVERIFY\n\t\ttoBytes(opts.earlyUnlockBytes),\n\t\tUint8Array.of(0x68, 0x69), // OP_ENDIF, OP_VERIFY\n\t\ttoBytes(opts.stakerUnlockBytes),\n\t);\n}\n\n/**\n * P2WSH `scriptPubKey` for a lockup script: `0x0020 || sha256(script)`.\n * Mirrors `construct-lockup-output-script`.\n */\nexport function buildLockupOutputScript(\n\topts: BuildLockupScriptOptions,\n): Uint8Array {\n\treturn concatBytes(\n\t\tUint8Array.of(0x00, 0x20),\n\t\tsha256(buildLockupScript(opts)),\n\t);\n}\n\n/** The bech32 P2WSH address a staker sends their L1 BTC lockup to. */\nexport function buildLockupAddress(\n\topts: BuildLockupScriptOptions,\n\tnetwork: BitcoinNetwork = \"mainnet\",\n): string {\n\tconst hash = sha256(buildLockupScript(opts));\n\treturn bech32.encode(BITCOIN_NETWORK_PARAMS[network].hrp, [\n\t\t0,\n\t\t...bech32.toWords(hash),\n\t]);\n}\n\n/**\n * The default staker subscript: `<pubkey> OP_CHECKSIG` — spendable by one\n * key. Any script tail is valid as far as the contract is concerned; this is\n * the common case.\n */\nexport function buildDefaultStakerUnlockBytes(\n\tpublicKey: Uint8Array | string,\n): Uint8Array {\n\tconst pubkey = toBytes(publicKey);\n\tif (pubkey.length !== 33)\n\t\tthrow new Error(`Expected 33-byte compressed pubkey, got ${pubkey.length}`);\n\treturn concatBytes(pushScriptBytes(pubkey), Uint8Array.of(0xac)); // OP_CHECKSIG\n}\n",
|
|
9
|
+
"import { secp256k1 } from \"@noble/curves/secp256k1.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport type { LocalAccount } from \"../accounts/types.ts\";\nimport { serializeCVBytes } from \"../clarity/serialize.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport { bytesToHex, concatBytes, hexToBytes } from \"../utils/encoding.ts\";\nimport { POX5_SIGNER_DOMAIN } from \"./constants.ts\";\n\n/**\n * PoX-5 signer-key grants: SIP-018 structured-data signatures authorizing a\n * signer-manager contract to use a signer key. Mirrors\n * `pox-5.get-signer-grant-message-hash` — domain `pox-5-signer/1.0.0`,\n * message `{ topic: \"grant-authorization\", signer-manager, auth-id }`.\n */\nexport type SignerGrantOptions = {\n\t/** The signer-manager contract principal being authorized. */\n\tsignerManager: string;\n\t/** Replay-protection id, chosen by the signer. */\n\tauthId: bigint | number;\n\t/** Stacks chain id (`mainnet.id` / `testnet.id`). */\n\tchainId: number;\n};\n\nconst SIP018_PREFIX = hexToBytes(\"534950303138\"); // \"SIP018\"\n\n/**\n * The 32-byte hash a signer signs to grant their key — byte-identical to the\n * contract's `get-signer-grant-message-hash` read-only (which doubles as an\n * on-chain cross-check).\n */\nexport function computeSignerGrantHash(opts: SignerGrantOptions): Uint8Array {\n\tconst domain = serializeCVBytes(\n\t\tCl.tuple({\n\t\t\tname: Cl.stringAscii(POX5_SIGNER_DOMAIN.name),\n\t\t\tversion: Cl.stringAscii(POX5_SIGNER_DOMAIN.version),\n\t\t\t\"chain-id\": Cl.uint(opts.chainId),\n\t\t}),\n\t);\n\tconst message = serializeCVBytes(\n\t\tCl.tuple({\n\t\t\ttopic: Cl.stringAscii(\"grant-authorization\"),\n\t\t\t\"signer-manager\": Cl.principal(opts.signerManager),\n\t\t\t\"auth-id\": Cl.uint(opts.authId),\n\t\t}),\n\t);\n\treturn sha256(concatBytes(SIP018_PREFIX, sha256(domain), sha256(message)));\n}\n\n/**\n * Sign a signer-key grant. Returns the 65-byte recoverable signature in RSV\n * order (recovery byte last), hex — the layout `grant-signer-key`'s\n * `signer-sig (buff 65)` expects.\n */\nexport async function signSignerGrant(\n\taccount: LocalAccount,\n\topts: SignerGrantOptions,\n): Promise<string> {\n\tconst vrs = await account.sign(computeSignerGrantHash(opts));\n\tif (vrs.length !== 65)\n\t\tthrow new Error(\n\t\t\t`Expected 65-byte recoverable signature, got ${vrs.length}`,\n\t\t);\n\t// account.sign returns VRS; the contract wants RSV.\n\treturn bytesToHex(concatBytes(vrs.slice(1), vrs.slice(0, 1)));\n}\n\n/**\n * Verify a signer-key grant signature locally: recover the pubkey from the\n * RSV signature over the grant hash and compare. Returns `false` for\n * malformed input rather than throwing.\n */\nexport function verifySignerGrant(\n\topts: SignerGrantOptions & {\n\t\tpublicKey: Uint8Array | string;\n\t\tsignature: Uint8Array | string;\n\t},\n): boolean {\n\ttry {\n\t\tconst sig =\n\t\t\ttypeof opts.signature === \"string\"\n\t\t\t\t? hexToBytes(opts.signature)\n\t\t\t\t: opts.signature;\n\t\tif (sig.length !== 65) return false;\n\t\tconst pubkey =\n\t\t\ttypeof opts.publicKey === \"string\"\n\t\t\t\t? hexToBytes(opts.publicKey)\n\t\t\t\t: opts.publicKey;\n\t\tconst hash = computeSignerGrantHash(opts);\n\t\tconst recovered = secp256k1.Signature.fromBytes(sig.slice(0, 64))\n\t\t\t.addRecoveryBit(sig[64] as number)\n\t\t\t.recoverPublicKey(hash)\n\t\t\t.toBytes(true);\n\t\treturn bytesToHex(recovered) === bytesToHex(pubkey);\n\t} catch {\n\t\treturn false;\n\t}\n}\n",
|
|
10
|
+
"import { readContract } from \"../actions/public/readContract.ts\";\nimport {\n\ttype CallContractParams,\n\tcallContract,\n} from \"../actions/wallet/callContract.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\nimport { POX5_CONTRACT_NAME } from \"./constants.ts\";\n\n/**\n * PoX-5 contract calls and reads, pinned against the final contract in\n * stacks-core 4.0.0. Wallet actions route through `callContract`, so they\n * inherit fee tiers, nonce management, and typed broadcast errors; pair the\n * returned txid with `waitForTransactionReceipt` to await inclusion.\n *\n * Note: pox-5 uses `contract-caller`/`tx-sender` directly (there is no\n * `allow-contract-caller` indirection like pox-4). Amount/lock safety is\n * expressed with the new Epoch 4.0 `Staking`/`Pox` post-conditions — pass\n * them via `postConditions` on any of these actions.\n */\n\n/** Resolve the boot `pox-5` contract id for the client's chain. */\nexport function pox5ContractId(client: Client): string {\n\tconst boot = client.chain?.bootAddress;\n\tif (!boot) throw new Error(\"Client must have a chain with a bootAddress\");\n\treturn `${boot}.${POX5_CONTRACT_NAME}`;\n}\n\ntype TxOptions = Pick<\n\tCallContractParams,\n\t\"fee\" | \"nonce\" | \"postConditions\" | \"postConditionMode\"\n>;\n\nfunction call(\n\tclient: Client,\n\tfunctionName: string,\n\tfunctionArgs: ClarityValue[],\n\toptions: TxOptions = {},\n): Promise<string> {\n\treturn callContract(client, {\n\t\tcontract: pox5ContractId(client),\n\t\tfunctionName,\n\t\tfunctionArgs,\n\t\t...options,\n\t});\n}\n\nfunction read(\n\tclient: Client,\n\tfunctionName: string,\n\tfunctionArgs: ClarityValue[] = [],\n): Promise<ClarityValue> {\n\tconst [address, name] = pox5ContractId(client).split(\".\") as [string, string];\n\treturn readContract(client, {\n\t\tcontract: `${address}.${name}`,\n\t\tfunctionName,\n\t\targs: functionArgs,\n\t});\n}\n\n// ---------------------------------------------------------------------------\n// L1 BTC lockup proof shape (register-for-bond's ok-branch outputs)\n// ---------------------------------------------------------------------------\n\n/**\n * One proven L1 timelock output — a Bitcoin SPV inclusion proof of the lockup\n * tx plus which output is the lockup. `@secondlayer/stacks/bitcoin`'s\n * `buildTxProof` produces the proof fields.\n */\nexport type L1LockupOutput = {\n\t/** Burn height of the Bitcoin block containing the lockup tx. */\n\theight: IntegerType;\n\t/** Raw Bitcoin tx (witness-stripped), hex or bytes. */\n\ttx: Uint8Array | string;\n\toutputIndex: IntegerType;\n\t/** 80-byte Bitcoin block header. */\n\theader: Uint8Array | string;\n\t/** Merkle siblings, leaf→root (max 14). */\n\tleafHashes: Array<Uint8Array | string>;\n\ttxCount: IntegerType;\n\ttxIndex: IntegerType;\n\t/** Output value in sats. */\n\tamount: IntegerType;\n\tunlockBurnHeight: IntegerType;\n};\n\n/** BTC side of a bond registration: proven L1 lockups, or an sBTC amount. */\nexport type BtcLockup =\n\t| { l1Outputs: L1LockupOutput[]; stakerUnlockBytes: Uint8Array | string }\n\t| { sbtcSats: IntegerType };\n\nfunction bufferCV(input: Uint8Array | string): ClarityValue {\n\treturn typeof input === \"string\" ? Cl.bufferFromHex(input) : Cl.buffer(input);\n}\n\nfunction btcLockupCV(lockup: BtcLockup): ClarityValue {\n\tif (\"sbtcSats\" in lockup) return Cl.error(Cl.uint(lockup.sbtcSats));\n\treturn Cl.ok(\n\t\tCl.tuple({\n\t\t\toutputs: Cl.list(\n\t\t\t\tlockup.l1Outputs.map((o) =>\n\t\t\t\t\tCl.tuple({\n\t\t\t\t\t\theight: Cl.uint(o.height),\n\t\t\t\t\t\ttx: bufferCV(o.tx),\n\t\t\t\t\t\t\"output-index\": Cl.uint(o.outputIndex),\n\t\t\t\t\t\theader: bufferCV(o.header),\n\t\t\t\t\t\t\"leaf-hashes\": Cl.list(o.leafHashes.map(bufferCV)),\n\t\t\t\t\t\t\"tx-count\": Cl.uint(o.txCount),\n\t\t\t\t\t\t\"tx-index\": Cl.uint(o.txIndex),\n\t\t\t\t\t\tamount: Cl.uint(o.amount),\n\t\t\t\t\t\t\"unlock-burn-height\": Cl.uint(o.unlockBurnHeight),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t\t\t\"staker-unlock-bytes\": bufferCV(lockup.stakerUnlockBytes),\n\t\t}),\n\t);\n}\n\nfunction optionalBuffer(input?: Uint8Array | string): ClarityValue {\n\treturn input === undefined ? Cl.none() : Cl.some(bufferCV(input));\n}\n\n// ---------------------------------------------------------------------------\n// Wallet actions (broadcast a pox-5 contract call, return the txid)\n// ---------------------------------------------------------------------------\n\nexport type SetupBondParams = TxOptions & {\n\tbondIndex: IntegerType;\n\t/** Target yield rate, basis points. */\n\ttargetRate: IntegerType;\n\t/** µSTX per 100 sats (BTCUSD / STXUSD representation). */\n\tstxValueRatio: IntegerType;\n\t/** Minimum locked STX relative to BTC, basis points. */\n\tminUstxRatio: IntegerType;\n\t/** Early-unlock subscript for this bond's L1 lockup scripts (max 683B). */\n\tearlyUnlockBytes: Uint8Array | string;\n\tallowlist: Array<{ staker: string; maxSats: IntegerType }>;\n};\n\n/** `setup-bond` — bond-admin only. */\nexport function setupBond(\n\tclient: Client,\n\tparams: SetupBondParams,\n): Promise<string> {\n\tconst {\n\t\tbondIndex,\n\t\ttargetRate,\n\t\tstxValueRatio,\n\t\tminUstxRatio,\n\t\tearlyUnlockBytes,\n\t\tallowlist,\n\t\t...tx\n\t} = params;\n\treturn call(\n\t\tclient,\n\t\t\"setup-bond\",\n\t\t[\n\t\t\tCl.uint(bondIndex),\n\t\t\tCl.uint(targetRate),\n\t\t\tCl.uint(stxValueRatio),\n\t\t\tCl.uint(minUstxRatio),\n\t\t\tbufferCV(earlyUnlockBytes),\n\t\t\tCl.list(\n\t\t\t\tallowlist.map((a) =>\n\t\t\t\t\tCl.tuple({\n\t\t\t\t\t\tstaker: Cl.principal(a.staker),\n\t\t\t\t\t\t\"max-sats\": Cl.uint(a.maxSats),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t\t],\n\t\ttx,\n\t);\n}\n\nexport type RegisterForBondParams = TxOptions & {\n\tbondIndex: IntegerType;\n\t/** Signer-manager contract principal. */\n\tsignerManager: string;\n\tamountUstx: IntegerType;\n\tbtcLockup: BtcLockup;\n\tsignerCalldata?: Uint8Array | string;\n};\n\n/** `register-for-bond` — join a bond with proven L1 lockups or sBTC. */\nexport function registerForBond(\n\tclient: Client,\n\tparams: RegisterForBondParams,\n): Promise<string> {\n\tconst {\n\t\tbondIndex,\n\t\tsignerManager,\n\t\tamountUstx,\n\t\tbtcLockup,\n\t\tsignerCalldata,\n\t\t...tx\n\t} = params;\n\treturn call(\n\t\tclient,\n\t\t\"register-for-bond\",\n\t\t[\n\t\t\tCl.uint(bondIndex),\n\t\t\tCl.principal(signerManager),\n\t\t\tCl.uint(amountUstx),\n\t\t\tbtcLockupCV(btcLockup),\n\t\t\toptionalBuffer(signerCalldata),\n\t\t],\n\t\ttx,\n\t);\n}\n\nexport type UpdateBondRegistrationParams = TxOptions & {\n\tsignerManager: string;\n\toldSignerManager: string;\n\tsignerCalldata?: Uint8Array | string;\n};\n\n/** `update-bond-registration` — switch signer-managers mid-bond. */\nexport function updateBondRegistration(\n\tclient: Client,\n\tparams: UpdateBondRegistrationParams,\n): Promise<string> {\n\tconst { signerManager, oldSignerManager, signerCalldata, ...tx } = params;\n\treturn call(\n\t\tclient,\n\t\t\"update-bond-registration\",\n\t\t[\n\t\t\tCl.principal(signerManager),\n\t\t\tCl.principal(oldSignerManager),\n\t\t\toptionalBuffer(signerCalldata),\n\t\t],\n\t\ttx,\n\t);\n}\n\nexport type StakeParams = TxOptions & {\n\tsignerManager: string;\n\tamountUstx: IntegerType;\n\tnumCycles: IntegerType;\n\tstartBurnHeight: IntegerType;\n\tsignerCalldata?: Uint8Array | string;\n};\n\n/** `stake` — STX-only staking. */\nexport function stake(client: Client, params: StakeParams): Promise<string> {\n\tconst {\n\t\tsignerManager,\n\t\tamountUstx,\n\t\tnumCycles,\n\t\tstartBurnHeight,\n\t\tsignerCalldata,\n\t\t...tx\n\t} = params;\n\treturn call(\n\t\tclient,\n\t\t\"stake\",\n\t\t[\n\t\t\tCl.principal(signerManager),\n\t\t\tCl.uint(amountUstx),\n\t\t\tCl.uint(numCycles),\n\t\t\tCl.uint(startBurnHeight),\n\t\t\toptionalBuffer(signerCalldata),\n\t\t],\n\t\ttx,\n\t);\n}\n\nexport type StakeUpdateParams = TxOptions & {\n\tsignerManager: string;\n\toldSignerManager: string;\n\tcyclesToExtend: IntegerType;\n\tamountIncrease: IntegerType;\n\tsignerCalldata?: Uint8Array | string;\n};\n\n/** `stake-update` — extend and/or increase an STX-only position. */\nexport function stakeUpdate(\n\tclient: Client,\n\tparams: StakeUpdateParams,\n): Promise<string> {\n\tconst {\n\t\tsignerManager,\n\t\toldSignerManager,\n\t\tcyclesToExtend,\n\t\tamountIncrease,\n\t\tsignerCalldata,\n\t\t...tx\n\t} = params;\n\treturn call(\n\t\tclient,\n\t\t\"stake-update\",\n\t\t[\n\t\t\tCl.principal(signerManager),\n\t\t\tCl.principal(oldSignerManager),\n\t\t\tCl.uint(cyclesToExtend),\n\t\t\tCl.uint(amountIncrease),\n\t\t\toptionalBuffer(signerCalldata),\n\t\t],\n\t\ttx,\n\t);\n}\n\nexport type UnstakeParams = TxOptions & { oldSignerManager: string };\n\n/** `unstake` — wind down an STX-only position at the next cycle. */\nexport function unstake(\n\tclient: Client,\n\tparams: UnstakeParams,\n): Promise<string> {\n\tconst { oldSignerManager, ...tx } = params;\n\treturn call(client, \"unstake\", [Cl.principal(oldSignerManager)], tx);\n}\n\nexport type UnstakeSbtcParams = TxOptions & {\n\tsignerManager: string;\n\tamountSats: IntegerType;\n};\n\n/** `unstake-sbtc` — withdraw custodied sBTC from a bond (rejected in prepare phase). */\nexport function unstakeSbtc(\n\tclient: Client,\n\tparams: UnstakeSbtcParams,\n): Promise<string> {\n\tconst { signerManager, amountSats, ...tx } = params;\n\treturn call(\n\t\tclient,\n\t\t\"unstake-sbtc\",\n\t\t[Cl.principal(signerManager), Cl.uint(amountSats)],\n\t\ttx,\n\t);\n}\n\nexport type AnnounceL1EarlyExitParams = TxOptions & {\n\tstaker: string;\n\toldSignerManager: string;\n};\n\n/** `announce-l1-early-exit` — staker-callable since 4.0.0 (rejected in prepare phase). */\nexport function announceL1EarlyExit(\n\tclient: Client,\n\tparams: AnnounceL1EarlyExitParams,\n): Promise<string> {\n\tconst { staker, oldSignerManager, ...tx } = params;\n\treturn call(\n\t\tclient,\n\t\t\"announce-l1-early-exit\",\n\t\t[Cl.principal(staker), Cl.principal(oldSignerManager)],\n\t\ttx,\n\t);\n}\n\nexport type CalculateRewardsParams = TxOptions & {\n\tbondPeriods: IntegerType[];\n};\n\n/** `calculate-rewards` — settle the reward accounting for up to 6 bond periods. */\nexport function calculateRewards(\n\tclient: Client,\n\tparams: CalculateRewardsParams,\n): Promise<string> {\n\tconst { bondPeriods, ...tx } = params;\n\treturn call(\n\t\tclient,\n\t\t\"calculate-rewards\",\n\t\t[Cl.list(bondPeriods.map((p) => Cl.uint(p)))],\n\t\ttx,\n\t);\n}\n\nexport type ClaimRewardsParams = TxOptions & {\n\tbondPeriods: IntegerType[];\n\trewardCycle: IntegerType;\n};\n\n/** `claim-rewards` — signer-manager claims accrued rewards for a cycle. */\nexport function claimRewards(\n\tclient: Client,\n\tparams: ClaimRewardsParams,\n): Promise<string> {\n\tconst { bondPeriods, rewardCycle, ...tx } = params;\n\treturn call(\n\t\tclient,\n\t\t\"claim-rewards\",\n\t\t[Cl.list(bondPeriods.map((p) => Cl.uint(p))), Cl.uint(rewardCycle)],\n\t\ttx,\n\t);\n}\n\nexport type ClaimStakerRewardsForSignerParams = TxOptions & {\n\tstaker: string;\n\trewardCycle: IntegerType;\n\tbondIndex?: IntegerType;\n};\n\n/** `claim-staker-rewards-for-signer`. */\nexport function claimStakerRewardsForSigner(\n\tclient: Client,\n\tparams: ClaimStakerRewardsForSignerParams,\n): Promise<string> {\n\tconst { staker, rewardCycle, bondIndex, ...tx } = params;\n\treturn call(\n\t\tclient,\n\t\t\"claim-staker-rewards-for-signer\",\n\t\t[\n\t\t\tCl.principal(staker),\n\t\t\tCl.uint(rewardCycle),\n\t\t\tbondIndex === undefined ? Cl.none() : Cl.some(Cl.uint(bondIndex)),\n\t\t],\n\t\ttx,\n\t);\n}\n\nexport type GrantSignerKeyParams = TxOptions & {\n\t/** 33-byte compressed signer key. */\n\tsignerKey: Uint8Array | string;\n\tsignerManager: string;\n\tauthId: IntegerType;\n\t/** 65-byte RSV signature from `signSignerGrant`. */\n\tsignerSig: Uint8Array | string;\n};\n\n/** `grant-signer-key` — callable by the signer-manager contract itself. */\nexport function grantSignerKey(\n\tclient: Client,\n\tparams: GrantSignerKeyParams,\n): Promise<string> {\n\tconst { signerKey, signerManager, authId, signerSig, ...tx } = params;\n\treturn call(\n\t\tclient,\n\t\t\"grant-signer-key\",\n\t\t[\n\t\t\tbufferCV(signerKey),\n\t\t\tCl.principal(signerManager),\n\t\t\tCl.uint(authId),\n\t\t\tbufferCV(signerSig),\n\t\t],\n\t\ttx,\n\t);\n}\n\nexport type RevokeSignerGrantParams = TxOptions & {\n\tsignerManager: string;\n\tsignerKey: Uint8Array | string;\n};\n\n/** `revoke-signer-grant`. */\nexport function revokeSignerGrant(\n\tclient: Client,\n\tparams: RevokeSignerGrantParams,\n): Promise<string> {\n\tconst { signerManager, signerKey, ...tx } = params;\n\treturn call(\n\t\tclient,\n\t\t\"revoke-signer-grant\",\n\t\t[Cl.principal(signerManager), bufferCV(signerKey)],\n\t\ttx,\n\t);\n}\n\n// ---------------------------------------------------------------------------\n// Reads (raw ClarityValues — decode with the caller's ABI knowledge)\n// ---------------------------------------------------------------------------\n\n/** `get-staker-info` — lock dimensions + signer, `none` when expired/absent. */\nexport function getStakerInfo(\n\tclient: Client,\n\tstaker: string,\n): Promise<ClarityValue> {\n\treturn read(client, \"get-staker-info\", [Cl.principal(staker)]);\n}\n\n/** `get-bond-membership` — the staker's active bond membership, if any. */\nexport function getBondMembership(\n\tclient: Client,\n\tstaker: string,\n): Promise<ClarityValue> {\n\treturn read(client, \"get-bond-membership\", [Cl.principal(staker)]);\n}\n\n/** `get-protocol-bond` — a bond's core parameters. */\nexport function getProtocolBond(\n\tclient: Client,\n\tbondIndex: IntegerType,\n): Promise<ClarityValue> {\n\treturn read(client, \"get-protocol-bond\", [Cl.uint(bondIndex)]);\n}\n\n/** `get-bond-allowance` — a staker's allowlisted max sats for a bond. */\nexport function getBondAllowance(\n\tclient: Client,\n\tbondIndex: IntegerType,\n\tstaker: string,\n): Promise<ClarityValue> {\n\treturn read(client, \"get-bond-allowance\", [\n\t\tCl.uint(bondIndex),\n\t\tCl.principal(staker),\n\t]);\n}\n\n/** `get-total-sbtc-staked-for-bond`. */\nexport function getTotalSbtcStakedForBond(\n\tclient: Client,\n\tbondIndex: IntegerType,\n): Promise<ClarityValue> {\n\treturn read(client, \"get-total-sbtc-staked-for-bond\", [Cl.uint(bondIndex)]);\n}\n\n/** `get-staker-custodied-sbtc`. */\nexport function getStakerCustodiedSbtc(\n\tclient: Client,\n\tstaker: string,\n): Promise<ClarityValue> {\n\treturn read(client, \"get-staker-custodied-sbtc\", [Cl.principal(staker)]);\n}\n\n/** `has-announced-l1-early-exit`. */\nexport function hasAnnouncedL1EarlyExit(\n\tclient: Client,\n\tbondIndex: IntegerType,\n\tstaker: string,\n): Promise<ClarityValue> {\n\treturn read(client, \"has-announced-l1-early-exit\", [\n\t\tCl.uint(bondIndex),\n\t\tCl.principal(staker),\n\t]);\n}\n\n/** `get-bond-l1-unlock-height` — half a cycle before the bond period ends. */\nexport function getBondL1UnlockHeight(\n\tclient: Client,\n\tbondIndex: IntegerType,\n): Promise<ClarityValue> {\n\treturn read(client, \"get-bond-l1-unlock-height\", [Cl.uint(bondIndex)]);\n}\n\n/** `get-signer-info`. */\nexport function getSignerInfo(\n\tclient: Client,\n\tsigner: string,\n): Promise<ClarityValue> {\n\treturn read(client, \"get-signer-info\", [Cl.principal(signer)]);\n}\n\n/** `verify-signer-key-grant` — whether a grant exists on-chain. */\nexport function verifySignerKeyGrantOnChain(\n\tclient: Client,\n\tsignerManager: string,\n\tsignerKey: Uint8Array | string,\n): Promise<ClarityValue> {\n\treturn read(client, \"verify-signer-key-grant\", [\n\t\tCl.principal(signerManager),\n\t\tbufferCV(signerKey),\n\t]);\n}\n\n/** `current-pox-reward-cycle`. */\nexport function getCurrentRewardCycle(client: Client): Promise<ClarityValue> {\n\treturn read(client, \"current-pox-reward-cycle\");\n}\n\n/** `get-first-pox-5-reward-cycle`. */\nexport function getFirstPox5RewardCycle(client: Client): Promise<ClarityValue> {\n\treturn read(client, \"get-first-pox-5-reward-cycle\");\n}\n",
|
|
11
|
+
"import { multicall } from \"../actions/public/multicall.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\nimport {\n\ttype AnnounceL1EarlyExitParams,\n\ttype CalculateRewardsParams,\n\ttype ClaimRewardsParams,\n\ttype ClaimStakerRewardsForSignerParams,\n\ttype GrantSignerKeyParams,\n\ttype RegisterForBondParams,\n\ttype RevokeSignerGrantParams,\n\ttype SetupBondParams,\n\ttype StakeParams,\n\ttype StakeUpdateParams,\n\ttype UnstakeParams,\n\ttype UnstakeSbtcParams,\n\ttype UpdateBondRegistrationParams,\n\tannounceL1EarlyExit,\n\tcalculateRewards,\n\tclaimRewards,\n\tclaimStakerRewardsForSigner,\n\tgetBondAllowance,\n\tgetBondL1UnlockHeight,\n\tgetBondMembership,\n\tgetCurrentRewardCycle,\n\tgetFirstPox5RewardCycle,\n\tgetProtocolBond,\n\tgetSignerInfo,\n\tgetStakerCustodiedSbtc,\n\tgetStakerInfo,\n\tgetTotalSbtcStakedForBond,\n\tgrantSignerKey,\n\thasAnnouncedL1EarlyExit,\n\tpox5ContractId,\n\tregisterForBond,\n\trevokeSignerGrant,\n\tsetupBond,\n\tstake,\n\tstakeUpdate,\n\tunstake,\n\tunstakeSbtc,\n\tupdateBondRegistration,\n\tverifySignerKeyGrantOnChain,\n} from \"./actions.ts\";\nimport {\n\ttype Pox5Activation,\n\tgetPox5Activation,\n\tisPox5Active,\n} from \"./activation.ts\";\n\n/**\n * A staker's whole PoX-5 position in ONE batched request: staker info, bond\n * membership, custodied sBTC, and the current cycle — the state a dashboard\n * or agent polls, without four round-trips.\n */\nexport type StakerState = {\n\tstakerInfo: ClarityValue;\n\tbondMembership: ClarityValue;\n\tcustodiedSbtc: ClarityValue;\n\tcurrentCycle: ClarityValue;\n};\n\nasync function getStakerState(\n\tclient: Client,\n\tstaker: string,\n): Promise<StakerState> {\n\tconst contract = pox5ContractId(client);\n\tconst results = await multicall(client, {\n\t\tallowFailure: false,\n\t\tcalls: [\n\t\t\t{\n\t\t\t\tcontract,\n\t\t\t\tfunctionName: \"get-staker-info\",\n\t\t\t\targs: [Cl.principal(staker)],\n\t\t\t},\n\t\t\t{\n\t\t\t\tcontract,\n\t\t\t\tfunctionName: \"get-bond-membership\",\n\t\t\t\targs: [Cl.principal(staker)],\n\t\t\t},\n\t\t\t{\n\t\t\t\tcontract,\n\t\t\t\tfunctionName: \"get-staker-custodied-sbtc\",\n\t\t\t\targs: [Cl.principal(staker)],\n\t\t\t},\n\t\t\t{ contract, functionName: \"current-pox-reward-cycle\", args: [] },\n\t\t],\n\t});\n\tconst [stakerInfo, bondMembership, custodiedSbtc, currentCycle] =\n\t\tresults as ClarityValue[];\n\treturn {\n\t\tstakerInfo: stakerInfo as ClarityValue,\n\t\tbondMembership: bondMembership as ClarityValue,\n\t\tcustodiedSbtc: custodiedSbtc as ClarityValue,\n\t\tcurrentCycle: currentCycle as ClarityValue,\n\t};\n}\n\n/** Actions provided by the pox5 extension. */\nexport type Pox5Actions = {\n\tpox5: {\n\t\t// activation\n\t\tisActive: () => Promise<boolean>;\n\t\tgetActivation: () => Promise<Pox5Activation | undefined>;\n\t\tcontractId: () => string;\n\t\t// batched state\n\t\tgetStakerState: (staker: string) => Promise<StakerState>;\n\t\t// reads\n\t\tgetStakerInfo: (staker: string) => Promise<ClarityValue>;\n\t\tgetBondMembership: (staker: string) => Promise<ClarityValue>;\n\t\tgetProtocolBond: (bondIndex: IntegerType) => Promise<ClarityValue>;\n\t\tgetBondAllowance: (\n\t\t\tbondIndex: IntegerType,\n\t\t\tstaker: string,\n\t\t) => Promise<ClarityValue>;\n\t\tgetTotalSbtcStakedForBond: (\n\t\t\tbondIndex: IntegerType,\n\t\t) => Promise<ClarityValue>;\n\t\tgetStakerCustodiedSbtc: (staker: string) => Promise<ClarityValue>;\n\t\thasAnnouncedL1EarlyExit: (\n\t\t\tbondIndex: IntegerType,\n\t\t\tstaker: string,\n\t\t) => Promise<ClarityValue>;\n\t\tgetBondL1UnlockHeight: (bondIndex: IntegerType) => Promise<ClarityValue>;\n\t\tgetSignerInfo: (signer: string) => Promise<ClarityValue>;\n\t\tverifySignerKeyGrant: (\n\t\t\tsignerManager: string,\n\t\t\tsignerKey: Uint8Array | string,\n\t\t) => Promise<ClarityValue>;\n\t\tgetCurrentRewardCycle: () => Promise<ClarityValue>;\n\t\tgetFirstRewardCycle: () => Promise<ClarityValue>;\n\t\t// wallet actions (txids; pair with waitForTransactionReceipt)\n\t\tsetupBond: (params: SetupBondParams) => Promise<string>;\n\t\tregisterForBond: (params: RegisterForBondParams) => Promise<string>;\n\t\tupdateBondRegistration: (\n\t\t\tparams: UpdateBondRegistrationParams,\n\t\t) => Promise<string>;\n\t\tstake: (params: StakeParams) => Promise<string>;\n\t\tstakeUpdate: (params: StakeUpdateParams) => Promise<string>;\n\t\tunstake: (params: UnstakeParams) => Promise<string>;\n\t\tunstakeSbtc: (params: UnstakeSbtcParams) => Promise<string>;\n\t\tannounceL1EarlyExit: (params: AnnounceL1EarlyExitParams) => Promise<string>;\n\t\tcalculateRewards: (params: CalculateRewardsParams) => Promise<string>;\n\t\tclaimRewards: (params: ClaimRewardsParams) => Promise<string>;\n\t\tclaimStakerRewardsForSigner: (\n\t\t\tparams: ClaimStakerRewardsForSignerParams,\n\t\t) => Promise<string>;\n\t\tgrantSignerKey: (params: GrantSignerKeyParams) => Promise<string>;\n\t\trevokeSignerGrant: (params: RevokeSignerGrantParams) => Promise<string>;\n\t};\n};\n\n/**\n * PoX-5 extension for the Stacks client.\n *\n * @example\n * const client = createWalletClient({ chain: mainnet, transport: http(), account })\n * .extend(pox5());\n *\n * if (await client.pox5.isActive()) {\n * const txid = await client.pox5.stake({\n * signerManager: \"SP….signer-mgr\",\n * amountUstx: 100_000_000_000n,\n * numCycles: 12,\n * startBurnHeight: 960_231,\n * fee: \"low\",\n * });\n * await client.waitForTransactionReceipt({ txid });\n * }\n */\nexport function pox5(): (client: Client) => Pox5Actions {\n\treturn (client: Client) => ({\n\t\tpox5: {\n\t\t\tisActive: () => isPox5Active(client),\n\t\t\tgetActivation: () => getPox5Activation(client),\n\t\t\tcontractId: () => pox5ContractId(client),\n\t\t\tgetStakerState: (staker) => getStakerState(client, staker),\n\t\t\tgetStakerInfo: (staker) => getStakerInfo(client, staker),\n\t\t\tgetBondMembership: (staker) => getBondMembership(client, staker),\n\t\t\tgetProtocolBond: (bondIndex) => getProtocolBond(client, bondIndex),\n\t\t\tgetBondAllowance: (bondIndex, staker) =>\n\t\t\t\tgetBondAllowance(client, bondIndex, staker),\n\t\t\tgetTotalSbtcStakedForBond: (bondIndex) =>\n\t\t\t\tgetTotalSbtcStakedForBond(client, bondIndex),\n\t\t\tgetStakerCustodiedSbtc: (staker) =>\n\t\t\t\tgetStakerCustodiedSbtc(client, staker),\n\t\t\thasAnnouncedL1EarlyExit: (bondIndex, staker) =>\n\t\t\t\thasAnnouncedL1EarlyExit(client, bondIndex, staker),\n\t\t\tgetBondL1UnlockHeight: (bondIndex) =>\n\t\t\t\tgetBondL1UnlockHeight(client, bondIndex),\n\t\t\tgetSignerInfo: (signer) => getSignerInfo(client, signer),\n\t\t\tverifySignerKeyGrant: (signerManager, signerKey) =>\n\t\t\t\tverifySignerKeyGrantOnChain(client, signerManager, signerKey),\n\t\t\tgetCurrentRewardCycle: () => getCurrentRewardCycle(client),\n\t\t\tgetFirstRewardCycle: () => getFirstPox5RewardCycle(client),\n\t\t\tsetupBond: (params) => setupBond(client, params),\n\t\t\tregisterForBond: (params) => registerForBond(client, params),\n\t\t\tupdateBondRegistration: (params) =>\n\t\t\t\tupdateBondRegistration(client, params),\n\t\t\tstake: (params) => stake(client, params),\n\t\t\tstakeUpdate: (params) => stakeUpdate(client, params),\n\t\t\tunstake: (params) => unstake(client, params),\n\t\t\tunstakeSbtc: (params) => unstakeSbtc(client, params),\n\t\t\tannounceL1EarlyExit: (params) => announceL1EarlyExit(client, params),\n\t\t\tcalculateRewards: (params) => calculateRewards(client, params),\n\t\t\tclaimRewards: (params) => claimRewards(client, params),\n\t\t\tclaimStakerRewardsForSigner: (params) =>\n\t\t\t\tclaimStakerRewardsForSigner(client, params),\n\t\t\tgrantSignerKey: (params) => grantSignerKey(client, params),\n\t\t\trevokeSignerGrant: (params) => revokeSignerGrant(client, params),\n\t\t},\n\t});\n}\n"
|
|
12
|
+
],
|
|
13
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,IAAM,qBAAqB;AAQ3B,IAAM,sCAAsC;AAG5C,IAAM,qBAAqB;AAG3B,IAAM,kBAAkB;AAGxB,IAAM,iBAAiB;AAGvB,IAAM,qBAAqB;AAAA,EACjC,MAAM;AAAA,EACN,SAAS;AACV;AAMO,IAAM,mBAAmB;AAOzB,IAAM,6BAA6B;;;ACZ1C,eAAsB,iBAAiB,CACtC,QACsC;AAAA,EACtC,MAAM,OAAQ,MAAM,OAAO,QAAQ,WAAW;AAAA,IAC7C,QAAQ;AAAA,EACT,CAAC;AAAA,EACD,MAAM,QAAQ,KAAK,mBAAmB,KAAK,CAAC,MAC3C,EAAE,YAAY,SAAS,IAAI,oBAAoB,CAChD;AAAA,EACA,IAAI,CAAC;AAAA,IAAO;AAAA,EACZ,OAAO;AAAA,IACN,YAAY,MAAM;AAAA,IAClB,gCAAgC,MAAM;AAAA,IACtC,oBAAoB,MAAM;AAAA,EAC3B;AAAA;AAOD,eA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