@hawksightco/hawk-sdk 1.2.120 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/addresses.d.ts +1 -0
- package/dist/src/addresses.d.ts.map +1 -1
- package/dist/src/addresses.js +2 -1
- package/dist/src/anchor.d.ts +2 -112
- package/dist/src/anchor.d.ts.map +1 -1
- package/dist/src/anchor.js +21 -3
- package/dist/src/classes/HawkAPI.d.ts +8 -0
- package/dist/src/classes/HawkAPI.d.ts.map +1 -1
- package/dist/src/classes/HawkAPI.js +10 -0
- package/dist/src/classes/Transactions.d.ts.map +1 -1
- package/dist/src/classes/Transactions.js +65 -43
- package/dist/src/classes/TxGenerator.d.ts.map +1 -1
- package/dist/src/classes/TxGenerator.js +5 -0
- package/dist/src/classes/account-cache/AccountCache.d.ts +41 -0
- package/dist/src/classes/account-cache/AccountCache.d.ts.map +1 -0
- package/dist/src/classes/account-cache/AccountCache.js +78 -0
- package/dist/src/classes/account-cache/MintCache.d.ts +33 -0
- package/dist/src/classes/account-cache/MintCache.d.ts.map +1 -0
- package/dist/src/classes/account-cache/MintCache.js +47 -0
- package/dist/src/functions.d.ts +17 -1
- package/dist/src/functions.d.ts.map +1 -1
- package/dist/src/functions.js +90 -16
- package/dist/src/hawksight.d.ts +5 -0
- package/dist/src/hawksight.d.ts.map +1 -1
- package/dist/src/hawksight.js +43 -18
- package/dist/src/idl/iyf-extension-idl.d.ts +0 -45
- package/dist/src/idl/iyf-extension-idl.d.ts.map +1 -1
- package/dist/src/idl/iyf-extension-idl.js +45 -90
- package/dist/src/idl/iyf-extension-wrapper.d.ts +112 -0
- package/dist/src/idl/iyf-extension-wrapper.d.ts.map +1 -0
- package/dist/src/idl/iyf-extension-wrapper.js +2 -0
- package/dist/src/idl/iyf-main-idl.d.ts +7275 -5865
- package/dist/src/idl/iyf-main-idl.d.ts.map +1 -1
- package/dist/src/idl/iyf-main-idl.js +7449 -6045
- package/dist/src/idl/iyf-main-wrapper.d.ts +112 -0
- package/dist/src/idl/iyf-main-wrapper.d.ts.map +1 -0
- package/dist/src/idl/iyf-main-wrapper.js +2 -0
- package/dist/src/ixGenerator/IyfMainIxGenerator.d.ts +30 -12
- package/dist/src/ixGenerator/IyfMainIxGenerator.d.ts.map +1 -1
- package/dist/src/ixGenerator/IyfMainIxGenerator.js +184 -46
- package/dist/src/meteora.d.ts +6 -5
- package/dist/src/meteora.d.ts.map +1 -1
- package/dist/src/meteora.js +30 -18
- package/dist/src/pdaGenerator/HawksightPdaGenerator.d.ts.map +1 -1
- package/dist/src/types.d.ts +3 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -46,7 +46,6 @@ const orca_1 = require("../orca");
|
|
|
46
46
|
const hsToMeteora_1 = require("../hsToMeteora");
|
|
47
47
|
const meteora_1 = require("../meteora");
|
|
48
48
|
const anchor_1 = require("../anchor");
|
|
49
|
-
const hawksight_1 = require("../hawksight");
|
|
50
49
|
const types_2 = require("../types");
|
|
51
50
|
const Logging_1 = require("./Logging");
|
|
52
51
|
const TransactionBatchExecute2_1 = require("./TransactionBatchExecute2");
|
|
@@ -120,6 +119,7 @@ class Transactions {
|
|
|
120
119
|
description: "Register User",
|
|
121
120
|
addressLookupTableAddresses: addresses_1.GLOBAL_ALT,
|
|
122
121
|
mainInstructions: [
|
|
122
|
+
// @ts-ignore
|
|
123
123
|
yield anchor_1.Anchor.instance()
|
|
124
124
|
.iyfMain.methods.newUser()
|
|
125
125
|
.accounts({
|
|
@@ -192,9 +192,9 @@ class Transactions {
|
|
|
192
192
|
*/
|
|
193
193
|
meteoraCreatePositionAndDeposit(_a) {
|
|
194
194
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
195
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(params.pool));
|
|
195
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(params.pool), this.ix);
|
|
196
196
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
197
|
-
const mainInstructions = (yield dlmmPool.initializePositionAndAddLiquidityByStrategy(params.userWallet, params.userWallet, {
|
|
197
|
+
const mainInstructions = (yield dlmmPool.initializePositionAndAddLiquidityByStrategy(connection, params.userWallet, params.userWallet, {
|
|
198
198
|
positionPubKey: params.position,
|
|
199
199
|
user: userPda,
|
|
200
200
|
totalXAmount: params.totalXAmount,
|
|
@@ -228,7 +228,7 @@ class Transactions {
|
|
|
228
228
|
*/
|
|
229
229
|
meteoraCreatePositionAndDepositPda(_a) {
|
|
230
230
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
231
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(params.pool));
|
|
231
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(params.pool), this.ix);
|
|
232
232
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
233
233
|
const mainInstructions = (yield dlmmPool.initializePositionAndAddLiquidityByStrategyPda(params.userWallet, params.userWallet, {
|
|
234
234
|
positionPubKey: params.position,
|
|
@@ -263,7 +263,7 @@ class Transactions {
|
|
|
263
263
|
meteoraInitializeBinArrays(_a) {
|
|
264
264
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
265
265
|
const poolAddress = new web3.PublicKey(params.pool);
|
|
266
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, poolAddress);
|
|
266
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, poolAddress, this.ix);
|
|
267
267
|
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);
|
|
268
268
|
const mainInstructions = yield dlmmPool.dlmm.initializeBinArrays(binArraysRequired.map((b) => b.index), new web3.PublicKey(params.userWallet));
|
|
269
269
|
return (0, functions_1.createTransactionMeta)({
|
|
@@ -297,9 +297,9 @@ class Transactions {
|
|
|
297
297
|
maxBinId = position.upperBinId;
|
|
298
298
|
minBinId = position.lowerBinId;
|
|
299
299
|
}
|
|
300
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(lbPair));
|
|
300
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, new web3.PublicKey(lbPair), this.ix);
|
|
301
301
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
302
|
-
const mainInstructions = (yield dlmmPool.addLiquidityByStrategy(params.userWallet, params.userWallet, {
|
|
302
|
+
const mainInstructions = (yield dlmmPool.addLiquidityByStrategy(connection, params.userWallet, params.userWallet, {
|
|
303
303
|
positionPubKey: params.position,
|
|
304
304
|
user: userPda,
|
|
305
305
|
totalXAmount: params.totalXAmount,
|
|
@@ -341,7 +341,7 @@ class Transactions {
|
|
|
341
341
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
342
342
|
lbPair = position.lbPair;
|
|
343
343
|
}
|
|
344
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair);
|
|
344
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
|
|
345
345
|
if (params.fastGeneration === undefined) {
|
|
346
346
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
347
347
|
const userPosition = userPositions.find((userPosition) => userPosition.publicKey.toString() === params.position.toString());
|
|
@@ -356,7 +356,7 @@ class Transactions {
|
|
|
356
356
|
const amountBps = params.shouldClaimAndClose
|
|
357
357
|
? new bn_js_1.default(10000)
|
|
358
358
|
: params.amountBps;
|
|
359
|
-
const mainInstructions = (yield dlmmPool.removeLiquidity(params.userWallet, params.userWallet, {
|
|
359
|
+
const mainInstructions = (yield dlmmPool.removeLiquidity(connection, params.userWallet, params.userWallet, {
|
|
360
360
|
user: userPda,
|
|
361
361
|
position: params.position,
|
|
362
362
|
binIds: binIdsToRemove,
|
|
@@ -404,7 +404,7 @@ class Transactions {
|
|
|
404
404
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
405
405
|
lbPair = position.lbPair;
|
|
406
406
|
}
|
|
407
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair);
|
|
407
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, lbPair, this.ix);
|
|
408
408
|
if (params.fastGeneration === undefined) {
|
|
409
409
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
410
410
|
const userPosition = userPositions.find((userPosition) => userPosition.publicKey.toString() === params.position.toString());
|
|
@@ -532,7 +532,7 @@ class Transactions {
|
|
|
532
532
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
533
533
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
534
534
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
535
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
535
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
536
536
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
537
537
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
538
538
|
const index = userPositions.findIndex((v) => v.publicKey.equals(params.position));
|
|
@@ -582,12 +582,14 @@ class Transactions {
|
|
|
582
582
|
}
|
|
583
583
|
if (result[2].exists) {
|
|
584
584
|
mainInstructions.push(yield this.ix.iyfMain.withdrawTokenFromUserPda({
|
|
585
|
+
connection,
|
|
585
586
|
userWallet: params.userWallet,
|
|
586
587
|
mint: params.mint,
|
|
587
588
|
useSta: true,
|
|
588
589
|
}));
|
|
589
590
|
}
|
|
590
591
|
mainInstructions.push(yield this.ix.iyfMain.withdrawTokenFromUserPda({
|
|
592
|
+
connection,
|
|
591
593
|
userWallet: params.userWallet,
|
|
592
594
|
mint: params.mint,
|
|
593
595
|
}));
|
|
@@ -625,12 +627,14 @@ class Transactions {
|
|
|
625
627
|
}));
|
|
626
628
|
}
|
|
627
629
|
});
|
|
628
|
-
mainInstructions.push(yield this.ix.iyfMain.
|
|
630
|
+
mainInstructions.push(yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
631
|
+
connection,
|
|
629
632
|
payer: params.userWallet,
|
|
630
633
|
withdraw: params.mints.map((mint) => {
|
|
631
|
-
return { mint };
|
|
634
|
+
return { mint, amount: new bn_js_1.default(0) };
|
|
632
635
|
}),
|
|
633
|
-
|
|
636
|
+
pdaTokenType: types_1.TokenType.STA,
|
|
637
|
+
hasAmount: false,
|
|
634
638
|
}));
|
|
635
639
|
return (0, functions_1.createTransactionMeta)({
|
|
636
640
|
payer: params.userWallet,
|
|
@@ -644,7 +648,7 @@ class Transactions {
|
|
|
644
648
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
645
649
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
646
650
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
647
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
651
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
648
652
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
649
653
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
650
654
|
const userPosition = userPositions.find((userPosition) => userPosition.publicKey.equals(params.position));
|
|
@@ -660,7 +664,7 @@ class Transactions {
|
|
|
660
664
|
pdaTokenType: types_1.TokenType.ATA,
|
|
661
665
|
}, hsToMeteora_1.meteoraToHawksightAutomationIxs);
|
|
662
666
|
// Re-deposit fees (TODO: How to re-deposit reward tokens that is not X or Y token?)
|
|
663
|
-
const addLiquidityBuilder = yield dlmmPool.addLiquidityByStrategy(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
667
|
+
const addLiquidityBuilder = yield dlmmPool.addLiquidityByStrategy(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
664
668
|
positionPubKey: params.position,
|
|
665
669
|
user: userPda,
|
|
666
670
|
totalXAmount: new bn_js_1.default(100000), // This is overriden on-chain, so value here do not matter
|
|
@@ -692,7 +696,7 @@ class Transactions {
|
|
|
692
696
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
693
697
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
694
698
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
695
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
699
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
696
700
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
697
701
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
698
702
|
const userPosition = userPositions.find((userPosition) => userPosition.publicKey.equals(params.position));
|
|
@@ -722,7 +726,7 @@ class Transactions {
|
|
|
722
726
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
723
727
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
724
728
|
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
725
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
729
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
726
730
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
727
731
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
728
732
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
@@ -731,7 +735,7 @@ class Transactions {
|
|
|
731
735
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
732
736
|
}
|
|
733
737
|
const binIdsToRemove = userPosition.positionData.positionBinData.map((bin) => bin.binId);
|
|
734
|
-
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
738
|
+
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
735
739
|
user: userPda,
|
|
736
740
|
position: params.currentPosition,
|
|
737
741
|
binIds: binIdsToRemove,
|
|
@@ -747,7 +751,7 @@ class Transactions {
|
|
|
747
751
|
removeLiquidityBuilder.replaceClaimRewardToSTA();
|
|
748
752
|
}
|
|
749
753
|
// Re-deposit fees (TODO: How to re-deposit reward tokens that is not X or Y token?)
|
|
750
|
-
const initPositionAndAddLiquidityBuilder = yield dlmmPool.initializePositionAndAddLiquidityByStrategy(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
754
|
+
const initPositionAndAddLiquidityBuilder = yield dlmmPool.initializePositionAndAddLiquidityByStrategy(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
751
755
|
positionPubKey: params.newPosition,
|
|
752
756
|
user: userPda,
|
|
753
757
|
totalXAmount: new bn_js_1.default(100000), // This is overriden on-chain, so value here do not matter
|
|
@@ -779,7 +783,7 @@ class Transactions {
|
|
|
779
783
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
780
784
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
781
785
|
const position = yield program.account.positionV2.fetch(params.currentPosition);
|
|
782
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
786
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
783
787
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
784
788
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
785
789
|
const { userPositions } = yield dlmmPool.getPositionsByUserAndLbPair(userPda);
|
|
@@ -788,7 +792,7 @@ class Transactions {
|
|
|
788
792
|
throw new Error(`Position: ${params.currentPosition} does not exist.`);
|
|
789
793
|
}
|
|
790
794
|
const binIdsToRemove = userPosition.positionData.positionBinData.map((bin) => bin.binId);
|
|
791
|
-
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
795
|
+
const removeLiquidityBuilder = yield dlmmPool.removeLiquidity(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
792
796
|
user: userPda,
|
|
793
797
|
position: params.currentPosition,
|
|
794
798
|
binIds: binIdsToRemove,
|
|
@@ -837,10 +841,10 @@ class Transactions {
|
|
|
837
841
|
}
|
|
838
842
|
openAutomationIx(_a) {
|
|
839
843
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
840
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, params.pool);
|
|
844
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, params.pool, this.ix);
|
|
841
845
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
842
846
|
// Open new position
|
|
843
|
-
const initPositionAndAddLiquidityBuilder = yield dlmmPool.initializePositionAndAddLiquidityByStrategy(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
847
|
+
const initPositionAndAddLiquidityBuilder = yield dlmmPool.initializePositionAndAddLiquidityByStrategy(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
844
848
|
positionPubKey: params.position,
|
|
845
849
|
user: userPda,
|
|
846
850
|
slippage: params.slippage,
|
|
@@ -904,7 +908,7 @@ class Transactions {
|
|
|
904
908
|
}
|
|
905
909
|
let dlmmPool;
|
|
906
910
|
try {
|
|
907
|
-
dlmmPool = yield retryRpcCall(() => meteora_1.MeteoraDLMM.create(connection, position.lbPair), `Create DLMM pool for lbPair ${position.lbPair}`);
|
|
911
|
+
dlmmPool = yield retryRpcCall(() => meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix), `Create DLMM pool for lbPair ${position.lbPair}`);
|
|
908
912
|
}
|
|
909
913
|
catch (error) {
|
|
910
914
|
throw new Error(`Failed to create DLMM pool for lbPair ${position.lbPair}: ${error}`);
|
|
@@ -941,7 +945,7 @@ class Transactions {
|
|
|
941
945
|
}
|
|
942
946
|
let removeLiquidityBuilder;
|
|
943
947
|
try {
|
|
944
|
-
removeLiquidityBuilder = yield retryRpcCall(() => dlmmPool.removeLiquidity(params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
948
|
+
removeLiquidityBuilder = yield retryRpcCall(() => dlmmPool.removeLiquidity(connection, params.userWallet, addresses_1.HS_AUTHORITY, {
|
|
945
949
|
user: userPda,
|
|
946
950
|
position: params.position,
|
|
947
951
|
binIds: binIdsToRemove,
|
|
@@ -981,7 +985,7 @@ class Transactions {
|
|
|
981
985
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
982
986
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
983
987
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
984
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
988
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
985
989
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
986
990
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
987
991
|
// const { userPositions } = await dlmmPool.getPositionsByUserAndLbPair(
|
|
@@ -1060,6 +1064,7 @@ class Transactions {
|
|
|
1060
1064
|
})
|
|
1061
1065
|
.instruction();
|
|
1062
1066
|
// Instruction via main hawksight contract
|
|
1067
|
+
// @ts-ignore
|
|
1063
1068
|
ix = yield anchor_1.Anchor.instance()
|
|
1064
1069
|
.iyfMain.methods.iyfExtensionExecuteV2(limitCloseAutomationIx.data)
|
|
1065
1070
|
.accounts({
|
|
@@ -1147,7 +1152,7 @@ class Transactions {
|
|
|
1147
1152
|
return __awaiter(this, arguments, void 0, function* ({ connection, params, }) {
|
|
1148
1153
|
const program = yield meteora_1.MeteoraDLMM.program(connection);
|
|
1149
1154
|
const position = yield program.account.positionV2.fetch(params.position);
|
|
1150
|
-
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair);
|
|
1155
|
+
const dlmmPool = yield meteora_1.MeteoraDLMM.create(connection, position.lbPair, this.ix);
|
|
1151
1156
|
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
1152
1157
|
// Step 1: Claim all fees/rewards, remove all liquidity and close current position
|
|
1153
1158
|
// const { userPositions } = await dlmmPool.getPositionsByUserAndLbPair(
|
|
@@ -1532,18 +1537,14 @@ class Transactions {
|
|
|
1532
1537
|
{ mint: mintA, amount: params.totalXAmount },
|
|
1533
1538
|
{ mint: mintB, amount: params.totalYAmount },
|
|
1534
1539
|
]);
|
|
1535
|
-
const depositIx = yield
|
|
1540
|
+
const depositIx = yield this.ix.iyfMain.depositMultipleTokenWithToken2022({
|
|
1541
|
+
connection,
|
|
1536
1542
|
payer: params.userWallet,
|
|
1537
1543
|
deposit: [
|
|
1538
|
-
{
|
|
1539
|
-
|
|
1540
|
-
amount: params.totalXAmount,
|
|
1541
|
-
},
|
|
1542
|
-
{
|
|
1543
|
-
mint: mintB,
|
|
1544
|
-
amount: params.totalYAmount,
|
|
1545
|
-
},
|
|
1544
|
+
{ mint: mintA, amount: params.totalXAmount },
|
|
1545
|
+
{ mint: mintB, amount: params.totalYAmount },
|
|
1546
1546
|
],
|
|
1547
|
+
pdaTokenType: types_1.TokenType.ATA,
|
|
1547
1548
|
});
|
|
1548
1549
|
// @ts-ignore
|
|
1549
1550
|
const extensionIx = yield anchor_1.Anchor.instance()
|
|
@@ -1570,6 +1571,7 @@ class Transactions {
|
|
|
1570
1571
|
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
1571
1572
|
})
|
|
1572
1573
|
.instruction();
|
|
1574
|
+
// @ts-ignore
|
|
1573
1575
|
const orcaIx = yield anchor_1.Anchor.instance()
|
|
1574
1576
|
.iyfMain.methods.iyfExtensionExecute(extensionIx.data)
|
|
1575
1577
|
.accounts({
|
|
@@ -1597,9 +1599,15 @@ class Transactions {
|
|
|
1597
1599
|
extensionIx.keys[18],
|
|
1598
1600
|
])
|
|
1599
1601
|
.instruction();
|
|
1600
|
-
const clearRemainingTokensIxs = yield
|
|
1602
|
+
const clearRemainingTokensIxs = yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
1603
|
+
connection,
|
|
1601
1604
|
payer: params.userWallet,
|
|
1602
|
-
withdraw: [
|
|
1605
|
+
withdraw: [
|
|
1606
|
+
{ mint: mintA, amount: new bn_js_1.default(0) },
|
|
1607
|
+
{ mint: mintB, amount: new bn_js_1.default(0) },
|
|
1608
|
+
],
|
|
1609
|
+
pdaTokenType: types_1.TokenType.ATA,
|
|
1610
|
+
hasAmount: false,
|
|
1603
1611
|
});
|
|
1604
1612
|
orcaIx.keys[2].isSigner = true; // authority must be signer.
|
|
1605
1613
|
const mainInstructions = [
|
|
@@ -1991,6 +1999,7 @@ class Transactions {
|
|
|
1991
1999
|
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
1992
2000
|
})
|
|
1993
2001
|
.instruction();
|
|
2002
|
+
// @ts-ignore
|
|
1994
2003
|
const orcaIx = yield anchor_1.Anchor.instance()
|
|
1995
2004
|
.iyfMain.methods.iyfExtensionExecute(extensionIx.data)
|
|
1996
2005
|
.accounts({
|
|
@@ -2018,9 +2027,15 @@ class Transactions {
|
|
|
2018
2027
|
extensionIx.keys[18],
|
|
2019
2028
|
])
|
|
2020
2029
|
.instruction();
|
|
2021
|
-
const withdrawFromPda = yield
|
|
2030
|
+
const withdrawFromPda = yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
2031
|
+
connection,
|
|
2022
2032
|
payer: params.userWallet,
|
|
2023
|
-
withdraw: [
|
|
2033
|
+
withdraw: [
|
|
2034
|
+
{ mint: mintA, amount: new bn_js_1.default(0) },
|
|
2035
|
+
{ mint: mintB, amount: new bn_js_1.default(0) },
|
|
2036
|
+
],
|
|
2037
|
+
pdaTokenType: types_1.TokenType.ATA,
|
|
2038
|
+
hasAmount: false,
|
|
2024
2039
|
});
|
|
2025
2040
|
orcaIx.keys[2].isSigner = true; // authority must be signer.
|
|
2026
2041
|
const mainInstructions = [orcaIx, withdrawFromPda];
|
|
@@ -2330,6 +2345,7 @@ class Transactions {
|
|
|
2330
2345
|
})
|
|
2331
2346
|
.remainingAccounts(remainingAccounts)
|
|
2332
2347
|
.instruction();
|
|
2348
|
+
// @ts-ignore
|
|
2333
2349
|
const orcaIx = yield anchor_1.Anchor.instance()
|
|
2334
2350
|
.iyfMain.methods.iyfExtensionExecute(extensionIx.data)
|
|
2335
2351
|
.accounts({
|
|
@@ -2341,9 +2357,15 @@ class Transactions {
|
|
|
2341
2357
|
})
|
|
2342
2358
|
.remainingAccounts([...extensionIx.keys.slice(4)])
|
|
2343
2359
|
.instruction();
|
|
2344
|
-
const withdrawFromPda = yield
|
|
2360
|
+
const withdrawFromPda = yield this.ix.iyfMain.withdrawMultipleTokenWithToken2022({
|
|
2361
|
+
connection,
|
|
2345
2362
|
payer: params.userWallet,
|
|
2346
|
-
withdraw: [
|
|
2363
|
+
withdraw: [
|
|
2364
|
+
{ mint: mintA, amount: new bn_js_1.default(0) },
|
|
2365
|
+
{ mint: mintB, amount: new bn_js_1.default(0) },
|
|
2366
|
+
],
|
|
2367
|
+
pdaTokenType: types_1.TokenType.ATA,
|
|
2368
|
+
hasAmount: false,
|
|
2347
2369
|
});
|
|
2348
2370
|
orcaIx.keys[2].isSigner = true; // authority must be signer.
|
|
2349
2371
|
const mainInstructions = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TxGenerator.d.ts","sourceRoot":"","sources":["../../../src/classes/TxGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,6BAA6B,EAC7B,kBAAkB,EAClB,iBAAi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OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IAiC7C,mBAAmB,CACvB,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IA8B7C,oBAAoB,CACxB,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IA8B7C,+BAA+B,CACnC,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IA8B7C,wBAAwB,CAC5B,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IA8B7C,wBAAwB,CAC5B,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,wBAAwB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;CA6BpD"}
|
|
@@ -177,6 +177,7 @@ class TxGenerator {
|
|
|
177
177
|
const ixs = [];
|
|
178
178
|
// Create limit token account
|
|
179
179
|
ixs.push(yield this.ix.iyfMain.createLimitToken({
|
|
180
|
+
connection,
|
|
180
181
|
userWallet: params.userWallet,
|
|
181
182
|
payer: params.payer,
|
|
182
183
|
mint: params.mint,
|
|
@@ -199,6 +200,7 @@ class TxGenerator {
|
|
|
199
200
|
const ixs = [];
|
|
200
201
|
// Close limit token account
|
|
201
202
|
ixs.push(yield this.ix.iyfMain.closeLimitToken({
|
|
203
|
+
connection,
|
|
202
204
|
userWallet: params.userWallet,
|
|
203
205
|
mint: params.mint,
|
|
204
206
|
}));
|
|
@@ -228,6 +230,7 @@ class TxGenerator {
|
|
|
228
230
|
// Idempotently create limit token accounts (generate instruction)
|
|
229
231
|
for (const deposit of params.deposit) {
|
|
230
232
|
ixs.push(yield this.ix.iyfMain.createLimitToken({
|
|
233
|
+
connection,
|
|
231
234
|
userWallet: params.userWallet,
|
|
232
235
|
payer: params.userWallet,
|
|
233
236
|
mint: deposit.mint,
|
|
@@ -235,6 +238,7 @@ class TxGenerator {
|
|
|
235
238
|
}
|
|
236
239
|
// Deposit to limit token accounts
|
|
237
240
|
ixs.push(yield this.ix.iyfMain.depositMultipleTokenV2({
|
|
241
|
+
connection,
|
|
238
242
|
payer: params.userWallet,
|
|
239
243
|
deposit: params.deposit,
|
|
240
244
|
pdaTokenType: types_1.TokenType.LTA,
|
|
@@ -264,6 +268,7 @@ class TxGenerator {
|
|
|
264
268
|
const ixs = [];
|
|
265
269
|
// Withdraw from limit token accounts
|
|
266
270
|
ixs.push(yield this.ix.iyfMain.withdrawMultipleTokenV2({
|
|
271
|
+
connection,
|
|
267
272
|
payer: params.userWallet,
|
|
268
273
|
withdraw: params.withdraw,
|
|
269
274
|
pdaTokenType: types_1.TokenType.LTA,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as web3 from "@solana/web3.js";
|
|
3
|
+
type AccountInfoInternal = {
|
|
4
|
+
refetch: boolean;
|
|
5
|
+
info: web3.AccountInfo<Buffer>;
|
|
6
|
+
};
|
|
7
|
+
type _AccountCache = Record<string, AccountInfoInternal>;
|
|
8
|
+
export declare abstract class AccountCache {
|
|
9
|
+
protected connection: web3.Connection;
|
|
10
|
+
protected accounts: _AccountCache;
|
|
11
|
+
protected pending: Promise<void> | null;
|
|
12
|
+
/**
|
|
13
|
+
* Instantiate the AccountCache class
|
|
14
|
+
*
|
|
15
|
+
* @param connection - The connection to the blockchain.
|
|
16
|
+
*/
|
|
17
|
+
constructor(connection: web3.Connection);
|
|
18
|
+
/**
|
|
19
|
+
* Criteria of accounts to be fetched must be only owned by the given programs
|
|
20
|
+
*/
|
|
21
|
+
protected abstract mustOwnedByEitherPrograms(): web3.PublicKey[];
|
|
22
|
+
/**
|
|
23
|
+
* Whether the account query should require the account to exist.
|
|
24
|
+
*/
|
|
25
|
+
protected abstract requireToExist(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Mark accounts to be refetched
|
|
28
|
+
*/
|
|
29
|
+
refetch(pubkeys: web3.PublicKey[]): this;
|
|
30
|
+
/**
|
|
31
|
+
* The goal of this function is to batch 100 accounts at a time as it is the max number of accounts that can be fetched at once.
|
|
32
|
+
* Skips accounts that are already fetched.
|
|
33
|
+
*
|
|
34
|
+
* @param pubkeys - The accounts to fetch.
|
|
35
|
+
* @returns - A promise that resolves to an array of TokenAccountInfo objects.
|
|
36
|
+
*/
|
|
37
|
+
getBatchedMultipleAccountsInfo(pubkeys: web3.PublicKey[], commitment?: web3.Commitment): this;
|
|
38
|
+
waitForResult(): Promise<_AccountCache>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=AccountCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountCache.d.ts","sourceRoot":"","sources":["../../../../src/classes/account-cache/AccountCache.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAExC,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;CAChC,CAAA;AAED,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAEzD,8BAAsB,YAAY;IAY9B,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU;IAVvC,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAM;IAEvC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAQ;IAE/C;;;;OAIG;gBAES,UAAU,EAAE,IAAI,CAAC,UAAU;IAGvC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,yBAAyB,IAAI,IAAI,CAAC,SAAS,EAAE;IAEhE;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,OAAO;IAE5C;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI;IAOxC;;;;;;OAMG;IACH,8BAA8B,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,UAAU,GAAE,IAAI,CAAC,UAAwB,GAAG,IAAI;IAiCpG,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;CAM9C"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AccountCache = void 0;
|
|
13
|
+
class AccountCache {
|
|
14
|
+
/**
|
|
15
|
+
* Instantiate the AccountCache class
|
|
16
|
+
*
|
|
17
|
+
* @param connection - The connection to the blockchain.
|
|
18
|
+
*/
|
|
19
|
+
constructor(connection) {
|
|
20
|
+
this.connection = connection;
|
|
21
|
+
this.accounts = {};
|
|
22
|
+
this.pending = null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Mark accounts to be refetched
|
|
26
|
+
*/
|
|
27
|
+
refetch(pubkeys) {
|
|
28
|
+
for (const pubkey of pubkeys) {
|
|
29
|
+
this.accounts[pubkey.toString()].refetch = true;
|
|
30
|
+
}
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The goal of this function is to batch 100 accounts at a time as it is the max number of accounts that can be fetched at once.
|
|
35
|
+
* Skips accounts that are already fetched.
|
|
36
|
+
*
|
|
37
|
+
* @param pubkeys - The accounts to fetch.
|
|
38
|
+
* @returns - A promise that resolves to an array of TokenAccountInfo objects.
|
|
39
|
+
*/
|
|
40
|
+
getBatchedMultipleAccountsInfo(pubkeys, commitment = "confirmed") {
|
|
41
|
+
// Check first if account is already fetched. Skips accounts that are marked to be refetched.
|
|
42
|
+
const pubkeysToFetch = pubkeys.filter(pubkey => !this.accounts[pubkey.toString()] && !this.accounts[pubkey.toString()].refetch);
|
|
43
|
+
const batchSize = 100;
|
|
44
|
+
const batches = [];
|
|
45
|
+
for (let i = 0; i < pubkeysToFetch.length; i += batchSize) {
|
|
46
|
+
batches.push(pubkeysToFetch.slice(i, i + batchSize));
|
|
47
|
+
}
|
|
48
|
+
const pending = Promise.all(batches.map(batch => this.connection.getMultipleAccountsInfo(batch, commitment))).then(batch => {
|
|
49
|
+
const result = batch.flat();
|
|
50
|
+
for (let i = 0; i < result.length; i++) {
|
|
51
|
+
const pubkey = pubkeysToFetch[i];
|
|
52
|
+
const info = result[i];
|
|
53
|
+
if (info !== null) {
|
|
54
|
+
// Throw error if account fetching requires program ownership
|
|
55
|
+
const mustBeOwnedByEither = this.mustOwnedByEitherPrograms();
|
|
56
|
+
if (mustBeOwnedByEither.length > 0 && !mustBeOwnedByEither.some(program => info.owner.equals(program))) {
|
|
57
|
+
throw new Error(`Account ${pubkey.toString()} is not owned by any of the programs ${mustBeOwnedByEither.map(program => program.toString()).join(", ")}`);
|
|
58
|
+
}
|
|
59
|
+
this.accounts[pubkey.toString()] = { refetch: false, info };
|
|
60
|
+
}
|
|
61
|
+
else if (this.requireToExist()) {
|
|
62
|
+
throw new Error(`Account ${pubkey.toString()} does not exist`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
this.pending = pending;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
waitForResult() {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
if (this.pending) {
|
|
72
|
+
yield this.pending;
|
|
73
|
+
}
|
|
74
|
+
return this.accounts;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.AccountCache = AccountCache;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as web3 from "@solana/web3.js";
|
|
2
|
+
import { AccountCache } from "./AccountCache";
|
|
3
|
+
/**
|
|
4
|
+
* Singleton instance of AccountCache for mint accounts.
|
|
5
|
+
*/
|
|
6
|
+
export declare class MintCache extends AccountCache {
|
|
7
|
+
/**
|
|
8
|
+
* Singleton instance of MintCache
|
|
9
|
+
*/
|
|
10
|
+
private static _instance;
|
|
11
|
+
/**
|
|
12
|
+
* Instantiate the MintCache class
|
|
13
|
+
*
|
|
14
|
+
* @param connection The Solana connection
|
|
15
|
+
*/
|
|
16
|
+
private constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Get the singleton instance of MintCache
|
|
19
|
+
*
|
|
20
|
+
* @param connection The Solana connection
|
|
21
|
+
* @returns The MintCache instance
|
|
22
|
+
*/
|
|
23
|
+
static instance(connection: web3.Connection): MintCache;
|
|
24
|
+
/**
|
|
25
|
+
* Criteria of accounts to be fetched must be only owned by the given programs
|
|
26
|
+
*/
|
|
27
|
+
protected mustOwnedByEitherPrograms(): web3.PublicKey[];
|
|
28
|
+
/**
|
|
29
|
+
* Whether the account query should require the account to exist.
|
|
30
|
+
*/
|
|
31
|
+
protected requireToExist(): boolean;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=MintCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MintCache.d.ts","sourceRoot":"","sources":["../../../../src/classes/account-cache/MintCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;GAEG;AACH,qBAAa,SAAU,SAAQ,YAAY;IAEzC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS,CAA0B;IAElD;;;;OAIG;IACH,OAAO;IAIP;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,GAAG,SAAS;IAOvD;;OAEG;IACH,SAAS,CAAC,yBAAyB,IAAI,IAAI,CAAC,SAAS,EAAE;IAIvD;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,OAAO;CAGpC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MintCache = void 0;
|
|
4
|
+
const AccountCache_1 = require("./AccountCache");
|
|
5
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
/**
|
|
7
|
+
* Singleton instance of AccountCache for mint accounts.
|
|
8
|
+
*/
|
|
9
|
+
class MintCache extends AccountCache_1.AccountCache {
|
|
10
|
+
/**
|
|
11
|
+
* Instantiate the MintCache class
|
|
12
|
+
*
|
|
13
|
+
* @param connection The Solana connection
|
|
14
|
+
*/
|
|
15
|
+
constructor(connection) {
|
|
16
|
+
super(connection);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the singleton instance of MintCache
|
|
20
|
+
*
|
|
21
|
+
* @param connection The Solana connection
|
|
22
|
+
* @returns The MintCache instance
|
|
23
|
+
*/
|
|
24
|
+
static instance(connection) {
|
|
25
|
+
if (!MintCache._instance) {
|
|
26
|
+
MintCache._instance = new MintCache(connection);
|
|
27
|
+
}
|
|
28
|
+
return MintCache._instance;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Criteria of accounts to be fetched must be only owned by the given programs
|
|
32
|
+
*/
|
|
33
|
+
mustOwnedByEitherPrograms() {
|
|
34
|
+
return [spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.TOKEN_2022_PROGRAM_ID];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether the account query should require the account to exist.
|
|
38
|
+
*/
|
|
39
|
+
requireToExist() {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.MintCache = MintCache;
|
|
44
|
+
/**
|
|
45
|
+
* Singleton instance of MintCache
|
|
46
|
+
*/
|
|
47
|
+
MintCache._instance = null;
|