@crypticdot/defituna-client 3.3.0 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +11 -13
- package/dist/index.d.ts +11 -13
- package/dist/index.js +892 -473
- package/dist/index.mjs +1153 -367
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -573,6 +573,8 @@ __export(index_exports, {
|
|
|
573
573
|
liquidateTunaSpotPositionOrcaInstructions: () => liquidateTunaSpotPositionOrcaInstructions,
|
|
574
574
|
modifyTunaSpotPositionFusionInstruction: () => modifyTunaSpotPositionFusionInstruction,
|
|
575
575
|
modifyTunaSpotPositionFusionInstructions: () => modifyTunaSpotPositionFusionInstructions,
|
|
576
|
+
modifyTunaSpotPositionJupiterInstruction: () => modifyTunaSpotPositionJupiterInstruction,
|
|
577
|
+
modifyTunaSpotPositionJupiterInstructions: () => modifyTunaSpotPositionJupiterInstructions,
|
|
576
578
|
modifyTunaSpotPositionOrcaInstruction: () => modifyTunaSpotPositionOrcaInstruction,
|
|
577
579
|
modifyTunaSpotPositionOrcaInstructions: () => modifyTunaSpotPositionOrcaInstructions,
|
|
578
580
|
mulDiv: () => mulDiv,
|
|
@@ -5154,10 +5156,9 @@ function getModifyTunaSpotPositionFusionInstructionDataEncoder() {
|
|
|
5154
5156
|
(0, import_kit36.getStructEncoder)([
|
|
5155
5157
|
["discriminator", (0, import_kit36.fixEncoderSize)((0, import_kit36.getBytesEncoder)(), 8)],
|
|
5156
5158
|
["decreasePercent", (0, import_kit36.getU32Encoder)()],
|
|
5157
|
-
["decreaseAcceptableSwapAmount", (0, import_kit36.getU64Encoder)()],
|
|
5158
5159
|
["collateralAmount", (0, import_kit36.getU64Encoder)()],
|
|
5159
5160
|
["borrowAmount", (0, import_kit36.getU64Encoder)()],
|
|
5160
|
-
["
|
|
5161
|
+
["requiredSwapAmount", (0, import_kit36.getU64Encoder)()],
|
|
5161
5162
|
["remainingAccountsInfo", getRemainingAccountsInfoEncoder()]
|
|
5162
5163
|
]),
|
|
5163
5164
|
(value) => ({
|
|
@@ -5170,10 +5171,9 @@ function getModifyTunaSpotPositionFusionInstructionDataDecoder() {
|
|
|
5170
5171
|
return (0, import_kit36.getStructDecoder)([
|
|
5171
5172
|
["discriminator", (0, import_kit36.fixDecoderSize)((0, import_kit36.getBytesDecoder)(), 8)],
|
|
5172
5173
|
["decreasePercent", (0, import_kit36.getU32Decoder)()],
|
|
5173
|
-
["decreaseAcceptableSwapAmount", (0, import_kit36.getU64Decoder)()],
|
|
5174
5174
|
["collateralAmount", (0, import_kit36.getU64Decoder)()],
|
|
5175
5175
|
["borrowAmount", (0, import_kit36.getU64Decoder)()],
|
|
5176
|
-
["
|
|
5176
|
+
["requiredSwapAmount", (0, import_kit36.getU64Decoder)()],
|
|
5177
5177
|
["remainingAccountsInfo", getRemainingAccountsInfoDecoder()]
|
|
5178
5178
|
]);
|
|
5179
5179
|
}
|
|
@@ -5549,10 +5549,9 @@ function getModifyTunaSpotPositionOrcaInstructionDataEncoder() {
|
|
|
5549
5549
|
(0, import_kit38.getStructEncoder)([
|
|
5550
5550
|
["discriminator", (0, import_kit38.fixEncoderSize)((0, import_kit38.getBytesEncoder)(), 8)],
|
|
5551
5551
|
["decreasePercent", (0, import_kit38.getU32Encoder)()],
|
|
5552
|
-
["decreaseAcceptableSwapAmount", (0, import_kit38.getU64Encoder)()],
|
|
5553
5552
|
["collateralAmount", (0, import_kit38.getU64Encoder)()],
|
|
5554
5553
|
["borrowAmount", (0, import_kit38.getU64Encoder)()],
|
|
5555
|
-
["
|
|
5554
|
+
["requiredSwapAmount", (0, import_kit38.getU64Encoder)()],
|
|
5556
5555
|
["remainingAccountsInfo", getRemainingAccountsInfoEncoder()]
|
|
5557
5556
|
]),
|
|
5558
5557
|
(value) => ({
|
|
@@ -5565,10 +5564,9 @@ function getModifyTunaSpotPositionOrcaInstructionDataDecoder() {
|
|
|
5565
5564
|
return (0, import_kit38.getStructDecoder)([
|
|
5566
5565
|
["discriminator", (0, import_kit38.fixDecoderSize)((0, import_kit38.getBytesDecoder)(), 8)],
|
|
5567
5566
|
["decreasePercent", (0, import_kit38.getU32Decoder)()],
|
|
5568
|
-
["decreaseAcceptableSwapAmount", (0, import_kit38.getU64Decoder)()],
|
|
5569
5567
|
["collateralAmount", (0, import_kit38.getU64Decoder)()],
|
|
5570
5568
|
["borrowAmount", (0, import_kit38.getU64Decoder)()],
|
|
5571
|
-
["
|
|
5569
|
+
["requiredSwapAmount", (0, import_kit38.getU64Decoder)()],
|
|
5572
5570
|
["remainingAccountsInfo", getRemainingAccountsInfoDecoder()]
|
|
5573
5571
|
]);
|
|
5574
5572
|
}
|
|
@@ -10616,23 +10614,29 @@ async function modifyTunaSpotPositionOrcaInstructions(rpc, authority, poolAddres
|
|
|
10616
10614
|
(await getLendingVaultAddress(pool.data.tokenMintA))[0],
|
|
10617
10615
|
(await getLendingVaultAddress(pool.data.tokenMintB))[0]
|
|
10618
10616
|
]);
|
|
10619
|
-
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
|
|
10623
|
-
|
|
10624
|
-
|
|
10625
|
-
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10617
|
+
let hasDirectlyTransferredTokensA = false;
|
|
10618
|
+
let hasDirectlyTransferredTokensB = false;
|
|
10619
|
+
if (tunaPosition.exists) {
|
|
10620
|
+
const tunaPositionAtaAAddress = (await (0, import_token_202213.findAssociatedTokenPda)({
|
|
10621
|
+
owner: tunaPositionAddress,
|
|
10622
|
+
mint: mintA.address,
|
|
10623
|
+
tokenProgram: mintA.programAddress
|
|
10624
|
+
}))[0];
|
|
10625
|
+
const tunaPositionAtaBAddress = (await (0, import_token_202213.findAssociatedTokenPda)({
|
|
10626
|
+
owner: tunaPositionAddress,
|
|
10627
|
+
mint: mintB.address,
|
|
10628
|
+
tokenProgram: mintB.programAddress
|
|
10629
|
+
}))[0];
|
|
10630
|
+
const [tunaPositionAtaA, tunaPositionAtaB] = await (0, import_token_202213.fetchAllToken)(rpc, [
|
|
10631
|
+
tunaPositionAtaAAddress,
|
|
10632
|
+
tunaPositionAtaBAddress
|
|
10633
|
+
]);
|
|
10634
|
+
hasDirectlyTransferredTokensA = tunaPositionAtaA.data.amount > (tunaPosition.data.positionToken == 0 /* A */ ? tunaPosition.data.amount : 0n);
|
|
10635
|
+
hasDirectlyTransferredTokensB = tunaPositionAtaB.data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n);
|
|
10636
|
+
}
|
|
10637
|
+
const createUserAtaAInstructions = collateralToken == 0 /* A */ || hasDirectlyTransferredTokensA ? await getCreateAtaInstructions(rpc, authority, mintA.address, authority.address, mintA.programAddress) : void 0;
|
|
10634
10638
|
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
10635
|
-
const createUserAtaBInstructions = collateralToken == 1 /* B */ ||
|
|
10639
|
+
const createUserAtaBInstructions = collateralToken == 1 /* B */ || hasDirectlyTransferredTokensB ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
10636
10640
|
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
10637
10641
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10638
10642
|
rpc,
|
|
@@ -10787,23 +10791,29 @@ async function modifyTunaSpotPositionFusionInstructions(rpc, authority, poolAddr
|
|
|
10787
10791
|
(await getLendingVaultAddress(pool.data.tokenMintA))[0],
|
|
10788
10792
|
(await getLendingVaultAddress(pool.data.tokenMintB))[0]
|
|
10789
10793
|
]);
|
|
10790
|
-
|
|
10791
|
-
|
|
10792
|
-
|
|
10793
|
-
|
|
10794
|
-
|
|
10795
|
-
|
|
10796
|
-
|
|
10797
|
-
|
|
10798
|
-
|
|
10799
|
-
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10794
|
+
let hasDirectlyTransferredTokensA = false;
|
|
10795
|
+
let hasDirectlyTransferredTokensB = false;
|
|
10796
|
+
if (tunaPosition.exists) {
|
|
10797
|
+
const tunaPositionAtaAAddress = (await (0, import_token_202214.findAssociatedTokenPda)({
|
|
10798
|
+
owner: tunaPositionAddress,
|
|
10799
|
+
mint: mintA.address,
|
|
10800
|
+
tokenProgram: mintA.programAddress
|
|
10801
|
+
}))[0];
|
|
10802
|
+
const tunaPositionAtaBAddress = (await (0, import_token_202214.findAssociatedTokenPda)({
|
|
10803
|
+
owner: tunaPositionAddress,
|
|
10804
|
+
mint: mintB.address,
|
|
10805
|
+
tokenProgram: mintB.programAddress
|
|
10806
|
+
}))[0];
|
|
10807
|
+
const [tunaPositionAtaA, tunaPositionAtaB] = await (0, import_token_202214.fetchAllToken)(rpc, [
|
|
10808
|
+
tunaPositionAtaAAddress,
|
|
10809
|
+
tunaPositionAtaBAddress
|
|
10810
|
+
]);
|
|
10811
|
+
hasDirectlyTransferredTokensA = tunaPositionAtaA.data.amount > (tunaPosition.data.positionToken == 0 /* A */ ? tunaPosition.data.amount : 0n);
|
|
10812
|
+
hasDirectlyTransferredTokensB = tunaPositionAtaB.data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n);
|
|
10813
|
+
}
|
|
10814
|
+
const createUserAtaAInstructions = collateralToken == 0 /* A */ || hasDirectlyTransferredTokensA ? await getCreateAtaInstructions(rpc, authority, mintA.address, authority.address, mintA.programAddress) : void 0;
|
|
10805
10815
|
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
10806
|
-
const createUserAtaBInstructions = collateralToken == 1 /* B */ ||
|
|
10816
|
+
const createUserAtaBInstructions = collateralToken == 1 /* B */ || hasDirectlyTransferredTokensB ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
10807
10817
|
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
10808
10818
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10809
10819
|
rpc,
|
|
@@ -10929,27 +10939,434 @@ async function modifyTunaSpotPositionFusionInstruction(authority, tunaConfig, mi
|
|
|
10929
10939
|
return ix;
|
|
10930
10940
|
}
|
|
10931
10941
|
|
|
10932
|
-
// src/txbuilder/
|
|
10942
|
+
// src/txbuilder/modifyTunaSpotPositionJupiter.ts
|
|
10943
|
+
var import_fusionamm_client8 = require("@crypticdot/fusionamm-client");
|
|
10944
|
+
|
|
10945
|
+
// ../../node_modules/.pnpm/@crypticdot+jupiter-solana-client@1.0.0_fastestsmallesttextencoderdecoder@1.0.22_typesc_c15ee540b6a974c893a6f86bc9defff2/node_modules/@crypticdot/jupiter-solana-client/dist/index.mjs
|
|
10946
|
+
var import_kit82 = require("@solana/kit");
|
|
10947
|
+
var import_kit83 = require("@solana/kit");
|
|
10948
|
+
var import_kit84 = require("@solana/kit");
|
|
10949
|
+
var import_kit85 = require("@solana/kit");
|
|
10950
|
+
var import_kit86 = require("@solana/kit");
|
|
10951
|
+
var import_kit87 = require("@solana/kit");
|
|
10952
|
+
var import_kit88 = require("@solana/kit");
|
|
10953
|
+
var import_kit89 = require("@solana/kit");
|
|
10954
|
+
var import_kit90 = require("@solana/kit");
|
|
10955
|
+
var import_kit91 = require("@solana/kit");
|
|
10956
|
+
var import_kit92 = require("@solana/kit");
|
|
10957
|
+
var import_kit93 = require("@solana/kit");
|
|
10958
|
+
var import_kit94 = require("@solana/kit");
|
|
10959
|
+
var import_kit95 = require("@solana/kit");
|
|
10960
|
+
var import_kit96 = require("@solana/kit");
|
|
10961
|
+
var import_kit97 = require("@solana/kit");
|
|
10962
|
+
var import_kit98 = require("@solana/kit");
|
|
10963
|
+
var import_kit99 = require("@solana/kit");
|
|
10964
|
+
var import_kit100 = require("@solana/kit");
|
|
10965
|
+
var import_kit101 = require("@solana/kit");
|
|
10966
|
+
var import_kit102 = require("@solana/kit");
|
|
10967
|
+
var import_kit103 = require("@solana/kit");
|
|
10968
|
+
var import_kit104 = require("@solana/kit");
|
|
10969
|
+
var import_kit105 = require("@solana/kit");
|
|
10970
|
+
var import_kit106 = require("@solana/kit");
|
|
10971
|
+
var import_kit107 = require("@solana/kit");
|
|
10972
|
+
var import_kit108 = require("@solana/kit");
|
|
10973
|
+
var import_kit109 = require("@solana/kit");
|
|
10974
|
+
var import_kit110 = require("@solana/kit");
|
|
10975
|
+
var import_kit111 = require("@solana/kit");
|
|
10976
|
+
var import_kit112 = require("@solana/kit");
|
|
10977
|
+
var import_kit113 = require("@solana/kit");
|
|
10978
|
+
var import_kit114 = require("@solana/kit");
|
|
10979
|
+
var import_kit115 = require("@solana/kit");
|
|
10980
|
+
var TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([
|
|
10981
|
+
156,
|
|
10982
|
+
247,
|
|
10983
|
+
9,
|
|
10984
|
+
188,
|
|
10985
|
+
54,
|
|
10986
|
+
108,
|
|
10987
|
+
85,
|
|
10988
|
+
77
|
|
10989
|
+
]);
|
|
10990
|
+
var JUPITER_PROGRAM_ADDRESS = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
|
|
10991
|
+
var JUPITER_ERROR__EMPTY_ROUTE = 6e3;
|
|
10992
|
+
var JUPITER_ERROR__SLIPPAGE_TOLERANCE_EXCEEDED = 6001;
|
|
10993
|
+
var JUPITER_ERROR__INVALID_CALCULATION = 6002;
|
|
10994
|
+
var JUPITER_ERROR__MISSING_PLATFORM_FEE_ACCOUNT = 6003;
|
|
10995
|
+
var JUPITER_ERROR__INVALID_SLIPPAGE = 6004;
|
|
10996
|
+
var JUPITER_ERROR__NOT_ENOUGH_PERCENT = 6005;
|
|
10997
|
+
var JUPITER_ERROR__INVALID_INPUT_INDEX = 6006;
|
|
10998
|
+
var JUPITER_ERROR__INVALID_OUTPUT_INDEX = 6007;
|
|
10999
|
+
var JUPITER_ERROR__NOT_ENOUGH_ACCOUNT_KEYS = 6008;
|
|
11000
|
+
var JUPITER_ERROR__NON_ZERO_MINIMUM_OUT_AMOUNT_NOT_SUPPORTED = 6009;
|
|
11001
|
+
var JUPITER_ERROR__INVALID_ROUTE_PLAN = 6010;
|
|
11002
|
+
var JUPITER_ERROR__INVALID_REFERRAL_AUTHORITY = 6011;
|
|
11003
|
+
var JUPITER_ERROR__LEDGER_TOKEN_ACCOUNT_DOES_NOT_MATCH = 6012;
|
|
11004
|
+
var JUPITER_ERROR__INVALID_TOKEN_LEDGER = 6013;
|
|
11005
|
+
var JUPITER_ERROR__INCORRECT_TOKEN_PROGRAM_I_D = 6014;
|
|
11006
|
+
var JUPITER_ERROR__TOKEN_PROGRAM_NOT_PROVIDED = 6015;
|
|
11007
|
+
var JUPITER_ERROR__SWAP_NOT_SUPPORTED = 6016;
|
|
11008
|
+
var JUPITER_ERROR__EXACT_OUT_AMOUNT_NOT_MATCHED = 6017;
|
|
11009
|
+
var JUPITER_ERROR__SOURCE_AND_DESTINATION_MINT_CANNOT_BE_THE_SAME = 6018;
|
|
11010
|
+
var jupiterErrorMessages;
|
|
11011
|
+
if (process.env.NODE_ENV !== "production") {
|
|
11012
|
+
jupiterErrorMessages = {
|
|
11013
|
+
[JUPITER_ERROR__EMPTY_ROUTE]: `Empty route`,
|
|
11014
|
+
[JUPITER_ERROR__EXACT_OUT_AMOUNT_NOT_MATCHED]: `Exact out amount doesn't match`,
|
|
11015
|
+
[JUPITER_ERROR__INCORRECT_TOKEN_PROGRAM_I_D]: `Token program ID is invalid`,
|
|
11016
|
+
[JUPITER_ERROR__INVALID_CALCULATION]: `Invalid calculation`,
|
|
11017
|
+
[JUPITER_ERROR__INVALID_INPUT_INDEX]: `Token input index is invalid`,
|
|
11018
|
+
[JUPITER_ERROR__INVALID_OUTPUT_INDEX]: `Token output index is invalid`,
|
|
11019
|
+
[JUPITER_ERROR__INVALID_REFERRAL_AUTHORITY]: `Invalid referral authority`,
|
|
11020
|
+
[JUPITER_ERROR__INVALID_ROUTE_PLAN]: `Invalid route plan`,
|
|
11021
|
+
[JUPITER_ERROR__INVALID_SLIPPAGE]: `Invalid slippage`,
|
|
11022
|
+
[JUPITER_ERROR__INVALID_TOKEN_LEDGER]: `Invalid token ledger`,
|
|
11023
|
+
[JUPITER_ERROR__LEDGER_TOKEN_ACCOUNT_DOES_NOT_MATCH]: `Token account doesn't match the ledger`,
|
|
11024
|
+
[JUPITER_ERROR__MISSING_PLATFORM_FEE_ACCOUNT]: `Missing platform fee account`,
|
|
11025
|
+
[JUPITER_ERROR__NON_ZERO_MINIMUM_OUT_AMOUNT_NOT_SUPPORTED]: `Non zero minimum out amount not supported`,
|
|
11026
|
+
[JUPITER_ERROR__NOT_ENOUGH_ACCOUNT_KEYS]: `Not Enough Account keys`,
|
|
11027
|
+
[JUPITER_ERROR__NOT_ENOUGH_PERCENT]: `Not enough percent to 100`,
|
|
11028
|
+
[JUPITER_ERROR__SLIPPAGE_TOLERANCE_EXCEEDED]: `Slippage tolerance exceeded`,
|
|
11029
|
+
[JUPITER_ERROR__SOURCE_AND_DESTINATION_MINT_CANNOT_BE_THE_SAME]: `Source mint and destination mint cannot the same`,
|
|
11030
|
+
[JUPITER_ERROR__SWAP_NOT_SUPPORTED]: `Swap not supported`,
|
|
11031
|
+
[JUPITER_ERROR__TOKEN_PROGRAM_NOT_PROVIDED]: `Token program not provided`
|
|
11032
|
+
};
|
|
11033
|
+
}
|
|
11034
|
+
var CLAIM_DISCRIMINATOR = new Uint8Array([
|
|
11035
|
+
62,
|
|
11036
|
+
198,
|
|
11037
|
+
214,
|
|
11038
|
+
193,
|
|
11039
|
+
213,
|
|
11040
|
+
159,
|
|
11041
|
+
108,
|
|
11042
|
+
210
|
|
11043
|
+
]);
|
|
11044
|
+
var CLAIM_TOKEN_DISCRIMINATOR = new Uint8Array([
|
|
11045
|
+
116,
|
|
11046
|
+
206,
|
|
11047
|
+
27,
|
|
11048
|
+
191,
|
|
11049
|
+
166,
|
|
11050
|
+
19,
|
|
11051
|
+
0,
|
|
11052
|
+
73
|
|
11053
|
+
]);
|
|
11054
|
+
var CLOSE_TOKEN_DISCRIMINATOR = new Uint8Array([
|
|
11055
|
+
26,
|
|
11056
|
+
74,
|
|
11057
|
+
236,
|
|
11058
|
+
151,
|
|
11059
|
+
104,
|
|
11060
|
+
64,
|
|
11061
|
+
183,
|
|
11062
|
+
249
|
|
11063
|
+
]);
|
|
11064
|
+
var CREATE_OPEN_ORDERS_DISCRIMINATOR = new Uint8Array([
|
|
11065
|
+
229,
|
|
11066
|
+
194,
|
|
11067
|
+
212,
|
|
11068
|
+
172,
|
|
11069
|
+
8,
|
|
11070
|
+
10,
|
|
11071
|
+
134,
|
|
11072
|
+
147
|
|
11073
|
+
]);
|
|
11074
|
+
var CREATE_PROGRAM_OPEN_ORDERS_DISCRIMINATOR = new Uint8Array([
|
|
11075
|
+
28,
|
|
11076
|
+
226,
|
|
11077
|
+
32,
|
|
11078
|
+
148,
|
|
11079
|
+
188,
|
|
11080
|
+
136,
|
|
11081
|
+
113,
|
|
11082
|
+
171
|
|
11083
|
+
]);
|
|
11084
|
+
var CREATE_TOKEN_ACCOUNT_DISCRIMINATOR = new Uint8Array([
|
|
11085
|
+
147,
|
|
11086
|
+
241,
|
|
11087
|
+
123,
|
|
11088
|
+
100,
|
|
11089
|
+
244,
|
|
11090
|
+
132,
|
|
11091
|
+
174,
|
|
11092
|
+
118
|
|
11093
|
+
]);
|
|
11094
|
+
var CREATE_TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([
|
|
11095
|
+
232,
|
|
11096
|
+
242,
|
|
11097
|
+
197,
|
|
11098
|
+
253,
|
|
11099
|
+
240,
|
|
11100
|
+
143,
|
|
11101
|
+
129,
|
|
11102
|
+
52
|
|
11103
|
+
]);
|
|
11104
|
+
var EXACT_OUT_ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
11105
|
+
208,
|
|
11106
|
+
51,
|
|
11107
|
+
239,
|
|
11108
|
+
151,
|
|
11109
|
+
123,
|
|
11110
|
+
43,
|
|
11111
|
+
237,
|
|
11112
|
+
92
|
|
11113
|
+
]);
|
|
11114
|
+
var EXACT_OUT_ROUTE_V2_DISCRIMINATOR = new Uint8Array([
|
|
11115
|
+
157,
|
|
11116
|
+
138,
|
|
11117
|
+
184,
|
|
11118
|
+
82,
|
|
11119
|
+
21,
|
|
11120
|
+
244,
|
|
11121
|
+
243,
|
|
11122
|
+
36
|
|
11123
|
+
]);
|
|
11124
|
+
var ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
11125
|
+
229,
|
|
11126
|
+
23,
|
|
11127
|
+
203,
|
|
11128
|
+
151,
|
|
11129
|
+
122,
|
|
11130
|
+
227,
|
|
11131
|
+
173,
|
|
11132
|
+
42
|
|
11133
|
+
]);
|
|
11134
|
+
var ROUTE_V2_DISCRIMINATOR = new Uint8Array([
|
|
11135
|
+
187,
|
|
11136
|
+
100,
|
|
11137
|
+
250,
|
|
11138
|
+
204,
|
|
11139
|
+
49,
|
|
11140
|
+
196,
|
|
11141
|
+
175,
|
|
11142
|
+
20
|
|
11143
|
+
]);
|
|
11144
|
+
var ROUTE_WITH_TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([
|
|
11145
|
+
150,
|
|
11146
|
+
86,
|
|
11147
|
+
71,
|
|
11148
|
+
116,
|
|
11149
|
+
167,
|
|
11150
|
+
93,
|
|
11151
|
+
14,
|
|
11152
|
+
104
|
|
11153
|
+
]);
|
|
11154
|
+
var SET_TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([
|
|
11155
|
+
228,
|
|
11156
|
+
85,
|
|
11157
|
+
185,
|
|
11158
|
+
112,
|
|
11159
|
+
78,
|
|
11160
|
+
79,
|
|
11161
|
+
77,
|
|
11162
|
+
2
|
|
11163
|
+
]);
|
|
11164
|
+
var SHARED_ACCOUNTS_EXACT_OUT_ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
11165
|
+
176,
|
|
11166
|
+
209,
|
|
11167
|
+
105,
|
|
11168
|
+
168,
|
|
11169
|
+
154,
|
|
11170
|
+
125,
|
|
11171
|
+
69,
|
|
11172
|
+
62
|
|
11173
|
+
]);
|
|
11174
|
+
var SHARED_ACCOUNTS_EXACT_OUT_ROUTE_V2_DISCRIMINATOR = new Uint8Array([
|
|
11175
|
+
53,
|
|
11176
|
+
96,
|
|
11177
|
+
229,
|
|
11178
|
+
202,
|
|
11179
|
+
216,
|
|
11180
|
+
187,
|
|
11181
|
+
250,
|
|
11182
|
+
24
|
|
11183
|
+
]);
|
|
11184
|
+
var SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
11185
|
+
193,
|
|
11186
|
+
32,
|
|
11187
|
+
155,
|
|
11188
|
+
51,
|
|
11189
|
+
65,
|
|
11190
|
+
214,
|
|
11191
|
+
156,
|
|
11192
|
+
129
|
|
11193
|
+
]);
|
|
11194
|
+
var SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR = new Uint8Array([
|
|
11195
|
+
209,
|
|
11196
|
+
152,
|
|
11197
|
+
83,
|
|
11198
|
+
147,
|
|
11199
|
+
124,
|
|
11200
|
+
254,
|
|
11201
|
+
216,
|
|
11202
|
+
233
|
|
11203
|
+
]);
|
|
11204
|
+
var SHARED_ACCOUNTS_ROUTE_WITH_TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([230, 121, 143, 80, 119, 159, 106, 170]);
|
|
11205
|
+
|
|
11206
|
+
// src/txbuilder/modifyTunaSpotPositionJupiter.ts
|
|
11207
|
+
var import_whirlpools_client8 = require("@orca-so/whirlpools-client");
|
|
11208
|
+
var import_memo10 = require("@solana-program/memo");
|
|
10933
11209
|
var import_token_202215 = require("@solana-program/token-2022");
|
|
10934
11210
|
var import_assert13 = __toESM(require("assert"));
|
|
11211
|
+
async function modifyTunaSpotPositionJupiterInstructions(rpc, authority, poolAddress, remainingAccounts, args, createInstructions, cleanupInstructions) {
|
|
11212
|
+
const instructions = [];
|
|
11213
|
+
if (!createInstructions) createInstructions = instructions;
|
|
11214
|
+
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
11215
|
+
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
11216
|
+
const marketAddress = (await getMarketAddress(poolAddress))[0];
|
|
11217
|
+
const market = await fetchMarket(rpc, marketAddress);
|
|
11218
|
+
const pool = market.data.marketMaker == 1 /* Fusion */ ? await (0, import_fusionamm_client8.fetchFusionPool)(rpc, poolAddress) : await (0, import_whirlpools_client8.fetchWhirlpool)(rpc, poolAddress);
|
|
11219
|
+
const [mintA, mintB] = await (0, import_token_202215.fetchAllMaybeMint)(rpc, [pool.data.tokenMintA, pool.data.tokenMintB]);
|
|
11220
|
+
(0, import_assert13.default)(mintA.exists, "Token A account not found");
|
|
11221
|
+
(0, import_assert13.default)(mintB.exists, "Token B account not found");
|
|
11222
|
+
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
11223
|
+
(await getLendingVaultAddress(mintA.address))[0],
|
|
11224
|
+
(await getLendingVaultAddress(mintB.address))[0]
|
|
11225
|
+
]);
|
|
11226
|
+
const createUserAtaAInstructions = await getCreateAtaInstructions(
|
|
11227
|
+
rpc,
|
|
11228
|
+
authority,
|
|
11229
|
+
mintA.address,
|
|
11230
|
+
authority.address,
|
|
11231
|
+
mintA.programAddress
|
|
11232
|
+
);
|
|
11233
|
+
createInstructions.push(...createUserAtaAInstructions.init);
|
|
11234
|
+
const createUserAtaBInstructions = await getCreateAtaInstructions(
|
|
11235
|
+
rpc,
|
|
11236
|
+
authority,
|
|
11237
|
+
mintB.address,
|
|
11238
|
+
authority.address,
|
|
11239
|
+
mintB.programAddress
|
|
11240
|
+
);
|
|
11241
|
+
createInstructions.push(...createUserAtaBInstructions.init);
|
|
11242
|
+
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
11243
|
+
rpc,
|
|
11244
|
+
authority,
|
|
11245
|
+
mintA.address,
|
|
11246
|
+
tunaConfig.data.feeRecipient,
|
|
11247
|
+
mintA.programAddress
|
|
11248
|
+
);
|
|
11249
|
+
createInstructions.push(...createFeeRecipientAtaAInstructions.init);
|
|
11250
|
+
const createFeeRecipientAtaBInstructions = await getCreateAtaInstructions(
|
|
11251
|
+
rpc,
|
|
11252
|
+
authority,
|
|
11253
|
+
mintB.address,
|
|
11254
|
+
tunaConfig.data.feeRecipient,
|
|
11255
|
+
mintB.programAddress
|
|
11256
|
+
);
|
|
11257
|
+
createInstructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
11258
|
+
const ix = await modifyTunaSpotPositionJupiterInstruction(
|
|
11259
|
+
authority,
|
|
11260
|
+
tunaConfig,
|
|
11261
|
+
mintA,
|
|
11262
|
+
mintB,
|
|
11263
|
+
vaultA,
|
|
11264
|
+
vaultB,
|
|
11265
|
+
poolAddress,
|
|
11266
|
+
remainingAccounts,
|
|
11267
|
+
{ ...args }
|
|
11268
|
+
);
|
|
11269
|
+
instructions.push(ix);
|
|
11270
|
+
if (createUserAtaAInstructions) cleanupInstructions.push(...createUserAtaAInstructions.cleanup);
|
|
11271
|
+
if (createUserAtaBInstructions) cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
11272
|
+
return instructions;
|
|
11273
|
+
}
|
|
11274
|
+
async function modifyTunaSpotPositionJupiterInstruction(authority, tunaConfig, mintA, mintB, vaultA, vaultB, poolAddress, remainingAccounts, args) {
|
|
11275
|
+
const marketAddress = (await getMarketAddress(poolAddress))[0];
|
|
11276
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
11277
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
11278
|
+
owner: authority.address,
|
|
11279
|
+
mint: mintA.address,
|
|
11280
|
+
tokenProgram: mintA.programAddress
|
|
11281
|
+
}))[0];
|
|
11282
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
11283
|
+
owner: authority.address,
|
|
11284
|
+
mint: mintB.address,
|
|
11285
|
+
tokenProgram: mintB.programAddress
|
|
11286
|
+
}))[0];
|
|
11287
|
+
const feeRecipientAtaA = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
11288
|
+
owner: tunaConfig.data.feeRecipient,
|
|
11289
|
+
mint: mintA.address,
|
|
11290
|
+
tokenProgram: mintA.programAddress
|
|
11291
|
+
}))[0];
|
|
11292
|
+
const feeRecipientAtaB = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
11293
|
+
owner: tunaConfig.data.feeRecipient,
|
|
11294
|
+
mint: mintB.address,
|
|
11295
|
+
tokenProgram: mintB.programAddress
|
|
11296
|
+
}))[0];
|
|
11297
|
+
const tunaPositionAtaA = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
11298
|
+
owner: tunaPositionAddress,
|
|
11299
|
+
mint: mintA.address,
|
|
11300
|
+
tokenProgram: mintA.programAddress
|
|
11301
|
+
}))[0];
|
|
11302
|
+
const tunaPositionAtaB = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
11303
|
+
owner: tunaPositionAddress,
|
|
11304
|
+
mint: mintB.address,
|
|
11305
|
+
tokenProgram: mintB.programAddress
|
|
11306
|
+
}))[0];
|
|
11307
|
+
const vaultAAta = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
11308
|
+
owner: vaultA.address,
|
|
11309
|
+
mint: mintA.address,
|
|
11310
|
+
tokenProgram: mintA.programAddress
|
|
11311
|
+
}))[0];
|
|
11312
|
+
const vaultBAta = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
11313
|
+
owner: vaultB.address,
|
|
11314
|
+
mint: mintB.address,
|
|
11315
|
+
tokenProgram: mintB.programAddress
|
|
11316
|
+
}))[0];
|
|
11317
|
+
const ix = getModifyTunaSpotPositionJupiterInstruction({
|
|
11318
|
+
authority,
|
|
11319
|
+
tunaConfig: tunaConfig.address,
|
|
11320
|
+
mintA: mintA.address,
|
|
11321
|
+
mintB: mintB.address,
|
|
11322
|
+
tokenProgramA: mintA.programAddress,
|
|
11323
|
+
tokenProgramB: mintB.programAddress,
|
|
11324
|
+
market: marketAddress,
|
|
11325
|
+
pythOraclePriceFeedA: vaultA.data.pythOraclePriceUpdate,
|
|
11326
|
+
pythOraclePriceFeedB: vaultB.data.pythOraclePriceUpdate,
|
|
11327
|
+
vaultA: vaultA.address,
|
|
11328
|
+
vaultAAta,
|
|
11329
|
+
vaultB: vaultB.address,
|
|
11330
|
+
vaultBAta,
|
|
11331
|
+
tunaPosition: tunaPositionAddress,
|
|
11332
|
+
tunaPositionAtaA,
|
|
11333
|
+
tunaPositionAtaB,
|
|
11334
|
+
tunaPositionOwnerAtaA,
|
|
11335
|
+
tunaPositionOwnerAtaB,
|
|
11336
|
+
feeRecipientAtaA,
|
|
11337
|
+
feeRecipientAtaB,
|
|
11338
|
+
pool: poolAddress,
|
|
11339
|
+
jupiterProgram: JUPITER_PROGRAM_ADDRESS,
|
|
11340
|
+
jupiterEventAuthority: JUPITER_EVENT_AUTHORITY,
|
|
11341
|
+
jupiterProgramAuthority: JUPITER_PROGRAM_AUTHORITY,
|
|
11342
|
+
memoProgram: import_memo10.MEMO_PROGRAM_ADDRESS,
|
|
11343
|
+
...args
|
|
11344
|
+
});
|
|
11345
|
+
ix.accounts.push(...remainingAccounts);
|
|
11346
|
+
return ix;
|
|
11347
|
+
}
|
|
11348
|
+
|
|
11349
|
+
// src/txbuilder/closeTunaSpotPosition.ts
|
|
11350
|
+
var import_token_202216 = require("@solana-program/token-2022");
|
|
11351
|
+
var import_assert14 = __toESM(require("assert"));
|
|
10935
11352
|
async function closeTunaSpotPositionInstructions(rpc, authority, poolAddress) {
|
|
10936
11353
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
10937
11354
|
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
10938
11355
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
10939
|
-
const [mintA, mintB] = await (0,
|
|
10940
|
-
(0,
|
|
10941
|
-
(0,
|
|
11356
|
+
const [mintA, mintB] = await (0, import_token_202216.fetchAllMaybeMint)(rpc, [tunaPosition.data.mintA, tunaPosition.data.mintB]);
|
|
11357
|
+
(0, import_assert14.default)(mintA.exists, "Token A account not found");
|
|
11358
|
+
(0, import_assert14.default)(mintB.exists, "Token B account not found");
|
|
10942
11359
|
const ix = await closeTunaSpotPositionInstruction(authority, poolAddress, mintA, mintB);
|
|
10943
11360
|
return [ix];
|
|
10944
11361
|
}
|
|
10945
11362
|
async function closeTunaSpotPositionInstruction(authority, poolAddress, mintA, mintB) {
|
|
10946
11363
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
10947
|
-
const tunaPositionAtaA = (await (0,
|
|
11364
|
+
const tunaPositionAtaA = (await (0, import_token_202216.findAssociatedTokenPda)({
|
|
10948
11365
|
owner: tunaPositionAddress,
|
|
10949
11366
|
mint: mintA.address,
|
|
10950
11367
|
tokenProgram: mintA.programAddress
|
|
10951
11368
|
}))[0];
|
|
10952
|
-
const tunaPositionAtaB = (await (0,
|
|
11369
|
+
const tunaPositionAtaB = (await (0, import_token_202216.findAssociatedTokenPda)({
|
|
10953
11370
|
owner: tunaPositionAddress,
|
|
10954
11371
|
mint: mintB.address,
|
|
10955
11372
|
tokenProgram: mintB.programAddress
|
|
@@ -10993,11 +11410,11 @@ async function createTunaConfigInstruction(authority, ownerAuthority, adminAutho
|
|
|
10993
11410
|
}
|
|
10994
11411
|
|
|
10995
11412
|
// src/txbuilder/createVault.ts
|
|
10996
|
-
var
|
|
11413
|
+
var import_token_202217 = require("@solana-program/token-2022");
|
|
10997
11414
|
async function createVaultInstructions(authority, mint, args) {
|
|
10998
11415
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
10999
11416
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
11000
|
-
const vaultAta = (await (0,
|
|
11417
|
+
const vaultAta = (await (0, import_token_202217.findAssociatedTokenPda)({
|
|
11001
11418
|
owner: vault,
|
|
11002
11419
|
mint: mint.address,
|
|
11003
11420
|
tokenProgram: mint.programAddress
|
|
@@ -11017,10 +11434,10 @@ async function createVaultInstructions(authority, mint, args) {
|
|
|
11017
11434
|
}
|
|
11018
11435
|
|
|
11019
11436
|
// src/txbuilder/liquidateTunaLpPositionOrca.ts
|
|
11020
|
-
var
|
|
11021
|
-
var
|
|
11022
|
-
var
|
|
11023
|
-
var
|
|
11437
|
+
var import_whirlpools_client9 = require("@orca-so/whirlpools-client");
|
|
11438
|
+
var import_kit116 = require("@solana/kit");
|
|
11439
|
+
var import_memo11 = require("@solana-program/memo");
|
|
11440
|
+
var import_token_202218 = require("@solana-program/token-2022");
|
|
11024
11441
|
async function liquidateTunaLpPositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11025
11442
|
const instructions = [];
|
|
11026
11443
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
@@ -11058,39 +11475,39 @@ async function liquidateTunaLpPositionOrcaInstructions(authority, tunaPosition,
|
|
|
11058
11475
|
async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11059
11476
|
const positionMint = tunaPosition.data.positionMint;
|
|
11060
11477
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11061
|
-
const orcaPositionAddress = (await (0,
|
|
11062
|
-
const orcaOracleAddress = (await (0,
|
|
11063
|
-
const tunaPositionAta = (await (0,
|
|
11478
|
+
const orcaPositionAddress = (await (0, import_whirlpools_client9.getPositionAddress)(positionMint))[0];
|
|
11479
|
+
const orcaOracleAddress = (await (0, import_whirlpools_client9.getOracleAddress)(whirlpool.address))[0];
|
|
11480
|
+
const tunaPositionAta = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11064
11481
|
owner: tunaPosition.address,
|
|
11065
11482
|
mint: positionMint,
|
|
11066
|
-
tokenProgram:
|
|
11483
|
+
tokenProgram: import_token_202218.TOKEN_2022_PROGRAM_ADDRESS
|
|
11067
11484
|
}))[0];
|
|
11068
|
-
const tunaPositionAtaA = (await (0,
|
|
11485
|
+
const tunaPositionAtaA = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11069
11486
|
owner: tunaPosition.address,
|
|
11070
11487
|
mint: mintA.address,
|
|
11071
11488
|
tokenProgram: mintA.programAddress
|
|
11072
11489
|
}))[0];
|
|
11073
|
-
const tunaPositionAtaB = (await (0,
|
|
11490
|
+
const tunaPositionAtaB = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11074
11491
|
owner: tunaPosition.address,
|
|
11075
11492
|
mint: mintB.address,
|
|
11076
11493
|
tokenProgram: mintB.programAddress
|
|
11077
11494
|
}))[0];
|
|
11078
|
-
const vaultAAta = (await (0,
|
|
11495
|
+
const vaultAAta = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11079
11496
|
owner: vaultA.address,
|
|
11080
11497
|
mint: mintA.address,
|
|
11081
11498
|
tokenProgram: mintA.programAddress
|
|
11082
11499
|
}))[0];
|
|
11083
|
-
const vaultBAta = (await (0,
|
|
11500
|
+
const vaultBAta = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11084
11501
|
owner: vaultB.address,
|
|
11085
11502
|
mint: mintB.address,
|
|
11086
11503
|
tokenProgram: mintB.programAddress
|
|
11087
11504
|
}))[0];
|
|
11088
|
-
const feeRecipientAtaA = (await (0,
|
|
11505
|
+
const feeRecipientAtaA = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11089
11506
|
owner: tunaConfig.data.feeRecipient,
|
|
11090
11507
|
mint: mintA.address,
|
|
11091
11508
|
tokenProgram: mintA.programAddress
|
|
11092
11509
|
}))[0];
|
|
11093
|
-
const feeRecipientAtaB = (await (0,
|
|
11510
|
+
const feeRecipientAtaB = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11094
11511
|
owner: tunaConfig.data.feeRecipient,
|
|
11095
11512
|
mint: mintB.address,
|
|
11096
11513
|
tokenProgram: mintB.programAddress
|
|
@@ -11105,16 +11522,16 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11105
11522
|
tunaPosition.data.tickUpperIndex
|
|
11106
11523
|
);
|
|
11107
11524
|
const remainingAccounts = [
|
|
11108
|
-
{ address: swapTickArrays[0], role:
|
|
11109
|
-
{ address: swapTickArrays[1], role:
|
|
11110
|
-
{ address: swapTickArrays[2], role:
|
|
11111
|
-
{ address: swapTickArrays[3], role:
|
|
11112
|
-
{ address: swapTickArrays[4], role:
|
|
11113
|
-
{ address: lowerTickArrayAddress, role:
|
|
11114
|
-
{ address: upperTickArrayAddress, role:
|
|
11115
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
11116
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
11117
|
-
{ address: orcaOracleAddress, role:
|
|
11525
|
+
{ address: swapTickArrays[0], role: import_kit116.AccountRole.WRITABLE },
|
|
11526
|
+
{ address: swapTickArrays[1], role: import_kit116.AccountRole.WRITABLE },
|
|
11527
|
+
{ address: swapTickArrays[2], role: import_kit116.AccountRole.WRITABLE },
|
|
11528
|
+
{ address: swapTickArrays[3], role: import_kit116.AccountRole.WRITABLE },
|
|
11529
|
+
{ address: swapTickArrays[4], role: import_kit116.AccountRole.WRITABLE },
|
|
11530
|
+
{ address: lowerTickArrayAddress, role: import_kit116.AccountRole.WRITABLE },
|
|
11531
|
+
{ address: upperTickArrayAddress, role: import_kit116.AccountRole.WRITABLE },
|
|
11532
|
+
{ address: whirlpool.data.tokenVaultA, role: import_kit116.AccountRole.WRITABLE },
|
|
11533
|
+
{ address: whirlpool.data.tokenVaultB, role: import_kit116.AccountRole.WRITABLE },
|
|
11534
|
+
{ address: orcaOracleAddress, role: import_kit116.AccountRole.WRITABLE }
|
|
11118
11535
|
];
|
|
11119
11536
|
const remainingAccountsInfo = {
|
|
11120
11537
|
slices: [
|
|
@@ -11146,10 +11563,10 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11146
11563
|
feeRecipientAtaA,
|
|
11147
11564
|
feeRecipientAtaB,
|
|
11148
11565
|
whirlpool: whirlpool.address,
|
|
11149
|
-
whirlpoolProgram:
|
|
11566
|
+
whirlpoolProgram: import_whirlpools_client9.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11150
11567
|
tokenProgramA: mintA.programAddress,
|
|
11151
11568
|
tokenProgramB: mintB.programAddress,
|
|
11152
|
-
memoProgram:
|
|
11569
|
+
memoProgram: import_memo11.MEMO_PROGRAM_ADDRESS,
|
|
11153
11570
|
decreasePercent,
|
|
11154
11571
|
remainingAccountsInfo
|
|
11155
11572
|
});
|
|
@@ -11158,10 +11575,10 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11158
11575
|
}
|
|
11159
11576
|
|
|
11160
11577
|
// src/txbuilder/liquidateTunaLpPositionFusion.ts
|
|
11161
|
-
var
|
|
11162
|
-
var
|
|
11163
|
-
var
|
|
11164
|
-
var
|
|
11578
|
+
var import_fusionamm_client9 = require("@crypticdot/fusionamm-client");
|
|
11579
|
+
var import_kit117 = require("@solana/kit");
|
|
11580
|
+
var import_memo12 = require("@solana-program/memo");
|
|
11581
|
+
var import_token_202219 = require("@solana-program/token-2022");
|
|
11165
11582
|
async function liquidateTunaLpPositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11166
11583
|
const instructions = [];
|
|
11167
11584
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
@@ -11199,38 +11616,38 @@ async function liquidateTunaLpPositionFusionInstructions(authority, tunaPosition
|
|
|
11199
11616
|
async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, decreasePercent) {
|
|
11200
11617
|
const positionMint = tunaPosition.data.positionMint;
|
|
11201
11618
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11202
|
-
const fusionPositionAddress = (await (0,
|
|
11203
|
-
const tunaPositionAta = (await (0,
|
|
11619
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client9.getPositionAddress)(positionMint))[0];
|
|
11620
|
+
const tunaPositionAta = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11204
11621
|
owner: tunaPosition.address,
|
|
11205
11622
|
mint: positionMint,
|
|
11206
|
-
tokenProgram:
|
|
11623
|
+
tokenProgram: import_token_202219.TOKEN_2022_PROGRAM_ADDRESS
|
|
11207
11624
|
}))[0];
|
|
11208
|
-
const tunaPositionAtaA = (await (0,
|
|
11625
|
+
const tunaPositionAtaA = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11209
11626
|
owner: tunaPosition.address,
|
|
11210
11627
|
mint: mintA.address,
|
|
11211
11628
|
tokenProgram: mintA.programAddress
|
|
11212
11629
|
}))[0];
|
|
11213
|
-
const tunaPositionAtaB = (await (0,
|
|
11630
|
+
const tunaPositionAtaB = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11214
11631
|
owner: tunaPosition.address,
|
|
11215
11632
|
mint: mintB.address,
|
|
11216
11633
|
tokenProgram: mintB.programAddress
|
|
11217
11634
|
}))[0];
|
|
11218
|
-
const vaultAAta = (await (0,
|
|
11635
|
+
const vaultAAta = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11219
11636
|
owner: vaultA.address,
|
|
11220
11637
|
mint: mintA.address,
|
|
11221
11638
|
tokenProgram: mintA.programAddress
|
|
11222
11639
|
}))[0];
|
|
11223
|
-
const vaultBAta = (await (0,
|
|
11640
|
+
const vaultBAta = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11224
11641
|
owner: vaultB.address,
|
|
11225
11642
|
mint: mintB.address,
|
|
11226
11643
|
tokenProgram: mintB.programAddress
|
|
11227
11644
|
}))[0];
|
|
11228
|
-
const feeRecipientAtaA = (await (0,
|
|
11645
|
+
const feeRecipientAtaA = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11229
11646
|
owner: tunaConfig.data.feeRecipient,
|
|
11230
11647
|
mint: mintA.address,
|
|
11231
11648
|
tokenProgram: mintA.programAddress
|
|
11232
11649
|
}))[0];
|
|
11233
|
-
const feeRecipientAtaB = (await (0,
|
|
11650
|
+
const feeRecipientAtaB = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11234
11651
|
owner: tunaConfig.data.feeRecipient,
|
|
11235
11652
|
mint: mintB.address,
|
|
11236
11653
|
tokenProgram: mintB.programAddress
|
|
@@ -11245,15 +11662,15 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11245
11662
|
tunaPosition.data.tickUpperIndex
|
|
11246
11663
|
);
|
|
11247
11664
|
const remainingAccounts = [
|
|
11248
|
-
{ address: swapTickArrays[0], role:
|
|
11249
|
-
{ address: swapTickArrays[1], role:
|
|
11250
|
-
{ address: swapTickArrays[2], role:
|
|
11251
|
-
{ address: swapTickArrays[3], role:
|
|
11252
|
-
{ address: swapTickArrays[4], role:
|
|
11253
|
-
{ address: lowerTickArrayAddress, role:
|
|
11254
|
-
{ address: upperTickArrayAddress, role:
|
|
11255
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
11256
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
11665
|
+
{ address: swapTickArrays[0], role: import_kit117.AccountRole.WRITABLE },
|
|
11666
|
+
{ address: swapTickArrays[1], role: import_kit117.AccountRole.WRITABLE },
|
|
11667
|
+
{ address: swapTickArrays[2], role: import_kit117.AccountRole.WRITABLE },
|
|
11668
|
+
{ address: swapTickArrays[3], role: import_kit117.AccountRole.WRITABLE },
|
|
11669
|
+
{ address: swapTickArrays[4], role: import_kit117.AccountRole.WRITABLE },
|
|
11670
|
+
{ address: lowerTickArrayAddress, role: import_kit117.AccountRole.WRITABLE },
|
|
11671
|
+
{ address: upperTickArrayAddress, role: import_kit117.AccountRole.WRITABLE },
|
|
11672
|
+
{ address: fusionPool.data.tokenVaultA, role: import_kit117.AccountRole.WRITABLE },
|
|
11673
|
+
{ address: fusionPool.data.tokenVaultB, role: import_kit117.AccountRole.WRITABLE }
|
|
11257
11674
|
];
|
|
11258
11675
|
const remainingAccountsInfo = {
|
|
11259
11676
|
slices: [
|
|
@@ -11284,10 +11701,10 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11284
11701
|
feeRecipientAtaA,
|
|
11285
11702
|
feeRecipientAtaB,
|
|
11286
11703
|
fusionPool: fusionPool.address,
|
|
11287
|
-
fusionammProgram:
|
|
11704
|
+
fusionammProgram: import_fusionamm_client9.FUSIONAMM_PROGRAM_ADDRESS,
|
|
11288
11705
|
tokenProgramA: mintA.programAddress,
|
|
11289
11706
|
tokenProgramB: mintB.programAddress,
|
|
11290
|
-
memoProgram:
|
|
11707
|
+
memoProgram: import_memo12.MEMO_PROGRAM_ADDRESS,
|
|
11291
11708
|
decreasePercent,
|
|
11292
11709
|
remainingAccountsInfo
|
|
11293
11710
|
});
|
|
@@ -11296,10 +11713,10 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11296
11713
|
}
|
|
11297
11714
|
|
|
11298
11715
|
// src/txbuilder/liquidateTunaSpotPositionFusion.ts
|
|
11299
|
-
var
|
|
11300
|
-
var
|
|
11301
|
-
var
|
|
11302
|
-
var
|
|
11716
|
+
var import_fusionamm_client10 = require("@crypticdot/fusionamm-client");
|
|
11717
|
+
var import_kit118 = require("@solana/kit");
|
|
11718
|
+
var import_memo13 = require("@solana-program/memo");
|
|
11719
|
+
var import_token_202220 = require("@solana-program/token-2022");
|
|
11303
11720
|
async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, createTunaPositionOwnerAta, decreasePercent) {
|
|
11304
11721
|
const instructions = [];
|
|
11305
11722
|
if (createTunaPositionOwnerAta) {
|
|
@@ -11347,55 +11764,55 @@ async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPositi
|
|
|
11347
11764
|
}
|
|
11348
11765
|
async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, decreasePercent) {
|
|
11349
11766
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11350
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
11767
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11351
11768
|
owner: tunaPosition.data.authority,
|
|
11352
11769
|
mint: mintA.address,
|
|
11353
11770
|
tokenProgram: mintA.programAddress
|
|
11354
11771
|
}))[0];
|
|
11355
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
11772
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11356
11773
|
owner: tunaPosition.data.authority,
|
|
11357
11774
|
mint: mintB.address,
|
|
11358
11775
|
tokenProgram: mintB.programAddress
|
|
11359
11776
|
}))[0];
|
|
11360
|
-
const tunaPositionAtaA = (await (0,
|
|
11777
|
+
const tunaPositionAtaA = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11361
11778
|
owner: tunaPosition.address,
|
|
11362
11779
|
mint: mintA.address,
|
|
11363
11780
|
tokenProgram: mintA.programAddress
|
|
11364
11781
|
}))[0];
|
|
11365
|
-
const tunaPositionAtaB = (await (0,
|
|
11782
|
+
const tunaPositionAtaB = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11366
11783
|
owner: tunaPosition.address,
|
|
11367
11784
|
mint: mintB.address,
|
|
11368
11785
|
tokenProgram: mintB.programAddress
|
|
11369
11786
|
}))[0];
|
|
11370
|
-
const feeRecipientAtaA = (await (0,
|
|
11787
|
+
const feeRecipientAtaA = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11371
11788
|
owner: tunaConfig.data.feeRecipient,
|
|
11372
11789
|
mint: mintA.address,
|
|
11373
11790
|
tokenProgram: mintA.programAddress
|
|
11374
11791
|
}))[0];
|
|
11375
|
-
const feeRecipientAtaB = (await (0,
|
|
11792
|
+
const feeRecipientAtaB = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11376
11793
|
owner: tunaConfig.data.feeRecipient,
|
|
11377
11794
|
mint: mintB.address,
|
|
11378
11795
|
tokenProgram: mintB.programAddress
|
|
11379
11796
|
}))[0];
|
|
11380
|
-
const vaultAAta = (await (0,
|
|
11797
|
+
const vaultAAta = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11381
11798
|
owner: vaultA.address,
|
|
11382
11799
|
mint: mintA.address,
|
|
11383
11800
|
tokenProgram: mintA.programAddress
|
|
11384
11801
|
}))[0];
|
|
11385
|
-
const vaultBAta = (await (0,
|
|
11802
|
+
const vaultBAta = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11386
11803
|
owner: vaultB.address,
|
|
11387
11804
|
mint: mintB.address,
|
|
11388
11805
|
tokenProgram: mintB.programAddress
|
|
11389
11806
|
}))[0];
|
|
11390
11807
|
const swapTickArrays = await FusionUtils.getSwapTickArrayAddresses(fusionPool);
|
|
11391
11808
|
const remainingAccounts = [
|
|
11392
|
-
{ address: swapTickArrays[0], role:
|
|
11393
|
-
{ address: swapTickArrays[1], role:
|
|
11394
|
-
{ address: swapTickArrays[2], role:
|
|
11395
|
-
{ address: swapTickArrays[3], role:
|
|
11396
|
-
{ address: swapTickArrays[4], role:
|
|
11397
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
11398
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
11809
|
+
{ address: swapTickArrays[0], role: import_kit118.AccountRole.WRITABLE },
|
|
11810
|
+
{ address: swapTickArrays[1], role: import_kit118.AccountRole.WRITABLE },
|
|
11811
|
+
{ address: swapTickArrays[2], role: import_kit118.AccountRole.WRITABLE },
|
|
11812
|
+
{ address: swapTickArrays[3], role: import_kit118.AccountRole.WRITABLE },
|
|
11813
|
+
{ address: swapTickArrays[4], role: import_kit118.AccountRole.WRITABLE },
|
|
11814
|
+
{ address: fusionPool.data.tokenVaultA, role: import_kit118.AccountRole.WRITABLE },
|
|
11815
|
+
{ address: fusionPool.data.tokenVaultB, role: import_kit118.AccountRole.WRITABLE }
|
|
11399
11816
|
];
|
|
11400
11817
|
const remainingAccountsInfo = {
|
|
11401
11818
|
slices: [
|
|
@@ -11427,8 +11844,8 @@ async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPositio
|
|
|
11427
11844
|
feeRecipientAtaA,
|
|
11428
11845
|
feeRecipientAtaB,
|
|
11429
11846
|
fusionPool: fusionPool.address,
|
|
11430
|
-
fusionammProgram:
|
|
11431
|
-
memoProgram:
|
|
11847
|
+
fusionammProgram: import_fusionamm_client10.FUSIONAMM_PROGRAM_ADDRESS,
|
|
11848
|
+
memoProgram: import_memo13.MEMO_PROGRAM_ADDRESS,
|
|
11432
11849
|
decreasePercent,
|
|
11433
11850
|
remainingAccountsInfo
|
|
11434
11851
|
});
|
|
@@ -11437,10 +11854,10 @@ async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPositio
|
|
|
11437
11854
|
}
|
|
11438
11855
|
|
|
11439
11856
|
// src/txbuilder/liquidateTunaSpotPositionOrca.ts
|
|
11440
|
-
var
|
|
11441
|
-
var
|
|
11442
|
-
var
|
|
11443
|
-
var
|
|
11857
|
+
var import_whirlpools_client10 = require("@orca-so/whirlpools-client");
|
|
11858
|
+
var import_kit119 = require("@solana/kit");
|
|
11859
|
+
var import_memo14 = require("@solana-program/memo");
|
|
11860
|
+
var import_token_202221 = require("@solana-program/token-2022");
|
|
11444
11861
|
async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, createTunaPositionOwnerAta, decreasePercent) {
|
|
11445
11862
|
const instructions = [];
|
|
11446
11863
|
if (createTunaPositionOwnerAta) {
|
|
@@ -11488,57 +11905,57 @@ async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition
|
|
|
11488
11905
|
}
|
|
11489
11906
|
async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11490
11907
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11491
|
-
const orcaOracleAddress = (await (0,
|
|
11492
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
11908
|
+
const orcaOracleAddress = (await (0, import_whirlpools_client10.getOracleAddress)(whirlpool.address))[0];
|
|
11909
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11493
11910
|
owner: tunaPosition.data.authority,
|
|
11494
11911
|
mint: mintA.address,
|
|
11495
11912
|
tokenProgram: mintA.programAddress
|
|
11496
11913
|
}))[0];
|
|
11497
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
11914
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11498
11915
|
owner: tunaPosition.data.authority,
|
|
11499
11916
|
mint: mintB.address,
|
|
11500
11917
|
tokenProgram: mintB.programAddress
|
|
11501
11918
|
}))[0];
|
|
11502
|
-
const tunaPositionAtaA = (await (0,
|
|
11919
|
+
const tunaPositionAtaA = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11503
11920
|
owner: tunaPosition.address,
|
|
11504
11921
|
mint: mintA.address,
|
|
11505
11922
|
tokenProgram: mintA.programAddress
|
|
11506
11923
|
}))[0];
|
|
11507
|
-
const tunaPositionAtaB = (await (0,
|
|
11924
|
+
const tunaPositionAtaB = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11508
11925
|
owner: tunaPosition.address,
|
|
11509
11926
|
mint: mintB.address,
|
|
11510
11927
|
tokenProgram: mintB.programAddress
|
|
11511
11928
|
}))[0];
|
|
11512
|
-
const feeRecipientAtaA = (await (0,
|
|
11929
|
+
const feeRecipientAtaA = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11513
11930
|
owner: tunaConfig.data.feeRecipient,
|
|
11514
11931
|
mint: mintA.address,
|
|
11515
11932
|
tokenProgram: mintA.programAddress
|
|
11516
11933
|
}))[0];
|
|
11517
|
-
const feeRecipientAtaB = (await (0,
|
|
11934
|
+
const feeRecipientAtaB = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11518
11935
|
owner: tunaConfig.data.feeRecipient,
|
|
11519
11936
|
mint: mintB.address,
|
|
11520
11937
|
tokenProgram: mintB.programAddress
|
|
11521
11938
|
}))[0];
|
|
11522
|
-
const vaultAAta = (await (0,
|
|
11939
|
+
const vaultAAta = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11523
11940
|
owner: vaultA.address,
|
|
11524
11941
|
mint: mintA.address,
|
|
11525
11942
|
tokenProgram: mintA.programAddress
|
|
11526
11943
|
}))[0];
|
|
11527
|
-
const vaultBAta = (await (0,
|
|
11944
|
+
const vaultBAta = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11528
11945
|
owner: vaultB.address,
|
|
11529
11946
|
mint: mintB.address,
|
|
11530
11947
|
tokenProgram: mintB.programAddress
|
|
11531
11948
|
}))[0];
|
|
11532
11949
|
const swapTickArrays = await OrcaUtils.getSwapTickArrayAddresses(whirlpool);
|
|
11533
11950
|
const remainingAccounts = [
|
|
11534
|
-
{ address: swapTickArrays[0], role:
|
|
11535
|
-
{ address: swapTickArrays[1], role:
|
|
11536
|
-
{ address: swapTickArrays[2], role:
|
|
11537
|
-
{ address: swapTickArrays[3], role:
|
|
11538
|
-
{ address: swapTickArrays[4], role:
|
|
11539
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
11540
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
11541
|
-
{ address: orcaOracleAddress, role:
|
|
11951
|
+
{ address: swapTickArrays[0], role: import_kit119.AccountRole.WRITABLE },
|
|
11952
|
+
{ address: swapTickArrays[1], role: import_kit119.AccountRole.WRITABLE },
|
|
11953
|
+
{ address: swapTickArrays[2], role: import_kit119.AccountRole.WRITABLE },
|
|
11954
|
+
{ address: swapTickArrays[3], role: import_kit119.AccountRole.WRITABLE },
|
|
11955
|
+
{ address: swapTickArrays[4], role: import_kit119.AccountRole.WRITABLE },
|
|
11956
|
+
{ address: whirlpool.data.tokenVaultA, role: import_kit119.AccountRole.WRITABLE },
|
|
11957
|
+
{ address: whirlpool.data.tokenVaultB, role: import_kit119.AccountRole.WRITABLE },
|
|
11958
|
+
{ address: orcaOracleAddress, role: import_kit119.AccountRole.WRITABLE }
|
|
11542
11959
|
];
|
|
11543
11960
|
const remainingAccountsInfo = {
|
|
11544
11961
|
slices: [
|
|
@@ -11571,8 +11988,8 @@ async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition,
|
|
|
11571
11988
|
feeRecipientAtaA,
|
|
11572
11989
|
feeRecipientAtaB,
|
|
11573
11990
|
whirlpool: whirlpool.address,
|
|
11574
|
-
whirlpoolProgram:
|
|
11575
|
-
memoProgram:
|
|
11991
|
+
whirlpoolProgram: import_whirlpools_client10.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11992
|
+
memoProgram: import_memo14.MEMO_PROGRAM_ADDRESS,
|
|
11576
11993
|
decreasePercent,
|
|
11577
11994
|
remainingAccountsInfo
|
|
11578
11995
|
});
|
|
@@ -11581,29 +11998,29 @@ async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition,
|
|
|
11581
11998
|
}
|
|
11582
11999
|
|
|
11583
12000
|
// src/txbuilder/openTunaLpPositionOrca.ts
|
|
11584
|
-
var
|
|
11585
|
-
var
|
|
11586
|
-
var
|
|
12001
|
+
var import_whirlpools_client11 = require("@orca-so/whirlpools-client");
|
|
12002
|
+
var import_token_202222 = require("@solana-program/token-2022");
|
|
12003
|
+
var import_assert15 = __toESM(require("assert"));
|
|
11587
12004
|
async function openTunaLpPositionOrcaInstruction(rpc, authority, positionMint, whirlpoolAddress, args) {
|
|
11588
|
-
const whirlpool = await (0,
|
|
12005
|
+
const whirlpool = await (0, import_whirlpools_client11.fetchMaybeWhirlpool)(rpc, whirlpoolAddress);
|
|
11589
12006
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
11590
|
-
const [mintA, mintB] = await (0,
|
|
11591
|
-
(0,
|
|
11592
|
-
(0,
|
|
12007
|
+
const [mintA, mintB] = await (0, import_token_202222.fetchAllMaybeMint)(rpc, [whirlpool.data.tokenMintA, whirlpool.data.tokenMintB]);
|
|
12008
|
+
(0, import_assert15.default)(mintA.exists, "Token A account not found");
|
|
12009
|
+
(0, import_assert15.default)(mintB.exists, "Token B account not found");
|
|
11593
12010
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11594
|
-
const orcaPositionAddress = (await (0,
|
|
12011
|
+
const orcaPositionAddress = (await (0, import_whirlpools_client11.getPositionAddress)(positionMint.address))[0];
|
|
11595
12012
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
11596
|
-
const tunaPositionAta = (await (0,
|
|
12013
|
+
const tunaPositionAta = (await (0, import_token_202222.findAssociatedTokenPda)({
|
|
11597
12014
|
owner: tunaPositionAddress,
|
|
11598
12015
|
mint: positionMint.address,
|
|
11599
|
-
tokenProgram:
|
|
12016
|
+
tokenProgram: import_token_202222.TOKEN_2022_PROGRAM_ADDRESS
|
|
11600
12017
|
}))[0];
|
|
11601
|
-
const tunaPositionAtaA = (await (0,
|
|
12018
|
+
const tunaPositionAtaA = (await (0, import_token_202222.findAssociatedTokenPda)({
|
|
11602
12019
|
owner: tunaPositionAddress,
|
|
11603
12020
|
mint: mintA.address,
|
|
11604
12021
|
tokenProgram: mintA.programAddress
|
|
11605
12022
|
}))[0];
|
|
11606
|
-
const tunaPositionAtaB = (await (0,
|
|
12023
|
+
const tunaPositionAtaB = (await (0, import_token_202222.findAssociatedTokenPda)({
|
|
11607
12024
|
owner: tunaPositionAddress,
|
|
11608
12025
|
mint: mintB.address,
|
|
11609
12026
|
tokenProgram: mintB.programAddress
|
|
@@ -11619,42 +12036,42 @@ async function openTunaLpPositionOrcaInstruction(rpc, authority, positionMint, w
|
|
|
11619
12036
|
tunaPositionAta,
|
|
11620
12037
|
tunaPositionAtaA,
|
|
11621
12038
|
tunaPositionAtaB,
|
|
11622
|
-
whirlpoolProgram:
|
|
12039
|
+
whirlpoolProgram: import_whirlpools_client11.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11623
12040
|
whirlpool: whirlpool.address,
|
|
11624
12041
|
metadataUpdateAuth: WP_NFT_UPDATE_AUTH,
|
|
11625
12042
|
tokenProgramA: mintA.programAddress,
|
|
11626
12043
|
tokenProgramB: mintB.programAddress,
|
|
11627
|
-
associatedTokenProgram:
|
|
11628
|
-
token2022Program:
|
|
12044
|
+
associatedTokenProgram: import_token_202222.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12045
|
+
token2022Program: import_token_202222.TOKEN_2022_PROGRAM_ADDRESS,
|
|
11629
12046
|
...args
|
|
11630
12047
|
});
|
|
11631
12048
|
}
|
|
11632
12049
|
|
|
11633
12050
|
// src/txbuilder/openTunaLpPositionFusion.ts
|
|
11634
|
-
var import_fusionamm_client10 = require("@crypticdot/fusionamm-client");
|
|
11635
12051
|
var import_fusionamm_client11 = require("@crypticdot/fusionamm-client");
|
|
11636
|
-
var
|
|
11637
|
-
var
|
|
12052
|
+
var import_fusionamm_client12 = require("@crypticdot/fusionamm-client");
|
|
12053
|
+
var import_token_202223 = require("@solana-program/token-2022");
|
|
12054
|
+
var import_assert16 = __toESM(require("assert"));
|
|
11638
12055
|
async function openTunaLpPositionFusionInstruction(rpc, authority, positionMint, fusionPoolAddress, args) {
|
|
11639
|
-
const fusionPool = await (0,
|
|
12056
|
+
const fusionPool = await (0, import_fusionamm_client11.fetchMaybeFusionPool)(rpc, fusionPoolAddress);
|
|
11640
12057
|
if (!fusionPool.exists) throw new Error("Whirlpool account not found");
|
|
11641
|
-
const [mintA, mintB] = await (0,
|
|
11642
|
-
(0,
|
|
11643
|
-
(0,
|
|
12058
|
+
const [mintA, mintB] = await (0, import_token_202223.fetchAllMaybeMint)(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
12059
|
+
(0, import_assert16.default)(mintA.exists, "Token A account not found");
|
|
12060
|
+
(0, import_assert16.default)(mintB.exists, "Token B account not found");
|
|
11644
12061
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11645
|
-
const fusionPositionAddress = (await (0,
|
|
12062
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client11.getPositionAddress)(positionMint.address))[0];
|
|
11646
12063
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
11647
|
-
const tunaPositionAta = (await (0,
|
|
12064
|
+
const tunaPositionAta = (await (0, import_token_202223.findAssociatedTokenPda)({
|
|
11648
12065
|
owner: tunaPositionAddress,
|
|
11649
12066
|
mint: positionMint.address,
|
|
11650
|
-
tokenProgram:
|
|
12067
|
+
tokenProgram: import_token_202223.TOKEN_2022_PROGRAM_ADDRESS
|
|
11651
12068
|
}))[0];
|
|
11652
|
-
const tunaPositionAtaA = (await (0,
|
|
12069
|
+
const tunaPositionAtaA = (await (0, import_token_202223.findAssociatedTokenPda)({
|
|
11653
12070
|
owner: tunaPositionAddress,
|
|
11654
12071
|
mint: mintA.address,
|
|
11655
12072
|
tokenProgram: mintA.programAddress
|
|
11656
12073
|
}))[0];
|
|
11657
|
-
const tunaPositionAtaB = (await (0,
|
|
12074
|
+
const tunaPositionAtaB = (await (0, import_token_202223.findAssociatedTokenPda)({
|
|
11658
12075
|
owner: tunaPositionAddress,
|
|
11659
12076
|
mint: mintB.address,
|
|
11660
12077
|
tokenProgram: mintB.programAddress
|
|
@@ -11670,25 +12087,25 @@ async function openTunaLpPositionFusionInstruction(rpc, authority, positionMint,
|
|
|
11670
12087
|
tunaPositionAta,
|
|
11671
12088
|
tunaPositionAtaA,
|
|
11672
12089
|
tunaPositionAtaB,
|
|
11673
|
-
fusionammProgram:
|
|
12090
|
+
fusionammProgram: import_fusionamm_client11.FUSIONAMM_PROGRAM_ADDRESS,
|
|
11674
12091
|
fusionPool: fusionPool.address,
|
|
11675
|
-
metadataUpdateAuth:
|
|
12092
|
+
metadataUpdateAuth: import_fusionamm_client12.FP_NFT_UPDATE_AUTH,
|
|
11676
12093
|
tokenProgramA: mintA.programAddress,
|
|
11677
12094
|
tokenProgramB: mintB.programAddress,
|
|
11678
|
-
associatedTokenProgram:
|
|
11679
|
-
token2022Program:
|
|
12095
|
+
associatedTokenProgram: import_token_202223.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12096
|
+
token2022Program: import_token_202223.TOKEN_2022_PROGRAM_ADDRESS,
|
|
11680
12097
|
...args
|
|
11681
12098
|
});
|
|
11682
12099
|
}
|
|
11683
12100
|
|
|
11684
12101
|
// src/txbuilder/openAndIncreaseTunaLpPositionOrca.ts
|
|
11685
|
-
var
|
|
12102
|
+
var import_whirlpools_client12 = require("@orca-so/whirlpools-client");
|
|
11686
12103
|
var import_whirlpools_core4 = require("@orca-so/whirlpools-core");
|
|
11687
|
-
var
|
|
12104
|
+
var import_kit120 = require("@solana/kit");
|
|
11688
12105
|
var import_sysvars = require("@solana/sysvars");
|
|
11689
|
-
var
|
|
11690
|
-
var
|
|
11691
|
-
var
|
|
12106
|
+
var import_memo15 = require("@solana-program/memo");
|
|
12107
|
+
var import_token_202224 = require("@solana-program/token-2022");
|
|
12108
|
+
var import_assert17 = __toESM(require("assert"));
|
|
11692
12109
|
|
|
11693
12110
|
// src/utils/sysvar.ts
|
|
11694
12111
|
var ACCOUNT_STORAGE_OVERHEAD = 128;
|
|
@@ -11706,15 +12123,15 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11706
12123
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
11707
12124
|
const rent = await (0, import_sysvars.fetchSysvarRent)(rpc);
|
|
11708
12125
|
let nonRefundableRent = 0n;
|
|
11709
|
-
const positionMint = await (0,
|
|
12126
|
+
const positionMint = await (0, import_kit120.generateKeyPairSigner)();
|
|
11710
12127
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
11711
|
-
const whirlpool = await (0,
|
|
12128
|
+
const whirlpool = await (0, import_whirlpools_client12.fetchMaybeWhirlpool)(rpc, whirlpoolAddress);
|
|
11712
12129
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
11713
12130
|
const marketAddress = (await getMarketAddress(whirlpoolAddress))[0];
|
|
11714
12131
|
const market = await fetchMarket(rpc, marketAddress);
|
|
11715
|
-
const [mintA, mintB] = await (0,
|
|
11716
|
-
(0,
|
|
11717
|
-
(0,
|
|
12132
|
+
const [mintA, mintB] = await (0, import_token_202224.fetchAllMaybeMint)(rpc, [whirlpool.data.tokenMintA, whirlpool.data.tokenMintB]);
|
|
12133
|
+
(0, import_assert17.default)(mintA.exists, "Token A account not found");
|
|
12134
|
+
(0, import_assert17.default)(mintB.exists, "Token B account not found");
|
|
11718
12135
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
11719
12136
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
11720
12137
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
@@ -11767,16 +12184,16 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11767
12184
|
);
|
|
11768
12185
|
createInstructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
11769
12186
|
const lowerTickArrayIndex = (0, import_whirlpools_core4.getTickArrayStartTickIndex)(args.tickLowerIndex, whirlpool.data.tickSpacing);
|
|
11770
|
-
const [lowerTickArrayAddress] = await (0,
|
|
12187
|
+
const [lowerTickArrayAddress] = await (0, import_whirlpools_client12.getTickArrayAddress)(whirlpool.address, lowerTickArrayIndex);
|
|
11771
12188
|
const upperTickArrayIndex = (0, import_whirlpools_core4.getTickArrayStartTickIndex)(args.tickUpperIndex, whirlpool.data.tickSpacing);
|
|
11772
|
-
const [upperTickArrayAddress] = await (0,
|
|
11773
|
-
const [lowerTickArray, upperTickArray] = await (0,
|
|
12189
|
+
const [upperTickArrayAddress] = await (0, import_whirlpools_client12.getTickArrayAddress)(whirlpool.address, upperTickArrayIndex);
|
|
12190
|
+
const [lowerTickArray, upperTickArray] = await (0, import_whirlpools_client12.fetchAllMaybeTickArray)(rpc, [
|
|
11774
12191
|
lowerTickArrayAddress,
|
|
11775
12192
|
upperTickArrayAddress
|
|
11776
12193
|
]);
|
|
11777
12194
|
if (!lowerTickArray.exists) {
|
|
11778
12195
|
instructions.push(
|
|
11779
|
-
(0,
|
|
12196
|
+
(0, import_whirlpools_client12.getInitializeDynamicTickArrayInstruction)({
|
|
11780
12197
|
whirlpool: whirlpool.address,
|
|
11781
12198
|
funder: authority,
|
|
11782
12199
|
tickArray: lowerTickArrayAddress,
|
|
@@ -11784,11 +12201,11 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11784
12201
|
idempotent: false
|
|
11785
12202
|
})
|
|
11786
12203
|
);
|
|
11787
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
12204
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client12.getDynamicTickArrayMinSize)());
|
|
11788
12205
|
}
|
|
11789
12206
|
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
11790
12207
|
instructions.push(
|
|
11791
|
-
(0,
|
|
12208
|
+
(0, import_whirlpools_client12.getInitializeDynamicTickArrayInstruction)({
|
|
11792
12209
|
whirlpool: whirlpool.address,
|
|
11793
12210
|
funder: authority,
|
|
11794
12211
|
tickArray: upperTickArrayAddress,
|
|
@@ -11796,7 +12213,7 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11796
12213
|
idempotent: false
|
|
11797
12214
|
})
|
|
11798
12215
|
);
|
|
11799
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
12216
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client12.getDynamicTickArrayMinSize)());
|
|
11800
12217
|
}
|
|
11801
12218
|
const ix = await openAndIncreaseTunaLpPositionOrcaInstruction(
|
|
11802
12219
|
authority,
|
|
@@ -11815,55 +12232,55 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11815
12232
|
return {
|
|
11816
12233
|
instructions,
|
|
11817
12234
|
positionMint: positionMint.address,
|
|
11818
|
-
initializationCost: (0,
|
|
12235
|
+
initializationCost: (0, import_kit120.lamports)(nonRefundableRent)
|
|
11819
12236
|
};
|
|
11820
12237
|
}
|
|
11821
12238
|
async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, args) {
|
|
11822
12239
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
11823
12240
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11824
|
-
const orcaPositionAddress = (await (0,
|
|
11825
|
-
const orcaOracleAddress = (await (0,
|
|
11826
|
-
const tunaPositionAta = (await (0,
|
|
12241
|
+
const orcaPositionAddress = (await (0, import_whirlpools_client12.getPositionAddress)(positionMint.address))[0];
|
|
12242
|
+
const orcaOracleAddress = (await (0, import_whirlpools_client12.getOracleAddress)(whirlpool.address))[0];
|
|
12243
|
+
const tunaPositionAta = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11827
12244
|
owner: tunaPositionAddress,
|
|
11828
12245
|
mint: positionMint.address,
|
|
11829
|
-
tokenProgram:
|
|
12246
|
+
tokenProgram: import_token_202224.TOKEN_2022_PROGRAM_ADDRESS
|
|
11830
12247
|
}))[0];
|
|
11831
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
12248
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11832
12249
|
owner: authority.address,
|
|
11833
12250
|
mint: mintA.address,
|
|
11834
12251
|
tokenProgram: mintA.programAddress
|
|
11835
12252
|
}))[0];
|
|
11836
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
12253
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11837
12254
|
owner: authority.address,
|
|
11838
12255
|
mint: mintB.address,
|
|
11839
12256
|
tokenProgram: mintB.programAddress
|
|
11840
12257
|
}))[0];
|
|
11841
|
-
const tunaPositionAtaA = (await (0,
|
|
12258
|
+
const tunaPositionAtaA = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11842
12259
|
owner: tunaPositionAddress,
|
|
11843
12260
|
mint: mintA.address,
|
|
11844
12261
|
tokenProgram: mintA.programAddress
|
|
11845
12262
|
}))[0];
|
|
11846
|
-
const tunaPositionAtaB = (await (0,
|
|
12263
|
+
const tunaPositionAtaB = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11847
12264
|
owner: tunaPositionAddress,
|
|
11848
12265
|
mint: mintB.address,
|
|
11849
12266
|
tokenProgram: mintB.programAddress
|
|
11850
12267
|
}))[0];
|
|
11851
|
-
const vaultAAta = (await (0,
|
|
12268
|
+
const vaultAAta = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11852
12269
|
owner: vaultA.address,
|
|
11853
12270
|
mint: mintA.address,
|
|
11854
12271
|
tokenProgram: mintA.programAddress
|
|
11855
12272
|
}))[0];
|
|
11856
|
-
const vaultBAta = (await (0,
|
|
12273
|
+
const vaultBAta = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11857
12274
|
owner: vaultB.address,
|
|
11858
12275
|
mint: mintB.address,
|
|
11859
12276
|
tokenProgram: mintB.programAddress
|
|
11860
12277
|
}))[0];
|
|
11861
|
-
const feeRecipientAtaA = (await (0,
|
|
12278
|
+
const feeRecipientAtaA = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11862
12279
|
owner: tunaConfig.data.feeRecipient,
|
|
11863
12280
|
mint: mintA.address,
|
|
11864
12281
|
tokenProgram: mintA.programAddress
|
|
11865
12282
|
}))[0];
|
|
11866
|
-
const feeRecipientAtaB = (await (0,
|
|
12283
|
+
const feeRecipientAtaB = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11867
12284
|
owner: tunaConfig.data.feeRecipient,
|
|
11868
12285
|
mint: mintB.address,
|
|
11869
12286
|
tokenProgram: mintB.programAddress
|
|
@@ -11872,16 +12289,16 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
11872
12289
|
const lowerTickArrayAddress = await OrcaUtils.getTickArrayAddressFromTickIndex(whirlpool, args.tickLowerIndex);
|
|
11873
12290
|
const upperTickArrayAddress = await OrcaUtils.getTickArrayAddressFromTickIndex(whirlpool, args.tickUpperIndex);
|
|
11874
12291
|
const remainingAccounts = [
|
|
11875
|
-
{ address: swapTickArrays[0], role:
|
|
11876
|
-
{ address: swapTickArrays[1], role:
|
|
11877
|
-
{ address: swapTickArrays[2], role:
|
|
11878
|
-
{ address: swapTickArrays[3], role:
|
|
11879
|
-
{ address: swapTickArrays[4], role:
|
|
11880
|
-
{ address: lowerTickArrayAddress, role:
|
|
11881
|
-
{ address: upperTickArrayAddress, role:
|
|
11882
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
11883
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
11884
|
-
{ address: orcaOracleAddress, role:
|
|
12292
|
+
{ address: swapTickArrays[0], role: import_kit120.AccountRole.WRITABLE },
|
|
12293
|
+
{ address: swapTickArrays[1], role: import_kit120.AccountRole.WRITABLE },
|
|
12294
|
+
{ address: swapTickArrays[2], role: import_kit120.AccountRole.WRITABLE },
|
|
12295
|
+
{ address: swapTickArrays[3], role: import_kit120.AccountRole.WRITABLE },
|
|
12296
|
+
{ address: swapTickArrays[4], role: import_kit120.AccountRole.WRITABLE },
|
|
12297
|
+
{ address: lowerTickArrayAddress, role: import_kit120.AccountRole.WRITABLE },
|
|
12298
|
+
{ address: upperTickArrayAddress, role: import_kit120.AccountRole.WRITABLE },
|
|
12299
|
+
{ address: whirlpool.data.tokenVaultA, role: import_kit120.AccountRole.WRITABLE },
|
|
12300
|
+
{ address: whirlpool.data.tokenVaultB, role: import_kit120.AccountRole.WRITABLE },
|
|
12301
|
+
{ address: orcaOracleAddress, role: import_kit120.AccountRole.WRITABLE }
|
|
11885
12302
|
];
|
|
11886
12303
|
const remainingAccountsInfo = {
|
|
11887
12304
|
slices: [
|
|
@@ -11915,14 +12332,14 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
11915
12332
|
feeRecipientAtaA,
|
|
11916
12333
|
feeRecipientAtaB,
|
|
11917
12334
|
whirlpool: whirlpool.address,
|
|
11918
|
-
whirlpoolProgram:
|
|
12335
|
+
whirlpoolProgram: import_whirlpools_client12.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11919
12336
|
orcaPosition: orcaPositionAddress,
|
|
11920
12337
|
tokenProgramA: mintA.programAddress,
|
|
11921
12338
|
tokenProgramB: mintB.programAddress,
|
|
11922
|
-
memoProgram:
|
|
12339
|
+
memoProgram: import_memo15.MEMO_PROGRAM_ADDRESS,
|
|
11923
12340
|
metadataUpdateAuth: WP_NFT_UPDATE_AUTH,
|
|
11924
|
-
associatedTokenProgram:
|
|
11925
|
-
token2022Program:
|
|
12341
|
+
associatedTokenProgram: import_token_202224.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12342
|
+
token2022Program: import_token_202224.TOKEN_2022_PROGRAM_ADDRESS,
|
|
11926
12343
|
...args,
|
|
11927
12344
|
remainingAccountsInfo
|
|
11928
12345
|
});
|
|
@@ -11931,28 +12348,28 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
11931
12348
|
}
|
|
11932
12349
|
|
|
11933
12350
|
// src/txbuilder/openAndIncreaseTunaLpPositionFusion.ts
|
|
11934
|
-
var
|
|
12351
|
+
var import_fusionamm_client13 = require("@crypticdot/fusionamm-client");
|
|
11935
12352
|
var import_fusionamm_core5 = require("@crypticdot/fusionamm-core");
|
|
11936
|
-
var
|
|
12353
|
+
var import_kit121 = require("@solana/kit");
|
|
11937
12354
|
var import_sysvars2 = require("@solana/sysvars");
|
|
11938
|
-
var
|
|
11939
|
-
var
|
|
11940
|
-
var
|
|
12355
|
+
var import_memo16 = require("@solana-program/memo");
|
|
12356
|
+
var import_token_202225 = require("@solana-program/token-2022");
|
|
12357
|
+
var import_assert18 = __toESM(require("assert"));
|
|
11941
12358
|
async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
11942
12359
|
const instructions = [];
|
|
11943
12360
|
if (!createInstructions) createInstructions = instructions;
|
|
11944
12361
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
11945
12362
|
const rent = await (0, import_sysvars2.fetchSysvarRent)(rpc);
|
|
11946
12363
|
let nonRefundableRent = 0n;
|
|
11947
|
-
const positionMint = await (0,
|
|
12364
|
+
const positionMint = await (0, import_kit121.generateKeyPairSigner)();
|
|
11948
12365
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
11949
|
-
const fusionPool = await (0,
|
|
12366
|
+
const fusionPool = await (0, import_fusionamm_client13.fetchMaybeFusionPool)(rpc, fusionPoolAddress);
|
|
11950
12367
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
11951
12368
|
const marketAddress = (await getMarketAddress(fusionPoolAddress))[0];
|
|
11952
12369
|
const market = await fetchMarket(rpc, marketAddress);
|
|
11953
|
-
const [mintA, mintB] = await (0,
|
|
11954
|
-
(0,
|
|
11955
|
-
(0,
|
|
12370
|
+
const [mintA, mintB] = await (0, import_token_202225.fetchAllMaybeMint)(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
12371
|
+
(0, import_assert18.default)(mintA.exists, "Token A account not found");
|
|
12372
|
+
(0, import_assert18.default)(mintB.exists, "Token B account not found");
|
|
11956
12373
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
11957
12374
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
11958
12375
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
@@ -12005,34 +12422,34 @@ async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, f
|
|
|
12005
12422
|
);
|
|
12006
12423
|
createInstructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
12007
12424
|
const lowerTickArrayIndex = (0, import_fusionamm_core5.getTickArrayStartTickIndex)(args.tickLowerIndex, fusionPool.data.tickSpacing);
|
|
12008
|
-
const [lowerTickArrayAddress] = await (0,
|
|
12425
|
+
const [lowerTickArrayAddress] = await (0, import_fusionamm_client13.getTickArrayAddress)(fusionPool.address, lowerTickArrayIndex);
|
|
12009
12426
|
const upperTickArrayIndex = (0, import_fusionamm_core5.getTickArrayStartTickIndex)(args.tickUpperIndex, fusionPool.data.tickSpacing);
|
|
12010
|
-
const [upperTickArrayAddress] = await (0,
|
|
12011
|
-
const [lowerTickArray, upperTickArray] = await (0,
|
|
12427
|
+
const [upperTickArrayAddress] = await (0, import_fusionamm_client13.getTickArrayAddress)(fusionPool.address, upperTickArrayIndex);
|
|
12428
|
+
const [lowerTickArray, upperTickArray] = await (0, import_fusionamm_client13.fetchAllMaybeTickArray)(rpc, [
|
|
12012
12429
|
lowerTickArrayAddress,
|
|
12013
12430
|
upperTickArrayAddress
|
|
12014
12431
|
]);
|
|
12015
12432
|
if (!lowerTickArray.exists) {
|
|
12016
12433
|
instructions.push(
|
|
12017
|
-
(0,
|
|
12434
|
+
(0, import_fusionamm_client13.getInitializeTickArrayInstruction)({
|
|
12018
12435
|
fusionPool: fusionPool.address,
|
|
12019
12436
|
funder: authority,
|
|
12020
12437
|
tickArray: lowerTickArrayAddress,
|
|
12021
12438
|
startTickIndex: lowerTickArrayIndex
|
|
12022
12439
|
})
|
|
12023
12440
|
);
|
|
12024
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
12441
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client13.getTickArraySize)());
|
|
12025
12442
|
}
|
|
12026
12443
|
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
12027
12444
|
instructions.push(
|
|
12028
|
-
(0,
|
|
12445
|
+
(0, import_fusionamm_client13.getInitializeTickArrayInstruction)({
|
|
12029
12446
|
fusionPool: fusionPool.address,
|
|
12030
12447
|
funder: authority,
|
|
12031
12448
|
tickArray: upperTickArrayAddress,
|
|
12032
12449
|
startTickIndex: upperTickArrayIndex
|
|
12033
12450
|
})
|
|
12034
12451
|
);
|
|
12035
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
12452
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client13.getTickArraySize)());
|
|
12036
12453
|
}
|
|
12037
12454
|
const ix = await openAndIncreaseTunaLpPositionFusionInstruction(
|
|
12038
12455
|
authority,
|
|
@@ -12051,54 +12468,54 @@ async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, f
|
|
|
12051
12468
|
return {
|
|
12052
12469
|
instructions,
|
|
12053
12470
|
positionMint: positionMint.address,
|
|
12054
|
-
initializationCost: (0,
|
|
12471
|
+
initializationCost: (0, import_kit121.lamports)(nonRefundableRent)
|
|
12055
12472
|
};
|
|
12056
12473
|
}
|
|
12057
12474
|
async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, args) {
|
|
12058
12475
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
12059
12476
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
12060
|
-
const fusionPositionAddress = (await (0,
|
|
12061
|
-
const tunaPositionAta = (await (0,
|
|
12477
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client13.getPositionAddress)(positionMint.address))[0];
|
|
12478
|
+
const tunaPositionAta = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12062
12479
|
owner: tunaPositionAddress,
|
|
12063
12480
|
mint: positionMint.address,
|
|
12064
|
-
tokenProgram:
|
|
12481
|
+
tokenProgram: import_token_202225.TOKEN_2022_PROGRAM_ADDRESS
|
|
12065
12482
|
}))[0];
|
|
12066
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
12483
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12067
12484
|
owner: authority.address,
|
|
12068
12485
|
mint: mintA.address,
|
|
12069
12486
|
tokenProgram: mintA.programAddress
|
|
12070
12487
|
}))[0];
|
|
12071
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
12488
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12072
12489
|
owner: authority.address,
|
|
12073
12490
|
mint: mintB.address,
|
|
12074
12491
|
tokenProgram: mintB.programAddress
|
|
12075
12492
|
}))[0];
|
|
12076
|
-
const tunaPositionAtaA = (await (0,
|
|
12493
|
+
const tunaPositionAtaA = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12077
12494
|
owner: tunaPositionAddress,
|
|
12078
12495
|
mint: mintA.address,
|
|
12079
12496
|
tokenProgram: mintA.programAddress
|
|
12080
12497
|
}))[0];
|
|
12081
|
-
const tunaPositionAtaB = (await (0,
|
|
12498
|
+
const tunaPositionAtaB = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12082
12499
|
owner: tunaPositionAddress,
|
|
12083
12500
|
mint: mintB.address,
|
|
12084
12501
|
tokenProgram: mintB.programAddress
|
|
12085
12502
|
}))[0];
|
|
12086
|
-
const vaultAAta = (await (0,
|
|
12503
|
+
const vaultAAta = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12087
12504
|
owner: vaultA.address,
|
|
12088
12505
|
mint: mintA.address,
|
|
12089
12506
|
tokenProgram: mintA.programAddress
|
|
12090
12507
|
}))[0];
|
|
12091
|
-
const vaultBAta = (await (0,
|
|
12508
|
+
const vaultBAta = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12092
12509
|
owner: vaultB.address,
|
|
12093
12510
|
mint: mintB.address,
|
|
12094
12511
|
tokenProgram: mintB.programAddress
|
|
12095
12512
|
}))[0];
|
|
12096
|
-
const feeRecipientAtaA = (await (0,
|
|
12513
|
+
const feeRecipientAtaA = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12097
12514
|
owner: tunaConfig.data.feeRecipient,
|
|
12098
12515
|
mint: mintA.address,
|
|
12099
12516
|
tokenProgram: mintA.programAddress
|
|
12100
12517
|
}))[0];
|
|
12101
|
-
const feeRecipientAtaB = (await (0,
|
|
12518
|
+
const feeRecipientAtaB = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12102
12519
|
owner: tunaConfig.data.feeRecipient,
|
|
12103
12520
|
mint: mintB.address,
|
|
12104
12521
|
tokenProgram: mintB.programAddress
|
|
@@ -12107,15 +12524,15 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12107
12524
|
const lowerTickArrayAddress = await FusionUtils.getTickArrayAddressFromTickIndex(fusionPool, args.tickLowerIndex);
|
|
12108
12525
|
const upperTickArrayAddress = await FusionUtils.getTickArrayAddressFromTickIndex(fusionPool, args.tickUpperIndex);
|
|
12109
12526
|
const remainingAccounts = [
|
|
12110
|
-
{ address: swapTickArrays[0], role:
|
|
12111
|
-
{ address: swapTickArrays[1], role:
|
|
12112
|
-
{ address: swapTickArrays[2], role:
|
|
12113
|
-
{ address: swapTickArrays[3], role:
|
|
12114
|
-
{ address: swapTickArrays[4], role:
|
|
12115
|
-
{ address: lowerTickArrayAddress, role:
|
|
12116
|
-
{ address: upperTickArrayAddress, role:
|
|
12117
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
12118
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
12527
|
+
{ address: swapTickArrays[0], role: import_kit121.AccountRole.WRITABLE },
|
|
12528
|
+
{ address: swapTickArrays[1], role: import_kit121.AccountRole.WRITABLE },
|
|
12529
|
+
{ address: swapTickArrays[2], role: import_kit121.AccountRole.WRITABLE },
|
|
12530
|
+
{ address: swapTickArrays[3], role: import_kit121.AccountRole.WRITABLE },
|
|
12531
|
+
{ address: swapTickArrays[4], role: import_kit121.AccountRole.WRITABLE },
|
|
12532
|
+
{ address: lowerTickArrayAddress, role: import_kit121.AccountRole.WRITABLE },
|
|
12533
|
+
{ address: upperTickArrayAddress, role: import_kit121.AccountRole.WRITABLE },
|
|
12534
|
+
{ address: fusionPool.data.tokenVaultA, role: import_kit121.AccountRole.WRITABLE },
|
|
12535
|
+
{ address: fusionPool.data.tokenVaultB, role: import_kit121.AccountRole.WRITABLE }
|
|
12119
12536
|
];
|
|
12120
12537
|
const remainingAccountsInfo = {
|
|
12121
12538
|
slices: [
|
|
@@ -12148,14 +12565,14 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12148
12565
|
feeRecipientAtaA,
|
|
12149
12566
|
feeRecipientAtaB,
|
|
12150
12567
|
fusionPool: fusionPool.address,
|
|
12151
|
-
fusionammProgram:
|
|
12568
|
+
fusionammProgram: import_fusionamm_client13.FUSIONAMM_PROGRAM_ADDRESS,
|
|
12152
12569
|
fusionPosition: fusionPositionAddress,
|
|
12153
12570
|
tokenProgramA: mintA.programAddress,
|
|
12154
12571
|
tokenProgramB: mintB.programAddress,
|
|
12155
|
-
memoProgram:
|
|
12156
|
-
metadataUpdateAuth:
|
|
12157
|
-
associatedTokenProgram:
|
|
12158
|
-
token2022Program:
|
|
12572
|
+
memoProgram: import_memo16.MEMO_PROGRAM_ADDRESS,
|
|
12573
|
+
metadataUpdateAuth: import_fusionamm_client13.FP_NFT_UPDATE_AUTH,
|
|
12574
|
+
associatedTokenProgram: import_token_202225.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12575
|
+
token2022Program: import_token_202225.TOKEN_2022_PROGRAM_ADDRESS,
|
|
12159
12576
|
...args,
|
|
12160
12577
|
remainingAccountsInfo
|
|
12161
12578
|
});
|
|
@@ -12164,36 +12581,36 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12164
12581
|
}
|
|
12165
12582
|
|
|
12166
12583
|
// src/txbuilder/openTunaSpotPosition.ts
|
|
12167
|
-
var
|
|
12168
|
-
var
|
|
12169
|
-
var
|
|
12170
|
-
var
|
|
12171
|
-
var
|
|
12584
|
+
var import_fusionamm_client14 = require("@crypticdot/fusionamm-client");
|
|
12585
|
+
var import_whirlpools_client13 = require("@orca-so/whirlpools-client");
|
|
12586
|
+
var import_kit122 = require("@solana/kit");
|
|
12587
|
+
var import_token_202226 = require("@solana-program/token-2022");
|
|
12588
|
+
var import_assert19 = __toESM(require("assert"));
|
|
12172
12589
|
async function openTunaSpotPositionInstructions(rpc, authority, poolAddress, args) {
|
|
12173
|
-
const poolAccount = await (0,
|
|
12174
|
-
(0,
|
|
12590
|
+
const poolAccount = await (0, import_kit122.fetchEncodedAccount)(rpc, poolAddress);
|
|
12591
|
+
(0, import_assert19.default)(poolAccount.exists, "Pool account not found");
|
|
12175
12592
|
let pool;
|
|
12176
|
-
if (poolAccount.programAddress ==
|
|
12177
|
-
pool = (0,
|
|
12178
|
-
} else if (poolAccount.programAddress ==
|
|
12179
|
-
pool = (0,
|
|
12593
|
+
if (poolAccount.programAddress == import_fusionamm_client14.FUSIONAMM_PROGRAM_ADDRESS) {
|
|
12594
|
+
pool = (0, import_kit122.decodeAccount)(poolAccount, (0, import_fusionamm_client14.getFusionPoolDecoder)());
|
|
12595
|
+
} else if (poolAccount.programAddress == import_whirlpools_client13.WHIRLPOOL_PROGRAM_ADDRESS) {
|
|
12596
|
+
pool = (0, import_kit122.decodeAccount)(poolAccount, (0, import_whirlpools_client13.getWhirlpoolDecoder)());
|
|
12180
12597
|
} else {
|
|
12181
12598
|
throw new Error("Incorrect Fusion or Orca pool account");
|
|
12182
12599
|
}
|
|
12183
|
-
const [mintA, mintB] = await (0,
|
|
12184
|
-
(0,
|
|
12185
|
-
(0,
|
|
12600
|
+
const [mintA, mintB] = await (0, import_token_202226.fetchAllMaybeMint)(rpc, [pool.data.tokenMintA, pool.data.tokenMintB]);
|
|
12601
|
+
(0, import_assert19.default)(mintA.exists, "Token A account not found");
|
|
12602
|
+
(0, import_assert19.default)(mintB.exists, "Token B account not found");
|
|
12186
12603
|
const ix = await openTunaSpotPositionInstruction(authority, mintA, mintB, poolAddress, args);
|
|
12187
12604
|
return [ix];
|
|
12188
12605
|
}
|
|
12189
12606
|
async function openTunaSpotPositionInstruction(authority, mintA, mintB, poolAddress, args) {
|
|
12190
12607
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
12191
|
-
const tunaPositionAtaA = (await (0,
|
|
12608
|
+
const tunaPositionAtaA = (await (0, import_token_202226.findAssociatedTokenPda)({
|
|
12192
12609
|
owner: tunaPositionAddress,
|
|
12193
12610
|
mint: mintA.address,
|
|
12194
12611
|
tokenProgram: mintA.programAddress
|
|
12195
12612
|
}))[0];
|
|
12196
|
-
const tunaPositionAtaB = (await (0,
|
|
12613
|
+
const tunaPositionAtaB = (await (0, import_token_202226.findAssociatedTokenPda)({
|
|
12197
12614
|
owner: tunaPositionAddress,
|
|
12198
12615
|
mint: mintB.address,
|
|
12199
12616
|
tokenProgram: mintB.programAddress
|
|
@@ -12208,48 +12625,48 @@ async function openTunaSpotPositionInstruction(authority, mintA, mintB, poolAddr
|
|
|
12208
12625
|
tunaPositionAtaA,
|
|
12209
12626
|
tunaPositionAtaB,
|
|
12210
12627
|
pool: poolAddress,
|
|
12211
|
-
associatedTokenProgram:
|
|
12628
|
+
associatedTokenProgram: import_token_202226.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12212
12629
|
...args
|
|
12213
12630
|
});
|
|
12214
12631
|
}
|
|
12215
12632
|
|
|
12216
12633
|
// src/txbuilder/decreaseTunaLpPositionOrca.ts
|
|
12217
|
-
var
|
|
12634
|
+
var import_whirlpools_client14 = require("@orca-so/whirlpools-client");
|
|
12218
12635
|
var import_whirlpools_core5 = require("@orca-so/whirlpools-core");
|
|
12219
|
-
var
|
|
12220
|
-
var
|
|
12221
|
-
var
|
|
12222
|
-
var
|
|
12636
|
+
var import_kit123 = require("@solana/kit");
|
|
12637
|
+
var import_memo17 = require("@solana-program/memo");
|
|
12638
|
+
var import_token_202227 = require("@solana-program/token-2022");
|
|
12639
|
+
var import_assert20 = __toESM(require("assert"));
|
|
12223
12640
|
async function decreaseTunaLpPositionOrcaInstructions(rpc, authority, positionMint, args, createInstructions, cleanupInstructions) {
|
|
12224
12641
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12225
12642
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12226
|
-
const orcaPosition = await (0,
|
|
12227
|
-
const whirlpool = await (0,
|
|
12643
|
+
const orcaPosition = await (0, import_whirlpools_client14.fetchPosition)(rpc, (await (0, import_whirlpools_client14.getPositionAddress)(positionMint))[0]);
|
|
12644
|
+
const whirlpool = await (0, import_whirlpools_client14.fetchMaybeWhirlpool)(rpc, tunaPosition.data.pool);
|
|
12228
12645
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
12229
12646
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
12230
12647
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
12231
12648
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
12232
12649
|
]);
|
|
12233
|
-
const [mintA, mintB, ...rewardMints] = await (0,
|
|
12650
|
+
const [mintA, mintB, ...rewardMints] = await (0, import_token_202227.fetchAllMaybeMint)(rpc, [
|
|
12234
12651
|
whirlpool.data.tokenMintA,
|
|
12235
12652
|
whirlpool.data.tokenMintB,
|
|
12236
12653
|
...whirlpool.data.rewardInfos.map((x) => x.mint).filter((x) => x !== DEFAULT_ADDRESS)
|
|
12237
12654
|
]);
|
|
12238
12655
|
const allMints = [mintA, mintB, ...rewardMints];
|
|
12239
|
-
(0,
|
|
12240
|
-
(0,
|
|
12241
|
-
(0,
|
|
12656
|
+
(0, import_assert20.default)(mintA.exists, "Token A account not found");
|
|
12657
|
+
(0, import_assert20.default)(mintB.exists, "Token B account not found");
|
|
12658
|
+
(0, import_kit123.assertAccountsExist)(rewardMints);
|
|
12242
12659
|
const lowerTickArrayStartIndex = (0, import_whirlpools_core5.getTickArrayStartTickIndex)(
|
|
12243
12660
|
tunaPosition.data.tickLowerIndex,
|
|
12244
12661
|
whirlpool.data.tickSpacing
|
|
12245
12662
|
);
|
|
12246
|
-
const [lowerTickArrayAddress] = await (0,
|
|
12663
|
+
const [lowerTickArrayAddress] = await (0, import_whirlpools_client14.getTickArrayAddress)(whirlpool.address, lowerTickArrayStartIndex);
|
|
12247
12664
|
const upperTickArrayStartIndex = (0, import_whirlpools_core5.getTickArrayStartTickIndex)(
|
|
12248
12665
|
tunaPosition.data.tickUpperIndex,
|
|
12249
12666
|
whirlpool.data.tickSpacing
|
|
12250
12667
|
);
|
|
12251
|
-
const [upperTickArrayAddress] = await (0,
|
|
12252
|
-
const [lowerTickArray, upperTickArray] = await (0,
|
|
12668
|
+
const [upperTickArrayAddress] = await (0, import_whirlpools_client14.getTickArrayAddress)(whirlpool.address, upperTickArrayStartIndex);
|
|
12669
|
+
const [lowerTickArray, upperTickArray] = await (0, import_whirlpools_client14.fetchAllTickArray)(rpc, [lowerTickArrayAddress, upperTickArrayAddress]);
|
|
12253
12670
|
const lowerTick = lowerTickArray.data.ticks[(0, import_whirlpools_core5.getTickIndexInArray)(tunaPosition.data.tickLowerIndex, lowerTickArrayStartIndex, whirlpool.data.tickSpacing)];
|
|
12254
12671
|
const upperTick = upperTickArray.data.ticks[(0, import_whirlpools_core5.getTickIndexInArray)(tunaPosition.data.tickUpperIndex, upperTickArrayStartIndex, whirlpool.data.tickSpacing)];
|
|
12255
12672
|
const instructions = [];
|
|
@@ -12278,7 +12695,7 @@ async function decreaseTunaLpPositionOrcaInstructions(rpc, authority, positionMi
|
|
|
12278
12695
|
}
|
|
12279
12696
|
for (const mintAddress of requiredMints) {
|
|
12280
12697
|
const mint = allMints.find((mint2) => mint2.address == mintAddress);
|
|
12281
|
-
(0,
|
|
12698
|
+
(0, import_assert20.default)(mint && mint.exists);
|
|
12282
12699
|
const ixs = await getCreateAtaInstructions(rpc, authority, mint.address, authority.address, mint.programAddress);
|
|
12283
12700
|
createInstructions.push(...ixs.init);
|
|
12284
12701
|
internalCleanupInstructions.push(...ixs.cleanup);
|
|
@@ -12304,39 +12721,39 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12304
12721
|
const positionMint = tunaPosition.data.positionMint;
|
|
12305
12722
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12306
12723
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
12307
|
-
const orcaPositionAddress = (await (0,
|
|
12308
|
-
const orcaOracleAddress = (await (0,
|
|
12309
|
-
const tunaPositionAta = (await (0,
|
|
12724
|
+
const orcaPositionAddress = (await (0, import_whirlpools_client14.getPositionAddress)(positionMint))[0];
|
|
12725
|
+
const orcaOracleAddress = (await (0, import_whirlpools_client14.getOracleAddress)(whirlpool.address))[0];
|
|
12726
|
+
const tunaPositionAta = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12310
12727
|
owner: tunaPosition.address,
|
|
12311
12728
|
mint: positionMint,
|
|
12312
|
-
tokenProgram:
|
|
12729
|
+
tokenProgram: import_token_202227.TOKEN_2022_PROGRAM_ADDRESS
|
|
12313
12730
|
}))[0];
|
|
12314
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
12731
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12315
12732
|
owner: authority.address,
|
|
12316
12733
|
mint: mintA.address,
|
|
12317
12734
|
tokenProgram: mintA.programAddress
|
|
12318
12735
|
}))[0];
|
|
12319
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
12736
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12320
12737
|
owner: authority.address,
|
|
12321
12738
|
mint: mintB.address,
|
|
12322
12739
|
tokenProgram: mintB.programAddress
|
|
12323
12740
|
}))[0];
|
|
12324
|
-
const tunaPositionAtaA = (await (0,
|
|
12741
|
+
const tunaPositionAtaA = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12325
12742
|
owner: tunaPosition.address,
|
|
12326
12743
|
mint: mintA.address,
|
|
12327
12744
|
tokenProgram: mintA.programAddress
|
|
12328
12745
|
}))[0];
|
|
12329
|
-
const tunaPositionAtaB = (await (0,
|
|
12746
|
+
const tunaPositionAtaB = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12330
12747
|
owner: tunaPosition.address,
|
|
12331
12748
|
mint: mintB.address,
|
|
12332
12749
|
tokenProgram: mintB.programAddress
|
|
12333
12750
|
}))[0];
|
|
12334
|
-
const vaultAAta = (await (0,
|
|
12751
|
+
const vaultAAta = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12335
12752
|
owner: vaultA.address,
|
|
12336
12753
|
mint: mintA.address,
|
|
12337
12754
|
tokenProgram: mintA.programAddress
|
|
12338
12755
|
}))[0];
|
|
12339
|
-
const vaultBAta = (await (0,
|
|
12756
|
+
const vaultBAta = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12340
12757
|
owner: vaultB.address,
|
|
12341
12758
|
mint: mintB.address,
|
|
12342
12759
|
tokenProgram: mintB.programAddress
|
|
@@ -12351,30 +12768,30 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12351
12768
|
tunaPosition.data.tickUpperIndex
|
|
12352
12769
|
);
|
|
12353
12770
|
const remainingAccounts = [
|
|
12354
|
-
{ address: swapTickArrays[0], role:
|
|
12355
|
-
{ address: swapTickArrays[1], role:
|
|
12356
|
-
{ address: swapTickArrays[2], role:
|
|
12357
|
-
{ address: swapTickArrays[3], role:
|
|
12358
|
-
{ address: swapTickArrays[4], role:
|
|
12359
|
-
{ address: lowerTickArrayAddress, role:
|
|
12360
|
-
{ address: upperTickArrayAddress, role:
|
|
12361
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
12362
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
12363
|
-
{ address: orcaOracleAddress, role:
|
|
12771
|
+
{ address: swapTickArrays[0], role: import_kit123.AccountRole.WRITABLE },
|
|
12772
|
+
{ address: swapTickArrays[1], role: import_kit123.AccountRole.WRITABLE },
|
|
12773
|
+
{ address: swapTickArrays[2], role: import_kit123.AccountRole.WRITABLE },
|
|
12774
|
+
{ address: swapTickArrays[3], role: import_kit123.AccountRole.WRITABLE },
|
|
12775
|
+
{ address: swapTickArrays[4], role: import_kit123.AccountRole.WRITABLE },
|
|
12776
|
+
{ address: lowerTickArrayAddress, role: import_kit123.AccountRole.WRITABLE },
|
|
12777
|
+
{ address: upperTickArrayAddress, role: import_kit123.AccountRole.WRITABLE },
|
|
12778
|
+
{ address: whirlpool.data.tokenVaultA, role: import_kit123.AccountRole.WRITABLE },
|
|
12779
|
+
{ address: whirlpool.data.tokenVaultB, role: import_kit123.AccountRole.WRITABLE },
|
|
12780
|
+
{ address: orcaOracleAddress, role: import_kit123.AccountRole.WRITABLE }
|
|
12364
12781
|
];
|
|
12365
12782
|
for (const rewardIndex of rewardIndicesToClaim) {
|
|
12366
12783
|
const rewardInfo = whirlpool.data.rewardInfos[rewardIndex];
|
|
12367
12784
|
const rewardMint = rewardMints.find((mint) => mint.address == rewardInfo.mint);
|
|
12368
|
-
(0,
|
|
12369
|
-
const ownerAta = await (0,
|
|
12785
|
+
(0, import_assert20.default)(rewardMint, "Reward mint not found in the provided reward mint accounts");
|
|
12786
|
+
const ownerAta = await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12370
12787
|
owner: authority.address,
|
|
12371
12788
|
mint: rewardMint.address,
|
|
12372
12789
|
tokenProgram: rewardMint.programAddress
|
|
12373
12790
|
});
|
|
12374
|
-
remainingAccounts.push({ address: rewardMint.address, role:
|
|
12375
|
-
remainingAccounts.push({ address: rewardMint.programAddress, role:
|
|
12376
|
-
remainingAccounts.push({ address: ownerAta[0], role:
|
|
12377
|
-
remainingAccounts.push({ address: rewardInfo.vault, role:
|
|
12791
|
+
remainingAccounts.push({ address: rewardMint.address, role: import_kit123.AccountRole.READONLY });
|
|
12792
|
+
remainingAccounts.push({ address: rewardMint.programAddress, role: import_kit123.AccountRole.READONLY });
|
|
12793
|
+
remainingAccounts.push({ address: ownerAta[0], role: import_kit123.AccountRole.WRITABLE });
|
|
12794
|
+
remainingAccounts.push({ address: rewardInfo.vault, role: import_kit123.AccountRole.WRITABLE });
|
|
12378
12795
|
}
|
|
12379
12796
|
const remainingAccountsInfo = {
|
|
12380
12797
|
slices: [
|
|
@@ -12409,10 +12826,10 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12409
12826
|
orcaPosition: orcaPositionAddress,
|
|
12410
12827
|
tunaPosition: tunaPosition.address,
|
|
12411
12828
|
whirlpool: whirlpool.address,
|
|
12412
|
-
whirlpoolProgram:
|
|
12829
|
+
whirlpoolProgram: import_whirlpools_client14.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
12413
12830
|
tokenProgramA: mintA.programAddress,
|
|
12414
12831
|
tokenProgramB: mintB.programAddress,
|
|
12415
|
-
memoProgram:
|
|
12832
|
+
memoProgram: import_memo17.MEMO_PROGRAM_ADDRESS,
|
|
12416
12833
|
...args,
|
|
12417
12834
|
remainingAccountsInfo
|
|
12418
12835
|
});
|
|
@@ -12421,23 +12838,23 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12421
12838
|
}
|
|
12422
12839
|
|
|
12423
12840
|
// src/txbuilder/decreaseTunaLpPositionFusion.ts
|
|
12424
|
-
var
|
|
12425
|
-
var
|
|
12426
|
-
var
|
|
12427
|
-
var
|
|
12428
|
-
var
|
|
12841
|
+
var import_fusionamm_client15 = require("@crypticdot/fusionamm-client");
|
|
12842
|
+
var import_kit124 = require("@solana/kit");
|
|
12843
|
+
var import_memo18 = require("@solana-program/memo");
|
|
12844
|
+
var import_token_202228 = require("@solana-program/token-2022");
|
|
12845
|
+
var import_assert21 = __toESM(require("assert"));
|
|
12429
12846
|
async function decreaseTunaLpPositionFusionInstructions(rpc, authority, positionMint, args, createInstructions, cleanupInstructions) {
|
|
12430
12847
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12431
12848
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12432
|
-
const fusionPool = await (0,
|
|
12849
|
+
const fusionPool = await (0, import_fusionamm_client15.fetchMaybeFusionPool)(rpc, tunaPosition.data.pool);
|
|
12433
12850
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
12434
12851
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
12435
12852
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
12436
12853
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
12437
12854
|
]);
|
|
12438
|
-
const [mintA, mintB] = await (0,
|
|
12439
|
-
(0,
|
|
12440
|
-
(0,
|
|
12855
|
+
const [mintA, mintB] = await (0, import_token_202228.fetchAllMaybeMint)(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
12856
|
+
(0, import_assert21.default)(mintA.exists, "Token A account not found");
|
|
12857
|
+
(0, import_assert21.default)(mintB.exists, "Token B account not found");
|
|
12441
12858
|
const instructions = [];
|
|
12442
12859
|
if (!createInstructions) createInstructions = instructions;
|
|
12443
12860
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
@@ -12477,38 +12894,38 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12477
12894
|
const positionMint = tunaPosition.data.positionMint;
|
|
12478
12895
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12479
12896
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
12480
|
-
const fusionPositionAddress = (await (0,
|
|
12481
|
-
const tunaPositionAta = (await (0,
|
|
12897
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client15.getPositionAddress)(positionMint))[0];
|
|
12898
|
+
const tunaPositionAta = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12482
12899
|
owner: tunaPosition.address,
|
|
12483
12900
|
mint: positionMint,
|
|
12484
|
-
tokenProgram:
|
|
12901
|
+
tokenProgram: import_token_202228.TOKEN_2022_PROGRAM_ADDRESS
|
|
12485
12902
|
}))[0];
|
|
12486
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
12903
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12487
12904
|
owner: authority.address,
|
|
12488
12905
|
mint: mintA.address,
|
|
12489
12906
|
tokenProgram: mintA.programAddress
|
|
12490
12907
|
}))[0];
|
|
12491
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
12908
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12492
12909
|
owner: authority.address,
|
|
12493
12910
|
mint: mintB.address,
|
|
12494
12911
|
tokenProgram: mintB.programAddress
|
|
12495
12912
|
}))[0];
|
|
12496
|
-
const tunaPositionAtaA = (await (0,
|
|
12913
|
+
const tunaPositionAtaA = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12497
12914
|
owner: tunaPosition.address,
|
|
12498
12915
|
mint: mintA.address,
|
|
12499
12916
|
tokenProgram: mintA.programAddress
|
|
12500
12917
|
}))[0];
|
|
12501
|
-
const tunaPositionAtaB = (await (0,
|
|
12918
|
+
const tunaPositionAtaB = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12502
12919
|
owner: tunaPosition.address,
|
|
12503
12920
|
mint: mintB.address,
|
|
12504
12921
|
tokenProgram: mintB.programAddress
|
|
12505
12922
|
}))[0];
|
|
12506
|
-
const vaultAAta = (await (0,
|
|
12923
|
+
const vaultAAta = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12507
12924
|
owner: vaultA.address,
|
|
12508
12925
|
mint: mintA.address,
|
|
12509
12926
|
tokenProgram: mintA.programAddress
|
|
12510
12927
|
}))[0];
|
|
12511
|
-
const vaultBAta = (await (0,
|
|
12928
|
+
const vaultBAta = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12512
12929
|
owner: vaultB.address,
|
|
12513
12930
|
mint: mintB.address,
|
|
12514
12931
|
tokenProgram: mintB.programAddress
|
|
@@ -12523,15 +12940,15 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12523
12940
|
tunaPosition.data.tickUpperIndex
|
|
12524
12941
|
);
|
|
12525
12942
|
const remainingAccounts = [
|
|
12526
|
-
{ address: swapTickArrays[0], role:
|
|
12527
|
-
{ address: swapTickArrays[1], role:
|
|
12528
|
-
{ address: swapTickArrays[2], role:
|
|
12529
|
-
{ address: swapTickArrays[3], role:
|
|
12530
|
-
{ address: swapTickArrays[4], role:
|
|
12531
|
-
{ address: lowerTickArrayAddress, role:
|
|
12532
|
-
{ address: upperTickArrayAddress, role:
|
|
12533
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
12534
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
12943
|
+
{ address: swapTickArrays[0], role: import_kit124.AccountRole.WRITABLE },
|
|
12944
|
+
{ address: swapTickArrays[1], role: import_kit124.AccountRole.WRITABLE },
|
|
12945
|
+
{ address: swapTickArrays[2], role: import_kit124.AccountRole.WRITABLE },
|
|
12946
|
+
{ address: swapTickArrays[3], role: import_kit124.AccountRole.WRITABLE },
|
|
12947
|
+
{ address: swapTickArrays[4], role: import_kit124.AccountRole.WRITABLE },
|
|
12948
|
+
{ address: lowerTickArrayAddress, role: import_kit124.AccountRole.WRITABLE },
|
|
12949
|
+
{ address: upperTickArrayAddress, role: import_kit124.AccountRole.WRITABLE },
|
|
12950
|
+
{ address: fusionPool.data.tokenVaultA, role: import_kit124.AccountRole.WRITABLE },
|
|
12951
|
+
{ address: fusionPool.data.tokenVaultB, role: import_kit124.AccountRole.WRITABLE }
|
|
12535
12952
|
];
|
|
12536
12953
|
const remainingAccountsInfo = {
|
|
12537
12954
|
slices: [
|
|
@@ -12562,10 +12979,10 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12562
12979
|
fusionPosition: fusionPositionAddress,
|
|
12563
12980
|
tunaPosition: tunaPosition.address,
|
|
12564
12981
|
fusionPool: fusionPool.address,
|
|
12565
|
-
fusionammProgram:
|
|
12982
|
+
fusionammProgram: import_fusionamm_client15.FUSIONAMM_PROGRAM_ADDRESS,
|
|
12566
12983
|
tokenProgramA: mintA.programAddress,
|
|
12567
12984
|
tokenProgramB: mintB.programAddress,
|
|
12568
|
-
memoProgram:
|
|
12985
|
+
memoProgram: import_memo18.MEMO_PROGRAM_ADDRESS,
|
|
12569
12986
|
...args,
|
|
12570
12987
|
remainingAccountsInfo
|
|
12571
12988
|
});
|
|
@@ -12574,19 +12991,19 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12574
12991
|
}
|
|
12575
12992
|
|
|
12576
12993
|
// src/txbuilder/repayBadDebt.ts
|
|
12577
|
-
var
|
|
12578
|
-
var
|
|
12994
|
+
var import_memo19 = require("@solana-program/memo");
|
|
12995
|
+
var import_token_202229 = require("@solana-program/token-2022");
|
|
12579
12996
|
async function repayBadDebtInstruction(rpc, authority, mintAddress, funds, shares) {
|
|
12580
|
-
const mint = await (0,
|
|
12997
|
+
const mint = await (0, import_token_202229.fetchMaybeMint)(rpc, mintAddress);
|
|
12581
12998
|
if (!mint.exists) throw new Error("Mint account not found");
|
|
12582
12999
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12583
13000
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
12584
|
-
const vaultAta = (await (0,
|
|
13001
|
+
const vaultAta = (await (0, import_token_202229.findAssociatedTokenPda)({
|
|
12585
13002
|
owner: vault,
|
|
12586
13003
|
mint: mint.address,
|
|
12587
13004
|
tokenProgram: mint.programAddress
|
|
12588
13005
|
}))[0];
|
|
12589
|
-
const authorityAta = (await (0,
|
|
13006
|
+
const authorityAta = (await (0, import_token_202229.findAssociatedTokenPda)({
|
|
12590
13007
|
owner: authority.address,
|
|
12591
13008
|
mint: mint.address,
|
|
12592
13009
|
tokenProgram: mint.programAddress
|
|
@@ -12599,7 +13016,7 @@ async function repayBadDebtInstruction(rpc, authority, mintAddress, funds, share
|
|
|
12599
13016
|
tunaConfig,
|
|
12600
13017
|
vault,
|
|
12601
13018
|
tokenProgram: mint.programAddress,
|
|
12602
|
-
memoProgram:
|
|
13019
|
+
memoProgram: import_memo19.MEMO_PROGRAM_ADDRESS,
|
|
12603
13020
|
funds,
|
|
12604
13021
|
shares
|
|
12605
13022
|
});
|
|
@@ -12631,20 +13048,20 @@ async function setTunaSpotPositionLimitOrdersInstruction(authority, poolAddress,
|
|
|
12631
13048
|
}
|
|
12632
13049
|
|
|
12633
13050
|
// src/txbuilder/resetTunaSpotPosition.ts
|
|
12634
|
-
var
|
|
12635
|
-
var
|
|
13051
|
+
var import_token_202230 = require("@solana-program/token-2022");
|
|
13052
|
+
var import_assert22 = __toESM(require("assert"));
|
|
12636
13053
|
async function resetTunaSpotPositionInstruction(rpc, authority, poolAddress, args) {
|
|
12637
13054
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
12638
13055
|
const tunaPosition = await fetchTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12639
|
-
const [mintA, mintB] = await (0,
|
|
12640
|
-
(0,
|
|
12641
|
-
(0,
|
|
12642
|
-
const tunaPositionAtaA = (await (0,
|
|
13056
|
+
const [mintA, mintB] = await (0, import_token_202230.fetchAllMaybeMint)(rpc, [tunaPosition.data.mintA, tunaPosition.data.mintB]);
|
|
13057
|
+
(0, import_assert22.default)(mintA.exists, "Token A not found");
|
|
13058
|
+
(0, import_assert22.default)(mintB.exists, "Token B not found");
|
|
13059
|
+
const tunaPositionAtaA = (await (0, import_token_202230.findAssociatedTokenPda)({
|
|
12643
13060
|
owner: tunaPositionAddress,
|
|
12644
13061
|
mint: mintA.address,
|
|
12645
13062
|
tokenProgram: mintA.programAddress
|
|
12646
13063
|
}))[0];
|
|
12647
|
-
const tunaPositionAtaB = (await (0,
|
|
13064
|
+
const tunaPositionAtaB = (await (0, import_token_202230.findAssociatedTokenPda)({
|
|
12648
13065
|
owner: tunaPositionAddress,
|
|
12649
13066
|
mint: mintB.address,
|
|
12650
13067
|
tokenProgram: mintB.programAddress
|
|
@@ -12685,11 +13102,11 @@ async function updateVaultInstruction(authority, mint, args) {
|
|
|
12685
13102
|
}
|
|
12686
13103
|
|
|
12687
13104
|
// src/txbuilder/withdraw.ts
|
|
12688
|
-
var
|
|
12689
|
-
var
|
|
13105
|
+
var import_memo20 = require("@solana-program/memo");
|
|
13106
|
+
var import_token_202231 = require("@solana-program/token-2022");
|
|
12690
13107
|
async function withdrawInstructions(rpc, authority, mintAddress, funds, shares) {
|
|
12691
13108
|
const instructions = [];
|
|
12692
|
-
const mint = await (0,
|
|
13109
|
+
const mint = await (0, import_token_202231.fetchMaybeMint)(rpc, mintAddress);
|
|
12693
13110
|
if (!mint.exists) throw new Error("Mint account not found");
|
|
12694
13111
|
const createUserAtaInstructions = await getCreateAtaInstructions(
|
|
12695
13112
|
rpc,
|
|
@@ -12708,12 +13125,12 @@ async function withdrawInstruction(authority, mint, funds, shares) {
|
|
|
12708
13125
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12709
13126
|
const lendingPosition = (await getLendingPositionAddress(authority.address, mint.address))[0];
|
|
12710
13127
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
12711
|
-
const vaultAta = (await (0,
|
|
13128
|
+
const vaultAta = (await (0, import_token_202231.findAssociatedTokenPda)({
|
|
12712
13129
|
owner: vault,
|
|
12713
13130
|
mint: mint.address,
|
|
12714
13131
|
tokenProgram: mint.programAddress
|
|
12715
13132
|
}))[0];
|
|
12716
|
-
const authorityAta = (await (0,
|
|
13133
|
+
const authorityAta = (await (0, import_token_202231.findAssociatedTokenPda)({
|
|
12717
13134
|
owner: authority.address,
|
|
12718
13135
|
mint: mint.address,
|
|
12719
13136
|
tokenProgram: mint.programAddress
|
|
@@ -12727,35 +13144,35 @@ async function withdrawInstruction(authority, mint, funds, shares) {
|
|
|
12727
13144
|
vault,
|
|
12728
13145
|
vaultAta,
|
|
12729
13146
|
tokenProgram: mint.programAddress,
|
|
12730
|
-
memoProgram:
|
|
13147
|
+
memoProgram: import_memo20.MEMO_PROGRAM_ADDRESS,
|
|
12731
13148
|
funds,
|
|
12732
13149
|
shares
|
|
12733
13150
|
});
|
|
12734
13151
|
}
|
|
12735
13152
|
|
|
12736
13153
|
// src/txbuilder/createMarketLookupTable.ts
|
|
12737
|
-
var
|
|
12738
|
-
var
|
|
12739
|
-
var
|
|
13154
|
+
var import_fusionamm_client16 = require("@crypticdot/fusionamm-client");
|
|
13155
|
+
var import_whirlpools_client15 = require("@orca-so/whirlpools-client");
|
|
13156
|
+
var import_kit125 = require("@solana/kit");
|
|
12740
13157
|
var import_address_lookup_table2 = require("@solana-program/address-lookup-table");
|
|
12741
|
-
var
|
|
13158
|
+
var import_memo21 = require("@solana-program/memo");
|
|
12742
13159
|
var import_system2 = require("@solana-program/system");
|
|
12743
13160
|
var import_token2 = require("@solana-program/token");
|
|
12744
|
-
var
|
|
13161
|
+
var import_token_202232 = require("@solana-program/token-2022");
|
|
12745
13162
|
async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
12746
13163
|
const tunaConfigAddress = (await getTunaConfigAddress())[0];
|
|
12747
13164
|
const marketAddress = (await getMarketAddress(poolAddress))[0];
|
|
12748
|
-
const orcaOracleAddress = (await (0,
|
|
13165
|
+
const orcaOracleAddress = (await (0, import_whirlpools_client15.getOracleAddress)(poolAddress))[0];
|
|
12749
13166
|
const tunaConfig = await fetchTunaConfig(rpc, tunaConfigAddress);
|
|
12750
|
-
const pool = marketMaker == 0 /* Orca */ ? await (0,
|
|
12751
|
-
const mintA = await (0,
|
|
12752
|
-
const mintB = await (0,
|
|
12753
|
-
const feeRecipientAtaA = (await (0,
|
|
13167
|
+
const pool = marketMaker == 0 /* Orca */ ? await (0, import_whirlpools_client15.fetchWhirlpool)(rpc, poolAddress) : await (0, import_fusionamm_client16.fetchFusionPool)(rpc, poolAddress);
|
|
13168
|
+
const mintA = await (0, import_token_202232.fetchMint)(rpc, pool.data.tokenMintA);
|
|
13169
|
+
const mintB = await (0, import_token_202232.fetchMint)(rpc, pool.data.tokenMintB);
|
|
13170
|
+
const feeRecipientAtaA = (await (0, import_token_202232.findAssociatedTokenPda)({
|
|
12754
13171
|
owner: tunaConfig.data.feeRecipient,
|
|
12755
13172
|
mint: mintA.address,
|
|
12756
13173
|
tokenProgram: mintA.programAddress
|
|
12757
13174
|
}))[0];
|
|
12758
|
-
const feeRecipientAtaB = (await (0,
|
|
13175
|
+
const feeRecipientAtaB = (await (0, import_token_202232.findAssociatedTokenPda)({
|
|
12759
13176
|
owner: tunaConfig.data.feeRecipient,
|
|
12760
13177
|
mint: mintB.address,
|
|
12761
13178
|
tokenProgram: mintB.programAddress
|
|
@@ -12764,24 +13181,24 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
12764
13181
|
(await getLendingVaultAddress(mintA.address))[0],
|
|
12765
13182
|
(await getLendingVaultAddress(mintB.address))[0]
|
|
12766
13183
|
]);
|
|
12767
|
-
const vaultAAta = (await (0,
|
|
13184
|
+
const vaultAAta = (await (0, import_token_202232.findAssociatedTokenPda)({
|
|
12768
13185
|
owner: vaultA.address,
|
|
12769
13186
|
mint: mintA.address,
|
|
12770
13187
|
tokenProgram: mintA.programAddress
|
|
12771
13188
|
}))[0];
|
|
12772
|
-
const vaultBAta = (await (0,
|
|
13189
|
+
const vaultBAta = (await (0, import_token_202232.findAssociatedTokenPda)({
|
|
12773
13190
|
owner: vaultB.address,
|
|
12774
13191
|
mint: mintB.address,
|
|
12775
13192
|
tokenProgram: mintB.programAddress
|
|
12776
13193
|
}))[0];
|
|
12777
13194
|
const addresses = [
|
|
12778
13195
|
import_system2.SYSTEM_PROGRAM_ADDRESS,
|
|
12779
|
-
(0,
|
|
12780
|
-
|
|
13196
|
+
(0, import_kit125.address)("SysvarRent111111111111111111111111111111111"),
|
|
13197
|
+
import_token_202232.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12781
13198
|
import_token2.TOKEN_PROGRAM_ADDRESS,
|
|
12782
|
-
|
|
13199
|
+
import_token_202232.TOKEN_2022_PROGRAM_ADDRESS,
|
|
12783
13200
|
NATIVE_MINT,
|
|
12784
|
-
|
|
13201
|
+
import_memo21.MEMO_PROGRAM_ADDRESS,
|
|
12785
13202
|
tunaConfigAddress,
|
|
12786
13203
|
marketAddress,
|
|
12787
13204
|
mintA.address,
|
|
@@ -12800,7 +13217,7 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
12800
13217
|
if (vaultA.data.pythOraclePriceUpdate != DEFAULT_ADDRESS) addresses.push(vaultA.data.pythOraclePriceUpdate);
|
|
12801
13218
|
if (vaultB.data.pythOraclePriceUpdate != DEFAULT_ADDRESS) addresses.push(vaultB.data.pythOraclePriceUpdate);
|
|
12802
13219
|
if (marketMaker == 0 /* Orca */) {
|
|
12803
|
-
addresses.push(
|
|
13220
|
+
addresses.push(import_whirlpools_client15.WHIRLPOOL_PROGRAM_ADDRESS);
|
|
12804
13221
|
addresses.push(WP_NFT_UPDATE_AUTH);
|
|
12805
13222
|
addresses.push(orcaOracleAddress);
|
|
12806
13223
|
const whirlpool = pool;
|
|
@@ -12812,8 +13229,8 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
12812
13229
|
}
|
|
12813
13230
|
}
|
|
12814
13231
|
} else {
|
|
12815
|
-
addresses.push(
|
|
12816
|
-
addresses.push(
|
|
13232
|
+
addresses.push(import_fusionamm_client16.FUSIONAMM_PROGRAM_ADDRESS);
|
|
13233
|
+
addresses.push(import_fusionamm_client16.FP_NFT_UPDATE_AUTH);
|
|
12817
13234
|
}
|
|
12818
13235
|
return addresses;
|
|
12819
13236
|
}
|
|
@@ -12836,17 +13253,17 @@ async function extendAddressLookupTableForMarketInstructions(rpc, poolAddress, m
|
|
|
12836
13253
|
}
|
|
12837
13254
|
|
|
12838
13255
|
// src/txbuilder/repayTunaLpPositionDebt.ts
|
|
12839
|
-
var
|
|
12840
|
-
var
|
|
12841
|
-
var
|
|
13256
|
+
var import_memo22 = require("@solana-program/memo");
|
|
13257
|
+
var import_token_202233 = require("@solana-program/token-2022");
|
|
13258
|
+
var import_assert23 = __toESM(require("assert"));
|
|
12842
13259
|
async function repayTunaLpPositionDebtInstructions(rpc, authority, positionMint, collateralA, collateralB, createInstructions, cleanupInstructions) {
|
|
12843
13260
|
const instructions = [];
|
|
12844
13261
|
if (!createInstructions) createInstructions = instructions;
|
|
12845
13262
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
12846
13263
|
const tunaPosition = await fetchTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12847
|
-
const [mintA, mintB] = await (0,
|
|
12848
|
-
(0,
|
|
12849
|
-
(0,
|
|
13264
|
+
const [mintA, mintB] = await (0, import_token_202233.fetchAllMaybeMint)(rpc, [tunaPosition.data.mintA, tunaPosition.data.mintB]);
|
|
13265
|
+
(0, import_assert23.default)(mintA.exists, "Token A not found");
|
|
13266
|
+
(0, import_assert23.default)(mintB.exists, "Token B not found");
|
|
12850
13267
|
const marketAddress = (await getMarketAddress(tunaPosition.data.pool))[0];
|
|
12851
13268
|
const createUserAtaAInstructions = await getCreateAtaInstructions(
|
|
12852
13269
|
rpc,
|
|
@@ -12882,34 +13299,34 @@ async function repayTunaLpPositionDebtInstructions(rpc, authority, positionMint,
|
|
|
12882
13299
|
}
|
|
12883
13300
|
async function repayTunaLpPositionDebtInstruction(authority, positionMint, mintA, mintB, marketAddress, collateralA, collateralB) {
|
|
12884
13301
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint))[0];
|
|
12885
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
13302
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12886
13303
|
owner: authority.address,
|
|
12887
13304
|
mint: mintA.address,
|
|
12888
13305
|
tokenProgram: mintA.programAddress
|
|
12889
13306
|
}))[0];
|
|
12890
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
13307
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12891
13308
|
owner: authority.address,
|
|
12892
13309
|
mint: mintB.address,
|
|
12893
13310
|
tokenProgram: mintB.programAddress
|
|
12894
13311
|
}))[0];
|
|
12895
|
-
const tunaPositionAtaA = (await (0,
|
|
13312
|
+
const tunaPositionAtaA = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12896
13313
|
owner: tunaPositionAddress,
|
|
12897
13314
|
mint: mintA.address,
|
|
12898
13315
|
tokenProgram: mintA.programAddress
|
|
12899
13316
|
}))[0];
|
|
12900
|
-
const tunaPositionAtaB = (await (0,
|
|
13317
|
+
const tunaPositionAtaB = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12901
13318
|
owner: tunaPositionAddress,
|
|
12902
13319
|
mint: mintB.address,
|
|
12903
13320
|
tokenProgram: mintB.programAddress
|
|
12904
13321
|
}))[0];
|
|
12905
13322
|
const vaultAAddress = (await getLendingVaultAddress(mintA.address))[0];
|
|
12906
|
-
const vaultAAta = (await (0,
|
|
13323
|
+
const vaultAAta = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12907
13324
|
owner: vaultAAddress,
|
|
12908
13325
|
mint: mintA.address,
|
|
12909
13326
|
tokenProgram: mintA.programAddress
|
|
12910
13327
|
}))[0];
|
|
12911
13328
|
const vaultBAddress = (await getLendingVaultAddress(mintB.address))[0];
|
|
12912
|
-
const vaultBAta = (await (0,
|
|
13329
|
+
const vaultBAta = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12913
13330
|
owner: vaultBAddress,
|
|
12914
13331
|
mint: mintB.address,
|
|
12915
13332
|
tokenProgram: mintB.programAddress
|
|
@@ -12917,7 +13334,7 @@ async function repayTunaLpPositionDebtInstruction(authority, positionMint, mintA
|
|
|
12917
13334
|
return getRepayTunaLpPositionDebtInstruction({
|
|
12918
13335
|
authority,
|
|
12919
13336
|
market: marketAddress,
|
|
12920
|
-
memoProgram:
|
|
13337
|
+
memoProgram: import_memo22.MEMO_PROGRAM_ADDRESS,
|
|
12921
13338
|
mintA: mintA.address,
|
|
12922
13339
|
mintB: mintB.address,
|
|
12923
13340
|
tokenProgramA: mintA.programAddress,
|
|
@@ -12937,39 +13354,39 @@ async function repayTunaLpPositionDebtInstruction(authority, positionMint, mintA
|
|
|
12937
13354
|
}
|
|
12938
13355
|
|
|
12939
13356
|
// src/txbuilder/rebalanceTunaLpPositionOrca.ts
|
|
12940
|
-
var
|
|
12941
|
-
var
|
|
13357
|
+
var import_whirlpools_client16 = require("@orca-so/whirlpools-client");
|
|
13358
|
+
var import_kit126 = require("@solana/kit");
|
|
12942
13359
|
var import_sysvars3 = require("@solana/sysvars");
|
|
12943
|
-
var
|
|
12944
|
-
var
|
|
12945
|
-
var
|
|
13360
|
+
var import_memo23 = require("@solana-program/memo");
|
|
13361
|
+
var import_token_202234 = require("@solana-program/token-2022");
|
|
13362
|
+
var import_assert24 = __toESM(require("assert"));
|
|
12946
13363
|
async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
12947
13364
|
const rent = await (0, import_sysvars3.fetchSysvarRent)(rpc);
|
|
12948
13365
|
let nonRefundableRent = 0n;
|
|
12949
13366
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
12950
13367
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12951
13368
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12952
|
-
const whirlpool = await (0,
|
|
13369
|
+
const whirlpool = await (0, import_whirlpools_client16.fetchMaybeWhirlpool)(rpc, tunaPosition.data.pool);
|
|
12953
13370
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
12954
13371
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
12955
13372
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
12956
13373
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
12957
13374
|
]);
|
|
12958
|
-
const [mintA, mintB] = await (0,
|
|
12959
|
-
(0,
|
|
12960
|
-
(0,
|
|
13375
|
+
const [mintA, mintB] = await (0, import_token_202234.fetchAllMaybeMint)(rpc, [whirlpool.data.tokenMintA, whirlpool.data.tokenMintB]);
|
|
13376
|
+
(0, import_assert24.default)(mintA.exists, "Token A account not found");
|
|
13377
|
+
(0, import_assert24.default)(mintB.exists, "Token B account not found");
|
|
12961
13378
|
const instructions = [];
|
|
12962
13379
|
if (!createInstructions) createInstructions = instructions;
|
|
12963
13380
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
12964
13381
|
const internalCleanupInstructions = [];
|
|
12965
13382
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
12966
|
-
const [lowerTickArray, upperTickArray] = await (0,
|
|
13383
|
+
const [lowerTickArray, upperTickArray] = await (0, import_whirlpools_client16.fetchAllMaybeTickArray)(rpc, [
|
|
12967
13384
|
secondaryTickArrays.lowerTickArrayAddress,
|
|
12968
13385
|
secondaryTickArrays.upperTickArrayAddress
|
|
12969
13386
|
]);
|
|
12970
13387
|
if (!lowerTickArray.exists) {
|
|
12971
13388
|
instructions.push(
|
|
12972
|
-
(0,
|
|
13389
|
+
(0, import_whirlpools_client16.getInitializeDynamicTickArrayInstruction)({
|
|
12973
13390
|
whirlpool: whirlpool.address,
|
|
12974
13391
|
funder: authority,
|
|
12975
13392
|
tickArray: secondaryTickArrays.lowerTickArrayAddress,
|
|
@@ -12977,11 +13394,11 @@ async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionM
|
|
|
12977
13394
|
idempotent: false
|
|
12978
13395
|
})
|
|
12979
13396
|
);
|
|
12980
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
13397
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client16.getDynamicTickArrayMinSize)());
|
|
12981
13398
|
}
|
|
12982
13399
|
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
12983
13400
|
instructions.push(
|
|
12984
|
-
(0,
|
|
13401
|
+
(0, import_whirlpools_client16.getInitializeDynamicTickArrayInstruction)({
|
|
12985
13402
|
whirlpool: whirlpool.address,
|
|
12986
13403
|
funder: authority,
|
|
12987
13404
|
tickArray: secondaryTickArrays.upperTickArrayAddress,
|
|
@@ -12989,7 +13406,7 @@ async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionM
|
|
|
12989
13406
|
idempotent: false
|
|
12990
13407
|
})
|
|
12991
13408
|
);
|
|
12992
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
13409
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client16.getDynamicTickArrayMinSize)());
|
|
12993
13410
|
}
|
|
12994
13411
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
12995
13412
|
rpc,
|
|
@@ -13021,35 +13438,35 @@ async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionM
|
|
|
13021
13438
|
cleanupInstructions.push(...internalCleanupInstructions);
|
|
13022
13439
|
return {
|
|
13023
13440
|
instructions,
|
|
13024
|
-
initializationCost: (0,
|
|
13441
|
+
initializationCost: (0, import_kit126.lamports)(nonRefundableRent)
|
|
13025
13442
|
};
|
|
13026
13443
|
}
|
|
13027
13444
|
async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool) {
|
|
13028
13445
|
const positionMint = tunaPosition.data.positionMint;
|
|
13029
13446
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
13030
|
-
const orcaPositionAddress = (await (0,
|
|
13031
|
-
const orcaOracleAddress = (await (0,
|
|
13032
|
-
const tunaPositionAta = (await (0,
|
|
13447
|
+
const orcaPositionAddress = (await (0, import_whirlpools_client16.getPositionAddress)(positionMint))[0];
|
|
13448
|
+
const orcaOracleAddress = (await (0, import_whirlpools_client16.getOracleAddress)(whirlpool.address))[0];
|
|
13449
|
+
const tunaPositionAta = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13033
13450
|
owner: tunaPosition.address,
|
|
13034
13451
|
mint: positionMint,
|
|
13035
|
-
tokenProgram:
|
|
13452
|
+
tokenProgram: import_token_202234.TOKEN_2022_PROGRAM_ADDRESS
|
|
13036
13453
|
}))[0];
|
|
13037
|
-
const tunaPositionAtaA = (await (0,
|
|
13454
|
+
const tunaPositionAtaA = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13038
13455
|
owner: tunaPosition.address,
|
|
13039
13456
|
mint: mintA.address,
|
|
13040
13457
|
tokenProgram: mintA.programAddress
|
|
13041
13458
|
}))[0];
|
|
13042
|
-
const tunaPositionAtaB = (await (0,
|
|
13459
|
+
const tunaPositionAtaB = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13043
13460
|
owner: tunaPosition.address,
|
|
13044
13461
|
mint: mintB.address,
|
|
13045
13462
|
tokenProgram: mintB.programAddress
|
|
13046
13463
|
}))[0];
|
|
13047
|
-
const feeRecipientAtaA = (await (0,
|
|
13464
|
+
const feeRecipientAtaA = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13048
13465
|
owner: tunaConfig.data.feeRecipient,
|
|
13049
13466
|
mint: mintA.address,
|
|
13050
13467
|
tokenProgram: mintA.programAddress
|
|
13051
13468
|
}))[0];
|
|
13052
|
-
const feeRecipientAtaB = (await (0,
|
|
13469
|
+
const feeRecipientAtaB = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13053
13470
|
owner: tunaConfig.data.feeRecipient,
|
|
13054
13471
|
mint: mintB.address,
|
|
13055
13472
|
tokenProgram: mintB.programAddress
|
|
@@ -13065,18 +13482,18 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13065
13482
|
);
|
|
13066
13483
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
13067
13484
|
const remainingAccounts = [
|
|
13068
|
-
{ address: swapTickArrays[0], role:
|
|
13069
|
-
{ address: swapTickArrays[1], role:
|
|
13070
|
-
{ address: swapTickArrays[2], role:
|
|
13071
|
-
{ address: swapTickArrays[3], role:
|
|
13072
|
-
{ address: swapTickArrays[4], role:
|
|
13073
|
-
{ address: lowerTickArrayAddress, role:
|
|
13074
|
-
{ address: upperTickArrayAddress, role:
|
|
13075
|
-
{ address: secondaryTickArrays.lowerTickArrayAddress, role:
|
|
13076
|
-
{ address: secondaryTickArrays.upperTickArrayAddress, role:
|
|
13077
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
13078
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
13079
|
-
{ address: orcaOracleAddress, role:
|
|
13485
|
+
{ address: swapTickArrays[0], role: import_kit126.AccountRole.WRITABLE },
|
|
13486
|
+
{ address: swapTickArrays[1], role: import_kit126.AccountRole.WRITABLE },
|
|
13487
|
+
{ address: swapTickArrays[2], role: import_kit126.AccountRole.WRITABLE },
|
|
13488
|
+
{ address: swapTickArrays[3], role: import_kit126.AccountRole.WRITABLE },
|
|
13489
|
+
{ address: swapTickArrays[4], role: import_kit126.AccountRole.WRITABLE },
|
|
13490
|
+
{ address: lowerTickArrayAddress, role: import_kit126.AccountRole.WRITABLE },
|
|
13491
|
+
{ address: upperTickArrayAddress, role: import_kit126.AccountRole.WRITABLE },
|
|
13492
|
+
{ address: secondaryTickArrays.lowerTickArrayAddress, role: import_kit126.AccountRole.WRITABLE },
|
|
13493
|
+
{ address: secondaryTickArrays.upperTickArrayAddress, role: import_kit126.AccountRole.WRITABLE },
|
|
13494
|
+
{ address: whirlpool.data.tokenVaultA, role: import_kit126.AccountRole.WRITABLE },
|
|
13495
|
+
{ address: whirlpool.data.tokenVaultB, role: import_kit126.AccountRole.WRITABLE },
|
|
13496
|
+
{ address: orcaOracleAddress, role: import_kit126.AccountRole.WRITABLE }
|
|
13080
13497
|
];
|
|
13081
13498
|
const remainingAccountsInfo = {
|
|
13082
13499
|
slices: [
|
|
@@ -13108,10 +13525,10 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13108
13525
|
feeRecipientAtaA,
|
|
13109
13526
|
feeRecipientAtaB,
|
|
13110
13527
|
whirlpool: whirlpool.address,
|
|
13111
|
-
whirlpoolProgram:
|
|
13528
|
+
whirlpoolProgram: import_whirlpools_client16.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
13112
13529
|
tokenProgramA: mintA.programAddress,
|
|
13113
13530
|
tokenProgramB: mintB.programAddress,
|
|
13114
|
-
memoProgram:
|
|
13531
|
+
memoProgram: import_memo23.MEMO_PROGRAM_ADDRESS,
|
|
13115
13532
|
remainingAccountsInfo
|
|
13116
13533
|
});
|
|
13117
13534
|
ix.accounts.push(...remainingAccounts);
|
|
@@ -13119,56 +13536,56 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13119
13536
|
}
|
|
13120
13537
|
|
|
13121
13538
|
// src/txbuilder/rebalanceTunaLpPositionFusion.ts
|
|
13122
|
-
var
|
|
13123
|
-
var
|
|
13539
|
+
var import_fusionamm_client17 = require("@crypticdot/fusionamm-client");
|
|
13540
|
+
var import_kit127 = require("@solana/kit");
|
|
13124
13541
|
var import_sysvars4 = require("@solana/sysvars");
|
|
13125
|
-
var
|
|
13126
|
-
var
|
|
13127
|
-
var
|
|
13542
|
+
var import_memo24 = require("@solana-program/memo");
|
|
13543
|
+
var import_token_202235 = require("@solana-program/token-2022");
|
|
13544
|
+
var import_assert25 = __toESM(require("assert"));
|
|
13128
13545
|
async function rebalanceTunaLpPositionFusionInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
13129
13546
|
const rent = await (0, import_sysvars4.fetchSysvarRent)(rpc);
|
|
13130
13547
|
let nonRefundableRent = 0n;
|
|
13131
13548
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
13132
13549
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
13133
13550
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
13134
|
-
const fusionPool = await (0,
|
|
13551
|
+
const fusionPool = await (0, import_fusionamm_client17.fetchMaybeFusionPool)(rpc, tunaPosition.data.pool);
|
|
13135
13552
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
13136
13553
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
13137
13554
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
13138
13555
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
13139
13556
|
]);
|
|
13140
|
-
const [mintA, mintB] = await (0,
|
|
13141
|
-
(0,
|
|
13142
|
-
(0,
|
|
13557
|
+
const [mintA, mintB] = await (0, import_token_202235.fetchAllMaybeMint)(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
13558
|
+
(0, import_assert25.default)(mintA.exists, "Token A account not found");
|
|
13559
|
+
(0, import_assert25.default)(mintB.exists, "Token B account not found");
|
|
13143
13560
|
const instructions = [];
|
|
13144
13561
|
if (!createInstructions) createInstructions = instructions;
|
|
13145
13562
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
13146
13563
|
const secondaryTickArrays = await FusionUtils.getTickArraysForRebalancedPosition(fusionPool, tunaPosition);
|
|
13147
|
-
const [lowerTickArray, upperTickArray] = await (0,
|
|
13564
|
+
const [lowerTickArray, upperTickArray] = await (0, import_fusionamm_client17.fetchAllMaybeTickArray)(rpc, [
|
|
13148
13565
|
secondaryTickArrays.lowerTickArrayAddress,
|
|
13149
13566
|
secondaryTickArrays.upperTickArrayAddress
|
|
13150
13567
|
]);
|
|
13151
13568
|
if (!lowerTickArray.exists) {
|
|
13152
13569
|
instructions.push(
|
|
13153
|
-
(0,
|
|
13570
|
+
(0, import_fusionamm_client17.getInitializeTickArrayInstruction)({
|
|
13154
13571
|
fusionPool: fusionPool.address,
|
|
13155
13572
|
funder: authority,
|
|
13156
13573
|
tickArray: secondaryTickArrays.lowerTickArrayAddress,
|
|
13157
13574
|
startTickIndex: secondaryTickArrays.lowerTickArrayStartIndex
|
|
13158
13575
|
})
|
|
13159
13576
|
);
|
|
13160
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
13577
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client17.getTickArraySize)());
|
|
13161
13578
|
}
|
|
13162
13579
|
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
13163
13580
|
instructions.push(
|
|
13164
|
-
(0,
|
|
13581
|
+
(0, import_fusionamm_client17.getInitializeTickArrayInstruction)({
|
|
13165
13582
|
fusionPool: fusionPool.address,
|
|
13166
13583
|
funder: authority,
|
|
13167
13584
|
tickArray: secondaryTickArrays.upperTickArrayAddress,
|
|
13168
13585
|
startTickIndex: secondaryTickArrays.upperTickArrayStartIndex
|
|
13169
13586
|
})
|
|
13170
13587
|
);
|
|
13171
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
13588
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client17.getTickArraySize)());
|
|
13172
13589
|
}
|
|
13173
13590
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
13174
13591
|
rpc,
|
|
@@ -13199,34 +13616,34 @@ async function rebalanceTunaLpPositionFusionInstructions(rpc, authority, positio
|
|
|
13199
13616
|
instructions.push(ix);
|
|
13200
13617
|
return {
|
|
13201
13618
|
instructions,
|
|
13202
|
-
initializationCost: (0,
|
|
13619
|
+
initializationCost: (0, import_kit127.lamports)(nonRefundableRent)
|
|
13203
13620
|
};
|
|
13204
13621
|
}
|
|
13205
13622
|
async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool) {
|
|
13206
13623
|
const positionMint = tunaPosition.data.positionMint;
|
|
13207
13624
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
13208
|
-
const fusionPositionAddress = (await (0,
|
|
13209
|
-
const tunaPositionAta = (await (0,
|
|
13625
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client17.getPositionAddress)(positionMint))[0];
|
|
13626
|
+
const tunaPositionAta = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13210
13627
|
owner: tunaPosition.address,
|
|
13211
13628
|
mint: positionMint,
|
|
13212
|
-
tokenProgram:
|
|
13629
|
+
tokenProgram: import_token_202235.TOKEN_2022_PROGRAM_ADDRESS
|
|
13213
13630
|
}))[0];
|
|
13214
|
-
const tunaPositionAtaA = (await (0,
|
|
13631
|
+
const tunaPositionAtaA = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13215
13632
|
owner: tunaPosition.address,
|
|
13216
13633
|
mint: mintA.address,
|
|
13217
13634
|
tokenProgram: mintA.programAddress
|
|
13218
13635
|
}))[0];
|
|
13219
|
-
const tunaPositionAtaB = (await (0,
|
|
13636
|
+
const tunaPositionAtaB = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13220
13637
|
owner: tunaPosition.address,
|
|
13221
13638
|
mint: mintB.address,
|
|
13222
13639
|
tokenProgram: mintB.programAddress
|
|
13223
13640
|
}))[0];
|
|
13224
|
-
const feeRecipientAtaA = (await (0,
|
|
13641
|
+
const feeRecipientAtaA = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13225
13642
|
owner: tunaConfig.data.feeRecipient,
|
|
13226
13643
|
mint: mintA.address,
|
|
13227
13644
|
tokenProgram: mintA.programAddress
|
|
13228
13645
|
}))[0];
|
|
13229
|
-
const feeRecipientAtaB = (await (0,
|
|
13646
|
+
const feeRecipientAtaB = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13230
13647
|
owner: tunaConfig.data.feeRecipient,
|
|
13231
13648
|
mint: mintB.address,
|
|
13232
13649
|
tokenProgram: mintB.programAddress
|
|
@@ -13242,17 +13659,17 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13242
13659
|
);
|
|
13243
13660
|
const secondaryTickArrays = await FusionUtils.getTickArraysForRebalancedPosition(fusionPool, tunaPosition);
|
|
13244
13661
|
const remainingAccounts = [
|
|
13245
|
-
{ address: swapTickArrays[0], role:
|
|
13246
|
-
{ address: swapTickArrays[1], role:
|
|
13247
|
-
{ address: swapTickArrays[2], role:
|
|
13248
|
-
{ address: swapTickArrays[3], role:
|
|
13249
|
-
{ address: swapTickArrays[4], role:
|
|
13250
|
-
{ address: lowerTickArrayAddress, role:
|
|
13251
|
-
{ address: upperTickArrayAddress, role:
|
|
13252
|
-
{ address: secondaryTickArrays.lowerTickArrayAddress, role:
|
|
13253
|
-
{ address: secondaryTickArrays.upperTickArrayAddress, role:
|
|
13254
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
13255
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
13662
|
+
{ address: swapTickArrays[0], role: import_kit127.AccountRole.WRITABLE },
|
|
13663
|
+
{ address: swapTickArrays[1], role: import_kit127.AccountRole.WRITABLE },
|
|
13664
|
+
{ address: swapTickArrays[2], role: import_kit127.AccountRole.WRITABLE },
|
|
13665
|
+
{ address: swapTickArrays[3], role: import_kit127.AccountRole.WRITABLE },
|
|
13666
|
+
{ address: swapTickArrays[4], role: import_kit127.AccountRole.WRITABLE },
|
|
13667
|
+
{ address: lowerTickArrayAddress, role: import_kit127.AccountRole.WRITABLE },
|
|
13668
|
+
{ address: upperTickArrayAddress, role: import_kit127.AccountRole.WRITABLE },
|
|
13669
|
+
{ address: secondaryTickArrays.lowerTickArrayAddress, role: import_kit127.AccountRole.WRITABLE },
|
|
13670
|
+
{ address: secondaryTickArrays.upperTickArrayAddress, role: import_kit127.AccountRole.WRITABLE },
|
|
13671
|
+
{ address: fusionPool.data.tokenVaultA, role: import_kit127.AccountRole.WRITABLE },
|
|
13672
|
+
{ address: fusionPool.data.tokenVaultB, role: import_kit127.AccountRole.WRITABLE }
|
|
13256
13673
|
];
|
|
13257
13674
|
const remainingAccountsInfo = {
|
|
13258
13675
|
slices: [
|
|
@@ -13283,10 +13700,10 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13283
13700
|
feeRecipientAtaA,
|
|
13284
13701
|
feeRecipientAtaB,
|
|
13285
13702
|
fusionPool: fusionPool.address,
|
|
13286
|
-
fusionammProgram:
|
|
13703
|
+
fusionammProgram: import_fusionamm_client17.FUSIONAMM_PROGRAM_ADDRESS,
|
|
13287
13704
|
tokenProgramA: mintA.programAddress,
|
|
13288
13705
|
tokenProgramB: mintB.programAddress,
|
|
13289
|
-
memoProgram:
|
|
13706
|
+
memoProgram: import_memo24.MEMO_PROGRAM_ADDRESS,
|
|
13290
13707
|
remainingAccountsInfo
|
|
13291
13708
|
});
|
|
13292
13709
|
ix.accounts.push(...remainingAccounts);
|
|
@@ -13838,6 +14255,8 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13838
14255
|
liquidateTunaSpotPositionOrcaInstructions,
|
|
13839
14256
|
modifyTunaSpotPositionFusionInstruction,
|
|
13840
14257
|
modifyTunaSpotPositionFusionInstructions,
|
|
14258
|
+
modifyTunaSpotPositionJupiterInstruction,
|
|
14259
|
+
modifyTunaSpotPositionJupiterInstructions,
|
|
13841
14260
|
modifyTunaSpotPositionOrcaInstruction,
|
|
13842
14261
|
modifyTunaSpotPositionOrcaInstructions,
|
|
13843
14262
|
mulDiv,
|