@secondlayer/stacks 3.3.1 → 4.1.0
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 +4 -0
- package/dist/shared/stacks-1arrcd11.js +48 -0
- package/dist/shared/stacks-1arrcd11.js.map +10 -0
- package/dist/shared/{stacks-6bgh2c9h.js → stacks-27fmgajb.js} +11 -3
- package/dist/shared/{stacks-b221qkst.cjs.map → stacks-27fmgajb.js.map} +4 -3
- package/dist/shared/{stacks-jknrzd6v.js → stacks-2evvn48s.js} +2 -2
- package/dist/shared/stacks-9mqveyjv.cjs.map +2 -2
- package/dist/shared/{stacks-8e5atbps.cjs → stacks-9qcr921s.cjs} +49 -5
- package/dist/shared/stacks-9qcr921s.cjs.map +10 -0
- package/dist/shared/{stacks-r1m1r72q.js → stacks-bw8qvqd1.js} +49 -23
- package/dist/shared/stacks-bw8qvqd1.js.map +27 -0
- package/dist/shared/stacks-enpj9krt.cjs +38 -0
- package/dist/shared/stacks-enpj9krt.cjs.map +10 -0
- package/dist/shared/{stacks-s361pmzs.cjs → stacks-fb75yew8.js} +86 -2
- package/dist/shared/{stacks-9d2d0qjc.js.map → stacks-fb75yew8.js.map} +6 -4
- package/dist/shared/{stacks-rw2xbtdv.js → stacks-gxq2pbky.js} +2 -2
- package/dist/shared/{stacks-rw2xbtdv.js.map → stacks-gxq2pbky.js.map} +1 -1
- package/dist/shared/{stacks-jx146qf1.js → stacks-hnqt5rz4.js} +27 -377
- package/dist/shared/stacks-hnqt5rz4.js.map +13 -0
- package/dist/shared/{stacks-v1hzk599.js → stacks-jpt52csy.js} +8 -10
- package/dist/shared/stacks-jpt52csy.js.map +10 -0
- package/dist/shared/{stacks-b221qkst.cjs → stacks-nyaw1z2a.cjs} +7 -2
- package/dist/shared/{stacks-6bgh2c9h.js.map → stacks-nyaw1z2a.cjs.map} +4 -3
- package/dist/shared/{stacks-bm49tsh0.js → stacks-rpqtgpyj.js} +42 -9
- package/dist/shared/stacks-rpqtgpyj.js.map +10 -0
- package/dist/shared/{stacks-g2qnr5qn.cjs → stacks-rryme9bv.cjs} +11 -364
- package/dist/shared/stacks-rryme9bv.cjs.map +13 -0
- package/dist/shared/{stacks-byyex2zk.cjs → stacks-ta1gar0b.cjs} +7 -2
- package/dist/shared/{stacks-byyex2zk.cjs.map → stacks-ta1gar0b.cjs.map} +2 -2
- package/dist/shared/{stacks-9d2d0qjc.js → stacks-tdsp5gsb.cjs} +54 -23
- package/dist/shared/{stacks-s361pmzs.cjs.map → stacks-tdsp5gsb.cjs.map} +6 -4
- package/dist/shared/stacks-vea7nde7.cjs +731 -0
- package/dist/shared/stacks-vea7nde7.cjs.map +13 -0
- package/dist/shared/stacks-w23294am.js +760 -0
- package/dist/shared/stacks-w23294am.js.map +13 -0
- package/dist/shared/{stacks-fvnxj77s.cjs → stacks-y4f7fm03.cjs} +33 -13
- package/dist/shared/{stacks-fvnxj77s.cjs.map → stacks-y4f7fm03.cjs.map} +7 -6
- package/dist/src/accounts/index.d.cts +1 -1
- package/dist/src/accounts/index.d.ts +1 -1
- package/dist/src/actions/index.d.cts +15 -11
- package/dist/src/actions/index.d.ts +15 -11
- package/dist/src/actions/index.js +21 -25
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.d.cts +29 -29
- package/dist/src/bitcoin/index.d.ts +29 -29
- package/dist/src/bitcoin/index.js +5 -6
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/bns/index.d.cts +1 -1
- package/dist/src/bns/index.d.ts +1 -1
- package/dist/src/bns/index.js +9 -10
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/clarity/index.d.cts +37 -1
- package/dist/src/clarity/index.d.ts +37 -1
- package/dist/src/clarity/index.js +14 -2
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/index.cjs.map +2 -2
- package/dist/src/index.d.cts +18 -14
- package/dist/src/index.d.ts +18 -14
- package/dist/src/index.js +22 -27
- package/dist/src/index.js.map +3 -3
- package/dist/src/postconditions/index.d.cts +66 -3
- package/dist/src/postconditions/index.d.ts +66 -3
- package/dist/src/postconditions/index.js +13 -3
- package/dist/src/postconditions/index.js.map +1 -1
- package/dist/src/pox/index.d.cts +1 -1
- package/dist/src/pox/index.d.ts +1 -1
- package/dist/src/pox/index.js +7 -9
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/pox5/index.cjs +213 -14
- package/dist/src/pox5/index.cjs.map +8 -7
- package/dist/src/pox5/index.d.cts +88 -5
- package/dist/src/pox5/index.d.ts +88 -5
- package/dist/src/pox5/index.js +222 -21
- package/dist/src/pox5/index.js.map +8 -7
- package/dist/src/sbtc/index.d.cts +1 -1
- package/dist/src/sbtc/index.d.ts +1 -1
- package/dist/src/sbtc/index.js +6 -7
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/stackingdao/index.d.cts +1 -1
- package/dist/src/stackingdao/index.d.ts +1 -1
- package/dist/src/stackingdao/index.js +7 -9
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/subscriptions/index.d.cts +1 -1
- package/dist/src/subscriptions/index.d.ts +1 -1
- package/dist/src/tools/index.cjs +494 -367
- package/dist/src/tools/index.cjs.map +11 -9
- package/dist/src/tools/index.d.cts +1 -1
- package/dist/src/tools/index.d.ts +1 -1
- package/dist/src/tools/index.js +494 -367
- package/dist/src/tools/index.js.map +11 -9
- package/dist/src/transactions/index.cjs +3 -1
- package/dist/src/transactions/index.cjs.map +1 -1
- package/dist/src/transactions/index.d.cts +16 -9
- package/dist/src/transactions/index.d.ts +16 -9
- package/dist/src/transactions/index.js +31 -27
- package/dist/src/transactions/index.js.map +1 -1
- package/package.json +2 -7
- package/dist/shared/stacks-1mpmzzyp.js +0 -85
- package/dist/shared/stacks-1mpmzzyp.js.map +0 -11
- package/dist/shared/stacks-44y18a8e.cjs +0 -28
- package/dist/shared/stacks-44y18a8e.cjs.map +0 -10
- package/dist/shared/stacks-8e5atbps.cjs.map +0 -10
- package/dist/shared/stacks-8khy9v27.cjs +0 -7
- package/dist/shared/stacks-8khy9v27.cjs.map +0 -10
- package/dist/shared/stacks-bm49tsh0.js.map +0 -10
- package/dist/shared/stacks-d6pgp4qk.cjs +0 -9
- package/dist/shared/stacks-d6pgp4qk.cjs.map +0 -9
- package/dist/shared/stacks-fh48neva.js +0 -13
- package/dist/shared/stacks-fh48neva.js.map +0 -10
- package/dist/shared/stacks-fjrpnkt3.cjs +0 -55
- package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
- package/dist/shared/stacks-g2qnr5qn.cjs.map +0 -15
- package/dist/shared/stacks-gkf9tsws.js +0 -285
- package/dist/shared/stacks-gkf9tsws.js.map +0 -10
- package/dist/shared/stacks-jx146qf1.js.map +0 -15
- package/dist/shared/stacks-qjgh6pqr.cjs +0 -258
- package/dist/shared/stacks-qjgh6pqr.cjs.map +0 -10
- package/dist/shared/stacks-r1m1r72q.js.map +0 -26
- package/dist/shared/stacks-v1hzk599.js.map +0 -10
- package/dist/shared/stacks-w8tt1fmt.js +0 -44
- package/dist/shared/stacks-w8tt1fmt.js.map +0 -10
- package/dist/shared/stacks-z53fwfcm.js +0 -3
- package/dist/shared/stacks-z53fwfcm.js.map +0 -9
- package/dist/src/x402/index.cjs +0 -65
- package/dist/src/x402/index.cjs.map +0 -11
- package/dist/src/x402/index.d.cts +0 -501
- package/dist/src/x402/index.d.ts +0 -501
- package/dist/src/x402/index.js +0 -90
- package/dist/src/x402/index.js.map +0 -11
- /package/dist/shared/{stacks-jknrzd6v.js.map → stacks-2evvn48s.js.map} +0 -0
package/dist/src/pox5/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type LocalAccount = {
|
|
|
6
6
|
publicKey: string
|
|
7
7
|
/** Raw ECDSA sign over a hash */
|
|
8
8
|
sign(hash: Uint8Array): Uint8Array
|
|
9
|
-
/** Sign a
|
|
9
|
+
/** Sign a raw UTF-8 / byte message (`sha256(bytes)`). Not SIP-018. */
|
|
10
10
|
signMessage(message: string | Uint8Array): string
|
|
11
11
|
};
|
|
12
12
|
/** Account with a user-provided signing function (sync or async). */
|
|
@@ -200,6 +200,24 @@ type Pox5Activation = {
|
|
|
200
200
|
firstRewardCycleId: number
|
|
201
201
|
};
|
|
202
202
|
/**
|
|
203
|
+
* `/v2/pox` fields a pox-5 integration actually needs. `sbtcContract` is
|
|
204
|
+
* compiled into the boot contract per network — never hardcode it.
|
|
205
|
+
*/
|
|
206
|
+
type Pox5Info = {
|
|
207
|
+
contractId?: string
|
|
208
|
+
currentBurnchainBlockHeight?: number
|
|
209
|
+
firstBurnchainBlockHeight?: number
|
|
210
|
+
/** Token principal pox-5 custodies. Read this for sBTC post-conditions. */
|
|
211
|
+
sbtcContract?: string
|
|
212
|
+
sbtcRegistryContract?: string
|
|
213
|
+
contractVersions: Array<{
|
|
214
|
+
contractId: string
|
|
215
|
+
activationBurnchainBlockHeight: number
|
|
216
|
+
firstRewardCycleId: number
|
|
217
|
+
}>
|
|
218
|
+
};
|
|
219
|
+
declare function getPoxInfo2(client: Client): Promise<Pox5Info>;
|
|
220
|
+
/**
|
|
203
221
|
* Read pox-5's activation entry from the node. Returns `undefined` when the
|
|
204
222
|
* node doesn't know about pox-5 yet (pre-4.0.0 node software).
|
|
205
223
|
*/
|
|
@@ -212,6 +230,67 @@ declare function isPox5Active(client: Client): Promise<boolean>;
|
|
|
212
230
|
/** Throw a descriptive error unless pox-5 is active on the client's chain. */
|
|
213
231
|
declare function assertPox5Active(client: Client): Promise<void>;
|
|
214
232
|
/**
|
|
233
|
+
* Numeric `(err uN)` codes from pox-5. Missing numbers were never assigned
|
|
234
|
+
* on-chain. Pair with {@link parsePox5Error} / {@link describePox5Error}.
|
|
235
|
+
*/
|
|
236
|
+
declare const Pox5ErrorCode: {
|
|
237
|
+
readonly Unauthorized: 1
|
|
238
|
+
readonly CannotSetupBondTooSoon: 2
|
|
239
|
+
readonly CannotSetupBondTooLate: 3
|
|
240
|
+
readonly BondAlreadySetup: 4
|
|
241
|
+
readonly StakerAlreadyAdded: 5
|
|
242
|
+
readonly BondNotFound: 7
|
|
243
|
+
readonly InsufficientStx: 8
|
|
244
|
+
readonly AlreadyRegistered: 9
|
|
245
|
+
readonly TooMuchSats: 10
|
|
246
|
+
readonly NotAllowlisted: 11
|
|
247
|
+
readonly SignerKeyGrantUsed: 12
|
|
248
|
+
readonly InvalidSignatureRecover: 13
|
|
249
|
+
readonly InvalidSignaturePubkey: 14
|
|
250
|
+
readonly SignerKeyGrantNotFound: 17
|
|
251
|
+
readonly AlreadyStaked: 19
|
|
252
|
+
readonly InvalidNumCycles: 20
|
|
253
|
+
readonly SignerNotFound: 23
|
|
254
|
+
readonly InvalidStartBurnHeight: 24
|
|
255
|
+
readonly UnauthorizedSignerRegistration: 26
|
|
256
|
+
readonly NotStaking: 27
|
|
257
|
+
readonly UnstakeInPreparePhase: 28
|
|
258
|
+
readonly InvalidBondPeriodOrdering: 29
|
|
259
|
+
readonly DistributionAlreadyComputed: 30
|
|
260
|
+
readonly BondNotActive: 31
|
|
261
|
+
readonly NoClaimableRewards: 32
|
|
262
|
+
readonly ActiveBondNotIncluded: 33
|
|
263
|
+
readonly NotBondParticipant: 34
|
|
264
|
+
readonly CannotAnnounceL1EarlyUnlock: 35
|
|
265
|
+
readonly InvalidOldSignerManager: 36
|
|
266
|
+
readonly InvalidUnstakeSbtcAmount: 37
|
|
267
|
+
readonly CannotUnstakeSbtc: 38
|
|
268
|
+
readonly ReadTxOutOfBounds: 39
|
|
269
|
+
readonly InvalidBtcHeader: 40
|
|
270
|
+
readonly InvalidMerkleProof: 41
|
|
271
|
+
readonly InvalidLockupScript: 42
|
|
272
|
+
readonly BondAlreadyStarted: 43
|
|
273
|
+
readonly UpdateBondSameSigner: 44
|
|
274
|
+
readonly InvalidLockupAmount: 45
|
|
275
|
+
readonly DuplicateLockupOutpoint: 46
|
|
276
|
+
readonly StakeInPreparePhase: 47
|
|
277
|
+
readonly RolloverTooEarly: 48
|
|
278
|
+
readonly ReentrantCall: 49
|
|
279
|
+
readonly L1EarlyExitAlreadyAnnounced: 50
|
|
280
|
+
readonly InsufficientReserveBalance: 51
|
|
281
|
+
readonly InvalidUnlockHeight: 52
|
|
282
|
+
readonly RewardsPaused: 53
|
|
283
|
+
};
|
|
284
|
+
type Pox5ErrorCode = (typeof Pox5ErrorCode)[keyof typeof Pox5ErrorCode];
|
|
285
|
+
declare const POX5_ERROR_NAMES: Record<Pox5ErrorCode, string>;
|
|
286
|
+
/** Extract `(err uN)` from a Clarity value or Hiro `repr` string. */
|
|
287
|
+
declare function parsePox5Error(result: ClarityValue | string | undefined): number | undefined;
|
|
288
|
+
declare function describePox5Error(code: number | bigint): {
|
|
289
|
+
code: number
|
|
290
|
+
name: string
|
|
291
|
+
description: string
|
|
292
|
+
} | undefined;
|
|
293
|
+
/**
|
|
215
294
|
* Stacks hard-fork epoch activation heights, as Bitcoin burn block heights.
|
|
216
295
|
*
|
|
217
296
|
* Epoch 4.0 carries both SIP-044 (the native Bitcoin SPV built-ins / Clarity 6)
|
|
@@ -442,7 +521,7 @@ type FeeTier = "min" | "low" | "mid" | "high";
|
|
|
442
521
|
/** Fee input accepted by wallet actions: an explicit amount or a named tier. */
|
|
443
522
|
type FeeParam = IntegerType | FeeTier;
|
|
444
523
|
type FungibleComparator = "eq" | "gt" | "gte" | "lt" | "lte";
|
|
445
|
-
type NonFungibleComparator = "sent" | "not-sent";
|
|
524
|
+
type NonFungibleComparator = "sent" | "not-sent" | "maybe-sent";
|
|
446
525
|
type StxPostCondition = {
|
|
447
526
|
type: "stx-postcondition"
|
|
448
527
|
address: string
|
|
@@ -476,6 +555,9 @@ type PoxPostCondition = {
|
|
|
476
555
|
condition: PoxComparator
|
|
477
556
|
};
|
|
478
557
|
type PostCondition = StxPostCondition | FtPostCondition | NftPostCondition | StakingPostCondition | PoxPostCondition;
|
|
558
|
+
/** Serialized PC hex is accepted anywhere a `PostCondition` object is. */
|
|
559
|
+
type PostConditionInput = PostCondition | string;
|
|
560
|
+
type PostConditionMode = "allow" | "deny" | "originator";
|
|
479
561
|
/**
|
|
480
562
|
* Mapped read-return types for the pox-5 contract — the JS shapes
|
|
481
563
|
* `getContract` produces from the ABI (camelCase keys, `uint` → `bigint`,
|
|
@@ -523,8 +605,8 @@ declare function pox5ContractId(client: Client): string;
|
|
|
523
605
|
type TxOptions = {
|
|
524
606
|
fee?: FeeParam
|
|
525
607
|
nonce?: IntegerType
|
|
526
|
-
postConditions?:
|
|
527
|
-
postConditionMode?:
|
|
608
|
+
postConditions?: PostConditionInput[]
|
|
609
|
+
postConditionMode?: PostConditionMode
|
|
528
610
|
};
|
|
529
611
|
/**
|
|
530
612
|
* One proven L1 timelock output — a Bitcoin SPV inclusion proof of the lockup
|
|
@@ -647,6 +729,7 @@ type Pox5Actions = {
|
|
|
647
729
|
pox5: {
|
|
648
730
|
isActive: () => Promise<boolean>
|
|
649
731
|
getActivation: () => Promise<Pox5Activation | undefined>
|
|
732
|
+
getPoxInfo: () => Promise<Pox5Info>
|
|
650
733
|
contractId: () => string
|
|
651
734
|
getStakerState: (staker: string) => Promise<StakerState>
|
|
652
735
|
getStakerInfo: (staker: string) => Promise<StakerInfo>
|
|
@@ -1593,4 +1676,4 @@ declare const POX5_ABI: {
|
|
|
1593
1676
|
}
|
|
1594
1677
|
}]
|
|
1595
1678
|
};
|
|
1596
|
-
export { verifySignerGrant, stakerPreimage, stakerConsensusBuff, signSignerGrant, serializeCScriptNum, rewardCycleToBurnHeight, pushScriptBytes, pushCScriptNum, pox5ContractId, pox5, isPox5Active, isInPreparePhase, getPox5Activation, computeSignerGrantHash, burnHeightToRewardCycle, burnHeightToDistributionIndex, buildLockupScript, buildLockupOutputScript, buildLockupAddress, buildDefaultStakerUnlockBytes, bondUnlockCycle, bondPhaseAtHeight, bondPeriodToRewardCycle, bondPeriodToBurnHeight, assertPox5Active, UpdateBondRegistrationParams, UnstakeSbtcParams, UnstakeParams, StakerState, StakeUpdateParams, StakeParams, SignerGrantOptions, SetupBondParams, RevokeSignerGrantParams, RegisterForBondParams, PoxCycleParams, Pox5EventTopic, Pox5Activation, Pox5Actions, POX5_SIGNER_DOMAIN, POX5_EVENT_TOPICS, POX5_CONTRACT_NAME, POX5_CONTRACT_ID_MAINNET, POX5_ACTIVATION_BURN_HEIGHT_MAINNET, POX5_ABI, MAX_NUM_CYCLES, L1LockupOutput, GrantSignerKeyParams, ClaimStakerRewardsForSignerParams, ClaimRewardsParams, CalculateRewardsParams, C_SCRIPT_NUM_MAX, BuildLockupScriptOptions, BtcLockup, BondPhase, BondCycleParams, BOND_LENGTH_CYCLES, BOND_GAP_CYCLES, BITCOIN_LOCKTIME_THRESHOLD, AnnounceL1EarlyExitParams };
|
|
1679
|
+
export { verifySignerGrant, stakerPreimage, stakerConsensusBuff, signSignerGrant, serializeCScriptNum, rewardCycleToBurnHeight, pushScriptBytes, pushCScriptNum, pox5ContractId, pox5, parsePox5Error, isPox5Active, isInPreparePhase, getPoxInfo2 as getPoxInfo, getPox5Activation, describePox5Error, computeSignerGrantHash, burnHeightToRewardCycle, burnHeightToDistributionIndex, buildLockupScript, buildLockupOutputScript, buildLockupAddress, buildDefaultStakerUnlockBytes, bondUnlockCycle, bondPhaseAtHeight, bondPeriodToRewardCycle, bondPeriodToBurnHeight, assertPox5Active, UpdateBondRegistrationParams, UnstakeSbtcParams, UnstakeParams, StakerState, StakeUpdateParams, StakeParams, SignerGrantOptions, SetupBondParams, RevokeSignerGrantParams, RegisterForBondParams, PoxCycleParams, Pox5Info, Pox5EventTopic, Pox5ErrorCode, Pox5Activation, Pox5Actions, POX5_SIGNER_DOMAIN, POX5_EVENT_TOPICS, POX5_ERROR_NAMES, POX5_CONTRACT_NAME, POX5_CONTRACT_ID_MAINNET, POX5_ACTIVATION_BURN_HEIGHT_MAINNET, POX5_ABI, MAX_NUM_CYCLES, L1LockupOutput, GrantSignerKeyParams, ClaimStakerRewardsForSignerParams, ClaimRewardsParams, CalculateRewardsParams, C_SCRIPT_NUM_MAX, BuildLockupScriptOptions, BtcLockup, BondPhase, BondCycleParams, BOND_LENGTH_CYCLES, BOND_GAP_CYCLES, BITCOIN_LOCKTIME_THRESHOLD, AnnounceL1EarlyExitParams };
|
package/dist/src/pox5/index.js
CHANGED
|
@@ -9,17 +9,19 @@ import {
|
|
|
9
9
|
} from "../../shared/stacks-5nmz5ad9.js";
|
|
10
10
|
import {
|
|
11
11
|
getContract
|
|
12
|
-
} from "../../shared/stacks-
|
|
12
|
+
} from "../../shared/stacks-jpt52csy.js";
|
|
13
13
|
import {
|
|
14
14
|
multicall
|
|
15
|
-
} from "../../shared/stacks-
|
|
16
|
-
import"../../shared/stacks-
|
|
17
|
-
import"../../shared/stacks-
|
|
18
|
-
import"../../shared/stacks-9d2d0qjc.js";
|
|
19
|
-
import"../../shared/stacks-fh48neva.js";
|
|
15
|
+
} from "../../shared/stacks-2evvn48s.js";
|
|
16
|
+
import"../../shared/stacks-fb75yew8.js";
|
|
17
|
+
import"../../shared/stacks-27fmgajb.js";
|
|
20
18
|
import"../../shared/stacks-709tra19.js";
|
|
21
19
|
import"../../shared/stacks-4z72akdf.js";
|
|
22
|
-
import
|
|
20
|
+
import {
|
|
21
|
+
structuredDataHash
|
|
22
|
+
} from "../../shared/stacks-1arrcd11.js";
|
|
23
|
+
import"../../shared/stacks-hnqt5rz4.js";
|
|
24
|
+
import"../../shared/stacks-w23294am.js";
|
|
23
25
|
import {
|
|
24
26
|
Cl,
|
|
25
27
|
serializeCVBytes
|
|
@@ -68,6 +70,23 @@ var C_SCRIPT_NUM_MAX = 549755813888n;
|
|
|
68
70
|
var BITCOIN_LOCKTIME_THRESHOLD = 500000000n;
|
|
69
71
|
|
|
70
72
|
// src/pox5/activation.ts
|
|
73
|
+
async function getPoxInfo(client) {
|
|
74
|
+
const info = await client.request("/v2/pox", {
|
|
75
|
+
method: "GET"
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
contractId: info.contract_id,
|
|
79
|
+
currentBurnchainBlockHeight: info.current_burnchain_block_height,
|
|
80
|
+
firstBurnchainBlockHeight: info.first_burnchain_block_height,
|
|
81
|
+
sbtcContract: info.pox_5_sbtc_contract,
|
|
82
|
+
sbtcRegistryContract: info.pox_5_sbtc_registry_contract,
|
|
83
|
+
contractVersions: (info.contract_versions ?? []).map((v) => ({
|
|
84
|
+
contractId: v.contract_id,
|
|
85
|
+
activationBurnchainBlockHeight: v.activation_burnchain_block_height,
|
|
86
|
+
firstRewardCycleId: v.first_reward_cycle_id
|
|
87
|
+
}))
|
|
88
|
+
};
|
|
89
|
+
}
|
|
71
90
|
async function getPox5Activation(client) {
|
|
72
91
|
const info = await client.request("/v2/pox", {
|
|
73
92
|
method: "GET"
|
|
@@ -95,6 +114,169 @@ async function assertPox5Active(client) {
|
|
|
95
114
|
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.");
|
|
96
115
|
}
|
|
97
116
|
}
|
|
117
|
+
// src/pox5/errors.ts
|
|
118
|
+
var Pox5ErrorCode = {
|
|
119
|
+
Unauthorized: 1,
|
|
120
|
+
CannotSetupBondTooSoon: 2,
|
|
121
|
+
CannotSetupBondTooLate: 3,
|
|
122
|
+
BondAlreadySetup: 4,
|
|
123
|
+
StakerAlreadyAdded: 5,
|
|
124
|
+
BondNotFound: 7,
|
|
125
|
+
InsufficientStx: 8,
|
|
126
|
+
AlreadyRegistered: 9,
|
|
127
|
+
TooMuchSats: 10,
|
|
128
|
+
NotAllowlisted: 11,
|
|
129
|
+
SignerKeyGrantUsed: 12,
|
|
130
|
+
InvalidSignatureRecover: 13,
|
|
131
|
+
InvalidSignaturePubkey: 14,
|
|
132
|
+
SignerKeyGrantNotFound: 17,
|
|
133
|
+
AlreadyStaked: 19,
|
|
134
|
+
InvalidNumCycles: 20,
|
|
135
|
+
SignerNotFound: 23,
|
|
136
|
+
InvalidStartBurnHeight: 24,
|
|
137
|
+
UnauthorizedSignerRegistration: 26,
|
|
138
|
+
NotStaking: 27,
|
|
139
|
+
UnstakeInPreparePhase: 28,
|
|
140
|
+
InvalidBondPeriodOrdering: 29,
|
|
141
|
+
DistributionAlreadyComputed: 30,
|
|
142
|
+
BondNotActive: 31,
|
|
143
|
+
NoClaimableRewards: 32,
|
|
144
|
+
ActiveBondNotIncluded: 33,
|
|
145
|
+
NotBondParticipant: 34,
|
|
146
|
+
CannotAnnounceL1EarlyUnlock: 35,
|
|
147
|
+
InvalidOldSignerManager: 36,
|
|
148
|
+
InvalidUnstakeSbtcAmount: 37,
|
|
149
|
+
CannotUnstakeSbtc: 38,
|
|
150
|
+
ReadTxOutOfBounds: 39,
|
|
151
|
+
InvalidBtcHeader: 40,
|
|
152
|
+
InvalidMerkleProof: 41,
|
|
153
|
+
InvalidLockupScript: 42,
|
|
154
|
+
BondAlreadyStarted: 43,
|
|
155
|
+
UpdateBondSameSigner: 44,
|
|
156
|
+
InvalidLockupAmount: 45,
|
|
157
|
+
DuplicateLockupOutpoint: 46,
|
|
158
|
+
StakeInPreparePhase: 47,
|
|
159
|
+
RolloverTooEarly: 48,
|
|
160
|
+
ReentrantCall: 49,
|
|
161
|
+
L1EarlyExitAlreadyAnnounced: 50,
|
|
162
|
+
InsufficientReserveBalance: 51,
|
|
163
|
+
InvalidUnlockHeight: 52,
|
|
164
|
+
RewardsPaused: 53
|
|
165
|
+
};
|
|
166
|
+
var POX5_ERROR_NAMES = {
|
|
167
|
+
[Pox5ErrorCode.Unauthorized]: "ERR_UNAUTHORIZED",
|
|
168
|
+
[Pox5ErrorCode.CannotSetupBondTooSoon]: "ERR_CANNOT_SETUP_BOND_TOO_SOON",
|
|
169
|
+
[Pox5ErrorCode.CannotSetupBondTooLate]: "ERR_CANNOT_SETUP_BOND_TOO_LATE",
|
|
170
|
+
[Pox5ErrorCode.BondAlreadySetup]: "ERR_BOND_ALREADY_SETUP",
|
|
171
|
+
[Pox5ErrorCode.StakerAlreadyAdded]: "ERR_STAKER_ALREADY_ADDED",
|
|
172
|
+
[Pox5ErrorCode.BondNotFound]: "ERR_BOND_NOT_FOUND",
|
|
173
|
+
[Pox5ErrorCode.InsufficientStx]: "ERR_INSUFFICIENT_STX",
|
|
174
|
+
[Pox5ErrorCode.AlreadyRegistered]: "ERR_ALREADY_REGISTERED",
|
|
175
|
+
[Pox5ErrorCode.TooMuchSats]: "ERR_TOO_MUCH_SATS",
|
|
176
|
+
[Pox5ErrorCode.NotAllowlisted]: "ERR_NOT_ALLOWLISTED",
|
|
177
|
+
[Pox5ErrorCode.SignerKeyGrantUsed]: "ERR_SIGNER_KEY_GRANT_USED",
|
|
178
|
+
[Pox5ErrorCode.InvalidSignatureRecover]: "ERR_INVALID_SIGNATURE_RECOVER",
|
|
179
|
+
[Pox5ErrorCode.InvalidSignaturePubkey]: "ERR_INVALID_SIGNATURE_PUBKEY",
|
|
180
|
+
[Pox5ErrorCode.SignerKeyGrantNotFound]: "ERR_SIGNER_KEY_GRANT_NOT_FOUND",
|
|
181
|
+
[Pox5ErrorCode.AlreadyStaked]: "ERR_ALREADY_STAKED",
|
|
182
|
+
[Pox5ErrorCode.InvalidNumCycles]: "ERR_INVALID_NUM_CYCLES",
|
|
183
|
+
[Pox5ErrorCode.SignerNotFound]: "ERR_SIGNER_NOT_FOUND",
|
|
184
|
+
[Pox5ErrorCode.InvalidStartBurnHeight]: "ERR_INVALID_START_BURN_HEIGHT",
|
|
185
|
+
[Pox5ErrorCode.UnauthorizedSignerRegistration]: "ERR_UNAUTHORIZED_SIGNER_REGISTRATION",
|
|
186
|
+
[Pox5ErrorCode.NotStaking]: "ERR_NOT_STAKING",
|
|
187
|
+
[Pox5ErrorCode.UnstakeInPreparePhase]: "ERR_UNSTAKE_IN_PREPARE_PHASE",
|
|
188
|
+
[Pox5ErrorCode.InvalidBondPeriodOrdering]: "ERR_INVALID_BOND_PERIOD_ORDERING",
|
|
189
|
+
[Pox5ErrorCode.DistributionAlreadyComputed]: "ERR_DISTRIBUTION_ALREADY_COMPUTED",
|
|
190
|
+
[Pox5ErrorCode.BondNotActive]: "ERR_BOND_NOT_ACTIVE",
|
|
191
|
+
[Pox5ErrorCode.NoClaimableRewards]: "ERR_NO_CLAIMABLE_REWARDS",
|
|
192
|
+
[Pox5ErrorCode.ActiveBondNotIncluded]: "ERR_ACTIVE_BOND_NOT_INCLUDED",
|
|
193
|
+
[Pox5ErrorCode.NotBondParticipant]: "ERR_NOT_BOND_PARTICIPANT",
|
|
194
|
+
[Pox5ErrorCode.CannotAnnounceL1EarlyUnlock]: "ERR_CANNOT_ANNOUNCE_L1_EARLY_UNLOCK",
|
|
195
|
+
[Pox5ErrorCode.InvalidOldSignerManager]: "ERR_INVALID_OLD_SIGNER_MANAGER",
|
|
196
|
+
[Pox5ErrorCode.InvalidUnstakeSbtcAmount]: "ERR_INVALID_UNSTAKE_SBTC_AMOUNT",
|
|
197
|
+
[Pox5ErrorCode.CannotUnstakeSbtc]: "ERR_CANNOT_UNSTAKE_SBTC",
|
|
198
|
+
[Pox5ErrorCode.ReadTxOutOfBounds]: "ERR_READ_TX_OUT_OF_BOUNDS",
|
|
199
|
+
[Pox5ErrorCode.InvalidBtcHeader]: "ERR_INVALID_BTC_HEADER",
|
|
200
|
+
[Pox5ErrorCode.InvalidMerkleProof]: "ERR_INVALID_MERKLE_PROOF",
|
|
201
|
+
[Pox5ErrorCode.InvalidLockupScript]: "ERR_INVALID_LOCKUP_SCRIPT",
|
|
202
|
+
[Pox5ErrorCode.BondAlreadyStarted]: "ERR_BOND_ALREADY_STARTED",
|
|
203
|
+
[Pox5ErrorCode.UpdateBondSameSigner]: "ERR_UPDATE_BOND_SAME_SIGNER",
|
|
204
|
+
[Pox5ErrorCode.InvalidLockupAmount]: "ERR_INVALID_LOCKUP_AMOUNT",
|
|
205
|
+
[Pox5ErrorCode.DuplicateLockupOutpoint]: "ERR_DUPLICATE_LOCKUP_OUTPOINT",
|
|
206
|
+
[Pox5ErrorCode.StakeInPreparePhase]: "ERR_STAKE_IN_PREPARE_PHASE",
|
|
207
|
+
[Pox5ErrorCode.RolloverTooEarly]: "ERR_ROLLOVER_TOO_EARLY",
|
|
208
|
+
[Pox5ErrorCode.ReentrantCall]: "ERR_REENTRANT_CALL",
|
|
209
|
+
[Pox5ErrorCode.L1EarlyExitAlreadyAnnounced]: "ERR_L1_EARLY_EXIT_ALREADY_ANNOUNCED",
|
|
210
|
+
[Pox5ErrorCode.InsufficientReserveBalance]: "ERR_INSUFFICIENT_RESERVE_BALANCE",
|
|
211
|
+
[Pox5ErrorCode.InvalidUnlockHeight]: "ERR_INVALID_UNLOCK_HEIGHT",
|
|
212
|
+
[Pox5ErrorCode.RewardsPaused]: "ERR_REWARDS_PAUSED"
|
|
213
|
+
};
|
|
214
|
+
var POX5_ERROR_DESCRIPTIONS = {
|
|
215
|
+
[Pox5ErrorCode.Unauthorized]: "Caller is not authorized.",
|
|
216
|
+
[Pox5ErrorCode.CannotSetupBondTooSoon]: "Bond setup window has not opened.",
|
|
217
|
+
[Pox5ErrorCode.CannotSetupBondTooLate]: "Bond setup window has closed.",
|
|
218
|
+
[Pox5ErrorCode.BondAlreadySetup]: "This bond period is already set up.",
|
|
219
|
+
[Pox5ErrorCode.StakerAlreadyAdded]: "Staker is already on this bond.",
|
|
220
|
+
[Pox5ErrorCode.BondNotFound]: "No bond at this index.",
|
|
221
|
+
[Pox5ErrorCode.InsufficientStx]: "Not enough STX for this operation.",
|
|
222
|
+
[Pox5ErrorCode.AlreadyRegistered]: "Staker already has an overlapping position.",
|
|
223
|
+
[Pox5ErrorCode.TooMuchSats]: "Sats amount exceeds the allowlist maximum.",
|
|
224
|
+
[Pox5ErrorCode.NotAllowlisted]: "Principal is not on the bond allowlist.",
|
|
225
|
+
[Pox5ErrorCode.SignerKeyGrantUsed]: "This signer-key grant was already consumed.",
|
|
226
|
+
[Pox5ErrorCode.InvalidSignatureRecover]: "Could not recover a public key from the signature.",
|
|
227
|
+
[Pox5ErrorCode.InvalidSignaturePubkey]: "Recovered public key does not match the signer key.",
|
|
228
|
+
[Pox5ErrorCode.SignerKeyGrantNotFound]: "No grant found for this signer key.",
|
|
229
|
+
[Pox5ErrorCode.AlreadyStaked]: "Principal already has an overlapping stake.",
|
|
230
|
+
[Pox5ErrorCode.InvalidNumCycles]: "Cycle count is outside the allowed range.",
|
|
231
|
+
[Pox5ErrorCode.SignerNotFound]: "No signer found for this principal.",
|
|
232
|
+
[Pox5ErrorCode.InvalidStartBurnHeight]: "Start burn height must fall in the current reward cycle.",
|
|
233
|
+
[Pox5ErrorCode.UnauthorizedSignerRegistration]: "Caller is not authorized to register this signer.",
|
|
234
|
+
[Pox5ErrorCode.NotStaking]: "Principal is not currently staking.",
|
|
235
|
+
[Pox5ErrorCode.UnstakeInPreparePhase]: "Unstaking is not allowed in the prepare phase.",
|
|
236
|
+
[Pox5ErrorCode.InvalidBondPeriodOrdering]: "Bond periods were supplied out of order.",
|
|
237
|
+
[Pox5ErrorCode.DistributionAlreadyComputed]: "Reward distribution already computed for this period.",
|
|
238
|
+
[Pox5ErrorCode.BondNotActive]: "Bond is not currently active.",
|
|
239
|
+
[Pox5ErrorCode.NoClaimableRewards]: "No claimable rewards for this caller.",
|
|
240
|
+
[Pox5ErrorCode.ActiveBondNotIncluded]: "The currently active bond was not included in the list.",
|
|
241
|
+
[Pox5ErrorCode.NotBondParticipant]: "Caller is not in a bond.",
|
|
242
|
+
[Pox5ErrorCode.CannotAnnounceL1EarlyUnlock]: "Early-exit announce is not valid for this membership.",
|
|
243
|
+
[Pox5ErrorCode.InvalidOldSignerManager]: "old-signer-manager does not match the staker's current signer.",
|
|
244
|
+
[Pox5ErrorCode.InvalidUnstakeSbtcAmount]: "sBTC unstake amount is invalid.",
|
|
245
|
+
[Pox5ErrorCode.CannotUnstakeSbtc]: "Bond participant did not stake sBTC.",
|
|
246
|
+
[Pox5ErrorCode.ReadTxOutOfBounds]: "Lockup proof buffer was truncated.",
|
|
247
|
+
[Pox5ErrorCode.InvalidBtcHeader]: "Bitcoin header in the lockup proof is invalid.",
|
|
248
|
+
[Pox5ErrorCode.InvalidMerkleProof]: "Merkle proof in the lockup proof is invalid.",
|
|
249
|
+
[Pox5ErrorCode.InvalidLockupScript]: "Lockup output script does not match.",
|
|
250
|
+
[Pox5ErrorCode.BondAlreadyStarted]: "Cannot register after the bond has started.",
|
|
251
|
+
[Pox5ErrorCode.UpdateBondSameSigner]: "update-bond-registration cannot keep the same signer.",
|
|
252
|
+
[Pox5ErrorCode.InvalidLockupAmount]: "Lockup output amount does not match sats.",
|
|
253
|
+
[Pox5ErrorCode.DuplicateLockupOutpoint]: "The same Bitcoin outpoint appeared twice in the lockup list.",
|
|
254
|
+
[Pox5ErrorCode.StakeInPreparePhase]: "Cannot modify next-cycle stake during the prepare phase.",
|
|
255
|
+
[Pox5ErrorCode.RolloverTooEarly]: "Bond rollover is too early.",
|
|
256
|
+
[Pox5ErrorCode.ReentrantCall]: "Reentrant call into pox-5 while a trait call is in flight.",
|
|
257
|
+
[Pox5ErrorCode.L1EarlyExitAlreadyAnnounced]: "L1 early exit already announced for this bond period.",
|
|
258
|
+
[Pox5ErrorCode.InsufficientReserveBalance]: "Reserve withdrawal exceeds the balance.",
|
|
259
|
+
[Pox5ErrorCode.InvalidUnlockHeight]: "Unlock height is below the bond minimum or at/above 500,000,000.",
|
|
260
|
+
[Pox5ErrorCode.RewardsPaused]: "Signer reward claims are paused."
|
|
261
|
+
};
|
|
262
|
+
function parsePox5Error(result) {
|
|
263
|
+
if (result == null)
|
|
264
|
+
return;
|
|
265
|
+
if (typeof result === "string") {
|
|
266
|
+
const match = result.trim().match(/^\(err u(\d+)\)$/);
|
|
267
|
+
return match ? Number(match[1]) : undefined;
|
|
268
|
+
}
|
|
269
|
+
if (result.type !== "err")
|
|
270
|
+
return;
|
|
271
|
+
return result.value.type === "uint" ? Number(result.value.value) : undefined;
|
|
272
|
+
}
|
|
273
|
+
function describePox5Error(code) {
|
|
274
|
+
const n = Number(code);
|
|
275
|
+
const name = POX5_ERROR_NAMES[n];
|
|
276
|
+
if (!name)
|
|
277
|
+
return;
|
|
278
|
+
return { code: n, name, description: POX5_ERROR_DESCRIPTIONS[n] };
|
|
279
|
+
}
|
|
98
280
|
// src/pox5/cycles.ts
|
|
99
281
|
function burnHeightToRewardCycle(burnHeight, params) {
|
|
100
282
|
if (burnHeight < params.firstBurnchainBlockHeight) {
|
|
@@ -210,20 +392,19 @@ function buildDefaultStakerUnlockBytes(publicKey) {
|
|
|
210
392
|
}
|
|
211
393
|
// src/pox5/grants.ts
|
|
212
394
|
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
213
|
-
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
214
|
-
var SIP018_PREFIX = hexToBytes("534950303138");
|
|
215
395
|
function computeSignerGrantHash(opts) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
396
|
+
return structuredDataHash({
|
|
397
|
+
domain: Cl.tuple({
|
|
398
|
+
name: Cl.stringAscii(POX5_SIGNER_DOMAIN.name),
|
|
399
|
+
version: Cl.stringAscii(POX5_SIGNER_DOMAIN.version),
|
|
400
|
+
"chain-id": Cl.uint(opts.chainId)
|
|
401
|
+
}),
|
|
402
|
+
message: Cl.tuple({
|
|
403
|
+
topic: Cl.stringAscii("grant-authorization"),
|
|
404
|
+
"signer-manager": Cl.principal(opts.signerManager),
|
|
405
|
+
"auth-id": Cl.uint(opts.authId)
|
|
406
|
+
})
|
|
407
|
+
});
|
|
227
408
|
}
|
|
228
409
|
async function signSignerGrant(account, opts) {
|
|
229
410
|
const vrs = await account.sign(computeSignerGrantHash(opts));
|
|
@@ -830,9 +1011,23 @@ function toBytes2(input) {
|
|
|
830
1011
|
function optionalBytes(input) {
|
|
831
1012
|
return input === undefined ? null : toBytes2(input);
|
|
832
1013
|
}
|
|
1014
|
+
var MAX_LOCKUP_OUTPUTS = 10;
|
|
1015
|
+
var MAX_LEAF_HASHES = 14;
|
|
833
1016
|
function btcLockupArg(lockup) {
|
|
834
1017
|
if ("sbtcSats" in lockup)
|
|
835
1018
|
return { err: intToBigInt(lockup.sbtcSats) };
|
|
1019
|
+
if (lockup.l1Outputs.length === 0) {
|
|
1020
|
+
throw new Error("registerForBond: l1Outputs is empty — nothing would be locked");
|
|
1021
|
+
}
|
|
1022
|
+
if (lockup.l1Outputs.length > MAX_LOCKUP_OUTPUTS) {
|
|
1023
|
+
throw new Error(`registerForBond: ${lockup.l1Outputs.length} lockup outputs; pox-5 accepts at most ${MAX_LOCKUP_OUTPUTS}`);
|
|
1024
|
+
}
|
|
1025
|
+
for (let i = 0;i < lockup.l1Outputs.length; i++) {
|
|
1026
|
+
const n = lockup.l1Outputs[i]?.leafHashes.length ?? 0;
|
|
1027
|
+
if (n > MAX_LEAF_HASHES) {
|
|
1028
|
+
throw new Error(`registerForBond: output ${i} has ${n} merkle siblings; pox-5 accepts at most ${MAX_LEAF_HASHES}`);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
836
1031
|
return {
|
|
837
1032
|
ok: {
|
|
838
1033
|
outputs: lockup.l1Outputs.map((o) => ({
|
|
@@ -1069,6 +1264,7 @@ function pox5() {
|
|
|
1069
1264
|
pox5: {
|
|
1070
1265
|
isActive: () => isPox5Active(client),
|
|
1071
1266
|
getActivation: () => getPox5Activation(client),
|
|
1267
|
+
getPoxInfo: () => getPoxInfo(client),
|
|
1072
1268
|
contractId: () => pox5ContractId(client),
|
|
1073
1269
|
getStakerState: (staker) => getStakerState(client, staker),
|
|
1074
1270
|
getStakerInfo: (staker) => getStakerInfo(client, staker),
|
|
@@ -1110,9 +1306,12 @@ export {
|
|
|
1110
1306
|
pushCScriptNum,
|
|
1111
1307
|
pox5ContractId,
|
|
1112
1308
|
pox5,
|
|
1309
|
+
parsePox5Error,
|
|
1113
1310
|
isPox5Active,
|
|
1114
1311
|
isInPreparePhase,
|
|
1312
|
+
getPoxInfo,
|
|
1115
1313
|
getPox5Activation,
|
|
1314
|
+
describePox5Error,
|
|
1116
1315
|
computeSignerGrantHash,
|
|
1117
1316
|
burnHeightToRewardCycle,
|
|
1118
1317
|
burnHeightToDistributionIndex,
|
|
@@ -1125,8 +1324,10 @@ export {
|
|
|
1125
1324
|
bondPeriodToRewardCycle,
|
|
1126
1325
|
bondPeriodToBurnHeight,
|
|
1127
1326
|
assertPox5Active,
|
|
1327
|
+
Pox5ErrorCode,
|
|
1128
1328
|
POX5_SIGNER_DOMAIN,
|
|
1129
1329
|
POX5_EVENT_TOPICS,
|
|
1330
|
+
POX5_ERROR_NAMES,
|
|
1130
1331
|
POX5_CONTRACT_NAME,
|
|
1131
1332
|
POX5_CONTRACT_ID_MAINNET,
|
|
1132
1333
|
POX5_ACTIVATION_BURN_HEIGHT_MAINNET,
|
|
@@ -1138,5 +1339,5 @@ export {
|
|
|
1138
1339
|
BITCOIN_LOCKTIME_THRESHOLD
|
|
1139
1340
|
};
|
|
1140
1341
|
|
|
1141
|
-
//# debugId=
|
|
1342
|
+
//# debugId=A1DC6FC93AED92D864756E2164756E21
|
|
1142
1343
|
//# sourceMappingURL=index.js.map
|