@crypticdot/defituna-client 2.0.13 → 2.0.15
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 +60 -32
- package/dist/index.d.ts +60 -32
- package/dist/index.js +141 -78
- package/dist/index.mjs +163 -88
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -3627,12 +3627,12 @@ function getLiquidatePositionFusionInstruction(input, config) {
|
|
|
3627
3627
|
value: input.tunaPositionAtaB ?? null,
|
|
3628
3628
|
isWritable: true
|
|
3629
3629
|
},
|
|
3630
|
-
|
|
3631
|
-
value: input.
|
|
3630
|
+
feeRecipientAtaA: {
|
|
3631
|
+
value: input.feeRecipientAtaA ?? null,
|
|
3632
3632
|
isWritable: true
|
|
3633
3633
|
},
|
|
3634
|
-
|
|
3635
|
-
value: input.
|
|
3634
|
+
feeRecipientAtaB: {
|
|
3635
|
+
value: input.feeRecipientAtaB ?? null,
|
|
3636
3636
|
isWritable: true
|
|
3637
3637
|
},
|
|
3638
3638
|
pythOraclePriceFeedA: {
|
|
@@ -3671,8 +3671,8 @@ function getLiquidatePositionFusionInstruction(input, config) {
|
|
|
3671
3671
|
getAccountMeta(accounts.tunaPositionAta),
|
|
3672
3672
|
getAccountMeta(accounts.tunaPositionAtaA),
|
|
3673
3673
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
3674
|
-
getAccountMeta(accounts.
|
|
3675
|
-
getAccountMeta(accounts.
|
|
3674
|
+
getAccountMeta(accounts.feeRecipientAtaA),
|
|
3675
|
+
getAccountMeta(accounts.feeRecipientAtaB),
|
|
3676
3676
|
getAccountMeta(accounts.pythOraclePriceFeedA),
|
|
3677
3677
|
getAccountMeta(accounts.pythOraclePriceFeedB),
|
|
3678
3678
|
getAccountMeta(accounts.fusionammProgram),
|
|
@@ -3715,8 +3715,8 @@ function parseLiquidatePositionFusionInstruction(instruction) {
|
|
|
3715
3715
|
tunaPositionAta: getNextAccount(),
|
|
3716
3716
|
tunaPositionAtaA: getNextAccount(),
|
|
3717
3717
|
tunaPositionAtaB: getNextAccount(),
|
|
3718
|
-
|
|
3719
|
-
|
|
3718
|
+
feeRecipientAtaA: getNextAccount(),
|
|
3719
|
+
feeRecipientAtaB: getNextAccount(),
|
|
3720
3720
|
pythOraclePriceFeedA: getNextAccount(),
|
|
3721
3721
|
pythOraclePriceFeedB: getNextAccount(),
|
|
3722
3722
|
fusionammProgram: getNextAccount(),
|
|
@@ -3795,12 +3795,12 @@ function getLiquidatePositionOrcaInstruction(input, config) {
|
|
|
3795
3795
|
value: input.tunaPositionAtaB ?? null,
|
|
3796
3796
|
isWritable: true
|
|
3797
3797
|
},
|
|
3798
|
-
|
|
3799
|
-
value: input.
|
|
3798
|
+
feeRecipientAtaA: {
|
|
3799
|
+
value: input.feeRecipientAtaA ?? null,
|
|
3800
3800
|
isWritable: true
|
|
3801
3801
|
},
|
|
3802
|
-
|
|
3803
|
-
value: input.
|
|
3802
|
+
feeRecipientAtaB: {
|
|
3803
|
+
value: input.feeRecipientAtaB ?? null,
|
|
3804
3804
|
isWritable: true
|
|
3805
3805
|
},
|
|
3806
3806
|
pythOraclePriceFeedA: {
|
|
@@ -3839,8 +3839,8 @@ function getLiquidatePositionOrcaInstruction(input, config) {
|
|
|
3839
3839
|
getAccountMeta(accounts.tunaPositionAta),
|
|
3840
3840
|
getAccountMeta(accounts.tunaPositionAtaA),
|
|
3841
3841
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
3842
|
-
getAccountMeta(accounts.
|
|
3843
|
-
getAccountMeta(accounts.
|
|
3842
|
+
getAccountMeta(accounts.feeRecipientAtaA),
|
|
3843
|
+
getAccountMeta(accounts.feeRecipientAtaB),
|
|
3844
3844
|
getAccountMeta(accounts.pythOraclePriceFeedA),
|
|
3845
3845
|
getAccountMeta(accounts.pythOraclePriceFeedB),
|
|
3846
3846
|
getAccountMeta(accounts.whirlpoolProgram),
|
|
@@ -3883,8 +3883,8 @@ function parseLiquidatePositionOrcaInstruction(instruction) {
|
|
|
3883
3883
|
tunaPositionAta: getNextAccount(),
|
|
3884
3884
|
tunaPositionAtaA: getNextAccount(),
|
|
3885
3885
|
tunaPositionAtaB: getNextAccount(),
|
|
3886
|
-
|
|
3887
|
-
|
|
3886
|
+
feeRecipientAtaA: getNextAccount(),
|
|
3887
|
+
feeRecipientAtaB: getNextAccount(),
|
|
3888
3888
|
pythOraclePriceFeedA: getNextAccount(),
|
|
3889
3889
|
pythOraclePriceFeedB: getNextAccount(),
|
|
3890
3890
|
whirlpoolProgram: getNextAccount(),
|
|
@@ -8735,7 +8735,7 @@ var import_whirlpools_client7 = require("@orca-so/whirlpools-client");
|
|
|
8735
8735
|
var import_kit67 = require("@solana/kit");
|
|
8736
8736
|
var import_memo8 = require("@solana-program/memo");
|
|
8737
8737
|
var import_token_202214 = require("@solana-program/token-2022");
|
|
8738
|
-
async function liquidatePositionOrcaInstructions(authority, tunaPosition, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8738
|
+
async function liquidatePositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8739
8739
|
const instructions = [];
|
|
8740
8740
|
const createLiquidatorAtaAInstructions = await getCreateAtaInstructions(
|
|
8741
8741
|
void 0,
|
|
@@ -8756,6 +8756,7 @@ async function liquidatePositionOrcaInstructions(authority, tunaPosition, mintA,
|
|
|
8756
8756
|
const ix = await liquidatePositionOrcaInstruction(
|
|
8757
8757
|
authority,
|
|
8758
8758
|
tunaPosition,
|
|
8759
|
+
tunaConfig,
|
|
8759
8760
|
mintA,
|
|
8760
8761
|
mintB,
|
|
8761
8762
|
vaultA,
|
|
@@ -8768,8 +8769,7 @@ async function liquidatePositionOrcaInstructions(authority, tunaPosition, mintA,
|
|
|
8768
8769
|
instructions.push(...createLiquidatorAtaBInstructions.cleanup);
|
|
8769
8770
|
return instructions;
|
|
8770
8771
|
}
|
|
8771
|
-
async function liquidatePositionOrcaInstruction(authority, tunaPosition, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8772
|
-
const tunaConfigAddress = (await getTunaConfigAddress())[0];
|
|
8772
|
+
async function liquidatePositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8773
8773
|
const positionMint = tunaPosition.data.positionMint;
|
|
8774
8774
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
8775
8775
|
const orcaPositionAddress = (await (0, import_whirlpools_client7.getPositionAddress)(positionMint))[0];
|
|
@@ -8799,13 +8799,13 @@ async function liquidatePositionOrcaInstruction(authority, tunaPosition, mintA,
|
|
|
8799
8799
|
mint: mintB.address,
|
|
8800
8800
|
tokenProgram: mintB.programAddress
|
|
8801
8801
|
}))[0];
|
|
8802
|
-
const
|
|
8803
|
-
owner:
|
|
8802
|
+
const feeRecipientAtaA = (await (0, import_token_202214.findAssociatedTokenPda)({
|
|
8803
|
+
owner: tunaConfig.data.feeRecipient,
|
|
8804
8804
|
mint: mintA.address,
|
|
8805
8805
|
tokenProgram: mintA.programAddress
|
|
8806
8806
|
}))[0];
|
|
8807
|
-
const
|
|
8808
|
-
owner:
|
|
8807
|
+
const feeRecipientAtaB = (await (0, import_token_202214.findAssociatedTokenPda)({
|
|
8808
|
+
owner: tunaConfig.data.feeRecipient,
|
|
8809
8809
|
mint: mintB.address,
|
|
8810
8810
|
tokenProgram: mintB.programAddress
|
|
8811
8811
|
}))[0];
|
|
@@ -8851,14 +8851,14 @@ async function liquidatePositionOrcaInstruction(authority, tunaPosition, mintA,
|
|
|
8851
8851
|
vaultB: vaultB.address,
|
|
8852
8852
|
vaultBAta,
|
|
8853
8853
|
authority,
|
|
8854
|
-
tunaConfig:
|
|
8854
|
+
tunaConfig: tunaConfig.address,
|
|
8855
8855
|
tunaPositionAta,
|
|
8856
8856
|
tunaPositionAtaA,
|
|
8857
8857
|
tunaPositionAtaB,
|
|
8858
8858
|
orcaPosition: orcaPositionAddress,
|
|
8859
8859
|
tunaPosition: tunaPosition.address,
|
|
8860
|
-
|
|
8861
|
-
|
|
8860
|
+
feeRecipientAtaA,
|
|
8861
|
+
feeRecipientAtaB,
|
|
8862
8862
|
whirlpool: whirlpool.address,
|
|
8863
8863
|
whirlpoolProgram: import_whirlpools_client7.WHIRLPOOL_PROGRAM_ADDRESS,
|
|
8864
8864
|
tokenProgramA: mintA.programAddress,
|
|
@@ -8876,7 +8876,7 @@ var import_fusionamm_client7 = require("@crypticdot/fusionamm-client");
|
|
|
8876
8876
|
var import_kit68 = require("@solana/kit");
|
|
8877
8877
|
var import_memo9 = require("@solana-program/memo");
|
|
8878
8878
|
var import_token_202215 = require("@solana-program/token-2022");
|
|
8879
|
-
async function liquidatePositionFusionInstructions(authority, tunaPosition, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8879
|
+
async function liquidatePositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8880
8880
|
const instructions = [];
|
|
8881
8881
|
const createLiquidatorAtaAInstructions = await getCreateAtaInstructions(
|
|
8882
8882
|
void 0,
|
|
@@ -8897,6 +8897,7 @@ async function liquidatePositionFusionInstructions(authority, tunaPosition, mint
|
|
|
8897
8897
|
const ix = await liquidatePositionFusionInstruction(
|
|
8898
8898
|
authority,
|
|
8899
8899
|
tunaPosition,
|
|
8900
|
+
tunaConfig,
|
|
8900
8901
|
mintA,
|
|
8901
8902
|
mintB,
|
|
8902
8903
|
vaultA,
|
|
@@ -8909,8 +8910,7 @@ async function liquidatePositionFusionInstructions(authority, tunaPosition, mint
|
|
|
8909
8910
|
instructions.push(...createLiquidatorAtaBInstructions.cleanup);
|
|
8910
8911
|
return instructions;
|
|
8911
8912
|
}
|
|
8912
|
-
async function liquidatePositionFusionInstruction(authority, tunaPosition, mintA, mintB, vaultA, vaultB, fusionPool, withdrawPercent) {
|
|
8913
|
-
const tunaConfigAddress = (await getTunaConfigAddress())[0];
|
|
8913
|
+
async function liquidatePositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, withdrawPercent) {
|
|
8914
8914
|
const positionMint = tunaPosition.data.positionMint;
|
|
8915
8915
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
8916
8916
|
const fusionPositionAddress = (await (0, import_fusionamm_client7.getPositionAddress)(positionMint))[0];
|
|
@@ -8939,13 +8939,13 @@ async function liquidatePositionFusionInstruction(authority, tunaPosition, mintA
|
|
|
8939
8939
|
mint: mintB.address,
|
|
8940
8940
|
tokenProgram: mintB.programAddress
|
|
8941
8941
|
}))[0];
|
|
8942
|
-
const
|
|
8943
|
-
owner:
|
|
8942
|
+
const feeRecipientAtaA = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
8943
|
+
owner: tunaConfig.data.feeRecipient,
|
|
8944
8944
|
mint: mintA.address,
|
|
8945
8945
|
tokenProgram: mintA.programAddress
|
|
8946
8946
|
}))[0];
|
|
8947
|
-
const
|
|
8948
|
-
owner:
|
|
8947
|
+
const feeRecipientAtaB = (await (0, import_token_202215.findAssociatedTokenPda)({
|
|
8948
|
+
owner: tunaConfig.data.feeRecipient,
|
|
8949
8949
|
mint: mintB.address,
|
|
8950
8950
|
tokenProgram: mintB.programAddress
|
|
8951
8951
|
}))[0];
|
|
@@ -8989,14 +8989,14 @@ async function liquidatePositionFusionInstruction(authority, tunaPosition, mintA
|
|
|
8989
8989
|
vaultB: vaultB.address,
|
|
8990
8990
|
vaultBAta,
|
|
8991
8991
|
authority,
|
|
8992
|
-
tunaConfig:
|
|
8992
|
+
tunaConfig: tunaConfig.address,
|
|
8993
8993
|
tunaPositionAta,
|
|
8994
8994
|
tunaPositionAtaA,
|
|
8995
8995
|
tunaPositionAtaB,
|
|
8996
8996
|
fusionPosition: fusionPositionAddress,
|
|
8997
8997
|
tunaPosition: tunaPosition.address,
|
|
8998
|
-
|
|
8999
|
-
|
|
8998
|
+
feeRecipientAtaA,
|
|
8999
|
+
feeRecipientAtaB,
|
|
9000
9000
|
fusionPool: fusionPool.address,
|
|
9001
9001
|
fusionammProgram: import_fusionamm_client7.FUSIONAMM_PROGRAM_ADDRESS,
|
|
9002
9002
|
tokenProgramA: mintA.programAddress,
|
|
@@ -9114,13 +9114,28 @@ async function openPositionFusionInstruction(rpc, authority, positionMint, fusio
|
|
|
9114
9114
|
var import_whirlpools_client9 = require("@orca-so/whirlpools-client");
|
|
9115
9115
|
var import_whirlpools_core4 = require("@orca-so/whirlpools-core");
|
|
9116
9116
|
var import_kit69 = require("@solana/kit");
|
|
9117
|
+
var import_sysvars = require("@solana/sysvars");
|
|
9117
9118
|
var import_memo10 = require("@solana-program/memo");
|
|
9118
9119
|
var import_token_202218 = require("@solana-program/token-2022");
|
|
9119
9120
|
var import_assert13 = __toESM(require("assert"));
|
|
9120
|
-
|
|
9121
|
+
|
|
9122
|
+
// src/utils/sysvar.ts
|
|
9123
|
+
var ACCOUNT_STORAGE_OVERHEAD = 128;
|
|
9124
|
+
function calculateMinimumBalanceForRentExemption(rent, dataSize) {
|
|
9125
|
+
const dataSizeForRent = BigInt(dataSize + ACCOUNT_STORAGE_OVERHEAD);
|
|
9126
|
+
const rentLamportsPerYear = rent.lamportsPerByteYear * dataSizeForRent;
|
|
9127
|
+
const minimumBalance = rentLamportsPerYear * BigInt(rent.exemptionThreshold);
|
|
9128
|
+
return minimumBalance;
|
|
9129
|
+
}
|
|
9130
|
+
|
|
9131
|
+
// src/txbuilder/openPositionWithLiquidityOrca.ts
|
|
9132
|
+
async function openPositionWithLiquidityOrcaInstructions(rpc, authority, whirlpoolAddress, args, createInstructions, cleanupInstructions) {
|
|
9121
9133
|
const instructions = [];
|
|
9122
9134
|
if (!createInstructions) createInstructions = instructions;
|
|
9123
9135
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
9136
|
+
const rent = await (0, import_sysvars.fetchSysvarRent)(rpc);
|
|
9137
|
+
let nonRefundableRent = 0n;
|
|
9138
|
+
const positionMint = await (0, import_kit69.generateKeyPairSigner)();
|
|
9124
9139
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
9125
9140
|
const whirlpool = await (0, import_whirlpools_client9.fetchMaybeWhirlpool)(rpc, whirlpoolAddress);
|
|
9126
9141
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
@@ -9184,24 +9199,34 @@ async function openPositionWithLiquidityOrcaInstructions(rpc, authority, positio
|
|
|
9184
9199
|
const [lowerTickArrayAddress] = await (0, import_whirlpools_client9.getTickArrayAddress)(whirlpool.address, lowerTickArrayIndex);
|
|
9185
9200
|
const upperTickArrayIndex = (0, import_whirlpools_core4.getTickArrayStartTickIndex)(args.tickUpperIndex, whirlpool.data.tickSpacing);
|
|
9186
9201
|
const [upperTickArrayAddress] = await (0, import_whirlpools_client9.getTickArrayAddress)(whirlpool.address, upperTickArrayIndex);
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9203
|
-
|
|
9204
|
-
|
|
9202
|
+
const [lowerTickArray, upperTickArray] = await (0, import_whirlpools_client9.fetchAllMaybeTickArray)(rpc, [
|
|
9203
|
+
lowerTickArrayAddress,
|
|
9204
|
+
upperTickArrayAddress
|
|
9205
|
+
]);
|
|
9206
|
+
if (!lowerTickArray.exists) {
|
|
9207
|
+
instructions.push(
|
|
9208
|
+
(0, import_whirlpools_client9.getInitializeDynamicTickArrayInstruction)({
|
|
9209
|
+
whirlpool: whirlpool.address,
|
|
9210
|
+
funder: authority,
|
|
9211
|
+
tickArray: lowerTickArrayAddress,
|
|
9212
|
+
startTickIndex: lowerTickArrayIndex,
|
|
9213
|
+
idempotent: false
|
|
9214
|
+
})
|
|
9215
|
+
);
|
|
9216
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client9.getDynamicTickArrayMinSize)());
|
|
9217
|
+
}
|
|
9218
|
+
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
9219
|
+
instructions.push(
|
|
9220
|
+
(0, import_whirlpools_client9.getInitializeDynamicTickArrayInstruction)({
|
|
9221
|
+
whirlpool: whirlpool.address,
|
|
9222
|
+
funder: authority,
|
|
9223
|
+
tickArray: upperTickArrayAddress,
|
|
9224
|
+
startTickIndex: upperTickArrayIndex,
|
|
9225
|
+
idempotent: false
|
|
9226
|
+
})
|
|
9227
|
+
);
|
|
9228
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client9.getDynamicTickArrayMinSize)());
|
|
9229
|
+
}
|
|
9205
9230
|
const ix = await openPositionWithLiquidityOrcaInstruction(
|
|
9206
9231
|
authority,
|
|
9207
9232
|
positionMint,
|
|
@@ -9218,7 +9243,11 @@ async function openPositionWithLiquidityOrcaInstructions(rpc, authority, positio
|
|
|
9218
9243
|
cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
9219
9244
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
9220
9245
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
9221
|
-
return
|
|
9246
|
+
return {
|
|
9247
|
+
instructions,
|
|
9248
|
+
positionMint: positionMint.address,
|
|
9249
|
+
initializationCost: (0, import_kit69.lamports)(nonRefundableRent)
|
|
9250
|
+
};
|
|
9222
9251
|
}
|
|
9223
9252
|
async function openPositionWithLiquidityOrcaInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, args) {
|
|
9224
9253
|
const tunaPositionAddress = (await getTunaPositionAddress(positionMint.address))[0];
|
|
@@ -9336,13 +9365,17 @@ async function openPositionWithLiquidityOrcaInstruction(authority, positionMint,
|
|
|
9336
9365
|
var import_fusionamm_client10 = require("@crypticdot/fusionamm-client");
|
|
9337
9366
|
var import_fusionamm_core5 = require("@crypticdot/fusionamm-core");
|
|
9338
9367
|
var import_kit70 = require("@solana/kit");
|
|
9368
|
+
var import_sysvars2 = require("@solana/sysvars");
|
|
9339
9369
|
var import_memo11 = require("@solana-program/memo");
|
|
9340
9370
|
var import_token_202219 = require("@solana-program/token-2022");
|
|
9341
9371
|
var import_assert14 = __toESM(require("assert"));
|
|
9342
|
-
async function openPositionWithLiquidityFusionInstructions(rpc, authority,
|
|
9372
|
+
async function openPositionWithLiquidityFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
9343
9373
|
const instructions = [];
|
|
9344
9374
|
if (!createInstructions) createInstructions = instructions;
|
|
9345
9375
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
9376
|
+
const rent = await (0, import_sysvars2.fetchSysvarRent)(rpc);
|
|
9377
|
+
let nonRefundableRent = 0n;
|
|
9378
|
+
const positionMint = await (0, import_kit70.generateKeyPairSigner)();
|
|
9346
9379
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
9347
9380
|
const fusionPool = await (0, import_fusionamm_client10.fetchMaybeFusionPool)(rpc, fusionPoolAddress);
|
|
9348
9381
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
@@ -9419,6 +9452,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9419
9452
|
startTickIndex: lowerTickArrayIndex
|
|
9420
9453
|
})
|
|
9421
9454
|
);
|
|
9455
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client10.getTickArraySize)());
|
|
9422
9456
|
}
|
|
9423
9457
|
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
9424
9458
|
instructions.push(
|
|
@@ -9429,6 +9463,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9429
9463
|
startTickIndex: upperTickArrayIndex
|
|
9430
9464
|
})
|
|
9431
9465
|
);
|
|
9466
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client10.getTickArraySize)());
|
|
9432
9467
|
}
|
|
9433
9468
|
const ix = await openPositionWithLiquidityFusionInstruction(
|
|
9434
9469
|
authority,
|
|
@@ -9446,7 +9481,11 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9446
9481
|
cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
9447
9482
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
9448
9483
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
9449
|
-
return
|
|
9484
|
+
return {
|
|
9485
|
+
instructions,
|
|
9486
|
+
positionMint: positionMint.address,
|
|
9487
|
+
initializationCost: (0, import_kit70.lamports)(nonRefundableRent)
|
|
9488
|
+
};
|
|
9450
9489
|
}
|
|
9451
9490
|
async function openPositionWithLiquidityFusionInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, args) {
|
|
9452
9491
|
const tunaPositionAddress = (await getTunaPositionAddress(positionMint.address))[0];
|
|
@@ -10221,10 +10260,13 @@ async function repayDebtInstruction(authority, positionMint, mintA, mintB, marke
|
|
|
10221
10260
|
// src/txbuilder/rebalancePositionOrca.ts
|
|
10222
10261
|
var import_whirlpools_client12 = require("@orca-so/whirlpools-client");
|
|
10223
10262
|
var import_kit74 = require("@solana/kit");
|
|
10263
|
+
var import_sysvars3 = require("@solana/sysvars");
|
|
10224
10264
|
var import_memo18 = require("@solana-program/memo");
|
|
10225
10265
|
var import_token_202226 = require("@solana-program/token-2022");
|
|
10226
10266
|
var import_assert18 = __toESM(require("assert"));
|
|
10227
10267
|
async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
10268
|
+
const rent = await (0, import_sysvars3.fetchSysvarRent)(rpc);
|
|
10269
|
+
let nonRefundableRent = 0n;
|
|
10228
10270
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
10229
10271
|
const tunaPosition = await fetchMaybeTunaPosition(rpc, (await getTunaPositionAddress(positionMint))[0]);
|
|
10230
10272
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -10242,24 +10284,34 @@ async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, c
|
|
|
10242
10284
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
10243
10285
|
const internalCleanupInstructions = [];
|
|
10244
10286
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10287
|
+
const [lowerTickArray, upperTickArray] = await (0, import_whirlpools_client12.fetchAllMaybeTickArray)(rpc, [
|
|
10288
|
+
secondaryTickArrays.lowerTickArrayAddress,
|
|
10289
|
+
secondaryTickArrays.upperTickArrayAddress
|
|
10290
|
+
]);
|
|
10291
|
+
if (!lowerTickArray.exists) {
|
|
10292
|
+
instructions.push(
|
|
10293
|
+
(0, import_whirlpools_client12.getInitializeDynamicTickArrayInstruction)({
|
|
10294
|
+
whirlpool: whirlpool.address,
|
|
10295
|
+
funder: authority,
|
|
10296
|
+
tickArray: secondaryTickArrays.lowerTickArrayAddress,
|
|
10297
|
+
startTickIndex: secondaryTickArrays.lowerTickArrayStartIndex,
|
|
10298
|
+
idempotent: false
|
|
10299
|
+
})
|
|
10300
|
+
);
|
|
10301
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client12.getDynamicTickArrayMinSize)());
|
|
10302
|
+
}
|
|
10303
|
+
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
10304
|
+
instructions.push(
|
|
10305
|
+
(0, import_whirlpools_client12.getInitializeDynamicTickArrayInstruction)({
|
|
10306
|
+
whirlpool: whirlpool.address,
|
|
10307
|
+
funder: authority,
|
|
10308
|
+
tickArray: secondaryTickArrays.upperTickArrayAddress,
|
|
10309
|
+
startTickIndex: secondaryTickArrays.upperTickArrayStartIndex,
|
|
10310
|
+
idempotent: false
|
|
10311
|
+
})
|
|
10312
|
+
);
|
|
10313
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_whirlpools_client12.getDynamicTickArrayMinSize)());
|
|
10314
|
+
}
|
|
10263
10315
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10264
10316
|
rpc,
|
|
10265
10317
|
authority,
|
|
@@ -10290,7 +10342,10 @@ async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, c
|
|
|
10290
10342
|
cleanupInstructions.push(...internalCleanupInstructions);
|
|
10291
10343
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
10292
10344
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
10293
|
-
return
|
|
10345
|
+
return {
|
|
10346
|
+
instructions,
|
|
10347
|
+
initializationCost: (0, import_kit74.lamports)(nonRefundableRent)
|
|
10348
|
+
};
|
|
10294
10349
|
}
|
|
10295
10350
|
async function rebalancePositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool) {
|
|
10296
10351
|
const positionMint = tunaPosition.data.positionMint;
|
|
@@ -10389,10 +10444,13 @@ async function rebalancePositionOrcaInstruction(authority, tunaPosition, tunaCon
|
|
|
10389
10444
|
// src/txbuilder/rebalancePositionFusion.ts
|
|
10390
10445
|
var import_fusionamm_client13 = require("@crypticdot/fusionamm-client");
|
|
10391
10446
|
var import_kit75 = require("@solana/kit");
|
|
10447
|
+
var import_sysvars4 = require("@solana/sysvars");
|
|
10392
10448
|
var import_memo19 = require("@solana-program/memo");
|
|
10393
10449
|
var import_token_202227 = require("@solana-program/token-2022");
|
|
10394
10450
|
var import_assert19 = __toESM(require("assert"));
|
|
10395
10451
|
async function rebalancePositionFusionInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
10452
|
+
const rent = await (0, import_sysvars4.fetchSysvarRent)(rpc);
|
|
10453
|
+
let nonRefundableRent = 0n;
|
|
10396
10454
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
10397
10455
|
const tunaPosition = await fetchMaybeTunaPosition(rpc, (await getTunaPositionAddress(positionMint))[0]);
|
|
10398
10456
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -10422,6 +10480,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10422
10480
|
startTickIndex: secondaryTickArrays.lowerTickArrayStartIndex
|
|
10423
10481
|
})
|
|
10424
10482
|
);
|
|
10483
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client13.getTickArraySize)());
|
|
10425
10484
|
}
|
|
10426
10485
|
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
10427
10486
|
instructions.push(
|
|
@@ -10432,6 +10491,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10432
10491
|
startTickIndex: secondaryTickArrays.upperTickArrayStartIndex
|
|
10433
10492
|
})
|
|
10434
10493
|
);
|
|
10494
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client13.getTickArraySize)());
|
|
10435
10495
|
}
|
|
10436
10496
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10437
10497
|
rpc,
|
|
@@ -10462,7 +10522,10 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10462
10522
|
instructions.push(ix);
|
|
10463
10523
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
10464
10524
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
10465
|
-
return
|
|
10525
|
+
return {
|
|
10526
|
+
instructions,
|
|
10527
|
+
initializationCost: (0, import_kit75.lamports)(nonRefundableRent)
|
|
10528
|
+
};
|
|
10466
10529
|
}
|
|
10467
10530
|
async function rebalancePositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool) {
|
|
10468
10531
|
const positionMint = tunaPosition.data.positionMint;
|