@crypticdot/defituna-client 3.0.3 → 3.1.0
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 +81 -104
- package/dist/index.d.ts +81 -104
- package/dist/index.js +149 -192
- package/dist/index.mjs +117 -162
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -688,7 +688,6 @@ function getTunaSpotPositionEncoder() {
|
|
|
688
688
|
["pool", getAddressEncoder5()],
|
|
689
689
|
["mintA", getAddressEncoder5()],
|
|
690
690
|
["mintB", getAddressEncoder5()],
|
|
691
|
-
["positionMint", getAddressEncoder5()],
|
|
692
691
|
["marketMaker", getMarketMakerEncoder()],
|
|
693
692
|
["positionToken", getPoolTokenEncoder()],
|
|
694
693
|
["collateralToken", getPoolTokenEncoder()],
|
|
@@ -714,7 +713,6 @@ function getTunaSpotPositionDecoder() {
|
|
|
714
713
|
["pool", getAddressDecoder5()],
|
|
715
714
|
["mintA", getAddressDecoder5()],
|
|
716
715
|
["mintB", getAddressDecoder5()],
|
|
717
|
-
["positionMint", getAddressDecoder5()],
|
|
718
716
|
["marketMaker", getMarketMakerDecoder()],
|
|
719
717
|
["positionToken", getPoolTokenDecoder()],
|
|
720
718
|
["collateralToken", getPoolTokenDecoder()],
|
|
@@ -766,7 +764,7 @@ async function fetchAllMaybeTunaSpotPosition(rpc, addresses, config) {
|
|
|
766
764
|
);
|
|
767
765
|
}
|
|
768
766
|
function getTunaSpotPositionSize() {
|
|
769
|
-
return
|
|
767
|
+
return 347;
|
|
770
768
|
}
|
|
771
769
|
|
|
772
770
|
// src/generated/accounts/vault.ts
|
|
@@ -6560,10 +6558,6 @@ function getOpenAndIncreaseTunaSpotPositionFusionInstruction(input, config) {
|
|
|
6560
6558
|
vaultAAta: { value: input.vaultAAta ?? null, isWritable: true },
|
|
6561
6559
|
vaultBAta: { value: input.vaultBAta ?? null, isWritable: true },
|
|
6562
6560
|
tunaPosition: { value: input.tunaPosition ?? null, isWritable: true },
|
|
6563
|
-
tunaPositionMint: {
|
|
6564
|
-
value: input.tunaPositionMint ?? null,
|
|
6565
|
-
isWritable: false
|
|
6566
|
-
},
|
|
6567
6561
|
tunaPositionAtaA: {
|
|
6568
6562
|
value: input.tunaPositionAtaA ?? null,
|
|
6569
6563
|
isWritable: true
|
|
@@ -6628,7 +6622,6 @@ function getOpenAndIncreaseTunaSpotPositionFusionInstruction(input, config) {
|
|
|
6628
6622
|
getAccountMeta(accounts.vaultAAta),
|
|
6629
6623
|
getAccountMeta(accounts.vaultBAta),
|
|
6630
6624
|
getAccountMeta(accounts.tunaPosition),
|
|
6631
|
-
getAccountMeta(accounts.tunaPositionMint),
|
|
6632
6625
|
getAccountMeta(accounts.tunaPositionAtaA),
|
|
6633
6626
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
6634
6627
|
getAccountMeta(accounts.tunaPositionOwnerAtaA),
|
|
@@ -6651,7 +6644,7 @@ function getOpenAndIncreaseTunaSpotPositionFusionInstruction(input, config) {
|
|
|
6651
6644
|
return instruction;
|
|
6652
6645
|
}
|
|
6653
6646
|
function parseOpenAndIncreaseTunaSpotPositionFusionInstruction(instruction) {
|
|
6654
|
-
if (instruction.accounts.length <
|
|
6647
|
+
if (instruction.accounts.length < 25) {
|
|
6655
6648
|
throw new Error("Not enough accounts");
|
|
6656
6649
|
}
|
|
6657
6650
|
let accountIndex = 0;
|
|
@@ -6679,7 +6672,6 @@ function parseOpenAndIncreaseTunaSpotPositionFusionInstruction(instruction) {
|
|
|
6679
6672
|
vaultAAta: getNextAccount(),
|
|
6680
6673
|
vaultBAta: getNextAccount(),
|
|
6681
6674
|
tunaPosition: getNextAccount(),
|
|
6682
|
-
tunaPositionMint: getNextAccount(),
|
|
6683
6675
|
tunaPositionAtaA: getNextAccount(),
|
|
6684
6676
|
tunaPositionAtaB: getNextAccount(),
|
|
6685
6677
|
tunaPositionOwnerAtaA: getNextOptionalAccount(),
|
|
@@ -6778,10 +6770,6 @@ function getOpenAndIncreaseTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
6778
6770
|
vaultAAta: { value: input.vaultAAta ?? null, isWritable: true },
|
|
6779
6771
|
vaultBAta: { value: input.vaultBAta ?? null, isWritable: true },
|
|
6780
6772
|
tunaPosition: { value: input.tunaPosition ?? null, isWritable: true },
|
|
6781
|
-
tunaPositionMint: {
|
|
6782
|
-
value: input.tunaPositionMint ?? null,
|
|
6783
|
-
isWritable: false
|
|
6784
|
-
},
|
|
6785
6773
|
tunaPositionAtaA: {
|
|
6786
6774
|
value: input.tunaPositionAtaA ?? null,
|
|
6787
6775
|
isWritable: true
|
|
@@ -6846,7 +6834,6 @@ function getOpenAndIncreaseTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
6846
6834
|
getAccountMeta(accounts.vaultAAta),
|
|
6847
6835
|
getAccountMeta(accounts.vaultBAta),
|
|
6848
6836
|
getAccountMeta(accounts.tunaPosition),
|
|
6849
|
-
getAccountMeta(accounts.tunaPositionMint),
|
|
6850
6837
|
getAccountMeta(accounts.tunaPositionAtaA),
|
|
6851
6838
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
6852
6839
|
getAccountMeta(accounts.tunaPositionOwnerAtaA),
|
|
@@ -6869,7 +6856,7 @@ function getOpenAndIncreaseTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
6869
6856
|
return instruction;
|
|
6870
6857
|
}
|
|
6871
6858
|
function parseOpenAndIncreaseTunaSpotPositionOrcaInstruction(instruction) {
|
|
6872
|
-
if (instruction.accounts.length <
|
|
6859
|
+
if (instruction.accounts.length < 25) {
|
|
6873
6860
|
throw new Error("Not enough accounts");
|
|
6874
6861
|
}
|
|
6875
6862
|
let accountIndex = 0;
|
|
@@ -6897,7 +6884,6 @@ function parseOpenAndIncreaseTunaSpotPositionOrcaInstruction(instruction) {
|
|
|
6897
6884
|
vaultAAta: getNextAccount(),
|
|
6898
6885
|
vaultBAta: getNextAccount(),
|
|
6899
6886
|
tunaPosition: getNextAccount(),
|
|
6900
|
-
tunaPositionMint: getNextAccount(),
|
|
6901
6887
|
tunaPositionAtaA: getNextAccount(),
|
|
6902
6888
|
tunaPositionAtaB: getNextAccount(),
|
|
6903
6889
|
tunaPositionOwnerAtaA: getNextOptionalAccount(),
|
|
@@ -7448,10 +7434,6 @@ function getOpenTunaSpotPositionFusionInstruction(input, config) {
|
|
|
7448
7434
|
tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false },
|
|
7449
7435
|
tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false },
|
|
7450
7436
|
tunaPosition: { value: input.tunaPosition ?? null, isWritable: true },
|
|
7451
|
-
tunaPositionMint: {
|
|
7452
|
-
value: input.tunaPositionMint ?? null,
|
|
7453
|
-
isWritable: false
|
|
7454
|
-
},
|
|
7455
7437
|
tunaPositionAtaA: {
|
|
7456
7438
|
value: input.tunaPositionAtaA ?? null,
|
|
7457
7439
|
isWritable: true
|
|
@@ -7481,7 +7463,6 @@ function getOpenTunaSpotPositionFusionInstruction(input, config) {
|
|
|
7481
7463
|
getAccountMeta(accounts.tokenProgramA),
|
|
7482
7464
|
getAccountMeta(accounts.tokenProgramB),
|
|
7483
7465
|
getAccountMeta(accounts.tunaPosition),
|
|
7484
|
-
getAccountMeta(accounts.tunaPositionMint),
|
|
7485
7466
|
getAccountMeta(accounts.tunaPositionAtaA),
|
|
7486
7467
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
7487
7468
|
getAccountMeta(accounts.fusionPool),
|
|
@@ -7496,7 +7477,7 @@ function getOpenTunaSpotPositionFusionInstruction(input, config) {
|
|
|
7496
7477
|
return instruction;
|
|
7497
7478
|
}
|
|
7498
7479
|
function parseOpenTunaSpotPositionFusionInstruction(instruction) {
|
|
7499
|
-
if (instruction.accounts.length <
|
|
7480
|
+
if (instruction.accounts.length < 11) {
|
|
7500
7481
|
throw new Error("Not enough accounts");
|
|
7501
7482
|
}
|
|
7502
7483
|
let accountIndex = 0;
|
|
@@ -7514,7 +7495,6 @@ function parseOpenTunaSpotPositionFusionInstruction(instruction) {
|
|
|
7514
7495
|
tokenProgramA: getNextAccount(),
|
|
7515
7496
|
tokenProgramB: getNextAccount(),
|
|
7516
7497
|
tunaPosition: getNextAccount(),
|
|
7517
|
-
tunaPositionMint: getNextAccount(),
|
|
7518
7498
|
tunaPositionAtaA: getNextAccount(),
|
|
7519
7499
|
tunaPositionAtaB: getNextAccount(),
|
|
7520
7500
|
fusionPool: getNextAccount(),
|
|
@@ -7598,10 +7578,6 @@ function getOpenTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
7598
7578
|
tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false },
|
|
7599
7579
|
tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false },
|
|
7600
7580
|
tunaPosition: { value: input.tunaPosition ?? null, isWritable: true },
|
|
7601
|
-
tunaPositionMint: {
|
|
7602
|
-
value: input.tunaPositionMint ?? null,
|
|
7603
|
-
isWritable: false
|
|
7604
|
-
},
|
|
7605
7581
|
tunaPositionAtaA: {
|
|
7606
7582
|
value: input.tunaPositionAtaA ?? null,
|
|
7607
7583
|
isWritable: true
|
|
@@ -7631,7 +7607,6 @@ function getOpenTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
7631
7607
|
getAccountMeta(accounts.tokenProgramA),
|
|
7632
7608
|
getAccountMeta(accounts.tokenProgramB),
|
|
7633
7609
|
getAccountMeta(accounts.tunaPosition),
|
|
7634
|
-
getAccountMeta(accounts.tunaPositionMint),
|
|
7635
7610
|
getAccountMeta(accounts.tunaPositionAtaA),
|
|
7636
7611
|
getAccountMeta(accounts.tunaPositionAtaB),
|
|
7637
7612
|
getAccountMeta(accounts.whirlpool),
|
|
@@ -7646,7 +7621,7 @@ function getOpenTunaSpotPositionOrcaInstruction(input, config) {
|
|
|
7646
7621
|
return instruction;
|
|
7647
7622
|
}
|
|
7648
7623
|
function parseOpenTunaSpotPositionOrcaInstruction(instruction) {
|
|
7649
|
-
if (instruction.accounts.length <
|
|
7624
|
+
if (instruction.accounts.length < 11) {
|
|
7650
7625
|
throw new Error("Not enough accounts");
|
|
7651
7626
|
}
|
|
7652
7627
|
let accountIndex = 0;
|
|
@@ -7664,7 +7639,6 @@ function parseOpenTunaSpotPositionOrcaInstruction(instruction) {
|
|
|
7664
7639
|
tokenProgramA: getNextAccount(),
|
|
7665
7640
|
tokenProgramB: getNextAccount(),
|
|
7666
7641
|
tunaPosition: getNextAccount(),
|
|
7667
|
-
tunaPositionMint: getNextAccount(),
|
|
7668
7642
|
tunaPositionAtaA: getNextAccount(),
|
|
7669
7643
|
tunaPositionAtaB: getNextAccount(),
|
|
7670
7644
|
whirlpool: getNextAccount(),
|
|
@@ -9850,6 +9824,35 @@ function parseWithdrawInstruction(instruction) {
|
|
|
9850
9824
|
|
|
9851
9825
|
// src/pda.ts
|
|
9852
9826
|
import { getAddressEncoder as getAddressEncoder16, getProgramDerivedAddress } from "@solana/kit";
|
|
9827
|
+
|
|
9828
|
+
// src/consts.ts
|
|
9829
|
+
import { address } from "@solana/kit";
|
|
9830
|
+
var DEFAULT_ADDRESS = address("11111111111111111111111111111111");
|
|
9831
|
+
var HUNDRED_PERCENT = 1e6;
|
|
9832
|
+
var LEVERAGE_ONE = HUNDRED_PERCENT;
|
|
9833
|
+
var MAX_LEVERAGE = 11 * LEVERAGE_ONE;
|
|
9834
|
+
var MAX_PROTOCOL_FEE = HUNDRED_PERCENT / 100;
|
|
9835
|
+
var MAX_LIQUIDATION_FEE = HUNDRED_PERCENT / 5;
|
|
9836
|
+
var MAX_LIMIT_ORDER_EXECUTION_FEE = HUNDRED_PERCENT / 100;
|
|
9837
|
+
var DEFAULT_MAX_SWAP_SLIPPAGE = HUNDRED_PERCENT / 50;
|
|
9838
|
+
var MAX_LIQUIDATION_THRESHOLD = HUNDRED_PERCENT * 95 / 100;
|
|
9839
|
+
var NO_LOWER_LIMIT_ORDER = -2147483648;
|
|
9840
|
+
var NO_UPPER_LIMIT_ORDER = 2147483647;
|
|
9841
|
+
var COMPUTED_AMOUNT = 18446744073709551615n;
|
|
9842
|
+
var UNLIMITED_SUPPLY_LIMIT = 18446744073709551615n;
|
|
9843
|
+
var TUNA_POSITION_FLAGS_LOWER_LIMIT_ORDER_SWAP_TO_TOKEN_A = 1;
|
|
9844
|
+
var TUNA_POSITION_FLAGS_LOWER_LIMIT_ORDER_SWAP_TO_TOKEN_B = 1 << 1;
|
|
9845
|
+
var TUNA_POSITION_FLAGS_UPPER_LIMIT_ORDER_SWAP_TO_TOKEN_A = 1 << 2;
|
|
9846
|
+
var TUNA_POSITION_FLAGS_UPPER_LIMIT_ORDER_SWAP_TO_TOKEN_B = 1 << 3;
|
|
9847
|
+
var TUNA_POSITION_FLAGS_AUTO_COMPOUND_YIELD = 1 << 4;
|
|
9848
|
+
var TUNA_POSITION_FLAGS_AUTO_COMPOUND_YIELD_WITH_LEVERAGE = 1 << 5;
|
|
9849
|
+
var TUNA_POSITION_FLAGS_ALLOW_REBALANCING = 1 << 6;
|
|
9850
|
+
var WP_NFT_UPDATE_AUTH = address("3axbTs2z5GBy6usVbNVoqEgZMng3vZvMnAoX29BFfwhr");
|
|
9851
|
+
var DEFAULT_PUSH_ORACLE_PROGRAM_ID = address("pythWSnswVUd12oZpeFP8e9CVaEqJg25g1Vtc2biRsT");
|
|
9852
|
+
var MIN_SQRT_PRICE = 4295048016n;
|
|
9853
|
+
var MAX_SQRT_PRICE = 79226673515401279992447579055n;
|
|
9854
|
+
|
|
9855
|
+
// src/pda.ts
|
|
9853
9856
|
async function getTunaConfigAddress() {
|
|
9854
9857
|
return await getProgramDerivedAddress({
|
|
9855
9858
|
programAddress: TUNA_PROGRAM_ADDRESS,
|
|
@@ -9868,10 +9871,10 @@ async function getLendingVaultAddress(mint) {
|
|
|
9868
9871
|
seeds: ["vault", getAddressEncoder16().encode(mint)]
|
|
9869
9872
|
});
|
|
9870
9873
|
}
|
|
9871
|
-
async function getLendingPositionAddress(
|
|
9874
|
+
async function getLendingPositionAddress(authority, mint) {
|
|
9872
9875
|
return await getProgramDerivedAddress({
|
|
9873
9876
|
programAddress: TUNA_PROGRAM_ADDRESS,
|
|
9874
|
-
seeds: ["lending_position", getAddressEncoder16().encode(
|
|
9877
|
+
seeds: ["lending_position", getAddressEncoder16().encode(authority), getAddressEncoder16().encode(mint)]
|
|
9875
9878
|
});
|
|
9876
9879
|
}
|
|
9877
9880
|
async function getTunaLpPositionAddress(positionMint) {
|
|
@@ -9880,10 +9883,28 @@ async function getTunaLpPositionAddress(positionMint) {
|
|
|
9880
9883
|
seeds: ["tuna_position", getAddressEncoder16().encode(positionMint)]
|
|
9881
9884
|
});
|
|
9882
9885
|
}
|
|
9883
|
-
async function getTunaSpotPositionAddress(
|
|
9886
|
+
async function getTunaSpotPositionAddress(authority, pool) {
|
|
9884
9887
|
return await getProgramDerivedAddress({
|
|
9885
9888
|
programAddress: TUNA_PROGRAM_ADDRESS,
|
|
9886
|
-
seeds: ["tuna_spot_position", getAddressEncoder16().encode(
|
|
9889
|
+
seeds: ["tuna_spot_position", getAddressEncoder16().encode(authority), getAddressEncoder16().encode(pool)]
|
|
9890
|
+
});
|
|
9891
|
+
}
|
|
9892
|
+
async function getPythPriceUpdateAccountAddress(shardId, priceFeedId) {
|
|
9893
|
+
if (typeof priceFeedId == "string") {
|
|
9894
|
+
if (priceFeedId.startsWith("0x")) {
|
|
9895
|
+
priceFeedId = Buffer.from(priceFeedId.slice(2), "hex");
|
|
9896
|
+
} else {
|
|
9897
|
+
priceFeedId = Buffer.from(priceFeedId, "hex");
|
|
9898
|
+
}
|
|
9899
|
+
}
|
|
9900
|
+
if (priceFeedId.length != 32) {
|
|
9901
|
+
throw new Error("Feed ID should be 32 bytes long");
|
|
9902
|
+
}
|
|
9903
|
+
const shardBuffer = Buffer.alloc(2);
|
|
9904
|
+
shardBuffer.writeUint16LE(shardId, 0);
|
|
9905
|
+
return await getProgramDerivedAddress({
|
|
9906
|
+
programAddress: DEFAULT_PUSH_ORACLE_PROGRAM_ID,
|
|
9907
|
+
seeds: [shardBuffer, priceFeedId]
|
|
9887
9908
|
});
|
|
9888
9909
|
}
|
|
9889
9910
|
|
|
@@ -10025,15 +10046,6 @@ function tunaSpotPositionMintBFilter(address4) {
|
|
|
10025
10046
|
}
|
|
10026
10047
|
};
|
|
10027
10048
|
}
|
|
10028
|
-
function tunaSpotPositionMintFilter(address4) {
|
|
10029
|
-
return {
|
|
10030
|
-
memcmp: {
|
|
10031
|
-
offset: 139n,
|
|
10032
|
-
bytes: getBase58Decoder2().decode(getAddressEncoder18().encode(address4)),
|
|
10033
|
-
encoding: "base58"
|
|
10034
|
-
}
|
|
10035
|
-
};
|
|
10036
|
-
}
|
|
10037
10049
|
async function fetchAllTunaSpotPositionWithFilter(rpc, ...filters) {
|
|
10038
10050
|
const discriminator = getBase58Decoder2().decode(TUNA_SPOT_POSITION_DISCRIMINATOR);
|
|
10039
10051
|
const discriminatorFilter = {
|
|
@@ -10198,7 +10210,7 @@ var FusionUtils = class {
|
|
|
10198
10210
|
};
|
|
10199
10211
|
|
|
10200
10212
|
// src/utils/token.ts
|
|
10201
|
-
import { address } from "@solana/kit";
|
|
10213
|
+
import { address as address2 } from "@solana/kit";
|
|
10202
10214
|
import { getTransferSolInstruction } from "@solana-program/system";
|
|
10203
10215
|
import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS } from "@solana-program/token";
|
|
10204
10216
|
import {
|
|
@@ -10207,7 +10219,7 @@ import {
|
|
|
10207
10219
|
getCreateAssociatedTokenIdempotentInstruction,
|
|
10208
10220
|
getSyncNativeInstruction
|
|
10209
10221
|
} from "@solana-program/token-2022";
|
|
10210
|
-
var NATIVE_MINT =
|
|
10222
|
+
var NATIVE_MINT = address2("So11111111111111111111111111111111111111112");
|
|
10211
10223
|
async function getCreateAtaInstruction(mint, owner, payer, tokenProgram = TOKEN_PROGRAM_ADDRESS) {
|
|
10212
10224
|
const ata = (await findAssociatedTokenPda({
|
|
10213
10225
|
mint,
|
|
@@ -10274,7 +10286,7 @@ async function createAddressLookupTableInstructions(authority, addresses, recent
|
|
|
10274
10286
|
return { instructions: [createInstruction, extendInstruction], lookupTableAddress: pda[0] };
|
|
10275
10287
|
}
|
|
10276
10288
|
|
|
10277
|
-
// src/utils/
|
|
10289
|
+
// src/utils/lpPositionMath.ts
|
|
10278
10290
|
import {
|
|
10279
10291
|
positionRatioX64,
|
|
10280
10292
|
tickIndexToSqrtPrice,
|
|
@@ -10284,36 +10296,7 @@ import {
|
|
|
10284
10296
|
tryGetTokenAFromLiquidity,
|
|
10285
10297
|
tryGetTokenBFromLiquidity
|
|
10286
10298
|
} from "@crypticdot/fusionamm-core";
|
|
10287
|
-
|
|
10288
|
-
// src/consts.ts
|
|
10289
|
-
import { address as address2 } from "@solana/kit";
|
|
10290
|
-
var DEFAULT_ADDRESS = address2("11111111111111111111111111111111");
|
|
10291
|
-
var HUNDRED_PERCENT = 1e6;
|
|
10292
|
-
var LEVERAGE_ONE = HUNDRED_PERCENT;
|
|
10293
|
-
var MAX_LEVERAGE = 11 * LEVERAGE_ONE;
|
|
10294
|
-
var MAX_PROTOCOL_FEE = HUNDRED_PERCENT / 100;
|
|
10295
|
-
var MAX_LIQUIDATION_FEE = HUNDRED_PERCENT / 5;
|
|
10296
|
-
var MAX_LIMIT_ORDER_EXECUTION_FEE = HUNDRED_PERCENT / 100;
|
|
10297
|
-
var DEFAULT_MAX_SWAP_SLIPPAGE = HUNDRED_PERCENT / 50;
|
|
10298
|
-
var MAX_LIQUIDATION_THRESHOLD = HUNDRED_PERCENT * 95 / 100;
|
|
10299
|
-
var NO_LOWER_LIMIT_ORDER = -2147483648;
|
|
10300
|
-
var NO_UPPER_LIMIT_ORDER = 2147483647;
|
|
10301
|
-
var COMPUTED_AMOUNT = 18446744073709551615n;
|
|
10302
|
-
var UNLIMITED_SUPPLY_LIMIT = 18446744073709551615n;
|
|
10303
|
-
var TUNA_POSITION_FLAGS_LOWER_LIMIT_ORDER_SWAP_TO_TOKEN_A = 1;
|
|
10304
|
-
var TUNA_POSITION_FLAGS_LOWER_LIMIT_ORDER_SWAP_TO_TOKEN_B = 1 << 1;
|
|
10305
|
-
var TUNA_POSITION_FLAGS_UPPER_LIMIT_ORDER_SWAP_TO_TOKEN_A = 1 << 2;
|
|
10306
|
-
var TUNA_POSITION_FLAGS_UPPER_LIMIT_ORDER_SWAP_TO_TOKEN_B = 1 << 3;
|
|
10307
|
-
var TUNA_POSITION_FLAGS_AUTO_COMPOUND_YIELD = 1 << 4;
|
|
10308
|
-
var TUNA_POSITION_FLAGS_AUTO_COMPOUND_YIELD_WITH_LEVERAGE = 1 << 5;
|
|
10309
|
-
var TUNA_POSITION_FLAGS_ALLOW_REBALANCING = 1 << 6;
|
|
10310
|
-
var WP_NFT_UPDATE_AUTH = address2("3axbTs2z5GBy6usVbNVoqEgZMng3vZvMnAoX29BFfwhr");
|
|
10311
|
-
var MIN_SQRT_PRICE = 4295048016n;
|
|
10312
|
-
var MAX_SQRT_PRICE = 79226673515401279992447579055n;
|
|
10313
|
-
|
|
10314
|
-
// src/utils/positionMath.ts
|
|
10315
|
-
var DEFAULT_MAX_AMOUNT_SLIPPAGE = HUNDRED_PERCENT / 2;
|
|
10316
|
-
function getLiquidityIncreaseQuote(args) {
|
|
10299
|
+
function getIncreaseLpPositionQuote(args) {
|
|
10317
10300
|
const { protocolFeeRate, protocolFeeRateOnCollateral, swapFeeRate, sqrtPrice, tickLowerIndex, tickUpperIndex } = args;
|
|
10318
10301
|
let { collateralA, collateralB, borrowA, borrowB } = args;
|
|
10319
10302
|
if (tickLowerIndex > tickUpperIndex) {
|
|
@@ -10325,7 +10308,7 @@ function getLiquidityIncreaseQuote(args) {
|
|
|
10325
10308
|
if (args.collateralA == COMPUTED_AMOUNT && args.collateralB == COMPUTED_AMOUNT) {
|
|
10326
10309
|
throw new Error("Both collateral amounts can't be set to COMPUTED_AMOUNT");
|
|
10327
10310
|
}
|
|
10328
|
-
const maxAmountSlippage =
|
|
10311
|
+
const maxAmountSlippage = BigInt(args.maxAmountSlippage);
|
|
10329
10312
|
let maxCollateralA = BigInt(collateralA);
|
|
10330
10313
|
let maxCollateralB = BigInt(collateralB);
|
|
10331
10314
|
const lowerSqrtPrice = tickIndexToSqrtPrice(tickLowerIndex);
|
|
@@ -10454,7 +10437,7 @@ async function increaseTunaLpPositionOrcaInstructions(rpc, authority, positionMi
|
|
|
10454
10437
|
const [mintA, mintB] = await fetchAllMaybeMint(rpc, [whirlpool.data.tokenMintA, whirlpool.data.tokenMintB]);
|
|
10455
10438
|
assert(mintA.exists, "Token A not found");
|
|
10456
10439
|
assert(mintB.exists, "Token B not found");
|
|
10457
|
-
const increaseAmounts =
|
|
10440
|
+
const increaseAmounts = getIncreaseLpPositionQuote({
|
|
10458
10441
|
collateralA: BigInt(args.collateralA),
|
|
10459
10442
|
collateralB: BigInt(args.collateralB),
|
|
10460
10443
|
borrowA: BigInt(args.borrowA),
|
|
@@ -10698,7 +10681,7 @@ async function increaseTunaLpPositionFusionInstructions(rpc, authority, position
|
|
|
10698
10681
|
const [mintA, mintB] = await fetchAllMaybeMint2(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
10699
10682
|
assert2(mintA.exists, "Token A not found");
|
|
10700
10683
|
assert2(mintB.exists, "Token B not found");
|
|
10701
|
-
const increaseAmounts =
|
|
10684
|
+
const increaseAmounts = getIncreaseLpPositionQuote({
|
|
10702
10685
|
collateralA: BigInt(args.collateralA),
|
|
10703
10686
|
collateralB: BigInt(args.collateralB),
|
|
10704
10687
|
borrowA: BigInt(args.borrowA),
|
|
@@ -11869,8 +11852,9 @@ import {
|
|
|
11869
11852
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS8 } from "@solana-program/memo";
|
|
11870
11853
|
import { fetchAllMaybeMint as fetchAllMaybeMint11, findAssociatedTokenPda as findAssociatedTokenPda13 } from "@solana-program/token-2022";
|
|
11871
11854
|
import assert11 from "assert";
|
|
11872
|
-
async function closeActiveTunaSpotPositionFusionInstructions(rpc, authority,
|
|
11873
|
-
const
|
|
11855
|
+
async function closeActiveTunaSpotPositionFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
11856
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, fusionPoolAddress))[0];
|
|
11857
|
+
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
11874
11858
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
11875
11859
|
const fusionPool = await fetchMaybeFusionPool6(rpc, tunaPosition.data.pool);
|
|
11876
11860
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
@@ -11998,8 +11982,9 @@ import {
|
|
|
11998
11982
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS9 } from "@solana-program/memo";
|
|
11999
11983
|
import { fetchAllMaybeMint as fetchAllMaybeMint12, findAssociatedTokenPda as findAssociatedTokenPda14 } from "@solana-program/token-2022";
|
|
12000
11984
|
import assert12 from "assert";
|
|
12001
|
-
async function closeActiveTunaSpotPositionOrcaInstructions(rpc, authority,
|
|
12002
|
-
const
|
|
11985
|
+
async function closeActiveTunaSpotPositionOrcaInstructions(rpc, authority, whirlpoolAddress, args, createInstructions, cleanupInstructions) {
|
|
11986
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, whirlpoolAddress))[0];
|
|
11987
|
+
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12003
11988
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12004
11989
|
const whirlpool = await fetchMaybeWhirlpool6(rpc, tunaPosition.data.pool);
|
|
12005
11990
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
@@ -12126,11 +12111,12 @@ import {
|
|
|
12126
12111
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS10 } from "@solana-program/memo";
|
|
12127
12112
|
import { fetchAllMaybeMint as fetchAllMaybeMint13, findAssociatedTokenPda as findAssociatedTokenPda15 } from "@solana-program/token-2022";
|
|
12128
12113
|
import assert13 from "assert";
|
|
12129
|
-
async function increaseTunaSpotPositionOrcaInstructions(rpc, authority,
|
|
12114
|
+
async function increaseTunaSpotPositionOrcaInstructions(rpc, authority, whirlpoolAddress, args, createInstructions, cleanupInstructions) {
|
|
12130
12115
|
const instructions = [];
|
|
12131
12116
|
if (!createInstructions) createInstructions = instructions;
|
|
12132
12117
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
12133
|
-
const
|
|
12118
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, whirlpoolAddress))[0];
|
|
12119
|
+
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12134
12120
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12135
12121
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
12136
12122
|
const whirlpool = await fetchWhirlpool(rpc, tunaPosition.data.pool);
|
|
@@ -12283,11 +12269,12 @@ import {
|
|
|
12283
12269
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS11 } from "@solana-program/memo";
|
|
12284
12270
|
import { fetchAllMaybeMint as fetchAllMaybeMint14, findAssociatedTokenPda as findAssociatedTokenPda16 } from "@solana-program/token-2022";
|
|
12285
12271
|
import assert14 from "assert";
|
|
12286
|
-
async function increaseTunaSpotPositionFusionInstructions(rpc, authority,
|
|
12272
|
+
async function increaseTunaSpotPositionFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
12287
12273
|
const instructions = [];
|
|
12288
12274
|
if (!createInstructions) createInstructions = instructions;
|
|
12289
12275
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
12290
|
-
const
|
|
12276
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, fusionPoolAddress))[0];
|
|
12277
|
+
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12291
12278
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12292
12279
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
12293
12280
|
const fusionPool = await fetchFusionPool(rpc, tunaPosition.data.pool);
|
|
@@ -12437,11 +12424,12 @@ import {
|
|
|
12437
12424
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS12 } from "@solana-program/memo";
|
|
12438
12425
|
import { fetchAllMaybeMint as fetchAllMaybeMint15, fetchAllToken, findAssociatedTokenPda as findAssociatedTokenPda17 } from "@solana-program/token-2022";
|
|
12439
12426
|
import assert15 from "assert";
|
|
12440
|
-
async function decreaseTunaSpotPositionOrcaInstructions(rpc, authority,
|
|
12427
|
+
async function decreaseTunaSpotPositionOrcaInstructions(rpc, authority, whirlpoolAddress, args, createInstructions, cleanupInstructions) {
|
|
12441
12428
|
const instructions = [];
|
|
12442
12429
|
if (!createInstructions) createInstructions = instructions;
|
|
12443
12430
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
12444
|
-
const
|
|
12431
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, whirlpoolAddress))[0];
|
|
12432
|
+
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12445
12433
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12446
12434
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
12447
12435
|
const whirlpool = await fetchWhirlpool2(rpc, tunaPosition.data.pool);
|
|
@@ -12592,11 +12580,12 @@ import {
|
|
|
12592
12580
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS13 } from "@solana-program/memo";
|
|
12593
12581
|
import { fetchAllMaybeMint as fetchAllMaybeMint16, fetchAllToken as fetchAllToken2, findAssociatedTokenPda as findAssociatedTokenPda18 } from "@solana-program/token-2022";
|
|
12594
12582
|
import assert16 from "assert";
|
|
12595
|
-
async function decreaseTunaSpotPositionFusionInstructions(rpc, authority,
|
|
12583
|
+
async function decreaseTunaSpotPositionFusionInstructions(rpc, authority, fusionPoolAddress, args, createInstructions, cleanupInstructions) {
|
|
12596
12584
|
const instructions = [];
|
|
12597
12585
|
if (!createInstructions) createInstructions = instructions;
|
|
12598
12586
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
12599
|
-
const
|
|
12587
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, fusionPoolAddress))[0];
|
|
12588
|
+
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12600
12589
|
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12601
12590
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
12602
12591
|
const fusionPool = await fetchFusionPool2(rpc, tunaPosition.data.pool);
|
|
@@ -12739,17 +12728,18 @@ async function decreaseTunaSpotPositionFusionInstruction(authority, tunaPosition
|
|
|
12739
12728
|
// src/txbuilder/closeTunaSpotPosition.ts
|
|
12740
12729
|
import { fetchAllMaybeMint as fetchAllMaybeMint17, findAssociatedTokenPda as findAssociatedTokenPda19 } from "@solana-program/token-2022";
|
|
12741
12730
|
import assert17 from "assert";
|
|
12742
|
-
async function closeTunaSpotPositionInstructions(rpc, authority,
|
|
12743
|
-
const tunaPositionAddress = (await getTunaSpotPositionAddress(
|
|
12744
|
-
const tunaPosition = await
|
|
12731
|
+
async function closeTunaSpotPositionInstructions(rpc, authority, poolAddress) {
|
|
12732
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
12733
|
+
const tunaPosition = await fetchMaybeTunaSpotPosition(rpc, tunaPositionAddress);
|
|
12734
|
+
if (!tunaPosition.exists) throw new Error("Tuna position account not found");
|
|
12745
12735
|
const [mintA, mintB] = await fetchAllMaybeMint17(rpc, [tunaPosition.data.mintA, tunaPosition.data.mintB]);
|
|
12746
12736
|
assert17(mintA.exists, "Token A account not found");
|
|
12747
12737
|
assert17(mintB.exists, "Token B account not found");
|
|
12748
|
-
const ix = await closeTunaSpotPositionInstruction(authority,
|
|
12738
|
+
const ix = await closeTunaSpotPositionInstruction(authority, poolAddress, mintA, mintB);
|
|
12749
12739
|
return [ix];
|
|
12750
12740
|
}
|
|
12751
|
-
async function closeTunaSpotPositionInstruction(authority,
|
|
12752
|
-
const tunaPositionAddress = (await getTunaSpotPositionAddress(
|
|
12741
|
+
async function closeTunaSpotPositionInstruction(authority, poolAddress, mintA, mintB) {
|
|
12742
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
12753
12743
|
const tunaPositionAtaA = (await findAssociatedTokenPda19({
|
|
12754
12744
|
owner: tunaPositionAddress,
|
|
12755
12745
|
mint: mintA.address,
|
|
@@ -13119,7 +13109,7 @@ async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPositi
|
|
|
13119
13109
|
instructions.push(...createFeeRecipientAtaInstructions.init);
|
|
13120
13110
|
const ix = await liquidateTunaSpotPositionFusionInstruction(
|
|
13121
13111
|
authority,
|
|
13122
|
-
tunaPosition.
|
|
13112
|
+
tunaPosition.address,
|
|
13123
13113
|
tunaConfig,
|
|
13124
13114
|
mintA,
|
|
13125
13115
|
mintB,
|
|
@@ -13131,8 +13121,7 @@ async function liquidateTunaSpotPositionFusionInstructions(authority, tunaPositi
|
|
|
13131
13121
|
instructions.push(ix);
|
|
13132
13122
|
return instructions;
|
|
13133
13123
|
}
|
|
13134
|
-
async function liquidateTunaSpotPositionFusionInstruction(authority,
|
|
13135
|
-
const tunaPositionAddress = (await getTunaSpotPositionAddress(positionMint))[0];
|
|
13124
|
+
async function liquidateTunaSpotPositionFusionInstruction(authority, tunaPositionAddress, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, withdrawPercent) {
|
|
13136
13125
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
13137
13126
|
const tunaPositionAtaA = (await findAssociatedTokenPda23({
|
|
13138
13127
|
owner: tunaPositionAddress,
|
|
@@ -13228,7 +13217,7 @@ async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition
|
|
|
13228
13217
|
instructions.push(...createFeeRecipientAtaInstructions.init);
|
|
13229
13218
|
const ix = await liquidateTunaSpotPositionOrcaInstruction(
|
|
13230
13219
|
authority,
|
|
13231
|
-
tunaPosition.
|
|
13220
|
+
tunaPosition.address,
|
|
13232
13221
|
tunaConfig,
|
|
13233
13222
|
mintA,
|
|
13234
13223
|
mintB,
|
|
@@ -13240,8 +13229,7 @@ async function liquidateTunaSpotPositionOrcaInstructions(authority, tunaPosition
|
|
|
13240
13229
|
instructions.push(ix);
|
|
13241
13230
|
return instructions;
|
|
13242
13231
|
}
|
|
13243
|
-
async function liquidateTunaSpotPositionOrcaInstruction(authority,
|
|
13244
|
-
const tunaPositionAddress = (await getTunaSpotPositionAddress(positionMint))[0];
|
|
13232
|
+
async function liquidateTunaSpotPositionOrcaInstruction(authority, tunaPositionAddress, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, withdrawPercent) {
|
|
13245
13233
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
13246
13234
|
const orcaOracleAddress = (await getOracleAddress7(whirlpool.address))[0];
|
|
13247
13235
|
const tunaPositionAtaA = (await findAssociatedTokenPda24({
|
|
@@ -13489,7 +13477,7 @@ async function openAndIncreaseTunaLpPositionOrcaInstructions(rpc, authority, whi
|
|
|
13489
13477
|
(await getLendingVaultAddress(whirlpool.data.tokenMintA))[0],
|
|
13490
13478
|
(await getLendingVaultAddress(whirlpool.data.tokenMintB))[0]
|
|
13491
13479
|
]);
|
|
13492
|
-
const increaseAmounts =
|
|
13480
|
+
const increaseAmounts = getIncreaseLpPositionQuote({
|
|
13493
13481
|
collateralA: BigInt(args.collateralA),
|
|
13494
13482
|
collateralB: BigInt(args.collateralB),
|
|
13495
13483
|
borrowA: BigInt(args.borrowA),
|
|
@@ -13745,7 +13733,7 @@ async function openAndIncreaseTunaLpPositionFusionInstructions(rpc, authority, f
|
|
|
13745
13733
|
(await getLendingVaultAddress(fusionPool.data.tokenMintA))[0],
|
|
13746
13734
|
(await getLendingVaultAddress(fusionPool.data.tokenMintB))[0]
|
|
13747
13735
|
]);
|
|
13748
|
-
const increaseAmounts =
|
|
13736
|
+
const increaseAmounts = getIncreaseLpPositionQuote({
|
|
13749
13737
|
collateralA: BigInt(args.collateralA),
|
|
13750
13738
|
collateralB: BigInt(args.collateralB),
|
|
13751
13739
|
borrowA: BigInt(args.borrowA),
|
|
@@ -13954,8 +13942,7 @@ async function openAndIncreaseTunaLpPositionFusionInstruction(authority, positio
|
|
|
13954
13942
|
// src/txbuilder/openAndIncreaseTunaSpotPositionFusion.ts
|
|
13955
13943
|
import { fetchMaybeFusionPool as fetchMaybeFusionPool9, FUSIONAMM_PROGRAM_ADDRESS as FUSIONAMM_PROGRAM_ADDRESS13 } from "@crypticdot/fusionamm-client";
|
|
13956
13944
|
import {
|
|
13957
|
-
AccountRole as AccountRole20
|
|
13958
|
-
generateKeyPairSigner as generateKeyPairSigner3
|
|
13945
|
+
AccountRole as AccountRole20
|
|
13959
13946
|
} from "@solana/kit";
|
|
13960
13947
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS20 } from "@solana-program/memo";
|
|
13961
13948
|
import {
|
|
@@ -13968,7 +13955,6 @@ async function openAndIncreaseTunaSpotPositionFusionInstructions(rpc, authority,
|
|
|
13968
13955
|
const instructions = [];
|
|
13969
13956
|
if (!createInstructions) createInstructions = instructions;
|
|
13970
13957
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
13971
|
-
const positionMint = await generateKeyPairSigner3();
|
|
13972
13958
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
13973
13959
|
const fusionPool = await fetchMaybeFusionPool9(rpc, fusionPoolAddress);
|
|
13974
13960
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
@@ -14007,7 +13993,6 @@ async function openAndIncreaseTunaSpotPositionFusionInstructions(rpc, authority,
|
|
|
14007
13993
|
createInstructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
14008
13994
|
const ix = await openAndIncreaseTunaSpotPositionFusionInstruction(
|
|
14009
13995
|
authority,
|
|
14010
|
-
positionMint,
|
|
14011
13996
|
tunaConfig,
|
|
14012
13997
|
mintA,
|
|
14013
13998
|
mintB,
|
|
@@ -14018,13 +14003,10 @@ async function openAndIncreaseTunaSpotPositionFusionInstructions(rpc, authority,
|
|
|
14018
14003
|
);
|
|
14019
14004
|
instructions.push(ix);
|
|
14020
14005
|
cleanupInstructions.push(...createUserAtaInstructions.cleanup);
|
|
14021
|
-
return
|
|
14022
|
-
instructions,
|
|
14023
|
-
positionMint: positionMint.address
|
|
14024
|
-
};
|
|
14006
|
+
return instructions;
|
|
14025
14007
|
}
|
|
14026
|
-
async function openAndIncreaseTunaSpotPositionFusionInstruction(authority,
|
|
14027
|
-
const tunaPositionAddress = (await getTunaSpotPositionAddress(
|
|
14008
|
+
async function openAndIncreaseTunaSpotPositionFusionInstruction(authority, tunaConfig, mintA, mintB, vaultA, vaultB, fusionPool, args) {
|
|
14009
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, fusionPool.address))[0];
|
|
14028
14010
|
const marketAddress = (await getMarketAddress(fusionPool.address))[0];
|
|
14029
14011
|
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda29({
|
|
14030
14012
|
owner: authority.address,
|
|
@@ -14098,7 +14080,6 @@ async function openAndIncreaseTunaSpotPositionFusionInstruction(authority, posit
|
|
|
14098
14080
|
vaultB: vaultB.address,
|
|
14099
14081
|
vaultBAta,
|
|
14100
14082
|
tunaPosition: tunaPositionAddress,
|
|
14101
|
-
tunaPositionMint: positionMint,
|
|
14102
14083
|
tunaPositionAtaA,
|
|
14103
14084
|
tunaPositionAtaB,
|
|
14104
14085
|
tunaPositionOwnerAtaA: args.collateralToken == 0 /* A */ ? tunaPositionOwnerAtaA : void 0,
|
|
@@ -14123,8 +14104,7 @@ import {
|
|
|
14123
14104
|
WHIRLPOOL_PROGRAM_ADDRESS as WHIRLPOOL_PROGRAM_ADDRESS13
|
|
14124
14105
|
} from "@orca-so/whirlpools-client";
|
|
14125
14106
|
import {
|
|
14126
|
-
AccountRole as AccountRole21
|
|
14127
|
-
generateKeyPairSigner as generateKeyPairSigner4
|
|
14107
|
+
AccountRole as AccountRole21
|
|
14128
14108
|
} from "@solana/kit";
|
|
14129
14109
|
import { MEMO_PROGRAM_ADDRESS as MEMO_PROGRAM_ADDRESS21 } from "@solana-program/memo";
|
|
14130
14110
|
import {
|
|
@@ -14137,7 +14117,6 @@ async function openAndIncreaseTunaSpotPositionOrcaInstructions(rpc, authority, w
|
|
|
14137
14117
|
const instructions = [];
|
|
14138
14118
|
if (!createInstructions) createInstructions = instructions;
|
|
14139
14119
|
if (!cleanupInstructions) cleanupInstructions = instructions;
|
|
14140
|
-
const positionMint = await generateKeyPairSigner4();
|
|
14141
14120
|
const tunaConfig = await fetchTunaConfig(rpc, (await getTunaConfigAddress())[0]);
|
|
14142
14121
|
const whirlpool = await fetchMaybeWhirlpool9(rpc, whirlpoolAddress);
|
|
14143
14122
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
@@ -14176,7 +14155,6 @@ async function openAndIncreaseTunaSpotPositionOrcaInstructions(rpc, authority, w
|
|
|
14176
14155
|
createInstructions.push(...createFeeRecipientAtaBInstructions.init);
|
|
14177
14156
|
const ix = await openAndIncreaseTunaSpotPositionOrcaInstruction(
|
|
14178
14157
|
authority,
|
|
14179
|
-
positionMint,
|
|
14180
14158
|
tunaConfig,
|
|
14181
14159
|
mintA,
|
|
14182
14160
|
mintB,
|
|
@@ -14187,13 +14165,10 @@ async function openAndIncreaseTunaSpotPositionOrcaInstructions(rpc, authority, w
|
|
|
14187
14165
|
);
|
|
14188
14166
|
instructions.push(ix);
|
|
14189
14167
|
cleanupInstructions.push(...createUserAtaInstructions.cleanup);
|
|
14190
|
-
return
|
|
14191
|
-
instructions,
|
|
14192
|
-
positionMint: positionMint.address
|
|
14193
|
-
};
|
|
14168
|
+
return instructions;
|
|
14194
14169
|
}
|
|
14195
|
-
async function openAndIncreaseTunaSpotPositionOrcaInstruction(authority,
|
|
14196
|
-
const tunaPositionAddress = (await getTunaSpotPositionAddress(
|
|
14170
|
+
async function openAndIncreaseTunaSpotPositionOrcaInstruction(authority, tunaConfig, mintA, mintB, vaultA, vaultB, whirlpool, args) {
|
|
14171
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, whirlpool.address))[0];
|
|
14197
14172
|
const marketAddress = (await getMarketAddress(whirlpool.address))[0];
|
|
14198
14173
|
const orcaOracleAddress = (await getOracleAddress9(whirlpool.address))[0];
|
|
14199
14174
|
const tunaPositionOwnerAtaA = (await findAssociatedTokenPda30({
|
|
@@ -14270,7 +14245,6 @@ async function openAndIncreaseTunaSpotPositionOrcaInstruction(authority, positio
|
|
|
14270
14245
|
vaultB: vaultB.address,
|
|
14271
14246
|
vaultBAta,
|
|
14272
14247
|
tunaPosition: tunaPositionAddress,
|
|
14273
|
-
tunaPositionMint: positionMint,
|
|
14274
14248
|
tunaPositionAtaA,
|
|
14275
14249
|
tunaPositionAtaB,
|
|
14276
14250
|
tunaPositionOwnerAtaA: args.collateralToken == 0 /* A */ ? tunaPositionOwnerAtaA : void 0,
|
|
@@ -14296,24 +14270,17 @@ import {
|
|
|
14296
14270
|
findAssociatedTokenPda as findAssociatedTokenPda31
|
|
14297
14271
|
} from "@solana-program/token-2022";
|
|
14298
14272
|
import assert24 from "assert";
|
|
14299
|
-
async function openTunaSpotPositionFusionInstructions(rpc, authority,
|
|
14273
|
+
async function openTunaSpotPositionFusionInstructions(rpc, authority, fusionPoolAddress, args) {
|
|
14300
14274
|
const fusionPool = await fetchMaybeFusionPool10(rpc, fusionPoolAddress);
|
|
14301
14275
|
if (!fusionPool.exists) throw new Error("FusionPool account not found");
|
|
14302
14276
|
const [mintA, mintB] = await fetchAllMaybeMint24(rpc, [fusionPool.data.tokenMintA, fusionPool.data.tokenMintB]);
|
|
14303
14277
|
assert24(mintA.exists, "Token A account not found");
|
|
14304
14278
|
assert24(mintB.exists, "Token B account not found");
|
|
14305
|
-
const ix = await openTunaSpotPositionFusionInstruction(
|
|
14306
|
-
authority,
|
|
14307
|
-
positionMint,
|
|
14308
|
-
mintA,
|
|
14309
|
-
mintB,
|
|
14310
|
-
fusionPoolAddress,
|
|
14311
|
-
args
|
|
14312
|
-
);
|
|
14279
|
+
const ix = await openTunaSpotPositionFusionInstruction(authority, mintA, mintB, fusionPoolAddress, args);
|
|
14313
14280
|
return [ix];
|
|
14314
14281
|
}
|
|
14315
|
-
async function openTunaSpotPositionFusionInstruction(authority,
|
|
14316
|
-
const tunaPositionAddress = (await getTunaSpotPositionAddress(
|
|
14282
|
+
async function openTunaSpotPositionFusionInstruction(authority, mintA, mintB, fusionPoolAddress, args) {
|
|
14283
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, fusionPoolAddress))[0];
|
|
14317
14284
|
const tunaPositionAtaA = (await findAssociatedTokenPda31({
|
|
14318
14285
|
owner: tunaPositionAddress,
|
|
14319
14286
|
mint: mintA.address,
|
|
@@ -14331,7 +14298,6 @@ async function openTunaSpotPositionFusionInstruction(authority, positionMint, mi
|
|
|
14331
14298
|
tokenProgramA: mintA.programAddress,
|
|
14332
14299
|
tokenProgramB: mintB.programAddress,
|
|
14333
14300
|
tunaPosition: tunaPositionAddress,
|
|
14334
|
-
tunaPositionMint: positionMint,
|
|
14335
14301
|
tunaPositionAtaA,
|
|
14336
14302
|
tunaPositionAtaB,
|
|
14337
14303
|
fusionPool: fusionPoolAddress,
|
|
@@ -14348,17 +14314,17 @@ import {
|
|
|
14348
14314
|
findAssociatedTokenPda as findAssociatedTokenPda32
|
|
14349
14315
|
} from "@solana-program/token-2022";
|
|
14350
14316
|
import assert25 from "assert";
|
|
14351
|
-
async function openTunaSpotPositionOrcaInstructions(rpc, authority,
|
|
14317
|
+
async function openTunaSpotPositionOrcaInstructions(rpc, authority, whirlpoolAddress, args) {
|
|
14352
14318
|
const whirlpool = await fetchMaybeWhirlpool10(rpc, whirlpoolAddress);
|
|
14353
14319
|
if (!whirlpool.exists) throw new Error("Whirlpool account not found");
|
|
14354
14320
|
const [mintA, mintB] = await fetchAllMaybeMint25(rpc, [whirlpool.data.tokenMintA, whirlpool.data.tokenMintB]);
|
|
14355
14321
|
assert25(mintA.exists, "Token A account not found");
|
|
14356
14322
|
assert25(mintB.exists, "Token B account not found");
|
|
14357
|
-
const ix = await openTunaSpotPositionOrcaInstruction(authority,
|
|
14323
|
+
const ix = await openTunaSpotPositionOrcaInstruction(authority, mintA, mintB, whirlpoolAddress, args);
|
|
14358
14324
|
return [ix];
|
|
14359
14325
|
}
|
|
14360
|
-
async function openTunaSpotPositionOrcaInstruction(authority,
|
|
14361
|
-
const tunaPositionAddress = (await getTunaSpotPositionAddress(
|
|
14326
|
+
async function openTunaSpotPositionOrcaInstruction(authority, mintA, mintB, whirlpoolAddress, args) {
|
|
14327
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, whirlpoolAddress))[0];
|
|
14362
14328
|
const tunaPositionAtaA = (await findAssociatedTokenPda32({
|
|
14363
14329
|
owner: tunaPositionAddress,
|
|
14364
14330
|
mint: mintA.address,
|
|
@@ -14376,7 +14342,6 @@ async function openTunaSpotPositionOrcaInstruction(authority, positionMint, mint
|
|
|
14376
14342
|
tokenProgramA: mintA.programAddress,
|
|
14377
14343
|
tokenProgramB: mintB.programAddress,
|
|
14378
14344
|
tunaPosition: tunaPositionAddress,
|
|
14379
|
-
tunaPositionMint: positionMint,
|
|
14380
14345
|
tunaPositionAtaA,
|
|
14381
14346
|
tunaPositionAtaB,
|
|
14382
14347
|
whirlpool: whirlpoolAddress,
|
|
@@ -14818,13 +14783,8 @@ async function setTunaLpPositionLimitOrdersInstruction(authority, args, position
|
|
|
14818
14783
|
}
|
|
14819
14784
|
|
|
14820
14785
|
// src/txbuilder/setTunaSpotPositionLimitOrders.ts
|
|
14821
|
-
async function setTunaSpotPositionLimitOrdersInstruction(authority,
|
|
14822
|
-
|
|
14823
|
-
if (positionMint === void 0) {
|
|
14824
|
-
throw new Error("At least one of 'positionMint' or 'tunaPositionAddress' must be provided.");
|
|
14825
|
-
}
|
|
14826
|
-
tunaPositionAddress = (await getTunaSpotPositionAddress(positionMint))[0];
|
|
14827
|
-
}
|
|
14786
|
+
async function setTunaSpotPositionLimitOrdersInstruction(authority, poolAddress, args) {
|
|
14787
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
14828
14788
|
return getSetTunaSpotPositionLimitOrdersInstruction({
|
|
14829
14789
|
...args,
|
|
14830
14790
|
authority,
|
|
@@ -14835,13 +14795,8 @@ async function setTunaSpotPositionLimitOrdersInstruction(authority, args, positi
|
|
|
14835
14795
|
// src/txbuilder/resetTunaSpotPosition.ts
|
|
14836
14796
|
import { fetchAllMaybeMint as fetchAllMaybeMint28, findAssociatedTokenPda as findAssociatedTokenPda36 } from "@solana-program/token-2022";
|
|
14837
14797
|
import assert28 from "assert";
|
|
14838
|
-
async function resetTunaSpotPositionInstruction(rpc, authority,
|
|
14839
|
-
|
|
14840
|
-
if (positionMint === void 0) {
|
|
14841
|
-
throw new Error("At least one of 'positionMint' or 'tunaPositionAddress' must be provided.");
|
|
14842
|
-
}
|
|
14843
|
-
tunaPositionAddress = (await getTunaSpotPositionAddress(positionMint))[0];
|
|
14844
|
-
}
|
|
14798
|
+
async function resetTunaSpotPositionInstruction(rpc, authority, poolAddress, args) {
|
|
14799
|
+
const tunaPositionAddress = (await getTunaSpotPositionAddress(authority.address, poolAddress))[0];
|
|
14845
14800
|
const tunaPosition = await fetchTunaSpotPosition(rpc, tunaPositionAddress);
|
|
14846
14801
|
const [mintA, mintB] = await fetchAllMaybeMint28(rpc, [tunaPosition.data.mintA, tunaPosition.data.mintB]);
|
|
14847
14802
|
assert28(mintA.exists, "Token A not found");
|
|
@@ -15542,8 +15497,8 @@ export {
|
|
|
15542
15497
|
DECREASE_TUNA_SPOT_POSITION_FUSION_DISCRIMINATOR,
|
|
15543
15498
|
DECREASE_TUNA_SPOT_POSITION_ORCA_DISCRIMINATOR,
|
|
15544
15499
|
DEFAULT_ADDRESS,
|
|
15545
|
-
DEFAULT_MAX_AMOUNT_SLIPPAGE,
|
|
15546
15500
|
DEFAULT_MAX_SWAP_SLIPPAGE,
|
|
15501
|
+
DEFAULT_PUSH_ORACLE_PROGRAM_ID,
|
|
15547
15502
|
DEPOSIT_DISCRIMINATOR,
|
|
15548
15503
|
FusionUtils,
|
|
15549
15504
|
HUNDRED_PERCENT,
|
|
@@ -15841,6 +15796,7 @@ export {
|
|
|
15841
15796
|
getDepositInstructionDataCodec,
|
|
15842
15797
|
getDepositInstructionDataDecoder,
|
|
15843
15798
|
getDepositInstructionDataEncoder,
|
|
15799
|
+
getIncreaseLpPositionQuote,
|
|
15844
15800
|
getIncreaseTunaLpPositionFusionDiscriminatorBytes,
|
|
15845
15801
|
getIncreaseTunaLpPositionFusionInstruction,
|
|
15846
15802
|
getIncreaseTunaLpPositionFusionInstructionDataCodec,
|
|
@@ -15888,7 +15844,6 @@ export {
|
|
|
15888
15844
|
getLiquidateTunaSpotPositionOrcaInstructionDataCodec,
|
|
15889
15845
|
getLiquidateTunaSpotPositionOrcaInstructionDataDecoder,
|
|
15890
15846
|
getLiquidateTunaSpotPositionOrcaInstructionDataEncoder,
|
|
15891
|
-
getLiquidityIncreaseQuote,
|
|
15892
15847
|
getMarketAddress,
|
|
15893
15848
|
getMarketCodec,
|
|
15894
15849
|
getMarketDecoder,
|
|
@@ -15946,6 +15901,7 @@ export {
|
|
|
15946
15901
|
getPoolTokenCodec,
|
|
15947
15902
|
getPoolTokenDecoder,
|
|
15948
15903
|
getPoolTokenEncoder,
|
|
15904
|
+
getPythPriceUpdateAccountAddress,
|
|
15949
15905
|
getRebalanceTunaLpPositionFusionDiscriminatorBytes,
|
|
15950
15906
|
getRebalanceTunaLpPositionFusionInstruction,
|
|
15951
15907
|
getRebalanceTunaLpPositionFusionInstructionDataCodec,
|
|
@@ -16190,7 +16146,6 @@ export {
|
|
|
16190
16146
|
tunaSpotPositionAuthorityFilter,
|
|
16191
16147
|
tunaSpotPositionMintAFilter,
|
|
16192
16148
|
tunaSpotPositionMintBFilter,
|
|
16193
|
-
tunaSpotPositionMintFilter,
|
|
16194
16149
|
tunaSpotPositionPoolFilter,
|
|
16195
16150
|
updateMarketInstruction,
|
|
16196
16151
|
updateVaultInstruction,
|