@secondlayer/stacks 5.1.1 → 5.1.3

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.
@@ -1286,6 +1286,18 @@ type UnwrapResponse<T> = T extends {
1286
1286
  } ? O : T extends {
1287
1287
  err: unknown
1288
1288
  } ? never : T;
1289
+ /**
1290
+ * True for a structural empty mapped type (`{}`) and for codegen's
1291
+ * `Record<string, never>`. `keyof Record<string, never>` is `string`, so the
1292
+ * first check alone is not enough.
1293
+ */
1294
+ type IsEmptyArgs<A> = [keyof A & string] extends [never] ? true : Record<string, never> extends A ? true : false;
1295
+ /** No-arg ABI functions may omit the dummy `{}`. Functions with args stay required. */
1296
+ type ContractMethod<
1297
+ A,
1298
+ R,
1299
+ Extra extends unknown[] = []
1300
+ > = IsEmptyArgs<A> extends true ? (args?: A, ...extra: Extra) => R : (args: A, ...extra: Extra) => R;
1289
1301
  type ReadMethodReturn<
1290
1302
  C extends AbiContract,
1291
1303
  N extends ExtractReadOnlyFunctions<C>
@@ -1295,11 +1307,11 @@ type ReadMethodReturn<
1295
1307
  * the generated named aliases — cleaner hovers and error messages. Un-branded
1296
1308
  * ABIs fall back to structural inference over the as-const literal.
1297
1309
  */
1298
- type TypedReadMethods<T extends ContractTypes> = { [K in keyof T["functions"] as T["functions"][K]["access"] extends "read-only" ? K : never] : (args: T["functions"][K]["args"]) => Promise<UnwrapResponse<T["functions"][K]["ret"]>> };
1299
- type TypedCallMethods<T extends ContractTypes> = { [K in keyof T["functions"] as T["functions"][K]["access"] extends "public" ? K : never] : (args: T["functions"][K]["args"], options?: ContractCallOptions) => Promise<string> };
1310
+ type TypedReadMethods<T extends ContractTypes> = { [K in keyof T["functions"] as T["functions"][K]["access"] extends "read-only" ? K : never] : ContractMethod<T["functions"][K]["args"], Promise<UnwrapResponse<T["functions"][K]["ret"]>>> };
1311
+ type TypedCallMethods<T extends ContractTypes> = { [K in keyof T["functions"] as T["functions"][K]["access"] extends "public" ? K : never] : ContractMethod<T["functions"][K]["args"], Promise<string>, [options?: ContractCallOptions]> };
1300
1312
  type TypedMapMethods<T extends ContractTypes> = { [K in keyof NonNullable<T["maps"]>] : (key: NonNullable<T["maps"]>[K]["key"]) => Promise<NonNullable<T["maps"]>[K]["value"] | null> };
1301
- type ReadMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never] ? { [N in ExtractReadOnlyFunctions<C> as ToCamelCase<N>] : (args: ExtractFunctionArgs<C, N>) => Promise<ReadMethodReturn<C, N>> } : TypedReadMethods<AbiTypesOf<C>>;
1302
- type CallMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never] ? { [N in ExtractPublicFunctions<C> as ToCamelCase<N>] : (args: ExtractFunctionArgs<C, N>, options?: ContractCallOptions) => Promise<string> } : TypedCallMethods<AbiTypesOf<C>>;
1313
+ type ReadMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never] ? { [N in ExtractReadOnlyFunctions<C> as ToCamelCase<N>] : ContractMethod<ExtractFunctionArgs<C, N>, Promise<ReadMethodReturn<C, N>>> } : TypedReadMethods<AbiTypesOf<C>>;
1314
+ type CallMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never] ? { [N in ExtractPublicFunctions<C> as ToCamelCase<N>] : ContractMethod<ExtractFunctionArgs<C, N>, Promise<string>, [options?: ContractCallOptions]> } : TypedCallMethods<AbiTypesOf<C>>;
1303
1315
  type MapMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never] ? { [N in ExtractMapNames<C> as ToCamelCase<N>] : (key: ExtractMapKey<C, N>) => Promise<ExtractMapValue<C, N> | null> } : TypedMapMethods<AbiTypesOf<C>>;
1304
1316
  type ContractCallOptions = {
1305
1317
  fee?: IntegerType
@@ -1319,8 +1331,8 @@ type ContractBuildCallOptions = ContractCallOptions & {
1319
1331
  publicKey?: string
1320
1332
  sponsored?: boolean
1321
1333
  };
1322
- type TypedBuildCallMethods<T extends ContractTypes> = { [K in keyof T["functions"] as T["functions"][K]["access"] extends "public" ? K : never] : (args: T["functions"][K]["args"], options?: ContractBuildCallOptions) => Promise<StacksTransaction> };
1323
- type BuildCallMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never] ? { [N in ExtractPublicFunctions<C> as ToCamelCase<N>] : (args: ExtractFunctionArgs<C, N>, options?: ContractBuildCallOptions) => Promise<StacksTransaction> } : TypedBuildCallMethods<AbiTypesOf<C>>;
1334
+ type TypedBuildCallMethods<T extends ContractTypes> = { [K in keyof T["functions"] as T["functions"][K]["access"] extends "public" ? K : never] : ContractMethod<T["functions"][K]["args"], Promise<StacksTransaction>, [options?: ContractBuildCallOptions]> };
1335
+ type BuildCallMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never] ? { [N in ExtractPublicFunctions<C> as ToCamelCase<N>] : ContractMethod<ExtractFunctionArgs<C, N>, Promise<StacksTransaction>, [options?: ContractBuildCallOptions]> } : TypedBuildCallMethods<AbiTypesOf<C>>;
1324
1336
  type ContractInstance<C extends AbiContract> = {
1325
1337
  read: ReadMethods<C>
1326
1338
  call: CallMethods<C>
@@ -1341,7 +1353,7 @@ declare function getContract<const TAbi extends AbiContract>(params: GetContract
1341
1353
  * it) can reuse the same encoding this module's read methods use, instead of
1342
1354
  * maintaining a second one that drifts.
1343
1355
  */
1344
- declare function buildFunctionArgs(fn: AbiFunction, args: Record<string, unknown>): ClarityValue[];
1356
+ declare function buildFunctionArgs(fn: AbiFunction, args?: Record<string, unknown>): ClarityValue[];
1345
1357
  /** True when an ABI output is a `(response ok err)` and needs unwrapping. */
1346
1358
  declare function isResponseOutput(type: AbiType): boolean;
1347
1359
  declare class ContractResponseError extends Error {
@@ -3,7 +3,7 @@ import {
3
3
  buildFunctionArgs,
4
4
  getContract,
5
5
  isResponseOutput
6
- } from "../../shared/stacks-gyp5ax89.js";
6
+ } from "../../shared/stacks-fd4rx56e.js";
7
7
  import {
8
8
  deployContract,
9
9
  getAccountHistory,
@@ -4,7 +4,7 @@ import {
4
4
  ContractResponseError,
5
5
  getContract,
6
6
  resolveNetworkContract
7
- } from "../../shared/stacks-gyp5ax89.js";
7
+ } from "../../shared/stacks-fd4rx56e.js";
8
8
  import"../../shared/stacks-v03zef3g.js";
9
9
  import"../../shared/stacks-qex691bh.js";
10
10
  import"../../shared/stacks-x0qqwrev.js";
@@ -189,7 +189,7 @@ interface StxLockSpec {
189
189
  minAmount?: bigint;
190
190
  }
191
191
  /** Scope to contracts conforming to a trait/standard (e.g. "sip-010") instead
192
- * of a fixed contract. Index + Subgraphs + Subscriptions; Streams has no
192
+ * of a fixed contract. Index + Subgraphs + Webhooks; Streams has no
193
193
  * trait resolution — `toStreamsParams()` throws if set. */
194
194
  type TraitScope = {
195
195
  trait?: string
@@ -300,7 +300,7 @@ type SpecFor<T extends ChainEventFilterType> = Extract<ChainEventFilterSpec, {
300
300
  type: T
301
301
  }>;
302
302
  /** The members expressible as subgraph sources (everything but the
303
- * Subscriptions-only sBTC lifecycle types). Instantiating
303
+ * Webhooks-only sBTC lifecycle types). Instantiating
304
304
  * `ChainEventFilter<SubgraphMemberType>` keeps `toSubgraphSource` present:
305
305
  * the conditional in `ProjectionsFor` evaluates over this whole union
306
306
  * (non-distributive at an instantiated site), and every member qualifies. */
@@ -310,7 +310,7 @@ type SubgraphMemberType = Exclude<ChainEventFilterType, `sbtc_${string}`>;
310
310
  type SubgraphSourceSpec = Extract<ChainEventFilterSpec, {
311
311
  type: SubgraphMemberType
312
312
  }>;
313
- /** Wire shape of a chain trigger (Subscriptions), derived per member from
313
+ /** Wire shape of a chain trigger (Webhooks), derived per member from
314
314
  * the spec: same fields, with `bigint` amounts stringified (uint128 exceeds
315
315
  * JS safe integers) and the type-only `abi`/`prints` decorations dropped.
316
316
  * Structurally assignable to the SDK's `ChainTrigger` union. */
@@ -189,7 +189,7 @@ interface StxLockSpec {
189
189
  minAmount?: bigint;
190
190
  }
191
191
  /** Scope to contracts conforming to a trait/standard (e.g. "sip-010") instead
192
- * of a fixed contract. Index + Subgraphs + Subscriptions; Streams has no
192
+ * of a fixed contract. Index + Subgraphs + Webhooks; Streams has no
193
193
  * trait resolution — `toStreamsParams()` throws if set. */
194
194
  type TraitScope = {
195
195
  trait?: string
@@ -300,7 +300,7 @@ type SpecFor<T extends ChainEventFilterType> = Extract<ChainEventFilterSpec, {
300
300
  type: T
301
301
  }>;
302
302
  /** The members expressible as subgraph sources (everything but the
303
- * Subscriptions-only sBTC lifecycle types). Instantiating
303
+ * Webhooks-only sBTC lifecycle types). Instantiating
304
304
  * `ChainEventFilter<SubgraphMemberType>` keeps `toSubgraphSource` present:
305
305
  * the conditional in `ProjectionsFor` evaluates over this whole union
306
306
  * (non-distributive at an instantiated site), and every member qualifies. */
@@ -310,7 +310,7 @@ type SubgraphMemberType = Exclude<ChainEventFilterType, `sbtc_${string}`>;
310
310
  type SubgraphSourceSpec = Extract<ChainEventFilterSpec, {
311
311
  type: SubgraphMemberType
312
312
  }>;
313
- /** Wire shape of a chain trigger (Subscriptions), derived per member from
313
+ /** Wire shape of a chain trigger (Webhooks), derived per member from
314
314
  * the spec: same fields, with `bigint` amounts stringified (uint128 exceeds
315
315
  * JS safe integers) and the type-only `abi`/`prints` decorations dropped.
316
316
  * Structurally assignable to the SDK's `ChainTrigger` union. */
@@ -187,7 +187,7 @@ interface StxLockSpec {
187
187
  minAmount?: bigint;
188
188
  }
189
189
  /** Scope to contracts conforming to a trait/standard (e.g. "sip-010") instead
190
- * of a fixed contract. Index + Subgraphs + Subscriptions; Streams has no
190
+ * of a fixed contract. Index + Subgraphs + Webhooks; Streams has no
191
191
  * trait resolution — `toStreamsParams()` throws if set. */
192
192
  type TraitScope = {
193
193
  trait?: string
@@ -297,7 +297,7 @@ type ChainEventFilterSpec = StxTransferSpec | StxMintSpec | StxBurnSpec | StxLoc
297
297
  type SpecFor<T extends ChainEventFilterType> = Extract<ChainEventFilterSpec, {
298
298
  type: T
299
299
  }>;
300
- /** Wire shape of a chain trigger (Subscriptions), derived per member from
300
+ /** Wire shape of a chain trigger (Webhooks), derived per member from
301
301
  * the spec: same fields, with `bigint` amounts stringified (uint128 exceeds
302
302
  * JS safe integers) and the type-only `abi`/`prints` decorations dropped.
303
303
  * Structurally assignable to the SDK's `ChainTrigger` union. */
@@ -187,7 +187,7 @@ interface StxLockSpec {
187
187
  minAmount?: bigint;
188
188
  }
189
189
  /** Scope to contracts conforming to a trait/standard (e.g. "sip-010") instead
190
- * of a fixed contract. Index + Subgraphs + Subscriptions; Streams has no
190
+ * of a fixed contract. Index + Subgraphs + Webhooks; Streams has no
191
191
  * trait resolution — `toStreamsParams()` throws if set. */
192
192
  type TraitScope = {
193
193
  trait?: string
@@ -297,7 +297,7 @@ type ChainEventFilterSpec = StxTransferSpec | StxMintSpec | StxBurnSpec | StxLoc
297
297
  type SpecFor<T extends ChainEventFilterType> = Extract<ChainEventFilterSpec, {
298
298
  type: T
299
299
  }>;
300
- /** Wire shape of a chain trigger (Subscriptions), derived per member from
300
+ /** Wire shape of a chain trigger (Webhooks), derived per member from
301
301
  * the spec: same fields, with `bigint` amounts stringified (uint128 exceeds
302
302
  * JS safe integers) and the type-only `abi`/`prints` decorations dropped.
303
303
  * Structurally assignable to the SDK's `ChainTrigger` union. */
@@ -9,7 +9,7 @@ import"../../shared/stacks-z90xdr1x.js";
9
9
  import {
10
10
  getContract,
11
11
  resolveNetworkContract
12
- } from "../../shared/stacks-gyp5ax89.js";
12
+ } from "../../shared/stacks-fd4rx56e.js";
13
13
  import"../../shared/stacks-v03zef3g.js";
14
14
  import"../../shared/stacks-qex691bh.js";
15
15
  import"../../shared/stacks-x0qqwrev.js";
@@ -15,7 +15,7 @@ import {
15
15
  } from "../../shared/stacks-z90xdr1x.js";
16
16
  import {
17
17
  getContract
18
- } from "../../shared/stacks-gyp5ax89.js";
18
+ } from "../../shared/stacks-fd4rx56e.js";
19
19
  import {
20
20
  getBalance,
21
21
  getDataVar,
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  getContract,
9
9
  resolveNetworkContract
10
- } from "../../shared/stacks-gyp5ax89.js";
10
+ } from "../../shared/stacks-fd4rx56e.js";
11
11
  import"../../shared/stacks-v03zef3g.js";
12
12
  import"../../shared/stacks-qex691bh.js";
13
13
  import"../../shared/stacks-x0qqwrev.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "../../shared/stacks-kg1npstf.js";
4
4
  import {
5
5
  getContract
6
- } from "../../shared/stacks-gyp5ax89.js";
6
+ } from "../../shared/stacks-fd4rx56e.js";
7
7
  import"../../shared/stacks-v03zef3g.js";
8
8
  import"../../shared/stacks-qex691bh.js";
9
9
  import"../../shared/stacks-x0qqwrev.js";
@@ -2563,7 +2563,7 @@ function getContract(params) {
2563
2563
  const fn = fnByName.get(fnName);
2564
2564
  if (!fn || fn.access !== "read-only")
2565
2565
  return;
2566
- return async (args) => {
2566
+ return async (args = {}) => {
2567
2567
  const clarityArgs = buildFunctionArgs(fn, args);
2568
2568
  const result = await readContract(client, {
2569
2569
  contract: contractId,
@@ -2587,7 +2587,7 @@ function getContract(params) {
2587
2587
  const fn = fnByName.get(fnName);
2588
2588
  if (!fn || fn.access !== "public")
2589
2589
  return;
2590
- return async (args, options) => {
2590
+ return async (args = {}, options) => {
2591
2591
  const clarityArgs = buildFunctionArgs(fn, args);
2592
2592
  return callContract(client, {
2593
2593
  contract: contractId,
@@ -2604,7 +2604,7 @@ function getContract(params) {
2604
2604
  const fn = fnByName.get(fnName);
2605
2605
  if (!fn || fn.access !== "public")
2606
2606
  return;
2607
- return async (args, options) => {
2607
+ return async (args = {}, options) => {
2608
2608
  const publicKey = options?.publicKey ?? client.account?.publicKey;
2609
2609
  if (!publicKey) {
2610
2610
  throw new Error("buildCall requires a publicKey (pass options.publicKey or configure a client account)");
@@ -2665,7 +2665,7 @@ function resolveNetworkContract(client, contracts) {
2665
2665
  }
2666
2666
  return contracts[client.chain.network];
2667
2667
  }
2668
- function buildFunctionArgs(fn, args) {
2668
+ function buildFunctionArgs(fn, args = {}) {
2669
2669
  return fn.args.map((arg) => {
2670
2670
  const camelKey = toCamelCase(arg.name);
2671
2671
  const hasOriginal = arg.name in args;
@@ -3861,5 +3861,5 @@ var getAccountHistory2 = defaultTools.getAccountHistory;
3861
3861
  var getMempoolStats2 = defaultTools.getMempoolStats;
3862
3862
  var getNftHoldings2 = defaultTools.getNftHoldings;
3863
3863
 
3864
- //# debugId=24BD4E2DF5A24D8B64756E2164756E21
3864
+ //# debugId=DE29EDB00BA8B07A64756E2164756E21
3865
3865
  //# sourceMappingURL=index.cjs.map