@hawksightco/hawk-sdk 0.0.70 → 1.0.0

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.
Files changed (50) hide show
  1. package/dist/src/addresses.d.ts +18 -0
  2. package/dist/src/addresses.d.ts.map +1 -0
  3. package/dist/src/addresses.js +54 -0
  4. package/dist/src/anchor.d.ts +16 -0
  5. package/dist/src/anchor.d.ts.map +1 -0
  6. package/dist/src/anchor.js +58 -0
  7. package/dist/src/classes/CreateTxMetadata.d.ts +1 -0
  8. package/dist/src/classes/CreateTxMetadata.d.ts.map +1 -1
  9. package/dist/src/classes/General.d.ts +1 -0
  10. package/dist/src/classes/General.d.ts.map +1 -1
  11. package/dist/src/classes/GeneralUtility.d.ts +10 -0
  12. package/dist/src/classes/GeneralUtility.d.ts.map +1 -1
  13. package/dist/src/classes/GeneralUtility.js +18 -0
  14. package/dist/src/classes/HawkAPI.d.ts.map +1 -1
  15. package/dist/src/classes/Transaction.d.ts +1 -0
  16. package/dist/src/classes/Transaction.d.ts.map +1 -1
  17. package/dist/src/classes/Transactions.d.ts +108 -0
  18. package/dist/src/classes/Transactions.d.ts.map +1 -0
  19. package/dist/src/classes/Transactions.js +742 -0
  20. package/dist/src/classes/TxGenerator.d.ts +1 -45
  21. package/dist/src/classes/TxGenerator.d.ts.map +1 -1
  22. package/dist/src/classes/TxGenerator.js +211 -115
  23. package/dist/src/classes/TxGeneratorAutomations.d.ts +1 -0
  24. package/dist/src/classes/TxGeneratorAutomations.d.ts.map +1 -1
  25. package/dist/src/classes/TxGeneratorAutomations.js +7 -0
  26. package/dist/src/errors.d.ts +3 -0
  27. package/dist/src/errors.d.ts.map +1 -0
  28. package/dist/src/errors.js +6 -0
  29. package/dist/src/functions.d.ts +203 -1
  30. package/dist/src/functions.d.ts.map +1 -1
  31. package/dist/src/functions.js +411 -1
  32. package/dist/src/hawksight.d.ts +17 -0
  33. package/dist/src/hawksight.d.ts.map +1 -0
  34. package/dist/src/hawksight.js +128 -0
  35. package/dist/src/hsToMeteora.d.ts +18 -0
  36. package/dist/src/hsToMeteora.d.ts.map +1 -0
  37. package/dist/src/hsToMeteora.js +1142 -0
  38. package/dist/src/idl/iyf-extension-idl.d.ts +7483 -0
  39. package/dist/src/idl/iyf-extension-idl.d.ts.map +1 -0
  40. package/dist/src/idl/iyf-extension-idl.js +7484 -0
  41. package/dist/src/idl/iyf-main-idl.d.ts +6840 -0
  42. package/dist/src/idl/iyf-main-idl.d.ts.map +1 -0
  43. package/dist/src/idl/iyf-main-idl.js +6841 -0
  44. package/dist/src/meteora.d.ts +304 -0
  45. package/dist/src/meteora.d.ts.map +1 -0
  46. package/dist/src/meteora.js +615 -0
  47. package/dist/src/types.d.ts +138 -18
  48. package/dist/src/types.d.ts.map +1 -1
  49. package/dist/src/types.js +11 -1
  50. package/package.json +8 -3
@@ -0,0 +1,1142 @@
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.meteoraToHawksightAutomationIxs = exports.meteoraToHawksight = void 0;
36
+ const addresses_1 = require("./addresses");
37
+ const anchor_1 = require("./anchor");
38
+ const bn_js_1 = require("bn.js");
39
+ const util = __importStar(require("./functions"));
40
+ /**
41
+ * Convert listed meteora instruction to generalized hawksight meteora cpi
42
+ *
43
+ * @param params
44
+ * @returns
45
+ */
46
+ function meteoraToHawksight(_a) {
47
+ return __awaiter(this, arguments, void 0, function* ({ ixs, userPda, authority }) {
48
+ return ixs.map((ix) => {
49
+ ix = HawksightMeteoraCpi.factory(ix, userPda, authority).getInstruction();
50
+ if (ix.programId.toString() === addresses_1.ASSOCIATED_TOKEN_PROGRAM.toString() && ix.keys.length === 6) {
51
+ ix.keys[0] = Object.assign(Object.assign({}, ix.keys[0]), { pubkey: authority });
52
+ }
53
+ return ix;
54
+ });
55
+ });
56
+ }
57
+ exports.meteoraToHawksight = meteoraToHawksight;
58
+ /**
59
+ * Convert listed meteora instruction to hawksight meteora automation cpi
60
+ *
61
+ * @param params
62
+ * @returns
63
+ */
64
+ function meteoraToHawksightAutomationIxs(_a) {
65
+ return __awaiter(this, arguments, void 0, function* ({ ixs, userPda, authority }) {
66
+ const _ixs = [];
67
+ for (const ix of ixs) {
68
+ const _ix = yield HawksightMeteoraAutomationCpi.factory(ix, userPda, authority).getInstruction();
69
+ if (ix.programId.toString() === addresses_1.ASSOCIATED_TOKEN_PROGRAM.toString() && ix.keys.length === 6) {
70
+ ix.keys[0] = Object.assign(Object.assign({}, ix.keys[0]), { pubkey: addresses_1.HS_AUTHORITY });
71
+ }
72
+ _ixs.push(_ix);
73
+ }
74
+ return _ixs;
75
+ });
76
+ }
77
+ exports.meteoraToHawksightAutomationIxs = meteoraToHawksightAutomationIxs;
78
+ /**
79
+ * Abstract base class `HawksightMeteoraCpi` for handling and chaining transaction instructions.
80
+ * This class provides a framework for creating and linking complex transaction processes in a blockchain environment.
81
+ *
82
+ * Attributes:
83
+ * - `ix`: web3.TransactionInstruction - The transaction instruction associated with this CPI.
84
+ * - `userPda`: web3.PublicKey - The public key of the user's program-derived address (PDA).
85
+ * - `authority`: web3.PublicKey - The public key of the authority that can sign transactions.
86
+ * - `_next`: HawksightMeteoraCpi | undefined - Pointer to the next CPI in the chain.
87
+ * - `sighash`: Buffer - A buffer representing the signature hash used for identifying and validating instructions.
88
+ *
89
+ * Methods:
90
+ * - `constructor(ix, userPda, authority, sighash)`: Constructs an instance of the HawksightMeteoraCpi.
91
+ * - `factory(ix, userPda, authority)`: Static factory method to create a chain of CPIs starting with `InitializePosition` and linking subsequent operations.
92
+ * - `getInstruction()`: Returns the modified transaction instruction after processing by matching CPIs in the chain.
93
+ * - `replace()`: Abstract method to be implemented by subclasses to modify the transaction keys or other properties.
94
+ * - `next(next)`: Chains the current CPI instance to the next one.
95
+ * - `sighashMatch()`: Checks if the current transaction instruction matches the provided sighash and recurses through the chain if not.
96
+ * - `programIdMatch()`: Checks if the program ID of the transaction matches the expected ID.
97
+ * - `addHawksightCpi()`: Modifies the transaction instruction to include specific Hawksight CPI details.
98
+ *
99
+ * Usage:
100
+ * This class is intended to be extended by specific CPI implementations like `InitializePosition`, each implementing their own `replace()` method to handle specific transaction modifications.
101
+ */
102
+ class HawksightMeteoraCpi {
103
+ /**
104
+ * Constructs an instance of HawksightMeteoraCpi with the necessary transaction parameters.
105
+ * @param ix The core transaction instruction.
106
+ * @param userPda The user's program-derived address (PDA) as a public key.
107
+ * @param authority The authority public key that has signing capabilities over the transaction.
108
+ * @param sighash A Buffer containing the sighash used for matching the transaction instruction.
109
+ */
110
+ constructor(ix, userPda, authority, sighash) {
111
+ this.ix = ix;
112
+ this.userPda = userPda;
113
+ this.authority = authority;
114
+ this.sighash = sighash;
115
+ }
116
+ /**
117
+ * Factory method to create and link a chain of CPIs starting from `InitializePosition`.
118
+ * Subsequent CPIs include operations like adding liquidity, removing liquidity, claiming fees, and rewards, and closing the position.
119
+ * @param ix The initial transaction instruction.
120
+ * @param userPda The user's public key.
121
+ * @param authority The authority public key.
122
+ * @returns The first CPI in the chain.
123
+ */
124
+ static factory(ix, userPda, authority) {
125
+ const chain = new InitializePosition(ix, userPda, authority);
126
+ chain
127
+ .next(new AddLiquidityByWeight(ix, userPda, authority))
128
+ .next(new AddLiquidityOneSide(ix, userPda, authority))
129
+ .next(new AddLiquidityByStrategy(ix, userPda, authority))
130
+ .next(new AddLiquidityByStrategyOneSide(ix, userPda, authority))
131
+ .next(new RemoveLiquidity(ix, userPda, authority))
132
+ .next(new RemoveLiquidityByRange(ix, userPda, authority))
133
+ .next(new ClaimFee(ix, userPda, authority))
134
+ .next(new ClaimReward(ix, userPda, authority))
135
+ .next(new ClosePosition(ix, userPda, authority));
136
+ return chain;
137
+ }
138
+ /**
139
+ * Retrieves and possibly modifies the transaction instruction based on matching conditions.
140
+ * If a matching CPI is found in the chain, it performs modifications and returns the updated instruction.
141
+ * @returns The (possibly modified) transaction instruction.
142
+ */
143
+ getInstruction() {
144
+ const matchInstance = this.sighashMatch();
145
+ if (this.programIdMatch() && matchInstance !== undefined) {
146
+ matchInstance.replace();
147
+ matchInstance.addHawksightCpi();
148
+ return this.ix;
149
+ }
150
+ return this.ix;
151
+ }
152
+ /**
153
+ * Adds a subsequent CPI to the chain.
154
+ * @param next The next CPI object to link.
155
+ * @returns The added CPI object, allowing for method chaining.
156
+ */
157
+ next(next) {
158
+ this._next = next;
159
+ return this._next;
160
+ }
161
+ /**
162
+ * Recursively checks this CPI and subsequent ones for a sighash match in the transaction data.
163
+ * @returns The first CPI instance in the chain that matches the sighash, or undefined if no match is found.
164
+ */
165
+ sighashMatch() {
166
+ var _a, _b;
167
+ try {
168
+ const match = util.sighashMatch(this.ix.data, this.sighash);
169
+ if (match) {
170
+ return this;
171
+ }
172
+ else if (this._next !== undefined) {
173
+ return (_a = this._next) === null || _a === void 0 ? void 0 : _a.sighashMatch();
174
+ }
175
+ }
176
+ catch (_c) {
177
+ if (this._next !== undefined) {
178
+ return (_b = this._next) === null || _b === void 0 ? void 0 : _b.sighashMatch();
179
+ }
180
+ }
181
+ return undefined;
182
+ }
183
+ /**
184
+ * Checks if the program ID of the transaction instruction matches the expected program ID.
185
+ * @returns True if the program ID matches, otherwise false.
186
+ */
187
+ programIdMatch() {
188
+ return this.ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
189
+ }
190
+ /**
191
+ * Modifies the transaction instruction to include specific Hawksight CPI details.
192
+ * Prepares the instruction for execution by adjusting its program ID and data based on Hawksight criteria.
193
+ */
194
+ addHawksightCpi() {
195
+ const METEORA_PROGRAM = addresses_1.METEORA_DLMM_PROGRAM;
196
+ const size = Buffer.alloc(4);
197
+ size.writeUint32LE(this.ix.data.length);
198
+ const data = Buffer.concat([util.sighash('meteora_dynamic_cpi'), size, this.ix.data]);
199
+ this.ix.programId = addresses_1.IYF_MAIN;
200
+ this.ix.data = data;
201
+ this.ix.keys.unshift(...[
202
+ { pubkey: this.userPda, isSigner: false, isWritable: false },
203
+ { pubkey: this.authority, isSigner: true, isWritable: true },
204
+ { pubkey: METEORA_PROGRAM, isSigner: false, isWritable: false },
205
+ ]);
206
+ }
207
+ }
208
+ /**
209
+ * Handles the initialization of a position in a blockchain transaction.
210
+ * This class extends the HawksightMeteoraCpi and provides specific logic to modify the transaction instruction for position initialization.
211
+ */
212
+ class InitializePosition extends HawksightMeteoraCpi {
213
+ /**
214
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
215
+ *
216
+ * @param ix The core transaction instruction.
217
+ * @param userPda The user's program-derived address (PDA) as a public key.
218
+ * @param authority The authority public key that has signing capabilities over the transaction.
219
+ */
220
+ constructor(ix, userPda, authority) {
221
+ super(ix, userPda, authority, util.sighash("InitializePosition"));
222
+ }
223
+ /**
224
+ * Modifies the transaction keys to set the correct public keys for an initial position setup.
225
+ */
226
+ replace() {
227
+ this.ix.keys[0].pubkey = this.authority;
228
+ this.ix.keys[3].pubkey = this.userPda;
229
+ this.ix.keys[3].isSigner = false;
230
+ }
231
+ }
232
+ /**
233
+ * Adjusts transaction instructions to add liquidity based on a specific weight in a financial application.
234
+ * This class is designed for blockchain operations that manage liquidity pools.
235
+ */
236
+ class AddLiquidityByWeight extends HawksightMeteoraCpi {
237
+ /**
238
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
239
+ *
240
+ * @param ix The core transaction instruction.
241
+ * @param userPda The user's program-derived address (PDA) as a public key.
242
+ * @param authority The authority public key that has signing capabilities over the transaction.
243
+ */
244
+ constructor(ix, userPda, authority) {
245
+ super(ix, userPda, authority, util.sighash("AddLiquidityByWeight"));
246
+ }
247
+ /**
248
+ * Alters the transaction keys for adding liquidity, ensuring the user's PDA is correctly configured.
249
+ */
250
+ replace() {
251
+ this.ix.keys[11].pubkey = this.userPda;
252
+ this.ix.keys[11].isSigner = false;
253
+ }
254
+ }
255
+ /**
256
+ * Adjusts transaction instructions to add liquidity based on a specific weight in a financial application.
257
+ * This class is designed for blockchain operations that manage liquidity pools.
258
+ */
259
+ class AddLiquidityByStrategy extends HawksightMeteoraCpi {
260
+ /**
261
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
262
+ *
263
+ * @param ix The core transaction instruction.
264
+ * @param userPda The user's program-derived address (PDA) as a public key.
265
+ * @param authority The authority public key that has signing capabilities over the transaction.
266
+ */
267
+ constructor(ix, userPda, authority) {
268
+ super(ix, userPda, authority, util.sighash("AddLiquidityByStrategy"));
269
+ }
270
+ /**
271
+ * Alters the transaction keys for adding liquidity, ensuring the user's PDA is correctly configured.
272
+ */
273
+ replace() {
274
+ this.ix.keys[11].pubkey = this.userPda;
275
+ this.ix.keys[11].isSigner = false;
276
+ }
277
+ }
278
+ /**
279
+ * Adjusts transaction instructions to add liquidity based on a specific weight in a financial application.
280
+ * This class is designed for blockchain operations that manage liquidity pools.
281
+ */
282
+ class AddLiquidityOneSide extends HawksightMeteoraCpi {
283
+ /**
284
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
285
+ *
286
+ * @param ix The core transaction instruction.
287
+ * @param userPda The user's program-derived address (PDA) as a public key.
288
+ * @param authority The authority public key that has signing capabilities over the transaction.
289
+ */
290
+ constructor(ix, userPda, authority) {
291
+ super(ix, userPda, authority, util.sighash("AddLiquidityOneSide"));
292
+ }
293
+ /**
294
+ * Alters the transaction keys for adding liquidity, ensuring the user's PDA is correctly configured.
295
+ */
296
+ replace() {
297
+ this.ix.keys[8].pubkey = this.userPda;
298
+ this.ix.keys[8].isSigner = false;
299
+ }
300
+ }
301
+ /**
302
+ * Adjusts transaction instructions to add liquidity based on a specific weight in a financial application.
303
+ * This class is designed for blockchain operations that manage liquidity pools.
304
+ */
305
+ class AddLiquidityByStrategyOneSide extends HawksightMeteoraCpi {
306
+ /**
307
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
308
+ *
309
+ * @param ix The core transaction instruction.
310
+ * @param userPda The user's program-derived address (PDA) as a public key.
311
+ * @param authority The authority public key that has signing capabilities over the transaction.
312
+ */
313
+ constructor(ix, userPda, authority) {
314
+ super(ix, userPda, authority, util.sighash("AddLiquidityByStrategyOneSide"));
315
+ }
316
+ /**
317
+ * Alters the transaction keys for adding liquidity, ensuring the user's PDA is correctly configured.
318
+ */
319
+ replace() {
320
+ this.ix.keys[8].pubkey = this.userPda;
321
+ this.ix.keys[8].isSigner = false;
322
+ }
323
+ }
324
+ /**
325
+ * Facilitates the removal of liquidity from a blockchain-based financial system.
326
+ */
327
+ class RemoveLiquidity extends HawksightMeteoraCpi {
328
+ /**
329
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
330
+ *
331
+ * @param ix The core transaction instruction.
332
+ * @param userPda The user's program-derived address (PDA) as a public key.
333
+ * @param authority The authority public key that has signing capabilities over the transaction.
334
+ */
335
+ constructor(ix, userPda, authority, sighash = util.sighash("RemoveLiquidity")) {
336
+ super(ix, userPda, authority, sighash);
337
+ }
338
+ /**
339
+ * Customizes the transaction keys to correctly handle the removal of liquidity.
340
+ */
341
+ replace() {
342
+ this.ix.keys[11].pubkey = this.userPda;
343
+ this.ix.keys[11].isSigner = false;
344
+ }
345
+ }
346
+ /**
347
+ * Facilitates the removal of liquidity from a blockchain-based financial system.
348
+ */
349
+ class RemoveLiquidityByRange extends RemoveLiquidity {
350
+ /**
351
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
352
+ *
353
+ * @param ix The core transaction instruction.
354
+ * @param userPda The user's program-derived address (PDA) as a public key.
355
+ * @param authority The authority public key that has signing capabilities over the transaction.
356
+ */
357
+ constructor(ix, userPda, authority) {
358
+ super(ix, userPda, authority, util.sighash("RemoveLiquidityByRange"));
359
+ }
360
+ }
361
+ /**
362
+ * Enables the claiming of fees generated from transactions within a blockchain protocol.
363
+ */
364
+ class ClaimFee extends HawksightMeteoraCpi {
365
+ /**
366
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
367
+ *
368
+ * @param ix The core transaction instruction.
369
+ * @param userPda The user's program-derived address (PDA) as a public key.
370
+ * @param authority The authority public key that has signing capabilities over the transaction.
371
+ */
372
+ constructor(ix, userPda, authority) {
373
+ super(ix, userPda, authority, util.sighash("ClaimFee"));
374
+ }
375
+ /**
376
+ * Modifies transaction keys for the purpose of claiming transaction fees.
377
+ */
378
+ replace() {
379
+ this.ix.keys[4].pubkey = this.userPda;
380
+ this.ix.keys[4].isSigner = false;
381
+ }
382
+ }
383
+ /**
384
+ * Manages the claiming of rewards in blockchain operations, typically associated with staking or similar activities.
385
+ */
386
+ class ClaimReward extends HawksightMeteoraCpi {
387
+ /**
388
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
389
+ *
390
+ * @param ix The core transaction instruction.
391
+ * @param userPda The user's program-derived address (PDA) as a public key.
392
+ * @param authority The authority public key that has signing capabilities over the transaction.
393
+ */
394
+ constructor(ix, userPda, authority) {
395
+ super(ix, userPda, authority, util.sighash("ClaimReward"));
396
+ }
397
+ /**
398
+ * Adjusts transaction keys to facilitate the claiming of rewards.
399
+ */
400
+ replace() {
401
+ this.ix.keys[4].pubkey = this.userPda;
402
+ this.ix.keys[4].isSigner = false;
403
+ }
404
+ }
405
+ /**
406
+ * Handles the closure of a position within a blockchain transaction.
407
+ */
408
+ class ClosePosition extends HawksightMeteoraCpi {
409
+ /**
410
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
411
+ *
412
+ * @param ix The core transaction instruction.
413
+ * @param userPda The user's program-derived address (PDA) as a public key.
414
+ * @param authority The authority public key that has signing capabilities over the transaction.
415
+ */
416
+ constructor(ix, userPda, authority) {
417
+ super(ix, userPda, authority, util.sighash("ClosePosition"));
418
+ }
419
+ /**
420
+ * Customizes the transaction keys to properly close a position, ensuring all relevant keys are set correctly.
421
+ */
422
+ replace() {
423
+ this.ix.keys[4].pubkey = this.userPda;
424
+ this.ix.keys[4].isSigner = false;
425
+ this.ix.keys[5].pubkey = this.authority;
426
+ }
427
+ }
428
+ class HawksightMeteoraAutomationCpi {
429
+ /**
430
+ * Instruction
431
+ */
432
+ get ix() { return this._ix; }
433
+ /**
434
+ * Constructs an instance of HawksightMeteoraCpi with the necessary transaction parameters.
435
+ *
436
+ * @param ix The core transaction instruction.
437
+ * @param userPda The user's program-derived address (PDA) as a public key.
438
+ * @param authority The authority public key that has signing capabilities over the transaction.
439
+ * @param sighash A Buffer containing the sighash used for matching the transaction instruction.
440
+ */
441
+ constructor(_ix, userPda, authority, sighash) {
442
+ this._ix = _ix;
443
+ this.userPda = userPda;
444
+ this.authority = authority;
445
+ this.sighash = sighash;
446
+ }
447
+ /**
448
+ * Factory method to create and link a chain of CPIs starting from `InitializePosition`.
449
+ * Subsequent CPIs include operations like adding liquidity, removing liquidity, claiming fees, and rewards, and closing the position.
450
+ * @param ix The initial transaction instruction.
451
+ * @param userPda The user's public key.
452
+ * @param authority The authority public key.
453
+ * @returns The first CPI in the chain.
454
+ */
455
+ static factory(ix, userPda, authority) {
456
+ const chain = new InitializePositionAutomation(ix, userPda, authority);
457
+ chain
458
+ .next(new AddLiquidityByWeightAutomation(ix, userPda, authority))
459
+ .next(new AddLiquidityOneSideAutomation(ix, userPda, authority))
460
+ .next(new RemoveLiquidityAutomation(ix, userPda, authority))
461
+ .next(new RemoveLiquidityByRangeAutomation(ix, userPda, authority))
462
+ .next(new ClaimFeeAutomation(ix, userPda, authority))
463
+ .next(new ClaimRewardAutomation(ix, userPda, authority))
464
+ .next(new ClosePositionAutomation(ix, userPda, authority));
465
+ return chain;
466
+ }
467
+ /**
468
+ * Retrieves and possibly modifies the transaction instruction based on matching conditions.
469
+ * If a matching CPI is found in the chain, it performs modifications and returns the updated instruction.
470
+ * @returns The (possibly modified) transaction instruction.
471
+ */
472
+ getInstruction() {
473
+ return __awaiter(this, void 0, void 0, function* () {
474
+ const matchInstance = this.sighashMatch();
475
+ if (this.programIdMatch() && matchInstance !== undefined) {
476
+ matchInstance.replace();
477
+ yield matchInstance.replaceCpi();
478
+ return matchInstance.ix;
479
+ }
480
+ return this.ix;
481
+ });
482
+ }
483
+ /**
484
+ * Adds a subsequent CPI to the chain.
485
+ * @param next The next CPI object to link.
486
+ * @returns The added CPI object, allowing for method chaining.
487
+ */
488
+ next(next) {
489
+ this._next = next;
490
+ return this._next;
491
+ }
492
+ /**
493
+ * Recursively checks this CPI and subsequent ones for a sighash match in the transaction data.
494
+ * @returns The first CPI instance in the chain that matches the sighash, or undefined if no match is found.
495
+ */
496
+ sighashMatch() {
497
+ try {
498
+ const match = util.sighashMatch(this.ix.data, this.sighash);
499
+ if (match) {
500
+ return this;
501
+ }
502
+ else if (this._next !== undefined) {
503
+ return this._next.sighashMatch();
504
+ }
505
+ }
506
+ catch (_a) {
507
+ if (this._next !== undefined) {
508
+ return this._next.sighashMatch();
509
+ }
510
+ }
511
+ return undefined;
512
+ }
513
+ /**
514
+ * Checks if the program ID of the transaction instruction matches the expected program ID.
515
+ * @returns True if the program ID matches, otherwise false.
516
+ */
517
+ programIdMatch() {
518
+ return this.ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
519
+ }
520
+ }
521
+ /**
522
+ * Handles the initialization of a position in a blockchain transaction.
523
+ * This class extends the HawksightMeteoraCpi and provides specific logic to modify the transaction instruction for position initialization.
524
+ */
525
+ class InitializePositionAutomation extends HawksightMeteoraAutomationCpi {
526
+ /**
527
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
528
+ *
529
+ * @param ix The core transaction instruction.
530
+ * @param userPda The user's program-derived address (PDA) as a public key.
531
+ * @param authority The authority public key that has signing capabilities over the transaction.
532
+ */
533
+ constructor(ix, userPda, authority) {
534
+ super(ix, userPda, authority, util.sighash("InitializePosition"));
535
+ }
536
+ /**
537
+ * Modifies the transaction keys to set the correct public keys for an initial position setup.
538
+ */
539
+ replace() {
540
+ this._ix.keys[0].pubkey = this.authority;
541
+ this._ix.keys[3].pubkey = this.userPda;
542
+ this._ix.keys[3].isSigner = false;
543
+ }
544
+ /**
545
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
546
+ */
547
+ replaceCpi() {
548
+ return __awaiter(this, void 0, void 0, function* () {
549
+ // Common parameters
550
+ const farm = addresses_1.USDC_FARM;
551
+ const userPda = this.userPda;
552
+ const authority = this.authority;
553
+ const iyfProgram = addresses_1.IYF_MAIN;
554
+ const hawksightAuthority = addresses_1.HS_AUTHORITY;
555
+ // Generate IX via extension contract
556
+ const initializePositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
557
+ .meteoraDlmmInitializePositionAutomation(this.ix.data.subarray(8))
558
+ .accounts({
559
+ farm,
560
+ userPda,
561
+ authority,
562
+ iyfProgram,
563
+ hawksightAuthority,
564
+ position: this.ix.keys[1].pubkey,
565
+ lbPair: this.ix.keys[2].pubkey,
566
+ systemProgram: this.ix.keys[4].pubkey,
567
+ rent: this.ix.keys[5].pubkey,
568
+ eventAuthority: this.ix.keys[6].pubkey,
569
+ meteoraDlmmProgram: this.ix.keys[7].pubkey,
570
+ }).instruction();
571
+ // Instruction via main hawksight contract
572
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
573
+ .iyfExtensionExecute(initializePositionIx.data)
574
+ .accounts({
575
+ farm,
576
+ userPda,
577
+ authority,
578
+ iyfProgram,
579
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
580
+ })
581
+ .remainingAccounts([
582
+ initializePositionIx.keys[4],
583
+ initializePositionIx.keys[5],
584
+ initializePositionIx.keys[6],
585
+ initializePositionIx.keys[7],
586
+ initializePositionIx.keys[8],
587
+ initializePositionIx.keys[9],
588
+ initializePositionIx.keys[10],
589
+ ])
590
+ .instruction();
591
+ // Override the instruction
592
+ this._ix = ix;
593
+ });
594
+ }
595
+ }
596
+ /**
597
+ * Adjusts transaction instructions to add liquidity based on a specific weight in a financial application.
598
+ * This class is designed for blockchain operations that manage liquidity pools.
599
+ */
600
+ class AddLiquidityByWeightAutomation extends HawksightMeteoraAutomationCpi {
601
+ /**
602
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
603
+ *
604
+ * @param ix The core transaction instruction.
605
+ * @param userPda The user's program-derived address (PDA) as a public key.
606
+ * @param authority The authority public key that has signing capabilities over the transaction.
607
+ */
608
+ constructor(ix, userPda, authority) {
609
+ super(ix, userPda, authority, util.sighash("AddLiquidityByStrategy"));
610
+ }
611
+ /**
612
+ * Alters the transaction keys for adding liquidity, ensuring the user's PDA is correctly configured.
613
+ */
614
+ replace() {
615
+ this._ix.keys[11].pubkey = this.userPda;
616
+ this._ix.keys[11].isSigner = false;
617
+ }
618
+ /**
619
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
620
+ */
621
+ replaceCpi() {
622
+ return __awaiter(this, void 0, void 0, function* () {
623
+ // Common parameters
624
+ const farm = addresses_1.USDC_FARM;
625
+ const userPda = this.userPda;
626
+ const authority = this.authority;
627
+ const iyfProgram = addresses_1.IYF_MAIN;
628
+ const hawksightAuthority = addresses_1.HS_AUTHORITY;
629
+ // Get token mints X and Y
630
+ const tokenXMint = this.ix.keys[7].pubkey;
631
+ const tokenYMint = this.ix.keys[8].pubkey;
632
+ // Generate IX via extension contract
633
+ const depositIx = yield anchor_1.Anchor.instance().iyfExtension.methods
634
+ .meteoraDlmmDepositAutomation(this.ix.data.subarray(8))
635
+ .accounts({
636
+ farm,
637
+ userPda,
638
+ authority,
639
+ iyfProgram,
640
+ hawksightAuthority,
641
+ position: this.ix.keys[0].pubkey,
642
+ lbPair: this.ix.keys[1].pubkey,
643
+ binArrayBitmapExtension: this.ix.keys[2].pubkey,
644
+ userTokenX: this.ix.keys[3].pubkey,
645
+ userTokenY: this.ix.keys[4].pubkey,
646
+ reserveX: this.ix.keys[5].pubkey,
647
+ reserveY: this.ix.keys[6].pubkey,
648
+ tokenXMint,
649
+ tokenYMint,
650
+ binArrayLower: this.ix.keys[9].pubkey,
651
+ binArrayUpper: this.ix.keys[10].pubkey,
652
+ tokenXProgram: this.ix.keys[12].pubkey,
653
+ tokenYProgram: this.ix.keys[13].pubkey,
654
+ eventAuthority: this.ix.keys[14].pubkey,
655
+ meteoraDlmmProgram: this.ix.keys[15].pubkey,
656
+ }).instruction();
657
+ // Instruction via main hawksight contract
658
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
659
+ .iyfExtensionExecute(depositIx.data)
660
+ .accounts({
661
+ farm,
662
+ userPda,
663
+ authority,
664
+ iyfProgram,
665
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
666
+ })
667
+ .remainingAccounts([
668
+ depositIx.keys[4],
669
+ depositIx.keys[5],
670
+ depositIx.keys[6],
671
+ depositIx.keys[7],
672
+ depositIx.keys[8],
673
+ depositIx.keys[9],
674
+ depositIx.keys[10],
675
+ depositIx.keys[11],
676
+ depositIx.keys[12],
677
+ depositIx.keys[13],
678
+ depositIx.keys[14],
679
+ depositIx.keys[15],
680
+ depositIx.keys[16],
681
+ depositIx.keys[17],
682
+ depositIx.keys[18],
683
+ depositIx.keys[19],
684
+ ])
685
+ .instruction();
686
+ // Override the instruction
687
+ this._ix = ix;
688
+ });
689
+ }
690
+ }
691
+ /**
692
+ * Adjusts transaction instructions to add liquidity based on a specific weight in a financial application.
693
+ * This class is designed for blockchain operations that manage liquidity pools.
694
+ */
695
+ class AddLiquidityOneSideAutomation extends HawksightMeteoraAutomationCpi {
696
+ /**
697
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
698
+ *
699
+ * @param ix The core transaction instruction.
700
+ * @param userPda The user's program-derived address (PDA) as a public key.
701
+ * @param authority The authority public key that has signing capabilities over the transaction.
702
+ */
703
+ constructor(ix, userPda, authority) {
704
+ super(ix, userPda, authority, util.sighash("AddLiquidityByStrategyOneSide"));
705
+ }
706
+ /**
707
+ * Alters the transaction keys for adding liquidity, ensuring the user's PDA is correctly configured.
708
+ */
709
+ replace() {
710
+ this._ix.keys[8].pubkey = this.userPda;
711
+ this._ix.keys[8].isSigner = false;
712
+ }
713
+ /**
714
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
715
+ */
716
+ replaceCpi() {
717
+ return __awaiter(this, void 0, void 0, function* () {
718
+ // Common parameters
719
+ const farm = addresses_1.USDC_FARM;
720
+ const userPda = this.userPda;
721
+ const authority = this.authority;
722
+ const iyfProgram = addresses_1.IYF_MAIN;
723
+ const hawksightAuthority = addresses_1.HS_AUTHORITY;
724
+ // Generate IX via extension contract
725
+ const depositIx = yield anchor_1.Anchor.instance().iyfExtension.methods
726
+ .meteoraDlmmOneSideDeposit(this.ix.data.subarray(8))
727
+ .accounts({
728
+ farm,
729
+ userPda,
730
+ authority,
731
+ iyfProgram,
732
+ hawksightAuthority,
733
+ position: this.ix.keys[0].pubkey,
734
+ lbPair: this.ix.keys[1].pubkey,
735
+ binArrayBitmapExtension: this.ix.keys[2].pubkey,
736
+ userToken: this.ix.keys[3].pubkey,
737
+ reserve: this.ix.keys[4].pubkey,
738
+ tokenMint: this.ix.keys[5].pubkey,
739
+ binArrayLower: this.ix.keys[6].pubkey,
740
+ binArrayUpper: this.ix.keys[7].pubkey,
741
+ tokenProgram: this.ix.keys[9].pubkey,
742
+ eventAuthority: this.ix.keys[10].pubkey,
743
+ meteoraDlmmProgram: this.ix.keys[11].pubkey,
744
+ }).instruction();
745
+ // Instruction via main hawksight contract
746
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
747
+ .iyfExtensionExecute(depositIx.data)
748
+ .accounts({
749
+ farm,
750
+ userPda,
751
+ authority,
752
+ iyfProgram,
753
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
754
+ })
755
+ .remainingAccounts([
756
+ depositIx.keys[4],
757
+ depositIx.keys[5],
758
+ depositIx.keys[6],
759
+ depositIx.keys[7],
760
+ depositIx.keys[8],
761
+ depositIx.keys[9],
762
+ depositIx.keys[10],
763
+ depositIx.keys[11],
764
+ depositIx.keys[12],
765
+ depositIx.keys[13],
766
+ depositIx.keys[14],
767
+ depositIx.keys[15],
768
+ ])
769
+ .instruction();
770
+ // Override the instruction
771
+ this._ix = ix;
772
+ });
773
+ }
774
+ }
775
+ /**
776
+ * Facilitates the removal of liquidity from a blockchain-based financial system.
777
+ */
778
+ class RemoveLiquidityAutomation extends HawksightMeteoraAutomationCpi {
779
+ /**
780
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
781
+ *
782
+ * @param ix The core transaction instruction.
783
+ * @param userPda The user's program-derived address (PDA) as a public key.
784
+ * @param authority The authority public key that has signing capabilities over the transaction.
785
+ */
786
+ constructor(ix, userPda, authority, sighash = util.sighash("RemoveLiquidity")) {
787
+ super(ix, userPda, authority, sighash);
788
+ }
789
+ /**
790
+ * Customizes the transaction keys to correctly handle the removal of liquidity.
791
+ */
792
+ replace() {
793
+ this._ix.keys[11].pubkey = this.userPda;
794
+ this._ix.keys[11].isSigner = false;
795
+ }
796
+ /**
797
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
798
+ */
799
+ replaceCpi() {
800
+ return __awaiter(this, void 0, void 0, function* () {
801
+ // Common parameters
802
+ const farm = addresses_1.USDC_FARM;
803
+ const userPda = this.userPda;
804
+ const authority = this.authority;
805
+ const iyfProgram = addresses_1.IYF_MAIN;
806
+ const hawksightAuthority = addresses_1.HS_AUTHORITY;
807
+ // Get token mints X and Y
808
+ const tokenXMint = this.ix.keys[7].pubkey;
809
+ const tokenYMint = this.ix.keys[8].pubkey;
810
+ // Generate IX via extension contract
811
+ const withdrawIx = yield anchor_1.Anchor.instance().iyfExtension.methods
812
+ .meteoraDlmmWithdrawAutomation(this.ix.data)
813
+ .accounts({
814
+ farm,
815
+ userPda,
816
+ authority,
817
+ iyfProgram,
818
+ hawksightAuthority,
819
+ position: this.ix.keys[0].pubkey,
820
+ lbPair: this.ix.keys[1].pubkey,
821
+ binArrayBitmapExtension: this.ix.keys[2].pubkey,
822
+ userTokenX: this.ix.keys[3].pubkey,
823
+ userTokenY: this.ix.keys[4].pubkey,
824
+ reserveX: this.ix.keys[5].pubkey,
825
+ reserveY: this.ix.keys[6].pubkey,
826
+ tokenXMint,
827
+ tokenYMint,
828
+ binArrayLower: this.ix.keys[9].pubkey,
829
+ binArrayUpper: this.ix.keys[10].pubkey,
830
+ tokenXProgram: this.ix.keys[12].pubkey,
831
+ tokenYProgram: this.ix.keys[13].pubkey,
832
+ eventAuthority: this.ix.keys[14].pubkey,
833
+ meteoraDlmmProgram: this.ix.keys[15].pubkey,
834
+ }).instruction();
835
+ // Instruction via main hawksight contract
836
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
837
+ .iyfExtensionExecute(withdrawIx.data)
838
+ .accounts({
839
+ farm,
840
+ userPda,
841
+ authority,
842
+ iyfProgram,
843
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
844
+ })
845
+ .remainingAccounts([
846
+ withdrawIx.keys[4],
847
+ withdrawIx.keys[5],
848
+ withdrawIx.keys[6],
849
+ withdrawIx.keys[7],
850
+ withdrawIx.keys[8],
851
+ withdrawIx.keys[9],
852
+ withdrawIx.keys[10],
853
+ withdrawIx.keys[11],
854
+ withdrawIx.keys[12],
855
+ withdrawIx.keys[13],
856
+ withdrawIx.keys[14],
857
+ withdrawIx.keys[15],
858
+ withdrawIx.keys[16],
859
+ withdrawIx.keys[17],
860
+ withdrawIx.keys[18],
861
+ withdrawIx.keys[19],
862
+ ])
863
+ .instruction();
864
+ // Override the instruction
865
+ this._ix = ix;
866
+ });
867
+ }
868
+ }
869
+ /**
870
+ * Facilitates the removal of liquidity from a blockchain-based financial system.
871
+ */
872
+ class RemoveLiquidityByRangeAutomation extends RemoveLiquidityAutomation {
873
+ /**
874
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
875
+ *
876
+ * @param ix The core transaction instruction.
877
+ * @param userPda The user's program-derived address (PDA) as a public key.
878
+ * @param authority The authority public key that has signing capabilities over the transaction.
879
+ */
880
+ constructor(ix, userPda, authority) {
881
+ super(ix, userPda, authority, util.sighash("RemoveLiquidityByRange"));
882
+ }
883
+ }
884
+ /**
885
+ * Enables the claiming of fees generated from transactions within a blockchain protocol.
886
+ */
887
+ class ClaimFeeAutomation extends HawksightMeteoraAutomationCpi {
888
+ /**
889
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
890
+ *
891
+ * @param ix The core transaction instruction.
892
+ * @param userPda The user's program-derived address (PDA) as a public key.
893
+ * @param authority The authority public key that has signing capabilities over the transaction.
894
+ */
895
+ constructor(ix, userPda, authority) {
896
+ super(ix, userPda, authority, util.sighash("ClaimFee"));
897
+ }
898
+ /**
899
+ * Modifies transaction keys for the purpose of claiming transaction fees.
900
+ */
901
+ replace() {
902
+ this._ix.keys[4].pubkey = this.userPda;
903
+ this._ix.keys[4].isSigner = false;
904
+ }
905
+ /**
906
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
907
+ */
908
+ replaceCpi() {
909
+ return __awaiter(this, void 0, void 0, function* () {
910
+ // Common parameters
911
+ const farm = addresses_1.USDC_FARM;
912
+ const userPda = this.userPda;
913
+ const authority = this.authority;
914
+ const iyfProgram = addresses_1.IYF_MAIN;
915
+ const hawksightAuthority = addresses_1.HS_AUTHORITY;
916
+ // Get token mints X and Y
917
+ const tokenXMint = this.ix.keys[9].pubkey;
918
+ const tokenYMint = this.ix.keys[10].pubkey;
919
+ // Generate owner fee X and Y ATA
920
+ const ownerFeeX = util.generateAta(addresses_1.SITE_FEE_OWNER, tokenXMint);
921
+ const ownerFeeY = util.generateAta(addresses_1.SITE_FEE_OWNER, tokenYMint);
922
+ // Generate IX via extension contract
923
+ const claimFeeIx = yield anchor_1.Anchor.instance().iyfExtension.methods
924
+ .meteoraDlmmClaimFeeAutomation()
925
+ .accounts({
926
+ farm,
927
+ userPda,
928
+ authority,
929
+ iyfProgram,
930
+ hawksightAuthority,
931
+ lbPair: this.ix.keys[0].pubkey,
932
+ position: this.ix.keys[1].pubkey,
933
+ binArrayLower: this.ix.keys[2].pubkey,
934
+ binArrayUpper: this.ix.keys[3].pubkey,
935
+ reserveX: this.ix.keys[5].pubkey,
936
+ reserveY: this.ix.keys[6].pubkey,
937
+ userTokenX: this.ix.keys[7].pubkey,
938
+ userTokenY: this.ix.keys[8].pubkey,
939
+ tokenXMint: this.ix.keys[9].pubkey,
940
+ tokenYMint: this.ix.keys[10].pubkey,
941
+ tokenProgram: this.ix.keys[11].pubkey,
942
+ eventAuthority: this.ix.keys[12].pubkey,
943
+ meteoraDlmmProgram: this.ix.keys[13].pubkey,
944
+ ownerFeeX,
945
+ ownerFeeY,
946
+ }).instruction();
947
+ // Instruction via main hawksight contract
948
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
949
+ .iyfExtensionExecute(claimFeeIx.data)
950
+ .accounts({
951
+ farm,
952
+ userPda,
953
+ authority,
954
+ iyfProgram,
955
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
956
+ })
957
+ .remainingAccounts([
958
+ claimFeeIx.keys[4],
959
+ claimFeeIx.keys[5],
960
+ claimFeeIx.keys[6],
961
+ claimFeeIx.keys[7],
962
+ claimFeeIx.keys[8],
963
+ claimFeeIx.keys[9],
964
+ claimFeeIx.keys[10],
965
+ claimFeeIx.keys[11],
966
+ claimFeeIx.keys[12],
967
+ claimFeeIx.keys[13],
968
+ claimFeeIx.keys[14],
969
+ claimFeeIx.keys[15],
970
+ claimFeeIx.keys[16],
971
+ claimFeeIx.keys[17],
972
+ claimFeeIx.keys[18],
973
+ claimFeeIx.keys[19],
974
+ ])
975
+ .instruction();
976
+ // Override the instruction
977
+ this._ix = ix;
978
+ });
979
+ }
980
+ }
981
+ /**
982
+ * Manages the claiming of rewards in blockchain operations, typically associated with staking or similar activities.
983
+ */
984
+ class ClaimRewardAutomation extends HawksightMeteoraAutomationCpi {
985
+ /**
986
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
987
+ *
988
+ * @param ix The core transaction instruction.
989
+ * @param userPda The user's program-derived address (PDA) as a public key.
990
+ * @param authority The authority public key that has signing capabilities over the transaction.
991
+ */
992
+ constructor(ix, userPda, authority) {
993
+ super(ix, userPda, authority, util.sighash("ClaimReward"));
994
+ }
995
+ /**
996
+ * Adjusts transaction keys to facilitate the claiming of rewards.
997
+ */
998
+ replace() {
999
+ this._ix.keys[4].pubkey = this.userPda;
1000
+ this._ix.keys[4].isSigner = false;
1001
+ }
1002
+ /**
1003
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
1004
+ */
1005
+ replaceCpi() {
1006
+ return __awaiter(this, void 0, void 0, function* () {
1007
+ // Get reward index from parameter
1008
+ const rewardIndex = new bn_js_1.BN(this.ix.data.readBigInt64LE(8).toString());
1009
+ // Common parameters
1010
+ const farm = addresses_1.USDC_FARM;
1011
+ const userPda = this.userPda;
1012
+ const authority = this.authority;
1013
+ const iyfProgram = addresses_1.IYF_MAIN;
1014
+ const hawksightAuthority = addresses_1.HS_AUTHORITY;
1015
+ // Generate owner fee ATA
1016
+ const rewardMint = this.ix.keys[6].pubkey;
1017
+ const ownerFee = util.generateAta(addresses_1.SITE_FEE_OWNER, rewardMint);
1018
+ // Generate IX via extension contract
1019
+ const claimRewardIx = yield anchor_1.Anchor.instance().iyfExtension.methods
1020
+ .meteoraDlmmClaimRewardAutomation(rewardIndex)
1021
+ .accounts({
1022
+ farm,
1023
+ userPda,
1024
+ authority,
1025
+ iyfProgram,
1026
+ hawksightAuthority,
1027
+ lbPair: this.ix.keys[0].pubkey,
1028
+ position: this.ix.keys[1].pubkey,
1029
+ binArrayLower: this.ix.keys[1].pubkey,
1030
+ binArrayUpper: this.ix.keys[2].pubkey,
1031
+ rewardVault: this.ix.keys[5].pubkey,
1032
+ rewardMint,
1033
+ userTokenAccount: this.ix.keys[7].pubkey,
1034
+ tokenProgram: this.ix.keys[8].pubkey,
1035
+ eventAuthority: this.ix.keys[9].pubkey,
1036
+ meteoraDlmmProgram: this.ix.keys[10].pubkey,
1037
+ ownerFee,
1038
+ }).instruction();
1039
+ // Instruction via main hawksight contract
1040
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
1041
+ .iyfExtensionExecute(claimRewardIx.data)
1042
+ .accounts({
1043
+ farm,
1044
+ userPda,
1045
+ authority,
1046
+ iyfProgram,
1047
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
1048
+ })
1049
+ .remainingAccounts([
1050
+ claimRewardIx.keys[4],
1051
+ claimRewardIx.keys[5],
1052
+ claimRewardIx.keys[6],
1053
+ claimRewardIx.keys[7],
1054
+ claimRewardIx.keys[8],
1055
+ claimRewardIx.keys[9],
1056
+ claimRewardIx.keys[10],
1057
+ claimRewardIx.keys[11],
1058
+ claimRewardIx.keys[12],
1059
+ claimRewardIx.keys[13],
1060
+ claimRewardIx.keys[14],
1061
+ claimRewardIx.keys[15],
1062
+ ])
1063
+ .instruction();
1064
+ // Override the instruction
1065
+ this._ix = ix;
1066
+ });
1067
+ }
1068
+ }
1069
+ /**
1070
+ * Handles the closure of a position within a blockchain transaction.
1071
+ */
1072
+ class ClosePositionAutomation extends HawksightMeteoraAutomationCpi {
1073
+ /**
1074
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
1075
+ *
1076
+ * @param ix The core transaction instruction.
1077
+ * @param userPda The user's program-derived address (PDA) as a public key.
1078
+ * @param authority The authority public key that has signing capabilities over the transaction.
1079
+ */
1080
+ constructor(ix, userPda, authority) {
1081
+ super(ix, userPda, authority, util.sighash("ClosePosition"));
1082
+ }
1083
+ /**
1084
+ * Customizes the transaction keys to properly close a position, ensuring all relevant keys are set correctly.
1085
+ */
1086
+ replace() {
1087
+ this._ix.keys[4].pubkey = this.userPda;
1088
+ this._ix.keys[4].isSigner = false;
1089
+ this._ix.keys[5].pubkey = this.authority;
1090
+ }
1091
+ /**
1092
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
1093
+ */
1094
+ replaceCpi() {
1095
+ return __awaiter(this, void 0, void 0, function* () {
1096
+ // Common parameters
1097
+ const farm = addresses_1.USDC_FARM;
1098
+ const userPda = this.userPda;
1099
+ const authority = this.authority;
1100
+ const iyfProgram = addresses_1.IYF_MAIN;
1101
+ const hawksightAuthority = addresses_1.HS_AUTHORITY;
1102
+ // Generate IX via extension contract
1103
+ const closePositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
1104
+ .meteoraDlmmClosePositionAutomation()
1105
+ .accounts({
1106
+ farm,
1107
+ userPda,
1108
+ authority,
1109
+ iyfProgram,
1110
+ hawksightAuthority,
1111
+ position: this.ix.keys[0].pubkey,
1112
+ lbPair: this.ix.keys[1].pubkey,
1113
+ binArrayLower: this.ix.keys[2].pubkey,
1114
+ binArrayUpper: this.ix.keys[3].pubkey,
1115
+ eventAuthority: this.ix.keys[6].pubkey,
1116
+ meteoraDlmmProgram: this.ix.keys[7].pubkey,
1117
+ }).instruction();
1118
+ // Instruction via main hawksight contract
1119
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
1120
+ .iyfExtensionExecute(closePositionIx.data)
1121
+ .accounts({
1122
+ farm,
1123
+ userPda,
1124
+ authority,
1125
+ iyfProgram,
1126
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
1127
+ })
1128
+ .remainingAccounts([
1129
+ closePositionIx.keys[4],
1130
+ closePositionIx.keys[5],
1131
+ closePositionIx.keys[6],
1132
+ closePositionIx.keys[7],
1133
+ closePositionIx.keys[8],
1134
+ closePositionIx.keys[9],
1135
+ closePositionIx.keys[10],
1136
+ ])
1137
+ .instruction();
1138
+ // Override the instruction
1139
+ this._ix = ix;
1140
+ });
1141
+ }
1142
+ }