@solana/sysvars 2.0.0-20241006045741
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.
- package/LICENSE +20 -0
- package/README.md +93 -0
- package/dist/index.browser.cjs +398 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +344 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.native.mjs +344 -0
- package/dist/index.native.mjs.map +1 -0
- package/dist/index.node.cjs +398 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +344 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/types/clock.d.ts +29 -0
- package/dist/types/clock.d.ts.map +1 -0
- package/dist/types/epoch-rewards.d.ts +42 -0
- package/dist/types/epoch-rewards.d.ts.map +1 -0
- package/dist/types/epoch-schedule.d.ts +29 -0
- package/dist/types/epoch-schedule.d.ts.map +1 -0
- package/dist/types/fees.d.ts +28 -0
- package/dist/types/fees.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/last-restart-slot.d.ts +33 -0
- package/dist/types/last-restart-slot.d.ts.map +1 -0
- package/dist/types/recent-blockhashes.d.ts +29 -0
- package/dist/types/recent-blockhashes.d.ts.map +1 -0
- package/dist/types/rent.d.ts +27 -0
- package/dist/types/rent.d.ts.map +1 -0
- package/dist/types/slot-hashes.d.ts +26 -0
- package/dist/types/slot-hashes.d.ts.map +1 -0
- package/dist/types/slot-history.d.ts +27 -0
- package/dist/types/slot-history.d.ts.map +1 -0
- package/dist/types/stake-history.d.ts +27 -0
- package/dist/types/stake-history.d.ts.map +1 -0
- package/dist/types/sysvar.d.ts +33 -0
- package/dist/types/sysvar.d.ts.map +1 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2018 Solana Labs, Inc
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
[![npm][npm-image]][npm-url]
|
|
2
|
+
[![npm-downloads][npm-downloads-image]][npm-url]
|
|
3
|
+
[![semantic-release][semantic-release-image]][semantic-release-url]
|
|
4
|
+
<br />
|
|
5
|
+
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
|
|
6
|
+
|
|
7
|
+
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
8
|
+
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
9
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/sysvars/rc.svg?style=flat
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/@solana/sysvars/rc.svg?style=flat
|
|
11
|
+
[npm-url]: https://www.npmjs.com/package/@solana/sysvars/v/rc
|
|
12
|
+
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
13
|
+
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
14
|
+
|
|
15
|
+
# @solana/sysvars
|
|
16
|
+
|
|
17
|
+
This package contains types and helpers for fetching and decoding Solana
|
|
18
|
+
sysvars. It can be used standalone, but it is also exported as part of the
|
|
19
|
+
Solana JavaScript SDK
|
|
20
|
+
[`@solana/web3.js@rc`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
|
|
21
|
+
|
|
22
|
+
More information about the available sysvars on Solana can be found in the docs
|
|
23
|
+
at <https://docs.solanalabs.com/runtime/sysvars>.
|
|
24
|
+
|
|
25
|
+
All currently available sysvars can be retrieved and/or decoded using this
|
|
26
|
+
library.
|
|
27
|
+
|
|
28
|
+
## Sysvar API
|
|
29
|
+
|
|
30
|
+
This package offers a simple API for working with sysvars.
|
|
31
|
+
|
|
32
|
+
One can fetch an encoded sysvar account using an RPC client.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const maybeEncodedClock = await fetchEncodedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS);
|
|
36
|
+
maybeEncodedClock satisfies MaybeEncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
One can also attempt to fetch a JSON-parsed sysvar account.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const maybeJsonParsedClock = await fetchJsonParsedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS);
|
|
43
|
+
maybeJsonParsedClock satisfies
|
|
44
|
+
| MaybeAccount<JsonParsedSysvarAccount, 'SysvarC1ock11111111111111111111111111111111'>
|
|
45
|
+
| MaybeEncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Each sysvar within the library ships with its own
|
|
49
|
+
[codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs)
|
|
50
|
+
for deserializing the account data.
|
|
51
|
+
|
|
52
|
+
You can pair this codec with the helpers from
|
|
53
|
+
[`@solana/accounts`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/accounts)
|
|
54
|
+
to assert and decode sysvar account data.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// Fetch.
|
|
58
|
+
const clock = await fetchEncodedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS);
|
|
59
|
+
clock satisfies MaybeEncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
|
|
60
|
+
|
|
61
|
+
// Assert.
|
|
62
|
+
assertAccountExists(clock);
|
|
63
|
+
clock satisfies EncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
|
|
64
|
+
|
|
65
|
+
// Decode.
|
|
66
|
+
const decodedClock = decodeAccount(clock, getSysvarClockDecoder());
|
|
67
|
+
decodedClock satisfies Account<SysvarClock, 'SysvarC1ock11111111111111111111111111111111'>;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Each supported sysvar also ships with its own fetch-and-decode function to
|
|
71
|
+
perform the steps above and return the decoded sysvar data.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const clock: SysvarClock = await fetchSysvarClock(rpc);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Supported Sysvars:
|
|
78
|
+
|
|
79
|
+
This package supports the following Solana sysvars:
|
|
80
|
+
|
|
81
|
+
- [`Clock`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/clock.ts)
|
|
82
|
+
- [`EpochRewards`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/epoch-rewards.ts)
|
|
83
|
+
- [`EpochSchedule`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/epoch-schedule.ts)
|
|
84
|
+
- [`Fees`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/fees.ts)
|
|
85
|
+
- [`LastRestartSlot`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/last-restart-slot.ts)
|
|
86
|
+
- [`RecentBlockhashes`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/recent-blockhashes.ts)
|
|
87
|
+
- [`Rent`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/rent.ts)
|
|
88
|
+
- [`SlotHashes`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/slot-hashes.ts)
|
|
89
|
+
- [`SlotHistory`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/slot-history.ts)
|
|
90
|
+
- [`StakeHistory`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/stake-history.ts)
|
|
91
|
+
|
|
92
|
+
The `Instructions` sysvar is also supported but does not exist on-chain,
|
|
93
|
+
therefore has no corresponding module or codec.
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var accounts = require('@solana/accounts');
|
|
4
|
+
var codecs = require('@solana/codecs');
|
|
5
|
+
var rpcTypes = require('@solana/rpc-types');
|
|
6
|
+
var errors = require('@solana/errors');
|
|
7
|
+
|
|
8
|
+
// src/clock.ts
|
|
9
|
+
var SYSVAR_CLOCK_ADDRESS = "SysvarC1ock11111111111111111111111111111111";
|
|
10
|
+
var SYSVAR_EPOCH_REWARDS_ADDRESS = "SysvarEpochRewards1111111111111111111111111";
|
|
11
|
+
var SYSVAR_EPOCH_SCHEDULE_ADDRESS = "SysvarEpochSchedu1e111111111111111111111111";
|
|
12
|
+
var SYSVAR_FEES_ADDRESS = "SysvarFees111111111111111111111111111111111";
|
|
13
|
+
var SYSVAR_INSTRUCTIONS_ADDRESS = "Sysvar1nstructions1111111111111111111111111";
|
|
14
|
+
var SYSVAR_LAST_RESTART_SLOT_ADDRESS = "SysvarLastRestartS1ot1111111111111111111111";
|
|
15
|
+
var SYSVAR_RECENT_BLOCKHASHES_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
16
|
+
var SYSVAR_RENT_ADDRESS = "SysvarRent111111111111111111111111111111111";
|
|
17
|
+
var SYSVAR_SLOT_HASHES_ADDRESS = "SysvarS1otHashes111111111111111111111111111";
|
|
18
|
+
var SYSVAR_SLOT_HISTORY_ADDRESS = "SysvarS1otHistory11111111111111111111111111";
|
|
19
|
+
var SYSVAR_STAKE_HISTORY_ADDRESS = "SysvarStakeHistory1111111111111111111111111";
|
|
20
|
+
async function fetchEncodedSysvarAccount(rpc, address, config) {
|
|
21
|
+
return await accounts.fetchEncodedAccount(rpc, address, config);
|
|
22
|
+
}
|
|
23
|
+
async function fetchJsonParsedSysvarAccount(rpc, address, config) {
|
|
24
|
+
return await accounts.fetchJsonParsedAccount(rpc, address, config);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/clock.ts
|
|
28
|
+
function getSysvarClockEncoder() {
|
|
29
|
+
return codecs.getStructEncoder([
|
|
30
|
+
["slot", codecs.getU64Encoder()],
|
|
31
|
+
["epochStartTimestamp", codecs.getI64Encoder()],
|
|
32
|
+
["epoch", codecs.getU64Encoder()],
|
|
33
|
+
["leaderScheduleEpoch", codecs.getU64Encoder()],
|
|
34
|
+
["unixTimestamp", codecs.getI64Encoder()]
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
function getSysvarClockDecoder() {
|
|
38
|
+
return codecs.getStructDecoder([
|
|
39
|
+
["slot", codecs.getU64Decoder()],
|
|
40
|
+
["epochStartTimestamp", codecs.getI64Decoder()],
|
|
41
|
+
["epoch", codecs.getU64Decoder()],
|
|
42
|
+
["leaderScheduleEpoch", codecs.getU64Decoder()],
|
|
43
|
+
["unixTimestamp", codecs.getI64Decoder()]
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
function getSysvarClockCodec() {
|
|
47
|
+
return codecs.combineCodec(getSysvarClockEncoder(), getSysvarClockDecoder());
|
|
48
|
+
}
|
|
49
|
+
async function fetchSysvarClock(rpc, config) {
|
|
50
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS, config);
|
|
51
|
+
accounts.assertAccountExists(account);
|
|
52
|
+
const decoded = accounts.decodeAccount(account, getSysvarClockDecoder());
|
|
53
|
+
return decoded.data;
|
|
54
|
+
}
|
|
55
|
+
function getSysvarEpochRewardsEncoder() {
|
|
56
|
+
return codecs.getStructEncoder([
|
|
57
|
+
["distributionCompleteBlockHeight", codecs.getU64Encoder()],
|
|
58
|
+
["distributedRewards", codecs.getU64Encoder()],
|
|
59
|
+
["totalRewards", codecs.getU64Encoder()]
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
function getSysvarEpochRewardsDecoder() {
|
|
63
|
+
return codecs.getStructDecoder([
|
|
64
|
+
["distributionCompleteBlockHeight", codecs.getU64Decoder()],
|
|
65
|
+
["distributedRewards", codecs.getU64Decoder()],
|
|
66
|
+
["totalRewards", codecs.getU64Decoder()]
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
function getSysvarEpochRewardsCodec() {
|
|
70
|
+
return codecs.combineCodec(getSysvarEpochRewardsEncoder(), getSysvarEpochRewardsDecoder());
|
|
71
|
+
}
|
|
72
|
+
async function fetchSysvarEpochRewards(rpc, config) {
|
|
73
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_EPOCH_REWARDS_ADDRESS, config);
|
|
74
|
+
accounts.assertAccountExists(account);
|
|
75
|
+
const decoded = accounts.decodeAccount(account, getSysvarEpochRewardsDecoder());
|
|
76
|
+
return decoded.data;
|
|
77
|
+
}
|
|
78
|
+
function getSysvarEpochScheduleEncoder() {
|
|
79
|
+
return codecs.getStructEncoder([
|
|
80
|
+
["slotsPerEpoch", codecs.getU64Encoder()],
|
|
81
|
+
["leaderScheduleSlotOffset", codecs.getU64Encoder()],
|
|
82
|
+
["warmup", codecs.getBooleanEncoder()],
|
|
83
|
+
["firstNormalEpoch", codecs.getU64Encoder()],
|
|
84
|
+
["firstNormalSlot", codecs.getU64Encoder()]
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
function getSysvarEpochScheduleDecoder() {
|
|
88
|
+
return codecs.getStructDecoder([
|
|
89
|
+
["slotsPerEpoch", codecs.getU64Decoder()],
|
|
90
|
+
["leaderScheduleSlotOffset", codecs.getU64Decoder()],
|
|
91
|
+
["warmup", codecs.getBooleanDecoder()],
|
|
92
|
+
["firstNormalEpoch", codecs.getU64Decoder()],
|
|
93
|
+
["firstNormalSlot", codecs.getU64Decoder()]
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
function getSysvarEpochScheduleCodec() {
|
|
97
|
+
return codecs.combineCodec(getSysvarEpochScheduleEncoder(), getSysvarEpochScheduleDecoder());
|
|
98
|
+
}
|
|
99
|
+
async function fetchSysvarEpochSchedule(rpc, config) {
|
|
100
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_EPOCH_SCHEDULE_ADDRESS, config);
|
|
101
|
+
accounts.assertAccountExists(account);
|
|
102
|
+
const decoded = accounts.decodeAccount(account, getSysvarEpochScheduleDecoder());
|
|
103
|
+
return decoded.data;
|
|
104
|
+
}
|
|
105
|
+
function getSysvarFeesEncoder() {
|
|
106
|
+
return codecs.getStructEncoder([
|
|
107
|
+
["feeCalculator", codecs.getStructEncoder([["lamportsPerSignature", rpcTypes.getDefaultLamportsEncoder()]])]
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
function getSysvarFeesDecoder() {
|
|
111
|
+
return codecs.getStructDecoder([
|
|
112
|
+
["feeCalculator", codecs.getStructDecoder([["lamportsPerSignature", rpcTypes.getDefaultLamportsDecoder()]])]
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
function getSysvarFeesCodec() {
|
|
116
|
+
return codecs.combineCodec(getSysvarFeesEncoder(), getSysvarFeesDecoder());
|
|
117
|
+
}
|
|
118
|
+
async function fetchSysvarFees(rpc, config) {
|
|
119
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_FEES_ADDRESS, config);
|
|
120
|
+
accounts.assertAccountExists(account);
|
|
121
|
+
const decoded = accounts.decodeAccount(account, getSysvarFeesDecoder());
|
|
122
|
+
return decoded.data;
|
|
123
|
+
}
|
|
124
|
+
function getSysvarLastRestartSlotEncoder() {
|
|
125
|
+
return codecs.getStructEncoder([["lastRestartSlot", codecs.getU64Encoder()]]);
|
|
126
|
+
}
|
|
127
|
+
function getSysvarLastRestartSlotDecoder() {
|
|
128
|
+
return codecs.getStructDecoder([["lastRestartSlot", codecs.getU64Decoder()]]);
|
|
129
|
+
}
|
|
130
|
+
function getSysvarLastRestartSlotCodec() {
|
|
131
|
+
return codecs.combineCodec(getSysvarLastRestartSlotEncoder(), getSysvarLastRestartSlotDecoder());
|
|
132
|
+
}
|
|
133
|
+
async function fetchSysvarLastRestartSlot(rpc, config) {
|
|
134
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_LAST_RESTART_SLOT_ADDRESS, config);
|
|
135
|
+
accounts.assertAccountExists(account);
|
|
136
|
+
const decoded = accounts.decodeAccount(account, getSysvarLastRestartSlotDecoder());
|
|
137
|
+
return decoded.data;
|
|
138
|
+
}
|
|
139
|
+
function getSysvarRecentBlockhashesEncoder() {
|
|
140
|
+
return codecs.getArrayEncoder(
|
|
141
|
+
codecs.getStructEncoder([
|
|
142
|
+
["blockhash", rpcTypes.getBlockhashEncoder()],
|
|
143
|
+
["feeCalculator", codecs.getStructEncoder([["lamportsPerSignature", rpcTypes.getDefaultLamportsEncoder()]])]
|
|
144
|
+
])
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
function getSysvarRecentBlockhashesDecoder() {
|
|
148
|
+
return codecs.getArrayDecoder(
|
|
149
|
+
codecs.getStructDecoder([
|
|
150
|
+
["blockhash", rpcTypes.getBlockhashDecoder()],
|
|
151
|
+
["feeCalculator", codecs.getStructDecoder([["lamportsPerSignature", rpcTypes.getDefaultLamportsDecoder()]])]
|
|
152
|
+
])
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
function getSysvarRecentBlockhashesCodec() {
|
|
156
|
+
return codecs.combineCodec(getSysvarRecentBlockhashesEncoder(), getSysvarRecentBlockhashesDecoder());
|
|
157
|
+
}
|
|
158
|
+
async function fetchSysvarRecentBlockhashes(rpc, config) {
|
|
159
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_RECENT_BLOCKHASHES_ADDRESS, config);
|
|
160
|
+
accounts.assertAccountExists(account);
|
|
161
|
+
const decoded = accounts.decodeAccount(account, getSysvarRecentBlockhashesDecoder());
|
|
162
|
+
return decoded.data;
|
|
163
|
+
}
|
|
164
|
+
function getSysvarRentEncoder() {
|
|
165
|
+
return codecs.getStructEncoder([
|
|
166
|
+
["lamportsPerByteYear", rpcTypes.getDefaultLamportsEncoder()],
|
|
167
|
+
["exemptionThreshold", codecs.getF64Encoder()],
|
|
168
|
+
["burnPercent", codecs.getU8Encoder()]
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
function getSysvarRentDecoder() {
|
|
172
|
+
return codecs.getStructDecoder([
|
|
173
|
+
["lamportsPerByteYear", rpcTypes.getDefaultLamportsDecoder()],
|
|
174
|
+
["exemptionThreshold", codecs.getF64Decoder()],
|
|
175
|
+
["burnPercent", codecs.getU8Decoder()]
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
function getSysvarRentCodec() {
|
|
179
|
+
return codecs.combineCodec(getSysvarRentEncoder(), getSysvarRentDecoder());
|
|
180
|
+
}
|
|
181
|
+
async function fetchSysvarRent(rpc, config) {
|
|
182
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_RENT_ADDRESS, config);
|
|
183
|
+
accounts.assertAccountExists(account);
|
|
184
|
+
const decoded = accounts.decodeAccount(account, getSysvarRentDecoder());
|
|
185
|
+
return decoded.data;
|
|
186
|
+
}
|
|
187
|
+
function getSysvarSlotHashesEncoder() {
|
|
188
|
+
return codecs.getArrayEncoder(
|
|
189
|
+
codecs.getStructEncoder([
|
|
190
|
+
["slot", codecs.getU64Encoder()],
|
|
191
|
+
["hash", rpcTypes.getBlockhashEncoder()]
|
|
192
|
+
])
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
function getSysvarSlotHashesDecoder() {
|
|
196
|
+
return codecs.getArrayDecoder(
|
|
197
|
+
codecs.getStructDecoder([
|
|
198
|
+
["slot", codecs.getU64Decoder()],
|
|
199
|
+
["hash", rpcTypes.getBlockhashDecoder()]
|
|
200
|
+
])
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
function getSysvarSlotHashesCodec() {
|
|
204
|
+
return codecs.combineCodec(getSysvarSlotHashesEncoder(), getSysvarSlotHashesDecoder());
|
|
205
|
+
}
|
|
206
|
+
async function fetchSysvarSlotHashes(rpc, config) {
|
|
207
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_SLOT_HASHES_ADDRESS, config);
|
|
208
|
+
accounts.assertAccountExists(account);
|
|
209
|
+
const decoded = accounts.decodeAccount(account, getSysvarSlotHashesDecoder());
|
|
210
|
+
return decoded.data;
|
|
211
|
+
}
|
|
212
|
+
var BITVEC_DISCRIMINATOR = 1;
|
|
213
|
+
var BITVEC_NUM_BITS = 1024 * 1024;
|
|
214
|
+
var BITVEC_LENGTH = BITVEC_NUM_BITS / 64;
|
|
215
|
+
var SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE = 1 + // Discriminator
|
|
216
|
+
8 + // bitvector length (u64)
|
|
217
|
+
BITVEC_LENGTH * 8 + 8 + // Number of bits (u64)
|
|
218
|
+
8;
|
|
219
|
+
var memoizedU64Encoder;
|
|
220
|
+
var memoizedU64Decoder;
|
|
221
|
+
var memoizedU64ArrayEncoder;
|
|
222
|
+
var memoizedU64ArrayDecoder;
|
|
223
|
+
function getMemoizedU64Encoder() {
|
|
224
|
+
if (!memoizedU64Encoder) memoizedU64Encoder = codecs.getU64Encoder();
|
|
225
|
+
return memoizedU64Encoder;
|
|
226
|
+
}
|
|
227
|
+
function getMemoizedU64Decoder() {
|
|
228
|
+
if (!memoizedU64Decoder) memoizedU64Decoder = codecs.getU64Decoder();
|
|
229
|
+
return memoizedU64Decoder;
|
|
230
|
+
}
|
|
231
|
+
function getMemoizedU64ArrayEncoder() {
|
|
232
|
+
if (!memoizedU64ArrayEncoder) memoizedU64ArrayEncoder = codecs.getArrayCodec(codecs.getU64Codec(), { size: BITVEC_LENGTH });
|
|
233
|
+
return memoizedU64ArrayEncoder;
|
|
234
|
+
}
|
|
235
|
+
function getMemoizedU64ArrayDecoder() {
|
|
236
|
+
if (!memoizedU64ArrayDecoder) memoizedU64ArrayDecoder = codecs.getArrayCodec(codecs.getU64Codec(), { size: BITVEC_LENGTH });
|
|
237
|
+
return memoizedU64ArrayDecoder;
|
|
238
|
+
}
|
|
239
|
+
function getSysvarSlotHistoryEncoder() {
|
|
240
|
+
return codecs.createEncoder({
|
|
241
|
+
fixedSize: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE,
|
|
242
|
+
write: (value, bytes, offset) => {
|
|
243
|
+
bytes.set([BITVEC_DISCRIMINATOR], offset);
|
|
244
|
+
offset += 1;
|
|
245
|
+
getMemoizedU64Encoder().write(BigInt(BITVEC_LENGTH), bytes, offset);
|
|
246
|
+
offset += 8;
|
|
247
|
+
getMemoizedU64ArrayEncoder().write(value.bits, bytes, offset);
|
|
248
|
+
offset += BITVEC_LENGTH * 8;
|
|
249
|
+
getMemoizedU64Encoder().write(BigInt(BITVEC_NUM_BITS), bytes, offset);
|
|
250
|
+
offset += 8;
|
|
251
|
+
getMemoizedU64Encoder().write(value.nextSlot, bytes, offset);
|
|
252
|
+
offset += 8;
|
|
253
|
+
return offset;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function getSysvarSlotHistoryDecoder() {
|
|
258
|
+
return codecs.createDecoder({
|
|
259
|
+
fixedSize: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE,
|
|
260
|
+
read: (bytes, offset) => {
|
|
261
|
+
if (bytes.length != SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE) {
|
|
262
|
+
throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH, {
|
|
263
|
+
actual: bytes.length,
|
|
264
|
+
expected: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const discriminator = bytes[offset];
|
|
268
|
+
offset += 1;
|
|
269
|
+
if (discriminator !== BITVEC_DISCRIMINATOR) {
|
|
270
|
+
throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__ENUM_DISCRIMINATOR_OUT_OF_RANGE, {
|
|
271
|
+
actual: discriminator,
|
|
272
|
+
expected: BITVEC_DISCRIMINATOR
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
const bitVecLength = getMemoizedU64Decoder().read(bytes, offset)[0];
|
|
276
|
+
offset += 8;
|
|
277
|
+
if (bitVecLength !== BigInt(BITVEC_LENGTH)) {
|
|
278
|
+
throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS, {
|
|
279
|
+
actual: bitVecLength,
|
|
280
|
+
codecDescription: "SysvarSlotHistoryCodec",
|
|
281
|
+
expected: BITVEC_LENGTH
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
const bits = getMemoizedU64ArrayDecoder().read(bytes, offset)[0];
|
|
285
|
+
offset += BITVEC_LENGTH * 8;
|
|
286
|
+
const numBits = getMemoizedU64Decoder().read(bytes, offset)[0];
|
|
287
|
+
offset += 8;
|
|
288
|
+
if (numBits !== BigInt(BITVEC_NUM_BITS)) {
|
|
289
|
+
throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS, {
|
|
290
|
+
actual: numBits,
|
|
291
|
+
codecDescription: "SysvarSlotHistoryCodec",
|
|
292
|
+
expected: BITVEC_NUM_BITS
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
const nextSlot = getMemoizedU64Decoder().read(bytes, offset)[0];
|
|
296
|
+
offset += 8;
|
|
297
|
+
return [
|
|
298
|
+
{
|
|
299
|
+
bits,
|
|
300
|
+
nextSlot
|
|
301
|
+
},
|
|
302
|
+
offset
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function getSysvarSlotHistoryCodec() {
|
|
308
|
+
return codecs.combineCodec(getSysvarSlotHistoryEncoder(), getSysvarSlotHistoryDecoder());
|
|
309
|
+
}
|
|
310
|
+
async function fetchSysvarSlotHistory(rpc, config) {
|
|
311
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_SLOT_HISTORY_ADDRESS, config);
|
|
312
|
+
accounts.assertAccountExists(account);
|
|
313
|
+
const decoded = accounts.decodeAccount(account, getSysvarSlotHistoryDecoder());
|
|
314
|
+
return decoded.data;
|
|
315
|
+
}
|
|
316
|
+
function getSysvarStakeHistoryEncoder() {
|
|
317
|
+
return codecs.getArrayEncoder(
|
|
318
|
+
codecs.getStructEncoder([
|
|
319
|
+
["effective", rpcTypes.getDefaultLamportsEncoder()],
|
|
320
|
+
["activating", rpcTypes.getDefaultLamportsEncoder()],
|
|
321
|
+
["deactivating", rpcTypes.getDefaultLamportsEncoder()]
|
|
322
|
+
])
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
function getSysvarStakeHistoryDecoder() {
|
|
326
|
+
return codecs.getArrayDecoder(
|
|
327
|
+
codecs.getStructDecoder([
|
|
328
|
+
["effective", rpcTypes.getDefaultLamportsDecoder()],
|
|
329
|
+
["activating", rpcTypes.getDefaultLamportsDecoder()],
|
|
330
|
+
["deactivating", rpcTypes.getDefaultLamportsDecoder()]
|
|
331
|
+
])
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
function getSysvarStakeHistoryCodec() {
|
|
335
|
+
return codecs.combineCodec(getSysvarStakeHistoryEncoder(), getSysvarStakeHistoryDecoder());
|
|
336
|
+
}
|
|
337
|
+
async function fetchSysvarStakeHistory(rpc, config) {
|
|
338
|
+
const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_STAKE_HISTORY_ADDRESS, config);
|
|
339
|
+
accounts.assertAccountExists(account);
|
|
340
|
+
const decoded = accounts.decodeAccount(account, getSysvarStakeHistoryDecoder());
|
|
341
|
+
return decoded.data;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
exports.SYSVAR_CLOCK_ADDRESS = SYSVAR_CLOCK_ADDRESS;
|
|
345
|
+
exports.SYSVAR_EPOCH_REWARDS_ADDRESS = SYSVAR_EPOCH_REWARDS_ADDRESS;
|
|
346
|
+
exports.SYSVAR_EPOCH_SCHEDULE_ADDRESS = SYSVAR_EPOCH_SCHEDULE_ADDRESS;
|
|
347
|
+
exports.SYSVAR_FEES_ADDRESS = SYSVAR_FEES_ADDRESS;
|
|
348
|
+
exports.SYSVAR_INSTRUCTIONS_ADDRESS = SYSVAR_INSTRUCTIONS_ADDRESS;
|
|
349
|
+
exports.SYSVAR_LAST_RESTART_SLOT_ADDRESS = SYSVAR_LAST_RESTART_SLOT_ADDRESS;
|
|
350
|
+
exports.SYSVAR_RECENT_BLOCKHASHES_ADDRESS = SYSVAR_RECENT_BLOCKHASHES_ADDRESS;
|
|
351
|
+
exports.SYSVAR_RENT_ADDRESS = SYSVAR_RENT_ADDRESS;
|
|
352
|
+
exports.SYSVAR_SLOT_HASHES_ADDRESS = SYSVAR_SLOT_HASHES_ADDRESS;
|
|
353
|
+
exports.SYSVAR_SLOT_HISTORY_ADDRESS = SYSVAR_SLOT_HISTORY_ADDRESS;
|
|
354
|
+
exports.SYSVAR_STAKE_HISTORY_ADDRESS = SYSVAR_STAKE_HISTORY_ADDRESS;
|
|
355
|
+
exports.fetchEncodedSysvarAccount = fetchEncodedSysvarAccount;
|
|
356
|
+
exports.fetchJsonParsedSysvarAccount = fetchJsonParsedSysvarAccount;
|
|
357
|
+
exports.fetchSysvarClock = fetchSysvarClock;
|
|
358
|
+
exports.fetchSysvarEpochRewards = fetchSysvarEpochRewards;
|
|
359
|
+
exports.fetchSysvarEpochSchedule = fetchSysvarEpochSchedule;
|
|
360
|
+
exports.fetchSysvarFees = fetchSysvarFees;
|
|
361
|
+
exports.fetchSysvarLastRestartSlot = fetchSysvarLastRestartSlot;
|
|
362
|
+
exports.fetchSysvarRecentBlockhashes = fetchSysvarRecentBlockhashes;
|
|
363
|
+
exports.fetchSysvarRent = fetchSysvarRent;
|
|
364
|
+
exports.fetchSysvarSlotHashes = fetchSysvarSlotHashes;
|
|
365
|
+
exports.fetchSysvarSlotHistory = fetchSysvarSlotHistory;
|
|
366
|
+
exports.fetchSysvarStakeHistory = fetchSysvarStakeHistory;
|
|
367
|
+
exports.getSysvarClockCodec = getSysvarClockCodec;
|
|
368
|
+
exports.getSysvarClockDecoder = getSysvarClockDecoder;
|
|
369
|
+
exports.getSysvarClockEncoder = getSysvarClockEncoder;
|
|
370
|
+
exports.getSysvarEpochRewardsCodec = getSysvarEpochRewardsCodec;
|
|
371
|
+
exports.getSysvarEpochRewardsDecoder = getSysvarEpochRewardsDecoder;
|
|
372
|
+
exports.getSysvarEpochRewardsEncoder = getSysvarEpochRewardsEncoder;
|
|
373
|
+
exports.getSysvarEpochScheduleCodec = getSysvarEpochScheduleCodec;
|
|
374
|
+
exports.getSysvarEpochScheduleDecoder = getSysvarEpochScheduleDecoder;
|
|
375
|
+
exports.getSysvarEpochScheduleEncoder = getSysvarEpochScheduleEncoder;
|
|
376
|
+
exports.getSysvarFeesCodec = getSysvarFeesCodec;
|
|
377
|
+
exports.getSysvarFeesDecoder = getSysvarFeesDecoder;
|
|
378
|
+
exports.getSysvarFeesEncoder = getSysvarFeesEncoder;
|
|
379
|
+
exports.getSysvarLastRestartSlotCodec = getSysvarLastRestartSlotCodec;
|
|
380
|
+
exports.getSysvarLastRestartSlotDecoder = getSysvarLastRestartSlotDecoder;
|
|
381
|
+
exports.getSysvarLastRestartSlotEncoder = getSysvarLastRestartSlotEncoder;
|
|
382
|
+
exports.getSysvarRecentBlockhashesCodec = getSysvarRecentBlockhashesCodec;
|
|
383
|
+
exports.getSysvarRecentBlockhashesDecoder = getSysvarRecentBlockhashesDecoder;
|
|
384
|
+
exports.getSysvarRecentBlockhashesEncoder = getSysvarRecentBlockhashesEncoder;
|
|
385
|
+
exports.getSysvarRentCodec = getSysvarRentCodec;
|
|
386
|
+
exports.getSysvarRentDecoder = getSysvarRentDecoder;
|
|
387
|
+
exports.getSysvarRentEncoder = getSysvarRentEncoder;
|
|
388
|
+
exports.getSysvarSlotHashesCodec = getSysvarSlotHashesCodec;
|
|
389
|
+
exports.getSysvarSlotHashesDecoder = getSysvarSlotHashesDecoder;
|
|
390
|
+
exports.getSysvarSlotHashesEncoder = getSysvarSlotHashesEncoder;
|
|
391
|
+
exports.getSysvarSlotHistoryCodec = getSysvarSlotHistoryCodec;
|
|
392
|
+
exports.getSysvarSlotHistoryDecoder = getSysvarSlotHistoryDecoder;
|
|
393
|
+
exports.getSysvarSlotHistoryEncoder = getSysvarSlotHistoryEncoder;
|
|
394
|
+
exports.getSysvarStakeHistoryCodec = getSysvarStakeHistoryCodec;
|
|
395
|
+
exports.getSysvarStakeHistoryDecoder = getSysvarStakeHistoryDecoder;
|
|
396
|
+
exports.getSysvarStakeHistoryEncoder = getSysvarStakeHistoryEncoder;
|
|
397
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
398
|
+
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sysvar.ts","../src/clock.ts","../src/epoch-rewards.ts","../src/epoch-schedule.ts","../src/fees.ts","../src/last-restart-slot.ts","../src/recent-blockhashes.ts","../src/rent.ts","../src/slot-hashes.ts","../src/slot-history.ts","../src/stake-history.ts"],"names":["fetchEncodedAccount","fetchJsonParsedAccount","getStructEncoder","getU64Encoder","getI64Encoder","getStructDecoder","getU64Decoder","getI64Decoder","combineCodec","assertAccountExists","decodeAccount","getBooleanEncoder","getBooleanDecoder","getDefaultLamportsEncoder","getDefaultLamportsDecoder","getArrayEncoder","getBlockhashEncoder","getArrayDecoder","getBlockhashDecoder","getF64Encoder","getU8Encoder","getF64Decoder","getU8Decoder","getArrayCodec","getU64Codec","createEncoder","createDecoder","SolanaError","SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH","SOLANA_ERROR__CODECS__ENUM_DISCRIMINATOR_OUT_OF_RANGE","SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS"],"mappings":";;;;;;;;AAYO,IAAM,oBACT,GAAA,8CAAA;AACG,IAAM,4BACT,GAAA,8CAAA;AACG,IAAM,6BACT,GAAA,8CAAA;AACG,IAAM,mBACT,GAAA,8CAAA;AACG,IAAM,2BACT,GAAA,8CAAA;AACG,IAAM,gCACT,GAAA,8CAAA;AACG,IAAM,iCACT,GAAA,8CAAA;AACG,IAAM,mBACT,GAAA,8CAAA;AACG,IAAM,0BACT,GAAA,8CAAA;AACG,IAAM,2BACT,GAAA,8CAAA;AACG,IAAM,4BACT,GAAA,8CAAA;AAqBJ,eAAsB,yBAAA,CAClB,GACA,EAAA,OAAA,EACA,MACsC,EAAA;AACtC,EAAA,OAAO,MAAMA,4BAAA,CAA8B,GAAK,EAAA,OAAA,EAAS,MAAM,CAAA,CAAA;AACnE,CAAA;AAQA,eAAsB,4BAAA,CAClB,GACA,EAAA,OAAA,EACA,MACwF,EAAA;AACxF,EAAA,OAAO,MAAMC,+BAAA,CAA0D,GAAK,EAAA,OAAA,EAAS,MAAM,CAAA,CAAA;AAC/F,CAAA;;;ACxCO,SAAS,qBAAwE,GAAA;AACpF,EAAA,OAAOC,uBAAiB,CAAA;AAAA,IACpB,CAAC,MAAQ,EAAAC,oBAAA,EAAe,CAAA;AAAA,IACxB,CAAC,qBAAuB,EAAAC,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OA,eAAsB,uBAAA,CAClB,KACA,MAC2B,EAAA;AAC3B,EAAA,MAAM,OAAU,GAAA,MAAM,yBAA0B,CAAA,GAAA,EAAK,8BAA8B,MAAM,CAAA,CAAA;AACzF,EAAAC,6BAAoB,OAAO,CAAA,CAAA;AAC3B,EAAA,MAAM,OAAUC,GAAAA,sBAAAA,CAAc,OAAS,EAAA,4BAAA,EAA8B,CAAA,CAAA;AACrE,EAAA,OAAO,OAAQ,CAAA,IAAA,CAAA;AACnB","file":"index.browser.cjs","sourcesContent":["import {\n type FetchAccountConfig,\n fetchEncodedAccount,\n fetchJsonParsedAccount,\n type MaybeAccount,\n type MaybeEncodedAccount,\n} from '@solana/accounts';\nimport type { Address } from '@solana/addresses';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { JsonParsedSysvarAccount } from '@solana/rpc-parsed-types';\nimport type { Rpc } from '@solana/rpc-spec';\n\nexport const SYSVAR_CLOCK_ADDRESS =\n 'SysvarC1ock11111111111111111111111111111111' as Address<'SysvarC1ock11111111111111111111111111111111'>;\nexport const SYSVAR_EPOCH_REWARDS_ADDRESS =\n 'SysvarEpochRewards1111111111111111111111111' as Address<'SysvarEpochRewards1111111111111111111111111'>;\nexport const SYSVAR_EPOCH_SCHEDULE_ADDRESS =\n 'SysvarEpochSchedu1e111111111111111111111111' as Address<'SysvarEpochSchedu1e111111111111111111111111'>;\nexport const SYSVAR_FEES_ADDRESS =\n 'SysvarFees111111111111111111111111111111111' as Address<'SysvarFees111111111111111111111111111111111'>;\nexport const SYSVAR_INSTRUCTIONS_ADDRESS =\n 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>;\nexport const SYSVAR_LAST_RESTART_SLOT_ADDRESS =\n 'SysvarLastRestartS1ot1111111111111111111111' as Address<'SysvarLastRestartS1ot1111111111111111111111'>;\nexport const SYSVAR_RECENT_BLOCKHASHES_ADDRESS =\n 'SysvarRecentB1ockHashes11111111111111111111' as Address<'SysvarRecentB1ockHashes11111111111111111111'>;\nexport const SYSVAR_RENT_ADDRESS =\n 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>;\nexport const SYSVAR_SLOT_HASHES_ADDRESS =\n 'SysvarS1otHashes111111111111111111111111111' as Address<'SysvarS1otHashes111111111111111111111111111'>;\nexport const SYSVAR_SLOT_HISTORY_ADDRESS =\n 'SysvarS1otHistory11111111111111111111111111' as Address<'SysvarS1otHistory11111111111111111111111111'>;\nexport const SYSVAR_STAKE_HISTORY_ADDRESS =\n 'SysvarStakeHistory1111111111111111111111111' as Address<'SysvarStakeHistory1111111111111111111111111'>;\n\ntype SysvarAddress =\n | typeof SYSVAR_CLOCK_ADDRESS\n | typeof SYSVAR_EPOCH_REWARDS_ADDRESS\n | typeof SYSVAR_EPOCH_SCHEDULE_ADDRESS\n | typeof SYSVAR_FEES_ADDRESS\n | typeof SYSVAR_INSTRUCTIONS_ADDRESS\n | typeof SYSVAR_LAST_RESTART_SLOT_ADDRESS\n | typeof SYSVAR_RECENT_BLOCKHASHES_ADDRESS\n | typeof SYSVAR_RENT_ADDRESS\n | typeof SYSVAR_SLOT_HASHES_ADDRESS\n | typeof SYSVAR_SLOT_HISTORY_ADDRESS\n | typeof SYSVAR_STAKE_HISTORY_ADDRESS;\n\n/**\n * Fetch an encoded sysvar account.\n *\n * Sysvars are special accounts that contain dynamically-updated data about the\n * network cluster, the blockchain history, and the executing transaction.\n */\nexport async function fetchEncodedSysvarAccount<TAddress extends SysvarAddress>(\n rpc: Rpc<GetAccountInfoApi>,\n address: TAddress,\n config?: FetchAccountConfig,\n): Promise<MaybeEncodedAccount<TAddress>> {\n return await fetchEncodedAccount<TAddress>(rpc, address, config);\n}\n\n/**\n * Fetch a JSON-parsed sysvar account.\n *\n * Sysvars are special accounts that contain dynamically-updated data about the\n * network cluster, the blockchain history, and the executing transaction.\n */\nexport async function fetchJsonParsedSysvarAccount<TAddress extends SysvarAddress>(\n rpc: Rpc<GetAccountInfoApi>,\n address: TAddress,\n config?: FetchAccountConfig,\n): Promise<MaybeAccount<JsonParsedSysvarAccount, TAddress> | MaybeEncodedAccount<TAddress>> {\n return await fetchJsonParsedAccount<JsonParsedSysvarAccount, TAddress>(rpc, address, config);\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n type FixedSizeCodec,\n type FixedSizeDecoder,\n type FixedSizeEncoder,\n getI64Decoder,\n getI64Encoder,\n getStructDecoder,\n getStructEncoder,\n getU64Decoder,\n getU64Encoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport type { Epoch, Slot, UnixTimestampUnsafeBeyond2Pow53Minus1 } from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_CLOCK_ADDRESS } from './sysvar';\n\ntype SysvarClockSize = 40;\n\n/**\n * The `Clock` sysvar.\n *\n * Information about the network’s clock, ticks, slots, etc.\n */\nexport type SysvarClock = Readonly<{\n epoch: Epoch;\n epochStartTimestamp: UnixTimestampUnsafeBeyond2Pow53Minus1;\n leaderScheduleEpoch: Epoch;\n slot: Slot;\n unixTimestamp: UnixTimestampUnsafeBeyond2Pow53Minus1;\n}>;\n\nexport function getSysvarClockEncoder(): FixedSizeEncoder<SysvarClock, SysvarClockSize> {\n return getStructEncoder([\n ['slot', getU64Encoder()],\n ['epochStartTimestamp', getI64Encoder()],\n ['epoch', getU64Encoder()],\n ['leaderScheduleEpoch', getU64Encoder()],\n ['unixTimestamp', getI64Encoder()],\n ]) as FixedSizeEncoder<SysvarClock, SysvarClockSize>;\n}\n\nexport function getSysvarClockDecoder(): FixedSizeDecoder<SysvarClock, SysvarClockSize> {\n return getStructDecoder([\n ['slot', getU64Decoder()],\n ['epochStartTimestamp', getI64Decoder()],\n ['epoch', getU64Decoder()],\n ['leaderScheduleEpoch', getU64Decoder()],\n ['unixTimestamp', getI64Decoder()],\n ]) as FixedSizeDecoder<SysvarClock, SysvarClockSize>;\n}\n\nexport function getSysvarClockCodec(): FixedSizeCodec<SysvarClock, SysvarClock, SysvarClockSize> {\n return combineCodec(getSysvarClockEncoder(), getSysvarClockDecoder());\n}\n\n/**\n * Fetch the `Clock` sysvar.\n *\n * Information about the network’s clock, ticks, slots, etc.\n */\nexport async function fetchSysvarClock(rpc: Rpc<GetAccountInfoApi>, config?: FetchAccountConfig): Promise<SysvarClock> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarClockDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n type FixedSizeCodec,\n type FixedSizeDecoder,\n type FixedSizeEncoder,\n getStructDecoder,\n getStructEncoder,\n getU64Decoder,\n getU64Encoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_EPOCH_REWARDS_ADDRESS } from './sysvar';\n\ntype SysvarEpochRewardsSize = 24;\n\n/**\n * The `EpochRewards` sysvar.\n *\n * Tracks the progress of epoch rewards distribution. It includes:\n * - Total rewards for the current epoch, in lamports.\n * - Rewards for the current epoch distributed so far, in lamports.\n * - Distribution completed block height, i.e. distribution of all staking rewards for the current\n * epoch will be completed at this block height.\n *\n * Note that `EpochRewards` only lasts for a handful of blocks at the start of\n * an epoch. When all rewards have been distributed, the sysvar is deleted.\n * See https://github.com/solana-labs/solana/blob/e0203f22dc83cb792fa97f91dbe6e924cbd08af1/docs/src/runtime/sysvars.md?plain=1#L155-L168\n */\nexport type SysvarEpochRewards = Readonly<{\n distributedRewards: bigint;\n distributionCompleteBlockHeight: bigint;\n totalRewards: bigint;\n}>;\n\nexport function getSysvarEpochRewardsEncoder(): FixedSizeEncoder<SysvarEpochRewards, SysvarEpochRewardsSize> {\n return getStructEncoder([\n ['distributionCompleteBlockHeight', getU64Encoder()],\n ['distributedRewards', getU64Encoder()],\n ['totalRewards', getU64Encoder()],\n ]) as FixedSizeEncoder<SysvarEpochRewards, SysvarEpochRewardsSize>;\n}\n\nexport function getSysvarEpochRewardsDecoder(): FixedSizeDecoder<SysvarEpochRewards, SysvarEpochRewardsSize> {\n return getStructDecoder([\n ['distributionCompleteBlockHeight', getU64Decoder()],\n ['distributedRewards', getU64Decoder()],\n ['totalRewards', getU64Decoder()],\n ]) as FixedSizeDecoder<SysvarEpochRewards, SysvarEpochRewardsSize>;\n}\n\nexport function getSysvarEpochRewardsCodec(): FixedSizeCodec<\n SysvarEpochRewards,\n SysvarEpochRewards,\n SysvarEpochRewardsSize\n> {\n return combineCodec(getSysvarEpochRewardsEncoder(), getSysvarEpochRewardsDecoder());\n}\n\n/**\n * Fetch the `EpochRewards` sysvar.\n *\n * Tracks the progress of epoch rewards distribution. It includes:\n * - Total rewards for the current epoch, in lamports.\n * - Rewards for the current epoch distributed so far, in lamports.\n * - Distribution completed block height, i.e. distribution of all staking rewards for the current\n * epoch will be completed at this block height.\n *\n * Note that `EpochRewards` only lasts for a handful of blocks at the start of\n * an epoch. When all rewards have been distributed, the sysvar is deleted.\n * See https://github.com/solana-labs/solana/blob/e0203f22dc83cb792fa97f91dbe6e924cbd08af1/docs/src/runtime/sysvars.md?plain=1#L155-L168\n */\nexport async function fetchSysvarEpochRewards(\n rpc: Rpc<GetAccountInfoApi>,\n config?: FetchAccountConfig,\n): Promise<SysvarEpochRewards> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_EPOCH_REWARDS_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarEpochRewardsDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n type FixedSizeCodec,\n type FixedSizeDecoder,\n type FixedSizeEncoder,\n getBooleanDecoder,\n getBooleanEncoder,\n getStructDecoder,\n getStructEncoder,\n getU64Decoder,\n getU64Encoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport type { Epoch, Slot } from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_EPOCH_SCHEDULE_ADDRESS } from './sysvar';\n\ntype SysvarEpochScheduleSize = 33;\n\n/**\n * The `EpochSchedule` sysvar.\n *\n * Information about epoch duration.\n */\nexport type SysvarEpochSchedule = Readonly<{\n firstNormalEpoch: Epoch;\n firstNormalSlot: Slot;\n leaderScheduleSlotOffset: bigint;\n slotsPerEpoch: bigint;\n warmup: boolean;\n}>;\n\nexport function getSysvarEpochScheduleEncoder(): FixedSizeEncoder<SysvarEpochSchedule, SysvarEpochScheduleSize> {\n return getStructEncoder([\n ['slotsPerEpoch', getU64Encoder()],\n ['leaderScheduleSlotOffset', getU64Encoder()],\n ['warmup', getBooleanEncoder()],\n ['firstNormalEpoch', getU64Encoder()],\n ['firstNormalSlot', getU64Encoder()],\n ]) as FixedSizeEncoder<SysvarEpochSchedule, SysvarEpochScheduleSize>;\n}\n\nexport function getSysvarEpochScheduleDecoder(): FixedSizeDecoder<SysvarEpochSchedule, SysvarEpochScheduleSize> {\n return getStructDecoder([\n ['slotsPerEpoch', getU64Decoder()],\n ['leaderScheduleSlotOffset', getU64Decoder()],\n ['warmup', getBooleanDecoder()],\n ['firstNormalEpoch', getU64Decoder()],\n ['firstNormalSlot', getU64Decoder()],\n ]) as FixedSizeDecoder<SysvarEpochSchedule, SysvarEpochScheduleSize>;\n}\n\nexport function getSysvarEpochScheduleCodec(): FixedSizeCodec<\n SysvarEpochSchedule,\n SysvarEpochSchedule,\n SysvarEpochScheduleSize\n> {\n return combineCodec(getSysvarEpochScheduleEncoder(), getSysvarEpochScheduleDecoder());\n}\n\n/**\n * Fetch the `EpochSchedule` sysvar.\n *\n * Information about epoch duration.\n */\nexport async function fetchSysvarEpochSchedule(\n rpc: Rpc<GetAccountInfoApi>,\n config?: FetchAccountConfig,\n): Promise<SysvarEpochSchedule> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_EPOCH_SCHEDULE_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarEpochScheduleDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n type FixedSizeCodec,\n type FixedSizeDecoder,\n type FixedSizeEncoder,\n getStructDecoder,\n getStructEncoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport {\n getDefaultLamportsDecoder,\n getDefaultLamportsEncoder,\n LamportsUnsafeBeyond2Pow53Minus1,\n} from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_FEES_ADDRESS } from './sysvar';\n\ntype FeeCalculator = Readonly<{\n lamportsPerSignature: LamportsUnsafeBeyond2Pow53Minus1;\n}>;\n\ntype SysvarFeesSize = 8;\n\n/**\n * The `Fees` sysvar.\n *\n * Current cluster fees.\n */\nexport type SysvarFees = Readonly<{\n feeCalculator: FeeCalculator;\n}>;\n\nexport function getSysvarFeesEncoder(): FixedSizeEncoder<SysvarFees, SysvarFeesSize> {\n return getStructEncoder([\n ['feeCalculator', getStructEncoder([['lamportsPerSignature', getDefaultLamportsEncoder()]])],\n ]) as FixedSizeEncoder<SysvarFees, SysvarFeesSize>;\n}\n\nexport function getSysvarFeesDecoder(): FixedSizeDecoder<SysvarFees, SysvarFeesSize> {\n return getStructDecoder([\n ['feeCalculator', getStructDecoder([['lamportsPerSignature', getDefaultLamportsDecoder()]])],\n ]) as FixedSizeDecoder<SysvarFees, SysvarFeesSize>;\n}\n\nexport function getSysvarFeesCodec(): FixedSizeCodec<SysvarFees, SysvarFees, SysvarFeesSize> {\n return combineCodec(getSysvarFeesEncoder(), getSysvarFeesDecoder());\n}\n\n/**\n * Fetch the `Fees` sysvar.\n *\n * Current cluster fees.\n */\nexport async function fetchSysvarFees(rpc: Rpc<GetAccountInfoApi>, config?: FetchAccountConfig): Promise<SysvarFees> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_FEES_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarFeesDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n type FixedSizeCodec,\n type FixedSizeDecoder,\n type FixedSizeEncoder,\n getStructDecoder,\n getStructEncoder,\n getU64Decoder,\n getU64Encoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport type { Slot } from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_LAST_RESTART_SLOT_ADDRESS } from './sysvar';\n\ntype SysvarLastRestartSlotSize = 8;\n\n/**\n * The `LastRestartSlot` sysvar.\n *\n * Information about the last restart slot (hard fork).\n *\n * The `LastRestartSlot` sysvar provides access to the last restart slot kept in the\n * bank fork for the slot on the fork that executes the current transaction.\n * In case there was no fork it returns `0`.\n */\nexport type SysvarLastRestartSlot = Readonly<{\n lastRestartSlot: Slot;\n}>;\n\nexport function getSysvarLastRestartSlotEncoder(): FixedSizeEncoder<SysvarLastRestartSlot, SysvarLastRestartSlotSize> {\n return getStructEncoder([['lastRestartSlot', getU64Encoder()]]) as FixedSizeEncoder<\n SysvarLastRestartSlot,\n SysvarLastRestartSlotSize\n >;\n}\n\nexport function getSysvarLastRestartSlotDecoder(): FixedSizeDecoder<SysvarLastRestartSlot, SysvarLastRestartSlotSize> {\n return getStructDecoder([['lastRestartSlot', getU64Decoder()]]) as FixedSizeDecoder<\n SysvarLastRestartSlot,\n SysvarLastRestartSlotSize\n >;\n}\n\nexport function getSysvarLastRestartSlotCodec(): FixedSizeCodec<\n SysvarLastRestartSlot,\n SysvarLastRestartSlot,\n SysvarLastRestartSlotSize\n> {\n return combineCodec(getSysvarLastRestartSlotEncoder(), getSysvarLastRestartSlotDecoder());\n}\n\n/**\n * Fetch the `LastRestartSlot` sysvar.\n *\n * Information about the last restart slot (hard fork).\n *\n * The `LastRestartSlot` sysvar provides access to the last restart slot kept in the\n * bank fork for the slot on the fork that executes the current transaction.\n * In case there was no fork it returns `0`.\n */\nexport async function fetchSysvarLastRestartSlot(\n rpc: Rpc<GetAccountInfoApi>,\n config?: FetchAccountConfig,\n): Promise<SysvarLastRestartSlot> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_LAST_RESTART_SLOT_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarLastRestartSlotDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n getArrayDecoder,\n getArrayEncoder,\n getStructDecoder,\n getStructEncoder,\n type VariableSizeCodec,\n type VariableSizeDecoder,\n type VariableSizeEncoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport {\n type Blockhash,\n getBlockhashDecoder,\n getBlockhashEncoder,\n getDefaultLamportsDecoder,\n getDefaultLamportsEncoder,\n type LamportsUnsafeBeyond2Pow53Minus1,\n} from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_RECENT_BLOCKHASHES_ADDRESS } from './sysvar';\n\ntype FeeCalculator = Readonly<{\n lamportsPerSignature: LamportsUnsafeBeyond2Pow53Minus1;\n}>;\ntype Entry = Readonly<{\n blockhash: Blockhash;\n feeCalculator: FeeCalculator;\n}>;\n\n/**\n * The `RecentBlockhashes` sysvar.\n *\n * Information about recent blocks and their fee calculators.\n */\nexport type SysvarRecentBlockhashes = Entry[];\n\nexport function getSysvarRecentBlockhashesEncoder(): VariableSizeEncoder<SysvarRecentBlockhashes> {\n return getArrayEncoder(\n getStructEncoder([\n ['blockhash', getBlockhashEncoder()],\n ['feeCalculator', getStructEncoder([['lamportsPerSignature', getDefaultLamportsEncoder()]])],\n ]),\n );\n}\n\nexport function getSysvarRecentBlockhashesDecoder(): VariableSizeDecoder<SysvarRecentBlockhashes> {\n return getArrayDecoder(\n getStructDecoder([\n ['blockhash', getBlockhashDecoder()],\n ['feeCalculator', getStructDecoder([['lamportsPerSignature', getDefaultLamportsDecoder()]])],\n ]),\n );\n}\n\nexport function getSysvarRecentBlockhashesCodec(): VariableSizeCodec<SysvarRecentBlockhashes> {\n return combineCodec(getSysvarRecentBlockhashesEncoder(), getSysvarRecentBlockhashesDecoder());\n}\n\n/**\n * Fetch the `RecentBlockhashes` sysvar.\n *\n * Information about recent blocks and their fee calculators.\n */\nexport async function fetchSysvarRecentBlockhashes(\n rpc: Rpc<GetAccountInfoApi>,\n config?: FetchAccountConfig,\n): Promise<SysvarRecentBlockhashes> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_RECENT_BLOCKHASHES_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarRecentBlockhashesDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n type FixedSizeCodec,\n type FixedSizeDecoder,\n type FixedSizeEncoder,\n getF64Decoder,\n getF64Encoder,\n getStructDecoder,\n getStructEncoder,\n getU8Decoder,\n getU8Encoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport {\n getDefaultLamportsDecoder,\n getDefaultLamportsEncoder,\n type LamportsUnsafeBeyond2Pow53Minus1,\n} from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_RENT_ADDRESS } from './sysvar';\n\ntype SysvarRentSize = 17;\n\n/**\n * The `Rent` sysvar.\n *\n * Configuration for network rent.\n */\nexport type SysvarRent = Readonly<{\n burnPercent: number;\n exemptionThreshold: number;\n lamportsPerByteYear: LamportsUnsafeBeyond2Pow53Minus1;\n}>;\n\nexport function getSysvarRentEncoder(): FixedSizeEncoder<SysvarRent, SysvarRentSize> {\n return getStructEncoder([\n ['lamportsPerByteYear', getDefaultLamportsEncoder()],\n ['exemptionThreshold', getF64Encoder()],\n ['burnPercent', getU8Encoder()],\n ]) as FixedSizeEncoder<SysvarRent, SysvarRentSize>;\n}\n\nexport function getSysvarRentDecoder(): FixedSizeDecoder<SysvarRent, SysvarRentSize> {\n return getStructDecoder([\n ['lamportsPerByteYear', getDefaultLamportsDecoder()],\n ['exemptionThreshold', getF64Decoder()],\n ['burnPercent', getU8Decoder()],\n ]) as FixedSizeDecoder<SysvarRent, SysvarRentSize>;\n}\n\nexport function getSysvarRentCodec(): FixedSizeCodec<SysvarRent, SysvarRent, SysvarRentSize> {\n return combineCodec(getSysvarRentEncoder(), getSysvarRentDecoder());\n}\n\n/**\n * Fetch the `Rent` sysvar.\n *\n * Configuration for network rent.\n */\nexport async function fetchSysvarRent(rpc: Rpc<GetAccountInfoApi>, config?: FetchAccountConfig): Promise<SysvarRent> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_RENT_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarRentDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n getArrayDecoder,\n getArrayEncoder,\n getStructDecoder,\n getStructEncoder,\n getU64Decoder,\n getU64Encoder,\n type VariableSizeCodec,\n type VariableSizeDecoder,\n type VariableSizeEncoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport { type Blockhash, getBlockhashDecoder, getBlockhashEncoder, type Slot } from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_SLOT_HASHES_ADDRESS } from './sysvar';\n\ntype Entry = Readonly<{\n hash: Blockhash;\n slot: Slot;\n}>;\n\n/**\n * The `SlotHashes` sysvar.\n *\n * The most recent hashes of a slot's parent banks.\n */\nexport type SysvarSlotHashes = Entry[];\n\nexport function getSysvarSlotHashesEncoder(): VariableSizeEncoder<SysvarSlotHashes> {\n return getArrayEncoder(\n getStructEncoder([\n ['slot', getU64Encoder()],\n ['hash', getBlockhashEncoder()],\n ]),\n );\n}\n\nexport function getSysvarSlotHashesDecoder(): VariableSizeDecoder<SysvarSlotHashes> {\n return getArrayDecoder(\n getStructDecoder([\n ['slot', getU64Decoder()],\n ['hash', getBlockhashDecoder()],\n ]),\n );\n}\n\nexport function getSysvarSlotHashesCodec(): VariableSizeCodec<SysvarSlotHashes> {\n return combineCodec(getSysvarSlotHashesEncoder(), getSysvarSlotHashesDecoder());\n}\n\n/**\n * Fetch the `SlotHashes` sysvar.\n *\n * The most recent hashes of a slot's parent banks.\n */\nexport async function fetchSysvarSlotHashes(\n rpc: Rpc<GetAccountInfoApi>,\n config?: FetchAccountConfig,\n): Promise<SysvarSlotHashes> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_SLOT_HASHES_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarSlotHashesDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n createDecoder,\n createEncoder,\n type FixedSizeCodec,\n type FixedSizeDecoder,\n type FixedSizeEncoder,\n getArrayCodec,\n getU64Codec,\n getU64Decoder,\n getU64Encoder,\n ReadonlyUint8Array,\n} from '@solana/codecs';\nimport {\n SOLANA_ERROR__CODECS__ENUM_DISCRIMINATOR_OUT_OF_RANGE,\n SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH,\n SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS,\n SolanaError,\n} from '@solana/errors';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport type { Slot } from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_SLOT_HISTORY_ADDRESS } from './sysvar';\n\nconst BITVEC_DISCRIMINATOR = 1;\n// Max number of bits in the bitvector.\n// The Solana SDK defines a constant `MAX_ENTRIES` representing the maximum\n// number of bits that can be represented by the bitvector in the `SlotHistory`\n// sysvar. This value is 1024 * 1024 = 1_048_576.\n// See https://github.com/solana-labs/solana/blob/e0203f22dc83cb792fa97f91dbe6e924cbd08af1/sdk/program/src/slot_history.rs#L43\nconst BITVEC_NUM_BITS = 1024 * 1024;\n// The length of the bitvector in blocks.\n// At 64 bits per block, this is 1024 * 1024 / 64 = 16_384.\nconst BITVEC_LENGTH = BITVEC_NUM_BITS / 64;\n\nconst SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE =\n 1 + // Discriminator\n 8 + // bitvector length (u64)\n BITVEC_LENGTH * 8 +\n 8 + // Number of bits (u64)\n 8; // Next slot (u64)\n\nlet memoizedU64Encoder: FixedSizeEncoder<bigint, 8> | undefined;\nlet memoizedU64Decoder: FixedSizeDecoder<bigint, 8> | undefined;\nlet memoizedU64ArrayEncoder: FixedSizeEncoder<bigint[]> | undefined;\nlet memoizedU64ArrayDecoder: FixedSizeDecoder<bigint[]> | undefined;\n\nfunction getMemoizedU64Encoder(): FixedSizeEncoder<bigint, 8> {\n if (!memoizedU64Encoder) memoizedU64Encoder = getU64Encoder();\n return memoizedU64Encoder;\n}\nfunction getMemoizedU64Decoder(): FixedSizeDecoder<bigint, 8> {\n if (!memoizedU64Decoder) memoizedU64Decoder = getU64Decoder();\n return memoizedU64Decoder;\n}\nfunction getMemoizedU64ArrayEncoder(): FixedSizeEncoder<bigint[], typeof BITVEC_LENGTH> {\n if (!memoizedU64ArrayEncoder) memoizedU64ArrayEncoder = getArrayCodec(getU64Codec(), { size: BITVEC_LENGTH });\n return memoizedU64ArrayEncoder;\n}\nfunction getMemoizedU64ArrayDecoder(): FixedSizeDecoder<bigint[], typeof BITVEC_LENGTH> {\n if (!memoizedU64ArrayDecoder) memoizedU64ArrayDecoder = getArrayCodec(getU64Codec(), { size: BITVEC_LENGTH });\n return memoizedU64ArrayDecoder;\n}\n\ntype SysvarSlotHistorySize = typeof SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE;\n\n/**\n * The `SlotHistory` sysvar.\n *\n * A bitvector of slots present over the last epoch.\n */\nexport type SysvarSlotHistory = {\n bits: bigint[];\n nextSlot: Slot;\n};\n\nexport function getSysvarSlotHistoryEncoder(): FixedSizeEncoder<SysvarSlotHistory, SysvarSlotHistorySize> {\n return createEncoder({\n fixedSize: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE,\n write: (value: SysvarSlotHistory, bytes, offset) => {\n // First byte is the bitvector discriminator.\n bytes.set([BITVEC_DISCRIMINATOR], offset);\n offset += 1;\n // Next 8 bytes are the bitvector length.\n getMemoizedU64Encoder().write(BigInt(BITVEC_LENGTH), bytes, offset);\n offset += 8;\n // Next `BITVEC_LENGTH` bytes are the bitvector.\n // Any missing bits are assumed to be 0.\n getMemoizedU64ArrayEncoder().write(value.bits, bytes, offset);\n offset += BITVEC_LENGTH * 8;\n // Next 8 bytes are the number of bits.\n getMemoizedU64Encoder().write(BigInt(BITVEC_NUM_BITS), bytes, offset);\n offset += 8;\n // Next 8 bytes are the next slot.\n getMemoizedU64Encoder().write(value.nextSlot, bytes, offset);\n offset += 8;\n return offset;\n },\n });\n}\n\nexport function getSysvarSlotHistoryDecoder(): FixedSizeDecoder<SysvarSlotHistory, SysvarSlotHistorySize> {\n return createDecoder({\n fixedSize: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE,\n read: (bytes: ReadonlyUint8Array | Uint8Array, offset) => {\n // Byte length should be exact.\n if (bytes.length != SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH, {\n actual: bytes.length,\n expected: SLOT_HISTORY_ACCOUNT_DATA_STATIC_SIZE,\n });\n }\n // First byte is the bitvector discriminator.\n const discriminator = bytes[offset];\n offset += 1;\n if (discriminator !== BITVEC_DISCRIMINATOR) {\n throw new SolanaError(SOLANA_ERROR__CODECS__ENUM_DISCRIMINATOR_OUT_OF_RANGE, {\n actual: discriminator,\n expected: BITVEC_DISCRIMINATOR,\n });\n }\n // Next 8 bytes are the bitvector length.\n const bitVecLength = getMemoizedU64Decoder().read(bytes, offset)[0];\n offset += 8;\n if (bitVecLength !== BigInt(BITVEC_LENGTH)) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS, {\n actual: bitVecLength,\n codecDescription: 'SysvarSlotHistoryCodec',\n expected: BITVEC_LENGTH,\n });\n }\n // Next `BITVEC_LENGTH` bytes are the bitvector.\n const bits = getMemoizedU64ArrayDecoder().read(bytes, offset)[0];\n offset += BITVEC_LENGTH * 8;\n // Next 8 bytes are the number of bits.\n const numBits = getMemoizedU64Decoder().read(bytes, offset)[0];\n offset += 8;\n if (numBits !== BigInt(BITVEC_NUM_BITS)) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_NUMBER_OF_ITEMS, {\n actual: numBits,\n codecDescription: 'SysvarSlotHistoryCodec',\n expected: BITVEC_NUM_BITS,\n });\n }\n // Next 8 bytes are the next slot.\n const nextSlot = getMemoizedU64Decoder().read(bytes, offset)[0];\n offset += 8;\n return [\n {\n bits,\n nextSlot,\n },\n offset,\n ];\n },\n });\n}\n\nexport function getSysvarSlotHistoryCodec(): FixedSizeCodec<\n SysvarSlotHistory,\n SysvarSlotHistory,\n SysvarSlotHistorySize\n> {\n return combineCodec(getSysvarSlotHistoryEncoder(), getSysvarSlotHistoryDecoder());\n}\n\n/**\n * Fetch the `SlotHistory` sysvar.\n *\n * A bitvector of slots present over the last epoch.\n */\nexport async function fetchSysvarSlotHistory(\n rpc: Rpc<GetAccountInfoApi>,\n config?: FetchAccountConfig,\n): Promise<SysvarSlotHistory> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_SLOT_HISTORY_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarSlotHistoryDecoder());\n return decoded.data;\n}\n","import { assertAccountExists, decodeAccount, type FetchAccountConfig } from '@solana/accounts';\nimport {\n combineCodec,\n getArrayDecoder,\n getArrayEncoder,\n getStructDecoder,\n getStructEncoder,\n type VariableSizeCodec,\n type VariableSizeDecoder,\n type VariableSizeEncoder,\n} from '@solana/codecs';\nimport type { GetAccountInfoApi } from '@solana/rpc-api';\nimport type { Rpc } from '@solana/rpc-spec';\nimport {\n getDefaultLamportsDecoder,\n getDefaultLamportsEncoder,\n type LamportsUnsafeBeyond2Pow53Minus1,\n} from '@solana/rpc-types';\n\nimport { fetchEncodedSysvarAccount, SYSVAR_STAKE_HISTORY_ADDRESS } from './sysvar';\n\ntype Entry = Readonly<{\n activating: LamportsUnsafeBeyond2Pow53Minus1;\n deactivating: LamportsUnsafeBeyond2Pow53Minus1;\n effective: LamportsUnsafeBeyond2Pow53Minus1;\n}>;\n\n/**\n * The `StakeHistory` sysvar.\n *\n * History of stake activations and de-activations.\n */\nexport type SysvarStakeHistory = Entry[];\n\nexport function getSysvarStakeHistoryEncoder(): VariableSizeEncoder<SysvarStakeHistory> {\n return getArrayEncoder(\n getStructEncoder([\n ['effective', getDefaultLamportsEncoder()],\n ['activating', getDefaultLamportsEncoder()],\n ['deactivating', getDefaultLamportsEncoder()],\n ]),\n );\n}\n\nexport function getSysvarStakeHistoryDecoder(): VariableSizeDecoder<SysvarStakeHistory> {\n return getArrayDecoder(\n getStructDecoder([\n ['effective', getDefaultLamportsDecoder()],\n ['activating', getDefaultLamportsDecoder()],\n ['deactivating', getDefaultLamportsDecoder()],\n ]),\n );\n}\n\nexport function getSysvarStakeHistoryCodec(): VariableSizeCodec<SysvarStakeHistory> {\n return combineCodec(getSysvarStakeHistoryEncoder(), getSysvarStakeHistoryDecoder());\n}\n\n/**\n * Fetch the `StakeHistory` sysvar.\n *\n * History of stake activations and de-activations.\n */\nexport async function fetchSysvarStakeHistory(\n rpc: Rpc<GetAccountInfoApi>,\n config?: FetchAccountConfig,\n): Promise<SysvarStakeHistory> {\n const account = await fetchEncodedSysvarAccount(rpc, SYSVAR_STAKE_HISTORY_ADDRESS, config);\n assertAccountExists(account);\n const decoded = decodeAccount(account, getSysvarStakeHistoryDecoder());\n return decoded.data;\n}\n"]}
|