@nosana/kit 2.3.1 → 2.4.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 (45) hide show
  1. package/dist/index.d.ts +13 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +8 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/services/programs/jobs/JobsProgram.d.ts +146 -1
  6. package/dist/services/programs/jobs/JobsProgram.d.ts.map +1 -1
  7. package/dist/services/programs/jobs/JobsProgram.js +77 -0
  8. package/dist/services/programs/jobs/JobsProgram.js.map +1 -1
  9. package/dist/services/programs/jobs/computeUnits.d.ts +16 -0
  10. package/dist/services/programs/jobs/computeUnits.d.ts.map +1 -0
  11. package/dist/services/programs/jobs/computeUnits.generated.d.ts +39 -0
  12. package/dist/services/programs/jobs/computeUnits.generated.d.ts.map +1 -0
  13. package/dist/services/programs/jobs/computeUnits.generated.js +34 -0
  14. package/dist/services/programs/jobs/computeUnits.generated.js.map +1 -0
  15. package/dist/services/programs/jobs/computeUnits.js +20 -0
  16. package/dist/services/programs/jobs/computeUnits.js.map +1 -0
  17. package/dist/services/programs/jobs/decode.d.ts +29 -0
  18. package/dist/services/programs/jobs/decode.d.ts.map +1 -0
  19. package/dist/services/programs/jobs/decode.js +48 -0
  20. package/dist/services/programs/jobs/decode.js.map +1 -0
  21. package/dist/services/programs/jobs/discriminators.d.ts +21 -0
  22. package/dist/services/programs/jobs/discriminators.d.ts.map +1 -0
  23. package/dist/services/programs/jobs/discriminators.js +47 -0
  24. package/dist/services/programs/jobs/discriminators.js.map +1 -0
  25. package/dist/services/programs/jobs/index.d.ts +4 -0
  26. package/dist/services/programs/jobs/index.d.ts.map +1 -1
  27. package/dist/services/programs/jobs/index.js +4 -0
  28. package/dist/services/programs/jobs/index.js.map +1 -1
  29. package/dist/services/programs/jobs/instructions/complete.d.ts +1 -1
  30. package/dist/services/programs/jobs/instructions/complete.d.ts.map +1 -1
  31. package/dist/services/programs/jobs/instructions/complete.js +3 -3
  32. package/dist/services/programs/jobs/instructions/complete.js.map +1 -1
  33. package/dist/services/solana/SolanaService.d.ts +70 -0
  34. package/dist/services/solana/SolanaService.d.ts.map +1 -1
  35. package/dist/services/solana/SolanaService.js +115 -0
  36. package/dist/services/solana/SolanaService.js.map +1 -1
  37. package/dist/utils/index.d.ts +1 -0
  38. package/dist/utils/index.d.ts.map +1 -1
  39. package/dist/utils/index.js +1 -0
  40. package/dist/utils/index.js.map +1 -1
  41. package/dist/utils/packInstructions.d.ts +79 -0
  42. package/dist/utils/packInstructions.d.ts.map +1 -0
  43. package/dist/utils/packInstructions.js +110 -0
  44. package/dist/utils/packInstructions.js.map +1 -0
  45. package/package.json +2 -2
@@ -0,0 +1,79 @@
1
+ import { type Address, type Instruction } from '@solana/kit';
2
+ /**
3
+ * Maximum size, in bytes, of a serialized Solana transaction (the packet MTU limit).
4
+ * @group @nosana/kit
5
+ */
6
+ export declare const TRANSACTION_SIZE_LIMIT = 1232;
7
+ /**
8
+ * Maximum compute units a single Solana transaction may consume.
9
+ * @group @nosana/kit
10
+ */
11
+ export declare const MAX_COMPUTE_UNITS = 1400000;
12
+ /**
13
+ * Options for {@link packInstructions}.
14
+ * @group @nosana/kit
15
+ */
16
+ export interface PackInstructionsOptions {
17
+ /**
18
+ * The fee payer address for the resulting transactions. Provided so that size
19
+ * measurement accounts for account deduplication accurately (the fee payer is
20
+ * shared across every instruction). Defaults to a placeholder address, which is
21
+ * slightly conservative.
22
+ */
23
+ feePayer?: Address;
24
+ /**
25
+ * Instructions that will be prepended to every transaction at send time (for
26
+ * example compute-budget or priority-fee instructions). They are charged against
27
+ * the size budget of each bucket but are NOT included in the returned buckets —
28
+ * the transaction builder adds the real ones when sending.
29
+ */
30
+ reservedInstructions?: Instruction[];
31
+ /**
32
+ * Maximum serialized transaction size in bytes. Defaults to
33
+ * {@link TRANSACTION_SIZE_LIMIT} (1232).
34
+ */
35
+ maxTransactionSize?: number;
36
+ /**
37
+ * Optional per-instruction compute-unit estimator. When provided, a bucket is
38
+ * also split whenever its cumulative estimated compute units would exceed
39
+ * {@link PackInstructionsOptions.maxComputeUnits}. When omitted, compute units
40
+ * are not considered and only transaction size bounds the packing.
41
+ */
42
+ computeUnits?: (instruction: Instruction) => number;
43
+ /**
44
+ * Maximum compute units per transaction. Only enforced when
45
+ * {@link PackInstructionsOptions.computeUnits} is provided. Defaults to
46
+ * {@link MAX_COMPUTE_UNITS} (1,400,000).
47
+ */
48
+ maxComputeUnits?: number;
49
+ }
50
+ /**
51
+ * Greedily pack instruction groups into the fewest transactions that each stay
52
+ * within Solana's transaction size limit.
53
+ *
54
+ * Each entry of `groups` is an *atomic group*: a single instruction, or an array
55
+ * of instructions that must land together in the same transaction (e.g. a
56
+ * create-account + initialize pair). A group is never split across transactions;
57
+ * groups are filled into a bucket in order until the next group would overflow the
58
+ * size limit, at which point a new bucket is started.
59
+ *
60
+ * A bucket is bounded by two constraints, and is split whenever the next group
61
+ * would exceed either one:
62
+ * - Transaction size: determined by compiling each candidate transaction
63
+ * in-memory and measuring its serialized length, so shared accounts (program
64
+ * ids, fee payer, sysvars) are correctly deduplicated — no static estimate and
65
+ * no RPC call.
66
+ * - Compute units (optional): when a `computeUnits` estimator is provided, the
67
+ * cumulative estimated compute units of a bucket may not exceed
68
+ * `maxComputeUnits`.
69
+ *
70
+ * @param groups Atomic instruction groups to pack, in order.
71
+ * @param options Packing options (fee payer, reserved instructions, limits).
72
+ * @returns An array of buckets; each bucket is a flat array of instructions for
73
+ * one transaction.
74
+ * @throws {NosanaError} If a single group cannot fit in one transaction (by size
75
+ * or compute units), since it cannot be split.
76
+ * @group @nosana/kit
77
+ */
78
+ export declare function packInstructions(groups: Array<Instruction | Instruction[]>, options?: PackInstructionsOptions): Instruction[][];
79
+ //# sourceMappingURL=packInstructions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packInstructions.d.ts","sourceRoot":"","sources":["../../src/utils/packInstructions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAEZ,KAAK,WAAW,EASjB,MAAM,aAAa,CAAC;AAGrB;;;GAGG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,UAAY,CAAC;AA+B3C;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC;IACrC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,MAAM,CAAC;IACpD;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,KAAK,CAAC,WAAW,GAAG,WAAW,EAAE,CAAC,EAC1C,OAAO,GAAE,uBAA4B,GACpC,WAAW,EAAE,EAAE,CA0DjB"}
@@ -0,0 +1,110 @@
1
+ import { address, appendTransactionMessageInstructions, compileTransaction, createTransactionMessage, getTransactionEncoder, pipe, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, } from '@solana/kit';
2
+ import { ErrorCodes, NosanaError } from '../errors/NosanaError.js';
3
+ /**
4
+ * Maximum size, in bytes, of a serialized Solana transaction (the packet MTU limit).
5
+ * @group @nosana/kit
6
+ */
7
+ export const TRANSACTION_SIZE_LIMIT = 1232;
8
+ /**
9
+ * Maximum compute units a single Solana transaction may consume.
10
+ * @group @nosana/kit
11
+ */
12
+ export const MAX_COMPUTE_UNITS = 1400000;
13
+ // Placeholder fee payer and blockhash used purely to measure a transaction's
14
+ // serialized size locally (no RPC). Neither value affects the byte length: a fee
15
+ // payer is always one 32-byte account and a blockhash is always 32 bytes, so the
16
+ // measurement is size-accurate. Using a placeholder fee payer that does not appear
17
+ // in any instruction is the conservative choice — it can only ever over-count by a
18
+ // single account, never under-count.
19
+ const PLACEHOLDER_FEE_PAYER = address('11111111111111111111111111111112');
20
+ const PLACEHOLDER_BLOCKHASH = {
21
+ blockhash: '11111111111111111111111111111111',
22
+ lastValidBlockHeight: 0n,
23
+ };
24
+ const transactionEncoder = getTransactionEncoder();
25
+ /**
26
+ * Measure the serialized byte size of a transaction built from the given
27
+ * instructions. Compiles the message in-memory using placeholder fee payer and
28
+ * blockhash values — no network access and no signing required.
29
+ */
30
+ function measureTransactionSize(instructions, feePayer) {
31
+ const message = pipe(createTransactionMessage({ version: 0 }), (tx) => setTransactionMessageFeePayer(feePayer, tx), (tx) => setTransactionMessageLifetimeUsingBlockhash(PLACEHOLDER_BLOCKHASH, tx), (tx) => appendTransactionMessageInstructions(instructions, tx));
32
+ return transactionEncoder.encode(compileTransaction(message)).length;
33
+ }
34
+ /**
35
+ * Greedily pack instruction groups into the fewest transactions that each stay
36
+ * within Solana's transaction size limit.
37
+ *
38
+ * Each entry of `groups` is an *atomic group*: a single instruction, or an array
39
+ * of instructions that must land together in the same transaction (e.g. a
40
+ * create-account + initialize pair). A group is never split across transactions;
41
+ * groups are filled into a bucket in order until the next group would overflow the
42
+ * size limit, at which point a new bucket is started.
43
+ *
44
+ * A bucket is bounded by two constraints, and is split whenever the next group
45
+ * would exceed either one:
46
+ * - Transaction size: determined by compiling each candidate transaction
47
+ * in-memory and measuring its serialized length, so shared accounts (program
48
+ * ids, fee payer, sysvars) are correctly deduplicated — no static estimate and
49
+ * no RPC call.
50
+ * - Compute units (optional): when a `computeUnits` estimator is provided, the
51
+ * cumulative estimated compute units of a bucket may not exceed
52
+ * `maxComputeUnits`.
53
+ *
54
+ * @param groups Atomic instruction groups to pack, in order.
55
+ * @param options Packing options (fee payer, reserved instructions, limits).
56
+ * @returns An array of buckets; each bucket is a flat array of instructions for
57
+ * one transaction.
58
+ * @throws {NosanaError} If a single group cannot fit in one transaction (by size
59
+ * or compute units), since it cannot be split.
60
+ * @group @nosana/kit
61
+ */
62
+ export function packInstructions(groups, options = {}) {
63
+ const feePayer = options.feePayer ?? PLACEHOLDER_FEE_PAYER;
64
+ const reserved = options.reservedInstructions ?? [];
65
+ const maxSize = options.maxTransactionSize ?? TRANSACTION_SIZE_LIMIT;
66
+ const computeUnitsOf = options.computeUnits;
67
+ const maxCU = options.maxComputeUnits ?? MAX_COMPUTE_UNITS;
68
+ const groupComputeUnits = (ixs) => computeUnitsOf ? ixs.reduce((sum, ix) => sum + computeUnitsOf(ix), 0) : 0;
69
+ const buckets = [];
70
+ let current = [];
71
+ let currentCU = 0;
72
+ const tooLargeToSplit = (groupSize, constraint) => {
73
+ const limit = constraint === 'size' ? `${maxSize} bytes` : `${maxCU} compute units`;
74
+ throw new NosanaError(`An atomic group of ${groupSize} instruction(s) exceeds the maximum transaction ` +
75
+ `${constraint} (${limit}) and cannot be split across transactions`, ErrorCodes.TRANSACTION_ERROR);
76
+ };
77
+ for (const group of groups) {
78
+ const groupIxs = Array.isArray(group) ? group : [group];
79
+ if (groupIxs.length === 0)
80
+ continue;
81
+ const groupCU = groupComputeUnits(groupIxs);
82
+ const withGroup = [...current, ...groupIxs];
83
+ const sizeFits = measureTransactionSize([...reserved, ...withGroup], feePayer) <= maxSize;
84
+ const computeFits = !computeUnitsOf || currentCU + groupCU <= maxCU;
85
+ if (sizeFits && computeFits) {
86
+ current = withGroup;
87
+ currentCU += groupCU;
88
+ continue;
89
+ }
90
+ // The group does not fit alongside the current bucket's contents.
91
+ if (current.length === 0) {
92
+ // Nothing to flush — the group cannot fit even on its own.
93
+ tooLargeToSplit(groupIxs.length, sizeFits ? 'compute units' : 'size');
94
+ }
95
+ // Flush the current bucket and place the group into a fresh one.
96
+ buckets.push(current);
97
+ if (measureTransactionSize([...reserved, ...groupIxs], feePayer) > maxSize) {
98
+ tooLargeToSplit(groupIxs.length, 'size');
99
+ }
100
+ if (computeUnitsOf && groupCU > maxCU) {
101
+ tooLargeToSplit(groupIxs.length, 'compute units');
102
+ }
103
+ current = [...groupIxs];
104
+ currentCU = groupCU;
105
+ }
106
+ if (current.length > 0)
107
+ buckets.push(current);
108
+ return buckets;
109
+ }
110
+ //# sourceMappingURL=packInstructions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packInstructions.js","sourceRoot":"","sources":["../../src/utils/packInstructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,OAAO,EACP,oCAAoC,EACpC,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,EACrB,IAAI,EACJ,6BAA6B,EAC7B,2CAA2C,GAC5C,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAS,CAAC;AAE3C,6EAA6E;AAC7E,iFAAiF;AACjF,iFAAiF;AACjF,mFAAmF;AACnF,mFAAmF;AACnF,qCAAqC;AACrC,MAAM,qBAAqB,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AAC1E,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,kCAA+C;IAC1D,oBAAoB,EAAE,EAAE;CACzB,CAAC;AAEF,MAAM,kBAAkB,GAAG,qBAAqB,EAAE,CAAC;AAEnD;;;;GAIG;AACH,SAAS,sBAAsB,CAAC,YAA2B,EAAE,QAAiB;IAC5E,MAAM,OAAO,GAAG,IAAI,CAClB,wBAAwB,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EACxC,CAAC,EAAE,EAAE,EAAE,CAAC,6BAA6B,CAAC,QAAQ,EAAE,EAAE,CAAC,EACnD,CAAC,EAAE,EAAE,EAAE,CAAC,2CAA2C,CAAC,qBAAqB,EAAE,EAAE,CAAC,EAC9E,CAAC,EAA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E,CAAC;YACtC,eAAe,CAAC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;QACxB,SAAS,GAAG,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/kit",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "Nosana KIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -71,5 +71,5 @@
71
71
  "package.json",
72
72
  "README.md"
73
73
  ],
74
- "gitHead": "f0557eb71c17043450f159a72d67967a6045c74a"
74
+ "gitHead": "727e525c44bdb61ec109d23d0f850475e1e0cc55"
75
75
  }