@solana/web3.js 1.32.2 → 1.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.iife.js CHANGED
@@ -13978,6 +13978,13 @@ var solanaWeb3 = (function (exports) {
13978
13978
  const lockup = (property = 'lockup') => {
13979
13979
  return struct([ns64('unixTimestamp'), ns64('epoch'), publicKey('custodian')], property);
13980
13980
  };
13981
+ /**
13982
+ * Layout for a VoteInit object
13983
+ */
13984
+
13985
+ const voteInit = (property = 'voteInit') => {
13986
+ return struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), u8('commission')], property);
13987
+ };
13981
13988
  function getAlloc(type, fields) {
13982
13989
  let alloc = 0;
13983
13990
  type.layout.fields.forEach(item => {
@@ -19844,13 +19851,13 @@ var solanaWeb3 = (function (exports) {
19844
19851
  const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
19845
19852
  err: nullable(union([type({}), string()])),
19846
19853
  logs: nullable(array(string())),
19847
- accounts: optional(nullable(array(type({
19854
+ accounts: optional(nullable(array(nullable(type({
19848
19855
  executable: boolean(),
19849
19856
  owner: string(),
19850
19857
  lamports: number(),
19851
19858
  data: array(string()),
19852
19859
  rentEpoch: optional(number())
19853
- })))),
19860
+ }))))),
19854
19861
  unitsConsumed: optional(number())
19855
19862
  }));
19856
19863
 
@@ -23749,30 +23756,22 @@ var solanaWeb3 = (function (exports) {
23749
23756
  });
23750
23757
  }
23751
23758
  /**
23752
- * Generate a Transaction that splits Stake tokens into another stake account
23759
+ * @internal
23753
23760
  */
23754
23761
 
23755
23762
 
23756
- static split(params) {
23763
+ static splitInstruction(params) {
23757
23764
  const {
23758
23765
  stakePubkey,
23759
23766
  authorizedPubkey,
23760
23767
  splitStakePubkey,
23761
23768
  lamports
23762
23769
  } = params;
23763
- const transaction = new Transaction();
23764
- transaction.add(SystemProgram.createAccount({
23765
- fromPubkey: authorizedPubkey,
23766
- newAccountPubkey: splitStakePubkey,
23767
- lamports: 0,
23768
- space: this.space,
23769
- programId: this.programId
23770
- }));
23771
23770
  const type = STAKE_INSTRUCTION_LAYOUTS.Split;
23772
23771
  const data = encodeData(type, {
23773
23772
  lamports
23774
23773
  });
23775
- return transaction.add({
23774
+ return new TransactionInstruction({
23776
23775
  keys: [{
23777
23776
  pubkey: stakePubkey,
23778
23777
  isSigner: false,
@@ -23790,6 +23789,52 @@ var solanaWeb3 = (function (exports) {
23790
23789
  data
23791
23790
  });
23792
23791
  }
23792
+ /**
23793
+ * Generate a Transaction that splits Stake tokens into another stake account
23794
+ */
23795
+
23796
+
23797
+ static split(params) {
23798
+ const transaction = new Transaction();
23799
+ transaction.add(SystemProgram.createAccount({
23800
+ fromPubkey: params.authorizedPubkey,
23801
+ newAccountPubkey: params.splitStakePubkey,
23802
+ lamports: 0,
23803
+ space: this.space,
23804
+ programId: this.programId
23805
+ }));
23806
+ return transaction.add(this.splitInstruction(params));
23807
+ }
23808
+ /**
23809
+ * Generate a Transaction that splits Stake tokens into another account
23810
+ * derived from a base public key and seed
23811
+ */
23812
+
23813
+
23814
+ static splitWithSeed(params) {
23815
+ const {
23816
+ stakePubkey,
23817
+ authorizedPubkey,
23818
+ splitStakePubkey,
23819
+ basePubkey,
23820
+ seed,
23821
+ lamports
23822
+ } = params;
23823
+ const transaction = new Transaction();
23824
+ transaction.add(SystemProgram.allocate({
23825
+ accountPubkey: splitStakePubkey,
23826
+ basePubkey,
23827
+ seed,
23828
+ space: this.space,
23829
+ programId: this.programId
23830
+ }));
23831
+ return transaction.add(this.splitInstruction({
23832
+ stakePubkey,
23833
+ authorizedPubkey,
23834
+ splitStakePubkey,
23835
+ lamports
23836
+ }));
23837
+ }
23793
23838
  /**
23794
23839
  * Generate a Transaction that merges Stake accounts.
23795
23840
  */
@@ -29082,6 +29127,322 @@ var solanaWeb3 = (function (exports) {
29082
29127
  return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
29083
29128
  }
29084
29129
 
29130
+ /**
29131
+ * Vote account info
29132
+ */
29133
+
29134
+ class VoteInit {
29135
+ /** [0, 100] */
29136
+ constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
29137
+ this.nodePubkey = void 0;
29138
+ this.authorizedVoter = void 0;
29139
+ this.authorizedWithdrawer = void 0;
29140
+ this.commission = void 0;
29141
+ this.nodePubkey = nodePubkey;
29142
+ this.authorizedVoter = authorizedVoter;
29143
+ this.authorizedWithdrawer = authorizedWithdrawer;
29144
+ this.commission = commission;
29145
+ }
29146
+
29147
+ }
29148
+ /**
29149
+ * Create vote account transaction params
29150
+ */
29151
+
29152
+ /**
29153
+ * Vote Instruction class
29154
+ */
29155
+ class VoteInstruction {
29156
+ /**
29157
+ * @internal
29158
+ */
29159
+ constructor() {}
29160
+ /**
29161
+ * Decode a vote instruction and retrieve the instruction type.
29162
+ */
29163
+
29164
+
29165
+ static decodeInstructionType(instruction) {
29166
+ this.checkProgramId(instruction.programId);
29167
+ const instructionTypeLayout = u32('instruction');
29168
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
29169
+ let type;
29170
+
29171
+ for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
29172
+ if (layout.index == typeIndex) {
29173
+ type = ixType;
29174
+ break;
29175
+ }
29176
+ }
29177
+
29178
+ if (!type) {
29179
+ throw new Error('Instruction type incorrect; not a VoteInstruction');
29180
+ }
29181
+
29182
+ return type;
29183
+ }
29184
+ /**
29185
+ * Decode an initialize vote instruction and retrieve the instruction params.
29186
+ */
29187
+
29188
+
29189
+ static decodeInitializeAccount(instruction) {
29190
+ this.checkProgramId(instruction.programId);
29191
+ this.checkKeyLength(instruction.keys, 4);
29192
+ const {
29193
+ voteInit
29194
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
29195
+ return {
29196
+ votePubkey: instruction.keys[0].pubkey,
29197
+ nodePubkey: instruction.keys[3].pubkey,
29198
+ voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
29199
+ };
29200
+ }
29201
+ /**
29202
+ * Decode an authorize instruction and retrieve the instruction params.
29203
+ */
29204
+
29205
+
29206
+ static decodeAuthorize(instruction) {
29207
+ this.checkProgramId(instruction.programId);
29208
+ this.checkKeyLength(instruction.keys, 3);
29209
+ const {
29210
+ newAuthorized,
29211
+ voteAuthorizationType
29212
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Authorize, instruction.data);
29213
+ return {
29214
+ votePubkey: instruction.keys[0].pubkey,
29215
+ authorizedPubkey: instruction.keys[2].pubkey,
29216
+ newAuthorizedPubkey: new PublicKey(newAuthorized),
29217
+ voteAuthorizationType: {
29218
+ index: voteAuthorizationType
29219
+ }
29220
+ };
29221
+ }
29222
+ /**
29223
+ * Decode a withdraw instruction and retrieve the instruction params.
29224
+ */
29225
+
29226
+
29227
+ static decodeWithdraw(instruction) {
29228
+ this.checkProgramId(instruction.programId);
29229
+ this.checkKeyLength(instruction.keys, 3);
29230
+ const {
29231
+ lamports
29232
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
29233
+ return {
29234
+ votePubkey: instruction.keys[0].pubkey,
29235
+ authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
29236
+ lamports,
29237
+ toPubkey: instruction.keys[1].pubkey
29238
+ };
29239
+ }
29240
+ /**
29241
+ * @internal
29242
+ */
29243
+
29244
+
29245
+ static checkProgramId(programId) {
29246
+ if (!programId.equals(VoteProgram.programId)) {
29247
+ throw new Error('invalid instruction; programId is not VoteProgram');
29248
+ }
29249
+ }
29250
+ /**
29251
+ * @internal
29252
+ */
29253
+
29254
+
29255
+ static checkKeyLength(keys, expectedLength) {
29256
+ if (keys.length < expectedLength) {
29257
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
29258
+ }
29259
+ }
29260
+
29261
+ }
29262
+ /**
29263
+ * An enumeration of valid VoteInstructionType's
29264
+ */
29265
+
29266
+ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
29267
+ InitializeAccount: {
29268
+ index: 0,
29269
+ layout: struct([u32('instruction'), voteInit()])
29270
+ },
29271
+ Authorize: {
29272
+ index: 1,
29273
+ layout: struct([u32('instruction'), publicKey('newAuthorized'), u32('voteAuthorizationType')])
29274
+ },
29275
+ Withdraw: {
29276
+ index: 3,
29277
+ layout: struct([u32('instruction'), ns64('lamports')])
29278
+ }
29279
+ });
29280
+ /**
29281
+ * VoteAuthorize type
29282
+ */
29283
+
29284
+ /**
29285
+ * An enumeration of valid VoteAuthorization layouts.
29286
+ */
29287
+ const VoteAuthorizationLayout = Object.freeze({
29288
+ Voter: {
29289
+ index: 0
29290
+ },
29291
+ Withdrawer: {
29292
+ index: 1
29293
+ }
29294
+ });
29295
+ /**
29296
+ * Factory class for transactions to interact with the Vote program
29297
+ */
29298
+
29299
+ class VoteProgram {
29300
+ /**
29301
+ * @internal
29302
+ */
29303
+ constructor() {}
29304
+ /**
29305
+ * Public key that identifies the Vote program
29306
+ */
29307
+
29308
+
29309
+ /**
29310
+ * Generate an Initialize instruction.
29311
+ */
29312
+ static initializeAccount(params) {
29313
+ const {
29314
+ votePubkey,
29315
+ nodePubkey,
29316
+ voteInit
29317
+ } = params;
29318
+ const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
29319
+ const data = encodeData(type, {
29320
+ voteInit: {
29321
+ nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
29322
+ authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
29323
+ authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
29324
+ commission: voteInit.commission
29325
+ }
29326
+ });
29327
+ const instructionData = {
29328
+ keys: [{
29329
+ pubkey: votePubkey,
29330
+ isSigner: false,
29331
+ isWritable: true
29332
+ }, {
29333
+ pubkey: SYSVAR_RENT_PUBKEY,
29334
+ isSigner: false,
29335
+ isWritable: false
29336
+ }, {
29337
+ pubkey: SYSVAR_CLOCK_PUBKEY,
29338
+ isSigner: false,
29339
+ isWritable: false
29340
+ }, {
29341
+ pubkey: nodePubkey,
29342
+ isSigner: true,
29343
+ isWritable: false
29344
+ }],
29345
+ programId: this.programId,
29346
+ data
29347
+ };
29348
+ return new TransactionInstruction(instructionData);
29349
+ }
29350
+ /**
29351
+ * Generate a transaction that creates a new Vote account.
29352
+ */
29353
+
29354
+
29355
+ static createAccount(params) {
29356
+ const transaction = new Transaction();
29357
+ transaction.add(SystemProgram.createAccount({
29358
+ fromPubkey: params.fromPubkey,
29359
+ newAccountPubkey: params.votePubkey,
29360
+ lamports: params.lamports,
29361
+ space: this.space,
29362
+ programId: this.programId
29363
+ }));
29364
+ return transaction.add(this.initializeAccount({
29365
+ votePubkey: params.votePubkey,
29366
+ nodePubkey: params.voteInit.nodePubkey,
29367
+ voteInit: params.voteInit
29368
+ }));
29369
+ }
29370
+ /**
29371
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
29372
+ */
29373
+
29374
+
29375
+ static authorize(params) {
29376
+ const {
29377
+ votePubkey,
29378
+ authorizedPubkey,
29379
+ newAuthorizedPubkey,
29380
+ voteAuthorizationType
29381
+ } = params;
29382
+ const type = VOTE_INSTRUCTION_LAYOUTS.Authorize;
29383
+ const data = encodeData(type, {
29384
+ newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
29385
+ voteAuthorizationType: voteAuthorizationType.index
29386
+ });
29387
+ const keys = [{
29388
+ pubkey: votePubkey,
29389
+ isSigner: false,
29390
+ isWritable: true
29391
+ }, {
29392
+ pubkey: SYSVAR_CLOCK_PUBKEY,
29393
+ isSigner: false,
29394
+ isWritable: false
29395
+ }, {
29396
+ pubkey: authorizedPubkey,
29397
+ isSigner: true,
29398
+ isWritable: false
29399
+ }];
29400
+ return new Transaction().add({
29401
+ keys,
29402
+ programId: this.programId,
29403
+ data
29404
+ });
29405
+ }
29406
+ /**
29407
+ * Generate a transaction to withdraw from a Vote account.
29408
+ */
29409
+
29410
+
29411
+ static withdraw(params) {
29412
+ const {
29413
+ votePubkey,
29414
+ authorizedWithdrawerPubkey,
29415
+ lamports,
29416
+ toPubkey
29417
+ } = params;
29418
+ const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
29419
+ const data = encodeData(type, {
29420
+ lamports
29421
+ });
29422
+ const keys = [{
29423
+ pubkey: votePubkey,
29424
+ isSigner: false,
29425
+ isWritable: true
29426
+ }, {
29427
+ pubkey: toPubkey,
29428
+ isSigner: false,
29429
+ isWritable: true
29430
+ }, {
29431
+ pubkey: authorizedWithdrawerPubkey,
29432
+ isSigner: true,
29433
+ isWritable: false
29434
+ }];
29435
+ return new Transaction().add({
29436
+ keys,
29437
+ programId: this.programId,
29438
+ data
29439
+ });
29440
+ }
29441
+
29442
+ }
29443
+ VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
29444
+ VoteProgram.space = 3731;
29445
+
29085
29446
  /**
29086
29447
  * Send and confirm a raw transaction
29087
29448
  *
@@ -29193,6 +29554,10 @@ var solanaWeb3 = (function (exports) {
29193
29554
  exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
29194
29555
  exports.ValidatorInfo = ValidatorInfo;
29195
29556
  exports.VoteAccount = VoteAccount;
29557
+ exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
29558
+ exports.VoteInit = VoteInit;
29559
+ exports.VoteInstruction = VoteInstruction;
29560
+ exports.VoteProgram = VoteProgram;
29196
29561
  exports.clusterApiUrl = clusterApiUrl;
29197
29562
  exports.sendAndConfirmRawTransaction = sendAndConfirmRawTransaction;
29198
29563
  exports.sendAndConfirmTransaction = sendAndConfirmTransaction;