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