@hawksightco/hawk-sdk 1.1.5 → 1.1.6-4.test

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 (130) hide show
  1. package/dist/src/addresses.d.ts +2 -1
  2. package/dist/src/addresses.d.ts.map +1 -1
  3. package/dist/src/addresses.js +3 -1
  4. package/dist/src/anchor.d.ts +113 -2
  5. package/dist/src/anchor.d.ts.map +1 -1
  6. package/dist/src/anchor.js +33 -1
  7. package/dist/src/classes/AltStorage.d.ts +29 -0
  8. package/dist/src/classes/AltStorage.d.ts.map +1 -0
  9. package/dist/src/classes/AltStorage.js +58 -0
  10. package/dist/src/classes/Atomicity.d.ts +34 -0
  11. package/dist/src/classes/Atomicity.d.ts.map +1 -0
  12. package/dist/src/classes/Atomicity.js +110 -0
  13. package/dist/src/classes/CreateTxMetadata.d.ts +16 -1
  14. package/dist/src/classes/CreateTxMetadata.d.ts.map +1 -1
  15. package/dist/src/classes/CreateTxMetadata.js +115 -6
  16. package/dist/src/classes/General.d.ts +16 -1
  17. package/dist/src/classes/General.d.ts.map +1 -1
  18. package/dist/src/classes/General.js +32 -0
  19. package/dist/src/classes/HawkAPI.d.ts +32 -0
  20. package/dist/src/classes/HawkAPI.d.ts.map +1 -1
  21. package/dist/src/classes/HawkAPI.js +37 -0
  22. package/dist/src/classes/JupiterAlts.d.ts +37 -0
  23. package/dist/src/classes/JupiterAlts.d.ts.map +1 -0
  24. package/dist/src/classes/JupiterAlts.js +104 -0
  25. package/dist/src/classes/JupiterSwap.d.ts +19 -0
  26. package/dist/src/classes/JupiterSwap.d.ts.map +1 -0
  27. package/dist/src/classes/JupiterSwap.js +37 -0
  28. package/dist/src/classes/Logging.d.ts +13 -0
  29. package/dist/src/classes/Logging.d.ts.map +1 -0
  30. package/dist/src/classes/Logging.js +51 -0
  31. package/dist/src/classes/MultiTransaction.d.ts +75 -0
  32. package/dist/src/classes/MultiTransaction.d.ts.map +1 -0
  33. package/dist/src/classes/MultiTransaction.js +286 -0
  34. package/dist/src/classes/SimpleIxGenerator.d.ts +34 -0
  35. package/dist/src/classes/SimpleIxGenerator.d.ts.map +1 -0
  36. package/dist/src/classes/SimpleIxGenerator.js +39 -0
  37. package/dist/src/classes/SimplePdaGenerator.d.ts +28 -0
  38. package/dist/src/classes/SimplePdaGenerator.d.ts.map +1 -0
  39. package/dist/src/classes/SimplePdaGenerator.js +33 -0
  40. package/dist/src/classes/Transaction.d.ts +42 -13
  41. package/dist/src/classes/Transaction.d.ts.map +1 -1
  42. package/dist/src/classes/Transaction.js +37 -15
  43. package/dist/src/classes/Transaction2.d.ts +107 -0
  44. package/dist/src/classes/Transaction2.d.ts.map +1 -0
  45. package/dist/src/classes/Transaction2.js +239 -0
  46. package/dist/src/classes/Transaction3.d.ts +165 -0
  47. package/dist/src/classes/Transaction3.d.ts.map +1 -0
  48. package/dist/src/classes/Transaction3.js +406 -0
  49. package/dist/src/classes/TransactionBatchExecute.d.ts +163 -0
  50. package/dist/src/classes/TransactionBatchExecute.d.ts.map +1 -0
  51. package/dist/src/classes/TransactionBatchExecute.js +456 -0
  52. package/dist/src/classes/TransactionBatchExecute2.d.ts +99 -0
  53. package/dist/src/classes/TransactionBatchExecute2.d.ts.map +1 -0
  54. package/dist/src/classes/TransactionBatchExecute2.js +347 -0
  55. package/dist/src/classes/Transactions.d.ts +102 -10
  56. package/dist/src/classes/Transactions.d.ts.map +1 -1
  57. package/dist/src/classes/Transactions.js +890 -116
  58. package/dist/src/classes/TxGenerator.d.ts +95 -2
  59. package/dist/src/classes/TxGenerator.d.ts.map +1 -1
  60. package/dist/src/classes/TxGenerator.js +333 -5
  61. package/dist/src/classes/TxGeneratorAutomations.d.ts +23 -2
  62. package/dist/src/classes/TxGeneratorAutomations.d.ts.map +1 -1
  63. package/dist/src/classes/TxGeneratorAutomations.js +72 -0
  64. package/dist/src/classes/Util.d.ts +22 -0
  65. package/dist/src/classes/Util.d.ts.map +1 -1
  66. package/dist/src/classes/Util.js +33 -0
  67. package/dist/src/functions.d.ts +81 -4
  68. package/dist/src/functions.d.ts.map +1 -1
  69. package/dist/src/functions.js +442 -8
  70. package/dist/src/hawksight.d.ts +14 -1
  71. package/dist/src/hawksight.d.ts.map +1 -1
  72. package/dist/src/hawksight.js +52 -2
  73. package/dist/src/hsToMeteora.d.ts +7 -1
  74. package/dist/src/hsToMeteora.d.ts.map +1 -1
  75. package/dist/src/hsToMeteora.js +563 -32
  76. package/dist/src/idl/iyf-extension-idl.d.ts +9207 -4250
  77. package/dist/src/idl/iyf-extension-idl.d.ts.map +1 -1
  78. package/dist/src/idl/iyf-extension-idl.js +9261 -4310
  79. package/dist/src/idl/iyf-main-idl.d.ts +244 -5
  80. package/dist/src/idl/iyf-main-idl.d.ts.map +1 -1
  81. package/dist/src/idl/iyf-main-idl.js +244 -5
  82. package/dist/src/idl/jupiter-idl.d.ts +1767 -0
  83. package/dist/src/idl/jupiter-idl.d.ts.map +1 -0
  84. package/dist/src/idl/jupiter-idl.js +1768 -0
  85. package/dist/src/idl/meteora-idl.d.ts +5251 -0
  86. package/dist/src/idl/meteora-idl.d.ts.map +1 -0
  87. package/dist/src/idl/meteora-idl.js +5252 -0
  88. package/dist/src/index.d.ts +3 -0
  89. package/dist/src/index.d.ts.map +1 -1
  90. package/dist/src/index.js +6 -1
  91. package/dist/src/ixGenerator/IyfExtensionIxGenerator.d.ts +26 -0
  92. package/dist/src/ixGenerator/IyfExtensionIxGenerator.d.ts.map +1 -0
  93. package/dist/src/ixGenerator/IyfExtensionIxGenerator.js +72 -0
  94. package/dist/src/ixGenerator/IyfMainIxGenerator.d.ts +119 -0
  95. package/dist/src/ixGenerator/IyfMainIxGenerator.d.ts.map +1 -0
  96. package/dist/src/ixGenerator/IyfMainIxGenerator.js +295 -0
  97. package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts +49 -0
  98. package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts.map +1 -0
  99. package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.js +279 -0
  100. package/dist/src/ixGenerator/OrcaIxGenerator.d.ts +23 -0
  101. package/dist/src/ixGenerator/OrcaIxGenerator.d.ts.map +1 -0
  102. package/dist/src/ixGenerator/OrcaIxGenerator.js +119 -0
  103. package/dist/src/ixGenerator/UtilIxGenerator.d.ts +20 -0
  104. package/dist/src/ixGenerator/UtilIxGenerator.d.ts.map +1 -0
  105. package/dist/src/ixGenerator/UtilIxGenerator.js +25 -0
  106. package/dist/src/meteora.d.ts +230 -2
  107. package/dist/src/meteora.d.ts.map +1 -1
  108. package/dist/src/meteora.js +704 -11
  109. package/dist/src/orca.d.ts +16 -1
  110. package/dist/src/orca.d.ts.map +1 -1
  111. package/dist/src/orca.js +29 -1
  112. package/dist/src/pdaGenerator/HawksightPdaGenerator.d.ts +23 -0
  113. package/dist/src/pdaGenerator/HawksightPdaGenerator.d.ts.map +1 -0
  114. package/dist/src/pdaGenerator/HawksightPdaGenerator.js +56 -0
  115. package/dist/src/pdaGenerator/MeteoraPdaGenerator.d.ts +6 -0
  116. package/dist/src/pdaGenerator/MeteoraPdaGenerator.d.ts.map +1 -0
  117. package/dist/src/pdaGenerator/MeteoraPdaGenerator.js +9 -0
  118. package/dist/src/pdaGenerator/OrcaPdaGenerator.d.ts +15 -0
  119. package/dist/src/pdaGenerator/OrcaPdaGenerator.d.ts.map +1 -0
  120. package/dist/src/pdaGenerator/OrcaPdaGenerator.js +45 -0
  121. package/dist/src/pdaGenerator/RaydiumPdaGenerator.d.ts +6 -0
  122. package/dist/src/pdaGenerator/RaydiumPdaGenerator.d.ts.map +1 -0
  123. package/dist/src/pdaGenerator/RaydiumPdaGenerator.js +9 -0
  124. package/dist/src/pdaGenerator/UtilPdaGenerator.d.ts +8 -0
  125. package/dist/src/pdaGenerator/UtilPdaGenerator.d.ts.map +1 -0
  126. package/dist/src/pdaGenerator/UtilPdaGenerator.js +41 -0
  127. package/dist/src/types.d.ts +81 -15
  128. package/dist/src/types.d.ts.map +1 -1
  129. package/dist/src/types.js +31 -5
  130. package/package.json +3 -2
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.meteoraToHawksightAutomationIxs = exports.meteoraToHawksight = void 0;
35
+ exports.meteoraToHawksightPdaIxs = exports.meteoraToHawksightAutomationIxs = exports.meteoraToHawksight = void 0;
36
36
  const addresses_1 = require("./addresses");
37
37
  const anchor_1 = require("./anchor");
38
38
  const bn_js_1 = require("bn.js");
@@ -45,13 +45,15 @@ const util = __importStar(require("./functions"));
45
45
  */
46
46
  function meteoraToHawksight(_a) {
47
47
  return __awaiter(this, arguments, void 0, function* ({ ixs, userPda, authority }) {
48
- return ixs.map((ix) => {
49
- ix = HawksightMeteoraCpi.factory(ix, userPda, authority).getInstruction();
48
+ const _ixs = [];
49
+ for (const ix of ixs) {
50
+ const _ix = yield HawksightMeteoraCpi.factory(ix, userPda, authority).getInstruction();
50
51
  if (ix.programId.toString() === addresses_1.ASSOCIATED_TOKEN_PROGRAM.toString() && ix.keys.length === 6) {
51
52
  ix.keys[0] = Object.assign(Object.assign({}, ix.keys[0]), { pubkey: authority });
52
53
  }
53
- return ix;
54
- });
54
+ _ixs.push(_ix);
55
+ }
56
+ return _ixs;
55
57
  });
56
58
  }
57
59
  exports.meteoraToHawksight = meteoraToHawksight;
@@ -75,6 +77,26 @@ function meteoraToHawksightAutomationIxs(_a) {
75
77
  });
76
78
  }
77
79
  exports.meteoraToHawksightAutomationIxs = meteoraToHawksightAutomationIxs;
80
+ /**
81
+ * Convert listed meteora instruction to hawksight meteora automation cpi
82
+ *
83
+ * @param params
84
+ * @returns
85
+ */
86
+ function meteoraToHawksightPdaIxs(_a) {
87
+ return __awaiter(this, arguments, void 0, function* ({ ixs, userPda, authority }) {
88
+ const _ixs = [];
89
+ for (const ix of ixs) {
90
+ const _ix = yield HawksightMeteoraPdaCpi.factory(ix, userPda, authority).getInstruction();
91
+ if (ix.programId.toString() === addresses_1.ASSOCIATED_TOKEN_PROGRAM.toString() && ix.keys.length === 6) {
92
+ ix.keys[0] = Object.assign(Object.assign({}, ix.keys[0]), { pubkey: addresses_1.HS_AUTHORITY });
93
+ }
94
+ _ixs.push(_ix);
95
+ }
96
+ return _ixs;
97
+ });
98
+ }
99
+ exports.meteoraToHawksightPdaIxs = meteoraToHawksightPdaIxs;
78
100
  /**
79
101
  * Abstract base class `HawksightMeteoraCpi` for handling and chaining transaction instructions.
80
102
  * This class provides a framework for creating and linking complex transaction processes in a blockchain environment.
@@ -141,13 +163,38 @@ class HawksightMeteoraCpi {
141
163
  * @returns The (possibly modified) transaction instruction.
142
164
  */
143
165
  getInstruction() {
144
- const matchInstance = this.sighashMatch();
145
- if (this.programIdMatch() && matchInstance !== undefined) {
146
- matchInstance.replace();
147
- matchInstance.addHawksightCpi();
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const matchInstance = this.sighashMatch();
168
+ if (this.programIdMatch() && matchInstance !== undefined) {
169
+ matchInstance.replace();
170
+ yield matchInstance.addHawksightCpi();
171
+ return this.ix;
172
+ }
148
173
  return this.ix;
149
- }
150
- return this.ix;
174
+ });
175
+ }
176
+ /**
177
+ * Modifies the transaction instruction to include specific Hawksight CPI details.
178
+ * Prepares the instruction for execution by adjusting its program ID and data based on Hawksight criteria.
179
+ */
180
+ addHawksightCpi() {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ const METEORA_PROGRAM = addresses_1.METEORA_DLMM_PROGRAM;
183
+ const size = Buffer.alloc(4);
184
+ size.writeUint32LE(this.ix.data.length);
185
+ const data = Buffer.concat([
186
+ new Uint8Array(util.sighash('meteora_dynamic_cpi')),
187
+ new Uint8Array(size),
188
+ new Uint8Array(this.ix.data),
189
+ ]);
190
+ this.ix.programId = addresses_1.IYF_MAIN;
191
+ this.ix.data = data;
192
+ this.ix.keys.unshift(...[
193
+ { pubkey: this.userPda, isSigner: false, isWritable: false },
194
+ { pubkey: this.authority, isSigner: true, isWritable: true },
195
+ { pubkey: METEORA_PROGRAM, isSigner: false, isWritable: false },
196
+ ]);
197
+ });
151
198
  }
152
199
  /**
153
200
  * Adds a subsequent CPI to the chain.
@@ -187,23 +234,6 @@ class HawksightMeteoraCpi {
187
234
  programIdMatch() {
188
235
  return this.ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
189
236
  }
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
237
  }
208
238
  /**
209
239
  * Handles the initialization of a position in a blockchain transaction.
@@ -379,6 +409,81 @@ class ClaimFee extends HawksightMeteoraCpi {
379
409
  this.ix.keys[4].pubkey = this.userPda;
380
410
  this.ix.keys[4].isSigner = false;
381
411
  }
412
+ /**
413
+ * Overrides default add hawksight cpi to use meteoraDlmmClaimFee instead of meteoraDynamicCpi
414
+ */
415
+ addHawksightCpi() {
416
+ return __awaiter(this, void 0, void 0, function* () {
417
+ // Common parameters
418
+ const farm = addresses_1.USDC_FARM;
419
+ const userPda = this.userPda;
420
+ const authority = this.authority;
421
+ const iyfProgram = addresses_1.IYF_MAIN;
422
+ // Get token mints X and Y
423
+ const tokenXMint = this.ix.keys[9].pubkey;
424
+ const tokenYMint = this.ix.keys[10].pubkey;
425
+ // Generate owner fee X and Y ATA
426
+ const ownerFeeX = util.generateAta(addresses_1.SITE_FEE_OWNER, tokenXMint);
427
+ const ownerFeeY = util.generateAta(addresses_1.SITE_FEE_OWNER, tokenYMint);
428
+ // Generate IX via extension contract
429
+ // @ts-ignore
430
+ const claimFeeIx = yield anchor_1.Anchor.instance().iyfExtension.methods
431
+ .meteoraDlmmClaimFee()
432
+ .accounts({
433
+ farm,
434
+ userPda,
435
+ authority,
436
+ iyfProgram,
437
+ lbPair: this.ix.keys[0].pubkey,
438
+ position: this.ix.keys[1].pubkey,
439
+ binArrayLower: this.ix.keys[2].pubkey,
440
+ binArrayUpper: this.ix.keys[3].pubkey,
441
+ reserveX: this.ix.keys[5].pubkey,
442
+ reserveY: this.ix.keys[6].pubkey,
443
+ userTokenX: this.ix.keys[7].pubkey,
444
+ userTokenY: this.ix.keys[8].pubkey,
445
+ tokenXMint: this.ix.keys[9].pubkey,
446
+ tokenYMint: this.ix.keys[10].pubkey,
447
+ tokenProgram: this.ix.keys[11].pubkey,
448
+ eventAuthority: this.ix.keys[12].pubkey,
449
+ meteoraDlmmProgram: this.ix.keys[13].pubkey,
450
+ ownerFeeX,
451
+ ownerFeeY,
452
+ }).instruction();
453
+ // Instruction via main hawksight contract
454
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
455
+ .iyfExtensionExecute(claimFeeIx.data)
456
+ .accounts({
457
+ farm,
458
+ userPda,
459
+ authority,
460
+ iyfProgram,
461
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
462
+ })
463
+ .remainingAccounts([
464
+ claimFeeIx.keys[4],
465
+ claimFeeIx.keys[5],
466
+ claimFeeIx.keys[6],
467
+ claimFeeIx.keys[7],
468
+ claimFeeIx.keys[8],
469
+ claimFeeIx.keys[9],
470
+ claimFeeIx.keys[10],
471
+ claimFeeIx.keys[11],
472
+ claimFeeIx.keys[12],
473
+ claimFeeIx.keys[13],
474
+ claimFeeIx.keys[14],
475
+ claimFeeIx.keys[15],
476
+ claimFeeIx.keys[16],
477
+ claimFeeIx.keys[17],
478
+ claimFeeIx.keys[18],
479
+ ])
480
+ .instruction();
481
+ // Override the instruction
482
+ this.ix.programId = ix.programId;
483
+ this.ix.data = ix.data;
484
+ this.ix.keys = ix.keys;
485
+ });
486
+ }
382
487
  }
383
488
  /**
384
489
  * Manages the claiming of rewards in blockchain operations, typically associated with staking or similar activities.
@@ -401,6 +506,73 @@ class ClaimReward extends HawksightMeteoraCpi {
401
506
  this.ix.keys[4].pubkey = this.userPda;
402
507
  this.ix.keys[4].isSigner = false;
403
508
  }
509
+ /**
510
+ * Overrides default add hawksight cpi to use meteoraDlmmClaimReward instead of meteoraDynamicCpi
511
+ */
512
+ addHawksightCpi() {
513
+ return __awaiter(this, void 0, void 0, function* () {
514
+ // Common parameters
515
+ const farm = addresses_1.USDC_FARM;
516
+ const userPda = this.userPda;
517
+ const authority = this.authority;
518
+ const iyfProgram = addresses_1.IYF_MAIN;
519
+ // Get token mint
520
+ const rewardMint = this.ix.keys[6].pubkey;
521
+ // Generate owner fee X and Y ATA
522
+ const ownerFee = util.generateAta(addresses_1.SITE_FEE_OWNER, rewardMint);
523
+ // Get reward index from parameter
524
+ const rewardIndex = new bn_js_1.BN(this.ix.data.readBigInt64LE(8).toString());
525
+ // Generate IX via extension contract
526
+ // @ts-ignore
527
+ const claimReward = yield anchor_1.Anchor.instance().iyfExtension.methods
528
+ .meteoraDlmmClaimReward(rewardIndex)
529
+ .accounts({
530
+ farm,
531
+ userPda,
532
+ authority,
533
+ iyfProgram,
534
+ lbPair: this.ix.keys[0].pubkey,
535
+ position: this.ix.keys[1].pubkey,
536
+ binArrayLower: this.ix.keys[2].pubkey,
537
+ binArrayUpper: this.ix.keys[3].pubkey,
538
+ rewardVault: this.ix.keys[5].pubkey,
539
+ rewardMint: this.ix.keys[6].pubkey,
540
+ userTokenAccount: this.ix.keys[7].pubkey,
541
+ tokenProgram: this.ix.keys[8].pubkey,
542
+ eventAuthority: this.ix.keys[9].pubkey,
543
+ meteoraDlmmProgram: this.ix.keys[10].pubkey,
544
+ ownerFee,
545
+ }).instruction();
546
+ // Instruction via main hawksight contract
547
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
548
+ .iyfExtensionExecute(claimReward.data)
549
+ .accounts({
550
+ farm,
551
+ userPda,
552
+ authority,
553
+ iyfProgram,
554
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
555
+ })
556
+ .remainingAccounts([
557
+ claimReward.keys[4],
558
+ claimReward.keys[5],
559
+ claimReward.keys[6],
560
+ claimReward.keys[7],
561
+ claimReward.keys[8],
562
+ claimReward.keys[9],
563
+ claimReward.keys[10],
564
+ claimReward.keys[11],
565
+ claimReward.keys[12],
566
+ claimReward.keys[13],
567
+ claimReward.keys[14],
568
+ ])
569
+ .instruction();
570
+ // Override the instruction
571
+ this.ix.programId = ix.programId;
572
+ this.ix.data = ix.data;
573
+ this.ix.keys = ix.keys;
574
+ });
575
+ }
404
576
  }
405
577
  /**
406
578
  * Handles the closure of a position within a blockchain transaction.
@@ -553,8 +725,12 @@ class InitializePositionAutomation extends HawksightMeteoraAutomationCpi {
553
725
  const iyfProgram = addresses_1.IYF_MAIN;
554
726
  const hawksightAuthority = addresses_1.HS_AUTHORITY;
555
727
  // Generate IX via extension contract
728
+ const data = this.ix.data.subarray(8);
729
+ const lowerBinId = data.subarray(0, 4).readInt32LE();
730
+ const width = data.subarray(4).readInt32LE();
731
+ // @ts-ignore
556
732
  const initializePositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
557
- .meteoraDlmmInitializePositionAutomation(this.ix.data.subarray(8))
733
+ .meteoraDlmmInitializePositionAutomation(lowerBinId, width)
558
734
  .accounts({
559
735
  farm,
560
736
  userPda,
@@ -630,8 +806,16 @@ class AddLiquidityByWeightAutomation extends HawksightMeteoraAutomationCpi {
630
806
  const tokenXMint = this.ix.keys[7].pubkey;
631
807
  const tokenYMint = this.ix.keys[8].pubkey;
632
808
  // Generate IX via extension contract
809
+ const data = this.ix.data.subarray(8);
810
+ const activeId = data.subarray(16, 20).readInt32LE();
811
+ const maxActiveBinSlippage = data.subarray(20, 24).readInt32LE();
812
+ const strategyParametersMinBinId = data.subarray(24, 28).readInt32LE();
813
+ const strategyParametersMaxBinId = data.subarray(28, 32).readInt32LE();
814
+ const strategyParametersStrategyType = data[32];
815
+ const strategyParametersParameters = Array.from(data.subarray(33));
816
+ // @ts-ignore
633
817
  const depositIx = yield anchor_1.Anchor.instance().iyfExtension.methods
634
- .meteoraDlmmDepositAutomation(this.ix.data.subarray(8))
818
+ .meteoraDlmmDepositAutomation(activeId, maxActiveBinSlippage, strategyParametersMinBinId, strategyParametersMaxBinId, strategyParametersStrategyType, strategyParametersParameters)
635
819
  .accounts({
636
820
  farm,
637
821
  userPda,
@@ -722,6 +906,7 @@ class AddLiquidityOneSideAutomation extends HawksightMeteoraAutomationCpi {
722
906
  const iyfProgram = addresses_1.IYF_MAIN;
723
907
  const hawksightAuthority = addresses_1.HS_AUTHORITY;
724
908
  // Generate IX via extension contract
909
+ // @ts-ignore
725
910
  const depositIx = yield anchor_1.Anchor.instance().iyfExtension.methods
726
911
  .meteoraDlmmOneSideDeposit(this.ix.data.subarray(8))
727
912
  .accounts({
@@ -808,6 +993,7 @@ class RemoveLiquidityAutomation extends HawksightMeteoraAutomationCpi {
808
993
  const tokenXMint = this.ix.keys[7].pubkey;
809
994
  const tokenYMint = this.ix.keys[8].pubkey;
810
995
  // Generate IX via extension contract
996
+ // @ts-ignore
811
997
  const withdrawIx = yield anchor_1.Anchor.instance().iyfExtension.methods
812
998
  .meteoraDlmmWithdrawAutomation(this.ix.data)
813
999
  .accounts({
@@ -920,6 +1106,7 @@ class ClaimFeeAutomation extends HawksightMeteoraAutomationCpi {
920
1106
  const ownerFeeX = util.generateAta(addresses_1.SITE_FEE_OWNER, tokenXMint);
921
1107
  const ownerFeeY = util.generateAta(addresses_1.SITE_FEE_OWNER, tokenYMint);
922
1108
  // Generate IX via extension contract
1109
+ // @ts-ignore
923
1110
  const claimFeeIx = yield anchor_1.Anchor.instance().iyfExtension.methods
924
1111
  .meteoraDlmmClaimFeeAutomation()
925
1112
  .accounts({
@@ -1016,6 +1203,7 @@ class ClaimRewardAutomation extends HawksightMeteoraAutomationCpi {
1016
1203
  const rewardMint = this.ix.keys[6].pubkey;
1017
1204
  const ownerFee = util.generateAta(addresses_1.SITE_FEE_OWNER, rewardMint);
1018
1205
  // Generate IX via extension contract
1206
+ // @ts-ignore
1019
1207
  const claimRewardIx = yield anchor_1.Anchor.instance().iyfExtension.methods
1020
1208
  .meteoraDlmmClaimRewardAutomation(rewardIndex)
1021
1209
  .accounts({
@@ -1026,8 +1214,8 @@ class ClaimRewardAutomation extends HawksightMeteoraAutomationCpi {
1026
1214
  hawksightAuthority,
1027
1215
  lbPair: this.ix.keys[0].pubkey,
1028
1216
  position: this.ix.keys[1].pubkey,
1029
- binArrayLower: this.ix.keys[1].pubkey,
1030
- binArrayUpper: this.ix.keys[2].pubkey,
1217
+ binArrayLower: this.ix.keys[2].pubkey,
1218
+ binArrayUpper: this.ix.keys[3].pubkey,
1031
1219
  rewardVault: this.ix.keys[5].pubkey,
1032
1220
  rewardMint,
1033
1221
  userTokenAccount: this.ix.keys[7].pubkey,
@@ -1100,6 +1288,7 @@ class ClosePositionAutomation extends HawksightMeteoraAutomationCpi {
1100
1288
  const iyfProgram = addresses_1.IYF_MAIN;
1101
1289
  const hawksightAuthority = addresses_1.HS_AUTHORITY;
1102
1290
  // Generate IX via extension contract
1291
+ // @ts-ignore
1103
1292
  const closePositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
1104
1293
  .meteoraDlmmClosePositionAutomation()
1105
1294
  .accounts({
@@ -1140,3 +1329,345 @@ class ClosePositionAutomation extends HawksightMeteoraAutomationCpi {
1140
1329
  });
1141
1330
  }
1142
1331
  }
1332
+ /**
1333
+ * Abstract base class `HawksightMeteoraCpi` for handling and chaining transaction instructions.
1334
+ * This class provides a framework for creating and linking complex transaction processes in a blockchain environment.
1335
+ *
1336
+ * Attributes:
1337
+ * - `ix`: web3.TransactionInstruction - The transaction instruction associated with this CPI.
1338
+ * - `userPda`: web3.PublicKey - The public key of the user's program-derived address (PDA).
1339
+ * - `authority`: web3.PublicKey - The public key of the authority that can sign transactions.
1340
+ * - `_next`: HawksightMeteoraCpi | undefined - Pointer to the next CPI in the chain.
1341
+ * - `sighash`: Buffer - A buffer representing the signature hash used for identifying and validating instructions.
1342
+ *
1343
+ * Methods:
1344
+ * - `constructor(ix, userPda, authority, sighash)`: Constructs an instance of the HawksightMeteoraCpi.
1345
+ * - `factory(ix, userPda, authority)`: Static factory method to create a chain of CPIs starting with `InitializePosition` and linking subsequent operations.
1346
+ * - `getInstruction()`: Returns the modified transaction instruction after processing by matching CPIs in the chain.
1347
+ * - `replace()`: Abstract method to be implemented by subclasses to modify the transaction keys or other properties.
1348
+ * - `next(next)`: Chains the current CPI instance to the next one.
1349
+ * - `sighashMatch()`: Checks if the current transaction instruction matches the provided sighash and recurses through the chain if not.
1350
+ * - `programIdMatch()`: Checks if the program ID of the transaction matches the expected ID.
1351
+ * - `addHawksightCpi()`: Modifies the transaction instruction to include specific Hawksight CPI details.
1352
+ *
1353
+ * Usage:
1354
+ * This class is intended to be extended by specific CPI implementations like `InitializePosition`, each implementing their own `replace()` method to handle specific transaction modifications.
1355
+ */
1356
+ class HawksightMeteoraPdaCpi {
1357
+ /**
1358
+ * Constructs an instance of HawksightMeteoraCpi with the necessary transaction parameters.
1359
+ * @param ix The core transaction instruction.
1360
+ * @param userPda The user's program-derived address (PDA) as a public key.
1361
+ * @param authority The authority public key that has signing capabilities over the transaction.
1362
+ * @param sighash A Buffer containing the sighash used for matching the transaction instruction.
1363
+ */
1364
+ constructor(ix, userPda, authority, sighash) {
1365
+ this.ix = ix;
1366
+ this.userPda = userPda;
1367
+ this.authority = authority;
1368
+ this.sighash = sighash;
1369
+ }
1370
+ /**
1371
+ * Factory method to create and link a chain of CPIs starting from `InitializePosition`.
1372
+ * Subsequent CPIs include operations like adding liquidity, removing liquidity, claiming fees, and rewards, and closing the position.
1373
+ * @param ix The initial transaction instruction.
1374
+ * @param userPda The user's public key.
1375
+ * @param authority The authority public key.
1376
+ * @returns The first CPI in the chain.
1377
+ */
1378
+ static factory(ix, userPda, authority) {
1379
+ const chain = new InitializePositionPda(ix, userPda, authority);
1380
+ chain
1381
+ .next(new AddLiquidityByStrategyPda(ix, userPda, authority))
1382
+ .next(new AddLiquidityByStrategyOneSidePda(ix, userPda, authority));
1383
+ return chain;
1384
+ }
1385
+ /**
1386
+ * Retrieves and possibly modifies the transaction instruction based on matching conditions.
1387
+ * If a matching CPI is found in the chain, it performs modifications and returns the updated instruction.
1388
+ * @returns The (possibly modified) transaction instruction.
1389
+ */
1390
+ getInstruction() {
1391
+ return __awaiter(this, void 0, void 0, function* () {
1392
+ const matchInstance = this.sighashMatch();
1393
+ if (this.programIdMatch() && matchInstance !== undefined) {
1394
+ matchInstance.replace();
1395
+ yield matchInstance.addHawksightCpi();
1396
+ return this.ix;
1397
+ }
1398
+ return this.ix;
1399
+ });
1400
+ }
1401
+ /**
1402
+ * Modifies the transaction instruction to include specific Hawksight CPI details.
1403
+ * Prepares the instruction for execution by adjusting its program ID and data based on Hawksight criteria.
1404
+ */
1405
+ addHawksightCpi() {
1406
+ return __awaiter(this, void 0, void 0, function* () {
1407
+ const METEORA_PROGRAM = addresses_1.METEORA_DLMM_PROGRAM;
1408
+ const size = Buffer.alloc(4);
1409
+ size.writeUint32LE(this.ix.data.length);
1410
+ const data = Buffer.concat([
1411
+ new Uint8Array(util.sighash('meteora_dynamic_cpi')),
1412
+ new Uint8Array(size),
1413
+ new Uint8Array(this.ix.data)
1414
+ ]);
1415
+ this.ix.programId = addresses_1.IYF_MAIN;
1416
+ this.ix.data = data;
1417
+ this.ix.keys.unshift(...[
1418
+ { pubkey: this.userPda, isSigner: false, isWritable: false },
1419
+ { pubkey: this.authority, isSigner: true, isWritable: true },
1420
+ { pubkey: METEORA_PROGRAM, isSigner: false, isWritable: false },
1421
+ ]);
1422
+ });
1423
+ }
1424
+ /**
1425
+ * Adds a subsequent CPI to the chain.
1426
+ * @param next The next CPI object to link.
1427
+ * @returns The added CPI object, allowing for method chaining.
1428
+ */
1429
+ next(next) {
1430
+ this._next = next;
1431
+ return this._next;
1432
+ }
1433
+ /**
1434
+ * Recursively checks this CPI and subsequent ones for a sighash match in the transaction data.
1435
+ * @returns The first CPI instance in the chain that matches the sighash, or undefined if no match is found.
1436
+ */
1437
+ sighashMatch() {
1438
+ var _a, _b;
1439
+ try {
1440
+ const match = util.sighashMatch(this.ix.data, this.sighash);
1441
+ if (match) {
1442
+ return this;
1443
+ }
1444
+ else if (this._next !== undefined) {
1445
+ return (_a = this._next) === null || _a === void 0 ? void 0 : _a.sighashMatch();
1446
+ }
1447
+ }
1448
+ catch (_c) {
1449
+ if (this._next !== undefined) {
1450
+ return (_b = this._next) === null || _b === void 0 ? void 0 : _b.sighashMatch();
1451
+ }
1452
+ }
1453
+ return undefined;
1454
+ }
1455
+ /**
1456
+ * Checks if the program ID of the transaction instruction matches the expected program ID.
1457
+ * @returns True if the program ID matches, otherwise false.
1458
+ */
1459
+ programIdMatch() {
1460
+ return this.ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
1461
+ }
1462
+ }
1463
+ /**
1464
+ * Handles the initialization of a position in a blockchain transaction.
1465
+ * This class extends the HawksightMeteoraCpi and provides specific logic to modify the transaction instruction for position initialization.
1466
+ */
1467
+ class InitializePositionPda extends HawksightMeteoraPdaCpi {
1468
+ /**
1469
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
1470
+ *
1471
+ * @param ix The core transaction instruction.
1472
+ * @param userPda The user's program-derived address (PDA) as a public key.
1473
+ * @param authority The authority public key that has signing capabilities over the transaction.
1474
+ */
1475
+ constructor(ix, userPda, authority) {
1476
+ super(ix, userPda, authority, util.sighash("InitializePosition"));
1477
+ }
1478
+ /**
1479
+ * Modifies the transaction keys to set the correct public keys for an initial position setup.
1480
+ */
1481
+ replace() {
1482
+ this.ix.keys[0].pubkey = this.authority;
1483
+ this.ix.keys[3].pubkey = this.userPda;
1484
+ this.ix.keys[3].isSigner = false;
1485
+ }
1486
+ }
1487
+ /**
1488
+ * Deposit liquidity via user pda
1489
+ */
1490
+ class AddLiquidityByStrategyPda extends HawksightMeteoraPdaCpi {
1491
+ /**
1492
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
1493
+ *
1494
+ * @param ix The core transaction instruction.
1495
+ * @param userPda The user's program-derived address (PDA) as a public key.
1496
+ * @param authority The authority public key that has signing capabilities over the transaction.
1497
+ */
1498
+ constructor(ix, userPda, authority) {
1499
+ super(ix, userPda, authority, util.sighash("AddLiquidityByStrategy"));
1500
+ }
1501
+ /**
1502
+ * Modifies transaction keys for the purpose of claiming transaction fees.
1503
+ */
1504
+ replace() {
1505
+ this.ix.keys[11].pubkey = this.userPda;
1506
+ this.ix.keys[11].isSigner = false;
1507
+ }
1508
+ /**
1509
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
1510
+ */
1511
+ addHawksightCpi() {
1512
+ return __awaiter(this, void 0, void 0, function* () {
1513
+ // Common parameters
1514
+ const farm = addresses_1.USDC_FARM;
1515
+ const userPda = this.userPda;
1516
+ const authority = this.authority;
1517
+ const iyfProgram = addresses_1.IYF_MAIN;
1518
+ // Get token mints X and Y
1519
+ const tokenXMint = this.ix.keys[7].pubkey;
1520
+ const tokenYMint = this.ix.keys[8].pubkey;
1521
+ // Generate IX via extension contract
1522
+ const data = this.ix.data.subarray(8);
1523
+ const activeId = data.subarray(16, 20).readInt32LE();
1524
+ const maxActiveBinSlippage = data.subarray(20, 24).readInt32LE();
1525
+ const strategyParametersMinBinId = data.subarray(24, 28).readInt32LE();
1526
+ const strategyParametersMaxBinId = data.subarray(28, 32).readInt32LE();
1527
+ const strategyParametersStrategyType = data[32];
1528
+ const strategyParametersParameters = Array.from(data.subarray(33));
1529
+ // @ts-ignore
1530
+ const depositIx = yield anchor_1.Anchor.instance().iyfExtension.methods
1531
+ .meteoraDlmmDeposit(activeId, maxActiveBinSlippage, strategyParametersMinBinId, strategyParametersMaxBinId, strategyParametersStrategyType, strategyParametersParameters)
1532
+ .accounts({
1533
+ farm,
1534
+ userPda,
1535
+ authority,
1536
+ iyfProgram,
1537
+ position: this.ix.keys[0].pubkey,
1538
+ lbPair: this.ix.keys[1].pubkey,
1539
+ binArrayBitmapExtension: this.ix.keys[2].pubkey,
1540
+ userTokenX: this.ix.keys[3].pubkey,
1541
+ userTokenY: this.ix.keys[4].pubkey,
1542
+ reserveX: this.ix.keys[5].pubkey,
1543
+ reserveY: this.ix.keys[6].pubkey,
1544
+ tokenXMint,
1545
+ tokenYMint,
1546
+ binArrayLower: this.ix.keys[9].pubkey,
1547
+ binArrayUpper: this.ix.keys[10].pubkey,
1548
+ tokenXProgram: this.ix.keys[12].pubkey,
1549
+ tokenYProgram: this.ix.keys[13].pubkey,
1550
+ eventAuthority: this.ix.keys[14].pubkey,
1551
+ meteoraDlmmProgram: this.ix.keys[15].pubkey,
1552
+ }).instruction();
1553
+ // Instruction via main hawksight contract
1554
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
1555
+ .iyfExtensionExecute(depositIx.data)
1556
+ .accounts({
1557
+ farm,
1558
+ userPda,
1559
+ authority,
1560
+ iyfProgram,
1561
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
1562
+ })
1563
+ .remainingAccounts([
1564
+ depositIx.keys[4],
1565
+ depositIx.keys[5],
1566
+ depositIx.keys[6],
1567
+ depositIx.keys[7],
1568
+ depositIx.keys[8],
1569
+ depositIx.keys[9],
1570
+ depositIx.keys[10],
1571
+ depositIx.keys[11],
1572
+ depositIx.keys[12],
1573
+ depositIx.keys[13],
1574
+ depositIx.keys[14],
1575
+ depositIx.keys[15],
1576
+ depositIx.keys[16],
1577
+ depositIx.keys[17],
1578
+ depositIx.keys[18],
1579
+ ])
1580
+ .instruction();
1581
+ // console.log("ix AddLiquidityByStrategyPda", JSON.stringify(ix));
1582
+ // Override the instruction
1583
+ this.ix.programId = ix.programId;
1584
+ this.ix.data = ix.data;
1585
+ this.ix.keys = ix.keys;
1586
+ });
1587
+ }
1588
+ }
1589
+ /**
1590
+ * Adjusts transaction instructions to add liquidity based on a specific weight in a financial application.
1591
+ * This class is designed for blockchain operations that manage liquidity pools.
1592
+ */
1593
+ class AddLiquidityByStrategyOneSidePda extends HawksightMeteoraPdaCpi {
1594
+ /**
1595
+ * Constructs an instance of InitializePosition with the necessary transaction parameters.
1596
+ *
1597
+ * @param ix The core transaction instruction.
1598
+ * @param userPda The user's program-derived address (PDA) as a public key.
1599
+ * @param authority The authority public key that has signing capabilities over the transaction.
1600
+ */
1601
+ constructor(ix, userPda, authority) {
1602
+ super(ix, userPda, authority, util.sighash("AddLiquidityByStrategyOneSide"));
1603
+ }
1604
+ /**
1605
+ * Alters the transaction keys for adding liquidity, ensuring the user's PDA is correctly configured.
1606
+ */
1607
+ replace() {
1608
+ this.ix.keys[8].pubkey = this.userPda;
1609
+ this.ix.keys[8].isSigner = false;
1610
+ }
1611
+ /**
1612
+ * Replaces Meteora CPI with Hawksight CPI that calls the target Meteora CPI.
1613
+ */
1614
+ addHawksightCpi() {
1615
+ return __awaiter(this, void 0, void 0, function* () {
1616
+ // Common parameters
1617
+ const farm = addresses_1.USDC_FARM;
1618
+ const userPda = this.userPda;
1619
+ const authority = this.authority;
1620
+ const iyfProgram = addresses_1.IYF_MAIN;
1621
+ // Generate IX via extension contract
1622
+ // @ts-ignore
1623
+ const depositIx = yield anchor_1.Anchor.instance().iyfExtension.methods
1624
+ .meteoraDlmmOneSideDepositManual(this.ix.data.subarray(8))
1625
+ .accounts({
1626
+ farm,
1627
+ userPda,
1628
+ authority,
1629
+ iyfProgram,
1630
+ position: this.ix.keys[0].pubkey,
1631
+ lbPair: this.ix.keys[1].pubkey,
1632
+ binArrayBitmapExtension: this.ix.keys[2].pubkey,
1633
+ userToken: this.ix.keys[3].pubkey,
1634
+ reserve: this.ix.keys[4].pubkey,
1635
+ tokenMint: this.ix.keys[5].pubkey,
1636
+ binArrayLower: this.ix.keys[6].pubkey,
1637
+ binArrayUpper: this.ix.keys[7].pubkey,
1638
+ tokenProgram: this.ix.keys[9].pubkey,
1639
+ eventAuthority: this.ix.keys[10].pubkey,
1640
+ meteoraDlmmProgram: this.ix.keys[11].pubkey,
1641
+ }).instruction();
1642
+ // Instruction via main hawksight contract
1643
+ const ix = yield anchor_1.Anchor.instance().iyfMain.methods
1644
+ .iyfExtensionExecute(depositIx.data)
1645
+ .accounts({
1646
+ farm,
1647
+ userPda,
1648
+ authority,
1649
+ iyfProgram,
1650
+ iyfExtensionProgram: addresses_1.IYF_EXTENSION,
1651
+ })
1652
+ .remainingAccounts([
1653
+ depositIx.keys[4],
1654
+ depositIx.keys[5],
1655
+ depositIx.keys[6],
1656
+ depositIx.keys[7],
1657
+ depositIx.keys[8],
1658
+ depositIx.keys[9],
1659
+ depositIx.keys[10],
1660
+ depositIx.keys[11],
1661
+ depositIx.keys[12],
1662
+ depositIx.keys[13],
1663
+ depositIx.keys[14],
1664
+ depositIx.keys[15],
1665
+ ])
1666
+ .instruction();
1667
+ // Override the instruction
1668
+ this.ix.programId = ix.programId;
1669
+ this.ix.data = ix.data;
1670
+ this.ix.keys = ix.keys;
1671
+ });
1672
+ }
1673
+ }