@hawksightco/hawk-sdk 0.0.27 → 0.0.28
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.
|
@@ -65,6 +65,20 @@ export declare class Transaction {
|
|
|
65
65
|
* Add priority fee instructions (compute budget)
|
|
66
66
|
*/
|
|
67
67
|
addPriorityFeeIx(connection: web3.Connection, priorityLevel: client.PriorityLevel, computeUnitLimit: number, maxPriorityFee?: number): Promise<web3.TransactionInstruction[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the compute unit limit from a transaction simulation.
|
|
70
|
+
*
|
|
71
|
+
* This function simulates a transaction and calculates the compute unit limit
|
|
72
|
+
* based on the simulation results. If an additional compute limit is provided,
|
|
73
|
+
* it is added to the units consumed in the simulation. Otherwise, the units
|
|
74
|
+
* consumed are increased by 10%.
|
|
75
|
+
*
|
|
76
|
+
* @param {web3.Connection} connection - The connection object to the Solana cluster.
|
|
77
|
+
* @param {number} [additionalComputeLimit] - Optional additional compute limit to add to the units consumed.
|
|
78
|
+
* @returns {Promise<number>} - A promise that resolves to the total compute unit limit.
|
|
79
|
+
* @throws {Error} - Throws an error if the transaction simulation fails.
|
|
80
|
+
*/
|
|
81
|
+
getComputeUnitLimit(connection: web3.Connection, additionalComputeLimit?: number): Promise<number>;
|
|
68
82
|
/**
|
|
69
83
|
* Simulate transaction
|
|
70
84
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../../src/classes/Transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AACtD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;GAGG;AACH,qBAAa,WAAW;IA+CpB,QAAQ,CAA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S,EAAE,UAAU,GAAG,IAAI;IAcpE;;;;OAIG;IACH,yBAAyB,IAAI,OAAO;IAIpC;;OAEG;IACG,gBAAgB,CACpB,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,aAAa,EAAE,MAAM,CAAC,aAAa,EACnC,gBAAgB,EAAE,MAAM,EACxB,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IA2CzC;;;;;;;;;;;;OAYG;IACG,mBAAmB,CACvB,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,MAAM,CAAC;IAiBlB;;;;;OAKG;IACG,mBAAmB,CACvB,UAAU,EAAE,IAAI,CAAC,UAAU,GAC1B,OAAO,CAAC,4BAA4B,CAAC;IAsCxC;;OAEG;IACH,gBAAgB,CACd,eAAe,EAAE,IAAI,CAAC,8BAA8B,GACnD,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,oBAAoB,CAAC;IAcvD;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAW1B;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAgBpC;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAgBpC;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAW7B"}
|
|
@@ -70,16 +70,6 @@ class Transaction {
|
|
|
70
70
|
* @param alts Address lookup tables that optimize account address storage
|
|
71
71
|
*/
|
|
72
72
|
constructor(txMetadataResponse, payerKey, latestBlockhash, alts, generalUtility) {
|
|
73
|
-
// // Construct compute instructions
|
|
74
|
-
// const computeIxs = txMetadataResponse.computeBudgetInstructions.map(ix => {
|
|
75
|
-
// return new web3.TransactionInstruction({
|
|
76
|
-
// keys: ix.accounts.map(meta => {
|
|
77
|
-
// return { pubkey: new web3.PublicKey(meta.pubkey), isSigner: meta.isSigner, isWritable: meta.isWritable };
|
|
78
|
-
// }),
|
|
79
|
-
// programId: new web3.PublicKey(ix.programId),
|
|
80
|
-
// data: Buffer.from(ix.data, 'base64'),
|
|
81
|
-
// });
|
|
82
|
-
// });
|
|
83
73
|
this.txMetadataResponse = txMetadataResponse;
|
|
84
74
|
this.payerKey = payerKey;
|
|
85
75
|
this.latestBlockhash = latestBlockhash;
|
|
@@ -106,12 +96,6 @@ class Transaction {
|
|
|
106
96
|
this._txMessage = txMessage;
|
|
107
97
|
this._versionedTransaction = versionedTransaction;
|
|
108
98
|
this.requiredSigners = this.getRequiredSigners();
|
|
109
|
-
// // Commented to allow payer to be a non required signer within the transaction
|
|
110
|
-
// if (typeof this.requiredSigners[payerKey.toString()] !== "boolean") {
|
|
111
|
-
// throw new Error(
|
|
112
|
-
// `Warning: The payer ${payerKey} is not one of the required signers of this transaction.`
|
|
113
|
-
// );
|
|
114
|
-
// }
|
|
115
99
|
}
|
|
116
100
|
/**
|
|
117
101
|
* Signs the transaction with provided signers.
|
|
@@ -199,6 +183,37 @@ class Transaction {
|
|
|
199
183
|
return priorityFeeIxs;
|
|
200
184
|
});
|
|
201
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Gets the compute unit limit from a transaction simulation.
|
|
188
|
+
*
|
|
189
|
+
* This function simulates a transaction and calculates the compute unit limit
|
|
190
|
+
* based on the simulation results. If an additional compute limit is provided,
|
|
191
|
+
* it is added to the units consumed in the simulation. Otherwise, the units
|
|
192
|
+
* consumed are increased by 10%.
|
|
193
|
+
*
|
|
194
|
+
* @param {web3.Connection} connection - The connection object to the Solana cluster.
|
|
195
|
+
* @param {number} [additionalComputeLimit] - Optional additional compute limit to add to the units consumed.
|
|
196
|
+
* @returns {Promise<number>} - A promise that resolves to the total compute unit limit.
|
|
197
|
+
* @throws {Error} - Throws an error if the transaction simulation fails.
|
|
198
|
+
*/
|
|
199
|
+
getComputeUnitLimit(connection, additionalComputeLimit) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const simulation = yield this.simulateTransaction(connection);
|
|
202
|
+
if (simulation.err !== null) {
|
|
203
|
+
if (simulation.logs === null) {
|
|
204
|
+
console.log(simulation.err);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
for (const log of simulation.logs) {
|
|
208
|
+
console.log(log);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
throw new Error(`Transaction simulation error. See logs above.`);
|
|
212
|
+
}
|
|
213
|
+
const totalUnitLimit = additionalComputeLimit ? simulation.unitsConsumed + additionalComputeLimit : Math.round(simulation.unitsConsumed * 1.1);
|
|
214
|
+
return totalUnitLimit;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
202
217
|
/**
|
|
203
218
|
* Simulate transaction
|
|
204
219
|
*
|