@crypticdot/defituna-client 2.0.12 → 2.0.14
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 +49 -23
- package/dist/index.d.ts +49 -23
- package/dist/index.js +121 -76
- package/dist/index.mjs +142 -79
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -288,7 +288,8 @@ function getMarketEncoder() {
|
|
|
288
288
|
["borrowLimitA", getU64Encoder2()],
|
|
289
289
|
["borrowLimitB", getU64Encoder2()],
|
|
290
290
|
["maxSwapSlippage", getU32Encoder()],
|
|
291
|
-
["
|
|
291
|
+
["rebalanceProtocolFee", getU32Encoder()],
|
|
292
|
+
["reserved", fixEncoderSize2(getBytesEncoder2(), 207)]
|
|
292
293
|
]),
|
|
293
294
|
(value) => ({ ...value, discriminator: MARKET_DISCRIMINATOR })
|
|
294
295
|
);
|
|
@@ -314,7 +315,8 @@ function getMarketDecoder() {
|
|
|
314
315
|
["borrowLimitA", getU64Decoder2()],
|
|
315
316
|
["borrowLimitB", getU64Decoder2()],
|
|
316
317
|
["maxSwapSlippage", getU32Decoder()],
|
|
317
|
-
["
|
|
318
|
+
["rebalanceProtocolFee", getU32Decoder()],
|
|
319
|
+
["reserved", fixDecoderSize2(getBytesDecoder2(), 207)]
|
|
318
320
|
]);
|
|
319
321
|
}
|
|
320
322
|
function getMarketCodec() {
|
|
@@ -1247,13 +1249,7 @@ var TUNA_ERROR__WITHDRAW_REQUEST_EXCEEDS_USER_BALANCE = 6052;
|
|
|
1247
1249
|
var TUNA_ERROR__ZERO_PRICE_RANGE = 6053;
|
|
1248
1250
|
var TUNA_ERROR__ZERO_TRADABLE_AMOUNT = 6054;
|
|
1249
1251
|
var TUNA_ERROR__ZERO_YIELD = 6055;
|
|
1250
|
-
var
|
|
1251
|
-
var TUNA_ERROR__RAYDIUM_INVALID_TICK_ARRAY = 6057;
|
|
1252
|
-
var TUNA_ERROR__RAYDIUM_INVAILD_TICK_INDEX = 6058;
|
|
1253
|
-
var TUNA_ERROR__RAYDIUM_MAX_TOKEN_OVERFLOW = 6059;
|
|
1254
|
-
var TUNA_ERROR__RAYDIUM_NOT_ENOUGH_TICK_ARRAY_ACCOUNT = 6060;
|
|
1255
|
-
var TUNA_ERROR__RAYDIUM_SQRT_PRICE_LIMIT_OVERFLOW = 6061;
|
|
1256
|
-
var TUNA_ERROR__RAYDIUM_ZERO_AMOUNT_SPECIFIED = 6062;
|
|
1252
|
+
var TUNA_ERROR__POSITION_IS_AUTO_REBALANCEABLE = 6056;
|
|
1257
1253
|
var tunaErrorMessages;
|
|
1258
1254
|
if (process.env.NODE_ENV !== "production") {
|
|
1259
1255
|
tunaErrorMessages = {
|
|
@@ -1282,18 +1278,12 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
1282
1278
|
[TUNA_ERROR__ORACLE_PRICE_DEVIATION_THRESHOLD_OUT_OF_RANGE]: `OraclePriceDeviationThresholdOutOfRange`,
|
|
1283
1279
|
[TUNA_ERROR__ORACLE_STALE_PRICE]: `Oracle price is stale`,
|
|
1284
1280
|
[TUNA_ERROR__PARTIAL_FILL_ERROR]: `Trade resulted in partial fill`,
|
|
1281
|
+
[TUNA_ERROR__POSITION_IS_AUTO_REBALANCEABLE]: `Unable to claim yield for auto re-balanceable positions`,
|
|
1285
1282
|
[TUNA_ERROR__POSITION_IS_HEALTHY]: `Position is healthy`,
|
|
1286
1283
|
[TUNA_ERROR__POSITION_IS_LIQUIDATED]: `Position is already liquidated`,
|
|
1287
1284
|
[TUNA_ERROR__POSITION_IS_UNHEALTHY]: `Position is unhealthy`,
|
|
1288
1285
|
[TUNA_ERROR__POSITION_NOT_EMPTY]: `Position is not empty`,
|
|
1289
1286
|
[TUNA_ERROR__PROTOCOL_FEE_IS_OUT_OF_RANGE]: `Protocol fee is out of range`,
|
|
1290
|
-
[TUNA_ERROR__RAYDIUM_INVAILD_TICK_INDEX]: `RaydiumInvaildTickIndex`,
|
|
1291
|
-
[TUNA_ERROR__RAYDIUM_INVALID_FIRST_TICK_ARRAY_ACCOUNT]: `RaydiumInvalidFirstTickArrayAccount`,
|
|
1292
|
-
[TUNA_ERROR__RAYDIUM_INVALID_TICK_ARRAY]: `RaydiumInvalidTickArray`,
|
|
1293
|
-
[TUNA_ERROR__RAYDIUM_MAX_TOKEN_OVERFLOW]: `RaydiumMaxTokenOverflow`,
|
|
1294
|
-
[TUNA_ERROR__RAYDIUM_NOT_ENOUGH_TICK_ARRAY_ACCOUNT]: `RaydiumNotEnoughTickArrayAccount`,
|
|
1295
|
-
[TUNA_ERROR__RAYDIUM_SQRT_PRICE_LIMIT_OVERFLOW]: `RaydiumSqrtPriceLimitOverflow`,
|
|
1296
|
-
[TUNA_ERROR__RAYDIUM_ZERO_AMOUNT_SPECIFIED]: `RaydiumZeroAmountSpecified`,
|
|
1297
1287
|
[TUNA_ERROR__REBALANCE_CONDITIONS_NOT_MET]: `Rebalance conditions are not met`,
|
|
1298
1288
|
[TUNA_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE]: `Same accounts type is provided more than once`,
|
|
1299
1289
|
[TUNA_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT]: `Insufficient remaining accounts`,
|
|
@@ -2902,7 +2892,8 @@ function getCreateMarketInstructionDataEncoder() {
|
|
|
2902
2892
|
["disabled", getBooleanEncoder5()],
|
|
2903
2893
|
["borrowLimitA", getU64Encoder7()],
|
|
2904
2894
|
["borrowLimitB", getU64Encoder7()],
|
|
2905
|
-
["maxSwapSlippage", getU32Encoder6()]
|
|
2895
|
+
["maxSwapSlippage", getU32Encoder6()],
|
|
2896
|
+
["rebalanceProtocolFee", getU32Encoder6()]
|
|
2906
2897
|
]),
|
|
2907
2898
|
(value) => ({ ...value, discriminator: CREATE_MARKET_DISCRIMINATOR })
|
|
2908
2899
|
);
|
|
@@ -2922,7 +2913,8 @@ function getCreateMarketInstructionDataDecoder() {
|
|
|
2922
2913
|
["disabled", getBooleanDecoder5()],
|
|
2923
2914
|
["borrowLimitA", getU64Decoder7()],
|
|
2924
2915
|
["borrowLimitB", getU64Decoder7()],
|
|
2925
|
-
["maxSwapSlippage", getU32Decoder6()]
|
|
2916
|
+
["maxSwapSlippage", getU32Decoder6()],
|
|
2917
|
+
["rebalanceProtocolFee", getU32Decoder6()]
|
|
2926
2918
|
]);
|
|
2927
2919
|
}
|
|
2928
2920
|
function getCreateMarketInstructionDataCodec() {
|
|
@@ -6670,7 +6662,8 @@ function getUpdateMarketInstructionDataEncoder() {
|
|
|
6670
6662
|
["disabled", getBooleanEncoder7()],
|
|
6671
6663
|
["borrowLimitA", getU64Encoder16()],
|
|
6672
6664
|
["borrowLimitB", getU64Encoder16()],
|
|
6673
|
-
["maxSwapSlippage", getU32Encoder20()]
|
|
6665
|
+
["maxSwapSlippage", getU32Encoder20()],
|
|
6666
|
+
["rebalanceProtocolFee", getU32Encoder20()]
|
|
6674
6667
|
]),
|
|
6675
6668
|
(value) => ({ ...value, discriminator: UPDATE_MARKET_DISCRIMINATOR })
|
|
6676
6669
|
);
|
|
@@ -6689,7 +6682,8 @@ function getUpdateMarketInstructionDataDecoder() {
|
|
|
6689
6682
|
["disabled", getBooleanDecoder7()],
|
|
6690
6683
|
["borrowLimitA", getU64Decoder16()],
|
|
6691
6684
|
["borrowLimitB", getU64Decoder16()],
|
|
6692
|
-
["maxSwapSlippage", getU32Decoder20()]
|
|
6685
|
+
["maxSwapSlippage", getU32Decoder20()],
|
|
6686
|
+
["rebalanceProtocolFee", getU32Decoder20()]
|
|
6693
6687
|
]);
|
|
6694
6688
|
}
|
|
6695
6689
|
function getUpdateMarketInstructionDataCodec() {
|
|
@@ -9311,7 +9305,9 @@ async function openPositionFusionInstruction(rpc, authority, positionMint, fusio
|
|
|
9311
9305
|
|
|
9312
9306
|
// src/txbuilder/openPositionWithLiquidityOrca.ts
|
|
9313
9307
|
import {
|
|
9308
|
+
fetchAllMaybeTickArray as fetchAllMaybeTickArray2,
|
|
9314
9309
|
fetchMaybeWhirlpool as fetchMaybeWhirlpool7,
|
|
9310
|
+
getDynamicTickArrayMinSize,
|
|
9315
9311
|
getInitializeDynamicTickArrayInstruction as getInitializeDynamicTickArrayInstruction2,
|
|
9316
9312
|
getOracleAddress as getOracleAddress4,
|
|
9317
9313
|
getPositionAddress as getPositionAddress15,
|
|
@@ -9320,8 +9316,11 @@ import {
|
|
|
9320
9316
|
} from "@orca-so/whirlpools-client";
|
|
9321
9317
|
import { getTickArrayStartTickIndex as getTickArrayStartTickIndex6 } from "@orca-so/whirlpools-core";
|
|
9322
9318
|
import {
|
|
9323
|
-
AccountRole as AccountRole10
|
|
9319
|
+
AccountRole as AccountRole10,
|
|
9320
|
+
generateKeyPairSigner,
|
|
9321
|
+
lamports
|
|
9324
9322
|
} from "@solana/kit";
|
|
9323
|
+
import { fetchSysvarRent } from "@solana/sysvars";
|
|
9325
9324
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS10 } from "@solana-program/memo";
|
|
9326
9325
|
import {
|
|
9327
9326
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS3,
|
|
@@ -9330,10 +9329,24 @@ import {
|
|
|
9330
9329
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS15
|
|
9331
9330
|
} from "@solana-program/token-2022";
|
|
9332
9331
|
import assert13 from "assert";
|
|
9333
|
-
|
|
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) {
|
|
9334
9344
|
const instructions = [];
|
|
9335
9345
|
if (!createInstructions) createInstructions = instructions;
|
|
9336
9346
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
9347
|
+
const rent = await fetchSysvarRent(rpc);
|
|
9348
|
+
let nonRefundableRent = 0n;
|
|
9349
|
+
const positionMint = await generateKeyPairSigner();
|
|
9337
9350
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
9338
9351
|
const whirlpool = await fetchMaybeWhirlpool7(rpc, whirlpoolAddress);
|
|
9339
9352
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
@@ -9397,24 +9410,34 @@ async function openPositionWithLiquidityOrcaInstructions(rpc, authority, positio
|
|
|
9397
9410
|
const [lowerTickArrayAddress] = await getTickArrayAddress6(whirlpool.address, lowerTickArrayIndex);
|
|
9398
9411
|
const upperTickArrayIndex = getTickArrayStartTickIndex6(args.tickUpperIndex, whirlpool.data.tickSpacing);
|
|
9399
9412
|
const [upperTickArrayAddress] = await getTickArrayAddress6(whirlpool.address, upperTickArrayIndex);
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
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
|
+
}
|
|
9418
9441
|
const ix = await openPositionWithLiquidityOrcaInstruction(
|
|
9419
9442
|
authority,
|
|
9420
9443
|
positionMint,
|
|
@@ -9431,7 +9454,11 @@ async function openPositionWithLiquidityOrcaInstructions(rpc, authority, positio
|
|
|
9431
9454
|
cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
9432
9455
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
9433
9456
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
9434
|
-
return
|
|
9457
|
+
return {
|
|
9458
|
+
instructions,
|
|
9459
|
+
positionMint: positionMint.address,
|
|
9460
|
+
initializationCost: lamports(nonRefundableRent)
|
|
9461
|
+
};
|
|
9435
9462
|
}
|
|
9436
9463
|
async function openPositionWithLiquidityOrcaInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, args) {
|
|
9437
9464
|
const tunaPositionAddress = (await getTunaPositionAddress(positionMint.address))[0];
|
|
@@ -9547,18 +9574,22 @@ async function openPositionWithLiquidityOrcaInstruction(authority, positionMint,
|
|
|
9547
9574
|
|
|
9548
9575
|
// src/txbuilder/openPositionWithLiquidityFusion.ts
|
|
9549
9576
|
import {
|
|
9550
|
-
fetchAllMaybeTickArray as
|
|
9577
|
+
fetchAllMaybeTickArray as fetchAllMaybeTickArray3,
|
|
9551
9578
|
fetchMaybeFusionPool as fetchMaybeFusionPool7,
|
|
9552
9579
|
FP_NFT_UPDATE_AUTH as FP_NFT_UPDATE_AUTH2,
|
|
9553
9580
|
FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS8,
|
|
9554
9581
|
getInitializeTickArrayInstruction as getInitializeTickArrayInstruction2,
|
|
9555
9582
|
getPositionAddress as getPositionAddress16,
|
|
9556
|
-
getTickArrayAddress as getTickArrayAddress7
|
|
9583
|
+
getTickArrayAddress as getTickArrayAddress7,
|
|
9584
|
+
getTickArraySize
|
|
9557
9585
|
} from "@crypticdot/fusionamm-client";
|
|
9558
9586
|
import { getTickArrayStartTickIndex as getTickArrayStartTickIndex7 } from "@crypticdot/fusionamm-core";
|
|
9559
9587
|
import {
|
|
9560
|
-
AccountRole as AccountRole11
|
|
9588
|
+
AccountRole as AccountRole11,
|
|
9589
|
+
generateKeyPairSigner as generateKeyPairSigner2,
|
|
9590
|
+
lamports as lamports2
|
|
9561
9591
|
} from "@solana/kit";
|
|
9592
|
+
import { fetchSysvarRent as fetchSysvarRent2 } from "@solana/sysvars";
|
|
9562
9593
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS11 } from "@solana-program/memo";
|
|
9563
9594
|
import {
|
|
9564
9595
|
ASSOCIATED_TOKEN_PROGRAM_ADDRESS as ASSOCIATED_TOKEN_PROGRAM_ADDRESS4,
|
|
@@ -9567,10 +9598,13 @@ import {
|
|
|
9567
9598
|
TOKEN_2022_PROGRAM_ADDRESS as TOKEN_2022_PROGRAM_ADDRESS16
|
|
9568
9599
|
} from "@solana-program/token-2022";
|
|
9569
9600
|
import assert14 from "assert";
|
|
9570
|
-
async function openPositionWithLiquidityFusionInstructions(rpc, authority,
|
|
9601
|
+
async function openPositionWithLiquidityFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
9571
9602
|
const instructions = [];
|
|
9572
9603
|
if (!createInstructions) createInstructions = instructions;
|
|
9573
9604
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
9605
|
+
const rent = await fetchSysvarRent2(rpc);
|
|
9606
|
+
let nonRefundableRent = 0n;
|
|
9607
|
+
const positionMint = await generateKeyPairSigner2();
|
|
9574
9608
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
9575
9609
|
const fusionPool = await fetchMaybeFusionPool7(rpc, fusionPoolAddress);
|
|
9576
9610
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
@@ -9634,7 +9668,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9634
9668
|
const [lowerTickArrayAddress] = await getTickArrayAddress7(fusionPool.address, lowerTickArrayIndex);
|
|
9635
9669
|
const upperTickArrayIndex = getTickArrayStartTickIndex7(args.tickUpperIndex, fusionPool.data.tickSpacing);
|
|
9636
9670
|
const [upperTickArrayAddress] = await getTickArrayAddress7(fusionPool.address, upperTickArrayIndex);
|
|
9637
|
-
const [lowerTickArray, upperTickArray] = await
|
|
9671
|
+
const [lowerTickArray, upperTickArray] = await fetchAllMaybeTickArray3(rpc, [
|
|
9638
9672
|
lowerTickArrayAddress,
|
|
9639
9673
|
upperTickArrayAddress
|
|
9640
9674
|
]);
|
|
@@ -9647,6 +9681,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9647
9681
|
startTickIndex: lowerTickArrayIndex
|
|
9648
9682
|
})
|
|
9649
9683
|
);
|
|
9684
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getTickArraySize());
|
|
9650
9685
|
}
|
|
9651
9686
|
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
9652
9687
|
instructions.push(
|
|
@@ -9657,6 +9692,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9657
9692
|
startTickIndex: upperTickArrayIndex
|
|
9658
9693
|
})
|
|
9659
9694
|
);
|
|
9695
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getTickArraySize());
|
|
9660
9696
|
}
|
|
9661
9697
|
const ix = await openPositionWithLiquidityFusionInstruction(
|
|
9662
9698
|
authority,
|
|
@@ -9674,7 +9710,11 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9674
9710
|
cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
9675
9711
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
9676
9712
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
9677
|
-
return
|
|
9713
|
+
return {
|
|
9714
|
+
instructions,
|
|
9715
|
+
positionMint: positionMint.address,
|
|
9716
|
+
initializationCost: lamports2(nonRefundableRent)
|
|
9717
|
+
};
|
|
9678
9718
|
}
|
|
9679
9719
|
async function openPositionWithLiquidityFusionInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, args) {
|
|
9680
9720
|
const tunaPositionAddress = (await getTunaPositionAddress(positionMint.address))[0];
|
|
@@ -10480,15 +10520,19 @@ async function repayDebtInstruction(authority, positionMint, mintA, mintB, marke
|
|
|
10480
10520
|
|
|
10481
10521
|
// src/txbuilder/rebalancePositionOrca.ts
|
|
10482
10522
|
import {
|
|
10523
|
+
fetchAllMaybeTickArray as fetchAllMaybeTickArray4,
|
|
10483
10524
|
fetchMaybeWhirlpool as fetchMaybeWhirlpool9,
|
|
10525
|
+
getDynamicTickArrayMinSize as getDynamicTickArrayMinSize2,
|
|
10484
10526
|
getInitializeDynamicTickArrayInstruction as getInitializeDynamicTickArrayInstruction3,
|
|
10485
10527
|
getOracleAddress as getOracleAddress7,
|
|
10486
10528
|
getPositionAddress as getPositionAddress19,
|
|
10487
10529
|
WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS11
|
|
10488
10530
|
} from "@orca-so/whirlpools-client";
|
|
10489
10531
|
import {
|
|
10490
|
-
AccountRole as AccountRole14
|
|
10532
|
+
AccountRole as AccountRole14,
|
|
10533
|
+
lamports as lamports3
|
|
10491
10534
|
} from "@solana/kit";
|
|
10535
|
+
import { fetchSysvarRent as fetchSysvarRent3 } from "@solana/sysvars";
|
|
10492
10536
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS18 } from "@solana-program/memo";
|
|
10493
10537
|
import {
|
|
10494
10538
|
fetchAllMaybeMint as fetchAllMaybeMint18,
|
|
@@ -10497,6 +10541,8 @@ import {
|
|
|
10497
10541
|
} from "@solana-program/token-2022";
|
|
10498
10542
|
import assert18 from "assert";
|
|
10499
10543
|
async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
10544
|
+
const rent = await fetchSysvarRent3(rpc);
|
|
10545
|
+
let nonRefundableRent = 0n;
|
|
10500
10546
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
10501
10547
|
const tunaPosition = await fetchMaybeTunaPosition(rpc, (await getTunaPositionAddress(positionMint))[0]);
|
|
10502
10548
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -10514,24 +10560,34 @@ async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, c
|
|
|
10514
10560
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
10515
10561
|
const internalCleanupInstructions = [];
|
|
10516
10562
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
|
|
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
|
+
}
|
|
10535
10591
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10536
10592
|
rpc,
|
|
10537
10593
|
authority,
|
|
@@ -10562,7 +10618,10 @@ async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, c
|
|
|
10562
10618
|
cleanupInstructions.push(...internalCleanupInstructions);
|
|
10563
10619
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
10564
10620
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
10565
|
-
return
|
|
10621
|
+
return {
|
|
10622
|
+
instructions,
|
|
10623
|
+
initializationCost: lamports3(nonRefundableRent)
|
|
10624
|
+
};
|
|
10566
10625
|
}
|
|
10567
10626
|
async function rebalancePositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool) {
|
|
10568
10627
|
const positionMint = tunaPosition.data.positionMint;
|
|
@@ -10660,15 +10719,18 @@ async function rebalancePositionOrcaInstruction(authority, tunaPosition, tunaCon
|
|
|
10660
10719
|
|
|
10661
10720
|
// src/txbuilder/rebalancePositionFusion.ts
|
|
10662
10721
|
import {
|
|
10663
|
-
fetchAllMaybeTickArray as
|
|
10722
|
+
fetchAllMaybeTickArray as fetchAllMaybeTickArray5,
|
|
10664
10723
|
fetchMaybeFusionPool as fetchMaybeFusionPool9,
|
|
10665
10724
|
FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS11,
|
|
10666
10725
|
getInitializeTickArrayInstruction as getInitializeTickArrayInstruction3,
|
|
10667
|
-
getPositionAddress as getPositionAddress20
|
|
10726
|
+
getPositionAddress as getPositionAddress20,
|
|
10727
|
+
getTickArraySize as getTickArraySize2
|
|
10668
10728
|
} from "@crypticdot/fusionamm-client";
|
|
10669
10729
|
import {
|
|
10670
|
-
AccountRole as AccountRole15
|
|
10730
|
+
AccountRole as AccountRole15,
|
|
10731
|
+
lamports as lamports4
|
|
10671
10732
|
} from "@solana/kit";
|
|
10733
|
+
import { fetchSysvarRent as fetchSysvarRent4 } from "@solana/sysvars";
|
|
10672
10734
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS19 } from "@solana-program/memo";
|
|
10673
10735
|
import {
|
|
10674
10736
|
fetchAllMaybeMint as fetchAllMaybeMint19,
|
|
@@ -10677,6 +10739,8 @@ import {
|
|
|
10677
10739
|
} from "@solana-program/token-2022";
|
|
10678
10740
|
import assert19 from "assert";
|
|
10679
10741
|
async function rebalancePositionFusionInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
10742
|
+
const rent = await fetchSysvarRent4(rpc);
|
|
10743
|
+
let nonRefundableRent = 0n;
|
|
10680
10744
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
10681
10745
|
const tunaPosition = await fetchMaybeTunaPosition(rpc, (await getTunaPositionAddress(positionMint))[0]);
|
|
10682
10746
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -10693,7 +10757,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10693
10757
|
if (!createInstructions) createInstructions = instructions;
|
|
10694
10758
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
10695
10759
|
const secondaryTickArrays = await FusionUtils.getTickArraysForRebalancedPosition(fusionPool, tunaPosition);
|
|
10696
|
-
const [lowerTickArray, upperTickArray] = await
|
|
10760
|
+
const [lowerTickArray, upperTickArray] = await fetchAllMaybeTickArray5(rpc, [
|
|
10697
10761
|
secondaryTickArrays.lowerTickArrayAddress,
|
|
10698
10762
|
secondaryTickArrays.upperTickArrayAddress
|
|
10699
10763
|
]);
|
|
@@ -10706,6 +10770,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10706
10770
|
startTickIndex: secondaryTickArrays.lowerTickArrayStartIndex
|
|
10707
10771
|
})
|
|
10708
10772
|
);
|
|
10773
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getTickArraySize2());
|
|
10709
10774
|
}
|
|
10710
10775
|
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
10711
10776
|
instructions.push(
|
|
@@ -10716,6 +10781,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10716
10781
|
startTickIndex: secondaryTickArrays.upperTickArrayStartIndex
|
|
10717
10782
|
})
|
|
10718
10783
|
);
|
|
10784
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, getTickArraySize2());
|
|
10719
10785
|
}
|
|
10720
10786
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10721
10787
|
rpc,
|
|
@@ -10746,7 +10812,10 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10746
10812
|
instructions.push(ix);
|
|
10747
10813
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
10748
10814
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
10749
|
-
return
|
|
10815
|
+
return {
|
|
10816
|
+
instructions,
|
|
10817
|
+
initializationCost: lamports4(nonRefundableRent)
|
|
10818
|
+
};
|
|
10750
10819
|
}
|
|
10751
10820
|
async function rebalancePositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool) {
|
|
10752
10821
|
const positionMint = tunaPosition.data.positionMint;
|
|
@@ -10922,18 +10991,12 @@ export {
|
|
|
10922
10991
|
TUNA_ERROR__ORACLE_PRICE_DEVIATION_THRESHOLD_OUT_OF_RANGE,
|
|
10923
10992
|
TUNA_ERROR__ORACLE_STALE_PRICE,
|
|
10924
10993
|
TUNA_ERROR__PARTIAL_FILL_ERROR,
|
|
10994
|
+
TUNA_ERROR__POSITION_IS_AUTO_REBALANCEABLE,
|
|
10925
10995
|
TUNA_ERROR__POSITION_IS_HEALTHY,
|
|
10926
10996
|
TUNA_ERROR__POSITION_IS_LIQUIDATED,
|
|
10927
10997
|
TUNA_ERROR__POSITION_IS_UNHEALTHY,
|
|
10928
10998
|
TUNA_ERROR__POSITION_NOT_EMPTY,
|
|
10929
10999
|
TUNA_ERROR__PROTOCOL_FEE_IS_OUT_OF_RANGE,
|
|
10930
|
-
TUNA_ERROR__RAYDIUM_INVAILD_TICK_INDEX,
|
|
10931
|
-
TUNA_ERROR__RAYDIUM_INVALID_FIRST_TICK_ARRAY_ACCOUNT,
|
|
10932
|
-
TUNA_ERROR__RAYDIUM_INVALID_TICK_ARRAY,
|
|
10933
|
-
TUNA_ERROR__RAYDIUM_MAX_TOKEN_OVERFLOW,
|
|
10934
|
-
TUNA_ERROR__RAYDIUM_NOT_ENOUGH_TICK_ARRAY_ACCOUNT,
|
|
10935
|
-
TUNA_ERROR__RAYDIUM_SQRT_PRICE_LIMIT_OVERFLOW,
|
|
10936
|
-
TUNA_ERROR__RAYDIUM_ZERO_AMOUNT_SPECIFIED,
|
|
10937
11000
|
TUNA_ERROR__REBALANCE_CONDITIONS_NOT_MET,
|
|
10938
11001
|
TUNA_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE,
|
|
10939
11002
|
TUNA_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT,
|
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.14",
|
|
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.4"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
57
58
|
"build": "node ./codama.mjs && tsup src/index.ts --format cjs,esm --dts",
|