@hawksightco/hawk-sdk 0.0.41 → 0.0.43
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.
|
@@ -62,19 +62,32 @@ export declare class Transaction {
|
|
|
62
62
|
*/
|
|
63
63
|
isSignedByRequiredSigners(): boolean;
|
|
64
64
|
/**
|
|
65
|
-
* Add priority fee instructions (compute budget)
|
|
65
|
+
* Add priority fee instructions (compute budget) with a fixed priority fee.
|
|
66
|
+
*
|
|
67
|
+
* This method adds priority fee instructions to the transaction based on a fixed priority fee.
|
|
68
|
+
*
|
|
69
|
+
* @param connection - The connection to the Solana cluster.
|
|
70
|
+
* @param computeUnitLimit - The limit on the number of compute units.
|
|
71
|
+
* @param fixedPriority - Set to true to indicate a fixed priority fee.
|
|
72
|
+
* @param fixedPriorityFee - The fixed priority fee in lamports.
|
|
73
|
+
* @returns An array of transaction instructions.
|
|
74
|
+
*/
|
|
75
|
+
addPriorityFeeIx(connection: web3.Connection, computeUnitLimit: number, fixedPriority: true, fixedPriorityFee: number): Promise<web3.TransactionInstruction[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Add priority fee instructions (compute budget) with a variable priority defined by Helius.
|
|
66
78
|
*
|
|
67
79
|
* This method adds priority fee instructions to the transaction based on the specified
|
|
68
80
|
* priority level and compute unit limit. It ensures that the total fee does not exceed
|
|
69
81
|
* the specified maximum priority fee (in SOL) if provided.
|
|
70
82
|
*
|
|
71
83
|
* @param connection - The connection to the Solana cluster.
|
|
72
|
-
* @param priorityLevel - The priority level for the fee estimation.
|
|
73
84
|
* @param computeUnitLimit - The limit on the number of compute units.
|
|
85
|
+
* @param fixedPriority - Set to false to indicate a variable priority fee.
|
|
86
|
+
* @param priorityLevel - The priority level for the fee estimation.
|
|
74
87
|
* @param maxPriorityFee - The maximum priority fee in SOL (optional).
|
|
75
88
|
* @returns An array of transaction instructions.
|
|
76
89
|
*/
|
|
77
|
-
addPriorityFeeIx(connection: web3.Connection, priorityLevel: client.PriorityLevel,
|
|
90
|
+
addPriorityFeeIx(connection: web3.Connection, computeUnitLimit: number, fixedPriority: false, priorityLevel: client.PriorityLevel, maxPriorityFee?: number): Promise<web3.TransactionInstruction[]>;
|
|
78
91
|
/**
|
|
79
92
|
* Gets the compute unit limit from a transaction simulation.
|
|
80
93
|
*
|
|
@@ -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,CAAC,kBAAkB,EAAE,2BAA2B;IACxD,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS;IACjC,OAAO,CAAC,eAAe;IACvB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,yBAAyB,EAAE;IAC/C,OAAO,CAAC,cAAc;IAlDxB,2FAA2F;IAC3F,OAAO,CAAC,UAAU,CAA0B;IAC5C,IAAI,SAAS,IAAI,IAAI,CAAC,kBAAkB,CAEvC;IAED,+DAA+D;IAC/D,OAAO,CAAC,qBAAqB,CAA4B;IACzD,IAAI,oBAAoB,IAAI,IAAI,CAAC,oBAAoB,CAEpD;IAED,+EAA+E;IAC/E,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElD,oFAAoF;IACpF,OAAO,CAAC,oBAAoB,CAAc;IAC1C,IAAI,mBAAmB,IAAI,MAAM,CAEhC;IAED,6CAA6C;IAC7C,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED,yEAAyE;IACzE,OAAO,CAAC,aAAa,CAAgC;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,EACpB,aAAa,EAAE,MAAM,CAAC,aAAa,EACnC,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IA+EzC;;;;;;;;;;;;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"}
|
|
@@ -156,42 +156,52 @@ class Transaction {
|
|
|
156
156
|
* the specified maximum priority fee (in SOL) if provided.
|
|
157
157
|
*
|
|
158
158
|
* @param connection - The connection to the Solana cluster.
|
|
159
|
-
* @param priorityLevel - The priority level for the fee estimation.
|
|
160
159
|
* @param computeUnitLimit - The limit on the number of compute units.
|
|
161
|
-
* @param
|
|
160
|
+
* @param fixedPriority - If true, a fixed priority fee is used; if false, the fee is based on priority level.
|
|
161
|
+
* @param priorityLevelOrPriorityFee - The priority level for the fee estimation or the fixed priority fee.
|
|
162
|
+
* @param maxPriorityFee - The maximum priority fee in SOL (optional, only applicable when fixedPriority is false).
|
|
162
163
|
* @returns An array of transaction instructions.
|
|
163
164
|
*/
|
|
164
|
-
addPriorityFeeIx(
|
|
165
|
-
return __awaiter(this,
|
|
166
|
-
// First, remove priority fee instructions
|
|
165
|
+
addPriorityFeeIx(connection_1, computeUnitLimit_1) {
|
|
166
|
+
return __awaiter(this, arguments, void 0, function* (connection, computeUnitLimit, fixedPriority = false, priorityLevelOrPriorityFee, maxPriorityFee) {
|
|
167
|
+
// First, remove any existing priority fee instructions
|
|
167
168
|
this.removePriorityFeeIxs();
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
169
|
+
let totalPriorityFeeLamports;
|
|
170
|
+
if (fixedPriority && typeof priorityLevelOrPriorityFee === 'number') {
|
|
171
|
+
// For fixed priority, directly use the provided fixed priority fee
|
|
172
|
+
totalPriorityFeeLamports = priorityLevelOrPriorityFee - 5000;
|
|
173
|
+
}
|
|
174
|
+
else if (typeof priorityLevelOrPriorityFee === 'string') {
|
|
175
|
+
// Convert maxPriorityFee from SOL to lamports (1 SOL = 1_000_000_000 lamports)
|
|
176
|
+
const maxPriorityFeeLamports = maxPriorityFee !== undefined ? maxPriorityFee * 1000000000 : undefined;
|
|
177
|
+
// Get fee estimate by simulating the transaction
|
|
178
|
+
const estimate = yield (0, functions_1.getFeeEstimate)(this.generalUtility, priorityLevelOrPriorityFee, this.txMetadataResponse);
|
|
179
|
+
// Calculate the total fee in lamports
|
|
180
|
+
totalPriorityFeeLamports = new bn_js_1.BN(estimate).mul(new bn_js_1.BN(computeUnitLimit)).div(new bn_js_1.BN(1000000)).toNumber();
|
|
181
|
+
// If maxPriorityFee is defined and it is less than the total calculated fee, cap it
|
|
182
|
+
if (maxPriorityFeeLamports !== undefined && totalPriorityFeeLamports > maxPriorityFeeLamports) {
|
|
183
|
+
totalPriorityFeeLamports = maxPriorityFeeLamports - 5000;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
throw new Error('Invalid parameters');
|
|
177
188
|
}
|
|
178
189
|
// Convert the total priority fee back to microLamports per compute unit
|
|
179
190
|
const priorityFeePerUnitMicroLamports = new bn_js_1.BN(totalPriorityFeeLamports).mul(new bn_js_1.BN(1000000)).div(new bn_js_1.BN(computeUnitLimit)).toNumber();
|
|
180
|
-
// Create priority fee instructions for transaction
|
|
191
|
+
// Create priority fee instructions for the transaction
|
|
181
192
|
const priorityFeeIxs = [
|
|
182
193
|
web3.ComputeBudgetProgram.setComputeUnitLimit({
|
|
183
194
|
units: computeUnitLimit,
|
|
184
195
|
}),
|
|
185
196
|
web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
186
|
-
// CU * CU PRICE -> 1400000 * feeEstimate.priorityFeeEstimate
|
|
187
197
|
microLamports: priorityFeePerUnitMicroLamports,
|
|
188
198
|
}),
|
|
189
199
|
];
|
|
190
200
|
// Store the total priority fee in lamports
|
|
191
201
|
this._priorityFeeEstimate = totalPriorityFeeLamports.toString();
|
|
192
|
-
// Append priority fee
|
|
202
|
+
// Append priority fee instructions at the beginning
|
|
193
203
|
this._instructions.unshift(...priorityFeeIxs);
|
|
194
|
-
// Rebuild versioned transaction
|
|
204
|
+
// Rebuild versioned transaction with the latest blockhash
|
|
195
205
|
const blockhash = yield connection.getLatestBlockhash();
|
|
196
206
|
this.buildTransaction(blockhash);
|
|
197
207
|
return priorityFeeIxs;
|