@solana/sysvars 2.0.0-preview.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.
Files changed (37) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +17 -0
  3. package/dist/index.browser.cjs +813 -0
  4. package/dist/index.browser.cjs.map +1 -0
  5. package/dist/index.browser.js +759 -0
  6. package/dist/index.browser.js.map +1 -0
  7. package/dist/index.native.js +759 -0
  8. package/dist/index.native.js.map +1 -0
  9. package/dist/index.node.cjs +813 -0
  10. package/dist/index.node.cjs.map +1 -0
  11. package/dist/index.node.js +759 -0
  12. package/dist/index.node.js.map +1 -0
  13. package/dist/types/clock.d.ts +30 -0
  14. package/dist/types/clock.d.ts.map +1 -0
  15. package/dist/types/epoch-rewards.d.ts +42 -0
  16. package/dist/types/epoch-rewards.d.ts.map +1 -0
  17. package/dist/types/epoch-schedule.d.ts +29 -0
  18. package/dist/types/epoch-schedule.d.ts.map +1 -0
  19. package/dist/types/fees.d.ts +28 -0
  20. package/dist/types/fees.d.ts.map +1 -0
  21. package/dist/types/index.d.ts +12 -0
  22. package/dist/types/index.d.ts.map +1 -0
  23. package/dist/types/last-restart-slot.d.ts +33 -0
  24. package/dist/types/last-restart-slot.d.ts.map +1 -0
  25. package/dist/types/recent-blockhashes.d.ts +29 -0
  26. package/dist/types/recent-blockhashes.d.ts.map +1 -0
  27. package/dist/types/rent.d.ts +27 -0
  28. package/dist/types/rent.d.ts.map +1 -0
  29. package/dist/types/slot-hashes.d.ts +26 -0
  30. package/dist/types/slot-hashes.d.ts.map +1 -0
  31. package/dist/types/slot-history.d.ts +27 -0
  32. package/dist/types/slot-history.d.ts.map +1 -0
  33. package/dist/types/stake-history.d.ts +27 -0
  34. package/dist/types/stake-history.d.ts.map +1 -0
  35. package/dist/types/sysvar.d.ts +33 -0
  36. package/dist/types/sysvar.d.ts.map +1 -0
  37. package/package.json +80 -0
@@ -0,0 +1,813 @@
1
+ 'use strict';
2
+
3
+ var accounts = require('@solana/accounts');
4
+ var codecs = require('@solana/codecs');
5
+ var errors = require('@solana/errors');
6
+
7
+ // src/clock.ts
8
+ var SYSVAR_CLOCK_ADDRESS = "SysvarC1ock11111111111111111111111111111111";
9
+ var SYSVAR_EPOCH_REWARDS_ADDRESS = "SysvarEpochRewards1111111111111111111111111";
10
+ var SYSVAR_EPOCH_SCHEDULE_ADDRESS = "SysvarEpochSchedu1e111111111111111111111111";
11
+ var SYSVAR_FEES_ADDRESS = "SysvarFees111111111111111111111111111111111";
12
+ var SYSVAR_INSTRUCTIONS_ADDRESS = "Sysvar1nstructions1111111111111111111111111";
13
+ var SYSVAR_LAST_RESTART_SLOT_ADDRESS = "SysvarLastRestartS1ot1111111111111111111111";
14
+ var SYSVAR_RECENT_BLOCKHASHES_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
15
+ var SYSVAR_RENT_ADDRESS = "SysvarRent111111111111111111111111111111111";
16
+ var SYSVAR_SLOT_HASHES_ADDRESS = "SysvarS1otHashes111111111111111111111111111";
17
+ var SYSVAR_SLOT_HISTORY_ADDRESS = "SysvarS1otHistory11111111111111111111111111";
18
+ var SYSVAR_STAKE_HISTORY_ADDRESS = "SysvarStakeHistory1111111111111111111111111";
19
+ async function fetchEncodedSysvarAccount(rpc, address, config) {
20
+ return accounts.fetchEncodedAccount(rpc, address, config);
21
+ }
22
+ async function fetchJsonParsedSysvarAccount(rpc, address, config) {
23
+ return accounts.fetchJsonParsedAccount(rpc, address, config);
24
+ }
25
+
26
+ // src/clock.ts
27
+ function getSysvarClockEncoder() {
28
+ return codecs.getStructEncoder([
29
+ ["slot", codecs.getU64Encoder()],
30
+ ["epochStartTimestamp", codecs.getI64Encoder()],
31
+ ["epoch", codecs.getU64Encoder()],
32
+ ["leaderScheduleEpoch", codecs.getU64Encoder()],
33
+ ["unixTimestamp", codecs.getI64Encoder()]
34
+ ]);
35
+ }
36
+ function getSysvarClockDecoder() {
37
+ return codecs.getStructDecoder([
38
+ ["slot", codecs.getU64Decoder()],
39
+ ["epochStartTimestamp", codecs.getI64Decoder()],
40
+ ["epoch", codecs.getU64Decoder()],
41
+ ["leaderScheduleEpoch", codecs.getU64Decoder()],
42
+ ["unixTimestamp", codecs.getI64Decoder()]
43
+ ]);
44
+ }
45
+ function getSysvarClockCodec() {
46
+ return codecs.combineCodec(getSysvarClockEncoder(), getSysvarClockDecoder());
47
+ }
48
+ async function fetchSysvarClock(rpc, config) {
49
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS, config);
50
+ accounts.assertAccountExists(account);
51
+ const decoded = accounts.decodeAccount(account, getSysvarClockDecoder());
52
+ return decoded.data;
53
+ }
54
+ function getSysvarEpochRewardsEncoder() {
55
+ return codecs.getStructEncoder([
56
+ ["distributionCompleteBlockHeight", codecs.getU64Encoder()],
57
+ ["distributedRewards", codecs.getU64Encoder()],
58
+ ["totalRewards", codecs.getU64Encoder()]
59
+ ]);
60
+ }
61
+ function getSysvarEpochRewardsDecoder() {
62
+ return codecs.getStructDecoder([
63
+ ["distributionCompleteBlockHeight", codecs.getU64Decoder()],
64
+ ["distributedRewards", codecs.getU64Decoder()],
65
+ ["totalRewards", codecs.getU64Decoder()]
66
+ ]);
67
+ }
68
+ function getSysvarEpochRewardsCodec() {
69
+ return codecs.combineCodec(getSysvarEpochRewardsEncoder(), getSysvarEpochRewardsDecoder());
70
+ }
71
+ async function fetchSysvarEpochRewards(rpc, config) {
72
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_EPOCH_REWARDS_ADDRESS, config);
73
+ accounts.assertAccountExists(account);
74
+ const decoded = accounts.decodeAccount(account, getSysvarEpochRewardsDecoder());
75
+ return decoded.data;
76
+ }
77
+ function getSysvarEpochScheduleEncoder() {
78
+ return codecs.getStructEncoder([
79
+ ["slotsPerEpoch", codecs.getU64Encoder()],
80
+ ["leaderScheduleSlotOffset", codecs.getU64Encoder()],
81
+ ["warmup", codecs.getBooleanEncoder()],
82
+ ["firstNormalEpoch", codecs.getU64Encoder()],
83
+ ["firstNormalSlot", codecs.getU64Encoder()]
84
+ ]);
85
+ }
86
+ function getSysvarEpochScheduleDecoder() {
87
+ return codecs.getStructDecoder([
88
+ ["slotsPerEpoch", codecs.getU64Decoder()],
89
+ ["leaderScheduleSlotOffset", codecs.getU64Decoder()],
90
+ ["warmup", codecs.getBooleanDecoder()],
91
+ ["firstNormalEpoch", codecs.getU64Decoder()],
92
+ ["firstNormalSlot", codecs.getU64Decoder()]
93
+ ]);
94
+ }
95
+ function getSysvarEpochScheduleCodec() {
96
+ return codecs.combineCodec(getSysvarEpochScheduleEncoder(), getSysvarEpochScheduleDecoder());
97
+ }
98
+ async function fetchSysvarEpochSchedule(rpc, config) {
99
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_EPOCH_SCHEDULE_ADDRESS, config);
100
+ accounts.assertAccountExists(account);
101
+ const decoded = accounts.decodeAccount(account, getSysvarEpochScheduleDecoder());
102
+ return decoded.data;
103
+ }
104
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
105
+ if (bytes.length - offset <= 0) {
106
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY, {
107
+ codecDescription
108
+ });
109
+ }
110
+ }
111
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
112
+ const bytesLength = bytes.length - offset;
113
+ if (bytesLength < expected) {
114
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH, {
115
+ bytesLength,
116
+ codecDescription,
117
+ expected
118
+ });
119
+ }
120
+ }
121
+ var padBytes = (bytes, length) => {
122
+ if (bytes.length >= length)
123
+ return bytes;
124
+ const paddedBytes = new Uint8Array(length).fill(0);
125
+ paddedBytes.set(bytes);
126
+ return paddedBytes;
127
+ };
128
+ var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
129
+ function getEncodedSize(value, encoder) {
130
+ return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
131
+ }
132
+ function createEncoder(encoder) {
133
+ return Object.freeze({
134
+ ...encoder,
135
+ encode: (value) => {
136
+ const bytes = new Uint8Array(getEncodedSize(value, encoder));
137
+ encoder.write(value, bytes, 0);
138
+ return bytes;
139
+ }
140
+ });
141
+ }
142
+ function createDecoder(decoder) {
143
+ return Object.freeze({
144
+ ...decoder,
145
+ decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
146
+ });
147
+ }
148
+ function isFixedSize(codec) {
149
+ return "fixedSize" in codec && typeof codec.fixedSize === "number";
150
+ }
151
+ function fixEncoder(encoder, fixedBytes) {
152
+ return createEncoder({
153
+ fixedSize: fixedBytes,
154
+ write: (value, bytes, offset) => {
155
+ const variableByteArray = encoder.encode(value);
156
+ const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
157
+ bytes.set(fixedByteArray, offset);
158
+ return offset + fixedBytes;
159
+ }
160
+ });
161
+ }
162
+ function fixDecoder(decoder, fixedBytes) {
163
+ return createDecoder({
164
+ fixedSize: fixedBytes,
165
+ read: (bytes, offset) => {
166
+ assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
167
+ if (offset > 0 || bytes.length > fixedBytes) {
168
+ bytes = bytes.slice(offset, offset + fixedBytes);
169
+ }
170
+ if (isFixedSize(decoder)) {
171
+ bytes = fixBytes(bytes, decoder.fixedSize);
172
+ }
173
+ const [value] = decoder.read(bytes, 0);
174
+ return [value, offset + fixedBytes];
175
+ }
176
+ });
177
+ }
178
+ function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
179
+ if (value < min || value > max) {
180
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__NUMBER_OUT_OF_RANGE, {
181
+ codecDescription,
182
+ max,
183
+ min,
184
+ value
185
+ });
186
+ }
187
+ }
188
+ function isLittleEndian(config) {
189
+ return config?.endian === 1 ? false : true;
190
+ }
191
+ function numberEncoderFactory(input) {
192
+ return createEncoder({
193
+ fixedSize: input.size,
194
+ write(value, bytes, offset) {
195
+ if (input.range) {
196
+ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
197
+ }
198
+ const arrayBuffer = new ArrayBuffer(input.size);
199
+ input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
200
+ bytes.set(new Uint8Array(arrayBuffer), offset);
201
+ return offset + input.size;
202
+ }
203
+ });
204
+ }
205
+ function numberDecoderFactory(input) {
206
+ return createDecoder({
207
+ fixedSize: input.size,
208
+ read(bytes, offset = 0) {
209
+ assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
210
+ assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
211
+ const view = new DataView(toArrayBuffer(bytes, offset, input.size));
212
+ return [input.get(view, isLittleEndian(input.config)), offset + input.size];
213
+ }
214
+ });
215
+ }
216
+ function toArrayBuffer(bytes, offset, length) {
217
+ const bytesOffset = bytes.byteOffset + (offset ?? 0);
218
+ const bytesLength = length ?? bytes.byteLength;
219
+ return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
220
+ }
221
+ var getU32Encoder = (config = {}) => numberEncoderFactory({
222
+ config,
223
+ name: "u32",
224
+ range: [0, Number("0xffffffff")],
225
+ set: (view, value, le) => view.setUint32(0, value, le),
226
+ size: 4
227
+ });
228
+ var getU32Decoder = (config = {}) => numberDecoderFactory({
229
+ config,
230
+ get: (view, le) => view.getUint32(0, le),
231
+ name: "u32",
232
+ size: 4
233
+ });
234
+ var getU64Encoder4 = (config = {}) => numberEncoderFactory({
235
+ config,
236
+ name: "u64",
237
+ range: [0n, BigInt("0xffffffffffffffff")],
238
+ set: (view, value, le) => view.setBigUint64(0, BigInt(value), le),
239
+ size: 8
240
+ });
241
+ var getU64Decoder4 = (config = {}) => numberDecoderFactory({
242
+ config,
243
+ get: (view, le) => view.getBigUint64(0, le),
244
+ name: "u64",
245
+ size: 8
246
+ });
247
+
248
+ // ../codecs-strings/dist/index.node.js
249
+ function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
250
+ if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
251
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
252
+ alphabet: alphabet4,
253
+ base: alphabet4.length,
254
+ value: givenValue
255
+ });
256
+ }
257
+ }
258
+ var getBaseXEncoder = (alphabet4) => {
259
+ return createEncoder({
260
+ getSizeFromValue: (value) => {
261
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
262
+ if (!tailChars)
263
+ return value.length;
264
+ const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
265
+ return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
266
+ },
267
+ write(value, bytes, offset) {
268
+ assertValidBaseString(alphabet4, value);
269
+ if (value === "")
270
+ return offset;
271
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
272
+ if (!tailChars) {
273
+ bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
274
+ return offset + leadingZeroes.length;
275
+ }
276
+ let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
277
+ const tailBytes = [];
278
+ while (base10Number > 0n) {
279
+ tailBytes.unshift(Number(base10Number % 256n));
280
+ base10Number /= 256n;
281
+ }
282
+ const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
283
+ bytes.set(bytesToAdd, offset);
284
+ return offset + bytesToAdd.length;
285
+ }
286
+ });
287
+ };
288
+ var getBaseXDecoder = (alphabet4) => {
289
+ return createDecoder({
290
+ read(rawBytes, offset) {
291
+ const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
292
+ if (bytes.length === 0)
293
+ return ["", 0];
294
+ let trailIndex = bytes.findIndex((n) => n !== 0);
295
+ trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
296
+ const leadingZeroes = alphabet4[0].repeat(trailIndex);
297
+ if (trailIndex === bytes.length)
298
+ return [leadingZeroes, rawBytes.length];
299
+ const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
300
+ const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
301
+ return [leadingZeroes + tailChars, rawBytes.length];
302
+ }
303
+ });
304
+ };
305
+ function partitionLeadingZeroes(value, zeroCharacter) {
306
+ const [leadingZeros, tailChars] = value.split(new RegExp(`((?!${zeroCharacter}).*)`));
307
+ return [leadingZeros, tailChars];
308
+ }
309
+ function getBigIntFromBaseX(value, alphabet4) {
310
+ const base = BigInt(alphabet4.length);
311
+ let sum = 0n;
312
+ for (const char of value) {
313
+ sum *= base;
314
+ sum += BigInt(alphabet4.indexOf(char));
315
+ }
316
+ return sum;
317
+ }
318
+ function getBaseXFromBigInt(value, alphabet4) {
319
+ const base = BigInt(alphabet4.length);
320
+ const tailChars = [];
321
+ while (value > 0n) {
322
+ tailChars.unshift(alphabet4[Number(value % base)]);
323
+ value /= base;
324
+ }
325
+ return tailChars.join("");
326
+ }
327
+ var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
328
+ var getBase58Encoder = () => getBaseXEncoder(alphabet2);
329
+ var getBase58Decoder = () => getBaseXDecoder(alphabet2);
330
+ var removeNullCharacters = (value) => (
331
+ // eslint-disable-next-line no-control-regex
332
+ value.replace(/\u0000/g, "")
333
+ );
334
+ var e = globalThis.TextDecoder;
335
+ var o = globalThis.TextEncoder;
336
+ var getUtf8Encoder = () => {
337
+ let textEncoder;
338
+ return createEncoder({
339
+ getSizeFromValue: (value) => (textEncoder ||= new o()).encode(value).length,
340
+ write: (value, bytes, offset) => {
341
+ const bytesToAdd = (textEncoder ||= new o()).encode(value);
342
+ bytes.set(bytesToAdd, offset);
343
+ return offset + bytesToAdd.length;
344
+ }
345
+ });
346
+ };
347
+ var getUtf8Decoder = () => {
348
+ let textDecoder;
349
+ return createDecoder({
350
+ read(bytes, offset) {
351
+ const value = (textDecoder ||= new e()).decode(bytes.slice(offset));
352
+ return [removeNullCharacters(value), bytes.length];
353
+ }
354
+ });
355
+ };
356
+ function getStringEncoder(config = {}) {
357
+ const size = config.size ?? getU32Encoder();
358
+ const encoding = config.encoding ?? getUtf8Encoder();
359
+ if (size === "variable") {
360
+ return encoding;
361
+ }
362
+ if (typeof size === "number") {
363
+ return fixEncoder(encoding, size);
364
+ }
365
+ return createEncoder({
366
+ getSizeFromValue: (value) => {
367
+ const contentSize = getEncodedSize(value, encoding);
368
+ return getEncodedSize(contentSize, size) + contentSize;
369
+ },
370
+ write: (value, bytes, offset) => {
371
+ const contentSize = getEncodedSize(value, encoding);
372
+ offset = size.write(contentSize, bytes, offset);
373
+ return encoding.write(value, bytes, offset);
374
+ }
375
+ });
376
+ }
377
+ function getStringDecoder(config = {}) {
378
+ const size = config.size ?? getU32Decoder();
379
+ const encoding = config.encoding ?? getUtf8Decoder();
380
+ if (size === "variable") {
381
+ return encoding;
382
+ }
383
+ if (typeof size === "number") {
384
+ return fixDecoder(encoding, size);
385
+ }
386
+ return createDecoder({
387
+ read: (bytes, offset = 0) => {
388
+ assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
389
+ const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
390
+ const length = Number(lengthBigInt);
391
+ offset = lengthOffset;
392
+ const contentBytes = bytes.slice(offset, offset + length);
393
+ assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
394
+ const [value, contentOffset] = encoding.read(contentBytes, 0);
395
+ offset += contentOffset;
396
+ return [value, offset];
397
+ }
398
+ });
399
+ }
400
+
401
+ // ../rpc-types/dist/index.node.js
402
+ function getEncodedSize2(value, encoder) {
403
+ return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
404
+ }
405
+ function createEncoder2(encoder) {
406
+ return Object.freeze({
407
+ ...encoder,
408
+ encode: (value) => {
409
+ const bytes = new Uint8Array(getEncodedSize2(value, encoder));
410
+ encoder.write(value, bytes, 0);
411
+ return bytes;
412
+ }
413
+ });
414
+ }
415
+ function createDecoder2(decoder) {
416
+ return Object.freeze({
417
+ ...decoder,
418
+ decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
419
+ });
420
+ }
421
+ function isFixedSize2(codec) {
422
+ return "fixedSize" in codec && typeof codec.fixedSize === "number";
423
+ }
424
+ function isVariableSize(codec) {
425
+ return !isFixedSize2(codec);
426
+ }
427
+ function mapEncoder(encoder, unmap) {
428
+ return createEncoder2({
429
+ ...isVariableSize(encoder) ? { ...encoder, getSizeFromValue: (value) => encoder.getSizeFromValue(unmap(value)) } : encoder,
430
+ write: (value, bytes, offset) => encoder.write(unmap(value), bytes, offset)
431
+ });
432
+ }
433
+ function mapDecoder(decoder, map) {
434
+ return createDecoder2({
435
+ ...decoder,
436
+ read: (bytes, offset) => {
437
+ const [value, newOffset] = decoder.read(bytes, offset);
438
+ return [map(value, bytes, offset), newOffset];
439
+ }
440
+ });
441
+ }
442
+ var memoizedBase58Encoder;
443
+ var memoizedBase58Decoder;
444
+ function getMemoizedBase58Encoder() {
445
+ if (!memoizedBase58Encoder)
446
+ memoizedBase58Encoder = getBase58Encoder();
447
+ return memoizedBase58Encoder;
448
+ }
449
+ function getMemoizedBase58Decoder() {
450
+ if (!memoizedBase58Decoder)
451
+ memoizedBase58Decoder = getBase58Decoder();
452
+ return memoizedBase58Decoder;
453
+ }
454
+ function assertIsBlockhash(putativeBlockhash) {
455
+ if (
456
+ // Lowest value (32 bytes of zeroes)
457
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
458
+ putativeBlockhash.length > 44
459
+ ) {
460
+ throw new errors.SolanaError(errors.SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE, {
461
+ actualLength: putativeBlockhash.length
462
+ });
463
+ }
464
+ const base58Encoder = getMemoizedBase58Encoder();
465
+ const bytes = base58Encoder.encode(putativeBlockhash);
466
+ const numBytes = bytes.byteLength;
467
+ if (numBytes !== 32) {
468
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INVALID_BLOCKHASH_BYTE_LENGTH, {
469
+ actualLength: numBytes
470
+ });
471
+ }
472
+ }
473
+ function blockhash(putativeBlockhash) {
474
+ assertIsBlockhash(putativeBlockhash);
475
+ return putativeBlockhash;
476
+ }
477
+ function getBlockhashEncoder() {
478
+ return mapEncoder(
479
+ getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }),
480
+ (putativeBlockhash) => blockhash(putativeBlockhash)
481
+ );
482
+ }
483
+ function getBlockhashDecoder() {
484
+ return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 });
485
+ }
486
+ var maxU64Value = 18446744073709551615n;
487
+ var memoizedU64Encoder;
488
+ var memoizedU64Decoder;
489
+ function getMemoizedU64Encoder() {
490
+ if (!memoizedU64Encoder)
491
+ memoizedU64Encoder = getU64Encoder4();
492
+ return memoizedU64Encoder;
493
+ }
494
+ function getMemoizedU64Decoder() {
495
+ if (!memoizedU64Decoder)
496
+ memoizedU64Decoder = getU64Decoder4();
497
+ return memoizedU64Decoder;
498
+ }
499
+ function assertIsLamports(putativeLamports) {
500
+ if (putativeLamports < 0 || putativeLamports > maxU64Value) {
501
+ throw new errors.SolanaError(errors.SOLANA_ERROR__LAMPORTS_OUT_OF_RANGE);
502
+ }
503
+ }
504
+ function lamports(putativeLamports) {
505
+ assertIsLamports(putativeLamports);
506
+ return putativeLamports;
507
+ }
508
+ function getLamportsEncoder() {
509
+ return getMemoizedU64Encoder();
510
+ }
511
+ function getLamportsDecoder() {
512
+ return mapDecoder(getMemoizedU64Decoder(), lamports);
513
+ }
514
+
515
+ // src/fees.ts
516
+ function getSysvarFeesEncoder() {
517
+ return codecs.getStructEncoder([
518
+ ["feeCalculator", codecs.getStructEncoder([["lamportsPerSignature", getLamportsEncoder()]])]
519
+ ]);
520
+ }
521
+ function getSysvarFeesDecoder() {
522
+ return codecs.getStructDecoder([
523
+ ["feeCalculator", codecs.getStructDecoder([["lamportsPerSignature", getLamportsDecoder()]])]
524
+ ]);
525
+ }
526
+ function getSysvarFeesCodec() {
527
+ return codecs.combineCodec(getSysvarFeesEncoder(), getSysvarFeesDecoder());
528
+ }
529
+ async function fetchSysvarFees(rpc, config) {
530
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_FEES_ADDRESS, config);
531
+ accounts.assertAccountExists(account);
532
+ const decoded = accounts.decodeAccount(account, getSysvarFeesDecoder());
533
+ return decoded.data;
534
+ }
535
+ function getSysvarLastRestartSlotEncoder() {
536
+ return codecs.getStructEncoder([["lastRestartSlot", codecs.getU64Encoder()]]);
537
+ }
538
+ function getSysvarLastRestartSlotDecoder() {
539
+ return codecs.getStructDecoder([["lastRestartSlot", codecs.getU64Decoder()]]);
540
+ }
541
+ function getSysvarLastRestartSlotCodec() {
542
+ return codecs.combineCodec(getSysvarLastRestartSlotEncoder(), getSysvarLastRestartSlotDecoder());
543
+ }
544
+ async function fetchSysvarLastRestartSlot(rpc, config) {
545
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_LAST_RESTART_SLOT_ADDRESS, config);
546
+ accounts.assertAccountExists(account);
547
+ const decoded = accounts.decodeAccount(account, getSysvarLastRestartSlotDecoder());
548
+ return decoded.data;
549
+ }
550
+ function getSysvarRecentBlockhashesEncoder() {
551
+ return codecs.getArrayEncoder(
552
+ codecs.getStructEncoder([
553
+ ["blockhash", getBlockhashEncoder()],
554
+ ["feeCalculator", codecs.getStructEncoder([["lamportsPerSignature", getLamportsEncoder()]])]
555
+ ])
556
+ );
557
+ }
558
+ function getSysvarRecentBlockhashesDecoder() {
559
+ return codecs.getArrayDecoder(
560
+ codecs.getStructDecoder([
561
+ ["blockhash", getBlockhashDecoder()],
562
+ ["feeCalculator", codecs.getStructDecoder([["lamportsPerSignature", getLamportsDecoder()]])]
563
+ ])
564
+ );
565
+ }
566
+ function getSysvarRecentBlockhashesCodec() {
567
+ return codecs.combineCodec(getSysvarRecentBlockhashesEncoder(), getSysvarRecentBlockhashesDecoder());
568
+ }
569
+ async function fetchSysvarRecentBlockhashes(rpc, config) {
570
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_RECENT_BLOCKHASHES_ADDRESS, config);
571
+ accounts.assertAccountExists(account);
572
+ const decoded = accounts.decodeAccount(account, getSysvarRecentBlockhashesDecoder());
573
+ return decoded.data;
574
+ }
575
+ function getSysvarRentEncoder() {
576
+ return codecs.getStructEncoder([
577
+ ["lamportsPerByteYear", getLamportsEncoder()],
578
+ ["exemptionThreshold", codecs.getF64Encoder()],
579
+ ["burnPercent", codecs.getU8Encoder()]
580
+ ]);
581
+ }
582
+ function getSysvarRentDecoder() {
583
+ return codecs.getStructDecoder([
584
+ ["lamportsPerByteYear", getLamportsDecoder()],
585
+ ["exemptionThreshold", codecs.getF64Decoder()],
586
+ ["burnPercent", codecs.getU8Decoder()]
587
+ ]);
588
+ }
589
+ function getSysvarRentCodec() {
590
+ return codecs.combineCodec(getSysvarRentEncoder(), getSysvarRentDecoder());
591
+ }
592
+ async function fetchSysvarRent(rpc, config) {
593
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_RENT_ADDRESS, config);
594
+ accounts.assertAccountExists(account);
595
+ const decoded = accounts.decodeAccount(account, getSysvarRentDecoder());
596
+ return decoded.data;
597
+ }
598
+ function getSysvarSlotHashesEncoder() {
599
+ return codecs.getArrayEncoder(
600
+ codecs.getStructEncoder([
601
+ ["slot", codecs.getU64Encoder()],
602
+ ["hash", getBlockhashEncoder()]
603
+ ])
604
+ );
605
+ }
606
+ function getSysvarSlotHashesDecoder() {
607
+ return codecs.getArrayDecoder(
608
+ codecs.getStructDecoder([
609
+ ["slot", codecs.getU64Decoder()],
610
+ ["hash", getBlockhashDecoder()]
611
+ ])
612
+ );
613
+ }
614
+ function getSysvarSlotHashesCodec() {
615
+ return codecs.combineCodec(getSysvarSlotHashesEncoder(), getSysvarSlotHashesDecoder());
616
+ }
617
+ async function fetchSysvarSlotHashes(rpc, config) {
618
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_SLOT_HASHES_ADDRESS, config);
619
+ accounts.assertAccountExists(account);
620
+ const decoded = accounts.decodeAccount(account, getSysvarSlotHashesDecoder());
621
+ return decoded.data;
622
+ }
623
+ var BITVEC_DISCRIMINATOR = 1;
624
+ var BITVEC_NUM_BITS = 1024 * 1024;
625
+ var BITVEC_LENGTH = BITVEC_NUM_BITS / 64;
626
+ var SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE = 1 + // Discriminator
627
+ 8 + // bitvector length (u64)
628
+ BITVEC_LENGTH * 8 + 8 + // Number of bits (u64)
629
+ 8;
630
+ var memoizedU64Encoder2;
631
+ var memoizedU64Decoder2;
632
+ var memoizedU64ArrayEncoder;
633
+ var memoizedU64ArrayDecoder;
634
+ function getMemoizedU64Encoder2() {
635
+ if (!memoizedU64Encoder2)
636
+ memoizedU64Encoder2 = codecs.getU64Encoder();
637
+ return memoizedU64Encoder2;
638
+ }
639
+ function getMemoizedU64Decoder2() {
640
+ if (!memoizedU64Decoder2)
641
+ memoizedU64Decoder2 = codecs.getU64Decoder();
642
+ return memoizedU64Decoder2;
643
+ }
644
+ function getMemoizedU64ArrayEncoder() {
645
+ if (!memoizedU64ArrayEncoder)
646
+ memoizedU64ArrayEncoder = codecs.getArrayCodec(codecs.getU64Codec(), { size: BITVEC_LENGTH });
647
+ return memoizedU64ArrayEncoder;
648
+ }
649
+ function getMemoizedU64ArrayDecoder() {
650
+ if (!memoizedU64ArrayDecoder)
651
+ memoizedU64ArrayDecoder = codecs.getArrayCodec(codecs.getU64Codec(), { size: BITVEC_LENGTH });
652
+ return memoizedU64ArrayDecoder;
653
+ }
654
+ function getSysvarSlotHistoryEncoder() {
655
+ return codecs.createEncoder({
656
+ fixedSize: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE,
657
+ write: (value, bytes, offset) => {
658
+ bytes.set([BITVEC_DISCRIMINATOR], offset);
659
+ offset += 1;
660
+ getMemoizedU64Encoder2().write(BigInt(BITVEC_LENGTH), bytes, offset);
661
+ offset += 8;
662
+ getMemoizedU64ArrayEncoder().write(value.bits, bytes, offset);
663
+ offset += BITVEC_LENGTH * 8;
664
+ getMemoizedU64Encoder2().write(BigInt(BITVEC_NUM_BITS), bytes, offset);
665
+ offset += 8;
666
+ getMemoizedU64Encoder2().write(value.nextSlot, bytes, offset);
667
+ offset += 8;
668
+ return offset;
669
+ }
670
+ });
671
+ }
672
+ function getSysvarSlotHistoryDecoder() {
673
+ return codecs.createDecoder({
674
+ fixedSize: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE,
675
+ read: (bytes, offset) => {
676
+ if (bytes.length != SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE) {
677
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH, {
678
+ actual: bytes.length,
679
+ expected: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE
680
+ });
681
+ }
682
+ const discriminator = bytes[offset];
683
+ offset += 1;
684
+ if (discriminator !== BITVEC_DISCRIMINATOR) {
685
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__ENUM_DISCRIMINATOR_OUT_OF_RANGE, {
686
+ actual: discriminator,
687
+ expected: BITVEC_DISCRIMINATOR
688
+ });
689
+ }
690
+ const bitVecLength = getMemoizedU64Decoder2().read(bytes, offset)[0];
691
+ offset += 8;
692
+ if (bitVecLength !== BigInt(BITVEC_LENGTH)) {
693
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS, {
694
+ actual: bitVecLength,
695
+ codecDescription: "SysvarSlotHistoryCodec",
696
+ expected: BITVEC_LENGTH
697
+ });
698
+ }
699
+ const bits = getMemoizedU64ArrayDecoder().read(bytes, offset)[0];
700
+ offset += BITVEC_LENGTH * 8;
701
+ const numBits = getMemoizedU64Decoder2().read(bytes, offset)[0];
702
+ offset += 8;
703
+ if (numBits !== BigInt(BITVEC_NUM_BITS)) {
704
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS, {
705
+ actual: numBits,
706
+ codecDescription: "SysvarSlotHistoryCodec",
707
+ expected: BITVEC_NUM_BITS
708
+ });
709
+ }
710
+ const nextSlot = getMemoizedU64Decoder2().read(bytes, offset)[0];
711
+ offset += 8;
712
+ return [
713
+ {
714
+ bits,
715
+ nextSlot
716
+ },
717
+ offset
718
+ ];
719
+ }
720
+ });
721
+ }
722
+ function getSysvarSlotHistoryCodec() {
723
+ return codecs.combineCodec(getSysvarSlotHistoryEncoder(), getSysvarSlotHistoryDecoder());
724
+ }
725
+ async function fetchSysvarSlotHistory(rpc, config) {
726
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_SLOT_HISTORY_ADDRESS, config);
727
+ accounts.assertAccountExists(account);
728
+ const decoded = accounts.decodeAccount(account, getSysvarSlotHistoryDecoder());
729
+ return decoded.data;
730
+ }
731
+ function getSysvarStakeHistoryEncoder() {
732
+ return codecs.getArrayEncoder(
733
+ codecs.getStructEncoder([
734
+ ["effective", getLamportsEncoder()],
735
+ ["activating", getLamportsEncoder()],
736
+ ["deactivating", getLamportsEncoder()]
737
+ ])
738
+ );
739
+ }
740
+ function getSysvarStakeHistoryDecoder() {
741
+ return codecs.getArrayDecoder(
742
+ codecs.getStructDecoder([
743
+ ["effective", getLamportsDecoder()],
744
+ ["activating", getLamportsDecoder()],
745
+ ["deactivating", getLamportsDecoder()]
746
+ ])
747
+ );
748
+ }
749
+ function getSysvarStakeHistoryCodec() {
750
+ return codecs.combineCodec(getSysvarStakeHistoryEncoder(), getSysvarStakeHistoryDecoder());
751
+ }
752
+ async function fetchSysvarStakeHistory(rpc, config) {
753
+ const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_STAKE_HISTORY_ADDRESS, config);
754
+ accounts.assertAccountExists(account);
755
+ const decoded = accounts.decodeAccount(account, getSysvarStakeHistoryDecoder());
756
+ return decoded.data;
757
+ }
758
+
759
+ exports.SYSVAR_CLOCK_ADDRESS = SYSVAR_CLOCK_ADDRESS;
760
+ exports.SYSVAR_EPOCH_REWARDS_ADDRESS = SYSVAR_EPOCH_REWARDS_ADDRESS;
761
+ exports.SYSVAR_EPOCH_SCHEDULE_ADDRESS = SYSVAR_EPOCH_SCHEDULE_ADDRESS;
762
+ exports.SYSVAR_FEES_ADDRESS = SYSVAR_FEES_ADDRESS;
763
+ exports.SYSVAR_INSTRUCTIONS_ADDRESS = SYSVAR_INSTRUCTIONS_ADDRESS;
764
+ exports.SYSVAR_LAST_RESTART_SLOT_ADDRESS = SYSVAR_LAST_RESTART_SLOT_ADDRESS;
765
+ exports.SYSVAR_RECENT_BLOCKHASHES_ADDRESS = SYSVAR_RECENT_BLOCKHASHES_ADDRESS;
766
+ exports.SYSVAR_RENT_ADDRESS = SYSVAR_RENT_ADDRESS;
767
+ exports.SYSVAR_SLOT_HASHES_ADDRESS = SYSVAR_SLOT_HASHES_ADDRESS;
768
+ exports.SYSVAR_SLOT_HISTORY_ADDRESS = SYSVAR_SLOT_HISTORY_ADDRESS;
769
+ exports.SYSVAR_STAKE_HISTORY_ADDRESS = SYSVAR_STAKE_HISTORY_ADDRESS;
770
+ exports.fetchEncodedSysvarAccount = fetchEncodedSysvarAccount;
771
+ exports.fetchJsonParsedSysvarAccount = fetchJsonParsedSysvarAccount;
772
+ exports.fetchSysvarClock = fetchSysvarClock;
773
+ exports.fetchSysvarEpochRewards = fetchSysvarEpochRewards;
774
+ exports.fetchSysvarEpochSchedule = fetchSysvarEpochSchedule;
775
+ exports.fetchSysvarFees = fetchSysvarFees;
776
+ exports.fetchSysvarLastRestartSlot = fetchSysvarLastRestartSlot;
777
+ exports.fetchSysvarRecentBlockhashes = fetchSysvarRecentBlockhashes;
778
+ exports.fetchSysvarRent = fetchSysvarRent;
779
+ exports.fetchSysvarSlotHashes = fetchSysvarSlotHashes;
780
+ exports.fetchSysvarSlotHistory = fetchSysvarSlotHistory;
781
+ exports.fetchSysvarStakeHistory = fetchSysvarStakeHistory;
782
+ exports.getSysvarClockCodec = getSysvarClockCodec;
783
+ exports.getSysvarClockDecoder = getSysvarClockDecoder;
784
+ exports.getSysvarClockEncoder = getSysvarClockEncoder;
785
+ exports.getSysvarEpochRewardsCodec = getSysvarEpochRewardsCodec;
786
+ exports.getSysvarEpochRewardsDecoder = getSysvarEpochRewardsDecoder;
787
+ exports.getSysvarEpochRewardsEncoder = getSysvarEpochRewardsEncoder;
788
+ exports.getSysvarEpochScheduleCodec = getSysvarEpochScheduleCodec;
789
+ exports.getSysvarEpochScheduleDecoder = getSysvarEpochScheduleDecoder;
790
+ exports.getSysvarEpochScheduleEncoder = getSysvarEpochScheduleEncoder;
791
+ exports.getSysvarFeesCodec = getSysvarFeesCodec;
792
+ exports.getSysvarFeesDecoder = getSysvarFeesDecoder;
793
+ exports.getSysvarFeesEncoder = getSysvarFeesEncoder;
794
+ exports.getSysvarLastRestartSlotCodec = getSysvarLastRestartSlotCodec;
795
+ exports.getSysvarLastRestartSlotDecoder = getSysvarLastRestartSlotDecoder;
796
+ exports.getSysvarLastRestartSlotEncoder = getSysvarLastRestartSlotEncoder;
797
+ exports.getSysvarRecentBlockhashesCodec = getSysvarRecentBlockhashesCodec;
798
+ exports.getSysvarRecentBlockhashesDecoder = getSysvarRecentBlockhashesDecoder;
799
+ exports.getSysvarRecentBlockhashesEncoder = getSysvarRecentBlockhashesEncoder;
800
+ exports.getSysvarRentCodec = getSysvarRentCodec;
801
+ exports.getSysvarRentDecoder = getSysvarRentDecoder;
802
+ exports.getSysvarRentEncoder = getSysvarRentEncoder;
803
+ exports.getSysvarSlotHashesCodec = getSysvarSlotHashesCodec;
804
+ exports.getSysvarSlotHashesDecoder = getSysvarSlotHashesDecoder;
805
+ exports.getSysvarSlotHashesEncoder = getSysvarSlotHashesEncoder;
806
+ exports.getSysvarSlotHistoryCodec = getSysvarSlotHistoryCodec;
807
+ exports.getSysvarSlotHistoryDecoder = getSysvarSlotHistoryDecoder;
808
+ exports.getSysvarSlotHistoryEncoder = getSysvarSlotHistoryEncoder;
809
+ exports.getSysvarStakeHistoryCodec = getSysvarStakeHistoryCodec;
810
+ exports.getSysvarStakeHistoryDecoder = getSysvarStakeHistoryDecoder;
811
+ exports.getSysvarStakeHistoryEncoder = getSysvarStakeHistoryEncoder;
812
+ //# sourceMappingURL=out.js.map
813
+ //# sourceMappingURL=index.node.cjs.map