@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.mjs
CHANGED
|
@@ -3393,12 +3393,12 @@ function getLiquidatePositionFusionInstruction(input, config) {
|
|
|
3393
3393
|
value: input.tunaPositionAtaB ?? null,
|
|
3394
3394
|
isWritable: true
|
|
3395
3395
|
},
|
|
3396
|
-
|
|
3397
|
-
value: input.
|
|
3396
|
+
feeRecipientAtaA: {
|
|
3397
|
+
value: input.feeRecipientAtaA ?? null,
|
|
3398
3398
|
isWritable: true
|
|
3399
3399
|
},
|
|
3400
|
-
|
|
3401
|
-
value: input.
|
|
3400
|
+
feeRecipientAtaB: {
|
|
3401
|
+
value: input.feeRecipientAtaB ?? null,
|
|
3402
3402
|
isWritable: true
|
|
3403
3403
|
},
|
|
3404
3404
|
pythOraclePriceFeedA: {
|
|
@@ -3437,8 +3437,8 @@ function getLiquidatePositionFusionInstruction(input, config) {
|
|
|
3437
3437
|
getAccountMeta(accounts.tunaPositionAta),
|
|
3438
3438
|
getAccountMeta(accounts.tunaPositionAtaA),
|
|
3439
3439
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
3440
|
-
getAccountMeta(accounts.
|
|
3441
|
-
getAccountMeta(accounts.
|
|
3440
|
+
getAccountMeta(accounts.feeRecipientAtaA),
|
|
3441
|
+
getAccountMeta(accounts.feeRecipientAtaB),
|
|
3442
3442
|
getAccountMeta(accounts.pythOraclePriceFeedA),
|
|
3443
3443
|
getAccountMeta(accounts.pythOraclePriceFeedB),
|
|
3444
3444
|
getAccountMeta(accounts.fusionammProgram),
|
|
@@ -3481,8 +3481,8 @@ function parseLiquidatePositionFusionInstruction(instruction) {
|
|
|
3481
3481
|
tunaPositionAta: getNextAccount(),
|
|
3482
3482
|
tunaPositionAtaA: getNextAccount(),
|
|
3483
3483
|
tunaPositionAtaB: getNextAccount(),
|
|
3484
|
-
|
|
3485
|
-
|
|
3484
|
+
feeRecipientAtaA: getNextAccount(),
|
|
3485
|
+
feeRecipientAtaB: getNextAccount(),
|
|
3486
3486
|
pythOraclePriceFeedA: getNextAccount(),
|
|
3487
3487
|
pythOraclePriceFeedB: getNextAccount(),
|
|
3488
3488
|
fusionammProgram: getNextAccount(),
|
|
@@ -3572,12 +3572,12 @@ function getLiquidatePositionOrcaInstruction(input, config) {
|
|
|
3572
3572
|
value: input.tunaPositionAtaB ?? null,
|
|
3573
3573
|
isWritable: true
|
|
3574
3574
|
},
|
|
3575
|
-
|
|
3576
|
-
value: input.
|
|
3575
|
+
feeRecipientAtaA: {
|
|
3576
|
+
value: input.feeRecipientAtaA ?? null,
|
|
3577
3577
|
isWritable: true
|
|
3578
3578
|
},
|
|
3579
|
-
|
|
3580
|
-
value: input.
|
|
3579
|
+
feeRecipientAtaB: {
|
|
3580
|
+
value: input.feeRecipientAtaB ?? null,
|
|
3581
3581
|
isWritable: true
|
|
3582
3582
|
},
|
|
3583
3583
|
pythOraclePriceFeedA: {
|
|
@@ -3616,8 +3616,8 @@ function getLiquidatePositionOrcaInstruction(input, config) {
|
|
|
3616
3616
|
getAccountMeta(accounts.tunaPositionAta),
|
|
3617
3617
|
getAccountMeta(accounts.tunaPositionAtaA),
|
|
3618
3618
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
3619
|
-
getAccountMeta(accounts.
|
|
3620
|
-
getAccountMeta(accounts.
|
|
3619
|
+
getAccountMeta(accounts.feeRecipientAtaA),
|
|
3620
|
+
getAccountMeta(accounts.feeRecipientAtaB),
|
|
3621
3621
|
getAccountMeta(accounts.pythOraclePriceFeedA),
|
|
3622
3622
|
getAccountMeta(accounts.pythOraclePriceFeedB),
|
|
3623
3623
|
getAccountMeta(accounts.whirlpoolProgram),
|
|
@@ -3660,8 +3660,8 @@ function parseLiquidatePositionOrcaInstruction(instruction) {
|
|
|
3660
3660
|
tunaPositionAta: getNextAccount(),
|
|
3661
3661
|
tunaPositionAtaA: getNextAccount(),
|
|
3662
3662
|
tunaPositionAtaB: getNextAccount(),
|
|
3663
|
-
|
|
3664
|
-
|
|
3663
|
+
feeRecipientAtaA: getNextAccount(),
|
|
3664
|
+
feeRecipientAtaB: getNextAccount(),
|
|
3665
3665
|
pythOraclePriceFeedA: getNextAccount(),
|
|
3666
3666
|
pythOraclePriceFeedB: getNextAccount(),
|
|
3667
3667
|
whirlpoolProgram: getNextAccount(),
|
|
@@ -8918,7 +8918,7 @@ import { getOracleAddress as getOracleAddress3, getPositionAddress as getPositio
|
|
|
8918
8918
|
import { AccountRole as AccountRole8 } from "@solana/kit";
|
|
8919
8919
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS8 } from "@solana-program/memo";
|
|
8920
8920
|
import { findAssociatedTokenPda as findAssociatedTokenPda14, TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS11 } from "@solana-program/token-2022";
|
|
8921
|
-
async function liquidatePositionOrcaInstructions(authority, tunaPosition, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8921
|
+
async function liquidatePositionOrcaInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8922
8922
|
const instructions = [];
|
|
8923
8923
|
const createLiquidatorAtaAInstructions = await getCreateAtaInstructions(
|
|
8924
8924
|
void 0,
|
|
@@ -8939,6 +8939,7 @@ async function liquidatePositionOrcaInstructions(authority, tunaPosition, mintA,
|
|
|
8939
8939
|
const ix = await liquidatePositionOrcaInstruction(
|
|
8940
8940
|
authority,
|
|
8941
8941
|
tunaPosition,
|
|
8942
|
+
tunaConfig,
|
|
8942
8943
|
mintA,
|
|
8943
8944
|
mintB,
|
|
8944
8945
|
vaultA,
|
|
@@ -8951,8 +8952,7 @@ async function liquidatePositionOrcaInstructions(authority, tunaPosition, mintA,
|
|
|
8951
8952
|
instructions.push(...createLiquidatorAtaBInstructions.cleanup);
|
|
8952
8953
|
return instructions;
|
|
8953
8954
|
}
|
|
8954
|
-
async function liquidatePositionOrcaInstruction(authority, tunaPosition, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8955
|
-
const tunaConfigAddress = (await getTunaConfigAddress())[0];
|
|
8955
|
+
async function liquidatePositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
8956
8956
|
const positionMint = tunaPosition.data.positionMint;
|
|
8957
8957
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
8958
8958
|
const orcaPositionAddress = (await getPositionAddress11(positionMint))[0];
|
|
@@ -8982,13 +8982,13 @@ async function liquidatePositionOrcaInstruction(authority, tunaPosition, mintA,
|
|
|
8982
8982
|
mint: mintB.address,
|
|
8983
8983
|
tokenProgram: mintB.programAddress
|
|
8984
8984
|
}))[0];
|
|
8985
|
-
const
|
|
8986
|
-
owner:
|
|
8985
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda14({
|
|
8986
|
+
owner: tunaConfig.data.feeRecipient,
|
|
8987
8987
|
mint: mintA.address,
|
|
8988
8988
|
tokenProgram: mintA.programAddress
|
|
8989
8989
|
}))[0];
|
|
8990
|
-
const
|
|
8991
|
-
owner:
|
|
8990
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda14({
|
|
8991
|
+
owner: tunaConfig.data.feeRecipient,
|
|
8992
8992
|
mint: mintB.address,
|
|
8993
8993
|
tokenProgram: mintB.programAddress
|
|
8994
8994
|
}))[0];
|
|
@@ -9034,14 +9034,14 @@ async function liquidatePositionOrcaInstruction(authority, tunaPosition, mintA,
|
|
|
9034
9034
|
vaultB: vaultB.address,
|
|
9035
9035
|
vaultBAta,
|
|
9036
9036
|
authority,
|
|
9037
|
-
tunaConfig:
|
|
9037
|
+
tunaConfig: tunaConfig.address,
|
|
9038
9038
|
tunaPositionAta,
|
|
9039
9039
|
tunaPositionAtaA,
|
|
9040
9040
|
tunaPositionAtaB,
|
|
9041
9041
|
orcaPosition: orcaPositionAddress,
|
|
9042
9042
|
tunaPosition: tunaPosition.address,
|
|
9043
|
-
|
|
9044
|
-
|
|
9043
|
+
feeRecipientAtaA,
|
|
9044
|
+
feeRecipientAtaB,
|
|
9045
9045
|
whirlpool: whirlpool.address,
|
|
9046
9046
|
whirlpoolProgram: WHIRLPOOL_PROGRAM_ADDRESS6,
|
|
9047
9047
|
tokenProgramA: mintA.programAddress,
|
|
@@ -9059,7 +9059,7 @@ import { FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS6, getPositionAdd
|
|
|
9059
9059
|
import { AccountRole as AccountRole9 } from "@solana/kit";
|
|
9060
9060
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS9 } from "@solana-program/memo";
|
|
9061
9061
|
import { findAssociatedTokenPda as findAssociatedTokenPda15, TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS12 } from "@solana-program/token-2022";
|
|
9062
|
-
async function liquidatePositionFusionInstructions(authority, tunaPosition, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
9062
|
+
async function liquidatePositionFusionInstructions(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
9063
9063
|
const instructions = [];
|
|
9064
9064
|
const createLiquidatorAtaAInstructions = await getCreateAtaInstructions(
|
|
9065
9065
|
void 0,
|
|
@@ -9080,6 +9080,7 @@ async function liquidatePositionFusionInstructions(authority, tunaPosition, mint
|
|
|
9080
9080
|
const ix = await liquidatePositionFusionInstruction(
|
|
9081
9081
|
authority,
|
|
9082
9082
|
tunaPosition,
|
|
9083
|
+
tunaConfig,
|
|
9083
9084
|
mintA,
|
|
9084
9085
|
mintB,
|
|
9085
9086
|
vaultA,
|
|
@@ -9092,8 +9093,7 @@ async function liquidatePositionFusionInstructions(authority, tunaPosition, mint
|
|
|
9092
9093
|
instructions.push(...createLiquidatorAtaBInstructions.cleanup);
|
|
9093
9094
|
return instructions;
|
|
9094
9095
|
}
|
|
9095
|
-
async function liquidatePositionFusionInstruction(authority, tunaPosition, mintA, mintB, vaultA, vaultB, fusionPool, withdrawPercent) {
|
|
9096
|
-
const tunaConfigAddress = (await getTunaConfigAddress())[0];
|
|
9096
|
+
async function liquidatePositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, withdrawPercent) {
|
|
9097
9097
|
const positionMint = tunaPosition.data.positionMint;
|
|
9098
9098
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
9099
9099
|
const fusionPositionAddress = (await getPositionAddress12(positionMint))[0];
|
|
@@ -9122,13 +9122,13 @@ async function liquidatePositionFusionInstruction(authority, tunaPosition, mintA
|
|
|
9122
9122
|
mint: mintB.address,
|
|
9123
9123
|
tokenProgram: mintB.programAddress
|
|
9124
9124
|
}))[0];
|
|
9125
|
-
const
|
|
9126
|
-
owner:
|
|
9125
|
+
const feeRecipientAtaA = (await findAssociatedTokenPda15({
|
|
9126
|
+
owner: tunaConfig.data.feeRecipient,
|
|
9127
9127
|
mint: mintA.address,
|
|
9128
9128
|
tokenProgram: mintA.programAddress
|
|
9129
9129
|
}))[0];
|
|
9130
|
-
const
|
|
9131
|
-
owner:
|
|
9130
|
+
const feeRecipientAtaB = (await findAssociatedTokenPda15({
|
|
9131
|
+
owner: tunaConfig.data.feeRecipient,
|
|
9132
9132
|
mint: mintB.address,
|
|
9133
9133
|
tokenProgram: mintB.programAddress
|
|
9134
9134
|
}))[0];
|
|
@@ -9172,14 +9172,14 @@ async function liquidatePositionFusionInstruction(authority, tunaPosition, mintA
|
|
|
9172
9172
|
vaultB: vaultB.address,
|
|
9173
9173
|
vaultBAta,
|
|
9174
9174
|
authority,
|
|
9175
|
-
tunaConfig:
|
|
9175
|
+
tunaConfig: tunaConfig.address,
|
|
9176
9176
|
tunaPositionAta,
|
|
9177
9177
|
tunaPositionAtaA,
|
|
9178
9178
|
tunaPositionAtaB,
|
|
9179
9179
|
fusionPosition: fusionPositionAddress,
|
|
9180
9180
|
tunaPosition: tunaPosition.address,
|
|
9181
|
-
|
|
9182
|
-
|
|
9181
|
+
feeRecipientAtaA,
|
|
9182
|
+
feeRecipientAtaB,
|
|
9183
9183
|
fusionPool: fusionPool.address,
|
|
9184
9184
|
fusionammProgram: FUSIONAMM_PROGRAM_ADDRESS6,
|
|
9185
9185
|
tokenProgramA: mintA.programAddress,
|
|
@@ -9305,7 +9305,9 @@ async function openPositionFusionInstruction(rpc, authority, positionMint, fusio
|
|
|
9305
9305
|
|
|
9306
9306
|
// src/txbuilder/openPositionWithLiquidityOrca.ts
|
|
9307
9307
|
import {
|
|
9308
|
+
fetchAllMaybeTickArray as fetchAllMaybeTickArray2,
|
|
9308
9309
|
fetchMaybeWhirlpool as fetchMaybeWhirlpool7,
|
|
9310
|
+
getDynamicTickArrayMinSize,
|
|
9309
9311
|
getInitializeDynamicTickArrayInstruction as getInitializeDynamicTickArrayInstruction2,
|
|
9310
9312
|
getOracleAddress as getOracleAddress4,
|
|
9311
9313
|
getPositionAddress as getPositionAddress15,
|
|
@@ -9314,8 +9316,11 @@ import {
|
|
|
9314
9316
|
} from "@orca-so/whirlpools-client";
|
|
9315
9317
|
import { getTickArrayStartTickIndex as getTickArrayStartTickIndex6 } from "@orca-so/whirlpools-core";
|
|
9316
9318
|
import {
|
|
9317
|
-
AccountRole as AccountRole10
|
|
9319
|
+
AccountRole as AccountRole10,
|
|
9320
|
+
generateKeyPairSigner,
|
|
9321
|
+
lamports
|
|
9318
9322
|
} from "@solana/kit";
|
|
9323
|
+
import { fetchSysvarRent } from "@solana/sysvars";
|
|
9319
9324
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS10 } from "@solana-program/memo";
|
|
9320
9325
|
import {
|
|
9321
9326
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS3,
|
|
@@ -9324,10 +9329,24 @@ import {
|
|
|
9324
9329
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS15
|
|
9325
9330
|
} from "@solana-program/token-2022";
|
|
9326
9331
|
import assert13 from "assert";
|
|
9327
|
-
|
|
9332
|
+
|
|
9333
|
+
// src/utils/sysvar.ts
|
|
9334
|
+
var ACCOUNT_STORAGE_OVERHEAD = 128;
|
|
9335
|
+
function calculateMinimumBalanceForRentExemption(rent, dataSize) {
|
|
9336
|
+
const dataSizeForRent = BigInt(dataSize + ACCOUNT_STORAGE_OVERHEAD);
|
|
9337
|
+
const rentLamportsPerYear = rent.lamportsPerByteYear * dataSizeForRent;
|
|
9338
|
+
const minimumBalance = rentLamportsPerYear * BigInt(rent.exemptionThreshold);
|
|
9339
|
+
return minimumBalance;
|
|
9340
|
+
}
|
|
9341
|
+
|
|
9342
|
+
// src/txbuilder/openPositionWithLiquidityOrca.ts
|
|
9343
|
+
async function openPositionWithLiquidityOrcaInstructions(rpc, authority, whirlpoolAddress, args, createInstructions, cleanupInstructions) {
|
|
9328
9344
|
const instructions = [];
|
|
9329
9345
|
if (!createInstructions) createInstructions = instructions;
|
|
9330
9346
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
9347
|
+
const rent = await fetchSysvarRent(rpc);
|
|
9348
|
+
let nonRefundableRent = 0n;
|
|
9349
|
+
const positionMint = await generateKeyPairSigner();
|
|
9331
9350
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
9332
9351
|
const whirlpool = await fetchMaybeWhirlpool7(rpc, whirlpoolAddress);
|
|
9333
9352
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
@@ -9391,24 +9410,34 @@ async function openPositionWithLiquidityOrcaInstructions(rpc, authority, positio
|
|
|
9391
9410
|
const [lowerTickArrayAddress] = await getTickArrayAddress6(whirlpool.address, lowerTickArrayIndex);
|
|
9392
9411
|
const upperTickArrayIndex = getTickArrayStartTickIndex6(args.tickUpperIndex, whirlpool.data.tickSpacing);
|
|
9393
9412
|
const [upperTickArrayAddress] = await getTickArrayAddress6(whirlpool.address, upperTickArrayIndex);
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9413
|
+
const [lowerTickArray, upperTickArray] = await fetchAllMaybeTickArray2(rpc, [
|
|
9414
|
+
lowerTickArrayAddress,
|
|
9415
|
+
upperTickArrayAddress
|
|
9416
|
+
]);
|
|
9417
|
+
if (!lowerTickArray.exists) {
|
|
9418
|
+
instructions.push(
|
|
9419
|
+
getInitializeDynamicTickArrayInstruction2({
|
|
9420
|
+
whirlpool: whirlpool.address,
|
|
9421
|
+
funder: authority,
|
|
9422
|
+
tickArray: lowerTickArrayAddress,
|
|
9423
|
+
startTickIndex: lowerTickArrayIndex,
|
|
9424
|
+
idempotent: false
|
|
9425
|
+
})
|
|
9426
|
+
);
|
|
9427
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getDynamicTickArrayMinSize());
|
|
9428
|
+
}
|
|
9429
|
+
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
9430
|
+
instructions.push(
|
|
9431
|
+
getInitializeDynamicTickArrayInstruction2({
|
|
9432
|
+
whirlpool: whirlpool.address,
|
|
9433
|
+
funder: authority,
|
|
9434
|
+
tickArray: upperTickArrayAddress,
|
|
9435
|
+
startTickIndex: upperTickArrayIndex,
|
|
9436
|
+
idempotent: false
|
|
9437
|
+
})
|
|
9438
|
+
);
|
|
9439
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getDynamicTickArrayMinSize());
|
|
9440
|
+
}
|
|
9412
9441
|
const ix = await openPositionWithLiquidityOrcaInstruction(
|
|
9413
9442
|
authority,
|
|
9414
9443
|
positionMint,
|
|
@@ -9425,7 +9454,11 @@ async function openPositionWithLiquidityOrcaInstructions(rpc, authority, positio
|
|
|
9425
9454
|
cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
9426
9455
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
9427
9456
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
9428
|
-
return
|
|
9457
|
+
return {
|
|
9458
|
+
instructions,
|
|
9459
|
+
positionMint: positionMint.address,
|
|
9460
|
+
initializationCost: lamports(nonRefundableRent)
|
|
9461
|
+
};
|
|
9429
9462
|
}
|
|
9430
9463
|
async function openPositionWithLiquidityOrcaInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, args) {
|
|
9431
9464
|
const tunaPositionAddress = (await getTunaPositionAddress(positionMint.address))[0];
|
|
@@ -9541,18 +9574,22 @@ async function openPositionWithLiquidityOrcaInstruction(authority, positionMint,
|
|
|
9541
9574
|
|
|
9542
9575
|
// src/txbuilder/openPositionWithLiquidityFusion.ts
|
|
9543
9576
|
import {
|
|
9544
|
-
fetchAllMaybeTickArray as
|
|
9577
|
+
fetchAllMaybeTickArray as fetchAllMaybeTickArray3,
|
|
9545
9578
|
fetchMaybeFusionPool as fetchMaybeFusionPool7,
|
|
9546
9579
|
FP_NFT_UPDATE_AUTH as FP_NFT_UPDATE_AUTH2,
|
|
9547
9580
|
FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS8,
|
|
9548
9581
|
getInitializeTickArrayInstruction as getInitializeTickArrayInstruction2,
|
|
9549
9582
|
getPositionAddress as getPositionAddress16,
|
|
9550
|
-
getTickArrayAddress as getTickArrayAddress7
|
|
9583
|
+
getTickArrayAddress as getTickArrayAddress7,
|
|
9584
|
+
getTickArraySize
|
|
9551
9585
|
} from "@crypticdot/fusionamm-client";
|
|
9552
9586
|
import { getTickArrayStartTickIndex as getTickArrayStartTickIndex7 } from "@crypticdot/fusionamm-core";
|
|
9553
9587
|
import {
|
|
9554
|
-
AccountRole as AccountRole11
|
|
9588
|
+
AccountRole as AccountRole11,
|
|
9589
|
+
generateKeyPairSigner as generateKeyPairSigner2,
|
|
9590
|
+
lamports as lamports2
|
|
9555
9591
|
} from "@solana/kit";
|
|
9592
|
+
import { fetchSysvarRent as fetchSysvarRent2 } from "@solana/sysvars";
|
|
9556
9593
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS11 } from "@solana-program/memo";
|
|
9557
9594
|
import {
|
|
9558
9595
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS4,
|
|
@@ -9561,10 +9598,13 @@ import {
|
|
|
9561
9598
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS16
|
|
9562
9599
|
} from "@solana-program/token-2022";
|
|
9563
9600
|
import assert14 from "assert";
|
|
9564
|
-
async function openPositionWithLiquidityFusionInstructions(rpc, authority,
|
|
9601
|
+
async function openPositionWithLiquidityFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
9565
9602
|
const instructions = [];
|
|
9566
9603
|
if (!createInstructions) createInstructions = instructions;
|
|
9567
9604
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
9605
|
+
const rent = await fetchSysvarRent2(rpc);
|
|
9606
|
+
let nonRefundableRent = 0n;
|
|
9607
|
+
const positionMint = await generateKeyPairSigner2();
|
|
9568
9608
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
9569
9609
|
const fusionPool = await fetchMaybeFusionPool7(rpc, fusionPoolAddress);
|
|
9570
9610
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
@@ -9628,7 +9668,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9628
9668
|
const [lowerTickArrayAddress] = await getTickArrayAddress7(fusionPool.address, lowerTickArrayIndex);
|
|
9629
9669
|
const upperTickArrayIndex = getTickArrayStartTickIndex7(args.tickUpperIndex, fusionPool.data.tickSpacing);
|
|
9630
9670
|
const [upperTickArrayAddress] = await getTickArrayAddress7(fusionPool.address, upperTickArrayIndex);
|
|
9631
|
-
const [lowerTickArray, upperTickArray] = await
|
|
9671
|
+
const [lowerTickArray, upperTickArray] = await fetchAllMaybeTickArray3(rpc, [
|
|
9632
9672
|
lowerTickArrayAddress,
|
|
9633
9673
|
upperTickArrayAddress
|
|
9634
9674
|
]);
|
|
@@ -9641,6 +9681,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9641
9681
|
startTickIndex: lowerTickArrayIndex
|
|
9642
9682
|
})
|
|
9643
9683
|
);
|
|
9684
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getTickArraySize());
|
|
9644
9685
|
}
|
|
9645
9686
|
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
9646
9687
|
instructions.push(
|
|
@@ -9651,6 +9692,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9651
9692
|
startTickIndex: upperTickArrayIndex
|
|
9652
9693
|
})
|
|
9653
9694
|
);
|
|
9695
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getTickArraySize());
|
|
9654
9696
|
}
|
|
9655
9697
|
const ix = await openPositionWithLiquidityFusionInstruction(
|
|
9656
9698
|
authority,
|
|
@@ -9668,7 +9710,11 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9668
9710
|
cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
9669
9711
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
9670
9712
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
9671
|
-
return
|
|
9713
|
+
return {
|
|
9714
|
+
instructions,
|
|
9715
|
+
positionMint: positionMint.address,
|
|
9716
|
+
initializationCost: lamports2(nonRefundableRent)
|
|
9717
|
+
};
|
|
9672
9718
|
}
|
|
9673
9719
|
async function openPositionWithLiquidityFusionInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, args) {
|
|
9674
9720
|
const tunaPositionAddress = (await getTunaPositionAddress(positionMint.address))[0];
|
|
@@ -10474,15 +10520,19 @@ async function repayDebtInstruction(authority, positionMint, mintA, mintB, marke
|
|
|
10474
10520
|
|
|
10475
10521
|
// src/txbuilder/rebalancePositionOrca.ts
|
|
10476
10522
|
import {
|
|
10523
|
+
fetchAllMaybeTickArray as fetchAllMaybeTickArray4,
|
|
10477
10524
|
fetchMaybeWhirlpool as fetchMaybeWhirlpool9,
|
|
10525
|
+
getDynamicTickArrayMinSize as getDynamicTickArrayMinSize2,
|
|
10478
10526
|
getInitializeDynamicTickArrayInstruction as getInitializeDynamicTickArrayInstruction3,
|
|
10479
10527
|
getOracleAddress as getOracleAddress7,
|
|
10480
10528
|
getPositionAddress as getPositionAddress19,
|
|
10481
10529
|
WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS11
|
|
10482
10530
|
} from "@orca-so/whirlpools-client";
|
|
10483
10531
|
import {
|
|
10484
|
-
AccountRole as AccountRole14
|
|
10532
|
+
AccountRole as AccountRole14,
|
|
10533
|
+
lamports as lamports3
|
|
10485
10534
|
} from "@solana/kit";
|
|
10535
|
+
import { fetchSysvarRent as fetchSysvarRent3 } from "@solana/sysvars";
|
|
10486
10536
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS18 } from "@solana-program/memo";
|
|
10487
10537
|
import {
|
|
10488
10538
|
fetchAllMaybeMint as fetchAllMaybeMint18,
|
|
@@ -10491,6 +10541,8 @@ import {
|
|
|
10491
10541
|
} from "@solana-program/token-2022";
|
|
10492
10542
|
import assert18 from "assert";
|
|
10493
10543
|
async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
10544
|
+
const rent = await fetchSysvarRent3(rpc);
|
|
10545
|
+
let nonRefundableRent = 0n;
|
|
10494
10546
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
10495
10547
|
const tunaPosition = await fetchMaybeTunaPosition(rpc, (await getTunaPositionAddress(positionMint))[0]);
|
|
10496
10548
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -10508,24 +10560,34 @@ async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, c
|
|
|
10508
10560
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
10509
10561
|
const internalCleanupInstructions = [];
|
|
10510
10562
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10563
|
+
const [lowerTickArray, upperTickArray] = await fetchAllMaybeTickArray4(rpc, [
|
|
10564
|
+
secondaryTickArrays.lowerTickArrayAddress,
|
|
10565
|
+
secondaryTickArrays.upperTickArrayAddress
|
|
10566
|
+
]);
|
|
10567
|
+
if (!lowerTickArray.exists) {
|
|
10568
|
+
instructions.push(
|
|
10569
|
+
getInitializeDynamicTickArrayInstruction3({
|
|
10570
|
+
whirlpool: whirlpool.address,
|
|
10571
|
+
funder: authority,
|
|
10572
|
+
tickArray: secondaryTickArrays.lowerTickArrayAddress,
|
|
10573
|
+
startTickIndex: secondaryTickArrays.lowerTickArrayStartIndex,
|
|
10574
|
+
idempotent: false
|
|
10575
|
+
})
|
|
10576
|
+
);
|
|
10577
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getDynamicTickArrayMinSize2());
|
|
10578
|
+
}
|
|
10579
|
+
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
10580
|
+
instructions.push(
|
|
10581
|
+
getInitializeDynamicTickArrayInstruction3({
|
|
10582
|
+
whirlpool: whirlpool.address,
|
|
10583
|
+
funder: authority,
|
|
10584
|
+
tickArray: secondaryTickArrays.upperTickArrayAddress,
|
|
10585
|
+
startTickIndex: secondaryTickArrays.upperTickArrayStartIndex,
|
|
10586
|
+
idempotent: false
|
|
10587
|
+
})
|
|
10588
|
+
);
|
|
10589
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getDynamicTickArrayMinSize2());
|
|
10590
|
+
}
|
|
10529
10591
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10530
10592
|
rpc,
|
|
10531
10593
|
authority,
|
|
@@ -10556,7 +10618,10 @@ async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, c
|
|
|
10556
10618
|
cleanupInstructions.push(...internalCleanupInstructions);
|
|
10557
10619
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
10558
10620
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
10559
|
-
return
|
|
10621
|
+
return {
|
|
10622
|
+
instructions,
|
|
10623
|
+
initializationCost: lamports3(nonRefundableRent)
|
|
10624
|
+
};
|
|
10560
10625
|
}
|
|
10561
10626
|
async function rebalancePositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool) {
|
|
10562
10627
|
const positionMint = tunaPosition.data.positionMint;
|
|
@@ -10654,15 +10719,18 @@ async function rebalancePositionOrcaInstruction(authority, tunaPosition, tunaCon
|
|
|
10654
10719
|
|
|
10655
10720
|
// src/txbuilder/rebalancePositionFusion.ts
|
|
10656
10721
|
import {
|
|
10657
|
-
fetchAllMaybeTickArray as
|
|
10722
|
+
fetchAllMaybeTickArray as fetchAllMaybeTickArray5,
|
|
10658
10723
|
fetchMaybeFusionPool as fetchMaybeFusionPool9,
|
|
10659
10724
|
FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS11,
|
|
10660
10725
|
getInitializeTickArrayInstruction as getInitializeTickArrayInstruction3,
|
|
10661
|
-
getPositionAddress as getPositionAddress20
|
|
10726
|
+
getPositionAddress as getPositionAddress20,
|
|
10727
|
+
getTickArraySize as getTickArraySize2
|
|
10662
10728
|
} from "@crypticdot/fusionamm-client";
|
|
10663
10729
|
import {
|
|
10664
|
-
AccountRole as AccountRole15
|
|
10730
|
+
AccountRole as AccountRole15,
|
|
10731
|
+
lamports as lamports4
|
|
10665
10732
|
} from "@solana/kit";
|
|
10733
|
+
import { fetchSysvarRent as fetchSysvarRent4 } from "@solana/sysvars";
|
|
10666
10734
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS19 } from "@solana-program/memo";
|
|
10667
10735
|
import {
|
|
10668
10736
|
fetchAllMaybeMint as fetchAllMaybeMint19,
|
|
@@ -10671,6 +10739,8 @@ import {
|
|
|
10671
10739
|
} from "@solana-program/token-2022";
|
|
10672
10740
|
import assert19 from "assert";
|
|
10673
10741
|
async function rebalancePositionFusionInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
10742
|
+
const rent = await fetchSysvarRent4(rpc);
|
|
10743
|
+
let nonRefundableRent = 0n;
|
|
10674
10744
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
10675
10745
|
const tunaPosition = await fetchMaybeTunaPosition(rpc, (await getTunaPositionAddress(positionMint))[0]);
|
|
10676
10746
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -10687,7 +10757,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10687
10757
|
if (!createInstructions) createInstructions = instructions;
|
|
10688
10758
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
10689
10759
|
const secondaryTickArrays = await FusionUtils.getTickArraysForRebalancedPosition(fusionPool, tunaPosition);
|
|
10690
|
-
const [lowerTickArray, upperTickArray] = await
|
|
10760
|
+
const [lowerTickArray, upperTickArray] = await fetchAllMaybeTickArray5(rpc, [
|
|
10691
10761
|
secondaryTickArrays.lowerTickArrayAddress,
|
|
10692
10762
|
secondaryTickArrays.upperTickArrayAddress
|
|
10693
10763
|
]);
|
|
@@ -10700,6 +10770,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10700
10770
|
startTickIndex: secondaryTickArrays.lowerTickArrayStartIndex
|
|
10701
10771
|
})
|
|
10702
10772
|
);
|
|
10773
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getTickArraySize2());
|
|
10703
10774
|
}
|
|
10704
10775
|
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
10705
10776
|
instructions.push(
|
|
@@ -10710,6 +10781,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10710
10781
|
startTickIndex: secondaryTickArrays.upperTickArrayStartIndex
|
|
10711
10782
|
})
|
|
10712
10783
|
);
|
|
10784
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getTickArraySize2());
|
|
10713
10785
|
}
|
|
10714
10786
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10715
10787
|
rpc,
|
|
@@ -10740,7 +10812,10 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10740
10812
|
instructions.push(ix);
|
|
10741
10813
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
10742
10814
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
10743
|
-
return
|
|
10815
|
+
return {
|
|
10816
|
+
instructions,
|
|
10817
|
+
initializationCost: lamports4(nonRefundableRent)
|
|
10818
|
+
};
|
|
10744
10819
|
}
|
|
10745
10820
|
async function rebalancePositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool) {
|
|
10746
10821
|
const positionMint = tunaPosition.data.positionMint;
|
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": "2.0.
|
|
4
|
+
"version": "2.0.15",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"@crypticdot/fusionamm-client": "^1.0.54",
|
|
24
24
|
"@crypticdot/fusionamm-sdk": "^1.0.54",
|
|
25
25
|
"@solana/kit": "^2.1.0",
|
|
26
|
+
"@solana/sysvars": "^2.1.0",
|
|
26
27
|
"@solana-program/compute-budget": "^0.7.0",
|
|
27
28
|
"@solana-program/system": "^0.7.0",
|
|
28
29
|
"@solana-program/token": "^0.5.1",
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"rimraf": "^6.0.1",
|
|
52
53
|
"vitest": "^3.1.1",
|
|
53
54
|
"solana-bankrun": "^0.4.0",
|
|
54
|
-
"@crypticdot/defituna-program": "2.0.
|
|
55
|
+
"@crypticdot/defituna-program": "2.0.5"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
57
58
|
"build": "node ./codama.mjs && tsup src/index.ts --format cjs,esm --dts",
|