@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.
@@ -2068,6 +2068,13 @@ const authorized = (property = 'authorized') => {
2068
2068
  const lockup = (property = 'lockup') => {
2069
2069
  return BufferLayout.struct([BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('epoch'), publicKey('custodian')], property);
2070
2070
  };
2071
+ /**
2072
+ * Layout for a VoteInit object
2073
+ */
2074
+
2075
+ const voteInit = (property = 'voteInit') => {
2076
+ return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
2077
+ };
2071
2078
  function getAlloc(type, fields) {
2072
2079
  let alloc = 0;
2073
2080
  type.layout.fields.forEach(item => {
@@ -9221,6 +9228,246 @@ function getPriorVoters({
9221
9228
  return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
9222
9229
  }
9223
9230
 
9231
+ /**
9232
+ * Vote account info
9233
+ */
9234
+
9235
+ class VoteInit {
9236
+ /** [0, 100] */
9237
+ constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
9238
+ this.nodePubkey = void 0;
9239
+ this.authorizedVoter = void 0;
9240
+ this.authorizedWithdrawer = void 0;
9241
+ this.commission = void 0;
9242
+ this.nodePubkey = nodePubkey;
9243
+ this.authorizedVoter = authorizedVoter;
9244
+ this.authorizedWithdrawer = authorizedWithdrawer;
9245
+ this.commission = commission;
9246
+ }
9247
+
9248
+ }
9249
+ /**
9250
+ * Create vote account transaction params
9251
+ */
9252
+
9253
+ /**
9254
+ * Vote Instruction class
9255
+ */
9256
+ class VoteInstruction {
9257
+ /**
9258
+ * @internal
9259
+ */
9260
+ constructor() {}
9261
+ /**
9262
+ * Decode a vote instruction and retrieve the instruction type.
9263
+ */
9264
+
9265
+
9266
+ static decodeInstructionType(instruction) {
9267
+ this.checkProgramId(instruction.programId);
9268
+ const instructionTypeLayout = BufferLayout.u32('instruction');
9269
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
9270
+ let type;
9271
+
9272
+ for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
9273
+ if (layout.index == typeIndex) {
9274
+ type = ixType;
9275
+ break;
9276
+ }
9277
+ }
9278
+
9279
+ if (!type) {
9280
+ throw new Error('Instruction type incorrect; not a VoteInstruction');
9281
+ }
9282
+
9283
+ return type;
9284
+ }
9285
+ /**
9286
+ * Decode an initialize vote instruction and retrieve the instruction params.
9287
+ */
9288
+
9289
+
9290
+ static decodeInitializeAccount(instruction) {
9291
+ this.checkProgramId(instruction.programId);
9292
+ this.checkKeyLength(instruction.keys, 4);
9293
+ const {
9294
+ voteInit
9295
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
9296
+ return {
9297
+ votePubkey: instruction.keys[0].pubkey,
9298
+ nodePubkey: instruction.keys[3].pubkey,
9299
+ voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
9300
+ };
9301
+ }
9302
+ /**
9303
+ * Decode a withdraw instruction and retrieve the instruction params.
9304
+ */
9305
+
9306
+
9307
+ static decodeWithdraw(instruction) {
9308
+ this.checkProgramId(instruction.programId);
9309
+ this.checkKeyLength(instruction.keys, 3);
9310
+ const {
9311
+ lamports
9312
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
9313
+ return {
9314
+ votePubkey: instruction.keys[0].pubkey,
9315
+ authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
9316
+ lamports,
9317
+ toPubkey: instruction.keys[1].pubkey
9318
+ };
9319
+ }
9320
+ /**
9321
+ * @internal
9322
+ */
9323
+
9324
+
9325
+ static checkProgramId(programId) {
9326
+ if (!programId.equals(VoteProgram.programId)) {
9327
+ throw new Error('invalid instruction; programId is not VoteProgram');
9328
+ }
9329
+ }
9330
+ /**
9331
+ * @internal
9332
+ */
9333
+
9334
+
9335
+ static checkKeyLength(keys, expectedLength) {
9336
+ if (keys.length < expectedLength) {
9337
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
9338
+ }
9339
+ }
9340
+
9341
+ }
9342
+ /**
9343
+ * An enumeration of valid VoteInstructionType's
9344
+ */
9345
+
9346
+ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
9347
+ InitializeAccount: {
9348
+ index: 0,
9349
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteInit()])
9350
+ },
9351
+ Withdraw: {
9352
+ index: 3,
9353
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
9354
+ }
9355
+ });
9356
+ /**
9357
+ * Factory class for transactions to interact with the Vote program
9358
+ */
9359
+
9360
+ class VoteProgram {
9361
+ /**
9362
+ * @internal
9363
+ */
9364
+ constructor() {}
9365
+ /**
9366
+ * Public key that identifies the Vote program
9367
+ */
9368
+
9369
+
9370
+ /**
9371
+ * Generate an Initialize instruction.
9372
+ */
9373
+ static initializeAccount(params) {
9374
+ const {
9375
+ votePubkey,
9376
+ nodePubkey,
9377
+ voteInit
9378
+ } = params;
9379
+ const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
9380
+ const data = encodeData(type, {
9381
+ voteInit: {
9382
+ nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
9383
+ authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
9384
+ authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
9385
+ commission: voteInit.commission
9386
+ }
9387
+ });
9388
+ const instructionData = {
9389
+ keys: [{
9390
+ pubkey: votePubkey,
9391
+ isSigner: false,
9392
+ isWritable: true
9393
+ }, {
9394
+ pubkey: SYSVAR_RENT_PUBKEY,
9395
+ isSigner: false,
9396
+ isWritable: false
9397
+ }, {
9398
+ pubkey: SYSVAR_CLOCK_PUBKEY,
9399
+ isSigner: false,
9400
+ isWritable: false
9401
+ }, {
9402
+ pubkey: nodePubkey,
9403
+ isSigner: true,
9404
+ isWritable: false
9405
+ }],
9406
+ programId: this.programId,
9407
+ data
9408
+ };
9409
+ return new TransactionInstruction(instructionData);
9410
+ }
9411
+ /**
9412
+ * Generate a transaction that creates a new Vote account.
9413
+ */
9414
+
9415
+
9416
+ static createAccount(params) {
9417
+ const transaction = new Transaction();
9418
+ transaction.add(SystemProgram.createAccount({
9419
+ fromPubkey: params.fromPubkey,
9420
+ newAccountPubkey: params.votePubkey,
9421
+ lamports: params.lamports,
9422
+ space: this.space,
9423
+ programId: this.programId
9424
+ }));
9425
+ return transaction.add(this.initializeAccount({
9426
+ votePubkey: params.votePubkey,
9427
+ nodePubkey: params.voteInit.nodePubkey,
9428
+ voteInit: params.voteInit
9429
+ }));
9430
+ }
9431
+ /**
9432
+ * Generate a transaction to withdraw from a Vote account.
9433
+ */
9434
+
9435
+
9436
+ static withdraw(params) {
9437
+ const {
9438
+ votePubkey,
9439
+ authorizedWithdrawerPubkey,
9440
+ lamports,
9441
+ toPubkey
9442
+ } = params;
9443
+ const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
9444
+ const data = encodeData(type, {
9445
+ lamports
9446
+ });
9447
+ const keys = [{
9448
+ pubkey: votePubkey,
9449
+ isSigner: false,
9450
+ isWritable: true
9451
+ }, {
9452
+ pubkey: toPubkey,
9453
+ isSigner: false,
9454
+ isWritable: true
9455
+ }, {
9456
+ pubkey: authorizedWithdrawerPubkey,
9457
+ isSigner: true,
9458
+ isWritable: false
9459
+ }];
9460
+ return new Transaction().add({
9461
+ keys,
9462
+ programId: this.programId,
9463
+ data
9464
+ });
9465
+ }
9466
+
9467
+ }
9468
+ VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
9469
+ VoteProgram.space = 3731;
9470
+
9224
9471
  /**
9225
9472
  * Send and confirm a raw transaction
9226
9473
  *
@@ -9284,5 +9531,5 @@ function clusterApiUrl(cluster, tls) {
9284
9531
 
9285
9532
  const LAMPORTS_PER_SOL = 1000000000;
9286
9533
 
9287
- 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 };
9534
+ 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, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9288
9535
  //# sourceMappingURL=index.browser.esm.js.map