@hawksightco/hawk-sdk 1.3.145 → 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.
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as web3 from
|
|
2
|
-
import { MeteoraClaim, MeteoraClaimAll, MeteoraClose, MeteoraCompound, MeteoraCreatePositionAndDeposit, MeteoraCreatePositionAndDepositPda, MeteoraDeposit, MeteoraInitializeBinArrays, MeteoraRebalance, MeteoraWithdraw, Register, TxgenParams, InitializeStorageTokenAccount, MeteoraLimitCloseAutomation, MeteoraLimitCloseAutomation2, OrcaOpenPosition, OrcaClosePosition, OrcaDeposit, OrcaWithdraw, OrcaSweepDust, OrcaClaimRewards, TransactionMetadataResponse, MeteoraRebalance2, ClaimTokenFromSTA, ClaimTokensFromSTA, RaydiumClosePosition, OpenAutomationIx, RaydiumWithdrawAndClosePosition, MeteoraCreatePoolAndPosition } from
|
|
3
|
-
import { RaydiumIncreaseLiquidity, RaydiumOpenPosition, RaydiumDecreaseLiquidity } from
|
|
4
|
-
import { GeneralUtility } from
|
|
5
|
-
import { MultiTransaction } from
|
|
6
|
-
import { SimpleIxGenerator } from
|
|
1
|
+
import * as web3 from '@solana/web3.js';
|
|
2
|
+
import { MeteoraClaim, MeteoraClaimAll, MeteoraClose, MeteoraCompound, MeteoraCreatePositionAndDeposit, MeteoraCreatePositionAndDepositPda, MeteoraDeposit, MeteoraInitializeBinArrays, MeteoraRebalance, MeteoraWithdraw, Register, TxgenParams, InitializeStorageTokenAccount, MeteoraLimitCloseAutomation, MeteoraLimitCloseAutomation2, OrcaOpenPosition, OrcaClosePosition, OrcaDeposit, OrcaWithdraw, OrcaSweepDust, OrcaClaimRewards, TransactionMetadataResponse, MeteoraRebalance2, ClaimTokenFromSTA, ClaimTokensFromSTA, RaydiumClosePosition, OpenAutomationIx, RaydiumWithdrawAndClosePosition, MeteoraCreatePoolAndPosition } from '../types';
|
|
3
|
+
import { RaydiumIncreaseLiquidity, RaydiumOpenPosition, RaydiumDecreaseLiquidity } from '../types';
|
|
4
|
+
import { GeneralUtility } from './GeneralUtility';
|
|
5
|
+
import { MultiTransaction } from './MultiTransaction';
|
|
6
|
+
import { SimpleIxGenerator } from './SimpleIxGenerator';
|
|
7
7
|
export declare class Transactions {
|
|
8
8
|
/**
|
|
9
9
|
* Prohibit creating instance other than getInstance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes/Transactions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAqBxC,OAAO,EACL,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,+BAA+B,EAC/B,kCAAkC,EAClC,cAAc,EACd,0BAA0B,EAC1B,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,WAAW,EACX,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,2BAA2B,EAC3B,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EAEpB,gBAAgB,EAChB,+BAA+B,EAC/B,4BAA4B,EAC7B,MAAM,UAAU,CAAC;AA+BlB,OAAO,EAEL,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,UAAU,CAAC;AAKlB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../../src/classes/Transactions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAqBxC,OAAO,EACL,YAAY,EACZ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oI1E;;;;;;;OAOG;IACG,+BAA+B,CAAC,EACpC,UAAU,EACV,MAAM,GACP,EAAE,WAAW,CAAC,+BAA+B,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAoItF;;;;;;OAMG;IACG,oBAAoB,CAAC,EACzB,UAAU,EACV,MAAM,GACP,EAAE,WAAW,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAwB3E;;;;;;OAMG;IACG,wBAAwB,CAAC,EAC7B,UAAU,EACV,MAAM,GACP,EAAE,WAAW,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC;IA2G/E;;;;;;OAMG;IACG,wBAAwB,CAAC,EAC7B,UAAU,EACV,MAAM,GACP,EAAE,WAAW,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC;CAmGhF;AAED,eAAO,MAAM,KAAK,cAA6B,CAAC"}
|
|
@@ -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,10 @@ 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
286
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
287
287
|
mainInstructions,
|
|
288
288
|
});
|
|
@@ -305,11 +305,11 @@ class Transactions {
|
|
|
305
305
|
lbPair: params.pool,
|
|
306
306
|
lowerBinId: params.minBinId,
|
|
307
307
|
upperBinId: params.maxBinId,
|
|
308
|
-
})
|
|
308
|
+
}),
|
|
309
309
|
];
|
|
310
310
|
return (0, functions_1.createTransactionMeta)({
|
|
311
311
|
payer: params.userWallet,
|
|
312
|
-
description:
|
|
312
|
+
description: 'Initialize bin arrays for Meteora DLMM pool',
|
|
313
313
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
314
314
|
mainInstructions,
|
|
315
315
|
});
|
|
@@ -323,12 +323,15 @@ class Transactions {
|
|
|
323
323
|
]);
|
|
324
324
|
const tokenProgramX = tokenProgramMap[params.tokenMintX.toString()];
|
|
325
325
|
const tokenProgramY = tokenProgramMap[params.tokenMintY.toString()];
|
|
326
|
-
const validOwners = [
|
|
326
|
+
const validOwners = [
|
|
327
|
+
addresses_1.TOKEN_PROGRAM_ID.toString(),
|
|
328
|
+
addresses_1.TOKEN_2022_PROGRAM_ID.toString(),
|
|
329
|
+
];
|
|
327
330
|
if (!validOwners.includes(tokenProgramX.toString())) {
|
|
328
|
-
throw new errors_1.AppError(`tokenMintX: ${params.tokenMintX.toString()} is not a valid token mint. Program owner: ${tokenProgramX.toString()}`,
|
|
331
|
+
throw new errors_1.AppError(`tokenMintX: ${params.tokenMintX.toString()} is not a valid token mint. Program owner: ${tokenProgramX.toString()}`, 'meteoraCreatePoolAndPosition');
|
|
329
332
|
}
|
|
330
333
|
if (!validOwners.includes(tokenProgramY.toString())) {
|
|
331
|
-
throw new errors_1.AppError(`tokenMintY: ${params.tokenMintY.toString()} is not a valid token mint. Program owner: ${tokenProgramY.toString()}`,
|
|
334
|
+
throw new errors_1.AppError(`tokenMintY: ${params.tokenMintY.toString()} is not a valid token mint. Program owner: ${tokenProgramY.toString()}`, 'meteoraCreatePoolAndPosition');
|
|
332
335
|
}
|
|
333
336
|
const mainInstructions = yield Promise.all([
|
|
334
337
|
...(0, functions_1.wrapSolIfMintIsWsol)(params.userWallet, params.userWallet, [
|
|
@@ -366,11 +369,11 @@ class Transactions {
|
|
|
366
369
|
binStep: params.binStep,
|
|
367
370
|
baseFactor: params.baseFactor,
|
|
368
371
|
baseFeePowerFactor: params.baseFeePowerFactor,
|
|
369
|
-
})
|
|
372
|
+
}),
|
|
370
373
|
]);
|
|
371
374
|
return (0, functions_1.createTransactionMeta)({
|
|
372
375
|
payer: params.userWallet,
|
|
373
|
-
description:
|
|
376
|
+
description: 'Create pool and position in Meteora DLMM',
|
|
374
377
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
375
378
|
mainInstructions,
|
|
376
379
|
});
|
|
@@ -417,7 +420,7 @@ class Transactions {
|
|
|
417
420
|
}, hsToMeteora_1.meteoraToHawksight)).default();
|
|
418
421
|
return (0, functions_1.createTransactionMeta)({
|
|
419
422
|
payer: params.userWallet,
|
|
420
|
-
description:
|
|
423
|
+
description: 'Deposit to existing position in Meteora DLMM',
|
|
421
424
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
422
425
|
mainInstructions,
|
|
423
426
|
});
|
|
@@ -446,9 +449,9 @@ class Transactions {
|
|
|
446
449
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
|
|
447
450
|
if (params.fastGeneration === undefined) {
|
|
448
451
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
449
|
-
const userPosition = userPositions.find(
|
|
452
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.toString() === params.position.toString());
|
|
450
453
|
if (userPosition === undefined) {
|
|
451
|
-
throw new Error(
|
|
454
|
+
throw new Error('Position does not exist.'); // this error should not happen...
|
|
452
455
|
}
|
|
453
456
|
lowerBinId = userPosition.positionData.lowerBinId;
|
|
454
457
|
upperBinId = userPosition.positionData.upperBinId;
|
|
@@ -472,14 +475,14 @@ class Transactions {
|
|
|
472
475
|
let description;
|
|
473
476
|
if (params.shouldClaimAndClose) {
|
|
474
477
|
description =
|
|
475
|
-
|
|
478
|
+
'Full position withdrawal with claim and close instructisons from Meteora DLMM';
|
|
476
479
|
}
|
|
477
480
|
else if (amountBps.eq(new bn_js_1.default(10000))) {
|
|
478
481
|
description =
|
|
479
|
-
|
|
482
|
+
'Full position withdrawal without claim and close instructions from Meteora DLMM';
|
|
480
483
|
}
|
|
481
484
|
else {
|
|
482
|
-
description =
|
|
485
|
+
description = 'Partial position withdrawal from Meteora DLMM';
|
|
483
486
|
}
|
|
484
487
|
return (0, functions_1.createTransactionMeta)({
|
|
485
488
|
payer: params.userWallet,
|
|
@@ -512,9 +515,9 @@ class Transactions {
|
|
|
512
515
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
|
|
513
516
|
if (params.fastGeneration === undefined) {
|
|
514
517
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
515
|
-
const userPosition = userPositions.find(
|
|
518
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.toString() === params.position.toString());
|
|
516
519
|
if (userPosition === undefined) {
|
|
517
|
-
throw new Error(
|
|
520
|
+
throw new Error('Position does not exist.'); // this error should not happen...
|
|
518
521
|
}
|
|
519
522
|
lowerBinId = userPosition.positionData.lowerBinId;
|
|
520
523
|
upperBinId = userPosition.positionData.upperBinId;
|
|
@@ -544,14 +547,14 @@ class Transactions {
|
|
|
544
547
|
let description;
|
|
545
548
|
if (params.shouldClaimAndClose) {
|
|
546
549
|
description =
|
|
547
|
-
|
|
550
|
+
'Full position withdrawal with claim and close instructisons from Meteora DLMM';
|
|
548
551
|
}
|
|
549
552
|
else if (amountBps.eq(new bn_js_1.default(10000))) {
|
|
550
553
|
description =
|
|
551
|
-
|
|
554
|
+
'Full position withdrawal without claim and close instructions from Meteora DLMM';
|
|
552
555
|
}
|
|
553
556
|
else {
|
|
554
|
-
description =
|
|
557
|
+
description = 'Partial position withdrawal from Meteora DLMM';
|
|
555
558
|
}
|
|
556
559
|
return (0, functions_1.createTransactionMeta)({
|
|
557
560
|
payer: params.userWallet,
|
|
@@ -585,7 +588,7 @@ class Transactions {
|
|
|
585
588
|
const mainInstructions = (yield fn.claimFeeAndRewardIxs2(connection, [params.position], params.userWallet, userPda, hsToMeteora_1.meteoraToHawksight, lbPair)).default();
|
|
586
589
|
const txMeta = (0, functions_1.createTransactionMeta)({
|
|
587
590
|
payer: params.userWallet,
|
|
588
|
-
description:
|
|
591
|
+
description: 'Claim fees / rewards from Meteora DLMM Position',
|
|
589
592
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
590
593
|
mainInstructions,
|
|
591
594
|
});
|
|
@@ -612,13 +615,13 @@ class Transactions {
|
|
|
612
615
|
// Step 2.5: Generate transactions
|
|
613
616
|
const mainInstructions = builder.default();
|
|
614
617
|
const latestBlockhash = yield connection.getLatestBlockhash();
|
|
615
|
-
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);
|
|
616
619
|
// Insert nonce advance tx at end of transaction
|
|
617
620
|
batchGenerator.insertNonceAt({
|
|
618
621
|
onlyEndOfTx: true,
|
|
619
622
|
});
|
|
620
623
|
// Generate batch of transactions
|
|
621
|
-
const txs = yield batchGenerator.buildBatchWithAlts(
|
|
624
|
+
const txs = yield batchGenerator.buildBatchWithAlts('Claim all fees / rewards from Meteora DLMM position', generalUtility);
|
|
622
625
|
// Simplified return value
|
|
623
626
|
return txs;
|
|
624
627
|
});
|
|
@@ -638,7 +641,7 @@ class Transactions {
|
|
|
638
641
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
639
642
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
640
643
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
641
|
-
const index = userPositions.findIndex(
|
|
644
|
+
const index = userPositions.findIndex(v => v.publicKey.equals(params.position));
|
|
642
645
|
yield dlmmPool.getActiveBin();
|
|
643
646
|
const mainInstructions = yield dlmmPool.closePosition(params.userWallet, {
|
|
644
647
|
owner: userPda,
|
|
@@ -646,7 +649,7 @@ class Transactions {
|
|
|
646
649
|
}, hsToMeteora_1.meteoraToHawksight);
|
|
647
650
|
return (0, functions_1.createTransactionMeta)({
|
|
648
651
|
payer: params.userWallet,
|
|
649
|
-
description:
|
|
652
|
+
description: 'Close Meteora DLMM Position',
|
|
650
653
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
651
654
|
mainInstructions,
|
|
652
655
|
});
|
|
@@ -664,11 +667,26 @@ class Transactions {
|
|
|
664
667
|
const farm = addresses_1.USDC_FARM;
|
|
665
668
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet, farm);
|
|
666
669
|
const mainInstructions = [];
|
|
667
|
-
const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
|
|
670
|
+
const tokenProgramMap = yield (0, functions_1.getTokenProgramMapForMints)(connection, [
|
|
671
|
+
params.mint,
|
|
672
|
+
]);
|
|
668
673
|
const result = yield (0, functions_1.tokenAccountExists)(connection, [
|
|
669
|
-
{
|
|
670
|
-
|
|
671
|
-
|
|
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
|
+
},
|
|
672
690
|
]);
|
|
673
691
|
// if (!result[0].exists) {
|
|
674
692
|
// mainInstructions.push(
|
|
@@ -690,15 +708,15 @@ class Transactions {
|
|
|
690
708
|
// })
|
|
691
709
|
// );
|
|
692
710
|
// }
|
|
693
|
-
if (result[2].exists) {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
}
|
|
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
|
+
// }
|
|
702
720
|
mainInstructions.push(yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
703
721
|
connection,
|
|
704
722
|
payer: params.userWallet,
|
|
@@ -709,7 +727,7 @@ class Transactions {
|
|
|
709
727
|
mainInstructions.push(...(0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [params.mint]));
|
|
710
728
|
return (0, functions_1.createTransactionMeta)({
|
|
711
729
|
payer: params.userWallet,
|
|
712
|
-
description:
|
|
730
|
+
description: 'Withdraw token from PDA',
|
|
713
731
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
714
732
|
mainInstructions: mainInstructions,
|
|
715
733
|
});
|
|
@@ -727,11 +745,11 @@ class Transactions {
|
|
|
727
745
|
const farm = addresses_1.USDC_FARM;
|
|
728
746
|
const mainInstructions = [];
|
|
729
747
|
const result = yield (0, functions_1.tokenAccountExists)(connection, [
|
|
730
|
-
...params.mints.map(
|
|
748
|
+
...params.mints.map(mint => {
|
|
731
749
|
return { owner: params.userWallet, mint };
|
|
732
750
|
}),
|
|
733
751
|
]);
|
|
734
|
-
result.map(
|
|
752
|
+
result.map(result => {
|
|
735
753
|
if (!result.exists) {
|
|
736
754
|
mainInstructions.push(this.ix.util.createAssociatedTokenAccountInstruction({
|
|
737
755
|
payer: params.userWallet,
|
|
@@ -743,7 +761,7 @@ class Transactions {
|
|
|
743
761
|
mainInstructions.push(yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
744
762
|
connection,
|
|
745
763
|
payer: params.userWallet,
|
|
746
|
-
withdraw: params.mints.map(
|
|
764
|
+
withdraw: params.mints.map(mint => {
|
|
747
765
|
return { mint, amount: new bn_js_1.default(0) };
|
|
748
766
|
}),
|
|
749
767
|
pdaTokenType: types_1.TokenType.STA,
|
|
@@ -751,7 +769,7 @@ class Transactions {
|
|
|
751
769
|
}));
|
|
752
770
|
return (0, functions_1.createTransactionMeta)({
|
|
753
771
|
payer: params.userWallet,
|
|
754
|
-
description:
|
|
772
|
+
description: 'Withdraw multiple token/s from STA',
|
|
755
773
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
756
774
|
mainInstructions: mainInstructions,
|
|
757
775
|
});
|
|
@@ -769,12 +787,13 @@ class Transactions {
|
|
|
769
787
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
770
788
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
771
789
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
772
|
-
const userPosition = userPositions.find(
|
|
790
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.position));
|
|
773
791
|
if (userPosition === undefined) {
|
|
774
792
|
throw new Error(`Position: ${params.position} does not exist.`);
|
|
775
793
|
}
|
|
776
794
|
// Validate position bin IDs
|
|
777
|
-
if (position.upperBinId === undefined ||
|
|
795
|
+
if (position.upperBinId === undefined ||
|
|
796
|
+
position.lowerBinId === undefined) {
|
|
778
797
|
throw new Error(`Position ${params.position} has invalid bin IDs: upper=${position.upperBinId}, lower=${position.lowerBinId}`);
|
|
779
798
|
}
|
|
780
799
|
console.log(`Position validation passed: upperBinId=${position.upperBinId}, lowerBinId=${position.lowerBinId}, lbPair=${position.lbPair.toString()}`);
|
|
@@ -796,7 +815,7 @@ class Transactions {
|
|
|
796
815
|
strategy: {
|
|
797
816
|
maxBinId: position.upperBinId,
|
|
798
817
|
minBinId: position.lowerBinId,
|
|
799
|
-
strategyType: types_3.StrategyTypeMap[
|
|
818
|
+
strategyType: types_3.StrategyTypeMap['SPOT-IMBALANCED'], // TODO: how to get the right distribution from chain??
|
|
800
819
|
},
|
|
801
820
|
skipInputTokenCheck: true,
|
|
802
821
|
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
@@ -811,7 +830,7 @@ class Transactions {
|
|
|
811
830
|
];
|
|
812
831
|
return (0, functions_1.createTransactionMeta)({
|
|
813
832
|
payer: params.userWallet,
|
|
814
|
-
description:
|
|
833
|
+
description: 'Automation IX: Meteora Auto-compound instructions (claim fee, reward, and deposit to position)',
|
|
815
834
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
816
835
|
mainInstructions,
|
|
817
836
|
});
|
|
@@ -821,7 +840,8 @@ class Transactions {
|
|
|
821
840
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
822
841
|
console.error('compoundAutomationIx error:', errorMessage, error);
|
|
823
842
|
// Check for specific Meteora DLMM errors
|
|
824
|
-
if (errorMessage.includes('getSimulationComputeUnits') ||
|
|
843
|
+
if (errorMessage.includes('getSimulationComputeUnits') ||
|
|
844
|
+
errorMessage.includes('getEstimatedComputeUnit')) {
|
|
825
845
|
throw new Error(`Meteora DLMM compute unit estimation failed: ${errorMessage}. This usually indicates invalid position parameters or pool state.`);
|
|
826
846
|
}
|
|
827
847
|
if (errorMessage.includes('addLiquidityByStrategy')) {
|
|
@@ -837,7 +857,7 @@ class Transactions {
|
|
|
837
857
|
console.log('=== CLAIM AUTOMATION IX START ===');
|
|
838
858
|
console.log('Params:', {
|
|
839
859
|
userWallet: params.userWallet.toString(),
|
|
840
|
-
position: params.position.toString()
|
|
860
|
+
position: params.position.toString(),
|
|
841
861
|
});
|
|
842
862
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
843
863
|
console.log('Program fetched successfully');
|
|
@@ -846,7 +866,7 @@ class Transactions {
|
|
|
846
866
|
lbPair: position.lbPair.toString(),
|
|
847
867
|
owner: position.owner.toString(),
|
|
848
868
|
lowerBinId: position.lowerBinId.toString(),
|
|
849
|
-
upperBinId: position.upperBinId.toString()
|
|
869
|
+
upperBinId: position.upperBinId.toString(),
|
|
850
870
|
});
|
|
851
871
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
852
872
|
console.log('DLMM pool created successfully');
|
|
@@ -854,7 +874,7 @@ class Transactions {
|
|
|
854
874
|
console.log('User PDA generated:', userPda.toString());
|
|
855
875
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
856
876
|
console.log('User positions fetched, count:', userPositions.length);
|
|
857
|
-
const userPosition = userPositions.find(
|
|
877
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.position));
|
|
858
878
|
if (userPosition === undefined) {
|
|
859
879
|
throw new Error(`Position: ${params.position} does not exist.`);
|
|
860
880
|
}
|
|
@@ -878,7 +898,7 @@ class Transactions {
|
|
|
878
898
|
console.log('Creating transaction metadata...');
|
|
879
899
|
const result = (0, functions_1.createTransactionMeta)({
|
|
880
900
|
payer: params.userWallet,
|
|
881
|
-
description:
|
|
901
|
+
description: 'Automation IX: Meteora Auto-claim instructions (claim fee, reward)',
|
|
882
902
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
883
903
|
mainInstructions,
|
|
884
904
|
});
|
|
@@ -892,7 +912,7 @@ class Transactions {
|
|
|
892
912
|
console.error('Main instructions:', mainInstructions.map(ix => ({
|
|
893
913
|
programId: ix.programId.toString(),
|
|
894
914
|
keysCount: ix.keys.length,
|
|
895
|
-
dataLength: ix.data.length
|
|
915
|
+
dataLength: ix.data.length,
|
|
896
916
|
})));
|
|
897
917
|
console.error('=== END METADATA ERROR LOG ===');
|
|
898
918
|
throw metadataError;
|
|
@@ -917,11 +937,11 @@ class Transactions {
|
|
|
917
937
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
918
938
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
919
939
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
920
|
-
const userPosition = userPositions.find(
|
|
940
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.currentPosition));
|
|
921
941
|
if (userPosition === undefined) {
|
|
922
942
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
923
943
|
}
|
|
924
|
-
const binIdsToRemove = userPosition.positionData.positionBinData.map(
|
|
944
|
+
const binIdsToRemove = userPosition.positionData.positionBinData.map(bin => bin.binId);
|
|
925
945
|
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
926
946
|
user: userPda,
|
|
927
947
|
position: params.currentPosition,
|
|
@@ -961,7 +981,7 @@ class Transactions {
|
|
|
961
981
|
];
|
|
962
982
|
return (0, functions_1.createTransactionMeta)({
|
|
963
983
|
payer: params.userWallet,
|
|
964
|
-
description:
|
|
984
|
+
description: 'Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)',
|
|
965
985
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
966
986
|
mainInstructions,
|
|
967
987
|
});
|
|
@@ -978,7 +998,7 @@ class Transactions {
|
|
|
978
998
|
relativeBinRange: params.relativeBinRange,
|
|
979
999
|
distribution: params.distribution,
|
|
980
1000
|
checkRange: params.checkRange,
|
|
981
|
-
useAta: params.useAta
|
|
1001
|
+
useAta: params.useAta,
|
|
982
1002
|
}, null, 2));
|
|
983
1003
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
984
1004
|
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
@@ -987,7 +1007,7 @@ class Transactions {
|
|
|
987
1007
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
988
1008
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
989
1009
|
console.log('Found user positions:', userPositions.length);
|
|
990
|
-
const userPosition = userPositions.find(
|
|
1010
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.currentPosition));
|
|
991
1011
|
if (userPosition === undefined) {
|
|
992
1012
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
993
1013
|
}
|
|
@@ -1033,7 +1053,7 @@ class Transactions {
|
|
|
1033
1053
|
];
|
|
1034
1054
|
return (0, functions_1.createTransactionMeta)({
|
|
1035
1055
|
payer: params.userWallet,
|
|
1036
|
-
description:
|
|
1056
|
+
description: 'Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)',
|
|
1037
1057
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1038
1058
|
mainInstructions,
|
|
1039
1059
|
});
|
|
@@ -1078,7 +1098,7 @@ class Transactions {
|
|
|
1078
1098
|
const mainInstructions = [...initPositionAndAddLiquidityBuilder.mainIxs];
|
|
1079
1099
|
return (0, functions_1.createTransactionMeta)({
|
|
1080
1100
|
payer: params.userWallet,
|
|
1081
|
-
description:
|
|
1101
|
+
description: 'Automation IX: Meteora Open instruction (Open position)',
|
|
1082
1102
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1083
1103
|
mainInstructions,
|
|
1084
1104
|
});
|
|
@@ -1104,7 +1124,7 @@ class Transactions {
|
|
|
1104
1124
|
});
|
|
1105
1125
|
let program;
|
|
1106
1126
|
try {
|
|
1107
|
-
program = yield retryRpcCall(() => meteora_1.MeteoraDLMM.program(connection),
|
|
1127
|
+
program = yield retryRpcCall(() => meteora_1.MeteoraDLMM.program(connection), 'Initialize MeteoraDLMM program');
|
|
1108
1128
|
}
|
|
1109
1129
|
catch (error) {
|
|
1110
1130
|
throw new Error(`Failed to initialize MeteoraDLMM program: ${error}`);
|
|
@@ -1182,7 +1202,7 @@ class Transactions {
|
|
|
1182
1202
|
try {
|
|
1183
1203
|
return (0, functions_1.createTransactionMeta)({
|
|
1184
1204
|
payer: params.userWallet,
|
|
1185
|
-
description:
|
|
1205
|
+
description: 'Automation IX: Meteora Close instruction (Close position)',
|
|
1186
1206
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1187
1207
|
mainInstructions,
|
|
1188
1208
|
});
|
|
@@ -1213,7 +1233,7 @@ class Transactions {
|
|
|
1213
1233
|
shouldClaimAndClose: true,
|
|
1214
1234
|
});
|
|
1215
1235
|
// Filter out non-meteora instructions
|
|
1216
|
-
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));
|
|
1217
1237
|
const farm = addresses_1.USDC_FARM;
|
|
1218
1238
|
const authority = params.userWallet;
|
|
1219
1239
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -1290,7 +1310,7 @@ class Transactions {
|
|
|
1290
1310
|
];
|
|
1291
1311
|
return (0, functions_1.createTransactionMeta)({
|
|
1292
1312
|
payer: params.userWallet,
|
|
1293
|
-
description:
|
|
1313
|
+
description: 'Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)',
|
|
1294
1314
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1295
1315
|
mainInstructions,
|
|
1296
1316
|
});
|
|
@@ -1325,7 +1345,7 @@ class Transactions {
|
|
|
1325
1345
|
});
|
|
1326
1346
|
}));
|
|
1327
1347
|
// Filter out non-meteora instructions
|
|
1328
|
-
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));
|
|
1329
1349
|
const farm = addresses_1.USDC_FARM;
|
|
1330
1350
|
const authority = params.userWallet;
|
|
1331
1351
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -1410,7 +1430,7 @@ class Transactions {
|
|
|
1410
1430
|
];
|
|
1411
1431
|
return (0, functions_1.createTransactionMeta)({
|
|
1412
1432
|
payer: params.userWallet,
|
|
1413
|
-
description:
|
|
1433
|
+
description: 'Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)',
|
|
1414
1434
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1415
1435
|
mainInstructions,
|
|
1416
1436
|
});
|
|
@@ -1420,7 +1440,7 @@ class Transactions {
|
|
|
1420
1440
|
removeLiquidityByRangeInfo(ixs) {
|
|
1421
1441
|
for (const ix of ixs) {
|
|
1422
1442
|
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
1423
|
-
const removeLiquidityByRange = (0, functions_1.sighashMatch)(ix.data,
|
|
1443
|
+
const removeLiquidityByRange = (0, functions_1.sighashMatch)(ix.data, 'RemoveLiquidityByRange');
|
|
1424
1444
|
// Handle original RemoveLiquidityByRange instruction
|
|
1425
1445
|
if (programIdMatch && removeLiquidityByRange) {
|
|
1426
1446
|
return {
|
|
@@ -1451,7 +1471,7 @@ class Transactions {
|
|
|
1451
1471
|
removeLiquidityByRange2Info(ixs) {
|
|
1452
1472
|
for (const ix of ixs) {
|
|
1453
1473
|
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
1454
|
-
const removeLiquidityByRange2 = (0, functions_1.sighashMatch)(ix.data,
|
|
1474
|
+
const removeLiquidityByRange2 = (0, functions_1.sighashMatch)(ix.data, 'remove_liquidity_by_range2', undefined, true);
|
|
1455
1475
|
// Handle RemoveLiquidityByRange2 instruction with different account structure
|
|
1456
1476
|
if (programIdMatch && removeLiquidityByRange2) {
|
|
1457
1477
|
return {
|
|
@@ -1537,7 +1557,7 @@ class Transactions {
|
|
|
1537
1557
|
const mainInstructions = [orcaIx];
|
|
1538
1558
|
return (0, functions_1.createTransactionMeta)({
|
|
1539
1559
|
payer: params.userWallet,
|
|
1540
|
-
description:
|
|
1560
|
+
description: 'Create new Orca Position',
|
|
1541
1561
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1542
1562
|
mainInstructions,
|
|
1543
1563
|
});
|
|
@@ -1597,7 +1617,7 @@ class Transactions {
|
|
|
1597
1617
|
const mainInstructions = [orcaIx];
|
|
1598
1618
|
return (0, functions_1.createTransactionMeta)({
|
|
1599
1619
|
payer: params.userWallet,
|
|
1600
|
-
description:
|
|
1620
|
+
description: 'Close Orca Position',
|
|
1601
1621
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1602
1622
|
mainInstructions,
|
|
1603
1623
|
});
|
|
@@ -1620,7 +1640,8 @@ class Transactions {
|
|
|
1620
1640
|
let positionData;
|
|
1621
1641
|
if (params.mintOrPosition.position !== undefined) {
|
|
1622
1642
|
position = params.mintOrPosition.position;
|
|
1623
|
-
positionData =
|
|
1643
|
+
positionData =
|
|
1644
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1624
1645
|
positionMint = positionData.positionMint;
|
|
1625
1646
|
}
|
|
1626
1647
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1628,7 +1649,7 @@ class Transactions {
|
|
|
1628
1649
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1629
1650
|
}
|
|
1630
1651
|
else {
|
|
1631
|
-
throw new Error(
|
|
1652
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1632
1653
|
}
|
|
1633
1654
|
const positionTokenAccount = this.orcaPda.generatePositionTokenAccount(userPda, positionMint, params.is2022Position || false);
|
|
1634
1655
|
if (params.newPosition) {
|
|
@@ -1640,7 +1661,8 @@ class Transactions {
|
|
|
1640
1661
|
};
|
|
1641
1662
|
}
|
|
1642
1663
|
else {
|
|
1643
|
-
positionData =
|
|
1664
|
+
positionData =
|
|
1665
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1644
1666
|
}
|
|
1645
1667
|
if (positionData === null) {
|
|
1646
1668
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1658,7 +1680,7 @@ class Transactions {
|
|
|
1658
1680
|
const tokenKey = result.tokenKey;
|
|
1659
1681
|
const token = tokenSeeds[index];
|
|
1660
1682
|
if (!result.exists &&
|
|
1661
|
-
`${token.mint}` !==
|
|
1683
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1662
1684
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1663
1685
|
}
|
|
1664
1686
|
});
|
|
@@ -1777,7 +1799,8 @@ class Transactions {
|
|
|
1777
1799
|
let positionData;
|
|
1778
1800
|
if (params.mintOrPosition.position !== undefined) {
|
|
1779
1801
|
position = params.mintOrPosition.position;
|
|
1780
|
-
positionData =
|
|
1802
|
+
positionData =
|
|
1803
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1781
1804
|
positionMint = positionData.positionMint;
|
|
1782
1805
|
}
|
|
1783
1806
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1785,7 +1808,7 @@ class Transactions {
|
|
|
1785
1808
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1786
1809
|
}
|
|
1787
1810
|
else {
|
|
1788
|
-
throw new Error(
|
|
1811
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1789
1812
|
}
|
|
1790
1813
|
const positionTokenAccount = (0, functions_1.generateAta)(userPda, positionMint);
|
|
1791
1814
|
if (params.newPosition) {
|
|
@@ -1797,7 +1820,8 @@ class Transactions {
|
|
|
1797
1820
|
};
|
|
1798
1821
|
}
|
|
1799
1822
|
else {
|
|
1800
|
-
positionData =
|
|
1823
|
+
positionData =
|
|
1824
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1801
1825
|
}
|
|
1802
1826
|
if (positionData === null) {
|
|
1803
1827
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1815,7 +1839,7 @@ class Transactions {
|
|
|
1815
1839
|
const tokenKey = result.tokenKey;
|
|
1816
1840
|
const token = tokenSeeds[index];
|
|
1817
1841
|
if (!result.exists &&
|
|
1818
|
-
`${token.mint}` !==
|
|
1842
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1819
1843
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1820
1844
|
}
|
|
1821
1845
|
});
|
|
@@ -1929,7 +1953,8 @@ class Transactions {
|
|
|
1929
1953
|
let positionData;
|
|
1930
1954
|
if (params.mintOrPosition.position !== undefined) {
|
|
1931
1955
|
position = params.mintOrPosition.position;
|
|
1932
|
-
positionData =
|
|
1956
|
+
positionData =
|
|
1957
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1933
1958
|
positionMint = positionData.positionMint;
|
|
1934
1959
|
}
|
|
1935
1960
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1937,7 +1962,7 @@ class Transactions {
|
|
|
1937
1962
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1938
1963
|
}
|
|
1939
1964
|
else {
|
|
1940
|
-
throw new Error(
|
|
1965
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1941
1966
|
}
|
|
1942
1967
|
const positionTokenAccount = this.orcaPda.generatePositionTokenAccount(userPda, positionMint, params.is2022Position || false);
|
|
1943
1968
|
if (params.newPosition) {
|
|
@@ -1949,7 +1974,8 @@ class Transactions {
|
|
|
1949
1974
|
};
|
|
1950
1975
|
}
|
|
1951
1976
|
else {
|
|
1952
|
-
positionData =
|
|
1977
|
+
positionData =
|
|
1978
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1953
1979
|
}
|
|
1954
1980
|
if (positionData === null) {
|
|
1955
1981
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1967,7 +1993,7 @@ class Transactions {
|
|
|
1967
1993
|
const tokenKey = result.tokenKey;
|
|
1968
1994
|
const token = tokenSeeds[index];
|
|
1969
1995
|
if (!result.exists &&
|
|
1970
|
-
`${token.mint}` !==
|
|
1996
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1971
1997
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1972
1998
|
}
|
|
1973
1999
|
});
|
|
@@ -1977,7 +2003,7 @@ class Transactions {
|
|
|
1977
2003
|
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
1978
2004
|
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
1979
2005
|
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
1980
|
-
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);
|
|
1981
2007
|
// TODO: Derive based on amountToSwap calculation
|
|
1982
2008
|
let aToB = params.aToB;
|
|
1983
2009
|
const tickArrays = whirlpools_sdk_1.SwapUtils.getTickArrayPublicKeys(whirlpoolData.tickCurrentIndex, whirlpoolData.tickSpacing, aToB, addresses_1.ORCA_WHIRLPOOL_PROGRAM, whirlpool);
|
|
@@ -2442,11 +2468,11 @@ class Transactions {
|
|
|
2442
2468
|
});
|
|
2443
2469
|
}
|
|
2444
2470
|
}
|
|
2445
|
-
const result = yield (0, functions_1.tokenAccountExists)(connection, rewardMints.map(
|
|
2471
|
+
const result = yield (0, functions_1.tokenAccountExists)(connection, rewardMints.map(mint => {
|
|
2446
2472
|
return { owner: userPda, mint, isSta: false };
|
|
2447
2473
|
}));
|
|
2448
2474
|
const initRewardATA = result
|
|
2449
|
-
.map(
|
|
2475
|
+
.map(result => {
|
|
2450
2476
|
if (!result.exists) {
|
|
2451
2477
|
return (0, spl_token_1.createAssociatedTokenAccountInstruction)(params.userWallet, result.tokenKey, userPda, result.mint, addresses_1.TOKEN_PROGRAM_ID, addresses_1.ASSOCIATED_TOKEN_PROGRAM);
|
|
2452
2478
|
}
|
|
@@ -2454,7 +2480,7 @@ class Transactions {
|
|
|
2454
2480
|
return null;
|
|
2455
2481
|
}
|
|
2456
2482
|
})
|
|
2457
|
-
.filter(
|
|
2483
|
+
.filter(result => result !== null);
|
|
2458
2484
|
whirlpoolData.rewardInfos[0].mint;
|
|
2459
2485
|
// @ts-ignore
|
|
2460
2486
|
const extensionIx = yield anchor_1.Anchor.instance()
|
|
@@ -2534,8 +2560,12 @@ class Transactions {
|
|
|
2534
2560
|
// Get the pool keys (for lookup table account)
|
|
2535
2561
|
(0, functions_1.benchmark)({ name: `raydiumOpenPosition`, msg: `sdk.clmm.getClmmPoolKeys` });
|
|
2536
2562
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(params.poolState.toString());
|
|
2537
|
-
(0, functions_1.benchmark)({
|
|
2538
|
-
|
|
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);
|
|
2539
2569
|
const addressLookupTableAddresses = [];
|
|
2540
2570
|
if (poolKeys.lookupTableAccount) {
|
|
2541
2571
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2550,7 +2580,7 @@ class Transactions {
|
|
|
2550
2580
|
2846640 + // 281 - personal position
|
|
2551
2581
|
2296800 + // 202 - position nft mint
|
|
2552
2582
|
2074080; // 170 - position nft account
|
|
2553
|
-
console.log(
|
|
2583
|
+
console.log('SOL to send to pda lamport: ', lamports / 1000000000);
|
|
2554
2584
|
// Lamports needed for opening a position
|
|
2555
2585
|
const lamportIx = web3.SystemProgram.transfer({
|
|
2556
2586
|
fromPubkey: params.userWallet,
|
|
@@ -2564,7 +2594,7 @@ class Transactions {
|
|
|
2564
2594
|
const amountY = params.amountY
|
|
2565
2595
|
.mul(new bn_js_1.default(10000).sub(slippage))
|
|
2566
2596
|
.div(new bn_js_1.default(10000));
|
|
2567
|
-
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);
|
|
2568
2598
|
const wrapIxs = (0, functions_1.wrapSolIfMintIsWsol)(params.userWallet, params.userWallet, [
|
|
2569
2599
|
{ mint: tokenMint0, amount: amount0Max },
|
|
2570
2600
|
{ mint: tokenMint1, amount: amount1Max },
|
|
@@ -2597,7 +2627,7 @@ class Transactions {
|
|
|
2597
2627
|
});
|
|
2598
2628
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2599
2629
|
tokenMint0,
|
|
2600
|
-
tokenMint1
|
|
2630
|
+
tokenMint1,
|
|
2601
2631
|
]);
|
|
2602
2632
|
const mainInstructions = [
|
|
2603
2633
|
lamportIx,
|
|
@@ -2611,7 +2641,10 @@ class Transactions {
|
|
|
2611
2641
|
return yield (0, functions_1.createTransactionMeta)({
|
|
2612
2642
|
payer: params.userWallet,
|
|
2613
2643
|
description: `Open Raydium Position`,
|
|
2614
|
-
addressLookupTableAddresses: [
|
|
2644
|
+
addressLookupTableAddresses: [
|
|
2645
|
+
...addresses_1.GLOBAL_ALT,
|
|
2646
|
+
...addressLookupTableAddresses,
|
|
2647
|
+
],
|
|
2615
2648
|
mainInstructions,
|
|
2616
2649
|
});
|
|
2617
2650
|
});
|
|
@@ -2634,10 +2667,17 @@ class Transactions {
|
|
|
2634
2667
|
// Get the Raydium SDK instance
|
|
2635
2668
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2636
2669
|
// Get the pool keys (for lookup table account)
|
|
2637
|
-
(0, functions_1.benchmark)({
|
|
2670
|
+
(0, functions_1.benchmark)({
|
|
2671
|
+
name: `raydiumWithdrawAndClosePosition`,
|
|
2672
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2673
|
+
});
|
|
2638
2674
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2639
|
-
(0, functions_1.benchmark)({
|
|
2640
|
-
|
|
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);
|
|
2641
2681
|
const addressLookupTableAddresses = [];
|
|
2642
2682
|
if (poolKeys.lookupTableAccount) {
|
|
2643
2683
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2648,18 +2688,22 @@ class Transactions {
|
|
|
2648
2688
|
{ mint: fetch.poolStateInfo.tokenMint0 },
|
|
2649
2689
|
{ mint: fetch.poolStateInfo.tokenMint1 },
|
|
2650
2690
|
...fetch.poolStateInfo.rewardInfos
|
|
2651
|
-
.filter(
|
|
2652
|
-
.map(
|
|
2691
|
+
.filter(v => !v.tokenMint.equals(web3.SystemProgram.programId))
|
|
2692
|
+
.map(v => {
|
|
2653
2693
|
return { mint: v.tokenMint };
|
|
2654
2694
|
}),
|
|
2655
2695
|
],
|
|
2656
2696
|
});
|
|
2657
|
-
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2658
|
-
|
|
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([
|
|
2659
2702
|
...rewards,
|
|
2660
2703
|
fetch.poolStateInfo.tokenMint0.toString(),
|
|
2661
2704
|
fetch.poolStateInfo.tokenMint1.toString(),
|
|
2662
|
-
])
|
|
2705
|
+
]),
|
|
2706
|
+
].map(v => new web3.PublicKey(v));
|
|
2663
2707
|
const nftOwner = (0, functions_1.generateUserPdaLamport)(params.userWallet);
|
|
2664
2708
|
const initAtaIxs = mints.map(v => {
|
|
2665
2709
|
const payer = params.userWallet;
|
|
@@ -2669,7 +2713,7 @@ class Transactions {
|
|
|
2669
2713
|
});
|
|
2670
2714
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2671
2715
|
fetch.poolStateInfo.tokenMint0,
|
|
2672
|
-
fetch.poolStateInfo.tokenMint1
|
|
2716
|
+
fetch.poolStateInfo.tokenMint1,
|
|
2673
2717
|
]);
|
|
2674
2718
|
const raydiumDecreaseLiquidityIxViaHawksight = yield this.ix.raydium.raydiumDecreaseLiquidity({
|
|
2675
2719
|
connection,
|
|
@@ -2694,7 +2738,10 @@ class Transactions {
|
|
|
2694
2738
|
return (0, functions_1.createTransactionMeta)({
|
|
2695
2739
|
payer: params.userWallet,
|
|
2696
2740
|
description: `Close Raydium Position`,
|
|
2697
|
-
addressLookupTableAddresses: [
|
|
2741
|
+
addressLookupTableAddresses: [
|
|
2742
|
+
...addresses_1.GLOBAL_ALT,
|
|
2743
|
+
...addressLookupTableAddresses,
|
|
2744
|
+
],
|
|
2698
2745
|
mainInstructions,
|
|
2699
2746
|
});
|
|
2700
2747
|
}
|
|
@@ -2710,7 +2757,10 @@ class Transactions {
|
|
|
2710
2757
|
return (0, functions_1.createTransactionMeta)({
|
|
2711
2758
|
payer: params.userWallet,
|
|
2712
2759
|
description: `Withdraw and close Raydium Position`,
|
|
2713
|
-
addressLookupTableAddresses: [
|
|
2760
|
+
addressLookupTableAddresses: [
|
|
2761
|
+
...addresses_1.GLOBAL_ALT,
|
|
2762
|
+
...addressLookupTableAddresses,
|
|
2763
|
+
],
|
|
2714
2764
|
mainInstructions,
|
|
2715
2765
|
});
|
|
2716
2766
|
}
|
|
@@ -2764,10 +2814,17 @@ class Transactions {
|
|
|
2764
2814
|
// Get the Raydium SDK instance
|
|
2765
2815
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2766
2816
|
// Get the pool keys (for lookup table account)
|
|
2767
|
-
(0, functions_1.benchmark)({
|
|
2817
|
+
(0, functions_1.benchmark)({
|
|
2818
|
+
name: `raydiumIncreaseLiquidity`,
|
|
2819
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2820
|
+
});
|
|
2768
2821
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2769
|
-
(0, functions_1.benchmark)({
|
|
2770
|
-
|
|
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);
|
|
2771
2828
|
const addressLookupTableAddresses = [];
|
|
2772
2829
|
if (poolKeys.lookupTableAccount) {
|
|
2773
2830
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2779,14 +2836,14 @@ class Transactions {
|
|
|
2779
2836
|
const amountY = params.amountY
|
|
2780
2837
|
.mul(new bn_js_1.default(10000).sub(slippage))
|
|
2781
2838
|
.div(new bn_js_1.default(10000));
|
|
2782
|
-
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);
|
|
2783
2840
|
const wrapIxs = (0, functions_1.wrapSolIfMintIsWsol)(params.userWallet, params.userWallet, [
|
|
2784
2841
|
{ mint: tokenMint0, amount: amount0Max },
|
|
2785
2842
|
{ mint: tokenMint1, amount: amount1Max },
|
|
2786
2843
|
]);
|
|
2787
2844
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2788
2845
|
tokenMint0,
|
|
2789
|
-
tokenMint1
|
|
2846
|
+
tokenMint1,
|
|
2790
2847
|
]);
|
|
2791
2848
|
const depositIx = yield this.ix.iyfMain.depositMultipleLamportPdaToken({
|
|
2792
2849
|
userWallet: params.userWallet,
|
|
@@ -2820,7 +2877,10 @@ class Transactions {
|
|
|
2820
2877
|
return (0, functions_1.createTransactionMeta)({
|
|
2821
2878
|
payer: params.userWallet,
|
|
2822
2879
|
description: `Raydium increase liquidity`,
|
|
2823
|
-
addressLookupTableAddresses: [
|
|
2880
|
+
addressLookupTableAddresses: [
|
|
2881
|
+
...addresses_1.GLOBAL_ALT,
|
|
2882
|
+
...addressLookupTableAddresses,
|
|
2883
|
+
],
|
|
2824
2884
|
mainInstructions,
|
|
2825
2885
|
});
|
|
2826
2886
|
});
|
|
@@ -2842,10 +2902,17 @@ class Transactions {
|
|
|
2842
2902
|
// Get the Raydium SDK instance
|
|
2843
2903
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2844
2904
|
// Get the pool keys (for lookup table account)
|
|
2845
|
-
(0, functions_1.benchmark)({
|
|
2905
|
+
(0, functions_1.benchmark)({
|
|
2906
|
+
name: `raydiumDecreaseLiquidity`,
|
|
2907
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2908
|
+
});
|
|
2846
2909
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2847
|
-
(0, functions_1.benchmark)({
|
|
2848
|
-
|
|
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);
|
|
2849
2916
|
const addressLookupTableAddresses = [];
|
|
2850
2917
|
if (poolKeys.lookupTableAccount) {
|
|
2851
2918
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2856,18 +2923,22 @@ class Transactions {
|
|
|
2856
2923
|
{ mint: fetch.poolStateInfo.tokenMint0 },
|
|
2857
2924
|
{ mint: fetch.poolStateInfo.tokenMint1 },
|
|
2858
2925
|
...fetch.poolStateInfo.rewardInfos
|
|
2859
|
-
.filter(
|
|
2860
|
-
.map(
|
|
2926
|
+
.filter(v => !v.tokenMint.equals(web3.SystemProgram.programId))
|
|
2927
|
+
.map(v => {
|
|
2861
2928
|
return { mint: v.tokenMint };
|
|
2862
2929
|
}),
|
|
2863
2930
|
],
|
|
2864
2931
|
});
|
|
2865
|
-
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2866
|
-
|
|
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([
|
|
2867
2937
|
...rewards,
|
|
2868
2938
|
fetch.poolStateInfo.tokenMint0.toString(),
|
|
2869
2939
|
fetch.poolStateInfo.tokenMint1.toString(),
|
|
2870
|
-
])
|
|
2940
|
+
]),
|
|
2941
|
+
].map(v => new web3.PublicKey(v));
|
|
2871
2942
|
const nftOwner = (0, functions_1.generateUserPdaLamport)(params.userWallet);
|
|
2872
2943
|
const initAtaIxs = mints.map(v => {
|
|
2873
2944
|
const payer = params.userWallet;
|
|
@@ -2877,7 +2948,7 @@ class Transactions {
|
|
|
2877
2948
|
});
|
|
2878
2949
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2879
2950
|
fetch.poolStateInfo.tokenMint0,
|
|
2880
|
-
fetch.poolStateInfo.tokenMint1
|
|
2951
|
+
fetch.poolStateInfo.tokenMint1,
|
|
2881
2952
|
]);
|
|
2882
2953
|
const raydiumDecreaseLiquidityIxViaHawksight = yield this.ix.raydium.raydiumDecreaseLiquidity({
|
|
2883
2954
|
connection,
|
|
@@ -2893,7 +2964,10 @@ class Transactions {
|
|
|
2893
2964
|
return (0, functions_1.createTransactionMeta)({
|
|
2894
2965
|
payer: params.userWallet,
|
|
2895
2966
|
description: `Raydium decrease liquidity`,
|
|
2896
|
-
addressLookupTableAddresses: [
|
|
2967
|
+
addressLookupTableAddresses: [
|
|
2968
|
+
...addresses_1.GLOBAL_ALT,
|
|
2969
|
+
...addressLookupTableAddresses,
|
|
2970
|
+
],
|
|
2897
2971
|
mainInstructions,
|
|
2898
2972
|
});
|
|
2899
2973
|
});
|