@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.d.ts CHANGED
@@ -2948,6 +2948,106 @@ declare module '@solana/web3.js' {
2948
2948
  ): VoteAccount;
2949
2949
  }
2950
2950
 
2951
+ /**
2952
+ * Vote account info
2953
+ */
2954
+ export class VoteInit {
2955
+ nodePubkey: PublicKey;
2956
+ authorizedVoter: PublicKey;
2957
+ authorizedWithdrawer: PublicKey;
2958
+ commission: number; /** [0, 100] */
2959
+ constructor(
2960
+ nodePubkey: PublicKey,
2961
+ authorizedVoter: PublicKey,
2962
+ authorizedWithdrawer: PublicKey,
2963
+ commission: number,
2964
+ );
2965
+ }
2966
+ /**
2967
+ * Create vote account transaction params
2968
+ */
2969
+ export type CreateVoteAccountParams = {
2970
+ fromPubkey: PublicKey;
2971
+ votePubkey: PublicKey;
2972
+ voteInit: VoteInit;
2973
+ lamports: number;
2974
+ };
2975
+ /**
2976
+ * InitializeAccount instruction params
2977
+ */
2978
+ export type InitializeAccountParams = {
2979
+ votePubkey: PublicKey;
2980
+ nodePubkey: PublicKey;
2981
+ voteInit: VoteInit;
2982
+ };
2983
+ /**
2984
+ * Withdraw from vote account transaction params
2985
+ */
2986
+ export type WithdrawFromVoteAccountParams = {
2987
+ votePubkey: PublicKey;
2988
+ authorizedWithdrawerPubkey: PublicKey;
2989
+ lamports: number;
2990
+ toPubkey: PublicKey;
2991
+ };
2992
+ /**
2993
+ * Vote Instruction class
2994
+ */
2995
+ export class VoteInstruction {
2996
+ /**
2997
+ * Decode a vote instruction and retrieve the instruction type.
2998
+ */
2999
+ static decodeInstructionType(
3000
+ instruction: TransactionInstruction,
3001
+ ): VoteInstructionType;
3002
+ /**
3003
+ * Decode an initialize vote instruction and retrieve the instruction params.
3004
+ */
3005
+ static decodeInitializeAccount(
3006
+ instruction: TransactionInstruction,
3007
+ ): InitializeAccountParams;
3008
+ /**
3009
+ * Decode a withdraw instruction and retrieve the instruction params.
3010
+ */
3011
+ static decodeWithdraw(
3012
+ instruction: TransactionInstruction,
3013
+ ): WithdrawFromVoteAccountParams;
3014
+ }
3015
+ /**
3016
+ * An enumeration of valid VoteInstructionType's
3017
+ */
3018
+ export type VoteInstructionType = 'InitializeAccount' | 'Withdraw';
3019
+ /**
3020
+ * Factory class for transactions to interact with the Vote program
3021
+ */
3022
+ export class VoteProgram {
3023
+ /**
3024
+ * Public key that identifies the Vote program
3025
+ */
3026
+ static programId: PublicKey;
3027
+ /**
3028
+ * Max space of a Vote account
3029
+ *
3030
+ * This is generated from the solana-vote-program VoteState struct as
3031
+ * `VoteState::size_of()`:
3032
+ * https://docs.rs/solana-vote-program/1.9.5/solana_vote_program/vote_state/struct.VoteState.html#method.size_of
3033
+ */
3034
+ static space: number;
3035
+ /**
3036
+ * Generate an Initialize instruction.
3037
+ */
3038
+ static initializeAccount(
3039
+ params: InitializeAccountParams,
3040
+ ): TransactionInstruction;
3041
+ /**
3042
+ * Generate a transaction that creates a new Vote account.
3043
+ */
3044
+ static createAccount(params: CreateVoteAccountParams): Transaction;
3045
+ /**
3046
+ * Generate a transaction to withdraw from a Vote account.
3047
+ */
3048
+ static withdraw(params: WithdrawFromVoteAccountParams): Transaction;
3049
+ }
3050
+
2951
3051
  export const SYSVAR_CLOCK_PUBKEY: PublicKey;
2952
3052
  export const SYSVAR_EPOCH_SCHEDULE_PUBKEY: PublicKey;
2953
3053
  export const SYSVAR_INSTRUCTIONS_PUBKEY: PublicKey;
package/lib/index.esm.js CHANGED
@@ -2075,6 +2075,13 @@ const authorized = (property = 'authorized') => {
2075
2075
  const lockup = (property = 'lockup') => {
2076
2076
  return BufferLayout.struct([BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('epoch'), publicKey('custodian')], property);
2077
2077
  };
2078
+ /**
2079
+ * Layout for a VoteInit object
2080
+ */
2081
+
2082
+ const voteInit = (property = 'voteInit') => {
2083
+ return BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission')], property);
2084
+ };
2078
2085
  function getAlloc(type, fields) {
2079
2086
  let alloc = 0;
2080
2087
  type.layout.fields.forEach(item => {
@@ -8722,6 +8729,246 @@ function getPriorVoters({
8722
8729
  return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8723
8730
  }
8724
8731
 
8732
+ /**
8733
+ * Vote account info
8734
+ */
8735
+
8736
+ class VoteInit {
8737
+ /** [0, 100] */
8738
+ constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
8739
+ this.nodePubkey = void 0;
8740
+ this.authorizedVoter = void 0;
8741
+ this.authorizedWithdrawer = void 0;
8742
+ this.commission = void 0;
8743
+ this.nodePubkey = nodePubkey;
8744
+ this.authorizedVoter = authorizedVoter;
8745
+ this.authorizedWithdrawer = authorizedWithdrawer;
8746
+ this.commission = commission;
8747
+ }
8748
+
8749
+ }
8750
+ /**
8751
+ * Create vote account transaction params
8752
+ */
8753
+
8754
+ /**
8755
+ * Vote Instruction class
8756
+ */
8757
+ class VoteInstruction {
8758
+ /**
8759
+ * @internal
8760
+ */
8761
+ constructor() {}
8762
+ /**
8763
+ * Decode a vote instruction and retrieve the instruction type.
8764
+ */
8765
+
8766
+
8767
+ static decodeInstructionType(instruction) {
8768
+ this.checkProgramId(instruction.programId);
8769
+ const instructionTypeLayout = BufferLayout.u32('instruction');
8770
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
8771
+ let type;
8772
+
8773
+ for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
8774
+ if (layout.index == typeIndex) {
8775
+ type = ixType;
8776
+ break;
8777
+ }
8778
+ }
8779
+
8780
+ if (!type) {
8781
+ throw new Error('Instruction type incorrect; not a VoteInstruction');
8782
+ }
8783
+
8784
+ return type;
8785
+ }
8786
+ /**
8787
+ * Decode an initialize vote instruction and retrieve the instruction params.
8788
+ */
8789
+
8790
+
8791
+ static decodeInitializeAccount(instruction) {
8792
+ this.checkProgramId(instruction.programId);
8793
+ this.checkKeyLength(instruction.keys, 4);
8794
+ const {
8795
+ voteInit
8796
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
8797
+ return {
8798
+ votePubkey: instruction.keys[0].pubkey,
8799
+ nodePubkey: instruction.keys[3].pubkey,
8800
+ voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
8801
+ };
8802
+ }
8803
+ /**
8804
+ * Decode a withdraw instruction and retrieve the instruction params.
8805
+ */
8806
+
8807
+
8808
+ static decodeWithdraw(instruction) {
8809
+ this.checkProgramId(instruction.programId);
8810
+ this.checkKeyLength(instruction.keys, 3);
8811
+ const {
8812
+ lamports
8813
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
8814
+ return {
8815
+ votePubkey: instruction.keys[0].pubkey,
8816
+ authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
8817
+ lamports,
8818
+ toPubkey: instruction.keys[1].pubkey
8819
+ };
8820
+ }
8821
+ /**
8822
+ * @internal
8823
+ */
8824
+
8825
+
8826
+ static checkProgramId(programId) {
8827
+ if (!programId.equals(VoteProgram.programId)) {
8828
+ throw new Error('invalid instruction; programId is not VoteProgram');
8829
+ }
8830
+ }
8831
+ /**
8832
+ * @internal
8833
+ */
8834
+
8835
+
8836
+ static checkKeyLength(keys, expectedLength) {
8837
+ if (keys.length < expectedLength) {
8838
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
8839
+ }
8840
+ }
8841
+
8842
+ }
8843
+ /**
8844
+ * An enumeration of valid VoteInstructionType's
8845
+ */
8846
+
8847
+ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
8848
+ InitializeAccount: {
8849
+ index: 0,
8850
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteInit()])
8851
+ },
8852
+ Withdraw: {
8853
+ index: 3,
8854
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
8855
+ }
8856
+ });
8857
+ /**
8858
+ * Factory class for transactions to interact with the Vote program
8859
+ */
8860
+
8861
+ class VoteProgram {
8862
+ /**
8863
+ * @internal
8864
+ */
8865
+ constructor() {}
8866
+ /**
8867
+ * Public key that identifies the Vote program
8868
+ */
8869
+
8870
+
8871
+ /**
8872
+ * Generate an Initialize instruction.
8873
+ */
8874
+ static initializeAccount(params) {
8875
+ const {
8876
+ votePubkey,
8877
+ nodePubkey,
8878
+ voteInit
8879
+ } = params;
8880
+ const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
8881
+ const data = encodeData(type, {
8882
+ voteInit: {
8883
+ nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
8884
+ authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
8885
+ authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
8886
+ commission: voteInit.commission
8887
+ }
8888
+ });
8889
+ const instructionData = {
8890
+ keys: [{
8891
+ pubkey: votePubkey,
8892
+ isSigner: false,
8893
+ isWritable: true
8894
+ }, {
8895
+ pubkey: SYSVAR_RENT_PUBKEY,
8896
+ isSigner: false,
8897
+ isWritable: false
8898
+ }, {
8899
+ pubkey: SYSVAR_CLOCK_PUBKEY,
8900
+ isSigner: false,
8901
+ isWritable: false
8902
+ }, {
8903
+ pubkey: nodePubkey,
8904
+ isSigner: true,
8905
+ isWritable: false
8906
+ }],
8907
+ programId: this.programId,
8908
+ data
8909
+ };
8910
+ return new TransactionInstruction(instructionData);
8911
+ }
8912
+ /**
8913
+ * Generate a transaction that creates a new Vote account.
8914
+ */
8915
+
8916
+
8917
+ static createAccount(params) {
8918
+ const transaction = new Transaction();
8919
+ transaction.add(SystemProgram.createAccount({
8920
+ fromPubkey: params.fromPubkey,
8921
+ newAccountPubkey: params.votePubkey,
8922
+ lamports: params.lamports,
8923
+ space: this.space,
8924
+ programId: this.programId
8925
+ }));
8926
+ return transaction.add(this.initializeAccount({
8927
+ votePubkey: params.votePubkey,
8928
+ nodePubkey: params.voteInit.nodePubkey,
8929
+ voteInit: params.voteInit
8930
+ }));
8931
+ }
8932
+ /**
8933
+ * Generate a transaction to withdraw from a Vote account.
8934
+ */
8935
+
8936
+
8937
+ static withdraw(params) {
8938
+ const {
8939
+ votePubkey,
8940
+ authorizedWithdrawerPubkey,
8941
+ lamports,
8942
+ toPubkey
8943
+ } = params;
8944
+ const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
8945
+ const data = encodeData(type, {
8946
+ lamports
8947
+ });
8948
+ const keys = [{
8949
+ pubkey: votePubkey,
8950
+ isSigner: false,
8951
+ isWritable: true
8952
+ }, {
8953
+ pubkey: toPubkey,
8954
+ isSigner: false,
8955
+ isWritable: true
8956
+ }, {
8957
+ pubkey: authorizedWithdrawerPubkey,
8958
+ isSigner: true,
8959
+ isWritable: false
8960
+ }];
8961
+ return new Transaction().add({
8962
+ keys,
8963
+ programId: this.programId,
8964
+ data
8965
+ });
8966
+ }
8967
+
8968
+ }
8969
+ VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
8970
+ VoteProgram.space = 3731;
8971
+
8725
8972
  /**
8726
8973
  * Send and confirm a raw transaction
8727
8974
  *
@@ -8785,5 +9032,5 @@ function clusterApiUrl(cluster, tls) {
8785
9032
 
8786
9033
  const LAMPORTS_PER_SOL = 1000000000;
8787
9034
 
8788
- 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 };
9035
+ 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 };
8789
9036
  //# sourceMappingURL=index.esm.js.map