@crypticdot/defituna-client 3.3.0 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +11 -13
- package/dist/index.d.ts +11 -13
- package/dist/index.js +892 -473
- package/dist/index.mjs +1153 -367
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -4915,10 +4915,9 @@ function getModifyTunaSpotPositionFusionInstructionDataEncoder() {
|
|
|
4915
4915
|
getStructEncoder29([
|
|
4916
4916
|
["discriminator", fixEncoderSize28(getBytesEncoder28(), 8)],
|
|
4917
4917
|
["decreasePercent", getU32Encoder14()],
|
|
4918
|
-
["decreaseAcceptableSwapAmount", getU64Encoder13()],
|
|
4919
4918
|
["collateralAmount", getU64Encoder13()],
|
|
4920
4919
|
["borrowAmount", getU64Encoder13()],
|
|
4921
|
-
["
|
|
4920
|
+
["requiredSwapAmount", getU64Encoder13()],
|
|
4922
4921
|
["remainingAccountsInfo", getRemainingAccountsInfoEncoder()]
|
|
4923
4922
|
]),
|
|
4924
4923
|
(value) => ({
|
|
@@ -4931,10 +4930,9 @@ function getModifyTunaSpotPositionFusionInstructionDataDecoder() {
|
|
|
4931
4930
|
return getStructDecoder29([
|
|
4932
4931
|
["discriminator", fixDecoderSize27(getBytesDecoder27(), 8)],
|
|
4933
4932
|
["decreasePercent", getU32Decoder14()],
|
|
4934
|
-
["decreaseAcceptableSwapAmount", getU64Decoder13()],
|
|
4935
4933
|
["collateralAmount", getU64Decoder13()],
|
|
4936
4934
|
["borrowAmount", getU64Decoder13()],
|
|
4937
|
-
["
|
|
4935
|
+
["requiredSwapAmount", getU64Decoder13()],
|
|
4938
4936
|
["remainingAccountsInfo", getRemainingAccountsInfoDecoder()]
|
|
4939
4937
|
]);
|
|
4940
4938
|
}
|
|
@@ -5338,10 +5336,9 @@ function getModifyTunaSpotPositionOrcaInstructionDataEncoder() {
|
|
|
5338
5336
|
getStructEncoder31([
|
|
5339
5337
|
["discriminator", fixEncoderSize30(getBytesEncoder30(), 8)],
|
|
5340
5338
|
["decreasePercent", getU32Encoder16()],
|
|
5341
|
-
["decreaseAcceptableSwapAmount", getU64Encoder15()],
|
|
5342
5339
|
["collateralAmount", getU64Encoder15()],
|
|
5343
5340
|
["borrowAmount", getU64Encoder15()],
|
|
5344
|
-
["
|
|
5341
|
+
["requiredSwapAmount", getU64Encoder15()],
|
|
5345
5342
|
["remainingAccountsInfo", getRemainingAccountsInfoEncoder()]
|
|
5346
5343
|
]),
|
|
5347
5344
|
(value) => ({
|
|
@@ -5354,10 +5351,9 @@ function getModifyTunaSpotPositionOrcaInstructionDataDecoder() {
|
|
|
5354
5351
|
return getStructDecoder31([
|
|
5355
5352
|
["discriminator", fixDecoderSize29(getBytesDecoder29(), 8)],
|
|
5356
5353
|
["decreasePercent", getU32Decoder16()],
|
|
5357
|
-
["decreaseAcceptableSwapAmount", getU64Decoder15()],
|
|
5358
5354
|
["collateralAmount", getU64Decoder15()],
|
|
5359
5355
|
["borrowAmount", getU64Decoder15()],
|
|
5360
|
-
["
|
|
5356
|
+
["requiredSwapAmount", getU64Decoder15()],
|
|
5361
5357
|
["remainingAccountsInfo", getRemainingAccountsInfoDecoder()]
|
|
5362
5358
|
]);
|
|
5363
5359
|
}
|
|
@@ -10834,23 +10830,29 @@ async function modifyTunaSpotPositionOrcaInstructions(rpc, authority, poolAddres
|
|
|
10834
10830
|
(await getLendingVaultAddress(pool.data.tokenMintA))[0],
|
|
10835
10831
|
(await getLendingVaultAddress(pool.data.tokenMintB))[0]
|
|
10836
10832
|
]);
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10833
|
+
let hasDirectlyTransferredTokensA = false;
|
|
10834
|
+
let hasDirectlyTransferredTokensB = false;
|
|
10835
|
+
if (tunaPosition.exists) {
|
|
10836
|
+
const tunaPositionAtaAAddress = (await findAssociatedTokenPda13({
|
|
10837
|
+
owner: tunaPositionAddress,
|
|
10838
|
+
mint: mintA.address,
|
|
10839
|
+
tokenProgram: mintA.programAddress
|
|
10840
|
+
}))[0];
|
|
10841
|
+
const tunaPositionAtaBAddress = (await findAssociatedTokenPda13({
|
|
10842
|
+
owner: tunaPositionAddress,
|
|
10843
|
+
mint: mintB.address,
|
|
10844
|
+
tokenProgram: mintB.programAddress
|
|
10845
|
+
}))[0];
|
|
10846
|
+
const [tunaPositionAtaA, tunaPositionAtaB] = await fetchAllToken(rpc, [
|
|
10847
|
+
tunaPositionAtaAAddress,
|
|
10848
|
+
tunaPositionAtaBAddress
|
|
10849
|
+
]);
|
|
10850
|
+
hasDirectlyTransferredTokensA = tunaPositionAtaA.data.amount > (tunaPosition.data.positionToken == 0 /* A */ ? tunaPosition.data.amount : 0n);
|
|
10851
|
+
hasDirectlyTransferredTokensB = tunaPositionAtaB.data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n);
|
|
10852
|
+
}
|
|
10853
|
+
const createUserAtaAInstructions = collateralToken == 0 /* A */ || hasDirectlyTransferredTokensA ? await getCreateAtaInstructions(rpc, authority, mintA.address, authority.address, mintA.programAddress) : void 0;
|
|
10852
10854
|
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
10853
|
-
const createUserAtaBInstructions = collateralToken == 1 /* B */ ||
|
|
10855
|
+
const createUserAtaBInstructions = collateralToken == 1 /* B */ || hasDirectlyTransferredTokensB ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
10854
10856
|
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
10855
10857
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10856
10858
|
rpc,
|
|
@@ -11007,23 +11009,29 @@ async function modifyTunaSpotPositionFusionInstructions(rpc, authority, poolAddr
|
|
|
11007
11009
|
(await getLendingVaultAddress(pool.data.tokenMintA))[0],
|
|
11008
11010
|
(await getLendingVaultAddress(pool.data.tokenMintB))[0]
|
|
11009
11011
|
]);
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11012
|
+
let hasDirectlyTransferredTokensA = false;
|
|
11013
|
+
let hasDirectlyTransferredTokensB = false;
|
|
11014
|
+
if (tunaPosition.exists) {
|
|
11015
|
+
const tunaPositionAtaAAddress = (await findAssociatedTokenPda14({
|
|
11016
|
+
owner: tunaPositionAddress,
|
|
11017
|
+
mint: mintA.address,
|
|
11018
|
+
tokenProgram: mintA.programAddress
|
|
11019
|
+
}))[0];
|
|
11020
|
+
const tunaPositionAtaBAddress = (await findAssociatedTokenPda14({
|
|
11021
|
+
owner: tunaPositionAddress,
|
|
11022
|
+
mint: mintB.address,
|
|
11023
|
+
tokenProgram: mintB.programAddress
|
|
11024
|
+
}))[0];
|
|
11025
|
+
const [tunaPositionAtaA, tunaPositionAtaB] = await fetchAllToken2(rpc, [
|
|
11026
|
+
tunaPositionAtaAAddress,
|
|
11027
|
+
tunaPositionAtaBAddress
|
|
11028
|
+
]);
|
|
11029
|
+
hasDirectlyTransferredTokensA = tunaPositionAtaA.data.amount > (tunaPosition.data.positionToken == 0 /* A */ ? tunaPosition.data.amount : 0n);
|
|
11030
|
+
hasDirectlyTransferredTokensB = tunaPositionAtaB.data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n);
|
|
11031
|
+
}
|
|
11032
|
+
const createUserAtaAInstructions = collateralToken == 0 /* A */ || hasDirectlyTransferredTokensA ? await getCreateAtaInstructions(rpc, authority, mintA.address, authority.address, mintA.programAddress) : void 0;
|
|
11025
11033
|
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
11026
|
-
const createUserAtaBInstructions = collateralToken == 1 /* B */ ||
|
|
11034
|
+
const createUserAtaBInstructions = collateralToken == 1 /* B */ || hasDirectlyTransferredTokensB ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
11027
11035
|
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
11028
11036
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
11029
11037
|
rpc,
|
|
@@ -11149,27 +11157,803 @@ async function modifyTunaSpotPositionFusionInstruction(authority, tunaConfig, mi
|
|
|
11149
11157
|
return ix;
|
|
11150
11158
|
}
|
|
11151
11159
|
|
|
11152
|
-
// src/txbuilder/
|
|
11160
|
+
// src/txbuilder/modifyTunaSpotPositionJupiter.ts
|
|
11161
|
+
import { fetchFusionPool as fetchFusionPool2 } from "@crypticdot/fusionamm-client";
|
|
11162
|
+
|
|
11163
|
+
// ../../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
|
|
11164
|
+
import {
|
|
11165
|
+
assertAccountExists as assertAccountExists7,
|
|
11166
|
+
assertAccountsExist as assertAccountsExist8,
|
|
11167
|
+
combineCodec as combineCodec62,
|
|
11168
|
+
decodeAccount as decodeAccount7,
|
|
11169
|
+
fetchEncodedAccount as fetchEncodedAccount7,
|
|
11170
|
+
fetchEncodedAccounts as fetchEncodedAccounts7,
|
|
11171
|
+
fixDecoderSize as fixDecoderSize56,
|
|
11172
|
+
fixEncoderSize as fixEncoderSize57,
|
|
11173
|
+
getAddressDecoder as getAddressDecoder16,
|
|
11174
|
+
getAddressEncoder as getAddressEncoder20,
|
|
11175
|
+
getBytesDecoder as getBytesDecoder56,
|
|
11176
|
+
getBytesEncoder as getBytesEncoder57,
|
|
11177
|
+
getStructDecoder as getStructDecoder58,
|
|
11178
|
+
getStructEncoder as getStructEncoder58,
|
|
11179
|
+
getU64Decoder as getU64Decoder23,
|
|
11180
|
+
getU64Encoder as getU64Encoder23,
|
|
11181
|
+
transformEncoder as transformEncoder56
|
|
11182
|
+
} from "@solana/kit";
|
|
11183
|
+
import {
|
|
11184
|
+
isProgramError as isProgramError2
|
|
11185
|
+
} from "@solana/kit";
|
|
11186
|
+
import {
|
|
11187
|
+
containsBytes as containsBytes2,
|
|
11188
|
+
fixEncoderSize as fixEncoderSize210,
|
|
11189
|
+
getBytesEncoder as getBytesEncoder210
|
|
11190
|
+
} from "@solana/kit";
|
|
11191
|
+
import {
|
|
11192
|
+
combineCodec as combineCodec210,
|
|
11193
|
+
fixDecoderSize as fixDecoderSize210,
|
|
11194
|
+
fixEncoderSize as fixEncoderSize310,
|
|
11195
|
+
getBytesDecoder as getBytesDecoder210,
|
|
11196
|
+
getBytesEncoder as getBytesEncoder310,
|
|
11197
|
+
getStructDecoder as getStructDecoder210,
|
|
11198
|
+
getStructEncoder as getStructEncoder210,
|
|
11199
|
+
getU8Decoder as getU8Decoder6,
|
|
11200
|
+
getU8Encoder as getU8Encoder6,
|
|
11201
|
+
transformEncoder as transformEncoder210
|
|
11202
|
+
} from "@solana/kit";
|
|
11203
|
+
import {
|
|
11204
|
+
AccountRole as AccountRole10,
|
|
11205
|
+
isProgramDerivedAddress as isProgramDerivedAddress2,
|
|
11206
|
+
isTransactionSigner as kitIsTransactionSigner2,
|
|
11207
|
+
upgradeRoleToSigner as upgradeRoleToSigner2
|
|
11208
|
+
} from "@solana/kit";
|
|
11209
|
+
import {
|
|
11210
|
+
combineCodec as combineCodec310,
|
|
11211
|
+
fixDecoderSize as fixDecoderSize310,
|
|
11212
|
+
fixEncoderSize as fixEncoderSize410,
|
|
11213
|
+
getAddressEncoder as getAddressEncoder22,
|
|
11214
|
+
getBytesDecoder as getBytesDecoder310,
|
|
11215
|
+
getBytesEncoder as getBytesEncoder410,
|
|
11216
|
+
getProgramDerivedAddress as getProgramDerivedAddress2,
|
|
11217
|
+
getStructDecoder as getStructDecoder310,
|
|
11218
|
+
getStructEncoder as getStructEncoder310,
|
|
11219
|
+
getU8Decoder as getU8Decoder22,
|
|
11220
|
+
getU8Encoder as getU8Encoder22,
|
|
11221
|
+
transformEncoder as transformEncoder310
|
|
11222
|
+
} from "@solana/kit";
|
|
11223
|
+
import {
|
|
11224
|
+
combineCodec as combineCodec410,
|
|
11225
|
+
fixDecoderSize as fixDecoderSize410,
|
|
11226
|
+
fixEncoderSize as fixEncoderSize58,
|
|
11227
|
+
getBooleanDecoder as getBooleanDecoder9,
|
|
11228
|
+
getBooleanEncoder as getBooleanEncoder9,
|
|
11229
|
+
getBytesDecoder as getBytesDecoder410,
|
|
11230
|
+
getBytesEncoder as getBytesEncoder58,
|
|
11231
|
+
getStructDecoder as getStructDecoder410,
|
|
11232
|
+
getStructEncoder as getStructEncoder410,
|
|
11233
|
+
getU8Decoder as getU8Decoder32,
|
|
11234
|
+
getU8Encoder as getU8Encoder32,
|
|
11235
|
+
transformEncoder as transformEncoder410
|
|
11236
|
+
} from "@solana/kit";
|
|
11237
|
+
import {
|
|
11238
|
+
combineCodec as combineCodec510,
|
|
11239
|
+
fixDecoderSize as fixDecoderSize57,
|
|
11240
|
+
fixEncoderSize as fixEncoderSize62,
|
|
11241
|
+
getAddressEncoder as getAddressEncoder32,
|
|
11242
|
+
getBytesDecoder as getBytesDecoder57,
|
|
11243
|
+
getBytesEncoder as getBytesEncoder62,
|
|
11244
|
+
getProgramDerivedAddress as getProgramDerivedAddress22,
|
|
11245
|
+
getStructDecoder as getStructDecoder59,
|
|
11246
|
+
getStructEncoder as getStructEncoder59,
|
|
11247
|
+
transformEncoder as transformEncoder57
|
|
11248
|
+
} from "@solana/kit";
|
|
11249
|
+
import {
|
|
11250
|
+
combineCodec as combineCodec63,
|
|
11251
|
+
fixDecoderSize as fixDecoderSize62,
|
|
11252
|
+
fixEncoderSize as fixEncoderSize72,
|
|
11253
|
+
getAddressEncoder as getAddressEncoder42,
|
|
11254
|
+
getBytesDecoder as getBytesDecoder62,
|
|
11255
|
+
getBytesEncoder as getBytesEncoder72,
|
|
11256
|
+
getProgramDerivedAddress as getProgramDerivedAddress3,
|
|
11257
|
+
getStructDecoder as getStructDecoder62,
|
|
11258
|
+
getStructEncoder as getStructEncoder62,
|
|
11259
|
+
getU8Decoder as getU8Decoder42,
|
|
11260
|
+
getU8Encoder as getU8Encoder42,
|
|
11261
|
+
transformEncoder as transformEncoder62
|
|
11262
|
+
} from "@solana/kit";
|
|
11263
|
+
import {
|
|
11264
|
+
combineCodec as combineCodec72,
|
|
11265
|
+
fixDecoderSize as fixDecoderSize72,
|
|
11266
|
+
fixEncoderSize as fixEncoderSize82,
|
|
11267
|
+
getBytesDecoder as getBytesDecoder72,
|
|
11268
|
+
getBytesEncoder as getBytesEncoder82,
|
|
11269
|
+
getStructDecoder as getStructDecoder72,
|
|
11270
|
+
getStructEncoder as getStructEncoder72,
|
|
11271
|
+
getU8Decoder as getU8Decoder52,
|
|
11272
|
+
getU8Encoder as getU8Encoder52,
|
|
11273
|
+
transformEncoder as transformEncoder72
|
|
11274
|
+
} from "@solana/kit";
|
|
11275
|
+
import {
|
|
11276
|
+
combineCodec as combineCodec82,
|
|
11277
|
+
fixDecoderSize as fixDecoderSize82,
|
|
11278
|
+
fixEncoderSize as fixEncoderSize92,
|
|
11279
|
+
getBytesDecoder as getBytesDecoder82,
|
|
11280
|
+
getBytesEncoder as getBytesEncoder92,
|
|
11281
|
+
getStructDecoder as getStructDecoder82,
|
|
11282
|
+
getStructEncoder as getStructEncoder82,
|
|
11283
|
+
transformEncoder as transformEncoder82
|
|
11284
|
+
} from "@solana/kit";
|
|
11285
|
+
import {
|
|
11286
|
+
combineCodec as combineCodec212,
|
|
11287
|
+
fixDecoderSize as fixDecoderSize92,
|
|
11288
|
+
fixEncoderSize as fixEncoderSize102,
|
|
11289
|
+
getArrayDecoder as getArrayDecoder3,
|
|
11290
|
+
getArrayEncoder as getArrayEncoder3,
|
|
11291
|
+
getBytesDecoder as getBytesDecoder92,
|
|
11292
|
+
getBytesEncoder as getBytesEncoder102,
|
|
11293
|
+
getStructDecoder as getStructDecoder182,
|
|
11294
|
+
getStructEncoder as getStructEncoder182,
|
|
11295
|
+
getU16Decoder as getU16Decoder22,
|
|
11296
|
+
getU16Encoder as getU16Encoder22,
|
|
11297
|
+
getU64Decoder as getU64Decoder52,
|
|
11298
|
+
getU64Encoder as getU64Encoder52,
|
|
11299
|
+
getU8Decoder as getU8Decoder11,
|
|
11300
|
+
getU8Encoder as getU8Encoder11,
|
|
11301
|
+
transformEncoder as transformEncoder92
|
|
11302
|
+
} from "@solana/kit";
|
|
11303
|
+
import {
|
|
11304
|
+
combineCodec as combineCodec92,
|
|
11305
|
+
getEnumDecoder as getEnumDecoder5,
|
|
11306
|
+
getEnumEncoder as getEnumEncoder5
|
|
11307
|
+
} from "@solana/kit";
|
|
11308
|
+
import {
|
|
11309
|
+
combineCodec as combineCodec102,
|
|
11310
|
+
getEnumDecoder as getEnumDecoder22,
|
|
11311
|
+
getEnumEncoder as getEnumEncoder22
|
|
11312
|
+
} from "@solana/kit";
|
|
11313
|
+
import {
|
|
11314
|
+
combineCodec as combineCodec112,
|
|
11315
|
+
getArrayDecoder as getArrayDecoder2,
|
|
11316
|
+
getArrayEncoder as getArrayEncoder2,
|
|
11317
|
+
getStructDecoder as getStructDecoder92,
|
|
11318
|
+
getStructEncoder as getStructEncoder92
|
|
11319
|
+
} from "@solana/kit";
|
|
11320
|
+
import {
|
|
11321
|
+
combineCodec as combineCodec122,
|
|
11322
|
+
getStructDecoder as getStructDecoder102,
|
|
11323
|
+
getStructEncoder as getStructEncoder102,
|
|
11324
|
+
getU8Decoder as getU8Decoder62,
|
|
11325
|
+
getU8Encoder as getU8Encoder62
|
|
11326
|
+
} from "@solana/kit";
|
|
11327
|
+
import {
|
|
11328
|
+
combineCodec as combineCodec132,
|
|
11329
|
+
getAddressDecoder as getAddressDecoder22,
|
|
11330
|
+
getAddressEncoder as getAddressEncoder52,
|
|
11331
|
+
getStructDecoder as getStructDecoder112,
|
|
11332
|
+
getStructEncoder as getStructEncoder112,
|
|
11333
|
+
getU64Decoder as getU64Decoder24,
|
|
11334
|
+
getU64Encoder as getU64Encoder24
|
|
11335
|
+
} from "@solana/kit";
|
|
11336
|
+
import {
|
|
11337
|
+
combineCodec as combineCodec142,
|
|
11338
|
+
getArrayDecoder as getArrayDecoder22,
|
|
11339
|
+
getArrayEncoder as getArrayEncoder22,
|
|
11340
|
+
getStructDecoder as getStructDecoder122,
|
|
11341
|
+
getStructEncoder as getStructEncoder122
|
|
11342
|
+
} from "@solana/kit";
|
|
11343
|
+
import {
|
|
11344
|
+
combineCodec as combineCodec152,
|
|
11345
|
+
getStructDecoder as getStructDecoder132,
|
|
11346
|
+
getStructEncoder as getStructEncoder132,
|
|
11347
|
+
getU8Decoder as getU8Decoder7,
|
|
11348
|
+
getU8Encoder as getU8Encoder7
|
|
11349
|
+
} from "@solana/kit";
|
|
11350
|
+
import {
|
|
11351
|
+
combineCodec as combineCodec162,
|
|
11352
|
+
getStructDecoder as getStructDecoder142,
|
|
11353
|
+
getStructEncoder as getStructEncoder142,
|
|
11354
|
+
getU8Decoder as getU8Decoder8,
|
|
11355
|
+
getU8Encoder as getU8Encoder8
|
|
11356
|
+
} from "@solana/kit";
|
|
11357
|
+
import {
|
|
11358
|
+
combineCodec as combineCodec172,
|
|
11359
|
+
getStructDecoder as getStructDecoder152,
|
|
11360
|
+
getStructEncoder as getStructEncoder152,
|
|
11361
|
+
getU16Decoder as getU16Decoder9,
|
|
11362
|
+
getU16Encoder as getU16Encoder9,
|
|
11363
|
+
getU8Decoder as getU8Decoder9,
|
|
11364
|
+
getU8Encoder as getU8Encoder9
|
|
11365
|
+
} from "@solana/kit";
|
|
11366
|
+
import {
|
|
11367
|
+
combineCodec as combineCodec182,
|
|
11368
|
+
getEnumDecoder as getEnumDecoder32,
|
|
11369
|
+
getEnumEncoder as getEnumEncoder32
|
|
11370
|
+
} from "@solana/kit";
|
|
11371
|
+
import {
|
|
11372
|
+
combineCodec as combineCodec192,
|
|
11373
|
+
getBooleanDecoder as getBooleanDecoder22,
|
|
11374
|
+
getBooleanEncoder as getBooleanEncoder22,
|
|
11375
|
+
getDiscriminatedUnionDecoder,
|
|
11376
|
+
getDiscriminatedUnionEncoder,
|
|
11377
|
+
getOptionDecoder as getOptionDecoder3,
|
|
11378
|
+
getOptionEncoder as getOptionEncoder3,
|
|
11379
|
+
getStructDecoder as getStructDecoder162,
|
|
11380
|
+
getStructEncoder as getStructEncoder162,
|
|
11381
|
+
getU32Decoder as getU32Decoder27,
|
|
11382
|
+
getU32Encoder as getU32Encoder27,
|
|
11383
|
+
getU64Decoder as getU64Decoder32,
|
|
11384
|
+
getU64Encoder as getU64Encoder32,
|
|
11385
|
+
getU8Decoder as getU8Decoder10,
|
|
11386
|
+
getU8Encoder as getU8Encoder10,
|
|
11387
|
+
getUnitDecoder,
|
|
11388
|
+
getUnitEncoder
|
|
11389
|
+
} from "@solana/kit";
|
|
11390
|
+
import {
|
|
11391
|
+
combineCodec as combineCodec202,
|
|
11392
|
+
getAddressDecoder as getAddressDecoder32,
|
|
11393
|
+
getAddressEncoder as getAddressEncoder62,
|
|
11394
|
+
getStructDecoder as getStructDecoder172,
|
|
11395
|
+
getStructEncoder as getStructEncoder172,
|
|
11396
|
+
getU64Decoder as getU64Decoder42,
|
|
11397
|
+
getU64Encoder as getU64Encoder42
|
|
11398
|
+
} from "@solana/kit";
|
|
11399
|
+
import {
|
|
11400
|
+
combineCodec as combineCodec222,
|
|
11401
|
+
fixDecoderSize as fixDecoderSize102,
|
|
11402
|
+
fixEncoderSize as fixEncoderSize112,
|
|
11403
|
+
getArrayDecoder as getArrayDecoder4,
|
|
11404
|
+
getArrayEncoder as getArrayEncoder4,
|
|
11405
|
+
getBytesDecoder as getBytesDecoder102,
|
|
11406
|
+
getBytesEncoder as getBytesEncoder112,
|
|
11407
|
+
getStructDecoder as getStructDecoder192,
|
|
11408
|
+
getStructEncoder as getStructEncoder192,
|
|
11409
|
+
getU16Decoder as getU16Decoder32,
|
|
11410
|
+
getU16Encoder as getU16Encoder32,
|
|
11411
|
+
getU64Decoder as getU64Decoder62,
|
|
11412
|
+
getU64Encoder as getU64Encoder62,
|
|
11413
|
+
transformEncoder as transformEncoder102
|
|
11414
|
+
} from "@solana/kit";
|
|
11415
|
+
import {
|
|
11416
|
+
combineCodec as combineCodec232,
|
|
11417
|
+
fixDecoderSize as fixDecoderSize112,
|
|
11418
|
+
fixEncoderSize as fixEncoderSize122,
|
|
11419
|
+
getArrayDecoder as getArrayDecoder5,
|
|
11420
|
+
getArrayEncoder as getArrayEncoder5,
|
|
11421
|
+
getBytesDecoder as getBytesDecoder112,
|
|
11422
|
+
getBytesEncoder as getBytesEncoder122,
|
|
11423
|
+
getStructDecoder as getStructDecoder202,
|
|
11424
|
+
getStructEncoder as getStructEncoder202,
|
|
11425
|
+
getU16Decoder as getU16Decoder42,
|
|
11426
|
+
getU16Encoder as getU16Encoder42,
|
|
11427
|
+
getU64Decoder as getU64Decoder72,
|
|
11428
|
+
getU64Encoder as getU64Encoder72,
|
|
11429
|
+
getU8Decoder as getU8Decoder12,
|
|
11430
|
+
getU8Encoder as getU8Encoder12,
|
|
11431
|
+
transformEncoder as transformEncoder112
|
|
11432
|
+
} from "@solana/kit";
|
|
11433
|
+
import {
|
|
11434
|
+
combineCodec as combineCodec242,
|
|
11435
|
+
fixDecoderSize as fixDecoderSize122,
|
|
11436
|
+
fixEncoderSize as fixEncoderSize132,
|
|
11437
|
+
getArrayDecoder as getArrayDecoder6,
|
|
11438
|
+
getArrayEncoder as getArrayEncoder6,
|
|
11439
|
+
getBytesDecoder as getBytesDecoder122,
|
|
11440
|
+
getBytesEncoder as getBytesEncoder132,
|
|
11441
|
+
getStructDecoder as getStructDecoder212,
|
|
11442
|
+
getStructEncoder as getStructEncoder212,
|
|
11443
|
+
getU16Decoder as getU16Decoder52,
|
|
11444
|
+
getU16Encoder as getU16Encoder52,
|
|
11445
|
+
getU64Decoder as getU64Decoder82,
|
|
11446
|
+
getU64Encoder as getU64Encoder82,
|
|
11447
|
+
transformEncoder as transformEncoder122
|
|
11448
|
+
} from "@solana/kit";
|
|
11449
|
+
import {
|
|
11450
|
+
combineCodec as combineCodec252,
|
|
11451
|
+
fixDecoderSize as fixDecoderSize132,
|
|
11452
|
+
fixEncoderSize as fixEncoderSize142,
|
|
11453
|
+
getArrayDecoder as getArrayDecoder7,
|
|
11454
|
+
getArrayEncoder as getArrayEncoder7,
|
|
11455
|
+
getBytesDecoder as getBytesDecoder132,
|
|
11456
|
+
getBytesEncoder as getBytesEncoder142,
|
|
11457
|
+
getStructDecoder as getStructDecoder222,
|
|
11458
|
+
getStructEncoder as getStructEncoder222,
|
|
11459
|
+
getU16Decoder as getU16Decoder62,
|
|
11460
|
+
getU16Encoder as getU16Encoder62,
|
|
11461
|
+
getU64Decoder as getU64Decoder92,
|
|
11462
|
+
getU64Encoder as getU64Encoder92,
|
|
11463
|
+
getU8Decoder as getU8Decoder13,
|
|
11464
|
+
getU8Encoder as getU8Encoder13,
|
|
11465
|
+
transformEncoder as transformEncoder132
|
|
11466
|
+
} from "@solana/kit";
|
|
11467
|
+
import {
|
|
11468
|
+
combineCodec as combineCodec262,
|
|
11469
|
+
fixDecoderSize as fixDecoderSize142,
|
|
11470
|
+
fixEncoderSize as fixEncoderSize152,
|
|
11471
|
+
getBytesDecoder as getBytesDecoder142,
|
|
11472
|
+
getBytesEncoder as getBytesEncoder152,
|
|
11473
|
+
getStructDecoder as getStructDecoder232,
|
|
11474
|
+
getStructEncoder as getStructEncoder232,
|
|
11475
|
+
transformEncoder as transformEncoder142
|
|
11476
|
+
} from "@solana/kit";
|
|
11477
|
+
import {
|
|
11478
|
+
combineCodec as combineCodec272,
|
|
11479
|
+
fixDecoderSize as fixDecoderSize152,
|
|
11480
|
+
fixEncoderSize as fixEncoderSize162,
|
|
11481
|
+
getArrayDecoder as getArrayDecoder8,
|
|
11482
|
+
getArrayEncoder as getArrayEncoder8,
|
|
11483
|
+
getBytesDecoder as getBytesDecoder152,
|
|
11484
|
+
getBytesEncoder as getBytesEncoder162,
|
|
11485
|
+
getStructDecoder as getStructDecoder242,
|
|
11486
|
+
getStructEncoder as getStructEncoder242,
|
|
11487
|
+
getU16Decoder as getU16Decoder72,
|
|
11488
|
+
getU16Encoder as getU16Encoder72,
|
|
11489
|
+
getU64Decoder as getU64Decoder102,
|
|
11490
|
+
getU64Encoder as getU64Encoder102,
|
|
11491
|
+
getU8Decoder as getU8Decoder14,
|
|
11492
|
+
getU8Encoder as getU8Encoder14,
|
|
11493
|
+
transformEncoder as transformEncoder152
|
|
11494
|
+
} from "@solana/kit";
|
|
11495
|
+
import {
|
|
11496
|
+
combineCodec as combineCodec282,
|
|
11497
|
+
fixDecoderSize as fixDecoderSize162,
|
|
11498
|
+
fixEncoderSize as fixEncoderSize172,
|
|
11499
|
+
getArrayDecoder as getArrayDecoder9,
|
|
11500
|
+
getArrayEncoder as getArrayEncoder9,
|
|
11501
|
+
getBytesDecoder as getBytesDecoder162,
|
|
11502
|
+
getBytesEncoder as getBytesEncoder172,
|
|
11503
|
+
getStructDecoder as getStructDecoder252,
|
|
11504
|
+
getStructEncoder as getStructEncoder252,
|
|
11505
|
+
getU16Decoder as getU16Decoder82,
|
|
11506
|
+
getU16Encoder as getU16Encoder82,
|
|
11507
|
+
getU64Decoder as getU64Decoder112,
|
|
11508
|
+
getU64Encoder as getU64Encoder112,
|
|
11509
|
+
getU8Decoder as getU8Decoder15,
|
|
11510
|
+
getU8Encoder as getU8Encoder15,
|
|
11511
|
+
transformEncoder as transformEncoder162
|
|
11512
|
+
} from "@solana/kit";
|
|
11513
|
+
import {
|
|
11514
|
+
combineCodec as combineCodec292,
|
|
11515
|
+
fixDecoderSize as fixDecoderSize172,
|
|
11516
|
+
fixEncoderSize as fixEncoderSize182,
|
|
11517
|
+
getArrayDecoder as getArrayDecoder10,
|
|
11518
|
+
getArrayEncoder as getArrayEncoder10,
|
|
11519
|
+
getBytesDecoder as getBytesDecoder172,
|
|
11520
|
+
getBytesEncoder as getBytesEncoder182,
|
|
11521
|
+
getStructDecoder as getStructDecoder262,
|
|
11522
|
+
getStructEncoder as getStructEncoder262,
|
|
11523
|
+
getU16Decoder as getU16Decoder92,
|
|
11524
|
+
getU16Encoder as getU16Encoder92,
|
|
11525
|
+
getU64Decoder as getU64Decoder122,
|
|
11526
|
+
getU64Encoder as getU64Encoder122,
|
|
11527
|
+
getU8Decoder as getU8Decoder16,
|
|
11528
|
+
getU8Encoder as getU8Encoder16,
|
|
11529
|
+
transformEncoder as transformEncoder172
|
|
11530
|
+
} from "@solana/kit";
|
|
11531
|
+
import {
|
|
11532
|
+
combineCodec as combineCodec302,
|
|
11533
|
+
fixDecoderSize as fixDecoderSize182,
|
|
11534
|
+
fixEncoderSize as fixEncoderSize192,
|
|
11535
|
+
getArrayDecoder as getArrayDecoder11,
|
|
11536
|
+
getArrayEncoder as getArrayEncoder11,
|
|
11537
|
+
getBytesDecoder as getBytesDecoder182,
|
|
11538
|
+
getBytesEncoder as getBytesEncoder192,
|
|
11539
|
+
getStructDecoder as getStructDecoder272,
|
|
11540
|
+
getStructEncoder as getStructEncoder272,
|
|
11541
|
+
getU16Decoder as getU16Decoder10,
|
|
11542
|
+
getU16Encoder as getU16Encoder10,
|
|
11543
|
+
getU64Decoder as getU64Decoder132,
|
|
11544
|
+
getU64Encoder as getU64Encoder132,
|
|
11545
|
+
getU8Decoder as getU8Decoder17,
|
|
11546
|
+
getU8Encoder as getU8Encoder17,
|
|
11547
|
+
transformEncoder as transformEncoder182
|
|
11548
|
+
} from "@solana/kit";
|
|
11549
|
+
import {
|
|
11550
|
+
combineCodec as combineCodec312,
|
|
11551
|
+
fixDecoderSize as fixDecoderSize192,
|
|
11552
|
+
fixEncoderSize as fixEncoderSize202,
|
|
11553
|
+
getArrayDecoder as getArrayDecoder12,
|
|
11554
|
+
getArrayEncoder as getArrayEncoder12,
|
|
11555
|
+
getBytesDecoder as getBytesDecoder192,
|
|
11556
|
+
getBytesEncoder as getBytesEncoder202,
|
|
11557
|
+
getStructDecoder as getStructDecoder282,
|
|
11558
|
+
getStructEncoder as getStructEncoder282,
|
|
11559
|
+
getU16Decoder as getU16Decoder11,
|
|
11560
|
+
getU16Encoder as getU16Encoder11,
|
|
11561
|
+
getU64Decoder as getU64Decoder142,
|
|
11562
|
+
getU64Encoder as getU64Encoder142,
|
|
11563
|
+
getU8Decoder as getU8Decoder18,
|
|
11564
|
+
getU8Encoder as getU8Encoder18,
|
|
11565
|
+
transformEncoder as transformEncoder192
|
|
11566
|
+
} from "@solana/kit";
|
|
11567
|
+
var TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([
|
|
11568
|
+
156,
|
|
11569
|
+
247,
|
|
11570
|
+
9,
|
|
11571
|
+
188,
|
|
11572
|
+
54,
|
|
11573
|
+
108,
|
|
11574
|
+
85,
|
|
11575
|
+
77
|
|
11576
|
+
]);
|
|
11577
|
+
var JUPITER_PROGRAM_ADDRESS = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
|
|
11578
|
+
var JUPITER_ERROR__EMPTY_ROUTE = 6e3;
|
|
11579
|
+
var JUPITER_ERROR__SLIPPAGE_TOLERANCE_EXCEEDED = 6001;
|
|
11580
|
+
var JUPITER_ERROR__INVALID_CALCULATION = 6002;
|
|
11581
|
+
var JUPITER_ERROR__MISSING_PLATFORM_FEE_ACCOUNT = 6003;
|
|
11582
|
+
var JUPITER_ERROR__INVALID_SLIPPAGE = 6004;
|
|
11583
|
+
var JUPITER_ERROR__NOT_ENOUGH_PERCENT = 6005;
|
|
11584
|
+
var JUPITER_ERROR__INVALID_INPUT_INDEX = 6006;
|
|
11585
|
+
var JUPITER_ERROR__INVALID_OUTPUT_INDEX = 6007;
|
|
11586
|
+
var JUPITER_ERROR__NOT_ENOUGH_ACCOUNT_KEYS = 6008;
|
|
11587
|
+
var JUPITER_ERROR__NON_ZERO_MINIMUM_OUT_AMOUNT_NOT_SUPPORTED = 6009;
|
|
11588
|
+
var JUPITER_ERROR__INVALID_ROUTE_PLAN = 6010;
|
|
11589
|
+
var JUPITER_ERROR__INVALID_REFERRAL_AUTHORITY = 6011;
|
|
11590
|
+
var JUPITER_ERROR__LEDGER_TOKEN_ACCOUNT_DOES_NOT_MATCH = 6012;
|
|
11591
|
+
var JUPITER_ERROR__INVALID_TOKEN_LEDGER = 6013;
|
|
11592
|
+
var JUPITER_ERROR__INCORRECT_TOKEN_PROGRAM_I_D = 6014;
|
|
11593
|
+
var JUPITER_ERROR__TOKEN_PROGRAM_NOT_PROVIDED = 6015;
|
|
11594
|
+
var JUPITER_ERROR__SWAP_NOT_SUPPORTED = 6016;
|
|
11595
|
+
var JUPITER_ERROR__EXACT_OUT_AMOUNT_NOT_MATCHED = 6017;
|
|
11596
|
+
var JUPITER_ERROR__SOURCE_AND_DESTINATION_MINT_CANNOT_BE_THE_SAME = 6018;
|
|
11597
|
+
var jupiterErrorMessages;
|
|
11598
|
+
if (process.env.NODE_ENV !== "production") {
|
|
11599
|
+
jupiterErrorMessages = {
|
|
11600
|
+
[JUPITER_ERROR__EMPTY_ROUTE]: `Empty route`,
|
|
11601
|
+
[JUPITER_ERROR__EXACT_OUT_AMOUNT_NOT_MATCHED]: `Exact out amount doesn't match`,
|
|
11602
|
+
[JUPITER_ERROR__INCORRECT_TOKEN_PROGRAM_I_D]: `Token program ID is invalid`,
|
|
11603
|
+
[JUPITER_ERROR__INVALID_CALCULATION]: `Invalid calculation`,
|
|
11604
|
+
[JUPITER_ERROR__INVALID_INPUT_INDEX]: `Token input index is invalid`,
|
|
11605
|
+
[JUPITER_ERROR__INVALID_OUTPUT_INDEX]: `Token output index is invalid`,
|
|
11606
|
+
[JUPITER_ERROR__INVALID_REFERRAL_AUTHORITY]: `Invalid referral authority`,
|
|
11607
|
+
[JUPITER_ERROR__INVALID_ROUTE_PLAN]: `Invalid route plan`,
|
|
11608
|
+
[JUPITER_ERROR__INVALID_SLIPPAGE]: `Invalid slippage`,
|
|
11609
|
+
[JUPITER_ERROR__INVALID_TOKEN_LEDGER]: `Invalid token ledger`,
|
|
11610
|
+
[JUPITER_ERROR__LEDGER_TOKEN_ACCOUNT_DOES_NOT_MATCH]: `Token account doesn't match the ledger`,
|
|
11611
|
+
[JUPITER_ERROR__MISSING_PLATFORM_FEE_ACCOUNT]: `Missing platform fee account`,
|
|
11612
|
+
[JUPITER_ERROR__NON_ZERO_MINIMUM_OUT_AMOUNT_NOT_SUPPORTED]: `Non zero minimum out amount not supported`,
|
|
11613
|
+
[JUPITER_ERROR__NOT_ENOUGH_ACCOUNT_KEYS]: `Not Enough Account keys`,
|
|
11614
|
+
[JUPITER_ERROR__NOT_ENOUGH_PERCENT]: `Not enough percent to 100`,
|
|
11615
|
+
[JUPITER_ERROR__SLIPPAGE_TOLERANCE_EXCEEDED]: `Slippage tolerance exceeded`,
|
|
11616
|
+
[JUPITER_ERROR__SOURCE_AND_DESTINATION_MINT_CANNOT_BE_THE_SAME]: `Source mint and destination mint cannot the same`,
|
|
11617
|
+
[JUPITER_ERROR__SWAP_NOT_SUPPORTED]: `Swap not supported`,
|
|
11618
|
+
[JUPITER_ERROR__TOKEN_PROGRAM_NOT_PROVIDED]: `Token program not provided`
|
|
11619
|
+
};
|
|
11620
|
+
}
|
|
11621
|
+
var CLAIM_DISCRIMINATOR = new Uint8Array([
|
|
11622
|
+
62,
|
|
11623
|
+
198,
|
|
11624
|
+
214,
|
|
11625
|
+
193,
|
|
11626
|
+
213,
|
|
11627
|
+
159,
|
|
11628
|
+
108,
|
|
11629
|
+
210
|
|
11630
|
+
]);
|
|
11631
|
+
var CLAIM_TOKEN_DISCRIMINATOR = new Uint8Array([
|
|
11632
|
+
116,
|
|
11633
|
+
206,
|
|
11634
|
+
27,
|
|
11635
|
+
191,
|
|
11636
|
+
166,
|
|
11637
|
+
19,
|
|
11638
|
+
0,
|
|
11639
|
+
73
|
|
11640
|
+
]);
|
|
11641
|
+
var CLOSE_TOKEN_DISCRIMINATOR = new Uint8Array([
|
|
11642
|
+
26,
|
|
11643
|
+
74,
|
|
11644
|
+
236,
|
|
11645
|
+
151,
|
|
11646
|
+
104,
|
|
11647
|
+
64,
|
|
11648
|
+
183,
|
|
11649
|
+
249
|
|
11650
|
+
]);
|
|
11651
|
+
var CREATE_OPEN_ORDERS_DISCRIMINATOR = new Uint8Array([
|
|
11652
|
+
229,
|
|
11653
|
+
194,
|
|
11654
|
+
212,
|
|
11655
|
+
172,
|
|
11656
|
+
8,
|
|
11657
|
+
10,
|
|
11658
|
+
134,
|
|
11659
|
+
147
|
|
11660
|
+
]);
|
|
11661
|
+
var CREATE_PROGRAM_OPEN_ORDERS_DISCRIMINATOR = new Uint8Array([
|
|
11662
|
+
28,
|
|
11663
|
+
226,
|
|
11664
|
+
32,
|
|
11665
|
+
148,
|
|
11666
|
+
188,
|
|
11667
|
+
136,
|
|
11668
|
+
113,
|
|
11669
|
+
171
|
|
11670
|
+
]);
|
|
11671
|
+
var CREATE_TOKEN_ACCOUNT_DISCRIMINATOR = new Uint8Array([
|
|
11672
|
+
147,
|
|
11673
|
+
241,
|
|
11674
|
+
123,
|
|
11675
|
+
100,
|
|
11676
|
+
244,
|
|
11677
|
+
132,
|
|
11678
|
+
174,
|
|
11679
|
+
118
|
|
11680
|
+
]);
|
|
11681
|
+
var CREATE_TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([
|
|
11682
|
+
232,
|
|
11683
|
+
242,
|
|
11684
|
+
197,
|
|
11685
|
+
253,
|
|
11686
|
+
240,
|
|
11687
|
+
143,
|
|
11688
|
+
129,
|
|
11689
|
+
52
|
|
11690
|
+
]);
|
|
11691
|
+
var EXACT_OUT_ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
11692
|
+
208,
|
|
11693
|
+
51,
|
|
11694
|
+
239,
|
|
11695
|
+
151,
|
|
11696
|
+
123,
|
|
11697
|
+
43,
|
|
11698
|
+
237,
|
|
11699
|
+
92
|
|
11700
|
+
]);
|
|
11701
|
+
var EXACT_OUT_ROUTE_V2_DISCRIMINATOR = new Uint8Array([
|
|
11702
|
+
157,
|
|
11703
|
+
138,
|
|
11704
|
+
184,
|
|
11705
|
+
82,
|
|
11706
|
+
21,
|
|
11707
|
+
244,
|
|
11708
|
+
243,
|
|
11709
|
+
36
|
|
11710
|
+
]);
|
|
11711
|
+
var ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
11712
|
+
229,
|
|
11713
|
+
23,
|
|
11714
|
+
203,
|
|
11715
|
+
151,
|
|
11716
|
+
122,
|
|
11717
|
+
227,
|
|
11718
|
+
173,
|
|
11719
|
+
42
|
|
11720
|
+
]);
|
|
11721
|
+
var ROUTE_V2_DISCRIMINATOR = new Uint8Array([
|
|
11722
|
+
187,
|
|
11723
|
+
100,
|
|
11724
|
+
250,
|
|
11725
|
+
204,
|
|
11726
|
+
49,
|
|
11727
|
+
196,
|
|
11728
|
+
175,
|
|
11729
|
+
20
|
|
11730
|
+
]);
|
|
11731
|
+
var ROUTE_WITH_TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([
|
|
11732
|
+
150,
|
|
11733
|
+
86,
|
|
11734
|
+
71,
|
|
11735
|
+
116,
|
|
11736
|
+
167,
|
|
11737
|
+
93,
|
|
11738
|
+
14,
|
|
11739
|
+
104
|
|
11740
|
+
]);
|
|
11741
|
+
var SET_TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([
|
|
11742
|
+
228,
|
|
11743
|
+
85,
|
|
11744
|
+
185,
|
|
11745
|
+
112,
|
|
11746
|
+
78,
|
|
11747
|
+
79,
|
|
11748
|
+
77,
|
|
11749
|
+
2
|
|
11750
|
+
]);
|
|
11751
|
+
var SHARED_ACCOUNTS_EXACT_OUT_ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
11752
|
+
176,
|
|
11753
|
+
209,
|
|
11754
|
+
105,
|
|
11755
|
+
168,
|
|
11756
|
+
154,
|
|
11757
|
+
125,
|
|
11758
|
+
69,
|
|
11759
|
+
62
|
|
11760
|
+
]);
|
|
11761
|
+
var SHARED_ACCOUNTS_EXACT_OUT_ROUTE_V2_DISCRIMINATOR = new Uint8Array([
|
|
11762
|
+
53,
|
|
11763
|
+
96,
|
|
11764
|
+
229,
|
|
11765
|
+
202,
|
|
11766
|
+
216,
|
|
11767
|
+
187,
|
|
11768
|
+
250,
|
|
11769
|
+
24
|
|
11770
|
+
]);
|
|
11771
|
+
var SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR = new Uint8Array([
|
|
11772
|
+
193,
|
|
11773
|
+
32,
|
|
11774
|
+
155,
|
|
11775
|
+
51,
|
|
11776
|
+
65,
|
|
11777
|
+
214,
|
|
11778
|
+
156,
|
|
11779
|
+
129
|
|
11780
|
+
]);
|
|
11781
|
+
var SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR = new Uint8Array([
|
|
11782
|
+
209,
|
|
11783
|
+
152,
|
|
11784
|
+
83,
|
|
11785
|
+
147,
|
|
11786
|
+
124,
|
|
11787
|
+
254,
|
|
11788
|
+
216,
|
|
11789
|
+
233
|
|
11790
|
+
]);
|
|
11791
|
+
var SHARED_ACCOUNTS_ROUTE_WITH_TOKEN_LEDGER_DISCRIMINATOR = new Uint8Array([230, 121, 143, 80, 119, 159, 106, 170]);
|
|
11792
|
+
|
|
11793
|
+
// src/txbuilder/modifyTunaSpotPositionJupiter.ts
|
|
11794
|
+
import { fetchWhirlpool as fetchWhirlpool2 } from "@orca-so/whirlpools-client";
|
|
11795
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS10 } from "@solana-program/memo";
|
|
11153
11796
|
import { fetchAllMaybeMint as fetchAllMaybeMint13, findAssociatedTokenPda as findAssociatedTokenPda15 } from "@solana-program/token-2022";
|
|
11154
11797
|
import assert13 from "assert";
|
|
11798
|
+
async function modifyTunaSpotPositionJupiterInstructions(rpc, authority, poolAddress, remainingAccounts, args, createInstructions, cleanupInstructions) {
|
|
11799
|
+
const instructions = [];
|
|
11800
|
+
if (!createInstructions) createInstructions = instructions;
|
|
11801
|
+
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
11802
|
+
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
11803
|
+
const marketAddress = (await getMarketAddress(poolAddress))[0];
|
|
11804
|
+
const market = await fetchMarket(rpc, marketAddress);
|
|
11805
|
+
const pool = market.data.marketMaker == 1 /* Fusion */ ? await fetchFusionPool2(rpc, poolAddress) : await fetchWhirlpool2(rpc, poolAddress);
|
|
11806
|
+
const [mintA, mintB] = await fetchAllMaybeMint13(rpc, [pool.data.tokenMintA, pool.data.tokenMintB]);
|
|
11807
|
+
assert13(mintA.exists, "Token A account not found");
|
|
11808
|
+
assert13(mintB.exists, "Token B account not found");
|
|
11809
|
+
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
11810
|
+
(await getLendingVaultAddress(mintA.address))[0],
|
|
11811
|
+
(await getLendingVaultAddress(mintB.address))[0]
|
|
11812
|
+
]);
|
|
11813
|
+
const createUserAtaAInstructions = await getCreateAtaInstructions(
|
|
11814
|
+
rpc,
|
|
11815
|
+
authority,
|
|
11816
|
+
mintA.address,
|
|
11817
|
+
authority.address,
|
|
11818
|
+
mintA.programAddress
|
|
11819
|
+
);
|
|
11820
|
+
createInstructions.push(...createUserAtaAInstructions.init);
|
|
11821
|
+
const createUserAtaBInstructions = await getCreateAtaInstructions(
|
|
11822
|
+
rpc,
|
|
11823
|
+
authority,
|
|
11824
|
+
mintB.address,
|
|
11825
|
+
authority.address,
|
|
11826
|
+
mintB.programAddress
|
|
11827
|
+
);
|
|
11828
|
+
createInstructions.push(...createUserAtaBInstructions.init);
|
|
11829
|
+
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
11830
|
+
rpc,
|
|
11831
|
+
authority,
|
|
11832
|
+
mintA.address,
|
|
11833
|
+
tunaConfig.data.feeRecipient,
|
|
11834
|
+
mintA.programAddress
|
|
11835
|
+
);
|
|
11836
|
+
createInstructions.push(...createFeeRecipientAtaAInstructions.init);
|
|
11837
|
+
const createFeeRecipientAtaBInstructions = await getCreateAtaInstructions(
|
|
11838
|
+
rpc,
|
|
11839
|
+
authority,
|
|
11840
|
+
mintB.address,
|
|
11841
|
+
tunaConfig.data.feeRecipient,
|
|
11842
|
+
mintB.programAddress
|
|
11843
|
+
);
|
|
11844
|
+
createInstructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
11845
|
+
const ix = await modifyTunaSpotPositionJupiterInstruction(
|
|
11846
|
+
authority,
|
|
11847
|
+
tunaConfig,
|
|
11848
|
+
mintA,
|
|
11849
|
+
mintB,
|
|
11850
|
+
vaultA,
|
|
11851
|
+
vaultB,
|
|
11852
|
+
poolAddress,
|
|
11853
|
+
remainingAccounts,
|
|
11854
|
+
{ ...args }
|
|
11855
|
+
);
|
|
11856
|
+
instructions.push(ix);
|
|
11857
|
+
if (createUserAtaAInstructions) cleanupInstructions.push(...createUserAtaAInstructions.cleanup);
|
|
11858
|
+
if (createUserAtaBInstructions) cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
11859
|
+
return instructions;
|
|
11860
|
+
}
|
|
11861
|
+
async function modifyTunaSpotPositionJupiterInstruction(authority, tunaConfig, mintA, mintB, vaultA, vaultB, poolAddress, remainingAccounts, args) {
|
|
11862
|
+
const marketAddress = (await getMarketAddress(poolAddress))[0];
|
|
11863
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
11864
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda15({
|
|
11865
|
+
owner: authority.address,
|
|
11866
|
+
mint: mintA.address,
|
|
11867
|
+
tokenProgram: mintA.programAddress
|
|
11868
|
+
}))[0];
|
|
11869
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda15({
|
|
11870
|
+
owner: authority.address,
|
|
11871
|
+
mint: mintB.address,
|
|
11872
|
+
tokenProgram: mintB.programAddress
|
|
11873
|
+
}))[0];
|
|
11874
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda15({
|
|
11875
|
+
owner: tunaConfig.data.feeRecipient,
|
|
11876
|
+
mint: mintA.address,
|
|
11877
|
+
tokenProgram: mintA.programAddress
|
|
11878
|
+
}))[0];
|
|
11879
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda15({
|
|
11880
|
+
owner: tunaConfig.data.feeRecipient,
|
|
11881
|
+
mint: mintB.address,
|
|
11882
|
+
tokenProgram: mintB.programAddress
|
|
11883
|
+
}))[0];
|
|
11884
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda15({
|
|
11885
|
+
owner: tunaPositionAddress,
|
|
11886
|
+
mint: mintA.address,
|
|
11887
|
+
tokenProgram: mintA.programAddress
|
|
11888
|
+
}))[0];
|
|
11889
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda15({
|
|
11890
|
+
owner: tunaPositionAddress,
|
|
11891
|
+
mint: mintB.address,
|
|
11892
|
+
tokenProgram: mintB.programAddress
|
|
11893
|
+
}))[0];
|
|
11894
|
+
const vaultAAta = (await findAssociatedTokenPda15({
|
|
11895
|
+
owner: vaultA.address,
|
|
11896
|
+
mint: mintA.address,
|
|
11897
|
+
tokenProgram: mintA.programAddress
|
|
11898
|
+
}))[0];
|
|
11899
|
+
const vaultBAta = (await findAssociatedTokenPda15({
|
|
11900
|
+
owner: vaultB.address,
|
|
11901
|
+
mint: mintB.address,
|
|
11902
|
+
tokenProgram: mintB.programAddress
|
|
11903
|
+
}))[0];
|
|
11904
|
+
const ix = getModifyTunaSpotPositionJupiterInstruction({
|
|
11905
|
+
authority,
|
|
11906
|
+
tunaConfig: tunaConfig.address,
|
|
11907
|
+
mintA: mintA.address,
|
|
11908
|
+
mintB: mintB.address,
|
|
11909
|
+
tokenProgramA: mintA.programAddress,
|
|
11910
|
+
tokenProgramB: mintB.programAddress,
|
|
11911
|
+
market: marketAddress,
|
|
11912
|
+
pythOraclePriceFeedA: vaultA.data.pythOraclePriceUpdate,
|
|
11913
|
+
pythOraclePriceFeedB: vaultB.data.pythOraclePriceUpdate,
|
|
11914
|
+
vaultA: vaultA.address,
|
|
11915
|
+
vaultAAta,
|
|
11916
|
+
vaultB: vaultB.address,
|
|
11917
|
+
vaultBAta,
|
|
11918
|
+
tunaPosition: tunaPositionAddress,
|
|
11919
|
+
tunaPositionAtaA,
|
|
11920
|
+
tunaPositionAtaB,
|
|
11921
|
+
tunaPositionOwnerAtaA,
|
|
11922
|
+
tunaPositionOwnerAtaB,
|
|
11923
|
+
feeRecipientAtaA,
|
|
11924
|
+
feeRecipientAtaB,
|
|
11925
|
+
pool: poolAddress,
|
|
11926
|
+
jupiterProgram: JUPITER_PROGRAM_ADDRESS,
|
|
11927
|
+
jupiterEventAuthority: JUPITER_EVENT_AUTHORITY,
|
|
11928
|
+
jupiterProgramAuthority: JUPITER_PROGRAM_AUTHORITY,
|
|
11929
|
+
memoProgram: MEMO_PROGRAM_ADDRESS10,
|
|
11930
|
+
...args
|
|
11931
|
+
});
|
|
11932
|
+
ix.accounts.push(...remainingAccounts);
|
|
11933
|
+
return ix;
|
|
11934
|
+
}
|
|
11935
|
+
|
|
11936
|
+
// src/txbuilder/closeTunaSpotPosition.ts
|
|
11937
|
+
import { fetchAllMaybeMint as fetchAllMaybeMint14, findAssociatedTokenPda as findAssociatedTokenPda16 } from "@solana-program/token-2022";
|
|
11938
|
+
import assert14 from "assert";
|
|
11155
11939
|
async function closeTunaSpotPositionInstructions(rpc, authority, poolAddress) {
|
|
11156
11940
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
11157
11941
|
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
11158
11942
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
11159
|
-
const [mintA, mintB] = await
|
|
11160
|
-
|
|
11161
|
-
|
|
11943
|
+
const [mintA, mintB] = await fetchAllMaybeMint14(rpc, [tunaPosition.data.mintA, tunaPosition.data.mintB]);
|
|
11944
|
+
assert14(mintA.exists, "Token A account not found");
|
|
11945
|
+
assert14(mintB.exists, "Token B account not found");
|
|
11162
11946
|
const ix = await closeTunaSpotPositionInstruction(authority, poolAddress, mintA, mintB);
|
|
11163
11947
|
return [ix];
|
|
11164
11948
|
}
|
|
11165
11949
|
async function closeTunaSpotPositionInstruction(authority, poolAddress, mintA, mintB) {
|
|
11166
11950
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
11167
|
-
const tunaPositionAtaA = (await
|
|
11951
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda16({
|
|
11168
11952
|
owner: tunaPositionAddress,
|
|
11169
11953
|
mint: mintA.address,
|
|
11170
11954
|
tokenProgram: mintA.programAddress
|
|
11171
11955
|
}))[0];
|
|
11172
|
-
const tunaPositionAtaB = (await
|
|
11956
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda16({
|
|
11173
11957
|
owner: tunaPositionAddress,
|
|
11174
11958
|
mint: mintB.address,
|
|
11175
11959
|
tokenProgram: mintB.programAddress
|
|
@@ -11213,11 +11997,11 @@ async function createTunaConfigInstruction(authority, ownerAuthority, adminAutho
|
|
|
11213
11997
|
}
|
|
11214
11998
|
|
|
11215
11999
|
// src/txbuilder/createVault.ts
|
|
11216
|
-
import { findAssociatedTokenPda as
|
|
12000
|
+
import { findAssociatedTokenPda as findAssociatedTokenPda17 } from "@solana-program/token-2022";
|
|
11217
12001
|
async function createVaultInstructions(authority, mint, args) {
|
|
11218
12002
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
11219
12003
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
11220
|
-
const vaultAta = (await
|
|
12004
|
+
const vaultAta = (await findAssociatedTokenPda17({
|
|
11221
12005
|
owner: vault,
|
|
11222
12006
|
mint: mint.address,
|
|
11223
12007
|
tokenProgram: mint.programAddress
|
|
@@ -11238,9 +12022,9 @@ async function createVaultInstructions(authority, mint, args) {
|
|
|
11238
12022
|
|
|
11239
12023
|
// src/txbuilder/liquidateTunaLpPositionOrca.ts
|
|
11240
12024
|
import { getOracleAddress as getOracleAddress4, getPositionAddress as getPositionAddress11, WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS7 } from "@orca-so/whirlpools-client";
|
|
11241
|
-
import { AccountRole as
|
|
11242
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
11243
|
-
import { findAssociatedTokenPda as
|
|
12025
|
+
import { AccountRole as AccountRole11 } from "@solana/kit";
|
|
12026
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS11 } from "@solana-program/memo";
|
|
12027
|
+
import { findAssociatedTokenPda as findAssociatedTokenPda18, TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS11 } from "@solana-program/token-2022";
|
|
11244
12028
|
async function liquidateTunaLpPositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11245
12029
|
const instructions = [];
|
|
11246
12030
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
@@ -11280,37 +12064,37 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11280
12064
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11281
12065
|
const orcaPositionAddress = (await getPositionAddress11(positionMint))[0];
|
|
11282
12066
|
const orcaOracleAddress = (await getOracleAddress4(whirlpool.address))[0];
|
|
11283
|
-
const tunaPositionAta = (await
|
|
12067
|
+
const tunaPositionAta = (await findAssociatedTokenPda18({
|
|
11284
12068
|
owner: tunaPosition.address,
|
|
11285
12069
|
mint: positionMint,
|
|
11286
12070
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS11
|
|
11287
12071
|
}))[0];
|
|
11288
|
-
const tunaPositionAtaA = (await
|
|
12072
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda18({
|
|
11289
12073
|
owner: tunaPosition.address,
|
|
11290
12074
|
mint: mintA.address,
|
|
11291
12075
|
tokenProgram: mintA.programAddress
|
|
11292
12076
|
}))[0];
|
|
11293
|
-
const tunaPositionAtaB = (await
|
|
12077
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda18({
|
|
11294
12078
|
owner: tunaPosition.address,
|
|
11295
12079
|
mint: mintB.address,
|
|
11296
12080
|
tokenProgram: mintB.programAddress
|
|
11297
12081
|
}))[0];
|
|
11298
|
-
const vaultAAta = (await
|
|
12082
|
+
const vaultAAta = (await findAssociatedTokenPda18({
|
|
11299
12083
|
owner: vaultA.address,
|
|
11300
12084
|
mint: mintA.address,
|
|
11301
12085
|
tokenProgram: mintA.programAddress
|
|
11302
12086
|
}))[0];
|
|
11303
|
-
const vaultBAta = (await
|
|
12087
|
+
const vaultBAta = (await findAssociatedTokenPda18({
|
|
11304
12088
|
owner: vaultB.address,
|
|
11305
12089
|
mint: mintB.address,
|
|
11306
12090
|
tokenProgram: mintB.programAddress
|
|
11307
12091
|
}))[0];
|
|
11308
|
-
const feeRecipientAtaA = (await
|
|
12092
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda18({
|
|
11309
12093
|
owner: tunaConfig.data.feeRecipient,
|
|
11310
12094
|
mint: mintA.address,
|
|
11311
12095
|
tokenProgram: mintA.programAddress
|
|
11312
12096
|
}))[0];
|
|
11313
|
-
const feeRecipientAtaB = (await
|
|
12097
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda18({
|
|
11314
12098
|
owner: tunaConfig.data.feeRecipient,
|
|
11315
12099
|
mint: mintB.address,
|
|
11316
12100
|
tokenProgram: mintB.programAddress
|
|
@@ -11325,16 +12109,16 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11325
12109
|
tunaPosition.data.tickUpperIndex
|
|
11326
12110
|
);
|
|
11327
12111
|
const remainingAccounts = [
|
|
11328
|
-
{ address: swapTickArrays[0], role:
|
|
11329
|
-
{ address: swapTickArrays[1], role:
|
|
11330
|
-
{ address: swapTickArrays[2], role:
|
|
11331
|
-
{ address: swapTickArrays[3], role:
|
|
11332
|
-
{ address: swapTickArrays[4], role:
|
|
11333
|
-
{ address: lowerTickArrayAddress, role:
|
|
11334
|
-
{ address: upperTickArrayAddress, role:
|
|
11335
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
11336
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
11337
|
-
{ address: orcaOracleAddress, role:
|
|
12112
|
+
{ address: swapTickArrays[0], role: AccountRole11.WRITABLE },
|
|
12113
|
+
{ address: swapTickArrays[1], role: AccountRole11.WRITABLE },
|
|
12114
|
+
{ address: swapTickArrays[2], role: AccountRole11.WRITABLE },
|
|
12115
|
+
{ address: swapTickArrays[3], role: AccountRole11.WRITABLE },
|
|
12116
|
+
{ address: swapTickArrays[4], role: AccountRole11.WRITABLE },
|
|
12117
|
+
{ address: lowerTickArrayAddress, role: AccountRole11.WRITABLE },
|
|
12118
|
+
{ address: upperTickArrayAddress, role: AccountRole11.WRITABLE },
|
|
12119
|
+
{ address: whirlpool.data.tokenVaultA, role: AccountRole11.WRITABLE },
|
|
12120
|
+
{ address: whirlpool.data.tokenVaultB, role: AccountRole11.WRITABLE },
|
|
12121
|
+
{ address: orcaOracleAddress, role: AccountRole11.WRITABLE }
|
|
11338
12122
|
];
|
|
11339
12123
|
const remainingAccountsInfo = {
|
|
11340
12124
|
slices: [
|
|
@@ -11369,7 +12153,7 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11369
12153
|
whirlpoolProgram: WHIRLPOOL_PROGRAM_ADDRESS7,
|
|
11370
12154
|
tokenProgramA: mintA.programAddress,
|
|
11371
12155
|
tokenProgramB: mintB.programAddress,
|
|
11372
|
-
memoProgram:
|
|
12156
|
+
memoProgram: MEMO_PROGRAM_ADDRESS11,
|
|
11373
12157
|
decreasePercent,
|
|
11374
12158
|
remainingAccountsInfo
|
|
11375
12159
|
});
|
|
@@ -11379,9 +12163,9 @@ async function liquidateTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
11379
12163
|
|
|
11380
12164
|
// src/txbuilder/liquidateTunaLpPositionFusion.ts
|
|
11381
12165
|
import { FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS7, getPositionAddress as getPositionAddress12 } from "@crypticdot/fusionamm-client";
|
|
11382
|
-
import { AccountRole as
|
|
11383
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
11384
|
-
import { findAssociatedTokenPda as
|
|
12166
|
+
import { AccountRole as AccountRole12 } from "@solana/kit";
|
|
12167
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS12 } from "@solana-program/memo";
|
|
12168
|
+
import { findAssociatedTokenPda as findAssociatedTokenPda19, TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS12 } from "@solana-program/token-2022";
|
|
11385
12169
|
async function liquidateTunaLpPositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11386
12170
|
const instructions = [];
|
|
11387
12171
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
@@ -11420,37 +12204,37 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11420
12204
|
const positionMint = tunaPosition.data.positionMint;
|
|
11421
12205
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11422
12206
|
const fusionPositionAddress = (await getPositionAddress12(positionMint))[0];
|
|
11423
|
-
const tunaPositionAta = (await
|
|
12207
|
+
const tunaPositionAta = (await findAssociatedTokenPda19({
|
|
11424
12208
|
owner: tunaPosition.address,
|
|
11425
12209
|
mint: positionMint,
|
|
11426
12210
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS12
|
|
11427
12211
|
}))[0];
|
|
11428
|
-
const tunaPositionAtaA = (await
|
|
12212
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda19({
|
|
11429
12213
|
owner: tunaPosition.address,
|
|
11430
12214
|
mint: mintA.address,
|
|
11431
12215
|
tokenProgram: mintA.programAddress
|
|
11432
12216
|
}))[0];
|
|
11433
|
-
const tunaPositionAtaB = (await
|
|
12217
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda19({
|
|
11434
12218
|
owner: tunaPosition.address,
|
|
11435
12219
|
mint: mintB.address,
|
|
11436
12220
|
tokenProgram: mintB.programAddress
|
|
11437
12221
|
}))[0];
|
|
11438
|
-
const vaultAAta = (await
|
|
12222
|
+
const vaultAAta = (await findAssociatedTokenPda19({
|
|
11439
12223
|
owner: vaultA.address,
|
|
11440
12224
|
mint: mintA.address,
|
|
11441
12225
|
tokenProgram: mintA.programAddress
|
|
11442
12226
|
}))[0];
|
|
11443
|
-
const vaultBAta = (await
|
|
12227
|
+
const vaultBAta = (await findAssociatedTokenPda19({
|
|
11444
12228
|
owner: vaultB.address,
|
|
11445
12229
|
mint: mintB.address,
|
|
11446
12230
|
tokenProgram: mintB.programAddress
|
|
11447
12231
|
}))[0];
|
|
11448
|
-
const feeRecipientAtaA = (await
|
|
12232
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda19({
|
|
11449
12233
|
owner: tunaConfig.data.feeRecipient,
|
|
11450
12234
|
mint: mintA.address,
|
|
11451
12235
|
tokenProgram: mintA.programAddress
|
|
11452
12236
|
}))[0];
|
|
11453
|
-
const feeRecipientAtaB = (await
|
|
12237
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda19({
|
|
11454
12238
|
owner: tunaConfig.data.feeRecipient,
|
|
11455
12239
|
mint: mintB.address,
|
|
11456
12240
|
tokenProgram: mintB.programAddress
|
|
@@ -11465,15 +12249,15 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11465
12249
|
tunaPosition.data.tickUpperIndex
|
|
11466
12250
|
);
|
|
11467
12251
|
const remainingAccounts = [
|
|
11468
|
-
{ address: swapTickArrays[0], role:
|
|
11469
|
-
{ address: swapTickArrays[1], role:
|
|
11470
|
-
{ address: swapTickArrays[2], role:
|
|
11471
|
-
{ address: swapTickArrays[3], role:
|
|
11472
|
-
{ address: swapTickArrays[4], role:
|
|
11473
|
-
{ address: lowerTickArrayAddress, role:
|
|
11474
|
-
{ address: upperTickArrayAddress, role:
|
|
11475
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
11476
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
12252
|
+
{ address: swapTickArrays[0], role: AccountRole12.WRITABLE },
|
|
12253
|
+
{ address: swapTickArrays[1], role: AccountRole12.WRITABLE },
|
|
12254
|
+
{ address: swapTickArrays[2], role: AccountRole12.WRITABLE },
|
|
12255
|
+
{ address: swapTickArrays[3], role: AccountRole12.WRITABLE },
|
|
12256
|
+
{ address: swapTickArrays[4], role: AccountRole12.WRITABLE },
|
|
12257
|
+
{ address: lowerTickArrayAddress, role: AccountRole12.WRITABLE },
|
|
12258
|
+
{ address: upperTickArrayAddress, role: AccountRole12.WRITABLE },
|
|
12259
|
+
{ address: fusionPool.data.tokenVaultA, role: AccountRole12.WRITABLE },
|
|
12260
|
+
{ address: fusionPool.data.tokenVaultB, role: AccountRole12.WRITABLE }
|
|
11477
12261
|
];
|
|
11478
12262
|
const remainingAccountsInfo = {
|
|
11479
12263
|
slices: [
|
|
@@ -11507,7 +12291,7 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11507
12291
|
fusionammProgram: FUSIONAMM_PROGRAM_ADDRESS7,
|
|
11508
12292
|
tokenProgramA: mintA.programAddress,
|
|
11509
12293
|
tokenProgramB: mintB.programAddress,
|
|
11510
|
-
memoProgram:
|
|
12294
|
+
memoProgram: MEMO_PROGRAM_ADDRESS12,
|
|
11511
12295
|
decreasePercent,
|
|
11512
12296
|
remainingAccountsInfo
|
|
11513
12297
|
});
|
|
@@ -11517,9 +12301,9 @@ async function liquidateTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
11517
12301
|
|
|
11518
12302
|
// src/txbuilder/liquidateTunaSpotPositionFusion.ts
|
|
11519
12303
|
import { FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS8 } from "@crypticdot/fusionamm-client";
|
|
11520
|
-
import { AccountRole as
|
|
11521
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
11522
|
-
import { findAssociatedTokenPda as
|
|
12304
|
+
import { AccountRole as AccountRole13 } from "@solana/kit";
|
|
12305
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS13 } from "@solana-program/memo";
|
|
12306
|
+
import { findAssociatedTokenPda as findAssociatedTokenPda20 } from "@solana-program/token-2022";
|
|
11523
12307
|
async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, createTunaPositionOwnerAta, decreasePercent) {
|
|
11524
12308
|
const instructions = [];
|
|
11525
12309
|
if (createTunaPositionOwnerAta) {
|
|
@@ -11567,55 +12351,55 @@ async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPositi
|
|
|
11567
12351
|
}
|
|
11568
12352
|
async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, decreasePercent) {
|
|
11569
12353
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11570
|
-
const tunaPositionOwnerAtaA = (await
|
|
12354
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda20({
|
|
11571
12355
|
owner: tunaPosition.data.authority,
|
|
11572
12356
|
mint: mintA.address,
|
|
11573
12357
|
tokenProgram: mintA.programAddress
|
|
11574
12358
|
}))[0];
|
|
11575
|
-
const tunaPositionOwnerAtaB = (await
|
|
12359
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda20({
|
|
11576
12360
|
owner: tunaPosition.data.authority,
|
|
11577
12361
|
mint: mintB.address,
|
|
11578
12362
|
tokenProgram: mintB.programAddress
|
|
11579
12363
|
}))[0];
|
|
11580
|
-
const tunaPositionAtaA = (await
|
|
12364
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda20({
|
|
11581
12365
|
owner: tunaPosition.address,
|
|
11582
12366
|
mint: mintA.address,
|
|
11583
12367
|
tokenProgram: mintA.programAddress
|
|
11584
12368
|
}))[0];
|
|
11585
|
-
const tunaPositionAtaB = (await
|
|
12369
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda20({
|
|
11586
12370
|
owner: tunaPosition.address,
|
|
11587
12371
|
mint: mintB.address,
|
|
11588
12372
|
tokenProgram: mintB.programAddress
|
|
11589
12373
|
}))[0];
|
|
11590
|
-
const feeRecipientAtaA = (await
|
|
12374
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda20({
|
|
11591
12375
|
owner: tunaConfig.data.feeRecipient,
|
|
11592
12376
|
mint: mintA.address,
|
|
11593
12377
|
tokenProgram: mintA.programAddress
|
|
11594
12378
|
}))[0];
|
|
11595
|
-
const feeRecipientAtaB = (await
|
|
12379
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda20({
|
|
11596
12380
|
owner: tunaConfig.data.feeRecipient,
|
|
11597
12381
|
mint: mintB.address,
|
|
11598
12382
|
tokenProgram: mintB.programAddress
|
|
11599
12383
|
}))[0];
|
|
11600
|
-
const vaultAAta = (await
|
|
12384
|
+
const vaultAAta = (await findAssociatedTokenPda20({
|
|
11601
12385
|
owner: vaultA.address,
|
|
11602
12386
|
mint: mintA.address,
|
|
11603
12387
|
tokenProgram: mintA.programAddress
|
|
11604
12388
|
}))[0];
|
|
11605
|
-
const vaultBAta = (await
|
|
12389
|
+
const vaultBAta = (await findAssociatedTokenPda20({
|
|
11606
12390
|
owner: vaultB.address,
|
|
11607
12391
|
mint: mintB.address,
|
|
11608
12392
|
tokenProgram: mintB.programAddress
|
|
11609
12393
|
}))[0];
|
|
11610
12394
|
const swapTickArrays = await FusionUtils.getSwapTickArrayAddresses(fusionPool);
|
|
11611
12395
|
const remainingAccounts = [
|
|
11612
|
-
{ address: swapTickArrays[0], role:
|
|
11613
|
-
{ address: swapTickArrays[1], role:
|
|
11614
|
-
{ address: swapTickArrays[2], role:
|
|
11615
|
-
{ address: swapTickArrays[3], role:
|
|
11616
|
-
{ address: swapTickArrays[4], role:
|
|
11617
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
11618
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
12396
|
+
{ address: swapTickArrays[0], role: AccountRole13.WRITABLE },
|
|
12397
|
+
{ address: swapTickArrays[1], role: AccountRole13.WRITABLE },
|
|
12398
|
+
{ address: swapTickArrays[2], role: AccountRole13.WRITABLE },
|
|
12399
|
+
{ address: swapTickArrays[3], role: AccountRole13.WRITABLE },
|
|
12400
|
+
{ address: swapTickArrays[4], role: AccountRole13.WRITABLE },
|
|
12401
|
+
{ address: fusionPool.data.tokenVaultA, role: AccountRole13.WRITABLE },
|
|
12402
|
+
{ address: fusionPool.data.tokenVaultB, role: AccountRole13.WRITABLE }
|
|
11619
12403
|
];
|
|
11620
12404
|
const remainingAccountsInfo = {
|
|
11621
12405
|
slices: [
|
|
@@ -11648,7 +12432,7 @@ async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPositio
|
|
|
11648
12432
|
feeRecipientAtaB,
|
|
11649
12433
|
fusionPool: fusionPool.address,
|
|
11650
12434
|
fusionammProgram: FUSIONAMM_PROGRAM_ADDRESS8,
|
|
11651
|
-
memoProgram:
|
|
12435
|
+
memoProgram: MEMO_PROGRAM_ADDRESS13,
|
|
11652
12436
|
decreasePercent,
|
|
11653
12437
|
remainingAccountsInfo
|
|
11654
12438
|
});
|
|
@@ -11658,9 +12442,9 @@ async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPositio
|
|
|
11658
12442
|
|
|
11659
12443
|
// src/txbuilder/liquidateTunaSpotPositionOrca.ts
|
|
11660
12444
|
import { getOracleAddress as getOracleAddress5, WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS8 } from "@orca-so/whirlpools-client";
|
|
11661
|
-
import { AccountRole as
|
|
11662
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
11663
|
-
import { findAssociatedTokenPda as
|
|
12445
|
+
import { AccountRole as AccountRole14 } from "@solana/kit";
|
|
12446
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS14 } from "@solana-program/memo";
|
|
12447
|
+
import { findAssociatedTokenPda as findAssociatedTokenPda21 } from "@solana-program/token-2022";
|
|
11664
12448
|
async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, createTunaPositionOwnerAta, decreasePercent) {
|
|
11665
12449
|
const instructions = [];
|
|
11666
12450
|
if (createTunaPositionOwnerAta) {
|
|
@@ -11709,56 +12493,56 @@ async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition
|
|
|
11709
12493
|
async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, decreasePercent) {
|
|
11710
12494
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11711
12495
|
const orcaOracleAddress = (await getOracleAddress5(whirlpool.address))[0];
|
|
11712
|
-
const tunaPositionOwnerAtaA = (await
|
|
12496
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda21({
|
|
11713
12497
|
owner: tunaPosition.data.authority,
|
|
11714
12498
|
mint: mintA.address,
|
|
11715
12499
|
tokenProgram: mintA.programAddress
|
|
11716
12500
|
}))[0];
|
|
11717
|
-
const tunaPositionOwnerAtaB = (await
|
|
12501
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda21({
|
|
11718
12502
|
owner: tunaPosition.data.authority,
|
|
11719
12503
|
mint: mintB.address,
|
|
11720
12504
|
tokenProgram: mintB.programAddress
|
|
11721
12505
|
}))[0];
|
|
11722
|
-
const tunaPositionAtaA = (await
|
|
12506
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda21({
|
|
11723
12507
|
owner: tunaPosition.address,
|
|
11724
12508
|
mint: mintA.address,
|
|
11725
12509
|
tokenProgram: mintA.programAddress
|
|
11726
12510
|
}))[0];
|
|
11727
|
-
const tunaPositionAtaB = (await
|
|
12511
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda21({
|
|
11728
12512
|
owner: tunaPosition.address,
|
|
11729
12513
|
mint: mintB.address,
|
|
11730
12514
|
tokenProgram: mintB.programAddress
|
|
11731
12515
|
}))[0];
|
|
11732
|
-
const feeRecipientAtaA = (await
|
|
12516
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda21({
|
|
11733
12517
|
owner: tunaConfig.data.feeRecipient,
|
|
11734
12518
|
mint: mintA.address,
|
|
11735
12519
|
tokenProgram: mintA.programAddress
|
|
11736
12520
|
}))[0];
|
|
11737
|
-
const feeRecipientAtaB = (await
|
|
12521
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda21({
|
|
11738
12522
|
owner: tunaConfig.data.feeRecipient,
|
|
11739
12523
|
mint: mintB.address,
|
|
11740
12524
|
tokenProgram: mintB.programAddress
|
|
11741
12525
|
}))[0];
|
|
11742
|
-
const vaultAAta = (await
|
|
12526
|
+
const vaultAAta = (await findAssociatedTokenPda21({
|
|
11743
12527
|
owner: vaultA.address,
|
|
11744
12528
|
mint: mintA.address,
|
|
11745
12529
|
tokenProgram: mintA.programAddress
|
|
11746
12530
|
}))[0];
|
|
11747
|
-
const vaultBAta = (await
|
|
12531
|
+
const vaultBAta = (await findAssociatedTokenPda21({
|
|
11748
12532
|
owner: vaultB.address,
|
|
11749
12533
|
mint: mintB.address,
|
|
11750
12534
|
tokenProgram: mintB.programAddress
|
|
11751
12535
|
}))[0];
|
|
11752
12536
|
const swapTickArrays = await OrcaUtils.getSwapTickArrayAddresses(whirlpool);
|
|
11753
12537
|
const remainingAccounts = [
|
|
11754
|
-
{ address: swapTickArrays[0], role:
|
|
11755
|
-
{ address: swapTickArrays[1], role:
|
|
11756
|
-
{ address: swapTickArrays[2], role:
|
|
11757
|
-
{ address: swapTickArrays[3], role:
|
|
11758
|
-
{ address: swapTickArrays[4], role:
|
|
11759
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
11760
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
11761
|
-
{ address: orcaOracleAddress, role:
|
|
12538
|
+
{ address: swapTickArrays[0], role: AccountRole14.WRITABLE },
|
|
12539
|
+
{ address: swapTickArrays[1], role: AccountRole14.WRITABLE },
|
|
12540
|
+
{ address: swapTickArrays[2], role: AccountRole14.WRITABLE },
|
|
12541
|
+
{ address: swapTickArrays[3], role: AccountRole14.WRITABLE },
|
|
12542
|
+
{ address: swapTickArrays[4], role: AccountRole14.WRITABLE },
|
|
12543
|
+
{ address: whirlpool.data.tokenVaultA, role: AccountRole14.WRITABLE },
|
|
12544
|
+
{ address: whirlpool.data.tokenVaultB, role: AccountRole14.WRITABLE },
|
|
12545
|
+
{ address: orcaOracleAddress, role: AccountRole14.WRITABLE }
|
|
11762
12546
|
];
|
|
11763
12547
|
const remainingAccountsInfo = {
|
|
11764
12548
|
slices: [
|
|
@@ -11792,7 +12576,7 @@ async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition,
|
|
|
11792
12576
|
feeRecipientAtaB,
|
|
11793
12577
|
whirlpool: whirlpool.address,
|
|
11794
12578
|
whirlpoolProgram: WHIRLPOOL_PROGRAM_ADDRESS8,
|
|
11795
|
-
memoProgram:
|
|
12579
|
+
memoProgram: MEMO_PROGRAM_ADDRESS14,
|
|
11796
12580
|
decreasePercent,
|
|
11797
12581
|
remainingAccountsInfo
|
|
11798
12582
|
});
|
|
@@ -11804,31 +12588,31 @@ async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition,
|
|
|
11804
12588
|
import { fetchMaybeWhirlpool as fetchMaybeWhirlpool6, getPositionAddress as getPositionAddress13, WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS9 } from "@orca-so/whirlpools-client";
|
|
11805
12589
|
import {
|
|
11806
12590
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
|
|
11807
|
-
fetchAllMaybeMint as
|
|
11808
|
-
findAssociatedTokenPda as
|
|
12591
|
+
fetchAllMaybeMint as fetchAllMaybeMint15,
|
|
12592
|
+
findAssociatedTokenPda as findAssociatedTokenPda22,
|
|
11809
12593
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS13
|
|
11810
12594
|
} from "@solana-program/token-2022";
|
|
11811
|
-
import
|
|
12595
|
+
import assert15 from "assert";
|
|
11812
12596
|
async function openTunaLpPositionOrcaInstruction(rpc, authority, positionMint, whirlpoolAddress, args) {
|
|
11813
12597
|
const whirlpool = await fetchMaybeWhirlpool6(rpc, whirlpoolAddress);
|
|
11814
12598
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
11815
|
-
const [mintA, mintB] = await
|
|
11816
|
-
|
|
11817
|
-
|
|
12599
|
+
const [mintA, mintB] = await fetchAllMaybeMint15(rpc, [whirlpool.data.tokenMintA, whirlpool.data.tokenMintB]);
|
|
12600
|
+
assert15(mintA.exists, "Token A account not found");
|
|
12601
|
+
assert15(mintB.exists, "Token B account not found");
|
|
11818
12602
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11819
12603
|
const orcaPositionAddress = (await getPositionAddress13(positionMint.address))[0];
|
|
11820
12604
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
11821
|
-
const tunaPositionAta = (await
|
|
12605
|
+
const tunaPositionAta = (await findAssociatedTokenPda22({
|
|
11822
12606
|
owner: tunaPositionAddress,
|
|
11823
12607
|
mint: positionMint.address,
|
|
11824
12608
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS13
|
|
11825
12609
|
}))[0];
|
|
11826
|
-
const tunaPositionAtaA = (await
|
|
12610
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda22({
|
|
11827
12611
|
owner: tunaPositionAddress,
|
|
11828
12612
|
mint: mintA.address,
|
|
11829
12613
|
tokenProgram: mintA.programAddress
|
|
11830
12614
|
}))[0];
|
|
11831
|
-
const tunaPositionAtaB = (await
|
|
12615
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda22({
|
|
11832
12616
|
owner: tunaPositionAddress,
|
|
11833
12617
|
mint: mintB.address,
|
|
11834
12618
|
tokenProgram: mintB.programAddress
|
|
@@ -11860,31 +12644,31 @@ import { fetchMaybeFusionPool as fetchMaybeFusionPool6, FUSIONAMM_PROGRAM_ADDRES
|
|
|
11860
12644
|
import { FP_NFT_UPDATE_AUTH } from "@crypticdot/fusionamm-client";
|
|
11861
12645
|
import {
|
|
11862
12646
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS2,
|
|
11863
|
-
fetchAllMaybeMint as
|
|
11864
|
-
findAssociatedTokenPda as
|
|
12647
|
+
fetchAllMaybeMint as fetchAllMaybeMint16,
|
|
12648
|
+
findAssociatedTokenPda as findAssociatedTokenPda23,
|
|
11865
12649
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS14
|
|
11866
12650
|
} from "@solana-program/token-2022";
|
|
11867
|
-
import
|
|
12651
|
+
import assert16 from "assert";
|
|
11868
12652
|
async function openTunaLpPositionFusionInstruction(rpc, authority, positionMint, fusionPoolAddress, args) {
|
|
11869
12653
|
const fusionPool = await fetchMaybeFusionPool6(rpc, fusionPoolAddress);
|
|
11870
|
-
if (!fusionPool.exists) throw new Error("Whirlpool account not found");
|
|
11871
|
-
const [mintA, mintB] = await
|
|
11872
|
-
|
|
11873
|
-
|
|
12654
|
+
if (!fusionPool.exists) throw new Error("Whirlpool account not found");
|
|
12655
|
+
const [mintA, mintB] = await fetchAllMaybeMint16(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
12656
|
+
assert16(mintA.exists, "Token A account not found");
|
|
12657
|
+
assert16(mintB.exists, "Token B account not found");
|
|
11874
12658
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11875
12659
|
const fusionPositionAddress = (await getPositionAddress14(positionMint.address))[0];
|
|
11876
12660
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
11877
|
-
const tunaPositionAta = (await
|
|
12661
|
+
const tunaPositionAta = (await findAssociatedTokenPda23({
|
|
11878
12662
|
owner: tunaPositionAddress,
|
|
11879
12663
|
mint: positionMint.address,
|
|
11880
12664
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS14
|
|
11881
12665
|
}))[0];
|
|
11882
|
-
const tunaPositionAtaA = (await
|
|
12666
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda23({
|
|
11883
12667
|
owner: tunaPositionAddress,
|
|
11884
12668
|
mint: mintA.address,
|
|
11885
12669
|
tokenProgram: mintA.programAddress
|
|
11886
12670
|
}))[0];
|
|
11887
|
-
const tunaPositionAtaB = (await
|
|
12671
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda23({
|
|
11888
12672
|
owner: tunaPositionAddress,
|
|
11889
12673
|
mint: mintB.address,
|
|
11890
12674
|
tokenProgram: mintB.programAddress
|
|
@@ -11924,19 +12708,19 @@ import {
|
|
|
11924
12708
|
} from "@orca-so/whirlpools-client";
|
|
11925
12709
|
import { getTickArrayStartTickIndex as getTickArrayStartTickIndex6 } from "@orca-so/whirlpools-core";
|
|
11926
12710
|
import {
|
|
11927
|
-
AccountRole as
|
|
12711
|
+
AccountRole as AccountRole15,
|
|
11928
12712
|
generateKeyPairSigner,
|
|
11929
12713
|
lamports
|
|
11930
12714
|
} from "@solana/kit";
|
|
11931
12715
|
import { fetchSysvarRent } from "@solana/sysvars";
|
|
11932
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
12716
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS15 } from "@solana-program/memo";
|
|
11933
12717
|
import {
|
|
11934
12718
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS3,
|
|
11935
|
-
fetchAllMaybeMint as
|
|
11936
|
-
findAssociatedTokenPda as
|
|
12719
|
+
fetchAllMaybeMint as fetchAllMaybeMint17,
|
|
12720
|
+
findAssociatedTokenPda as findAssociatedTokenPda24,
|
|
11937
12721
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS15
|
|
11938
12722
|
} from "@solana-program/token-2022";
|
|
11939
|
-
import
|
|
12723
|
+
import assert17 from "assert";
|
|
11940
12724
|
|
|
11941
12725
|
// src/utils/sysvar.ts
|
|
11942
12726
|
var ACCOUNT_STORAGE_OVERHEAD = 128;
|
|
@@ -11960,9 +12744,9 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
11960
12744
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
11961
12745
|
const marketAddress = (await getMarketAddress(whirlpoolAddress))[0];
|
|
11962
12746
|
const market = await fetchMarket(rpc, marketAddress);
|
|
11963
|
-
const [mintA, mintB] = await
|
|
11964
|
-
|
|
11965
|
-
|
|
12747
|
+
const [mintA, mintB] = await fetchAllMaybeMint17(rpc, [whirlpool.data.tokenMintA, whirlpool.data.tokenMintB]);
|
|
12748
|
+
assert17(mintA.exists, "Token A account not found");
|
|
12749
|
+
assert17(mintB.exists, "Token B account not found");
|
|
11966
12750
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
11967
12751
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
11968
12752
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
@@ -12071,47 +12855,47 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
12071
12855
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
12072
12856
|
const orcaPositionAddress = (await getPositionAddress15(positionMint.address))[0];
|
|
12073
12857
|
const orcaOracleAddress = (await getOracleAddress6(whirlpool.address))[0];
|
|
12074
|
-
const tunaPositionAta = (await
|
|
12858
|
+
const tunaPositionAta = (await findAssociatedTokenPda24({
|
|
12075
12859
|
owner: tunaPositionAddress,
|
|
12076
12860
|
mint: positionMint.address,
|
|
12077
12861
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS15
|
|
12078
12862
|
}))[0];
|
|
12079
|
-
const tunaPositionOwnerAtaA = (await
|
|
12863
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda24({
|
|
12080
12864
|
owner: authority.address,
|
|
12081
12865
|
mint: mintA.address,
|
|
12082
12866
|
tokenProgram: mintA.programAddress
|
|
12083
12867
|
}))[0];
|
|
12084
|
-
const tunaPositionOwnerAtaB = (await
|
|
12868
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda24({
|
|
12085
12869
|
owner: authority.address,
|
|
12086
12870
|
mint: mintB.address,
|
|
12087
12871
|
tokenProgram: mintB.programAddress
|
|
12088
12872
|
}))[0];
|
|
12089
|
-
const tunaPositionAtaA = (await
|
|
12873
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda24({
|
|
12090
12874
|
owner: tunaPositionAddress,
|
|
12091
12875
|
mint: mintA.address,
|
|
12092
12876
|
tokenProgram: mintA.programAddress
|
|
12093
12877
|
}))[0];
|
|
12094
|
-
const tunaPositionAtaB = (await
|
|
12878
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda24({
|
|
12095
12879
|
owner: tunaPositionAddress,
|
|
12096
12880
|
mint: mintB.address,
|
|
12097
12881
|
tokenProgram: mintB.programAddress
|
|
12098
12882
|
}))[0];
|
|
12099
|
-
const vaultAAta = (await
|
|
12883
|
+
const vaultAAta = (await findAssociatedTokenPda24({
|
|
12100
12884
|
owner: vaultA.address,
|
|
12101
12885
|
mint: mintA.address,
|
|
12102
12886
|
tokenProgram: mintA.programAddress
|
|
12103
12887
|
}))[0];
|
|
12104
|
-
const vaultBAta = (await
|
|
12888
|
+
const vaultBAta = (await findAssociatedTokenPda24({
|
|
12105
12889
|
owner: vaultB.address,
|
|
12106
12890
|
mint: mintB.address,
|
|
12107
12891
|
tokenProgram: mintB.programAddress
|
|
12108
12892
|
}))[0];
|
|
12109
|
-
const feeRecipientAtaA = (await
|
|
12893
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda24({
|
|
12110
12894
|
owner: tunaConfig.data.feeRecipient,
|
|
12111
12895
|
mint: mintA.address,
|
|
12112
12896
|
tokenProgram: mintA.programAddress
|
|
12113
12897
|
}))[0];
|
|
12114
|
-
const feeRecipientAtaB = (await
|
|
12898
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda24({
|
|
12115
12899
|
owner: tunaConfig.data.feeRecipient,
|
|
12116
12900
|
mint: mintB.address,
|
|
12117
12901
|
tokenProgram: mintB.programAddress
|
|
@@ -12120,16 +12904,16 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
12120
12904
|
const lowerTickArrayAddress = await OrcaUtils.getTickArrayAddressFromTickIndex(whirlpool, args.tickLowerIndex);
|
|
12121
12905
|
const upperTickArrayAddress = await OrcaUtils.getTickArrayAddressFromTickIndex(whirlpool, args.tickUpperIndex);
|
|
12122
12906
|
const remainingAccounts = [
|
|
12123
|
-
{ address: swapTickArrays[0], role:
|
|
12124
|
-
{ address: swapTickArrays[1], role:
|
|
12125
|
-
{ address: swapTickArrays[2], role:
|
|
12126
|
-
{ address: swapTickArrays[3], role:
|
|
12127
|
-
{ address: swapTickArrays[4], role:
|
|
12128
|
-
{ address: lowerTickArrayAddress, role:
|
|
12129
|
-
{ address: upperTickArrayAddress, role:
|
|
12130
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
12131
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
12132
|
-
{ address: orcaOracleAddress, role:
|
|
12907
|
+
{ address: swapTickArrays[0], role: AccountRole15.WRITABLE },
|
|
12908
|
+
{ address: swapTickArrays[1], role: AccountRole15.WRITABLE },
|
|
12909
|
+
{ address: swapTickArrays[2], role: AccountRole15.WRITABLE },
|
|
12910
|
+
{ address: swapTickArrays[3], role: AccountRole15.WRITABLE },
|
|
12911
|
+
{ address: swapTickArrays[4], role: AccountRole15.WRITABLE },
|
|
12912
|
+
{ address: lowerTickArrayAddress, role: AccountRole15.WRITABLE },
|
|
12913
|
+
{ address: upperTickArrayAddress, role: AccountRole15.WRITABLE },
|
|
12914
|
+
{ address: whirlpool.data.tokenVaultA, role: AccountRole15.WRITABLE },
|
|
12915
|
+
{ address: whirlpool.data.tokenVaultB, role: AccountRole15.WRITABLE },
|
|
12916
|
+
{ address: orcaOracleAddress, role: AccountRole15.WRITABLE }
|
|
12133
12917
|
];
|
|
12134
12918
|
const remainingAccountsInfo = {
|
|
12135
12919
|
slices: [
|
|
@@ -12167,7 +12951,7 @@ async function openAndIncreaseTunaLpPositionOrcaInstruction(authority, positionM
|
|
|
12167
12951
|
orcaPosition: orcaPositionAddress,
|
|
12168
12952
|
tokenProgramA: mintA.programAddress,
|
|
12169
12953
|
tokenProgramB: mintB.programAddress,
|
|
12170
|
-
memoProgram:
|
|
12954
|
+
memoProgram: MEMO_PROGRAM_ADDRESS15,
|
|
12171
12955
|
metadataUpdateAuth: WP_NFT_UPDATE_AUTH,
|
|
12172
12956
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ADDRESS3,
|
|
12173
12957
|
token2022Program: TOKEN_2022_PROGRAM_ADDRESS15,
|
|
@@ -12191,19 +12975,19 @@ import {
|
|
|
12191
12975
|
} from "@crypticdot/fusionamm-client";
|
|
12192
12976
|
import { getTickArrayStartTickIndex as getTickArrayStartTickIndex7 } from "@crypticdot/fusionamm-core";
|
|
12193
12977
|
import {
|
|
12194
|
-
AccountRole as
|
|
12978
|
+
AccountRole as AccountRole16,
|
|
12195
12979
|
generateKeyPairSigner as generateKeyPairSigner2,
|
|
12196
12980
|
lamports as lamports2
|
|
12197
12981
|
} from "@solana/kit";
|
|
12198
12982
|
import { fetchSysvarRent as fetchSysvarRent2 } from "@solana/sysvars";
|
|
12199
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
12983
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS16 } from "@solana-program/memo";
|
|
12200
12984
|
import {
|
|
12201
12985
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS4,
|
|
12202
|
-
fetchAllMaybeMint as
|
|
12203
|
-
findAssociatedTokenPda as
|
|
12986
|
+
fetchAllMaybeMint as fetchAllMaybeMint18,
|
|
12987
|
+
findAssociatedTokenPda as findAssociatedTokenPda25,
|
|
12204
12988
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS16
|
|
12205
12989
|
} from "@solana-program/token-2022";
|
|
12206
|
-
import
|
|
12990
|
+
import assert18 from "assert";
|
|
12207
12991
|
async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
12208
12992
|
const instructions = [];
|
|
12209
12993
|
if (!createInstructions) createInstructions = instructions;
|
|
@@ -12216,9 +13000,9 @@ async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, f
|
|
|
12216
13000
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
12217
13001
|
const marketAddress = (await getMarketAddress(fusionPoolAddress))[0];
|
|
12218
13002
|
const market = await fetchMarket(rpc, marketAddress);
|
|
12219
|
-
const [mintA, mintB] = await
|
|
12220
|
-
|
|
12221
|
-
|
|
13003
|
+
const [mintA, mintB] = await fetchAllMaybeMint18(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
13004
|
+
assert18(mintA.exists, "Token A account not found");
|
|
13005
|
+
assert18(mintB.exists, "Token B account not found");
|
|
12222
13006
|
const [vaultA, vaultB] = await fetchAllVault(rpc, [
|
|
12223
13007
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
12224
13008
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
@@ -12324,47 +13108,47 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12324
13108
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint.address))[0];
|
|
12325
13109
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
12326
13110
|
const fusionPositionAddress = (await getPositionAddress16(positionMint.address))[0];
|
|
12327
|
-
const tunaPositionAta = (await
|
|
13111
|
+
const tunaPositionAta = (await findAssociatedTokenPda25({
|
|
12328
13112
|
owner: tunaPositionAddress,
|
|
12329
13113
|
mint: positionMint.address,
|
|
12330
13114
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS16
|
|
12331
13115
|
}))[0];
|
|
12332
|
-
const tunaPositionOwnerAtaA = (await
|
|
13116
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda25({
|
|
12333
13117
|
owner: authority.address,
|
|
12334
13118
|
mint: mintA.address,
|
|
12335
13119
|
tokenProgram: mintA.programAddress
|
|
12336
13120
|
}))[0];
|
|
12337
|
-
const tunaPositionOwnerAtaB = (await
|
|
13121
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda25({
|
|
12338
13122
|
owner: authority.address,
|
|
12339
13123
|
mint: mintB.address,
|
|
12340
13124
|
tokenProgram: mintB.programAddress
|
|
12341
13125
|
}))[0];
|
|
12342
|
-
const tunaPositionAtaA = (await
|
|
13126
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda25({
|
|
12343
13127
|
owner: tunaPositionAddress,
|
|
12344
13128
|
mint: mintA.address,
|
|
12345
13129
|
tokenProgram: mintA.programAddress
|
|
12346
13130
|
}))[0];
|
|
12347
|
-
const tunaPositionAtaB = (await
|
|
13131
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda25({
|
|
12348
13132
|
owner: tunaPositionAddress,
|
|
12349
13133
|
mint: mintB.address,
|
|
12350
13134
|
tokenProgram: mintB.programAddress
|
|
12351
13135
|
}))[0];
|
|
12352
|
-
const vaultAAta = (await
|
|
13136
|
+
const vaultAAta = (await findAssociatedTokenPda25({
|
|
12353
13137
|
owner: vaultA.address,
|
|
12354
13138
|
mint: mintA.address,
|
|
12355
13139
|
tokenProgram: mintA.programAddress
|
|
12356
13140
|
}))[0];
|
|
12357
|
-
const vaultBAta = (await
|
|
13141
|
+
const vaultBAta = (await findAssociatedTokenPda25({
|
|
12358
13142
|
owner: vaultB.address,
|
|
12359
13143
|
mint: mintB.address,
|
|
12360
13144
|
tokenProgram: mintB.programAddress
|
|
12361
13145
|
}))[0];
|
|
12362
|
-
const feeRecipientAtaA = (await
|
|
13146
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda25({
|
|
12363
13147
|
owner: tunaConfig.data.feeRecipient,
|
|
12364
13148
|
mint: mintA.address,
|
|
12365
13149
|
tokenProgram: mintA.programAddress
|
|
12366
13150
|
}))[0];
|
|
12367
|
-
const feeRecipientAtaB = (await
|
|
13151
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda25({
|
|
12368
13152
|
owner: tunaConfig.data.feeRecipient,
|
|
12369
13153
|
mint: mintB.address,
|
|
12370
13154
|
tokenProgram: mintB.programAddress
|
|
@@ -12373,15 +13157,15 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12373
13157
|
const lowerTickArrayAddress = await FusionUtils.getTickArrayAddressFromTickIndex(fusionPool, args.tickLowerIndex);
|
|
12374
13158
|
const upperTickArrayAddress = await FusionUtils.getTickArrayAddressFromTickIndex(fusionPool, args.tickUpperIndex);
|
|
12375
13159
|
const remainingAccounts = [
|
|
12376
|
-
{ address: swapTickArrays[0], role:
|
|
12377
|
-
{ address: swapTickArrays[1], role:
|
|
12378
|
-
{ address: swapTickArrays[2], role:
|
|
12379
|
-
{ address: swapTickArrays[3], role:
|
|
12380
|
-
{ address: swapTickArrays[4], role:
|
|
12381
|
-
{ address: lowerTickArrayAddress, role:
|
|
12382
|
-
{ address: upperTickArrayAddress, role:
|
|
12383
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
12384
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
13160
|
+
{ address: swapTickArrays[0], role: AccountRole16.WRITABLE },
|
|
13161
|
+
{ address: swapTickArrays[1], role: AccountRole16.WRITABLE },
|
|
13162
|
+
{ address: swapTickArrays[2], role: AccountRole16.WRITABLE },
|
|
13163
|
+
{ address: swapTickArrays[3], role: AccountRole16.WRITABLE },
|
|
13164
|
+
{ address: swapTickArrays[4], role: AccountRole16.WRITABLE },
|
|
13165
|
+
{ address: lowerTickArrayAddress, role: AccountRole16.WRITABLE },
|
|
13166
|
+
{ address: upperTickArrayAddress, role: AccountRole16.WRITABLE },
|
|
13167
|
+
{ address: fusionPool.data.tokenVaultA, role: AccountRole16.WRITABLE },
|
|
13168
|
+
{ address: fusionPool.data.tokenVaultB, role: AccountRole16.WRITABLE }
|
|
12385
13169
|
];
|
|
12386
13170
|
const remainingAccountsInfo = {
|
|
12387
13171
|
slices: [
|
|
@@ -12418,7 +13202,7 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12418
13202
|
fusionPosition: fusionPositionAddress,
|
|
12419
13203
|
tokenProgramA: mintA.programAddress,
|
|
12420
13204
|
tokenProgramB: mintB.programAddress,
|
|
12421
|
-
memoProgram:
|
|
13205
|
+
memoProgram: MEMO_PROGRAM_ADDRESS16,
|
|
12422
13206
|
metadataUpdateAuth: FP_NFT_UPDATE_AUTH2,
|
|
12423
13207
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ADDRESS4,
|
|
12424
13208
|
token2022Program: TOKEN_2022_PROGRAM_ADDRESS16,
|
|
@@ -12433,40 +13217,40 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
12433
13217
|
import { FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS11, getFusionPoolDecoder } from "@crypticdot/fusionamm-client";
|
|
12434
13218
|
import { getWhirlpoolDecoder, WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS11 } from "@orca-so/whirlpools-client";
|
|
12435
13219
|
import {
|
|
12436
|
-
decodeAccount as
|
|
12437
|
-
fetchEncodedAccount as
|
|
13220
|
+
decodeAccount as decodeAccount8,
|
|
13221
|
+
fetchEncodedAccount as fetchEncodedAccount8
|
|
12438
13222
|
} from "@solana/kit";
|
|
12439
13223
|
import {
|
|
12440
13224
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS5,
|
|
12441
|
-
fetchAllMaybeMint as
|
|
12442
|
-
findAssociatedTokenPda as
|
|
13225
|
+
fetchAllMaybeMint as fetchAllMaybeMint19,
|
|
13226
|
+
findAssociatedTokenPda as findAssociatedTokenPda26
|
|
12443
13227
|
} from "@solana-program/token-2022";
|
|
12444
|
-
import
|
|
13228
|
+
import assert19 from "assert";
|
|
12445
13229
|
async function openTunaSpotPositionInstructions(rpc, authority, poolAddress, args) {
|
|
12446
|
-
const poolAccount = await
|
|
12447
|
-
|
|
13230
|
+
const poolAccount = await fetchEncodedAccount8(rpc, poolAddress);
|
|
13231
|
+
assert19(poolAccount.exists, "Pool account not found");
|
|
12448
13232
|
let pool;
|
|
12449
13233
|
if (poolAccount.programAddress == FUSIONAMM_PROGRAM_ADDRESS11) {
|
|
12450
|
-
pool =
|
|
13234
|
+
pool = decodeAccount8(poolAccount, getFusionPoolDecoder());
|
|
12451
13235
|
} else if (poolAccount.programAddress == WHIRLPOOL_PROGRAM_ADDRESS11) {
|
|
12452
|
-
pool =
|
|
13236
|
+
pool = decodeAccount8(poolAccount, getWhirlpoolDecoder());
|
|
12453
13237
|
} else {
|
|
12454
13238
|
throw new Error("Incorrect Fusion or Orca pool account");
|
|
12455
13239
|
}
|
|
12456
|
-
const [mintA, mintB] = await
|
|
12457
|
-
|
|
12458
|
-
|
|
13240
|
+
const [mintA, mintB] = await fetchAllMaybeMint19(rpc, [pool.data.tokenMintA, pool.data.tokenMintB]);
|
|
13241
|
+
assert19(mintA.exists, "Token A account not found");
|
|
13242
|
+
assert19(mintB.exists, "Token B account not found");
|
|
12459
13243
|
const ix = await openTunaSpotPositionInstruction(authority, mintA, mintB, poolAddress, args);
|
|
12460
13244
|
return [ix];
|
|
12461
13245
|
}
|
|
12462
13246
|
async function openTunaSpotPositionInstruction(authority, mintA, mintB, poolAddress, args) {
|
|
12463
13247
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
12464
|
-
const tunaPositionAtaA = (await
|
|
13248
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda26({
|
|
12465
13249
|
owner: tunaPositionAddress,
|
|
12466
13250
|
mint: mintA.address,
|
|
12467
13251
|
tokenProgram: mintA.programAddress
|
|
12468
13252
|
}))[0];
|
|
12469
|
-
const tunaPositionAtaB = (await
|
|
13253
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda26({
|
|
12470
13254
|
owner: tunaPositionAddress,
|
|
12471
13255
|
mint: mintB.address,
|
|
12472
13256
|
tokenProgram: mintB.programAddress
|
|
@@ -12498,16 +13282,16 @@ import {
|
|
|
12498
13282
|
} from "@orca-so/whirlpools-client";
|
|
12499
13283
|
import { collectRewardsQuote as collectRewardsQuote2, getTickArrayStartTickIndex as getTickArrayStartTickIndex8, getTickIndexInArray as getTickIndexInArray2 } from "@orca-so/whirlpools-core";
|
|
12500
13284
|
import {
|
|
12501
|
-
AccountRole as
|
|
12502
|
-
assertAccountsExist as
|
|
13285
|
+
AccountRole as AccountRole17,
|
|
13286
|
+
assertAccountsExist as assertAccountsExist9
|
|
12503
13287
|
} from "@solana/kit";
|
|
12504
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
13288
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS17 } from "@solana-program/memo";
|
|
12505
13289
|
import {
|
|
12506
|
-
fetchAllMaybeMint as
|
|
12507
|
-
findAssociatedTokenPda as
|
|
13290
|
+
fetchAllMaybeMint as fetchAllMaybeMint20,
|
|
13291
|
+
findAssociatedTokenPda as findAssociatedTokenPda27,
|
|
12508
13292
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS17
|
|
12509
13293
|
} from "@solana-program/token-2022";
|
|
12510
|
-
import
|
|
13294
|
+
import assert20 from "assert";
|
|
12511
13295
|
async function decreaseTunaLpPositionOrcaInstructions(rpc, authority, positionMint, args, createInstructions, cleanupInstructions) {
|
|
12512
13296
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12513
13297
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -12518,15 +13302,15 @@ async function decreaseTunaLpPositionOrcaInstructions(rpc, authority, positionMi
|
|
|
12518
13302
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
12519
13303
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
12520
13304
|
]);
|
|
12521
|
-
const [mintA, mintB, ...rewardMints] = await
|
|
13305
|
+
const [mintA, mintB, ...rewardMints] = await fetchAllMaybeMint20(rpc, [
|
|
12522
13306
|
whirlpool.data.tokenMintA,
|
|
12523
13307
|
whirlpool.data.tokenMintB,
|
|
12524
13308
|
...whirlpool.data.rewardInfos.map((x) => x.mint).filter((x) => x !== DEFAULT_ADDRESS)
|
|
12525
13309
|
]);
|
|
12526
13310
|
const allMints = [mintA, mintB, ...rewardMints];
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
13311
|
+
assert20(mintA.exists, "Token A account not found");
|
|
13312
|
+
assert20(mintB.exists, "Token B account not found");
|
|
13313
|
+
assertAccountsExist9(rewardMints);
|
|
12530
13314
|
const lowerTickArrayStartIndex = getTickArrayStartTickIndex8(
|
|
12531
13315
|
tunaPosition.data.tickLowerIndex,
|
|
12532
13316
|
whirlpool.data.tickSpacing
|
|
@@ -12566,7 +13350,7 @@ async function decreaseTunaLpPositionOrcaInstructions(rpc, authority, positionMi
|
|
|
12566
13350
|
}
|
|
12567
13351
|
for (const mintAddress of requiredMints) {
|
|
12568
13352
|
const mint = allMints.find((mint2) => mint2.address == mintAddress);
|
|
12569
|
-
|
|
13353
|
+
assert20(mint && mint.exists);
|
|
12570
13354
|
const ixs = await getCreateAtaInstructions(rpc, authority, mint.address, authority.address, mint.programAddress);
|
|
12571
13355
|
createInstructions.push(...ixs.init);
|
|
12572
13356
|
internalCleanupInstructions.push(...ixs.cleanup);
|
|
@@ -12594,37 +13378,37 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12594
13378
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
12595
13379
|
const orcaPositionAddress = (await getPositionAddress17(positionMint))[0];
|
|
12596
13380
|
const orcaOracleAddress = (await getOracleAddress7(whirlpool.address))[0];
|
|
12597
|
-
const tunaPositionAta = (await
|
|
13381
|
+
const tunaPositionAta = (await findAssociatedTokenPda27({
|
|
12598
13382
|
owner: tunaPosition.address,
|
|
12599
13383
|
mint: positionMint,
|
|
12600
13384
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS17
|
|
12601
13385
|
}))[0];
|
|
12602
|
-
const tunaPositionOwnerAtaA = (await
|
|
13386
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda27({
|
|
12603
13387
|
owner: authority.address,
|
|
12604
13388
|
mint: mintA.address,
|
|
12605
13389
|
tokenProgram: mintA.programAddress
|
|
12606
13390
|
}))[0];
|
|
12607
|
-
const tunaPositionOwnerAtaB = (await
|
|
13391
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda27({
|
|
12608
13392
|
owner: authority.address,
|
|
12609
13393
|
mint: mintB.address,
|
|
12610
13394
|
tokenProgram: mintB.programAddress
|
|
12611
13395
|
}))[0];
|
|
12612
|
-
const tunaPositionAtaA = (await
|
|
13396
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda27({
|
|
12613
13397
|
owner: tunaPosition.address,
|
|
12614
13398
|
mint: mintA.address,
|
|
12615
13399
|
tokenProgram: mintA.programAddress
|
|
12616
13400
|
}))[0];
|
|
12617
|
-
const tunaPositionAtaB = (await
|
|
13401
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda27({
|
|
12618
13402
|
owner: tunaPosition.address,
|
|
12619
13403
|
mint: mintB.address,
|
|
12620
13404
|
tokenProgram: mintB.programAddress
|
|
12621
13405
|
}))[0];
|
|
12622
|
-
const vaultAAta = (await
|
|
13406
|
+
const vaultAAta = (await findAssociatedTokenPda27({
|
|
12623
13407
|
owner: vaultA.address,
|
|
12624
13408
|
mint: mintA.address,
|
|
12625
13409
|
tokenProgram: mintA.programAddress
|
|
12626
13410
|
}))[0];
|
|
12627
|
-
const vaultBAta = (await
|
|
13411
|
+
const vaultBAta = (await findAssociatedTokenPda27({
|
|
12628
13412
|
owner: vaultB.address,
|
|
12629
13413
|
mint: mintB.address,
|
|
12630
13414
|
tokenProgram: mintB.programAddress
|
|
@@ -12639,30 +13423,30 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12639
13423
|
tunaPosition.data.tickUpperIndex
|
|
12640
13424
|
);
|
|
12641
13425
|
const remainingAccounts = [
|
|
12642
|
-
{ address: swapTickArrays[0], role:
|
|
12643
|
-
{ address: swapTickArrays[1], role:
|
|
12644
|
-
{ address: swapTickArrays[2], role:
|
|
12645
|
-
{ address: swapTickArrays[3], role:
|
|
12646
|
-
{ address: swapTickArrays[4], role:
|
|
12647
|
-
{ address: lowerTickArrayAddress, role:
|
|
12648
|
-
{ address: upperTickArrayAddress, role:
|
|
12649
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
12650
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
12651
|
-
{ address: orcaOracleAddress, role:
|
|
13426
|
+
{ address: swapTickArrays[0], role: AccountRole17.WRITABLE },
|
|
13427
|
+
{ address: swapTickArrays[1], role: AccountRole17.WRITABLE },
|
|
13428
|
+
{ address: swapTickArrays[2], role: AccountRole17.WRITABLE },
|
|
13429
|
+
{ address: swapTickArrays[3], role: AccountRole17.WRITABLE },
|
|
13430
|
+
{ address: swapTickArrays[4], role: AccountRole17.WRITABLE },
|
|
13431
|
+
{ address: lowerTickArrayAddress, role: AccountRole17.WRITABLE },
|
|
13432
|
+
{ address: upperTickArrayAddress, role: AccountRole17.WRITABLE },
|
|
13433
|
+
{ address: whirlpool.data.tokenVaultA, role: AccountRole17.WRITABLE },
|
|
13434
|
+
{ address: whirlpool.data.tokenVaultB, role: AccountRole17.WRITABLE },
|
|
13435
|
+
{ address: orcaOracleAddress, role: AccountRole17.WRITABLE }
|
|
12652
13436
|
];
|
|
12653
13437
|
for (const rewardIndex of rewardIndicesToClaim) {
|
|
12654
13438
|
const rewardInfo = whirlpool.data.rewardInfos[rewardIndex];
|
|
12655
13439
|
const rewardMint = rewardMints.find((mint) => mint.address == rewardInfo.mint);
|
|
12656
|
-
|
|
12657
|
-
const ownerAta = await
|
|
13440
|
+
assert20(rewardMint, "Reward mint not found in the provided reward mint accounts");
|
|
13441
|
+
const ownerAta = await findAssociatedTokenPda27({
|
|
12658
13442
|
owner: authority.address,
|
|
12659
13443
|
mint: rewardMint.address,
|
|
12660
13444
|
tokenProgram: rewardMint.programAddress
|
|
12661
13445
|
});
|
|
12662
|
-
remainingAccounts.push({ address: rewardMint.address, role:
|
|
12663
|
-
remainingAccounts.push({ address: rewardMint.programAddress, role:
|
|
12664
|
-
remainingAccounts.push({ address: ownerAta[0], role:
|
|
12665
|
-
remainingAccounts.push({ address: rewardInfo.vault, role:
|
|
13446
|
+
remainingAccounts.push({ address: rewardMint.address, role: AccountRole17.READONLY });
|
|
13447
|
+
remainingAccounts.push({ address: rewardMint.programAddress, role: AccountRole17.READONLY });
|
|
13448
|
+
remainingAccounts.push({ address: ownerAta[0], role: AccountRole17.WRITABLE });
|
|
13449
|
+
remainingAccounts.push({ address: rewardInfo.vault, role: AccountRole17.WRITABLE });
|
|
12666
13450
|
}
|
|
12667
13451
|
const remainingAccountsInfo = {
|
|
12668
13452
|
slices: [
|
|
@@ -12700,7 +13484,7 @@ async function decreaseTunaLpPositionOrcaInstruction(authority, tunaPosition, mi
|
|
|
12700
13484
|
whirlpoolProgram: WHIRLPOOL_PROGRAM_ADDRESS12,
|
|
12701
13485
|
tokenProgramA: mintA.programAddress,
|
|
12702
13486
|
tokenProgramB: mintB.programAddress,
|
|
12703
|
-
memoProgram:
|
|
13487
|
+
memoProgram: MEMO_PROGRAM_ADDRESS17,
|
|
12704
13488
|
...args,
|
|
12705
13489
|
remainingAccountsInfo
|
|
12706
13490
|
});
|
|
@@ -12715,15 +13499,15 @@ import {
|
|
|
12715
13499
|
getPositionAddress as getPositionAddress18
|
|
12716
13500
|
} from "@crypticdot/fusionamm-client";
|
|
12717
13501
|
import {
|
|
12718
|
-
AccountRole as
|
|
13502
|
+
AccountRole as AccountRole18
|
|
12719
13503
|
} from "@solana/kit";
|
|
12720
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
13504
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS18 } from "@solana-program/memo";
|
|
12721
13505
|
import {
|
|
12722
|
-
fetchAllMaybeMint as
|
|
12723
|
-
findAssociatedTokenPda as
|
|
13506
|
+
fetchAllMaybeMint as fetchAllMaybeMint21,
|
|
13507
|
+
findAssociatedTokenPda as findAssociatedTokenPda28,
|
|
12724
13508
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS18
|
|
12725
13509
|
} from "@solana-program/token-2022";
|
|
12726
|
-
import
|
|
13510
|
+
import assert21 from "assert";
|
|
12727
13511
|
async function decreaseTunaLpPositionFusionInstructions(rpc, authority, positionMint, args, createInstructions, cleanupInstructions) {
|
|
12728
13512
|
const tunaPosition = await fetchMaybeTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
12729
13513
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -12733,9 +13517,9 @@ async function decreaseTunaLpPositionFusionInstructions(rpc, authority, position
|
|
|
12733
13517
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
12734
13518
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
12735
13519
|
]);
|
|
12736
|
-
const [mintA, mintB] = await
|
|
12737
|
-
|
|
12738
|
-
|
|
13520
|
+
const [mintA, mintB] = await fetchAllMaybeMint21(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
13521
|
+
assert21(mintA.exists, "Token A account not found");
|
|
13522
|
+
assert21(mintB.exists, "Token B account not found");
|
|
12739
13523
|
const instructions = [];
|
|
12740
13524
|
if (!createInstructions) createInstructions = instructions;
|
|
12741
13525
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
@@ -12776,37 +13560,37 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12776
13560
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12777
13561
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
12778
13562
|
const fusionPositionAddress = (await getPositionAddress18(positionMint))[0];
|
|
12779
|
-
const tunaPositionAta = (await
|
|
13563
|
+
const tunaPositionAta = (await findAssociatedTokenPda28({
|
|
12780
13564
|
owner: tunaPosition.address,
|
|
12781
13565
|
mint: positionMint,
|
|
12782
13566
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS18
|
|
12783
13567
|
}))[0];
|
|
12784
|
-
const tunaPositionOwnerAtaA = (await
|
|
13568
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda28({
|
|
12785
13569
|
owner: authority.address,
|
|
12786
13570
|
mint: mintA.address,
|
|
12787
13571
|
tokenProgram: mintA.programAddress
|
|
12788
13572
|
}))[0];
|
|
12789
|
-
const tunaPositionOwnerAtaB = (await
|
|
13573
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda28({
|
|
12790
13574
|
owner: authority.address,
|
|
12791
13575
|
mint: mintB.address,
|
|
12792
13576
|
tokenProgram: mintB.programAddress
|
|
12793
13577
|
}))[0];
|
|
12794
|
-
const tunaPositionAtaA = (await
|
|
13578
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda28({
|
|
12795
13579
|
owner: tunaPosition.address,
|
|
12796
13580
|
mint: mintA.address,
|
|
12797
13581
|
tokenProgram: mintA.programAddress
|
|
12798
13582
|
}))[0];
|
|
12799
|
-
const tunaPositionAtaB = (await
|
|
13583
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda28({
|
|
12800
13584
|
owner: tunaPosition.address,
|
|
12801
13585
|
mint: mintB.address,
|
|
12802
13586
|
tokenProgram: mintB.programAddress
|
|
12803
13587
|
}))[0];
|
|
12804
|
-
const vaultAAta = (await
|
|
13588
|
+
const vaultAAta = (await findAssociatedTokenPda28({
|
|
12805
13589
|
owner: vaultA.address,
|
|
12806
13590
|
mint: mintA.address,
|
|
12807
13591
|
tokenProgram: mintA.programAddress
|
|
12808
13592
|
}))[0];
|
|
12809
|
-
const vaultBAta = (await
|
|
13593
|
+
const vaultBAta = (await findAssociatedTokenPda28({
|
|
12810
13594
|
owner: vaultB.address,
|
|
12811
13595
|
mint: mintB.address,
|
|
12812
13596
|
tokenProgram: mintB.programAddress
|
|
@@ -12821,15 +13605,15 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12821
13605
|
tunaPosition.data.tickUpperIndex
|
|
12822
13606
|
);
|
|
12823
13607
|
const remainingAccounts = [
|
|
12824
|
-
{ address: swapTickArrays[0], role:
|
|
12825
|
-
{ address: swapTickArrays[1], role:
|
|
12826
|
-
{ address: swapTickArrays[2], role:
|
|
12827
|
-
{ address: swapTickArrays[3], role:
|
|
12828
|
-
{ address: swapTickArrays[4], role:
|
|
12829
|
-
{ address: lowerTickArrayAddress, role:
|
|
12830
|
-
{ address: upperTickArrayAddress, role:
|
|
12831
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
12832
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
13608
|
+
{ address: swapTickArrays[0], role: AccountRole18.WRITABLE },
|
|
13609
|
+
{ address: swapTickArrays[1], role: AccountRole18.WRITABLE },
|
|
13610
|
+
{ address: swapTickArrays[2], role: AccountRole18.WRITABLE },
|
|
13611
|
+
{ address: swapTickArrays[3], role: AccountRole18.WRITABLE },
|
|
13612
|
+
{ address: swapTickArrays[4], role: AccountRole18.WRITABLE },
|
|
13613
|
+
{ address: lowerTickArrayAddress, role: AccountRole18.WRITABLE },
|
|
13614
|
+
{ address: upperTickArrayAddress, role: AccountRole18.WRITABLE },
|
|
13615
|
+
{ address: fusionPool.data.tokenVaultA, role: AccountRole18.WRITABLE },
|
|
13616
|
+
{ address: fusionPool.data.tokenVaultB, role: AccountRole18.WRITABLE }
|
|
12833
13617
|
];
|
|
12834
13618
|
const remainingAccountsInfo = {
|
|
12835
13619
|
slices: [
|
|
@@ -12863,7 +13647,7 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12863
13647
|
fusionammProgram: FUSIONAMM_PROGRAM_ADDRESS12,
|
|
12864
13648
|
tokenProgramA: mintA.programAddress,
|
|
12865
13649
|
tokenProgramB: mintB.programAddress,
|
|
12866
|
-
memoProgram:
|
|
13650
|
+
memoProgram: MEMO_PROGRAM_ADDRESS18,
|
|
12867
13651
|
...args,
|
|
12868
13652
|
remainingAccountsInfo
|
|
12869
13653
|
});
|
|
@@ -12872,19 +13656,19 @@ async function decreaseTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
12872
13656
|
}
|
|
12873
13657
|
|
|
12874
13658
|
// src/txbuilder/repayBadDebt.ts
|
|
12875
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
12876
|
-
import { fetchMaybeMint as fetchMaybeMint2, findAssociatedTokenPda as
|
|
13659
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS19 } from "@solana-program/memo";
|
|
13660
|
+
import { fetchMaybeMint as fetchMaybeMint2, findAssociatedTokenPda as findAssociatedTokenPda29 } from "@solana-program/token-2022";
|
|
12877
13661
|
async function repayBadDebtInstruction(rpc, authority, mintAddress, funds, shares) {
|
|
12878
13662
|
const mint = await fetchMaybeMint2(rpc, mintAddress);
|
|
12879
13663
|
if (!mint.exists) throw new Error("Mint account not found");
|
|
12880
13664
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
12881
13665
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
12882
|
-
const vaultAta = (await
|
|
13666
|
+
const vaultAta = (await findAssociatedTokenPda29({
|
|
12883
13667
|
owner: vault,
|
|
12884
13668
|
mint: mint.address,
|
|
12885
13669
|
tokenProgram: mint.programAddress
|
|
12886
13670
|
}))[0];
|
|
12887
|
-
const authorityAta = (await
|
|
13671
|
+
const authorityAta = (await findAssociatedTokenPda29({
|
|
12888
13672
|
owner: authority.address,
|
|
12889
13673
|
mint: mint.address,
|
|
12890
13674
|
tokenProgram: mint.programAddress
|
|
@@ -12897,7 +13681,7 @@ async function repayBadDebtInstruction(rpc, authority, mintAddress, funds, share
|
|
|
12897
13681
|
tunaConfig,
|
|
12898
13682
|
vault,
|
|
12899
13683
|
tokenProgram: mint.programAddress,
|
|
12900
|
-
memoProgram:
|
|
13684
|
+
memoProgram: MEMO_PROGRAM_ADDRESS19,
|
|
12901
13685
|
funds,
|
|
12902
13686
|
shares
|
|
12903
13687
|
});
|
|
@@ -12929,20 +13713,20 @@ async function setTunaSpotPositionLimitOrdersInstruction(authority, poolAddress,
|
|
|
12929
13713
|
}
|
|
12930
13714
|
|
|
12931
13715
|
// src/txbuilder/resetTunaSpotPosition.ts
|
|
12932
|
-
import { fetchAllMaybeMint as
|
|
12933
|
-
import
|
|
13716
|
+
import { fetchAllMaybeMint as fetchAllMaybeMint22, findAssociatedTokenPda as findAssociatedTokenPda30 } from "@solana-program/token-2022";
|
|
13717
|
+
import assert22 from "assert";
|
|
12934
13718
|
async function resetTunaSpotPositionInstruction(rpc, authority, poolAddress, args) {
|
|
12935
13719
|
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
12936
13720
|
const tunaPosition = await fetchTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12937
|
-
const [mintA, mintB] = await
|
|
12938
|
-
|
|
12939
|
-
|
|
12940
|
-
const tunaPositionAtaA = (await
|
|
13721
|
+
const [mintA, mintB] = await fetchAllMaybeMint22(rpc, [tunaPosition.data.mintA, tunaPosition.data.mintB]);
|
|
13722
|
+
assert22(mintA.exists, "Token A not found");
|
|
13723
|
+
assert22(mintB.exists, "Token B not found");
|
|
13724
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda30({
|
|
12941
13725
|
owner: tunaPositionAddress,
|
|
12942
13726
|
mint: mintA.address,
|
|
12943
13727
|
tokenProgram: mintA.programAddress
|
|
12944
13728
|
}))[0];
|
|
12945
|
-
const tunaPositionAtaB = (await
|
|
13729
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda30({
|
|
12946
13730
|
owner: tunaPositionAddress,
|
|
12947
13731
|
mint: mintB.address,
|
|
12948
13732
|
tokenProgram: mintB.programAddress
|
|
@@ -12983,8 +13767,8 @@ async function updateVaultInstruction(authority, mint, args) {
|
|
|
12983
13767
|
}
|
|
12984
13768
|
|
|
12985
13769
|
// src/txbuilder/withdraw.ts
|
|
12986
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
12987
|
-
import { fetchMaybeMint as fetchMaybeMint3, findAssociatedTokenPda as
|
|
13770
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS20 } from "@solana-program/memo";
|
|
13771
|
+
import { fetchMaybeMint as fetchMaybeMint3, findAssociatedTokenPda as findAssociatedTokenPda31 } from "@solana-program/token-2022";
|
|
12988
13772
|
async function withdrawInstructions(rpc, authority, mintAddress, funds, shares) {
|
|
12989
13773
|
const instructions = [];
|
|
12990
13774
|
const mint = await fetchMaybeMint3(rpc, mintAddress);
|
|
@@ -13006,12 +13790,12 @@ async function withdrawInstruction(authority, mint, funds, shares) {
|
|
|
13006
13790
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
13007
13791
|
const lendingPosition = (await getLendingPositionAddress(authority.address, mint.address))[0];
|
|
13008
13792
|
const vault = (await getLendingVaultAddress(mint.address))[0];
|
|
13009
|
-
const vaultAta = (await
|
|
13793
|
+
const vaultAta = (await findAssociatedTokenPda31({
|
|
13010
13794
|
owner: vault,
|
|
13011
13795
|
mint: mint.address,
|
|
13012
13796
|
tokenProgram: mint.programAddress
|
|
13013
13797
|
}))[0];
|
|
13014
|
-
const authorityAta = (await
|
|
13798
|
+
const authorityAta = (await findAssociatedTokenPda31({
|
|
13015
13799
|
owner: authority.address,
|
|
13016
13800
|
mint: mint.address,
|
|
13017
13801
|
tokenProgram: mint.programAddress
|
|
@@ -13025,26 +13809,26 @@ async function withdrawInstruction(authority, mint, funds, shares) {
|
|
|
13025
13809
|
vault,
|
|
13026
13810
|
vaultAta,
|
|
13027
13811
|
tokenProgram: mint.programAddress,
|
|
13028
|
-
memoProgram:
|
|
13812
|
+
memoProgram: MEMO_PROGRAM_ADDRESS20,
|
|
13029
13813
|
funds,
|
|
13030
13814
|
shares
|
|
13031
13815
|
});
|
|
13032
13816
|
}
|
|
13033
13817
|
|
|
13034
13818
|
// src/txbuilder/createMarketLookupTable.ts
|
|
13035
|
-
import { fetchFusionPool as
|
|
13036
|
-
import { fetchWhirlpool as
|
|
13819
|
+
import { fetchFusionPool as fetchFusionPool3, FP_NFT_UPDATE_AUTH as FP_NFT_UPDATE_AUTH3, FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS13 } from "@crypticdot/fusionamm-client";
|
|
13820
|
+
import { fetchWhirlpool as fetchWhirlpool3, getOracleAddress as getOracleAddress8, WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS13 } from "@orca-so/whirlpools-client";
|
|
13037
13821
|
import {
|
|
13038
13822
|
address as address3
|
|
13039
13823
|
} from "@solana/kit";
|
|
13040
13824
|
import { fetchAddressLookupTable, getExtendLookupTableInstruction as getExtendLookupTableInstruction2 } from "@solana-program/address-lookup-table";
|
|
13041
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
13825
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS21 } from "@solana-program/memo";
|
|
13042
13826
|
import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
|
|
13043
13827
|
import { TOKEN_PROGRAM_ADDRESS as TOKEN_PROGRAM_ADDRESS2 } from "@solana-program/token";
|
|
13044
13828
|
import {
|
|
13045
13829
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS6,
|
|
13046
13830
|
fetchMint,
|
|
13047
|
-
findAssociatedTokenPda as
|
|
13831
|
+
findAssociatedTokenPda as findAssociatedTokenPda32,
|
|
13048
13832
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS19
|
|
13049
13833
|
} from "@solana-program/token-2022";
|
|
13050
13834
|
async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
@@ -13052,15 +13836,15 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
13052
13836
|
const marketAddress = (await getMarketAddress(poolAddress))[0];
|
|
13053
13837
|
const orcaOracleAddress = (await getOracleAddress8(poolAddress))[0];
|
|
13054
13838
|
const tunaConfig = await fetchTunaConfig(rpc, tunaConfigAddress);
|
|
13055
|
-
const pool = marketMaker == 0 /* Orca */ ? await
|
|
13839
|
+
const pool = marketMaker == 0 /* Orca */ ? await fetchWhirlpool3(rpc, poolAddress) : await fetchFusionPool3(rpc, poolAddress);
|
|
13056
13840
|
const mintA = await fetchMint(rpc, pool.data.tokenMintA);
|
|
13057
13841
|
const mintB = await fetchMint(rpc, pool.data.tokenMintB);
|
|
13058
|
-
const feeRecipientAtaA = (await
|
|
13842
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda32({
|
|
13059
13843
|
owner: tunaConfig.data.feeRecipient,
|
|
13060
13844
|
mint: mintA.address,
|
|
13061
13845
|
tokenProgram: mintA.programAddress
|
|
13062
13846
|
}))[0];
|
|
13063
|
-
const feeRecipientAtaB = (await
|
|
13847
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda32({
|
|
13064
13848
|
owner: tunaConfig.data.feeRecipient,
|
|
13065
13849
|
mint: mintB.address,
|
|
13066
13850
|
tokenProgram: mintB.programAddress
|
|
@@ -13069,12 +13853,12 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
13069
13853
|
(await getLendingVaultAddress(mintA.address))[0],
|
|
13070
13854
|
(await getLendingVaultAddress(mintB.address))[0]
|
|
13071
13855
|
]);
|
|
13072
|
-
const vaultAAta = (await
|
|
13856
|
+
const vaultAAta = (await findAssociatedTokenPda32({
|
|
13073
13857
|
owner: vaultA.address,
|
|
13074
13858
|
mint: mintA.address,
|
|
13075
13859
|
tokenProgram: mintA.programAddress
|
|
13076
13860
|
}))[0];
|
|
13077
|
-
const vaultBAta = (await
|
|
13861
|
+
const vaultBAta = (await findAssociatedTokenPda32({
|
|
13078
13862
|
owner: vaultB.address,
|
|
13079
13863
|
mint: mintB.address,
|
|
13080
13864
|
tokenProgram: mintB.programAddress
|
|
@@ -13086,7 +13870,7 @@ async function getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker) {
|
|
|
13086
13870
|
TOKEN_PROGRAM_ADDRESS2,
|
|
13087
13871
|
TOKEN_2022_PROGRAM_ADDRESS19,
|
|
13088
13872
|
NATIVE_MINT,
|
|
13089
|
-
|
|
13873
|
+
MEMO_PROGRAM_ADDRESS21,
|
|
13090
13874
|
tunaConfigAddress,
|
|
13091
13875
|
marketAddress,
|
|
13092
13876
|
mintA.address,
|
|
@@ -13141,17 +13925,17 @@ async function extendAddressLookupTableForMarketInstructions(rpc, poolAddress, m
|
|
|
13141
13925
|
}
|
|
13142
13926
|
|
|
13143
13927
|
// src/txbuilder/repayTunaLpPositionDebt.ts
|
|
13144
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
13145
|
-
import { fetchAllMaybeMint as
|
|
13146
|
-
import
|
|
13928
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS22 } from "@solana-program/memo";
|
|
13929
|
+
import { fetchAllMaybeMint as fetchAllMaybeMint23, findAssociatedTokenPda as findAssociatedTokenPda33 } from "@solana-program/token-2022";
|
|
13930
|
+
import assert23 from "assert";
|
|
13147
13931
|
async function repayTunaLpPositionDebtInstructions(rpc, authority, positionMint, collateralA, collateralB, createInstructions, cleanupInstructions) {
|
|
13148
13932
|
const instructions = [];
|
|
13149
13933
|
if (!createInstructions) createInstructions = instructions;
|
|
13150
13934
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
13151
13935
|
const tunaPosition = await fetchTunaLpPosition(rpc, (await getTunaLpPositionAddress(positionMint))[0]);
|
|
13152
|
-
const [mintA, mintB] = await
|
|
13153
|
-
|
|
13154
|
-
|
|
13936
|
+
const [mintA, mintB] = await fetchAllMaybeMint23(rpc, [tunaPosition.data.mintA, tunaPosition.data.mintB]);
|
|
13937
|
+
assert23(mintA.exists, "Token A not found");
|
|
13938
|
+
assert23(mintB.exists, "Token B not found");
|
|
13155
13939
|
const marketAddress = (await getMarketAddress(tunaPosition.data.pool))[0];
|
|
13156
13940
|
const createUserAtaAInstructions = await getCreateAtaInstructions(
|
|
13157
13941
|
rpc,
|
|
@@ -13187,34 +13971,34 @@ async function repayTunaLpPositionDebtInstructions(rpc, authority, positionMint,
|
|
|
13187
13971
|
}
|
|
13188
13972
|
async function repayTunaLpPositionDebtInstruction(authority, positionMint, mintA, mintB, marketAddress, collateralA, collateralB) {
|
|
13189
13973
|
const tunaPositionAddress = (await getTunaLpPositionAddress(positionMint))[0];
|
|
13190
|
-
const tunaPositionOwnerAtaA = (await
|
|
13974
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda33({
|
|
13191
13975
|
owner: authority.address,
|
|
13192
13976
|
mint: mintA.address,
|
|
13193
13977
|
tokenProgram: mintA.programAddress
|
|
13194
13978
|
}))[0];
|
|
13195
|
-
const tunaPositionOwnerAtaB = (await
|
|
13979
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda33({
|
|
13196
13980
|
owner: authority.address,
|
|
13197
13981
|
mint: mintB.address,
|
|
13198
13982
|
tokenProgram: mintB.programAddress
|
|
13199
13983
|
}))[0];
|
|
13200
|
-
const tunaPositionAtaA = (await
|
|
13984
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda33({
|
|
13201
13985
|
owner: tunaPositionAddress,
|
|
13202
13986
|
mint: mintA.address,
|
|
13203
13987
|
tokenProgram: mintA.programAddress
|
|
13204
13988
|
}))[0];
|
|
13205
|
-
const tunaPositionAtaB = (await
|
|
13989
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda33({
|
|
13206
13990
|
owner: tunaPositionAddress,
|
|
13207
13991
|
mint: mintB.address,
|
|
13208
13992
|
tokenProgram: mintB.programAddress
|
|
13209
13993
|
}))[0];
|
|
13210
13994
|
const vaultAAddress = (await getLendingVaultAddress(mintA.address))[0];
|
|
13211
|
-
const vaultAAta = (await
|
|
13995
|
+
const vaultAAta = (await findAssociatedTokenPda33({
|
|
13212
13996
|
owner: vaultAAddress,
|
|
13213
13997
|
mint: mintA.address,
|
|
13214
13998
|
tokenProgram: mintA.programAddress
|
|
13215
13999
|
}))[0];
|
|
13216
14000
|
const vaultBAddress = (await getLendingVaultAddress(mintB.address))[0];
|
|
13217
|
-
const vaultBAta = (await
|
|
14001
|
+
const vaultBAta = (await findAssociatedTokenPda33({
|
|
13218
14002
|
owner: vaultBAddress,
|
|
13219
14003
|
mint: mintB.address,
|
|
13220
14004
|
tokenProgram: mintB.programAddress
|
|
@@ -13222,7 +14006,7 @@ async function repayTunaLpPositionDebtInstruction(authority, positionMint, mintA
|
|
|
13222
14006
|
return getRepayTunaLpPositionDebtInstruction({
|
|
13223
14007
|
authority,
|
|
13224
14008
|
market: marketAddress,
|
|
13225
|
-
memoProgram:
|
|
14009
|
+
memoProgram: MEMO_PROGRAM_ADDRESS22,
|
|
13226
14010
|
mintA: mintA.address,
|
|
13227
14011
|
mintB: mintB.address,
|
|
13228
14012
|
tokenProgramA: mintA.programAddress,
|
|
@@ -13252,17 +14036,17 @@ import {
|
|
|
13252
14036
|
WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS14
|
|
13253
14037
|
} from "@orca-so/whirlpools-client";
|
|
13254
14038
|
import {
|
|
13255
|
-
AccountRole as
|
|
14039
|
+
AccountRole as AccountRole19,
|
|
13256
14040
|
lamports as lamports3
|
|
13257
14041
|
} from "@solana/kit";
|
|
13258
14042
|
import { fetchSysvarRent as fetchSysvarRent3 } from "@solana/sysvars";
|
|
13259
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
14043
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS23 } from "@solana-program/memo";
|
|
13260
14044
|
import {
|
|
13261
|
-
fetchAllMaybeMint as
|
|
13262
|
-
findAssociatedTokenPda as
|
|
14045
|
+
fetchAllMaybeMint as fetchAllMaybeMint24,
|
|
14046
|
+
findAssociatedTokenPda as findAssociatedTokenPda34,
|
|
13263
14047
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS20
|
|
13264
14048
|
} from "@solana-program/token-2022";
|
|
13265
|
-
import
|
|
14049
|
+
import assert24 from "assert";
|
|
13266
14050
|
async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
13267
14051
|
const rent = await fetchSysvarRent3(rpc);
|
|
13268
14052
|
let nonRefundableRent = 0n;
|
|
@@ -13275,9 +14059,9 @@ async function rebalanceTunaLpPositionOrcaInstructions(rpc, authority, positionM
|
|
|
13275
14059
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
13276
14060
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
13277
14061
|
]);
|
|
13278
|
-
const [mintA, mintB] = await
|
|
13279
|
-
|
|
13280
|
-
|
|
14062
|
+
const [mintA, mintB] = await fetchAllMaybeMint24(rpc, [whirlpool.data.tokenMintA, whirlpool.data.tokenMintB]);
|
|
14063
|
+
assert24(mintA.exists, "Token A account not found");
|
|
14064
|
+
assert24(mintB.exists, "Token B account not found");
|
|
13281
14065
|
const instructions = [];
|
|
13282
14066
|
if (!createInstructions) createInstructions = instructions;
|
|
13283
14067
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
@@ -13349,27 +14133,27 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13349
14133
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
13350
14134
|
const orcaPositionAddress = (await getPositionAddress19(positionMint))[0];
|
|
13351
14135
|
const orcaOracleAddress = (await getOracleAddress9(whirlpool.address))[0];
|
|
13352
|
-
const tunaPositionAta = (await
|
|
14136
|
+
const tunaPositionAta = (await findAssociatedTokenPda34({
|
|
13353
14137
|
owner: tunaPosition.address,
|
|
13354
14138
|
mint: positionMint,
|
|
13355
14139
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS20
|
|
13356
14140
|
}))[0];
|
|
13357
|
-
const tunaPositionAtaA = (await
|
|
14141
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda34({
|
|
13358
14142
|
owner: tunaPosition.address,
|
|
13359
14143
|
mint: mintA.address,
|
|
13360
14144
|
tokenProgram: mintA.programAddress
|
|
13361
14145
|
}))[0];
|
|
13362
|
-
const tunaPositionAtaB = (await
|
|
14146
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda34({
|
|
13363
14147
|
owner: tunaPosition.address,
|
|
13364
14148
|
mint: mintB.address,
|
|
13365
14149
|
tokenProgram: mintB.programAddress
|
|
13366
14150
|
}))[0];
|
|
13367
|
-
const feeRecipientAtaA = (await
|
|
14151
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda34({
|
|
13368
14152
|
owner: tunaConfig.data.feeRecipient,
|
|
13369
14153
|
mint: mintA.address,
|
|
13370
14154
|
tokenProgram: mintA.programAddress
|
|
13371
14155
|
}))[0];
|
|
13372
|
-
const feeRecipientAtaB = (await
|
|
14156
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda34({
|
|
13373
14157
|
owner: tunaConfig.data.feeRecipient,
|
|
13374
14158
|
mint: mintB.address,
|
|
13375
14159
|
tokenProgram: mintB.programAddress
|
|
@@ -13385,18 +14169,18 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13385
14169
|
);
|
|
13386
14170
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
13387
14171
|
const remainingAccounts = [
|
|
13388
|
-
{ address: swapTickArrays[0], role:
|
|
13389
|
-
{ address: swapTickArrays[1], role:
|
|
13390
|
-
{ address: swapTickArrays[2], role:
|
|
13391
|
-
{ address: swapTickArrays[3], role:
|
|
13392
|
-
{ address: swapTickArrays[4], role:
|
|
13393
|
-
{ address: lowerTickArrayAddress, role:
|
|
13394
|
-
{ address: upperTickArrayAddress, role:
|
|
13395
|
-
{ address: secondaryTickArrays.lowerTickArrayAddress, role:
|
|
13396
|
-
{ address: secondaryTickArrays.upperTickArrayAddress, role:
|
|
13397
|
-
{ address: whirlpool.data.tokenVaultA, role:
|
|
13398
|
-
{ address: whirlpool.data.tokenVaultB, role:
|
|
13399
|
-
{ address: orcaOracleAddress, role:
|
|
14172
|
+
{ address: swapTickArrays[0], role: AccountRole19.WRITABLE },
|
|
14173
|
+
{ address: swapTickArrays[1], role: AccountRole19.WRITABLE },
|
|
14174
|
+
{ address: swapTickArrays[2], role: AccountRole19.WRITABLE },
|
|
14175
|
+
{ address: swapTickArrays[3], role: AccountRole19.WRITABLE },
|
|
14176
|
+
{ address: swapTickArrays[4], role: AccountRole19.WRITABLE },
|
|
14177
|
+
{ address: lowerTickArrayAddress, role: AccountRole19.WRITABLE },
|
|
14178
|
+
{ address: upperTickArrayAddress, role: AccountRole19.WRITABLE },
|
|
14179
|
+
{ address: secondaryTickArrays.lowerTickArrayAddress, role: AccountRole19.WRITABLE },
|
|
14180
|
+
{ address: secondaryTickArrays.upperTickArrayAddress, role: AccountRole19.WRITABLE },
|
|
14181
|
+
{ address: whirlpool.data.tokenVaultA, role: AccountRole19.WRITABLE },
|
|
14182
|
+
{ address: whirlpool.data.tokenVaultB, role: AccountRole19.WRITABLE },
|
|
14183
|
+
{ address: orcaOracleAddress, role: AccountRole19.WRITABLE }
|
|
13400
14184
|
];
|
|
13401
14185
|
const remainingAccountsInfo = {
|
|
13402
14186
|
slices: [
|
|
@@ -13431,7 +14215,7 @@ async function rebalanceTunaLpPositionOrcaInstruction(authority, tunaPosition, t
|
|
|
13431
14215
|
whirlpoolProgram: WHIRLPOOL_PROGRAM_ADDRESS14,
|
|
13432
14216
|
tokenProgramA: mintA.programAddress,
|
|
13433
14217
|
tokenProgramB: mintB.programAddress,
|
|
13434
|
-
memoProgram:
|
|
14218
|
+
memoProgram: MEMO_PROGRAM_ADDRESS23,
|
|
13435
14219
|
remainingAccountsInfo
|
|
13436
14220
|
});
|
|
13437
14221
|
ix.accounts.push(...remainingAccounts);
|
|
@@ -13448,17 +14232,17 @@ import {
|
|
|
13448
14232
|
getTickArraySize as getTickArraySize2
|
|
13449
14233
|
} from "@crypticdot/fusionamm-client";
|
|
13450
14234
|
import {
|
|
13451
|
-
AccountRole as
|
|
14235
|
+
AccountRole as AccountRole20,
|
|
13452
14236
|
lamports as lamports4
|
|
13453
14237
|
} from "@solana/kit";
|
|
13454
14238
|
import { fetchSysvarRent as fetchSysvarRent4 } from "@solana/sysvars";
|
|
13455
|
-
import { MEMO_PROGRAM_ADDRESS as
|
|
14239
|
+
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS24 } from "@solana-program/memo";
|
|
13456
14240
|
import {
|
|
13457
|
-
fetchAllMaybeMint as
|
|
13458
|
-
findAssociatedTokenPda as
|
|
14241
|
+
fetchAllMaybeMint as fetchAllMaybeMint25,
|
|
14242
|
+
findAssociatedTokenPda as findAssociatedTokenPda35,
|
|
13459
14243
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS21
|
|
13460
14244
|
} from "@solana-program/token-2022";
|
|
13461
|
-
import
|
|
14245
|
+
import assert25 from "assert";
|
|
13462
14246
|
async function rebalanceTunaLpPositionFusionInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
13463
14247
|
const rent = await fetchSysvarRent4(rpc);
|
|
13464
14248
|
let nonRefundableRent = 0n;
|
|
@@ -13471,9 +14255,9 @@ async function rebalanceTunaLpPositionFusionInstructions(rpc, authority, positio
|
|
|
13471
14255
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
13472
14256
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
13473
14257
|
]);
|
|
13474
|
-
const [mintA, mintB] = await
|
|
13475
|
-
|
|
13476
|
-
|
|
14258
|
+
const [mintA, mintB] = await fetchAllMaybeMint25(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
14259
|
+
assert25(mintA.exists, "Token A account not found");
|
|
14260
|
+
assert25(mintB.exists, "Token B account not found");
|
|
13477
14261
|
const instructions = [];
|
|
13478
14262
|
if (!createInstructions) createInstructions = instructions;
|
|
13479
14263
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
@@ -13540,27 +14324,27 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13540
14324
|
const positionMint = tunaPosition.data.positionMint;
|
|
13541
14325
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
13542
14326
|
const fusionPositionAddress = (await getPositionAddress20(positionMint))[0];
|
|
13543
|
-
const tunaPositionAta = (await
|
|
14327
|
+
const tunaPositionAta = (await findAssociatedTokenPda35({
|
|
13544
14328
|
owner: tunaPosition.address,
|
|
13545
14329
|
mint: positionMint,
|
|
13546
14330
|
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS21
|
|
13547
14331
|
}))[0];
|
|
13548
|
-
const tunaPositionAtaA = (await
|
|
14332
|
+
const tunaPositionAtaA = (await findAssociatedTokenPda35({
|
|
13549
14333
|
owner: tunaPosition.address,
|
|
13550
14334
|
mint: mintA.address,
|
|
13551
14335
|
tokenProgram: mintA.programAddress
|
|
13552
14336
|
}))[0];
|
|
13553
|
-
const tunaPositionAtaB = (await
|
|
14337
|
+
const tunaPositionAtaB = (await findAssociatedTokenPda35({
|
|
13554
14338
|
owner: tunaPosition.address,
|
|
13555
14339
|
mint: mintB.address,
|
|
13556
14340
|
tokenProgram: mintB.programAddress
|
|
13557
14341
|
}))[0];
|
|
13558
|
-
const feeRecipientAtaA = (await
|
|
14342
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda35({
|
|
13559
14343
|
owner: tunaConfig.data.feeRecipient,
|
|
13560
14344
|
mint: mintA.address,
|
|
13561
14345
|
tokenProgram: mintA.programAddress
|
|
13562
14346
|
}))[0];
|
|
13563
|
-
const feeRecipientAtaB = (await
|
|
14347
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda35({
|
|
13564
14348
|
owner: tunaConfig.data.feeRecipient,
|
|
13565
14349
|
mint: mintB.address,
|
|
13566
14350
|
tokenProgram: mintB.programAddress
|
|
@@ -13576,17 +14360,17 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13576
14360
|
);
|
|
13577
14361
|
const secondaryTickArrays = await FusionUtils.getTickArraysForRebalancedPosition(fusionPool, tunaPosition);
|
|
13578
14362
|
const remainingAccounts = [
|
|
13579
|
-
{ address: swapTickArrays[0], role:
|
|
13580
|
-
{ address: swapTickArrays[1], role:
|
|
13581
|
-
{ address: swapTickArrays[2], role:
|
|
13582
|
-
{ address: swapTickArrays[3], role:
|
|
13583
|
-
{ address: swapTickArrays[4], role:
|
|
13584
|
-
{ address: lowerTickArrayAddress, role:
|
|
13585
|
-
{ address: upperTickArrayAddress, role:
|
|
13586
|
-
{ address: secondaryTickArrays.lowerTickArrayAddress, role:
|
|
13587
|
-
{ address: secondaryTickArrays.upperTickArrayAddress, role:
|
|
13588
|
-
{ address: fusionPool.data.tokenVaultA, role:
|
|
13589
|
-
{ address: fusionPool.data.tokenVaultB, role:
|
|
14363
|
+
{ address: swapTickArrays[0], role: AccountRole20.WRITABLE },
|
|
14364
|
+
{ address: swapTickArrays[1], role: AccountRole20.WRITABLE },
|
|
14365
|
+
{ address: swapTickArrays[2], role: AccountRole20.WRITABLE },
|
|
14366
|
+
{ address: swapTickArrays[3], role: AccountRole20.WRITABLE },
|
|
14367
|
+
{ address: swapTickArrays[4], role: AccountRole20.WRITABLE },
|
|
14368
|
+
{ address: lowerTickArrayAddress, role: AccountRole20.WRITABLE },
|
|
14369
|
+
{ address: upperTickArrayAddress, role: AccountRole20.WRITABLE },
|
|
14370
|
+
{ address: secondaryTickArrays.lowerTickArrayAddress, role: AccountRole20.WRITABLE },
|
|
14371
|
+
{ address: secondaryTickArrays.upperTickArrayAddress, role: AccountRole20.WRITABLE },
|
|
14372
|
+
{ address: fusionPool.data.tokenVaultA, role: AccountRole20.WRITABLE },
|
|
14373
|
+
{ address: fusionPool.data.tokenVaultB, role: AccountRole20.WRITABLE }
|
|
13590
14374
|
];
|
|
13591
14375
|
const remainingAccountsInfo = {
|
|
13592
14376
|
slices: [
|
|
@@ -13620,7 +14404,7 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
13620
14404
|
fusionammProgram: FUSIONAMM_PROGRAM_ADDRESS14,
|
|
13621
14405
|
tokenProgramA: mintA.programAddress,
|
|
13622
14406
|
tokenProgramB: mintB.programAddress,
|
|
13623
|
-
memoProgram:
|
|
14407
|
+
memoProgram: MEMO_PROGRAM_ADDRESS24,
|
|
13624
14408
|
remainingAccountsInfo
|
|
13625
14409
|
});
|
|
13626
14410
|
ix.accounts.push(...remainingAccounts);
|
|
@@ -14171,6 +14955,8 @@ export {
|
|
|
14171
14955
|
liquidateTunaSpotPositionOrcaInstructions,
|
|
14172
14956
|
modifyTunaSpotPositionFusionInstruction,
|
|
14173
14957
|
modifyTunaSpotPositionFusionInstructions,
|
|
14958
|
+
modifyTunaSpotPositionJupiterInstruction,
|
|
14959
|
+
modifyTunaSpotPositionJupiterInstructions,
|
|
14174
14960
|
modifyTunaSpotPositionOrcaInstruction,
|
|
14175
14961
|
modifyTunaSpotPositionOrcaInstructions,
|
|
14176
14962
|
mulDiv,
|