@crypticdot/defituna-client 3.3.1 → 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 +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +888 -465
- package/dist/index.mjs +1149 -359
- package/package.json +2 -2
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,
|
|
@@ -10612,23 +10614,29 @@ async function modifyTunaSpotPositionOrcaInstructions(rpc, authority, poolAddres
|
|
|
10612
10614
|
(await getLendingVaultAddress(pool.data.tokenMintA))[0],
|
|
10613
10615
|
(await getLendingVaultAddress(pool.data.tokenMintB))[0]
|
|
10614
10616
|
]);
|
|
10615
|
-
|
|
10616
|
-
|
|
10617
|
-
|
|
10618
|
-
|
|
10619
|
-
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
|
|
10623
|
-
|
|
10624
|
-
|
|
10625
|
-
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
|
|
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;
|
|
10630
10638
|
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
10631
|
-
const createUserAtaBInstructions = collateralToken == 1 /* B */ ||
|
|
10639
|
+
const createUserAtaBInstructions = collateralToken == 1 /* B */ || hasDirectlyTransferredTokensB ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
10632
10640
|
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
10633
10641
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10634
10642
|
rpc,
|
|
@@ -10783,23 +10791,29 @@ async function modifyTunaSpotPositionFusionInstructions(rpc, authority, poolAddr
|
|
|
10783
10791
|
(await getLendingVaultAddress(pool.data.tokenMintA))[0],
|
|
10784
10792
|
(await getLendingVaultAddress(pool.data.tokenMintB))[0]
|
|
10785
10793
|
]);
|
|
10786
|
-
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
|
|
10792
|
-
|
|
10793
|
-
|
|
10794
|
-
|
|
10795
|
-
|
|
10796
|
-
|
|
10797
|
-
|
|
10798
|
-
|
|
10799
|
-
|
|
10800
|
-
|
|
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;
|
|
10801
10815
|
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
10802
|
-
const createUserAtaBInstructions = collateralToken == 1 /* B */ ||
|
|
10816
|
+
const createUserAtaBInstructions = collateralToken == 1 /* B */ || hasDirectlyTransferredTokensB ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
10803
10817
|
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
10804
10818
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10805
10819
|
rpc,
|
|
@@ -10925,27 +10939,434 @@ async function modifyTunaSpotPositionFusionInstruction(authority, tunaConfig, mi
|
|
|
10925
10939
|
return ix;
|
|
10926
10940
|
}
|
|
10927
10941
|
|
|
10928
|
-
// 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");
|
|
10929
11209
|
var import_token_202215 = require("@solana-program/token-2022");
|
|
10930
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"));
|
|
10931
11352
|
async function closeTunaSpotPositionInstructions(rpc, authority, poolAddress) {
|
|
10932
11353
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
10933
11354
|
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
10934
11355
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
10935
|
-
const [mintA, mintB] = await (0,
|
|
10936
|
-
(0,
|
|
10937
|
-
(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");
|
|
10938
11359
|
const ix = await closeTunaSpotPositionInstruction(authority, poolAddress, mintA, mintB);
|
|
10939
11360
|
return [ix];
|
|
10940
11361
|
}
|
|
10941
11362
|
async function closeTunaSpotPositionInstruction(authority, poolAddress, mintA, mintB) {
|
|
10942
11363
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
10943
|
-
const tunaPositionAtaA = (await (0,
|
|
11364
|
+
const tunaPositionAtaA = (await (0, import_token_202216.findAssociatedTokenPda)({
|
|
10944
11365
|
owner: tunaPositionAddress,
|
|
10945
11366
|
mint: mintA.address,
|
|
10946
11367
|
tokenProgram: mintA.programAddress
|
|
10947
11368
|
}))[0];
|
|
10948
|
-
const tunaPositionAtaB = (await (0,
|
|
11369
|
+
const tunaPositionAtaB = (await (0, import_token_202216.findAssociatedTokenPda)({
|
|
10949
11370
|
owner: tunaPositionAddress,
|
|
10950
11371
|
mint: mintB.address,
|
|
10951
11372
|
tokenProgram: mintB.programAddress
|
|
@@ -10989,11 +11410,11 @@ async function createTunaConfigInstruction(authority, ownerAuthority, adminAutho
|
|
|
10989
11410
|
}
|
|
10990
11411
|
|
|
10991
11412
|
// src/txbuilder/createVault.ts
|
|
10992
|
-
var
|
|
11413
|
+
var import_token_202217 = require("@solana-program/token-2022");
|
|
10993
11414
|
async function createVaultInstructions(authority, mint, args) {
|
|
10994
11415
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
10995
11416
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
10996
|
-
const vaultAta = (await (0,
|
|
11417
|
+
const vaultAta = (await (0, import_token_202217.findAssociatedTokenPda)({
|
|
10997
11418
|
owner: vault,
|
|
10998
11419
|
mint: mint.address,
|
|
10999
11420
|
tokenProgram: mint.programAddress
|
|
@@ -11013,10 +11434,10 @@ async function createVaultInstructions(authority, mint, args) {
|
|
|
11013
11434
|
}
|
|
11014
11435
|
|
|
11015
11436
|
// src/txbuilder/liquidateTunaLpPositionOrca.ts
|
|
11016
|
-
var
|
|
11017
|
-
var
|
|
11018
|
-
var
|
|
11019
|
-
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");
|
|
11020
11441
|
async function liquidateTunaLpPositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11021
11442
|
const instructions = [];
|
|
11022
11443
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
@@ -11054,39 +11475,39 @@ async function liquidateTunaLpPositionOrcaInstructions(authority, tunaPosition,
|
|
|
11054
11475
|
async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11055
11476
|
const positionMint = tunaPosition.data.positionMint;
|
|
11056
11477
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11057
|
-
const orcaPositionAddress = (await (0,
|
|
11058
|
-
const orcaOracleAddress = (await (0,
|
|
11059
|
-
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)({
|
|
11060
11481
|
owner: tunaPosition.address,
|
|
11061
11482
|
mint: positionMint,
|
|
11062
|
-
tokenProgram:
|
|
11483
|
+
tokenProgram: import_token_202218.TOKEN_2022_PROGRAM_ADDRESS
|
|
11063
11484
|
}))[0];
|
|
11064
|
-
const tunaPositionAtaA = (await (0,
|
|
11485
|
+
const tunaPositionAtaA = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11065
11486
|
owner: tunaPosition.address,
|
|
11066
11487
|
mint: mintA.address,
|
|
11067
11488
|
tokenProgram: mintA.programAddress
|
|
11068
11489
|
}))[0];
|
|
11069
|
-
const tunaPositionAtaB = (await (0,
|
|
11490
|
+
const tunaPositionAtaB = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11070
11491
|
owner: tunaPosition.address,
|
|
11071
11492
|
mint: mintB.address,
|
|
11072
11493
|
tokenProgram: mintB.programAddress
|
|
11073
11494
|
}))[0];
|
|
11074
|
-
const vaultAAta = (await (0,
|
|
11495
|
+
const vaultAAta = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11075
11496
|
owner: vaultA.address,
|
|
11076
11497
|
mint: mintA.address,
|
|
11077
11498
|
tokenProgram: mintA.programAddress
|
|
11078
11499
|
}))[0];
|
|
11079
|
-
const vaultBAta = (await (0,
|
|
11500
|
+
const vaultBAta = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11080
11501
|
owner: vaultB.address,
|
|
11081
11502
|
mint: mintB.address,
|
|
11082
11503
|
tokenProgram: mintB.programAddress
|
|
11083
11504
|
}))[0];
|
|
11084
|
-
const feeRecipientAtaA = (await (0,
|
|
11505
|
+
const feeRecipientAtaA = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11085
11506
|
owner: tunaConfig.data.feeRecipient,
|
|
11086
11507
|
mint: mintA.address,
|
|
11087
11508
|
tokenProgram: mintA.programAddress
|
|
11088
11509
|
}))[0];
|
|
11089
|
-
const feeRecipientAtaB = (await (0,
|
|
11510
|
+
const feeRecipientAtaB = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
11090
11511
|
owner: tunaConfig.data.feeRecipient,
|
|
11091
11512
|
mint: mintB.address,
|
|
11092
11513
|
tokenProgram: mintB.programAddress
|
|
@@ -11101,16 +11522,16 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11101
11522
|
tunaPosition.data.tickUpperIndex
|
|
11102
11523
|
);
|
|
11103
11524
|
const remainingAccounts = [
|
|
11104
|
-
{ address: swapTickArrays[0], role:
|
|
11105
|
-
{ address: swapTickArrays[1], role:
|
|
11106
|
-
{ address: swapTickArrays[2], role:
|
|
11107
|
-
{ address: swapTickArrays[3], role:
|
|
11108
|
-
{ address: swapTickArrays[4], role:
|
|
11109
|
-
{ address: lowerTickArrayAddress, role:
|
|
11110
|
-
{ address: upperTickArrayAddress, role:
|
|
11111
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
11112
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
11113
|
-
{ 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 }
|
|
11114
11535
|
];
|
|
11115
11536
|
const remainingAccountsInfo = {
|
|
11116
11537
|
slices: [
|
|
@@ -11142,10 +11563,10 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11142
11563
|
feeRecipientAtaA,
|
|
11143
11564
|
feeRecipientAtaB,
|
|
11144
11565
|
whirlpool: whirlpool.address,
|
|
11145
|
-
whirlpoolProgram:
|
|
11566
|
+
whirlpoolProgram: import_whirlpools_client9.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11146
11567
|
tokenProgramA: mintA.programAddress,
|
|
11147
11568
|
tokenProgramB: mintB.programAddress,
|
|
11148
|
-
memoProgram:
|
|
11569
|
+
memoProgram: import_memo11.MEMO_PROGRAM_ADDRESS,
|
|
11149
11570
|
decreasePercent,
|
|
11150
11571
|
remainingAccountsInfo
|
|
11151
11572
|
});
|
|
@@ -11154,10 +11575,10 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11154
11575
|
}
|
|
11155
11576
|
|
|
11156
11577
|
// src/txbuilder/liquidateTunaLpPositionFusion.ts
|
|
11157
|
-
var
|
|
11158
|
-
var
|
|
11159
|
-
var
|
|
11160
|
-
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");
|
|
11161
11582
|
async function liquidateTunaLpPositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11162
11583
|
const instructions = [];
|
|
11163
11584
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
@@ -11195,38 +11616,38 @@ async function liquidateTunaLpPositionFusionInstructions(authority, tunaPosition
|
|
|
11195
11616
|
async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, decreasePercent) {
|
|
11196
11617
|
const positionMint = tunaPosition.data.positionMint;
|
|
11197
11618
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11198
|
-
const fusionPositionAddress = (await (0,
|
|
11199
|
-
const tunaPositionAta = (await (0,
|
|
11619
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client9.getPositionAddress)(positionMint))[0];
|
|
11620
|
+
const tunaPositionAta = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11200
11621
|
owner: tunaPosition.address,
|
|
11201
11622
|
mint: positionMint,
|
|
11202
|
-
tokenProgram:
|
|
11623
|
+
tokenProgram: import_token_202219.TOKEN_2022_PROGRAM_ADDRESS
|
|
11203
11624
|
}))[0];
|
|
11204
|
-
const tunaPositionAtaA = (await (0,
|
|
11625
|
+
const tunaPositionAtaA = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11205
11626
|
owner: tunaPosition.address,
|
|
11206
11627
|
mint: mintA.address,
|
|
11207
11628
|
tokenProgram: mintA.programAddress
|
|
11208
11629
|
}))[0];
|
|
11209
|
-
const tunaPositionAtaB = (await (0,
|
|
11630
|
+
const tunaPositionAtaB = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11210
11631
|
owner: tunaPosition.address,
|
|
11211
11632
|
mint: mintB.address,
|
|
11212
11633
|
tokenProgram: mintB.programAddress
|
|
11213
11634
|
}))[0];
|
|
11214
|
-
const vaultAAta = (await (0,
|
|
11635
|
+
const vaultAAta = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11215
11636
|
owner: vaultA.address,
|
|
11216
11637
|
mint: mintA.address,
|
|
11217
11638
|
tokenProgram: mintA.programAddress
|
|
11218
11639
|
}))[0];
|
|
11219
|
-
const vaultBAta = (await (0,
|
|
11640
|
+
const vaultBAta = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11220
11641
|
owner: vaultB.address,
|
|
11221
11642
|
mint: mintB.address,
|
|
11222
11643
|
tokenProgram: mintB.programAddress
|
|
11223
11644
|
}))[0];
|
|
11224
|
-
const feeRecipientAtaA = (await (0,
|
|
11645
|
+
const feeRecipientAtaA = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11225
11646
|
owner: tunaConfig.data.feeRecipient,
|
|
11226
11647
|
mint: mintA.address,
|
|
11227
11648
|
tokenProgram: mintA.programAddress
|
|
11228
11649
|
}))[0];
|
|
11229
|
-
const feeRecipientAtaB = (await (0,
|
|
11650
|
+
const feeRecipientAtaB = (await (0, import_token_202219.findAssociatedTokenPda)({
|
|
11230
11651
|
owner: tunaConfig.data.feeRecipient,
|
|
11231
11652
|
mint: mintB.address,
|
|
11232
11653
|
tokenProgram: mintB.programAddress
|
|
@@ -11241,15 +11662,15 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11241
11662
|
tunaPosition.data.tickUpperIndex
|
|
11242
11663
|
);
|
|
11243
11664
|
const remainingAccounts = [
|
|
11244
|
-
{ address: swapTickArrays[0], role:
|
|
11245
|
-
{ address: swapTickArrays[1], role:
|
|
11246
|
-
{ address: swapTickArrays[2], role:
|
|
11247
|
-
{ address: swapTickArrays[3], role:
|
|
11248
|
-
{ address: swapTickArrays[4], role:
|
|
11249
|
-
{ address: lowerTickArrayAddress, role:
|
|
11250
|
-
{ address: upperTickArrayAddress, role:
|
|
11251
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
11252
|
-
{ 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 }
|
|
11253
11674
|
];
|
|
11254
11675
|
const remainingAccountsInfo = {
|
|
11255
11676
|
slices: [
|
|
@@ -11280,10 +11701,10 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11280
11701
|
feeRecipientAtaA,
|
|
11281
11702
|
feeRecipientAtaB,
|
|
11282
11703
|
fusionPool: fusionPool.address,
|
|
11283
|
-
fusionammProgram:
|
|
11704
|
+
fusionammProgram: import_fusionamm_client9.FUSIONAMM_PROGRAM_ADDRESS,
|
|
11284
11705
|
tokenProgramA: mintA.programAddress,
|
|
11285
11706
|
tokenProgramB: mintB.programAddress,
|
|
11286
|
-
memoProgram:
|
|
11707
|
+
memoProgram: import_memo12.MEMO_PROGRAM_ADDRESS,
|
|
11287
11708
|
decreasePercent,
|
|
11288
11709
|
remainingAccountsInfo
|
|
11289
11710
|
});
|
|
@@ -11292,10 +11713,10 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11292
11713
|
}
|
|
11293
11714
|
|
|
11294
11715
|
// src/txbuilder/liquidateTunaSpotPositionFusion.ts
|
|
11295
|
-
var
|
|
11296
|
-
var
|
|
11297
|
-
var
|
|
11298
|
-
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");
|
|
11299
11720
|
async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, createTunaPositionOwnerAta, decreasePercent) {
|
|
11300
11721
|
const instructions = [];
|
|
11301
11722
|
if (createTunaPositionOwnerAta) {
|
|
@@ -11343,55 +11764,55 @@ async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPositi
|
|
|
11343
11764
|
}
|
|
11344
11765
|
async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, decreasePercent) {
|
|
11345
11766
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11346
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
11767
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11347
11768
|
owner: tunaPosition.data.authority,
|
|
11348
11769
|
mint: mintA.address,
|
|
11349
11770
|
tokenProgram: mintA.programAddress
|
|
11350
11771
|
}))[0];
|
|
11351
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
11772
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11352
11773
|
owner: tunaPosition.data.authority,
|
|
11353
11774
|
mint: mintB.address,
|
|
11354
11775
|
tokenProgram: mintB.programAddress
|
|
11355
11776
|
}))[0];
|
|
11356
|
-
const tunaPositionAtaA = (await (0,
|
|
11777
|
+
const tunaPositionAtaA = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11357
11778
|
owner: tunaPosition.address,
|
|
11358
11779
|
mint: mintA.address,
|
|
11359
11780
|
tokenProgram: mintA.programAddress
|
|
11360
11781
|
}))[0];
|
|
11361
|
-
const tunaPositionAtaB = (await (0,
|
|
11782
|
+
const tunaPositionAtaB = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11362
11783
|
owner: tunaPosition.address,
|
|
11363
11784
|
mint: mintB.address,
|
|
11364
11785
|
tokenProgram: mintB.programAddress
|
|
11365
11786
|
}))[0];
|
|
11366
|
-
const feeRecipientAtaA = (await (0,
|
|
11787
|
+
const feeRecipientAtaA = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11367
11788
|
owner: tunaConfig.data.feeRecipient,
|
|
11368
11789
|
mint: mintA.address,
|
|
11369
11790
|
tokenProgram: mintA.programAddress
|
|
11370
11791
|
}))[0];
|
|
11371
|
-
const feeRecipientAtaB = (await (0,
|
|
11792
|
+
const feeRecipientAtaB = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11372
11793
|
owner: tunaConfig.data.feeRecipient,
|
|
11373
11794
|
mint: mintB.address,
|
|
11374
11795
|
tokenProgram: mintB.programAddress
|
|
11375
11796
|
}))[0];
|
|
11376
|
-
const vaultAAta = (await (0,
|
|
11797
|
+
const vaultAAta = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11377
11798
|
owner: vaultA.address,
|
|
11378
11799
|
mint: mintA.address,
|
|
11379
11800
|
tokenProgram: mintA.programAddress
|
|
11380
11801
|
}))[0];
|
|
11381
|
-
const vaultBAta = (await (0,
|
|
11802
|
+
const vaultBAta = (await (0, import_token_202220.findAssociatedTokenPda)({
|
|
11382
11803
|
owner: vaultB.address,
|
|
11383
11804
|
mint: mintB.address,
|
|
11384
11805
|
tokenProgram: mintB.programAddress
|
|
11385
11806
|
}))[0];
|
|
11386
11807
|
const swapTickArrays = await FusionUtils.getSwapTickArrayAddresses(fusionPool);
|
|
11387
11808
|
const remainingAccounts = [
|
|
11388
|
-
{ address: swapTickArrays[0], role:
|
|
11389
|
-
{ address: swapTickArrays[1], role:
|
|
11390
|
-
{ address: swapTickArrays[2], role:
|
|
11391
|
-
{ address: swapTickArrays[3], role:
|
|
11392
|
-
{ address: swapTickArrays[4], role:
|
|
11393
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
11394
|
-
{ 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 }
|
|
11395
11816
|
];
|
|
11396
11817
|
const remainingAccountsInfo = {
|
|
11397
11818
|
slices: [
|
|
@@ -11423,8 +11844,8 @@ async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPositio
|
|
|
11423
11844
|
feeRecipientAtaA,
|
|
11424
11845
|
feeRecipientAtaB,
|
|
11425
11846
|
fusionPool: fusionPool.address,
|
|
11426
|
-
fusionammProgram:
|
|
11427
|
-
memoProgram:
|
|
11847
|
+
fusionammProgram: import_fusionamm_client10.FUSIONAMM_PROGRAM_ADDRESS,
|
|
11848
|
+
memoProgram: import_memo13.MEMO_PROGRAM_ADDRESS,
|
|
11428
11849
|
decreasePercent,
|
|
11429
11850
|
remainingAccountsInfo
|
|
11430
11851
|
});
|
|
@@ -11433,10 +11854,10 @@ async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPositio
|
|
|
11433
11854
|
}
|
|
11434
11855
|
|
|
11435
11856
|
// src/txbuilder/liquidateTunaSpotPositionOrca.ts
|
|
11436
|
-
var
|
|
11437
|
-
var
|
|
11438
|
-
var
|
|
11439
|
-
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");
|
|
11440
11861
|
async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, createTunaPositionOwnerAta, decreasePercent) {
|
|
11441
11862
|
const instructions = [];
|
|
11442
11863
|
if (createTunaPositionOwnerAta) {
|
|
@@ -11484,57 +11905,57 @@ async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition
|
|
|
11484
11905
|
}
|
|
11485
11906
|
async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11486
11907
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11487
|
-
const orcaOracleAddress = (await (0,
|
|
11488
|
-
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)({
|
|
11489
11910
|
owner: tunaPosition.data.authority,
|
|
11490
11911
|
mint: mintA.address,
|
|
11491
11912
|
tokenProgram: mintA.programAddress
|
|
11492
11913
|
}))[0];
|
|
11493
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
11914
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11494
11915
|
owner: tunaPosition.data.authority,
|
|
11495
11916
|
mint: mintB.address,
|
|
11496
11917
|
tokenProgram: mintB.programAddress
|
|
11497
11918
|
}))[0];
|
|
11498
|
-
const tunaPositionAtaA = (await (0,
|
|
11919
|
+
const tunaPositionAtaA = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11499
11920
|
owner: tunaPosition.address,
|
|
11500
11921
|
mint: mintA.address,
|
|
11501
11922
|
tokenProgram: mintA.programAddress
|
|
11502
11923
|
}))[0];
|
|
11503
|
-
const tunaPositionAtaB = (await (0,
|
|
11924
|
+
const tunaPositionAtaB = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11504
11925
|
owner: tunaPosition.address,
|
|
11505
11926
|
mint: mintB.address,
|
|
11506
11927
|
tokenProgram: mintB.programAddress
|
|
11507
11928
|
}))[0];
|
|
11508
|
-
const feeRecipientAtaA = (await (0,
|
|
11929
|
+
const feeRecipientAtaA = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11509
11930
|
owner: tunaConfig.data.feeRecipient,
|
|
11510
11931
|
mint: mintA.address,
|
|
11511
11932
|
tokenProgram: mintA.programAddress
|
|
11512
11933
|
}))[0];
|
|
11513
|
-
const feeRecipientAtaB = (await (0,
|
|
11934
|
+
const feeRecipientAtaB = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11514
11935
|
owner: tunaConfig.data.feeRecipient,
|
|
11515
11936
|
mint: mintB.address,
|
|
11516
11937
|
tokenProgram: mintB.programAddress
|
|
11517
11938
|
}))[0];
|
|
11518
|
-
const vaultAAta = (await (0,
|
|
11939
|
+
const vaultAAta = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11519
11940
|
owner: vaultA.address,
|
|
11520
11941
|
mint: mintA.address,
|
|
11521
11942
|
tokenProgram: mintA.programAddress
|
|
11522
11943
|
}))[0];
|
|
11523
|
-
const vaultBAta = (await (0,
|
|
11944
|
+
const vaultBAta = (await (0, import_token_202221.findAssociatedTokenPda)({
|
|
11524
11945
|
owner: vaultB.address,
|
|
11525
11946
|
mint: mintB.address,
|
|
11526
11947
|
tokenProgram: mintB.programAddress
|
|
11527
11948
|
}))[0];
|
|
11528
11949
|
const swapTickArrays = await OrcaUtils.getSwapTickArrayAddresses(whirlpool);
|
|
11529
11950
|
const remainingAccounts = [
|
|
11530
|
-
{ address: swapTickArrays[0], role:
|
|
11531
|
-
{ address: swapTickArrays[1], role:
|
|
11532
|
-
{ address: swapTickArrays[2], role:
|
|
11533
|
-
{ address: swapTickArrays[3], role:
|
|
11534
|
-
{ address: swapTickArrays[4], role:
|
|
11535
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
11536
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
11537
|
-
{ 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 }
|
|
11538
11959
|
];
|
|
11539
11960
|
const remainingAccountsInfo = {
|
|
11540
11961
|
slices: [
|
|
@@ -11567,8 +11988,8 @@ async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition,
|
|
|
11567
11988
|
feeRecipientAtaA,
|
|
11568
11989
|
feeRecipientAtaB,
|
|
11569
11990
|
whirlpool: whirlpool.address,
|
|
11570
|
-
whirlpoolProgram:
|
|
11571
|
-
memoProgram:
|
|
11991
|
+
whirlpoolProgram: import_whirlpools_client10.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11992
|
+
memoProgram: import_memo14.MEMO_PROGRAM_ADDRESS,
|
|
11572
11993
|
decreasePercent,
|
|
11573
11994
|
remainingAccountsInfo
|
|
11574
11995
|
});
|
|
@@ -11577,29 +11998,29 @@ async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition,
|
|
|
11577
11998
|
}
|
|
11578
11999
|
|
|
11579
12000
|
// src/txbuilder/openTunaLpPositionOrca.ts
|
|
11580
|
-
var
|
|
11581
|
-
var
|
|
11582
|
-
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"));
|
|
11583
12004
|
async function openTunaLpPositionOrcaInstruction(rpc, authority, positionMint, whirlpoolAddress, args) {
|
|
11584
|
-
const whirlpool = await (0,
|
|
12005
|
+
const whirlpool = await (0, import_whirlpools_client11.fetchMaybeWhirlpool)(rpc, whirlpoolAddress);
|
|
11585
12006
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
11586
|
-
const [mintA, mintB] = await (0,
|
|
11587
|
-
(0,
|
|
11588
|
-
(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");
|
|
11589
12010
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11590
|
-
const orcaPositionAddress = (await (0,
|
|
12011
|
+
const orcaPositionAddress = (await (0, import_whirlpools_client11.getPositionAddress)(positionMint.address))[0];
|
|
11591
12012
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
11592
|
-
const tunaPositionAta = (await (0,
|
|
12013
|
+
const tunaPositionAta = (await (0, import_token_202222.findAssociatedTokenPda)({
|
|
11593
12014
|
owner: tunaPositionAddress,
|
|
11594
12015
|
mint: positionMint.address,
|
|
11595
|
-
tokenProgram:
|
|
12016
|
+
tokenProgram: import_token_202222.TOKEN_2022_PROGRAM_ADDRESS
|
|
11596
12017
|
}))[0];
|
|
11597
|
-
const tunaPositionAtaA = (await (0,
|
|
12018
|
+
const tunaPositionAtaA = (await (0, import_token_202222.findAssociatedTokenPda)({
|
|
11598
12019
|
owner: tunaPositionAddress,
|
|
11599
12020
|
mint: mintA.address,
|
|
11600
12021
|
tokenProgram: mintA.programAddress
|
|
11601
12022
|
}))[0];
|
|
11602
|
-
const tunaPositionAtaB = (await (0,
|
|
12023
|
+
const tunaPositionAtaB = (await (0, import_token_202222.findAssociatedTokenPda)({
|
|
11603
12024
|
owner: tunaPositionAddress,
|
|
11604
12025
|
mint: mintB.address,
|
|
11605
12026
|
tokenProgram: mintB.programAddress
|
|
@@ -11615,42 +12036,42 @@ async function openTunaLpPositionOrcaInstruction(rpc, authority, positionMint, w
|
|
|
11615
12036
|
tunaPositionAta,
|
|
11616
12037
|
tunaPositionAtaA,
|
|
11617
12038
|
tunaPositionAtaB,
|
|
11618
|
-
whirlpoolProgram:
|
|
12039
|
+
whirlpoolProgram: import_whirlpools_client11.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11619
12040
|
whirlpool: whirlpool.address,
|
|
11620
12041
|
metadataUpdateAuth: WP_NFT_UPDATE_AUTH,
|
|
11621
12042
|
tokenProgramA: mintA.programAddress,
|
|
11622
12043
|
tokenProgramB: mintB.programAddress,
|
|
11623
|
-
associatedTokenProgram:
|
|
11624
|
-
token2022Program:
|
|
12044
|
+
associatedTokenProgram: import_token_202222.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12045
|
+
token2022Program: import_token_202222.TOKEN_2022_PROGRAM_ADDRESS,
|
|
11625
12046
|
...args
|
|
11626
12047
|
});
|
|
11627
12048
|
}
|
|
11628
12049
|
|
|
11629
12050
|
// src/txbuilder/openTunaLpPositionFusion.ts
|
|
11630
|
-
var import_fusionamm_client10 = require("@crypticdot/fusionamm-client");
|
|
11631
12051
|
var import_fusionamm_client11 = require("@crypticdot/fusionamm-client");
|
|
11632
|
-
var
|
|
11633
|
-
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"));
|
|
11634
12055
|
async function openTunaLpPositionFusionInstruction(rpc, authority, positionMint, fusionPoolAddress, args) {
|
|
11635
|
-
const fusionPool = await (0,
|
|
12056
|
+
const fusionPool = await (0, import_fusionamm_client11.fetchMaybeFusionPool)(rpc, fusionPoolAddress);
|
|
11636
12057
|
if (!fusionPool.exists) throw new Error("Whirlpool account not found");
|
|
11637
|
-
const [mintA, mintB] = await (0,
|
|
11638
|
-
(0,
|
|
11639
|
-
(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");
|
|
11640
12061
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11641
|
-
const fusionPositionAddress = (await (0,
|
|
12062
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client11.getPositionAddress)(positionMint.address))[0];
|
|
11642
12063
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
11643
|
-
const tunaPositionAta = (await (0,
|
|
12064
|
+
const tunaPositionAta = (await (0, import_token_202223.findAssociatedTokenPda)({
|
|
11644
12065
|
owner: tunaPositionAddress,
|
|
11645
12066
|
mint: positionMint.address,
|
|
11646
|
-
tokenProgram:
|
|
12067
|
+
tokenProgram: import_token_202223.TOKEN_2022_PROGRAM_ADDRESS
|
|
11647
12068
|
}))[0];
|
|
11648
|
-
const tunaPositionAtaA = (await (0,
|
|
12069
|
+
const tunaPositionAtaA = (await (0, import_token_202223.findAssociatedTokenPda)({
|
|
11649
12070
|
owner: tunaPositionAddress,
|
|
11650
12071
|
mint: mintA.address,
|
|
11651
12072
|
tokenProgram: mintA.programAddress
|
|
11652
12073
|
}))[0];
|
|
11653
|
-
const tunaPositionAtaB = (await (0,
|
|
12074
|
+
const tunaPositionAtaB = (await (0, import_token_202223.findAssociatedTokenPda)({
|
|
11654
12075
|
owner: tunaPositionAddress,
|
|
11655
12076
|
mint: mintB.address,
|
|
11656
12077
|
tokenProgram: mintB.programAddress
|
|
@@ -11666,25 +12087,25 @@ async function openTunaLpPositionFusionInstruction(rpc, authority, positionMint,
|
|
|
11666
12087
|
tunaPositionAta,
|
|
11667
12088
|
tunaPositionAtaA,
|
|
11668
12089
|
tunaPositionAtaB,
|
|
11669
|
-
fusionammProgram:
|
|
12090
|
+
fusionammProgram: import_fusionamm_client11.FUSIONAMM_PROGRAM_ADDRESS,
|
|
11670
12091
|
fusionPool: fusionPool.address,
|
|
11671
|
-
metadataUpdateAuth:
|
|
12092
|
+
metadataUpdateAuth: import_fusionamm_client12.FP_NFT_UPDATE_AUTH,
|
|
11672
12093
|
tokenProgramA: mintA.programAddress,
|
|
11673
12094
|
tokenProgramB: mintB.programAddress,
|
|
11674
|
-
associatedTokenProgram:
|
|
11675
|
-
token2022Program:
|
|
12095
|
+
associatedTokenProgram: import_token_202223.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12096
|
+
token2022Program: import_token_202223.TOKEN_2022_PROGRAM_ADDRESS,
|
|
11676
12097
|
...args
|
|
11677
12098
|
});
|
|
11678
12099
|
}
|
|
11679
12100
|
|
|
11680
12101
|
// src/txbuilder/openAndIncreaseTunaLpPositionOrca.ts
|
|
11681
|
-
var
|
|
12102
|
+
var import_whirlpools_client12 = require("@orca-so/whirlpools-client");
|
|
11682
12103
|
var import_whirlpools_core4 = require("@orca-so/whirlpools-core");
|
|
11683
|
-
var
|
|
12104
|
+
var import_kit120 = require("@solana/kit");
|
|
11684
12105
|
var import_sysvars = require("@solana/sysvars");
|
|
11685
|
-
var
|
|
11686
|
-
var
|
|
11687
|
-
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"));
|
|
11688
12109
|
|
|
11689
12110
|
// src/utils/sysvar.ts
|
|
11690
12111
|
var ACCOUNT_STORAGE_OVERHEAD = 128;
|
|
@@ -11702,15 +12123,15 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11702
12123
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
11703
12124
|
const rent = await (0, import_sysvars.fetchSysvarRent)(rpc);
|
|
11704
12125
|
let nonRefundableRent = 0n;
|
|
11705
|
-
const positionMint = await (0,
|
|
12126
|
+
const positionMint = await (0, import_kit120.generateKeyPairSigner)();
|
|
11706
12127
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
11707
|
-
const whirlpool = await (0,
|
|
12128
|
+
const whirlpool = await (0, import_whirlpools_client12.fetchMaybeWhirlpool)(rpc, whirlpoolAddress);
|
|
11708
12129
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
11709
12130
|
const marketAddress = (await getMarketAddress(whirlpoolAddress))[0];
|
|
11710
12131
|
const market = await fetchMarket(rpc, marketAddress);
|
|
11711
|
-
const [mintA, mintB] = await (0,
|
|
11712
|
-
(0,
|
|
11713
|
-
(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");
|
|
11714
12135
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
11715
12136
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
11716
12137
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
@@ -11763,16 +12184,16 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11763
12184
|
);
|
|
11764
12185
|
createInstructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
11765
12186
|
const lowerTickArrayIndex = (0, import_whirlpools_core4.getTickArrayStartTickIndex)(args.tickLowerIndex, whirlpool.data.tickSpacing);
|
|
11766
|
-
const [lowerTickArrayAddress] = await (0,
|
|
12187
|
+
const [lowerTickArrayAddress] = await (0, import_whirlpools_client12.getTickArrayAddress)(whirlpool.address, lowerTickArrayIndex);
|
|
11767
12188
|
const upperTickArrayIndex = (0, import_whirlpools_core4.getTickArrayStartTickIndex)(args.tickUpperIndex, whirlpool.data.tickSpacing);
|
|
11768
|
-
const [upperTickArrayAddress] = await (0,
|
|
11769
|
-
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, [
|
|
11770
12191
|
lowerTickArrayAddress,
|
|
11771
12192
|
upperTickArrayAddress
|
|
11772
12193
|
]);
|
|
11773
12194
|
if (!lowerTickArray.exists) {
|
|
11774
12195
|
instructions.push(
|
|
11775
|
-
(0,
|
|
12196
|
+
(0, import_whirlpools_client12.getInitializeDynamicTickArrayInstruction)({
|
|
11776
12197
|
whirlpool: whirlpool.address,
|
|
11777
12198
|
funder: authority,
|
|
11778
12199
|
tickArray: lowerTickArrayAddress,
|
|
@@ -11780,11 +12201,11 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11780
12201
|
idempotent: false
|
|
11781
12202
|
})
|
|
11782
12203
|
);
|
|
11783
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
12204
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client12.getDynamicTickArrayMinSize)());
|
|
11784
12205
|
}
|
|
11785
12206
|
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
11786
12207
|
instructions.push(
|
|
11787
|
-
(0,
|
|
12208
|
+
(0, import_whirlpools_client12.getInitializeDynamicTickArrayInstruction)({
|
|
11788
12209
|
whirlpool: whirlpool.address,
|
|
11789
12210
|
funder: authority,
|
|
11790
12211
|
tickArray: upperTickArrayAddress,
|
|
@@ -11792,7 +12213,7 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11792
12213
|
idempotent: false
|
|
11793
12214
|
})
|
|
11794
12215
|
);
|
|
11795
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
12216
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client12.getDynamicTickArrayMinSize)());
|
|
11796
12217
|
}
|
|
11797
12218
|
const ix = await openAndIncreaseTunaLpPositionOrcaInstruction(
|
|
11798
12219
|
authority,
|
|
@@ -11811,55 +12232,55 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11811
12232
|
return {
|
|
11812
12233
|
instructions,
|
|
11813
12234
|
positionMint: positionMint.address,
|
|
11814
|
-
initializationCost: (0,
|
|
12235
|
+
initializationCost: (0, import_kit120.lamports)(nonRefundableRent)
|
|
11815
12236
|
};
|
|
11816
12237
|
}
|
|
11817
12238
|
async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, args) {
|
|
11818
12239
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
11819
12240
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11820
|
-
const orcaPositionAddress = (await (0,
|
|
11821
|
-
const orcaOracleAddress = (await (0,
|
|
11822
|
-
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)({
|
|
11823
12244
|
owner: tunaPositionAddress,
|
|
11824
12245
|
mint: positionMint.address,
|
|
11825
|
-
tokenProgram:
|
|
12246
|
+
tokenProgram: import_token_202224.TOKEN_2022_PROGRAM_ADDRESS
|
|
11826
12247
|
}))[0];
|
|
11827
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
12248
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11828
12249
|
owner: authority.address,
|
|
11829
12250
|
mint: mintA.address,
|
|
11830
12251
|
tokenProgram: mintA.programAddress
|
|
11831
12252
|
}))[0];
|
|
11832
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
12253
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11833
12254
|
owner: authority.address,
|
|
11834
12255
|
mint: mintB.address,
|
|
11835
12256
|
tokenProgram: mintB.programAddress
|
|
11836
12257
|
}))[0];
|
|
11837
|
-
const tunaPositionAtaA = (await (0,
|
|
12258
|
+
const tunaPositionAtaA = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11838
12259
|
owner: tunaPositionAddress,
|
|
11839
12260
|
mint: mintA.address,
|
|
11840
12261
|
tokenProgram: mintA.programAddress
|
|
11841
12262
|
}))[0];
|
|
11842
|
-
const tunaPositionAtaB = (await (0,
|
|
12263
|
+
const tunaPositionAtaB = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11843
12264
|
owner: tunaPositionAddress,
|
|
11844
12265
|
mint: mintB.address,
|
|
11845
12266
|
tokenProgram: mintB.programAddress
|
|
11846
12267
|
}))[0];
|
|
11847
|
-
const vaultAAta = (await (0,
|
|
12268
|
+
const vaultAAta = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11848
12269
|
owner: vaultA.address,
|
|
11849
12270
|
mint: mintA.address,
|
|
11850
12271
|
tokenProgram: mintA.programAddress
|
|
11851
12272
|
}))[0];
|
|
11852
|
-
const vaultBAta = (await (0,
|
|
12273
|
+
const vaultBAta = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11853
12274
|
owner: vaultB.address,
|
|
11854
12275
|
mint: mintB.address,
|
|
11855
12276
|
tokenProgram: mintB.programAddress
|
|
11856
12277
|
}))[0];
|
|
11857
|
-
const feeRecipientAtaA = (await (0,
|
|
12278
|
+
const feeRecipientAtaA = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11858
12279
|
owner: tunaConfig.data.feeRecipient,
|
|
11859
12280
|
mint: mintA.address,
|
|
11860
12281
|
tokenProgram: mintA.programAddress
|
|
11861
12282
|
}))[0];
|
|
11862
|
-
const feeRecipientAtaB = (await (0,
|
|
12283
|
+
const feeRecipientAtaB = (await (0, import_token_202224.findAssociatedTokenPda)({
|
|
11863
12284
|
owner: tunaConfig.data.feeRecipient,
|
|
11864
12285
|
mint: mintB.address,
|
|
11865
12286
|
tokenProgram: mintB.programAddress
|
|
@@ -11868,16 +12289,16 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
11868
12289
|
const lowerTickArrayAddress = await OrcaUtils.getTickArrayAddressFromTickIndex(whirlpool, args.tickLowerIndex);
|
|
11869
12290
|
const upperTickArrayAddress = await OrcaUtils.getTickArrayAddressFromTickIndex(whirlpool, args.tickUpperIndex);
|
|
11870
12291
|
const remainingAccounts = [
|
|
11871
|
-
{ address: swapTickArrays[0], role:
|
|
11872
|
-
{ address: swapTickArrays[1], role:
|
|
11873
|
-
{ address: swapTickArrays[2], role:
|
|
11874
|
-
{ address: swapTickArrays[3], role:
|
|
11875
|
-
{ address: swapTickArrays[4], role:
|
|
11876
|
-
{ address: lowerTickArrayAddress, role:
|
|
11877
|
-
{ address: upperTickArrayAddress, role:
|
|
11878
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
11879
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
11880
|
-
{ 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 }
|
|
11881
12302
|
];
|
|
11882
12303
|
const remainingAccountsInfo = {
|
|
11883
12304
|
slices: [
|
|
@@ -11911,14 +12332,14 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
11911
12332
|
feeRecipientAtaA,
|
|
11912
12333
|
feeRecipientAtaB,
|
|
11913
12334
|
whirlpool: whirlpool.address,
|
|
11914
|
-
whirlpoolProgram:
|
|
12335
|
+
whirlpoolProgram: import_whirlpools_client12.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11915
12336
|
orcaPosition: orcaPositionAddress,
|
|
11916
12337
|
tokenProgramA: mintA.programAddress,
|
|
11917
12338
|
tokenProgramB: mintB.programAddress,
|
|
11918
|
-
memoProgram:
|
|
12339
|
+
memoProgram: import_memo15.MEMO_PROGRAM_ADDRESS,
|
|
11919
12340
|
metadataUpdateAuth: WP_NFT_UPDATE_AUTH,
|
|
11920
|
-
associatedTokenProgram:
|
|
11921
|
-
token2022Program:
|
|
12341
|
+
associatedTokenProgram: import_token_202224.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12342
|
+
token2022Program: import_token_202224.TOKEN_2022_PROGRAM_ADDRESS,
|
|
11922
12343
|
...args,
|
|
11923
12344
|
remainingAccountsInfo
|
|
11924
12345
|
});
|
|
@@ -11927,28 +12348,28 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
11927
12348
|
}
|
|
11928
12349
|
|
|
11929
12350
|
// src/txbuilder/openAndIncreaseTunaLpPositionFusion.ts
|
|
11930
|
-
var
|
|
12351
|
+
var import_fusionamm_client13 = require("@crypticdot/fusionamm-client");
|
|
11931
12352
|
var import_fusionamm_core5 = require("@crypticdot/fusionamm-core");
|
|
11932
|
-
var
|
|
12353
|
+
var import_kit121 = require("@solana/kit");
|
|
11933
12354
|
var import_sysvars2 = require("@solana/sysvars");
|
|
11934
|
-
var
|
|
11935
|
-
var
|
|
11936
|
-
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"));
|
|
11937
12358
|
async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
11938
12359
|
const instructions = [];
|
|
11939
12360
|
if (!createInstructions) createInstructions = instructions;
|
|
11940
12361
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
11941
12362
|
const rent = await (0, import_sysvars2.fetchSysvarRent)(rpc);
|
|
11942
12363
|
let nonRefundableRent = 0n;
|
|
11943
|
-
const positionMint = await (0,
|
|
12364
|
+
const positionMint = await (0, import_kit121.generateKeyPairSigner)();
|
|
11944
12365
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
11945
|
-
const fusionPool = await (0,
|
|
12366
|
+
const fusionPool = await (0, import_fusionamm_client13.fetchMaybeFusionPool)(rpc, fusionPoolAddress);
|
|
11946
12367
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
11947
12368
|
const marketAddress = (await getMarketAddress(fusionPoolAddress))[0];
|
|
11948
12369
|
const market = await fetchMarket(rpc, marketAddress);
|
|
11949
|
-
const [mintA, mintB] = await (0,
|
|
11950
|
-
(0,
|
|
11951
|
-
(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");
|
|
11952
12373
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
11953
12374
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
11954
12375
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
@@ -12001,34 +12422,34 @@ async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, f
|
|
|
12001
12422
|
);
|
|
12002
12423
|
createInstructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
12003
12424
|
const lowerTickArrayIndex = (0, import_fusionamm_core5.getTickArrayStartTickIndex)(args.tickLowerIndex, fusionPool.data.tickSpacing);
|
|
12004
|
-
const [lowerTickArrayAddress] = await (0,
|
|
12425
|
+
const [lowerTickArrayAddress] = await (0, import_fusionamm_client13.getTickArrayAddress)(fusionPool.address, lowerTickArrayIndex);
|
|
12005
12426
|
const upperTickArrayIndex = (0, import_fusionamm_core5.getTickArrayStartTickIndex)(args.tickUpperIndex, fusionPool.data.tickSpacing);
|
|
12006
|
-
const [upperTickArrayAddress] = await (0,
|
|
12007
|
-
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, [
|
|
12008
12429
|
lowerTickArrayAddress,
|
|
12009
12430
|
upperTickArrayAddress
|
|
12010
12431
|
]);
|
|
12011
12432
|
if (!lowerTickArray.exists) {
|
|
12012
12433
|
instructions.push(
|
|
12013
|
-
(0,
|
|
12434
|
+
(0, import_fusionamm_client13.getInitializeTickArrayInstruction)({
|
|
12014
12435
|
fusionPool: fusionPool.address,
|
|
12015
12436
|
funder: authority,
|
|
12016
12437
|
tickArray: lowerTickArrayAddress,
|
|
12017
12438
|
startTickIndex: lowerTickArrayIndex
|
|
12018
12439
|
})
|
|
12019
12440
|
);
|
|
12020
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
12441
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client13.getTickArraySize)());
|
|
12021
12442
|
}
|
|
12022
12443
|
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
12023
12444
|
instructions.push(
|
|
12024
|
-
(0,
|
|
12445
|
+
(0, import_fusionamm_client13.getInitializeTickArrayInstruction)({
|
|
12025
12446
|
fusionPool: fusionPool.address,
|
|
12026
12447
|
funder: authority,
|
|
12027
12448
|
tickArray: upperTickArrayAddress,
|
|
12028
12449
|
startTickIndex: upperTickArrayIndex
|
|
12029
12450
|
})
|
|
12030
12451
|
);
|
|
12031
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
12452
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client13.getTickArraySize)());
|
|
12032
12453
|
}
|
|
12033
12454
|
const ix = await openAndIncreaseTunaLpPositionFusionInstruction(
|
|
12034
12455
|
authority,
|
|
@@ -12047,54 +12468,54 @@ async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, f
|
|
|
12047
12468
|
return {
|
|
12048
12469
|
instructions,
|
|
12049
12470
|
positionMint: positionMint.address,
|
|
12050
|
-
initializationCost: (0,
|
|
12471
|
+
initializationCost: (0, import_kit121.lamports)(nonRefundableRent)
|
|
12051
12472
|
};
|
|
12052
12473
|
}
|
|
12053
12474
|
async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, args) {
|
|
12054
12475
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
12055
12476
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
12056
|
-
const fusionPositionAddress = (await (0,
|
|
12057
|
-
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)({
|
|
12058
12479
|
owner: tunaPositionAddress,
|
|
12059
12480
|
mint: positionMint.address,
|
|
12060
|
-
tokenProgram:
|
|
12481
|
+
tokenProgram: import_token_202225.TOKEN_2022_PROGRAM_ADDRESS
|
|
12061
12482
|
}))[0];
|
|
12062
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
12483
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12063
12484
|
owner: authority.address,
|
|
12064
12485
|
mint: mintA.address,
|
|
12065
12486
|
tokenProgram: mintA.programAddress
|
|
12066
12487
|
}))[0];
|
|
12067
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
12488
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12068
12489
|
owner: authority.address,
|
|
12069
12490
|
mint: mintB.address,
|
|
12070
12491
|
tokenProgram: mintB.programAddress
|
|
12071
12492
|
}))[0];
|
|
12072
|
-
const tunaPositionAtaA = (await (0,
|
|
12493
|
+
const tunaPositionAtaA = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12073
12494
|
owner: tunaPositionAddress,
|
|
12074
12495
|
mint: mintA.address,
|
|
12075
12496
|
tokenProgram: mintA.programAddress
|
|
12076
12497
|
}))[0];
|
|
12077
|
-
const tunaPositionAtaB = (await (0,
|
|
12498
|
+
const tunaPositionAtaB = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12078
12499
|
owner: tunaPositionAddress,
|
|
12079
12500
|
mint: mintB.address,
|
|
12080
12501
|
tokenProgram: mintB.programAddress
|
|
12081
12502
|
}))[0];
|
|
12082
|
-
const vaultAAta = (await (0,
|
|
12503
|
+
const vaultAAta = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12083
12504
|
owner: vaultA.address,
|
|
12084
12505
|
mint: mintA.address,
|
|
12085
12506
|
tokenProgram: mintA.programAddress
|
|
12086
12507
|
}))[0];
|
|
12087
|
-
const vaultBAta = (await (0,
|
|
12508
|
+
const vaultBAta = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12088
12509
|
owner: vaultB.address,
|
|
12089
12510
|
mint: mintB.address,
|
|
12090
12511
|
tokenProgram: mintB.programAddress
|
|
12091
12512
|
}))[0];
|
|
12092
|
-
const feeRecipientAtaA = (await (0,
|
|
12513
|
+
const feeRecipientAtaA = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12093
12514
|
owner: tunaConfig.data.feeRecipient,
|
|
12094
12515
|
mint: mintA.address,
|
|
12095
12516
|
tokenProgram: mintA.programAddress
|
|
12096
12517
|
}))[0];
|
|
12097
|
-
const feeRecipientAtaB = (await (0,
|
|
12518
|
+
const feeRecipientAtaB = (await (0, import_token_202225.findAssociatedTokenPda)({
|
|
12098
12519
|
owner: tunaConfig.data.feeRecipient,
|
|
12099
12520
|
mint: mintB.address,
|
|
12100
12521
|
tokenProgram: mintB.programAddress
|
|
@@ -12103,15 +12524,15 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12103
12524
|
const lowerTickArrayAddress = await FusionUtils.getTickArrayAddressFromTickIndex(fusionPool, args.tickLowerIndex);
|
|
12104
12525
|
const upperTickArrayAddress = await FusionUtils.getTickArrayAddressFromTickIndex(fusionPool, args.tickUpperIndex);
|
|
12105
12526
|
const remainingAccounts = [
|
|
12106
|
-
{ address: swapTickArrays[0], role:
|
|
12107
|
-
{ address: swapTickArrays[1], role:
|
|
12108
|
-
{ address: swapTickArrays[2], role:
|
|
12109
|
-
{ address: swapTickArrays[3], role:
|
|
12110
|
-
{ address: swapTickArrays[4], role:
|
|
12111
|
-
{ address: lowerTickArrayAddress, role:
|
|
12112
|
-
{ address: upperTickArrayAddress, role:
|
|
12113
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
12114
|
-
{ 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 }
|
|
12115
12536
|
];
|
|
12116
12537
|
const remainingAccountsInfo = {
|
|
12117
12538
|
slices: [
|
|
@@ -12144,14 +12565,14 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12144
12565
|
feeRecipientAtaA,
|
|
12145
12566
|
feeRecipientAtaB,
|
|
12146
12567
|
fusionPool: fusionPool.address,
|
|
12147
|
-
fusionammProgram:
|
|
12568
|
+
fusionammProgram: import_fusionamm_client13.FUSIONAMM_PROGRAM_ADDRESS,
|
|
12148
12569
|
fusionPosition: fusionPositionAddress,
|
|
12149
12570
|
tokenProgramA: mintA.programAddress,
|
|
12150
12571
|
tokenProgramB: mintB.programAddress,
|
|
12151
|
-
memoProgram:
|
|
12152
|
-
metadataUpdateAuth:
|
|
12153
|
-
associatedTokenProgram:
|
|
12154
|
-
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,
|
|
12155
12576
|
...args,
|
|
12156
12577
|
remainingAccountsInfo
|
|
12157
12578
|
});
|
|
@@ -12160,36 +12581,36 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12160
12581
|
}
|
|
12161
12582
|
|
|
12162
12583
|
// src/txbuilder/openTunaSpotPosition.ts
|
|
12163
|
-
var
|
|
12164
|
-
var
|
|
12165
|
-
var
|
|
12166
|
-
var
|
|
12167
|
-
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"));
|
|
12168
12589
|
async function openTunaSpotPositionInstructions(rpc, authority, poolAddress, args) {
|
|
12169
|
-
const poolAccount = await (0,
|
|
12170
|
-
(0,
|
|
12590
|
+
const poolAccount = await (0, import_kit122.fetchEncodedAccount)(rpc, poolAddress);
|
|
12591
|
+
(0, import_assert19.default)(poolAccount.exists, "Pool account not found");
|
|
12171
12592
|
let pool;
|
|
12172
|
-
if (poolAccount.programAddress ==
|
|
12173
|
-
pool = (0,
|
|
12174
|
-
} else if (poolAccount.programAddress ==
|
|
12175
|
-
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)());
|
|
12176
12597
|
} else {
|
|
12177
12598
|
throw new Error("Incorrect Fusion or Orca pool account");
|
|
12178
12599
|
}
|
|
12179
|
-
const [mintA, mintB] = await (0,
|
|
12180
|
-
(0,
|
|
12181
|
-
(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");
|
|
12182
12603
|
const ix = await openTunaSpotPositionInstruction(authority, mintA, mintB, poolAddress, args);
|
|
12183
12604
|
return [ix];
|
|
12184
12605
|
}
|
|
12185
12606
|
async function openTunaSpotPositionInstruction(authority, mintA, mintB, poolAddress, args) {
|
|
12186
12607
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
12187
|
-
const tunaPositionAtaA = (await (0,
|
|
12608
|
+
const tunaPositionAtaA = (await (0, import_token_202226.findAssociatedTokenPda)({
|
|
12188
12609
|
owner: tunaPositionAddress,
|
|
12189
12610
|
mint: mintA.address,
|
|
12190
12611
|
tokenProgram: mintA.programAddress
|
|
12191
12612
|
}))[0];
|
|
12192
|
-
const tunaPositionAtaB = (await (0,
|
|
12613
|
+
const tunaPositionAtaB = (await (0, import_token_202226.findAssociatedTokenPda)({
|
|
12193
12614
|
owner: tunaPositionAddress,
|
|
12194
12615
|
mint: mintB.address,
|
|
12195
12616
|
tokenProgram: mintB.programAddress
|
|
@@ -12204,48 +12625,48 @@ async function openTunaSpotPositionInstruction(authority, mintA, mintB, poolAddr
|
|
|
12204
12625
|
tunaPositionAtaA,
|
|
12205
12626
|
tunaPositionAtaB,
|
|
12206
12627
|
pool: poolAddress,
|
|
12207
|
-
associatedTokenProgram:
|
|
12628
|
+
associatedTokenProgram: import_token_202226.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12208
12629
|
...args
|
|
12209
12630
|
});
|
|
12210
12631
|
}
|
|
12211
12632
|
|
|
12212
12633
|
// src/txbuilder/decreaseTunaLpPositionOrca.ts
|
|
12213
|
-
var
|
|
12634
|
+
var import_whirlpools_client14 = require("@orca-so/whirlpools-client");
|
|
12214
12635
|
var import_whirlpools_core5 = require("@orca-so/whirlpools-core");
|
|
12215
|
-
var
|
|
12216
|
-
var
|
|
12217
|
-
var
|
|
12218
|
-
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"));
|
|
12219
12640
|
async function decreaseTunaLpPositionOrcaInstructions(rpc, authority, positionMint, args, createInstructions, cleanupInstructions) {
|
|
12220
12641
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12221
12642
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12222
|
-
const orcaPosition = await (0,
|
|
12223
|
-
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);
|
|
12224
12645
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
12225
12646
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
12226
12647
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
12227
12648
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
12228
12649
|
]);
|
|
12229
|
-
const [mintA, mintB, ...rewardMints] = await (0,
|
|
12650
|
+
const [mintA, mintB, ...rewardMints] = await (0, import_token_202227.fetchAllMaybeMint)(rpc, [
|
|
12230
12651
|
whirlpool.data.tokenMintA,
|
|
12231
12652
|
whirlpool.data.tokenMintB,
|
|
12232
12653
|
...whirlpool.data.rewardInfos.map((x) => x.mint).filter((x) => x !== DEFAULT_ADDRESS)
|
|
12233
12654
|
]);
|
|
12234
12655
|
const allMints = [mintA, mintB, ...rewardMints];
|
|
12235
|
-
(0,
|
|
12236
|
-
(0,
|
|
12237
|
-
(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);
|
|
12238
12659
|
const lowerTickArrayStartIndex = (0, import_whirlpools_core5.getTickArrayStartTickIndex)(
|
|
12239
12660
|
tunaPosition.data.tickLowerIndex,
|
|
12240
12661
|
whirlpool.data.tickSpacing
|
|
12241
12662
|
);
|
|
12242
|
-
const [lowerTickArrayAddress] = await (0,
|
|
12663
|
+
const [lowerTickArrayAddress] = await (0, import_whirlpools_client14.getTickArrayAddress)(whirlpool.address, lowerTickArrayStartIndex);
|
|
12243
12664
|
const upperTickArrayStartIndex = (0, import_whirlpools_core5.getTickArrayStartTickIndex)(
|
|
12244
12665
|
tunaPosition.data.tickUpperIndex,
|
|
12245
12666
|
whirlpool.data.tickSpacing
|
|
12246
12667
|
);
|
|
12247
|
-
const [upperTickArrayAddress] = await (0,
|
|
12248
|
-
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]);
|
|
12249
12670
|
const lowerTick = lowerTickArray.data.ticks[(0, import_whirlpools_core5.getTickIndexInArray)(tunaPosition.data.tickLowerIndex, lowerTickArrayStartIndex, whirlpool.data.tickSpacing)];
|
|
12250
12671
|
const upperTick = upperTickArray.data.ticks[(0, import_whirlpools_core5.getTickIndexInArray)(tunaPosition.data.tickUpperIndex, upperTickArrayStartIndex, whirlpool.data.tickSpacing)];
|
|
12251
12672
|
const instructions = [];
|
|
@@ -12274,7 +12695,7 @@ async function decreaseTunaLpPositionOrcaInstructions(rpc, authority, positionMi
|
|
|
12274
12695
|
}
|
|
12275
12696
|
for (const mintAddress of requiredMints) {
|
|
12276
12697
|
const mint = allMints.find((mint2) => mint2.address == mintAddress);
|
|
12277
|
-
(0,
|
|
12698
|
+
(0, import_assert20.default)(mint && mint.exists);
|
|
12278
12699
|
const ixs = await getCreateAtaInstructions(rpc, authority, mint.address, authority.address, mint.programAddress);
|
|
12279
12700
|
createInstructions.push(...ixs.init);
|
|
12280
12701
|
internalCleanupInstructions.push(...ixs.cleanup);
|
|
@@ -12300,39 +12721,39 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12300
12721
|
const positionMint = tunaPosition.data.positionMint;
|
|
12301
12722
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12302
12723
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
12303
|
-
const orcaPositionAddress = (await (0,
|
|
12304
|
-
const orcaOracleAddress = (await (0,
|
|
12305
|
-
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)({
|
|
12306
12727
|
owner: tunaPosition.address,
|
|
12307
12728
|
mint: positionMint,
|
|
12308
|
-
tokenProgram:
|
|
12729
|
+
tokenProgram: import_token_202227.TOKEN_2022_PROGRAM_ADDRESS
|
|
12309
12730
|
}))[0];
|
|
12310
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
12731
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12311
12732
|
owner: authority.address,
|
|
12312
12733
|
mint: mintA.address,
|
|
12313
12734
|
tokenProgram: mintA.programAddress
|
|
12314
12735
|
}))[0];
|
|
12315
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
12736
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12316
12737
|
owner: authority.address,
|
|
12317
12738
|
mint: mintB.address,
|
|
12318
12739
|
tokenProgram: mintB.programAddress
|
|
12319
12740
|
}))[0];
|
|
12320
|
-
const tunaPositionAtaA = (await (0,
|
|
12741
|
+
const tunaPositionAtaA = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12321
12742
|
owner: tunaPosition.address,
|
|
12322
12743
|
mint: mintA.address,
|
|
12323
12744
|
tokenProgram: mintA.programAddress
|
|
12324
12745
|
}))[0];
|
|
12325
|
-
const tunaPositionAtaB = (await (0,
|
|
12746
|
+
const tunaPositionAtaB = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12326
12747
|
owner: tunaPosition.address,
|
|
12327
12748
|
mint: mintB.address,
|
|
12328
12749
|
tokenProgram: mintB.programAddress
|
|
12329
12750
|
}))[0];
|
|
12330
|
-
const vaultAAta = (await (0,
|
|
12751
|
+
const vaultAAta = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12331
12752
|
owner: vaultA.address,
|
|
12332
12753
|
mint: mintA.address,
|
|
12333
12754
|
tokenProgram: mintA.programAddress
|
|
12334
12755
|
}))[0];
|
|
12335
|
-
const vaultBAta = (await (0,
|
|
12756
|
+
const vaultBAta = (await (0, import_token_202227.findAssociatedTokenPda)({
|
|
12336
12757
|
owner: vaultB.address,
|
|
12337
12758
|
mint: mintB.address,
|
|
12338
12759
|
tokenProgram: mintB.programAddress
|
|
@@ -12347,30 +12768,30 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12347
12768
|
tunaPosition.data.tickUpperIndex
|
|
12348
12769
|
);
|
|
12349
12770
|
const remainingAccounts = [
|
|
12350
|
-
{ address: swapTickArrays[0], role:
|
|
12351
|
-
{ address: swapTickArrays[1], role:
|
|
12352
|
-
{ address: swapTickArrays[2], role:
|
|
12353
|
-
{ address: swapTickArrays[3], role:
|
|
12354
|
-
{ address: swapTickArrays[4], role:
|
|
12355
|
-
{ address: lowerTickArrayAddress, role:
|
|
12356
|
-
{ address: upperTickArrayAddress, role:
|
|
12357
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
12358
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
12359
|
-
{ 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 }
|
|
12360
12781
|
];
|
|
12361
12782
|
for (const rewardIndex of rewardIndicesToClaim) {
|
|
12362
12783
|
const rewardInfo = whirlpool.data.rewardInfos[rewardIndex];
|
|
12363
12784
|
const rewardMint = rewardMints.find((mint) => mint.address == rewardInfo.mint);
|
|
12364
|
-
(0,
|
|
12365
|
-
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)({
|
|
12366
12787
|
owner: authority.address,
|
|
12367
12788
|
mint: rewardMint.address,
|
|
12368
12789
|
tokenProgram: rewardMint.programAddress
|
|
12369
12790
|
});
|
|
12370
|
-
remainingAccounts.push({ address: rewardMint.address, role:
|
|
12371
|
-
remainingAccounts.push({ address: rewardMint.programAddress, role:
|
|
12372
|
-
remainingAccounts.push({ address: ownerAta[0], role:
|
|
12373
|
-
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 });
|
|
12374
12795
|
}
|
|
12375
12796
|
const remainingAccountsInfo = {
|
|
12376
12797
|
slices: [
|
|
@@ -12405,10 +12826,10 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12405
12826
|
orcaPosition: orcaPositionAddress,
|
|
12406
12827
|
tunaPosition: tunaPosition.address,
|
|
12407
12828
|
whirlpool: whirlpool.address,
|
|
12408
|
-
whirlpoolProgram:
|
|
12829
|
+
whirlpoolProgram: import_whirlpools_client14.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
12409
12830
|
tokenProgramA: mintA.programAddress,
|
|
12410
12831
|
tokenProgramB: mintB.programAddress,
|
|
12411
|
-
memoProgram:
|
|
12832
|
+
memoProgram: import_memo17.MEMO_PROGRAM_ADDRESS,
|
|
12412
12833
|
...args,
|
|
12413
12834
|
remainingAccountsInfo
|
|
12414
12835
|
});
|
|
@@ -12417,23 +12838,23 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12417
12838
|
}
|
|
12418
12839
|
|
|
12419
12840
|
// src/txbuilder/decreaseTunaLpPositionFusion.ts
|
|
12420
|
-
var
|
|
12421
|
-
var
|
|
12422
|
-
var
|
|
12423
|
-
var
|
|
12424
|
-
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"));
|
|
12425
12846
|
async function decreaseTunaLpPositionFusionInstructions(rpc, authority, positionMint, args, createInstructions, cleanupInstructions) {
|
|
12426
12847
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12427
12848
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12428
|
-
const fusionPool = await (0,
|
|
12849
|
+
const fusionPool = await (0, import_fusionamm_client15.fetchMaybeFusionPool)(rpc, tunaPosition.data.pool);
|
|
12429
12850
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
12430
12851
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
12431
12852
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
12432
12853
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
12433
12854
|
]);
|
|
12434
|
-
const [mintA, mintB] = await (0,
|
|
12435
|
-
(0,
|
|
12436
|
-
(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");
|
|
12437
12858
|
const instructions = [];
|
|
12438
12859
|
if (!createInstructions) createInstructions = instructions;
|
|
12439
12860
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
@@ -12473,38 +12894,38 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12473
12894
|
const positionMint = tunaPosition.data.positionMint;
|
|
12474
12895
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12475
12896
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
12476
|
-
const fusionPositionAddress = (await (0,
|
|
12477
|
-
const tunaPositionAta = (await (0,
|
|
12897
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client15.getPositionAddress)(positionMint))[0];
|
|
12898
|
+
const tunaPositionAta = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12478
12899
|
owner: tunaPosition.address,
|
|
12479
12900
|
mint: positionMint,
|
|
12480
|
-
tokenProgram:
|
|
12901
|
+
tokenProgram: import_token_202228.TOKEN_2022_PROGRAM_ADDRESS
|
|
12481
12902
|
}))[0];
|
|
12482
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
12903
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12483
12904
|
owner: authority.address,
|
|
12484
12905
|
mint: mintA.address,
|
|
12485
12906
|
tokenProgram: mintA.programAddress
|
|
12486
12907
|
}))[0];
|
|
12487
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
12908
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12488
12909
|
owner: authority.address,
|
|
12489
12910
|
mint: mintB.address,
|
|
12490
12911
|
tokenProgram: mintB.programAddress
|
|
12491
12912
|
}))[0];
|
|
12492
|
-
const tunaPositionAtaA = (await (0,
|
|
12913
|
+
const tunaPositionAtaA = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12493
12914
|
owner: tunaPosition.address,
|
|
12494
12915
|
mint: mintA.address,
|
|
12495
12916
|
tokenProgram: mintA.programAddress
|
|
12496
12917
|
}))[0];
|
|
12497
|
-
const tunaPositionAtaB = (await (0,
|
|
12918
|
+
const tunaPositionAtaB = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12498
12919
|
owner: tunaPosition.address,
|
|
12499
12920
|
mint: mintB.address,
|
|
12500
12921
|
tokenProgram: mintB.programAddress
|
|
12501
12922
|
}))[0];
|
|
12502
|
-
const vaultAAta = (await (0,
|
|
12923
|
+
const vaultAAta = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12503
12924
|
owner: vaultA.address,
|
|
12504
12925
|
mint: mintA.address,
|
|
12505
12926
|
tokenProgram: mintA.programAddress
|
|
12506
12927
|
}))[0];
|
|
12507
|
-
const vaultBAta = (await (0,
|
|
12928
|
+
const vaultBAta = (await (0, import_token_202228.findAssociatedTokenPda)({
|
|
12508
12929
|
owner: vaultB.address,
|
|
12509
12930
|
mint: mintB.address,
|
|
12510
12931
|
tokenProgram: mintB.programAddress
|
|
@@ -12519,15 +12940,15 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12519
12940
|
tunaPosition.data.tickUpperIndex
|
|
12520
12941
|
);
|
|
12521
12942
|
const remainingAccounts = [
|
|
12522
|
-
{ address: swapTickArrays[0], role:
|
|
12523
|
-
{ address: swapTickArrays[1], role:
|
|
12524
|
-
{ address: swapTickArrays[2], role:
|
|
12525
|
-
{ address: swapTickArrays[3], role:
|
|
12526
|
-
{ address: swapTickArrays[4], role:
|
|
12527
|
-
{ address: lowerTickArrayAddress, role:
|
|
12528
|
-
{ address: upperTickArrayAddress, role:
|
|
12529
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
12530
|
-
{ 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 }
|
|
12531
12952
|
];
|
|
12532
12953
|
const remainingAccountsInfo = {
|
|
12533
12954
|
slices: [
|
|
@@ -12558,10 +12979,10 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12558
12979
|
fusionPosition: fusionPositionAddress,
|
|
12559
12980
|
tunaPosition: tunaPosition.address,
|
|
12560
12981
|
fusionPool: fusionPool.address,
|
|
12561
|
-
fusionammProgram:
|
|
12982
|
+
fusionammProgram: import_fusionamm_client15.FUSIONAMM_PROGRAM_ADDRESS,
|
|
12562
12983
|
tokenProgramA: mintA.programAddress,
|
|
12563
12984
|
tokenProgramB: mintB.programAddress,
|
|
12564
|
-
memoProgram:
|
|
12985
|
+
memoProgram: import_memo18.MEMO_PROGRAM_ADDRESS,
|
|
12565
12986
|
...args,
|
|
12566
12987
|
remainingAccountsInfo
|
|
12567
12988
|
});
|
|
@@ -12570,19 +12991,19 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12570
12991
|
}
|
|
12571
12992
|
|
|
12572
12993
|
// src/txbuilder/repayBadDebt.ts
|
|
12573
|
-
var
|
|
12574
|
-
var
|
|
12994
|
+
var import_memo19 = require("@solana-program/memo");
|
|
12995
|
+
var import_token_202229 = require("@solana-program/token-2022");
|
|
12575
12996
|
async function repayBadDebtInstruction(rpc, authority, mintAddress, funds, shares) {
|
|
12576
|
-
const mint = await (0,
|
|
12997
|
+
const mint = await (0, import_token_202229.fetchMaybeMint)(rpc, mintAddress);
|
|
12577
12998
|
if (!mint.exists) throw new Error("Mint account not found");
|
|
12578
12999
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12579
13000
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
12580
|
-
const vaultAta = (await (0,
|
|
13001
|
+
const vaultAta = (await (0, import_token_202229.findAssociatedTokenPda)({
|
|
12581
13002
|
owner: vault,
|
|
12582
13003
|
mint: mint.address,
|
|
12583
13004
|
tokenProgram: mint.programAddress
|
|
12584
13005
|
}))[0];
|
|
12585
|
-
const authorityAta = (await (0,
|
|
13006
|
+
const authorityAta = (await (0, import_token_202229.findAssociatedTokenPda)({
|
|
12586
13007
|
owner: authority.address,
|
|
12587
13008
|
mint: mint.address,
|
|
12588
13009
|
tokenProgram: mint.programAddress
|
|
@@ -12595,7 +13016,7 @@ async function repayBadDebtInstruction(rpc, authority, mintAddress, funds, share
|
|
|
12595
13016
|
tunaConfig,
|
|
12596
13017
|
vault,
|
|
12597
13018
|
tokenProgram: mint.programAddress,
|
|
12598
|
-
memoProgram:
|
|
13019
|
+
memoProgram: import_memo19.MEMO_PROGRAM_ADDRESS,
|
|
12599
13020
|
funds,
|
|
12600
13021
|
shares
|
|
12601
13022
|
});
|
|
@@ -12627,20 +13048,20 @@ async function setTunaSpotPositionLimitOrdersInstruction(authority, poolAddress,
|
|
|
12627
13048
|
}
|
|
12628
13049
|
|
|
12629
13050
|
// src/txbuilder/resetTunaSpotPosition.ts
|
|
12630
|
-
var
|
|
12631
|
-
var
|
|
13051
|
+
var import_token_202230 = require("@solana-program/token-2022");
|
|
13052
|
+
var import_assert22 = __toESM(require("assert"));
|
|
12632
13053
|
async function resetTunaSpotPositionInstruction(rpc, authority, poolAddress, args) {
|
|
12633
13054
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
12634
13055
|
const tunaPosition = await fetchTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12635
|
-
const [mintA, mintB] = await (0,
|
|
12636
|
-
(0,
|
|
12637
|
-
(0,
|
|
12638
|
-
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)({
|
|
12639
13060
|
owner: tunaPositionAddress,
|
|
12640
13061
|
mint: mintA.address,
|
|
12641
13062
|
tokenProgram: mintA.programAddress
|
|
12642
13063
|
}))[0];
|
|
12643
|
-
const tunaPositionAtaB = (await (0,
|
|
13064
|
+
const tunaPositionAtaB = (await (0, import_token_202230.findAssociatedTokenPda)({
|
|
12644
13065
|
owner: tunaPositionAddress,
|
|
12645
13066
|
mint: mintB.address,
|
|
12646
13067
|
tokenProgram: mintB.programAddress
|
|
@@ -12681,11 +13102,11 @@ async function updateVaultInstruction(authority, mint, args) {
|
|
|
12681
13102
|
}
|
|
12682
13103
|
|
|
12683
13104
|
// src/txbuilder/withdraw.ts
|
|
12684
|
-
var
|
|
12685
|
-
var
|
|
13105
|
+
var import_memo20 = require("@solana-program/memo");
|
|
13106
|
+
var import_token_202231 = require("@solana-program/token-2022");
|
|
12686
13107
|
async function withdrawInstructions(rpc, authority, mintAddress, funds, shares) {
|
|
12687
13108
|
const instructions = [];
|
|
12688
|
-
const mint = await (0,
|
|
13109
|
+
const mint = await (0, import_token_202231.fetchMaybeMint)(rpc, mintAddress);
|
|
12689
13110
|
if (!mint.exists) throw new Error("Mint account not found");
|
|
12690
13111
|
const createUserAtaInstructions = await getCreateAtaInstructions(
|
|
12691
13112
|
rpc,
|
|
@@ -12704,12 +13125,12 @@ async function withdrawInstruction(authority, mint, funds, shares) {
|
|
|
12704
13125
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12705
13126
|
const lendingPosition = (await getLendingPositionAddress(authority.address, mint.address))[0];
|
|
12706
13127
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
12707
|
-
const vaultAta = (await (0,
|
|
13128
|
+
const vaultAta = (await (0, import_token_202231.findAssociatedTokenPda)({
|
|
12708
13129
|
owner: vault,
|
|
12709
13130
|
mint: mint.address,
|
|
12710
13131
|
tokenProgram: mint.programAddress
|
|
12711
13132
|
}))[0];
|
|
12712
|
-
const authorityAta = (await (0,
|
|
13133
|
+
const authorityAta = (await (0, import_token_202231.findAssociatedTokenPda)({
|
|
12713
13134
|
owner: authority.address,
|
|
12714
13135
|
mint: mint.address,
|
|
12715
13136
|
tokenProgram: mint.programAddress
|
|
@@ -12723,35 +13144,35 @@ async function withdrawInstruction(authority, mint, funds, shares) {
|
|
|
12723
13144
|
vault,
|
|
12724
13145
|
vaultAta,
|
|
12725
13146
|
tokenProgram: mint.programAddress,
|
|
12726
|
-
memoProgram:
|
|
13147
|
+
memoProgram: import_memo20.MEMO_PROGRAM_ADDRESS,
|
|
12727
13148
|
funds,
|
|
12728
13149
|
shares
|
|
12729
13150
|
});
|
|
12730
13151
|
}
|
|
12731
13152
|
|
|
12732
13153
|
// src/txbuilder/createMarketLookupTable.ts
|
|
12733
|
-
var
|
|
12734
|
-
var
|
|
12735
|
-
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");
|
|
12736
13157
|
var import_address_lookup_table2 = require("@solana-program/address-lookup-table");
|
|
12737
|
-
var
|
|
13158
|
+
var import_memo21 = require("@solana-program/memo");
|
|
12738
13159
|
var import_system2 = require("@solana-program/system");
|
|
12739
13160
|
var import_token2 = require("@solana-program/token");
|
|
12740
|
-
var
|
|
13161
|
+
var import_token_202232 = require("@solana-program/token-2022");
|
|
12741
13162
|
async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
12742
13163
|
const tunaConfigAddress = (await getTunaConfigAddress())[0];
|
|
12743
13164
|
const marketAddress = (await getMarketAddress(poolAddress))[0];
|
|
12744
|
-
const orcaOracleAddress = (await (0,
|
|
13165
|
+
const orcaOracleAddress = (await (0, import_whirlpools_client15.getOracleAddress)(poolAddress))[0];
|
|
12745
13166
|
const tunaConfig = await fetchTunaConfig(rpc, tunaConfigAddress);
|
|
12746
|
-
const pool = marketMaker == 0 /* Orca */ ? await (0,
|
|
12747
|
-
const mintA = await (0,
|
|
12748
|
-
const mintB = await (0,
|
|
12749
|
-
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)({
|
|
12750
13171
|
owner: tunaConfig.data.feeRecipient,
|
|
12751
13172
|
mint: mintA.address,
|
|
12752
13173
|
tokenProgram: mintA.programAddress
|
|
12753
13174
|
}))[0];
|
|
12754
|
-
const feeRecipientAtaB = (await (0,
|
|
13175
|
+
const feeRecipientAtaB = (await (0, import_token_202232.findAssociatedTokenPda)({
|
|
12755
13176
|
owner: tunaConfig.data.feeRecipient,
|
|
12756
13177
|
mint: mintB.address,
|
|
12757
13178
|
tokenProgram: mintB.programAddress
|
|
@@ -12760,24 +13181,24 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
12760
13181
|
(await getLendingVaultAddress(mintA.address))[0],
|
|
12761
13182
|
(await getLendingVaultAddress(mintB.address))[0]
|
|
12762
13183
|
]);
|
|
12763
|
-
const vaultAAta = (await (0,
|
|
13184
|
+
const vaultAAta = (await (0, import_token_202232.findAssociatedTokenPda)({
|
|
12764
13185
|
owner: vaultA.address,
|
|
12765
13186
|
mint: mintA.address,
|
|
12766
13187
|
tokenProgram: mintA.programAddress
|
|
12767
13188
|
}))[0];
|
|
12768
|
-
const vaultBAta = (await (0,
|
|
13189
|
+
const vaultBAta = (await (0, import_token_202232.findAssociatedTokenPda)({
|
|
12769
13190
|
owner: vaultB.address,
|
|
12770
13191
|
mint: mintB.address,
|
|
12771
13192
|
tokenProgram: mintB.programAddress
|
|
12772
13193
|
}))[0];
|
|
12773
13194
|
const addresses = [
|
|
12774
13195
|
import_system2.SYSTEM_PROGRAM_ADDRESS,
|
|
12775
|
-
(0,
|
|
12776
|
-
|
|
13196
|
+
(0, import_kit125.address)("SysvarRent111111111111111111111111111111111"),
|
|
13197
|
+
import_token_202232.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
12777
13198
|
import_token2.TOKEN_PROGRAM_ADDRESS,
|
|
12778
|
-
|
|
13199
|
+
import_token_202232.TOKEN_2022_PROGRAM_ADDRESS,
|
|
12779
13200
|
NATIVE_MINT,
|
|
12780
|
-
|
|
13201
|
+
import_memo21.MEMO_PROGRAM_ADDRESS,
|
|
12781
13202
|
tunaConfigAddress,
|
|
12782
13203
|
marketAddress,
|
|
12783
13204
|
mintA.address,
|
|
@@ -12796,7 +13217,7 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
12796
13217
|
if (vaultA.data.pythOraclePriceUpdate != DEFAULT_ADDRESS) addresses.push(vaultA.data.pythOraclePriceUpdate);
|
|
12797
13218
|
if (vaultB.data.pythOraclePriceUpdate != DEFAULT_ADDRESS) addresses.push(vaultB.data.pythOraclePriceUpdate);
|
|
12798
13219
|
if (marketMaker == 0 /* Orca */) {
|
|
12799
|
-
addresses.push(
|
|
13220
|
+
addresses.push(import_whirlpools_client15.WHIRLPOOL_PROGRAM_ADDRESS);
|
|
12800
13221
|
addresses.push(WP_NFT_UPDATE_AUTH);
|
|
12801
13222
|
addresses.push(orcaOracleAddress);
|
|
12802
13223
|
const whirlpool = pool;
|
|
@@ -12808,8 +13229,8 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
12808
13229
|
}
|
|
12809
13230
|
}
|
|
12810
13231
|
} else {
|
|
12811
|
-
addresses.push(
|
|
12812
|
-
addresses.push(
|
|
13232
|
+
addresses.push(import_fusionamm_client16.FUSIONAMM_PROGRAM_ADDRESS);
|
|
13233
|
+
addresses.push(import_fusionamm_client16.FP_NFT_UPDATE_AUTH);
|
|
12813
13234
|
}
|
|
12814
13235
|
return addresses;
|
|
12815
13236
|
}
|
|
@@ -12832,17 +13253,17 @@ async function extendAddressLookupTableForMarketInstructions(rpc, poolAddress, m
|
|
|
12832
13253
|
}
|
|
12833
13254
|
|
|
12834
13255
|
// src/txbuilder/repayTunaLpPositionDebt.ts
|
|
12835
|
-
var
|
|
12836
|
-
var
|
|
12837
|
-
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"));
|
|
12838
13259
|
async function repayTunaLpPositionDebtInstructions(rpc, authority, positionMint, collateralA, collateralB, createInstructions, cleanupInstructions) {
|
|
12839
13260
|
const instructions = [];
|
|
12840
13261
|
if (!createInstructions) createInstructions = instructions;
|
|
12841
13262
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
12842
13263
|
const tunaPosition = await fetchTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12843
|
-
const [mintA, mintB] = await (0,
|
|
12844
|
-
(0,
|
|
12845
|
-
(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");
|
|
12846
13267
|
const marketAddress = (await getMarketAddress(tunaPosition.data.pool))[0];
|
|
12847
13268
|
const createUserAtaAInstructions = await getCreateAtaInstructions(
|
|
12848
13269
|
rpc,
|
|
@@ -12878,34 +13299,34 @@ async function repayTunaLpPositionDebtInstructions(rpc, authority, positionMint,
|
|
|
12878
13299
|
}
|
|
12879
13300
|
async function repayTunaLpPositionDebtInstruction(authority, positionMint, mintA, mintB, marketAddress, collateralA, collateralB) {
|
|
12880
13301
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint))[0];
|
|
12881
|
-
const tunaPositionOwnerAtaA = (await (0,
|
|
13302
|
+
const tunaPositionOwnerAtaA = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12882
13303
|
owner: authority.address,
|
|
12883
13304
|
mint: mintA.address,
|
|
12884
13305
|
tokenProgram: mintA.programAddress
|
|
12885
13306
|
}))[0];
|
|
12886
|
-
const tunaPositionOwnerAtaB = (await (0,
|
|
13307
|
+
const tunaPositionOwnerAtaB = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12887
13308
|
owner: authority.address,
|
|
12888
13309
|
mint: mintB.address,
|
|
12889
13310
|
tokenProgram: mintB.programAddress
|
|
12890
13311
|
}))[0];
|
|
12891
|
-
const tunaPositionAtaA = (await (0,
|
|
13312
|
+
const tunaPositionAtaA = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12892
13313
|
owner: tunaPositionAddress,
|
|
12893
13314
|
mint: mintA.address,
|
|
12894
13315
|
tokenProgram: mintA.programAddress
|
|
12895
13316
|
}))[0];
|
|
12896
|
-
const tunaPositionAtaB = (await (0,
|
|
13317
|
+
const tunaPositionAtaB = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12897
13318
|
owner: tunaPositionAddress,
|
|
12898
13319
|
mint: mintB.address,
|
|
12899
13320
|
tokenProgram: mintB.programAddress
|
|
12900
13321
|
}))[0];
|
|
12901
13322
|
const vaultAAddress = (await getLendingVaultAddress(mintA.address))[0];
|
|
12902
|
-
const vaultAAta = (await (0,
|
|
13323
|
+
const vaultAAta = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12903
13324
|
owner: vaultAAddress,
|
|
12904
13325
|
mint: mintA.address,
|
|
12905
13326
|
tokenProgram: mintA.programAddress
|
|
12906
13327
|
}))[0];
|
|
12907
13328
|
const vaultBAddress = (await getLendingVaultAddress(mintB.address))[0];
|
|
12908
|
-
const vaultBAta = (await (0,
|
|
13329
|
+
const vaultBAta = (await (0, import_token_202233.findAssociatedTokenPda)({
|
|
12909
13330
|
owner: vaultBAddress,
|
|
12910
13331
|
mint: mintB.address,
|
|
12911
13332
|
tokenProgram: mintB.programAddress
|
|
@@ -12913,7 +13334,7 @@ async function repayTunaLpPositionDebtInstruction(authority, positionMint, mintA
|
|
|
12913
13334
|
return getRepayTunaLpPositionDebtInstruction({
|
|
12914
13335
|
authority,
|
|
12915
13336
|
market: marketAddress,
|
|
12916
|
-
memoProgram:
|
|
13337
|
+
memoProgram: import_memo22.MEMO_PROGRAM_ADDRESS,
|
|
12917
13338
|
mintA: mintA.address,
|
|
12918
13339
|
mintB: mintB.address,
|
|
12919
13340
|
tokenProgramA: mintA.programAddress,
|
|
@@ -12933,39 +13354,39 @@ async function repayTunaLpPositionDebtInstruction(authority, positionMint, mintA
|
|
|
12933
13354
|
}
|
|
12934
13355
|
|
|
12935
13356
|
// src/txbuilder/rebalanceTunaLpPositionOrca.ts
|
|
12936
|
-
var
|
|
12937
|
-
var
|
|
13357
|
+
var import_whirlpools_client16 = require("@orca-so/whirlpools-client");
|
|
13358
|
+
var import_kit126 = require("@solana/kit");
|
|
12938
13359
|
var import_sysvars3 = require("@solana/sysvars");
|
|
12939
|
-
var
|
|
12940
|
-
var
|
|
12941
|
-
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"));
|
|
12942
13363
|
async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
12943
13364
|
const rent = await (0, import_sysvars3.fetchSysvarRent)(rpc);
|
|
12944
13365
|
let nonRefundableRent = 0n;
|
|
12945
13366
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
12946
13367
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12947
13368
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12948
|
-
const whirlpool = await (0,
|
|
13369
|
+
const whirlpool = await (0, import_whirlpools_client16.fetchMaybeWhirlpool)(rpc, tunaPosition.data.pool);
|
|
12949
13370
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
12950
13371
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
12951
13372
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
12952
13373
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
12953
13374
|
]);
|
|
12954
|
-
const [mintA, mintB] = await (0,
|
|
12955
|
-
(0,
|
|
12956
|
-
(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");
|
|
12957
13378
|
const instructions = [];
|
|
12958
13379
|
if (!createInstructions) createInstructions = instructions;
|
|
12959
13380
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
12960
13381
|
const internalCleanupInstructions = [];
|
|
12961
13382
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
12962
|
-
const [lowerTickArray, upperTickArray] = await (0,
|
|
13383
|
+
const [lowerTickArray, upperTickArray] = await (0, import_whirlpools_client16.fetchAllMaybeTickArray)(rpc, [
|
|
12963
13384
|
secondaryTickArrays.lowerTickArrayAddress,
|
|
12964
13385
|
secondaryTickArrays.upperTickArrayAddress
|
|
12965
13386
|
]);
|
|
12966
13387
|
if (!lowerTickArray.exists) {
|
|
12967
13388
|
instructions.push(
|
|
12968
|
-
(0,
|
|
13389
|
+
(0, import_whirlpools_client16.getInitializeDynamicTickArrayInstruction)({
|
|
12969
13390
|
whirlpool: whirlpool.address,
|
|
12970
13391
|
funder: authority,
|
|
12971
13392
|
tickArray: secondaryTickArrays.lowerTickArrayAddress,
|
|
@@ -12973,11 +13394,11 @@ async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionM
|
|
|
12973
13394
|
idempotent: false
|
|
12974
13395
|
})
|
|
12975
13396
|
);
|
|
12976
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
13397
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client16.getDynamicTickArrayMinSize)());
|
|
12977
13398
|
}
|
|
12978
13399
|
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
12979
13400
|
instructions.push(
|
|
12980
|
-
(0,
|
|
13401
|
+
(0, import_whirlpools_client16.getInitializeDynamicTickArrayInstruction)({
|
|
12981
13402
|
whirlpool: whirlpool.address,
|
|
12982
13403
|
funder: authority,
|
|
12983
13404
|
tickArray: secondaryTickArrays.upperTickArrayAddress,
|
|
@@ -12985,7 +13406,7 @@ async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionM
|
|
|
12985
13406
|
idempotent: false
|
|
12986
13407
|
})
|
|
12987
13408
|
);
|
|
12988
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
13409
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client16.getDynamicTickArrayMinSize)());
|
|
12989
13410
|
}
|
|
12990
13411
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
12991
13412
|
rpc,
|
|
@@ -13017,35 +13438,35 @@ async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionM
|
|
|
13017
13438
|
cleanupInstructions.push(...internalCleanupInstructions);
|
|
13018
13439
|
return {
|
|
13019
13440
|
instructions,
|
|
13020
|
-
initializationCost: (0,
|
|
13441
|
+
initializationCost: (0, import_kit126.lamports)(nonRefundableRent)
|
|
13021
13442
|
};
|
|
13022
13443
|
}
|
|
13023
13444
|
async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool) {
|
|
13024
13445
|
const positionMint = tunaPosition.data.positionMint;
|
|
13025
13446
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
13026
|
-
const orcaPositionAddress = (await (0,
|
|
13027
|
-
const orcaOracleAddress = (await (0,
|
|
13028
|
-
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)({
|
|
13029
13450
|
owner: tunaPosition.address,
|
|
13030
13451
|
mint: positionMint,
|
|
13031
|
-
tokenProgram:
|
|
13452
|
+
tokenProgram: import_token_202234.TOKEN_2022_PROGRAM_ADDRESS
|
|
13032
13453
|
}))[0];
|
|
13033
|
-
const tunaPositionAtaA = (await (0,
|
|
13454
|
+
const tunaPositionAtaA = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13034
13455
|
owner: tunaPosition.address,
|
|
13035
13456
|
mint: mintA.address,
|
|
13036
13457
|
tokenProgram: mintA.programAddress
|
|
13037
13458
|
}))[0];
|
|
13038
|
-
const tunaPositionAtaB = (await (0,
|
|
13459
|
+
const tunaPositionAtaB = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13039
13460
|
owner: tunaPosition.address,
|
|
13040
13461
|
mint: mintB.address,
|
|
13041
13462
|
tokenProgram: mintB.programAddress
|
|
13042
13463
|
}))[0];
|
|
13043
|
-
const feeRecipientAtaA = (await (0,
|
|
13464
|
+
const feeRecipientAtaA = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13044
13465
|
owner: tunaConfig.data.feeRecipient,
|
|
13045
13466
|
mint: mintA.address,
|
|
13046
13467
|
tokenProgram: mintA.programAddress
|
|
13047
13468
|
}))[0];
|
|
13048
|
-
const feeRecipientAtaB = (await (0,
|
|
13469
|
+
const feeRecipientAtaB = (await (0, import_token_202234.findAssociatedTokenPda)({
|
|
13049
13470
|
owner: tunaConfig.data.feeRecipient,
|
|
13050
13471
|
mint: mintB.address,
|
|
13051
13472
|
tokenProgram: mintB.programAddress
|
|
@@ -13061,18 +13482,18 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13061
13482
|
);
|
|
13062
13483
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
13063
13484
|
const remainingAccounts = [
|
|
13064
|
-
{ address: swapTickArrays[0], role:
|
|
13065
|
-
{ address: swapTickArrays[1], role:
|
|
13066
|
-
{ address: swapTickArrays[2], role:
|
|
13067
|
-
{ address: swapTickArrays[3], role:
|
|
13068
|
-
{ address: swapTickArrays[4], role:
|
|
13069
|
-
{ address: lowerTickArrayAddress, role:
|
|
13070
|
-
{ address: upperTickArrayAddress, role:
|
|
13071
|
-
{ address: secondaryTickArrays.lowerTickArrayAddress, role:
|
|
13072
|
-
{ address: secondaryTickArrays.upperTickArrayAddress, role:
|
|
13073
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
13074
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
13075
|
-
{ 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 }
|
|
13076
13497
|
];
|
|
13077
13498
|
const remainingAccountsInfo = {
|
|
13078
13499
|
slices: [
|
|
@@ -13104,10 +13525,10 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13104
13525
|
feeRecipientAtaA,
|
|
13105
13526
|
feeRecipientAtaB,
|
|
13106
13527
|
whirlpool: whirlpool.address,
|
|
13107
|
-
whirlpoolProgram:
|
|
13528
|
+
whirlpoolProgram: import_whirlpools_client16.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
13108
13529
|
tokenProgramA: mintA.programAddress,
|
|
13109
13530
|
tokenProgramB: mintB.programAddress,
|
|
13110
|
-
memoProgram:
|
|
13531
|
+
memoProgram: import_memo23.MEMO_PROGRAM_ADDRESS,
|
|
13111
13532
|
remainingAccountsInfo
|
|
13112
13533
|
});
|
|
13113
13534
|
ix.accounts.push(...remainingAccounts);
|
|
@@ -13115,56 +13536,56 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13115
13536
|
}
|
|
13116
13537
|
|
|
13117
13538
|
// src/txbuilder/rebalanceTunaLpPositionFusion.ts
|
|
13118
|
-
var
|
|
13119
|
-
var
|
|
13539
|
+
var import_fusionamm_client17 = require("@crypticdot/fusionamm-client");
|
|
13540
|
+
var import_kit127 = require("@solana/kit");
|
|
13120
13541
|
var import_sysvars4 = require("@solana/sysvars");
|
|
13121
|
-
var
|
|
13122
|
-
var
|
|
13123
|
-
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"));
|
|
13124
13545
|
async function rebalanceTunaLpPositionFusionInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
13125
13546
|
const rent = await (0, import_sysvars4.fetchSysvarRent)(rpc);
|
|
13126
13547
|
let nonRefundableRent = 0n;
|
|
13127
13548
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
13128
13549
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
13129
13550
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
13130
|
-
const fusionPool = await (0,
|
|
13551
|
+
const fusionPool = await (0, import_fusionamm_client17.fetchMaybeFusionPool)(rpc, tunaPosition.data.pool);
|
|
13131
13552
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
13132
13553
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
13133
13554
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
13134
13555
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
13135
13556
|
]);
|
|
13136
|
-
const [mintA, mintB] = await (0,
|
|
13137
|
-
(0,
|
|
13138
|
-
(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");
|
|
13139
13560
|
const instructions = [];
|
|
13140
13561
|
if (!createInstructions) createInstructions = instructions;
|
|
13141
13562
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
13142
13563
|
const secondaryTickArrays = await FusionUtils.getTickArraysForRebalancedPosition(fusionPool, tunaPosition);
|
|
13143
|
-
const [lowerTickArray, upperTickArray] = await (0,
|
|
13564
|
+
const [lowerTickArray, upperTickArray] = await (0, import_fusionamm_client17.fetchAllMaybeTickArray)(rpc, [
|
|
13144
13565
|
secondaryTickArrays.lowerTickArrayAddress,
|
|
13145
13566
|
secondaryTickArrays.upperTickArrayAddress
|
|
13146
13567
|
]);
|
|
13147
13568
|
if (!lowerTickArray.exists) {
|
|
13148
13569
|
instructions.push(
|
|
13149
|
-
(0,
|
|
13570
|
+
(0, import_fusionamm_client17.getInitializeTickArrayInstruction)({
|
|
13150
13571
|
fusionPool: fusionPool.address,
|
|
13151
13572
|
funder: authority,
|
|
13152
13573
|
tickArray: secondaryTickArrays.lowerTickArrayAddress,
|
|
13153
13574
|
startTickIndex: secondaryTickArrays.lowerTickArrayStartIndex
|
|
13154
13575
|
})
|
|
13155
13576
|
);
|
|
13156
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
13577
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client17.getTickArraySize)());
|
|
13157
13578
|
}
|
|
13158
13579
|
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
13159
13580
|
instructions.push(
|
|
13160
|
-
(0,
|
|
13581
|
+
(0, import_fusionamm_client17.getInitializeTickArrayInstruction)({
|
|
13161
13582
|
fusionPool: fusionPool.address,
|
|
13162
13583
|
funder: authority,
|
|
13163
13584
|
tickArray: secondaryTickArrays.upperTickArrayAddress,
|
|
13164
13585
|
startTickIndex: secondaryTickArrays.upperTickArrayStartIndex
|
|
13165
13586
|
})
|
|
13166
13587
|
);
|
|
13167
|
-
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0,
|
|
13588
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client17.getTickArraySize)());
|
|
13168
13589
|
}
|
|
13169
13590
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
13170
13591
|
rpc,
|
|
@@ -13195,34 +13616,34 @@ async function rebalanceTunaLpPositionFusionInstructions(rpc, authority, positio
|
|
|
13195
13616
|
instructions.push(ix);
|
|
13196
13617
|
return {
|
|
13197
13618
|
instructions,
|
|
13198
|
-
initializationCost: (0,
|
|
13619
|
+
initializationCost: (0, import_kit127.lamports)(nonRefundableRent)
|
|
13199
13620
|
};
|
|
13200
13621
|
}
|
|
13201
13622
|
async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool) {
|
|
13202
13623
|
const positionMint = tunaPosition.data.positionMint;
|
|
13203
13624
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
13204
|
-
const fusionPositionAddress = (await (0,
|
|
13205
|
-
const tunaPositionAta = (await (0,
|
|
13625
|
+
const fusionPositionAddress = (await (0, import_fusionamm_client17.getPositionAddress)(positionMint))[0];
|
|
13626
|
+
const tunaPositionAta = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13206
13627
|
owner: tunaPosition.address,
|
|
13207
13628
|
mint: positionMint,
|
|
13208
|
-
tokenProgram:
|
|
13629
|
+
tokenProgram: import_token_202235.TOKEN_2022_PROGRAM_ADDRESS
|
|
13209
13630
|
}))[0];
|
|
13210
|
-
const tunaPositionAtaA = (await (0,
|
|
13631
|
+
const tunaPositionAtaA = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13211
13632
|
owner: tunaPosition.address,
|
|
13212
13633
|
mint: mintA.address,
|
|
13213
13634
|
tokenProgram: mintA.programAddress
|
|
13214
13635
|
}))[0];
|
|
13215
|
-
const tunaPositionAtaB = (await (0,
|
|
13636
|
+
const tunaPositionAtaB = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13216
13637
|
owner: tunaPosition.address,
|
|
13217
13638
|
mint: mintB.address,
|
|
13218
13639
|
tokenProgram: mintB.programAddress
|
|
13219
13640
|
}))[0];
|
|
13220
|
-
const feeRecipientAtaA = (await (0,
|
|
13641
|
+
const feeRecipientAtaA = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13221
13642
|
owner: tunaConfig.data.feeRecipient,
|
|
13222
13643
|
mint: mintA.address,
|
|
13223
13644
|
tokenProgram: mintA.programAddress
|
|
13224
13645
|
}))[0];
|
|
13225
|
-
const feeRecipientAtaB = (await (0,
|
|
13646
|
+
const feeRecipientAtaB = (await (0, import_token_202235.findAssociatedTokenPda)({
|
|
13226
13647
|
owner: tunaConfig.data.feeRecipient,
|
|
13227
13648
|
mint: mintB.address,
|
|
13228
13649
|
tokenProgram: mintB.programAddress
|
|
@@ -13238,17 +13659,17 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13238
13659
|
);
|
|
13239
13660
|
const secondaryTickArrays = await FusionUtils.getTickArraysForRebalancedPosition(fusionPool, tunaPosition);
|
|
13240
13661
|
const remainingAccounts = [
|
|
13241
|
-
{ address: swapTickArrays[0], role:
|
|
13242
|
-
{ address: swapTickArrays[1], role:
|
|
13243
|
-
{ address: swapTickArrays[2], role:
|
|
13244
|
-
{ address: swapTickArrays[3], role:
|
|
13245
|
-
{ address: swapTickArrays[4], role:
|
|
13246
|
-
{ address: lowerTickArrayAddress, role:
|
|
13247
|
-
{ address: upperTickArrayAddress, role:
|
|
13248
|
-
{ address: secondaryTickArrays.lowerTickArrayAddress, role:
|
|
13249
|
-
{ address: secondaryTickArrays.upperTickArrayAddress, role:
|
|
13250
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
13251
|
-
{ 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 }
|
|
13252
13673
|
];
|
|
13253
13674
|
const remainingAccountsInfo = {
|
|
13254
13675
|
slices: [
|
|
@@ -13279,10 +13700,10 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13279
13700
|
feeRecipientAtaA,
|
|
13280
13701
|
feeRecipientAtaB,
|
|
13281
13702
|
fusionPool: fusionPool.address,
|
|
13282
|
-
fusionammProgram:
|
|
13703
|
+
fusionammProgram: import_fusionamm_client17.FUSIONAMM_PROGRAM_ADDRESS,
|
|
13283
13704
|
tokenProgramA: mintA.programAddress,
|
|
13284
13705
|
tokenProgramB: mintB.programAddress,
|
|
13285
|
-
memoProgram:
|
|
13706
|
+
memoProgram: import_memo24.MEMO_PROGRAM_ADDRESS,
|
|
13286
13707
|
remainingAccountsInfo
|
|
13287
13708
|
});
|
|
13288
13709
|
ix.accounts.push(...remainingAccounts);
|
|
@@ -13834,6 +14255,8 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13834
14255
|
liquidateTunaSpotPositionOrcaInstructions,
|
|
13835
14256
|
modifyTunaSpotPositionFusionInstruction,
|
|
13836
14257
|
modifyTunaSpotPositionFusionInstructions,
|
|
14258
|
+
modifyTunaSpotPositionJupiterInstruction,
|
|
14259
|
+
modifyTunaSpotPositionJupiterInstructions,
|
|
13837
14260
|
modifyTunaSpotPositionOrcaInstruction,
|
|
13838
14261
|
modifyTunaSpotPositionOrcaInstructions,
|
|
13839
14262
|
mulDiv,
|