@crypticdot/defituna-client 3.1.0 → 3.1.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 +86 -39
- package/dist/index.d.ts +86 -39
- package/dist/index.js +251 -34
- package/dist/index.mjs +246 -28
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -692,7 +692,6 @@ function getTunaSpotPositionEncoder() {
|
|
|
692
692
|
["positionToken", getPoolTokenEncoder()],
|
|
693
693
|
["collateralToken", getPoolTokenEncoder()],
|
|
694
694
|
["flags", getU32Encoder4()],
|
|
695
|
-
["state", getTunaPositionStateEncoder()],
|
|
696
695
|
["amount", getU64Encoder4()],
|
|
697
696
|
["loanShares", getU64Encoder4()],
|
|
698
697
|
["loanFunds", getU64Encoder4()],
|
|
@@ -717,7 +716,6 @@ function getTunaSpotPositionDecoder() {
|
|
|
717
716
|
["positionToken", getPoolTokenDecoder()],
|
|
718
717
|
["collateralToken", getPoolTokenDecoder()],
|
|
719
718
|
["flags", getU32Decoder4()],
|
|
720
|
-
["state", getTunaPositionStateDecoder()],
|
|
721
719
|
["amount", getU64Decoder4()],
|
|
722
720
|
["loanShares", getU64Decoder4()],
|
|
723
721
|
["loanFunds", getU64Decoder4()],
|
|
@@ -764,7 +762,7 @@ async function fetchAllMaybeTunaSpotPosition(rpc, addresses, config) {
|
|
|
764
762
|
);
|
|
765
763
|
}
|
|
766
764
|
function getTunaSpotPositionSize() {
|
|
767
|
-
return
|
|
765
|
+
return 346;
|
|
768
766
|
}
|
|
769
767
|
|
|
770
768
|
// src/generated/accounts/vault.ts
|
|
@@ -5719,6 +5717,18 @@ function getLiquidateTunaSpotPositionFusionInstruction(input, config) {
|
|
|
5719
5717
|
value: input.feeRecipientAtaB ?? null,
|
|
5720
5718
|
isWritable: true
|
|
5721
5719
|
},
|
|
5720
|
+
tunaPositionOwner: {
|
|
5721
|
+
value: input.tunaPositionOwner ?? null,
|
|
5722
|
+
isWritable: true
|
|
5723
|
+
},
|
|
5724
|
+
tunaPositionOwnerAtaA: {
|
|
5725
|
+
value: input.tunaPositionOwnerAtaA ?? null,
|
|
5726
|
+
isWritable: true
|
|
5727
|
+
},
|
|
5728
|
+
tunaPositionOwnerAtaB: {
|
|
5729
|
+
value: input.tunaPositionOwnerAtaB ?? null,
|
|
5730
|
+
isWritable: true
|
|
5731
|
+
},
|
|
5722
5732
|
pythOraclePriceFeedA: {
|
|
5723
5733
|
value: input.pythOraclePriceFeedA ?? null,
|
|
5724
5734
|
isWritable: false
|
|
@@ -5759,6 +5769,9 @@ function getLiquidateTunaSpotPositionFusionInstruction(input, config) {
|
|
|
5759
5769
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
5760
5770
|
getAccountMeta(accounts.feeRecipientAtaA),
|
|
5761
5771
|
getAccountMeta(accounts.feeRecipientAtaB),
|
|
5772
|
+
getAccountMeta(accounts.tunaPositionOwner),
|
|
5773
|
+
getAccountMeta(accounts.tunaPositionOwnerAtaA),
|
|
5774
|
+
getAccountMeta(accounts.tunaPositionOwnerAtaB),
|
|
5762
5775
|
getAccountMeta(accounts.pythOraclePriceFeedA),
|
|
5763
5776
|
getAccountMeta(accounts.pythOraclePriceFeedB),
|
|
5764
5777
|
getAccountMeta(accounts.fusionammProgram),
|
|
@@ -5774,7 +5787,7 @@ function getLiquidateTunaSpotPositionFusionInstruction(input, config) {
|
|
|
5774
5787
|
return instruction;
|
|
5775
5788
|
}
|
|
5776
5789
|
function parseLiquidateTunaSpotPositionFusionInstruction(instruction) {
|
|
5777
|
-
if (instruction.accounts.length <
|
|
5790
|
+
if (instruction.accounts.length < 25) {
|
|
5778
5791
|
throw new Error("Not enough accounts");
|
|
5779
5792
|
}
|
|
5780
5793
|
let accountIndex = 0;
|
|
@@ -5783,6 +5796,10 @@ function parseLiquidateTunaSpotPositionFusionInstruction(instruction) {
|
|
|
5783
5796
|
accountIndex += 1;
|
|
5784
5797
|
return accountMeta;
|
|
5785
5798
|
};
|
|
5799
|
+
const getNextOptionalAccount = () => {
|
|
5800
|
+
const accountMeta = getNextAccount();
|
|
5801
|
+
return accountMeta.address === TUNA_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
5802
|
+
};
|
|
5786
5803
|
return {
|
|
5787
5804
|
programAddress: instruction.programAddress,
|
|
5788
5805
|
accounts: {
|
|
@@ -5802,6 +5819,9 @@ function parseLiquidateTunaSpotPositionFusionInstruction(instruction) {
|
|
|
5802
5819
|
tunaPositionAtaB: getNextAccount(),
|
|
5803
5820
|
feeRecipientAtaA: getNextAccount(),
|
|
5804
5821
|
feeRecipientAtaB: getNextAccount(),
|
|
5822
|
+
tunaPositionOwner: getNextAccount(),
|
|
5823
|
+
tunaPositionOwnerAtaA: getNextOptionalAccount(),
|
|
5824
|
+
tunaPositionOwnerAtaB: getNextOptionalAccount(),
|
|
5805
5825
|
pythOraclePriceFeedA: getNextAccount(),
|
|
5806
5826
|
pythOraclePriceFeedB: getNextAccount(),
|
|
5807
5827
|
fusionammProgram: getNextAccount(),
|
|
@@ -5900,6 +5920,18 @@ function getLiquidateTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
5900
5920
|
value: input.feeRecipientAtaB ?? null,
|
|
5901
5921
|
isWritable: true
|
|
5902
5922
|
},
|
|
5923
|
+
tunaPositionOwner: {
|
|
5924
|
+
value: input.tunaPositionOwner ?? null,
|
|
5925
|
+
isWritable: true
|
|
5926
|
+
},
|
|
5927
|
+
tunaPositionOwnerAtaA: {
|
|
5928
|
+
value: input.tunaPositionOwnerAtaA ?? null,
|
|
5929
|
+
isWritable: true
|
|
5930
|
+
},
|
|
5931
|
+
tunaPositionOwnerAtaB: {
|
|
5932
|
+
value: input.tunaPositionOwnerAtaB ?? null,
|
|
5933
|
+
isWritable: true
|
|
5934
|
+
},
|
|
5903
5935
|
pythOraclePriceFeedA: {
|
|
5904
5936
|
value: input.pythOraclePriceFeedA ?? null,
|
|
5905
5937
|
isWritable: false
|
|
@@ -5940,6 +5972,9 @@ function getLiquidateTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
5940
5972
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
5941
5973
|
getAccountMeta(accounts.feeRecipientAtaA),
|
|
5942
5974
|
getAccountMeta(accounts.feeRecipientAtaB),
|
|
5975
|
+
getAccountMeta(accounts.tunaPositionOwner),
|
|
5976
|
+
getAccountMeta(accounts.tunaPositionOwnerAtaA),
|
|
5977
|
+
getAccountMeta(accounts.tunaPositionOwnerAtaB),
|
|
5943
5978
|
getAccountMeta(accounts.pythOraclePriceFeedA),
|
|
5944
5979
|
getAccountMeta(accounts.pythOraclePriceFeedB),
|
|
5945
5980
|
getAccountMeta(accounts.whirlpoolProgram),
|
|
@@ -5955,7 +5990,7 @@ function getLiquidateTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
5955
5990
|
return instruction;
|
|
5956
5991
|
}
|
|
5957
5992
|
function parseLiquidateTunaSpotPositionOrcaInstruction(instruction) {
|
|
5958
|
-
if (instruction.accounts.length <
|
|
5993
|
+
if (instruction.accounts.length < 25) {
|
|
5959
5994
|
throw new Error("Not enough accounts");
|
|
5960
5995
|
}
|
|
5961
5996
|
let accountIndex = 0;
|
|
@@ -5964,6 +5999,10 @@ function parseLiquidateTunaSpotPositionOrcaInstruction(instruction) {
|
|
|
5964
5999
|
accountIndex += 1;
|
|
5965
6000
|
return accountMeta;
|
|
5966
6001
|
};
|
|
6002
|
+
const getNextOptionalAccount = () => {
|
|
6003
|
+
const accountMeta = getNextAccount();
|
|
6004
|
+
return accountMeta.address === TUNA_PROGRAM_ADDRESS ? void 0 : accountMeta;
|
|
6005
|
+
};
|
|
5967
6006
|
return {
|
|
5968
6007
|
programAddress: instruction.programAddress,
|
|
5969
6008
|
accounts: {
|
|
@@ -5983,6 +6022,9 @@ function parseLiquidateTunaSpotPositionOrcaInstruction(instruction) {
|
|
|
5983
6022
|
tunaPositionAtaB: getNextAccount(),
|
|
5984
6023
|
feeRecipientAtaA: getNextAccount(),
|
|
5985
6024
|
feeRecipientAtaB: getNextAccount(),
|
|
6025
|
+
tunaPositionOwner: getNextAccount(),
|
|
6026
|
+
tunaPositionOwnerAtaA: getNextOptionalAccount(),
|
|
6027
|
+
tunaPositionOwnerAtaB: getNextOptionalAccount(),
|
|
5986
6028
|
pythOraclePriceFeedA: getNextAccount(),
|
|
5987
6029
|
pythOraclePriceFeedB: getNextAccount(),
|
|
5988
6030
|
whirlpoolProgram: getNextAccount(),
|
|
@@ -10283,7 +10325,7 @@ async function createAddressLookupTableInstructions(authority, addresses, recent
|
|
|
10283
10325
|
authority,
|
|
10284
10326
|
payer: authority
|
|
10285
10327
|
});
|
|
10286
|
-
return { instructions: [createInstruction, extendInstruction], lookupTableAddress: pda[0] };
|
|
10328
|
+
return { instructions: [createInstruction, extendInstruction], lookupTableAddress: pda[0], addresses };
|
|
10287
10329
|
}
|
|
10288
10330
|
|
|
10289
10331
|
// src/utils/lpPositionMath.ts
|
|
@@ -10399,6 +10441,100 @@ function calculateProtocolFee(collateralAmount, borrowAmount, protocolFeeRateOnC
|
|
|
10399
10441
|
return collateralAmount * BigInt(protocolFeeRateOnCollateral) / BigInt(HUNDRED_PERCENT) + borrowAmount * BigInt(protocolFeeRate) / BigInt(HUNDRED_PERCENT);
|
|
10400
10442
|
}
|
|
10401
10443
|
|
|
10444
|
+
// src/utils/spotPositionMath.ts
|
|
10445
|
+
import {
|
|
10446
|
+
sqrtPriceToPrice,
|
|
10447
|
+
swapQuoteByOutputToken
|
|
10448
|
+
} from "@crypticdot/fusionamm-core";
|
|
10449
|
+
function getIncreaseSpotPositionQuote(args) {
|
|
10450
|
+
const {
|
|
10451
|
+
fusionPool,
|
|
10452
|
+
tickArrays,
|
|
10453
|
+
leverage,
|
|
10454
|
+
protocolFeeRate,
|
|
10455
|
+
protocolFeeRateOnCollateral,
|
|
10456
|
+
totalAmount,
|
|
10457
|
+
collateralToken,
|
|
10458
|
+
positionToken
|
|
10459
|
+
} = args;
|
|
10460
|
+
if (leverage < 1) {
|
|
10461
|
+
throw new Error("leverage must be greater or equal than 1.0");
|
|
10462
|
+
}
|
|
10463
|
+
if (protocolFeeRate < 0) {
|
|
10464
|
+
throw new Error("protocolFeeRate must be greater or equal than zero");
|
|
10465
|
+
}
|
|
10466
|
+
if (protocolFeeRateOnCollateral < 0) {
|
|
10467
|
+
throw new Error("protocolFeeRate must be greater or equal than zero");
|
|
10468
|
+
}
|
|
10469
|
+
if (totalAmount < 0) {
|
|
10470
|
+
throw new Error("totalAmount must be greater or equal than zero");
|
|
10471
|
+
}
|
|
10472
|
+
if (totalAmount == 0n) {
|
|
10473
|
+
return {
|
|
10474
|
+
collateral: 0n,
|
|
10475
|
+
borrow: 0n,
|
|
10476
|
+
protocolFeeA: 0n,
|
|
10477
|
+
protocolFeeB: 0n,
|
|
10478
|
+
priceImpact: 0
|
|
10479
|
+
};
|
|
10480
|
+
}
|
|
10481
|
+
let borrow;
|
|
10482
|
+
let collateral;
|
|
10483
|
+
let nextSqrtPrice = fusionPool.sqrtPrice;
|
|
10484
|
+
if (positionToken != collateralToken) {
|
|
10485
|
+
const price = sqrtPriceToPrice(fusionPool.sqrtPrice, 1, 1);
|
|
10486
|
+
const totalAmountInOppositeToken = BigInt(
|
|
10487
|
+
Math.floor(positionToken == 0 /* A */ ? Number(totalAmount) / price : Number(totalAmount) * price)
|
|
10488
|
+
);
|
|
10489
|
+
const swapQuote = swapQuoteByOutputToken(
|
|
10490
|
+
totalAmountInOppositeToken,
|
|
10491
|
+
positionToken == 0 /* A */,
|
|
10492
|
+
0,
|
|
10493
|
+
fusionPool,
|
|
10494
|
+
tickArrays
|
|
10495
|
+
);
|
|
10496
|
+
nextSqrtPrice = swapQuote.nextSqrtPrice;
|
|
10497
|
+
const inputAmount = swapQuote.tokenEstIn;
|
|
10498
|
+
collateral = leverage > 1 ? BigInt(Math.floor(Number(inputAmount) / leverage)) : inputAmount;
|
|
10499
|
+
borrow = inputAmount - collateral;
|
|
10500
|
+
} else {
|
|
10501
|
+
if (leverage > 1) {
|
|
10502
|
+
collateral = BigInt(Math.floor(Number(totalAmount) / leverage));
|
|
10503
|
+
const swapQuote = swapQuoteByOutputToken(
|
|
10504
|
+
totalAmount - collateral,
|
|
10505
|
+
positionToken == 0 /* A */,
|
|
10506
|
+
0,
|
|
10507
|
+
fusionPool,
|
|
10508
|
+
tickArrays
|
|
10509
|
+
);
|
|
10510
|
+
nextSqrtPrice = swapQuote.nextSqrtPrice;
|
|
10511
|
+
borrow = swapQuote.tokenEstIn;
|
|
10512
|
+
} else {
|
|
10513
|
+
collateral = totalAmount;
|
|
10514
|
+
borrow = 0n;
|
|
10515
|
+
}
|
|
10516
|
+
}
|
|
10517
|
+
const collateralExcludingFee = collateral;
|
|
10518
|
+
const borrowExcludingFee = borrow;
|
|
10519
|
+
collateral = reverseApplyTunaProtocolFee(collateral, protocolFeeRateOnCollateral);
|
|
10520
|
+
borrow = reverseApplyTunaProtocolFee(borrow, protocolFeeRate);
|
|
10521
|
+
const protocolFeeA = (collateralToken == 0 /* A */ ? collateral - collateralExcludingFee : 0n) + (positionToken == 1 /* B */ ? borrow - borrowExcludingFee : 0n);
|
|
10522
|
+
const protocolFeeB = (collateralToken == 1 /* B */ ? collateral - collateralExcludingFee : 0n) + (positionToken == 0 /* A */ ? borrow - borrowExcludingFee : 0n);
|
|
10523
|
+
const oldPrice = sqrtPriceToPrice(fusionPool.sqrtPrice, 1, 1);
|
|
10524
|
+
const newPrice = sqrtPriceToPrice(nextSqrtPrice, 1, 1);
|
|
10525
|
+
const priceImpact = Math.abs(newPrice / oldPrice - 1) * 100;
|
|
10526
|
+
return {
|
|
10527
|
+
collateral,
|
|
10528
|
+
borrow,
|
|
10529
|
+
protocolFeeA,
|
|
10530
|
+
protocolFeeB,
|
|
10531
|
+
priceImpact
|
|
10532
|
+
};
|
|
10533
|
+
}
|
|
10534
|
+
function reverseApplyTunaProtocolFee(amount, protocolFeeRate) {
|
|
10535
|
+
return amount * BigInt(HUNDRED_PERCENT) / BigInt(HUNDRED_PERCENT - protocolFeeRate);
|
|
10536
|
+
}
|
|
10537
|
+
|
|
10402
10538
|
// src/txbuilder/increaseTunaLpPositionOrca.ts
|
|
10403
10539
|
import {
|
|
10404
10540
|
fetchMaybeWhirlpool,
|
|
@@ -13096,20 +13232,40 @@ import { FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS10 } from "@crypt
|
|
|
13096
13232
|
import { AccountRole as AccountRole16 } from "@solana/kit";
|
|
13097
13233
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS16 } from "@solana-program/memo";
|
|
13098
13234
|
import { findAssociatedTokenPda as findAssociatedTokenPda23 } from "@solana-program/token-2022";
|
|
13099
|
-
async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, withdrawPercent) {
|
|
13235
|
+
async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, createTunaPositionOwnerAta, withdrawPercent) {
|
|
13100
13236
|
const instructions = [];
|
|
13101
|
-
|
|
13102
|
-
|
|
13237
|
+
if (createTunaPositionOwnerAta) {
|
|
13238
|
+
const collateralTokenMint = tunaPosition.data.collateralToken == 0 /* A */ ? mintA : mintB;
|
|
13239
|
+
if (collateralTokenMint.address != NATIVE_MINT) {
|
|
13240
|
+
const createPositionOwnerAtaInstructions = await getCreateAtaInstructions(
|
|
13241
|
+
void 0,
|
|
13242
|
+
authority,
|
|
13243
|
+
collateralTokenMint.address,
|
|
13244
|
+
tunaPosition.data.authority,
|
|
13245
|
+
collateralTokenMint.programAddress
|
|
13246
|
+
);
|
|
13247
|
+
instructions.push(...createPositionOwnerAtaInstructions.init);
|
|
13248
|
+
}
|
|
13249
|
+
}
|
|
13250
|
+
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
13251
|
+
void 0,
|
|
13252
|
+
authority,
|
|
13253
|
+
mintA.address,
|
|
13254
|
+
tunaConfig.data.feeRecipient,
|
|
13255
|
+
mintA.programAddress
|
|
13256
|
+
);
|
|
13257
|
+
instructions.push(...createFeeRecipientAtaAInstructions.init);
|
|
13258
|
+
const createFeeRecipientAtaBInstructions = await getCreateAtaInstructions(
|
|
13103
13259
|
void 0,
|
|
13104
13260
|
authority,
|
|
13105
|
-
|
|
13261
|
+
mintB.address,
|
|
13106
13262
|
tunaConfig.data.feeRecipient,
|
|
13107
|
-
|
|
13263
|
+
mintB.programAddress
|
|
13108
13264
|
);
|
|
13109
|
-
instructions.push(...
|
|
13265
|
+
instructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
13110
13266
|
const ix = await liquidateTunaSpotPositionFusionInstruction(
|
|
13111
13267
|
authority,
|
|
13112
|
-
tunaPosition
|
|
13268
|
+
tunaPosition,
|
|
13113
13269
|
tunaConfig,
|
|
13114
13270
|
mintA,
|
|
13115
13271
|
mintB,
|
|
@@ -13121,15 +13277,25 @@ async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPositi
|
|
|
13121
13277
|
instructions.push(ix);
|
|
13122
13278
|
return instructions;
|
|
13123
13279
|
}
|
|
13124
|
-
async function liquidateTunaSpotPositionFusionInstruction(authority,
|
|
13280
|
+
async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, withdrawPercent) {
|
|
13125
13281
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
13282
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda23({
|
|
13283
|
+
owner: tunaPosition.data.authority,
|
|
13284
|
+
mint: mintA.address,
|
|
13285
|
+
tokenProgram: mintA.programAddress
|
|
13286
|
+
}))[0];
|
|
13287
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda23({
|
|
13288
|
+
owner: tunaPosition.data.authority,
|
|
13289
|
+
mint: mintB.address,
|
|
13290
|
+
tokenProgram: mintB.programAddress
|
|
13291
|
+
}))[0];
|
|
13126
13292
|
const tunaPositionAtaA = (await findAssociatedTokenPda23({
|
|
13127
|
-
owner:
|
|
13293
|
+
owner: tunaPosition.address,
|
|
13128
13294
|
mint: mintA.address,
|
|
13129
13295
|
tokenProgram: mintA.programAddress
|
|
13130
13296
|
}))[0];
|
|
13131
13297
|
const tunaPositionAtaB = (await findAssociatedTokenPda23({
|
|
13132
|
-
owner:
|
|
13298
|
+
owner: tunaPosition.address,
|
|
13133
13299
|
mint: mintB.address,
|
|
13134
13300
|
tokenProgram: mintB.programAddress
|
|
13135
13301
|
}))[0];
|
|
@@ -13184,9 +13350,12 @@ async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPositio
|
|
|
13184
13350
|
vaultAAta,
|
|
13185
13351
|
vaultB: vaultB.address,
|
|
13186
13352
|
vaultBAta,
|
|
13187
|
-
tunaPosition:
|
|
13353
|
+
tunaPosition: tunaPosition.address,
|
|
13188
13354
|
tunaPositionAtaA,
|
|
13189
13355
|
tunaPositionAtaB,
|
|
13356
|
+
tunaPositionOwner: tunaPosition.data.authority,
|
|
13357
|
+
tunaPositionOwnerAtaA: tunaPosition.data.collateralToken == 0 /* A */ && mintA.address != NATIVE_MINT ? tunaPositionOwnerAtaA : void 0,
|
|
13358
|
+
tunaPositionOwnerAtaB: tunaPosition.data.collateralToken == 1 /* B */ && mintB.address != NATIVE_MINT ? tunaPositionOwnerAtaB : void 0,
|
|
13190
13359
|
feeRecipientAtaA,
|
|
13191
13360
|
feeRecipientAtaB,
|
|
13192
13361
|
fusionPool: fusionPool.address,
|
|
@@ -13204,20 +13373,40 @@ import { getOracleAddress as getOracleAddress7, WHIRLPOOL_PROGRAM_ADDRESS as WHI
|
|
|
13204
13373
|
import { AccountRole as AccountRole17 } from "@solana/kit";
|
|
13205
13374
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS17 } from "@solana-program/memo";
|
|
13206
13375
|
import { findAssociatedTokenPda as findAssociatedTokenPda24 } from "@solana-program/token-2022";
|
|
13207
|
-
async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
13376
|
+
async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, createTunaPositionOwnerAta, withdrawPercent) {
|
|
13208
13377
|
const instructions = [];
|
|
13209
|
-
|
|
13210
|
-
|
|
13378
|
+
if (createTunaPositionOwnerAta) {
|
|
13379
|
+
const collateralTokenMint = tunaPosition.data.collateralToken == 0 /* A */ ? mintA : mintB;
|
|
13380
|
+
if (collateralTokenMint.address != NATIVE_MINT) {
|
|
13381
|
+
const createPositionOwnerAtaInstructions = await getCreateAtaInstructions(
|
|
13382
|
+
void 0,
|
|
13383
|
+
authority,
|
|
13384
|
+
collateralTokenMint.address,
|
|
13385
|
+
tunaPosition.data.authority,
|
|
13386
|
+
collateralTokenMint.programAddress
|
|
13387
|
+
);
|
|
13388
|
+
instructions.push(...createPositionOwnerAtaInstructions.init);
|
|
13389
|
+
}
|
|
13390
|
+
}
|
|
13391
|
+
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
13211
13392
|
void 0,
|
|
13212
13393
|
authority,
|
|
13213
|
-
|
|
13394
|
+
mintA.address,
|
|
13214
13395
|
tunaConfig.data.feeRecipient,
|
|
13215
|
-
|
|
13396
|
+
mintA.programAddress
|
|
13216
13397
|
);
|
|
13217
|
-
instructions.push(...
|
|
13398
|
+
instructions.push(...createFeeRecipientAtaAInstructions.init);
|
|
13399
|
+
const createFeeRecipientAtaBInstructions = await getCreateAtaInstructions(
|
|
13400
|
+
void 0,
|
|
13401
|
+
authority,
|
|
13402
|
+
mintB.address,
|
|
13403
|
+
tunaConfig.data.feeRecipient,
|
|
13404
|
+
mintB.programAddress
|
|
13405
|
+
);
|
|
13406
|
+
instructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
13218
13407
|
const ix = await liquidateTunaSpotPositionOrcaInstruction(
|
|
13219
13408
|
authority,
|
|
13220
|
-
tunaPosition
|
|
13409
|
+
tunaPosition,
|
|
13221
13410
|
tunaConfig,
|
|
13222
13411
|
mintA,
|
|
13223
13412
|
mintB,
|
|
@@ -13229,16 +13418,26 @@ async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition
|
|
|
13229
13418
|
instructions.push(ix);
|
|
13230
13419
|
return instructions;
|
|
13231
13420
|
}
|
|
13232
|
-
async function liquidateTunaSpotPositionOrcaInstruction(authority,
|
|
13421
|
+
async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
13233
13422
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
13234
13423
|
const orcaOracleAddress = (await getOracleAddress7(whirlpool.address))[0];
|
|
13424
|
+
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda24({
|
|
13425
|
+
owner: tunaPosition.data.authority,
|
|
13426
|
+
mint: mintA.address,
|
|
13427
|
+
tokenProgram: mintA.programAddress
|
|
13428
|
+
}))[0];
|
|
13429
|
+
const tunaPositionOwnerAtaB = (await findAssociatedTokenPda24({
|
|
13430
|
+
owner: tunaPosition.data.authority,
|
|
13431
|
+
mint: mintB.address,
|
|
13432
|
+
tokenProgram: mintB.programAddress
|
|
13433
|
+
}))[0];
|
|
13235
13434
|
const tunaPositionAtaA = (await findAssociatedTokenPda24({
|
|
13236
|
-
owner:
|
|
13435
|
+
owner: tunaPosition.address,
|
|
13237
13436
|
mint: mintA.address,
|
|
13238
13437
|
tokenProgram: mintA.programAddress
|
|
13239
13438
|
}))[0];
|
|
13240
13439
|
const tunaPositionAtaB = (await findAssociatedTokenPda24({
|
|
13241
|
-
owner:
|
|
13440
|
+
owner: tunaPosition.address,
|
|
13242
13441
|
mint: mintB.address,
|
|
13243
13442
|
tokenProgram: mintB.programAddress
|
|
13244
13443
|
}))[0];
|
|
@@ -13295,9 +13494,12 @@ async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPositionA
|
|
|
13295
13494
|
vaultAAta,
|
|
13296
13495
|
vaultB: vaultB.address,
|
|
13297
13496
|
vaultBAta,
|
|
13298
|
-
tunaPosition:
|
|
13497
|
+
tunaPosition: tunaPosition.address,
|
|
13299
13498
|
tunaPositionAtaA,
|
|
13300
13499
|
tunaPositionAtaB,
|
|
13500
|
+
tunaPositionOwner: tunaPosition.data.authority,
|
|
13501
|
+
tunaPositionOwnerAtaA: tunaPosition.data.collateralToken == 0 /* A */ && mintA.address != NATIVE_MINT ? tunaPositionOwnerAtaA : void 0,
|
|
13502
|
+
tunaPositionOwnerAtaB: tunaPosition.data.collateralToken == 1 /* B */ && mintB.address != NATIVE_MINT ? tunaPositionOwnerAtaB : void 0,
|
|
13301
13503
|
feeRecipientAtaA,
|
|
13302
13504
|
feeRecipientAtaB,
|
|
13303
13505
|
whirlpool: whirlpool.address,
|
|
@@ -14901,6 +15103,7 @@ import { fetchWhirlpool as fetchWhirlpool3, getOracleAddress as getOracleAddress
|
|
|
14901
15103
|
import {
|
|
14902
15104
|
address as address3
|
|
14903
15105
|
} from "@solana/kit";
|
|
15106
|
+
import { fetchAddressLookupTable, getExtendLookupTableInstruction as getExtendLookupTableInstruction2 } from "@solana-program/address-lookup-table";
|
|
14904
15107
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS26 } from "@solana-program/memo";
|
|
14905
15108
|
import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
|
|
14906
15109
|
import { TOKEN_PROGRAM_ADDRESS as TOKEN_PROGRAM_ADDRESS2 } from "@solana-program/token";
|
|
@@ -14989,6 +15192,19 @@ async function createAddressLookupTableForMarketInstructions(rpc, poolAddress, m
|
|
|
14989
15192
|
const addresses = await getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker);
|
|
14990
15193
|
return createAddressLookupTableInstructions(authority, addresses, recentSlot);
|
|
14991
15194
|
}
|
|
15195
|
+
async function extendAddressLookupTableForMarketInstructions(rpc, poolAddress, marketMaker, authority, lookupTableAddress) {
|
|
15196
|
+
const marketAddresses = await getAddressesForMarketLookupTable(rpc, poolAddress, marketMaker);
|
|
15197
|
+
const lookupTable = await fetchAddressLookupTable(rpc, lookupTableAddress);
|
|
15198
|
+
const existingAddresses = lookupTable.data.addresses;
|
|
15199
|
+
const addresses = marketAddresses.filter((addr) => !existingAddresses.includes(addr));
|
|
15200
|
+
const extendInstruction = getExtendLookupTableInstruction2({
|
|
15201
|
+
address: lookupTableAddress,
|
|
15202
|
+
addresses,
|
|
15203
|
+
authority,
|
|
15204
|
+
payer: authority
|
|
15205
|
+
});
|
|
15206
|
+
return { instructions: [extendInstruction], lookupTableAddress, addresses };
|
|
15207
|
+
}
|
|
14992
15208
|
|
|
14993
15209
|
// src/txbuilder/repayTunaLpPositionDebt.ts
|
|
14994
15210
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS27 } from "@solana-program/memo";
|
|
@@ -15673,6 +15889,7 @@ export {
|
|
|
15673
15889
|
decreaseTunaSpotPositionOrcaInstructions,
|
|
15674
15890
|
depositInstruction,
|
|
15675
15891
|
depositInstructions,
|
|
15892
|
+
extendAddressLookupTableForMarketInstructions,
|
|
15676
15893
|
fetchAllLendingPosition,
|
|
15677
15894
|
fetchAllLendingPositionWithFilter,
|
|
15678
15895
|
fetchAllMarket,
|
|
@@ -15797,6 +16014,7 @@ export {
|
|
|
15797
16014
|
getDepositInstructionDataDecoder,
|
|
15798
16015
|
getDepositInstructionDataEncoder,
|
|
15799
16016
|
getIncreaseLpPositionQuote,
|
|
16017
|
+
getIncreaseSpotPositionQuote,
|
|
15800
16018
|
getIncreaseTunaLpPositionFusionDiscriminatorBytes,
|
|
15801
16019
|
getIncreaseTunaLpPositionFusionInstruction,
|
|
15802
16020
|
getIncreaseTunaLpPositionFusionInstructionDataCodec,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crypticdot/defituna-client",
|
|
3
3
|
"description": "Typescript client to interact with DefiTuna's on-chain program.",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"rimraf": "^6.0.1",
|
|
52
52
|
"vitest": "^3.1.1",
|
|
53
53
|
"solana-bankrun": "^0.4.0",
|
|
54
|
-
"@crypticdot/defituna-program": "3.1.
|
|
54
|
+
"@crypticdot/defituna-program": "3.1.2"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "node ./codama.mjs && tsup src/index.ts --format cjs,esm --dts",
|