@solana/web3.js 1.32.3 → 1.33.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 => {
@@ -29109,6 +29116,246 @@ var solanaWeb3 = (function (exports) {
29109
29116
  return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
29110
29117
  }
29111
29118
 
29119
+ /**
29120
+ * Vote account info
29121
+ */
29122
+
29123
+ class VoteInit {
29124
+ /** [0, 100] */
29125
+ constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
29126
+ this.nodePubkey = void 0;
29127
+ this.authorizedVoter = void 0;
29128
+ this.authorizedWithdrawer = void 0;
29129
+ this.commission = void 0;
29130
+ this.nodePubkey = nodePubkey;
29131
+ this.authorizedVoter = authorizedVoter;
29132
+ this.authorizedWithdrawer = authorizedWithdrawer;
29133
+ this.commission = commission;
29134
+ }
29135
+
29136
+ }
29137
+ /**
29138
+ * Create vote account transaction params
29139
+ */
29140
+
29141
+ /**
29142
+ * Vote Instruction class
29143
+ */
29144
+ class VoteInstruction {
29145
+ /**
29146
+ * @internal
29147
+ */
29148
+ constructor() {}
29149
+ /**
29150
+ * Decode a vote instruction and retrieve the instruction type.
29151
+ */
29152
+
29153
+
29154
+ static decodeInstructionType(instruction) {
29155
+ this.checkProgramId(instruction.programId);
29156
+ const instructionTypeLayout = u32('instruction');
29157
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
29158
+ let type;
29159
+
29160
+ for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
29161
+ if (layout.index == typeIndex) {
29162
+ type = ixType;
29163
+ break;
29164
+ }
29165
+ }
29166
+
29167
+ if (!type) {
29168
+ throw new Error('Instruction type incorrect; not a VoteInstruction');
29169
+ }
29170
+
29171
+ return type;
29172
+ }
29173
+ /**
29174
+ * Decode an initialize vote instruction and retrieve the instruction params.
29175
+ */
29176
+
29177
+
29178
+ static decodeInitializeAccount(instruction) {
29179
+ this.checkProgramId(instruction.programId);
29180
+ this.checkKeyLength(instruction.keys, 4);
29181
+ const {
29182
+ voteInit
29183
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
29184
+ return {
29185
+ votePubkey: instruction.keys[0].pubkey,
29186
+ nodePubkey: instruction.keys[3].pubkey,
29187
+ voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
29188
+ };
29189
+ }
29190
+ /**
29191
+ * Decode a withdraw instruction and retrieve the instruction params.
29192
+ */
29193
+
29194
+
29195
+ static decodeWithdraw(instruction) {
29196
+ this.checkProgramId(instruction.programId);
29197
+ this.checkKeyLength(instruction.keys, 3);
29198
+ const {
29199
+ lamports
29200
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
29201
+ return {
29202
+ votePubkey: instruction.keys[0].pubkey,
29203
+ authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
29204
+ lamports,
29205
+ toPubkey: instruction.keys[1].pubkey
29206
+ };
29207
+ }
29208
+ /**
29209
+ * @internal
29210
+ */
29211
+
29212
+
29213
+ static checkProgramId(programId) {
29214
+ if (!programId.equals(VoteProgram.programId)) {
29215
+ throw new Error('invalid instruction; programId is not VoteProgram');
29216
+ }
29217
+ }
29218
+ /**
29219
+ * @internal
29220
+ */
29221
+
29222
+
29223
+ static checkKeyLength(keys, expectedLength) {
29224
+ if (keys.length < expectedLength) {
29225
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
29226
+ }
29227
+ }
29228
+
29229
+ }
29230
+ /**
29231
+ * An enumeration of valid VoteInstructionType's
29232
+ */
29233
+
29234
+ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
29235
+ InitializeAccount: {
29236
+ index: 0,
29237
+ layout: struct([u32('instruction'), voteInit()])
29238
+ },
29239
+ Withdraw: {
29240
+ index: 3,
29241
+ layout: struct([u32('instruction'), ns64('lamports')])
29242
+ }
29243
+ });
29244
+ /**
29245
+ * Factory class for transactions to interact with the Vote program
29246
+ */
29247
+
29248
+ class VoteProgram {
29249
+ /**
29250
+ * @internal
29251
+ */
29252
+ constructor() {}
29253
+ /**
29254
+ * Public key that identifies the Vote program
29255
+ */
29256
+
29257
+
29258
+ /**
29259
+ * Generate an Initialize instruction.
29260
+ */
29261
+ static initializeAccount(params) {
29262
+ const {
29263
+ votePubkey,
29264
+ nodePubkey,
29265
+ voteInit
29266
+ } = params;
29267
+ const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
29268
+ const data = encodeData(type, {
29269
+ voteInit: {
29270
+ nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
29271
+ authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
29272
+ authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
29273
+ commission: voteInit.commission
29274
+ }
29275
+ });
29276
+ const instructionData = {
29277
+ keys: [{
29278
+ pubkey: votePubkey,
29279
+ isSigner: false,
29280
+ isWritable: true
29281
+ }, {
29282
+ pubkey: SYSVAR_RENT_PUBKEY,
29283
+ isSigner: false,
29284
+ isWritable: false
29285
+ }, {
29286
+ pubkey: SYSVAR_CLOCK_PUBKEY,
29287
+ isSigner: false,
29288
+ isWritable: false
29289
+ }, {
29290
+ pubkey: nodePubkey,
29291
+ isSigner: true,
29292
+ isWritable: false
29293
+ }],
29294
+ programId: this.programId,
29295
+ data
29296
+ };
29297
+ return new TransactionInstruction(instructionData);
29298
+ }
29299
+ /**
29300
+ * Generate a transaction that creates a new Vote account.
29301
+ */
29302
+
29303
+
29304
+ static createAccount(params) {
29305
+ const transaction = new Transaction();
29306
+ transaction.add(SystemProgram.createAccount({
29307
+ fromPubkey: params.fromPubkey,
29308
+ newAccountPubkey: params.votePubkey,
29309
+ lamports: params.lamports,
29310
+ space: this.space,
29311
+ programId: this.programId
29312
+ }));
29313
+ return transaction.add(this.initializeAccount({
29314
+ votePubkey: params.votePubkey,
29315
+ nodePubkey: params.voteInit.nodePubkey,
29316
+ voteInit: params.voteInit
29317
+ }));
29318
+ }
29319
+ /**
29320
+ * Generate a transaction to withdraw from a Vote account.
29321
+ */
29322
+
29323
+
29324
+ static withdraw(params) {
29325
+ const {
29326
+ votePubkey,
29327
+ authorizedWithdrawerPubkey,
29328
+ lamports,
29329
+ toPubkey
29330
+ } = params;
29331
+ const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
29332
+ const data = encodeData(type, {
29333
+ lamports
29334
+ });
29335
+ const keys = [{
29336
+ pubkey: votePubkey,
29337
+ isSigner: false,
29338
+ isWritable: true
29339
+ }, {
29340
+ pubkey: toPubkey,
29341
+ isSigner: false,
29342
+ isWritable: true
29343
+ }, {
29344
+ pubkey: authorizedWithdrawerPubkey,
29345
+ isSigner: true,
29346
+ isWritable: false
29347
+ }];
29348
+ return new Transaction().add({
29349
+ keys,
29350
+ programId: this.programId,
29351
+ data
29352
+ });
29353
+ }
29354
+
29355
+ }
29356
+ VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
29357
+ VoteProgram.space = 3731;
29358
+
29112
29359
  /**
29113
29360
  * Send and confirm a raw transaction
29114
29361
  *
@@ -29220,6 +29467,9 @@ var solanaWeb3 = (function (exports) {
29220
29467
  exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
29221
29468
  exports.ValidatorInfo = ValidatorInfo;
29222
29469
  exports.VoteAccount = VoteAccount;
29470
+ exports.VoteInit = VoteInit;
29471
+ exports.VoteInstruction = VoteInstruction;
29472
+ exports.VoteProgram = VoteProgram;
29223
29473
  exports.clusterApiUrl = clusterApiUrl;
29224
29474
  exports.sendAndConfirmRawTransaction = sendAndConfirmRawTransaction;
29225
29475
  exports.sendAndConfirmTransaction = sendAndConfirmTransaction;