@hawksightco/hawk-sdk 1.0.1 → 1.0.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes/Transactions.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes/Transactions.ts"],"names":[],"mappings":"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"}
|
|
@@ -40,16 +40,14 @@ const dlmm_1 = require("@meteora-ag/dlmm");
|
|
|
40
40
|
const web3 = __importStar(require("@solana/web3.js"));
|
|
41
41
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
42
42
|
const addresses_1 = require("../addresses");
|
|
43
|
-
const functions_1 = require("../functions");
|
|
44
43
|
const types_1 = require("../types");
|
|
45
|
-
const
|
|
44
|
+
const functions_1 = require("../functions");
|
|
45
|
+
const orca_1 = require("../orca");
|
|
46
46
|
const hsToMeteora_1 = require("../hsToMeteora");
|
|
47
47
|
const meteora_1 = require("../meteora");
|
|
48
48
|
const anchor_1 = require("../anchor");
|
|
49
|
-
// import { PDAUtil } from "@orca-so/whirlpools-sdk";
|
|
50
49
|
const hawksight_1 = require("../hawksight");
|
|
51
50
|
const types_2 = require("../types");
|
|
52
|
-
const whirlpools_sdk_1 = require("@orca-so/whirlpools-sdk");
|
|
53
51
|
class Transactions {
|
|
54
52
|
/**
|
|
55
53
|
* Generate UserPDA
|
|
@@ -59,7 +57,7 @@ class Transactions {
|
|
|
59
57
|
* @returns
|
|
60
58
|
*/
|
|
61
59
|
generateUserPda(userWallet, farm = addresses_1.USDC_FARM) {
|
|
62
|
-
return (0,
|
|
60
|
+
return (0, functions_1.generateUserPda)(userWallet, farm);
|
|
63
61
|
}
|
|
64
62
|
/**s
|
|
65
63
|
* Registers a new entity or user with the necessary parameters, handling transaction creation and response.
|
|
@@ -72,7 +70,7 @@ class Transactions {
|
|
|
72
70
|
register(_a) {
|
|
73
71
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
74
72
|
const farm = addresses_1.USDC_FARM;
|
|
75
|
-
const user = (0,
|
|
73
|
+
const user = (0, functions_1.generateUserPda)(params.authority, farm);
|
|
76
74
|
const [stableToken] = web3.PublicKey.findProgramAddressSync([
|
|
77
75
|
Buffer.from("index-token", "utf-8"),
|
|
78
76
|
addresses_1.STABLEMINT_1.toBuffer(),
|
|
@@ -91,7 +89,7 @@ class Transactions {
|
|
|
91
89
|
throw new Error(`User PDA for wallet: ${params.authority} is already registered.`);
|
|
92
90
|
}
|
|
93
91
|
catch (_b) {
|
|
94
|
-
return (0,
|
|
92
|
+
return (0, functions_1.createTransactionMeta)({
|
|
95
93
|
payer: params.authority,
|
|
96
94
|
description: "Register User",
|
|
97
95
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -127,7 +125,7 @@ class Transactions {
|
|
|
127
125
|
meteoraCreatePositionAndDeposit(_a) {
|
|
128
126
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
129
127
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(params.pool));
|
|
130
|
-
const userPda = (0,
|
|
128
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
131
129
|
const mainInstructions = (yield dlmmPool.initializePositionAndAddLiquidityByStrategy(params.userWallet, params.userWallet, {
|
|
132
130
|
positionPubKey: params.position,
|
|
133
131
|
user: userPda,
|
|
@@ -141,7 +139,7 @@ class Transactions {
|
|
|
141
139
|
slippage: params.slippage,
|
|
142
140
|
skipInputTokenCheck: params.skipInputTokenCheck,
|
|
143
141
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
144
|
-
return (0,
|
|
142
|
+
return (0, functions_1.createTransactionMeta)({
|
|
145
143
|
payer: params.userWallet,
|
|
146
144
|
description: "Create position and deposit to Meteora DLMM",
|
|
147
145
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -163,7 +161,7 @@ class Transactions {
|
|
|
163
161
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, poolAddress);
|
|
164
162
|
const binArraysRequired = yield (0, dlmm_1.getBinArraysRequiredByPositionRange)(poolAddress, new bn_js_1.default(params.minBinId), new bn_js_1.default(params.maxBinId), dlmmPool.dlmm.program.programId);
|
|
165
163
|
const mainInstructions = yield dlmmPool.dlmm.initializeBinArrays(binArraysRequired.map((b) => b.index), new web3.PublicKey(params.userWallet));
|
|
166
|
-
return (0,
|
|
164
|
+
return (0, functions_1.createTransactionMeta)({
|
|
167
165
|
payer: params.userWallet,
|
|
168
166
|
description: "Initialize bin arrays for Meteora DLMM pool",
|
|
169
167
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -195,7 +193,7 @@ class Transactions {
|
|
|
195
193
|
minBinId = position.lowerBinId;
|
|
196
194
|
}
|
|
197
195
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(lbPair));
|
|
198
|
-
const userPda = (0,
|
|
196
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
199
197
|
const mainInstructions = (yield dlmmPool.addLiquidityByStrategy(params.userWallet, params.userWallet, {
|
|
200
198
|
positionPubKey: params.position,
|
|
201
199
|
user: userPda,
|
|
@@ -209,7 +207,7 @@ class Transactions {
|
|
|
209
207
|
slippage: params.slippage,
|
|
210
208
|
skipInputTokenCheck: params.skipInputTokenCheck,
|
|
211
209
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
212
|
-
return (0,
|
|
210
|
+
return (0, functions_1.createTransactionMeta)({
|
|
213
211
|
payer: params.userWallet,
|
|
214
212
|
description: "Deposit to existing position in Meteora DLMM",
|
|
215
213
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -227,7 +225,7 @@ class Transactions {
|
|
|
227
225
|
*/
|
|
228
226
|
meteoraWithdraw(_a) {
|
|
229
227
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
230
|
-
const userPda = (0,
|
|
228
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
231
229
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
232
230
|
let lbPair, binIdsToRemove;
|
|
233
231
|
if (params.fastGeneration !== undefined) {
|
|
@@ -271,7 +269,7 @@ class Transactions {
|
|
|
271
269
|
else {
|
|
272
270
|
description = "Partial position withdrawal from Meteora DLMM";
|
|
273
271
|
}
|
|
274
|
-
return (0,
|
|
272
|
+
return (0, functions_1.createTransactionMeta)({
|
|
275
273
|
payer: params.userWallet,
|
|
276
274
|
description,
|
|
277
275
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -299,14 +297,14 @@ class Transactions {
|
|
|
299
297
|
lbPair = position.lbPair;
|
|
300
298
|
}
|
|
301
299
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair);
|
|
302
|
-
const userPda = (0,
|
|
300
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
303
301
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
304
302
|
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
305
303
|
const mainInstructions = (yield dlmmPool.claimAllRewardsByPosition(params.userWallet, params.userWallet, {
|
|
306
304
|
owner: userPda,
|
|
307
305
|
position: userPositions[index],
|
|
308
306
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
309
|
-
return (0,
|
|
307
|
+
return (0, functions_1.createTransactionMeta)({
|
|
310
308
|
payer: params.userWallet,
|
|
311
309
|
description: "Claim fees / rewards from Meteora DLMM Position",
|
|
312
310
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -327,7 +325,7 @@ class Transactions {
|
|
|
327
325
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
328
326
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
329
327
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
330
|
-
const userPda = (0,
|
|
328
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
331
329
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
332
330
|
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
333
331
|
yield dlmmPool.getActiveBin();
|
|
@@ -335,7 +333,7 @@ class Transactions {
|
|
|
335
333
|
owner: userPda,
|
|
336
334
|
position: userPositions[index],
|
|
337
335
|
}, hsToMeteora_1.meteoraToHawksight);
|
|
338
|
-
return (0,
|
|
336
|
+
return (0, functions_1.createTransactionMeta)({
|
|
339
337
|
payer: params.userWallet,
|
|
340
338
|
description: "Close Meteora DLMM Position",
|
|
341
339
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -348,7 +346,7 @@ class Transactions {
|
|
|
348
346
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
349
347
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
350
348
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
351
|
-
const userPda = (0,
|
|
349
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
352
350
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
353
351
|
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
354
352
|
// Claim fee and claim reward ixs
|
|
@@ -377,7 +375,7 @@ class Transactions {
|
|
|
377
375
|
// Step 3: Re-deposit fees
|
|
378
376
|
...addLiquidityBuilder.mainIxs,
|
|
379
377
|
];
|
|
380
|
-
return (0,
|
|
378
|
+
return (0, functions_1.createTransactionMeta)({
|
|
381
379
|
payer: params.userWallet,
|
|
382
380
|
description: "Automation IX: Meteora Auto-compound instructions (claim fee, reward, and deposit to position)",
|
|
383
381
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -390,7 +388,7 @@ class Transactions {
|
|
|
390
388
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
391
389
|
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
392
390
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
393
|
-
const userPda = (0,
|
|
391
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
394
392
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
395
393
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
396
394
|
const binIdsToRemove = userPositions[0].positionData.positionBinData.map((bin) => bin.binId);
|
|
@@ -436,7 +434,7 @@ class Transactions {
|
|
|
436
434
|
// Sweep dust
|
|
437
435
|
...sweepLiquidityBuilder.mainIxs,
|
|
438
436
|
];
|
|
439
|
-
return (0,
|
|
437
|
+
return (0, functions_1.createTransactionMeta)({
|
|
440
438
|
payer: params.userWallet,
|
|
441
439
|
description: "Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)",
|
|
442
440
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -455,7 +453,7 @@ class Transactions {
|
|
|
455
453
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
456
454
|
const activePoolRewards = [];
|
|
457
455
|
const mainInstructions = [];
|
|
458
|
-
const userPda = (0,
|
|
456
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
459
457
|
if (params.protocol === types_2.Protocol.Meteora && params.pool) {
|
|
460
458
|
const poolInfo = yield (0, functions_1.getMeteoraPool)(params.pool);
|
|
461
459
|
if (poolInfo.reward_mint_x !== "11111111111111111111111111111111") {
|
|
@@ -467,7 +465,7 @@ class Transactions {
|
|
|
467
465
|
}
|
|
468
466
|
const combinedMints = [...params.mints, ...activePoolRewards];
|
|
469
467
|
const filteredMints = combinedMints.filter((m, i) => combinedMints.findIndex((mint) => mint.equals(m)) === i);
|
|
470
|
-
const storageAddresses = filteredMints.map((mint) => (0,
|
|
468
|
+
const storageAddresses = filteredMints.map((mint) => (0, functions_1.generateUserPdaStorageAccount)(userPda, mint));
|
|
471
469
|
const accountsData = yield connection.getMultipleAccountsInfo(storageAddresses, "processed");
|
|
472
470
|
for (let i = 0; i < accountsData.length; i++) {
|
|
473
471
|
if (!accountsData[i]) {
|
|
@@ -487,7 +485,7 @@ class Transactions {
|
|
|
487
485
|
}
|
|
488
486
|
}
|
|
489
487
|
if (mainInstructions.length) {
|
|
490
|
-
return (0,
|
|
488
|
+
return (0, functions_1.createTransactionMeta)({
|
|
491
489
|
payer: params.userWallet,
|
|
492
490
|
description: "Initialize STAs",
|
|
493
491
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -502,7 +500,7 @@ class Transactions {
|
|
|
502
500
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
503
501
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
504
502
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
505
|
-
const userPda = (0,
|
|
503
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
506
504
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
507
505
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
508
506
|
const binIdsToRemove = userPositions[0].positionData.positionBinData.map((bin) => bin.binId);
|
|
@@ -515,7 +513,7 @@ class Transactions {
|
|
|
515
513
|
shouldClaimAndClose: true,
|
|
516
514
|
});
|
|
517
515
|
// Filter out non-meteora instructions
|
|
518
|
-
const ixs = (0,
|
|
516
|
+
const ixs = (0, functions_1.getIxs)(txn).filter((ix) => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
519
517
|
const farm = addresses_1.USDC_FARM;
|
|
520
518
|
const authority = params.userWallet;
|
|
521
519
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -533,8 +531,8 @@ class Transactions {
|
|
|
533
531
|
position: _position.pubkey,
|
|
534
532
|
lbPair: lbPair.pubkey,
|
|
535
533
|
binArrayBitmapExtension: binArrayBitmapExtension.pubkey,
|
|
536
|
-
userTokenX: (0,
|
|
537
|
-
userTokenY: (0,
|
|
534
|
+
userTokenX: (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenXMint.pubkey),
|
|
535
|
+
userTokenY: (0, functions_1.generateUserPdaStorageAccount)(userPda, tokenYMint.pubkey),
|
|
538
536
|
reserveX: reserveX.pubkey,
|
|
539
537
|
reserveY: reserveY.pubkey,
|
|
540
538
|
tokenXMint: tokenXMint.pubkey,
|
|
@@ -545,8 +543,8 @@ class Transactions {
|
|
|
545
543
|
binArrayUpper: binArrayUpper.pubkey,
|
|
546
544
|
eventAuthority: eventAuthority.pubkey,
|
|
547
545
|
meteoraDlmmProgram: meteoraDlmmProgram.pubkey,
|
|
548
|
-
ownerFeeX: (0,
|
|
549
|
-
ownerFeeY: (0,
|
|
546
|
+
ownerFeeX: (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, tokenXMint.pubkey),
|
|
547
|
+
ownerFeeY: (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, tokenYMint.pubkey),
|
|
550
548
|
})
|
|
551
549
|
.instruction();
|
|
552
550
|
// Instruction via main hawksight contract
|
|
@@ -584,7 +582,7 @@ class Transactions {
|
|
|
584
582
|
// Limit Close Automation Instruction (Hawksight CPI)
|
|
585
583
|
ix,
|
|
586
584
|
];
|
|
587
|
-
return (0,
|
|
585
|
+
return (0, functions_1.createTransactionMeta)({
|
|
588
586
|
payer: params.userWallet,
|
|
589
587
|
description: "Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)",
|
|
590
588
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -595,7 +593,7 @@ class Transactions {
|
|
|
595
593
|
removeLiquidityByRangeInfo(ixs) {
|
|
596
594
|
for (const ix of ixs) {
|
|
597
595
|
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
598
|
-
const _sighashMatch = (0,
|
|
596
|
+
const _sighashMatch = (0, functions_1.sighashMatch)(ix.data, "RemoveLiquidityByRange");
|
|
599
597
|
if (programIdMatch && _sighashMatch) {
|
|
600
598
|
return {
|
|
601
599
|
data: ix.data,
|
|
@@ -633,9 +631,9 @@ class Transactions {
|
|
|
633
631
|
orcaOpenPosition(_a) {
|
|
634
632
|
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
635
633
|
const farm = addresses_1.USDC_FARM;
|
|
636
|
-
const userPda = (0,
|
|
637
|
-
const position = (0,
|
|
638
|
-
const positionTokenAccount = (0,
|
|
634
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
635
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
636
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
639
637
|
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
640
638
|
.orcaOpenPosition(params.tickLowerIndex, params.tickUpperIndex)
|
|
641
639
|
.accounts({
|
|
@@ -676,7 +674,7 @@ class Transactions {
|
|
|
676
674
|
])
|
|
677
675
|
.instruction();
|
|
678
676
|
const mainInstructions = [orcaOpenPositionIxViaMain];
|
|
679
|
-
return (0,
|
|
677
|
+
return (0, functions_1.createTransactionMeta)({
|
|
680
678
|
payer: params.userWallet,
|
|
681
679
|
description: "Create new Orca Position",
|
|
682
680
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -695,9 +693,9 @@ class Transactions {
|
|
|
695
693
|
orcaClosePosition(_a) {
|
|
696
694
|
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
697
695
|
const farm = addresses_1.USDC_FARM;
|
|
698
|
-
const userPda = (0,
|
|
699
|
-
const position = (0,
|
|
700
|
-
const positionTokenAccount = (0,
|
|
696
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
697
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
698
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
701
699
|
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
702
700
|
.orcaClosePosition()
|
|
703
701
|
.accounts({
|
|
@@ -732,7 +730,7 @@ class Transactions {
|
|
|
732
730
|
])
|
|
733
731
|
.instruction();
|
|
734
732
|
const mainInstructions = [orcaOpenPositionIxViaMain];
|
|
735
|
-
return (0,
|
|
733
|
+
return (0, functions_1.createTransactionMeta)({
|
|
736
734
|
payer: params.userWallet,
|
|
737
735
|
description: "Close Orca Position",
|
|
738
736
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -751,9 +749,9 @@ class Transactions {
|
|
|
751
749
|
orcaDeposit(_a) {
|
|
752
750
|
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
753
751
|
const farm = addresses_1.USDC_FARM;
|
|
754
|
-
const userPda = (0,
|
|
755
|
-
const position = (0,
|
|
756
|
-
const positionTokenAccount = (0,
|
|
752
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
753
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
754
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
757
755
|
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
758
756
|
if (positionData === null) {
|
|
759
757
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
@@ -766,7 +764,7 @@ class Transactions {
|
|
|
766
764
|
{ owner: params.userWallet, mint: mintA },
|
|
767
765
|
{ owner: params.userWallet, mint: mintB },
|
|
768
766
|
];
|
|
769
|
-
const resultMap = yield (0,
|
|
767
|
+
const resultMap = yield (0, functions_1.tokenAccountExists)(connection, tokenSeeds);
|
|
770
768
|
resultMap.map((result, index) => {
|
|
771
769
|
const tokenKey = result.tokenKey;
|
|
772
770
|
const token = tokenSeeds[index];
|
|
@@ -774,12 +772,12 @@ class Transactions {
|
|
|
774
772
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
775
773
|
}
|
|
776
774
|
});
|
|
777
|
-
const tokenOwnerAccountA = (0,
|
|
778
|
-
const tokenOwnerAccountB = (0,
|
|
779
|
-
const { publicKey: tickArrayLower } =
|
|
780
|
-
const { publicKey: tickArrayUpper } =
|
|
781
|
-
const ownerFeeA = (0,
|
|
782
|
-
const ownerFeeB = (0,
|
|
775
|
+
const tokenOwnerAccountA = (0, functions_1.generateAta)(userPda, mintA);
|
|
776
|
+
const tokenOwnerAccountB = (0, functions_1.generateAta)(userPda, mintB);
|
|
777
|
+
const { publicKey: tickArrayLower } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
778
|
+
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
779
|
+
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
780
|
+
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
783
781
|
const depositIx = yield (0, hawksight_1.depositMultipleToken)({
|
|
784
782
|
payer: params.userWallet,
|
|
785
783
|
deposit: [
|
|
@@ -852,7 +850,7 @@ class Transactions {
|
|
|
852
850
|
],
|
|
853
851
|
});
|
|
854
852
|
const mainInstructions = [depositIx, orcaOpenPositionIxViaMain, clearRemainingTokensIxs];
|
|
855
|
-
return (0,
|
|
853
|
+
return (0, functions_1.createTransactionMeta)({
|
|
856
854
|
payer: params.userWallet,
|
|
857
855
|
description: `Deposit to Orca Position: ${position}`,
|
|
858
856
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -871,9 +869,9 @@ class Transactions {
|
|
|
871
869
|
orcaWithdraw(_a) {
|
|
872
870
|
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
873
871
|
const farm = addresses_1.USDC_FARM;
|
|
874
|
-
const userPda = (0,
|
|
875
|
-
const position = (0,
|
|
876
|
-
const positionTokenAccount = (0,
|
|
872
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
873
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
874
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
877
875
|
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
878
876
|
if (positionData === null) {
|
|
879
877
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
@@ -882,12 +880,12 @@ class Transactions {
|
|
|
882
880
|
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
883
881
|
const mintA = whirlpoolData.tokenMintA;
|
|
884
882
|
const mintB = whirlpoolData.tokenMintB;
|
|
885
|
-
const tokenOwnerAccountA = (0,
|
|
886
|
-
const tokenOwnerAccountB = (0,
|
|
887
|
-
const { publicKey: tickArrayLower } =
|
|
888
|
-
const { publicKey: tickArrayUpper } =
|
|
889
|
-
const ownerFeeA = (0,
|
|
890
|
-
const ownerFeeB = (0,
|
|
883
|
+
const tokenOwnerAccountA = (0, functions_1.generateAta)(userPda, mintA);
|
|
884
|
+
const tokenOwnerAccountB = (0, functions_1.generateAta)(userPda, mintB);
|
|
885
|
+
const { publicKey: tickArrayLower } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
886
|
+
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
887
|
+
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
888
|
+
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
891
889
|
const orcaOpenPositionIx = yield anchor_1.Anchor.instance().iyfExtension.methods
|
|
892
890
|
.orcaWithdraw(params.liquidityAmount)
|
|
893
891
|
.accounts({
|
|
@@ -947,7 +945,7 @@ class Transactions {
|
|
|
947
945
|
],
|
|
948
946
|
});
|
|
949
947
|
const mainInstructions = [orcaOpenPositionIxViaMain, withdrawFromPda];
|
|
950
|
-
return (0,
|
|
948
|
+
return (0, functions_1.createTransactionMeta)({
|
|
951
949
|
payer: params.userWallet,
|
|
952
950
|
description: `Withdraw deposits from Orca Position: ${position}`,
|
|
953
951
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -966,9 +964,9 @@ class Transactions {
|
|
|
966
964
|
orcaClaimRewards(_a) {
|
|
967
965
|
return __awaiter(this, arguments, void 0, function* ({ connection, params }) {
|
|
968
966
|
const farm = addresses_1.USDC_FARM;
|
|
969
|
-
const userPda = (0,
|
|
970
|
-
const position = (0,
|
|
971
|
-
const positionTokenAccount = (0,
|
|
967
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
968
|
+
const position = (0, functions_1.generateOrcaPositionPDA)(params.positionMint);
|
|
969
|
+
const positionTokenAccount = (0, functions_1.generateAta)(userPda, params.positionMint);
|
|
972
970
|
const positionData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPosition(position);
|
|
973
971
|
if (positionData === null) {
|
|
974
972
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${params.positionMint}`);
|
|
@@ -977,18 +975,18 @@ class Transactions {
|
|
|
977
975
|
const whirlpoolData = yield anchor_1.Anchor.instance().whirlpoolCtx.fetcher.getPool(whirlpool);
|
|
978
976
|
const mintA = whirlpoolData.tokenMintA;
|
|
979
977
|
const mintB = whirlpoolData.tokenMintB;
|
|
980
|
-
const tokenOwnerAccountA = (0,
|
|
981
|
-
const tokenOwnerAccountB = (0,
|
|
982
|
-
const { publicKey: tickArrayLower } =
|
|
983
|
-
const { publicKey: tickArrayUpper } =
|
|
984
|
-
const ownerFeeA = (0,
|
|
985
|
-
const ownerFeeB = (0,
|
|
978
|
+
const tokenOwnerAccountA = (0, functions_1.generateAta)(userPda, mintA);
|
|
979
|
+
const tokenOwnerAccountB = (0, functions_1.generateAta)(userPda, mintB);
|
|
980
|
+
const { publicKey: tickArrayLower } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickLowerIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
981
|
+
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
982
|
+
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
983
|
+
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
986
984
|
const remainingAccounts = [];
|
|
987
985
|
for (const rewardInfo of whirlpoolData.rewardInfos) {
|
|
988
986
|
if (rewardInfo.mint.toString() !== web3.SystemProgram.programId.toString()) {
|
|
989
|
-
const rewardOwnerAccount = (0,
|
|
987
|
+
const rewardOwnerAccount = (0, functions_1.generateAta)(userPda, rewardInfo.mint);
|
|
990
988
|
const rewardVault = rewardInfo.vault;
|
|
991
|
-
const rewardFee = (0,
|
|
989
|
+
const rewardFee = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, rewardInfo.mint);
|
|
992
990
|
remainingAccounts.push({ pubkey: rewardOwnerAccount, isSigner: false, isWritable: true });
|
|
993
991
|
remainingAccounts.push({ pubkey: rewardVault, isSigner: false, isWritable: true });
|
|
994
992
|
remainingAccounts.push({ pubkey: rewardFee, isSigner: false, isWritable: true });
|
|
@@ -1055,7 +1053,7 @@ class Transactions {
|
|
|
1055
1053
|
],
|
|
1056
1054
|
});
|
|
1057
1055
|
const mainInstructions = [orcaOpenPositionIxViaMain, withdrawFromPda];
|
|
1058
|
-
return (0,
|
|
1056
|
+
return (0, functions_1.createTransactionMeta)({
|
|
1059
1057
|
payer: params.userWallet,
|
|
1060
1058
|
description: `Claim rewards from Orca Position: ${position}`,
|
|
1061
1059
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="@meteora-ag/dlmm/node_modules/@solana/web3.js" />
|
|
2
|
+
import * as web3 from "@solana/web3.js";
|
|
3
|
+
export declare const TICK_ARRAY_SIZE = 88;
|
|
4
|
+
export declare const MIN_TICK_INDEX = -443636;
|
|
5
|
+
export declare const MAX_TICK_INDEX = 443636;
|
|
6
|
+
export declare const PDA_TICK_ARRAY_SEED = "tick_array";
|
|
7
|
+
/**
|
|
8
|
+
* Get the PDA of the tick array containing tickIndex.
|
|
9
|
+
* tickArrayOffset can be used to get neighboring tick arrays.
|
|
10
|
+
*
|
|
11
|
+
* @param tickIndex
|
|
12
|
+
* @param tickSpacing
|
|
13
|
+
* @param whirlpool
|
|
14
|
+
* @param programId
|
|
15
|
+
* @param tickArrayOffset
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTickArrayFromTickIndex(tickIndex: number, tickSpacing: number, whirlpool: web3.PublicKey, programId: web3.PublicKey, tickArrayOffset?: number): {
|
|
19
|
+
bump: number;
|
|
20
|
+
publicKey: web3.PublicKey;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Get the startIndex of the tick array containing tickIndex.
|
|
24
|
+
*
|
|
25
|
+
* @param tickIndex
|
|
26
|
+
* @param tickSpacing
|
|
27
|
+
* @param offset can be used to get neighboring tick array startIndex.
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare function getStartTickIndex(tickIndex: number, tickSpacing: number, offset?: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* @category Program Derived Addresses
|
|
33
|
+
* @param programId
|
|
34
|
+
* @param whirlpoolAddress
|
|
35
|
+
* @param startTick
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export declare function getTickArray(programId: web3.PublicKey, whirlpoolAddress: web3.PublicKey, startTick: number): {
|
|
39
|
+
bump: number;
|
|
40
|
+
publicKey: web3.PublicKey;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=orca.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orca.d.ts","sourceRoot":"","sources":["../../src/orca.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAGxC,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,eAAe,GAAE,MAAU;;;EAGlK;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAE,MAAU,UAQ3F;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM;;;EAO1G"}
|
package/dist/src/orca.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getTickArray = exports.getStartTickIndex = exports.getTickArrayFromTickIndex = exports.PDA_TICK_ARRAY_SEED = exports.MAX_TICK_INDEX = exports.MIN_TICK_INDEX = exports.TICK_ARRAY_SIZE = void 0;
|
|
30
|
+
const web3 = __importStar(require("@solana/web3.js"));
|
|
31
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
32
|
+
exports.TICK_ARRAY_SIZE = 88;
|
|
33
|
+
exports.MIN_TICK_INDEX = -443636;
|
|
34
|
+
exports.MAX_TICK_INDEX = 443636;
|
|
35
|
+
exports.PDA_TICK_ARRAY_SEED = "tick_array";
|
|
36
|
+
/**
|
|
37
|
+
* Get the PDA of the tick array containing tickIndex.
|
|
38
|
+
* tickArrayOffset can be used to get neighboring tick arrays.
|
|
39
|
+
*
|
|
40
|
+
* @param tickIndex
|
|
41
|
+
* @param tickSpacing
|
|
42
|
+
* @param whirlpool
|
|
43
|
+
* @param programId
|
|
44
|
+
* @param tickArrayOffset
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
function getTickArrayFromTickIndex(tickIndex, tickSpacing, whirlpool, programId, tickArrayOffset = 0) {
|
|
48
|
+
const startIndex = getStartTickIndex(tickIndex, tickSpacing, tickArrayOffset);
|
|
49
|
+
return getTickArray(programId, whirlpool, startIndex);
|
|
50
|
+
}
|
|
51
|
+
exports.getTickArrayFromTickIndex = getTickArrayFromTickIndex;
|
|
52
|
+
/**
|
|
53
|
+
* Get the startIndex of the tick array containing tickIndex.
|
|
54
|
+
*
|
|
55
|
+
* @param tickIndex
|
|
56
|
+
* @param tickSpacing
|
|
57
|
+
* @param offset can be used to get neighboring tick array startIndex.
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
function getStartTickIndex(tickIndex, tickSpacing, offset = 0) {
|
|
61
|
+
const realIndex = Math.floor(tickIndex / tickSpacing / exports.TICK_ARRAY_SIZE);
|
|
62
|
+
const startTickIndex = (realIndex + offset) * tickSpacing * exports.TICK_ARRAY_SIZE;
|
|
63
|
+
const ticksInArray = exports.TICK_ARRAY_SIZE * tickSpacing;
|
|
64
|
+
const minTickIndex = exports.MIN_TICK_INDEX - ((exports.MIN_TICK_INDEX % ticksInArray) + ticksInArray);
|
|
65
|
+
(0, tiny_invariant_1.default)(startTickIndex >= minTickIndex, `startTickIndex is too small - - ${startTickIndex}`);
|
|
66
|
+
(0, tiny_invariant_1.default)(startTickIndex <= exports.MAX_TICK_INDEX, `startTickIndex is too large - ${startTickIndex}`);
|
|
67
|
+
return startTickIndex;
|
|
68
|
+
}
|
|
69
|
+
exports.getStartTickIndex = getStartTickIndex;
|
|
70
|
+
/**
|
|
71
|
+
* @category Program Derived Addresses
|
|
72
|
+
* @param programId
|
|
73
|
+
* @param whirlpoolAddress
|
|
74
|
+
* @param startTick
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
function getTickArray(programId, whirlpoolAddress, startTick) {
|
|
78
|
+
const [publicKey, bump] = web3.PublicKey.findProgramAddressSync([
|
|
79
|
+
Buffer.from(exports.PDA_TICK_ARRAY_SEED),
|
|
80
|
+
whirlpoolAddress.toBuffer(),
|
|
81
|
+
Buffer.from(startTick.toString()),
|
|
82
|
+
], programId);
|
|
83
|
+
return { bump, publicKey };
|
|
84
|
+
}
|
|
85
|
+
exports.getTickArray = getTickArray;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hawksightco/hawk-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Hawksight v2 SDK",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"repository": "https://github.com/ghabxph/hawk-api-client.git",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"@solana/spl-token": "^0.4.6",
|
|
29
29
|
"@solana/web3.js": "^1.89.1",
|
|
30
30
|
"bn.js": "^5.2.1",
|
|
31
|
-
"lodash": "^4.17.21"
|
|
31
|
+
"lodash": "^4.17.21",
|
|
32
|
+
"tiny-invariant": "^1.3.1"
|
|
32
33
|
},
|
|
33
34
|
"scripts": {
|
|
34
35
|
"start": "npx ts-node src/index.ts",
|