@solana/web3.js 1.39.1 → 1.41.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
@@ -80,6 +80,14 @@ declare module '@solana/web3.js' {
80
80
  /**
81
81
  * Derive a program address from seeds and a program ID.
82
82
  */
83
+ static createProgramAddressSync(
84
+ seeds: Array<Buffer | Uint8Array>,
85
+ programId: PublicKey,
86
+ ): PublicKey;
87
+ /**
88
+ * Async version of createProgramAddressSync
89
+ * For backwards compatibility
90
+ */
83
91
  static createProgramAddress(
84
92
  seeds: Array<Buffer | Uint8Array>,
85
93
  programId: PublicKey,
@@ -91,6 +99,14 @@ declare module '@solana/web3.js' {
91
99
  * iterates a nonce until it finds one that when combined with the seeds
92
100
  * results in a valid program address.
93
101
  */
102
+ static findProgramAddressSync(
103
+ seeds: Array<Buffer | Uint8Array>,
104
+ programId: PublicKey,
105
+ ): [PublicKey, number];
106
+ /**
107
+ * Async version of findProgramAddressSync
108
+ * For backwards compatibility
109
+ */
94
110
  static findProgramAddress(
95
111
  seeds: Array<Buffer | Uint8Array>,
96
112
  programId: PublicKey,
@@ -98,7 +114,7 @@ declare module '@solana/web3.js' {
98
114
  /**
99
115
  * Check that a pubkey is on the ed25519 curve.
100
116
  */
101
- static isOnCurve(pubkey: Uint8Array): boolean;
117
+ static isOnCurve(pubkeyData: PublicKeyInitData): boolean;
102
118
  }
103
119
 
104
120
  /**
@@ -1807,6 +1823,14 @@ declare module '@solana/web3.js' {
1807
1823
  signatures: TransactionSignature[],
1808
1824
  commitment?: Finality,
1809
1825
  ): Promise<(ParsedConfirmedTransaction | null)[]>;
1826
+ /**
1827
+ * Fetch transaction details for a batch of confirmed transactions.
1828
+ * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
1829
+ */
1830
+ getTransactions(
1831
+ signatures: TransactionSignature[],
1832
+ commitment?: Finality,
1833
+ ): Promise<(TransactionResponse | null)[]>;
1810
1834
  /**
1811
1835
  * Fetch a list of Transactions and transaction statuses from the cluster
1812
1836
  * for a confirmed block.
@@ -2141,6 +2165,65 @@ declare module '@solana/web3.js' {
2141
2165
  ): Promise<boolean>;
2142
2166
  }
2143
2167
 
2168
+ /**
2169
+ * Compute Budget Instruction class
2170
+ */
2171
+ export class ComputeBudgetInstruction {
2172
+ /**
2173
+ * Decode a compute budget instruction and retrieve the instruction type.
2174
+ */
2175
+ static decodeInstructionType(
2176
+ instruction: TransactionInstruction,
2177
+ ): ComputeBudgetInstructionType;
2178
+ /**
2179
+ * Decode request units compute budget instruction and retrieve the instruction params.
2180
+ */
2181
+ static decodeRequestUnits(
2182
+ instruction: TransactionInstruction,
2183
+ ): RequestUnitsParams;
2184
+ /**
2185
+ * Decode request heap frame compute budget instruction and retrieve the instruction params.
2186
+ */
2187
+ static decodeRequestHeapFrame(
2188
+ instruction: TransactionInstruction,
2189
+ ): RequestHeapFrameParams;
2190
+ }
2191
+ /**
2192
+ * An enumeration of valid ComputeBudgetInstructionType's
2193
+ */
2194
+ export type ComputeBudgetInstructionType =
2195
+ | 'RequestUnits'
2196
+ | 'RequestHeapFrame';
2197
+ /**
2198
+ * Request units instruction params
2199
+ */
2200
+ interface RequestUnitsParams {
2201
+ /** Units to request for transaction-wide compute */
2202
+ units: number;
2203
+ /** Additional fee to pay */
2204
+ additionalFee: number;
2205
+ }
2206
+ /**
2207
+ * Request heap frame instruction params
2208
+ */
2209
+ export type RequestHeapFrameParams = {
2210
+ /** Requested transaction-wide program heap size in bytes. Must be multiple of 1024. Applies to each program, including CPIs. */
2211
+ bytes: number;
2212
+ };
2213
+ /**
2214
+ * Factory class for transaction instructions to interact with the Compute Budget program
2215
+ */
2216
+ export class ComputeBudgetProgram {
2217
+ /**
2218
+ * Public key that identifies the Compute Budget program
2219
+ */
2220
+ static programId: PublicKey;
2221
+ static requestUnits(params: RequestUnitsParams): TransactionInstruction;
2222
+ static requestHeapFrame(
2223
+ params: RequestHeapFrameParams,
2224
+ ): TransactionInstruction;
2225
+ }
2226
+
2144
2227
  /**
2145
2228
  * Params for creating an ed25519 instruction using a public key
2146
2229
  */
@@ -2460,8 +2543,8 @@ declare module '@solana/web3.js' {
2460
2543
  * Max space of a Stake account
2461
2544
  *
2462
2545
  * This is generated from the solana-stake-program StakeState struct as
2463
- * `std::mem::size_of::<StakeState>()`:
2464
- * https://docs.rs/solana-stake-program/1.4.4/solana_stake_program/stake_state/enum.StakeState.html
2546
+ * `StakeState::size_of()`:
2547
+ * https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.StakeState.html
2465
2548
  */
2466
2549
  static space: number;
2467
2550
  /**
package/lib/index.esm.js CHANGED
@@ -1902,7 +1902,7 @@ class PublicKey extends Struct {
1902
1902
  /* eslint-disable require-await */
1903
1903
 
1904
1904
 
1905
- static async createProgramAddress(seeds, programId) {
1905
+ static createProgramAddressSync(seeds, programId) {
1906
1906
  let buffer = Buffer.alloc(0);
1907
1907
  seeds.forEach(function (seed) {
1908
1908
  if (seed.length > MAX_SEED_LENGTH) {
@@ -1921,6 +1921,17 @@ class PublicKey extends Struct {
1921
1921
 
1922
1922
  return new PublicKey(publicKeyBytes);
1923
1923
  }
1924
+ /**
1925
+ * Async version of createProgramAddressSync
1926
+ * For backwards compatibility
1927
+ */
1928
+
1929
+ /* eslint-disable require-await */
1930
+
1931
+
1932
+ static async createProgramAddress(seeds, programId) {
1933
+ return this.createProgramAddressSync(seeds, programId);
1934
+ }
1924
1935
  /**
1925
1936
  * Find a valid program address
1926
1937
  *
@@ -1930,14 +1941,14 @@ class PublicKey extends Struct {
1930
1941
  */
1931
1942
 
1932
1943
 
1933
- static async findProgramAddress(seeds, programId) {
1944
+ static findProgramAddressSync(seeds, programId) {
1934
1945
  let nonce = 255;
1935
1946
  let address;
1936
1947
 
1937
1948
  while (nonce != 0) {
1938
1949
  try {
1939
1950
  const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
1940
- address = await this.createProgramAddress(seedsWithNonce, programId);
1951
+ address = this.createProgramAddressSync(seedsWithNonce, programId);
1941
1952
  } catch (err) {
1942
1953
  if (err instanceof TypeError) {
1943
1954
  throw err;
@@ -1952,13 +1963,23 @@ class PublicKey extends Struct {
1952
1963
 
1953
1964
  throw new Error(`Unable to find a viable program address nonce`);
1954
1965
  }
1966
+ /**
1967
+ * Async version of findProgramAddressSync
1968
+ * For backwards compatibility
1969
+ */
1970
+
1971
+
1972
+ static async findProgramAddress(seeds, programId) {
1973
+ return this.findProgramAddressSync(seeds, programId);
1974
+ }
1955
1975
  /**
1956
1976
  * Check that a pubkey is on the ed25519 curve.
1957
1977
  */
1958
1978
 
1959
1979
 
1960
- static isOnCurve(pubkey) {
1961
- return is_on_curve(pubkey) == 1;
1980
+ static isOnCurve(pubkeyData) {
1981
+ const pubkey = new PublicKey(pubkeyData);
1982
+ return is_on_curve(pubkey.toBytes()) == 1;
1962
1983
  }
1963
1984
 
1964
1985
  }
@@ -2445,13 +2466,11 @@ class Transaction {
2445
2466
  nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
2446
2467
  } : null,
2447
2468
  instructions: this.instructions.map(instruction => instruction.toJSON()),
2448
- signatures: this.signatures.map(({
2449
- publicKey,
2450
- signature
2451
- }) => ({
2452
- publicKey: publicKey.toJSON(),
2453
- signature: signature ? [...signature] : null
2454
- }))
2469
+ signers: this.signatures.map(({
2470
+ publicKey
2471
+ }) => {
2472
+ return publicKey.toJSON();
2473
+ })
2455
2474
  };
2456
2475
  }
2457
2476
  /**
@@ -2483,7 +2502,7 @@ class Transaction {
2483
2502
  compileMessage() {
2484
2503
  if (this._message) {
2485
2504
  if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
2486
- throw new Error('Transaction mutated after being populated from Message');
2505
+ throw new Error('Transaction message mutated after being populated from Message');
2487
2506
  }
2488
2507
 
2489
2508
  return this._message;
@@ -4062,6 +4081,136 @@ class BpfLoader {
4062
4081
 
4063
4082
  }
4064
4083
 
4084
+ /**
4085
+ * Compute Budget Instruction class
4086
+ */
4087
+
4088
+ class ComputeBudgetInstruction {
4089
+ /**
4090
+ * @internal
4091
+ */
4092
+ constructor() {}
4093
+ /**
4094
+ * Decode a compute budget instruction and retrieve the instruction type.
4095
+ */
4096
+
4097
+
4098
+ static decodeInstructionType(instruction) {
4099
+ this.checkProgramId(instruction.programId);
4100
+ const instructionTypeLayout = BufferLayout.u8('instruction');
4101
+ const typeIndex = instructionTypeLayout.decode(instruction.data);
4102
+ let type;
4103
+
4104
+ for (const [ixType, layout] of Object.entries(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS)) {
4105
+ if (layout.index == typeIndex) {
4106
+ type = ixType;
4107
+ break;
4108
+ }
4109
+ }
4110
+
4111
+ if (!type) {
4112
+ throw new Error('Instruction type incorrect; not a ComputeBudgetInstruction');
4113
+ }
4114
+
4115
+ return type;
4116
+ }
4117
+ /**
4118
+ * Decode request units compute budget instruction and retrieve the instruction params.
4119
+ */
4120
+
4121
+
4122
+ static decodeRequestUnits(instruction) {
4123
+ this.checkProgramId(instruction.programId);
4124
+ const {
4125
+ units,
4126
+ additionalFee
4127
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits, instruction.data);
4128
+ return {
4129
+ units,
4130
+ additionalFee
4131
+ };
4132
+ }
4133
+ /**
4134
+ * Decode request heap frame compute budget instruction and retrieve the instruction params.
4135
+ */
4136
+
4137
+
4138
+ static decodeRequestHeapFrame(instruction) {
4139
+ this.checkProgramId(instruction.programId);
4140
+ const {
4141
+ bytes
4142
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame, instruction.data);
4143
+ return {
4144
+ bytes
4145
+ };
4146
+ }
4147
+ /**
4148
+ * @internal
4149
+ */
4150
+
4151
+
4152
+ static checkProgramId(programId) {
4153
+ if (!programId.equals(ComputeBudgetProgram.programId)) {
4154
+ throw new Error('invalid instruction; programId is not ComputeBudgetProgram');
4155
+ }
4156
+ }
4157
+
4158
+ }
4159
+ /**
4160
+ * An enumeration of valid ComputeBudgetInstructionType's
4161
+ */
4162
+
4163
+ /**
4164
+ * An enumeration of valid ComputeBudget InstructionType's
4165
+ * @internal
4166
+ */
4167
+ const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
4168
+ RequestUnits: {
4169
+ index: 0,
4170
+ layout: BufferLayout.struct([BufferLayout.u8('instruction'), BufferLayout.u32('units'), BufferLayout.u32('additionalFee')])
4171
+ },
4172
+ RequestHeapFrame: {
4173
+ index: 1,
4174
+ layout: BufferLayout.struct([BufferLayout.u8('instruction'), BufferLayout.u32('bytes')])
4175
+ }
4176
+ });
4177
+ /**
4178
+ * Factory class for transaction instructions to interact with the Compute Budget program
4179
+ */
4180
+
4181
+ class ComputeBudgetProgram {
4182
+ /**
4183
+ * @internal
4184
+ */
4185
+ constructor() {}
4186
+ /**
4187
+ * Public key that identifies the Compute Budget program
4188
+ */
4189
+
4190
+
4191
+ static requestUnits(params) {
4192
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits;
4193
+ const data = encodeData(type, params);
4194
+ return new TransactionInstruction({
4195
+ keys: [],
4196
+ programId: this.programId,
4197
+ data
4198
+ });
4199
+ }
4200
+
4201
+ static requestHeapFrame(params) {
4202
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame;
4203
+ const data = encodeData(type, params);
4204
+ return new TransactionInstruction({
4205
+ keys: [],
4206
+ programId: this.programId,
4207
+ data
4208
+ });
4209
+ }
4210
+
4211
+ }
4212
+ ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
4213
+
4065
4214
  const DESTROY_TIMEOUT_MS = 5000;
4066
4215
  class AgentManager {
4067
4216
  static _newAgent(useHttps) {
@@ -5151,9 +5300,14 @@ const LogsNotificationResult = type({
5151
5300
  * Filter for log subscriptions.
5152
5301
  */
5153
5302
 
5303
+ function createSubscriptionWarningMessage(id, label) {
5304
+ return 'Ignored unsubscribe request because an active subscription ' + `with id \`${id}\` for '${label}' events could not be found.`;
5305
+ }
5154
5306
  /**
5155
5307
  * A connection to a fullnode JSON RPC endpoint
5156
5308
  */
5309
+
5310
+
5157
5311
  class Connection {
5158
5312
  /** @internal */
5159
5313
 
@@ -6353,6 +6507,33 @@ class Connection {
6353
6507
  });
6354
6508
  return res;
6355
6509
  }
6510
+ /**
6511
+ * Fetch transaction details for a batch of confirmed transactions.
6512
+ * Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
6513
+ */
6514
+
6515
+
6516
+ async getTransactions(signatures, commitment) {
6517
+ const batch = signatures.map(signature => {
6518
+ const args = this._buildArgsAtLeastConfirmed([signature], commitment);
6519
+
6520
+ return {
6521
+ methodName: 'getTransaction',
6522
+ args
6523
+ };
6524
+ });
6525
+ const unsafeRes = await this._rpcBatchRequest(batch);
6526
+ const res = unsafeRes.map(unsafeRes => {
6527
+ const res = create(unsafeRes, GetTransactionRpcResult);
6528
+
6529
+ if ('error' in res) {
6530
+ throw new Error('failed to get transactions: ' + res.error.message);
6531
+ }
6532
+
6533
+ return res.result;
6534
+ });
6535
+ return res;
6536
+ }
6356
6537
  /**
6357
6538
  * Fetch a list of Transactions and transaction statuses from the cluster
6358
6539
  * for a confirmed block.
@@ -7222,7 +7403,7 @@ class Connection {
7222
7403
 
7223
7404
  this._updateSubscriptions();
7224
7405
  } else {
7225
- throw new Error(`Unknown account change id: ${id}`);
7406
+ console.warn(createSubscriptionWarningMessage(id, 'account change'));
7226
7407
  }
7227
7408
  }
7228
7409
  /**
@@ -7288,7 +7469,7 @@ class Connection {
7288
7469
 
7289
7470
  this._updateSubscriptions();
7290
7471
  } else {
7291
- throw new Error(`Unknown program account change id: ${id}`);
7472
+ console.warn(createSubscriptionWarningMessage(id, 'program account change'));
7292
7473
  }
7293
7474
  }
7294
7475
  /**
@@ -7317,15 +7498,15 @@ class Connection {
7317
7498
 
7318
7499
 
7319
7500
  async removeOnLogsListener(id) {
7320
- if (!this._logsSubscriptions[id]) {
7321
- throw new Error(`Unknown logs id: ${id}`);
7322
- }
7323
-
7324
- const subInfo = this._logsSubscriptions[id];
7325
- delete this._logsSubscriptions[id];
7326
- await this._unsubscribe(subInfo, 'logsUnsubscribe');
7501
+ if (this._logsSubscriptions[id]) {
7502
+ const subInfo = this._logsSubscriptions[id];
7503
+ delete this._logsSubscriptions[id];
7504
+ await this._unsubscribe(subInfo, 'logsUnsubscribe');
7327
7505
 
7328
- this._updateSubscriptions();
7506
+ this._updateSubscriptions();
7507
+ } else {
7508
+ console.warn(createSubscriptionWarningMessage(id, 'logs'));
7509
+ }
7329
7510
  }
7330
7511
  /**
7331
7512
  * @internal
@@ -7394,7 +7575,7 @@ class Connection {
7394
7575
 
7395
7576
  this._updateSubscriptions();
7396
7577
  } else {
7397
- throw new Error(`Unknown slot change id: ${id}`);
7578
+ console.warn(createSubscriptionWarningMessage(id, 'slot change'));
7398
7579
  }
7399
7580
  }
7400
7581
  /**
@@ -7447,7 +7628,7 @@ class Connection {
7447
7628
 
7448
7629
  this._updateSubscriptions();
7449
7630
  } else {
7450
- throw new Error(`Unknown slot update id: ${id}`);
7631
+ console.warn(createSubscriptionWarningMessage(id, 'slot update'));
7451
7632
  }
7452
7633
  }
7453
7634
 
@@ -7588,7 +7769,7 @@ class Connection {
7588
7769
 
7589
7770
  this._updateSubscriptions();
7590
7771
  } else {
7591
- throw new Error(`Unknown signature result id: ${id}`);
7772
+ console.warn(createSubscriptionWarningMessage(id, 'signature result'));
7592
7773
  }
7593
7774
  }
7594
7775
  /**
@@ -7640,7 +7821,7 @@ class Connection {
7640
7821
 
7641
7822
  this._updateSubscriptions();
7642
7823
  } else {
7643
- throw new Error(`Unknown root change id: ${id}`);
7824
+ console.warn(createSubscriptionWarningMessage(id, 'root change'));
7644
7825
  }
7645
7826
  }
7646
7827
 
@@ -9321,5 +9502,5 @@ function clusterApiUrl(cluster, tls) {
9321
9502
 
9322
9503
  const LAMPORTS_PER_SOL = 1000000000;
9323
9504
 
9324
- 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, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9505
+ export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, 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, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
9325
9506
  //# sourceMappingURL=index.esm.js.map