@hawksightco/hawk-sdk 1.1.39 → 1.1.41-hotfix-1
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/dist/src/classes/CreateTxMetadata.d.ts.map +1 -1
- package/dist/src/classes/CreateTxMetadata.js +2 -12
- package/dist/src/classes/MultiTransaction.d.ts +76 -0
- package/dist/src/classes/MultiTransaction.d.ts.map +1 -0
- package/dist/src/classes/MultiTransaction.js +286 -0
- package/dist/src/classes/Transaction copy.d.ts +162 -0
- package/dist/src/classes/Transaction copy.d.ts.map +1 -0
- package/dist/src/classes/Transaction copy.js +458 -0
- package/dist/src/classes/Transaction.d.ts +42 -12
- package/dist/src/classes/Transaction.d.ts.map +1 -1
- package/dist/src/classes/Transaction.js +1 -0
- package/dist/src/classes/Transaction2.d.ts +108 -0
- package/dist/src/classes/Transaction2.d.ts.map +1 -0
- package/dist/src/classes/Transaction2.js +239 -0
- package/dist/src/classes/Transaction3.d.ts +166 -0
- package/dist/src/classes/Transaction3.d.ts.map +1 -0
- package/dist/src/classes/Transaction3.js +406 -0
- package/dist/src/classes/TransactionBatchExecute2.d.ts +18 -0
- package/dist/src/classes/TransactionBatchExecute2.d.ts.map +1 -1
- package/dist/src/classes/TransactionBatchExecute2.js +72 -1
- package/dist/src/classes/Transactions.d.ts +4 -2
- package/dist/src/classes/Transactions.d.ts.map +1 -1
- package/dist/src/classes/Transactions.js +17 -11
- package/dist/src/classes/TxGenerator.d.ts +2 -1
- package/dist/src/classes/TxGenerator.d.ts.map +1 -1
- package/dist/src/classes/TxGenerator.js +8 -23
- package/dist/src/functions.d.ts +25 -0
- package/dist/src/functions.d.ts.map +1 -1
- package/dist/src/functions.js +70 -1
- package/dist/src/hsToMeteora.d.ts.map +1 -1
- package/dist/src/hsToMeteora.js +173 -27
- package/dist/src/idl/meteora-idl.d.ts +5251 -0
- package/dist/src/idl/meteora-idl.d.ts.map +1 -0
- package/dist/src/idl/meteora-idl.js +5252 -0
- package/dist/src/meteora.d.ts +1 -1
- package/dist/src/meteora.d.ts.map +1 -1
- package/dist/src/meteora.js +37 -2
- package/dist/src/types.d.ts +6 -7
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/// <reference types="@meteora-ag/dlmm/node_modules/@solana/web3.js" />
|
|
2
|
+
import * as client from "@hawksightco/swagger-client";
|
|
3
|
+
import * as web3 from "@solana/web3.js";
|
|
4
|
+
import { GeneralUtility } from "./GeneralUtility";
|
|
5
|
+
import { Transaction3, TransactionMetadataResponse } from "./Transaction3";
|
|
6
|
+
export declare const DummyTransactionMetadataResponse: TransactionMetadataResponse;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a transaction object in Solana using the web3.js library.
|
|
9
|
+
* This class encapsulates the logic for creating, signing, and verifying signatures of transactions.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Transaction2 extends Transaction3 {
|
|
12
|
+
readonly txMetadataResponse: TransactionMetadataResponse;
|
|
13
|
+
readonly payerKey: web3.PublicKey;
|
|
14
|
+
protected latestBlockhash: {
|
|
15
|
+
blockhash: string;
|
|
16
|
+
lastValidBlockHeight: number;
|
|
17
|
+
};
|
|
18
|
+
readonly alts: web3.AddressLookupTableAccount[];
|
|
19
|
+
protected generalUtility: GeneralUtility;
|
|
20
|
+
/**
|
|
21
|
+
* Whether transaction has nonce advance instruction
|
|
22
|
+
*/
|
|
23
|
+
readonly hasNonceAdvanceIx: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Fee estimate that can be overwritten
|
|
26
|
+
*/
|
|
27
|
+
feeEstimate: number;
|
|
28
|
+
/**
|
|
29
|
+
* Constructs a new Transaction object.
|
|
30
|
+
*
|
|
31
|
+
* @param payerKey PublicKey of the transaction payer
|
|
32
|
+
* @param instructions Array of TransactionInstruction to be executed in this transaction
|
|
33
|
+
* @param recentBlockhash The blockhash of a recent ledger entry
|
|
34
|
+
* @param alts Address lookup tables that optimize account address storage
|
|
35
|
+
*/
|
|
36
|
+
private constructor();
|
|
37
|
+
static new(payerKey: web3.PublicKey, alts: web3.AddressLookupTableAccount[], generalUtility: GeneralUtility, _mainIxs?: web3.TransactionInstruction[], latestBlockhash?: {
|
|
38
|
+
blockhash: string;
|
|
39
|
+
lastValidBlockHeight: number;
|
|
40
|
+
}): Transaction2;
|
|
41
|
+
/**
|
|
42
|
+
* Generate nonde advance instruction (dummy instruction)
|
|
43
|
+
*/
|
|
44
|
+
private nonceAdvanceIx;
|
|
45
|
+
/**
|
|
46
|
+
* Get nonce index
|
|
47
|
+
*
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
private getNonceIndex;
|
|
51
|
+
/**
|
|
52
|
+
* Signs the transaction with provided signers.
|
|
53
|
+
*
|
|
54
|
+
* @param signers Array of Signer objects whose private keys will be used to sign the transaction.
|
|
55
|
+
* @param idempotent Boolean indicating whether signing should be idempotent (default is false).
|
|
56
|
+
* @throws Error if a signer is not required or has already signed the transaction when not idempotent.
|
|
57
|
+
*/
|
|
58
|
+
sign(signers: web3.Signer[], idempotent?: boolean): void;
|
|
59
|
+
/**
|
|
60
|
+
* Add a signature on the transaction with provided signature.
|
|
61
|
+
*
|
|
62
|
+
* @param publicKey The public key of the signer
|
|
63
|
+
* @param signature A signature of the signed transaction
|
|
64
|
+
* @throws Error if a signer is not required or has already signed the transaction.
|
|
65
|
+
*/
|
|
66
|
+
addSignature(publicKey: web3.PublicKey, signature: Uint8Array): void;
|
|
67
|
+
/**
|
|
68
|
+
* Checks if all required signers have signed the transaction.
|
|
69
|
+
*
|
|
70
|
+
* @returns Boolean indicating whether all required signers have signed.
|
|
71
|
+
*/
|
|
72
|
+
isSignedByRequiredSigners(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Add priority fee instructions (compute budget) with a fixed priority fee.
|
|
75
|
+
*
|
|
76
|
+
* This method adds priority fee instructions to the transaction based on a fixed priority fee.
|
|
77
|
+
*
|
|
78
|
+
* @param connection - The connection to the Solana cluster.
|
|
79
|
+
* @param computeUnitLimit - The limit on the number of compute units.
|
|
80
|
+
* @param fixedPriority - Set to true to indicate a fixed priority fee.
|
|
81
|
+
* @param fixedPriorityFee - The fixed priority fee in lamports.
|
|
82
|
+
* @returns An array of transaction instructions.
|
|
83
|
+
*/
|
|
84
|
+
addPriorityFeeIx(connection: web3.Connection, computeUnitLimit: number, fixedPriority: true, fixedPriorityFee: number): Promise<web3.TransactionInstruction[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Add priority fee instructions (compute budget) with a variable priority defined by Helius.
|
|
87
|
+
*
|
|
88
|
+
* This method adds priority fee instructions to the transaction based on the specified
|
|
89
|
+
* priority level and compute unit limit. It ensures that the total fee does not exceed
|
|
90
|
+
* the specified maximum priority fee (in SOL) if provided.
|
|
91
|
+
*
|
|
92
|
+
* @param connection - The connection to the Solana cluster.
|
|
93
|
+
* @param computeUnitLimit - The limit on the number of compute units.
|
|
94
|
+
* @param fixedPriority - Set to false to indicate a variable priority fee.
|
|
95
|
+
* @param priorityLevel - The priority level for the fee estimation.
|
|
96
|
+
* @param maxPriorityFee - The maximum priority fee in SOL (optional).
|
|
97
|
+
* @returns An array of transaction instructions.
|
|
98
|
+
*/
|
|
99
|
+
addPriorityFeeIx(connection: web3.Connection, computeUnitLimit: number, fixedPriority: false, priorityLevel: client.PriorityLevel, maxPriorityFee?: number): Promise<web3.TransactionInstruction[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Overwrite blockhash and rebuild transaction
|
|
102
|
+
*
|
|
103
|
+
* @param blockhash
|
|
104
|
+
* @param lastValidBlockHeight
|
|
105
|
+
*/
|
|
106
|
+
setBlockhash(blockhash: string | null, lastValidBlockHeight: number | null): void;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=Transaction2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transaction2.d.ts","sourceRoot":"","sources":["../../../src/classes/Transaction2.ts"],"names":[],"mappings":";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C,SAAS,EAAE,SAAS,EAAE,UAAU,GAAG,IAAI;IAcpE;;;;OAIG;IACH,yBAAyB,IAAI,OAAO;IAIpC;;;;;;;;;;OAUG;IACG,gBAAgB,CACpB,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,IAAI,EACnB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAEzC;;;;;;;;;;;;;OAaG;IACG,gBAAgB,CACpB,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,KAAK,EACpB,aAAa,EAAE,MAAM,CAAC,aAAa,EACnC,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IA4EzC;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,oBAAoB,EAAE,MAAM,GAAG,IAAI;CAY3E"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.Transaction2 = exports.DummyTransactionMetadataResponse = void 0;
|
|
36
|
+
const client = __importStar(require("@hawksightco/swagger-client"));
|
|
37
|
+
const web3 = __importStar(require("@solana/web3.js"));
|
|
38
|
+
const bn_js_1 = require("bn.js");
|
|
39
|
+
const Transaction3_1 = require("./Transaction3");
|
|
40
|
+
const Logging_1 = require("./Logging");
|
|
41
|
+
exports.DummyTransactionMetadataResponse = {
|
|
42
|
+
description: '',
|
|
43
|
+
estimatedFeeInSOL: '',
|
|
44
|
+
addressLookupTableAddresses: [], // "alts" is confusing, copied jup's naming
|
|
45
|
+
computeBudgetInstructions: [], // this enables for ease of access while also making them optional
|
|
46
|
+
mainInstructions: [],
|
|
47
|
+
payer: '',
|
|
48
|
+
signature: '',
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Represents a transaction object in Solana using the web3.js library.
|
|
52
|
+
* This class encapsulates the logic for creating, signing, and verifying signatures of transactions.
|
|
53
|
+
*/
|
|
54
|
+
class Transaction2 extends Transaction3_1.Transaction3 {
|
|
55
|
+
/**
|
|
56
|
+
* Constructs a new Transaction object.
|
|
57
|
+
*
|
|
58
|
+
* @param payerKey PublicKey of the transaction payer
|
|
59
|
+
* @param instructions Array of TransactionInstruction to be executed in this transaction
|
|
60
|
+
* @param recentBlockhash The blockhash of a recent ledger entry
|
|
61
|
+
* @param alts Address lookup tables that optimize account address storage
|
|
62
|
+
*/
|
|
63
|
+
constructor(txMetadataResponse, payerKey, latestBlockhash, alts, generalUtility, _mainIxs = []) {
|
|
64
|
+
super(txMetadataResponse, payerKey, latestBlockhash, alts, generalUtility, _mainIxs);
|
|
65
|
+
this.txMetadataResponse = txMetadataResponse;
|
|
66
|
+
this.payerKey = payerKey;
|
|
67
|
+
this.latestBlockhash = latestBlockhash;
|
|
68
|
+
this.alts = alts;
|
|
69
|
+
this.generalUtility = generalUtility;
|
|
70
|
+
/**
|
|
71
|
+
* Fee estimate that can be overwritten
|
|
72
|
+
*/
|
|
73
|
+
this.feeEstimate = 0;
|
|
74
|
+
const index = this.getNonceIndex();
|
|
75
|
+
this.hasNonceAdvanceIx = index > -1;
|
|
76
|
+
}
|
|
77
|
+
;
|
|
78
|
+
static new(payerKey, alts, generalUtility, _mainIxs = [], latestBlockhash = { blockhash: '', lastValidBlockHeight: 0 }) {
|
|
79
|
+
const instance = new Transaction2(exports.DummyTransactionMetadataResponse, payerKey, latestBlockhash, alts, generalUtility, _mainIxs);
|
|
80
|
+
return instance;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Generate nonde advance instruction (dummy instruction)
|
|
84
|
+
*/
|
|
85
|
+
nonceAdvanceIx(noncePubkey) {
|
|
86
|
+
// Generate dummy nonce ix
|
|
87
|
+
return web3.SystemProgram.nonceAdvance({
|
|
88
|
+
/** Nonce account */
|
|
89
|
+
noncePubkey,
|
|
90
|
+
/** Public key of the nonce authority */
|
|
91
|
+
authorizedPubkey: this.payerKey,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get nonce index
|
|
96
|
+
*
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
getNonceIndex() {
|
|
100
|
+
const referenceIx = this.nonceAdvanceIx(web3.Keypair.generate().publicKey);
|
|
101
|
+
const index = this._instructions.findIndex(ix => {
|
|
102
|
+
const isNonceAdvanceIx = ix.data.toString("base64") == referenceIx.data.toString("base64") &&
|
|
103
|
+
ix.programId.toString() == referenceIx.programId.toString();
|
|
104
|
+
return isNonceAdvanceIx;
|
|
105
|
+
});
|
|
106
|
+
return index;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Signs the transaction with provided signers.
|
|
110
|
+
*
|
|
111
|
+
* @param signers Array of Signer objects whose private keys will be used to sign the transaction.
|
|
112
|
+
* @param idempotent Boolean indicating whether signing should be idempotent (default is false).
|
|
113
|
+
* @throws Error if a signer is not required or has already signed the transaction when not idempotent.
|
|
114
|
+
*/
|
|
115
|
+
sign(signers, idempotent = false) {
|
|
116
|
+
// First validate all signers
|
|
117
|
+
signers.forEach((signer) => {
|
|
118
|
+
const key = signer.publicKey.toString();
|
|
119
|
+
if (typeof this.requiredSigners[key] !== "boolean") {
|
|
120
|
+
throw new Error(`Key ${key} is not a required signer!`);
|
|
121
|
+
}
|
|
122
|
+
if (!idempotent && this.requiredSigners[key]) {
|
|
123
|
+
throw new Error(`Key ${key} has already been signed by required signer!`);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
// If all signers are valid and the process is idempotent or they haven't signed yet, update and sign
|
|
127
|
+
signers.forEach((signer) => {
|
|
128
|
+
const key = signer.publicKey.toString();
|
|
129
|
+
this.requiredSigners[key] = true;
|
|
130
|
+
});
|
|
131
|
+
this.versionedTransaction.sign(signers);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Add a signature on the transaction with provided signature.
|
|
135
|
+
*
|
|
136
|
+
* @param publicKey The public key of the signer
|
|
137
|
+
* @param signature A signature of the signed transaction
|
|
138
|
+
* @throws Error if a signer is not required or has already signed the transaction.
|
|
139
|
+
*/
|
|
140
|
+
addSignature(publicKey, signature) {
|
|
141
|
+
const key = publicKey.toBase58();
|
|
142
|
+
if (typeof this.requiredSigners[key] !== "boolean") {
|
|
143
|
+
throw new Error(`Key ${key} is not a required signer!`);
|
|
144
|
+
}
|
|
145
|
+
if (this.requiredSigners[key]) {
|
|
146
|
+
throw new Error(`Key ${key} has already been signed by required signer!`);
|
|
147
|
+
}
|
|
148
|
+
this.requiredSigners[key] = true;
|
|
149
|
+
this.versionedTransaction.addSignature(publicKey, signature);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Checks if all required signers have signed the transaction.
|
|
153
|
+
*
|
|
154
|
+
* @returns Boolean indicating whether all required signers have signed.
|
|
155
|
+
*/
|
|
156
|
+
isSignedByRequiredSigners() {
|
|
157
|
+
return Object.values(this.requiredSigners).every((isSigned) => isSigned);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Add priority fee instructions (compute budget)
|
|
161
|
+
*
|
|
162
|
+
* This method adds priority fee instructions to the transaction based on the specified
|
|
163
|
+
* priority level and compute unit limit. It ensures that the total fee does not exceed
|
|
164
|
+
* the specified maximum priority fee (in SOL) if provided.
|
|
165
|
+
*
|
|
166
|
+
* @param connection - The connection to the Solana cluster.
|
|
167
|
+
* @param computeUnitLimit - The limit on the number of compute units.
|
|
168
|
+
* @param fixedPriority - If true, a fixed priority fee is used; if false, the fee is based on priority level.
|
|
169
|
+
* @param priorityLevelOrPriorityFee - The priority level for the fee estimation or the fixed priority fee.
|
|
170
|
+
* @param maxPriorityFee - The maximum priority fee in SOL (optional, only applicable when fixedPriority is false).
|
|
171
|
+
* @returns An array of transaction instructions.
|
|
172
|
+
*/
|
|
173
|
+
addPriorityFeeIx(connection_1, computeUnitLimit_1) {
|
|
174
|
+
return __awaiter(this, arguments, void 0, function* (connection, computeUnitLimit, fixedPriority = false, priorityLevelOrPriorityFee, maxPriorityFee) {
|
|
175
|
+
(0, Logging_1.Log)(`addPriorityFeeIx`);
|
|
176
|
+
// First, remove any existing priority fee instructions
|
|
177
|
+
this.removePriorityFeeIxs();
|
|
178
|
+
let totalPriorityFeeLamports;
|
|
179
|
+
if (fixedPriority && typeof priorityLevelOrPriorityFee === 'number') {
|
|
180
|
+
// For fixed priority, directly use the provided fixed priority fee
|
|
181
|
+
totalPriorityFeeLamports = priorityLevelOrPriorityFee - 5000;
|
|
182
|
+
}
|
|
183
|
+
else if (typeof priorityLevelOrPriorityFee === 'string') {
|
|
184
|
+
// Convert maxPriorityFee from SOL to lamports (1 SOL = 1_000_000_000 lamports)
|
|
185
|
+
const maxPriorityFeeLamports = maxPriorityFee !== undefined ? maxPriorityFee * 1000000000 : undefined;
|
|
186
|
+
// Get fee estimate by simulating the transaction
|
|
187
|
+
let estimate = this.feeEstimate;
|
|
188
|
+
// If priority is set to default or medium, we multiply estimate by 2 to increase its chance on blockchain.
|
|
189
|
+
if (priorityLevelOrPriorityFee === client.PriorityLevel.Default || priorityLevelOrPriorityFee === client.PriorityLevel.Medium) {
|
|
190
|
+
estimate = estimate * 2;
|
|
191
|
+
}
|
|
192
|
+
// Calculate the total fee in lamports
|
|
193
|
+
totalPriorityFeeLamports = new bn_js_1.BN(estimate).mul(new bn_js_1.BN(computeUnitLimit)).div(new bn_js_1.BN(1000000)).toNumber();
|
|
194
|
+
// If maxPriorityFee is defined and it is less than the total calculated fee, cap it
|
|
195
|
+
if (maxPriorityFeeLamports !== undefined && totalPriorityFeeLamports > maxPriorityFeeLamports) {
|
|
196
|
+
totalPriorityFeeLamports = maxPriorityFeeLamports - 5000;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
throw new Error('Invalid parameters');
|
|
201
|
+
}
|
|
202
|
+
// Convert the total priority fee back to microLamports per compute unit
|
|
203
|
+
const priorityFeePerUnitMicroLamports = new bn_js_1.BN(totalPriorityFeeLamports).mul(new bn_js_1.BN(1000000)).div(new bn_js_1.BN(computeUnitLimit)).toNumber();
|
|
204
|
+
// Create priority fee instructions for the transaction
|
|
205
|
+
const priorityFeeIxs = [
|
|
206
|
+
web3.ComputeBudgetProgram.setComputeUnitLimit({
|
|
207
|
+
units: computeUnitLimit,
|
|
208
|
+
}),
|
|
209
|
+
web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
210
|
+
microLamports: priorityFeePerUnitMicroLamports,
|
|
211
|
+
}),
|
|
212
|
+
];
|
|
213
|
+
// Store the total priority fee in lamports
|
|
214
|
+
this._priorityFeeEstimate = totalPriorityFeeLamports.toString();
|
|
215
|
+
// Append priority fee instructions at the beginning
|
|
216
|
+
this._instructions.unshift(...priorityFeeIxs);
|
|
217
|
+
return priorityFeeIxs;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Overwrite blockhash and rebuild transaction
|
|
222
|
+
*
|
|
223
|
+
* @param blockhash
|
|
224
|
+
* @param lastValidBlockHeight
|
|
225
|
+
*/
|
|
226
|
+
setBlockhash(blockhash, lastValidBlockHeight) {
|
|
227
|
+
if (blockhash !== null) {
|
|
228
|
+
this.latestBlockhash.blockhash = blockhash;
|
|
229
|
+
}
|
|
230
|
+
if (lastValidBlockHeight !== null) {
|
|
231
|
+
this.latestBlockhash.lastValidBlockHeight = lastValidBlockHeight;
|
|
232
|
+
}
|
|
233
|
+
this.buildTransaction({
|
|
234
|
+
blockhash: this.latestBlockhash.blockhash,
|
|
235
|
+
lastValidBlockHeight: this.latestBlockhash.lastValidBlockHeight
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.Transaction2 = Transaction2;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/// <reference types="@meteora-ag/dlmm/node_modules/@solana/web3.js" />
|
|
2
|
+
import * as client from "@hawksightco/swagger-client";
|
|
3
|
+
import * as web3 from "@solana/web3.js";
|
|
4
|
+
import { GeneralUtility } from "./GeneralUtility";
|
|
5
|
+
export type SimulatedTransactionResponse = {
|
|
6
|
+
err: web3.TransactionError | string | null;
|
|
7
|
+
logs: Array<string> | null;
|
|
8
|
+
accounts?: (web3.SimulatedTransactionAccountInfo | null)[] | null;
|
|
9
|
+
unitsConsumed: number;
|
|
10
|
+
returnData?: web3.TransactionReturnData | null;
|
|
11
|
+
};
|
|
12
|
+
export type TransactionMetadataResponse = {
|
|
13
|
+
description: string;
|
|
14
|
+
estimatedFeeInSOL: string;
|
|
15
|
+
addressLookupTableAddresses: string[];
|
|
16
|
+
computeBudgetInstructions: Instruction[];
|
|
17
|
+
mainInstructions: Instruction[];
|
|
18
|
+
payer: string;
|
|
19
|
+
signature: string;
|
|
20
|
+
};
|
|
21
|
+
export type Instruction = {
|
|
22
|
+
accounts: {
|
|
23
|
+
isSigner: boolean;
|
|
24
|
+
isWritable: boolean;
|
|
25
|
+
pubkey: string;
|
|
26
|
+
}[];
|
|
27
|
+
data: string;
|
|
28
|
+
programId: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Represents a transaction object in Solana using the web3.js library.
|
|
32
|
+
* This class encapsulates the logic for creating, signing, and verifying signatures of transactions.
|
|
33
|
+
*/
|
|
34
|
+
export declare class Transaction3 {
|
|
35
|
+
readonly txMetadataResponse: TransactionMetadataResponse;
|
|
36
|
+
readonly payerKey: web3.PublicKey;
|
|
37
|
+
protected latestBlockhash: {
|
|
38
|
+
blockhash: string;
|
|
39
|
+
lastValidBlockHeight: number;
|
|
40
|
+
};
|
|
41
|
+
readonly alts: web3.AddressLookupTableAccount[];
|
|
42
|
+
protected generalUtility: GeneralUtility;
|
|
43
|
+
/** Compiled TransactionMessage which includes payer, instructions, and recent blockhash */
|
|
44
|
+
protected _txMessage: web3.TransactionMessage;
|
|
45
|
+
get txMessage(): web3.TransactionMessage;
|
|
46
|
+
/** Versioned transaction built from the transaction message */
|
|
47
|
+
protected _versionedTransaction: web3.VersionedTransaction;
|
|
48
|
+
get versionedTransaction(): web3.VersionedTransaction;
|
|
49
|
+
/** A map indicating whether each required signer has signed the transaction */
|
|
50
|
+
readonly requiredSigners: Record<string, boolean>;
|
|
51
|
+
/** Estimated fee in SOL for priority fee when addPriorityFee() method is called. */
|
|
52
|
+
protected _priorityFeeEstimate: string;
|
|
53
|
+
get priorityFeeEstimate(): string;
|
|
54
|
+
/** The blockhash of a recent ledger entry */
|
|
55
|
+
get recentBlockhash(): string;
|
|
56
|
+
/** Array of TransactionInstruction to be executed in this transaction */
|
|
57
|
+
protected _instructions: web3.TransactionInstruction[];
|
|
58
|
+
get instructions(): web3.TransactionInstruction[];
|
|
59
|
+
/** last valid block height */
|
|
60
|
+
get lastValidBlockHeight(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Constructs a new Transaction object.
|
|
63
|
+
*
|
|
64
|
+
* @param payerKey PublicKey of the transaction payer
|
|
65
|
+
* @param instructions Array of TransactionInstruction to be executed in this transaction
|
|
66
|
+
* @param recentBlockhash The blockhash of a recent ledger entry
|
|
67
|
+
* @param alts Address lookup tables that optimize account address storage
|
|
68
|
+
*/
|
|
69
|
+
constructor(txMetadataResponse: TransactionMetadataResponse, payerKey: web3.PublicKey, latestBlockhash: {
|
|
70
|
+
blockhash: string;
|
|
71
|
+
lastValidBlockHeight: number;
|
|
72
|
+
}, alts: web3.AddressLookupTableAccount[], generalUtility: GeneralUtility, _mainIxs?: web3.TransactionInstruction[]);
|
|
73
|
+
/**
|
|
74
|
+
* Signs the transaction with provided signers.
|
|
75
|
+
*
|
|
76
|
+
* @param signers Array of Signer objects whose private keys will be used to sign the transaction.
|
|
77
|
+
* @param idempotent Boolean indicating whether signing should be idempotent (default is false).
|
|
78
|
+
* @throws Error if a signer is not required or has already signed the transaction when not idempotent.
|
|
79
|
+
*/
|
|
80
|
+
sign(signers: web3.Signer[], idempotent?: boolean): void;
|
|
81
|
+
/**
|
|
82
|
+
* Add a signature on the transaction with provided signature.
|
|
83
|
+
*
|
|
84
|
+
* @param publicKey The public key of the signer
|
|
85
|
+
* @param signature A signature of the signed transaction
|
|
86
|
+
* @throws Error if a signer is not required or has already signed the transaction.
|
|
87
|
+
*/
|
|
88
|
+
addSignature(publicKey: web3.PublicKey, signature: Uint8Array): void;
|
|
89
|
+
/**
|
|
90
|
+
* Checks if all required signers have signed the transaction.
|
|
91
|
+
*
|
|
92
|
+
* @returns Boolean indicating whether all required signers have signed.
|
|
93
|
+
*/
|
|
94
|
+
isSignedByRequiredSigners(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Add priority fee instructions (compute budget) with a fixed priority fee.
|
|
97
|
+
*
|
|
98
|
+
* This method adds priority fee instructions to the transaction based on a fixed priority fee.
|
|
99
|
+
*
|
|
100
|
+
* @param connection - The connection to the Solana cluster.
|
|
101
|
+
* @param computeUnitLimit - The limit on the number of compute units.
|
|
102
|
+
* @param fixedPriority - Set to true to indicate a fixed priority fee.
|
|
103
|
+
* @param fixedPriorityFee - The fixed priority fee in lamports.
|
|
104
|
+
* @returns An array of transaction instructions.
|
|
105
|
+
*/
|
|
106
|
+
addPriorityFeeIx(connection: web3.Connection, computeUnitLimit: number, fixedPriority: true, fixedPriorityFee: number): Promise<web3.TransactionInstruction[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Add priority fee instructions (compute budget) with a variable priority defined by Helius.
|
|
109
|
+
*
|
|
110
|
+
* This method adds priority fee instructions to the transaction based on the specified
|
|
111
|
+
* priority level and compute unit limit. It ensures that the total fee does not exceed
|
|
112
|
+
* the specified maximum priority fee (in SOL) if provided.
|
|
113
|
+
*
|
|
114
|
+
* @param connection - The connection to the Solana cluster.
|
|
115
|
+
* @param computeUnitLimit - The limit on the number of compute units.
|
|
116
|
+
* @param fixedPriority - Set to false to indicate a variable priority fee.
|
|
117
|
+
* @param priorityLevel - The priority level for the fee estimation.
|
|
118
|
+
* @param maxPriorityFee - The maximum priority fee in SOL (optional).
|
|
119
|
+
* @returns An array of transaction instructions.
|
|
120
|
+
*/
|
|
121
|
+
addPriorityFeeIx(connection: web3.Connection, computeUnitLimit: number, fixedPriority: false, priorityLevel: client.PriorityLevel, maxPriorityFee?: number): Promise<web3.TransactionInstruction[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Gets the compute unit limit from a transaction simulation.
|
|
124
|
+
*
|
|
125
|
+
* This function simulates a transaction and calculates the compute unit limit
|
|
126
|
+
* based on the simulation results. If an additional compute limit is provided,
|
|
127
|
+
* it is added to the units consumed in the simulation. Otherwise, the units
|
|
128
|
+
* consumed are increased by 10%.
|
|
129
|
+
*
|
|
130
|
+
* @param {web3.Connection} connection - The connection object to the Solana cluster.
|
|
131
|
+
* @param {number} [additionalComputeLimit] - Optional additional compute limit to add to the units consumed.
|
|
132
|
+
* @returns {Promise<number>} - A promise that resolves to the total compute unit limit.
|
|
133
|
+
* @throws {Error} - Throws an error if the transaction simulation fails.
|
|
134
|
+
*/
|
|
135
|
+
getComputeUnitLimit(connection: web3.Connection, additionalComputeLimit?: number): Promise<number>;
|
|
136
|
+
/**
|
|
137
|
+
* Simulate transaction
|
|
138
|
+
*
|
|
139
|
+
* @param connection
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
simulateTransaction(connection: web3.Connection, signers?: web3.Keypair[]): Promise<SimulatedTransactionResponse>;
|
|
143
|
+
/**
|
|
144
|
+
* Builds transaction object
|
|
145
|
+
*/
|
|
146
|
+
buildTransaction(latestBlockhash: web3.BlockhashWithExpiryBlockHeight): [web3.TransactionMessage, web3.VersionedTransaction];
|
|
147
|
+
/**
|
|
148
|
+
* Gathers the public keys of all parties required to sign the transaction.
|
|
149
|
+
*
|
|
150
|
+
* @returns A record of signer public keys mapped to a boolean indicating whether they have signed.
|
|
151
|
+
*/
|
|
152
|
+
protected getRequiredSigners(): Record<string, boolean>;
|
|
153
|
+
/**
|
|
154
|
+
* Find setComputeUnitLimit index within the instructions
|
|
155
|
+
*/
|
|
156
|
+
protected findSetComputeUnitLimitIndex(instructions?: web3.TransactionInstruction[]): number;
|
|
157
|
+
/**
|
|
158
|
+
* Find setComputeUnitPrice index within the instructions
|
|
159
|
+
*/
|
|
160
|
+
protected findSetComputeUnitPriceIndex(instructions?: web3.TransactionInstruction[]): number;
|
|
161
|
+
/**
|
|
162
|
+
* Remove priority fee instructions
|
|
163
|
+
*/
|
|
164
|
+
protected removePriorityFeeIxs(): void;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=Transaction3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transaction3.d.ts","sourceRoot":"","sources":["../../../src/classes/Transaction3.ts"],"names":[],"mappings":";AAYA,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AACtD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,MAAM,4BAA4B,GAAG;IACzC,GAAG,EAAE,IAAI,CAAC,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3C,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,+BAA+B,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;IAClE,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,2BAA2B,EAAE,MAAM,EAAE,CAAC;IACtC,yBAAyB,EAAE,WAAW,EAAE,CAAC;IACzC,gBAAgB,EAAE,WAAW,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,E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