@elemental-stv-core/sdk 0.4.0 → 0.6.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/LICENSE +201 -0
- package/README.md +250 -0
- package/dist/common/ata.d.ts +14 -0
- package/dist/common/ata.js +21 -0
- package/dist/common/buffer.d.ts +0 -1
- package/dist/common/buffer.js +16 -1
- package/dist/common/connection.d.ts +13 -0
- package/dist/common/connection.js +2 -0
- package/dist/common/constants.d.ts +6 -1
- package/dist/common/constants.js +21 -2
- package/dist/common/index.d.ts +3 -2
- package/dist/common/index.js +6 -2
- package/dist/common/strategy-interface.d.ts +35 -5
- package/dist/common/strategy-interface.js +7 -5
- package/dist/elemental-lend/accounts.d.ts +53 -9
- package/dist/elemental-lend/accounts.js +66 -8
- package/dist/elemental-lend/constants.d.ts +6 -7
- package/dist/elemental-lend/constants.js +13 -12
- package/dist/elemental-lend/index.d.ts +0 -1
- package/dist/elemental-lend/index.js +0 -1
- package/dist/elemental-lend/instructions.d.ts +0 -1
- package/dist/elemental-lend/instructions.js +0 -1
- package/dist/elemental-lend/jupiter-lend.d.ts +0 -1
- package/dist/elemental-lend/jupiter-lend.js +2 -3
- package/dist/elemental-lend/kamino-vault.d.ts +6 -6
- package/dist/elemental-lend/kamino-vault.js +49 -26
- package/dist/elemental-lend/pda.d.ts +9 -2
- package/dist/elemental-lend/pda.js +10 -3
- package/dist/elemental-lend/protocol-actions.d.ts +6 -5
- package/dist/elemental-lend/protocol-actions.js +22 -17
- package/dist/elemental-lend/types.d.ts +0 -1
- package/dist/elemental-lend/types.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/jlpd-strategy/accounts.d.ts +64 -11
- package/dist/jlpd-strategy/accounts.js +66 -7
- package/dist/jlpd-strategy/adapter.d.ts +60 -0
- package/dist/jlpd-strategy/adapter.js +90 -0
- package/dist/jlpd-strategy/constants.d.ts +27 -16
- package/dist/jlpd-strategy/constants.js +40 -29
- package/dist/jlpd-strategy/index.d.ts +3 -1
- package/dist/jlpd-strategy/index.js +3 -1
- package/dist/jlpd-strategy/instructions.d.ts +0 -1
- package/dist/jlpd-strategy/instructions.js +0 -1
- 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 +4 -4
- package/dist/jlpd-strategy/jlp-data.js +0 -1
- package/dist/jlpd-strategy/jupusd-earn.d.ts +90 -0
- package/dist/jlpd-strategy/jupusd-earn.js +166 -0
- package/dist/jlpd-strategy/pda.d.ts +9 -4
- package/dist/jlpd-strategy/pda.js +10 -6
- package/dist/jlpd-strategy/settle-yield.d.ts +12 -45
- package/dist/jlpd-strategy/settle-yield.js +14 -19
- package/dist/jlpd-strategy/swap-jlp.d.ts +4 -4
- package/dist/jlpd-strategy/swap-jlp.js +35 -27
- package/dist/jlpd-strategy/types.d.ts +5 -4
- package/dist/jlpd-strategy/types.js +0 -1
- package/dist/p-stv-core/accounts.d.ts +84 -11
- package/dist/p-stv-core/accounts.js +83 -5
- package/dist/p-stv-core/constants.d.ts +13 -3
- package/dist/p-stv-core/constants.js +23 -11
- package/dist/p-stv-core/events.d.ts +0 -1
- package/dist/p-stv-core/events.js +50 -1
- package/dist/p-stv-core/index.d.ts +0 -1
- package/dist/p-stv-core/index.js +0 -1
- package/dist/p-stv-core/instructions.d.ts +49 -4
- package/dist/p-stv-core/instructions.js +46 -14
- package/dist/p-stv-core/pda.d.ts +9 -2
- package/dist/p-stv-core/pda.js +10 -3
- package/dist/p-stv-core/prices.d.ts +0 -1
- package/dist/p-stv-core/prices.js +0 -1
- package/dist/p-stv-core/remaining-accounts.d.ts +13 -14
- package/dist/p-stv-core/remaining-accounts.js +53 -46
- package/dist/p-stv-core/send-tx.d.ts +23 -7
- package/dist/p-stv-core/send-tx.js +17 -26
- package/dist/p-stv-core/sol-wrap.d.ts +0 -1
- package/dist/p-stv-core/sol-wrap.js +5 -6
- package/dist/p-stv-core/types.d.ts +9 -2
- package/dist/p-stv-core/types.js +0 -1
- package/package.json +17 -1
- package/dist/common/buffer.d.ts.map +0 -1
- package/dist/common/buffer.js.map +0 -1
- package/dist/common/constants.d.ts.map +0 -1
- package/dist/common/constants.js.map +0 -1
- package/dist/common/index.d.ts.map +0 -1
- package/dist/common/index.js.map +0 -1
- package/dist/common/strategy-interface.d.ts.map +0 -1
- package/dist/common/strategy-interface.js.map +0 -1
- package/dist/elemental-lend/accounts.d.ts.map +0 -1
- package/dist/elemental-lend/accounts.js.map +0 -1
- package/dist/elemental-lend/constants.d.ts.map +0 -1
- package/dist/elemental-lend/constants.js.map +0 -1
- package/dist/elemental-lend/index.d.ts.map +0 -1
- package/dist/elemental-lend/index.js.map +0 -1
- package/dist/elemental-lend/instructions.d.ts.map +0 -1
- package/dist/elemental-lend/instructions.js.map +0 -1
- package/dist/elemental-lend/jupiter-lend.d.ts.map +0 -1
- package/dist/elemental-lend/jupiter-lend.js.map +0 -1
- package/dist/elemental-lend/kamino-vault.d.ts.map +0 -1
- package/dist/elemental-lend/kamino-vault.js.map +0 -1
- package/dist/elemental-lend/pda.d.ts.map +0 -1
- package/dist/elemental-lend/pda.js.map +0 -1
- package/dist/elemental-lend/protocol-actions.d.ts.map +0 -1
- package/dist/elemental-lend/protocol-actions.js.map +0 -1
- package/dist/elemental-lend/types.d.ts.map +0 -1
- package/dist/elemental-lend/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jlpd-strategy/accounts.d.ts.map +0 -1
- package/dist/jlpd-strategy/accounts.js.map +0 -1
- package/dist/jlpd-strategy/constants.d.ts.map +0 -1
- package/dist/jlpd-strategy/constants.js.map +0 -1
- package/dist/jlpd-strategy/index.d.ts.map +0 -1
- package/dist/jlpd-strategy/index.js.map +0 -1
- package/dist/jlpd-strategy/instructions.d.ts.map +0 -1
- package/dist/jlpd-strategy/instructions.js.map +0 -1
- package/dist/jlpd-strategy/jlp-data.d.ts.map +0 -1
- package/dist/jlpd-strategy/jlp-data.js.map +0 -1
- package/dist/jlpd-strategy/pda.d.ts.map +0 -1
- package/dist/jlpd-strategy/pda.js.map +0 -1
- package/dist/jlpd-strategy/settle-yield.d.ts.map +0 -1
- package/dist/jlpd-strategy/settle-yield.js.map +0 -1
- package/dist/jlpd-strategy/swap-jlp.d.ts.map +0 -1
- package/dist/jlpd-strategy/swap-jlp.js.map +0 -1
- package/dist/jlpd-strategy/types.d.ts.map +0 -1
- package/dist/jlpd-strategy/types.js.map +0 -1
- package/dist/p-stv-core/accounts.d.ts.map +0 -1
- package/dist/p-stv-core/accounts.js.map +0 -1
- package/dist/p-stv-core/constants.d.ts.map +0 -1
- package/dist/p-stv-core/constants.js.map +0 -1
- package/dist/p-stv-core/events.d.ts.map +0 -1
- package/dist/p-stv-core/events.js.map +0 -1
- package/dist/p-stv-core/index.d.ts.map +0 -1
- package/dist/p-stv-core/index.js.map +0 -1
- package/dist/p-stv-core/instructions.d.ts.map +0 -1
- package/dist/p-stv-core/instructions.js.map +0 -1
- package/dist/p-stv-core/pda.d.ts.map +0 -1
- package/dist/p-stv-core/pda.js.map +0 -1
- package/dist/p-stv-core/prices.d.ts.map +0 -1
- package/dist/p-stv-core/prices.js.map +0 -1
- package/dist/p-stv-core/remaining-accounts.d.ts.map +0 -1
- package/dist/p-stv-core/remaining-accounts.js.map +0 -1
- package/dist/p-stv-core/send-tx.d.ts.map +0 -1
- package/dist/p-stv-core/send-tx.js.map +0 -1
- package/dist/p-stv-core/sol-wrap.d.ts.map +0 -1
- package/dist/p-stv-core/sol-wrap.js.map +0 -1
- package/dist/p-stv-core/types.d.ts.map +0 -1
- package/dist/p-stv-core/types.js.map +0 -1
|
@@ -1,54 +1,21 @@
|
|
|
1
1
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
-
/** Arguments
|
|
2
|
+
/** Arguments accepted by `createSettleYieldIx`. */
|
|
3
3
|
export interface CreateSettleYieldIxArgs {
|
|
4
|
-
config: PublicKey;
|
|
5
|
-
managerRole: PublicKey;
|
|
6
|
-
vaultJlpAta: PublicKey;
|
|
7
|
-
stv0: PublicKey;
|
|
8
|
-
stv1: PublicKey;
|
|
9
|
-
stv2: PublicKey;
|
|
10
|
-
stv3: PublicKey;
|
|
11
|
-
stv4: PublicKey;
|
|
12
|
-
dovesBtcUsd: PublicKey;
|
|
13
|
-
dovesEthUsd: PublicKey;
|
|
14
|
-
dovesSolUsd: PublicKey;
|
|
15
|
-
jlpPool: PublicKey;
|
|
16
|
-
jlpMintAccount: PublicKey;
|
|
17
4
|
manager: PublicKey;
|
|
5
|
+
/** 5 base asset mints in order: [BTC, ETH, SOL, USDC, JupUSD]. */
|
|
6
|
+
baseAssetMints: [PublicKey, PublicKey, PublicKey, PublicKey, PublicKey];
|
|
7
|
+
jlpMint?: PublicKey;
|
|
8
|
+
tokenProgram?: PublicKey;
|
|
9
|
+
programId?: PublicKey;
|
|
18
10
|
}
|
|
19
11
|
/**
|
|
20
|
-
* Build
|
|
21
|
-
*
|
|
22
|
-
* settle_yield takes no params -- instruction data is just the 8-byte discriminator.
|
|
23
|
-
*
|
|
24
|
-
* Accounts (14 total):
|
|
25
|
-
* 0: config (JlpdConfig PDA)
|
|
26
|
-
* 1: manager_role (ManagerRole PDA)
|
|
27
|
-
* 2: vault_jlp_ata (JLP ATA owned by config)
|
|
28
|
-
* 3: stv_0 (BTC strategy_state, mut)
|
|
29
|
-
* 4: stv_1 (ETH strategy_state, mut)
|
|
30
|
-
* 5: stv_2 (SOL strategy_state, mut)
|
|
31
|
-
* 6: stv_3 (USDC strategy_state, mut)
|
|
32
|
-
* 7: stv_4 (JupUSD strategy_state, mut)
|
|
33
|
-
* 8: doves_btc_usd (oracle)
|
|
34
|
-
* 9: doves_eth_usd (oracle)
|
|
35
|
-
* 10: doves_sol_usd (oracle)
|
|
36
|
-
* 11: jlp_pool (Jupiter Perps Pool)
|
|
37
|
-
* 12: jlp_mint_account
|
|
38
|
-
* 13: manager (signer)
|
|
39
|
-
*/
|
|
40
|
-
export declare function createSettleYieldIx(args: CreateSettleYieldIxArgs, programId?: PublicKey): TransactionInstruction;
|
|
41
|
-
/**
|
|
42
|
-
* Build a settle_yield instruction with automatic PDA derivation.
|
|
12
|
+
* Build a `settle_yield` instruction with automatic PDA derivation.
|
|
43
13
|
*
|
|
44
14
|
* Requires the 5 base asset mints in order: [BTC, ETH, SOL, USDC, JupUSD].
|
|
45
15
|
* These must match the `base_asset_mints` array on the JlpdConfig account.
|
|
16
|
+
*
|
|
17
|
+
* Naming follows the SDK convention: low-level instruction builders are named
|
|
18
|
+
* `create*Ix` (this is the canonical name); high-level transaction wrappers
|
|
19
|
+
* (if any) are named `build*Transaction`.
|
|
46
20
|
*/
|
|
47
|
-
export declare function
|
|
48
|
-
manager: PublicKey;
|
|
49
|
-
baseAssetMints: [PublicKey, PublicKey, PublicKey, PublicKey, PublicKey];
|
|
50
|
-
jlpMint?: PublicKey;
|
|
51
|
-
tokenProgram?: PublicKey;
|
|
52
|
-
programId?: PublicKey;
|
|
53
|
-
}): TransactionInstruction;
|
|
54
|
-
//# sourceMappingURL=settle-yield.d.ts.map
|
|
21
|
+
export declare function createSettleYieldIx(args: CreateSettleYieldIxArgs): TransactionInstruction;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSettleYieldIx = createSettleYieldIx;
|
|
4
|
-
exports.buildSettleYieldIx = buildSettleYieldIx;
|
|
5
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
5
|
const spl_token_1 = require("@solana/spl-token");
|
|
7
6
|
const constants_1 = require("./constants");
|
|
8
7
|
const pda_1 = require("./pda");
|
|
8
|
+
const ata_1 = require("../common/ata");
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
|
-
//
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
/** Derive ATA address */
|
|
13
|
-
function findAta(mint, owner, tokenProgram) {
|
|
14
|
-
const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
15
|
-
return ata;
|
|
16
|
-
}
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
// Low-level instruction builder
|
|
10
|
+
// Internal raw builder
|
|
19
11
|
// ---------------------------------------------------------------------------
|
|
20
12
|
/**
|
|
21
|
-
* Build the on-chain `settle_yield` instruction.
|
|
13
|
+
* Build the on-chain `settle_yield` instruction from explicit account inputs.
|
|
22
14
|
*
|
|
23
15
|
* settle_yield takes no params -- instruction data is just the 8-byte discriminator.
|
|
24
16
|
*
|
|
@@ -38,7 +30,7 @@ function findAta(mint, owner, tokenProgram) {
|
|
|
38
30
|
* 12: jlp_mint_account
|
|
39
31
|
* 13: manager (signer)
|
|
40
32
|
*/
|
|
41
|
-
function
|
|
33
|
+
function buildRawSettleYieldIx(args, programId = constants_1.PROGRAM_ID) {
|
|
42
34
|
const { config, managerRole, vaultJlpAta, stv0, stv1, stv2, stv3, stv4, dovesBtcUsd, dovesEthUsd, dovesSolUsd, jlpPool, jlpMintAccount, manager, } = args;
|
|
43
35
|
// Instruction data: just the 8-byte discriminator (no params)
|
|
44
36
|
const data = Buffer.alloc(8);
|
|
@@ -62,19 +54,23 @@ function createSettleYieldIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
62
54
|
return new web3_js_1.TransactionInstruction({ keys, programId, data });
|
|
63
55
|
}
|
|
64
56
|
// ---------------------------------------------------------------------------
|
|
65
|
-
//
|
|
57
|
+
// Public instruction builder
|
|
66
58
|
// ---------------------------------------------------------------------------
|
|
67
59
|
/**
|
|
68
|
-
* Build a settle_yield instruction with automatic PDA derivation.
|
|
60
|
+
* Build a `settle_yield` instruction with automatic PDA derivation.
|
|
69
61
|
*
|
|
70
62
|
* Requires the 5 base asset mints in order: [BTC, ETH, SOL, USDC, JupUSD].
|
|
71
63
|
* These must match the `base_asset_mints` array on the JlpdConfig account.
|
|
64
|
+
*
|
|
65
|
+
* Naming follows the SDK convention: low-level instruction builders are named
|
|
66
|
+
* `create*Ix` (this is the canonical name); high-level transaction wrappers
|
|
67
|
+
* (if any) are named `build*Transaction`.
|
|
72
68
|
*/
|
|
73
|
-
function
|
|
69
|
+
function createSettleYieldIx(args) {
|
|
74
70
|
const { manager, baseAssetMints, jlpMint = constants_1.JLP_MINT, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID, programId = constants_1.PROGRAM_ID, } = args;
|
|
75
71
|
// Derive PDAs
|
|
76
72
|
const [config] = (0, pda_1.findJlpdConfigPda)(programId);
|
|
77
|
-
const [managerRole] = (0, pda_1.
|
|
73
|
+
const [managerRole] = (0, pda_1.findJlpdManagerRolePda)(config, manager, programId);
|
|
78
74
|
// Derive strategy_state PDAs for all 5 base assets
|
|
79
75
|
const [stv0] = (0, pda_1.findStrategyStatePda)(baseAssetMints[0], programId);
|
|
80
76
|
const [stv1] = (0, pda_1.findStrategyStatePda)(baseAssetMints[1], programId);
|
|
@@ -82,8 +78,8 @@ function buildSettleYieldIx(args) {
|
|
|
82
78
|
const [stv3] = (0, pda_1.findStrategyStatePda)(baseAssetMints[3], programId);
|
|
83
79
|
const [stv4] = (0, pda_1.findStrategyStatePda)(baseAssetMints[4], programId);
|
|
84
80
|
// Derive vault JLP ATA (owned by config PDA)
|
|
85
|
-
const vaultJlpAta = findAta(jlpMint, config, tokenProgram);
|
|
86
|
-
return
|
|
81
|
+
const vaultJlpAta = (0, ata_1.findAta)(jlpMint, config, tokenProgram);
|
|
82
|
+
return buildRawSettleYieldIx({
|
|
87
83
|
config,
|
|
88
84
|
managerRole,
|
|
89
85
|
vaultJlpAta,
|
|
@@ -100,4 +96,3 @@ function buildSettleYieldIx(args) {
|
|
|
100
96
|
manager,
|
|
101
97
|
}, programId);
|
|
102
98
|
}
|
|
103
|
-
//# sourceMappingURL=settle-yield.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PublicKey, TransactionInstruction,
|
|
1
|
+
import { PublicKey, TransactionInstruction, AddressLookupTableAccount, AccountMeta } from "@solana/web3.js";
|
|
2
|
+
import type { SolanaConnection } from "../common/connection";
|
|
2
3
|
import BN from "bn.js";
|
|
3
4
|
/** Direction of the JLP swap */
|
|
4
5
|
export type SwapDirection = "BaseToJlp" | "JlpToBase";
|
|
@@ -97,7 +98,7 @@ export declare function getJupiterSwapInstructions(args: {
|
|
|
97
98
|
* 5. Returns instructions + ALTs for a versioned transaction
|
|
98
99
|
*/
|
|
99
100
|
export declare function buildSwapJlpTransaction(args: {
|
|
100
|
-
connection:
|
|
101
|
+
connection: SolanaConnection;
|
|
101
102
|
manager: PublicKey;
|
|
102
103
|
baseMint: PublicKey;
|
|
103
104
|
direction: SwapDirection;
|
|
@@ -113,7 +114,7 @@ export declare function buildSwapJlpTransaction(args: {
|
|
|
113
114
|
quoteInAmount: bigint;
|
|
114
115
|
}>;
|
|
115
116
|
export interface RebalanceArgs {
|
|
116
|
-
connection:
|
|
117
|
+
connection: SolanaConnection;
|
|
117
118
|
manager: PublicKey;
|
|
118
119
|
baseMint: PublicKey;
|
|
119
120
|
vaultId: number;
|
|
@@ -150,4 +151,3 @@ export interface RebalanceResult {
|
|
|
150
151
|
* For JlpToBase: builds swap_jlp + withdraw_from_strategy in 1 tx.
|
|
151
152
|
*/
|
|
152
153
|
export declare function buildRebalanceTransaction(args: RebalanceArgs): Promise<RebalanceResult>;
|
|
153
|
-
//# sourceMappingURL=swap-jlp.d.ts.map
|
|
@@ -10,6 +10,7 @@ exports.buildSwapJlpTransaction = buildSwapJlpTransaction;
|
|
|
10
10
|
exports.buildRebalanceTransaction = buildRebalanceTransaction;
|
|
11
11
|
const web3_js_1 = require("@solana/web3.js");
|
|
12
12
|
const spl_token_1 = require("@solana/spl-token");
|
|
13
|
+
const ata_1 = require("../common/ata");
|
|
13
14
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
14
15
|
const constants_1 = require("./constants");
|
|
15
16
|
const pda_1 = require("./pda");
|
|
@@ -26,15 +27,20 @@ const instructions_2 = require("../elemental-lend/instructions");
|
|
|
26
27
|
// Helpers
|
|
27
28
|
// ---------------------------------------------------------------------------
|
|
28
29
|
const JUPITER_API_BASE = "https://api.jup.ag/swap/v1";
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Optional Jupiter API key, read once at module load time. When set,
|
|
32
|
+
* outbound Jupiter requests include an `x-api-key` header for higher rate
|
|
33
|
+
* limits. Read once instead of per-call so the env var is consistent across
|
|
34
|
+
* the lifetime of the process.
|
|
35
|
+
*/
|
|
36
|
+
const JUPITER_API_KEY = process.env.NEXT_PUBLIC_JUPITER_API_KEY;
|
|
34
37
|
function toBigInt(v) {
|
|
35
38
|
if (typeof v === "bigint")
|
|
36
39
|
return v;
|
|
37
|
-
|
|
40
|
+
const bn = v;
|
|
41
|
+
if (typeof bn.toBigInt === "function")
|
|
42
|
+
return bn.toBigInt();
|
|
43
|
+
return BigInt(bn.toString());
|
|
38
44
|
}
|
|
39
45
|
// ---------------------------------------------------------------------------
|
|
40
46
|
// Low-level instruction builder
|
|
@@ -89,7 +95,6 @@ function createSwapJlpIx(args, programId = constants_1.PROGRAM_ID) {
|
|
|
89
95
|
*/
|
|
90
96
|
async function getJupiterSwapQuote(args) {
|
|
91
97
|
const { inputMint, outputMint, amount, slippageBps = 50, maxAccounts = 40 } = args;
|
|
92
|
-
const apiKey = process.env.NEXT_PUBLIC_JUPITER_API_KEY;
|
|
93
98
|
const params = new URLSearchParams({
|
|
94
99
|
inputMint: inputMint.toBase58(),
|
|
95
100
|
outputMint: outputMint.toBase58(),
|
|
@@ -99,8 +104,8 @@ async function getJupiterSwapQuote(args) {
|
|
|
99
104
|
});
|
|
100
105
|
const url = `${JUPITER_API_BASE}/quote?${params.toString()}`;
|
|
101
106
|
const headers = {};
|
|
102
|
-
if (
|
|
103
|
-
headers["x-api-key"] =
|
|
107
|
+
if (JUPITER_API_KEY) {
|
|
108
|
+
headers["x-api-key"] = JUPITER_API_KEY;
|
|
104
109
|
}
|
|
105
110
|
const response = await fetch(url, { headers });
|
|
106
111
|
if (!response.ok) {
|
|
@@ -121,7 +126,6 @@ async function getJupiterSwapQuote(args) {
|
|
|
121
126
|
*/
|
|
122
127
|
async function getJupiterSwapInstructions(args) {
|
|
123
128
|
const { quoteResponse, userPublicKey } = args;
|
|
124
|
-
const apiKey = process.env.NEXT_PUBLIC_JUPITER_API_KEY;
|
|
125
129
|
const url = `${JUPITER_API_BASE}/swap-instructions`;
|
|
126
130
|
const body = {
|
|
127
131
|
quoteResponse,
|
|
@@ -133,8 +137,8 @@ async function getJupiterSwapInstructions(args) {
|
|
|
133
137
|
const headers = {
|
|
134
138
|
"Content-Type": "application/json",
|
|
135
139
|
};
|
|
136
|
-
if (
|
|
137
|
-
headers["x-api-key"] =
|
|
140
|
+
if (JUPITER_API_KEY) {
|
|
141
|
+
headers["x-api-key"] = JUPITER_API_KEY;
|
|
138
142
|
}
|
|
139
143
|
const response = await fetch(url, {
|
|
140
144
|
method: "POST",
|
|
@@ -204,12 +208,12 @@ async function buildSwapJlpTransaction(args) {
|
|
|
204
208
|
const { connection, manager, baseMint, direction, amount, slippageBps = 50, jlpMint = constants_1.JLP_MINT, tokenProgram = spl_token_1.TOKEN_PROGRAM_ID, programId = constants_1.PROGRAM_ID, } = args;
|
|
205
209
|
// 1. Derive PDAs
|
|
206
210
|
const [config] = (0, pda_1.findJlpdConfigPda)(programId);
|
|
207
|
-
const [managerRole] = (0, pda_1.
|
|
211
|
+
const [managerRole] = (0, pda_1.findJlpdManagerRolePda)(config, manager, programId);
|
|
208
212
|
const [strategyState] = (0, pda_1.findStrategyStatePda)(baseMint, programId);
|
|
209
213
|
// Derive ATAs
|
|
210
|
-
const strategyBaseAta = findAta(baseMint, strategyState, tokenProgram);
|
|
211
|
-
const strategyJlpAta = findAta(jlpMint, strategyState, tokenProgram);
|
|
212
|
-
const vaultJlpAta = findAta(jlpMint, config, tokenProgram);
|
|
214
|
+
const strategyBaseAta = (0, ata_1.findAta)(baseMint, strategyState, tokenProgram);
|
|
215
|
+
const strategyJlpAta = (0, ata_1.findAta)(jlpMint, strategyState, tokenProgram);
|
|
216
|
+
const vaultJlpAta = (0, ata_1.findAta)(jlpMint, config, tokenProgram);
|
|
213
217
|
// 2. Determine input/output mints for the Jupiter quote
|
|
214
218
|
const inputMint = direction === "BaseToJlp" ? baseMint : jlpMint;
|
|
215
219
|
const outputMint = direction === "BaseToJlp" ? jlpMint : baseMint;
|
|
@@ -284,7 +288,7 @@ async function buildBaseToJlpRebalance(args) {
|
|
|
284
288
|
const { connection, manager, baseMint, vaultId, amount, slippageBps, jlpMint, tokenProgram, programId, pStvProgramId, liquidity, } = args;
|
|
285
289
|
// Derive JLPD PDAs
|
|
286
290
|
const [strategyState] = (0, pda_1.findStrategyStatePda)(baseMint, programId);
|
|
287
|
-
const strategyBaseAta = findAta(baseMint, strategyState, tokenProgram);
|
|
291
|
+
const strategyBaseAta = (0, ata_1.findAta)(baseMint, strategyState, tokenProgram);
|
|
288
292
|
// Check if strategy_base_ata already has enough
|
|
289
293
|
let strategyBalance = liquidity?.strategyAtaBalance ?? 0n;
|
|
290
294
|
if (!liquidity) {
|
|
@@ -320,7 +324,7 @@ async function buildBaseToJlpRebalance(args) {
|
|
|
320
324
|
// Fetch STV on-chain for lend info
|
|
321
325
|
const stv = await (0, accounts_2.fetchStv)(connection, vaultId, pStvProgramId);
|
|
322
326
|
const [stvAddress] = (0, pda_2.findStvPda)(vaultId, pStvProgramId);
|
|
323
|
-
const [stvManagerRole] = (0, pda_2.
|
|
327
|
+
const [stvManagerRole] = (0, pda_2.findStvManagerRolePda)(stvAddress, manager, pStvProgramId);
|
|
324
328
|
// Build deposit_to_strategy remaining accounts (lend + auto-unroute)
|
|
325
329
|
const vaultInfo = {
|
|
326
330
|
address: stvAddress,
|
|
@@ -332,10 +336,12 @@ async function buildBaseToJlpRebalance(args) {
|
|
|
332
336
|
const depositCtx = await (0, remaining_accounts_1.buildDepositToStrategyContext)(connection, vaultInfo);
|
|
333
337
|
// Derive the JLPD strategy's position PDA in p-STV Core
|
|
334
338
|
const [jlpdStvPosition] = (0, pda_1.findStvPositionPda)(stvAddress, programId);
|
|
335
|
-
const vaultAta = findAta(baseMint, stvAddress, tokenProgram);
|
|
339
|
+
const vaultAta = (0, ata_1.findAta)(baseMint, stvAddress, tokenProgram);
|
|
340
|
+
const [configPda] = (0, pda_2.findConfigPda)(pStvProgramId);
|
|
336
341
|
const depositIx = (0, instructions_1.createDepositToStrategyIx)({
|
|
337
342
|
manager,
|
|
338
343
|
managerRole: stvManagerRole,
|
|
344
|
+
config: configPda,
|
|
339
345
|
stv: stvAddress,
|
|
340
346
|
vaultAta,
|
|
341
347
|
baseMint,
|
|
@@ -346,6 +352,7 @@ async function buildBaseToJlpRebalance(args) {
|
|
|
346
352
|
tokenProgram,
|
|
347
353
|
amount: new bn_js_1.default(deficit.toString()),
|
|
348
354
|
minShares: new bn_js_1.default(0),
|
|
355
|
+
protocolAumCount: depositCtx.protocolAumCount,
|
|
349
356
|
autoUnrouteCount: depositCtx.autoUnrouteCount,
|
|
350
357
|
remainingAccounts: depositCtx.remainingAccounts,
|
|
351
358
|
}, pStvProgramId);
|
|
@@ -391,17 +398,17 @@ async function buildJlpToBaseRebalance(args) {
|
|
|
391
398
|
sharesToWithdraw = positionShares;
|
|
392
399
|
}
|
|
393
400
|
// Build withdraw_from_strategy
|
|
394
|
-
const [stvManagerRole] = (0, pda_2.
|
|
401
|
+
const [stvManagerRole] = (0, pda_2.findStvManagerRolePda)(stvAddress, manager, pStvProgramId);
|
|
395
402
|
const [jlpdStvPosition] = (0, pda_1.findStvPositionPda)(stvAddress, programId);
|
|
396
|
-
const strategyBaseAta = findAta(baseMint, strategyState, tokenProgram);
|
|
397
|
-
const vaultAta = findAta(baseMint, stvAddress, tokenProgram);
|
|
403
|
+
const strategyBaseAta = (0, ata_1.findAta)(baseMint, strategyState, tokenProgram);
|
|
404
|
+
const vaultAta = (0, ata_1.findAta)(baseMint, stvAddress, tokenProgram);
|
|
398
405
|
// Build lend remaining_accounts for auto-sweep after withdraw
|
|
399
406
|
const lendAccounts = [];
|
|
400
407
|
const DEFAULT_PUBKEY = web3_js_1.PublicKey.default;
|
|
401
408
|
if (!stv.lendProgram.equals(DEFAULT_PUBKEY)) {
|
|
402
409
|
const [lendStrategyState] = (0, pda_3.findStrategyStatePda)(baseMint, stv.lendProgram);
|
|
403
410
|
const [lendPosition] = (0, pda_3.findStvPositionPda)(stvAddress, stv.lendProgram);
|
|
404
|
-
const lendBaseAta = findAta(baseMint, lendStrategyState, tokenProgram);
|
|
411
|
+
const lendBaseAta = (0, ata_1.findAta)(baseMint, lendStrategyState, tokenProgram);
|
|
405
412
|
lendAccounts.push(...(0, instructions_1.buildLendRemainingAccounts)({
|
|
406
413
|
lendProgram: stv.lendProgram,
|
|
407
414
|
lendStrategyState,
|
|
@@ -409,9 +416,11 @@ async function buildJlpToBaseRebalance(args) {
|
|
|
409
416
|
lendBaseAta,
|
|
410
417
|
}));
|
|
411
418
|
}
|
|
419
|
+
const [configPda] = (0, pda_2.findConfigPda)(pStvProgramId);
|
|
412
420
|
const withdrawIx = (0, instructions_1.createWithdrawFromStrategyIx)({
|
|
413
421
|
manager,
|
|
414
422
|
managerRole: stvManagerRole,
|
|
423
|
+
config: configPda,
|
|
415
424
|
stv: stvAddress,
|
|
416
425
|
vaultAta,
|
|
417
426
|
baseMint,
|
|
@@ -431,9 +440,9 @@ async function buildJlpToBaseRebalance(args) {
|
|
|
431
440
|
if (!stv.lendProgram.equals(DEFAULT_PUBKEY) && jupPool) {
|
|
432
441
|
const lendProgramId = stv.lendProgram;
|
|
433
442
|
const [lendStrategyState] = (0, pda_3.findStrategyStatePda)(baseMint, lendProgramId);
|
|
434
|
-
const [lendManagerRole] = (0, pda_3.
|
|
435
|
-
const lendBaseAta = findAta(baseMint, lendStrategyState, tokenProgram);
|
|
436
|
-
const lendFtokenAta = findAta(jupPool.fTokenMint, lendStrategyState, tokenProgram);
|
|
443
|
+
const [lendManagerRole] = (0, pda_3.findLendManagerRolePda)(lendStrategyState, manager, lendProgramId);
|
|
444
|
+
const lendBaseAta = (0, ata_1.findAta)(baseMint, lendStrategyState, tokenProgram);
|
|
445
|
+
const lendFtokenAta = (0, ata_1.findAta)(jupPool.fTokenMint, lendStrategyState, tokenProgram);
|
|
437
446
|
const JUP_LEND_PROG = new web3_js_1.PublicKey("jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9");
|
|
438
447
|
const jupLendAccounts = [
|
|
439
448
|
...(0, jupiter_lend_1.buildJupLendDepositAccounts)(jupPool, lendStrategyState, lendBaseAta, lendFtokenAta).map((a) => ({ ...a, isSigner: false })),
|
|
@@ -462,4 +471,3 @@ async function buildJlpToBaseRebalance(args) {
|
|
|
462
471
|
: "Swap JLP → base → withdraw to vault",
|
|
463
472
|
};
|
|
464
473
|
}
|
|
465
|
-
//# sourceMappingURL=swap-jlp.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import BN from "bn.js";
|
|
3
3
|
import type { StrategyStateHeader } from "../common/strategy-interface";
|
|
4
|
-
/** JlpdConfig global config (
|
|
4
|
+
/** JlpdConfig global config (392 bytes) */
|
|
5
5
|
export interface JlpdConfig {
|
|
6
6
|
admin: PublicKey;
|
|
7
7
|
jlpMint: PublicKey;
|
|
@@ -11,9 +11,11 @@ export interface JlpdConfig {
|
|
|
11
11
|
jlpSlippageBps: number;
|
|
12
12
|
version: number;
|
|
13
13
|
bump: number;
|
|
14
|
+
/** JLP loaned to the JLPD Lend Adapter (not in vault ATA). Total JLP = vault_jlp_ata + jlpEarnAmount. */
|
|
15
|
+
jlpEarnAmount: BN;
|
|
16
|
+
/** Whitelisted adapter program. PublicKey.default = no adapter. */
|
|
17
|
+
jlpAdapterProgram: PublicKey;
|
|
14
18
|
}
|
|
15
|
-
/** @deprecated Use JlpdConfig instead */
|
|
16
|
-
export type JLPVault = JlpdConfig;
|
|
17
19
|
/** ManagerRole PDA (80 bytes) — grants manager access to rebalance operations */
|
|
18
20
|
export interface ManagerRole {
|
|
19
21
|
config: PublicKey;
|
|
@@ -53,4 +55,3 @@ export interface ManagerRemovedEvent {
|
|
|
53
55
|
config: PublicKey;
|
|
54
56
|
manager: PublicKey;
|
|
55
57
|
}
|
|
56
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,17 +1,90 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import BN from "bn.js";
|
|
3
|
+
import type { SolanaConnection } from "../common/connection";
|
|
3
4
|
import { GlobalConfig, Stv, WithdrawRequest, ManagerRole } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* GlobalConfig — singleton protocol registry. Total 56 bytes.
|
|
7
|
+
*
|
|
8
|
+
* Layout (offsets include the 8-byte discriminator):
|
|
9
|
+
* [ 0.. 8] discriminator (sha256("account:GlobalConfig")[..8])
|
|
10
|
+
* [ 8.. 40] admin Pubkey
|
|
11
|
+
* [ 40.. 48] nextVaultId u64
|
|
12
|
+
* [ 48.. 50] flags u16 (CFG_FLAG_*)
|
|
13
|
+
* [ 50.. 51] version u8
|
|
14
|
+
* [ 51.. 52] bump u8
|
|
15
|
+
* [ 52.. 56] _padding [u8; 4]
|
|
16
|
+
*/
|
|
4
17
|
export declare function deserializeGlobalConfig(data: Buffer): GlobalConfig;
|
|
18
|
+
/**
|
|
19
|
+
* STV — per-vault state. Total 664 bytes.
|
|
20
|
+
*
|
|
21
|
+
* Layout (offsets include the 8-byte discriminator):
|
|
22
|
+
* [ 0.. 8] discriminator (sha256("account:Stv")[..8])
|
|
23
|
+
* [ 8.. 40] baseMint Pubkey
|
|
24
|
+
* [ 40.. 72] evMint Pubkey
|
|
25
|
+
* [ 72..104] strategy Pubkey (legacy single-strategy slot)
|
|
26
|
+
* [104..136] feeReceiver Pubkey
|
|
27
|
+
* [136..168] lendProgram Pubkey (zero pubkey if lend not opted-in)
|
|
28
|
+
* [168..488] strategies[10] [Pubkey; 10] (whitelisted strategy programs)
|
|
29
|
+
* [488..496] vaultId u64
|
|
30
|
+
* [496..504] reservedBase u64 (base reserved for pending claims)
|
|
31
|
+
* [504..512] requestedBase u64 (base requested via request_withdraw)
|
|
32
|
+
* [512..520] vaultCapacity u64 (0 = uncapped)
|
|
33
|
+
* [520..528] minDeposit u64
|
|
34
|
+
* [528..536] hwm u64 (high-water mark for perf fees)
|
|
35
|
+
* [536..544] lastFeeTs u64 (last fee crystallization timestamp)
|
|
36
|
+
* [544..552] epochPps u64 (locked PPS for current epoch claims)
|
|
37
|
+
* [552..560] lastNav u64 (snapshot for the rate-limit window)
|
|
38
|
+
* [560..568] dailyWithdrawnBase u64 (rate-limit accumulator)
|
|
39
|
+
* [568..572] nextEpochTs u32
|
|
40
|
+
* [572..576] epochSec u32
|
|
41
|
+
* [576..580] currentEpochId u32
|
|
42
|
+
* [580..584] pendingWithdrawals u32
|
|
43
|
+
* [584..588] withdrawWindowStart u32
|
|
44
|
+
* [588..590] mgmtFeeBps u16
|
|
45
|
+
* [590..592] perfFeeBps u16
|
|
46
|
+
* [592..594] flags u16 (FLAG_PAUSED / DEPOSITS_DISABLED / …)
|
|
47
|
+
* [594..596] dailyWithdrawLimitBps u16
|
|
48
|
+
* [596..597] strategyCount u8
|
|
49
|
+
* [597..598] version u8
|
|
50
|
+
* [598..599] bump u8
|
|
51
|
+
* [599..600] _padding [u8; 1]
|
|
52
|
+
* [600..664] _reserved [u8; 64]
|
|
53
|
+
*/
|
|
5
54
|
export declare function deserializeStv(data: Buffer): Stv;
|
|
55
|
+
/**
|
|
56
|
+
* WithdrawRequest — per-(STV, user, epoch) withdraw escrow. Total 168 bytes.
|
|
57
|
+
*
|
|
58
|
+
* Layout (offsets include the 8-byte discriminator):
|
|
59
|
+
* [ 0.. 8] discriminator (sha256("account:WithdrawRequest")[..8])
|
|
60
|
+
* [ 8.. 40] stv Pubkey
|
|
61
|
+
* [ 40.. 72] user Pubkey
|
|
62
|
+
* [ 72.. 80] shares u64
|
|
63
|
+
* [ 80.. 88] pps u64 (locked at process_epoch time)
|
|
64
|
+
* [ 88.. 92] epochId u32
|
|
65
|
+
* [ 92.. 96] claimAvailableAfter u32 (unix seconds)
|
|
66
|
+
* [ 96.. 97] bump u8
|
|
67
|
+
* [ 97..168] _reserved [u8; 71]
|
|
68
|
+
*/
|
|
6
69
|
export declare function deserializeWithdrawRequest(data: Buffer): WithdrawRequest;
|
|
70
|
+
/**
|
|
71
|
+
* ManagerRole — per-(STV, manager) authorization record. Total 80 bytes.
|
|
72
|
+
*
|
|
73
|
+
* Layout (offsets include the 8-byte discriminator):
|
|
74
|
+
* [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
|
|
75
|
+
* shared with elemental-lend + jlpd-strategy)
|
|
76
|
+
* [ 8.. 40] stv Pubkey
|
|
77
|
+
* [ 40.. 72] manager Pubkey
|
|
78
|
+
* [ 72.. 73] bump u8
|
|
79
|
+
* [ 73.. 80] _padding [u8; 7]
|
|
80
|
+
*/
|
|
7
81
|
export declare function deserializeManagerRole(data: Buffer): ManagerRole;
|
|
8
|
-
export declare function fetchGlobalConfig(connection:
|
|
9
|
-
export declare function fetchStv(connection:
|
|
10
|
-
export declare function fetchStvByAddress(connection:
|
|
11
|
-
export declare function fetchWithdrawRequest(connection:
|
|
12
|
-
export declare function fetchWithdrawRequestByAddress(connection:
|
|
13
|
-
export declare function fetchAllStvs(connection:
|
|
14
|
-
export declare function fetchPendingWithdrawRequests(connection:
|
|
15
|
-
export declare function fetchManagerRole(connection:
|
|
16
|
-
export declare function fetchManagersForStv(connection:
|
|
17
|
-
//# sourceMappingURL=accounts.d.ts.map
|
|
82
|
+
export declare function fetchGlobalConfig(connection: SolanaConnection, programId?: PublicKey): Promise<GlobalConfig>;
|
|
83
|
+
export declare function fetchStv(connection: SolanaConnection, vaultId: number | BN, programId?: PublicKey): Promise<Stv>;
|
|
84
|
+
export declare function fetchStvByAddress(connection: SolanaConnection, address: PublicKey): Promise<Stv>;
|
|
85
|
+
export declare function fetchWithdrawRequest(connection: SolanaConnection, stv: PublicKey, user: PublicKey, epochId: number, programId?: PublicKey): Promise<WithdrawRequest>;
|
|
86
|
+
export declare function fetchWithdrawRequestByAddress(connection: SolanaConnection, address: PublicKey): Promise<WithdrawRequest>;
|
|
87
|
+
export declare function fetchAllStvs(connection: SolanaConnection, programId?: PublicKey): Promise<[PublicKey, Stv][]>;
|
|
88
|
+
export declare function fetchPendingWithdrawRequests(connection: SolanaConnection, stv: PublicKey, epochId: number, programId?: PublicKey): Promise<[PublicKey, WithdrawRequest][]>;
|
|
89
|
+
export declare function fetchManagerRole(connection: SolanaConnection, stv: PublicKey, manager: PublicKey, programId?: PublicKey): Promise<ManagerRole | null>;
|
|
90
|
+
export declare function fetchManagersForStv(connection: SolanaConnection, stv: PublicKey, programId?: PublicKey): Promise<[PublicKey, ManagerRole][]>;
|
|
@@ -18,7 +18,25 @@ const constants_1 = require("./constants");
|
|
|
18
18
|
const pda_1 = require("./pda");
|
|
19
19
|
// ---------------------------------------------------------------------------
|
|
20
20
|
// Deserialization
|
|
21
|
+
//
|
|
22
|
+
// All offsets below INCLUDE the 8-byte Anchor account discriminator. Layout
|
|
23
|
+
// blocks above each parser show the field map; the helpers in
|
|
24
|
+
// `common/buffer.ts` validate that `offset + width <= data.length` so a
|
|
25
|
+
// drift between this file and the on-chain layout fails loudly with a
|
|
26
|
+
// `RangeError` rather than returning garbage.
|
|
21
27
|
// ---------------------------------------------------------------------------
|
|
28
|
+
/**
|
|
29
|
+
* GlobalConfig — singleton protocol registry. Total 56 bytes.
|
|
30
|
+
*
|
|
31
|
+
* Layout (offsets include the 8-byte discriminator):
|
|
32
|
+
* [ 0.. 8] discriminator (sha256("account:GlobalConfig")[..8])
|
|
33
|
+
* [ 8.. 40] admin Pubkey
|
|
34
|
+
* [ 40.. 48] nextVaultId u64
|
|
35
|
+
* [ 48.. 50] flags u16 (CFG_FLAG_*)
|
|
36
|
+
* [ 50.. 51] version u8
|
|
37
|
+
* [ 51.. 52] bump u8
|
|
38
|
+
* [ 52.. 56] _padding [u8; 4]
|
|
39
|
+
*/
|
|
22
40
|
function deserializeGlobalConfig(data) {
|
|
23
41
|
if (data.length < constants_1.GLOBAL_CONFIG_SIZE) {
|
|
24
42
|
throw new Error(`GlobalConfig data too short: ${data.length} < ${constants_1.GLOBAL_CONFIG_SIZE}`);
|
|
@@ -35,6 +53,42 @@ function deserializeGlobalConfig(data) {
|
|
|
35
53
|
bump: (0, buffer_1.readU8)(data, 51),
|
|
36
54
|
};
|
|
37
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* STV — per-vault state. Total 664 bytes.
|
|
58
|
+
*
|
|
59
|
+
* Layout (offsets include the 8-byte discriminator):
|
|
60
|
+
* [ 0.. 8] discriminator (sha256("account:Stv")[..8])
|
|
61
|
+
* [ 8.. 40] baseMint Pubkey
|
|
62
|
+
* [ 40.. 72] evMint Pubkey
|
|
63
|
+
* [ 72..104] strategy Pubkey (legacy single-strategy slot)
|
|
64
|
+
* [104..136] feeReceiver Pubkey
|
|
65
|
+
* [136..168] lendProgram Pubkey (zero pubkey if lend not opted-in)
|
|
66
|
+
* [168..488] strategies[10] [Pubkey; 10] (whitelisted strategy programs)
|
|
67
|
+
* [488..496] vaultId u64
|
|
68
|
+
* [496..504] reservedBase u64 (base reserved for pending claims)
|
|
69
|
+
* [504..512] requestedBase u64 (base requested via request_withdraw)
|
|
70
|
+
* [512..520] vaultCapacity u64 (0 = uncapped)
|
|
71
|
+
* [520..528] minDeposit u64
|
|
72
|
+
* [528..536] hwm u64 (high-water mark for perf fees)
|
|
73
|
+
* [536..544] lastFeeTs u64 (last fee crystallization timestamp)
|
|
74
|
+
* [544..552] epochPps u64 (locked PPS for current epoch claims)
|
|
75
|
+
* [552..560] lastNav u64 (snapshot for the rate-limit window)
|
|
76
|
+
* [560..568] dailyWithdrawnBase u64 (rate-limit accumulator)
|
|
77
|
+
* [568..572] nextEpochTs u32
|
|
78
|
+
* [572..576] epochSec u32
|
|
79
|
+
* [576..580] currentEpochId u32
|
|
80
|
+
* [580..584] pendingWithdrawals u32
|
|
81
|
+
* [584..588] withdrawWindowStart u32
|
|
82
|
+
* [588..590] mgmtFeeBps u16
|
|
83
|
+
* [590..592] perfFeeBps u16
|
|
84
|
+
* [592..594] flags u16 (FLAG_PAUSED / DEPOSITS_DISABLED / …)
|
|
85
|
+
* [594..596] dailyWithdrawLimitBps u16
|
|
86
|
+
* [596..597] strategyCount u8
|
|
87
|
+
* [597..598] version u8
|
|
88
|
+
* [598..599] bump u8
|
|
89
|
+
* [599..600] _padding [u8; 1]
|
|
90
|
+
* [600..664] _reserved [u8; 64]
|
|
91
|
+
*/
|
|
38
92
|
function deserializeStv(data) {
|
|
39
93
|
if (data.length < constants_1.STV_SIZE) {
|
|
40
94
|
throw new Error(`Stv data too short: ${data.length} < ${constants_1.STV_SIZE}`);
|
|
@@ -44,7 +98,7 @@ function deserializeStv(data) {
|
|
|
44
98
|
throw new Error(`Invalid Stv discriminator`);
|
|
45
99
|
}
|
|
46
100
|
const strategies = [];
|
|
47
|
-
for (let i = 0; i <
|
|
101
|
+
for (let i = 0; i < constants_1.MAX_STRATEGIES; i++) {
|
|
48
102
|
strategies.push((0, buffer_1.readPubkey)(data, 168 + i * 32));
|
|
49
103
|
}
|
|
50
104
|
return {
|
|
@@ -78,6 +132,20 @@ function deserializeStv(data) {
|
|
|
78
132
|
bump: (0, buffer_1.readU8)(data, 598),
|
|
79
133
|
};
|
|
80
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* WithdrawRequest — per-(STV, user, epoch) withdraw escrow. Total 168 bytes.
|
|
137
|
+
*
|
|
138
|
+
* Layout (offsets include the 8-byte discriminator):
|
|
139
|
+
* [ 0.. 8] discriminator (sha256("account:WithdrawRequest")[..8])
|
|
140
|
+
* [ 8.. 40] stv Pubkey
|
|
141
|
+
* [ 40.. 72] user Pubkey
|
|
142
|
+
* [ 72.. 80] shares u64
|
|
143
|
+
* [ 80.. 88] pps u64 (locked at process_epoch time)
|
|
144
|
+
* [ 88.. 92] epochId u32
|
|
145
|
+
* [ 92.. 96] claimAvailableAfter u32 (unix seconds)
|
|
146
|
+
* [ 96.. 97] bump u8
|
|
147
|
+
* [ 97..168] _reserved [u8; 71]
|
|
148
|
+
*/
|
|
81
149
|
function deserializeWithdrawRequest(data) {
|
|
82
150
|
if (data.length < constants_1.WITHDRAW_REQUEST_SIZE) {
|
|
83
151
|
throw new Error(`WithdrawRequest data too short: ${data.length} < ${constants_1.WITHDRAW_REQUEST_SIZE}`);
|
|
@@ -96,6 +164,17 @@ function deserializeWithdrawRequest(data) {
|
|
|
96
164
|
bump: (0, buffer_1.readU8)(data, 96),
|
|
97
165
|
};
|
|
98
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* ManagerRole — per-(STV, manager) authorization record. Total 80 bytes.
|
|
169
|
+
*
|
|
170
|
+
* Layout (offsets include the 8-byte discriminator):
|
|
171
|
+
* [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
|
|
172
|
+
* shared with elemental-lend + jlpd-strategy)
|
|
173
|
+
* [ 8.. 40] stv Pubkey
|
|
174
|
+
* [ 40.. 72] manager Pubkey
|
|
175
|
+
* [ 72.. 73] bump u8
|
|
176
|
+
* [ 73.. 80] _padding [u8; 7]
|
|
177
|
+
*/
|
|
99
178
|
function deserializeManagerRole(data) {
|
|
100
179
|
if (data.length < constants_1.MANAGER_ROLE_SIZE) {
|
|
101
180
|
throw new Error(`ManagerRole data too short: ${data.length} < ${constants_1.MANAGER_ROLE_SIZE}`);
|
|
@@ -165,14 +244,14 @@ async function fetchPendingWithdrawRequests(connection, stv, epochId, programId
|
|
|
165
244
|
filters: [
|
|
166
245
|
{ dataSize: constants_1.WITHDRAW_REQUEST_SIZE },
|
|
167
246
|
{ memcmp: { offset: 0, bytes: constants_1.DISC_WITHDRAW_REQUEST.toString("base64"), encoding: "base64" } },
|
|
168
|
-
{ memcmp: { offset: 8, bytes: stv.
|
|
247
|
+
{ memcmp: { offset: 8, bytes: stv.toBuffer().toString("base64"), encoding: "base64" } },
|
|
169
248
|
{ memcmp: { offset: 88, bytes: epochBuf.toString("base64"), encoding: "base64" } },
|
|
170
249
|
],
|
|
171
250
|
});
|
|
172
251
|
return accounts.map((a) => [a.pubkey, deserializeWithdrawRequest(a.account.data)]);
|
|
173
252
|
}
|
|
174
253
|
async function fetchManagerRole(connection, stv, manager, programId = constants_1.PROGRAM_ID) {
|
|
175
|
-
const [pda] = (0, pda_1.
|
|
254
|
+
const [pda] = (0, pda_1.findStvManagerRolePda)(stv, manager, programId);
|
|
176
255
|
const info = await connection.getAccountInfo(pda);
|
|
177
256
|
if (!info)
|
|
178
257
|
return null;
|
|
@@ -183,9 +262,8 @@ async function fetchManagersForStv(connection, stv, programId = constants_1.PROG
|
|
|
183
262
|
filters: [
|
|
184
263
|
{ dataSize: constants_1.MANAGER_ROLE_SIZE },
|
|
185
264
|
{ memcmp: { offset: 0, bytes: constants_1.DISC_MANAGER_ROLE.toString("base64"), encoding: "base64" } },
|
|
186
|
-
{ memcmp: { offset: 8, bytes: stv.
|
|
265
|
+
{ memcmp: { offset: 8, bytes: stv.toBuffer().toString("base64"), encoding: "base64" } },
|
|
187
266
|
],
|
|
188
267
|
});
|
|
189
268
|
return accounts.map((a) => [a.pubkey, deserializeManagerRole(a.account.data)]);
|
|
190
269
|
}
|
|
191
|
-
//# sourceMappingURL=accounts.js.map
|