@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.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 => {
@@ -8749,6 +8756,246 @@ function getPriorVoters({
8749
8756
  return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8750
8757
  }
8751
8758
 
8759
+ /**
8760
+ * Vote account info
8761
+ */
8762
+
8763
+ class VoteInit {
8764
+ /** [0, 100] */
8765
+ constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
8766
+ this.nodePubkey = void 0;
8767
+ this.authorizedVoter = void 0;
8768
+ this.authorizedWithdrawer = void 0;
8769
+ this.commission = void 0;
8770
+ this.nodePubkey = nodePubkey;
8771
+ this.authorizedVoter = authorizedVoter;
8772
+ this.authorizedWithdrawer = authorizedWithdrawer;
8773
+ this.commission = commission;
8774
+ }
8775
+
8776
+ }
8777
+ /**
8778
+ * Create vote account transaction params
8779
+ */
8780
+
8781
+ /**
8782
+ * Vote Instruction class
8783
+ */
8784
+ class VoteInstruction {
8785
+ /**
8786
+ * @internal
8787
+ */
8788
+ constructor() {}
8789
+ /**
8790
+ * Decode a vote instruction and retrieve the instruction type.
8791
+ */
8792
+
8793
+
8794
+ static decodeInstructionType(instruction) {
8795
+ this.checkProgramId(instruction.programId);
8796
+ const instructionTypeLayout = BufferLayout.u32('instruction');
8797
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
8798
+ let type;
8799
+
8800
+ for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
8801
+ if (layout.index == typeIndex) {
8802
+ type = ixType;
8803
+ break;
8804
+ }
8805
+ }
8806
+
8807
+ if (!type) {
8808
+ throw new Error('Instruction type incorrect; not a VoteInstruction');
8809
+ }
8810
+
8811
+ return type;
8812
+ }
8813
+ /**
8814
+ * Decode an initialize vote instruction and retrieve the instruction params.
8815
+ */
8816
+
8817
+
8818
+ static decodeInitializeAccount(instruction) {
8819
+ this.checkProgramId(instruction.programId);
8820
+ this.checkKeyLength(instruction.keys, 4);
8821
+ const {
8822
+ voteInit
8823
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
8824
+ return {
8825
+ votePubkey: instruction.keys[0].pubkey,
8826
+ nodePubkey: instruction.keys[3].pubkey,
8827
+ voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
8828
+ };
8829
+ }
8830
+ /**
8831
+ * Decode a withdraw instruction and retrieve the instruction params.
8832
+ */
8833
+
8834
+
8835
+ static decodeWithdraw(instruction) {
8836
+ this.checkProgramId(instruction.programId);
8837
+ this.checkKeyLength(instruction.keys, 3);
8838
+ const {
8839
+ lamports
8840
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
8841
+ return {
8842
+ votePubkey: instruction.keys[0].pubkey,
8843
+ authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
8844
+ lamports,
8845
+ toPubkey: instruction.keys[1].pubkey
8846
+ };
8847
+ }
8848
+ /**
8849
+ * @internal
8850
+ */
8851
+
8852
+
8853
+ static checkProgramId(programId) {
8854
+ if (!programId.equals(VoteProgram.programId)) {
8855
+ throw new Error('invalid instruction; programId is not VoteProgram');
8856
+ }
8857
+ }
8858
+ /**
8859
+ * @internal
8860
+ */
8861
+
8862
+
8863
+ static checkKeyLength(keys, expectedLength) {
8864
+ if (keys.length < expectedLength) {
8865
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
8866
+ }
8867
+ }
8868
+
8869
+ }
8870
+ /**
8871
+ * An enumeration of valid VoteInstructionType's
8872
+ */
8873
+
8874
+ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
8875
+ InitializeAccount: {
8876
+ index: 0,
8877
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), voteInit()])
8878
+ },
8879
+ Withdraw: {
8880
+ index: 3,
8881
+ layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
8882
+ }
8883
+ });
8884
+ /**
8885
+ * Factory class for transactions to interact with the Vote program
8886
+ */
8887
+
8888
+ class VoteProgram {
8889
+ /**
8890
+ * @internal
8891
+ */
8892
+ constructor() {}
8893
+ /**
8894
+ * Public key that identifies the Vote program
8895
+ */
8896
+
8897
+
8898
+ /**
8899
+ * Generate an Initialize instruction.
8900
+ */
8901
+ static initializeAccount(params) {
8902
+ const {
8903
+ votePubkey,
8904
+ nodePubkey,
8905
+ voteInit
8906
+ } = params;
8907
+ const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
8908
+ const data = encodeData(type, {
8909
+ voteInit: {
8910
+ nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
8911
+ authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
8912
+ authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
8913
+ commission: voteInit.commission
8914
+ }
8915
+ });
8916
+ const instructionData = {
8917
+ keys: [{
8918
+ pubkey: votePubkey,
8919
+ isSigner: false,
8920
+ isWritable: true
8921
+ }, {
8922
+ pubkey: SYSVAR_RENT_PUBKEY,
8923
+ isSigner: false,
8924
+ isWritable: false
8925
+ }, {
8926
+ pubkey: SYSVAR_CLOCK_PUBKEY,
8927
+ isSigner: false,
8928
+ isWritable: false
8929
+ }, {
8930
+ pubkey: nodePubkey,
8931
+ isSigner: true,
8932
+ isWritable: false
8933
+ }],
8934
+ programId: this.programId,
8935
+ data
8936
+ };
8937
+ return new TransactionInstruction(instructionData);
8938
+ }
8939
+ /**
8940
+ * Generate a transaction that creates a new Vote account.
8941
+ */
8942
+
8943
+
8944
+ static createAccount(params) {
8945
+ const transaction = new Transaction();
8946
+ transaction.add(SystemProgram.createAccount({
8947
+ fromPubkey: params.fromPubkey,
8948
+ newAccountPubkey: params.votePubkey,
8949
+ lamports: params.lamports,
8950
+ space: this.space,
8951
+ programId: this.programId
8952
+ }));
8953
+ return transaction.add(this.initializeAccount({
8954
+ votePubkey: params.votePubkey,
8955
+ nodePubkey: params.voteInit.nodePubkey,
8956
+ voteInit: params.voteInit
8957
+ }));
8958
+ }
8959
+ /**
8960
+ * Generate a transaction to withdraw from a Vote account.
8961
+ */
8962
+
8963
+
8964
+ static withdraw(params) {
8965
+ const {
8966
+ votePubkey,
8967
+ authorizedWithdrawerPubkey,
8968
+ lamports,
8969
+ toPubkey
8970
+ } = params;
8971
+ const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
8972
+ const data = encodeData(type, {
8973
+ lamports
8974
+ });
8975
+ const keys = [{
8976
+ pubkey: votePubkey,
8977
+ isSigner: false,
8978
+ isWritable: true
8979
+ }, {
8980
+ pubkey: toPubkey,
8981
+ isSigner: false,
8982
+ isWritable: true
8983
+ }, {
8984
+ pubkey: authorizedWithdrawerPubkey,
8985
+ isSigner: true,
8986
+ isWritable: false
8987
+ }];
8988
+ return new Transaction().add({
8989
+ keys,
8990
+ programId: this.programId,
8991
+ data
8992
+ });
8993
+ }
8994
+
8995
+ }
8996
+ VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
8997
+ VoteProgram.space = 3731;
8998
+
8752
8999
  /**
8753
9000
  * Send and confirm a raw transaction
8754
9001
  *
@@ -8812,5 +9059,5 @@ function clusterApiUrl(cluster, tls) {
8812
9059
 
8813
9060
  const LAMPORTS_PER_SOL = 1000000000;
8814
9061
 
8815
- 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 };
9062
+ 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 };
8816
9063
  //# sourceMappingURL=index.esm.js.map