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