@solana/web3.js 1.32.2 → 1.35.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/module.flow.js CHANGED
@@ -1027,7 +1027,7 @@ declare module "@solana/web3.js" {
1027
1027
  declare export type SimulatedTransactionResponse = {
1028
1028
  err: TransactionError | string | null,
1029
1029
  logs: Array<string> | null,
1030
- accounts?: SimulatedTransactionAccountInfo[] | null,
1030
+ accounts?: (SimulatedTransactionAccountInfo | null)[] | null,
1031
1031
  unitsConsumed?: number,
1032
1032
  ...
1033
1033
  };
@@ -3146,6 +3146,19 @@ lastValidBlockHeight: number,...
3146
3146
  ...
3147
3147
  };
3148
3148
 
3149
+ /**
3150
+ * Split with seed transaction params
3151
+ */
3152
+ declare export type SplitStakeWithSeedParams = {
3153
+ stakePubkey: PublicKey,
3154
+ authorizedPubkey: PublicKey,
3155
+ splitStakePubkey: PublicKey,
3156
+ basePubkey: PublicKey,
3157
+ seed: string,
3158
+ lamports: number,
3159
+ ...
3160
+ };
3161
+
3149
3162
  /**
3150
3163
  * Withdraw stake instruction params
3151
3164
  */
@@ -3340,6 +3353,12 @@ lastValidBlockHeight: number,...
3340
3353
  */
3341
3354
  static split(params: SplitStakeParams): Transaction;
3342
3355
 
3356
+ /**
3357
+ * Generate a Transaction that splits Stake tokens into another account
3358
+ * derived from a base public key and seed
3359
+ */
3360
+ static splitWithSeed(params: SplitStakeWithSeedParams): Transaction;
3361
+
3343
3362
  /**
3344
3363
  * Generate a Transaction that merges Stake accounts.
3345
3364
  */
@@ -4082,6 +4101,177 @@ lastValidBlockHeight: number,...
4082
4101
  buffer: Buffer | Uint8Array | Array<number>
4083
4102
  ): VoteAccount;
4084
4103
  }
4104
+
4105
+ /**
4106
+ * Vote account info
4107
+ */
4108
+ declare export class VoteInit {
4109
+ nodePubkey: PublicKey;
4110
+ authorizedVoter: PublicKey;
4111
+ authorizedWithdrawer: PublicKey;
4112
+ commission: number;
4113
+ constructor(
4114
+ nodePubkey: PublicKey,
4115
+ authorizedVoter: PublicKey,
4116
+ authorizedWithdrawer: PublicKey,
4117
+ commission: number
4118
+ ): this;
4119
+ }
4120
+
4121
+ /**
4122
+ * Create vote account transaction params
4123
+ */
4124
+ declare export type CreateVoteAccountParams = {
4125
+ fromPubkey: PublicKey,
4126
+ votePubkey: PublicKey,
4127
+ voteInit: VoteInit,
4128
+ lamports: number,
4129
+ ...
4130
+ };
4131
+
4132
+ /**
4133
+ * InitializeAccount instruction params
4134
+ */
4135
+ declare export type InitializeAccountParams = {
4136
+ votePubkey: PublicKey,
4137
+ nodePubkey: PublicKey,
4138
+ voteInit: VoteInit,
4139
+ ...
4140
+ };
4141
+
4142
+ /**
4143
+ * Authorize instruction params
4144
+ */
4145
+ declare export type AuthorizeVoteParams = {
4146
+ votePubkey: PublicKey,
4147
+
4148
+ /**
4149
+ * Current vote or withdraw authority, depending on `voteAuthorizationType`
4150
+ */
4151
+ authorizedPubkey: PublicKey,
4152
+ newAuthorizedPubkey: PublicKey,
4153
+ voteAuthorizationType: VoteAuthorizationType,
4154
+ ...
4155
+ };
4156
+
4157
+ /**
4158
+ * Withdraw from vote account transaction params
4159
+ */
4160
+ declare export type WithdrawFromVoteAccountParams = {
4161
+ votePubkey: PublicKey,
4162
+ authorizedWithdrawerPubkey: PublicKey,
4163
+ lamports: number,
4164
+ toPubkey: PublicKey,
4165
+ ...
4166
+ };
4167
+
4168
+ /**
4169
+ * Vote Instruction class
4170
+ */
4171
+ declare export class VoteInstruction {
4172
+ /**
4173
+ * Decode a vote instruction and retrieve the instruction type.
4174
+ */
4175
+ static decodeInstructionType(
4176
+ instruction: TransactionInstruction
4177
+ ): VoteInstructionType;
4178
+
4179
+ /**
4180
+ * Decode an initialize vote instruction and retrieve the instruction params.
4181
+ */
4182
+ static decodeInitializeAccount(
4183
+ instruction: TransactionInstruction
4184
+ ): InitializeAccountParams;
4185
+
4186
+ /**
4187
+ * Decode an authorize instruction and retrieve the instruction params.
4188
+ */
4189
+ static decodeAuthorize(
4190
+ instruction: TransactionInstruction
4191
+ ): AuthorizeVoteParams;
4192
+
4193
+ /**
4194
+ * Decode a withdraw instruction and retrieve the instruction params.
4195
+ */
4196
+ static decodeWithdraw(
4197
+ instruction: TransactionInstruction
4198
+ ): WithdrawFromVoteAccountParams;
4199
+ }
4200
+
4201
+ /**
4202
+ * An enumeration of valid VoteInstructionType's
4203
+ */
4204
+ declare export type VoteInstructionType =
4205
+ | "Authorize"
4206
+ | "InitializeAccount"
4207
+ | "Withdraw";
4208
+
4209
+ /**
4210
+ * VoteAuthorize type
4211
+ */
4212
+ declare export type VoteAuthorizationType = {
4213
+ /**
4214
+ * The VoteAuthorize index (from solana-vote-program)
4215
+ */
4216
+ index: number,
4217
+ ...
4218
+ };
4219
+
4220
+ /**
4221
+ * An enumeration of valid VoteAuthorization layouts.
4222
+ */
4223
+ declare export var VoteAuthorizationLayout: $ReadOnly<{
4224
+ Voter: {
4225
+ index: number,
4226
+ ...
4227
+ },
4228
+ Withdrawer: {
4229
+ index: number,
4230
+ ...
4231
+ },
4232
+ ...
4233
+ }>;
4234
+
4235
+ /**
4236
+ * Factory class for transactions to interact with the Vote program
4237
+ */
4238
+ declare export class VoteProgram {
4239
+ /**
4240
+ * Public key that identifies the Vote program
4241
+ */
4242
+ static programId: PublicKey;
4243
+
4244
+ /**
4245
+ * Max space of a Vote account
4246
+ *
4247
+ * This is generated from the solana-vote-program VoteState struct as
4248
+ * `VoteState::size_of()`:
4249
+ * https://docs.rs/solana-vote-program/1.9.5/solana_vote_program/vote_state/struct.VoteState.html#method.size_of
4250
+ */
4251
+ static space: number;
4252
+
4253
+ /**
4254
+ * Generate an Initialize instruction.
4255
+ */
4256
+ static initializeAccount(
4257
+ params: InitializeAccountParams
4258
+ ): TransactionInstruction;
4259
+
4260
+ /**
4261
+ * Generate a transaction that creates a new Vote account.
4262
+ */
4263
+ static createAccount(params: CreateVoteAccountParams): Transaction;
4264
+
4265
+ /**
4266
+ * Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account.
4267
+ */
4268
+ static authorize(params: AuthorizeVoteParams): Transaction;
4269
+
4270
+ /**
4271
+ * Generate a transaction to withdraw from a Vote account.
4272
+ */
4273
+ static withdraw(params: WithdrawFromVoteAccountParams): Transaction;
4274
+ }
4085
4275
  declare export var SYSVAR_CLOCK_PUBKEY: PublicKey;
4086
4276
  declare export var SYSVAR_EPOCH_SCHEDULE_PUBKEY: PublicKey;
4087
4277
  declare export var SYSVAR_INSTRUCTIONS_PUBKEY: PublicKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.32.2",
3
+ "version": "1.35.1",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
package/src/connection.ts CHANGED
@@ -469,7 +469,7 @@ export type SimulatedTransactionAccountInfo = {
469
469
  export type SimulatedTransactionResponse = {
470
470
  err: TransactionError | string | null;
471
471
  logs: Array<string> | null;
472
- accounts?: SimulatedTransactionAccountInfo[] | null;
472
+ accounts?: (SimulatedTransactionAccountInfo | null)[] | null;
473
473
  unitsConsumed?: number;
474
474
  };
475
475
 
@@ -480,13 +480,15 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(
480
480
  accounts: optional(
481
481
  nullable(
482
482
  array(
483
- pick({
484
- executable: boolean(),
485
- owner: string(),
486
- lamports: number(),
487
- data: array(string()),
488
- rentEpoch: optional(number()),
489
- }),
483
+ nullable(
484
+ pick({
485
+ executable: boolean(),
486
+ owner: string(),
487
+ lamports: number(),
488
+ data: array(string()),
489
+ rentEpoch: optional(number()),
490
+ }),
491
+ ),
490
492
  ),
491
493
  ),
492
494
  ),
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ export * from './secp256k1-program';
17
17
  export * from './transaction';
18
18
  export * from './validator-info';
19
19
  export * from './vote-account';
20
+ export * from './vote-program';
20
21
  export * from './sysvar';
21
22
  export * from './errors';
22
23
  export * from './util/borsh-schema';
package/src/layout.ts CHANGED
@@ -79,6 +79,21 @@ export const lockup = (property: string = 'lockup') => {
79
79
  );
80
80
  };
81
81
 
82
+ /**
83
+ * Layout for a VoteInit object
84
+ */
85
+ export const voteInit = (property: string = 'voteInit') => {
86
+ return BufferLayout.struct(
87
+ [
88
+ publicKey('nodePubkey'),
89
+ publicKey('authorizedVoter'),
90
+ publicKey('authorizedWithdrawer'),
91
+ BufferLayout.u8('commission'),
92
+ ],
93
+ property,
94
+ );
95
+ };
96
+
82
97
  export function getAlloc(type: any, fields: any): number {
83
98
  let alloc = 0;
84
99
  type.layout.fields.forEach((item: any) => {
@@ -147,6 +147,18 @@ export type SplitStakeParams = {
147
147
  lamports: number;
148
148
  };
149
149
 
150
+ /**
151
+ * Split with seed transaction params
152
+ */
153
+ export type SplitStakeWithSeedParams = {
154
+ stakePubkey: PublicKey;
155
+ authorizedPubkey: PublicKey;
156
+ splitStakePubkey: PublicKey;
157
+ basePubkey: PublicKey;
158
+ seed: string;
159
+ lamports: number;
160
+ };
161
+
150
162
  /**
151
163
  * Withdraw stake instruction params
152
164
  */
@@ -706,25 +718,13 @@ export class StakeProgram {
706
718
  }
707
719
 
708
720
  /**
709
- * Generate a Transaction that splits Stake tokens into another stake account
721
+ * @internal
710
722
  */
711
- static split(params: SplitStakeParams): Transaction {
723
+ static splitInstruction(params: SplitStakeParams): TransactionInstruction {
712
724
  const {stakePubkey, authorizedPubkey, splitStakePubkey, lamports} = params;
713
-
714
- const transaction = new Transaction();
715
- transaction.add(
716
- SystemProgram.createAccount({
717
- fromPubkey: authorizedPubkey,
718
- newAccountPubkey: splitStakePubkey,
719
- lamports: 0,
720
- space: this.space,
721
- programId: this.programId,
722
- }),
723
- );
724
725
  const type = STAKE_INSTRUCTION_LAYOUTS.Split;
725
726
  const data = encodeData(type, {lamports});
726
-
727
- return transaction.add({
727
+ return new TransactionInstruction({
728
728
  keys: [
729
729
  {pubkey: stakePubkey, isSigner: false, isWritable: true},
730
730
  {pubkey: splitStakePubkey, isSigner: false, isWritable: true},
@@ -735,6 +735,56 @@ export class StakeProgram {
735
735
  });
736
736
  }
737
737
 
738
+ /**
739
+ * Generate a Transaction that splits Stake tokens into another stake account
740
+ */
741
+ static split(params: SplitStakeParams): Transaction {
742
+ const transaction = new Transaction();
743
+ transaction.add(
744
+ SystemProgram.createAccount({
745
+ fromPubkey: params.authorizedPubkey,
746
+ newAccountPubkey: params.splitStakePubkey,
747
+ lamports: 0,
748
+ space: this.space,
749
+ programId: this.programId,
750
+ }),
751
+ );
752
+ return transaction.add(this.splitInstruction(params));
753
+ }
754
+
755
+ /**
756
+ * Generate a Transaction that splits Stake tokens into another account
757
+ * derived from a base public key and seed
758
+ */
759
+ static splitWithSeed(params: SplitStakeWithSeedParams): Transaction {
760
+ const {
761
+ stakePubkey,
762
+ authorizedPubkey,
763
+ splitStakePubkey,
764
+ basePubkey,
765
+ seed,
766
+ lamports,
767
+ } = params;
768
+ const transaction = new Transaction();
769
+ transaction.add(
770
+ SystemProgram.allocate({
771
+ accountPubkey: splitStakePubkey,
772
+ basePubkey,
773
+ seed,
774
+ space: this.space,
775
+ programId: this.programId,
776
+ }),
777
+ );
778
+ return transaction.add(
779
+ this.splitInstruction({
780
+ stakePubkey,
781
+ authorizedPubkey,
782
+ splitStakePubkey,
783
+ lamports,
784
+ }),
785
+ );
786
+ }
787
+
738
788
  /**
739
789
  * Generate a Transaction that merges Stake accounts.
740
790
  */