@elmntl/jlpd-sdk 0.2.0 → 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 -4199
- package/dist/index.js +37 -5187
- 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 -4199
- package/dist/index.mjs +0 -5090
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* p-STV Core Address Lookup Table helpers.
|
|
3
|
+
*
|
|
4
|
+
* Packages the STATIC (per-program, not per-tx) p-stv-core accounts into a LUT
|
|
5
|
+
* so versioned transactions can compress them into a single 1-byte index.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* // Owner flow (one-time):
|
|
9
|
+
* const [createIx, lutAddress] = AddressLookupTableProgram.createLookupTable({...});
|
|
10
|
+
* const extendIxs = buildPstvCoreLutExtendIxs(payer, lutAddress);
|
|
11
|
+
* // send createIx + extendIxs
|
|
12
|
+
*
|
|
13
|
+
* // Consumer flow (every tx):
|
|
14
|
+
* const lutAccount = await resolvePstvCoreLut(connection, lutAddress);
|
|
15
|
+
* const msg = new TransactionMessage({...}).compileToV0Message([lutAccount]);
|
|
16
|
+
*
|
|
17
|
+
* NOTE: Only program IDs, the GlobalConfig PDA, and token/ATA/compute-budget
|
|
18
|
+
* program IDs. Per-vault PDAs (stv, evMint, vaultAta, withdrawRequest,
|
|
19
|
+
* managerRole) and strategy/lend state live in separate LUTs.
|
|
20
|
+
*/
|
|
21
|
+
import { AddressLookupTableAccount, Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
22
|
+
/**
|
|
23
|
+
* Static p-stv-core accounts for the shared LUT. Order is deterministic so
|
|
24
|
+
* callers can cross-check against an on-chain LUT.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getPstvCoreLutAddresses(programId?: PublicKey): PublicKey[];
|
|
27
|
+
/**
|
|
28
|
+
* Build `extendLookupTable` ixs pushing every static p-stv-core account
|
|
29
|
+
* into `lutAddress`. Chunks at `MAX_ADDRS_PER_EXTEND` for safety.
|
|
30
|
+
*
|
|
31
|
+
* @param payer Wallet funding + authority of the LUT.
|
|
32
|
+
* @param lutAddress LUT to extend (must be created via
|
|
33
|
+
* `AddressLookupTableProgram.createLookupTable` first).
|
|
34
|
+
* @param programId Override for p-stv-core program ID (defaults to mainnet).
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildPstvCoreLutExtendIxs(payer: PublicKey, lutAddress: PublicKey, programId?: PublicKey): TransactionInstruction[];
|
|
37
|
+
/**
|
|
38
|
+
* Fetch an `AddressLookupTableAccount` by address for use in
|
|
39
|
+
* `TransactionMessage.compileToV0Message([lutAccount])`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolvePstvCoreLut(connection: Pick<Connection, "getAddressLookupTable">, lutAddress: PublicKey): Promise<AddressLookupTableAccount>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* p-STV Core Address Lookup Table helpers.
|
|
4
|
+
*
|
|
5
|
+
* Packages the STATIC (per-program, not per-tx) p-stv-core accounts into a LUT
|
|
6
|
+
* so versioned transactions can compress them into a single 1-byte index.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* // Owner flow (one-time):
|
|
10
|
+
* const [createIx, lutAddress] = AddressLookupTableProgram.createLookupTable({...});
|
|
11
|
+
* const extendIxs = buildPstvCoreLutExtendIxs(payer, lutAddress);
|
|
12
|
+
* // send createIx + extendIxs
|
|
13
|
+
*
|
|
14
|
+
* // Consumer flow (every tx):
|
|
15
|
+
* const lutAccount = await resolvePstvCoreLut(connection, lutAddress);
|
|
16
|
+
* const msg = new TransactionMessage({...}).compileToV0Message([lutAccount]);
|
|
17
|
+
*
|
|
18
|
+
* NOTE: Only program IDs, the GlobalConfig PDA, and token/ATA/compute-budget
|
|
19
|
+
* program IDs. Per-vault PDAs (stv, evMint, vaultAta, withdrawRequest,
|
|
20
|
+
* managerRole) and strategy/lend state live in separate LUTs.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.getPstvCoreLutAddresses = getPstvCoreLutAddresses;
|
|
24
|
+
exports.buildPstvCoreLutExtendIxs = buildPstvCoreLutExtendIxs;
|
|
25
|
+
exports.resolvePstvCoreLut = resolvePstvCoreLut;
|
|
26
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
27
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
28
|
+
const constants_1 = require("./constants");
|
|
29
|
+
const pda_1 = require("./pda");
|
|
30
|
+
/** Max addresses per `extendLookupTable` ix (Solana runtime limit). */
|
|
31
|
+
const MAX_ADDRS_PER_EXTEND = 20;
|
|
32
|
+
/**
|
|
33
|
+
* Static p-stv-core accounts for the shared LUT. Order is deterministic so
|
|
34
|
+
* callers can cross-check against an on-chain LUT.
|
|
35
|
+
*/
|
|
36
|
+
function getPstvCoreLutAddresses(programId = constants_1.PROGRAM_ID) {
|
|
37
|
+
const [configPda] = (0, pda_1.findConfigPda)(programId);
|
|
38
|
+
return [
|
|
39
|
+
programId,
|
|
40
|
+
web3_js_1.SystemProgram.programId,
|
|
41
|
+
spl_token_1.TOKEN_PROGRAM_ID,
|
|
42
|
+
spl_token_1.TOKEN_2022_PROGRAM_ID,
|
|
43
|
+
spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
44
|
+
web3_js_1.ComputeBudgetProgram.programId,
|
|
45
|
+
configPda,
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build `extendLookupTable` ixs pushing every static p-stv-core account
|
|
50
|
+
* into `lutAddress`. Chunks at `MAX_ADDRS_PER_EXTEND` for safety.
|
|
51
|
+
*
|
|
52
|
+
* @param payer Wallet funding + authority of the LUT.
|
|
53
|
+
* @param lutAddress LUT to extend (must be created via
|
|
54
|
+
* `AddressLookupTableProgram.createLookupTable` first).
|
|
55
|
+
* @param programId Override for p-stv-core program ID (defaults to mainnet).
|
|
56
|
+
*/
|
|
57
|
+
function buildPstvCoreLutExtendIxs(payer, lutAddress, programId = constants_1.PROGRAM_ID) {
|
|
58
|
+
const addresses = getPstvCoreLutAddresses(programId);
|
|
59
|
+
const ixs = [];
|
|
60
|
+
for (let i = 0; i < addresses.length; i += MAX_ADDRS_PER_EXTEND) {
|
|
61
|
+
const chunk = addresses.slice(i, i + MAX_ADDRS_PER_EXTEND);
|
|
62
|
+
ixs.push(web3_js_1.AddressLookupTableProgram.extendLookupTable({
|
|
63
|
+
payer,
|
|
64
|
+
authority: payer,
|
|
65
|
+
lookupTable: lutAddress,
|
|
66
|
+
addresses: chunk,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
return ixs;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Fetch an `AddressLookupTableAccount` by address for use in
|
|
73
|
+
* `TransactionMessage.compileToV0Message([lutAccount])`.
|
|
74
|
+
*/
|
|
75
|
+
async function resolvePstvCoreLut(connection, lutAddress) {
|
|
76
|
+
const { value } = await connection.getAddressLookupTable(lutAddress);
|
|
77
|
+
if (!value) {
|
|
78
|
+
throw new Error(`p-stv-core LUT not found at ${lutAddress.toBase58()} — create it first with buildPstvCoreLutExtendIxs`);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
export declare function findConfigPda(programId?: PublicKey): [PublicKey, number];
|
|
4
|
+
export declare function findStvPda(vaultId: number | BN, programId?: PublicKey): [PublicKey, number];
|
|
5
|
+
export declare function findEvMintPda(vaultId: number | BN, programId?: PublicKey): [PublicKey, number];
|
|
6
|
+
export declare function findWithdrawRequestPda(stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): [PublicKey, number];
|
|
7
|
+
/**
|
|
8
|
+
* Derive the migrate-kind WithdrawRequest PDA.
|
|
9
|
+
* Seeds: `["migrate_request", stv, user, epoch_id_le4]`.
|
|
10
|
+
*
|
|
11
|
+
* Distinct prefix from `findWithdrawRequestPda` so a user can hold both a
|
|
12
|
+
* withdraw and a migrate request for the same (stv, user, epoch) without
|
|
13
|
+
* a PDA collision. `stv` is the SOURCE STV; `epochId` is the source STV's
|
|
14
|
+
* `currentEpochId` at request time.
|
|
15
|
+
*/
|
|
16
|
+
export declare function findMigrateRequestPda(stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): [PublicKey, number];
|
|
17
|
+
/**
|
|
18
|
+
* Derive the per-user delayed deposit request PDA.
|
|
19
|
+
* Seeds: `["delayed_deposit", stv, user, epoch_id_le4]`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function findDelayedDepositRequestPda(stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): [PublicKey, number];
|
|
22
|
+
/**
|
|
23
|
+
* Derive the per-STV `ManagerRole` PDA for p-STV Core.
|
|
24
|
+
* Seeds: `["manager", stv, manager]`.
|
|
25
|
+
*
|
|
26
|
+
* Note the per-program prefix on the name: each Elemental program has its
|
|
27
|
+
* own `ManagerRole` PDA scoped to a different anchor account
|
|
28
|
+
* (`elemental-lend` → strategy_state, `jlpd-strategy` → config).
|
|
29
|
+
*/
|
|
30
|
+
export declare function findStvManagerRolePda(stv: PublicKey, manager: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findConfigPda = findConfigPda;
|
|
7
|
+
exports.findStvPda = findStvPda;
|
|
8
|
+
exports.findEvMintPda = findEvMintPda;
|
|
9
|
+
exports.findWithdrawRequestPda = findWithdrawRequestPda;
|
|
10
|
+
exports.findMigrateRequestPda = findMigrateRequestPda;
|
|
11
|
+
exports.findDelayedDepositRequestPda = findDelayedDepositRequestPda;
|
|
12
|
+
exports.findStvManagerRolePda = findStvManagerRolePda;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
function findConfigPda(programId = constants_1.PROGRAM_ID) {
|
|
17
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.CONFIG_SEED], programId);
|
|
18
|
+
}
|
|
19
|
+
function findStvPda(vaultId, programId = constants_1.PROGRAM_ID) {
|
|
20
|
+
const id = new bn_js_1.default(vaultId);
|
|
21
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.STV_SEED, id.toArrayLike(Buffer, "le", 8)], programId);
|
|
22
|
+
}
|
|
23
|
+
function findEvMintPda(vaultId, programId = constants_1.PROGRAM_ID) {
|
|
24
|
+
const id = new bn_js_1.default(vaultId);
|
|
25
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.EV_MINT_SEED, id.toArrayLike(Buffer, "le", 8)], programId);
|
|
26
|
+
}
|
|
27
|
+
function findWithdrawRequestPda(stv, user, epochId, programId = constants_1.PROGRAM_ID) {
|
|
28
|
+
const epochBuf = Buffer.alloc(4);
|
|
29
|
+
epochBuf.writeUInt32LE(epochId, 0);
|
|
30
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.WITHDRAW_REQUEST_SEED, stv.toBuffer(), user.toBuffer(), epochBuf], programId);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Derive the migrate-kind WithdrawRequest PDA.
|
|
34
|
+
* Seeds: `["migrate_request", stv, user, epoch_id_le4]`.
|
|
35
|
+
*
|
|
36
|
+
* Distinct prefix from `findWithdrawRequestPda` so a user can hold both a
|
|
37
|
+
* withdraw and a migrate request for the same (stv, user, epoch) without
|
|
38
|
+
* a PDA collision. `stv` is the SOURCE STV; `epochId` is the source STV's
|
|
39
|
+
* `currentEpochId` at request time.
|
|
40
|
+
*/
|
|
41
|
+
function findMigrateRequestPda(stv, user, epochId, programId = constants_1.PROGRAM_ID) {
|
|
42
|
+
const epochBuf = Buffer.alloc(4);
|
|
43
|
+
epochBuf.writeUInt32LE(epochId, 0);
|
|
44
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.MIGRATE_REQUEST_SEED, stv.toBuffer(), user.toBuffer(), epochBuf], programId);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Derive the per-user delayed deposit request PDA.
|
|
48
|
+
* Seeds: `["delayed_deposit", stv, user, epoch_id_le4]`.
|
|
49
|
+
*/
|
|
50
|
+
function findDelayedDepositRequestPda(stv, user, epochId, programId = constants_1.PROGRAM_ID) {
|
|
51
|
+
const epochBuf = Buffer.alloc(4);
|
|
52
|
+
epochBuf.writeUInt32LE(epochId, 0);
|
|
53
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.DELAYED_DEPOSIT_SEED, stv.toBuffer(), user.toBuffer(), epochBuf], programId);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Derive the per-STV `ManagerRole` PDA for p-STV Core.
|
|
57
|
+
* Seeds: `["manager", stv, manager]`.
|
|
58
|
+
*
|
|
59
|
+
* Note the per-program prefix on the name: each Elemental program has its
|
|
60
|
+
* own `ManagerRole` PDA scoped to a different anchor account
|
|
61
|
+
* (`elemental-lend` → strategy_state, `jlpd-strategy` → config).
|
|
62
|
+
*/
|
|
63
|
+
function findStvManagerRolePda(stv, manager, programId = constants_1.PROGRAM_ID) {
|
|
64
|
+
return web3_js_1.PublicKey.findProgramAddressSync([constants_1.MANAGER_SEED, stv.toBuffer(), manager.toBuffer()], programId);
|
|
65
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* USD price fetcher for display purposes.
|
|
3
|
+
*
|
|
4
|
+
* Stablecoins (USDC, JupUSD) are hardcoded to $1.00.
|
|
5
|
+
* Other tokens use Jupiter swap quote API (1 unit → USDC) to derive price.
|
|
6
|
+
*/
|
|
7
|
+
export interface TokenPrice {
|
|
8
|
+
mint: string;
|
|
9
|
+
price: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Fetch USD prices for a list of token mint addresses.
|
|
13
|
+
*
|
|
14
|
+
* Stablecoins (USDC, JupUSD) are hardcoded to $1.00.
|
|
15
|
+
* Other tokens: fetches a Jupiter swap quote (1 unit → USDC) to derive price.
|
|
16
|
+
*
|
|
17
|
+
* @param mints - Array of mint address strings (base58)
|
|
18
|
+
* @returns Record<mint, usdPrice>
|
|
19
|
+
*/
|
|
20
|
+
export declare function fetchUsdPrices(mints: string[]): Promise<Record<string, number>>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* USD price fetcher for display purposes.
|
|
4
|
+
*
|
|
5
|
+
* Stablecoins (USDC, JupUSD) are hardcoded to $1.00.
|
|
6
|
+
* Other tokens use Jupiter swap quote API (1 unit → USDC) to derive price.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.fetchUsdPrices = fetchUsdPrices;
|
|
10
|
+
const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
11
|
+
const JUPUSD_MINT = "JuprjznTrTSp2UFa3ZBUFgwdAmtZCq4MQCwysN55USD";
|
|
12
|
+
/** Mints pegged 1:1 to USD */
|
|
13
|
+
const STABLE_MINTS = new Set([USDC_MINT, JUPUSD_MINT]);
|
|
14
|
+
/** Decimals per mint (for computing 1 unit in base units) */
|
|
15
|
+
const MINT_DECIMALS = {
|
|
16
|
+
"So11111111111111111111111111111111111111112": 9, // SOL
|
|
17
|
+
"3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh": 8, // wBTC
|
|
18
|
+
"7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs": 8, // wETH
|
|
19
|
+
};
|
|
20
|
+
const USDC_DECIMALS = 6;
|
|
21
|
+
const JUPITER_QUOTE_API = "https://api.jup.ag/swap/v1/quote";
|
|
22
|
+
function getJupiterApiKey() {
|
|
23
|
+
if (typeof process !== "undefined" && process.env) {
|
|
24
|
+
return process.env.NEXT_PUBLIC_JUPITER_API_KEY || process.env.JUPITER_API_KEY;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Public API
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
/**
|
|
32
|
+
* Fetch USD prices for a list of token mint addresses.
|
|
33
|
+
*
|
|
34
|
+
* Stablecoins (USDC, JupUSD) are hardcoded to $1.00.
|
|
35
|
+
* Other tokens: fetches a Jupiter swap quote (1 unit → USDC) to derive price.
|
|
36
|
+
*
|
|
37
|
+
* @param mints - Array of mint address strings (base58)
|
|
38
|
+
* @returns Record<mint, usdPrice>
|
|
39
|
+
*/
|
|
40
|
+
async function fetchUsdPrices(mints) {
|
|
41
|
+
const prices = {};
|
|
42
|
+
const toFetch = [];
|
|
43
|
+
for (const mint of mints) {
|
|
44
|
+
if (STABLE_MINTS.has(mint)) {
|
|
45
|
+
prices[mint] = 1.0;
|
|
46
|
+
}
|
|
47
|
+
else if (MINT_DECIMALS[mint] !== undefined) {
|
|
48
|
+
toFetch.push(mint);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (toFetch.length === 0)
|
|
52
|
+
return prices;
|
|
53
|
+
const apiKey = getJupiterApiKey();
|
|
54
|
+
const headers = {};
|
|
55
|
+
if (apiKey)
|
|
56
|
+
headers["x-api-key"] = apiKey;
|
|
57
|
+
// Fetch prices in parallel (1 unit of each → USDC)
|
|
58
|
+
const results = await Promise.allSettled(toFetch.map(async (mint) => {
|
|
59
|
+
const decimals = MINT_DECIMALS[mint];
|
|
60
|
+
const oneUnit = Math.pow(10, decimals).toString();
|
|
61
|
+
const url = `${JUPITER_QUOTE_API}?inputMint=${mint}&outputMint=${USDC_MINT}&amount=${oneUnit}&slippageBps=50`;
|
|
62
|
+
const resp = await fetch(url, { headers });
|
|
63
|
+
if (!resp.ok)
|
|
64
|
+
return null;
|
|
65
|
+
const data = (await resp.json());
|
|
66
|
+
const outAmount = data?.outAmount;
|
|
67
|
+
if (!outAmount)
|
|
68
|
+
return null;
|
|
69
|
+
return { mint, price: Number(outAmount) / Math.pow(10, USDC_DECIMALS) };
|
|
70
|
+
}));
|
|
71
|
+
for (const result of results) {
|
|
72
|
+
if (result.status === "fulfilled" && result.value) {
|
|
73
|
+
prices[result.value.mint] = result.value.price;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return prices;
|
|
77
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
10
|
+
import type { SolanaConnection } from "../common/connection";
|
|
11
|
+
export type { SolanaConnection };
|
|
12
|
+
/** Minimal vault shape required by the context builders. */
|
|
13
|
+
export interface VaultInfo {
|
|
14
|
+
/** STV account address */
|
|
15
|
+
address: PublicKey;
|
|
16
|
+
/** Base token mint */
|
|
17
|
+
baseMint: PublicKey;
|
|
18
|
+
/** Lend program (PublicKey.default if not active) */
|
|
19
|
+
lendProgram: PublicKey;
|
|
20
|
+
/** Immutable strategy program (PublicKey.default if none) */
|
|
21
|
+
strategy: PublicKey;
|
|
22
|
+
/**
|
|
23
|
+
* Token program for the base mint (SPL Token or Token-2022).
|
|
24
|
+
*
|
|
25
|
+
* This MUST match the token_program passed as a fixed account to the p-stv-core
|
|
26
|
+
* instruction. The on-chain handler derives lend_base_ata using
|
|
27
|
+
* [strategy_state, token_program, base_mint] (check_lend_base_ata, lend.rs:61)
|
|
28
|
+
* and rejects a mismatch. Defaults to SPL Token when omitted for back-compat,
|
|
29
|
+
* but callers MUST supply the correct value for Token-2022 mints.
|
|
30
|
+
*/
|
|
31
|
+
tokenProgram?: PublicKey;
|
|
32
|
+
}
|
|
33
|
+
export interface DepositContext {
|
|
34
|
+
remainingAccounts: AccountMeta[];
|
|
35
|
+
protocolAumCount: number;
|
|
36
|
+
autoRouteCount: number;
|
|
37
|
+
preInstructions: TransactionInstruction[];
|
|
38
|
+
}
|
|
39
|
+
export interface ClaimWithdrawContext {
|
|
40
|
+
remainingAccounts: AccountMeta[];
|
|
41
|
+
autoUnrouteCount: number;
|
|
42
|
+
/** Protocol-AUM accounts placed between the 4 fixed lend accounts and auto-unroute,
|
|
43
|
+
* feeding the pre-unsweep update_aum refresh. Pass to createClaimWithdrawIx.protocolAumCount. */
|
|
44
|
+
protocolAumCount: number;
|
|
45
|
+
/**
|
|
46
|
+
* Pre-instructions to add before the claim_withdraw ix.
|
|
47
|
+
* Currently always empty — see DepositContext.preInstructions.
|
|
48
|
+
*/
|
|
49
|
+
preInstructions: TransactionInstruction[];
|
|
50
|
+
}
|
|
51
|
+
export interface DepositToStrategyContext {
|
|
52
|
+
remainingAccounts: AccountMeta[];
|
|
53
|
+
/** Number of protocol AUM accounts (after the 4 fixed lend accounts). */
|
|
54
|
+
protocolAumCount: number;
|
|
55
|
+
autoUnrouteCount: number;
|
|
56
|
+
preInstructions: TransactionInstruction[];
|
|
57
|
+
}
|
|
58
|
+
export interface ProcessEpochContext {
|
|
59
|
+
remainingAccounts: AccountMeta[];
|
|
60
|
+
protocolAumCount: number;
|
|
61
|
+
/**
|
|
62
|
+
* Pre-instructions to add before the process_epoch ix.
|
|
63
|
+
* Currently always empty — see DepositContext.preInstructions.
|
|
64
|
+
*/
|
|
65
|
+
preInstructions: TransactionInstruction[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build the complete remaining_accounts for a deposit instruction.
|
|
69
|
+
*
|
|
70
|
+
* Layout: [4 lend, N protocol_aum, M*2+P strategy_pairs, K auto_route]
|
|
71
|
+
*
|
|
72
|
+
* - If lend is active, derives lend PDAs and fetches protocol AUM accounts
|
|
73
|
+
* - Builds strategy pair accounts for each active strategy
|
|
74
|
+
* - If USDC + Jupiter Lend registered, appends auto-route accounts
|
|
75
|
+
* - Checks for stale kVaults (returned in preInstructions once invest ix is available)
|
|
76
|
+
*/
|
|
77
|
+
export declare function buildDepositContext(connection: SolanaConnection, vault: VaultInfo, payer?: PublicKey): Promise<DepositContext>;
|
|
78
|
+
/**
|
|
79
|
+
* Build the complete remaining_accounts for a claim_withdraw instruction.
|
|
80
|
+
*
|
|
81
|
+
* Layout: [4 lend, K auto_unroute]
|
|
82
|
+
*
|
|
83
|
+
* - If lend is active, derives lend PDAs
|
|
84
|
+
* - If USDC + Jupiter Lend, appends auto-unroute accounts
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildClaimWithdrawContext(connection: SolanaConnection, vault: VaultInfo): Promise<ClaimWithdrawContext>;
|
|
87
|
+
/**
|
|
88
|
+
* Build the complete remaining_accounts for a deposit_to_strategy instruction.
|
|
89
|
+
*
|
|
90
|
+
* Layout: [4 fixed lend, N protocol_aum, K auto_unroute]
|
|
91
|
+
*
|
|
92
|
+
* - Fixed lend accounts (if lend is active)
|
|
93
|
+
* - Protocol AUM accounts: required by the on-chain handler to refresh lend
|
|
94
|
+
* valuation via update_lend_aum before the reserved_base liquidity lock check
|
|
95
|
+
* - Auto-unroute accounts: forwarded to the lend withdraw CPI for unsweep
|
|
96
|
+
*
|
|
97
|
+
* The `connection` parameter is required to fetch LendStrategyState and
|
|
98
|
+
* resolve protocol AUM accounts.
|
|
99
|
+
*/
|
|
100
|
+
export declare function buildDepositToStrategyContext(connection: SolanaConnection, vault: VaultInfo): Promise<DepositToStrategyContext>;
|
|
101
|
+
/**
|
|
102
|
+
* Build the complete remaining_accounts for a process_epoch instruction.
|
|
103
|
+
*
|
|
104
|
+
* @param phase - 'lockPps': needs lend + protocol AUM + strategy pairs for NAV.
|
|
105
|
+
* 'advance': empty remaining_accounts.
|
|
106
|
+
*/
|
|
107
|
+
export declare function buildProcessEpochContext(connection: SolanaConnection, vault: VaultInfo, phase: "lockPps" | "advance"): Promise<ProcessEpochContext>;
|