@elemental-stv-core/sdk 0.2.0 → 0.3.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/elemental-lend/index.d.ts +2 -0
- package/dist/elemental-lend/index.d.ts.map +1 -1
- package/dist/elemental-lend/index.js +2 -0
- package/dist/elemental-lend/index.js.map +1 -1
- package/dist/elemental-lend/jupiter-lend.d.ts +4 -0
- package/dist/elemental-lend/jupiter-lend.d.ts.map +1 -1
- package/dist/elemental-lend/jupiter-lend.js +29 -1
- package/dist/elemental-lend/jupiter-lend.js.map +1 -1
- package/dist/elemental-lend/kamino-vault.d.ts +173 -0
- package/dist/elemental-lend/kamino-vault.d.ts.map +1 -0
- package/dist/elemental-lend/kamino-vault.js +460 -0
- package/dist/elemental-lend/kamino-vault.js.map +1 -0
- package/dist/elemental-lend/protocol-actions.d.ts +49 -0
- package/dist/elemental-lend/protocol-actions.d.ts.map +1 -0
- package/dist/elemental-lend/protocol-actions.js +228 -0
- package/dist/elemental-lend/protocol-actions.js.map +1 -0
- package/dist/jlpd-strategy/constants.d.ts +16 -0
- package/dist/jlpd-strategy/constants.d.ts.map +1 -1
- package/dist/jlpd-strategy/constants.js +28 -3
- package/dist/jlpd-strategy/constants.js.map +1 -1
- package/dist/jlpd-strategy/index.d.ts +3 -0
- package/dist/jlpd-strategy/index.d.ts.map +1 -1
- package/dist/jlpd-strategy/index.js +3 -0
- package/dist/jlpd-strategy/index.js.map +1 -1
- package/dist/jlpd-strategy/jlp-data.d.ts +73 -0
- package/dist/jlpd-strategy/jlp-data.d.ts.map +1 -0
- package/dist/jlpd-strategy/jlp-data.js +406 -0
- package/dist/jlpd-strategy/jlp-data.js.map +1 -0
- package/dist/jlpd-strategy/settle-yield.d.ts +54 -0
- package/dist/jlpd-strategy/settle-yield.d.ts.map +1 -0
- package/dist/jlpd-strategy/settle-yield.js +103 -0
- package/dist/jlpd-strategy/settle-yield.js.map +1 -0
- package/dist/jlpd-strategy/swap-jlp.d.ts +151 -0
- package/dist/jlpd-strategy/swap-jlp.d.ts.map +1 -0
- package/dist/jlpd-strategy/swap-jlp.js +429 -0
- package/dist/jlpd-strategy/swap-jlp.js.map +1 -0
- package/dist/p-stv-core/accounts.d.ts.map +1 -1
- package/dist/p-stv-core/accounts.js +14 -10
- package/dist/p-stv-core/accounts.js.map +1 -1
- package/dist/p-stv-core/constants.d.ts +3 -1
- package/dist/p-stv-core/constants.d.ts.map +1 -1
- package/dist/p-stv-core/constants.js +5 -3
- package/dist/p-stv-core/constants.js.map +1 -1
- package/dist/p-stv-core/index.d.ts +4 -0
- package/dist/p-stv-core/index.d.ts.map +1 -1
- package/dist/p-stv-core/index.js +4 -0
- package/dist/p-stv-core/index.js.map +1 -1
- package/dist/p-stv-core/instructions.d.ts +26 -0
- package/dist/p-stv-core/instructions.d.ts.map +1 -1
- package/dist/p-stv-core/instructions.js +37 -6
- package/dist/p-stv-core/instructions.js.map +1 -1
- package/dist/p-stv-core/prices.d.ts +21 -0
- package/dist/p-stv-core/prices.d.ts.map +1 -0
- package/dist/p-stv-core/prices.js +78 -0
- package/dist/p-stv-core/prices.js.map +1 -0
- package/dist/p-stv-core/remaining-accounts.d.ts +99 -0
- package/dist/p-stv-core/remaining-accounts.d.ts.map +1 -0
- package/dist/p-stv-core/remaining-accounts.js +262 -0
- package/dist/p-stv-core/remaining-accounts.js.map +1 -0
- package/dist/p-stv-core/send-tx.d.ts +56 -0
- package/dist/p-stv-core/send-tx.d.ts.map +1 -0
- package/dist/p-stv-core/send-tx.js +299 -0
- package/dist/p-stv-core/send-tx.js.map +1 -0
- package/dist/p-stv-core/sol-wrap.d.ts +35 -0
- package/dist/p-stv-core/sol-wrap.d.ts.map +1 -0
- package/dist/p-stv-core/sol-wrap.js +95 -0
- package/dist/p-stv-core/sol-wrap.js.map +1 -0
- package/dist/p-stv-core/types.d.ts +16 -1
- package/dist/p-stv-core/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remaining accounts builders for p-STV Core instructions.
|
|
3
|
+
*
|
|
4
|
+
* These functions build the complete `remainingAccounts` arrays needed for
|
|
5
|
+
* deposit, claim_withdraw, and process_epoch instructions, pulling all the
|
|
6
|
+
* lend + protocol AUM + strategy pair + auto-route/unroute account building
|
|
7
|
+
* logic out of the frontend and into the SDK.
|
|
8
|
+
*/
|
|
9
|
+
import { AccountMeta, Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
10
|
+
/**
|
|
11
|
+
* Minimal connection interface accepted by the context builders.
|
|
12
|
+
* Using a structural type avoids nominal type mismatches when the
|
|
13
|
+
* consumer has a different version of @solana/web3.js installed.
|
|
14
|
+
*/
|
|
15
|
+
export type SolanaConnection = Pick<Connection, "getAccountInfo" | "getMultipleAccountsInfo" | "getTokenAccountsByOwner" | "getSlot" | "getEpochInfo" | "getBlockTime">;
|
|
16
|
+
/** Minimal vault shape required by the context builders. */
|
|
17
|
+
export interface VaultInfo {
|
|
18
|
+
/** STV account address */
|
|
19
|
+
address: PublicKey;
|
|
20
|
+
/** Base token mint */
|
|
21
|
+
baseMint: PublicKey;
|
|
22
|
+
/** Lend program (PublicKey.default if not active) */
|
|
23
|
+
lendProgram: PublicKey;
|
|
24
|
+
/** Strategy program keys (10-element array) */
|
|
25
|
+
strategies: PublicKey[];
|
|
26
|
+
/** Number of active strategies */
|
|
27
|
+
strategyCount: number;
|
|
28
|
+
}
|
|
29
|
+
export interface DepositContext {
|
|
30
|
+
remainingAccounts: AccountMeta[];
|
|
31
|
+
protocolAumCount: number;
|
|
32
|
+
autoRouteCount: number;
|
|
33
|
+
preInstructions: TransactionInstruction[];
|
|
34
|
+
}
|
|
35
|
+
export interface ClaimWithdrawContext {
|
|
36
|
+
remainingAccounts: AccountMeta[];
|
|
37
|
+
autoUnrouteCount: number;
|
|
38
|
+
/**
|
|
39
|
+
* Pre-instructions to add before the claim_withdraw ix.
|
|
40
|
+
* Currently always empty — see DepositContext.preInstructions.
|
|
41
|
+
*/
|
|
42
|
+
preInstructions: TransactionInstruction[];
|
|
43
|
+
}
|
|
44
|
+
export interface DepositToStrategyContext {
|
|
45
|
+
remainingAccounts: AccountMeta[];
|
|
46
|
+
autoUnrouteCount: number;
|
|
47
|
+
preInstructions: TransactionInstruction[];
|
|
48
|
+
}
|
|
49
|
+
export interface ProcessEpochContext {
|
|
50
|
+
remainingAccounts: AccountMeta[];
|
|
51
|
+
protocolAumCount: number;
|
|
52
|
+
/**
|
|
53
|
+
* Pre-instructions to add before the process_epoch ix.
|
|
54
|
+
* Currently always empty — see DepositContext.preInstructions.
|
|
55
|
+
*/
|
|
56
|
+
preInstructions: TransactionInstruction[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* Build the complete remaining_accounts for a deposit instruction.
|
|
62
|
+
*
|
|
63
|
+
* Layout: [4 lend, N protocol_aum, M*2+P strategy_pairs, K auto_route]
|
|
64
|
+
*
|
|
65
|
+
* - If lend is active, derives lend PDAs and fetches protocol AUM accounts
|
|
66
|
+
* - Builds strategy pair accounts for each active strategy
|
|
67
|
+
* - If USDC + Jupiter Lend registered, appends auto-route accounts
|
|
68
|
+
* - Checks for stale kVaults (returned in preInstructions once invest ix is available)
|
|
69
|
+
*/
|
|
70
|
+
export declare function buildDepositContext(connection: SolanaConnection, vault: VaultInfo, payer?: PublicKey): Promise<DepositContext>;
|
|
71
|
+
/**
|
|
72
|
+
* Build the complete remaining_accounts for a claim_withdraw instruction.
|
|
73
|
+
*
|
|
74
|
+
* Layout: [4 lend, K auto_unroute]
|
|
75
|
+
*
|
|
76
|
+
* - If lend is active, derives lend PDAs
|
|
77
|
+
* - If USDC + Jupiter Lend, appends auto-unroute accounts
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildClaimWithdrawContext(connection: SolanaConnection, vault: VaultInfo): Promise<ClaimWithdrawContext>;
|
|
80
|
+
/**
|
|
81
|
+
* Build the complete remaining_accounts for a deposit_to_strategy instruction.
|
|
82
|
+
*
|
|
83
|
+
* Layout: [4 lend, K auto_unroute]
|
|
84
|
+
*
|
|
85
|
+
* Same as claim_withdraw: if lend is active, derives lend PDAs.
|
|
86
|
+
* If USDC + Jupiter Lend, appends auto-unroute accounts for unsweep.
|
|
87
|
+
*
|
|
88
|
+
* Note: no Kamino invest pre-instructions here — deposit_to_strategy unsweeps
|
|
89
|
+
* from the active protocol (Jupiter Lend for USDC), not Kamino.
|
|
90
|
+
*/
|
|
91
|
+
export declare function buildDepositToStrategyContext(connection: SolanaConnection, vault: VaultInfo): Promise<DepositToStrategyContext>;
|
|
92
|
+
/**
|
|
93
|
+
* Build the complete remaining_accounts for a process_epoch instruction.
|
|
94
|
+
*
|
|
95
|
+
* @param phase - 'lockPps': needs lend + protocol AUM + strategy pairs for NAV.
|
|
96
|
+
* 'advance': empty remaining_accounts.
|
|
97
|
+
*/
|
|
98
|
+
export declare function buildProcessEpochContext(connection: SolanaConnection, vault: VaultInfo, phase: "lockPps" | "advance"): Promise<ProcessEpochContext>;
|
|
99
|
+
//# sourceMappingURL=remaining-accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remaining-accounts.d.ts","sourceRoot":"","sources":["../../src/p-stv-core/remaining-accounts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,WAAW,EACX,UAAU,EACV,SAAS,EACT,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAoBzB;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,UAAU,EAC1C,gBAAgB,GAChB,yBAAyB,GACzB,yBAAyB,GACzB,SAAS,GACT,cAAc,GACd,cAAc,CACjB,CAAC;AAMF,4DAA4D;AAC5D,MAAM,WAAW,SAAS;IACxB,0BAA0B;IAC1B,OAAO,EAAE,SAAS,CAAC;IACnB,sBAAsB;IACtB,QAAQ,EAAE,SAAS,C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AACH,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,GAAG,SAAS,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CAoC9B"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Remaining accounts builders for p-STV Core instructions.
|
|
4
|
+
*
|
|
5
|
+
* These functions build the complete `remainingAccounts` arrays needed for
|
|
6
|
+
* deposit, claim_withdraw, and process_epoch instructions, pulling all the
|
|
7
|
+
* lend + protocol AUM + strategy pair + auto-route/unroute account building
|
|
8
|
+
* logic out of the frontend and into the SDK.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.buildDepositContext = buildDepositContext;
|
|
12
|
+
exports.buildClaimWithdrawContext = buildClaimWithdrawContext;
|
|
13
|
+
exports.buildDepositToStrategyContext = buildDepositToStrategyContext;
|
|
14
|
+
exports.buildProcessEpochContext = buildProcessEpochContext;
|
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
16
|
+
const pda_1 = require("../elemental-lend/pda");
|
|
17
|
+
const accounts_1 = require("../elemental-lend/accounts");
|
|
18
|
+
const jupiter_lend_1 = require("../elemental-lend/jupiter-lend");
|
|
19
|
+
const kamino_vault_1 = require("../elemental-lend/kamino-vault");
|
|
20
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Helpers
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
const DEFAULT_PUBKEY = web3_js_1.PublicKey.default;
|
|
25
|
+
const TOKEN_PROGRAM = new web3_js_1.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
26
|
+
const USDC_MINT = new web3_js_1.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
27
|
+
const STRATEGY_STATE_SEED = Buffer.from("strategy_state");
|
|
28
|
+
const POSITION_SEED = Buffer.from("position");
|
|
29
|
+
function isDefault(pubkey) {
|
|
30
|
+
return pubkey.equals(DEFAULT_PUBKEY);
|
|
31
|
+
}
|
|
32
|
+
/** Derive the ATA address (same logic as @solana/spl-token getAssociatedTokenAddressSync) */
|
|
33
|
+
function findAta(mint, owner, tokenProgram) {
|
|
34
|
+
const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
35
|
+
return ata;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build the 4 fixed lend accounts: [lendProgram, lendStrategyState, lendPosition, lendBaseAta]
|
|
39
|
+
*/
|
|
40
|
+
function buildFixedLendAccounts(lendProgram, baseMint, stvAddress) {
|
|
41
|
+
const [lendStrategyState] = (0, pda_1.findStrategyStatePda)(baseMint, lendProgram);
|
|
42
|
+
const [lendPosition] = (0, pda_1.findStvPositionPda)(stvAddress, lendProgram);
|
|
43
|
+
const lendBaseAta = findAta(baseMint, lendStrategyState, TOKEN_PROGRAM);
|
|
44
|
+
return {
|
|
45
|
+
lendStrategyState,
|
|
46
|
+
accounts: [
|
|
47
|
+
{ pubkey: lendProgram, isSigner: false, isWritable: false },
|
|
48
|
+
{ pubkey: lendStrategyState, isSigner: false, isWritable: true },
|
|
49
|
+
{ pubkey: lendPosition, isSigner: false, isWritable: true },
|
|
50
|
+
{ pubkey: lendBaseAta, isSigner: false, isWritable: true },
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Build strategy pair accounts for NAV computation.
|
|
56
|
+
* For each active strategy: [strategy_state, stv_position, strategy_program (deduplicated)]
|
|
57
|
+
*/
|
|
58
|
+
function buildStrategyPairAccounts(vault) {
|
|
59
|
+
const accounts = [];
|
|
60
|
+
if (vault.strategyCount === 0)
|
|
61
|
+
return accounts;
|
|
62
|
+
for (let i = 0; i < vault.strategyCount; i++) {
|
|
63
|
+
const strategyProgram = vault.strategies[i];
|
|
64
|
+
if (isDefault(strategyProgram))
|
|
65
|
+
continue;
|
|
66
|
+
const [stratState] = web3_js_1.PublicKey.findProgramAddressSync([STRATEGY_STATE_SEED, vault.baseMint.toBuffer()], strategyProgram);
|
|
67
|
+
const [stratPos] = web3_js_1.PublicKey.findProgramAddressSync([POSITION_SEED, vault.address.toBuffer()], strategyProgram);
|
|
68
|
+
accounts.push({ pubkey: stratState, isSigner: false, isWritable: true }, { pubkey: stratPos, isSigner: false, isWritable: true });
|
|
69
|
+
// Note: strategy program is NOT added to remaining_accounts.
|
|
70
|
+
// The on-chain code expects exactly 2 accounts per strategy (state + position).
|
|
71
|
+
// The strategy program resolves from the transaction's account list via invoke_signed.
|
|
72
|
+
}
|
|
73
|
+
return accounts;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
*/
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Context Builders
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
/**
|
|
81
|
+
* Build the complete remaining_accounts for a deposit instruction.
|
|
82
|
+
*
|
|
83
|
+
* Layout: [4 lend, N protocol_aum, M*2+P strategy_pairs, K auto_route]
|
|
84
|
+
*
|
|
85
|
+
* - If lend is active, derives lend PDAs and fetches protocol AUM accounts
|
|
86
|
+
* - Builds strategy pair accounts for each active strategy
|
|
87
|
+
* - If USDC + Jupiter Lend registered, appends auto-route accounts
|
|
88
|
+
* - Checks for stale kVaults (returned in preInstructions once invest ix is available)
|
|
89
|
+
*/
|
|
90
|
+
async function buildDepositContext(connection, vault, payer) {
|
|
91
|
+
const remainingAccounts = [];
|
|
92
|
+
const preInstructions = [];
|
|
93
|
+
let protocolAumCount = 0;
|
|
94
|
+
// 1. Lend accounts (if active)
|
|
95
|
+
if (!isDefault(vault.lendProgram)) {
|
|
96
|
+
const { accounts: lendAccounts, lendStrategyState } = buildFixedLendAccounts(vault.lendProgram, vault.baseMint, vault.address);
|
|
97
|
+
remainingAccounts.push(...lendAccounts);
|
|
98
|
+
// Protocol AUM accounts
|
|
99
|
+
const conn = connection;
|
|
100
|
+
try {
|
|
101
|
+
const lendState = await (0, accounts_1.fetchLendStrategyState)(conn, vault.baseMint, vault.lendProgram);
|
|
102
|
+
const protocolAccounts = await (0, accounts_1.buildProtocolAccountsForAum)(conn, lendState, lendStrategyState, TOKEN_PROGRAM);
|
|
103
|
+
protocolAumCount = protocolAccounts.length;
|
|
104
|
+
remainingAccounts.push(...protocolAccounts);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// If strategy state not found, skip protocol accounts
|
|
108
|
+
}
|
|
109
|
+
// Check kVault staleness — prepend invest ix if stale
|
|
110
|
+
try {
|
|
111
|
+
const conn = connection;
|
|
112
|
+
const lendState = await (0, accounts_1.fetchLendStrategyState)(conn, vault.baseMint, vault.lendProgram).catch(() => null);
|
|
113
|
+
if (lendState) {
|
|
114
|
+
const protocolKeys = lendState.protocols
|
|
115
|
+
.filter((p) => !isDefault(p));
|
|
116
|
+
// Need a payer for the invest ix — will be set by the caller
|
|
117
|
+
// Use PublicKey.default as placeholder; the caller replaces it
|
|
118
|
+
const investIxs = payer ? await (0, kamino_vault_1.buildKaminoInvestIxsIfStale)(conn, payer, vault.baseMint, protocolKeys) : [];
|
|
119
|
+
preInstructions.push(...investIxs);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Skip if staleness check fails
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// 2. Strategy pair accounts (2 per strategy: state + position)
|
|
127
|
+
const strategyAccounts = buildStrategyPairAccounts(vault);
|
|
128
|
+
remainingAccounts.push(...strategyAccounts);
|
|
129
|
+
// 3. Auto-route to Jupiter Lend (for any asset with a configured pool)
|
|
130
|
+
let autoRouteCount = 0;
|
|
131
|
+
const jupPool = jupiter_lend_1.JUP_LEND_POOLS[vault.baseMint.toBase58()];
|
|
132
|
+
if (!isDefault(vault.lendProgram) && jupPool) {
|
|
133
|
+
try {
|
|
134
|
+
const [lendSS] = (0, pda_1.findStrategyStatePda)(vault.baseMint, vault.lendProgram);
|
|
135
|
+
const strategyBaseAta = findAta(vault.baseMint, lendSS, TOKEN_PROGRAM);
|
|
136
|
+
const strategyFtokenAta = findAta(jupPool.fTokenMint, lendSS, TOKEN_PROGRAM);
|
|
137
|
+
const autoRouteAccounts = (0, jupiter_lend_1.buildJupLendAutoRouteAccounts)(jupPool, lendSS, strategyBaseAta, strategyFtokenAta);
|
|
138
|
+
autoRouteCount = autoRouteAccounts.length;
|
|
139
|
+
for (const acc of autoRouteAccounts) {
|
|
140
|
+
remainingAccounts.push({ ...acc, isSigner: false });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// Skip auto-route if account resolution fails
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// 4. Strategy programs (after auto-route, for CPI resolution)
|
|
148
|
+
// These must be in the transaction but are NOT counted as auto-route or strategy pairs.
|
|
149
|
+
// The on-chain code uses auto_route_count to bound the auto-route slice.
|
|
150
|
+
const seenPrograms = new Set();
|
|
151
|
+
for (let i = 0; i < vault.strategyCount; i++) {
|
|
152
|
+
const prog = vault.strategies[i];
|
|
153
|
+
if (isDefault(prog))
|
|
154
|
+
continue;
|
|
155
|
+
const key = prog.toBase58();
|
|
156
|
+
if (!seenPrograms.has(key)) {
|
|
157
|
+
seenPrograms.add(key);
|
|
158
|
+
remainingAccounts.push({ pubkey: prog, isSigner: false, isWritable: false });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return { remainingAccounts, protocolAumCount, autoRouteCount, preInstructions };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Build the complete remaining_accounts for a claim_withdraw instruction.
|
|
165
|
+
*
|
|
166
|
+
* Layout: [4 lend, K auto_unroute]
|
|
167
|
+
*
|
|
168
|
+
* - If lend is active, derives lend PDAs
|
|
169
|
+
* - If USDC + Jupiter Lend, appends auto-unroute accounts
|
|
170
|
+
*/
|
|
171
|
+
async function buildClaimWithdrawContext(connection, vault) {
|
|
172
|
+
const remainingAccounts = [];
|
|
173
|
+
const preInstructions = [];
|
|
174
|
+
let autoUnrouteCount = 0;
|
|
175
|
+
if (!isDefault(vault.lendProgram)) {
|
|
176
|
+
const { accounts: lendAccounts, lendStrategyState } = buildFixedLendAccounts(vault.lendProgram, vault.baseMint, vault.address);
|
|
177
|
+
remainingAccounts.push(...lendAccounts);
|
|
178
|
+
// Auto-unroute from Jupiter Lend (for any asset with a configured pool)
|
|
179
|
+
const jupPoolForUnroute = jupiter_lend_1.JUP_LEND_POOLS[vault.baseMint.toBase58()];
|
|
180
|
+
if (jupPoolForUnroute) {
|
|
181
|
+
try {
|
|
182
|
+
const lendBaseAta = findAta(vault.baseMint, lendStrategyState, TOKEN_PROGRAM);
|
|
183
|
+
const strategyFtokenAta = findAta(jupPoolForUnroute.fTokenMint, lendStrategyState, TOKEN_PROGRAM);
|
|
184
|
+
const autoUnrouteAccounts = (0, jupiter_lend_1.buildJupLendAutoUnrouteAccounts)(jupPoolForUnroute, lendStrategyState, strategyFtokenAta, lendBaseAta);
|
|
185
|
+
autoUnrouteCount = autoUnrouteAccounts.length;
|
|
186
|
+
remainingAccounts.push(...autoUnrouteAccounts.map(a => ({ ...a, isSigner: false })));
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
// Skip auto-unroute if resolution fails
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { remainingAccounts, autoUnrouteCount, preInstructions };
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Build the complete remaining_accounts for a deposit_to_strategy instruction.
|
|
197
|
+
*
|
|
198
|
+
* Layout: [4 lend, K auto_unroute]
|
|
199
|
+
*
|
|
200
|
+
* Same as claim_withdraw: if lend is active, derives lend PDAs.
|
|
201
|
+
* If USDC + Jupiter Lend, appends auto-unroute accounts for unsweep.
|
|
202
|
+
*
|
|
203
|
+
* Note: no Kamino invest pre-instructions here — deposit_to_strategy unsweeps
|
|
204
|
+
* from the active protocol (Jupiter Lend for USDC), not Kamino.
|
|
205
|
+
*/
|
|
206
|
+
async function buildDepositToStrategyContext(connection, vault) {
|
|
207
|
+
const remainingAccounts = [];
|
|
208
|
+
let autoUnrouteCount = 0;
|
|
209
|
+
if (!isDefault(vault.lendProgram)) {
|
|
210
|
+
const { accounts: lendAccounts, lendStrategyState } = buildFixedLendAccounts(vault.lendProgram, vault.baseMint, vault.address);
|
|
211
|
+
remainingAccounts.push(...lendAccounts);
|
|
212
|
+
// Auto-unroute from Jupiter Lend (for any asset with a configured pool)
|
|
213
|
+
const jupPoolForUnroute = jupiter_lend_1.JUP_LEND_POOLS[vault.baseMint.toBase58()];
|
|
214
|
+
if (jupPoolForUnroute) {
|
|
215
|
+
try {
|
|
216
|
+
const lendBaseAta = findAta(vault.baseMint, lendStrategyState, TOKEN_PROGRAM);
|
|
217
|
+
const strategyFtokenAta = findAta(jupPoolForUnroute.fTokenMint, lendStrategyState, TOKEN_PROGRAM);
|
|
218
|
+
const autoUnrouteAccounts = (0, jupiter_lend_1.buildJupLendAutoUnrouteAccounts)(jupPoolForUnroute, lendStrategyState, strategyFtokenAta, lendBaseAta);
|
|
219
|
+
autoUnrouteCount = autoUnrouteAccounts.length;
|
|
220
|
+
remainingAccounts.push(...autoUnrouteAccounts.map(a => ({ ...a, isSigner: false })));
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// Skip auto-unroute if resolution fails
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return { remainingAccounts, autoUnrouteCount, preInstructions: [] };
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Build the complete remaining_accounts for a process_epoch instruction.
|
|
231
|
+
*
|
|
232
|
+
* @param phase - 'lockPps': needs lend + protocol AUM + strategy pairs for NAV.
|
|
233
|
+
* 'advance': empty remaining_accounts.
|
|
234
|
+
*/
|
|
235
|
+
async function buildProcessEpochContext(connection, vault, phase) {
|
|
236
|
+
if (phase === "advance") {
|
|
237
|
+
return { remainingAccounts: [], protocolAumCount: 0, preInstructions: [] };
|
|
238
|
+
}
|
|
239
|
+
// lockPps: same as deposit (lend + protocol AUM + strategy pairs) but without auto-route
|
|
240
|
+
const remainingAccounts = [];
|
|
241
|
+
const preInstructions = [];
|
|
242
|
+
let protocolAumCount = 0;
|
|
243
|
+
if (!isDefault(vault.lendProgram)) {
|
|
244
|
+
const { accounts: lendAccounts, lendStrategyState } = buildFixedLendAccounts(vault.lendProgram, vault.baseMint, vault.address);
|
|
245
|
+
remainingAccounts.push(...lendAccounts);
|
|
246
|
+
const conn = connection;
|
|
247
|
+
try {
|
|
248
|
+
const lendState = await (0, accounts_1.fetchLendStrategyState)(conn, vault.baseMint, vault.lendProgram);
|
|
249
|
+
const protocolAccounts = await (0, accounts_1.buildProtocolAccountsForAum)(conn, lendState, lendStrategyState, TOKEN_PROGRAM);
|
|
250
|
+
protocolAumCount = protocolAccounts.length;
|
|
251
|
+
remainingAccounts.push(...protocolAccounts);
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
// Skip protocol accounts if unavailable
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// Strategy pairs for NAV
|
|
258
|
+
const strategyAccounts = buildStrategyPairAccounts(vault);
|
|
259
|
+
remainingAccounts.push(...strategyAccounts);
|
|
260
|
+
return { remainingAccounts, protocolAumCount, preInstructions };
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=remaining-accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remaining-accounts.js","sourceRoot":"","sources":["../../src/p-stv-core/remaining-accounts.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AA6LH,kDA0FC;AAUD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B,CAAC,KAAK,CAAC,CAAC;IAC1D,iBAAiB,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC;IAE5C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart transaction builder and sender.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Simulates to get exact compute units, adds 10% buffer
|
|
6
|
+
* - Fetches priority fee from Helius (medium tier)
|
|
7
|
+
* - Pre-checks size to decide legacy vs versioned tx with LUT (no double-sign)
|
|
8
|
+
* - Uses lastValidBlockHeight for reliable confirmation
|
|
9
|
+
* - Parallel fetches where possible
|
|
10
|
+
*/
|
|
11
|
+
import { AddressLookupTableAccount, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
12
|
+
/** @deprecated Use DEFAULT_LUT_ADDRESSES instead */
|
|
13
|
+
export declare const DEFAULT_LUT_ADDRESS: PublicKey;
|
|
14
|
+
/**
|
|
15
|
+
* Default LUTs for Elemental Vaults.
|
|
16
|
+
* These are fetched in parallel and merged for every versioned transaction.
|
|
17
|
+
*
|
|
18
|
+
* After creating new LUTs with `scripts/create-luts.ts --create`,
|
|
19
|
+
* replace these placeholder addresses with the real ones.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_LUT_ADDRESSES: {
|
|
22
|
+
/** Elemental Lend (Kamino + Jupiter Lend + protocol infra) */
|
|
23
|
+
lend: PublicKey;
|
|
24
|
+
/** p-STV Core (vaults, evMints, vault ATAs, config) */
|
|
25
|
+
stv: PublicKey;
|
|
26
|
+
/** JLPD Strategy (config, strategy states, positions, JLP, oracles) */
|
|
27
|
+
jlpd: PublicKey;
|
|
28
|
+
};
|
|
29
|
+
export type SignTransactionFn = (tx: any) => Promise<any>;
|
|
30
|
+
export type SmartTxConnection = any;
|
|
31
|
+
export interface SmartTxOptions {
|
|
32
|
+
/** Single LUT address (deprecated — use additionalLuts or DEFAULT_LUT_ADDRESSES) */
|
|
33
|
+
lutAddress?: PublicKey;
|
|
34
|
+
/** Additional pre-fetched ALTs to merge (e.g. Jupiter ALTs) */
|
|
35
|
+
additionalLuts?: AddressLookupTableAccount[];
|
|
36
|
+
/** Skip priority fee fetch (use 0) */
|
|
37
|
+
noPriorityFee?: boolean;
|
|
38
|
+
/** Custom compute unit limit (skips simulation) */
|
|
39
|
+
computeUnits?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build, simulate, and send a transaction with optimal compute budget.
|
|
43
|
+
*
|
|
44
|
+
* 1. Fetches blockhash + LUT + priority fee in parallel
|
|
45
|
+
* 2. Pre-checks serialized size to choose legacy vs versioned
|
|
46
|
+
* 3. Simulates to get exact CU, adds 10% buffer
|
|
47
|
+
* 4. Prepends ComputeBudget instructions
|
|
48
|
+
* 5. Signs and sends with lastValidBlockHeight confirmation
|
|
49
|
+
*/
|
|
50
|
+
export declare function sendSmartTx(connection: SmartTxConnection, instructions: TransactionInstruction[], payer: PublicKey, signTransaction: SignTransactionFn, optionsOrLut?: PublicKey | SmartTxOptions): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Simulate a transaction without signing. Returns true if simulation succeeds.
|
|
53
|
+
* Use this to gate combined-tx attempts before asking the wallet to sign.
|
|
54
|
+
*/
|
|
55
|
+
export declare function simulateSmartTx(connection: SmartTxConnection, instructions: TransactionInstruction[], payer: PublicKey, optionsOrLut?: PublicKey | SmartTxOptions): Promise<boolean>;
|
|
56
|
+
//# sourceMappingURL=send-tx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-tx.d.ts","sourceRoot":"","sources":["../../src/p-stv-core/send-tx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,yBAAyB,EAGzB,SAAS,EAET,sBAAsB,EAGvB,MAAM,iBAAiB,CAAC;AAEzB,oDAAoD;AACpD,e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