@secondlayer/stacks 6.1.0 → 6.1.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/dist/shared/stacks-esm-0pc6tmf0.js +50 -0
- package/dist/shared/{stacks-esm-743jfh10.js.map → stacks-esm-0pc6tmf0.js.map} +2 -2
- package/dist/shared/{stacks-esm-0rdxcta7.js → stacks-esm-16d82wyc.js} +10 -10
- package/dist/shared/{stacks-esm-0rdxcta7.js.map → stacks-esm-16d82wyc.js.map} +2 -2
- package/dist/shared/{stacks-esm-cvhazvhd.js → stacks-esm-7a0ehykf.js} +43 -43
- package/dist/shared/{stacks-esm-cvhazvhd.js.map → stacks-esm-7a0ehykf.js.map} +2 -2
- package/dist/shared/{stacks-esm-1jae0a3r.js → stacks-esm-7v18h5dk.js} +4 -4
- package/dist/shared/{stacks-esm-1jae0a3r.js.map → stacks-esm-7v18h5dk.js.map} +2 -2
- package/dist/shared/{stacks-esm-9rnx0zxr.js → stacks-esm-8f5catbf.js} +126 -126
- package/dist/shared/{stacks-esm-9rnx0zxr.js.map → stacks-esm-8f5catbf.js.map} +2 -2
- package/dist/shared/{stacks-esm-7fpqgtyx.js → stacks-esm-8jt6k8p3.js} +13 -13
- package/dist/shared/{stacks-esm-7fpqgtyx.js.map → stacks-esm-8jt6k8p3.js.map} +2 -2
- package/dist/shared/{stacks-esm-hr7fpxtj.js → stacks-esm-a20wyky3.js} +92 -92
- package/dist/shared/{stacks-esm-hr7fpxtj.js.map → stacks-esm-a20wyky3.js.map} +2 -2
- package/dist/shared/{stacks-esm-3pv5avgr.js → stacks-esm-b54n1jdx.js} +54 -54
- package/dist/shared/{stacks-esm-3pv5avgr.js.map → stacks-esm-b54n1jdx.js.map} +2 -2
- package/dist/shared/{stacks-esm-r9q4wnyw.js → stacks-esm-cmtj5vky.js} +162 -162
- package/dist/shared/{stacks-esm-r9q4wnyw.js.map → stacks-esm-cmtj5vky.js.map} +2 -2
- package/dist/shared/{stacks-esm-wv67m4g6.js → stacks-esm-e2qhfgke.js} +36 -36
- package/dist/shared/{stacks-esm-wv67m4g6.js.map → stacks-esm-e2qhfgke.js.map} +2 -2
- package/dist/shared/{stacks-esm-qk0p9fr6.js → stacks-esm-ea4m4bk7.js} +117 -117
- package/dist/shared/{stacks-esm-qk0p9fr6.js.map → stacks-esm-ea4m4bk7.js.map} +2 -2
- package/dist/shared/{stacks-esm-fcfdn2zx.js → stacks-esm-hkw1kvd4.js} +140 -140
- package/dist/shared/{stacks-esm-fcfdn2zx.js.map → stacks-esm-hkw1kvd4.js.map} +2 -2
- package/dist/shared/{stacks-esm-qkj67g80.js → stacks-esm-k108pemv.js} +4 -4
- package/dist/shared/{stacks-esm-qkj67g80.js.map → stacks-esm-k108pemv.js.map} +2 -2
- package/dist/shared/stacks-esm-kbz5s6v8.js +84 -0
- package/dist/shared/{stacks-esm-2mc7ebrm.js.map → stacks-esm-kbz5s6v8.js.map} +2 -2
- package/dist/shared/{stacks-esm-n53kvwmt.js → stacks-esm-mt1thm7k.js} +9 -9
- package/dist/shared/{stacks-esm-n53kvwmt.js.map → stacks-esm-mt1thm7k.js.map} +2 -2
- package/dist/shared/{stacks-esm-v45990hx.js → stacks-esm-n1mekwnb.js} +9 -9
- package/dist/shared/{stacks-esm-v45990hx.js.map → stacks-esm-n1mekwnb.js.map} +2 -2
- package/dist/shared/{stacks-esm-r6dejrgr.js → stacks-esm-nt5hf8ht.js} +34 -34
- package/dist/shared/{stacks-esm-r6dejrgr.js.map → stacks-esm-nt5hf8ht.js.map} +2 -2
- package/dist/shared/{stacks-esm-skmcf5n2.js → stacks-esm-phgy8yqf.js} +210 -210
- package/dist/shared/{stacks-esm-skmcf5n2.js.map → stacks-esm-phgy8yqf.js.map} +2 -2
- package/dist/shared/{stacks-esm-kds4n82p.js → stacks-esm-pxv6ny92.js} +116 -116
- package/dist/shared/{stacks-esm-kds4n82p.js.map → stacks-esm-pxv6ny92.js.map} +2 -2
- package/dist/shared/{stacks-esm-3g33bqsm.js → stacks-esm-qfzxhdqz.js} +19 -19
- package/dist/shared/{stacks-esm-3g33bqsm.js.map → stacks-esm-qfzxhdqz.js.map} +2 -2
- package/dist/shared/{stacks-esm-aw2mj3sj.js → stacks-esm-snj9s2q8.js} +43 -43
- package/dist/shared/{stacks-esm-aw2mj3sj.js.map → stacks-esm-snj9s2q8.js.map} +2 -2
- package/dist/shared/{stacks-esm-q19a17fd.js → stacks-esm-ss9ap75h.js} +28 -28
- package/dist/shared/{stacks-esm-q19a17fd.js.map → stacks-esm-ss9ap75h.js.map} +2 -2
- package/dist/shared/{stacks-esm-x1r01353.js → stacks-esm-t88hc019.js} +18 -18
- package/dist/shared/{stacks-esm-x1r01353.js.map → stacks-esm-t88hc019.js.map} +2 -2
- package/dist/shared/stacks-esm-tdrdye4y.js +48 -0
- package/dist/shared/{stacks-esm-pxhfqfff.js.map → stacks-esm-tdrdye4y.js.map} +2 -2
- package/dist/src/accounts/index.cjs +15 -13
- package/dist/src/accounts/index.cjs.map +2 -2
- package/dist/src/accounts/index.d.cts +1 -1
- package/dist/src/accounts/index.d.ts +1 -1
- package/dist/src/accounts/index.js +26 -26
- package/dist/src/accounts/index.js.map +2 -2
- package/dist/src/actions/index.cjs +83 -81
- package/dist/src/actions/index.cjs.map +2 -2
- package/dist/src/actions/index.d.cts +1 -1
- package/dist/src/actions/index.d.ts +1 -1
- package/dist/src/actions/index.js +102 -103
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.cjs +2035 -2036
- package/dist/src/bitcoin/index.cjs.map +8 -8
- package/dist/src/bitcoin/index.d.cts +92 -92
- package/dist/src/bitcoin/index.d.ts +92 -92
- package/dist/src/bitcoin/index.js +88 -90
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/bns/index.cjs +3313 -3310
- package/dist/src/bns/index.cjs.map +13 -13
- package/dist/src/bns/index.d.cts +1 -1
- package/dist/src/bns/index.d.ts +1 -1
- package/dist/src/bns/index.js +39 -41
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/chains/index.cjs +14 -12
- package/dist/src/chains/index.cjs.map +2 -2
- package/dist/src/chains/index.d.cts +1 -1
- package/dist/src/chains/index.d.ts +1 -1
- package/dist/src/chains/index.js +12 -12
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/clarity/index.cjs +98 -96
- package/dist/src/clarity/index.cjs.map +2 -2
- package/dist/src/clarity/index.d.cts +1 -1
- package/dist/src/clarity/index.d.ts +1 -1
- package/dist/src/clarity/index.js +170 -171
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/connect/index.cjs +19 -19
- package/dist/src/connect/index.cjs.map +2 -2
- package/dist/src/connect/index.d.cts +1 -1
- package/dist/src/connect/index.d.ts +1 -1
- package/dist/src/connect/index.js +19 -19
- package/dist/src/connect/index.js.map +2 -2
- package/dist/src/connect/walletconnect/index.cjs +6 -46
- package/dist/src/connect/walletconnect/index.cjs.map +3 -4
- package/dist/src/connect/walletconnect/index.d.cts +1 -1
- package/dist/src/connect/walletconnect/index.d.ts +1 -1
- package/dist/src/connect/walletconnect/index.js +6 -46
- package/dist/src/connect/walletconnect/index.js.map +3 -4
- package/dist/src/filters/index.cjs +22 -20
- package/dist/src/filters/index.cjs.map +2 -2
- package/dist/src/filters/index.d.cts +1 -1
- package/dist/src/filters/index.d.ts +1 -1
- package/dist/src/filters/index.js +30 -30
- package/dist/src/filters/index.js.map +1 -1
- package/dist/src/index.cjs +1411 -1410
- package/dist/src/index.cjs.map +11 -11
- package/dist/src/index.d.cts +724 -724
- package/dist/src/index.d.ts +724 -724
- package/dist/src/index.js +219 -219
- package/dist/src/index.js.map +2 -2
- package/dist/src/postconditions/index.cjs +26 -24
- package/dist/src/postconditions/index.cjs.map +2 -2
- package/dist/src/postconditions/index.d.cts +1 -1
- package/dist/src/postconditions/index.d.ts +1 -1
- package/dist/src/postconditions/index.js +16 -17
- package/dist/src/postconditions/index.js.map +1 -1
- package/dist/src/pox/index.cjs +722 -721
- package/dist/src/pox/index.cjs.map +9 -9
- package/dist/src/pox/index.d.cts +1 -1
- package/dist/src/pox/index.d.ts +1 -1
- package/dist/src/pox/index.js +40 -41
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/pox5/index.cjs +141 -137
- package/dist/src/pox5/index.cjs.map +3 -3
- package/dist/src/pox5/index.d.cts +9 -1
- package/dist/src/pox5/index.d.ts +9 -1
- package/dist/src/pox5/index.js +210 -209
- package/dist/src/pox5/index.js.map +3 -3
- package/dist/src/sbtc/index.cjs +71 -69
- package/dist/src/sbtc/index.cjs.map +2 -2
- package/dist/src/sbtc/index.d.cts +1 -1
- package/dist/src/sbtc/index.d.ts +1 -1
- package/dist/src/sbtc/index.js +39 -40
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/simnet/index.cjs +16 -16
- package/dist/src/simnet/index.cjs.map +2 -2
- package/dist/src/simnet/index.d.cts +1 -1
- package/dist/src/simnet/index.d.ts +1 -1
- package/dist/src/simnet/index.js +16 -16
- package/dist/src/simnet/index.js.map +2 -2
- package/dist/src/stackingdao/index.cjs +716 -715
- package/dist/src/stackingdao/index.cjs.map +9 -9
- package/dist/src/stackingdao/index.d.cts +1 -1
- package/dist/src/stackingdao/index.d.ts +1 -1
- package/dist/src/stackingdao/index.js +26 -27
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/subscriptions/index.cjs +15 -13
- package/dist/src/subscriptions/index.cjs.map +2 -2
- package/dist/src/subscriptions/index.d.cts +1 -1
- package/dist/src/subscriptions/index.d.ts +1 -1
- package/dist/src/subscriptions/index.js +14 -15
- package/dist/src/subscriptions/index.js.map +1 -1
- package/dist/src/transactions/index.cjs +79 -77
- package/dist/src/transactions/index.cjs.map +2 -2
- package/dist/src/transactions/index.d.cts +1 -1
- package/dist/src/transactions/index.d.ts +1 -1
- package/dist/src/transactions/index.js +104 -105
- package/dist/src/transactions/index.js.map +1 -1
- package/dist/src/utils/index.cjs +76 -74
- package/dist/src/utils/index.cjs.map +2 -2
- package/dist/src/utils/index.d.cts +1 -1
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.js +131 -131
- package/dist/src/utils/index.js.map +2 -2
- package/package.json +1 -1
- package/dist/shared/stacks-esm-2mc7ebrm.js +0 -84
- package/dist/shared/stacks-esm-743jfh10.js +0 -50
- package/dist/shared/stacks-esm-pxhfqfff.js +0 -48
package/dist/src/pox5/index.js
CHANGED
|
@@ -1,49 +1,48 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
bytesToHex2,
|
|
3
|
+
hexToBytes2,
|
|
4
|
+
concatBytes2,
|
|
5
|
+
intToBigInt2
|
|
6
|
+
} from "../../shared/stacks-esm-7a0ehykf.js";
|
|
5
7
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
serializeCVBytes2,
|
|
9
|
+
Cl2,
|
|
10
|
+
deserializeCVBytes2
|
|
11
|
+
} from "../../shared/stacks-esm-hkw1kvd4.js";
|
|
12
|
+
import"../../shared/stacks-esm-kbz5s6v8.js";
|
|
13
|
+
import"../../shared/stacks-esm-a20wyky3.js";
|
|
14
|
+
import"../../shared/stacks-esm-phgy8yqf.js";
|
|
15
|
+
import"../../shared/stacks-esm-cmtj5vky.js";
|
|
11
16
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "../../shared/stacks-esm-
|
|
17
|
+
parseBitcoinTx2,
|
|
18
|
+
stripWitness2,
|
|
19
|
+
BITCOIN_NETWORK_PARAMS
|
|
20
|
+
} from "../../shared/stacks-esm-e2qhfgke.js";
|
|
16
21
|
import {
|
|
17
|
-
|
|
18
|
-
} from "../../shared/stacks-esm-
|
|
22
|
+
structuredDataHash2
|
|
23
|
+
} from "../../shared/stacks-esm-tdrdye4y.js";
|
|
19
24
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
canonicalizeBtcAddress,
|
|
26
|
+
parseBtcAddress2,
|
|
27
|
+
stringifyBtcAddress2,
|
|
28
|
+
BtcAddress2
|
|
29
|
+
} from "../../shared/stacks-esm-ss9ap75h.js";
|
|
24
30
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
import"../../shared/stacks-esm-hr7fpxtj.js";
|
|
31
|
+
buildTxProof2,
|
|
32
|
+
EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET2
|
|
33
|
+
} from "../../shared/stacks-esm-nt5hf8ht.js";
|
|
29
34
|
import {
|
|
30
|
-
|
|
31
|
-
} from "../../shared/stacks-esm-
|
|
32
|
-
import"../../shared/stacks-esm-r9q4wnyw.js";
|
|
33
|
-
import"../../shared/stacks-esm-skmcf5n2.js";
|
|
35
|
+
getContract2
|
|
36
|
+
} from "../../shared/stacks-esm-snj9s2q8.js";
|
|
34
37
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} from "../../shared/stacks-esm-
|
|
39
|
-
import"../../shared/stacks-esm-1jae0a3r.js";
|
|
40
|
-
import"../../shared/stacks-esm-2mc7ebrm.js";
|
|
38
|
+
getBalance2,
|
|
39
|
+
getDataVar2,
|
|
40
|
+
multicall2
|
|
41
|
+
} from "../../shared/stacks-esm-t88hc019.js";
|
|
41
42
|
import {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
intToBigInt
|
|
46
|
-
} from "../../shared/stacks-esm-cvhazvhd.js";
|
|
43
|
+
getMapEntry2
|
|
44
|
+
} from "../../shared/stacks-esm-ea4m4bk7.js";
|
|
45
|
+
import"../../shared/stacks-esm-0pc6tmf0.js";
|
|
47
46
|
|
|
48
47
|
// src/pox5/constants.ts
|
|
49
48
|
var POX5_CONTRACT_NAME = "pox-5";
|
|
@@ -69,7 +68,8 @@ var POX5_EVENT_TOPICS = [
|
|
|
69
68
|
"grant-signer-key",
|
|
70
69
|
"revoke-signer-grant"
|
|
71
70
|
];
|
|
72
|
-
var POX5_ACTIVATION_BURN_HEIGHT_MAINNET =
|
|
71
|
+
var POX5_ACTIVATION_BURN_HEIGHT_MAINNET = EPOCH_4_ACTIVATION_BURN_HEIGHT_MAINNET2;
|
|
72
|
+
var MAINNET_PREPARE_CYCLE_LENGTH = 100;
|
|
73
73
|
var BOND_LENGTH_CYCLES = 12;
|
|
74
74
|
var BOND_GAP_CYCLES = 2;
|
|
75
75
|
var MAX_NUM_CYCLES = 96;
|
|
@@ -945,10 +945,10 @@ function pox5ContractId(client) {
|
|
|
945
945
|
}
|
|
946
946
|
function getPox5Contract(client) {
|
|
947
947
|
const [address, name] = pox5ContractId(client).split(".");
|
|
948
|
-
return
|
|
948
|
+
return getContract2({ client, address, name, abi: POX5_ABI });
|
|
949
949
|
}
|
|
950
950
|
function toBytes(input) {
|
|
951
|
-
return typeof input === "string" ?
|
|
951
|
+
return typeof input === "string" ? hexToBytes2(input) : input;
|
|
952
952
|
}
|
|
953
953
|
function optionalBytes(input) {
|
|
954
954
|
return input === undefined ? null : toBytes(input);
|
|
@@ -957,7 +957,7 @@ var MAX_LOCKUP_OUTPUTS = 10;
|
|
|
957
957
|
var MAX_LEAF_HASHES = 14;
|
|
958
958
|
function btcLockupArg(lockup) {
|
|
959
959
|
if ("sbtcSats" in lockup)
|
|
960
|
-
return { err:
|
|
960
|
+
return { err: intToBigInt2(lockup.sbtcSats) };
|
|
961
961
|
if (lockup.l1Outputs.length === 0) {
|
|
962
962
|
throw new Error("registerForBond: l1Outputs is empty — nothing would be locked");
|
|
963
963
|
}
|
|
@@ -973,15 +973,15 @@ function btcLockupArg(lockup) {
|
|
|
973
973
|
return {
|
|
974
974
|
ok: {
|
|
975
975
|
outputs: lockup.l1Outputs.map((o) => ({
|
|
976
|
-
height:
|
|
976
|
+
height: intToBigInt2(o.height),
|
|
977
977
|
tx: toBytes(o.tx),
|
|
978
|
-
outputIndex:
|
|
978
|
+
outputIndex: intToBigInt2(o.outputIndex),
|
|
979
979
|
header: toBytes(o.header),
|
|
980
980
|
leafHashes: o.leafHashes.map(toBytes),
|
|
981
|
-
txCount:
|
|
982
|
-
txIndex:
|
|
983
|
-
amount:
|
|
984
|
-
unlockBurnHeight:
|
|
981
|
+
txCount: intToBigInt2(o.txCount),
|
|
982
|
+
txIndex: intToBigInt2(o.txIndex),
|
|
983
|
+
amount: intToBigInt2(o.amount),
|
|
984
|
+
unlockBurnHeight: intToBigInt2(o.unlockBurnHeight)
|
|
985
985
|
})),
|
|
986
986
|
stakerUnlockBytes: toBytes(lockup.stakerUnlockBytes)
|
|
987
987
|
}
|
|
@@ -998,14 +998,14 @@ function setupBond(client, params) {
|
|
|
998
998
|
...tx
|
|
999
999
|
} = params;
|
|
1000
1000
|
return getPox5Contract(client).call.setupBond({
|
|
1001
|
-
bondIndex:
|
|
1002
|
-
targetRate:
|
|
1003
|
-
stxValueRatio:
|
|
1004
|
-
minUstxRatio:
|
|
1001
|
+
bondIndex: intToBigInt2(bondIndex),
|
|
1002
|
+
targetRate: intToBigInt2(targetRate),
|
|
1003
|
+
stxValueRatio: intToBigInt2(stxValueRatio),
|
|
1004
|
+
minUstxRatio: intToBigInt2(minUstxRatio),
|
|
1005
1005
|
earlyUnlockBytes: toBytes(earlyUnlockBytes),
|
|
1006
1006
|
allowlist: allowlist.map((a) => ({
|
|
1007
1007
|
staker: a.staker,
|
|
1008
|
-
maxSats:
|
|
1008
|
+
maxSats: intToBigInt2(a.maxSats)
|
|
1009
1009
|
}))
|
|
1010
1010
|
}, tx);
|
|
1011
1011
|
}
|
|
@@ -1019,9 +1019,9 @@ function registerForBond(client, params) {
|
|
|
1019
1019
|
...tx
|
|
1020
1020
|
} = params;
|
|
1021
1021
|
return getPox5Contract(client).call.registerForBond({
|
|
1022
|
-
bondIndex:
|
|
1022
|
+
bondIndex: intToBigInt2(bondIndex),
|
|
1023
1023
|
signerManager,
|
|
1024
|
-
amountUstx:
|
|
1024
|
+
amountUstx: intToBigInt2(amountUstx),
|
|
1025
1025
|
btcLockup: btcLockupArg(btcLockup),
|
|
1026
1026
|
signerCalldata: optionalBytes(signerCalldata)
|
|
1027
1027
|
}, tx);
|
|
@@ -1045,9 +1045,9 @@ function stake(client, params) {
|
|
|
1045
1045
|
} = params;
|
|
1046
1046
|
return getPox5Contract(client).call.stake({
|
|
1047
1047
|
signerManager,
|
|
1048
|
-
amountUstx:
|
|
1049
|
-
numCycles:
|
|
1050
|
-
startBurnHt:
|
|
1048
|
+
amountUstx: intToBigInt2(amountUstx),
|
|
1049
|
+
numCycles: intToBigInt2(numCycles),
|
|
1050
|
+
startBurnHt: intToBigInt2(startBurnHeight),
|
|
1051
1051
|
signerCalldata: optionalBytes(signerCalldata)
|
|
1052
1052
|
}, tx);
|
|
1053
1053
|
}
|
|
@@ -1063,8 +1063,8 @@ function stakeUpdate(client, params) {
|
|
|
1063
1063
|
return getPox5Contract(client).call.stakeUpdate({
|
|
1064
1064
|
signerManager,
|
|
1065
1065
|
oldSignerManager,
|
|
1066
|
-
cyclesToExtend:
|
|
1067
|
-
amountIncrease:
|
|
1066
|
+
cyclesToExtend: intToBigInt2(cyclesToExtend),
|
|
1067
|
+
amountIncrease: intToBigInt2(amountIncrease),
|
|
1068
1068
|
signerCalldata: optionalBytes(signerCalldata)
|
|
1069
1069
|
}, tx);
|
|
1070
1070
|
}
|
|
@@ -1074,7 +1074,7 @@ function unstake(client, params) {
|
|
|
1074
1074
|
}
|
|
1075
1075
|
function unstakeSbtc(client, params) {
|
|
1076
1076
|
const { signerManager, amountSats, ...tx } = params;
|
|
1077
|
-
return getPox5Contract(client).call.unstakeSbtc({ signerManager, amountToWithdrawalSats:
|
|
1077
|
+
return getPox5Contract(client).call.unstakeSbtc({ signerManager, amountToWithdrawalSats: intToBigInt2(amountSats) }, tx);
|
|
1078
1078
|
}
|
|
1079
1079
|
function announceL1EarlyExit(client, params) {
|
|
1080
1080
|
const { staker, oldSignerManager, ...tx } = params;
|
|
@@ -1082,21 +1082,21 @@ function announceL1EarlyExit(client, params) {
|
|
|
1082
1082
|
}
|
|
1083
1083
|
function calculateRewards(client, params) {
|
|
1084
1084
|
const { bondPeriods, ...tx } = params;
|
|
1085
|
-
return getPox5Contract(client).call.calculateRewards({ bondPeriods: bondPeriods.map(
|
|
1085
|
+
return getPox5Contract(client).call.calculateRewards({ bondPeriods: bondPeriods.map(intToBigInt2) }, tx);
|
|
1086
1086
|
}
|
|
1087
1087
|
function claimRewards(client, params) {
|
|
1088
1088
|
const { bondPeriods, rewardCycle, ...tx } = params;
|
|
1089
1089
|
return getPox5Contract(client).call.claimRewards({
|
|
1090
|
-
bondPeriods: bondPeriods.map(
|
|
1091
|
-
rewardCycle:
|
|
1090
|
+
bondPeriods: bondPeriods.map(intToBigInt2),
|
|
1091
|
+
rewardCycle: intToBigInt2(rewardCycle)
|
|
1092
1092
|
}, tx);
|
|
1093
1093
|
}
|
|
1094
1094
|
function claimStakerRewardsForSigner(client, params) {
|
|
1095
1095
|
const { staker, rewardCycle, bondIndex, ...tx } = params;
|
|
1096
1096
|
return getPox5Contract(client).call.claimStakerRewardsForSigner({
|
|
1097
1097
|
staker,
|
|
1098
|
-
rewardCycle:
|
|
1099
|
-
bondIndex: bondIndex === undefined ? null :
|
|
1098
|
+
rewardCycle: intToBigInt2(rewardCycle),
|
|
1099
|
+
bondIndex: bondIndex === undefined ? null : intToBigInt2(bondIndex)
|
|
1100
1100
|
}, tx);
|
|
1101
1101
|
}
|
|
1102
1102
|
function grantSignerKey(client, params) {
|
|
@@ -1104,7 +1104,7 @@ function grantSignerKey(client, params) {
|
|
|
1104
1104
|
return getPox5Contract(client).call.grantSignerKey({
|
|
1105
1105
|
signerKey: toBytes(signerKey),
|
|
1106
1106
|
signerManager,
|
|
1107
|
-
authId:
|
|
1107
|
+
authId: intToBigInt2(authId),
|
|
1108
1108
|
signerSig: toBytes(signerSig)
|
|
1109
1109
|
}, tx);
|
|
1110
1110
|
}
|
|
@@ -1135,18 +1135,18 @@ async function getBondMembership(client, staker) {
|
|
|
1135
1135
|
}
|
|
1136
1136
|
async function getProtocolBond(client, bondIndex) {
|
|
1137
1137
|
return await getPox5Contract(client).read.getProtocolBond({
|
|
1138
|
-
bondIndex:
|
|
1138
|
+
bondIndex: intToBigInt2(bondIndex)
|
|
1139
1139
|
});
|
|
1140
1140
|
}
|
|
1141
1141
|
async function getBondAllowance(client, bondIndex, staker) {
|
|
1142
1142
|
return await getPox5Contract(client).read.getBondAllowance({
|
|
1143
|
-
bondIndex:
|
|
1143
|
+
bondIndex: intToBigInt2(bondIndex),
|
|
1144
1144
|
staker
|
|
1145
1145
|
});
|
|
1146
1146
|
}
|
|
1147
1147
|
function getTotalSbtcStakedForBond(client, bondIndex) {
|
|
1148
1148
|
return getPox5Contract(client).read.getTotalSbtcStakedForBond({
|
|
1149
|
-
bondIndex:
|
|
1149
|
+
bondIndex: intToBigInt2(bondIndex)
|
|
1150
1150
|
});
|
|
1151
1151
|
}
|
|
1152
1152
|
function getStakerCustodiedSbtc(client, staker) {
|
|
@@ -1154,13 +1154,13 @@ function getStakerCustodiedSbtc(client, staker) {
|
|
|
1154
1154
|
}
|
|
1155
1155
|
function hasAnnouncedL1EarlyExit(client, bondIndex, staker) {
|
|
1156
1156
|
return getPox5Contract(client).read.hasAnnouncedL1EarlyExit({
|
|
1157
|
-
bondIndex:
|
|
1157
|
+
bondIndex: intToBigInt2(bondIndex),
|
|
1158
1158
|
staker
|
|
1159
1159
|
});
|
|
1160
1160
|
}
|
|
1161
1161
|
function getBondL1UnlockHeight(client, bondIndex) {
|
|
1162
1162
|
return getPox5Contract(client).read.getBondL1UnlockHeight({
|
|
1163
|
-
bondIndex:
|
|
1163
|
+
bondIndex: intToBigInt2(bondIndex)
|
|
1164
1164
|
});
|
|
1165
1165
|
}
|
|
1166
1166
|
async function getSignerInfo(client, signer) {
|
|
@@ -1183,15 +1183,15 @@ function getFirstPox5RewardCycle(client) {
|
|
|
1183
1183
|
function getEarned(client, params) {
|
|
1184
1184
|
return getPox5Contract(client).read.getEarned({
|
|
1185
1185
|
signer: params.signer,
|
|
1186
|
-
rewardCycle:
|
|
1187
|
-
bondIndex: params.bondIndex === undefined ? null :
|
|
1186
|
+
rewardCycle: intToBigInt2(params.rewardCycle),
|
|
1187
|
+
bondIndex: params.bondIndex === undefined ? null : intToBigInt2(params.bondIndex)
|
|
1188
1188
|
});
|
|
1189
1189
|
}
|
|
1190
1190
|
function getEarnedStakerRewards(client, params) {
|
|
1191
1191
|
return getPox5Contract(client).read.getEarnedStakerRewards({
|
|
1192
1192
|
signer: params.signer,
|
|
1193
|
-
rewardCycle:
|
|
1194
|
-
bondIndex: params.bondIndex === undefined ? null :
|
|
1193
|
+
rewardCycle: intToBigInt2(params.rewardCycle),
|
|
1194
|
+
bondIndex: params.bondIndex === undefined ? null : intToBigInt2(params.bondIndex),
|
|
1195
1195
|
staker: params.staker
|
|
1196
1196
|
});
|
|
1197
1197
|
}
|
|
@@ -1200,8 +1200,8 @@ function getLastRewardComputeHeight(client) {
|
|
|
1200
1200
|
}
|
|
1201
1201
|
function getTotalSharesStakedForCycle(client, rewardCycle, bondIndex) {
|
|
1202
1202
|
return getPox5Contract(client).read.getTotalSharesStakedForCycle({
|
|
1203
|
-
rewardCycle:
|
|
1204
|
-
bondIndex: bondIndex === undefined ? null :
|
|
1203
|
+
rewardCycle: intToBigInt2(rewardCycle),
|
|
1204
|
+
bondIndex: bondIndex === undefined ? null : intToBigInt2(bondIndex)
|
|
1205
1205
|
});
|
|
1206
1206
|
}
|
|
1207
1207
|
|
|
@@ -1285,11 +1285,11 @@ function finish(reasons) {
|
|
|
1285
1285
|
return { ok: false, reasons: unique };
|
|
1286
1286
|
}
|
|
1287
1287
|
function toBytes2(input) {
|
|
1288
|
-
return typeof input === "string" ?
|
|
1288
|
+
return typeof input === "string" ? hexToBytes2(input) : input;
|
|
1289
1289
|
}
|
|
1290
1290
|
function outpointKey(tx, outputIndex) {
|
|
1291
|
-
const hex = typeof tx === "string" ? tx.toLowerCase() :
|
|
1292
|
-
return `${hex}:${
|
|
1291
|
+
const hex = typeof tx === "string" ? tx.toLowerCase() : bytesToHex2(tx);
|
|
1292
|
+
return `${hex}:${intToBigInt2(outputIndex)}`;
|
|
1293
1293
|
}
|
|
1294
1294
|
async function readCycleClock(client) {
|
|
1295
1295
|
const info = await getPoxInfo(client);
|
|
@@ -1338,7 +1338,7 @@ function bondOverlaps(membership, newFirstCycle, clock) {
|
|
|
1338
1338
|
return start + BOND_LENGTH_CYCLES > newFirstCycle;
|
|
1339
1339
|
}
|
|
1340
1340
|
async function stxFloor(client, staker, amountUstx) {
|
|
1341
|
-
const balance = await
|
|
1341
|
+
const balance = await getBalance2(client, { address: staker });
|
|
1342
1342
|
if (balance < amountUstx)
|
|
1343
1343
|
return Pox5ErrorCode.InsufficientStx;
|
|
1344
1344
|
return;
|
|
@@ -1353,9 +1353,9 @@ function minUstxForSats(sats, stxValueRatio, minUstxRatio) {
|
|
|
1353
1353
|
}
|
|
1354
1354
|
async function eligibleStake(client, params) {
|
|
1355
1355
|
const reasons = [];
|
|
1356
|
-
const amountUstx =
|
|
1357
|
-
const numCycles =
|
|
1358
|
-
const startBurnHeight =
|
|
1356
|
+
const amountUstx = intToBigInt2(params.amountUstx);
|
|
1357
|
+
const numCycles = intToBigInt2(params.numCycles);
|
|
1358
|
+
const startBurnHeight = intToBigInt2(params.startBurnHeight);
|
|
1359
1359
|
const [clock, stakerInfo, membership, signerErrs, floor] = await Promise.all([
|
|
1360
1360
|
readCycleClock(client),
|
|
1361
1361
|
getStakerInfo(client, params.staker),
|
|
@@ -1396,18 +1396,18 @@ async function eligibleStake(client, params) {
|
|
|
1396
1396
|
}
|
|
1397
1397
|
async function eligibleRegisterForBond(client, params) {
|
|
1398
1398
|
const reasons = [];
|
|
1399
|
-
const amountUstx =
|
|
1399
|
+
const amountUstx = intToBigInt2(params.amountUstx);
|
|
1400
1400
|
const lockup = params.btcLockup;
|
|
1401
1401
|
let sats = 0n;
|
|
1402
1402
|
if ("sbtcSats" in lockup) {
|
|
1403
|
-
sats =
|
|
1403
|
+
sats = intToBigInt2(lockup.sbtcSats);
|
|
1404
1404
|
} else {
|
|
1405
1405
|
if (lockup.l1Outputs.length === 0) {
|
|
1406
1406
|
reasons.push(Pox5ErrorCode.InvalidLockupAmount);
|
|
1407
1407
|
}
|
|
1408
1408
|
const seen = new Set;
|
|
1409
1409
|
for (const output of lockup.l1Outputs) {
|
|
1410
|
-
sats +=
|
|
1410
|
+
sats += intToBigInt2(output.amount);
|
|
1411
1411
|
const key = outpointKey(output.tx, output.outputIndex);
|
|
1412
1412
|
if (seen.has(key))
|
|
1413
1413
|
reasons.push(Pox5ErrorCode.DuplicateLockupOutpoint);
|
|
@@ -1440,14 +1440,14 @@ async function eligibleRegisterForBond(client, params) {
|
|
|
1440
1440
|
reasons.push(Pox5ErrorCode.InsufficientStx);
|
|
1441
1441
|
}
|
|
1442
1442
|
if (clock) {
|
|
1443
|
-
const bondStart = bondPeriodToBurnHeight(Number(
|
|
1443
|
+
const bondStart = bondPeriodToBurnHeight(Number(intToBigInt2(params.bondIndex)), {
|
|
1444
1444
|
...clock.params,
|
|
1445
1445
|
firstBondPeriodCycle: clock.firstBondPeriodCycle
|
|
1446
1446
|
});
|
|
1447
1447
|
if (clock.burnHeight >= bondStart) {
|
|
1448
1448
|
reasons.push(Pox5ErrorCode.BondAlreadyStarted);
|
|
1449
1449
|
}
|
|
1450
|
-
const firstRewardCycle = bondPeriodToRewardCycle(Number(
|
|
1450
|
+
const firstRewardCycle = bondPeriodToRewardCycle(Number(intToBigInt2(params.bondIndex)), { ...clock.params, firstBondPeriodCycle: clock.firstBondPeriodCycle });
|
|
1451
1451
|
if (stakerInfo) {
|
|
1452
1452
|
const unlockCycle = Number(stakerInfo.firstRewardCycle) + Number(stakerInfo.numCycles);
|
|
1453
1453
|
if (unlockCycle > firstRewardCycle) {
|
|
@@ -1467,7 +1467,7 @@ async function eligibleRegisterForBond(client, params) {
|
|
|
1467
1467
|
if ("l1Outputs" in lockup && lockup.l1Outputs.length > 0) {
|
|
1468
1468
|
const minUnlock = await getBondL1UnlockHeight(client, params.bondIndex);
|
|
1469
1469
|
for (const output of lockup.l1Outputs) {
|
|
1470
|
-
const height =
|
|
1470
|
+
const height = intToBigInt2(output.unlockBurnHeight);
|
|
1471
1471
|
if (height < minUnlock || height >= BITCOIN_LOCKTIME_THRESHOLD) {
|
|
1472
1472
|
reasons.push(Pox5ErrorCode.InvalidUnlockHeight);
|
|
1473
1473
|
}
|
|
@@ -1492,7 +1492,7 @@ async function eligibleUnstake(client, params) {
|
|
|
1492
1492
|
}
|
|
1493
1493
|
async function eligibleUnstakeSbtc(client, params) {
|
|
1494
1494
|
const reasons = [];
|
|
1495
|
-
const amount =
|
|
1495
|
+
const amount = intToBigInt2(params.amountSats);
|
|
1496
1496
|
const [clock, membership] = await Promise.all([
|
|
1497
1497
|
readCycleClock(client),
|
|
1498
1498
|
getBondMembership(client, params.staker)
|
|
@@ -1516,7 +1516,7 @@ async function eligibleUnstakeSbtc(client, params) {
|
|
|
1516
1516
|
async function eligibleClaimRewards(client, params) {
|
|
1517
1517
|
const reasons = [];
|
|
1518
1518
|
const contract = pox5ContractId(client);
|
|
1519
|
-
const paused = await
|
|
1519
|
+
const paused = await getDataVar2(client, {
|
|
1520
1520
|
contract,
|
|
1521
1521
|
varName: "rewards-paused"
|
|
1522
1522
|
});
|
|
@@ -1544,13 +1544,13 @@ async function eligibleClaimRewards(client, params) {
|
|
|
1544
1544
|
}
|
|
1545
1545
|
async function eligibleGrantSignerKey(client, params) {
|
|
1546
1546
|
const reasons = [];
|
|
1547
|
-
const used = await
|
|
1547
|
+
const used = await getMapEntry2(client, {
|
|
1548
1548
|
contract: pox5ContractId(client),
|
|
1549
1549
|
mapName: "used-signer-key-grants",
|
|
1550
|
-
key:
|
|
1551
|
-
"signer-key":
|
|
1552
|
-
"signer-manager":
|
|
1553
|
-
"auth-id":
|
|
1550
|
+
key: Cl2.tuple({
|
|
1551
|
+
"signer-key": Cl2.buffer(toBytes2(params.signerKey)),
|
|
1552
|
+
"signer-manager": Cl2.principal(params.signerManager),
|
|
1553
|
+
"auth-id": Cl2.uint(intToBigInt2(params.authId))
|
|
1554
1554
|
})
|
|
1555
1555
|
});
|
|
1556
1556
|
if (used.type === "some")
|
|
@@ -1558,7 +1558,7 @@ async function eligibleGrantSignerKey(client, params) {
|
|
|
1558
1558
|
return finish(reasons);
|
|
1559
1559
|
}
|
|
1560
1560
|
async function eligibleSetBondAdmin(client, params) {
|
|
1561
|
-
const admin = await
|
|
1561
|
+
const admin = await getDataVar2(client, {
|
|
1562
1562
|
contract: pox5ContractId(client),
|
|
1563
1563
|
varName: "bond-admin"
|
|
1564
1564
|
});
|
|
@@ -1568,7 +1568,7 @@ async function eligibleSetBondAdmin(client, params) {
|
|
|
1568
1568
|
return { ok: true };
|
|
1569
1569
|
}
|
|
1570
1570
|
async function eligiblePauseRewards(client, params) {
|
|
1571
|
-
const admin = await
|
|
1571
|
+
const admin = await getDataVar2(client, {
|
|
1572
1572
|
contract: pox5ContractId(client),
|
|
1573
1573
|
varName: "pause-admin"
|
|
1574
1574
|
});
|
|
@@ -1610,7 +1610,7 @@ function pushScriptBytes(bytes) {
|
|
|
1610
1610
|
prefix = Uint8Array.of(76, len);
|
|
1611
1611
|
else
|
|
1612
1612
|
prefix = Uint8Array.of(77, len & 255, len >> 8);
|
|
1613
|
-
return
|
|
1613
|
+
return concatBytes2(prefix, bytes);
|
|
1614
1614
|
}
|
|
1615
1615
|
function pushCScriptNum(n) {
|
|
1616
1616
|
const big = typeof n === "bigint" ? n : BigInt(n);
|
|
@@ -1621,13 +1621,13 @@ function pushCScriptNum(n) {
|
|
|
1621
1621
|
return pushScriptBytes(serializeCScriptNum(big));
|
|
1622
1622
|
}
|
|
1623
1623
|
function stakerConsensusBuff(stxAddress) {
|
|
1624
|
-
return
|
|
1624
|
+
return serializeCVBytes2(Cl2.principal(stxAddress));
|
|
1625
1625
|
}
|
|
1626
1626
|
function stakerPreimage(stxAddress) {
|
|
1627
1627
|
return sha256(stakerConsensusBuff(stxAddress));
|
|
1628
1628
|
}
|
|
1629
1629
|
function toBytes3(input) {
|
|
1630
|
-
return typeof input === "string" ?
|
|
1630
|
+
return typeof input === "string" ? hexToBytes2(input) : input;
|
|
1631
1631
|
}
|
|
1632
1632
|
function buildLockupScript(opts) {
|
|
1633
1633
|
const height = BigInt(opts.unlockBurnHeight);
|
|
@@ -1638,10 +1638,10 @@ function buildLockupScript(opts) {
|
|
|
1638
1638
|
throw new Error("unlockBurnHeight >= 500,000,000 would be read by Bitcoin as a timestamp (contract rejects it)");
|
|
1639
1639
|
}
|
|
1640
1640
|
const stakerHash = sha256(stakerPreimage(opts.stxAddress));
|
|
1641
|
-
return
|
|
1641
|
+
return concatBytes2(Uint8Array.of(99), pushCScriptNum(height), Uint8Array.of(177, 103), hexToBytes2("82012088a820"), stakerHash, Uint8Array.of(136), toBytes3(opts.earlyUnlockBytes), Uint8Array.of(104, 105), toBytes3(opts.stakerUnlockBytes));
|
|
1642
1642
|
}
|
|
1643
1643
|
function buildLockupOutputScript(opts) {
|
|
1644
|
-
return
|
|
1644
|
+
return concatBytes2(Uint8Array.of(0, 32), sha256(buildLockupScript(opts)));
|
|
1645
1645
|
}
|
|
1646
1646
|
function buildLockupAddress(opts, network = "mainnet") {
|
|
1647
1647
|
const hash = sha256(buildLockupScript(opts));
|
|
@@ -1658,7 +1658,7 @@ function buildDefaultStakerUnlockBytes(publicKey) {
|
|
|
1658
1658
|
if (prefix !== 2 && prefix !== 3) {
|
|
1659
1659
|
throw new Error(`Expected compressed pubkey prefix 0x02 or 0x03, got ${prefix}`);
|
|
1660
1660
|
}
|
|
1661
|
-
return
|
|
1661
|
+
return concatBytes2(pushScriptBytes(pubkey), Uint8Array.of(172));
|
|
1662
1662
|
}
|
|
1663
1663
|
function buildRegisterMetadata(opts) {
|
|
1664
1664
|
const unlockHeight = computeBondUnlockHeight(opts.bondIndex, opts.cycle);
|
|
@@ -1680,16 +1680,16 @@ function buildRegisterMetadata(opts) {
|
|
|
1680
1680
|
// src/pox5/grants.ts
|
|
1681
1681
|
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
1682
1682
|
function computeSignerGrantHash(opts) {
|
|
1683
|
-
return
|
|
1684
|
-
domain:
|
|
1685
|
-
name:
|
|
1686
|
-
version:
|
|
1687
|
-
"chain-id":
|
|
1683
|
+
return structuredDataHash2({
|
|
1684
|
+
domain: Cl2.tuple({
|
|
1685
|
+
name: Cl2.stringAscii(POX5_SIGNER_DOMAIN.name),
|
|
1686
|
+
version: Cl2.stringAscii(POX5_SIGNER_DOMAIN.version),
|
|
1687
|
+
"chain-id": Cl2.uint(opts.chainId)
|
|
1688
1688
|
}),
|
|
1689
|
-
message:
|
|
1690
|
-
topic:
|
|
1691
|
-
"signer-manager":
|
|
1692
|
-
"auth-id":
|
|
1689
|
+
message: Cl2.tuple({
|
|
1690
|
+
topic: Cl2.stringAscii("grant-authorization"),
|
|
1691
|
+
"signer-manager": Cl2.principal(opts.signerManager),
|
|
1692
|
+
"auth-id": Cl2.uint(opts.authId)
|
|
1693
1693
|
})
|
|
1694
1694
|
});
|
|
1695
1695
|
}
|
|
@@ -1697,17 +1697,17 @@ async function signSignerGrant(account, opts) {
|
|
|
1697
1697
|
const vrs = await account.sign(computeSignerGrantHash(opts));
|
|
1698
1698
|
if (vrs.length !== 65)
|
|
1699
1699
|
throw new Error(`Expected 65-byte recoverable signature, got ${vrs.length}`);
|
|
1700
|
-
return
|
|
1700
|
+
return bytesToHex2(concatBytes2(vrs.slice(1), vrs.slice(0, 1)));
|
|
1701
1701
|
}
|
|
1702
1702
|
function verifySignerGrant(opts) {
|
|
1703
1703
|
try {
|
|
1704
|
-
const sig = typeof opts.signature === "string" ?
|
|
1704
|
+
const sig = typeof opts.signature === "string" ? hexToBytes2(opts.signature) : opts.signature;
|
|
1705
1705
|
if (sig.length !== 65)
|
|
1706
1706
|
return false;
|
|
1707
|
-
const pubkey = typeof opts.publicKey === "string" ?
|
|
1707
|
+
const pubkey = typeof opts.publicKey === "string" ? hexToBytes2(opts.publicKey) : opts.publicKey;
|
|
1708
1708
|
const hash = computeSignerGrantHash(opts);
|
|
1709
1709
|
const recovered = secp256k1.Signature.fromBytes(sig.slice(0, 64)).addRecoveryBit(sig[64]).recoverPublicKey(hash).toBytes(true);
|
|
1710
|
-
return
|
|
1710
|
+
return bytesToHex2(recovered) === bytesToHex2(pubkey);
|
|
1711
1711
|
} catch {
|
|
1712
1712
|
return false;
|
|
1713
1713
|
}
|
|
@@ -1716,15 +1716,15 @@ function verifySignerGrant(opts) {
|
|
|
1716
1716
|
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
1717
1717
|
var MAX_LEAF_HASHES2 = 14;
|
|
1718
1718
|
function lockupScriptPubKey(lockScript) {
|
|
1719
|
-
return
|
|
1719
|
+
return concatBytes2(Uint8Array.of(0, 32), sha2562(lockScript));
|
|
1720
1720
|
}
|
|
1721
1721
|
function scriptsEqual(a, b) {
|
|
1722
|
-
return
|
|
1722
|
+
return bytesToHex2(a) === bytesToHex2(b);
|
|
1723
1723
|
}
|
|
1724
1724
|
function spvProofToL1LockupOutput(opts) {
|
|
1725
1725
|
const { proof, lockScript, unlockBurnHeight } = opts;
|
|
1726
|
-
const tx =
|
|
1727
|
-
const parsed =
|
|
1726
|
+
const tx = stripWitness2(proof.rawTx);
|
|
1727
|
+
const parsed = parseBitcoinTx2(proof.rawTx);
|
|
1728
1728
|
const expected = lockupScriptPubKey(lockScript);
|
|
1729
1729
|
let outputIndex = opts.vout ?? proof.vout;
|
|
1730
1730
|
if (outputIndex === undefined) {
|
|
@@ -1763,7 +1763,7 @@ function spvProofToL1LockupOutput(opts) {
|
|
|
1763
1763
|
};
|
|
1764
1764
|
}
|
|
1765
1765
|
async function buildPox5LockProof(opts) {
|
|
1766
|
-
const proof = await
|
|
1766
|
+
const proof = await buildTxProof2(opts.source, {
|
|
1767
1767
|
txid: opts.txid,
|
|
1768
1768
|
vout: opts.vout
|
|
1769
1769
|
});
|
|
@@ -1796,16 +1796,16 @@ function btcNetworkFrom(network) {
|
|
|
1796
1796
|
return REGTEST_NETWORK;
|
|
1797
1797
|
}
|
|
1798
1798
|
function toBytes4(value) {
|
|
1799
|
-
return typeof value === "string" ?
|
|
1799
|
+
return typeof value === "string" ? hexToBytes2(value) : value;
|
|
1800
1800
|
}
|
|
1801
1801
|
function toPrivBytes(value) {
|
|
1802
1802
|
return toBytes4(value).slice(0, 32);
|
|
1803
1803
|
}
|
|
1804
1804
|
function bytesEqual(a, b) {
|
|
1805
|
-
return
|
|
1805
|
+
return bytesToHex2(a) === bytesToHex2(b);
|
|
1806
1806
|
}
|
|
1807
1807
|
function scriptToWshOutput(lockScript) {
|
|
1808
|
-
return
|
|
1808
|
+
return concatBytes2(Uint8Array.of(0, 32), sha2563(lockScript));
|
|
1809
1809
|
}
|
|
1810
1810
|
var SCAFFOLD_PREFIX_LEN = 10;
|
|
1811
1811
|
function decodeLockScript(script) {
|
|
@@ -1829,9 +1829,9 @@ function buildReclaim(opts) {
|
|
|
1829
1829
|
const network = btcNetworkFrom(opts.network);
|
|
1830
1830
|
const lockScript = toBytes4(opts.lockScript);
|
|
1831
1831
|
const { unlockHeight: scriptHeight } = decodeLockScript(lockScript);
|
|
1832
|
-
const amount =
|
|
1832
|
+
const amount = intToBigInt2(opts.utxo.value);
|
|
1833
1833
|
const { address } = opts.output;
|
|
1834
|
-
const feeSats =
|
|
1834
|
+
const feeSats = intToBigInt2(opts.output.feeSats);
|
|
1835
1835
|
if (feeSats < 0n) {
|
|
1836
1836
|
throw new Error(`buildReclaim: feeSats (${feeSats}) must be non-negative`);
|
|
1837
1837
|
}
|
|
@@ -1865,7 +1865,7 @@ function buildReclaim(opts) {
|
|
|
1865
1865
|
function computeReclaimSighash(tx, opts) {
|
|
1866
1866
|
const input = tx.getInput(0);
|
|
1867
1867
|
const witnessScript = opts?.witnessScript != null ? toBytes4(opts.witnessScript) : input.witnessScript;
|
|
1868
|
-
const amount = opts?.amountSats != null ?
|
|
1868
|
+
const amount = opts?.amountSats != null ? intToBigInt2(opts.amountSats) : input.witnessUtxo?.amount;
|
|
1869
1869
|
if (!witnessScript || amount == null) {
|
|
1870
1870
|
throw new Error("computeReclaimSighash: need witnessScript + amount (pass `opts` for a raw-hex tx)");
|
|
1871
1871
|
}
|
|
@@ -1873,7 +1873,7 @@ function computeReclaimSighash(tx, opts) {
|
|
|
1873
1873
|
}
|
|
1874
1874
|
function signReclaim(sighash, privateKey, opts) {
|
|
1875
1875
|
const priv = toPrivBytes(privateKey);
|
|
1876
|
-
return
|
|
1876
|
+
return concatBytes2(signECDSA(sighash, priv, opts?.lowR ?? false), Uint8Array.of(SIGHASH_ALL));
|
|
1877
1877
|
}
|
|
1878
1878
|
function finalizeReclaim(opts) {
|
|
1879
1879
|
const { tx } = opts;
|
|
@@ -1941,23 +1941,23 @@ function reclaim(opts) {
|
|
|
1941
1941
|
// src/pox5/extension.ts
|
|
1942
1942
|
async function getStakerState(client, staker) {
|
|
1943
1943
|
const contract = pox5ContractId(client);
|
|
1944
|
-
const results = await
|
|
1944
|
+
const results = await multicall2(client, {
|
|
1945
1945
|
allowFailure: false,
|
|
1946
1946
|
calls: [
|
|
1947
1947
|
{
|
|
1948
1948
|
contract,
|
|
1949
1949
|
functionName: "get-staker-info",
|
|
1950
|
-
args: [
|
|
1950
|
+
args: [Cl2.principal(staker)]
|
|
1951
1951
|
},
|
|
1952
1952
|
{
|
|
1953
1953
|
contract,
|
|
1954
1954
|
functionName: "get-bond-membership",
|
|
1955
|
-
args: [
|
|
1955
|
+
args: [Cl2.principal(staker)]
|
|
1956
1956
|
},
|
|
1957
1957
|
{
|
|
1958
1958
|
contract,
|
|
1959
1959
|
functionName: "get-staker-custodied-sbtc",
|
|
1960
|
-
args: [
|
|
1960
|
+
args: [Cl2.principal(staker)]
|
|
1961
1961
|
},
|
|
1962
1962
|
{ contract, functionName: "current-pox-reward-cycle", args: [] }
|
|
1963
1963
|
]
|
|
@@ -2024,17 +2024,17 @@ function pox5() {
|
|
|
2024
2024
|
}
|
|
2025
2025
|
// src/pox5/signerCalldata.ts
|
|
2026
2026
|
function buildSignerCalldata(opts) {
|
|
2027
|
-
const repr = canonicalizeBtcAddress(typeof opts.poxAddress === "string" ?
|
|
2028
|
-
return
|
|
2029
|
-
"pox-addr":
|
|
2030
|
-
version:
|
|
2031
|
-
hashbytes:
|
|
2027
|
+
const repr = canonicalizeBtcAddress(typeof opts.poxAddress === "string" ? parseBtcAddress2(opts.poxAddress) : opts.poxAddress);
|
|
2028
|
+
return serializeCVBytes2(Cl2.tuple({
|
|
2029
|
+
"pox-addr": Cl2.tuple({
|
|
2030
|
+
version: Cl2.buffer(Uint8Array.of(repr.version)),
|
|
2031
|
+
hashbytes: Cl2.buffer(repr.hashbytes)
|
|
2032
2032
|
}),
|
|
2033
|
-
"max-fee":
|
|
2033
|
+
"max-fee": Cl2.uint(opts.maxFeeSats)
|
|
2034
2034
|
}));
|
|
2035
2035
|
}
|
|
2036
2036
|
function parseSignerCalldata(calldata) {
|
|
2037
|
-
const cv =
|
|
2037
|
+
const cv = deserializeCVBytes2(calldata);
|
|
2038
2038
|
if (cv.type !== "tuple") {
|
|
2039
2039
|
throw new Error("signer calldata is not a Clarity tuple");
|
|
2040
2040
|
}
|
|
@@ -2054,7 +2054,7 @@ function parseSignerCalldata(calldata) {
|
|
|
2054
2054
|
if (!hashCv || hashCv.type !== "buffer") {
|
|
2055
2055
|
throw new Error("signer calldata pox-addr missing hashbytes buffer");
|
|
2056
2056
|
}
|
|
2057
|
-
const versionBytes =
|
|
2057
|
+
const versionBytes = hexToBytes2(versionCv.value);
|
|
2058
2058
|
if (versionBytes.length !== 1) {
|
|
2059
2059
|
throw new Error(`signer calldata version must be buff 1, got ${versionBytes.length}`);
|
|
2060
2060
|
}
|
|
@@ -2065,79 +2065,80 @@ function parseSignerCalldata(calldata) {
|
|
|
2065
2065
|
return {
|
|
2066
2066
|
poxAddress: canonicalizeBtcAddress({
|
|
2067
2067
|
version,
|
|
2068
|
-
hashbytes:
|
|
2068
|
+
hashbytes: hexToBytes2(hashCv.value)
|
|
2069
2069
|
}),
|
|
2070
2070
|
maxFeeSats: maxFee.value
|
|
2071
2071
|
};
|
|
2072
2072
|
}
|
|
2073
2073
|
export {
|
|
2074
|
-
|
|
2075
|
-
stringifyBtcAddress,
|
|
2076
|
-
stakerPreimage,
|
|
2077
|
-
stakerConsensusBuff,
|
|
2078
|
-
spvProofToL1LockupOutput,
|
|
2079
|
-
signSignerGrant,
|
|
2080
|
-
signReclaim,
|
|
2081
|
-
serializeCScriptNum,
|
|
2082
|
-
rewardCycleToBurnHeight,
|
|
2083
|
-
reclaim,
|
|
2084
|
-
pushScriptBytes,
|
|
2085
|
-
pushCScriptNum,
|
|
2086
|
-
pox5ContractId,
|
|
2087
|
-
pox5,
|
|
2088
|
-
parseSignerCalldata,
|
|
2089
|
-
parsePox5Error,
|
|
2090
|
-
parseBtcAddress,
|
|
2091
|
-
isPox5Active,
|
|
2092
|
-
isInPreparePhase,
|
|
2093
|
-
getPoxInfo,
|
|
2094
|
-
getPox5Activation,
|
|
2095
|
-
finalizeReclaim,
|
|
2096
|
-
eligibleUnstakeSbtc,
|
|
2097
|
-
eligibleUnstake,
|
|
2098
|
-
eligibleStake,
|
|
2099
|
-
eligibleSetBondAdmin,
|
|
2100
|
-
eligibleRegisterForBond,
|
|
2101
|
-
eligiblePauseRewards,
|
|
2102
|
-
eligibleGrantSignerKey,
|
|
2103
|
-
eligibleClaimRewards,
|
|
2104
|
-
distributionCycleToBurnHeight,
|
|
2105
|
-
describePox5Error,
|
|
2106
|
-
currentDistributionCycle,
|
|
2107
|
-
computeSignerGrantHash,
|
|
2108
|
-
computeReclaimSighash,
|
|
2109
|
-
computeBondUnlockHeight,
|
|
2110
|
-
burnHeightToRewardCycle,
|
|
2111
|
-
burnHeightToDistributionIndex,
|
|
2112
|
-
buildSignerCalldata,
|
|
2113
|
-
buildRegisterMetadata,
|
|
2114
|
-
buildReclaim,
|
|
2115
|
-
buildPox5LockProof,
|
|
2116
|
-
buildLockupScript,
|
|
2117
|
-
buildLockupOutputScript,
|
|
2118
|
-
buildLockupAddress,
|
|
2119
|
-
buildDefaultStakerUnlockBytes,
|
|
2120
|
-
bondUnlockCycle,
|
|
2121
|
-
bondStatusAtHeight,
|
|
2122
|
-
bondPhaseAtHeight,
|
|
2123
|
-
bondPeriodToRewardCycle,
|
|
2124
|
-
bondPeriodToBurnHeight,
|
|
2125
|
-
assertPox5Active,
|
|
2126
|
-
Pox5ErrorCode,
|
|
2127
|
-
POX5_SIGNER_DOMAIN,
|
|
2128
|
-
POX5_EVENT_TOPICS,
|
|
2129
|
-
POX5_ERROR_NAMES,
|
|
2130
|
-
POX5_CONTRACT_NAME,
|
|
2131
|
-
POX5_CONTRACT_ID_MAINNET,
|
|
2132
|
-
POX5_ACTIVATION_BURN_HEIGHT_MAINNET,
|
|
2133
|
-
POX5_ABI,
|
|
2134
|
-
MAX_NUM_CYCLES,
|
|
2135
|
-
C_SCRIPT_NUM_MAX,
|
|
2136
|
-
BtcAddress,
|
|
2137
|
-
BOND_LENGTH_CYCLES,
|
|
2074
|
+
BITCOIN_LOCKTIME_THRESHOLD,
|
|
2138
2075
|
BOND_GAP_CYCLES,
|
|
2139
|
-
|
|
2076
|
+
BOND_LENGTH_CYCLES,
|
|
2077
|
+
BtcAddress2 as BtcAddress,
|
|
2078
|
+
C_SCRIPT_NUM_MAX,
|
|
2079
|
+
MAINNET_PREPARE_CYCLE_LENGTH,
|
|
2080
|
+
MAX_NUM_CYCLES,
|
|
2081
|
+
POX5_ABI,
|
|
2082
|
+
POX5_ACTIVATION_BURN_HEIGHT_MAINNET,
|
|
2083
|
+
POX5_CONTRACT_ID_MAINNET,
|
|
2084
|
+
POX5_CONTRACT_NAME,
|
|
2085
|
+
POX5_ERROR_NAMES,
|
|
2086
|
+
POX5_EVENT_TOPICS,
|
|
2087
|
+
POX5_SIGNER_DOMAIN,
|
|
2088
|
+
Pox5ErrorCode,
|
|
2089
|
+
assertPox5Active,
|
|
2090
|
+
bondPeriodToBurnHeight,
|
|
2091
|
+
bondPeriodToRewardCycle,
|
|
2092
|
+
bondPhaseAtHeight,
|
|
2093
|
+
bondStatusAtHeight,
|
|
2094
|
+
bondUnlockCycle,
|
|
2095
|
+
buildDefaultStakerUnlockBytes,
|
|
2096
|
+
buildLockupAddress,
|
|
2097
|
+
buildLockupOutputScript,
|
|
2098
|
+
buildLockupScript,
|
|
2099
|
+
buildPox5LockProof,
|
|
2100
|
+
buildReclaim,
|
|
2101
|
+
buildRegisterMetadata,
|
|
2102
|
+
buildSignerCalldata,
|
|
2103
|
+
burnHeightToDistributionIndex,
|
|
2104
|
+
burnHeightToRewardCycle,
|
|
2105
|
+
computeBondUnlockHeight,
|
|
2106
|
+
computeReclaimSighash,
|
|
2107
|
+
computeSignerGrantHash,
|
|
2108
|
+
currentDistributionCycle,
|
|
2109
|
+
describePox5Error,
|
|
2110
|
+
distributionCycleToBurnHeight,
|
|
2111
|
+
eligibleClaimRewards,
|
|
2112
|
+
eligibleGrantSignerKey,
|
|
2113
|
+
eligiblePauseRewards,
|
|
2114
|
+
eligibleRegisterForBond,
|
|
2115
|
+
eligibleSetBondAdmin,
|
|
2116
|
+
eligibleStake,
|
|
2117
|
+
eligibleUnstake,
|
|
2118
|
+
eligibleUnstakeSbtc,
|
|
2119
|
+
finalizeReclaim,
|
|
2120
|
+
getPox5Activation,
|
|
2121
|
+
getPoxInfo,
|
|
2122
|
+
isInPreparePhase,
|
|
2123
|
+
isPox5Active,
|
|
2124
|
+
parseBtcAddress2 as parseBtcAddress,
|
|
2125
|
+
parsePox5Error,
|
|
2126
|
+
parseSignerCalldata,
|
|
2127
|
+
pox5,
|
|
2128
|
+
pox5ContractId,
|
|
2129
|
+
pushCScriptNum,
|
|
2130
|
+
pushScriptBytes,
|
|
2131
|
+
reclaim,
|
|
2132
|
+
rewardCycleToBurnHeight,
|
|
2133
|
+
serializeCScriptNum,
|
|
2134
|
+
signReclaim,
|
|
2135
|
+
signSignerGrant,
|
|
2136
|
+
spvProofToL1LockupOutput,
|
|
2137
|
+
stakerConsensusBuff,
|
|
2138
|
+
stakerPreimage,
|
|
2139
|
+
stringifyBtcAddress2 as stringifyBtcAddress,
|
|
2140
|
+
verifySignerGrant
|
|
2140
2141
|
};
|
|
2141
2142
|
|
|
2142
|
-
//# debugId=
|
|
2143
|
+
//# debugId=ACA0F7197C35CC4B64756E2164756E21
|
|
2143
2144
|
//# sourceMappingURL=index.js.map
|