@secondlayer/stacks 2.11.0 → 2.13.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 +47 -0
- package/dist/shared/{stacks-v150hffx.js → stacks-01pbr7gf.js} +13 -12
- package/dist/shared/stacks-01pbr7gf.js.map +11 -0
- package/dist/shared/stacks-0cdm20eh.js +225 -0
- package/dist/shared/stacks-0cdm20eh.js.map +11 -0
- package/dist/shared/{stacks-hxm7r5ay.cjs → stacks-44y18a8e.cjs} +3 -10
- package/dist/shared/stacks-44y18a8e.cjs.map +10 -0
- package/dist/shared/{stacks-7nvbv61d.js → stacks-59xy6t1p.js} +27 -25
- package/dist/shared/{stacks-7nvbv61d.js.map → stacks-59xy6t1p.js.map} +6 -6
- package/dist/shared/{stacks-63xbc6cj.js → stacks-6n2m9hyk.js} +3 -3
- package/dist/shared/stacks-bnbdqznq.cjs +211 -0
- package/dist/shared/stacks-bnbdqznq.cjs.map +11 -0
- package/dist/shared/stacks-esn3wcw5.cjs +416 -0
- package/dist/shared/stacks-esn3wcw5.cjs.map +18 -0
- package/dist/shared/{stacks-3kmj5yre.js → stacks-g67f4w1d.js} +5 -12
- package/dist/shared/stacks-g67f4w1d.js.map +10 -0
- package/dist/shared/stacks-kjg7fw4y.js +434 -0
- package/dist/shared/stacks-kjg7fw4y.js.map +18 -0
- package/dist/shared/{stacks-maamjqma.cjs → stacks-tbv5p6pn.cjs} +7 -9
- package/dist/shared/stacks-tbv5p6pn.cjs.map +11 -0
- package/dist/shared/{stacks-k5an9zcw.cjs → stacks-y5epf0sb.cjs} +19 -22
- package/dist/shared/{stacks-k5an9zcw.cjs.map → stacks-y5epf0sb.cjs.map} +6 -6
- package/dist/src/accounts/index.cjs +28 -1
- package/dist/src/accounts/index.cjs.map +4 -3
- package/dist/src/accounts/index.d.cts +23 -1
- package/dist/src/accounts/index.d.ts +23 -1
- package/dist/src/accounts/index.js +33 -1
- package/dist/src/accounts/index.js.map +4 -3
- package/dist/src/actions/index.cjs +8 -1
- package/dist/src/actions/index.cjs.map +1 -1
- package/dist/src/actions/index.d.cts +140 -6
- package/dist/src/actions/index.d.ts +140 -6
- package/dist/src/actions/index.js +22 -8
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.cjs +4 -175
- package/dist/src/bitcoin/index.cjs.map +4 -6
- package/dist/src/bitcoin/index.d.cts +18 -2
- package/dist/src/bitcoin/index.d.ts +18 -2
- package/dist/src/bitcoin/index.js +18 -181
- package/dist/src/bitcoin/index.js.map +4 -6
- package/dist/src/bns/index.js +3 -3
- package/dist/src/index.cjs +10 -1
- package/dist/src/index.cjs.map +3 -3
- package/dist/src/index.d.cts +167 -9
- package/dist/src/index.d.ts +167 -9
- package/dist/src/index.js +23 -7
- package/dist/src/index.js.map +3 -3
- package/dist/src/pox/index.js +3 -3
- package/dist/src/sbtc/index.cjs +49 -7
- package/dist/src/sbtc/index.cjs.map +6 -6
- package/dist/src/sbtc/index.d.cts +8 -2
- package/dist/src/sbtc/index.d.ts +8 -2
- package/dist/src/sbtc/index.js +56 -10
- package/dist/src/sbtc/index.js.map +6 -6
- package/dist/src/stackingdao/index.js +3 -3
- package/dist/src/tools/index.cjs +194 -13
- package/dist/src/tools/index.cjs.map +12 -9
- package/dist/src/tools/index.js +194 -13
- package/dist/src/tools/index.js.map +12 -9
- package/dist/src/x402/index.cjs +5 -2
- package/dist/src/x402/index.cjs.map +3 -3
- package/dist/src/x402/index.d.cts +36 -0
- package/dist/src/x402/index.d.ts +36 -0
- package/dist/src/x402/index.js +7 -4
- package/dist/src/x402/index.js.map +3 -3
- package/package.json +2 -4
- package/dist/shared/stacks-3kmj5yre.js.map +0 -10
- package/dist/shared/stacks-502j0efj.js +0 -210
- package/dist/shared/stacks-502j0efj.js.map +0 -15
- package/dist/shared/stacks-hxm7r5ay.cjs.map +0 -10
- package/dist/shared/stacks-maamjqma.cjs.map +0 -11
- package/dist/shared/stacks-v150hffx.js.map +0 -11
- package/dist/shared/stacks-xmsms921.cjs +0 -196
- package/dist/shared/stacks-xmsms921.cjs.map +0 -15
- /package/dist/shared/{stacks-63xbc6cj.js.map → stacks-6n2m9hyk.js.map} +0 -0
package/dist/src/tools/index.cjs
CHANGED
|
@@ -41,7 +41,7 @@ var __export = (target, all) => {
|
|
|
41
41
|
var exports_tools = {};
|
|
42
42
|
__export(exports_tools, {
|
|
43
43
|
readContract: () => readContract2,
|
|
44
|
-
getTransaction: () =>
|
|
44
|
+
getTransaction: () => getTransaction2,
|
|
45
45
|
getStxBalance: () => getStxBalance,
|
|
46
46
|
getNftHoldings: () => getNftHoldings,
|
|
47
47
|
getMempoolStats: () => getMempoolStats,
|
|
@@ -1489,10 +1489,39 @@ class BroadcastError extends BaseError {
|
|
|
1489
1489
|
name = "BroadcastError";
|
|
1490
1490
|
txid;
|
|
1491
1491
|
reason;
|
|
1492
|
+
reasonData;
|
|
1492
1493
|
constructor(message, options) {
|
|
1493
1494
|
super(message, options);
|
|
1494
1495
|
this.txid = options?.txid;
|
|
1495
1496
|
this.reason = options?.reason;
|
|
1497
|
+
this.reasonData = options?.reasonData;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
class TransactionAbortedError extends BaseError {
|
|
1502
|
+
name = "TransactionAbortedError";
|
|
1503
|
+
receipt;
|
|
1504
|
+
constructor(message, options) {
|
|
1505
|
+
super(message, options);
|
|
1506
|
+
this.receipt = options.receipt;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
class TransactionDroppedError extends BaseError {
|
|
1511
|
+
name = "TransactionDroppedError";
|
|
1512
|
+
txid;
|
|
1513
|
+
constructor(message, options) {
|
|
1514
|
+
super(message, options);
|
|
1515
|
+
this.txid = options.txid;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
class WaitForTransactionTimeoutError extends BaseError {
|
|
1520
|
+
name = "WaitForTransactionTimeoutError";
|
|
1521
|
+
txid;
|
|
1522
|
+
constructor(message, options) {
|
|
1523
|
+
super(message, options);
|
|
1524
|
+
this.txid = options.txid;
|
|
1496
1525
|
}
|
|
1497
1526
|
}
|
|
1498
1527
|
|
|
@@ -1508,6 +1537,107 @@ async function getNonce(client, params) {
|
|
|
1508
1537
|
return BigInt(nonce);
|
|
1509
1538
|
}
|
|
1510
1539
|
|
|
1540
|
+
// src/actions/public/txSources.ts
|
|
1541
|
+
function normalizeTxid(txid2) {
|
|
1542
|
+
return txid2.startsWith("0x") ? txid2 : `0x${txid2}`;
|
|
1543
|
+
}
|
|
1544
|
+
function decodeResultHex(hex) {
|
|
1545
|
+
if (!hex)
|
|
1546
|
+
return {};
|
|
1547
|
+
try {
|
|
1548
|
+
return { result: deserializeCVBytes(hex), resultHex: hex };
|
|
1549
|
+
} catch {
|
|
1550
|
+
return { resultHex: hex };
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
function normalizeStatus(txStatus) {
|
|
1554
|
+
switch (txStatus) {
|
|
1555
|
+
case "pending":
|
|
1556
|
+
case "success":
|
|
1557
|
+
case "abort_by_response":
|
|
1558
|
+
case "abort_by_post_condition":
|
|
1559
|
+
return txStatus;
|
|
1560
|
+
default:
|
|
1561
|
+
return txStatus.startsWith("dropped") ? "dropped" : undefined;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
function extendedApiSource() {
|
|
1565
|
+
return {
|
|
1566
|
+
async get({ client, txid: txid2 }) {
|
|
1567
|
+
const data = await client.request(`/extended/v1/tx/${normalizeTxid(txid2)}`, { method: "GET" });
|
|
1568
|
+
const txStatus = typeof data?.tx_status === "string" ? data.tx_status : undefined;
|
|
1569
|
+
if (!txStatus)
|
|
1570
|
+
return { receipt: null };
|
|
1571
|
+
const status = normalizeStatus(txStatus);
|
|
1572
|
+
if (!status)
|
|
1573
|
+
return { receipt: null };
|
|
1574
|
+
return {
|
|
1575
|
+
receipt: {
|
|
1576
|
+
txid: normalizeTxid(txid2),
|
|
1577
|
+
status,
|
|
1578
|
+
blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
|
|
1579
|
+
blockHash: data.block_hash ?? undefined,
|
|
1580
|
+
...decodeResultHex(data.tx_result?.hex),
|
|
1581
|
+
events: Array.isArray(data.events) ? data.events : [],
|
|
1582
|
+
raw: data
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// src/actions/public/waitForTransactionReceipt.ts
|
|
1590
|
+
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1591
|
+
async function waitForTransactionReceipt(client, params) {
|
|
1592
|
+
const {
|
|
1593
|
+
txid: txid2,
|
|
1594
|
+
confirmations = 1,
|
|
1595
|
+
timeout = 180000,
|
|
1596
|
+
pollingInterval = 3000,
|
|
1597
|
+
droppedGracePeriod = 30000
|
|
1598
|
+
} = params;
|
|
1599
|
+
const source = params.source ?? extendedApiSource();
|
|
1600
|
+
const startedAt = Date.now();
|
|
1601
|
+
let unknownSince = null;
|
|
1602
|
+
let everPending = false;
|
|
1603
|
+
while (true) {
|
|
1604
|
+
const snapshot = await source.get({ client, txid: txid2 });
|
|
1605
|
+
const receipt = snapshot.receipt;
|
|
1606
|
+
if (receipt === null) {
|
|
1607
|
+
unknownSince ??= Date.now();
|
|
1608
|
+
if (Date.now() - unknownSince >= droppedGracePeriod) {
|
|
1609
|
+
throw new TransactionDroppedError(everPending ? `Transaction ${txid2} left the mempool without being mined` : `Transaction ${txid2} was never observed by the status source`, { txid: txid2 });
|
|
1610
|
+
}
|
|
1611
|
+
} else {
|
|
1612
|
+
unknownSince = null;
|
|
1613
|
+
switch (receipt.status) {
|
|
1614
|
+
case "dropped":
|
|
1615
|
+
throw new TransactionDroppedError(`Transaction ${txid2} was dropped from the mempool`, { txid: txid2 });
|
|
1616
|
+
case "abort_by_response":
|
|
1617
|
+
case "abort_by_post_condition":
|
|
1618
|
+
throw new TransactionAbortedError(`Transaction ${txid2} aborted (${receipt.status})`, { receipt });
|
|
1619
|
+
case "pending":
|
|
1620
|
+
everPending = true;
|
|
1621
|
+
break;
|
|
1622
|
+
case "success": {
|
|
1623
|
+
if (confirmations <= 1)
|
|
1624
|
+
return receipt;
|
|
1625
|
+
if (receipt.blockHeight !== undefined) {
|
|
1626
|
+
const tip = snapshot.tip ?? await getBlockHeight(client);
|
|
1627
|
+
if (tip - receipt.blockHeight + 1 >= confirmations)
|
|
1628
|
+
return receipt;
|
|
1629
|
+
}
|
|
1630
|
+
break;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (Date.now() - startedAt >= timeout) {
|
|
1635
|
+
throw new WaitForTransactionTimeoutError(`Timed out after ${timeout}ms waiting for transaction ${txid2}`, { txid: txid2 });
|
|
1636
|
+
}
|
|
1637
|
+
await sleep(pollingInterval);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1511
1641
|
// src/actions/wallet/sendTransaction.ts
|
|
1512
1642
|
async function sendTransaction(client, params) {
|
|
1513
1643
|
const hex = bytesToHex(serializeTransaction(params.transaction));
|
|
@@ -1521,10 +1651,20 @@ async function sendTransaction(client, params) {
|
|
|
1521
1651
|
});
|
|
1522
1652
|
if (data.error) {
|
|
1523
1653
|
throw new BroadcastError(data.reason ?? data.error, {
|
|
1524
|
-
reason: data.reason
|
|
1654
|
+
reason: data.reason,
|
|
1655
|
+
reasonData: data.reason_data,
|
|
1656
|
+
txid: data.txid ?? getTransactionId(params.transaction)
|
|
1525
1657
|
});
|
|
1526
1658
|
}
|
|
1527
1659
|
const txid2 = typeof data === "string" ? data.replace(/"/g, "") : data.txid ?? getTransactionId(params.transaction);
|
|
1660
|
+
if (params.wait) {
|
|
1661
|
+
const confirmations = params.wait === true ? 1 : params.wait;
|
|
1662
|
+
const receipt = await waitForTransactionReceipt(client, {
|
|
1663
|
+
txid: txid2,
|
|
1664
|
+
confirmations
|
|
1665
|
+
});
|
|
1666
|
+
return { txid: txid2, receipt };
|
|
1667
|
+
}
|
|
1528
1668
|
return { txid: txid2 };
|
|
1529
1669
|
}
|
|
1530
1670
|
|
|
@@ -1537,8 +1677,12 @@ async function resolveNonce(client, address) {
|
|
|
1537
1677
|
function isNonceConflictError(error) {
|
|
1538
1678
|
if (!(error instanceof BroadcastError))
|
|
1539
1679
|
return false;
|
|
1540
|
-
|
|
1541
|
-
|
|
1680
|
+
if (error.reason === "ConflictingNonceInMempool" || error.reason === "BadNonce") {
|
|
1681
|
+
return true;
|
|
1682
|
+
}
|
|
1683
|
+
if (error.reason !== undefined)
|
|
1684
|
+
return false;
|
|
1685
|
+
return error.message.toLowerCase().includes("nonce");
|
|
1542
1686
|
}
|
|
1543
1687
|
async function broadcastWithNonceReset(client, params) {
|
|
1544
1688
|
try {
|
|
@@ -1558,6 +1702,36 @@ async function broadcastWithNonceReset(client, params) {
|
|
|
1558
1702
|
function isProviderAccount(account) {
|
|
1559
1703
|
return account.type === "provider";
|
|
1560
1704
|
}
|
|
1705
|
+
var FEE_TIERS = ["min", "low", "mid", "high"];
|
|
1706
|
+
var TIER_INDEX = { low: 0, mid: 1, high: 2 };
|
|
1707
|
+
function isFeeTier(fee) {
|
|
1708
|
+
return typeof fee === "string" && FEE_TIERS.includes(fee);
|
|
1709
|
+
}
|
|
1710
|
+
function minimumFee(transaction) {
|
|
1711
|
+
return BigInt(serializeTransaction(transaction).length);
|
|
1712
|
+
}
|
|
1713
|
+
async function resolveFee(client, transaction, fee) {
|
|
1714
|
+
if (fee !== undefined && !isFeeTier(fee))
|
|
1715
|
+
return intToBigInt(fee);
|
|
1716
|
+
const tier = fee ?? "mid";
|
|
1717
|
+
if (tier === "min")
|
|
1718
|
+
return minimumFee(transaction);
|
|
1719
|
+
try {
|
|
1720
|
+
const estimates = await estimateFee(client, { transaction });
|
|
1721
|
+
const pick = estimates[TIER_INDEX[tier]] ?? estimates[estimates.length - 1];
|
|
1722
|
+
if (pick)
|
|
1723
|
+
return BigInt(pick.fee);
|
|
1724
|
+
} catch {}
|
|
1725
|
+
return minimumFee(transaction);
|
|
1726
|
+
}
|
|
1727
|
+
function setUnsignedFee(transaction, fee) {
|
|
1728
|
+
transaction.auth.spendingCondition.fee = fee;
|
|
1729
|
+
}
|
|
1730
|
+
function assertNoFeeTierForProvider(fee) {
|
|
1731
|
+
if (isFeeTier(fee)) {
|
|
1732
|
+
throw new Error(`Fee tier '${fee}' requires local signing; provider (wallet) accounts set their own fee`);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1561
1735
|
|
|
1562
1736
|
// src/actions/wallet/callContract.ts
|
|
1563
1737
|
async function callContract(client, params) {
|
|
@@ -1566,6 +1740,7 @@ async function callContract(client, params) {
|
|
|
1566
1740
|
throw new Error("Account required");
|
|
1567
1741
|
const [contractAddress, contractName] = parseContractId(params.contract);
|
|
1568
1742
|
if (isProviderAccount(account)) {
|
|
1743
|
+
assertNoFeeTierForProvider(params.fee);
|
|
1569
1744
|
const result = await account.provider.request("stx_callContract", {
|
|
1570
1745
|
contract: params.contract,
|
|
1571
1746
|
functionName: params.functionName,
|
|
@@ -1574,24 +1749,21 @@ async function callContract(client, params) {
|
|
|
1574
1749
|
return result.txid;
|
|
1575
1750
|
}
|
|
1576
1751
|
const nonce = params.nonce ?? await resolveNonce(client, account.address);
|
|
1752
|
+
const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
|
|
1577
1753
|
const unsigned = buildContractCall({
|
|
1578
1754
|
contractAddress,
|
|
1579
1755
|
contractName,
|
|
1580
1756
|
functionName: params.functionName,
|
|
1581
1757
|
functionArgs: params.functionArgs ?? [],
|
|
1582
|
-
fee: params.fee
|
|
1758
|
+
fee: needsFeeResolution ? 0n : params.fee,
|
|
1583
1759
|
nonce,
|
|
1584
1760
|
publicKey: account.publicKey,
|
|
1585
1761
|
chain: client.chain,
|
|
1586
1762
|
postConditionMode: params.postConditionMode,
|
|
1587
1763
|
postConditions: params.postConditions
|
|
1588
1764
|
});
|
|
1589
|
-
if (
|
|
1590
|
-
|
|
1591
|
-
const mid = estimates[1] ?? estimates[0];
|
|
1592
|
-
if (mid) {
|
|
1593
|
-
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
1594
|
-
}
|
|
1765
|
+
if (needsFeeResolution) {
|
|
1766
|
+
setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
|
|
1595
1767
|
}
|
|
1596
1768
|
const signed = await signTransactionWithAccount(unsigned, account);
|
|
1597
1769
|
return broadcastWithNonceReset(client, {
|
|
@@ -2411,6 +2583,13 @@ async function getContractAbi(client, params) {
|
|
|
2411
2583
|
});
|
|
2412
2584
|
}
|
|
2413
2585
|
|
|
2586
|
+
// src/actions/public/getTransaction.ts
|
|
2587
|
+
async function getTransaction(client, params) {
|
|
2588
|
+
const source = params.source ?? extendedApiSource();
|
|
2589
|
+
const { receipt } = await source.get({ client, txid: params.txid });
|
|
2590
|
+
return receipt;
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2414
2593
|
// src/actions/public/multicall.ts
|
|
2415
2594
|
async function multicall(client, params) {
|
|
2416
2595
|
const { calls, allowFailure = true } = params;
|
|
@@ -2561,6 +2740,8 @@ function publicActions(client) {
|
|
|
2561
2740
|
multicall: (params) => multicall(client, params),
|
|
2562
2741
|
simulateCall: (params) => simulateCall(client, params),
|
|
2563
2742
|
simulateTransaction: (params) => simulateTransaction(client, params),
|
|
2743
|
+
getTransaction: (params) => getTransaction(client, params),
|
|
2744
|
+
waitForTransactionReceipt: (params) => waitForTransactionReceipt(client, params),
|
|
2564
2745
|
watchBlocks: (params) => watchBlocks(client, params),
|
|
2565
2746
|
watchMempool: (params) => watchMempool(client, params),
|
|
2566
2747
|
watchTransaction: (params) => watchTransaction(client, params),
|
|
@@ -2869,7 +3050,7 @@ var bnsReverse = import_ai.tool({
|
|
|
2869
3050
|
inputSchema: import_zod.z.object({ principal: PRINCIPAL }),
|
|
2870
3051
|
execute: ({ principal }) => bnsReverseImpl(getDefaultPublicClient(), principal)
|
|
2871
3052
|
});
|
|
2872
|
-
var
|
|
3053
|
+
var getTransaction2 = import_ai.tool({
|
|
2873
3054
|
description: "Fetch a confirmed Stacks transaction by txId (Hiro extended API).",
|
|
2874
3055
|
inputSchema: import_zod.z.object({ txId: import_zod.z.string() }),
|
|
2875
3056
|
execute: ({ txId }) => transactionByTxId(getDefaultPublicClient(), txId)
|
|
@@ -2896,5 +3077,5 @@ var getNftHoldings = import_ai.tool({
|
|
|
2896
3077
|
execute: ({ principal, limit }) => nftHoldings(getDefaultPublicClient(), principal, limit)
|
|
2897
3078
|
});
|
|
2898
3079
|
|
|
2899
|
-
//# debugId=
|
|
3080
|
+
//# debugId=E0CFA9E2C0C074CF64756E2164756E21
|
|
2900
3081
|
//# sourceMappingURL=index.cjs.map
|