@crypticdot/defituna-client 3.1.3 → 3.1.5
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 +53 -6
- package/dist/index.d.ts +53 -6
- package/dist/index.js +229 -119
- package/dist/index.mjs +233 -123
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -325,6 +325,7 @@ __export(index_exports, {
|
|
|
325
325
|
getCreateVaultInstructionDataCodec: () => getCreateVaultInstructionDataCodec,
|
|
326
326
|
getCreateVaultInstructionDataDecoder: () => getCreateVaultInstructionDataDecoder,
|
|
327
327
|
getCreateVaultInstructionDataEncoder: () => getCreateVaultInstructionDataEncoder,
|
|
328
|
+
getDecreaseSpotPositionQuote: () => getDecreaseSpotPositionQuote,
|
|
328
329
|
getDecreaseTunaLpPositionFusionDiscriminatorBytes: () => getDecreaseTunaLpPositionFusionDiscriminatorBytes,
|
|
329
330
|
getDecreaseTunaLpPositionFusionInstruction: () => getDecreaseTunaLpPositionFusionInstruction,
|
|
330
331
|
getDecreaseTunaLpPositionFusionInstructionDataCodec: () => getDecreaseTunaLpPositionFusionInstructionDataCodec,
|
|
@@ -10297,7 +10298,7 @@ function getIncreaseSpotPositionQuote(args) {
|
|
|
10297
10298
|
leverage,
|
|
10298
10299
|
protocolFeeRate,
|
|
10299
10300
|
protocolFeeRateOnCollateral,
|
|
10300
|
-
|
|
10301
|
+
increaseAmount,
|
|
10301
10302
|
collateralToken,
|
|
10302
10303
|
positionToken
|
|
10303
10304
|
} = args;
|
|
@@ -10310,52 +10311,48 @@ function getIncreaseSpotPositionQuote(args) {
|
|
|
10310
10311
|
if (protocolFeeRateOnCollateral < 0) {
|
|
10311
10312
|
throw new Error("protocolFeeRate must be greater or equal than zero");
|
|
10312
10313
|
}
|
|
10313
|
-
if (
|
|
10314
|
-
throw new Error("
|
|
10315
|
-
}
|
|
10316
|
-
if (totalAmount == 0n) {
|
|
10317
|
-
return {
|
|
10318
|
-
collateral: 0n,
|
|
10319
|
-
borrow: 0n,
|
|
10320
|
-
protocolFeeA: 0n,
|
|
10321
|
-
protocolFeeB: 0n,
|
|
10322
|
-
priceImpact: 0
|
|
10323
|
-
};
|
|
10314
|
+
if (increaseAmount <= 0) {
|
|
10315
|
+
throw new Error("increaseAmount must be greater than zero");
|
|
10324
10316
|
}
|
|
10325
10317
|
let borrow;
|
|
10326
10318
|
let collateral;
|
|
10319
|
+
let estimatedAmount;
|
|
10327
10320
|
let nextSqrtPrice = fusionPool.sqrtPrice;
|
|
10328
10321
|
if (positionToken != collateralToken) {
|
|
10329
10322
|
const price = (0, import_fusionamm_core4.sqrtPriceToPrice)(fusionPool.sqrtPrice, 1, 1);
|
|
10330
|
-
|
|
10331
|
-
|
|
10323
|
+
collateral = leverage > 1 ? BigInt(Math.floor(Number(increaseAmount) / leverage)) : increaseAmount;
|
|
10324
|
+
borrow = increaseAmount - collateral;
|
|
10325
|
+
estimatedAmount = BigInt(
|
|
10326
|
+
Math.floor(collateralToken == 0 /* A */ ? Number(increaseAmount) * price : Number(increaseAmount) / price)
|
|
10332
10327
|
);
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10328
|
+
nextSqrtPrice = (0, import_fusionamm_core4.swapQuoteByInputToken)(
|
|
10329
|
+
increaseAmount,
|
|
10330
|
+
collateralToken == 0 /* A */,
|
|
10336
10331
|
0,
|
|
10337
10332
|
fusionPool,
|
|
10338
10333
|
tickArrays
|
|
10339
|
-
);
|
|
10340
|
-
nextSqrtPrice = swapQuote.nextSqrtPrice;
|
|
10341
|
-
const inputAmount = swapQuote.tokenEstIn;
|
|
10342
|
-
collateral = leverage > 1 ? BigInt(Math.floor(Number(inputAmount) / leverage)) : inputAmount;
|
|
10343
|
-
borrow = inputAmount - collateral;
|
|
10334
|
+
).nextSqrtPrice;
|
|
10344
10335
|
} else {
|
|
10345
10336
|
if (leverage > 1) {
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10337
|
+
const price = (0, import_fusionamm_core4.sqrtPriceToPrice)(fusionPool.sqrtPrice, 1, 1);
|
|
10338
|
+
collateral = BigInt(Math.floor(Number(increaseAmount) / leverage));
|
|
10339
|
+
borrow = BigInt(
|
|
10340
|
+
Math.floor(
|
|
10341
|
+
collateralToken == 0 /* A */ ? Number(increaseAmount - collateral) * price : Number(increaseAmount - collateral) / price
|
|
10342
|
+
)
|
|
10343
|
+
);
|
|
10344
|
+
estimatedAmount = increaseAmount;
|
|
10345
|
+
nextSqrtPrice = (0, import_fusionamm_core4.swapQuoteByOutputToken)(
|
|
10346
|
+
increaseAmount - collateral,
|
|
10349
10347
|
positionToken == 0 /* A */,
|
|
10350
10348
|
0,
|
|
10351
10349
|
fusionPool,
|
|
10352
10350
|
tickArrays
|
|
10353
|
-
);
|
|
10354
|
-
nextSqrtPrice = swapQuote.nextSqrtPrice;
|
|
10355
|
-
borrow = swapQuote.tokenEstIn;
|
|
10351
|
+
).nextSqrtPrice;
|
|
10356
10352
|
} else {
|
|
10357
|
-
collateral =
|
|
10353
|
+
collateral = increaseAmount;
|
|
10358
10354
|
borrow = 0n;
|
|
10355
|
+
estimatedAmount = increaseAmount;
|
|
10359
10356
|
}
|
|
10360
10357
|
}
|
|
10361
10358
|
const collateralExcludingFee = collateral;
|
|
@@ -10370,6 +10367,124 @@ function getIncreaseSpotPositionQuote(args) {
|
|
|
10370
10367
|
return {
|
|
10371
10368
|
collateral,
|
|
10372
10369
|
borrow,
|
|
10370
|
+
estimatedAmount,
|
|
10371
|
+
protocolFeeA,
|
|
10372
|
+
protocolFeeB,
|
|
10373
|
+
priceImpact
|
|
10374
|
+
};
|
|
10375
|
+
}
|
|
10376
|
+
function getDecreaseSpotPositionQuote(args) {
|
|
10377
|
+
const {
|
|
10378
|
+
fusionPool,
|
|
10379
|
+
tickArrays,
|
|
10380
|
+
leverage,
|
|
10381
|
+
protocolFeeRate,
|
|
10382
|
+
protocolFeeRateOnCollateral,
|
|
10383
|
+
decreaseAmount,
|
|
10384
|
+
collateralToken,
|
|
10385
|
+
positionToken,
|
|
10386
|
+
positionAmount,
|
|
10387
|
+
positionDebt,
|
|
10388
|
+
reduceOnly
|
|
10389
|
+
} = args;
|
|
10390
|
+
if (leverage < 1) {
|
|
10391
|
+
throw new Error("leverage must be greater or equal than 1.0");
|
|
10392
|
+
}
|
|
10393
|
+
if (protocolFeeRate < 0) {
|
|
10394
|
+
throw new Error("protocolFeeRate must be greater or equal than zero");
|
|
10395
|
+
}
|
|
10396
|
+
if (protocolFeeRateOnCollateral < 0) {
|
|
10397
|
+
throw new Error("protocolFeeRate must be greater or equal than zero");
|
|
10398
|
+
}
|
|
10399
|
+
if (decreaseAmount <= 0) {
|
|
10400
|
+
throw new Error("decreaseAmount must be greater than zero");
|
|
10401
|
+
}
|
|
10402
|
+
let collateral = 0n;
|
|
10403
|
+
let borrow = 0n;
|
|
10404
|
+
let estimatedAmount = 0n;
|
|
10405
|
+
let nextSqrtPrice = fusionPool.sqrtPrice;
|
|
10406
|
+
let newPositionToken = positionToken;
|
|
10407
|
+
let decreasePercent;
|
|
10408
|
+
const price = (0, import_fusionamm_core4.sqrtPriceToPrice)(fusionPool.sqrtPrice, 1, 1);
|
|
10409
|
+
if (decreaseAmount <= positionAmount || reduceOnly) {
|
|
10410
|
+
let decreaseAmountInPositionToken;
|
|
10411
|
+
if (collateralToken == positionToken) {
|
|
10412
|
+
decreaseAmountInPositionToken = decreaseAmount;
|
|
10413
|
+
} else {
|
|
10414
|
+
decreaseAmountInPositionToken = BigInt(
|
|
10415
|
+
Math.floor(collateralToken == 0 /* A */ ? Number(decreaseAmount) * price : Number(decreaseAmount) / price)
|
|
10416
|
+
);
|
|
10417
|
+
}
|
|
10418
|
+
decreasePercent = Math.min(
|
|
10419
|
+
Math.floor(Number(decreaseAmountInPositionToken) * HUNDRED_PERCENT / Number(positionAmount)),
|
|
10420
|
+
HUNDRED_PERCENT
|
|
10421
|
+
);
|
|
10422
|
+
const swapOut = BigInt(Math.floor(Number(positionDebt) * decreasePercent / HUNDRED_PERCENT));
|
|
10423
|
+
const swapQuote = (0, import_fusionamm_core4.swapQuoteByOutputToken)(swapOut, positionToken == 1 /* B */, 0, fusionPool, tickArrays);
|
|
10424
|
+
nextSqrtPrice = swapQuote.nextSqrtPrice;
|
|
10425
|
+
estimatedAmount = decreaseAmountInPositionToken <= positionAmount ? positionAmount - decreaseAmountInPositionToken : 0n;
|
|
10426
|
+
} else {
|
|
10427
|
+
decreasePercent = HUNDRED_PERCENT;
|
|
10428
|
+
const positionTokenIsA = positionToken == 0 /* A */;
|
|
10429
|
+
newPositionToken = positionToken == 0 /* A */ ? 1 /* B */ : 0 /* A */;
|
|
10430
|
+
const increaseAmount = decreaseAmount - positionAmount;
|
|
10431
|
+
if (positionToken == collateralToken) {
|
|
10432
|
+
estimatedAmount = BigInt(
|
|
10433
|
+
Math.floor(positionTokenIsA ? Number(increaseAmount) * price : Number(increaseAmount) / price)
|
|
10434
|
+
);
|
|
10435
|
+
collateral = leverage > 1 ? BigInt(Math.floor(Number(increaseAmount) / leverage)) : estimatedAmount;
|
|
10436
|
+
borrow = increaseAmount - collateral;
|
|
10437
|
+
const borrowInNewPositionToken = BigInt(
|
|
10438
|
+
Math.floor(positionTokenIsA ? Number(borrow) * price : Number(borrow) / price)
|
|
10439
|
+
);
|
|
10440
|
+
nextSqrtPrice = (0, import_fusionamm_core4.swapQuoteByInputToken)(
|
|
10441
|
+
positionDebt + borrowInNewPositionToken,
|
|
10442
|
+
!positionTokenIsA,
|
|
10443
|
+
0,
|
|
10444
|
+
fusionPool,
|
|
10445
|
+
tickArrays
|
|
10446
|
+
).nextSqrtPrice;
|
|
10447
|
+
} else {
|
|
10448
|
+
if (leverage > 1) {
|
|
10449
|
+
const collateralInPositionToken = BigInt(Math.floor(Number(increaseAmount) / leverage));
|
|
10450
|
+
borrow = increaseAmount - collateralInPositionToken;
|
|
10451
|
+
collateral = BigInt(
|
|
10452
|
+
Math.floor(
|
|
10453
|
+
positionToken == 0 /* A */ ? Number(collateralInPositionToken) * price : Number(collateralInPositionToken) / price
|
|
10454
|
+
)
|
|
10455
|
+
);
|
|
10456
|
+
const borrowInNewPositionToken = BigInt(
|
|
10457
|
+
Math.floor(newPositionToken == 1 /* B */ ? Number(borrow) * price : Number(borrow) / price)
|
|
10458
|
+
);
|
|
10459
|
+
estimatedAmount = collateral + borrowInNewPositionToken;
|
|
10460
|
+
nextSqrtPrice = (0, import_fusionamm_core4.swapQuoteByInputToken)(
|
|
10461
|
+
positionAmount + borrow,
|
|
10462
|
+
positionTokenIsA,
|
|
10463
|
+
0,
|
|
10464
|
+
fusionPool,
|
|
10465
|
+
tickArrays
|
|
10466
|
+
).nextSqrtPrice;
|
|
10467
|
+
} else {
|
|
10468
|
+
collateral = increaseAmount;
|
|
10469
|
+
borrow = 0n;
|
|
10470
|
+
}
|
|
10471
|
+
}
|
|
10472
|
+
}
|
|
10473
|
+
const collateralExcludingFee = collateral;
|
|
10474
|
+
const borrowExcludingFee = borrow;
|
|
10475
|
+
collateral = reverseApplyTunaProtocolFee(collateral, protocolFeeRateOnCollateral);
|
|
10476
|
+
borrow = reverseApplyTunaProtocolFee(borrow, protocolFeeRate);
|
|
10477
|
+
const protocolFeeA = (collateralToken == 0 /* A */ ? collateral - collateralExcludingFee : 0n) + (positionToken == 1 /* B */ ? borrow - borrowExcludingFee : 0n);
|
|
10478
|
+
const protocolFeeB = (collateralToken == 1 /* B */ ? collateral - collateralExcludingFee : 0n) + (positionToken == 0 /* A */ ? borrow - borrowExcludingFee : 0n);
|
|
10479
|
+
const newPrice = (0, import_fusionamm_core4.sqrtPriceToPrice)(nextSqrtPrice, 1, 1);
|
|
10480
|
+
const priceImpact = Math.abs(newPrice / price - 1) * 100;
|
|
10481
|
+
return {
|
|
10482
|
+
decreasePercent,
|
|
10483
|
+
collateralToken,
|
|
10484
|
+
positionToken: newPositionToken,
|
|
10485
|
+
collateral,
|
|
10486
|
+
estimatedAmount,
|
|
10487
|
+
borrow,
|
|
10373
10488
|
protocolFeeA,
|
|
10374
10489
|
protocolFeeB,
|
|
10375
10490
|
priceImpact
|
|
@@ -11765,30 +11880,42 @@ async function closeActiveTunaSpotPositionFusionInstructions(rpc, authority, fus
|
|
|
11765
11880
|
const instructions = [];
|
|
11766
11881
|
if (!createInstructions) createInstructions = instructions;
|
|
11767
11882
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
11768
|
-
const
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11883
|
+
const tunaPositionAtaAAddress = (await (0, import_token_202213.findAssociatedTokenPda)({
|
|
11884
|
+
owner: tunaPosition.address,
|
|
11885
|
+
mint: mintA.address,
|
|
11886
|
+
tokenProgram: mintA.programAddress
|
|
11887
|
+
}))[0];
|
|
11888
|
+
const tunaPositionAtaBAddress = (await (0, import_token_202213.findAssociatedTokenPda)({
|
|
11889
|
+
owner: tunaPosition.address,
|
|
11890
|
+
mint: mintB.address,
|
|
11891
|
+
tokenProgram: mintB.programAddress
|
|
11892
|
+
}))[0];
|
|
11893
|
+
const [tunaPositionAtaA, tunaPositionAtaB] = await (0, import_token_202213.fetchAllToken)(rpc, [
|
|
11894
|
+
tunaPositionAtaAAddress,
|
|
11895
|
+
tunaPositionAtaBAddress
|
|
11896
|
+
]);
|
|
11897
|
+
const createUserAtaAInstructions = tunaPosition.data.collateralToken == 0 /* A */ || tunaPositionAtaA.data.amount > (tunaPosition.data.positionToken == 0 /* A */ ? tunaPosition.data.amount : 0n) ? await getCreateAtaInstructions(rpc, authority, mintA.address, authority.address, mintA.programAddress) : void 0;
|
|
11898
|
+
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
11899
|
+
const createUserAtaBInstructions = tunaPosition.data.collateralToken == 1 /* B */ || tunaPositionAtaB.data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n) ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
11900
|
+
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
11777
11901
|
const ix = await closeActiveTunaSpotPositionFusionInstruction(
|
|
11778
11902
|
authority,
|
|
11779
|
-
tunaPosition
|
|
11903
|
+
tunaPosition,
|
|
11780
11904
|
mintA,
|
|
11781
11905
|
mintB,
|
|
11782
11906
|
vaultA,
|
|
11783
11907
|
vaultB,
|
|
11784
11908
|
fusionPool,
|
|
11909
|
+
createUserAtaAInstructions != void 0,
|
|
11910
|
+
createUserAtaBInstructions != void 0,
|
|
11785
11911
|
{ ...args }
|
|
11786
11912
|
);
|
|
11787
11913
|
instructions.push(ix);
|
|
11788
|
-
cleanupInstructions.push(...
|
|
11914
|
+
if (createUserAtaAInstructions) cleanupInstructions.push(...createUserAtaAInstructions.cleanup);
|
|
11915
|
+
if (createUserAtaBInstructions) cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
11789
11916
|
return instructions;
|
|
11790
11917
|
}
|
|
11791
|
-
async function closeActiveTunaSpotPositionFusionInstruction(authority,
|
|
11918
|
+
async function closeActiveTunaSpotPositionFusionInstruction(authority, tunaPosition, mintA, mintB, vaultA, vaultB, fusionPool, setTunaPositionOwnerAtaA, setTunaPositionOwnerAtaB, args) {
|
|
11792
11919
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
11793
11920
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
11794
11921
|
const tunaPositionOwnerAtaA = (await (0, import_token_202213.findAssociatedTokenPda)({
|
|
@@ -11802,12 +11929,12 @@ async function closeActiveTunaSpotPositionFusionInstruction(authority, tunaPosit
|
|
|
11802
11929
|
tokenProgram: mintB.programAddress
|
|
11803
11930
|
}))[0];
|
|
11804
11931
|
const tunaPositionAtaA = (await (0, import_token_202213.findAssociatedTokenPda)({
|
|
11805
|
-
owner:
|
|
11932
|
+
owner: tunaPosition.address,
|
|
11806
11933
|
mint: mintA.address,
|
|
11807
11934
|
tokenProgram: mintA.programAddress
|
|
11808
11935
|
}))[0];
|
|
11809
11936
|
const tunaPositionAtaB = (await (0, import_token_202213.findAssociatedTokenPda)({
|
|
11810
|
-
owner:
|
|
11937
|
+
owner: tunaPosition.address,
|
|
11811
11938
|
mint: mintB.address,
|
|
11812
11939
|
tokenProgram: mintB.programAddress
|
|
11813
11940
|
}))[0];
|
|
@@ -11852,9 +11979,9 @@ async function closeActiveTunaSpotPositionFusionInstruction(authority, tunaPosit
|
|
|
11852
11979
|
tunaConfig,
|
|
11853
11980
|
tunaPositionAtaA,
|
|
11854
11981
|
tunaPositionAtaB,
|
|
11855
|
-
tunaPositionOwnerAtaA,
|
|
11856
|
-
tunaPositionOwnerAtaB,
|
|
11857
|
-
tunaPosition:
|
|
11982
|
+
...setTunaPositionOwnerAtaA && { tunaPositionOwnerAtaA },
|
|
11983
|
+
...setTunaPositionOwnerAtaB && { tunaPositionOwnerAtaB },
|
|
11984
|
+
tunaPosition: tunaPosition.address,
|
|
11858
11985
|
fusionPool: fusionPool.address,
|
|
11859
11986
|
fusionammProgram: import_fusionamm_client7.FUSIONAMM_PROGRAM_ADDRESS,
|
|
11860
11987
|
tokenProgramA: mintA.programAddress,
|
|
@@ -11889,30 +12016,42 @@ async function closeActiveTunaSpotPositionOrcaInstructions(rpc, authority, whirl
|
|
|
11889
12016
|
const instructions = [];
|
|
11890
12017
|
if (!createInstructions) createInstructions = instructions;
|
|
11891
12018
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
11892
|
-
const
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11900
|
-
|
|
12019
|
+
const tunaPositionAtaAAddress = (await (0, import_token_202214.findAssociatedTokenPda)({
|
|
12020
|
+
owner: tunaPosition.address,
|
|
12021
|
+
mint: mintA.address,
|
|
12022
|
+
tokenProgram: mintA.programAddress
|
|
12023
|
+
}))[0];
|
|
12024
|
+
const tunaPositionAtaBAddress = (await (0, import_token_202214.findAssociatedTokenPda)({
|
|
12025
|
+
owner: tunaPosition.address,
|
|
12026
|
+
mint: mintB.address,
|
|
12027
|
+
tokenProgram: mintB.programAddress
|
|
12028
|
+
}))[0];
|
|
12029
|
+
const [tunaPositionAtaA, tunaPositionAtaB] = await (0, import_token_202214.fetchAllToken)(rpc, [
|
|
12030
|
+
tunaPositionAtaAAddress,
|
|
12031
|
+
tunaPositionAtaBAddress
|
|
12032
|
+
]);
|
|
12033
|
+
const createUserAtaAInstructions = tunaPosition.data.collateralToken == 0 /* A */ || tunaPositionAtaA.data.amount > (tunaPosition.data.positionToken == 0 /* A */ ? tunaPosition.data.amount : 0n) ? await getCreateAtaInstructions(rpc, authority, mintA.address, authority.address, mintA.programAddress) : void 0;
|
|
12034
|
+
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
12035
|
+
const createUserAtaBInstructions = tunaPosition.data.collateralToken == 1 /* B */ || tunaPositionAtaB.data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n) ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
12036
|
+
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
11901
12037
|
const ix = await closeActiveTunaSpotPositionOrcaInstruction(
|
|
11902
12038
|
authority,
|
|
11903
|
-
tunaPosition
|
|
12039
|
+
tunaPosition,
|
|
11904
12040
|
mintA,
|
|
11905
12041
|
mintB,
|
|
11906
12042
|
vaultA,
|
|
11907
12043
|
vaultB,
|
|
11908
12044
|
whirlpool,
|
|
12045
|
+
createUserAtaAInstructions != void 0,
|
|
12046
|
+
createUserAtaBInstructions != void 0,
|
|
11909
12047
|
{ ...args }
|
|
11910
12048
|
);
|
|
11911
12049
|
instructions.push(ix);
|
|
11912
|
-
cleanupInstructions.push(...
|
|
12050
|
+
if (createUserAtaAInstructions) cleanupInstructions.push(...createUserAtaAInstructions.cleanup);
|
|
12051
|
+
if (createUserAtaBInstructions) cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
11913
12052
|
return instructions;
|
|
11914
12053
|
}
|
|
11915
|
-
async function closeActiveTunaSpotPositionOrcaInstruction(authority,
|
|
12054
|
+
async function closeActiveTunaSpotPositionOrcaInstruction(authority, tunaPosition, mintA, mintB, vaultA, vaultB, whirlpool, setTunaPositionOwnerAtaA, setTunaPositionOwnerAtaB, args) {
|
|
11916
12055
|
const tunaConfig = (await getTunaConfigAddress())[0];
|
|
11917
12056
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
11918
12057
|
const orcaOracleAddress = (await (0, import_whirlpools_client7.getOracleAddress)(whirlpool.address))[0];
|
|
@@ -11927,12 +12066,12 @@ async function closeActiveTunaSpotPositionOrcaInstruction(authority, tunaPositio
|
|
|
11927
12066
|
tokenProgram: mintB.programAddress
|
|
11928
12067
|
}))[0];
|
|
11929
12068
|
const tunaPositionAtaA = (await (0, import_token_202214.findAssociatedTokenPda)({
|
|
11930
|
-
owner:
|
|
12069
|
+
owner: tunaPosition.address,
|
|
11931
12070
|
mint: mintA.address,
|
|
11932
12071
|
tokenProgram: mintA.programAddress
|
|
11933
12072
|
}))[0];
|
|
11934
12073
|
const tunaPositionAtaB = (await (0, import_token_202214.findAssociatedTokenPda)({
|
|
11935
|
-
owner:
|
|
12074
|
+
owner: tunaPosition.address,
|
|
11936
12075
|
mint: mintB.address,
|
|
11937
12076
|
tokenProgram: mintB.programAddress
|
|
11938
12077
|
}))[0];
|
|
@@ -11979,9 +12118,9 @@ async function closeActiveTunaSpotPositionOrcaInstruction(authority, tunaPositio
|
|
|
11979
12118
|
tunaConfig,
|
|
11980
12119
|
tunaPositionAtaA,
|
|
11981
12120
|
tunaPositionAtaB,
|
|
11982
|
-
tunaPositionOwnerAtaA,
|
|
11983
|
-
tunaPositionOwnerAtaB,
|
|
11984
|
-
tunaPosition:
|
|
12121
|
+
...setTunaPositionOwnerAtaA && { tunaPositionOwnerAtaA },
|
|
12122
|
+
...setTunaPositionOwnerAtaB && { tunaPositionOwnerAtaB },
|
|
12123
|
+
tunaPosition: tunaPosition.address,
|
|
11985
12124
|
whirlpool: whirlpool.address,
|
|
11986
12125
|
whirlpoolProgram: import_whirlpools_client7.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
11987
12126
|
tokenProgramA: mintA.programAddress,
|
|
@@ -12325,39 +12464,24 @@ async function decreaseTunaSpotPositionOrcaInstructions(rpc, authority, whirlpoo
|
|
|
12325
12464
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
12326
12465
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
12327
12466
|
]);
|
|
12328
|
-
const
|
|
12467
|
+
const tunaPositionAtaAAddress = (await (0, import_token_202217.findAssociatedTokenPda)({
|
|
12329
12468
|
owner: tunaPosition.address,
|
|
12330
12469
|
mint: mintA.address,
|
|
12331
12470
|
tokenProgram: mintA.programAddress
|
|
12332
12471
|
}))[0];
|
|
12333
|
-
const
|
|
12472
|
+
const tunaPositionAtaBAddress = (await (0, import_token_202217.findAssociatedTokenPda)({
|
|
12334
12473
|
owner: tunaPosition.address,
|
|
12335
12474
|
mint: mintB.address,
|
|
12336
12475
|
tokenProgram: mintB.programAddress
|
|
12337
12476
|
}))[0];
|
|
12338
|
-
const
|
|
12339
|
-
|
|
12340
|
-
|
|
12341
|
-
|
|
12342
|
-
|
|
12343
|
-
|
|
12344
|
-
|
|
12345
|
-
|
|
12346
|
-
mintA.programAddress
|
|
12347
|
-
);
|
|
12348
|
-
createInstructions.push(...createUserAtaAInstructions.init);
|
|
12349
|
-
}
|
|
12350
|
-
let createUserAtaBInstructions = void 0;
|
|
12351
|
-
if (tunaPosition.data.collateralToken == 1 /* B */ || tunaPositionTokenAccounts[1].data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n)) {
|
|
12352
|
-
createUserAtaBInstructions = await getCreateAtaInstructions(
|
|
12353
|
-
rpc,
|
|
12354
|
-
authority,
|
|
12355
|
-
mintB.address,
|
|
12356
|
-
authority.address,
|
|
12357
|
-
mintB.programAddress
|
|
12358
|
-
);
|
|
12359
|
-
createInstructions.push(...createUserAtaBInstructions.init);
|
|
12360
|
-
}
|
|
12477
|
+
const [tunaPositionAtaA, tunaPositionAtaB] = await (0, import_token_202217.fetchAllToken)(rpc, [
|
|
12478
|
+
tunaPositionAtaAAddress,
|
|
12479
|
+
tunaPositionAtaBAddress
|
|
12480
|
+
]);
|
|
12481
|
+
const createUserAtaAInstructions = tunaPosition.data.collateralToken == 0 /* A */ || tunaPositionAtaA.data.amount > (tunaPosition.data.positionToken == 0 /* A */ ? tunaPosition.data.amount : 0n) ? await getCreateAtaInstructions(rpc, authority, mintA.address, authority.address, mintA.programAddress) : void 0;
|
|
12482
|
+
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
12483
|
+
const createUserAtaBInstructions = tunaPosition.data.collateralToken == 1 /* B */ || tunaPositionAtaB.data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n) ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
12484
|
+
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
12361
12485
|
const ix = await decreaseTunaSpotPositionOrcaInstruction(
|
|
12362
12486
|
authority,
|
|
12363
12487
|
tunaPosition,
|
|
@@ -12376,7 +12500,7 @@ async function decreaseTunaSpotPositionOrcaInstructions(rpc, authority, whirlpoo
|
|
|
12376
12500
|
if (createUserAtaBInstructions) cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
12377
12501
|
return instructions;
|
|
12378
12502
|
}
|
|
12379
|
-
async function decreaseTunaSpotPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool,
|
|
12503
|
+
async function decreaseTunaSpotPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, setTunaPositionOwnerAtaA, setTunaPositionOwnerAtaB, args) {
|
|
12380
12504
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
12381
12505
|
const orcaOracleAddress = (await (0, import_whirlpools_client9.getOracleAddress)(whirlpool.address))[0];
|
|
12382
12506
|
const tunaPositionOwnerAtaA = (await (0, import_token_202217.findAssociatedTokenPda)({
|
|
@@ -12445,8 +12569,8 @@ async function decreaseTunaSpotPositionOrcaInstruction(authority, tunaPosition,
|
|
|
12445
12569
|
tunaPosition: tunaPosition.address,
|
|
12446
12570
|
tunaPositionAtaA,
|
|
12447
12571
|
tunaPositionAtaB,
|
|
12448
|
-
|
|
12449
|
-
|
|
12572
|
+
...setTunaPositionOwnerAtaA && { tunaPositionOwnerAtaA },
|
|
12573
|
+
...setTunaPositionOwnerAtaB && { tunaPositionOwnerAtaB },
|
|
12450
12574
|
whirlpool: whirlpool.address,
|
|
12451
12575
|
whirlpoolProgram: import_whirlpools_client9.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
12452
12576
|
memoProgram: import_memo12.MEMO_PROGRAM_ADDRESS,
|
|
@@ -12479,39 +12603,24 @@ async function decreaseTunaSpotPositionFusionInstructions(rpc, authority, fusion
|
|
|
12479
12603
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
12480
12604
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
12481
12605
|
]);
|
|
12482
|
-
const
|
|
12606
|
+
const tunaPositionAtaAAddress = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
12483
12607
|
owner: tunaPosition.address,
|
|
12484
12608
|
mint: mintA.address,
|
|
12485
12609
|
tokenProgram: mintA.programAddress
|
|
12486
12610
|
}))[0];
|
|
12487
|
-
const
|
|
12611
|
+
const tunaPositionAtaBAddress = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
12488
12612
|
owner: tunaPosition.address,
|
|
12489
12613
|
mint: mintB.address,
|
|
12490
12614
|
tokenProgram: mintB.programAddress
|
|
12491
12615
|
}))[0];
|
|
12492
|
-
const
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
|
|
12498
|
-
|
|
12499
|
-
|
|
12500
|
-
mintA.programAddress
|
|
12501
|
-
);
|
|
12502
|
-
createInstructions.push(...createUserAtaAInstructions.init);
|
|
12503
|
-
}
|
|
12504
|
-
let createUserAtaBInstructions = void 0;
|
|
12505
|
-
if (tunaPosition.data.collateralToken == 1 /* B */ || tunaPositionTokenAccounts[1].data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n)) {
|
|
12506
|
-
createUserAtaBInstructions = await getCreateAtaInstructions(
|
|
12507
|
-
rpc,
|
|
12508
|
-
authority,
|
|
12509
|
-
mintB.address,
|
|
12510
|
-
authority.address,
|
|
12511
|
-
mintB.programAddress
|
|
12512
|
-
);
|
|
12513
|
-
createInstructions.push(...createUserAtaBInstructions.init);
|
|
12514
|
-
}
|
|
12616
|
+
const [tunaPositionAtaA, tunaPositionAtaB] = await (0, import_token_202218.fetchAllToken)(rpc, [
|
|
12617
|
+
tunaPositionAtaAAddress,
|
|
12618
|
+
tunaPositionAtaBAddress
|
|
12619
|
+
]);
|
|
12620
|
+
const createUserAtaAInstructions = tunaPosition.data.collateralToken == 0 /* A */ || tunaPositionAtaA.data.amount > (tunaPosition.data.positionToken == 0 /* A */ ? tunaPosition.data.amount : 0n) ? await getCreateAtaInstructions(rpc, authority, mintA.address, authority.address, mintA.programAddress) : void 0;
|
|
12621
|
+
if (createUserAtaAInstructions) createInstructions.push(...createUserAtaAInstructions.init);
|
|
12622
|
+
const createUserAtaBInstructions = tunaPosition.data.collateralToken == 1 /* B */ || tunaPositionAtaB.data.amount > (tunaPosition.data.positionToken == 1 /* B */ ? tunaPosition.data.amount : 0n) ? await getCreateAtaInstructions(rpc, authority, mintB.address, authority.address, mintB.programAddress) : void 0;
|
|
12623
|
+
if (createUserAtaBInstructions) createInstructions.push(...createUserAtaBInstructions.init);
|
|
12515
12624
|
const ix = await decreaseTunaSpotPositionFusionInstruction(
|
|
12516
12625
|
authority,
|
|
12517
12626
|
tunaPosition,
|
|
@@ -12530,7 +12639,7 @@ async function decreaseTunaSpotPositionFusionInstructions(rpc, authority, fusion
|
|
|
12530
12639
|
if (createUserAtaBInstructions) cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
12531
12640
|
return instructions;
|
|
12532
12641
|
}
|
|
12533
|
-
async function decreaseTunaSpotPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool,
|
|
12642
|
+
async function decreaseTunaSpotPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, setTunaPositionOwnerAtaA, setTunaPositionOwnerAtaB, args) {
|
|
12534
12643
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
12535
12644
|
const tunaPositionOwnerAtaA = (await (0, import_token_202218.findAssociatedTokenPda)({
|
|
12536
12645
|
owner: authority.address,
|
|
@@ -12596,8 +12705,8 @@ async function decreaseTunaSpotPositionFusionInstruction(authority, tunaPosition
|
|
|
12596
12705
|
tunaPosition: tunaPosition.address,
|
|
12597
12706
|
tunaPositionAtaA,
|
|
12598
12707
|
tunaPositionAtaB,
|
|
12599
|
-
|
|
12600
|
-
|
|
12708
|
+
...setTunaPositionOwnerAtaA && { tunaPositionOwnerAtaA },
|
|
12709
|
+
...setTunaPositionOwnerAtaB && { tunaPositionOwnerAtaB },
|
|
12601
12710
|
fusionPool: fusionPool.address,
|
|
12602
12711
|
fusionammProgram: import_fusionamm_client9.FUSIONAMM_PROGRAM_ADDRESS,
|
|
12603
12712
|
memoProgram: import_memo13.MEMO_PROGRAM_ADDRESS,
|
|
@@ -15606,6 +15715,7 @@ async function rebalanceTunaLpPositionFusionInstruction(authority, tunaPosition,
|
|
|
15606
15715
|
getCreateVaultInstructionDataCodec,
|
|
15607
15716
|
getCreateVaultInstructionDataDecoder,
|
|
15608
15717
|
getCreateVaultInstructionDataEncoder,
|
|
15718
|
+
getDecreaseSpotPositionQuote,
|
|
15609
15719
|
getDecreaseTunaLpPositionFusionDiscriminatorBytes,
|
|
15610
15720
|
getDecreaseTunaLpPositionFusionInstruction,
|
|
15611
15721
|
getDecreaseTunaLpPositionFusionInstructionDataCodec,
|