@elemental-stv-core/sdk 0.11.0 → 0.12.3

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.
@@ -23,7 +23,8 @@ import { LendStrategyState, ManagerRole } from "./types";
23
23
  * [112..144] admin Pubkey
24
24
  * [144..464] protocols[10] [Pubkey; 10] (registered protocol accounts)
25
25
  * [464..465] protocolCount u8
26
- * [465..472] _padding [u8; 7]
26
+ * [465..466] managerCount u8
27
+ * [466..472] _padding [u8; 6]
27
28
  * [472..536] _reserved [u8; 64]
28
29
  */
29
30
  export declare function deserializeLendStrategyState(data: Buffer): LendStrategyState;
@@ -45,7 +45,8 @@ const pda_1 = require("./pda");
45
45
  * [112..144] admin Pubkey
46
46
  * [144..464] protocols[10] [Pubkey; 10] (registered protocol accounts)
47
47
  * [464..465] protocolCount u8
48
- * [465..472] _padding [u8; 7]
48
+ * [465..466] managerCount u8
49
+ * [466..472] _padding [u8; 6]
49
50
  * [472..536] _reserved [u8; 64]
50
51
  */
51
52
  function deserializeLendStrategyState(data) {
@@ -57,6 +58,7 @@ function deserializeLendStrategyState(data) {
57
58
  throw new Error(`Invalid LendStrategyState discriminator`);
58
59
  }
59
60
  const protocolCount = (0, buffer_1.readU8)(data, 464);
61
+ const managerCount = (0, buffer_1.readU8)(data, 465);
60
62
  const protocols = [];
61
63
  for (let i = 0; i < protocolCount; i++) {
62
64
  protocols.push((0, buffer_1.readPubkey)(data, 144 + i * 32));
@@ -76,6 +78,7 @@ function deserializeLendStrategyState(data) {
76
78
  admin: (0, buffer_1.readPubkey)(data, 112),
77
79
  protocols,
78
80
  protocolCount,
81
+ managerCount,
79
82
  };
80
83
  }
81
84
  /**
@@ -5,16 +5,14 @@ export declare const POSITION_SEED: Buffer<ArrayBuffer>;
5
5
  export declare const MANAGER_SEED: Buffer<ArrayBuffer>;
6
6
  export { DISC_STRATEGY_STATE, DISC_STV_POSITION, DISC_MANAGER_ROLE, } from "../common/constants";
7
7
  export declare const IX_INIT_OR_UPDATE_STRATEGY: Buffer<ArrayBuffer>;
8
- export declare const IX_INIT_POSITION: Buffer<ArrayBuffer>;
9
- export declare const IX_DEPOSIT: Buffer<ArrayBuffer>;
10
- export declare const IX_WITHDRAW: Buffer<ArrayBuffer>;
11
- export declare const IX_UPDATE_AUM: Buffer<ArrayBuffer>;
8
+ export declare const IX_CLOSE_STRATEGY: Buffer<ArrayBuffer>;
9
+ export declare const IX_RESET_STRATEGY: Buffer<ArrayBuffer>;
10
+ export declare const IX_ADD_MANAGER: Buffer<ArrayBuffer>;
11
+ export declare const IX_REMOVE_MANAGER: Buffer<ArrayBuffer>;
12
12
  export declare const IX_KVAULT_DEPOSIT: Buffer<ArrayBuffer>;
13
13
  export declare const IX_KVAULT_WITHDRAW: Buffer<ArrayBuffer>;
14
14
  export declare const IX_JUP_LEND_DEPOSIT: Buffer<ArrayBuffer>;
15
15
  export declare const IX_JUP_LEND_WITHDRAW: Buffer<ArrayBuffer>;
16
- export declare const IX_ADD_MANAGER: Buffer<ArrayBuffer>;
17
- export declare const IX_REMOVE_MANAGER: Buffer<ArrayBuffer>;
18
16
  export declare const STRATEGY_STATE_SIZE = 536;
19
17
  export declare const STV_POSITION_SIZE = 120;
20
18
  export declare const MANAGER_ROLE_SIZE = 80;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PPS_DECIMALS = exports.JUP_LEND_EARN_PROGRAM = exports.KLEND_PROGRAM = exports.KAMINO_VAULT_PROGRAM = exports.MAX_PROTOCOLS = exports.FLAG_PAUSED = exports.MANAGER_ROLE_SIZE = exports.STV_POSITION_SIZE = exports.STRATEGY_STATE_SIZE = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_JUP_LEND_WITHDRAW = exports.IX_JUP_LEND_DEPOSIT = exports.IX_KVAULT_WITHDRAW = exports.IX_KVAULT_DEPOSIT = exports.IX_UPDATE_AUM = exports.IX_WITHDRAW = exports.IX_DEPOSIT = exports.IX_INIT_POSITION = exports.IX_INIT_OR_UPDATE_STRATEGY = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.MANAGER_SEED = exports.POSITION_SEED = exports.STRATEGY_STATE_SEED = exports.PROGRAM_ID = void 0;
3
+ exports.PPS_DECIMALS = exports.JUP_LEND_EARN_PROGRAM = exports.KLEND_PROGRAM = exports.KAMINO_VAULT_PROGRAM = exports.MAX_PROTOCOLS = exports.FLAG_PAUSED = exports.MANAGER_ROLE_SIZE = exports.STV_POSITION_SIZE = exports.STRATEGY_STATE_SIZE = exports.IX_JUP_LEND_WITHDRAW = exports.IX_JUP_LEND_DEPOSIT = exports.IX_KVAULT_WITHDRAW = exports.IX_KVAULT_DEPOSIT = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_RESET_STRATEGY = exports.IX_CLOSE_STRATEGY = exports.IX_INIT_OR_UPDATE_STRATEGY = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.MANAGER_SEED = exports.POSITION_SEED = exports.STRATEGY_STATE_SEED = exports.PROGRAM_ID = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  exports.PROGRAM_ID = new web3_js_1.PublicKey("EHaGVh7p6xSxZsq4CcEEZhnV5adDvWg1gS1Rc5rLiBpC");
6
6
  // PDA Seeds
@@ -13,19 +13,24 @@ Object.defineProperty(exports, "DISC_STRATEGY_STATE", { enumerable: true, get: f
13
13
  Object.defineProperty(exports, "DISC_STV_POSITION", { enumerable: true, get: function () { return constants_1.DISC_STV_POSITION; } });
14
14
  Object.defineProperty(exports, "DISC_MANAGER_ROLE", { enumerable: true, get: function () { return constants_1.DISC_MANAGER_ROLE; } });
15
15
  // Instruction discriminators (Anchor 8-byte)
16
+ // --- Admin instructions ---
16
17
  exports.IX_INIT_OR_UPDATE_STRATEGY = Buffer.from([221, 4, 60, 139, 83, 148, 116, 247]);
17
- exports.IX_INIT_POSITION = Buffer.from([197, 20, 10, 1, 97, 160, 177, 91]);
18
- exports.IX_DEPOSIT = Buffer.from([242, 35, 198, 137, 82, 225, 242, 182]);
19
- exports.IX_WITHDRAW = Buffer.from([183, 18, 70, 156, 148, 109, 161, 34]);
20
- exports.IX_UPDATE_AUM = Buffer.from([162, 40, 227, 16, 84, 169, 182, 185]);
21
- exports.IX_KVAULT_DEPOSIT = Buffer.from([240, 233, 97, 12, 52, 70, 230, 243]);
22
- exports.IX_KVAULT_WITHDRAW = Buffer.from([186, 254, 50, 47, 123, 146, 242, 216]);
23
- exports.IX_JUP_LEND_DEPOSIT = Buffer.from([87, 129, 182, 64, 170, 11, 223, 59]);
24
- exports.IX_JUP_LEND_WITHDRAW = Buffer.from([46, 152, 191, 164, 24, 135, 89, 64]);
18
+ // sha256("global:close_strategy")[..8] verified against elemental_lend.json IDL
19
+ exports.IX_CLOSE_STRATEGY = Buffer.from([56, 247, 170, 246, 89, 221, 134, 200]);
20
+ // sha256("global:reset_strategy")[..8] verified against elemental_lend.json IDL
21
+ exports.IX_RESET_STRATEGY = Buffer.from([127, 28, 155, 41, 137, 170, 16, 39]);
25
22
  // sha256("global:add_manager")[..8]
26
23
  exports.IX_ADD_MANAGER = Buffer.from([0x7d, 0x26, 0xc0, 0xd4, 0x65, 0x5b, 0xb3, 0x10]);
27
24
  // sha256("global:remove_manager")[..8]
28
25
  exports.IX_REMOVE_MANAGER = Buffer.from([0x96, 0x37, 0x9d, 0x4d, 0x80, 0x94, 0x07, 0x0f]);
26
+ // --- Protocol instructions (manager-only via ManagerRole PDA) ---
27
+ exports.IX_KVAULT_DEPOSIT = Buffer.from([240, 233, 97, 12, 52, 70, 230, 243]);
28
+ exports.IX_KVAULT_WITHDRAW = Buffer.from([186, 254, 50, 47, 123, 146, 242, 216]);
29
+ exports.IX_JUP_LEND_DEPOSIT = Buffer.from([87, 129, 182, 64, 170, 11, 223, 59]);
30
+ exports.IX_JUP_LEND_WITHDRAW = Buffer.from([46, 152, 191, 164, 24, 135, 89, 64]);
31
+ // NOTE: The CPI-facing discriminators (init_position, deposit, withdraw, update_aum)
32
+ // are invoked by p-stv-core directly via remaining_accounts; clients do not call them
33
+ // standalone and they are not exported from this SDK module.
29
34
  // Account sizes
30
35
  exports.STRATEGY_STATE_SIZE = 536;
31
36
  exports.STV_POSITION_SIZE = 120;
@@ -22,6 +22,22 @@ export interface InitOrUpdateStrategyArgs {
22
22
  remainingAccounts?: AccountMeta[];
23
23
  }
24
24
  export declare function createInitOrUpdateStrategyIx(args: InitOrUpdateStrategyArgs, programId?: PublicKey): TransactionInstruction;
25
+ export interface CloseStrategyArgs {
26
+ admin: PublicKey;
27
+ payer: PublicKey;
28
+ strategyState: PublicKey;
29
+ strategyBaseAta: PublicKey;
30
+ baseMint: PublicKey;
31
+ tokenProgram: PublicKey;
32
+ /** Optional: required when strategy_base_ata has residual balance to drain. */
33
+ remainingAccounts?: AccountMeta[];
34
+ }
35
+ export declare function createCloseStrategyIx(args: CloseStrategyArgs, programId?: PublicKey): TransactionInstruction;
36
+ export interface ResetStrategyArgs {
37
+ admin: PublicKey;
38
+ strategyState: PublicKey;
39
+ }
40
+ export declare function createResetStrategyIx(args: ResetStrategyArgs, programId?: PublicKey): TransactionInstruction;
25
41
  export interface KvaultDepositArgs {
26
42
  manager: PublicKey;
27
43
  strategyState: PublicKey;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createInitOrUpdateStrategyIx = createInitOrUpdateStrategyIx;
4
+ exports.createCloseStrategyIx = createCloseStrategyIx;
5
+ exports.createResetStrategyIx = createResetStrategyIx;
4
6
  exports.createKvaultDepositIx = createKvaultDepositIx;
5
7
  exports.createKvaultWithdrawIx = createKvaultWithdrawIx;
6
8
  exports.createJupLendDepositIx = createJupLendDepositIx;
@@ -89,6 +91,33 @@ function createInitOrUpdateStrategyIx(args, programId = constants_1.PROGRAM_ID)
89
91
  data,
90
92
  });
91
93
  }
94
+ function createCloseStrategyIx(args, programId = constants_1.PROGRAM_ID) {
95
+ const { admin, payer, strategyState, strategyBaseAta, baseMint, tokenProgram, remainingAccounts = [] } = args;
96
+ return new web3_js_1.TransactionInstruction({
97
+ keys: [
98
+ { pubkey: admin, isSigner: true, isWritable: false },
99
+ { pubkey: payer, isSigner: false, isWritable: true },
100
+ { pubkey: strategyState, isSigner: false, isWritable: true },
101
+ { pubkey: strategyBaseAta, isSigner: false, isWritable: true },
102
+ { pubkey: baseMint, isSigner: false, isWritable: false },
103
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
104
+ ...remainingAccounts,
105
+ ],
106
+ programId,
107
+ data: constants_1.IX_CLOSE_STRATEGY,
108
+ });
109
+ }
110
+ function createResetStrategyIx(args, programId = constants_1.PROGRAM_ID) {
111
+ const { admin, strategyState } = args;
112
+ return new web3_js_1.TransactionInstruction({
113
+ keys: [
114
+ { pubkey: admin, isSigner: true, isWritable: false },
115
+ { pubkey: strategyState, isSigner: false, isWritable: true },
116
+ ],
117
+ programId,
118
+ data: constants_1.IX_RESET_STRATEGY,
119
+ });
120
+ }
92
121
  function createKvaultDepositIx(args, programId = constants_1.PROGRAM_ID) {
93
122
  const { manager, strategyState, managerRole, depositorBaseAta, depositorSharesAta, amount, minOut = 0, remainingAccounts } = args;
94
123
  const data = [...constants_1.IX_KVAULT_DEPOSIT];
@@ -185,7 +214,9 @@ function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
185
214
  keys: [
186
215
  { pubkey: admin, isSigner: true, isWritable: false },
187
216
  { pubkey: payer, isSigner: false, isWritable: true },
188
- { pubkey: strategyState, isSigner: false, isWritable: false },
217
+ // strategy_state is #[account(mut)] in remove_manager.rs:17 the handler
218
+ // calls load_mut() and decrements manager_count at line 56.
219
+ { pubkey: strategyState, isSigner: false, isWritable: true },
189
220
  { pubkey: managerRole, isSigner: false, isWritable: true },
190
221
  ],
191
222
  programId,
@@ -1,11 +1,12 @@
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
- /** Full StrategyState for Elemental Lend (472 bytes) */
4
+ /** Full StrategyState for Elemental Lend (536 bytes) */
5
5
  export interface LendStrategyState extends StrategyStateHeader {
6
6
  admin: PublicKey;
7
7
  protocols: PublicKey[];
8
8
  protocolCount: number;
9
+ managerCount: number;
9
10
  }
10
11
  /** ManagerRole account — authorizes a manager for protocol instructions */
11
12
  export interface ManagerRole {
@@ -4,7 +4,7 @@ import type { SolanaConnection } from "../common/connection";
4
4
  import { JlpdConfig, ManagerRole, JlpStrategyState } from "./types";
5
5
  /**
6
6
  * JlpdConfig — singleton config shared across all five base-asset strategies.
7
- * Total 272 bytes.
7
+ * Total 392 bytes.
8
8
  *
9
9
  * Layout (offsets include the 8-byte discriminator):
10
10
  * [ 0.. 8] discriminator (sha256("account:JlpdConfig")[..8])
@@ -16,7 +16,11 @@ import { JlpdConfig, ManagerRole, JlpStrategyState } from "./types";
16
16
  * [242..244] jlpSlippageBps u16 (max slippage on swap_jlp)
17
17
  * [244..245] version u8
18
18
  * [245..246] bump u8
19
- * [246..272] _reserved [u8; 26]
19
+ * [246..248] _padding [u8; 2]
20
+ * [248..256] jlpEarnAmount u64
21
+ * [256..288] jlpAdapterProgram Pubkey
22
+ * [288..320] vaultJlpAta Pubkey (canonical vault JLP ATA, carved from _reserved)
23
+ * [320..392] _reserved [u8; 72]
20
24
  */
21
25
  export declare function deserializeJlpdConfig(data: Buffer): JlpdConfig;
22
26
  /**
@@ -24,7 +24,7 @@ const pda_1 = require("./pda");
24
24
  // ---------------------------------------------------------------------------
25
25
  /**
26
26
  * JlpdConfig — singleton config shared across all five base-asset strategies.
27
- * Total 272 bytes.
27
+ * Total 392 bytes.
28
28
  *
29
29
  * Layout (offsets include the 8-byte discriminator):
30
30
  * [ 0.. 8] discriminator (sha256("account:JlpdConfig")[..8])
@@ -36,7 +36,11 @@ const pda_1 = require("./pda");
36
36
  * [242..244] jlpSlippageBps u16 (max slippage on swap_jlp)
37
37
  * [244..245] version u8
38
38
  * [245..246] bump u8
39
- * [246..272] _reserved [u8; 26]
39
+ * [246..248] _padding [u8; 2]
40
+ * [248..256] jlpEarnAmount u64
41
+ * [256..288] jlpAdapterProgram Pubkey
42
+ * [288..320] vaultJlpAta Pubkey (canonical vault JLP ATA, carved from _reserved)
43
+ * [320..392] _reserved [u8; 72]
40
44
  */
41
45
  function deserializeJlpdConfig(data) {
42
46
  if (data.length < constants_1.JLPD_CONFIG_SIZE) {
@@ -61,6 +65,7 @@ function deserializeJlpdConfig(data) {
61
65
  bump: (0, buffer_1.readU8)(data, 245),
62
66
  jlpEarnAmount: (0, buffer_1.readU64)(data, 248),
63
67
  jlpAdapterProgram: (0, buffer_1.readPubkey)(data, 256),
68
+ vaultJlpAta: (0, buffer_1.readPubkey)(data, 288),
64
69
  };
65
70
  }
66
71
  /**
@@ -44,6 +44,7 @@ export declare const IX_WITHDRAW_FROM_ADAPTER: Buffer<ArrayBuffer>;
44
44
  export declare const IX_ADAPTER_MANAGE: Buffer<ArrayBuffer>;
45
45
  export declare const IX_ADD_MANAGER: Buffer<ArrayBuffer>;
46
46
  export declare const IX_REMOVE_MANAGER: Buffer<ArrayBuffer>;
47
+ export declare const IX_CLOSE_STRATEGY_STATE: Buffer<ArrayBuffer>;
47
48
  export declare const JLPD_CONFIG_SIZE = 392;
48
49
  export declare const MANAGER_ROLE_SIZE = 80;
49
50
  export declare const STRATEGY_STATE_SIZE = 224;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JLPD_VAULT_IDS = exports.JLPD_POOLS = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.MAX_PERF_FEE_BPS = exports.MAX_MGMT_FEE_BPS = exports.NUM_ASSETS = exports.FLAG_TEST_MODE = exports.FLAG_REBALANCE_DISABLED = exports.FLAG_JLP_DISABLED = exports.FLAG_WITHDRAWALS_DISABLED = exports.FLAG_DEPOSITS_DISABLED = exports.FLAG_PAUSED = exports.STV_POSITION_SIZE = exports.STRATEGY_STATE_SIZE = exports.MANAGER_ROLE_SIZE = exports.JLPD_CONFIG_SIZE = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_ADAPTER_MANAGE = exports.IX_WITHDRAW_FROM_ADAPTER = exports.IX_DEPOSIT_TO_ADAPTER = exports.IX_SETTLE_YIELD = exports.IX_BASE_TO_BASE_SWAP = exports.IX_SWAP_JLP = exports.IX_UPDATE_AUM = exports.IX_WITHDRAW = exports.IX_DEPOSIT = exports.IX_CLOSE_POSITION = exports.IX_INIT_POSITION = exports.IX_INIT_OR_UPDATE_STRATEGY_STATE = exports.IX_INIT_OR_UPDATE_CONFIG = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.DISC_JLPD_CONFIG = exports.POSITION_SEED = exports.STRATEGY_STATE_SEED = exports.MANAGER_SEED = exports.CONFIG_SEED = exports.JUPITER_PERPS_PROGRAM = exports.JLP_POOL_ACCOUNT = exports.DOVES_SOL_USD = exports.DOVES_ETH_USD = exports.DOVES_BTC_USD = exports.JUPITER_PROGRAM = exports.JLP_MINT = exports.PROGRAM_ID_DEVNET = exports.PROGRAM_ID_MAINNET = exports.PROGRAM_ID = void 0;
4
- exports.JLPD_POOL_DECIMALS = exports.JLPD_VAULT_IDS_BY_POOL = void 0;
3
+ exports.JLPD_POOLS = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.MAX_PERF_FEE_BPS = exports.MAX_MGMT_FEE_BPS = exports.NUM_ASSETS = exports.FLAG_TEST_MODE = exports.FLAG_REBALANCE_DISABLED = exports.FLAG_JLP_DISABLED = exports.FLAG_WITHDRAWALS_DISABLED = exports.FLAG_DEPOSITS_DISABLED = exports.FLAG_PAUSED = exports.STV_POSITION_SIZE = exports.STRATEGY_STATE_SIZE = exports.MANAGER_ROLE_SIZE = exports.JLPD_CONFIG_SIZE = exports.IX_CLOSE_STRATEGY_STATE = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_ADAPTER_MANAGE = exports.IX_WITHDRAW_FROM_ADAPTER = exports.IX_DEPOSIT_TO_ADAPTER = exports.IX_SETTLE_YIELD = exports.IX_BASE_TO_BASE_SWAP = exports.IX_SWAP_JLP = exports.IX_UPDATE_AUM = exports.IX_WITHDRAW = exports.IX_DEPOSIT = exports.IX_CLOSE_POSITION = exports.IX_INIT_POSITION = exports.IX_INIT_OR_UPDATE_STRATEGY_STATE = exports.IX_INIT_OR_UPDATE_CONFIG = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.DISC_JLPD_CONFIG = exports.POSITION_SEED = exports.STRATEGY_STATE_SEED = exports.MANAGER_SEED = exports.CONFIG_SEED = exports.JUPITER_PERPS_PROGRAM = exports.JLP_POOL_ACCOUNT = exports.DOVES_SOL_USD = exports.DOVES_ETH_USD = exports.DOVES_BTC_USD = exports.JUPITER_PROGRAM = exports.JLP_MINT = exports.PROGRAM_ID_DEVNET = exports.PROGRAM_ID_MAINNET = exports.PROGRAM_ID = void 0;
4
+ exports.JLPD_POOL_DECIMALS = exports.JLPD_VAULT_IDS_BY_POOL = exports.JLPD_VAULT_IDS = void 0;
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  exports.PROGRAM_ID = new web3_js_1.PublicKey("GXqt4ZH2UUBsLWwMNJiZMXza3q7xEGChfW8XjVRjLxr5");
7
7
  exports.PROGRAM_ID_MAINNET = exports.PROGRAM_ID;
@@ -65,6 +65,8 @@ exports.IX_ADAPTER_MANAGE = Buffer.from([210, 30, 127, 237, 109, 210, 2, 212]);
65
65
  exports.IX_ADD_MANAGER = Buffer.from([125, 38, 192, 212, 101, 91, 179, 16]);
66
66
  // sha256("global:remove_manager")[..8]
67
67
  exports.IX_REMOVE_MANAGER = Buffer.from([150, 55, 157, 77, 128, 148, 7, 15]);
68
+ // sha256("global:close_strategy_state")[..8] — verified against IDL discriminator
69
+ exports.IX_CLOSE_STRATEGY_STATE = Buffer.from([126, 163, 50, 191, 191, 74, 84, 53]);
68
70
  // Account sizes
69
71
  exports.JLPD_CONFIG_SIZE = 392;
70
72
  exports.MANAGER_ROLE_SIZE = 80;
@@ -1,4 +1,30 @@
1
1
  import { PublicKey, TransactionInstruction } from "@solana/web3.js";
2
+ export interface InitOrUpdateConfigArgs {
3
+ /** Must equal params.admin on init; must be existing config.admin on update. Signer + writable. */
4
+ payer: PublicKey;
5
+ /** Config PDA (init_if_needed). */
6
+ config: PublicKey;
7
+ /** JLP token mint — used for ATA derivation on init; must still be passed on update. */
8
+ jlpMint: PublicKey;
9
+ /** Token program that owns the JLP mint's ATA namespace. */
10
+ tokenProgram: PublicKey;
11
+ systemProgram?: PublicKey;
12
+ /** Required on init; ignored on update (pass null on update). */
13
+ jlpMintParam?: PublicKey | null;
14
+ /** Required on init; ignored on update (pass null on update). */
15
+ baseAssetMints?: [PublicKey, PublicKey, PublicKey, PublicKey, PublicKey] | null;
16
+ /** Admin pubkey (sets config.admin; must equal payer on init). */
17
+ admin: PublicKey;
18
+ /** Config flags (FLAG_PAUSED, FLAG_DEPOSITS_DISABLED, etc). */
19
+ flags: number;
20
+ /** Oracle slippage tolerance BPS (max 1000). */
21
+ jlpSlippageBps: number;
22
+ /** Oracle staleness threshold in seconds (1..600). Defaults to 60 on init when null. */
23
+ oracleStalenessSecs?: number | null;
24
+ /** Adapter program pubkey (Pubkey::default = no adapter). */
25
+ jlpAdapterProgram?: PublicKey | null;
26
+ }
27
+ export declare function createInitOrUpdateConfigIx(args: InitOrUpdateConfigArgs, programId?: PublicKey): TransactionInstruction;
2
28
  export interface InitOrUpdateStrategyStateArgs {
3
29
  /** Admin signer; also the rent payer for the init_if_needed ATAs (writable). */
4
30
  admin: PublicKey;
@@ -87,3 +113,30 @@ export interface RemoveManagerArgs {
87
113
  * 3. manager_role (writable — closed)
88
114
  */
89
115
  export declare function createRemoveManagerIx(args: RemoveManagerArgs, programId?: PublicKey): TransactionInstruction;
116
+ export interface CloseStrategyStateArgs {
117
+ /** Admin signer — must match config.admin. */
118
+ admin: PublicKey;
119
+ /** Receives rent refund from the closed StrategyState account. */
120
+ payer: PublicKey;
121
+ /** JLPD Config PDA. */
122
+ config: PublicKey;
123
+ /** The StrategyState PDA to close. */
124
+ strategyState: PublicKey;
125
+ /** Base asset mint stored in strategy_state.base_mint. */
126
+ baseMint: PublicKey;
127
+ /** JLP mint stored in config.jlp_mint. */
128
+ jlpMint: PublicKey;
129
+ /** Canonical base ATA owned by StrategyState PDA (must have zero balance). */
130
+ strategyBaseAta: PublicKey;
131
+ /** Canonical JLP staging ATA owned by StrategyState PDA (must have zero balance). */
132
+ strategyJlpAta: PublicKey;
133
+ /** Token program that owns the ATA namespace (used for canonical ATA derivation). */
134
+ tokenProgram: PublicKey;
135
+ }
136
+ /**
137
+ * Create a `close_strategy_state` instruction for the JLPD Strategy program.
138
+ *
139
+ * Discriminator verified against IDL:
140
+ * sha256("global:close_strategy_state")[..8] = [126, 163, 50, 191, 191, 74, 84, 53]
141
+ */
142
+ export declare function createCloseStrategyStateIx(args: CloseStrategyStateArgs, programId?: PublicKey): TransactionInstruction;
@@ -1,12 +1,84 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInitOrUpdateConfigIx = createInitOrUpdateConfigIx;
3
4
  exports.createInitOrUpdateStrategyStateIx = createInitOrUpdateStrategyStateIx;
4
5
  exports.createAddManagerIx = createAddManagerIx;
5
6
  exports.createRemoveManagerIx = createRemoveManagerIx;
7
+ exports.createCloseStrategyStateIx = createCloseStrategyStateIx;
6
8
  const web3_js_1 = require("@solana/web3.js");
7
9
  const spl_token_1 = require("@solana/spl-token");
8
10
  const buffer_1 = require("../common/buffer");
9
11
  const constants_1 = require("./constants");
12
+ /**
13
+ * Serialize `InitOrUpdateConfigParams` in Anchor/Borsh field order.
14
+ * Option<T> → 0x00 (None) or 0x01 + value bytes (Some).
15
+ */
16
+ function serializeInitOrUpdateConfigParams(args) {
17
+ const parts = [];
18
+ // jlp_mint: Option<Pubkey>
19
+ if (args.jlpMintParam != null) {
20
+ parts.push(0x01);
21
+ parts.push(...args.jlpMintParam.toBuffer());
22
+ }
23
+ else {
24
+ parts.push(0x00);
25
+ }
26
+ // base_asset_mints: Option<[Pubkey; 5]>
27
+ if (args.baseAssetMints != null) {
28
+ parts.push(0x01);
29
+ for (const m of args.baseAssetMints) {
30
+ parts.push(...m.toBuffer());
31
+ }
32
+ }
33
+ else {
34
+ parts.push(0x00);
35
+ }
36
+ // admin: Pubkey (not optional)
37
+ parts.push(...args.admin.toBuffer());
38
+ // flags: u16 LE
39
+ const flagsBuf = Buffer.alloc(2);
40
+ flagsBuf.writeUInt16LE(args.flags & 0xffff, 0);
41
+ parts.push(...flagsBuf);
42
+ // jlp_slippage_bps: u16 LE
43
+ const slippageBuf = Buffer.alloc(2);
44
+ slippageBuf.writeUInt16LE(args.jlpSlippageBps & 0xffff, 0);
45
+ parts.push(...slippageBuf);
46
+ // oracle_staleness_threshold: Option<u64>
47
+ if (args.oracleStalenessSecs != null) {
48
+ parts.push(0x01);
49
+ const stalenessArr = [];
50
+ (0, buffer_1.writeU64)(stalenessArr, args.oracleStalenessSecs);
51
+ parts.push(...stalenessArr);
52
+ }
53
+ else {
54
+ parts.push(0x00);
55
+ }
56
+ // jlp_adapter_program: Option<Pubkey>
57
+ if (args.jlpAdapterProgram != null) {
58
+ parts.push(0x01);
59
+ parts.push(...args.jlpAdapterProgram.toBuffer());
60
+ }
61
+ else {
62
+ parts.push(0x00);
63
+ }
64
+ return parts;
65
+ }
66
+ function createInitOrUpdateConfigIx(args, programId = constants_1.PROGRAM_ID) {
67
+ const { payer, config, jlpMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, } = args;
68
+ const paramBytes = serializeInitOrUpdateConfigParams(args);
69
+ const data = Buffer.concat([constants_1.IX_INIT_OR_UPDATE_CONFIG, Buffer.from(paramBytes)]);
70
+ return new web3_js_1.TransactionInstruction({
71
+ keys: [
72
+ { pubkey: payer, isSigner: true, isWritable: true },
73
+ { pubkey: config, isSigner: false, isWritable: true },
74
+ { pubkey: jlpMint, isSigner: false, isWritable: false },
75
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
76
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
77
+ ],
78
+ programId,
79
+ data,
80
+ });
81
+ }
10
82
  /**
11
83
  * Create an `init_or_update_strategy_state` instruction for the JLPD program.
12
84
  *
@@ -116,3 +188,30 @@ function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
116
188
  data,
117
189
  });
118
190
  }
191
+ /**
192
+ * Create a `close_strategy_state` instruction for the JLPD Strategy program.
193
+ *
194
+ * Discriminator verified against IDL:
195
+ * sha256("global:close_strategy_state")[..8] = [126, 163, 50, 191, 191, 74, 84, 53]
196
+ */
197
+ function createCloseStrategyStateIx(args, programId = constants_1.PROGRAM_ID) {
198
+ const { admin, payer, config, strategyState, baseMint, jlpMint, strategyBaseAta, strategyJlpAta, tokenProgram, } = args;
199
+ // Discriminator only — no additional instruction data
200
+ const data = Buffer.alloc(8);
201
+ constants_1.IX_CLOSE_STRATEGY_STATE.copy(data, 0);
202
+ return new web3_js_1.TransactionInstruction({
203
+ keys: [
204
+ { pubkey: admin, isSigner: true, isWritable: false },
205
+ { pubkey: payer, isSigner: false, isWritable: true },
206
+ { pubkey: config, isSigner: false, isWritable: false },
207
+ { pubkey: strategyState, isSigner: false, isWritable: true },
208
+ { pubkey: baseMint, isSigner: false, isWritable: false },
209
+ { pubkey: jlpMint, isSigner: false, isWritable: false },
210
+ { pubkey: strategyBaseAta, isSigner: false, isWritable: false },
211
+ { pubkey: strategyJlpAta, isSigner: false, isWritable: false },
212
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
213
+ ],
214
+ programId,
215
+ data,
216
+ });
217
+ }
@@ -15,6 +15,8 @@ export interface JlpdConfig {
15
15
  jlpEarnAmount: BN;
16
16
  /** Whitelisted adapter program. PublicKey.default = no adapter. */
17
17
  jlpAdapterProgram: PublicKey;
18
+ /** Canonical vault JLP ATA stored on-chain (ATA(config_pda, jlp_mint)). Carved from _reserved; SIZE unchanged. */
19
+ vaultJlpAta: PublicKey;
18
20
  }
19
21
  /** ManagerRole PDA (80 bytes) — grants manager access to rebalance operations */
20
22
  export interface ManagerRole {
@@ -18,46 +18,53 @@ export declare function deserializeGlobalConfig(data: Buffer): GlobalConfig;
18
18
  /**
19
19
  * STV — per-vault state. Total 664 bytes (v2 layout).
20
20
  *
21
- * Layout (offsets include the 8-byte discriminator):
21
+ * v2 layout (offsets include the 8-byte Anchor-compatible discriminator).
22
+ * All compile-time asserts in p-stv-core/programs/p-stv-core/src/state/stv.rs
23
+ * are the canonical source of truth; offsets here are copied from those asserts.
24
+ *
22
25
  * [ 0.. 8] discriminator (sha256("account:Stv")[..8])
23
- * [ 8.. 40] baseMint Pubkey
24
- * [ 40.. 72] evMint Pubkey
25
- * [ 72..104] strategy Pubkey (immutable strategy program)
26
- * [104..136] feeReceiver Pubkey
27
- * [136..168] lendProgram Pubkey (zero pubkey if lend not opted-in)
28
- * [168..200] vaultAta Pubkey (canonical ATA for stv_pda+base_mint+token_program)
29
- * [200..248] childVaults[6] [u64; 6] (allocator child vault IDs)
30
- * [248..256] vaultId u64
31
- * [256..264] reservedBase u64 (base reserved for pending claims)
32
- * [264..272] requestedShares u64 (shares pending in escrow — multiply × PPS to estimate base)
33
- * [272..280] vaultCapacity u64 (0 = uncapped)
34
- * [280..288] minDeposit u64
35
- * [288..296] hwm u64 (high-water mark for perf fees)
36
- * [296..304] lastFeeTs u64 (last fee crystallization timestamp)
37
- * [304..312] epochPps u64 (locked PPS for current epoch claims)
38
- * [312..320] lastNav u64 (snapshot for the rate-limit window)
39
- * [320..328] dailyWithdrawnBase u64 (rate-limit accumulator)
40
- * [328..332] nextEpochTs u32
41
- * [332..336] epochSec u32
42
- * [336..340] currentEpochId u32
43
- * [340..344] pendingWithdrawals u32
44
- * [344..348] withdrawWindowStart u32
45
- * [348..350] mgmtFeeBps u16
46
- * [350..352] perfFeeBps u16
47
- * [352..354] flags u16 (FLAG_PAUSED / DEPOSITS_DISABLED / …)
48
- * [354..356] dailyWithdrawLimitBps u16
49
- * [356..357] childVaultCount u8
50
- * [357..358] version u8
51
- * [358..359] bump u8
52
- * [359..360] _padding [u8; 1]
53
- * [360..362] depositFeeBps u16
54
- * [362..364] withdrawalFeeBps u16
55
- * [364..368] pendingDepositCount u32
56
- * [368..376] pendingDepositBase u64 (delayed deposit principal not yet active)
57
- * [376..408] feeReceiverEvAta Pubkey (pinned canonical fee receiver evX ATA)
58
- * [408..416] lockedSeedShares u64 (C-1 supply floor)
59
- * [416..417] withdrawalMode u8 (0=instant, 1=X, 2=X+1)
60
- * [417..664] _reserved [u8; 247]
26
+ * [ 8.. 40] baseMint Pubkey (_OFFSET_BASE_MINT == 8)
27
+ * [ 40.. 72] evMint Pubkey (_OFFSET_EV_MINT == 40)
28
+ * [ 72..104] strategy Pubkey (_OFFSET_STRATEGY == 72; immutable)
29
+ * [104..136] feeReceiver Pubkey (_OFFSET_FEE_RECEIVER == 104)
30
+ * [136..168] lendProgram Pubkey (_OFFSET_LEND_PROGRAM == 136; zero = inactive)
31
+ * [168..200] vaultAta Pubkey (_OFFSET_VAULT_ATA == 168; canonical ATA)
32
+ * [200..232] admin Pubkey (_OFFSET_ADMIN == 200; per-vault admin, never zero on v2)
33
+ * [232..264] pendingAdmin Pubkey (_OFFSET_PENDING_ADMIN == 232; zero = no rotation in progress)
34
+ * [264..296] childVaults[4] [u64; 4] (_OFFSET_CHILD_VAULTS == 264; MAX_CHILD_VAULTS = 4)
35
+ * [296..304] vaultId u64 (_OFFSET_VAULT_ID == 296)
36
+ * [304..312] reservedBase u64
37
+ * [312..320] requestedShares u64 (shares pending in escrow)
38
+ * [320..328] vaultCapacity u64 (0 = uncapped)
39
+ * [328..336] minDeposit u64
40
+ * [336..344] hwm u64 (high-water mark for perf fees)
41
+ * [344..352] lastFeeTs u64
42
+ * [352..360] epochPps u64 (locked PPS for current epoch claims)
43
+ * [360..368] lastNav u64 (snapshot for rate-limit window)
44
+ * [368..376] dailyWithdrawnBase u64 (rate-limit accumulator)
45
+ * [376..380] nextEpochTs u32
46
+ * [380..384] epochSec u32
47
+ * [384..388] currentEpochId u32
48
+ * [388..392] pendingWithdrawals u32
49
+ * [392..396] withdrawWindowStart u32
50
+ * [396..398] mgmtFeeBps u16
51
+ * [398..400] perfFeeBps u16
52
+ * [400..402] flags u16
53
+ * [402..404] dailyWithdrawLimitBps u16
54
+ * [404..405] childVaultCount u8
55
+ * [405..406] version u8 (== 2 for v2 accounts)
56
+ * [406..407] bump u8
57
+ * [407..408] _padding [u8; 1]
58
+ * [408..410] depositFeeBps u16 (_OFFSET_DEPOSIT_FEE_BPS == 408)
59
+ * [410..412] withdrawalFeeBps u16 (_OFFSET_WITHDRAWAL_FEE_BPS == 410)
60
+ * [412..416] pendingDepositCount u32 (_OFFSET_PENDING_DEPOSIT_COUNT == 412)
61
+ * [416..424] pendingDepositBase u64 (_OFFSET_PENDING_DEPOSIT_BASE == 416)
62
+ * [424..456] feeReceiverEvAta Pubkey (_OFFSET_FEE_RECEIVER_EV_ATA == 424)
63
+ * [456..464] lockedSeedShares u64 (_OFFSET_LOCKED_SEED_SHARES == 456)
64
+ * [464..465] withdrawalMode u8 (_OFFSET_WITHDRAWAL_MODE == 464; 0=instant, 1=X, 2=X+1)
65
+ * [465..468] _reservedPad [u8; 3] (_OFFSET_RESERVED_PAD == 465; alignment before last_nav_ts)
66
+ * [468..472] lastNavTs u32 (_OFFSET_LAST_NAV_TS == 468; unix seconds; 0 = no epoch yet)
67
+ * [472..664] _reserved [u8; 192] (_OFFSET_RESERVED == 472)
61
68
  */
62
69
  export declare function deserializeStv(data: Buffer): Stv;
63
70
  /**