@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.js
CHANGED
|
@@ -112,18 +112,12 @@ __export(index_exports, {
|
|
|
112
112
|
TUNA_ERROR__ORACLE_PRICE_DEVIATION_THRESHOLD_OUT_OF_RANGE: () => TUNA_ERROR__ORACLE_PRICE_DEVIATION_THRESHOLD_OUT_OF_RANGE,
|
|
113
113
|
TUNA_ERROR__ORACLE_STALE_PRICE: () => TUNA_ERROR__ORACLE_STALE_PRICE,
|
|
114
114
|
TUNA_ERROR__PARTIAL_FILL_ERROR: () => TUNA_ERROR__PARTIAL_FILL_ERROR,
|
|
115
|
+
TUNA_ERROR__POSITION_IS_AUTO_REBALANCEABLE: () => TUNA_ERROR__POSITION_IS_AUTO_REBALANCEABLE,
|
|
115
116
|
TUNA_ERROR__POSITION_IS_HEALTHY: () => TUNA_ERROR__POSITION_IS_HEALTHY,
|
|
116
117
|
TUNA_ERROR__POSITION_IS_LIQUIDATED: () => TUNA_ERROR__POSITION_IS_LIQUIDATED,
|
|
117
118
|
TUNA_ERROR__POSITION_IS_UNHEALTHY: () => TUNA_ERROR__POSITION_IS_UNHEALTHY,
|
|
118
119
|
TUNA_ERROR__POSITION_NOT_EMPTY: () => TUNA_ERROR__POSITION_NOT_EMPTY,
|
|
119
120
|
TUNA_ERROR__PROTOCOL_FEE_IS_OUT_OF_RANGE: () => TUNA_ERROR__PROTOCOL_FEE_IS_OUT_OF_RANGE,
|
|
120
|
-
TUNA_ERROR__RAYDIUM_INVAILD_TICK_INDEX: () => TUNA_ERROR__RAYDIUM_INVAILD_TICK_INDEX,
|
|
121
|
-
TUNA_ERROR__RAYDIUM_INVALID_FIRST_TICK_ARRAY_ACCOUNT: () => TUNA_ERROR__RAYDIUM_INVALID_FIRST_TICK_ARRAY_ACCOUNT,
|
|
122
|
-
TUNA_ERROR__RAYDIUM_INVALID_TICK_ARRAY: () => TUNA_ERROR__RAYDIUM_INVALID_TICK_ARRAY,
|
|
123
|
-
TUNA_ERROR__RAYDIUM_MAX_TOKEN_OVERFLOW: () => TUNA_ERROR__RAYDIUM_MAX_TOKEN_OVERFLOW,
|
|
124
|
-
TUNA_ERROR__RAYDIUM_NOT_ENOUGH_TICK_ARRAY_ACCOUNT: () => TUNA_ERROR__RAYDIUM_NOT_ENOUGH_TICK_ARRAY_ACCOUNT,
|
|
125
|
-
TUNA_ERROR__RAYDIUM_SQRT_PRICE_LIMIT_OVERFLOW: () => TUNA_ERROR__RAYDIUM_SQRT_PRICE_LIMIT_OVERFLOW,
|
|
126
|
-
TUNA_ERROR__RAYDIUM_ZERO_AMOUNT_SPECIFIED: () => TUNA_ERROR__RAYDIUM_ZERO_AMOUNT_SPECIFIED,
|
|
127
121
|
TUNA_ERROR__REBALANCE_CONDITIONS_NOT_MET: () => TUNA_ERROR__REBALANCE_CONDITIONS_NOT_MET,
|
|
128
122
|
TUNA_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE: () => TUNA_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE,
|
|
129
123
|
TUNA_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT: () => TUNA_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT,
|
|
@@ -771,7 +765,8 @@ function getMarketEncoder() {
|
|
|
771
765
|
["borrowLimitA", (0, import_kit7.getU64Encoder)()],
|
|
772
766
|
["borrowLimitB", (0, import_kit7.getU64Encoder)()],
|
|
773
767
|
["maxSwapSlippage", (0, import_kit7.getU32Encoder)()],
|
|
774
|
-
["
|
|
768
|
+
["rebalanceProtocolFee", (0, import_kit7.getU32Encoder)()],
|
|
769
|
+
["reserved", (0, import_kit7.fixEncoderSize)((0, import_kit7.getBytesEncoder)(), 207)]
|
|
775
770
|
]),
|
|
776
771
|
(value) => ({ ...value, discriminator: MARKET_DISCRIMINATOR })
|
|
777
772
|
);
|
|
@@ -797,7 +792,8 @@ function getMarketDecoder() {
|
|
|
797
792
|
["borrowLimitA", (0, import_kit7.getU64Decoder)()],
|
|
798
793
|
["borrowLimitB", (0, import_kit7.getU64Decoder)()],
|
|
799
794
|
["maxSwapSlippage", (0, import_kit7.getU32Decoder)()],
|
|
800
|
-
["
|
|
795
|
+
["rebalanceProtocolFee", (0, import_kit7.getU32Decoder)()],
|
|
796
|
+
["reserved", (0, import_kit7.fixDecoderSize)((0, import_kit7.getBytesDecoder)(), 207)]
|
|
801
797
|
]);
|
|
802
798
|
}
|
|
803
799
|
function getMarketCodec() {
|
|
@@ -1652,13 +1648,7 @@ var TUNA_ERROR__WITHDRAW_REQUEST_EXCEEDS_USER_BALANCE = 6052;
|
|
|
1652
1648
|
var TUNA_ERROR__ZERO_PRICE_RANGE = 6053;
|
|
1653
1649
|
var TUNA_ERROR__ZERO_TRADABLE_AMOUNT = 6054;
|
|
1654
1650
|
var TUNA_ERROR__ZERO_YIELD = 6055;
|
|
1655
|
-
var
|
|
1656
|
-
var TUNA_ERROR__RAYDIUM_INVALID_TICK_ARRAY = 6057;
|
|
1657
|
-
var TUNA_ERROR__RAYDIUM_INVAILD_TICK_INDEX = 6058;
|
|
1658
|
-
var TUNA_ERROR__RAYDIUM_MAX_TOKEN_OVERFLOW = 6059;
|
|
1659
|
-
var TUNA_ERROR__RAYDIUM_NOT_ENOUGH_TICK_ARRAY_ACCOUNT = 6060;
|
|
1660
|
-
var TUNA_ERROR__RAYDIUM_SQRT_PRICE_LIMIT_OVERFLOW = 6061;
|
|
1661
|
-
var TUNA_ERROR__RAYDIUM_ZERO_AMOUNT_SPECIFIED = 6062;
|
|
1651
|
+
var TUNA_ERROR__POSITION_IS_AUTO_REBALANCEABLE = 6056;
|
|
1662
1652
|
var tunaErrorMessages;
|
|
1663
1653
|
if (process.env.NODE_ENV !== "production") {
|
|
1664
1654
|
tunaErrorMessages = {
|
|
@@ -1687,18 +1677,12 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
1687
1677
|
[TUNA_ERROR__ORACLE_PRICE_DEVIATION_THRESHOLD_OUT_OF_RANGE]: `OraclePriceDeviationThresholdOutOfRange`,
|
|
1688
1678
|
[TUNA_ERROR__ORACLE_STALE_PRICE]: `Oracle price is stale`,
|
|
1689
1679
|
[TUNA_ERROR__PARTIAL_FILL_ERROR]: `Trade resulted in partial fill`,
|
|
1680
|
+
[TUNA_ERROR__POSITION_IS_AUTO_REBALANCEABLE]: `Unable to claim yield for auto re-balanceable positions`,
|
|
1690
1681
|
[TUNA_ERROR__POSITION_IS_HEALTHY]: `Position is healthy`,
|
|
1691
1682
|
[TUNA_ERROR__POSITION_IS_LIQUIDATED]: `Position is already liquidated`,
|
|
1692
1683
|
[TUNA_ERROR__POSITION_IS_UNHEALTHY]: `Position is unhealthy`,
|
|
1693
1684
|
[TUNA_ERROR__POSITION_NOT_EMPTY]: `Position is not empty`,
|
|
1694
1685
|
[TUNA_ERROR__PROTOCOL_FEE_IS_OUT_OF_RANGE]: `Protocol fee is out of range`,
|
|
1695
|
-
[TUNA_ERROR__RAYDIUM_INVAILD_TICK_INDEX]: `RaydiumInvaildTickIndex`,
|
|
1696
|
-
[TUNA_ERROR__RAYDIUM_INVALID_FIRST_TICK_ARRAY_ACCOUNT]: `RaydiumInvalidFirstTickArrayAccount`,
|
|
1697
|
-
[TUNA_ERROR__RAYDIUM_INVALID_TICK_ARRAY]: `RaydiumInvalidTickArray`,
|
|
1698
|
-
[TUNA_ERROR__RAYDIUM_MAX_TOKEN_OVERFLOW]: `RaydiumMaxTokenOverflow`,
|
|
1699
|
-
[TUNA_ERROR__RAYDIUM_NOT_ENOUGH_TICK_ARRAY_ACCOUNT]: `RaydiumNotEnoughTickArrayAccount`,
|
|
1700
|
-
[TUNA_ERROR__RAYDIUM_SQRT_PRICE_LIMIT_OVERFLOW]: `RaydiumSqrtPriceLimitOverflow`,
|
|
1701
|
-
[TUNA_ERROR__RAYDIUM_ZERO_AMOUNT_SPECIFIED]: `RaydiumZeroAmountSpecified`,
|
|
1702
1686
|
[TUNA_ERROR__REBALANCE_CONDITIONS_NOT_MET]: `Rebalance conditions are not met`,
|
|
1703
1687
|
[TUNA_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE]: `Same accounts type is provided more than once`,
|
|
1704
1688
|
[TUNA_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT]: `Insufficient remaining accounts`,
|
|
@@ -3188,7 +3172,8 @@ function getCreateMarketInstructionDataEncoder() {
|
|
|
3188
3172
|
["disabled", (0, import_kit23.getBooleanEncoder)()],
|
|
3189
3173
|
["borrowLimitA", (0, import_kit23.getU64Encoder)()],
|
|
3190
3174
|
["borrowLimitB", (0, import_kit23.getU64Encoder)()],
|
|
3191
|
-
["maxSwapSlippage", (0, import_kit23.getU32Encoder)()]
|
|
3175
|
+
["maxSwapSlippage", (0, import_kit23.getU32Encoder)()],
|
|
3176
|
+
["rebalanceProtocolFee", (0, import_kit23.getU32Encoder)()]
|
|
3192
3177
|
]),
|
|
3193
3178
|
(value) => ({ ...value, discriminator: CREATE_MARKET_DISCRIMINATOR })
|
|
3194
3179
|
);
|
|
@@ -3208,7 +3193,8 @@ function getCreateMarketInstructionDataDecoder() {
|
|
|
3208
3193
|
["disabled", (0, import_kit23.getBooleanDecoder)()],
|
|
3209
3194
|
["borrowLimitA", (0, import_kit23.getU64Decoder)()],
|
|
3210
3195
|
["borrowLimitB", (0, import_kit23.getU64Decoder)()],
|
|
3211
|
-
["maxSwapSlippage", (0, import_kit23.getU32Decoder)()]
|
|
3196
|
+
["maxSwapSlippage", (0, import_kit23.getU32Decoder)()],
|
|
3197
|
+
["rebalanceProtocolFee", (0, import_kit23.getU32Decoder)()]
|
|
3212
3198
|
]);
|
|
3213
3199
|
}
|
|
3214
3200
|
function getCreateMarketInstructionDataCodec() {
|
|
@@ -6622,7 +6608,8 @@ function getUpdateMarketInstructionDataEncoder() {
|
|
|
6622
6608
|
["disabled", (0, import_kit51.getBooleanEncoder)()],
|
|
6623
6609
|
["borrowLimitA", (0, import_kit51.getU64Encoder)()],
|
|
6624
6610
|
["borrowLimitB", (0, import_kit51.getU64Encoder)()],
|
|
6625
|
-
["maxSwapSlippage", (0, import_kit51.getU32Encoder)()]
|
|
6611
|
+
["maxSwapSlippage", (0, import_kit51.getU32Encoder)()],
|
|
6612
|
+
["rebalanceProtocolFee", (0, import_kit51.getU32Encoder)()]
|
|
6626
6613
|
]),
|
|
6627
6614
|
(value) => ({ ...value, discriminator: UPDATE_MARKET_DISCRIMINATOR })
|
|
6628
6615
|
);
|
|
@@ -6641,7 +6628,8 @@ function getUpdateMarketInstructionDataDecoder() {
|
|
|
6641
6628
|
["disabled", (0, import_kit51.getBooleanDecoder)()],
|
|
6642
6629
|
["borrowLimitA", (0, import_kit51.getU64Decoder)()],
|
|
6643
6630
|
["borrowLimitB", (0, import_kit51.getU64Decoder)()],
|
|
6644
|
-
["maxSwapSlippage", (0, import_kit51.getU32Decoder)()]
|
|
6631
|
+
["maxSwapSlippage", (0, import_kit51.getU32Decoder)()],
|
|
6632
|
+
["rebalanceProtocolFee", (0, import_kit51.getU32Decoder)()]
|
|
6645
6633
|
]);
|
|
6646
6634
|
}
|
|
6647
6635
|
function getUpdateMarketInstructionDataCodec() {
|
|
@@ -9126,13 +9114,28 @@ async function openPositionFusionInstruction(rpc, authority, positionMint, fusio
|
|
|
9126
9114
|
var import_whirlpools_client9 = require("@orca-so/whirlpools-client");
|
|
9127
9115
|
var import_whirlpools_core4 = require("@orca-so/whirlpools-core");
|
|
9128
9116
|
var import_kit69 = require("@solana/kit");
|
|
9117
|
+
var import_sysvars = require("@solana/sysvars");
|
|
9129
9118
|
var import_memo10 = require("@solana-program/memo");
|
|
9130
9119
|
var import_token_202218 = require("@solana-program/token-2022");
|
|
9131
9120
|
var import_assert13 = __toESM(require("assert"));
|
|
9132
|
-
|
|
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) {
|
|
9133
9133
|
const instructions = [];
|
|
9134
9134
|
if (!createInstructions) createInstructions = instructions;
|
|
9135
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)();
|
|
9136
9139
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
9137
9140
|
const whirlpool = await (0, import_whirlpools_client9.fetchMaybeWhirlpool)(rpc, whirlpoolAddress);
|
|
9138
9141
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
@@ -9196,24 +9199,34 @@ async function openPositionWithLiquidityOrcaInstructions(rpc, authority, positio
|
|
|
9196
9199
|
const [lowerTickArrayAddress] = await (0, import_whirlpools_client9.getTickArrayAddress)(whirlpool.address, lowerTickArrayIndex);
|
|
9197
9200
|
const upperTickArrayIndex = (0, import_whirlpools_core4.getTickArrayStartTickIndex)(args.tickUpperIndex, whirlpool.data.tickSpacing);
|
|
9198
9201
|
const [upperTickArrayAddress] = await (0, import_whirlpools_client9.getTickArrayAddress)(whirlpool.address, upperTickArrayIndex);
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9203
|
-
|
|
9204
|
-
|
|
9205
|
-
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
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
|
+
}
|
|
9217
9230
|
const ix = await openPositionWithLiquidityOrcaInstruction(
|
|
9218
9231
|
authority,
|
|
9219
9232
|
positionMint,
|
|
@@ -9230,7 +9243,11 @@ async function openPositionWithLiquidityOrcaInstructions(rpc, authority, positio
|
|
|
9230
9243
|
cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
9231
9244
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
9232
9245
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
9233
|
-
return
|
|
9246
|
+
return {
|
|
9247
|
+
instructions,
|
|
9248
|
+
positionMint: positionMint.address,
|
|
9249
|
+
initializationCost: (0, import_kit69.lamports)(nonRefundableRent)
|
|
9250
|
+
};
|
|
9234
9251
|
}
|
|
9235
9252
|
async function openPositionWithLiquidityOrcaInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, args) {
|
|
9236
9253
|
const tunaPositionAddress = (await getTunaPositionAddress(positionMint.address))[0];
|
|
@@ -9348,13 +9365,17 @@ async function openPositionWithLiquidityOrcaInstruction(authority, positionMint,
|
|
|
9348
9365
|
var import_fusionamm_client10 = require("@crypticdot/fusionamm-client");
|
|
9349
9366
|
var import_fusionamm_core5 = require("@crypticdot/fusionamm-core");
|
|
9350
9367
|
var import_kit70 = require("@solana/kit");
|
|
9368
|
+
var import_sysvars2 = require("@solana/sysvars");
|
|
9351
9369
|
var import_memo11 = require("@solana-program/memo");
|
|
9352
9370
|
var import_token_202219 = require("@solana-program/token-2022");
|
|
9353
9371
|
var import_assert14 = __toESM(require("assert"));
|
|
9354
|
-
async function openPositionWithLiquidityFusionInstructions(rpc, authority,
|
|
9372
|
+
async function openPositionWithLiquidityFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
9355
9373
|
const instructions = [];
|
|
9356
9374
|
if (!createInstructions) createInstructions = instructions;
|
|
9357
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)();
|
|
9358
9379
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
9359
9380
|
const fusionPool = await (0, import_fusionamm_client10.fetchMaybeFusionPool)(rpc, fusionPoolAddress);
|
|
9360
9381
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
@@ -9431,6 +9452,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9431
9452
|
startTickIndex: lowerTickArrayIndex
|
|
9432
9453
|
})
|
|
9433
9454
|
);
|
|
9455
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client10.getTickArraySize)());
|
|
9434
9456
|
}
|
|
9435
9457
|
if (!upperTickArray.exists && lowerTickArrayIndex !== upperTickArrayIndex) {
|
|
9436
9458
|
instructions.push(
|
|
@@ -9441,6 +9463,7 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9441
9463
|
startTickIndex: upperTickArrayIndex
|
|
9442
9464
|
})
|
|
9443
9465
|
);
|
|
9466
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client10.getTickArraySize)());
|
|
9444
9467
|
}
|
|
9445
9468
|
const ix = await openPositionWithLiquidityFusionInstruction(
|
|
9446
9469
|
authority,
|
|
@@ -9458,7 +9481,11 @@ async function openPositionWithLiquidityFusionInstructions(rpc, authority, posit
|
|
|
9458
9481
|
cleanupInstructions.push(...createUserAtaBInstructions.cleanup);
|
|
9459
9482
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
9460
9483
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
9461
|
-
return
|
|
9484
|
+
return {
|
|
9485
|
+
instructions,
|
|
9486
|
+
positionMint: positionMint.address,
|
|
9487
|
+
initializationCost: (0, import_kit70.lamports)(nonRefundableRent)
|
|
9488
|
+
};
|
|
9462
9489
|
}
|
|
9463
9490
|
async function openPositionWithLiquidityFusionInstruction(authority, positionMint, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, args) {
|
|
9464
9491
|
const tunaPositionAddress = (await getTunaPositionAddress(positionMint.address))[0];
|
|
@@ -10233,10 +10260,13 @@ async function repayDebtInstruction(authority, positionMint, mintA, mintB, marke
|
|
|
10233
10260
|
// src/txbuilder/rebalancePositionOrca.ts
|
|
10234
10261
|
var import_whirlpools_client12 = require("@orca-so/whirlpools-client");
|
|
10235
10262
|
var import_kit74 = require("@solana/kit");
|
|
10263
|
+
var import_sysvars3 = require("@solana/sysvars");
|
|
10236
10264
|
var import_memo18 = require("@solana-program/memo");
|
|
10237
10265
|
var import_token_202226 = require("@solana-program/token-2022");
|
|
10238
10266
|
var import_assert18 = __toESM(require("assert"));
|
|
10239
10267
|
async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
10268
|
+
const rent = await (0, import_sysvars3.fetchSysvarRent)(rpc);
|
|
10269
|
+
let nonRefundableRent = 0n;
|
|
10240
10270
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
10241
10271
|
const tunaPosition = await fetchMaybeTunaPosition(rpc, (await getTunaPositionAddress(positionMint))[0]);
|
|
10242
10272
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -10254,24 +10284,34 @@ async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, c
|
|
|
10254
10284
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
10255
10285
|
const internalCleanupInstructions = [];
|
|
10256
10286
|
const secondaryTickArrays = await OrcaUtils.getTickArraysForRebalancedPosition(whirlpool, tunaPosition);
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
|
|
10273
|
-
|
|
10274
|
-
|
|
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
|
+
}
|
|
10275
10315
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10276
10316
|
rpc,
|
|
10277
10317
|
authority,
|
|
@@ -10302,7 +10342,10 @@ async function rebalancePositionOrcaInstructions(rpc, authority, positionMint, c
|
|
|
10302
10342
|
cleanupInstructions.push(...internalCleanupInstructions);
|
|
10303
10343
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
10304
10344
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
10305
|
-
return
|
|
10345
|
+
return {
|
|
10346
|
+
instructions,
|
|
10347
|
+
initializationCost: (0, import_kit74.lamports)(nonRefundableRent)
|
|
10348
|
+
};
|
|
10306
10349
|
}
|
|
10307
10350
|
async function rebalancePositionOrcaInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool) {
|
|
10308
10351
|
const positionMint = tunaPosition.data.positionMint;
|
|
@@ -10401,10 +10444,13 @@ async function rebalancePositionOrcaInstruction(authority, tunaPosition, tunaCon
|
|
|
10401
10444
|
// src/txbuilder/rebalancePositionFusion.ts
|
|
10402
10445
|
var import_fusionamm_client13 = require("@crypticdot/fusionamm-client");
|
|
10403
10446
|
var import_kit75 = require("@solana/kit");
|
|
10447
|
+
var import_sysvars4 = require("@solana/sysvars");
|
|
10404
10448
|
var import_memo19 = require("@solana-program/memo");
|
|
10405
10449
|
var import_token_202227 = require("@solana-program/token-2022");
|
|
10406
10450
|
var import_assert19 = __toESM(require("assert"));
|
|
10407
10451
|
async function rebalancePositionFusionInstructions(rpc, authority, positionMint, createInstructions, cleanupInstructions) {
|
|
10452
|
+
const rent = await (0, import_sysvars4.fetchSysvarRent)(rpc);
|
|
10453
|
+
let nonRefundableRent = 0n;
|
|
10408
10454
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
10409
10455
|
const tunaPosition = await fetchMaybeTunaPosition(rpc, (await getTunaPositionAddress(positionMint))[0]);
|
|
10410
10456
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
@@ -10434,6 +10480,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10434
10480
|
startTickIndex: secondaryTickArrays.lowerTickArrayStartIndex
|
|
10435
10481
|
})
|
|
10436
10482
|
);
|
|
10483
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client13.getTickArraySize)());
|
|
10437
10484
|
}
|
|
10438
10485
|
if (!upperTickArray.exists && secondaryTickArrays.lowerTickArrayStartIndex !== secondaryTickArrays.upperTickArrayStartIndex) {
|
|
10439
10486
|
instructions.push(
|
|
@@ -10444,6 +10491,7 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10444
10491
|
startTickIndex: secondaryTickArrays.upperTickArrayStartIndex
|
|
10445
10492
|
})
|
|
10446
10493
|
);
|
|
10494
|
+
nonRefundableRent += calculateMinimumBalanceForRentExemption(rent, (0, import_fusionamm_client13.getTickArraySize)());
|
|
10447
10495
|
}
|
|
10448
10496
|
const createFeeRecipientAtaAInstructions = await getCreateAtaInstructions(
|
|
10449
10497
|
rpc,
|
|
@@ -10474,7 +10522,10 @@ async function rebalancePositionFusionInstructions(rpc, authority, positionMint,
|
|
|
10474
10522
|
instructions.push(ix);
|
|
10475
10523
|
cleanupInstructions.push(...createFeeRecipientAtaAInstructions.cleanup);
|
|
10476
10524
|
cleanupInstructions.push(...createFeeRecipientAtaBInstructions.cleanup);
|
|
10477
|
-
return
|
|
10525
|
+
return {
|
|
10526
|
+
instructions,
|
|
10527
|
+
initializationCost: (0, import_kit75.lamports)(nonRefundableRent)
|
|
10528
|
+
};
|
|
10478
10529
|
}
|
|
10479
10530
|
async function rebalancePositionFusionInstruction(authority, tunaPosition, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool) {
|
|
10480
10531
|
const positionMint = tunaPosition.data.positionMint;
|
|
@@ -10651,18 +10702,12 @@ async function rebalancePositionFusionInstruction(authority, tunaPosition, tunaC
|
|
|
10651
10702
|
TUNA_ERROR__ORACLE_PRICE_DEVIATION_THRESHOLD_OUT_OF_RANGE,
|
|
10652
10703
|
TUNA_ERROR__ORACLE_STALE_PRICE,
|
|
10653
10704
|
TUNA_ERROR__PARTIAL_FILL_ERROR,
|
|
10705
|
+
TUNA_ERROR__POSITION_IS_AUTO_REBALANCEABLE,
|
|
10654
10706
|
TUNA_ERROR__POSITION_IS_HEALTHY,
|
|
10655
10707
|
TUNA_ERROR__POSITION_IS_LIQUIDATED,
|
|
10656
10708
|
TUNA_ERROR__POSITION_IS_UNHEALTHY,
|
|
10657
10709
|
TUNA_ERROR__POSITION_NOT_EMPTY,
|
|
10658
10710
|
TUNA_ERROR__PROTOCOL_FEE_IS_OUT_OF_RANGE,
|
|
10659
|
-
TUNA_ERROR__RAYDIUM_INVAILD_TICK_INDEX,
|
|
10660
|
-
TUNA_ERROR__RAYDIUM_INVALID_FIRST_TICK_ARRAY_ACCOUNT,
|
|
10661
|
-
TUNA_ERROR__RAYDIUM_INVALID_TICK_ARRAY,
|
|
10662
|
-
TUNA_ERROR__RAYDIUM_MAX_TOKEN_OVERFLOW,
|
|
10663
|
-
TUNA_ERROR__RAYDIUM_NOT_ENOUGH_TICK_ARRAY_ACCOUNT,
|
|
10664
|
-
TUNA_ERROR__RAYDIUM_SQRT_PRICE_LIMIT_OVERFLOW,
|
|
10665
|
-
TUNA_ERROR__RAYDIUM_ZERO_AMOUNT_SPECIFIED,
|
|
10666
10711
|
TUNA_ERROR__REBALANCE_CONDITIONS_NOT_MET,
|
|
10667
10712
|
TUNA_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE,
|
|
10668
10713
|
TUNA_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT,
|