-
Notifications
You must be signed in to change notification settings - Fork 907
/
connection.ts
6666 lines (6216 loc) · 190 KB
/
connection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import HttpKeepAliveAgent, {
HttpsAgent as HttpsKeepAliveAgent,
} from 'agentkeepalive';
import bs58 from 'bs58';
import {Buffer} from 'buffer';
// @ts-ignore
import fastStableStringify from 'fast-stable-stringify';
import type {Agent as NodeHttpAgent} from 'http';
import {Agent as NodeHttpsAgent} from 'https';
import {
type as pick,
number,
string,
array,
boolean,
literal,
record,
union,
optional,
nullable,
coerce,
instance,
create,
tuple,
unknown,
any,
} from 'superstruct';
import type {Struct} from 'superstruct';
import RpcClient from 'jayson/lib/client/browser';
import {JSONRPCError} from 'jayson';
import {EpochSchedule} from './epoch-schedule';
import {SendTransactionError, SolanaJSONRPCError} from './errors';
import fetchImpl, {Response} from './fetch-impl';
import {DurableNonce, NonceAccount} from './nonce-account';
import {PublicKey} from './publickey';
import {Signer} from './keypair';
import RpcWebSocketClient from './rpc-websocket';
import {MS_PER_SLOT} from './timing';
import {
Transaction,
TransactionStatus,
TransactionVersion,
VersionedTransaction,
} from './transaction';
import {Message, MessageHeader, MessageV0, VersionedMessage} from './message';
import {AddressLookupTableAccount} from './programs/address-lookup-table/state';
import assert from './utils/assert';
import {sleep} from './utils/sleep';
import {toBuffer} from './utils/to-buffer';
import {
TransactionExpiredBlockheightExceededError,
TransactionExpiredNonceInvalidError,
TransactionExpiredTimeoutError,
} from './transaction/expiry-custom-errors';
import {makeWebsocketUrl} from './utils/makeWebsocketUrl';
import type {Blockhash} from './blockhash';
import type {FeeCalculator} from './fee-calculator';
import type {TransactionSignature} from './transaction';
import type {CompiledInstruction} from './message';
const PublicKeyFromString = coerce(
instance(PublicKey),
string(),
value => new PublicKey(value),
);
const RawAccountDataResult = tuple([string(), literal('base64')]);
const BufferFromRawAccountData = coerce(
instance(Buffer),
RawAccountDataResult,
value => Buffer.from(value[0], 'base64'),
);
/**
* Attempt to use a recent blockhash for up to 30 seconds
* @internal
*/
export const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
/**
* HACK.
* Copied from rpc-websockets/dist/lib/client.
* Otherwise, `yarn build` fails with:
* https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
*/
interface IWSRequestParams {
[x: string]: any;
[x: number]: any;
}
type ClientSubscriptionId = number;
/** @internal */ type ServerSubscriptionId = number;
/** @internal */ type SubscriptionConfigHash = string;
/** @internal */ type SubscriptionDisposeFn = () => Promise<void>;
/** @internal */ type SubscriptionStateChangeCallback = (
nextState: StatefulSubscription['state'],
) => void;
/** @internal */ type SubscriptionStateChangeDisposeFn = () => void;
/**
* @internal
* Every subscription contains the args used to open the subscription with
* the server, and a list of callers interested in notifications.
*/
type BaseSubscription<TMethod = SubscriptionConfig['method']> = Readonly<{
args: IWSRequestParams;
callbacks: Set<Extract<SubscriptionConfig, {method: TMethod}>['callback']>;
}>;
/**
* @internal
* A subscription may be in various states of connectedness. Only when it is
* fully connected will it have a server subscription id associated with it.
* This id can be returned to the server to unsubscribe the client entirely.
*/
type StatefulSubscription = Readonly<
// New subscriptions that have not yet been
// sent to the server start in this state.
| {
state: 'pending';
}
// These subscriptions have been sent to the server
// and are waiting for the server to acknowledge them.
| {
state: 'subscribing';
}
// These subscriptions have been acknowledged by the
// server and have been assigned server subscription ids.
| {
serverSubscriptionId: ServerSubscriptionId;
state: 'subscribed';
}
// These subscriptions are intended to be torn down and
// are waiting on an acknowledgement from the server.
| {
serverSubscriptionId: ServerSubscriptionId;
state: 'unsubscribing';
}
// The request to tear down these subscriptions has been
// acknowledged by the server. The `serverSubscriptionId`
// is the id of the now-dead subscription.
| {
serverSubscriptionId: ServerSubscriptionId;
state: 'unsubscribed';
}
>;
/**
* A type that encapsulates a subscription's RPC method
* names and notification (callback) signature.
*/
type SubscriptionConfig = Readonly<
| {
callback: AccountChangeCallback;
method: 'accountSubscribe';
unsubscribeMethod: 'accountUnsubscribe';
}
| {
callback: LogsCallback;
method: 'logsSubscribe';
unsubscribeMethod: 'logsUnsubscribe';
}
| {
callback: ProgramAccountChangeCallback;
method: 'programSubscribe';
unsubscribeMethod: 'programUnsubscribe';
}
| {
callback: RootChangeCallback;
method: 'rootSubscribe';
unsubscribeMethod: 'rootUnsubscribe';
}
| {
callback: SignatureSubscriptionCallback;
method: 'signatureSubscribe';
unsubscribeMethod: 'signatureUnsubscribe';
}
| {
callback: SlotChangeCallback;
method: 'slotSubscribe';
unsubscribeMethod: 'slotUnsubscribe';
}
| {
callback: SlotUpdateCallback;
method: 'slotsUpdatesSubscribe';
unsubscribeMethod: 'slotsUpdatesUnsubscribe';
}
>;
/**
* @internal
* Utility type that keeps tagged unions intact while omitting properties.
*/
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown
? Omit<T, K>
: never;
/**
* @internal
* This type represents a single subscribable 'topic.' It's made up of:
*
* - The args used to open the subscription with the server,
* - The state of the subscription, in terms of its connectedness, and
* - The set of callbacks to call when the server publishes notifications
*
* This record gets indexed by `SubscriptionConfigHash` and is used to
* set up subscriptions, fan out notifications, and track subscription state.
*/
type Subscription = BaseSubscription &
StatefulSubscription &
DistributiveOmit<SubscriptionConfig, 'callback'>;
type RpcRequest = (methodName: string, args: Array<any>) => Promise<any>;
type RpcBatchRequest = (requests: RpcParams[]) => Promise<any[]>;
/**
* @internal
*/
export type RpcParams = {
methodName: string;
args: Array<any>;
};
export type TokenAccountsFilter =
| {
mint: PublicKey;
}
| {
programId: PublicKey;
};
/**
* Extra contextual information for RPC responses
*/
export type Context = {
slot: number;
};
/**
* Options for sending transactions
*/
export type SendOptions = {
/** disable transaction verification step */
skipPreflight?: boolean;
/** preflight commitment level */
preflightCommitment?: Commitment;
/** Maximum number of times for the RPC node to retry sending the transaction to the leader. */
maxRetries?: number;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Options for confirming transactions
*/
export type ConfirmOptions = {
/** disable transaction verification step */
skipPreflight?: boolean;
/** desired commitment level */
commitment?: Commitment;
/** preflight commitment level */
preflightCommitment?: Commitment;
/** Maximum number of times for the RPC node to retry sending the transaction to the leader. */
maxRetries?: number;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Options for getConfirmedSignaturesForAddress2
*/
export type ConfirmedSignaturesForAddress2Options = {
/**
* Start searching backwards from this transaction signature.
* @remark If not provided the search starts from the highest max confirmed block.
*/
before?: TransactionSignature;
/** Search until this transaction signature is reached, if found before `limit`. */
until?: TransactionSignature;
/** Maximum transaction signatures to return (between 1 and 1,000, default: 1,000). */
limit?: number;
};
/**
* Options for getSignaturesForAddress
*/
export type SignaturesForAddressOptions = {
/**
* Start searching backwards from this transaction signature.
* @remark If not provided the search starts from the highest max confirmed block.
*/
before?: TransactionSignature;
/** Search until this transaction signature is reached, if found before `limit`. */
until?: TransactionSignature;
/** Maximum transaction signatures to return (between 1 and 1,000, default: 1,000). */
limit?: number;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* RPC Response with extra contextual information
*/
export type RpcResponseAndContext<T> = {
/** response context */
context: Context;
/** response value */
value: T;
};
export type BlockhashWithExpiryBlockHeight = Readonly<{
blockhash: Blockhash;
lastValidBlockHeight: number;
}>;
/**
* A strategy for confirming transactions that uses the last valid
* block height for a given blockhash to check for transaction expiration.
*/
export type BlockheightBasedTransactionConfirmationStrategy =
BaseTransactionConfirmationStrategy & BlockhashWithExpiryBlockHeight;
/**
* A strategy for confirming durable nonce transactions.
*/
export type DurableNonceTransactionConfirmationStrategy =
BaseTransactionConfirmationStrategy & {
/**
* The lowest slot at which to fetch the nonce value from the
* nonce account. This should be no lower than the slot at
* which the last-known value of the nonce was fetched.
*/
minContextSlot: number;
/**
* The account where the current value of the nonce is stored.
*/
nonceAccountPubkey: PublicKey;
/**
* The nonce value that was used to sign the transaction
* for which confirmation is being sought.
*/
nonceValue: DurableNonce;
};
/**
* Properties shared by all transaction confirmation strategies
*/
export type BaseTransactionConfirmationStrategy = Readonly<{
/** A signal that, when aborted, cancels any outstanding transaction confirmation operations */
abortSignal?: AbortSignal;
signature: TransactionSignature;
}>;
/**
* This type represents all transaction confirmation strategies
*/
export type TransactionConfirmationStrategy =
| BlockheightBasedTransactionConfirmationStrategy
| DurableNonceTransactionConfirmationStrategy;
/* @internal */
function assertEndpointUrl(putativeUrl: string) {
if (/^https?:/.test(putativeUrl) === false) {
throw new TypeError('Endpoint URL must start with `http:` or `https:`.');
}
return putativeUrl;
}
/** @internal */
function extractCommitmentFromConfig<TConfig>(
commitmentOrConfig?: Commitment | ({commitment?: Commitment} & TConfig),
) {
let commitment: Commitment | undefined;
let config: Omit<TConfig, 'commitment'> | undefined;
if (typeof commitmentOrConfig === 'string') {
commitment = commitmentOrConfig;
} else if (commitmentOrConfig) {
const {commitment: specifiedCommitment, ...specifiedConfig} =
commitmentOrConfig;
commitment = specifiedCommitment;
config = specifiedConfig;
}
return {commitment, config};
}
/**
* @internal
*/
function createRpcResult<T, U>(result: Struct<T, U>) {
return union([
pick({
jsonrpc: literal('2.0'),
id: string(),
result,
}),
pick({
jsonrpc: literal('2.0'),
id: string(),
error: pick({
code: unknown(),
message: string(),
data: optional(any()),
}),
}),
]);
}
const UnknownRpcResult = createRpcResult(unknown());
/**
* @internal
*/
function jsonRpcResult<T, U>(schema: Struct<T, U>) {
return coerce(createRpcResult(schema), UnknownRpcResult, value => {
if ('error' in value) {
return value;
} else {
return {
...value,
result: create(value.result, schema),
};
}
});
}
/**
* @internal
*/
function jsonRpcResultAndContext<T, U>(value: Struct<T, U>) {
return jsonRpcResult(
pick({
context: pick({
slot: number(),
}),
value,
}),
);
}
/**
* @internal
*/
function notificationResultAndContext<T, U>(value: Struct<T, U>) {
return pick({
context: pick({
slot: number(),
}),
value,
});
}
/**
* @internal
*/
function versionedMessageFromResponse(
version: TransactionVersion | undefined,
response: MessageResponse,
): VersionedMessage {
if (version === 0) {
return new MessageV0({
header: response.header,
staticAccountKeys: response.accountKeys.map(
accountKey => new PublicKey(accountKey),
),
recentBlockhash: response.recentBlockhash,
compiledInstructions: response.instructions.map(ix => ({
programIdIndex: ix.programIdIndex,
accountKeyIndexes: ix.accounts,
data: bs58.decode(ix.data),
})),
addressTableLookups: response.addressTableLookups!,
});
} else {
return new Message(response);
}
}
/**
* The level of commitment desired when querying state
* <pre>
* 'processed': Query the most recent block which has reached 1 confirmation by the connected node
* 'confirmed': Query the most recent block which has reached 1 confirmation by the cluster
* 'finalized': Query the most recent block which has been finalized by the cluster
* </pre>
*/
export type Commitment =
| 'processed'
| 'confirmed'
| 'finalized'
| 'recent' // Deprecated as of v1.5.5
| 'single' // Deprecated as of v1.5.5
| 'singleGossip' // Deprecated as of v1.5.5
| 'root' // Deprecated as of v1.5.5
| 'max'; // Deprecated as of v1.5.5
/**
* A subset of Commitment levels, which are at least optimistically confirmed
* <pre>
* 'confirmed': Query the most recent block which has reached 1 confirmation by the cluster
* 'finalized': Query the most recent block which has been finalized by the cluster
* </pre>
*/
export type Finality = 'confirmed' | 'finalized';
/**
* Filter for largest accounts query
* <pre>
* 'circulating': Return the largest accounts that are part of the circulating supply
* 'nonCirculating': Return the largest accounts that are not part of the circulating supply
* </pre>
*/
export type LargestAccountsFilter = 'circulating' | 'nonCirculating';
/**
* Configuration object for changing `getAccountInfo` query behavior
*/
export type GetAccountInfoConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
/** Optional data slice to limit the returned account data */
dataSlice?: DataSlice;
};
/**
* Configuration object for changing `getBalance` query behavior
*/
export type GetBalanceConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Configuration object for changing `getBlock` query behavior
*/
export type GetBlockConfig = {
/** The level of finality desired */
commitment?: Finality;
/**
* Whether to populate the rewards array. If parameter not provided, the default includes rewards.
*/
rewards?: boolean;
/**
* Level of transaction detail to return, either "full", "accounts", "signatures", or "none". If
* parameter not provided, the default detail level is "full". If "accounts" are requested,
* transaction details only include signatures and an annotated list of accounts in each
* transaction. Transaction metadata is limited to only: fee, err, pre_balances, post_balances,
* pre_token_balances, and post_token_balances.
*/
transactionDetails?: 'accounts' | 'full' | 'none' | 'signatures';
};
/**
* Configuration object for changing `getBlock` query behavior
*/
export type GetVersionedBlockConfig = {
/** The level of finality desired */
commitment?: Finality;
/** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
maxSupportedTransactionVersion?: number;
/**
* Whether to populate the rewards array. If parameter not provided, the default includes rewards.
*/
rewards?: boolean;
/**
* Level of transaction detail to return, either "full", "accounts", "signatures", or "none". If
* parameter not provided, the default detail level is "full". If "accounts" are requested,
* transaction details only include signatures and an annotated list of accounts in each
* transaction. Transaction metadata is limited to only: fee, err, pre_balances, post_balances,
* pre_token_balances, and post_token_balances.
*/
transactionDetails?: 'accounts' | 'full' | 'none' | 'signatures';
};
/**
* Configuration object for changing `getStakeMinimumDelegation` query behavior
*/
export type GetStakeMinimumDelegationConfig = {
/** The level of commitment desired */
commitment?: Commitment;
};
/**
* Configuration object for changing `getBlockHeight` query behavior
*/
export type GetBlockHeightConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Configuration object for changing `getEpochInfo` query behavior
*/
export type GetEpochInfoConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Configuration object for changing `getInflationReward` query behavior
*/
export type GetInflationRewardConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** An epoch for which the reward occurs. If omitted, the previous epoch will be used */
epoch?: number;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Configuration object for changing `getLatestBlockhash` query behavior
*/
export type GetLatestBlockhashConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Configuration object for changing `getSlot` query behavior
*/
export type GetSlotConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Configuration object for changing `getSlotLeader` query behavior
*/
export type GetSlotLeaderConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: number;
};
/**
* Configuration object for changing `getTransaction` query behavior
*/
export type GetTransactionConfig = {
/** The level of finality desired */
commitment?: Finality;
};
/**
* Configuration object for changing `getTransaction` query behavior
*/
export type GetVersionedTransactionConfig = {
/** The level of finality desired */
commitment?: Finality;
/** The max transaction version to return in responses. If the requested transaction is a higher version, an error will be returned */
maxSupportedTransactionVersion?: number;
};
/**
* Configuration object for changing `getLargestAccounts` query behavior
*/
export type GetLargestAccountsConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** Filter largest accounts by whether they are part of the circulating supply */
filter?: LargestAccountsFilter;
};
/**
* Configuration object for changing `getSupply` request behavior
*/
export type GetSupplyConfig = {
/** The level of commitment desired */
commitment?: Commitment;
/** Exclude non circulating accounts list from response */
excludeNonCirculatingAccountsList?: boolean;
};
/**
* Configuration object for changing query behavior
*/
export type SignatureStatusConfig = {
/** enable searching status history, not needed for recent transactions */
searchTransactionHistory: boolean;
};
/**
* Information describing a cluster node
*/
export type ContactInfo = {
/** Identity public key of the node */
pubkey: string;
/** Gossip network address for the node */
gossip: string | null;
/** TPU network address for the node (null if not available) */
tpu: string | null;
/** JSON RPC network address for the node (null if not available) */
rpc: string | null;
/** Software version of the node (null if not available) */
version: string | null;
};
/**
* Information describing a vote account
*/
export type VoteAccountInfo = {
/** Public key of the vote account */
votePubkey: string;
/** Identity public key of the node voting with this account */
nodePubkey: string;
/** The stake, in lamports, delegated to this vote account and activated */
activatedStake: number;
/** Whether the vote account is staked for this epoch */
epochVoteAccount: boolean;
/** Recent epoch voting credit history for this voter */
epochCredits: Array<[number, number, number]>;
/** A percentage (0-100) of rewards payout owed to the voter */
commission: number;
/** Most recent slot voted on by this vote account */
lastVote: number;
};
/**
* A collection of cluster vote accounts
*/
export type VoteAccountStatus = {
/** Active vote accounts */
current: Array<VoteAccountInfo>;
/** Inactive vote accounts */
delinquent: Array<VoteAccountInfo>;
};
/**
* Network Inflation
* (see https://docs.solana.com/implemented-proposals/ed_overview)
*/
export type InflationGovernor = {
foundation: number;
foundationTerm: number;
initial: number;
taper: number;
terminal: number;
};
const GetInflationGovernorResult = pick({
foundation: number(),
foundationTerm: number(),
initial: number(),
taper: number(),
terminal: number(),
});
/**
* The inflation reward for an epoch
*/
export type InflationReward = {
/** epoch for which the reward occurs */
epoch: number;
/** the slot in which the rewards are effective */
effectiveSlot: number;
/** reward amount in lamports */
amount: number;
/** post balance of the account in lamports */
postBalance: number;
/** vote account commission when the reward was credited */
commission?: number | null;
};
/**
* Expected JSON RPC response for the "getInflationReward" message
*/
const GetInflationRewardResult = jsonRpcResult(
array(
nullable(
pick({
epoch: number(),
effectiveSlot: number(),
amount: number(),
postBalance: number(),
commission: optional(nullable(number())),
}),
),
),
);
export type InflationRate = {
/** total inflation */
total: number;
/** inflation allocated to validators */
validator: number;
/** inflation allocated to the foundation */
foundation: number;
/** epoch for which these values are valid */
epoch: number;
};
/**
* Expected JSON RPC response for the "getInflationRate" message
*/
const GetInflationRateResult = pick({
total: number(),
validator: number(),
foundation: number(),
epoch: number(),
});
/**
* Information about the current epoch
*/
export type EpochInfo = {
epoch: number;
slotIndex: number;
slotsInEpoch: number;
absoluteSlot: number;
blockHeight?: number;
transactionCount?: number;
};
const GetEpochInfoResult = pick({
epoch: number(),
slotIndex: number(),
slotsInEpoch: number(),
absoluteSlot: number(),
blockHeight: optional(number()),
transactionCount: optional(number()),
});
const GetEpochScheduleResult = pick({
slotsPerEpoch: number(),
leaderScheduleSlotOffset: number(),
warmup: boolean(),
firstNormalEpoch: number(),
firstNormalSlot: number(),
});
/**
* Leader schedule
* (see https://docs.solana.com/terminology#leader-schedule)
*/
export type LeaderSchedule = {
[address: string]: number[];
};
const GetLeaderScheduleResult = record(string(), array(number()));
/**
* Transaction error or null
*/
const TransactionErrorResult = nullable(union([pick({}), string()]));
/**
* Signature status for a transaction
*/
const SignatureStatusResult = pick({
err: TransactionErrorResult,
});
/**
* Transaction signature received notification
*/
const SignatureReceivedResult = literal('receivedSignature');
/**
* Version info for a node
*/
export type Version = {
/** Version of solana-core */
'solana-core': string;
'feature-set'?: number;
};
const VersionResult = pick({
'solana-core': string(),
'feature-set': optional(number()),
});
export type SimulatedTransactionAccountInfo = {
/** `true` if this account's data contains a loaded program */
executable: boolean;
/** Identifier of the program that owns the account */
owner: string;
/** Number of lamports assigned to the account */
lamports: number;
/** Optional data assigned to the account */
data: string[];
/** Optional rent epoch info for account */
rentEpoch?: number;
};
export type TransactionReturnDataEncoding = 'base64';
export type TransactionReturnData = {
programId: string;
data: [string, TransactionReturnDataEncoding];
};
export type SimulateTransactionConfig = {
/** Optional parameter used to enable signature verification before simulation */
sigVerify?: boolean;
/** Optional parameter used to replace the simulated transaction's recent blockhash with the latest blockhash */
replaceRecentBlockhash?: boolean;
/** Optional parameter used to set the commitment level when selecting the latest block */
commitment?: Commitment;
/** Optional parameter used to specify a list of account addresses to return post simulation state for */
accounts?: {
encoding: 'base64';
addresses: string[];
};
/** Optional parameter used to specify the minimum block slot that can be used for simulation */
minContextSlot?: number;
};
export type SimulatedTransactionResponse = {
err: TransactionError | string | null;
logs: Array<string> | null;
accounts?: (SimulatedTransactionAccountInfo | null)[] | null;
unitsConsumed?: number;
returnData?: TransactionReturnData | null;
};
const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(
pick({
err: nullable(union([pick({}), string()])),
logs: nullable(array(string())),
accounts: optional(
nullable(
array(
nullable(
pick({
executable: boolean(),
owner: string(),
lamports: number(),
data: array(string()),
rentEpoch: optional(number()),
}),
),
),
),
),
unitsConsumed: optional(number()),
returnData: optional(
nullable(
pick({
programId: string(),
data: tuple([string(), literal('base64')]),
}),
),
),
}),
);
export type ParsedInnerInstruction = {
index: number;
instructions: (ParsedInstruction | PartiallyDecodedInstruction)[];
};
export type TokenBalance = {
accountIndex: number;
mint: string;
owner?: string;
uiTokenAmount: TokenAmount;
};
/**
* Metadata for a parsed confirmed transaction on the ledger
*
* @deprecated Deprecated since Solana v1.8.0. Please use {@link ParsedTransactionMeta} instead.
*/
export type ParsedConfirmedTransactionMeta = ParsedTransactionMeta;
/**
* Collection of addresses loaded by a transaction using address table lookups
*/
export type LoadedAddresses = {
writable: Array<PublicKey>;
readonly: Array<PublicKey>;
};
/**
* Metadata for a parsed transaction on the ledger
*/
export type ParsedTransactionMeta = {
/** The fee charged for processing the transaction */
fee: number;
/** An array of cross program invoked parsed instructions */
innerInstructions?: ParsedInnerInstruction[] | null;
/** The balances of the transaction accounts before processing */
preBalances: Array<number>;
/** The balances of the transaction accounts after processing */
postBalances: Array<number>;
/** An array of program log messages emitted during a transaction */
logMessages?: Array<string> | null;
/** The token balances of the transaction accounts before processing */
preTokenBalances?: Array<TokenBalance> | null;
/** The token balances of the transaction accounts after processing */
postTokenBalances?: Array<TokenBalance> | null;