@secondlayer/stacks 2.5.2 → 2.7.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.
Files changed (56) hide show
  1. package/README.md +65 -0
  2. package/dist/shared/{stacks-jevhg39n.cjs → stacks-7nf5h3qe.cjs} +16 -12
  3. package/dist/shared/{stacks-jevhg39n.cjs.map → stacks-7nf5h3qe.cjs.map} +4 -4
  4. package/dist/shared/{stacks-5th5dffx.js → stacks-a48qj7ss.js} +20 -16
  5. package/dist/shared/{stacks-5th5dffx.js.map → stacks-a48qj7ss.js.map} +4 -4
  6. package/dist/shared/{stacks-7wfdkhj6.cjs → stacks-e7pmsrbs.cjs} +9 -7
  7. package/dist/shared/{stacks-7wfdkhj6.cjs.map → stacks-e7pmsrbs.cjs.map} +3 -3
  8. package/dist/shared/{stacks-7wqprfrm.cjs → stacks-hxm7r5ay.cjs} +3 -3
  9. package/dist/shared/{stacks-7wqprfrm.cjs.map → stacks-hxm7r5ay.cjs.map} +3 -3
  10. package/dist/shared/{stacks-hyz7zgdk.js → stacks-k96f5g1a.js} +2 -2
  11. package/dist/shared/stacks-r3mqgw2d.js +204 -0
  12. package/dist/shared/stacks-r3mqgw2d.js.map +15 -0
  13. package/dist/shared/{stacks-4z1jhw6y.js → stacks-s6v8k4j5.js} +6 -6
  14. package/dist/shared/{stacks-4z1jhw6y.js.map → stacks-s6v8k4j5.js.map} +3 -3
  15. package/dist/shared/{stacks-yq5a5cda.js → stacks-txh6dadn.js} +12 -10
  16. package/dist/shared/{stacks-yq5a5cda.js.map → stacks-txh6dadn.js.map} +3 -3
  17. package/dist/shared/stacks-wb06pevp.cjs +190 -0
  18. package/dist/shared/stacks-wb06pevp.cjs.map +15 -0
  19. package/dist/src/actions/index.d.cts +138 -120
  20. package/dist/src/actions/index.d.ts +138 -120
  21. package/dist/src/actions/index.js +5 -5
  22. package/dist/src/bns/index.d.cts +18 -0
  23. package/dist/src/bns/index.d.ts +18 -0
  24. package/dist/src/bns/index.js +3 -3
  25. package/dist/src/index.cjs +180 -5
  26. package/dist/src/index.cjs.map +7 -5
  27. package/dist/src/index.d.cts +377 -101
  28. package/dist/src/index.d.ts +377 -101
  29. package/dist/src/index.js +193 -10
  30. package/dist/src/index.js.map +7 -5
  31. package/dist/src/pox/index.d.cts +18 -0
  32. package/dist/src/pox/index.d.ts +18 -0
  33. package/dist/src/pox/index.js +3 -3
  34. package/dist/src/sbtc/index.d.cts +18 -0
  35. package/dist/src/sbtc/index.d.ts +18 -0
  36. package/dist/src/sbtc/index.js +3 -3
  37. package/dist/src/stackingdao/index.d.cts +18 -0
  38. package/dist/src/stackingdao/index.d.ts +18 -0
  39. package/dist/src/stackingdao/index.js +3 -3
  40. package/dist/src/subscriptions/index.d.cts +18 -0
  41. package/dist/src/subscriptions/index.d.ts +18 -0
  42. package/dist/src/tools/index.cjs +44 -14
  43. package/dist/src/tools/index.cjs.map +7 -6
  44. package/dist/src/tools/index.d.cts +18 -0
  45. package/dist/src/tools/index.d.ts +18 -0
  46. package/dist/src/tools/index.js +44 -14
  47. package/dist/src/tools/index.js.map +7 -6
  48. package/dist/src/x402/index.d.cts +18 -0
  49. package/dist/src/x402/index.d.ts +18 -0
  50. package/dist/src/x402/index.js +2 -2
  51. package/package.json +1 -1
  52. package/dist/shared/stacks-qk8pdyjy.cjs +0 -76
  53. package/dist/shared/stacks-qk8pdyjy.cjs.map +0 -14
  54. package/dist/shared/stacks-y8e3gx6w.js +0 -90
  55. package/dist/shared/stacks-y8e3gx6w.js.map +0 -14
  56. /package/dist/shared/{stacks-hyz7zgdk.js.map → stacks-k96f5g1a.js.map} +0 -0
@@ -27,6 +27,22 @@ type ProviderAccount = {
27
27
  publicKey: string
28
28
  provider: StacksProvider
29
29
  };
30
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
31
+ type NonceManager = {
32
+ consume(params: {
33
+ client: Client
34
+ address: string
35
+ }): Promise<bigint>
36
+ reset(params: {
37
+ client: Client
38
+ address: string
39
+ }): void | Promise<void>
40
+ /** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */
41
+ peek(params: {
42
+ client: Client
43
+ address: string
44
+ }): Promise<bigint | undefined>
45
+ };
30
46
  /** Full chain descriptor used by clients and transports for network-aware operations. */
31
47
  type StacksChain = {
32
48
  /** Chain ID (e.g. 0x00000001 for mainnet) */
@@ -104,6 +120,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
104
120
  account?: Account
105
121
  transport: Transport
106
122
  request: RequestFn
123
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
124
+ nonceManager?: NonceManager
107
125
  extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
108
126
  } & TExtended;
109
127
  /**
@@ -4,9 +4,9 @@ import {
4
4
  } from "../../shared/stacks-9z833ww5.js";
5
5
  import {
6
6
  getContract
7
- } from "../../shared/stacks-hyz7zgdk.js";
8
- import"../../shared/stacks-yq5a5cda.js";
9
- import"../../shared/stacks-y8e3gx6w.js";
7
+ } from "../../shared/stacks-k96f5g1a.js";
8
+ import"../../shared/stacks-txh6dadn.js";
9
+ import"../../shared/stacks-r3mqgw2d.js";
10
10
  import"../../shared/stacks-709tra19.js";
11
11
  import"../../shared/stacks-g7ffp8aj.js";
12
12
  import"../../shared/stacks-4trgpb5a.js";
@@ -27,6 +27,22 @@ type ProviderAccount = {
27
27
  publicKey: string
28
28
  provider: StacksProvider
29
29
  };
30
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
31
+ type NonceManager = {
32
+ consume(params: {
33
+ client: Client
34
+ address: string
35
+ }): Promise<bigint>
36
+ reset(params: {
37
+ client: Client
38
+ address: string
39
+ }): void | Promise<void>
40
+ /** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */
41
+ peek(params: {
42
+ client: Client
43
+ address: string
44
+ }): Promise<bigint | undefined>
45
+ };
30
46
  /** Full chain descriptor used by clients and transports for network-aware operations. */
31
47
  type StacksChain = {
32
48
  /** Chain ID (e.g. 0x00000001 for mainnet) */
@@ -104,6 +120,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
104
120
  account?: Account
105
121
  transport: Transport
106
122
  request: RequestFn
123
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
124
+ nonceManager?: NonceManager
107
125
  extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
108
126
  } & TExtended;
109
127
  interface DepositParams {
@@ -27,6 +27,22 @@ type ProviderAccount = {
27
27
  publicKey: string
28
28
  provider: StacksProvider
29
29
  };
30
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
31
+ type NonceManager = {
32
+ consume(params: {
33
+ client: Client
34
+ address: string
35
+ }): Promise<bigint>
36
+ reset(params: {
37
+ client: Client
38
+ address: string
39
+ }): void | Promise<void>
40
+ /** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */
41
+ peek(params: {
42
+ client: Client
43
+ address: string
44
+ }): Promise<bigint | undefined>
45
+ };
30
46
  /** Full chain descriptor used by clients and transports for network-aware operations. */
31
47
  type StacksChain = {
32
48
  /** Chain ID (e.g. 0x00000001 for mainnet) */
@@ -104,6 +120,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
104
120
  account?: Account
105
121
  transport: Transport
106
122
  request: RequestFn
123
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
124
+ nonceManager?: NonceManager
107
125
  extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
108
126
  } & TExtended;
109
127
  interface DepositParams {
@@ -3,9 +3,9 @@ import {
3
3
  } from "../../shared/stacks-kg1npstf.js";
4
4
  import {
5
5
  getContract
6
- } from "../../shared/stacks-hyz7zgdk.js";
7
- import"../../shared/stacks-yq5a5cda.js";
8
- import"../../shared/stacks-y8e3gx6w.js";
6
+ } from "../../shared/stacks-k96f5g1a.js";
7
+ import"../../shared/stacks-txh6dadn.js";
8
+ import"../../shared/stacks-r3mqgw2d.js";
9
9
  import"../../shared/stacks-709tra19.js";
10
10
  import"../../shared/stacks-g7ffp8aj.js";
11
11
  import"../../shared/stacks-z53fwfcm.js";
@@ -139,6 +139,22 @@ type ProviderAccount = {
139
139
  publicKey: string
140
140
  provider: StacksProvider
141
141
  };
142
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
143
+ type NonceManager = {
144
+ consume(params: {
145
+ client: Client
146
+ address: string
147
+ }): Promise<bigint>
148
+ reset(params: {
149
+ client: Client
150
+ address: string
151
+ }): void | Promise<void>
152
+ /** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */
153
+ peek(params: {
154
+ client: Client
155
+ address: string
156
+ }): Promise<bigint | undefined>
157
+ };
142
158
  /** Full chain descriptor used by clients and transports for network-aware operations. */
143
159
  type StacksChain = {
144
160
  /** Chain ID (e.g. 0x00000001 for mainnet) */
@@ -216,6 +232,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
216
232
  account?: Account
217
233
  transport: Transport
218
234
  request: RequestFn
235
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
236
+ nonceManager?: NonceManager
219
237
  extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
220
238
  } & TExtended;
221
239
  type WatchBlocksParams = {
@@ -139,6 +139,22 @@ type ProviderAccount = {
139
139
  publicKey: string
140
140
  provider: StacksProvider
141
141
  };
142
+ /** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
143
+ type NonceManager = {
144
+ consume(params: {
145
+ client: Client
146
+ address: string
147
+ }): Promise<bigint>
148
+ reset(params: {
149
+ client: Client
150
+ address: string
151
+ }): void | Promise<void>
152
+ /** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */
153
+ peek(params: {
154
+ client: Client
155
+ address: string
156
+ }): Promise<bigint | undefined>
157
+ };
142
158
  /** Full chain descriptor used by clients and transports for network-aware operations. */
143
159
  type StacksChain = {
144
160
  /** Chain ID (e.g. 0x00000001 for mainnet) */
@@ -216,6 +232,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
216
232
  account?: Account
217
233
  transport: Transport
218
234
  request: RequestFn
235
+ /** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
236
+ nonceManager?: NonceManager
219
237
  extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
220
238
  } & TExtended;
221
239
  type WatchBlocksParams = {
@@ -1358,14 +1358,6 @@ function getTransactionId(tx) {
1358
1358
  return txid(tx);
1359
1359
  }
1360
1360
 
1361
- // src/actions/public/getNonce.ts
1362
- async function getNonce(client, params) {
1363
- const data = await client.request(`/v2/accounts/${params.address}`, {
1364
- method: "GET"
1365
- });
1366
- return BigInt(data.nonce);
1367
- }
1368
-
1369
1361
  // src/errors/base.ts
1370
1362
  class BaseError extends Error {
1371
1363
  name = "StacksError";
@@ -1404,6 +1396,14 @@ class BroadcastError extends BaseError {
1404
1396
  }
1405
1397
  }
1406
1398
 
1399
+ // src/actions/public/getNonce.ts
1400
+ async function getNonce(client, params) {
1401
+ const data = await client.request(`/v2/accounts/${params.address}`, {
1402
+ method: "GET"
1403
+ });
1404
+ return BigInt(data.nonce);
1405
+ }
1406
+
1407
1407
  // src/actions/wallet/sendTransaction.ts
1408
1408
  async function sendTransaction(client, params) {
1409
1409
  const hex = bytesToHex(serializeTransaction(params.transaction));
@@ -1424,6 +1424,32 @@ async function sendTransaction(client, params) {
1424
1424
  return { txid: txid2 };
1425
1425
  }
1426
1426
 
1427
+ // src/actions/wallet/nonceManager.ts
1428
+ async function resolveNonce(client, address) {
1429
+ if (client.nonceManager)
1430
+ return client.nonceManager.consume({ client, address });
1431
+ return getNonce(client, { address });
1432
+ }
1433
+ function isNonceConflictError(error) {
1434
+ if (!(error instanceof BroadcastError))
1435
+ return false;
1436
+ const haystack = `${error.reason ?? ""} ${error.message}`.toLowerCase();
1437
+ return haystack.includes("nonce");
1438
+ }
1439
+ async function broadcastWithNonceReset(client, params) {
1440
+ try {
1441
+ const result = await sendTransaction(client, {
1442
+ transaction: params.transaction
1443
+ });
1444
+ return result.txid;
1445
+ } catch (error) {
1446
+ if (client.nonceManager && isNonceConflictError(error)) {
1447
+ await client.nonceManager.reset({ client, address: params.address });
1448
+ }
1449
+ throw error;
1450
+ }
1451
+ }
1452
+
1427
1453
  // src/actions/wallet/utils.ts
1428
1454
  function isProviderAccount(account) {
1429
1455
  return account.type === "provider";
@@ -1435,15 +1461,15 @@ async function callContract(client, params) {
1435
1461
  if (!account)
1436
1462
  throw new Error("Account required");
1437
1463
  if (isProviderAccount(account)) {
1438
- const result2 = await account.provider.request("stx_callContract", {
1464
+ const result = await account.provider.request("stx_callContract", {
1439
1465
  contract: params.contract,
1440
1466
  functionName: params.functionName,
1441
1467
  functionArgs: params.functionArgs ?? []
1442
1468
  });
1443
- return result2.txid;
1469
+ return result.txid;
1444
1470
  }
1445
1471
  const [contractAddress, contractName] = parseContractId(params.contract);
1446
- const nonce = params.nonce ?? await getNonce(client, { address: account.address });
1472
+ const nonce = params.nonce ?? await resolveNonce(client, account.address);
1447
1473
  const unsigned = buildContractCall({
1448
1474
  contractAddress,
1449
1475
  contractName,
@@ -1464,8 +1490,10 @@ async function callContract(client, params) {
1464
1490
  }
1465
1491
  }
1466
1492
  const signed = await signTransactionWithAccount(unsigned, account);
1467
- const result = await sendTransaction(client, { transaction: signed });
1468
- return result.txid;
1493
+ return broadcastWithNonceReset(client, {
1494
+ transaction: signed,
1495
+ address: account.address
1496
+ });
1469
1497
  }
1470
1498
 
1471
1499
  // src/actions/getContract.ts
@@ -2199,6 +2227,7 @@ var BASE_KEYS = new Set([
2199
2227
  "account",
2200
2228
  "transport",
2201
2229
  "request",
2230
+ "nonceManager",
2202
2231
  "extend"
2203
2232
  ]);
2204
2233
  function bindExtend(base) {
@@ -2221,6 +2250,7 @@ function createClient(config) {
2221
2250
  account: config.account,
2222
2251
  transport,
2223
2252
  request: transport.request,
2253
+ nonceManager: config.nonceManager,
2224
2254
  extend: null
2225
2255
  };
2226
2256
  client.extend = bindExtend(client);
@@ -2720,5 +2750,5 @@ var getNftHoldings = import_ai.tool({
2720
2750
  execute: ({ principal, limit }) => nftHoldings(getDefaultPublicClient(), principal, limit)
2721
2751
  });
2722
2752
 
2723
- //# debugId=C9A44682320EBB2264756E2164756E21
2753
+ //# debugId=B0ABAC70FB7980FB64756E2164756E21
2724
2754
  //# sourceMappingURL=index.cjs.map