@hawksightco/hawk-sdk 1.3.276 → 1.3.277

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.
@@ -1,6 +1,12 @@
1
1
  import * as web3 from "@solana/web3.js";
2
2
  import { TransactionMetadata, TransactionMetadataWithActions, TransactionMetadataResponse, TransactionMetadataResponse2 } from "../types";
3
3
  import { GeneralUtility } from "./GeneralUtility";
4
+ /**
5
+ * Where the blockhash baked into a transaction at construction time comes from.
6
+ * Either a value or a function producing one, mirroring how callers hand a blockhash
7
+ * to `addPriorityFeeIx`.
8
+ */
9
+ export type ConstructionBlockhashSource = web3.BlockhashWithExpiryBlockHeight | (() => Promise<web3.BlockhashWithExpiryBlockHeight> | web3.BlockhashWithExpiryBlockHeight);
4
10
  /**
5
11
  * The CreateTxMetadata class is responsible for creating and managing transaction metadata,
6
12
  * including handling address lookup tables and constructing transactions with the necessary parameters.
@@ -8,12 +14,34 @@ import { GeneralUtility } from "./GeneralUtility";
8
14
  export declare class CreateTxMetadata {
9
15
  private constructor();
10
16
  private connection?;
17
+ /**
18
+ * A blockhash that is valid to compile against but not to land against. Callers that
19
+ * have proven every path overwrites the construction blockhash before signing can hand
20
+ * this over and save one foreground getLatestBlockhash per transaction built (H-2582).
21
+ * Same value `toVersionedTransaction` and `Transaction.simulateTransaction` compile with.
22
+ */
23
+ static readonly PLACEHOLDER_BLOCKHASH: web3.BlockhashWithExpiryBlockHeight;
24
+ private constructionBlockhash?;
11
25
  /**
12
26
  * Sets the connection to the Solana blockchain.
13
27
  *
14
28
  * @param connection - The Solana blockchain connection object.
15
29
  */
16
30
  setConnection(connection: web3.Connection): void;
31
+ /**
32
+ * Overrides where the blockhash baked in at construction comes from. Left unset (the
33
+ * default) one is fetched per transaction built, which every transaction the SDK builds
34
+ * needs since `Transaction`'s constructor compiles a versioned transaction.
35
+ *
36
+ * @param source - A blockhash, a function producing one, or undefined to fetch.
37
+ */
38
+ setConstructionBlockhash(source?: ConstructionBlockhashSource): void;
39
+ /**
40
+ * Resolves the blockhash to construct a transaction with.
41
+ *
42
+ * @param connection - The Solana blockchain connection object, used only when no source is set.
43
+ */
44
+ private resolveConstructionBlockhash;
17
45
  private static _instance;
18
46
  /**
19
47
  * Gets the singleton instance of the CreateTxMetadata class.
@@ -1 +1 @@
1
- {"version":3,"file":"CreateTxMetadata.d.ts","sourceRoot":"","sources":["../../src/classes/CreateTxMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,8BAA8B,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAE1I,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD;;;GAGG;AACH,qBAAa,gBAAgB;IAE3B,OAAO;IAEP,OAAO,CAAC,UAAU,CAAC,CAAkB;IAErC;;;;OAIG;IACH,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU;IAEzC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAmB;IAE3C;;;;OAIG;IACH,MAAM,CAAC,QAAQ,IAAI,gBAAgB;IAOnC,OAAO,CAAC,IAAI,CAaV;IAEF;;OAEG;IACG,IAAI;IAIV;;OAEG;IACG,UAAU;IAUhB;;;;;;;OAOG;IACG,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC;IAcvG;;;;;OAKG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAIzE;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,yBAAyB;IAI7D;;;;;;OAMG;IACG,WAAW,CACf,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC,I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UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,mBAAmB,EAAE,CAAC;CA0ElC"}
@@ -75,6 +75,31 @@ class CreateTxMetadata {
75
75
  * @param connection - The Solana blockchain connection object.
76
76
  */
77
77
  setConnection(connection) { this.connection = connection; }
78
+ /**
79
+ * Overrides where the blockhash baked in at construction comes from. Left unset (the
80
+ * default) one is fetched per transaction built, which every transaction the SDK builds
81
+ * needs since `Transaction`'s constructor compiles a versioned transaction.
82
+ *
83
+ * @param source - A blockhash, a function producing one, or undefined to fetch.
84
+ */
85
+ setConstructionBlockhash(source) {
86
+ this.constructionBlockhash = source;
87
+ }
88
+ /**
89
+ * Resolves the blockhash to construct a transaction with.
90
+ *
91
+ * @param connection - The Solana blockchain connection object, used only when no source is set.
92
+ */
93
+ resolveConstructionBlockhash(connection) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ if (this.constructionBlockhash === undefined) {
96
+ return yield connection.getLatestBlockhash();
97
+ }
98
+ return typeof this.constructionBlockhash === "function"
99
+ ? yield this.constructionBlockhash()
100
+ : this.constructionBlockhash;
101
+ });
102
+ }
78
103
  /**
79
104
  * Gets the singleton instance of the CreateTxMetadata class.
80
105
  *
@@ -257,7 +282,7 @@ class CreateTxMetadata {
257
282
  (0, Logging_1.Log)(`createTxMetadata: Checkpoint: (jupAlts after loop) ${(new Date().getTime() / 1000) - startTime}`);
258
283
  // Get the recent blockhash
259
284
  startTime = new Date().getTime() / 1000;
260
- const latestBlockhash = yield connection.getLatestBlockhash();
285
+ const latestBlockhash = yield this.resolveConstructionBlockhash(connection);
261
286
  (0, Logging_1.Log)(`createTxMetadata: Checkpoint: (latestBlockhash) ${(new Date().getTime() / 1000) - startTime}`);
262
287
  // Create initial transaction instance
263
288
  const transaction = new Transaction_1.Transaction(data, new web3.PublicKey(payer), latestBlockhash, alts, generalUtility);
@@ -334,7 +359,7 @@ class CreateTxMetadata {
334
359
  (0, Logging_1.Log)(`createTxMetadataWithActions: Checkpoint: (jupAlts after loop) ${(new Date().getTime() / 1000) - startTime}`);
335
360
  // Get the recent blockhash
336
361
  startTime = new Date().getTime() / 1000;
337
- const latestBlockhash = yield connection.getLatestBlockhash();
362
+ const latestBlockhash = yield this.resolveConstructionBlockhash(connection);
338
363
  (0, Logging_1.Log)(`createTxMetadataWithActions: Checkpoint: (latestBlockhash) ${(new Date().getTime() / 1000) - startTime}`);
339
364
  // Create initial transaction instance
340
365
  const transaction = new Transaction_1.Transaction({
@@ -366,7 +391,7 @@ class CreateTxMetadata {
366
391
  const mainStartTime = new Date().getTime() / 1000;
367
392
  // Get the recent blockhash
368
393
  let startTime = mainStartTime;
369
- const latestBlockhash = yield connection.getLatestBlockhash();
394
+ const latestBlockhash = yield this.resolveConstructionBlockhash(connection);
370
395
  (0, Logging_1.Log)(`createTxMetadata2: Checkpoint: (latestBlockhash) ${(new Date().getTime() / 1000) - startTime}`);
371
396
  startTime = new Date().getTime() / 1000;
372
397
  const batchExecute = new TransactionBatchExecute2_1.TransactionBatchExecute2(data.addressLookupTableAddresses.map(p => new web3.PublicKey(p)), data.mainInstructions.map(ix => {
@@ -413,3 +438,13 @@ class CreateTxMetadata {
413
438
  }
414
439
  }
415
440
  exports.CreateTxMetadata = CreateTxMetadata;
441
+ /**
442
+ * A blockhash that is valid to compile against but not to land against. Callers that
443
+ * have proven every path overwrites the construction blockhash before signing can hand
444
+ * this over and save one foreground getLatestBlockhash per transaction built (H-2582).
445
+ * Same value `toVersionedTransaction` and `Transaction.simulateTransaction` compile with.
446
+ */
447
+ CreateTxMetadata.PLACEHOLDER_BLOCKHASH = {
448
+ blockhash: web3.PublicKey.default.toString(),
449
+ lastValidBlockHeight: 0,
450
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hawksightco/hawk-sdk",
3
- "version": "1.3.276",
3
+ "version": "1.3.277",
4
4
  "description": "Hawksight v2 SDK",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://github.com/ghabxph/hawk-api-client.git",