@hawksightco/hawk-sdk 1.3.143 → 1.3.146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/classes/Transactions.d.ts +16 -6
- package/dist/src/classes/Transactions.d.ts.map +1 -1
- package/dist/src/classes/Transactions.js +288 -126
- package/dist/src/classes/TxGenerator.d.ts +12 -2
- package/dist/src/classes/TxGenerator.d.ts.map +1 -1
- package/dist/src/classes/TxGenerator.js +63 -1
- package/dist/src/idl/iyf-main-idl.d.ts +1 -0
- package/dist/src/idl/iyf-main-idl.d.ts.map +1 -1
- package/dist/src/idl/iyf-main-idl.js +2 -1
- package/dist/src/ixGenerator/IyfMainIxGenerator.js +2 -2
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts +28 -2
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/MeteoraDlmmIxGenerator.js +94 -2
- package/dist/src/meteora.d.ts +3 -3
- package/dist/src/meteora.d.ts.map +1 -1
- package/dist/src/meteora.js +12 -12
- package/dist/src/pdaGenerator/HawksightPdaGenerator.d.ts +6 -0
- package/dist/src/pdaGenerator/HawksightPdaGenerator.d.ts.map +1 -1
- package/dist/src/pdaGenerator/HawksightPdaGenerator.js +9 -0
- package/dist/src/types.d.ts +16 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +3 -2
|
@@ -111,26 +111,26 @@ class Transactions {
|
|
|
111
111
|
const farm = addresses_1.USDC_FARM;
|
|
112
112
|
const user = (0, functions_1.generateUserPda)(params.authority, farm);
|
|
113
113
|
const [stableToken] = web3.PublicKey.findProgramAddressSync([
|
|
114
|
-
Buffer.from(
|
|
114
|
+
Buffer.from('index-token', 'utf-8'),
|
|
115
115
|
addresses_1.STABLEMINT_1.toBuffer(),
|
|
116
116
|
farm.toBuffer(),
|
|
117
117
|
user.toBuffer(),
|
|
118
118
|
], anchor_1.Anchor.instance().iyfMain.programId);
|
|
119
119
|
const [stableToken2] = web3.PublicKey.findProgramAddressSync([
|
|
120
|
-
Buffer.from(
|
|
120
|
+
Buffer.from('index-token', 'utf-8'),
|
|
121
121
|
addresses_1.STABLEMINT_2.toBuffer(),
|
|
122
122
|
farm.toBuffer(),
|
|
123
123
|
user.toBuffer(),
|
|
124
124
|
], anchor_1.Anchor.instance().iyfMain.programId);
|
|
125
125
|
// check if user pda is already registered:
|
|
126
126
|
try {
|
|
127
|
-
yield anchor_1.Anchor.instance().iyfMain.account.userAccountMulti.fetch(user,
|
|
127
|
+
yield anchor_1.Anchor.instance().iyfMain.account.userAccountMulti.fetch(user, 'confirmed');
|
|
128
128
|
throw new Error(`User PDA for wallet: ${params.authority} is already registered.`);
|
|
129
129
|
}
|
|
130
130
|
catch (_b) {
|
|
131
131
|
return (0, functions_1.createTransactionMeta)({
|
|
132
132
|
payer: params.authority,
|
|
133
|
-
description:
|
|
133
|
+
description: 'Register User',
|
|
134
134
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
135
135
|
mainInstructions: [
|
|
136
136
|
// @ts-ignore
|
|
@@ -168,17 +168,17 @@ class Transactions {
|
|
|
168
168
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
169
169
|
if (params.protocol === types_2.Protocol.Meteora && params.pool) {
|
|
170
170
|
const poolInfo = yield (0, functions_1.getMeteoraPool)(params.pool);
|
|
171
|
-
if (poolInfo.reward_mint_x !==
|
|
171
|
+
if (poolInfo.reward_mint_x !== '11111111111111111111111111111111') {
|
|
172
172
|
activePoolRewards.push(new web3.PublicKey(poolInfo.reward_mint_x));
|
|
173
173
|
}
|
|
174
|
-
if (poolInfo.reward_mint_y !==
|
|
174
|
+
if (poolInfo.reward_mint_y !== '11111111111111111111111111111111') {
|
|
175
175
|
activePoolRewards.push(new web3.PublicKey(poolInfo.reward_mint_y));
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
const combinedMints = [...params.mints, ...activePoolRewards];
|
|
179
|
-
const filteredMints = combinedMints.filter((m, i) => combinedMints.findIndex(
|
|
180
|
-
const storageAddresses = filteredMints.map(
|
|
181
|
-
const accountsData = yield connection.getMultipleAccountsInfo(storageAddresses,
|
|
179
|
+
const filteredMints = combinedMints.filter((m, i) => combinedMints.findIndex(mint => mint.equals(m)) === i);
|
|
180
|
+
const storageAddresses = filteredMints.map(mint => (0, functions_1.generateUserPdaStorageAccount)(userPda, mint));
|
|
181
|
+
const accountsData = yield connection.getMultipleAccountsInfo(storageAddresses, 'processed');
|
|
182
182
|
for (let i = 0; i < accountsData.length; i++) {
|
|
183
183
|
if (!accountsData[i]) {
|
|
184
184
|
(0, Logging_1.Log)(`initializing STA: ${filteredMints[i].toBase58()}`);
|
|
@@ -190,7 +190,7 @@ class Transactions {
|
|
|
190
190
|
}
|
|
191
191
|
return (0, functions_1.createTransactionMeta)({
|
|
192
192
|
payer: params.userWallet,
|
|
193
|
-
description:
|
|
193
|
+
description: 'Initialize STAs',
|
|
194
194
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
195
195
|
mainInstructions,
|
|
196
196
|
});
|
|
@@ -226,7 +226,7 @@ class Transactions {
|
|
|
226
226
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
227
227
|
return (0, functions_1.createTransactionMeta)({
|
|
228
228
|
payer: params.userWallet,
|
|
229
|
-
description:
|
|
229
|
+
description: 'Create position and deposit to Meteora DLMM',
|
|
230
230
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
231
231
|
mainInstructions,
|
|
232
232
|
});
|
|
@@ -260,7 +260,7 @@ class Transactions {
|
|
|
260
260
|
}, hsToMeteora_1.meteoraToHawksightPdaIxs)).default();
|
|
261
261
|
return (0, functions_1.createTransactionMeta)({
|
|
262
262
|
payer: params.userWallet,
|
|
263
|
-
description:
|
|
263
|
+
description: 'Create position and deposit to Meteora DLMM',
|
|
264
264
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
265
265
|
mainInstructions,
|
|
266
266
|
});
|
|
@@ -279,10 +279,101 @@ class Transactions {
|
|
|
279
279
|
const poolAddress = new web3.PublicKey(params.pool);
|
|
280
280
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, poolAddress, this.ix);
|
|
281
281
|
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);
|
|
282
|
-
const mainInstructions = yield dlmmPool.dlmm.initializeBinArrays(binArraysRequired.map(
|
|
282
|
+
const mainInstructions = yield dlmmPool.dlmm.initializeBinArrays(binArraysRequired.map(b => b.index), new web3.PublicKey(params.userWallet));
|
|
283
283
|
return (0, functions_1.createTransactionMeta)({
|
|
284
284
|
payer: params.userWallet,
|
|
285
|
-
description:
|
|
285
|
+
description: 'Initialize bin arrays for Meteora DLMM pool',
|
|
286
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
287
|
+
mainInstructions,
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Creates meteora instruction that initializes bin arrays (via hawkfi program -- main iyf)
|
|
293
|
+
*
|
|
294
|
+
* @param connection The Solana web3 connection object for blockchain interactions.
|
|
295
|
+
* @param payer The public key of the payer for transaction fees.
|
|
296
|
+
* @param params Parameters required
|
|
297
|
+
* @returns A ResponseWithStatus containing either TransactionMetadataResponse.
|
|
298
|
+
*/
|
|
299
|
+
meteoraInitializeBinArrays2(_a) {
|
|
300
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
301
|
+
const mainInstructions = [
|
|
302
|
+
yield this.ix.meteoraDlmm.meteoraDlmmInitializeBinArray({
|
|
303
|
+
connection,
|
|
304
|
+
userWallet: params.userWallet,
|
|
305
|
+
lbPair: params.pool,
|
|
306
|
+
lowerBinId: params.minBinId,
|
|
307
|
+
upperBinId: params.maxBinId,
|
|
308
|
+
}),
|
|
309
|
+
];
|
|
310
|
+
return (0, functions_1.createTransactionMeta)({
|
|
311
|
+
payer: params.userWallet,
|
|
312
|
+
description: 'Initialize bin arrays for Meteora DLMM pool',
|
|
313
|
+
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
314
|
+
mainInstructions,
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
meteoraCreatePoolAndPosition(_a) {
|
|
319
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
320
|
+
const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
|
|
321
|
+
params.tokenMintX,
|
|
322
|
+
params.tokenMintY,
|
|
323
|
+
]);
|
|
324
|
+
const tokenProgramX = tokenProgramMap[params.tokenMintX.toString()];
|
|
325
|
+
const tokenProgramY = tokenProgramMap[params.tokenMintY.toString()];
|
|
326
|
+
const validOwners = [
|
|
327
|
+
addresses_1.TOKEN_PROGRAM_ID.toString(),
|
|
328
|
+
addresses_1.TOKEN_2022_PROGRAM_ID.toString(),
|
|
329
|
+
];
|
|
330
|
+
if (!validOwners.includes(tokenProgramX.toString())) {
|
|
331
|
+
throw new errors_1.AppError(`tokenMintX: ${params.tokenMintX.toString()} is not a valid token mint. Program owner: ${tokenProgramX.toString()}`, 'meteoraCreatePoolAndPosition');
|
|
332
|
+
}
|
|
333
|
+
if (!validOwners.includes(tokenProgramY.toString())) {
|
|
334
|
+
throw new errors_1.AppError(`tokenMintY: ${params.tokenMintY.toString()} is not a valid token mint. Program owner: ${tokenProgramY.toString()}`, 'meteoraCreatePoolAndPosition');
|
|
335
|
+
}
|
|
336
|
+
const mainInstructions = yield Promise.all([
|
|
337
|
+
...(0, functions_1.wrapSolIfMintIsWsol)(params.userWallet, params.userWallet, [
|
|
338
|
+
{ mint: params.tokenMintX, amount: params.amountX },
|
|
339
|
+
{ mint: params.tokenMintY, amount: params.amountY },
|
|
340
|
+
]),
|
|
341
|
+
this.ix.iyfMain.depositMultipleTokenWithToken2022({
|
|
342
|
+
connection,
|
|
343
|
+
payer: params.userWallet,
|
|
344
|
+
deposit: [
|
|
345
|
+
{
|
|
346
|
+
mint: params.tokenMintX,
|
|
347
|
+
amount: params.amountX,
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
mint: params.tokenMintY,
|
|
351
|
+
amount: params.amountY,
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
pdaTokenType: types_1.TokenType.ATA,
|
|
355
|
+
}),
|
|
356
|
+
this.ix.meteoraDlmm.meteoraDlmmCreatePoolAndPosition({
|
|
357
|
+
connection,
|
|
358
|
+
userWallet: params.userWallet,
|
|
359
|
+
position: params.position,
|
|
360
|
+
presetParameter: params.presetParameter,
|
|
361
|
+
tokenMintX: params.tokenMintX,
|
|
362
|
+
tokenMintY: params.tokenMintY,
|
|
363
|
+
tokenProgramX,
|
|
364
|
+
tokenProgramY,
|
|
365
|
+
activeId: params.activeId,
|
|
366
|
+
lowerBinId: params.lowerBinId,
|
|
367
|
+
upperBinId: params.upperBinId,
|
|
368
|
+
strategyType: params.strategyType,
|
|
369
|
+
binStep: params.binStep,
|
|
370
|
+
baseFactor: params.baseFactor,
|
|
371
|
+
baseFeePowerFactor: params.baseFeePowerFactor,
|
|
372
|
+
}),
|
|
373
|
+
]);
|
|
374
|
+
return (0, functions_1.createTransactionMeta)({
|
|
375
|
+
payer: params.userWallet,
|
|
376
|
+
description: 'Create pool and position in Meteora DLMM',
|
|
286
377
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
287
378
|
mainInstructions,
|
|
288
379
|
});
|
|
@@ -329,7 +420,7 @@ class Transactions {
|
|
|
329
420
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
330
421
|
return (0, functions_1.createTransactionMeta)({
|
|
331
422
|
payer: params.userWallet,
|
|
332
|
-
description:
|
|
423
|
+
description: 'Deposit to existing position in Meteora DLMM',
|
|
333
424
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
334
425
|
mainInstructions,
|
|
335
426
|
});
|
|
@@ -358,9 +449,9 @@ class Transactions {
|
|
|
358
449
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
|
|
359
450
|
if (params.fastGeneration === undefined) {
|
|
360
451
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
361
|
-
const userPosition = userPositions.find(
|
|
452
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.toString() === params.position.toString());
|
|
362
453
|
if (userPosition === undefined) {
|
|
363
|
-
throw new Error(
|
|
454
|
+
throw new Error('Position does not exist.'); // this error should not happen...
|
|
364
455
|
}
|
|
365
456
|
lowerBinId = userPosition.positionData.lowerBinId;
|
|
366
457
|
upperBinId = userPosition.positionData.upperBinId;
|
|
@@ -384,14 +475,14 @@ class Transactions {
|
|
|
384
475
|
let description;
|
|
385
476
|
if (params.shouldClaimAndClose) {
|
|
386
477
|
description =
|
|
387
|
-
|
|
478
|
+
'Full position withdrawal with claim and close instructisons from Meteora DLMM';
|
|
388
479
|
}
|
|
389
480
|
else if (amountBps.eq(new bn_js_1.default(10000))) {
|
|
390
481
|
description =
|
|
391
|
-
|
|
482
|
+
'Full position withdrawal without claim and close instructions from Meteora DLMM';
|
|
392
483
|
}
|
|
393
484
|
else {
|
|
394
|
-
description =
|
|
485
|
+
description = 'Partial position withdrawal from Meteora DLMM';
|
|
395
486
|
}
|
|
396
487
|
return (0, functions_1.createTransactionMeta)({
|
|
397
488
|
payer: params.userWallet,
|
|
@@ -424,9 +515,9 @@ class Transactions {
|
|
|
424
515
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
|
|
425
516
|
if (params.fastGeneration === undefined) {
|
|
426
517
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
427
|
-
const userPosition = userPositions.find(
|
|
518
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.toString() === params.position.toString());
|
|
428
519
|
if (userPosition === undefined) {
|
|
429
|
-
throw new Error(
|
|
520
|
+
throw new Error('Position does not exist.'); // this error should not happen...
|
|
430
521
|
}
|
|
431
522
|
lowerBinId = userPosition.positionData.lowerBinId;
|
|
432
523
|
upperBinId = userPosition.positionData.upperBinId;
|
|
@@ -456,14 +547,14 @@ class Transactions {
|
|
|
456
547
|
let description;
|
|
457
548
|
if (params.shouldClaimAndClose) {
|
|
458
549
|
description =
|
|
459
|
-
|
|
550
|
+
'Full position withdrawal with claim and close instructisons from Meteora DLMM';
|
|
460
551
|
}
|
|
461
552
|
else if (amountBps.eq(new bn_js_1.default(10000))) {
|
|
462
553
|
description =
|
|
463
|
-
|
|
554
|
+
'Full position withdrawal without claim and close instructions from Meteora DLMM';
|
|
464
555
|
}
|
|
465
556
|
else {
|
|
466
|
-
description =
|
|
557
|
+
description = 'Partial position withdrawal from Meteora DLMM';
|
|
467
558
|
}
|
|
468
559
|
return (0, functions_1.createTransactionMeta)({
|
|
469
560
|
payer: params.userWallet,
|
|
@@ -497,7 +588,7 @@ class Transactions {
|
|
|
497
588
|
const mainInstructions = (yield fn.claimFeeAndRewardIxs2(connection, [params.position], params.userWallet, userPda, hsToMeteora_1.meteoraToHawksight, lbPair)).default();
|
|
498
589
|
const txMeta = (0, functions_1.createTransactionMeta)({
|
|
499
590
|
payer: params.userWallet,
|
|
500
|
-
description:
|
|
591
|
+
description: 'Claim fees / rewards from Meteora DLMM Position',
|
|
501
592
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
502
593
|
mainInstructions,
|
|
503
594
|
});
|
|
@@ -524,13 +615,13 @@ class Transactions {
|
|
|
524
615
|
// Step 2.5: Generate transactions
|
|
525
616
|
const mainInstructions = builder.default();
|
|
526
617
|
const latestBlockhash = yield connection.getLatestBlockhash();
|
|
527
|
-
const batchGenerator = new TransactionBatchExecute2_1.TransactionBatchExecute2(addresses_1.GLOBAL_ALT.map(
|
|
618
|
+
const batchGenerator = new TransactionBatchExecute2_1.TransactionBatchExecute2(addresses_1.GLOBAL_ALT.map(p => new web3.PublicKey(p)), mainInstructions, connection, CreateTxMetadata_1.CreateTxMetadata.instance(), latestBlockhash, payer);
|
|
528
619
|
// Insert nonce advance tx at end of transaction
|
|
529
620
|
batchGenerator.insertNonceAt({
|
|
530
621
|
onlyEndOfTx: true,
|
|
531
622
|
});
|
|
532
623
|
// Generate batch of transactions
|
|
533
|
-
const txs = yield batchGenerator.buildBatchWithAlts(
|
|
624
|
+
const txs = yield batchGenerator.buildBatchWithAlts('Claim all fees / rewards from Meteora DLMM position', generalUtility);
|
|
534
625
|
// Simplified return value
|
|
535
626
|
return txs;
|
|
536
627
|
});
|
|
@@ -550,7 +641,7 @@ class Transactions {
|
|
|
550
641
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
551
642
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
552
643
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
553
|
-
const index = userPositions.findIndex(
|
|
644
|
+
const index = userPositions.findIndex(v => v.publicKey.equals(params.position));
|
|
554
645
|
yield dlmmPool.getActiveBin();
|
|
555
646
|
const mainInstructions = yield dlmmPool.closePosition(params.userWallet, {
|
|
556
647
|
owner: userPda,
|
|
@@ -558,7 +649,7 @@ class Transactions {
|
|
|
558
649
|
}, hsToMeteora_1.meteoraToHawksight);
|
|
559
650
|
return (0, functions_1.createTransactionMeta)({
|
|
560
651
|
payer: params.userWallet,
|
|
561
|
-
description:
|
|
652
|
+
description: 'Close Meteora DLMM Position',
|
|
562
653
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
563
654
|
mainInstructions,
|
|
564
655
|
});
|
|
@@ -576,11 +667,26 @@ class Transactions {
|
|
|
576
667
|
const farm = addresses_1.USDC_FARM;
|
|
577
668
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
578
669
|
const mainInstructions = [];
|
|
579
|
-
const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
|
|
670
|
+
const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
|
|
671
|
+
params.mint,
|
|
672
|
+
]);
|
|
580
673
|
const result = yield (0, functions_1.tokenAccountExists)(connection, [
|
|
581
|
-
{
|
|
582
|
-
|
|
583
|
-
|
|
674
|
+
{
|
|
675
|
+
owner: params.userWallet,
|
|
676
|
+
mint: params.mint,
|
|
677
|
+
tokenProgram: tokenProgramMap[params.mint.toString()],
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
owner: userPda,
|
|
681
|
+
mint: params.mint,
|
|
682
|
+
tokenProgram: tokenProgramMap[params.mint.toString()],
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
owner: userPda,
|
|
686
|
+
mint: params.mint,
|
|
687
|
+
isSta: true,
|
|
688
|
+
tokenProgram: tokenProgramMap[params.mint.toString()],
|
|
689
|
+
},
|
|
584
690
|
]);
|
|
585
691
|
// if (!result[0].exists) {
|
|
586
692
|
// mainInstructions.push(
|
|
@@ -602,15 +708,15 @@ class Transactions {
|
|
|
602
708
|
// })
|
|
603
709
|
// );
|
|
604
710
|
// }
|
|
605
|
-
if (result[2].exists) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
}
|
|
711
|
+
// if (result[2].exists) {
|
|
712
|
+
mainInstructions.push(yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
713
|
+
connection,
|
|
714
|
+
payer: params.userWallet,
|
|
715
|
+
withdraw: [{ mint: params.mint, amount: new bn_js_1.default(0) }],
|
|
716
|
+
pdaTokenType: types_1.TokenType.STA,
|
|
717
|
+
hasAmount: false,
|
|
718
|
+
}));
|
|
719
|
+
// }
|
|
614
720
|
mainInstructions.push(yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
615
721
|
connection,
|
|
616
722
|
payer: params.userWallet,
|
|
@@ -621,7 +727,7 @@ class Transactions {
|
|
|
621
727
|
mainInstructions.push(...(0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [params.mint]));
|
|
622
728
|
return (0, functions_1.createTransactionMeta)({
|
|
623
729
|
payer: params.userWallet,
|
|
624
|
-
description:
|
|
730
|
+
description: 'Withdraw token from PDA',
|
|
625
731
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
626
732
|
mainInstructions: mainInstructions,
|
|
627
733
|
});
|
|
@@ -639,11 +745,11 @@ class Transactions {
|
|
|
639
745
|
const farm = addresses_1.USDC_FARM;
|
|
640
746
|
const mainInstructions = [];
|
|
641
747
|
const result = yield (0, functions_1.tokenAccountExists)(connection, [
|
|
642
|
-
...params.mints.map(
|
|
748
|
+
...params.mints.map(mint => {
|
|
643
749
|
return { owner: params.userWallet, mint };
|
|
644
750
|
}),
|
|
645
751
|
]);
|
|
646
|
-
result.map(
|
|
752
|
+
result.map(result => {
|
|
647
753
|
if (!result.exists) {
|
|
648
754
|
mainInstructions.push(this.ix.util.createAssociatedTokenAccountInstruction({
|
|
649
755
|
payer: params.userWallet,
|
|
@@ -655,7 +761,7 @@ class Transactions {
|
|
|
655
761
|
mainInstructions.push(yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
656
762
|
connection,
|
|
657
763
|
payer: params.userWallet,
|
|
658
|
-
withdraw: params.mints.map(
|
|
764
|
+
withdraw: params.mints.map(mint => {
|
|
659
765
|
return { mint, amount: new bn_js_1.default(0) };
|
|
660
766
|
}),
|
|
661
767
|
pdaTokenType: types_1.TokenType.STA,
|
|
@@ -663,7 +769,7 @@ class Transactions {
|
|
|
663
769
|
}));
|
|
664
770
|
return (0, functions_1.createTransactionMeta)({
|
|
665
771
|
payer: params.userWallet,
|
|
666
|
-
description:
|
|
772
|
+
description: 'Withdraw multiple token/s from STA',
|
|
667
773
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
668
774
|
mainInstructions: mainInstructions,
|
|
669
775
|
});
|
|
@@ -681,12 +787,13 @@ class Transactions {
|
|
|
681
787
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
682
788
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
683
789
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
684
|
-
const userPosition = userPositions.find(
|
|
790
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.position));
|
|
685
791
|
if (userPosition === undefined) {
|
|
686
792
|
throw new Error(`Position: ${params.position} does not exist.`);
|
|
687
793
|
}
|
|
688
794
|
// Validate position bin IDs
|
|
689
|
-
if (position.upperBinId === undefined ||
|
|
795
|
+
if (position.upperBinId === undefined ||
|
|
796
|
+
position.lowerBinId === undefined) {
|
|
690
797
|
throw new Error(`Position ${params.position} has invalid bin IDs: upper=${position.upperBinId}, lower=${position.lowerBinId}`);
|
|
691
798
|
}
|
|
692
799
|
console.log(`Position validation passed: upperBinId=${position.upperBinId}, lowerBinId=${position.lowerBinId}, lbPair=${position.lbPair.toString()}`);
|
|
@@ -708,7 +815,7 @@ class Transactions {
|
|
|
708
815
|
strategy: {
|
|
709
816
|
maxBinId: position.upperBinId,
|
|
710
817
|
minBinId: position.lowerBinId,
|
|
711
|
-
strategyType: types_3.StrategyTypeMap[
|
|
818
|
+
strategyType: types_3.StrategyTypeMap['SPOT-IMBALANCED'], // TODO: how to get the right distribution from chain??
|
|
712
819
|
},
|
|
713
820
|
skipInputTokenCheck: true,
|
|
714
821
|
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
@@ -723,7 +830,7 @@ class Transactions {
|
|
|
723
830
|
];
|
|
724
831
|
return (0, functions_1.createTransactionMeta)({
|
|
725
832
|
payer: params.userWallet,
|
|
726
|
-
description:
|
|
833
|
+
description: 'Automation IX: Meteora Auto-compound instructions (claim fee, reward, and deposit to position)',
|
|
727
834
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
728
835
|
mainInstructions,
|
|
729
836
|
});
|
|
@@ -733,7 +840,8 @@ class Transactions {
|
|
|
733
840
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
734
841
|
console.error('compoundAutomationIx error:', errorMessage, error);
|
|
735
842
|
// Check for specific Meteora DLMM errors
|
|
736
|
-
if (errorMessage.includes('getSimulationComputeUnits') ||
|
|
843
|
+
if (errorMessage.includes('getSimulationComputeUnits') ||
|
|
844
|
+
errorMessage.includes('getEstimatedComputeUnit')) {
|
|
737
845
|
throw new Error(`Meteora DLMM compute unit estimation failed: ${errorMessage}. This usually indicates invalid position parameters or pool state.`);
|
|
738
846
|
}
|
|
739
847
|
if (errorMessage.includes('addLiquidityByStrategy')) {
|
|
@@ -749,7 +857,7 @@ class Transactions {
|
|
|
749
857
|
console.log('=== CLAIM AUTOMATION IX START ===');
|
|
750
858
|
console.log('Params:', {
|
|
751
859
|
userWallet: params.userWallet.toString(),
|
|
752
|
-
position: params.position.toString()
|
|
860
|
+
position: params.position.toString(),
|
|
753
861
|
});
|
|
754
862
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
755
863
|
console.log('Program fetched successfully');
|
|
@@ -758,7 +866,7 @@ class Transactions {
|
|
|
758
866
|
lbPair: position.lbPair.toString(),
|
|
759
867
|
owner: position.owner.toString(),
|
|
760
868
|
lowerBinId: position.lowerBinId.toString(),
|
|
761
|
-
upperBinId: position.upperBinId.toString()
|
|
869
|
+
upperBinId: position.upperBinId.toString(),
|
|
762
870
|
});
|
|
763
871
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
764
872
|
console.log('DLMM pool created successfully');
|
|
@@ -766,7 +874,7 @@ class Transactions {
|
|
|
766
874
|
console.log('User PDA generated:', userPda.toString());
|
|
767
875
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
768
876
|
console.log('User positions fetched, count:', userPositions.length);
|
|
769
|
-
const userPosition = userPositions.find(
|
|
877
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.position));
|
|
770
878
|
if (userPosition === undefined) {
|
|
771
879
|
throw new Error(`Position: ${params.position} does not exist.`);
|
|
772
880
|
}
|
|
@@ -790,7 +898,7 @@ class Transactions {
|
|
|
790
898
|
console.log('Creating transaction metadata...');
|
|
791
899
|
const result = (0, functions_1.createTransactionMeta)({
|
|
792
900
|
payer: params.userWallet,
|
|
793
|
-
description:
|
|
901
|
+
description: 'Automation IX: Meteora Auto-claim instructions (claim fee, reward)',
|
|
794
902
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
795
903
|
mainInstructions,
|
|
796
904
|
});
|
|
@@ -804,7 +912,7 @@ class Transactions {
|
|
|
804
912
|
console.error('Main instructions:', mainInstructions.map(ix => ({
|
|
805
913
|
programId: ix.programId.toString(),
|
|
806
914
|
keysCount: ix.keys.length,
|
|
807
|
-
dataLength: ix.data.length
|
|
915
|
+
dataLength: ix.data.length,
|
|
808
916
|
})));
|
|
809
917
|
console.error('=== END METADATA ERROR LOG ===');
|
|
810
918
|
throw metadataError;
|
|
@@ -829,11 +937,11 @@ class Transactions {
|
|
|
829
937
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
830
938
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
831
939
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
832
|
-
const userPosition = userPositions.find(
|
|
940
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.currentPosition));
|
|
833
941
|
if (userPosition === undefined) {
|
|
834
942
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
835
943
|
}
|
|
836
|
-
const binIdsToRemove = userPosition.positionData.positionBinData.map(
|
|
944
|
+
const binIdsToRemove = userPosition.positionData.positionBinData.map(bin => bin.binId);
|
|
837
945
|
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
838
946
|
user: userPda,
|
|
839
947
|
position: params.currentPosition,
|
|
@@ -873,7 +981,7 @@ class Transactions {
|
|
|
873
981
|
];
|
|
874
982
|
return (0, functions_1.createTransactionMeta)({
|
|
875
983
|
payer: params.userWallet,
|
|
876
|
-
description:
|
|
984
|
+
description: 'Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)',
|
|
877
985
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
878
986
|
mainInstructions,
|
|
879
987
|
});
|
|
@@ -890,7 +998,7 @@ class Transactions {
|
|
|
890
998
|
relativeBinRange: params.relativeBinRange,
|
|
891
999
|
distribution: params.distribution,
|
|
892
1000
|
checkRange: params.checkRange,
|
|
893
|
-
useAta: params.useAta
|
|
1001
|
+
useAta: params.useAta,
|
|
894
1002
|
}, null, 2));
|
|
895
1003
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
896
1004
|
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
@@ -899,7 +1007,7 @@ class Transactions {
|
|
|
899
1007
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
900
1008
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
901
1009
|
console.log('Found user positions:', userPositions.length);
|
|
902
|
-
const userPosition = userPositions.find(
|
|
1010
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.currentPosition));
|
|
903
1011
|
if (userPosition === undefined) {
|
|
904
1012
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
905
1013
|
}
|
|
@@ -945,7 +1053,7 @@ class Transactions {
|
|
|
945
1053
|
];
|
|
946
1054
|
return (0, functions_1.createTransactionMeta)({
|
|
947
1055
|
payer: params.userWallet,
|
|
948
|
-
description:
|
|
1056
|
+
description: 'Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)',
|
|
949
1057
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
950
1058
|
mainInstructions,
|
|
951
1059
|
});
|
|
@@ -990,7 +1098,7 @@ class Transactions {
|
|
|
990
1098
|
const mainInstructions = [...initPositionAndAddLiquidityBuilder.mainIxs];
|
|
991
1099
|
return (0, functions_1.createTransactionMeta)({
|
|
992
1100
|
payer: params.userWallet,
|
|
993
|
-
description:
|
|
1101
|
+
description: 'Automation IX: Meteora Open instruction (Open position)',
|
|
994
1102
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
995
1103
|
mainInstructions,
|
|
996
1104
|
});
|
|
@@ -1016,7 +1124,7 @@ class Transactions {
|
|
|
1016
1124
|
});
|
|
1017
1125
|
let program;
|
|
1018
1126
|
try {
|
|
1019
|
-
program = yield retryRpcCall(() => meteora_1.MeteoraDLMM.program(connection),
|
|
1127
|
+
program = yield retryRpcCall(() => meteora_1.MeteoraDLMM.program(connection), 'Initialize MeteoraDLMM program');
|
|
1020
1128
|
}
|
|
1021
1129
|
catch (error) {
|
|
1022
1130
|
throw new Error(`Failed to initialize MeteoraDLMM program: ${error}`);
|
|
@@ -1094,7 +1202,7 @@ class Transactions {
|
|
|
1094
1202
|
try {
|
|
1095
1203
|
return (0, functions_1.createTransactionMeta)({
|
|
1096
1204
|
payer: params.userWallet,
|
|
1097
|
-
description:
|
|
1205
|
+
description: 'Automation IX: Meteora Close instruction (Close position)',
|
|
1098
1206
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1099
1207
|
mainInstructions,
|
|
1100
1208
|
});
|
|
@@ -1125,7 +1233,7 @@ class Transactions {
|
|
|
1125
1233
|
shouldClaimAndClose: true,
|
|
1126
1234
|
});
|
|
1127
1235
|
// Filter out non-meteora instructions
|
|
1128
|
-
const ixs = (0, functions_1.getIxs)(txn).filter(
|
|
1236
|
+
const ixs = (0, functions_1.getIxs)(txn).filter(ix => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
1129
1237
|
const farm = addresses_1.USDC_FARM;
|
|
1130
1238
|
const authority = params.userWallet;
|
|
1131
1239
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -1162,7 +1270,7 @@ class Transactions {
|
|
|
1162
1270
|
.iyfMain.methods.iyfExtensionExecuteV2(limitCloseAutomationIx.data)
|
|
1163
1271
|
.accounts({
|
|
1164
1272
|
userPda,
|
|
1165
|
-
authority,
|
|
1273
|
+
authority: addresses_1.HS_AUTHORITY,
|
|
1166
1274
|
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
1167
1275
|
})
|
|
1168
1276
|
.remainingAccounts([...limitCloseAutomationIx.keys.slice(2)])
|
|
@@ -1202,7 +1310,7 @@ class Transactions {
|
|
|
1202
1310
|
];
|
|
1203
1311
|
return (0, functions_1.createTransactionMeta)({
|
|
1204
1312
|
payer: params.userWallet,
|
|
1205
|
-
description:
|
|
1313
|
+
description: 'Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)',
|
|
1206
1314
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1207
1315
|
mainInstructions,
|
|
1208
1316
|
});
|
|
@@ -1237,7 +1345,7 @@ class Transactions {
|
|
|
1237
1345
|
});
|
|
1238
1346
|
}));
|
|
1239
1347
|
// Filter out non-meteora instructions
|
|
1240
|
-
const ixs = (0, functions_1.getIxs)(txn).filter(
|
|
1348
|
+
const ixs = (0, functions_1.getIxs)(txn).filter(ix => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
1241
1349
|
const farm = addresses_1.USDC_FARM;
|
|
1242
1350
|
const authority = params.userWallet;
|
|
1243
1351
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -1277,7 +1385,7 @@ class Transactions {
|
|
|
1277
1385
|
.iyfMain.methods.iyfExtensionExecuteV2(limitCloseAutomationIx.data)
|
|
1278
1386
|
.accounts({
|
|
1279
1387
|
userPda,
|
|
1280
|
-
authority,
|
|
1388
|
+
authority: addresses_1.HS_AUTHORITY,
|
|
1281
1389
|
iyfExtensionProgram: addresses_1.IYF_EXTENSION,
|
|
1282
1390
|
})
|
|
1283
1391
|
.remainingAccounts([...limitCloseAutomationIx.keys.slice(2)])
|
|
@@ -1322,7 +1430,7 @@ class Transactions {
|
|
|
1322
1430
|
];
|
|
1323
1431
|
return (0, functions_1.createTransactionMeta)({
|
|
1324
1432
|
payer: params.userWallet,
|
|
1325
|
-
description:
|
|
1433
|
+
description: 'Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)',
|
|
1326
1434
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1327
1435
|
mainInstructions,
|
|
1328
1436
|
});
|
|
@@ -1332,7 +1440,7 @@ class Transactions {
|
|
|
1332
1440
|
removeLiquidityByRangeInfo(ixs) {
|
|
1333
1441
|
for (const ix of ixs) {
|
|
1334
1442
|
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
1335
|
-
const removeLiquidityByRange = (0, functions_1.sighashMatch)(ix.data,
|
|
1443
|
+
const removeLiquidityByRange = (0, functions_1.sighashMatch)(ix.data, 'RemoveLiquidityByRange');
|
|
1336
1444
|
// Handle original RemoveLiquidityByRange instruction
|
|
1337
1445
|
if (programIdMatch && removeLiquidityByRange) {
|
|
1338
1446
|
return {
|
|
@@ -1363,7 +1471,7 @@ class Transactions {
|
|
|
1363
1471
|
removeLiquidityByRange2Info(ixs) {
|
|
1364
1472
|
for (const ix of ixs) {
|
|
1365
1473
|
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
1366
|
-
const removeLiquidityByRange2 = (0, functions_1.sighashMatch)(ix.data,
|
|
1474
|
+
const removeLiquidityByRange2 = (0, functions_1.sighashMatch)(ix.data, 'remove_liquidity_by_range2', undefined, true);
|
|
1367
1475
|
// Handle RemoveLiquidityByRange2 instruction with different account structure
|
|
1368
1476
|
if (programIdMatch && removeLiquidityByRange2) {
|
|
1369
1477
|
return {
|
|
@@ -1449,7 +1557,7 @@ class Transactions {
|
|
|
1449
1557
|
const mainInstructions = [orcaIx];
|
|
1450
1558
|
return (0, functions_1.createTransactionMeta)({
|
|
1451
1559
|
payer: params.userWallet,
|
|
1452
|
-
description:
|
|
1560
|
+
description: 'Create new Orca Position',
|
|
1453
1561
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1454
1562
|
mainInstructions,
|
|
1455
1563
|
});
|
|
@@ -1509,7 +1617,7 @@ class Transactions {
|
|
|
1509
1617
|
const mainInstructions = [orcaIx];
|
|
1510
1618
|
return (0, functions_1.createTransactionMeta)({
|
|
1511
1619
|
payer: params.userWallet,
|
|
1512
|
-
description:
|
|
1620
|
+
description: 'Close Orca Position',
|
|
1513
1621
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1514
1622
|
mainInstructions,
|
|
1515
1623
|
});
|
|
@@ -1532,7 +1640,8 @@ class Transactions {
|
|
|
1532
1640
|
let positionData;
|
|
1533
1641
|
if (params.mintOrPosition.position !== undefined) {
|
|
1534
1642
|
position = params.mintOrPosition.position;
|
|
1535
|
-
positionData =
|
|
1643
|
+
positionData =
|
|
1644
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1536
1645
|
positionMint = positionData.positionMint;
|
|
1537
1646
|
}
|
|
1538
1647
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1540,7 +1649,7 @@ class Transactions {
|
|
|
1540
1649
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1541
1650
|
}
|
|
1542
1651
|
else {
|
|
1543
|
-
throw new Error(
|
|
1652
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1544
1653
|
}
|
|
1545
1654
|
const positionTokenAccount = this.orcaPda.generatePositionTokenAccount(userPda, positionMint, params.is2022Position || false);
|
|
1546
1655
|
if (params.newPosition) {
|
|
@@ -1552,7 +1661,8 @@ class Transactions {
|
|
|
1552
1661
|
};
|
|
1553
1662
|
}
|
|
1554
1663
|
else {
|
|
1555
|
-
positionData =
|
|
1664
|
+
positionData =
|
|
1665
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1556
1666
|
}
|
|
1557
1667
|
if (positionData === null) {
|
|
1558
1668
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1570,7 +1680,7 @@ class Transactions {
|
|
|
1570
1680
|
const tokenKey = result.tokenKey;
|
|
1571
1681
|
const token = tokenSeeds[index];
|
|
1572
1682
|
if (!result.exists &&
|
|
1573
|
-
`${token.mint}` !==
|
|
1683
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1574
1684
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1575
1685
|
}
|
|
1576
1686
|
});
|
|
@@ -1689,7 +1799,8 @@ class Transactions {
|
|
|
1689
1799
|
let positionData;
|
|
1690
1800
|
if (params.mintOrPosition.position !== undefined) {
|
|
1691
1801
|
position = params.mintOrPosition.position;
|
|
1692
|
-
positionData =
|
|
1802
|
+
positionData =
|
|
1803
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1693
1804
|
positionMint = positionData.positionMint;
|
|
1694
1805
|
}
|
|
1695
1806
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1697,7 +1808,7 @@ class Transactions {
|
|
|
1697
1808
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1698
1809
|
}
|
|
1699
1810
|
else {
|
|
1700
|
-
throw new Error(
|
|
1811
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1701
1812
|
}
|
|
1702
1813
|
const positionTokenAccount = (0, functions_1.generateAta)(userPda, positionMint);
|
|
1703
1814
|
if (params.newPosition) {
|
|
@@ -1709,7 +1820,8 @@ class Transactions {
|
|
|
1709
1820
|
};
|
|
1710
1821
|
}
|
|
1711
1822
|
else {
|
|
1712
|
-
positionData =
|
|
1823
|
+
positionData =
|
|
1824
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1713
1825
|
}
|
|
1714
1826
|
if (positionData === null) {
|
|
1715
1827
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1727,7 +1839,7 @@ class Transactions {
|
|
|
1727
1839
|
const tokenKey = result.tokenKey;
|
|
1728
1840
|
const token = tokenSeeds[index];
|
|
1729
1841
|
if (!result.exists &&
|
|
1730
|
-
`${token.mint}` !==
|
|
1842
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1731
1843
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1732
1844
|
}
|
|
1733
1845
|
});
|
|
@@ -1841,7 +1953,8 @@ class Transactions {
|
|
|
1841
1953
|
let positionData;
|
|
1842
1954
|
if (params.mintOrPosition.position !== undefined) {
|
|
1843
1955
|
position = params.mintOrPosition.position;
|
|
1844
|
-
positionData =
|
|
1956
|
+
positionData =
|
|
1957
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1845
1958
|
positionMint = positionData.positionMint;
|
|
1846
1959
|
}
|
|
1847
1960
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1849,7 +1962,7 @@ class Transactions {
|
|
|
1849
1962
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1850
1963
|
}
|
|
1851
1964
|
else {
|
|
1852
|
-
throw new Error(
|
|
1965
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1853
1966
|
}
|
|
1854
1967
|
const positionTokenAccount = this.orcaPda.generatePositionTokenAccount(userPda, positionMint, params.is2022Position || false);
|
|
1855
1968
|
if (params.newPosition) {
|
|
@@ -1861,7 +1974,8 @@ class Transactions {
|
|
|
1861
1974
|
};
|
|
1862
1975
|
}
|
|
1863
1976
|
else {
|
|
1864
|
-
positionData =
|
|
1977
|
+
positionData =
|
|
1978
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1865
1979
|
}
|
|
1866
1980
|
if (positionData === null) {
|
|
1867
1981
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1879,7 +1993,7 @@ class Transactions {
|
|
|
1879
1993
|
const tokenKey = result.tokenKey;
|
|
1880
1994
|
const token = tokenSeeds[index];
|
|
1881
1995
|
if (!result.exists &&
|
|
1882
|
-
`${token.mint}` !==
|
|
1996
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1883
1997
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1884
1998
|
}
|
|
1885
1999
|
});
|
|
@@ -1889,7 +2003,7 @@ class Transactions {
|
|
|
1889
2003
|
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
1890
2004
|
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
1891
2005
|
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
1892
|
-
const [oracle] = web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode(
|
|
2006
|
+
const [oracle] = web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('oracle'), whirlpool.toBuffer()], addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
1893
2007
|
// TODO: Derive based on amountToSwap calculation
|
|
1894
2008
|
let aToB = params.aToB;
|
|
1895
2009
|
const tickArrays = whirlpools_sdk_1.SwapUtils.getTickArrayPublicKeys(whirlpoolData.tickCurrentIndex, whirlpoolData.tickSpacing, aToB, addresses_1.ORCA_WHIRLPOOL_PROGRAM, whirlpool);
|
|
@@ -2354,11 +2468,11 @@ class Transactions {
|
|
|
2354
2468
|
});
|
|
2355
2469
|
}
|
|
2356
2470
|
}
|
|
2357
|
-
const result = yield (0, functions_1.tokenAccountExists)(connection, rewardMints.map(
|
|
2471
|
+
const result = yield (0, functions_1.tokenAccountExists)(connection, rewardMints.map(mint => {
|
|
2358
2472
|
return { owner: userPda, mint, isSta: false };
|
|
2359
2473
|
}));
|
|
2360
2474
|
const initRewardATA = result
|
|
2361
|
-
.map(
|
|
2475
|
+
.map(result => {
|
|
2362
2476
|
if (!result.exists) {
|
|
2363
2477
|
return (0, spl_token_1.createAssociatedTokenAccountInstruction)(params.userWallet, result.tokenKey, userPda, result.mint, addresses_1.TOKEN_PROGRAM_ID, addresses_1.ASSOCIATED_TOKEN_PROGRAM);
|
|
2364
2478
|
}
|
|
@@ -2366,7 +2480,7 @@ class Transactions {
|
|
|
2366
2480
|
return null;
|
|
2367
2481
|
}
|
|
2368
2482
|
})
|
|
2369
|
-
.filter(
|
|
2483
|
+
.filter(result => result !== null);
|
|
2370
2484
|
whirlpoolData.rewardInfos[0].mint;
|
|
2371
2485
|
// @ts-ignore
|
|
2372
2486
|
const extensionIx = yield anchor_1.Anchor.instance()
|
|
@@ -2446,8 +2560,12 @@ class Transactions {
|
|
|
2446
2560
|
// Get the pool keys (for lookup table account)
|
|
2447
2561
|
(0, functions_1.benchmark)({ name: `raydiumOpenPosition`, msg: `sdk.clmm.getClmmPoolKeys` });
|
|
2448
2562
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(params.poolState.toString());
|
|
2449
|
-
(0, functions_1.benchmark)({
|
|
2450
|
-
|
|
2563
|
+
(0, functions_1.benchmark)({
|
|
2564
|
+
name: `raydiumOpenPosition`,
|
|
2565
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2566
|
+
end: true,
|
|
2567
|
+
});
|
|
2568
|
+
console.log('pool lookup table account:', poolKeys.lookupTableAccount);
|
|
2451
2569
|
const addressLookupTableAddresses = [];
|
|
2452
2570
|
if (poolKeys.lookupTableAccount) {
|
|
2453
2571
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2462,7 +2580,7 @@ class Transactions {
|
|
|
2462
2580
|
2846640 + // 281 - personal position
|
|
2463
2581
|
2296800 + // 202 - position nft mint
|
|
2464
2582
|
2074080; // 170 - position nft account
|
|
2465
|
-
console.log(
|
|
2583
|
+
console.log('SOL to send to pda lamport: ', lamports / 1000000000);
|
|
2466
2584
|
// Lamports needed for opening a position
|
|
2467
2585
|
const lamportIx = web3.SystemProgram.transfer({
|
|
2468
2586
|
fromPubkey: params.userWallet,
|
|
@@ -2476,7 +2594,7 @@ class Transactions {
|
|
|
2476
2594
|
const amountY = params.amountY
|
|
2477
2595
|
.mul(new bn_js_1.default(10000).sub(slippage))
|
|
2478
2596
|
.div(new bn_js_1.default(10000));
|
|
2479
|
-
const { liquidity, amount0Max, amount1Max
|
|
2597
|
+
const { liquidity, amount0Max, amount1Max } = yield (0, RaydiumIxGenerator_1.getLiquidityFromAmounts)(connection, params.poolState, amountX, amountY, params.tickLowerIndex, params.tickUpperIndex, params.slippage, true);
|
|
2480
2598
|
const wrapIxs = (0, functions_1.wrapSolIfMintIsWsol)(params.userWallet, params.userWallet, [
|
|
2481
2599
|
{ mint: tokenMint0, amount: amount0Max },
|
|
2482
2600
|
{ mint: tokenMint1, amount: amount1Max },
|
|
@@ -2509,7 +2627,7 @@ class Transactions {
|
|
|
2509
2627
|
});
|
|
2510
2628
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2511
2629
|
tokenMint0,
|
|
2512
|
-
tokenMint1
|
|
2630
|
+
tokenMint1,
|
|
2513
2631
|
]);
|
|
2514
2632
|
const mainInstructions = [
|
|
2515
2633
|
lamportIx,
|
|
@@ -2523,7 +2641,10 @@ class Transactions {
|
|
|
2523
2641
|
return yield (0, functions_1.createTransactionMeta)({
|
|
2524
2642
|
payer: params.userWallet,
|
|
2525
2643
|
description: `Open Raydium Position`,
|
|
2526
|
-
addressLookupTableAddresses: [
|
|
2644
|
+
addressLookupTableAddresses: [
|
|
2645
|
+
...addresses_1.GLOBAL_ALT,
|
|
2646
|
+
...addressLookupTableAddresses,
|
|
2647
|
+
],
|
|
2527
2648
|
mainInstructions,
|
|
2528
2649
|
});
|
|
2529
2650
|
});
|
|
@@ -2546,10 +2667,17 @@ class Transactions {
|
|
|
2546
2667
|
// Get the Raydium SDK instance
|
|
2547
2668
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2548
2669
|
// Get the pool keys (for lookup table account)
|
|
2549
|
-
(0, functions_1.benchmark)({
|
|
2670
|
+
(0, functions_1.benchmark)({
|
|
2671
|
+
name: `raydiumWithdrawAndClosePosition`,
|
|
2672
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2673
|
+
});
|
|
2550
2674
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2551
|
-
(0, functions_1.benchmark)({
|
|
2552
|
-
|
|
2675
|
+
(0, functions_1.benchmark)({
|
|
2676
|
+
name: `raydiumWithdrawAndClosePosition`,
|
|
2677
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2678
|
+
end: true,
|
|
2679
|
+
});
|
|
2680
|
+
console.log('pool lookup table account:', poolKeys.lookupTableAccount);
|
|
2553
2681
|
const addressLookupTableAddresses = [];
|
|
2554
2682
|
if (poolKeys.lookupTableAccount) {
|
|
2555
2683
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2560,18 +2688,22 @@ class Transactions {
|
|
|
2560
2688
|
{ mint: fetch.poolStateInfo.tokenMint0 },
|
|
2561
2689
|
{ mint: fetch.poolStateInfo.tokenMint1 },
|
|
2562
2690
|
...fetch.poolStateInfo.rewardInfos
|
|
2563
|
-
.filter(
|
|
2564
|
-
.map(
|
|
2691
|
+
.filter(v => !v.tokenMint.equals(web3.SystemProgram.programId))
|
|
2692
|
+
.map(v => {
|
|
2565
2693
|
return { mint: v.tokenMint };
|
|
2566
2694
|
}),
|
|
2567
2695
|
],
|
|
2568
2696
|
});
|
|
2569
|
-
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2570
|
-
|
|
2697
|
+
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2698
|
+
.map(v => v.tokenMint.toString())
|
|
2699
|
+
.filter(v => v !== web3.SystemProgram.programId.toString());
|
|
2700
|
+
const mints = [
|
|
2701
|
+
...new Set([
|
|
2571
2702
|
...rewards,
|
|
2572
2703
|
fetch.poolStateInfo.tokenMint0.toString(),
|
|
2573
2704
|
fetch.poolStateInfo.tokenMint1.toString(),
|
|
2574
|
-
])
|
|
2705
|
+
]),
|
|
2706
|
+
].map(v => new web3.PublicKey(v));
|
|
2575
2707
|
const nftOwner = (0, functions_1.generateUserPdaLamport)(params.userWallet);
|
|
2576
2708
|
const initAtaIxs = mints.map(v => {
|
|
2577
2709
|
const payer = params.userWallet;
|
|
@@ -2581,7 +2713,7 @@ class Transactions {
|
|
|
2581
2713
|
});
|
|
2582
2714
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2583
2715
|
fetch.poolStateInfo.tokenMint0,
|
|
2584
|
-
fetch.poolStateInfo.tokenMint1
|
|
2716
|
+
fetch.poolStateInfo.tokenMint1,
|
|
2585
2717
|
]);
|
|
2586
2718
|
const raydiumDecreaseLiquidityIxViaHawksight = yield this.ix.raydium.raydiumDecreaseLiquidity({
|
|
2587
2719
|
connection,
|
|
@@ -2606,7 +2738,10 @@ class Transactions {
|
|
|
2606
2738
|
return (0, functions_1.createTransactionMeta)({
|
|
2607
2739
|
payer: params.userWallet,
|
|
2608
2740
|
description: `Close Raydium Position`,
|
|
2609
|
-
addressLookupTableAddresses: [
|
|
2741
|
+
addressLookupTableAddresses: [
|
|
2742
|
+
...addresses_1.GLOBAL_ALT,
|
|
2743
|
+
...addressLookupTableAddresses,
|
|
2744
|
+
],
|
|
2610
2745
|
mainInstructions,
|
|
2611
2746
|
});
|
|
2612
2747
|
}
|
|
@@ -2622,7 +2757,10 @@ class Transactions {
|
|
|
2622
2757
|
return (0, functions_1.createTransactionMeta)({
|
|
2623
2758
|
payer: params.userWallet,
|
|
2624
2759
|
description: `Withdraw and close Raydium Position`,
|
|
2625
|
-
addressLookupTableAddresses: [
|
|
2760
|
+
addressLookupTableAddresses: [
|
|
2761
|
+
...addresses_1.GLOBAL_ALT,
|
|
2762
|
+
...addressLookupTableAddresses,
|
|
2763
|
+
],
|
|
2626
2764
|
mainInstructions,
|
|
2627
2765
|
});
|
|
2628
2766
|
}
|
|
@@ -2676,10 +2814,17 @@ class Transactions {
|
|
|
2676
2814
|
// Get the Raydium SDK instance
|
|
2677
2815
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2678
2816
|
// Get the pool keys (for lookup table account)
|
|
2679
|
-
(0, functions_1.benchmark)({
|
|
2817
|
+
(0, functions_1.benchmark)({
|
|
2818
|
+
name: `raydiumIncreaseLiquidity`,
|
|
2819
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2820
|
+
});
|
|
2680
2821
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2681
|
-
(0, functions_1.benchmark)({
|
|
2682
|
-
|
|
2822
|
+
(0, functions_1.benchmark)({
|
|
2823
|
+
name: `raydiumIncreaseLiquidity`,
|
|
2824
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2825
|
+
end: true,
|
|
2826
|
+
});
|
|
2827
|
+
console.log('pool lookup table account:', poolKeys.lookupTableAccount);
|
|
2683
2828
|
const addressLookupTableAddresses = [];
|
|
2684
2829
|
if (poolKeys.lookupTableAccount) {
|
|
2685
2830
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2691,14 +2836,14 @@ class Transactions {
|
|
|
2691
2836
|
const amountY = params.amountY
|
|
2692
2837
|
.mul(new bn_js_1.default(10000).sub(slippage))
|
|
2693
2838
|
.div(new bn_js_1.default(10000));
|
|
2694
|
-
const { liquidity, amount0Max, amount1Max
|
|
2839
|
+
const { liquidity, amount0Max, amount1Max } = yield (0, RaydiumIxGenerator_1.getLiquidityFromAmounts)(connection, fetch.positionInfo.poolId, amountX, amountY, fetch.positionInfo.tickLowerIndex, fetch.positionInfo.tickUpperIndex, params.slippage, true);
|
|
2695
2840
|
const wrapIxs = (0, functions_1.wrapSolIfMintIsWsol)(params.userWallet, params.userWallet, [
|
|
2696
2841
|
{ mint: tokenMint0, amount: amount0Max },
|
|
2697
2842
|
{ mint: tokenMint1, amount: amount1Max },
|
|
2698
2843
|
]);
|
|
2699
2844
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2700
2845
|
tokenMint0,
|
|
2701
|
-
tokenMint1
|
|
2846
|
+
tokenMint1,
|
|
2702
2847
|
]);
|
|
2703
2848
|
const depositIx = yield this.ix.iyfMain.depositMultipleLamportPdaToken({
|
|
2704
2849
|
userWallet: params.userWallet,
|
|
@@ -2732,7 +2877,10 @@ class Transactions {
|
|
|
2732
2877
|
return (0, functions_1.createTransactionMeta)({
|
|
2733
2878
|
payer: params.userWallet,
|
|
2734
2879
|
description: `Raydium increase liquidity`,
|
|
2735
|
-
addressLookupTableAddresses: [
|
|
2880
|
+
addressLookupTableAddresses: [
|
|
2881
|
+
...addresses_1.GLOBAL_ALT,
|
|
2882
|
+
...addressLookupTableAddresses,
|
|
2883
|
+
],
|
|
2736
2884
|
mainInstructions,
|
|
2737
2885
|
});
|
|
2738
2886
|
});
|
|
@@ -2754,10 +2902,17 @@ class Transactions {
|
|
|
2754
2902
|
// Get the Raydium SDK instance
|
|
2755
2903
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2756
2904
|
// Get the pool keys (for lookup table account)
|
|
2757
|
-
(0, functions_1.benchmark)({
|
|
2905
|
+
(0, functions_1.benchmark)({
|
|
2906
|
+
name: `raydiumDecreaseLiquidity`,
|
|
2907
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2908
|
+
});
|
|
2758
2909
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2759
|
-
(0, functions_1.benchmark)({
|
|
2760
|
-
|
|
2910
|
+
(0, functions_1.benchmark)({
|
|
2911
|
+
name: `raydiumDecreaseLiquidity`,
|
|
2912
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2913
|
+
end: true,
|
|
2914
|
+
});
|
|
2915
|
+
console.log('pool lookup table account:', poolKeys.lookupTableAccount);
|
|
2761
2916
|
const addressLookupTableAddresses = [];
|
|
2762
2917
|
if (poolKeys.lookupTableAccount) {
|
|
2763
2918
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2768,18 +2923,22 @@ class Transactions {
|
|
|
2768
2923
|
{ mint: fetch.poolStateInfo.tokenMint0 },
|
|
2769
2924
|
{ mint: fetch.poolStateInfo.tokenMint1 },
|
|
2770
2925
|
...fetch.poolStateInfo.rewardInfos
|
|
2771
|
-
.filter(
|
|
2772
|
-
.map(
|
|
2926
|
+
.filter(v => !v.tokenMint.equals(web3.SystemProgram.programId))
|
|
2927
|
+
.map(v => {
|
|
2773
2928
|
return { mint: v.tokenMint };
|
|
2774
2929
|
}),
|
|
2775
2930
|
],
|
|
2776
2931
|
});
|
|
2777
|
-
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2778
|
-
|
|
2932
|
+
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2933
|
+
.map(v => v.tokenMint.toString())
|
|
2934
|
+
.filter(v => v !== web3.SystemProgram.programId.toString());
|
|
2935
|
+
const mints = [
|
|
2936
|
+
...new Set([
|
|
2779
2937
|
...rewards,
|
|
2780
2938
|
fetch.poolStateInfo.tokenMint0.toString(),
|
|
2781
2939
|
fetch.poolStateInfo.tokenMint1.toString(),
|
|
2782
|
-
])
|
|
2940
|
+
]),
|
|
2941
|
+
].map(v => new web3.PublicKey(v));
|
|
2783
2942
|
const nftOwner = (0, functions_1.generateUserPdaLamport)(params.userWallet);
|
|
2784
2943
|
const initAtaIxs = mints.map(v => {
|
|
2785
2944
|
const payer = params.userWallet;
|
|
@@ -2789,7 +2948,7 @@ class Transactions {
|
|
|
2789
2948
|
});
|
|
2790
2949
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2791
2950
|
fetch.poolStateInfo.tokenMint0,
|
|
2792
|
-
fetch.poolStateInfo.tokenMint1
|
|
2951
|
+
fetch.poolStateInfo.tokenMint1,
|
|
2793
2952
|
]);
|
|
2794
2953
|
const raydiumDecreaseLiquidityIxViaHawksight = yield this.ix.raydium.raydiumDecreaseLiquidity({
|
|
2795
2954
|
connection,
|
|
@@ -2805,7 +2964,10 @@ class Transactions {
|
|
|
2805
2964
|
return (0, functions_1.createTransactionMeta)({
|
|
2806
2965
|
payer: params.userWallet,
|
|
2807
2966
|
description: `Raydium decrease liquidity`,
|
|
2808
|
-
addressLookupTableAddresses: [
|
|
2967
|
+
addressLookupTableAddresses: [
|
|
2968
|
+
...addresses_1.GLOBAL_ALT,
|
|
2969
|
+
...addressLookupTableAddresses,
|
|
2970
|
+
],
|
|
2809
2971
|
mainInstructions,
|
|
2810
2972
|
});
|
|
2811
2973
|
});
|