@elmntl/jlpd-sdk 0.1.11 → 0.13.4
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/LICENSE +201 -0
- package/README.md +185 -404
- package/dist/common/ata.d.ts +26 -0
- package/dist/common/ata.js +48 -0
- package/dist/common/buffer.d.ts +15 -0
- package/dist/common/buffer.js +118 -0
- package/dist/common/connection.d.ts +13 -0
- package/dist/common/connection.js +2 -0
- package/dist/common/constants.d.ts +14 -0
- package/dist/common/constants.js +31 -0
- package/dist/common/index.d.ts +6 -0
- package/dist/common/index.js +28 -0
- package/dist/common/strategy-interface.d.ts +59 -0
- package/dist/common/strategy-interface.js +42 -0
- package/dist/elemental-lend/accounts.d.ts +103 -0
- package/dist/elemental-lend/accounts.js +354 -0
- package/dist/elemental-lend/constants.d.ts +25 -0
- package/dist/elemental-lend/constants.js +48 -0
- package/dist/elemental-lend/index.d.ts +8 -0
- package/dist/elemental-lend/index.js +24 -0
- package/dist/elemental-lend/instructions.d.ts +104 -0
- package/dist/elemental-lend/instructions.js +266 -0
- package/dist/elemental-lend/jupiter-lend.d.ts +91 -0
- package/dist/elemental-lend/jupiter-lend.js +189 -0
- package/dist/elemental-lend/kamino-vault.d.ts +173 -0
- package/dist/elemental-lend/kamino-vault.js +483 -0
- package/dist/elemental-lend/pda.d.ts +12 -0
- package/dist/elemental-lend/pda.js +24 -0
- package/dist/elemental-lend/protocol-actions.d.ts +56 -0
- package/dist/elemental-lend/protocol-actions.js +244 -0
- package/dist/elemental-lend/types.d.ts +113 -0
- package/dist/elemental-lend/types.js +2 -0
- package/dist/elemental-lend-v2/accounts.d.ts +14 -0
- package/dist/elemental-lend-v2/accounts.js +136 -0
- package/dist/elemental-lend-v2/adapters.d.ts +22 -0
- package/dist/elemental-lend-v2/adapters.js +50 -0
- package/dist/elemental-lend-v2/constants.d.ts +48 -0
- package/dist/elemental-lend-v2/constants.js +104 -0
- package/dist/elemental-lend-v2/index.d.ts +8 -0
- package/dist/elemental-lend-v2/index.js +24 -0
- package/dist/elemental-lend-v2/instructions.d.ts +96 -0
- package/dist/elemental-lend-v2/instructions.js +190 -0
- package/dist/elemental-lend-v2/lut.d.ts +20 -0
- package/dist/elemental-lend-v2/lut.js +65 -0
- package/dist/elemental-lend-v2/pda.d.ts +9 -0
- package/dist/elemental-lend-v2/pda.js +27 -0
- package/dist/elemental-lend-v2/types.d.ts +105 -0
- package/dist/elemental-lend-v2/types.js +2 -0
- package/dist/elemental-lend-v2/update-aum.d.ts +29 -0
- package/dist/elemental-lend-v2/update-aum.js +82 -0
- package/dist/index.d.ts +5 -3552
- package/dist/index.js +37 -4454
- package/dist/jlpd-strategy/accounts.d.ts +83 -0
- package/dist/jlpd-strategy/accounts.js +216 -0
- package/dist/jlpd-strategy/adapter.d.ts +81 -0
- package/dist/jlpd-strategy/adapter.js +118 -0
- package/dist/jlpd-strategy/base-to-base-swap.d.ts +74 -0
- package/dist/jlpd-strategy/base-to-base-swap.js +205 -0
- package/dist/jlpd-strategy/constants.d.ts +127 -0
- package/dist/jlpd-strategy/constants.js +174 -0
- package/dist/jlpd-strategy/fluid-view.d.ts +199 -0
- package/dist/jlpd-strategy/fluid-view.js +799 -0
- package/dist/jlpd-strategy/hedge-derived.d.ts +135 -0
- package/dist/jlpd-strategy/hedge-derived.js +231 -0
- package/dist/jlpd-strategy/hedge-instructions.d.ts +210 -0
- package/dist/jlpd-strategy/hedge-instructions.js +300 -0
- package/dist/jlpd-strategy/hedge-state.d.ts +88 -0
- package/dist/jlpd-strategy/hedge-state.js +110 -0
- package/dist/jlpd-strategy/index.d.ts +17 -0
- package/dist/jlpd-strategy/index.js +33 -0
- package/dist/jlpd-strategy/instructions.d.ts +159 -0
- package/dist/jlpd-strategy/instructions.js +234 -0
- package/dist/jlpd-strategy/jlp-borrow.d.ts +63 -0
- package/dist/jlpd-strategy/jlp-borrow.js +87 -0
- package/dist/jlpd-strategy/jlp-data.d.ts +166 -0
- package/dist/jlpd-strategy/jlp-data.js +611 -0
- package/dist/jlpd-strategy/jupusd-earn.d.ts +90 -0
- package/dist/jlpd-strategy/jupusd-earn.js +166 -0
- package/dist/jlpd-strategy/live-jlp-price.d.ts +46 -0
- package/dist/jlpd-strategy/live-jlp-price.js +267 -0
- package/dist/jlpd-strategy/pda.d.ts +13 -0
- package/dist/jlpd-strategy/pda.js +28 -0
- package/dist/jlpd-strategy/settle-yield.d.ts +45 -0
- package/dist/jlpd-strategy/settle-yield.js +113 -0
- package/dist/jlpd-strategy/swap-jlp.d.ts +198 -0
- package/dist/jlpd-strategy/swap-jlp.js +586 -0
- package/dist/jlpd-strategy/types.d.ts +101 -0
- package/dist/jlpd-strategy/types.js +29 -0
- package/dist/p-stv-core/accounts.d.ts +152 -0
- package/dist/p-stv-core/accounts.js +407 -0
- package/dist/p-stv-core/constants.d.ts +138 -0
- package/dist/p-stv-core/constants.js +181 -0
- package/dist/p-stv-core/events.d.ts +7 -0
- package/dist/p-stv-core/events.js +246 -0
- package/dist/p-stv-core/index.d.ts +11 -0
- package/dist/p-stv-core/index.js +27 -0
- package/dist/p-stv-core/instructions.d.ts +637 -0
- package/dist/p-stv-core/instructions.js +670 -0
- package/dist/p-stv-core/lut.d.ts +41 -0
- package/dist/p-stv-core/lut.js +81 -0
- package/dist/p-stv-core/pda.d.ts +30 -0
- package/dist/p-stv-core/pda.js +65 -0
- package/dist/p-stv-core/prices.d.ts +20 -0
- package/dist/p-stv-core/prices.js +77 -0
- package/dist/p-stv-core/remaining-accounts.d.ts +107 -0
- package/dist/p-stv-core/remaining-accounts.js +326 -0
- package/dist/p-stv-core/send-tx.d.ts +72 -0
- package/dist/p-stv-core/send-tx.js +290 -0
- package/dist/p-stv-core/sol-wrap.d.ts +34 -0
- package/dist/p-stv-core/sol-wrap.js +74 -0
- package/dist/p-stv-core/types.d.ts +361 -0
- package/dist/p-stv-core/types.js +2 -0
- package/package.json +56 -15
- package/dist/index.d.mts +0 -3552
- package/dist/index.mjs +0 -4363
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSettleYieldIx = createSettleYieldIx;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const pda_1 = require("./pda");
|
|
8
|
+
const ata_1 = require("../common/ata");
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Internal raw builder
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
/**
|
|
13
|
+
* Build the on-chain `settle_yield` instruction from explicit account inputs.
|
|
14
|
+
*
|
|
15
|
+
* settle_yield takes no params -- instruction data is just the 8-byte discriminator.
|
|
16
|
+
*
|
|
17
|
+
* Accounts (15 total):
|
|
18
|
+
* 0: config (JlpdConfig PDA)
|
|
19
|
+
* 1: manager_role (ManagerRole PDA)
|
|
20
|
+
* 2: hedge_state (HedgeState PDA, mut -- resets swap-churn accumulator)
|
|
21
|
+
* 3: vault_jlp_ata (JLP ATA owned by config)
|
|
22
|
+
* 4: stv_0 (BTC strategy_state, mut)
|
|
23
|
+
* 5: stv_1 (ETH strategy_state, mut)
|
|
24
|
+
* 6: stv_2 (SOL strategy_state, mut)
|
|
25
|
+
* 7: stv_3 (USDC strategy_state, mut)
|
|
26
|
+
* 8: stv_4 (JupUSD strategy_state, mut)
|
|
27
|
+
* 9: doves_btc_usd (oracle)
|
|
28
|
+
* 10: doves_eth_usd (oracle)
|
|
29
|
+
* 11: doves_sol_usd (oracle)
|
|
30
|
+
* 12: jlp_pool (Jupiter Perps Pool)
|
|
31
|
+
* 13: jlp_mint_account
|
|
32
|
+
* 14: manager (signer)
|
|
33
|
+
* 15+: remaining_accounts, in this EXACT order:
|
|
34
|
+
* [0 .. 2*enabled_hedge_slots) -- (position, vault_state) pairs per
|
|
35
|
+
* ENABLED hedge slot, then the manifest + earn block (one account per
|
|
36
|
+
* non-default hedge manifest slot). Empty while the hedge is disabled.
|
|
37
|
+
* [.. remainder) -- the JLP pool custody accounts, in pool `custodies`
|
|
38
|
+
* Vec order (6 today). REQUIRED on mainnet even when the hedge is off
|
|
39
|
+
* (consumed by `compute_live_jlp_price`).
|
|
40
|
+
*/
|
|
41
|
+
function buildRawSettleYieldIx(args, programId = constants_1.PROGRAM_ID) {
|
|
42
|
+
const { config, managerRole, hedgeState, vaultJlpAta, stv0, stv1, stv2, stv3, stv4, dovesBtcUsd, dovesEthUsd, dovesSolUsd, jlpPool, jlpMintAccount, manager, hedgeAccounts = [], custodyAccounts, } = args;
|
|
43
|
+
// Instruction data: just the 8-byte discriminator (no params)
|
|
44
|
+
const data = Buffer.alloc(8);
|
|
45
|
+
constants_1.IX_SETTLE_YIELD.copy(data, 0);
|
|
46
|
+
const keys = [
|
|
47
|
+
{ pubkey: config, isSigner: false, isWritable: true },
|
|
48
|
+
{ pubkey: managerRole, isSigner: false, isWritable: false },
|
|
49
|
+
{ pubkey: hedgeState, isSigner: false, isWritable: true },
|
|
50
|
+
{ pubkey: vaultJlpAta, isSigner: false, isWritable: false },
|
|
51
|
+
{ pubkey: stv0, isSigner: false, isWritable: true },
|
|
52
|
+
{ pubkey: stv1, isSigner: false, isWritable: true },
|
|
53
|
+
{ pubkey: stv2, isSigner: false, isWritable: true },
|
|
54
|
+
{ pubkey: stv3, isSigner: false, isWritable: true },
|
|
55
|
+
{ pubkey: stv4, isSigner: false, isWritable: true },
|
|
56
|
+
{ pubkey: dovesBtcUsd, isSigner: false, isWritable: false },
|
|
57
|
+
{ pubkey: dovesEthUsd, isSigner: false, isWritable: false },
|
|
58
|
+
{ pubkey: dovesSolUsd, isSigner: false, isWritable: false },
|
|
59
|
+
{ pubkey: jlpPool, isSigner: false, isWritable: false },
|
|
60
|
+
{ pubkey: jlpMintAccount, isSigner: false, isWritable: false },
|
|
61
|
+
{ pubkey: manager, isSigner: true, isWritable: false },
|
|
62
|
+
...hedgeAccounts,
|
|
63
|
+
...custodyAccounts.map((pubkey) => ({ pubkey, isSigner: false, isWritable: false })),
|
|
64
|
+
];
|
|
65
|
+
return new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
66
|
+
}
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// Public instruction builder
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
/**
|
|
71
|
+
* Build a `settle_yield` instruction with automatic PDA derivation.
|
|
72
|
+
*
|
|
73
|
+
* Requires the 5 base asset mints in order: [BTC, ETH, SOL, USDC, JupUSD].
|
|
74
|
+
* These must match the `base_asset_mints` array on the JlpdConfig account.
|
|
75
|
+
*
|
|
76
|
+
* Naming follows the SDK convention: low-level instruction builders are named
|
|
77
|
+
* `create*Ix` (this is the canonical name); high-level transaction wrappers
|
|
78
|
+
* (if any) are named `build*Transaction`.
|
|
79
|
+
*/
|
|
80
|
+
function createSettleYieldIx(args) {
|
|
81
|
+
const { manager, baseAssetMints, jlpMint = constants_1.JLP_MINT, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID, programId = constants_1.PROGRAM_ID, hedgeAccounts, custodyAccounts, priceOracleBtc = constants_1.DOVES_BTC_USD, priceOracleEth = constants_1.DOVES_ETH_USD, priceOracleSol = constants_1.DOVES_SOL_USD, } = args;
|
|
82
|
+
// Derive PDAs
|
|
83
|
+
const [config] = (0, pda_1.findJlpdConfigPda)(programId);
|
|
84
|
+
const [managerRole] = (0, pda_1.findJlpdManagerRolePda)(config, manager, programId);
|
|
85
|
+
const [hedgeState] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("hedge"), config.toBuffer()], programId);
|
|
86
|
+
// Derive strategy_state PDAs for all 5 base assets
|
|
87
|
+
const [stv0] = (0, pda_1.findStrategyStatePda)(baseAssetMints[0], programId);
|
|
88
|
+
const [stv1] = (0, pda_1.findStrategyStatePda)(baseAssetMints[1], programId);
|
|
89
|
+
const [stv2] = (0, pda_1.findStrategyStatePda)(baseAssetMints[2], programId);
|
|
90
|
+
const [stv3] = (0, pda_1.findStrategyStatePda)(baseAssetMints[3], programId);
|
|
91
|
+
const [stv4] = (0, pda_1.findStrategyStatePda)(baseAssetMints[4], programId);
|
|
92
|
+
// Derive vault JLP ATA (owned by config PDA)
|
|
93
|
+
const vaultJlpAta = (0, ata_1.findAta)(jlpMint, config, tokenProgram);
|
|
94
|
+
return buildRawSettleYieldIx({
|
|
95
|
+
config,
|
|
96
|
+
managerRole,
|
|
97
|
+
hedgeState,
|
|
98
|
+
vaultJlpAta,
|
|
99
|
+
stv0,
|
|
100
|
+
stv1,
|
|
101
|
+
stv2,
|
|
102
|
+
stv3,
|
|
103
|
+
stv4,
|
|
104
|
+
dovesBtcUsd: priceOracleBtc,
|
|
105
|
+
dovesEthUsd: priceOracleEth,
|
|
106
|
+
dovesSolUsd: priceOracleSol,
|
|
107
|
+
jlpPool: constants_1.JLP_POOL_ACCOUNT,
|
|
108
|
+
jlpMintAccount: jlpMint,
|
|
109
|
+
manager,
|
|
110
|
+
hedgeAccounts,
|
|
111
|
+
custodyAccounts,
|
|
112
|
+
}, programId);
|
|
113
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction, AddressLookupTableAccount, AccountMeta } from "@solana/web3.js";
|
|
2
|
+
import type { SolanaConnection } from "../common/connection";
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
import { fetchJlpStrategyState } from "./accounts";
|
|
5
|
+
/** Direction of the JLP swap */
|
|
6
|
+
export type SwapDirection = "BaseToJlp" | "JlpToBase";
|
|
7
|
+
/** Arguments for building a swap_jlp instruction */
|
|
8
|
+
export interface CreateSwapJlpIxArgs {
|
|
9
|
+
manager: PublicKey;
|
|
10
|
+
config: PublicKey;
|
|
11
|
+
managerRole: PublicKey;
|
|
12
|
+
strategyState: PublicKey;
|
|
13
|
+
strategyBaseAta: PublicKey;
|
|
14
|
+
strategyJlpAta: PublicKey;
|
|
15
|
+
vaultJlpAta: PublicKey;
|
|
16
|
+
baseMint: PublicKey;
|
|
17
|
+
jlpMint: PublicKey;
|
|
18
|
+
tokenProgram: PublicKey;
|
|
19
|
+
jupiterProgram: PublicKey;
|
|
20
|
+
/**
|
|
21
|
+
* Doves price-feed account for this base asset. Must match
|
|
22
|
+
* strategy_state.price_oracle on-chain. Stablecoins (USDC/JupUSD) use
|
|
23
|
+
* PublicKey.default — the program ignores the oracle for $1-pegged assets.
|
|
24
|
+
*/
|
|
25
|
+
priceOracle: PublicKey;
|
|
26
|
+
/** Jupiter Perps JLP pool account — must equal the on-chain JLP_POOL_ACCOUNT. */
|
|
27
|
+
jlpPool: PublicKey;
|
|
28
|
+
/** JLP mint account (raw) for pool-price supply read — equals config.jlp_mint. */
|
|
29
|
+
jlpMintAccount: PublicKey;
|
|
30
|
+
direction: SwapDirection;
|
|
31
|
+
amount: bigint | BN;
|
|
32
|
+
minOut: bigint | BN;
|
|
33
|
+
jupiterData: Buffer | Uint8Array;
|
|
34
|
+
remainingAccounts?: AccountMeta[];
|
|
35
|
+
}
|
|
36
|
+
/** Jupiter swap quote response */
|
|
37
|
+
export interface JupiterQuote {
|
|
38
|
+
inputMint: string;
|
|
39
|
+
inAmount: string;
|
|
40
|
+
outputMint: string;
|
|
41
|
+
outAmount: string;
|
|
42
|
+
otherAmountThreshold: string;
|
|
43
|
+
swapMode: string;
|
|
44
|
+
slippageBps: number;
|
|
45
|
+
priceImpactPct: string;
|
|
46
|
+
routePlan: unknown[];
|
|
47
|
+
contextSlot?: number;
|
|
48
|
+
timeTaken?: number;
|
|
49
|
+
}
|
|
50
|
+
/** Parsed Jupiter swap instruction from the API */
|
|
51
|
+
export interface JupiterSwapInstruction {
|
|
52
|
+
programId: string;
|
|
53
|
+
data: string;
|
|
54
|
+
accounts: {
|
|
55
|
+
pubkey: string;
|
|
56
|
+
isSigner: boolean;
|
|
57
|
+
isWritable: boolean;
|
|
58
|
+
}[];
|
|
59
|
+
}
|
|
60
|
+
/** Jupiter swap-instructions API response */
|
|
61
|
+
export interface JupiterSwapInstructionsResponse {
|
|
62
|
+
tokenLedgerInstruction: JupiterSwapInstruction | null;
|
|
63
|
+
computeBudgetInstructions: JupiterSwapInstruction[];
|
|
64
|
+
setupInstructions: JupiterSwapInstruction[];
|
|
65
|
+
swapInstruction: JupiterSwapInstruction;
|
|
66
|
+
cleanupInstruction: JupiterSwapInstruction | null;
|
|
67
|
+
addressLookupTableAddresses: string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build the on-chain `swap_jlp` instruction.
|
|
71
|
+
*
|
|
72
|
+
* Instruction data layout (Anchor Borsh):
|
|
73
|
+
* [8-byte disc, 1-byte direction, 8-byte amount (LE), 8-byte min_out (LE),
|
|
74
|
+
* 4-byte jupiter_data_len (LE), ...jupiter_data_bytes]
|
|
75
|
+
*/
|
|
76
|
+
export declare function createSwapJlpIx(args: CreateSwapJlpIxArgs, programId?: PublicKey): TransactionInstruction;
|
|
77
|
+
/**
|
|
78
|
+
* Fetch a swap quote from Jupiter's v1 quote API.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getJupiterSwapQuote(args: {
|
|
81
|
+
inputMint: PublicKey;
|
|
82
|
+
outputMint: PublicKey;
|
|
83
|
+
amount: number | bigint;
|
|
84
|
+
slippageBps?: number;
|
|
85
|
+
maxAccounts?: number;
|
|
86
|
+
}): Promise<JupiterQuote>;
|
|
87
|
+
/**
|
|
88
|
+
* Fetch swap instructions from Jupiter's v1 swap-instructions API.
|
|
89
|
+
*
|
|
90
|
+
* @param quoteResponse The quote from getJupiterSwapQuote
|
|
91
|
+
* @param userPublicKey The account that signs the swap -- for JLPD this is the strategy_state PDA
|
|
92
|
+
* @param destinationTokenAccount Optional override for the destination token account.
|
|
93
|
+
* For base_to_base_swap: must be base_out_ata (ATA owned by strategy_state_OUT) so
|
|
94
|
+
* Jupiter routes output tokens there instead of to userPublicKey's default ATA.
|
|
95
|
+
* For swap_jlp: omit — Jupiter defaults destination to userPublicKey's ATA which is correct.
|
|
96
|
+
*/
|
|
97
|
+
export declare function getJupiterSwapInstructions(args: {
|
|
98
|
+
quoteResponse: JupiterQuote;
|
|
99
|
+
userPublicKey: PublicKey;
|
|
100
|
+
destinationTokenAccount?: PublicKey;
|
|
101
|
+
}): Promise<{
|
|
102
|
+
swapInstructionData: Buffer;
|
|
103
|
+
remainingAccounts: AccountMeta[];
|
|
104
|
+
addressLookupTableAddresses: string[];
|
|
105
|
+
/** Decoded compute-budget instructions from Jupiter. Must be prepended to the tx. */
|
|
106
|
+
computeBudgetInstructions: TransactionInstruction[];
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Build a complete swap_jlp transaction with Jupiter quote + instructions + ALTs.
|
|
110
|
+
*
|
|
111
|
+
* This is the main function the frontend calls. It:
|
|
112
|
+
* 1. Derives all PDAs (config, manager_role, strategy_state, ATAs)
|
|
113
|
+
* 2. Gets Jupiter quote
|
|
114
|
+
* 3. Gets Jupiter swap instructions
|
|
115
|
+
* 4. Builds the swap_jlp instruction with remaining accounts
|
|
116
|
+
* 5. Returns instructions + ALTs for a versioned transaction
|
|
117
|
+
*/
|
|
118
|
+
export declare function buildSwapJlpTransaction(args: {
|
|
119
|
+
connection: SolanaConnection;
|
|
120
|
+
manager: PublicKey;
|
|
121
|
+
baseMint: PublicKey;
|
|
122
|
+
direction: SwapDirection;
|
|
123
|
+
amount: bigint;
|
|
124
|
+
slippageBps?: number;
|
|
125
|
+
jlpMint?: PublicKey;
|
|
126
|
+
tokenProgram?: PublicKey;
|
|
127
|
+
programId?: PublicKey;
|
|
128
|
+
/**
|
|
129
|
+
* Doves price-feed account for this base asset. Must equal
|
|
130
|
+
* strategy_state.price_oracle on-chain.
|
|
131
|
+
*
|
|
132
|
+
* - For non-stable assets (BTC/ETH/SOL): if omitted the strategy state is
|
|
133
|
+
* fetched from the chain to read the stored feed. Provide this when you
|
|
134
|
+
* already have the strategy state in memory to avoid an extra RPC call.
|
|
135
|
+
* - For stable assets (USDC/JupUSD): pass `PublicKey.default` or omit —
|
|
136
|
+
* the program uses a hardcoded $1 price and ignores the oracle account.
|
|
137
|
+
*/
|
|
138
|
+
priceOracle?: PublicKey;
|
|
139
|
+
/**
|
|
140
|
+
* Pre-fetched strategy state (optional). When provided AND the asset is not a stable,
|
|
141
|
+
* the internal strategy-state fetch is skipped, saving one RPC call. Also used to
|
|
142
|
+
* thread the decoded `swapArb` field for BaseToJlp without a second fetch.
|
|
143
|
+
*
|
|
144
|
+
* Callers that already have the strategy state (e.g. `buildJlpToBaseRebalance`)
|
|
145
|
+
* should pass it here to avoid redundant fetches.
|
|
146
|
+
*/
|
|
147
|
+
prefetchedStrategyState?: Awaited<ReturnType<typeof fetchJlpStrategyState>>;
|
|
148
|
+
}): Promise<{
|
|
149
|
+
instructions: TransactionInstruction[];
|
|
150
|
+
addressLookupTables: AddressLookupTableAccount[];
|
|
151
|
+
/** Actual input amount from Jupiter quote (may differ from requested amount) */
|
|
152
|
+
quoteInAmount: bigint;
|
|
153
|
+
/**
|
|
154
|
+
* minOut encoded in the swap_jlp instruction data (= quote.otherAmountThreshold).
|
|
155
|
+
* Returned explicitly so callers do not need to locate and parse the swap_jlp ix
|
|
156
|
+
* inside the instruction array (whose index can shift when compute-budget ixs are
|
|
157
|
+
* prepended).
|
|
158
|
+
*/
|
|
159
|
+
minOut: bigint;
|
|
160
|
+
}>;
|
|
161
|
+
export interface RebalanceArgs {
|
|
162
|
+
connection: SolanaConnection;
|
|
163
|
+
manager: PublicKey;
|
|
164
|
+
baseMint: PublicKey;
|
|
165
|
+
vaultId: number;
|
|
166
|
+
direction: SwapDirection;
|
|
167
|
+
/** Base amount (BaseToJlp) or JLP amount (JlpToBase) */
|
|
168
|
+
amount: bigint;
|
|
169
|
+
slippageBps?: number;
|
|
170
|
+
/** Pass from frontend to skip RPC balance lookups */
|
|
171
|
+
liquidity?: {
|
|
172
|
+
strategyAtaBalance: bigint;
|
|
173
|
+
vaultAtaBalance: bigint;
|
|
174
|
+
};
|
|
175
|
+
jlpMint?: PublicKey;
|
|
176
|
+
tokenProgram?: PublicKey;
|
|
177
|
+
programId?: PublicKey;
|
|
178
|
+
pStvProgramId?: PublicKey;
|
|
179
|
+
}
|
|
180
|
+
export interface RebalanceResult {
|
|
181
|
+
/** Tx 1 instructions (deposit_to_strategy pre-fill, or empty) */
|
|
182
|
+
preInstructions: TransactionInstruction[];
|
|
183
|
+
/** Tx 2 instructions (swap_jlp, optionally + withdraw_from_strategy) */
|
|
184
|
+
instructions: TransactionInstruction[];
|
|
185
|
+
/** Tx 3 instructions (post-sweep route to Jupiter Lend, or empty) */
|
|
186
|
+
postInstructions: TransactionInstruction[];
|
|
187
|
+
addressLookupTables: AddressLookupTableAccount[];
|
|
188
|
+
routeDescription: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Build a complete rebalance transaction set for JLPD strategy.
|
|
192
|
+
*
|
|
193
|
+
* For BaseToJlp: auto-detects liquidity location and builds
|
|
194
|
+
* deposit_to_strategy + swap_jlp (tries 1 tx, falls back to 2 if needed).
|
|
195
|
+
*
|
|
196
|
+
* For JlpToBase: builds swap_jlp + withdraw_from_strategy in 1 tx.
|
|
197
|
+
*/
|
|
198
|
+
export declare function buildRebalanceTransaction(args: RebalanceArgs): Promise<RebalanceResult>;
|