@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.iife.js CHANGED
@@ -11124,6 +11124,10 @@ var solanaWeb3 = (function (exports) {
11124
11124
  toBase58() {
11125
11125
  return bs58$1.encode(this.toBytes());
11126
11126
  }
11127
+
11128
+ toJSON() {
11129
+ return this.toBase58();
11130
+ }
11127
11131
  /**
11128
11132
  * Return the byte array representation of the public key
11129
11133
  */
@@ -14347,8 +14351,9 @@ var solanaWeb3 = (function (exports) {
14347
14351
  }); // Sort. Prioritizing first by signer, then by writable
14348
14352
 
14349
14353
  accountMetas.sort(function (x, y) {
14354
+ const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
14350
14355
  const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
14351
- const checkWritable = x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
14356
+ const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
14352
14357
  return checkSigner || checkWritable;
14353
14358
  }); // Cull duplicate account metas
14354
14359
 
@@ -14804,11 +14809,14 @@ var solanaWeb3 = (function (exports) {
14804
14809
  }
14805
14810
 
14806
14811
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
14812
+ const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
14813
+ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
14807
14814
  const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
14808
14815
  const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
14809
14816
  const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
14817
+ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
14818
+ const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
14810
14819
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
14811
- const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
14812
14820
 
14813
14821
  /**
14814
14822
  * Sign, send and confirm a transaction.
@@ -19850,16 +19858,15 @@ var solanaWeb3 = (function (exports) {
19850
19858
  let fetchWithMiddleware;
19851
19859
 
19852
19860
  if (fetchMiddleware) {
19853
- fetchWithMiddleware = (url, options) => {
19854
- return new Promise((resolve, reject) => {
19855
- fetchMiddleware(url, options, async (url, options) => {
19856
- try {
19857
- resolve(await fetch(url, options));
19858
- } catch (error) {
19859
- reject(error);
19860
- }
19861
- });
19861
+ fetchWithMiddleware = async (url, options) => {
19862
+ const modifiedFetchArgs = await new Promise((resolve, reject) => {
19863
+ try {
19864
+ fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
19865
+ } catch (error) {
19866
+ reject(error);
19867
+ }
19862
19868
  });
19869
+ return await fetch(...modifiedFetchArgs);
19863
19870
  };
19864
19871
  }
19865
19872
 
@@ -20352,6 +20359,7 @@ var solanaWeb3 = (function (exports) {
20352
20359
  const TokenBalanceResult = type({
20353
20360
  accountIndex: number(),
20354
20361
  mint: string(),
20362
+ owner: optional(string()),
20355
20363
  uiTokenAmount: TokenAmountResult
20356
20364
  });
20357
20365
  /**
@@ -20955,13 +20963,25 @@ var solanaWeb3 = (function (exports) {
20955
20963
  */
20956
20964
 
20957
20965
 
20958
- async getMultipleAccountsInfo(publicKeys, commitment) {
20966
+ async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
20959
20967
  const keys = publicKeys.map(key => key.toBase58());
20968
+ let commitment;
20969
+ let encoding = 'base64';
20970
+
20971
+ if (configOrCommitment) {
20972
+ if (typeof configOrCommitment === 'string') {
20973
+ commitment = configOrCommitment;
20974
+ encoding = 'base64';
20975
+ } else {
20976
+ commitment = configOrCommitment.commitment;
20977
+ encoding = configOrCommitment.encoding || 'base64';
20978
+ }
20979
+ }
20960
20980
 
20961
- const args = this._buildArgs([keys], commitment, 'base64');
20981
+ const args = this._buildArgs([keys], commitment, encoding);
20962
20982
 
20963
20983
  const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
20964
- const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(AccountInfoResult))));
20984
+ const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
20965
20985
 
20966
20986
  if ('error' in res) {
20967
20987
  throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
@@ -21442,6 +21462,29 @@ var solanaWeb3 = (function (exports) {
21442
21462
  value: value !== null ? value.feeCalculator : null
21443
21463
  };
21444
21464
  }
21465
+ /**
21466
+ * Fetch the fee for a message from the cluster, return with context
21467
+ */
21468
+
21469
+
21470
+ async getFeeForMessage(message, commitment) {
21471
+ const wireMessage = message.serialize().toString('base64');
21472
+
21473
+ const args = this._buildArgs([wireMessage], commitment);
21474
+
21475
+ const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
21476
+ const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
21477
+
21478
+ if ('error' in res) {
21479
+ throw new Error('failed to get slot: ' + res.error.message);
21480
+ }
21481
+
21482
+ if (res.result === null) {
21483
+ throw new Error('invalid blockhash');
21484
+ }
21485
+
21486
+ return res.result;
21487
+ }
21445
21488
  /**
21446
21489
  * Fetch a recent blockhash from the cluster
21447
21490
  * @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
@@ -28755,9 +28798,10 @@ var solanaWeb3 = (function (exports) {
28755
28798
  *
28756
28799
  * @internal
28757
28800
  */
28758
- const VoteAccountLayout = struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), u8('commission'), nu64(), // votes.length
28759
- seq(struct([nu64('slot'), u32('confirmationCount')]), offset(u32(), -8), 'votes'), u8('rootSlotValid'), nu64('rootSlot'), nu64('epoch'), nu64('credits'), nu64('lastEpochCredits'), nu64(), // epochCredits.length
28760
- seq(struct([nu64('epoch'), nu64('credits'), nu64('prevCredits')]), offset(u32(), -8), 'epochCredits')]);
28801
+ const VoteAccountLayout = struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), u8('commission'), nu64(), // votes.length
28802
+ seq(struct([nu64('slot'), u32('confirmationCount')]), offset(u32(), -8), 'votes'), u8('rootSlotValid'), nu64('rootSlot'), nu64(), // authorizedVoters.length
28803
+ seq(struct([nu64('epoch'), publicKey('authorizedVoter')]), offset(u32(), -8), 'authorizedVoters'), struct([seq(struct([publicKey('authorizedPubkey'), nu64('epochOfLastAuthorizedSwitch'), nu64('targetEpoch')]), 32, 'buf'), nu64('idx'), u8('isEmpty')], 'priorVoters'), nu64(), // epochCredits.length
28804
+ seq(struct([nu64('epoch'), nu64('credits'), nu64('prevCredits')]), offset(u32(), -8), 'epochCredits'), struct([nu64('slot'), nu64('timestamp')], 'lastTimestamp')]);
28761
28805
 
28762
28806
  /**
28763
28807
  * VoteAccount class
@@ -28768,25 +28812,23 @@ var solanaWeb3 = (function (exports) {
28768
28812
  */
28769
28813
  constructor(args) {
28770
28814
  this.nodePubkey = void 0;
28771
- this.authorizedVoterPubkey = void 0;
28772
- this.authorizedWithdrawerPubkey = void 0;
28815
+ this.authorizedWithdrawer = void 0;
28773
28816
  this.commission = void 0;
28774
- this.votes = void 0;
28775
28817
  this.rootSlot = void 0;
28776
- this.epoch = void 0;
28777
- this.credits = void 0;
28778
- this.lastEpochCredits = void 0;
28818
+ this.votes = void 0;
28819
+ this.authorizedVoters = void 0;
28820
+ this.priorVoters = void 0;
28779
28821
  this.epochCredits = void 0;
28822
+ this.lastTimestamp = void 0;
28780
28823
  this.nodePubkey = args.nodePubkey;
28781
- this.authorizedVoterPubkey = args.authorizedVoterPubkey;
28782
- this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
28824
+ this.authorizedWithdrawer = args.authorizedWithdrawer;
28783
28825
  this.commission = args.commission;
28784
- this.votes = args.votes;
28785
28826
  this.rootSlot = args.rootSlot;
28786
- this.epoch = args.epoch;
28787
- this.credits = args.credits;
28788
- this.lastEpochCredits = args.lastEpochCredits;
28827
+ this.votes = args.votes;
28828
+ this.authorizedVoters = args.authorizedVoters;
28829
+ this.priorVoters = args.priorVoters;
28789
28830
  this.epochCredits = args.epochCredits;
28831
+ this.lastTimestamp = args.lastTimestamp;
28790
28832
  }
28791
28833
  /**
28792
28834
  * Deserialize VoteAccount from the account data.
@@ -28797,7 +28839,8 @@ var solanaWeb3 = (function (exports) {
28797
28839
 
28798
28840
 
28799
28841
  static fromAccountData(buffer) {
28800
- const va = VoteAccountLayout.decode(toBuffer(buffer), 0);
28842
+ const versionOffset = 4;
28843
+ const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
28801
28844
  let rootSlot = va.rootSlot;
28802
28845
 
28803
28846
  if (!va.rootSlotValid) {
@@ -28806,20 +28849,53 @@ var solanaWeb3 = (function (exports) {
28806
28849
 
28807
28850
  return new VoteAccount({
28808
28851
  nodePubkey: new PublicKey(va.nodePubkey),
28809
- authorizedVoterPubkey: new PublicKey(va.authorizedVoterPubkey),
28810
- authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
28852
+ authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
28811
28853
  commission: va.commission,
28812
28854
  votes: va.votes,
28813
28855
  rootSlot,
28814
- epoch: va.epoch,
28815
- credits: va.credits,
28816
- lastEpochCredits: va.lastEpochCredits,
28817
- epochCredits: va.epochCredits
28856
+ authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
28857
+ priorVoters: getPriorVoters(va.priorVoters),
28858
+ epochCredits: va.epochCredits,
28859
+ lastTimestamp: va.lastTimestamp
28818
28860
  });
28819
28861
  }
28820
28862
 
28821
28863
  }
28822
28864
 
28865
+ function parseAuthorizedVoter({
28866
+ epoch,
28867
+ authorizedVoter
28868
+ }) {
28869
+ return {
28870
+ epoch,
28871
+ authorizedVoter: new PublicKey(authorizedVoter)
28872
+ };
28873
+ }
28874
+
28875
+ function parsePriorVoters({
28876
+ authorizedPubkey,
28877
+ epochOfLastAuthorizedSwitch,
28878
+ targetEpoch
28879
+ }) {
28880
+ return {
28881
+ authorizedPubkey: new PublicKey(authorizedPubkey),
28882
+ epochOfLastAuthorizedSwitch,
28883
+ targetEpoch
28884
+ };
28885
+ }
28886
+
28887
+ function getPriorVoters({
28888
+ buf,
28889
+ idx,
28890
+ isEmpty
28891
+ }) {
28892
+ if (isEmpty) {
28893
+ return [];
28894
+ }
28895
+
28896
+ return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
28897
+ }
28898
+
28823
28899
  /**
28824
28900
  * Send and confirm a raw transaction
28825
28901
  *
@@ -28909,10 +28985,13 @@ var solanaWeb3 = (function (exports) {
28909
28985
  exports.STAKE_INSTRUCTION_LAYOUTS = STAKE_INSTRUCTION_LAYOUTS;
28910
28986
  exports.SYSTEM_INSTRUCTION_LAYOUTS = SYSTEM_INSTRUCTION_LAYOUTS;
28911
28987
  exports.SYSVAR_CLOCK_PUBKEY = SYSVAR_CLOCK_PUBKEY;
28988
+ exports.SYSVAR_EPOCH_SCHEDULE_PUBKEY = SYSVAR_EPOCH_SCHEDULE_PUBKEY;
28912
28989
  exports.SYSVAR_INSTRUCTIONS_PUBKEY = SYSVAR_INSTRUCTIONS_PUBKEY;
28913
28990
  exports.SYSVAR_RECENT_BLOCKHASHES_PUBKEY = SYSVAR_RECENT_BLOCKHASHES_PUBKEY;
28914
28991
  exports.SYSVAR_RENT_PUBKEY = SYSVAR_RENT_PUBKEY;
28915
28992
  exports.SYSVAR_REWARDS_PUBKEY = SYSVAR_REWARDS_PUBKEY;
28993
+ exports.SYSVAR_SLOT_HASHES_PUBKEY = SYSVAR_SLOT_HASHES_PUBKEY;
28994
+ exports.SYSVAR_SLOT_HISTORY_PUBKEY = SYSVAR_SLOT_HISTORY_PUBKEY;
28916
28995
  exports.SYSVAR_STAKE_HISTORY_PUBKEY = SYSVAR_STAKE_HISTORY_PUBKEY;
28917
28996
  exports.Secp256k1Program = Secp256k1Program;
28918
28997
  exports.SendTransactionError = SendTransactionError;