@solana/web3.js 1.31.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -53,6 +53,7 @@ declare module '@solana/web3.js' {
53
53
  * Return the base-58 representation of the public key
54
54
  */
55
55
  toBase58(): string;
56
+ toJSON(): string;
56
57
  /**
57
58
  * Return the byte array representation of the public key
58
59
  */
@@ -759,6 +760,7 @@ declare module '@solana/web3.js' {
759
760
  export type TokenBalance = {
760
761
  accountIndex: number;
761
762
  mint: string;
763
+ owner?: string;
762
764
  uiTokenAmount: TokenAmount;
763
765
  };
764
766
  /**
@@ -1188,6 +1190,15 @@ declare module '@solana/web3.js' {
1188
1190
  /** Optional array of filters to apply to accounts */
1189
1191
  filters?: GetProgramAccountsFilter[];
1190
1192
  };
1193
+ /**
1194
+ * Configuration object for getMultipleAccounts
1195
+ */
1196
+ export type GetMultipleAccountsConfig = {
1197
+ /** Optional commitment level */
1198
+ commitment?: Commitment;
1199
+ /** Optional encoding for account data (default base64) */
1200
+ encoding?: 'base64' | 'jsonParsed';
1201
+ };
1191
1202
  /**
1192
1203
  * Information describing an account
1193
1204
  */
@@ -1200,7 +1211,7 @@ declare module '@solana/web3.js' {
1200
1211
  lamports: number;
1201
1212
  /** Optional data assigned to the account */
1202
1213
  data: T;
1203
- /** Optional rent epoch infor for account */
1214
+ /** Optional rent epoch info for account */
1204
1215
  rentEpoch?: number;
1205
1216
  };
1206
1217
  /**
@@ -1348,7 +1359,7 @@ declare module '@solana/web3.js' {
1348
1359
  export type FetchMiddleware = (
1349
1360
  url: string,
1350
1361
  options: any,
1351
- fetch: Function,
1362
+ fetch: (modifiedUrl: string, modifiedOptions: any) => void,
1352
1363
  ) => void;
1353
1364
  /**
1354
1365
  * Configuration for instantiating a Connection
@@ -1505,8 +1516,8 @@ declare module '@solana/web3.js' {
1505
1516
  */
1506
1517
  getMultipleAccountsInfo(
1507
1518
  publicKeys: PublicKey[],
1508
- commitment?: Commitment,
1509
- ): Promise<(AccountInfo<Buffer> | null)[]>;
1519
+ configOrCommitment?: GetMultipleAccountsConfig | Commitment,
1520
+ ): Promise<(AccountInfo<Buffer | ParsedAccountData> | null)[]>;
1510
1521
  /**
1511
1522
  * Returns epoch activation information for a stake account that has been delegated
1512
1523
  */
@@ -1652,6 +1663,13 @@ declare module '@solana/web3.js' {
1652
1663
  blockhash: Blockhash,
1653
1664
  commitment?: Commitment,
1654
1665
  ): Promise<RpcResponseAndContext<FeeCalculator | null>>;
1666
+ /**
1667
+ * Fetch the fee for a message from the cluster, return with context
1668
+ */
1669
+ getFeeForMessage(
1670
+ message: Message,
1671
+ commitment?: Commitment,
1672
+ ): Promise<RpcResponseAndContext<number>>;
1655
1673
  /**
1656
1674
  * Fetch a recent blockhash from the cluster
1657
1675
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
@@ -2824,20 +2842,32 @@ declare module '@solana/web3.js' {
2824
2842
  credits: number;
2825
2843
  prevCredits: number;
2826
2844
  };
2845
+ export type AuthorizedVoter = {
2846
+ epoch: number;
2847
+ authorizedVoter: PublicKey;
2848
+ };
2849
+ export type PriorVoter = {
2850
+ authorizedPubkey: PublicKey;
2851
+ epochOfLastAuthorizedSwitch: number;
2852
+ targetEpoch: number;
2853
+ };
2854
+ export type BlockTimestamp = {
2855
+ slot: number;
2856
+ timetamp: number;
2857
+ };
2827
2858
  /**
2828
2859
  * VoteAccount class
2829
2860
  */
2830
2861
  export class VoteAccount {
2831
2862
  nodePubkey: PublicKey;
2832
- authorizedVoterPubkey: PublicKey;
2833
- authorizedWithdrawerPubkey: PublicKey;
2863
+ authorizedWithdrawer: PublicKey;
2834
2864
  commission: number;
2835
- votes: Array<Lockout>;
2836
2865
  rootSlot: number | null;
2837
- epoch: number;
2838
- credits: number;
2839
- lastEpochCredits: number;
2840
- epochCredits: Array<EpochCredits>;
2866
+ votes: Lockout[];
2867
+ authorizedVoters: AuthorizedVoter[];
2868
+ priorVoters: PriorVoter[];
2869
+ epochCredits: EpochCredits[];
2870
+ lastTimestamp: BlockTimestamp;
2841
2871
  /**
2842
2872
  * Deserialize VoteAccount from the account data.
2843
2873
  *
@@ -2850,11 +2880,14 @@ declare module '@solana/web3.js' {
2850
2880
  }
2851
2881
 
2852
2882
  export const SYSVAR_CLOCK_PUBKEY: PublicKey;
2883
+ export const SYSVAR_EPOCH_SCHEDULE_PUBKEY: PublicKey;
2884
+ export const SYSVAR_INSTRUCTIONS_PUBKEY: PublicKey;
2853
2885
  export const SYSVAR_RECENT_BLOCKHASHES_PUBKEY: PublicKey;
2854
2886
  export const SYSVAR_RENT_PUBKEY: PublicKey;
2855
2887
  export const SYSVAR_REWARDS_PUBKEY: PublicKey;
2888
+ export const SYSVAR_SLOT_HASHES_PUBKEY: PublicKey;
2889
+ export const SYSVAR_SLOT_HISTORY_PUBKEY: PublicKey;
2856
2890
  export const SYSVAR_STAKE_HISTORY_PUBKEY: PublicKey;
2857
- export const SYSVAR_INSTRUCTIONS_PUBKEY: PublicKey;
2858
2891
 
2859
2892
  export class SendTransactionError extends Error {
2860
2893
  logs: string[] | undefined;
package/lib/index.esm.js CHANGED
@@ -1805,6 +1805,10 @@ class PublicKey extends Struct {
1805
1805
  toBase58() {
1806
1806
  return bs58.encode(this.toBytes());
1807
1807
  }
1808
+
1809
+ toJSON() {
1810
+ return this.toBase58();
1811
+ }
1808
1812
  /**
1809
1813
  * Return the byte array representation of the public key
1810
1814
  */
@@ -2444,8 +2448,9 @@ class Transaction {
2444
2448
  }); // Sort. Prioritizing first by signer, then by writable
2445
2449
 
2446
2450
  accountMetas.sort(function (x, y) {
2451
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
2447
2452
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
2448
- const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
2453
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
2449
2454
  return checkSigner || checkWritable;
2450
2455
  }); // Cull duplicate account metas
2451
2456
 
@@ -2901,11 +2906,14 @@ class Transaction {
2901
2906
  }
2902
2907
 
2903
2908
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
2909
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
2910
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2904
2911
  const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
2905
2912
  const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
2906
2913
  const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
2914
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
2915
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2907
2916
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2908
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
2909
2917
 
2910
2918
  /**
2911
2919
  * Sign, send and confirm a transaction.
@@ -4323,16 +4331,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
4323
4331
  let fetchWithMiddleware;
4324
4332
 
4325
4333
  if (fetchMiddleware) {
4326
- fetchWithMiddleware = (url, options) => {
4327
- return new Promise((resolve, reject) => {
4328
- fetchMiddleware(url, options, async (url, options) => {
4329
- try {
4330
- resolve(await fetch(url, options));
4331
- } catch (error) {
4332
- reject(error);
4333
- }
4334
- });
4334
+ fetchWithMiddleware = async (url, options) => {
4335
+ const modifiedFetchArgs = await new Promise((resolve, reject) => {
4336
+ try {
4337
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4338
+ } catch (error) {
4339
+ reject(error);
4340
+ }
4335
4341
  });
4342
+ return await fetch(...modifiedFetchArgs);
4336
4343
  };
4337
4344
  }
4338
4345
 
@@ -4826,6 +4833,7 @@ const ParsedConfirmedTransactionResult = type({
4826
4833
  const TokenBalanceResult = type({
4827
4834
  accountIndex: number(),
4828
4835
  mint: string(),
4836
+ owner: optional(string()),
4829
4837
  uiTokenAmount: TokenAmountResult
4830
4838
  });
4831
4839
  /**
@@ -5429,13 +5437,25 @@ class Connection {
5429
5437
  */
5430
5438
 
5431
5439
 
5432
- async getMultipleAccountsInfo(publicKeys, commitment) {
5440
+ async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
5433
5441
  const keys = publicKeys.map(key => key.toBase58());
5442
+ let commitment;
5443
+ let encoding = 'base64';
5444
+
5445
+ if (configOrCommitment) {
5446
+ if (typeof configOrCommitment === 'string') {
5447
+ commitment = configOrCommitment;
5448
+ encoding = 'base64';
5449
+ } else {
5450
+ commitment = configOrCommitment.commitment;
5451
+ encoding = configOrCommitment.encoding || 'base64';
5452
+ }
5453
+ }
5434
5454
 
5435
- const args = this._buildArgs([keys], commitment, 'base64');
5455
+ const args = this._buildArgs([keys], commitment, encoding);
5436
5456
 
5437
5457
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
5438
- const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
5458
+ const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
5439
5459
 
5440
5460
  if ('error' in res) {
5441
5461
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
@@ -5916,6 +5936,29 @@ class Connection {
5916
5936
  value: value !== null ? value.feeCalculator : null
5917
5937
  };
5918
5938
  }
5939
+ /**
5940
+ * Fetch the fee for a message from the cluster, return with context
5941
+ */
5942
+
5943
+
5944
+ async getFeeForMessage(message, commitment) {
5945
+ const wireMessage = message.serialize().toString('base64');
5946
+
5947
+ const args = this._buildArgs([wireMessage], commitment);
5948
+
5949
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
5950
+ const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
5951
+
5952
+ if ('error' in res) {
5953
+ throw new Error('failed to get slot: ' + res.error.message);
5954
+ }
5955
+
5956
+ if (res.result === null) {
5957
+ throw new Error('invalid blockhash');
5958
+ }
5959
+
5960
+ return res.result;
5961
+ }
5919
5962
  /**
5920
5963
  * Fetch a recent blockhash from the cluster
5921
5964
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
@@ -8395,9 +8438,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
8395
8438
  *
8396
8439
  * @internal
8397
8440
  */
8398
- const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
8399
- BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('lastEpochCredits'), BufferLayout.nu64(), // epochCredits.length
8400
- BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits')]);
8441
+ const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
8442
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(), // authorizedVoters.length
8443
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout.offset(BufferLayout.u32(), -8), 'authorizedVoters'), BufferLayout.struct([BufferLayout.seq(BufferLayout.struct([publicKey('authorizedPubkey'), BufferLayout.nu64('epochOfLastAuthorizedSwitch'), BufferLayout.nu64('targetEpoch')]), 32, 'buf'), BufferLayout.nu64('idx'), BufferLayout.u8('isEmpty')], 'priorVoters'), BufferLayout.nu64(), // epochCredits.length
8444
+ BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits'), BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')], 'lastTimestamp')]);
8401
8445
 
8402
8446
  /**
8403
8447
  * VoteAccount class
@@ -8408,25 +8452,23 @@ class VoteAccount {
8408
8452
  */
8409
8453
  constructor(args) {
8410
8454
  this.nodePubkey = void 0;
8411
- this.authorizedVoterPubkey = void 0;
8412
- this.authorizedWithdrawerPubkey = void 0;
8455
+ this.authorizedWithdrawer = void 0;
8413
8456
  this.commission = void 0;
8414
- this.votes = void 0;
8415
8457
  this.rootSlot = void 0;
8416
- this.epoch = void 0;
8417
- this.credits = void 0;
8418
- this.lastEpochCredits = void 0;
8458
+ this.votes = void 0;
8459
+ this.authorizedVoters = void 0;
8460
+ this.priorVoters = void 0;
8419
8461
  this.epochCredits = void 0;
8462
+ this.lastTimestamp = void 0;
8420
8463
  this.nodePubkey = args.nodePubkey;
8421
- this.authorizedVoterPubkey = args.authorizedVoterPubkey;
8422
- this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
8464
+ this.authorizedWithdrawer = args.authorizedWithdrawer;
8423
8465
  this.commission = args.commission;
8424
- this.votes = args.votes;
8425
8466
  this.rootSlot = args.rootSlot;
8426
- this.epoch = args.epoch;
8427
- this.credits = args.credits;
8428
- this.lastEpochCredits = args.lastEpochCredits;
8467
+ this.votes = args.votes;
8468
+ this.authorizedVoters = args.authorizedVoters;
8469
+ this.priorVoters = args.priorVoters;
8429
8470
  this.epochCredits = args.epochCredits;
8471
+ this.lastTimestamp = args.lastTimestamp;
8430
8472
  }
8431
8473
  /**
8432
8474
  * Deserialize VoteAccount from the account data.
@@ -8437,7 +8479,8 @@ class VoteAccount {
8437
8479
 
8438
8480
 
8439
8481
  static fromAccountData(buffer) {
8440
- const va = VoteAccountLayout.decode(toBuffer(buffer), 0);
8482
+ const versionOffset = 4;
8483
+ const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
8441
8484
  let rootSlot = va.rootSlot;
8442
8485
 
8443
8486
  if (!va.rootSlotValid) {
@@ -8446,20 +8489,53 @@ class VoteAccount {
8446
8489
 
8447
8490
  return new VoteAccount({
8448
8491
  nodePubkey: new PublicKey(va.nodePubkey),
8449
- authorizedVoterPubkey: new PublicKey(va.authorizedVoterPubkey),
8450
- authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
8492
+ authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
8451
8493
  commission: va.commission,
8452
8494
  votes: va.votes,
8453
8495
  rootSlot,
8454
- epoch: va.epoch,
8455
- credits: va.credits,
8456
- lastEpochCredits: va.lastEpochCredits,
8457
- epochCredits: va.epochCredits
8496
+ authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
8497
+ priorVoters: getPriorVoters(va.priorVoters),
8498
+ epochCredits: va.epochCredits,
8499
+ lastTimestamp: va.lastTimestamp
8458
8500
  });
8459
8501
  }
8460
8502
 
8461
8503
  }
8462
8504
 
8505
+ function parseAuthorizedVoter({
8506
+ epoch,
8507
+ authorizedVoter
8508
+ }) {
8509
+ return {
8510
+ epoch,
8511
+ authorizedVoter: new PublicKey(authorizedVoter)
8512
+ };
8513
+ }
8514
+
8515
+ function parsePriorVoters({
8516
+ authorizedPubkey,
8517
+ epochOfLastAuthorizedSwitch,
8518
+ targetEpoch
8519
+ }) {
8520
+ return {
8521
+ authorizedPubkey: new PublicKey(authorizedPubkey),
8522
+ epochOfLastAuthorizedSwitch,
8523
+ targetEpoch
8524
+ };
8525
+ }
8526
+
8527
+ function getPriorVoters({
8528
+ buf,
8529
+ idx,
8530
+ isEmpty
8531
+ }) {
8532
+ if (isEmpty) {
8533
+ return [];
8534
+ }
8535
+
8536
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8537
+ }
8538
+
8463
8539
  /**
8464
8540
  * Send and confirm a raw transaction
8465
8541
  *
@@ -8523,5 +8599,5 @@ function clusterApiUrl(cluster, tls) {
8523
8599
 
8524
8600
  const LAMPORTS_PER_SOL = 1000000000;
8525
8601
 
8526
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
8602
+ export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
8527
8603
  //# sourceMappingURL=index.esm.js.map