@solana/web3.js 1.42.0 → 1.43.2

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
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  declare module '@solana/web3.js' {
3
3
  import {Buffer} from 'buffer';
4
- import crossFetch from 'cross-fetch';
4
+ import * as nodeFetch from 'node-fetch';
5
5
 
6
6
  export class Struct {
7
7
  constructor(properties: any);
@@ -179,6 +179,11 @@ declare module '@solana/web3.js' {
179
179
  getSlotsInEpoch(epoch: number): number;
180
180
  }
181
181
 
182
+ export function export_default(
183
+ input: nodeFetch.RequestInfo,
184
+ init?: nodeFetch.RequestInit,
185
+ ): Promise<nodeFetch.Response>;
186
+
182
187
  /**
183
188
  * Calculator for transaction fees.
184
189
  */
@@ -633,7 +638,7 @@ declare module '@solana/web3.js' {
633
638
  * A strategy for confirming transactions that uses the last valid
634
639
  * block height for a given blockhash to check for transaction expiration.
635
640
  */
636
- export type BlockheightBasedTransactionConfimationStrategy = {
641
+ export type BlockheightBasedTransactionConfirmationStrategy = {
637
642
  signature: TransactionSignature;
638
643
  } & BlockhashWithExpiryBlockHeight;
639
644
  /**
@@ -1444,13 +1449,17 @@ declare module '@solana/web3.js' {
1444
1449
  export type HttpHeaders = {
1445
1450
  [header: string]: string;
1446
1451
  };
1452
+ /**
1453
+ * The type of the JavaScript `fetch()` API
1454
+ */
1455
+ export type FetchFn = typeof export_default;
1447
1456
  /**
1448
1457
  * A callback used to augment the outgoing HTTP request
1449
1458
  */
1450
1459
  export type FetchMiddleware = (
1451
- url: string,
1452
- options: any,
1453
- fetch: (modifiedUrl: string, modifiedOptions: any) => void,
1460
+ info: Parameters<FetchFn>[0],
1461
+ init: Parameters<FetchFn>[1],
1462
+ fetch: (...a: Parameters<FetchFn>) => void,
1454
1463
  ) => void;
1455
1464
  /**
1456
1465
  * Configuration for instantiating a Connection
@@ -1463,7 +1472,7 @@ declare module '@solana/web3.js' {
1463
1472
  /** Optional HTTP headers object */
1464
1473
  httpHeaders?: HttpHeaders;
1465
1474
  /** Optional custom fetch function */
1466
- fetch?: typeof crossFetch;
1475
+ fetch?: FetchFn;
1467
1476
  /** Optional fetch middleware callback */
1468
1477
  fetchMiddleware?: FetchMiddleware;
1469
1478
  /** Optional Disable retrying calls when server responds with HTTP 429 (Too Many Requests) */
@@ -1659,7 +1668,7 @@ declare module '@solana/web3.js' {
1659
1668
  }>
1660
1669
  >;
1661
1670
  confirmTransaction(
1662
- strategy: BlockheightBasedTransactionConfimationStrategy,
1671
+ strategy: BlockheightBasedTransactionConfirmationStrategy,
1663
1672
  commitment?: Commitment,
1664
1673
  ): Promise<RpcResponseAndContext<SignatureResult>>;
1665
1674
  /** @deprecated Instead, call `confirmTransaction` using a `TransactionConfirmationConfig` */
@@ -2226,20 +2235,34 @@ declare module '@solana/web3.js' {
2226
2235
  static decodeRequestHeapFrame(
2227
2236
  instruction: TransactionInstruction,
2228
2237
  ): RequestHeapFrameParams;
2238
+ /**
2239
+ * Decode set compute unit limit compute budget instruction and retrieve the instruction params.
2240
+ */
2241
+ static decodeSetComputeUnitLimit(
2242
+ instruction: TransactionInstruction,
2243
+ ): SetComputeUnitLimitParams;
2244
+ /**
2245
+ * Decode set compute unit price compute budget instruction and retrieve the instruction params.
2246
+ */
2247
+ static decodeSetComputeUnitPrice(
2248
+ instruction: TransactionInstruction,
2249
+ ): SetComputeUnitPriceParams;
2229
2250
  }
2230
2251
  /**
2231
2252
  * An enumeration of valid ComputeBudgetInstructionType's
2232
2253
  */
2233
2254
  export type ComputeBudgetInstructionType =
2234
2255
  | 'RequestUnits'
2235
- | 'RequestHeapFrame';
2256
+ | 'RequestHeapFrame'
2257
+ | 'SetComputeUnitLimit'
2258
+ | 'SetComputeUnitPrice';
2236
2259
  /**
2237
2260
  * Request units instruction params
2238
2261
  */
2239
2262
  interface RequestUnitsParams {
2240
2263
  /** Units to request for transaction-wide compute */
2241
2264
  units: number;
2242
- /** Additional fee to pay */
2265
+ /** Prioritization fee lamports */
2243
2266
  additionalFee: number;
2244
2267
  }
2245
2268
  /**
@@ -2249,6 +2272,20 @@ declare module '@solana/web3.js' {
2249
2272
  /** Requested transaction-wide program heap size in bytes. Must be multiple of 1024. Applies to each program, including CPIs. */
2250
2273
  bytes: number;
2251
2274
  };
2275
+ /**
2276
+ * Set compute unit limit instruction params
2277
+ */
2278
+ interface SetComputeUnitLimitParams {
2279
+ /** Transaction-wide compute unit limit */
2280
+ units: number;
2281
+ }
2282
+ /**
2283
+ * Set compute unit price instruction params
2284
+ */
2285
+ interface SetComputeUnitPriceParams {
2286
+ /** Transaction compute unit price used for prioritization fees */
2287
+ microLamports: number | bigint;
2288
+ }
2252
2289
  /**
2253
2290
  * Factory class for transaction instructions to interact with the Compute Budget program
2254
2291
  */
@@ -2261,6 +2298,12 @@ declare module '@solana/web3.js' {
2261
2298
  static requestHeapFrame(
2262
2299
  params: RequestHeapFrameParams,
2263
2300
  ): TransactionInstruction;
2301
+ static setComputeUnitLimit(
2302
+ params: SetComputeUnitLimitParams,
2303
+ ): TransactionInstruction;
2304
+ static setComputeUnitPrice(
2305
+ params: SetComputeUnitPriceParams,
2306
+ ): TransactionInstruction;
2264
2307
  }
2265
2308
 
2266
2309
  /**
@@ -3352,14 +3395,14 @@ declare module '@solana/web3.js' {
3352
3395
  *
3353
3396
  * @param {Connection} connection
3354
3397
  * @param {Buffer} rawTransaction
3355
- * @param {BlockheightBasedTransactionConfimationStrategy} confirmationStrategy
3398
+ * @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
3356
3399
  * @param {ConfirmOptions} [options]
3357
3400
  * @returns {Promise<TransactionSignature>}
3358
3401
  */
3359
3402
  export function sendAndConfirmRawTransaction(
3360
3403
  connection: Connection,
3361
3404
  rawTransaction: Buffer,
3362
- confirmationStrategy: BlockheightBasedTransactionConfimationStrategy,
3405
+ confirmationStrategy: BlockheightBasedTransactionConfirmationStrategy,
3363
3406
  options?: ConfirmOptions,
3364
3407
  ): Promise<TransactionSignature>;
3365
3408
  /**
package/lib/index.esm.js CHANGED
@@ -4,13 +4,14 @@ import BN from 'bn.js';
4
4
  import bs58 from 'bs58';
5
5
  import { serialize, deserialize, deserializeUnchecked } from 'borsh';
6
6
  import * as BufferLayout from '@solana/buffer-layout';
7
- import { u64 } from '@solana/buffer-layout-utils';
8
- import crossFetch from 'cross-fetch';
7
+ import { blob } from '@solana/buffer-layout';
8
+ import { toBigIntLE, toBufferLE } from 'bigint-buffer';
9
9
  import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
10
10
  import { Client } from 'rpc-websockets';
11
11
  import RpcClient from 'jayson/lib/client/browser';
12
12
  import http from 'http';
13
13
  import https from 'https';
14
+ import * as nodeFetch from 'node-fetch';
14
15
  import secp256k1 from 'secp256k1';
15
16
  import sha3 from 'js-sha3';
16
17
 
@@ -44,43 +45,52 @@ var inherits$1 = {exports: {}};
44
45
 
45
46
  var inherits_browser = {exports: {}};
46
47
 
47
- if (typeof Object.create === 'function') {
48
- // implementation from standard node.js 'util' module
49
- inherits_browser.exports = function inherits(ctor, superCtor) {
50
- if (superCtor) {
51
- ctor.super_ = superCtor;
52
- ctor.prototype = Object.create(superCtor.prototype, {
53
- constructor: {
54
- value: ctor,
55
- enumerable: false,
56
- writable: true,
57
- configurable: true
58
- }
59
- });
60
- }
61
- };
62
- } else {
63
- // old school shim for old browsers
64
- inherits_browser.exports = function inherits(ctor, superCtor) {
65
- if (superCtor) {
66
- ctor.super_ = superCtor;
67
- var TempCtor = function () {};
68
- TempCtor.prototype = superCtor.prototype;
69
- ctor.prototype = new TempCtor();
70
- ctor.prototype.constructor = ctor;
71
- }
72
- };
48
+ var hasRequiredInherits_browser;
49
+
50
+ function requireInherits_browser () {
51
+ if (hasRequiredInherits_browser) return inherits_browser.exports;
52
+ hasRequiredInherits_browser = 1;
53
+ if (typeof Object.create === 'function') {
54
+ // implementation from standard node.js 'util' module
55
+ inherits_browser.exports = function inherits(ctor, superCtor) {
56
+ if (superCtor) {
57
+ ctor.super_ = superCtor;
58
+ ctor.prototype = Object.create(superCtor.prototype, {
59
+ constructor: {
60
+ value: ctor,
61
+ enumerable: false,
62
+ writable: true,
63
+ configurable: true
64
+ }
65
+ });
66
+ }
67
+ };
68
+ } else {
69
+ // old school shim for old browsers
70
+ inherits_browser.exports = function inherits(ctor, superCtor) {
71
+ if (superCtor) {
72
+ ctor.super_ = superCtor;
73
+ var TempCtor = function () {};
74
+ TempCtor.prototype = superCtor.prototype;
75
+ ctor.prototype = new TempCtor();
76
+ ctor.prototype.constructor = ctor;
77
+ }
78
+ };
79
+ }
80
+ return inherits_browser.exports;
73
81
  }
74
82
 
75
- try {
76
- var util = require('util');
77
- /* istanbul ignore next */
78
- if (typeof util.inherits !== 'function') throw '';
79
- inherits$1.exports = util.inherits;
80
- } catch (e) {
81
- /* istanbul ignore next */
82
- inherits$1.exports = inherits_browser.exports;
83
- }
83
+ (function (module) {
84
+ try {
85
+ var util = require('util');
86
+ /* istanbul ignore next */
87
+ if (typeof util.inherits !== 'function') throw '';
88
+ module.exports = util.inherits;
89
+ } catch (e) {
90
+ /* istanbul ignore next */
91
+ module.exports = requireInherits_browser();
92
+ }
93
+ } (inherits$1));
84
94
 
85
95
  var assert$5 = minimalisticAssert;
86
96
  var inherits = inherits$1.exports;
@@ -1272,22 +1282,22 @@ Hmac.prototype.digest = function digest(enc) {
1272
1282
  };
1273
1283
 
1274
1284
  (function (exports) {
1275
- var hash = exports;
1276
-
1277
- hash.utils = utils$9;
1278
- hash.common = common$5;
1279
- hash.sha = sha;
1280
- hash.ripemd = ripemd;
1281
- hash.hmac = hmac;
1282
-
1283
- // Proxy hash functions to the main object
1284
- hash.sha1 = hash.sha.sha1;
1285
- hash.sha256 = hash.sha.sha256;
1286
- hash.sha224 = hash.sha.sha224;
1287
- hash.sha384 = hash.sha.sha384;
1288
- hash.sha512 = hash.sha.sha512;
1289
- hash.ripemd160 = hash.ripemd.ripemd160;
1290
- }(hash$1));
1285
+ var hash = exports;
1286
+
1287
+ hash.utils = utils$9;
1288
+ hash.common = common$5;
1289
+ hash.sha = sha;
1290
+ hash.ripemd = ripemd;
1291
+ hash.hmac = hmac;
1292
+
1293
+ // Proxy hash functions to the main object
1294
+ hash.sha1 = hash.sha.sha1;
1295
+ hash.sha256 = hash.sha.sha256;
1296
+ hash.sha224 = hash.sha.sha224;
1297
+ hash.sha384 = hash.sha.sha384;
1298
+ hash.sha512 = hash.sha.sha512;
1299
+ hash.ripemd160 = hash.ripemd.ripemd160;
1300
+ } (hash$1));
1291
1301
 
1292
1302
  var hash = hash$1;
1293
1303
 
@@ -2805,8 +2815,6 @@ class Transaction {
2805
2815
  const message = this._compile();
2806
2816
 
2807
2817
  this._partialSign(message, ...uniqueSigners);
2808
-
2809
- this._verifySignatures(message.serialize(), true);
2810
2818
  }
2811
2819
  /**
2812
2820
  * Partially sign a transaction with the specified accounts. All accounts must
@@ -3186,6 +3194,38 @@ class NonceAccount {
3186
3194
 
3187
3195
  }
3188
3196
 
3197
+ const encodeDecode = layout => {
3198
+ const decode = layout.decode.bind(layout);
3199
+ const encode = layout.encode.bind(layout);
3200
+ return {
3201
+ decode,
3202
+ encode
3203
+ };
3204
+ };
3205
+
3206
+ const bigInt = length => property => {
3207
+ const layout = blob(length, property);
3208
+ const {
3209
+ encode,
3210
+ decode
3211
+ } = encodeDecode(layout);
3212
+ const bigIntLayout = layout;
3213
+
3214
+ bigIntLayout.decode = (buffer, offset) => {
3215
+ const src = decode(buffer, offset);
3216
+ return toBigIntLE(Buffer.from(src));
3217
+ };
3218
+
3219
+ bigIntLayout.encode = (bigInt, buffer, offset) => {
3220
+ const src = toBufferLE(bigInt, length);
3221
+ return encode(src, buffer, offset);
3222
+ };
3223
+
3224
+ return bigIntLayout;
3225
+ };
3226
+
3227
+ const u64 = bigInt(8);
3228
+
3189
3229
  /**
3190
3230
  * Create account system transaction params
3191
3231
  */
@@ -4164,6 +4204,34 @@ class ComputeBudgetInstruction {
4164
4204
  bytes
4165
4205
  };
4166
4206
  }
4207
+ /**
4208
+ * Decode set compute unit limit compute budget instruction and retrieve the instruction params.
4209
+ */
4210
+
4211
+
4212
+ static decodeSetComputeUnitLimit(instruction) {
4213
+ this.checkProgramId(instruction.programId);
4214
+ const {
4215
+ units
4216
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit, instruction.data);
4217
+ return {
4218
+ units
4219
+ };
4220
+ }
4221
+ /**
4222
+ * Decode set compute unit price compute budget instruction and retrieve the instruction params.
4223
+ */
4224
+
4225
+
4226
+ static decodeSetComputeUnitPrice(instruction) {
4227
+ this.checkProgramId(instruction.programId);
4228
+ const {
4229
+ microLamports
4230
+ } = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice, instruction.data);
4231
+ return {
4232
+ microLamports
4233
+ };
4234
+ }
4167
4235
  /**
4168
4236
  * @internal
4169
4237
  */
@@ -4192,6 +4260,14 @@ const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
4192
4260
  RequestHeapFrame: {
4193
4261
  index: 1,
4194
4262
  layout: BufferLayout.struct([BufferLayout.u8('instruction'), BufferLayout.u32('bytes')])
4263
+ },
4264
+ SetComputeUnitLimit: {
4265
+ index: 2,
4266
+ layout: BufferLayout.struct([BufferLayout.u8('instruction'), BufferLayout.u32('units')])
4267
+ },
4268
+ SetComputeUnitPrice: {
4269
+ index: 3,
4270
+ layout: BufferLayout.struct([BufferLayout.u8('instruction'), u64('microLamports')])
4195
4271
  }
4196
4272
  });
4197
4273
  /**
@@ -4228,6 +4304,28 @@ class ComputeBudgetProgram {
4228
4304
  });
4229
4305
  }
4230
4306
 
4307
+ static setComputeUnitLimit(params) {
4308
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit;
4309
+ const data = encodeData(type, params);
4310
+ return new TransactionInstruction({
4311
+ keys: [],
4312
+ programId: this.programId,
4313
+ data
4314
+ });
4315
+ }
4316
+
4317
+ static setComputeUnitPrice(params) {
4318
+ const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice;
4319
+ const data = encodeData(type, {
4320
+ microLamports: BigInt(params.microLamports)
4321
+ });
4322
+ return new TransactionInstruction({
4323
+ keys: [],
4324
+ programId: this.programId,
4325
+ data
4326
+ });
4327
+ }
4328
+
4231
4329
  }
4232
4330
  ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
4233
4331
 
@@ -4461,6 +4559,11 @@ class SendTransactionError extends Error {
4461
4559
 
4462
4560
  }
4463
4561
 
4562
+ async function fetchImpl (input, init) {
4563
+ const processedInput = typeof input === 'string' && input.slice(0, 2) === '//' ? 'https:' + input : input;
4564
+ return await nodeFetch.default(processedInput, init);
4565
+ }
4566
+
4464
4567
  // TODO: These constants should be removed in favor of reading them out of a
4465
4568
  // Syscall account
4466
4569
 
@@ -4710,7 +4813,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
4710
4813
  */
4711
4814
 
4712
4815
  function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
4713
- const fetch = customFetch ? customFetch : crossFetch;
4816
+ const fetch = customFetch ? customFetch : fetchImpl;
4714
4817
  let agentManager;
4715
4818
 
4716
4819
  {
@@ -4720,10 +4823,10 @@ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddlewar
4720
4823
  let fetchWithMiddleware;
4721
4824
 
4722
4825
  if (fetchMiddleware) {
4723
- fetchWithMiddleware = async (url, options) => {
4826
+ fetchWithMiddleware = async (info, init) => {
4724
4827
  const modifiedFetchArgs = await new Promise((resolve, reject) => {
4725
4828
  try {
4726
- fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
4829
+ fetchMiddleware(info, init, (modifiedInfo, modifiedInit) => resolve([modifiedInfo, modifiedInit]));
4727
4830
  } catch (error) {
4728
4831
  reject(error);
4729
4832
  }
@@ -9669,7 +9772,7 @@ VoteProgram.space = 3731;
9669
9772
  *
9670
9773
  * @param {Connection} connection
9671
9774
  * @param {Buffer} rawTransaction
9672
- * @param {BlockheightBasedTransactionConfimationStrategy} confirmationStrategy
9775
+ * @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
9673
9776
  * @param {ConfirmOptions} [options]
9674
9777
  * @returns {Promise<TransactionSignature>}
9675
9778
  */