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