@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.cjs.js CHANGED
@@ -2110,6 +2110,13 @@ const authorized = (property = 'authorized') => {
2110
2110
  const lockup = (property = 'lockup') => {
2111
2111
  return BufferLayout__namespace.struct([BufferLayout__namespace.ns64('unixTimestamp'), BufferLayout__namespace.ns64('epoch'), publicKey('custodian')], property);
2112
2112
  };
2113
+ /**
2114
+ * Layout for a VoteInit object
2115
+ */
2116
+
2117
+ const voteInit = (property = 'voteInit') => {
2118
+ return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
2119
+ };
2113
2120
  function getAlloc(type, fields) {
2114
2121
  let alloc = 0;
2115
2122
  type.layout.fields.forEach(item => {
@@ -8784,6 +8791,246 @@ function getPriorVoters({
8784
8791
  return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
8785
8792
  }
8786
8793
 
8794
+ /**
8795
+ * Vote account info
8796
+ */
8797
+
8798
+ class VoteInit {
8799
+ /** [0, 100] */
8800
+ constructor(nodePubkey, authorizedVoter, authorizedWithdrawer, commission) {
8801
+ this.nodePubkey = void 0;
8802
+ this.authorizedVoter = void 0;
8803
+ this.authorizedWithdrawer = void 0;
8804
+ this.commission = void 0;
8805
+ this.nodePubkey = nodePubkey;
8806
+ this.authorizedVoter = authorizedVoter;
8807
+ this.authorizedWithdrawer = authorizedWithdrawer;
8808
+ this.commission = commission;
8809
+ }
8810
+
8811
+ }
8812
+ /**
8813
+ * Create vote account transaction params
8814
+ */
8815
+
8816
+ /**
8817
+ * Vote Instruction class
8818
+ */
8819
+ class VoteInstruction {
8820
+ /**
8821
+ * @internal
8822
+ */
8823
+ constructor() {}
8824
+ /**
8825
+ * Decode a vote instruction and retrieve the instruction type.
8826
+ */
8827
+
8828
+
8829
+ static decodeInstructionType(instruction) {
8830
+ this.checkProgramId(instruction.programId);
8831
+ const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
8832
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
8833
+ let type;
8834
+
8835
+ for (const [ixType, layout] of Object.entries(VOTE_INSTRUCTION_LAYOUTS)) {
8836
+ if (layout.index == typeIndex) {
8837
+ type = ixType;
8838
+ break;
8839
+ }
8840
+ }
8841
+
8842
+ if (!type) {
8843
+ throw new Error('Instruction type incorrect; not a VoteInstruction');
8844
+ }
8845
+
8846
+ return type;
8847
+ }
8848
+ /**
8849
+ * Decode an initialize vote instruction and retrieve the instruction params.
8850
+ */
8851
+
8852
+
8853
+ static decodeInitializeAccount(instruction) {
8854
+ this.checkProgramId(instruction.programId);
8855
+ this.checkKeyLength(instruction.keys, 4);
8856
+ const {
8857
+ voteInit
8858
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.InitializeAccount, instruction.data);
8859
+ return {
8860
+ votePubkey: instruction.keys[0].pubkey,
8861
+ nodePubkey: instruction.keys[3].pubkey,
8862
+ voteInit: new VoteInit(new PublicKey(voteInit.nodePubkey), new PublicKey(voteInit.authorizedVoter), new PublicKey(voteInit.authorizedWithdrawer), voteInit.commission)
8863
+ };
8864
+ }
8865
+ /**
8866
+ * Decode a withdraw instruction and retrieve the instruction params.
8867
+ */
8868
+
8869
+
8870
+ static decodeWithdraw(instruction) {
8871
+ this.checkProgramId(instruction.programId);
8872
+ this.checkKeyLength(instruction.keys, 3);
8873
+ const {
8874
+ lamports
8875
+ } = decodeData(VOTE_INSTRUCTION_LAYOUTS.Withdraw, instruction.data);
8876
+ return {
8877
+ votePubkey: instruction.keys[0].pubkey,
8878
+ authorizedWithdrawerPubkey: instruction.keys[2].pubkey,
8879
+ lamports,
8880
+ toPubkey: instruction.keys[1].pubkey
8881
+ };
8882
+ }
8883
+ /**
8884
+ * @internal
8885
+ */
8886
+
8887
+
8888
+ static checkProgramId(programId) {
8889
+ if (!programId.equals(VoteProgram.programId)) {
8890
+ throw new Error('invalid instruction; programId is not VoteProgram');
8891
+ }
8892
+ }
8893
+ /**
8894
+ * @internal
8895
+ */
8896
+
8897
+
8898
+ static checkKeyLength(keys, expectedLength) {
8899
+ if (keys.length < expectedLength) {
8900
+ throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
8901
+ }
8902
+ }
8903
+
8904
+ }
8905
+ /**
8906
+ * An enumeration of valid VoteInstructionType's
8907
+ */
8908
+
8909
+ const VOTE_INSTRUCTION_LAYOUTS = Object.freeze({
8910
+ InitializeAccount: {
8911
+ index: 0,
8912
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), voteInit()])
8913
+ },
8914
+ Withdraw: {
8915
+ index: 3,
8916
+ layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), BufferLayout__namespace.ns64('lamports')])
8917
+ }
8918
+ });
8919
+ /**
8920
+ * Factory class for transactions to interact with the Vote program
8921
+ */
8922
+
8923
+ class VoteProgram {
8924
+ /**
8925
+ * @internal
8926
+ */
8927
+ constructor() {}
8928
+ /**
8929
+ * Public key that identifies the Vote program
8930
+ */
8931
+
8932
+
8933
+ /**
8934
+ * Generate an Initialize instruction.
8935
+ */
8936
+ static initializeAccount(params) {
8937
+ const {
8938
+ votePubkey,
8939
+ nodePubkey,
8940
+ voteInit
8941
+ } = params;
8942
+ const type = VOTE_INSTRUCTION_LAYOUTS.InitializeAccount;
8943
+ const data = encodeData(type, {
8944
+ voteInit: {
8945
+ nodePubkey: toBuffer(voteInit.nodePubkey.toBuffer()),
8946
+ authorizedVoter: toBuffer(voteInit.authorizedVoter.toBuffer()),
8947
+ authorizedWithdrawer: toBuffer(voteInit.authorizedWithdrawer.toBuffer()),
8948
+ commission: voteInit.commission
8949
+ }
8950
+ });
8951
+ const instructionData = {
8952
+ keys: [{
8953
+ pubkey: votePubkey,
8954
+ isSigner: false,
8955
+ isWritable: true
8956
+ }, {
8957
+ pubkey: SYSVAR_RENT_PUBKEY,
8958
+ isSigner: false,
8959
+ isWritable: false
8960
+ }, {
8961
+ pubkey: SYSVAR_CLOCK_PUBKEY,
8962
+ isSigner: false,
8963
+ isWritable: false
8964
+ }, {
8965
+ pubkey: nodePubkey,
8966
+ isSigner: true,
8967
+ isWritable: false
8968
+ }],
8969
+ programId: this.programId,
8970
+ data
8971
+ };
8972
+ return new TransactionInstruction(instructionData);
8973
+ }
8974
+ /**
8975
+ * Generate a transaction that creates a new Vote account.
8976
+ */
8977
+
8978
+
8979
+ static createAccount(params) {
8980
+ const transaction = new Transaction();
8981
+ transaction.add(SystemProgram.createAccount({
8982
+ fromPubkey: params.fromPubkey,
8983
+ newAccountPubkey: params.votePubkey,
8984
+ lamports: params.lamports,
8985
+ space: this.space,
8986
+ programId: this.programId
8987
+ }));
8988
+ return transaction.add(this.initializeAccount({
8989
+ votePubkey: params.votePubkey,
8990
+ nodePubkey: params.voteInit.nodePubkey,
8991
+ voteInit: params.voteInit
8992
+ }));
8993
+ }
8994
+ /**
8995
+ * Generate a transaction to withdraw from a Vote account.
8996
+ */
8997
+
8998
+
8999
+ static withdraw(params) {
9000
+ const {
9001
+ votePubkey,
9002
+ authorizedWithdrawerPubkey,
9003
+ lamports,
9004
+ toPubkey
9005
+ } = params;
9006
+ const type = VOTE_INSTRUCTION_LAYOUTS.Withdraw;
9007
+ const data = encodeData(type, {
9008
+ lamports
9009
+ });
9010
+ const keys = [{
9011
+ pubkey: votePubkey,
9012
+ isSigner: false,
9013
+ isWritable: true
9014
+ }, {
9015
+ pubkey: toPubkey,
9016
+ isSigner: false,
9017
+ isWritable: true
9018
+ }, {
9019
+ pubkey: authorizedWithdrawerPubkey,
9020
+ isSigner: true,
9021
+ isWritable: false
9022
+ }];
9023
+ return new Transaction().add({
9024
+ keys,
9025
+ programId: this.programId,
9026
+ data
9027
+ });
9028
+ }
9029
+
9030
+ }
9031
+ VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
9032
+ VoteProgram.space = 3731;
9033
+
8787
9034
  /**
8788
9035
  * Send and confirm a raw transaction
8789
9036
  *
@@ -8895,6 +9142,9 @@ exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
8895
9142
  exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
8896
9143
  exports.ValidatorInfo = ValidatorInfo;
8897
9144
  exports.VoteAccount = VoteAccount;
9145
+ exports.VoteInit = VoteInit;
9146
+ exports.VoteInstruction = VoteInstruction;
9147
+ exports.VoteProgram = VoteProgram;
8898
9148
  exports.clusterApiUrl = clusterApiUrl;
8899
9149
  exports.sendAndConfirmRawTransaction = sendAndConfirmRawTransaction;
8900
9150
  exports.sendAndConfirmTransaction = sendAndConfirmTransaction;