@hawksightco/hawk-sdk 1.3.145 → 1.3.147
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,16 @@ 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
|
+
useSta: true,
|
|
717
|
+
pdaTokenType: types_1.TokenType.STA,
|
|
718
|
+
hasAmount: false,
|
|
719
|
+
}));
|
|
720
|
+
// }
|
|
702
721
|
mainInstructions.push(yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
703
722
|
connection,
|
|
704
723
|
payer: params.userWallet,
|
|
@@ -709,7 +728,7 @@ class Transactions {
|
|
|
709
728
|
mainInstructions.push(...(0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [params.mint]));
|
|
710
729
|
return (0, functions_1.createTransactionMeta)({
|
|
711
730
|
payer: params.userWallet,
|
|
712
|
-
description:
|
|
731
|
+
description: 'Withdraw token from PDA',
|
|
713
732
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
714
733
|
mainInstructions: mainInstructions,
|
|
715
734
|
});
|
|
@@ -727,11 +746,11 @@ class Transactions {
|
|
|
727
746
|
const farm = addresses_1.USDC_FARM;
|
|
728
747
|
const mainInstructions = [];
|
|
729
748
|
const result = yield (0, functions_1.tokenAccountExists)(connection, [
|
|
730
|
-
...params.mints.map(
|
|
749
|
+
...params.mints.map(mint => {
|
|
731
750
|
return { owner: params.userWallet, mint };
|
|
732
751
|
}),
|
|
733
752
|
]);
|
|
734
|
-
result.map(
|
|
753
|
+
result.map(result => {
|
|
735
754
|
if (!result.exists) {
|
|
736
755
|
mainInstructions.push(this.ix.util.createAssociatedTokenAccountInstruction({
|
|
737
756
|
payer: params.userWallet,
|
|
@@ -743,7 +762,7 @@ class Transactions {
|
|
|
743
762
|
mainInstructions.push(yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
744
763
|
connection,
|
|
745
764
|
payer: params.userWallet,
|
|
746
|
-
withdraw: params.mints.map(
|
|
765
|
+
withdraw: params.mints.map(mint => {
|
|
747
766
|
return { mint, amount: new bn_js_1.default(0) };
|
|
748
767
|
}),
|
|
749
768
|
pdaTokenType: types_1.TokenType.STA,
|
|
@@ -751,7 +770,7 @@ class Transactions {
|
|
|
751
770
|
}));
|
|
752
771
|
return (0, functions_1.createTransactionMeta)({
|
|
753
772
|
payer: params.userWallet,
|
|
754
|
-
description:
|
|
773
|
+
description: 'Withdraw multiple token/s from STA',
|
|
755
774
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
756
775
|
mainInstructions: mainInstructions,
|
|
757
776
|
});
|
|
@@ -769,12 +788,13 @@ class Transactions {
|
|
|
769
788
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
770
789
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
771
790
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
772
|
-
const userPosition = userPositions.find(
|
|
791
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.position));
|
|
773
792
|
if (userPosition === undefined) {
|
|
774
793
|
throw new Error(`Position: ${params.position} does not exist.`);
|
|
775
794
|
}
|
|
776
795
|
// Validate position bin IDs
|
|
777
|
-
if (position.upperBinId === undefined ||
|
|
796
|
+
if (position.upperBinId === undefined ||
|
|
797
|
+
position.lowerBinId === undefined) {
|
|
778
798
|
throw new Error(`Position ${params.position} has invalid bin IDs: upper=${position.upperBinId}, lower=${position.lowerBinId}`);
|
|
779
799
|
}
|
|
780
800
|
console.log(`Position validation passed: upperBinId=${position.upperBinId}, lowerBinId=${position.lowerBinId}, lbPair=${position.lbPair.toString()}`);
|
|
@@ -796,7 +816,7 @@ class Transactions {
|
|
|
796
816
|
strategy: {
|
|
797
817
|
maxBinId: position.upperBinId,
|
|
798
818
|
minBinId: position.lowerBinId,
|
|
799
|
-
strategyType: types_3.StrategyTypeMap[
|
|
819
|
+
strategyType: types_3.StrategyTypeMap['SPOT-IMBALANCED'], // TODO: how to get the right distribution from chain??
|
|
800
820
|
},
|
|
801
821
|
skipInputTokenCheck: true,
|
|
802
822
|
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
@@ -811,7 +831,7 @@ class Transactions {
|
|
|
811
831
|
];
|
|
812
832
|
return (0, functions_1.createTransactionMeta)({
|
|
813
833
|
payer: params.userWallet,
|
|
814
|
-
description:
|
|
834
|
+
description: 'Automation IX: Meteora Auto-compound instructions (claim fee, reward, and deposit to position)',
|
|
815
835
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
816
836
|
mainInstructions,
|
|
817
837
|
});
|
|
@@ -821,7 +841,8 @@ class Transactions {
|
|
|
821
841
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
822
842
|
console.error('compoundAutomationIx error:', errorMessage, error);
|
|
823
843
|
// Check for specific Meteora DLMM errors
|
|
824
|
-
if (errorMessage.includes('getSimulationComputeUnits') ||
|
|
844
|
+
if (errorMessage.includes('getSimulationComputeUnits') ||
|
|
845
|
+
errorMessage.includes('getEstimatedComputeUnit')) {
|
|
825
846
|
throw new Error(`Meteora DLMM compute unit estimation failed: ${errorMessage}. This usually indicates invalid position parameters or pool state.`);
|
|
826
847
|
}
|
|
827
848
|
if (errorMessage.includes('addLiquidityByStrategy')) {
|
|
@@ -837,7 +858,7 @@ class Transactions {
|
|
|
837
858
|
console.log('=== CLAIM AUTOMATION IX START ===');
|
|
838
859
|
console.log('Params:', {
|
|
839
860
|
userWallet: params.userWallet.toString(),
|
|
840
|
-
position: params.position.toString()
|
|
861
|
+
position: params.position.toString(),
|
|
841
862
|
});
|
|
842
863
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
843
864
|
console.log('Program fetched successfully');
|
|
@@ -846,7 +867,7 @@ class Transactions {
|
|
|
846
867
|
lbPair: position.lbPair.toString(),
|
|
847
868
|
owner: position.owner.toString(),
|
|
848
869
|
lowerBinId: position.lowerBinId.toString(),
|
|
849
|
-
upperBinId: position.upperBinId.toString()
|
|
870
|
+
upperBinId: position.upperBinId.toString(),
|
|
850
871
|
});
|
|
851
872
|
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
852
873
|
console.log('DLMM pool created successfully');
|
|
@@ -854,7 +875,7 @@ class Transactions {
|
|
|
854
875
|
console.log('User PDA generated:', userPda.toString());
|
|
855
876
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
856
877
|
console.log('User positions fetched, count:', userPositions.length);
|
|
857
|
-
const userPosition = userPositions.find(
|
|
878
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.position));
|
|
858
879
|
if (userPosition === undefined) {
|
|
859
880
|
throw new Error(`Position: ${params.position} does not exist.`);
|
|
860
881
|
}
|
|
@@ -878,7 +899,7 @@ class Transactions {
|
|
|
878
899
|
console.log('Creating transaction metadata...');
|
|
879
900
|
const result = (0, functions_1.createTransactionMeta)({
|
|
880
901
|
payer: params.userWallet,
|
|
881
|
-
description:
|
|
902
|
+
description: 'Automation IX: Meteora Auto-claim instructions (claim fee, reward)',
|
|
882
903
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
883
904
|
mainInstructions,
|
|
884
905
|
});
|
|
@@ -892,7 +913,7 @@ class Transactions {
|
|
|
892
913
|
console.error('Main instructions:', mainInstructions.map(ix => ({
|
|
893
914
|
programId: ix.programId.toString(),
|
|
894
915
|
keysCount: ix.keys.length,
|
|
895
|
-
dataLength: ix.data.length
|
|
916
|
+
dataLength: ix.data.length,
|
|
896
917
|
})));
|
|
897
918
|
console.error('=== END METADATA ERROR LOG ===');
|
|
898
919
|
throw metadataError;
|
|
@@ -917,11 +938,11 @@ class Transactions {
|
|
|
917
938
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
918
939
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
919
940
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
920
|
-
const userPosition = userPositions.find(
|
|
941
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.currentPosition));
|
|
921
942
|
if (userPosition === undefined) {
|
|
922
943
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
923
944
|
}
|
|
924
|
-
const binIdsToRemove = userPosition.positionData.positionBinData.map(
|
|
945
|
+
const binIdsToRemove = userPosition.positionData.positionBinData.map(bin => bin.binId);
|
|
925
946
|
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
926
947
|
user: userPda,
|
|
927
948
|
position: params.currentPosition,
|
|
@@ -961,7 +982,7 @@ class Transactions {
|
|
|
961
982
|
];
|
|
962
983
|
return (0, functions_1.createTransactionMeta)({
|
|
963
984
|
payer: params.userWallet,
|
|
964
|
-
description:
|
|
985
|
+
description: 'Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)',
|
|
965
986
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
966
987
|
mainInstructions,
|
|
967
988
|
});
|
|
@@ -978,7 +999,7 @@ class Transactions {
|
|
|
978
999
|
relativeBinRange: params.relativeBinRange,
|
|
979
1000
|
distribution: params.distribution,
|
|
980
1001
|
checkRange: params.checkRange,
|
|
981
|
-
useAta: params.useAta
|
|
1002
|
+
useAta: params.useAta,
|
|
982
1003
|
}, null, 2));
|
|
983
1004
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
984
1005
|
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
@@ -987,7 +1008,7 @@ class Transactions {
|
|
|
987
1008
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
988
1009
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
989
1010
|
console.log('Found user positions:', userPositions.length);
|
|
990
|
-
const userPosition = userPositions.find(
|
|
1011
|
+
const userPosition = userPositions.find(userPosition => userPosition.publicKey.equals(params.currentPosition));
|
|
991
1012
|
if (userPosition === undefined) {
|
|
992
1013
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
993
1014
|
}
|
|
@@ -1033,7 +1054,7 @@ class Transactions {
|
|
|
1033
1054
|
];
|
|
1034
1055
|
return (0, functions_1.createTransactionMeta)({
|
|
1035
1056
|
payer: params.userWallet,
|
|
1036
|
-
description:
|
|
1057
|
+
description: 'Automation IX: Meteora Auto-rebalance instructions (Close position and deposit to new position)',
|
|
1037
1058
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1038
1059
|
mainInstructions,
|
|
1039
1060
|
});
|
|
@@ -1078,7 +1099,7 @@ class Transactions {
|
|
|
1078
1099
|
const mainInstructions = [...initPositionAndAddLiquidityBuilder.mainIxs];
|
|
1079
1100
|
return (0, functions_1.createTransactionMeta)({
|
|
1080
1101
|
payer: params.userWallet,
|
|
1081
|
-
description:
|
|
1102
|
+
description: 'Automation IX: Meteora Open instruction (Open position)',
|
|
1082
1103
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1083
1104
|
mainInstructions,
|
|
1084
1105
|
});
|
|
@@ -1104,7 +1125,7 @@ class Transactions {
|
|
|
1104
1125
|
});
|
|
1105
1126
|
let program;
|
|
1106
1127
|
try {
|
|
1107
|
-
program = yield retryRpcCall(() => meteora_1.MeteoraDLMM.program(connection),
|
|
1128
|
+
program = yield retryRpcCall(() => meteora_1.MeteoraDLMM.program(connection), 'Initialize MeteoraDLMM program');
|
|
1108
1129
|
}
|
|
1109
1130
|
catch (error) {
|
|
1110
1131
|
throw new Error(`Failed to initialize MeteoraDLMM program: ${error}`);
|
|
@@ -1182,7 +1203,7 @@ class Transactions {
|
|
|
1182
1203
|
try {
|
|
1183
1204
|
return (0, functions_1.createTransactionMeta)({
|
|
1184
1205
|
payer: params.userWallet,
|
|
1185
|
-
description:
|
|
1206
|
+
description: 'Automation IX: Meteora Close instruction (Close position)',
|
|
1186
1207
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1187
1208
|
mainInstructions,
|
|
1188
1209
|
});
|
|
@@ -1213,7 +1234,7 @@ class Transactions {
|
|
|
1213
1234
|
shouldClaimAndClose: true,
|
|
1214
1235
|
});
|
|
1215
1236
|
// Filter out non-meteora instructions
|
|
1216
|
-
const ixs = (0, functions_1.getIxs)(txn).filter(
|
|
1237
|
+
const ixs = (0, functions_1.getIxs)(txn).filter(ix => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
1217
1238
|
const farm = addresses_1.USDC_FARM;
|
|
1218
1239
|
const authority = params.userWallet;
|
|
1219
1240
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -1290,7 +1311,7 @@ class Transactions {
|
|
|
1290
1311
|
];
|
|
1291
1312
|
return (0, functions_1.createTransactionMeta)({
|
|
1292
1313
|
payer: params.userWallet,
|
|
1293
|
-
description:
|
|
1314
|
+
description: 'Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)',
|
|
1294
1315
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1295
1316
|
mainInstructions,
|
|
1296
1317
|
});
|
|
@@ -1325,7 +1346,7 @@ class Transactions {
|
|
|
1325
1346
|
});
|
|
1326
1347
|
}));
|
|
1327
1348
|
// Filter out non-meteora instructions
|
|
1328
|
-
const ixs = (0, functions_1.getIxs)(txn).filter(
|
|
1349
|
+
const ixs = (0, functions_1.getIxs)(txn).filter(ix => ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM));
|
|
1329
1350
|
const farm = addresses_1.USDC_FARM;
|
|
1330
1351
|
const authority = params.userWallet;
|
|
1331
1352
|
const iyfProgram = addresses_1.IYF_MAIN;
|
|
@@ -1410,7 +1431,7 @@ class Transactions {
|
|
|
1410
1431
|
];
|
|
1411
1432
|
return (0, functions_1.createTransactionMeta)({
|
|
1412
1433
|
payer: params.userWallet,
|
|
1413
|
-
description:
|
|
1434
|
+
description: 'Automation IX: Meteora limit close instruction (Full withdraw and close on to specific bin id)',
|
|
1414
1435
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1415
1436
|
mainInstructions,
|
|
1416
1437
|
});
|
|
@@ -1420,7 +1441,7 @@ class Transactions {
|
|
|
1420
1441
|
removeLiquidityByRangeInfo(ixs) {
|
|
1421
1442
|
for (const ix of ixs) {
|
|
1422
1443
|
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
1423
|
-
const removeLiquidityByRange = (0, functions_1.sighashMatch)(ix.data,
|
|
1444
|
+
const removeLiquidityByRange = (0, functions_1.sighashMatch)(ix.data, 'RemoveLiquidityByRange');
|
|
1424
1445
|
// Handle original RemoveLiquidityByRange instruction
|
|
1425
1446
|
if (programIdMatch && removeLiquidityByRange) {
|
|
1426
1447
|
return {
|
|
@@ -1451,7 +1472,7 @@ class Transactions {
|
|
|
1451
1472
|
removeLiquidityByRange2Info(ixs) {
|
|
1452
1473
|
for (const ix of ixs) {
|
|
1453
1474
|
const programIdMatch = ix.programId.equals(addresses_1.METEORA_DLMM_PROGRAM);
|
|
1454
|
-
const removeLiquidityByRange2 = (0, functions_1.sighashMatch)(ix.data,
|
|
1475
|
+
const removeLiquidityByRange2 = (0, functions_1.sighashMatch)(ix.data, 'remove_liquidity_by_range2', undefined, true);
|
|
1455
1476
|
// Handle RemoveLiquidityByRange2 instruction with different account structure
|
|
1456
1477
|
if (programIdMatch && removeLiquidityByRange2) {
|
|
1457
1478
|
return {
|
|
@@ -1537,7 +1558,7 @@ class Transactions {
|
|
|
1537
1558
|
const mainInstructions = [orcaIx];
|
|
1538
1559
|
return (0, functions_1.createTransactionMeta)({
|
|
1539
1560
|
payer: params.userWallet,
|
|
1540
|
-
description:
|
|
1561
|
+
description: 'Create new Orca Position',
|
|
1541
1562
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1542
1563
|
mainInstructions,
|
|
1543
1564
|
});
|
|
@@ -1597,7 +1618,7 @@ class Transactions {
|
|
|
1597
1618
|
const mainInstructions = [orcaIx];
|
|
1598
1619
|
return (0, functions_1.createTransactionMeta)({
|
|
1599
1620
|
payer: params.userWallet,
|
|
1600
|
-
description:
|
|
1621
|
+
description: 'Close Orca Position',
|
|
1601
1622
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
1602
1623
|
mainInstructions,
|
|
1603
1624
|
});
|
|
@@ -1620,7 +1641,8 @@ class Transactions {
|
|
|
1620
1641
|
let positionData;
|
|
1621
1642
|
if (params.mintOrPosition.position !== undefined) {
|
|
1622
1643
|
position = params.mintOrPosition.position;
|
|
1623
|
-
positionData =
|
|
1644
|
+
positionData =
|
|
1645
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1624
1646
|
positionMint = positionData.positionMint;
|
|
1625
1647
|
}
|
|
1626
1648
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1628,7 +1650,7 @@ class Transactions {
|
|
|
1628
1650
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1629
1651
|
}
|
|
1630
1652
|
else {
|
|
1631
|
-
throw new Error(
|
|
1653
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1632
1654
|
}
|
|
1633
1655
|
const positionTokenAccount = this.orcaPda.generatePositionTokenAccount(userPda, positionMint, params.is2022Position || false);
|
|
1634
1656
|
if (params.newPosition) {
|
|
@@ -1640,7 +1662,8 @@ class Transactions {
|
|
|
1640
1662
|
};
|
|
1641
1663
|
}
|
|
1642
1664
|
else {
|
|
1643
|
-
positionData =
|
|
1665
|
+
positionData =
|
|
1666
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1644
1667
|
}
|
|
1645
1668
|
if (positionData === null) {
|
|
1646
1669
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1658,7 +1681,7 @@ class Transactions {
|
|
|
1658
1681
|
const tokenKey = result.tokenKey;
|
|
1659
1682
|
const token = tokenSeeds[index];
|
|
1660
1683
|
if (!result.exists &&
|
|
1661
|
-
`${token.mint}` !==
|
|
1684
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1662
1685
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1663
1686
|
}
|
|
1664
1687
|
});
|
|
@@ -1777,7 +1800,8 @@ class Transactions {
|
|
|
1777
1800
|
let positionData;
|
|
1778
1801
|
if (params.mintOrPosition.position !== undefined) {
|
|
1779
1802
|
position = params.mintOrPosition.position;
|
|
1780
|
-
positionData =
|
|
1803
|
+
positionData =
|
|
1804
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1781
1805
|
positionMint = positionData.positionMint;
|
|
1782
1806
|
}
|
|
1783
1807
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1785,7 +1809,7 @@ class Transactions {
|
|
|
1785
1809
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1786
1810
|
}
|
|
1787
1811
|
else {
|
|
1788
|
-
throw new Error(
|
|
1812
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1789
1813
|
}
|
|
1790
1814
|
const positionTokenAccount = (0, functions_1.generateAta)(userPda, positionMint);
|
|
1791
1815
|
if (params.newPosition) {
|
|
@@ -1797,7 +1821,8 @@ class Transactions {
|
|
|
1797
1821
|
};
|
|
1798
1822
|
}
|
|
1799
1823
|
else {
|
|
1800
|
-
positionData =
|
|
1824
|
+
positionData =
|
|
1825
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1801
1826
|
}
|
|
1802
1827
|
if (positionData === null) {
|
|
1803
1828
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1815,7 +1840,7 @@ class Transactions {
|
|
|
1815
1840
|
const tokenKey = result.tokenKey;
|
|
1816
1841
|
const token = tokenSeeds[index];
|
|
1817
1842
|
if (!result.exists &&
|
|
1818
|
-
`${token.mint}` !==
|
|
1843
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1819
1844
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1820
1845
|
}
|
|
1821
1846
|
});
|
|
@@ -1929,7 +1954,8 @@ class Transactions {
|
|
|
1929
1954
|
let positionData;
|
|
1930
1955
|
if (params.mintOrPosition.position !== undefined) {
|
|
1931
1956
|
position = params.mintOrPosition.position;
|
|
1932
|
-
positionData =
|
|
1957
|
+
positionData =
|
|
1958
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1933
1959
|
positionMint = positionData.positionMint;
|
|
1934
1960
|
}
|
|
1935
1961
|
else if (params.mintOrPosition.positionMint !== undefined) {
|
|
@@ -1937,7 +1963,7 @@ class Transactions {
|
|
|
1937
1963
|
position = (0, functions_1.generateOrcaPositionPDA)(positionMint);
|
|
1938
1964
|
}
|
|
1939
1965
|
else {
|
|
1940
|
-
throw new Error(
|
|
1966
|
+
throw new Error('Position mint or orca position needs to be provided.');
|
|
1941
1967
|
}
|
|
1942
1968
|
const positionTokenAccount = this.orcaPda.generatePositionTokenAccount(userPda, positionMint, params.is2022Position || false);
|
|
1943
1969
|
if (params.newPosition) {
|
|
@@ -1949,7 +1975,8 @@ class Transactions {
|
|
|
1949
1975
|
};
|
|
1950
1976
|
}
|
|
1951
1977
|
else {
|
|
1952
|
-
positionData =
|
|
1978
|
+
positionData =
|
|
1979
|
+
yield anchor_1.Anchor.instance().orcaProgram.account.position.fetch(position);
|
|
1953
1980
|
}
|
|
1954
1981
|
if (positionData === null) {
|
|
1955
1982
|
throw new Error(`Position: ${position} does not exist or already closed. Position mint: ${positionMint}`);
|
|
@@ -1967,7 +1994,7 @@ class Transactions {
|
|
|
1967
1994
|
const tokenKey = result.tokenKey;
|
|
1968
1995
|
const token = tokenSeeds[index];
|
|
1969
1996
|
if (!result.exists &&
|
|
1970
|
-
`${token.mint}` !==
|
|
1997
|
+
`${token.mint}` !== 'So11111111111111111111111111111111111111112') {
|
|
1971
1998
|
throw new Error(`Token: ${tokenKey} owned by ${token.owner} does not exist. Mint: ${token.mint}`);
|
|
1972
1999
|
}
|
|
1973
2000
|
});
|
|
@@ -1977,7 +2004,7 @@ class Transactions {
|
|
|
1977
2004
|
const { publicKey: tickArrayUpper } = (0, orca_1.getTickArrayFromTickIndex)(positionData.tickUpperIndex, whirlpoolData.tickSpacing, whirlpool, addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
1978
2005
|
const ownerFeeA = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintA);
|
|
1979
2006
|
const ownerFeeB = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mintB);
|
|
1980
|
-
const [oracle] = web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode(
|
|
2007
|
+
const [oracle] = web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('oracle'), whirlpool.toBuffer()], addresses_1.ORCA_WHIRLPOOL_PROGRAM);
|
|
1981
2008
|
// TODO: Derive based on amountToSwap calculation
|
|
1982
2009
|
let aToB = params.aToB;
|
|
1983
2010
|
const tickArrays = whirlpools_sdk_1.SwapUtils.getTickArrayPublicKeys(whirlpoolData.tickCurrentIndex, whirlpoolData.tickSpacing, aToB, addresses_1.ORCA_WHIRLPOOL_PROGRAM, whirlpool);
|
|
@@ -2442,11 +2469,11 @@ class Transactions {
|
|
|
2442
2469
|
});
|
|
2443
2470
|
}
|
|
2444
2471
|
}
|
|
2445
|
-
const result = yield (0, functions_1.tokenAccountExists)(connection, rewardMints.map(
|
|
2472
|
+
const result = yield (0, functions_1.tokenAccountExists)(connection, rewardMints.map(mint => {
|
|
2446
2473
|
return { owner: userPda, mint, isSta: false };
|
|
2447
2474
|
}));
|
|
2448
2475
|
const initRewardATA = result
|
|
2449
|
-
.map(
|
|
2476
|
+
.map(result => {
|
|
2450
2477
|
if (!result.exists) {
|
|
2451
2478
|
return (0, spl_token_1.createAssociatedTokenAccountInstruction)(params.userWallet, result.tokenKey, userPda, result.mint, addresses_1.TOKEN_PROGRAM_ID, addresses_1.ASSOCIATED_TOKEN_PROGRAM);
|
|
2452
2479
|
}
|
|
@@ -2454,7 +2481,7 @@ class Transactions {
|
|
|
2454
2481
|
return null;
|
|
2455
2482
|
}
|
|
2456
2483
|
})
|
|
2457
|
-
.filter(
|
|
2484
|
+
.filter(result => result !== null);
|
|
2458
2485
|
whirlpoolData.rewardInfos[0].mint;
|
|
2459
2486
|
// @ts-ignore
|
|
2460
2487
|
const extensionIx = yield anchor_1.Anchor.instance()
|
|
@@ -2534,8 +2561,12 @@ class Transactions {
|
|
|
2534
2561
|
// Get the pool keys (for lookup table account)
|
|
2535
2562
|
(0, functions_1.benchmark)({ name: `raydiumOpenPosition`, msg: `sdk.clmm.getClmmPoolKeys` });
|
|
2536
2563
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(params.poolState.toString());
|
|
2537
|
-
(0, functions_1.benchmark)({
|
|
2538
|
-
|
|
2564
|
+
(0, functions_1.benchmark)({
|
|
2565
|
+
name: `raydiumOpenPosition`,
|
|
2566
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2567
|
+
end: true,
|
|
2568
|
+
});
|
|
2569
|
+
console.log('pool lookup table account:', poolKeys.lookupTableAccount);
|
|
2539
2570
|
const addressLookupTableAddresses = [];
|
|
2540
2571
|
if (poolKeys.lookupTableAccount) {
|
|
2541
2572
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2550,7 +2581,7 @@ class Transactions {
|
|
|
2550
2581
|
2846640 + // 281 - personal position
|
|
2551
2582
|
2296800 + // 202 - position nft mint
|
|
2552
2583
|
2074080; // 170 - position nft account
|
|
2553
|
-
console.log(
|
|
2584
|
+
console.log('SOL to send to pda lamport: ', lamports / 1000000000);
|
|
2554
2585
|
// Lamports needed for opening a position
|
|
2555
2586
|
const lamportIx = web3.SystemProgram.transfer({
|
|
2556
2587
|
fromPubkey: params.userWallet,
|
|
@@ -2564,7 +2595,7 @@ class Transactions {
|
|
|
2564
2595
|
const amountY = params.amountY
|
|
2565
2596
|
.mul(new bn_js_1.default(10000).sub(slippage))
|
|
2566
2597
|
.div(new bn_js_1.default(10000));
|
|
2567
|
-
const { liquidity, amount0Max, amount1Max
|
|
2598
|
+
const { liquidity, amount0Max, amount1Max } = yield (0, RaydiumIxGenerator_1.getLiquidityFromAmounts)(connection, params.poolState, amountX, amountY, params.tickLowerIndex, params.tickUpperIndex, params.slippage, true);
|
|
2568
2599
|
const wrapIxs = (0, functions_1.wrapSolIfMintIsWsol)(params.userWallet, params.userWallet, [
|
|
2569
2600
|
{ mint: tokenMint0, amount: amount0Max },
|
|
2570
2601
|
{ mint: tokenMint1, amount: amount1Max },
|
|
@@ -2597,7 +2628,7 @@ class Transactions {
|
|
|
2597
2628
|
});
|
|
2598
2629
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2599
2630
|
tokenMint0,
|
|
2600
|
-
tokenMint1
|
|
2631
|
+
tokenMint1,
|
|
2601
2632
|
]);
|
|
2602
2633
|
const mainInstructions = [
|
|
2603
2634
|
lamportIx,
|
|
@@ -2611,7 +2642,10 @@ class Transactions {
|
|
|
2611
2642
|
return yield (0, functions_1.createTransactionMeta)({
|
|
2612
2643
|
payer: params.userWallet,
|
|
2613
2644
|
description: `Open Raydium Position`,
|
|
2614
|
-
addressLookupTableAddresses: [
|
|
2645
|
+
addressLookupTableAddresses: [
|
|
2646
|
+
...addresses_1.GLOBAL_ALT,
|
|
2647
|
+
...addressLookupTableAddresses,
|
|
2648
|
+
],
|
|
2615
2649
|
mainInstructions,
|
|
2616
2650
|
});
|
|
2617
2651
|
});
|
|
@@ -2634,10 +2668,17 @@ class Transactions {
|
|
|
2634
2668
|
// Get the Raydium SDK instance
|
|
2635
2669
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2636
2670
|
// Get the pool keys (for lookup table account)
|
|
2637
|
-
(0, functions_1.benchmark)({
|
|
2671
|
+
(0, functions_1.benchmark)({
|
|
2672
|
+
name: `raydiumWithdrawAndClosePosition`,
|
|
2673
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2674
|
+
});
|
|
2638
2675
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2639
|
-
(0, functions_1.benchmark)({
|
|
2640
|
-
|
|
2676
|
+
(0, functions_1.benchmark)({
|
|
2677
|
+
name: `raydiumWithdrawAndClosePosition`,
|
|
2678
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2679
|
+
end: true,
|
|
2680
|
+
});
|
|
2681
|
+
console.log('pool lookup table account:', poolKeys.lookupTableAccount);
|
|
2641
2682
|
const addressLookupTableAddresses = [];
|
|
2642
2683
|
if (poolKeys.lookupTableAccount) {
|
|
2643
2684
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2648,18 +2689,22 @@ class Transactions {
|
|
|
2648
2689
|
{ mint: fetch.poolStateInfo.tokenMint0 },
|
|
2649
2690
|
{ mint: fetch.poolStateInfo.tokenMint1 },
|
|
2650
2691
|
...fetch.poolStateInfo.rewardInfos
|
|
2651
|
-
.filter(
|
|
2652
|
-
.map(
|
|
2692
|
+
.filter(v => !v.tokenMint.equals(web3.SystemProgram.programId))
|
|
2693
|
+
.map(v => {
|
|
2653
2694
|
return { mint: v.tokenMint };
|
|
2654
2695
|
}),
|
|
2655
2696
|
],
|
|
2656
2697
|
});
|
|
2657
|
-
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2658
|
-
|
|
2698
|
+
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2699
|
+
.map(v => v.tokenMint.toString())
|
|
2700
|
+
.filter(v => v !== web3.SystemProgram.programId.toString());
|
|
2701
|
+
const mints = [
|
|
2702
|
+
...new Set([
|
|
2659
2703
|
...rewards,
|
|
2660
2704
|
fetch.poolStateInfo.tokenMint0.toString(),
|
|
2661
2705
|
fetch.poolStateInfo.tokenMint1.toString(),
|
|
2662
|
-
])
|
|
2706
|
+
]),
|
|
2707
|
+
].map(v => new web3.PublicKey(v));
|
|
2663
2708
|
const nftOwner = (0, functions_1.generateUserPdaLamport)(params.userWallet);
|
|
2664
2709
|
const initAtaIxs = mints.map(v => {
|
|
2665
2710
|
const payer = params.userWallet;
|
|
@@ -2669,7 +2714,7 @@ class Transactions {
|
|
|
2669
2714
|
});
|
|
2670
2715
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2671
2716
|
fetch.poolStateInfo.tokenMint0,
|
|
2672
|
-
fetch.poolStateInfo.tokenMint1
|
|
2717
|
+
fetch.poolStateInfo.tokenMint1,
|
|
2673
2718
|
]);
|
|
2674
2719
|
const raydiumDecreaseLiquidityIxViaHawksight = yield this.ix.raydium.raydiumDecreaseLiquidity({
|
|
2675
2720
|
connection,
|
|
@@ -2694,7 +2739,10 @@ class Transactions {
|
|
|
2694
2739
|
return (0, functions_1.createTransactionMeta)({
|
|
2695
2740
|
payer: params.userWallet,
|
|
2696
2741
|
description: `Close Raydium Position`,
|
|
2697
|
-
addressLookupTableAddresses: [
|
|
2742
|
+
addressLookupTableAddresses: [
|
|
2743
|
+
...addresses_1.GLOBAL_ALT,
|
|
2744
|
+
...addressLookupTableAddresses,
|
|
2745
|
+
],
|
|
2698
2746
|
mainInstructions,
|
|
2699
2747
|
});
|
|
2700
2748
|
}
|
|
@@ -2710,7 +2758,10 @@ class Transactions {
|
|
|
2710
2758
|
return (0, functions_1.createTransactionMeta)({
|
|
2711
2759
|
payer: params.userWallet,
|
|
2712
2760
|
description: `Withdraw and close Raydium Position`,
|
|
2713
|
-
addressLookupTableAddresses: [
|
|
2761
|
+
addressLookupTableAddresses: [
|
|
2762
|
+
...addresses_1.GLOBAL_ALT,
|
|
2763
|
+
...addressLookupTableAddresses,
|
|
2764
|
+
],
|
|
2714
2765
|
mainInstructions,
|
|
2715
2766
|
});
|
|
2716
2767
|
}
|
|
@@ -2764,10 +2815,17 @@ class Transactions {
|
|
|
2764
2815
|
// Get the Raydium SDK instance
|
|
2765
2816
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2766
2817
|
// Get the pool keys (for lookup table account)
|
|
2767
|
-
(0, functions_1.benchmark)({
|
|
2818
|
+
(0, functions_1.benchmark)({
|
|
2819
|
+
name: `raydiumIncreaseLiquidity`,
|
|
2820
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2821
|
+
});
|
|
2768
2822
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2769
|
-
(0, functions_1.benchmark)({
|
|
2770
|
-
|
|
2823
|
+
(0, functions_1.benchmark)({
|
|
2824
|
+
name: `raydiumIncreaseLiquidity`,
|
|
2825
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2826
|
+
end: true,
|
|
2827
|
+
});
|
|
2828
|
+
console.log('pool lookup table account:', poolKeys.lookupTableAccount);
|
|
2771
2829
|
const addressLookupTableAddresses = [];
|
|
2772
2830
|
if (poolKeys.lookupTableAccount) {
|
|
2773
2831
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2779,14 +2837,14 @@ class Transactions {
|
|
|
2779
2837
|
const amountY = params.amountY
|
|
2780
2838
|
.mul(new bn_js_1.default(10000).sub(slippage))
|
|
2781
2839
|
.div(new bn_js_1.default(10000));
|
|
2782
|
-
const { liquidity, amount0Max, amount1Max
|
|
2840
|
+
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
2841
|
const wrapIxs = (0, functions_1.wrapSolIfMintIsWsol)(params.userWallet, params.userWallet, [
|
|
2784
2842
|
{ mint: tokenMint0, amount: amount0Max },
|
|
2785
2843
|
{ mint: tokenMint1, amount: amount1Max },
|
|
2786
2844
|
]);
|
|
2787
2845
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2788
2846
|
tokenMint0,
|
|
2789
|
-
tokenMint1
|
|
2847
|
+
tokenMint1,
|
|
2790
2848
|
]);
|
|
2791
2849
|
const depositIx = yield this.ix.iyfMain.depositMultipleLamportPdaToken({
|
|
2792
2850
|
userWallet: params.userWallet,
|
|
@@ -2820,7 +2878,10 @@ class Transactions {
|
|
|
2820
2878
|
return (0, functions_1.createTransactionMeta)({
|
|
2821
2879
|
payer: params.userWallet,
|
|
2822
2880
|
description: `Raydium increase liquidity`,
|
|
2823
|
-
addressLookupTableAddresses: [
|
|
2881
|
+
addressLookupTableAddresses: [
|
|
2882
|
+
...addresses_1.GLOBAL_ALT,
|
|
2883
|
+
...addressLookupTableAddresses,
|
|
2884
|
+
],
|
|
2824
2885
|
mainInstructions,
|
|
2825
2886
|
});
|
|
2826
2887
|
});
|
|
@@ -2842,10 +2903,17 @@ class Transactions {
|
|
|
2842
2903
|
// Get the Raydium SDK instance
|
|
2843
2904
|
const sdk = (0, RaydiumSDK_1.raydium)();
|
|
2844
2905
|
// Get the pool keys (for lookup table account)
|
|
2845
|
-
(0, functions_1.benchmark)({
|
|
2906
|
+
(0, functions_1.benchmark)({
|
|
2907
|
+
name: `raydiumDecreaseLiquidity`,
|
|
2908
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2909
|
+
});
|
|
2846
2910
|
const poolKeys = yield sdk.clmm.getClmmPoolKeys(fetch.positionInfo.poolId.toString());
|
|
2847
|
-
(0, functions_1.benchmark)({
|
|
2848
|
-
|
|
2911
|
+
(0, functions_1.benchmark)({
|
|
2912
|
+
name: `raydiumDecreaseLiquidity`,
|
|
2913
|
+
msg: `sdk.clmm.getClmmPoolKeys`,
|
|
2914
|
+
end: true,
|
|
2915
|
+
});
|
|
2916
|
+
console.log('pool lookup table account:', poolKeys.lookupTableAccount);
|
|
2849
2917
|
const addressLookupTableAddresses = [];
|
|
2850
2918
|
if (poolKeys.lookupTableAccount) {
|
|
2851
2919
|
addressLookupTableAddresses.push(poolKeys.lookupTableAccount);
|
|
@@ -2856,18 +2924,22 @@ class Transactions {
|
|
|
2856
2924
|
{ mint: fetch.poolStateInfo.tokenMint0 },
|
|
2857
2925
|
{ mint: fetch.poolStateInfo.tokenMint1 },
|
|
2858
2926
|
...fetch.poolStateInfo.rewardInfos
|
|
2859
|
-
.filter(
|
|
2860
|
-
.map(
|
|
2927
|
+
.filter(v => !v.tokenMint.equals(web3.SystemProgram.programId))
|
|
2928
|
+
.map(v => {
|
|
2861
2929
|
return { mint: v.tokenMint };
|
|
2862
2930
|
}),
|
|
2863
2931
|
],
|
|
2864
2932
|
});
|
|
2865
|
-
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2866
|
-
|
|
2933
|
+
const rewards = fetch.poolStateInfo.rewardInfos
|
|
2934
|
+
.map(v => v.tokenMint.toString())
|
|
2935
|
+
.filter(v => v !== web3.SystemProgram.programId.toString());
|
|
2936
|
+
const mints = [
|
|
2937
|
+
...new Set([
|
|
2867
2938
|
...rewards,
|
|
2868
2939
|
fetch.poolStateInfo.tokenMint0.toString(),
|
|
2869
2940
|
fetch.poolStateInfo.tokenMint1.toString(),
|
|
2870
|
-
])
|
|
2941
|
+
]),
|
|
2942
|
+
].map(v => new web3.PublicKey(v));
|
|
2871
2943
|
const nftOwner = (0, functions_1.generateUserPdaLamport)(params.userWallet);
|
|
2872
2944
|
const initAtaIxs = mints.map(v => {
|
|
2873
2945
|
const payer = params.userWallet;
|
|
@@ -2877,7 +2949,7 @@ class Transactions {
|
|
|
2877
2949
|
});
|
|
2878
2950
|
const unwrapSolIx = (0, functions_1.unwrapSolIfMintIsWsol)(params.userWallet, [
|
|
2879
2951
|
fetch.poolStateInfo.tokenMint0,
|
|
2880
|
-
fetch.poolStateInfo.tokenMint1
|
|
2952
|
+
fetch.poolStateInfo.tokenMint1,
|
|
2881
2953
|
]);
|
|
2882
2954
|
const raydiumDecreaseLiquidityIxViaHawksight = yield this.ix.raydium.raydiumDecreaseLiquidity({
|
|
2883
2955
|
connection,
|
|
@@ -2893,7 +2965,10 @@ class Transactions {
|
|
|
2893
2965
|
return (0, functions_1.createTransactionMeta)({
|
|
2894
2966
|
payer: params.userWallet,
|
|
2895
2967
|
description: `Raydium decrease liquidity`,
|
|
2896
|
-
addressLookupTableAddresses: [
|
|
2968
|
+
addressLookupTableAddresses: [
|
|
2969
|
+
...addresses_1.GLOBAL_ALT,
|
|
2970
|
+
...addressLookupTableAddresses,
|
|
2971
|
+
],
|
|
2897
2972
|
mainInstructions,
|
|
2898
2973
|
});
|
|
2899
2974
|
});
|