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