@elmntl/jlpd-sdk 0.1.11 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +185 -404
  3. package/dist/common/ata.d.ts +26 -0
  4. package/dist/common/ata.js +48 -0
  5. package/dist/common/buffer.d.ts +15 -0
  6. package/dist/common/buffer.js +118 -0
  7. package/dist/common/connection.d.ts +13 -0
  8. package/dist/common/connection.js +2 -0
  9. package/dist/common/constants.d.ts +14 -0
  10. package/dist/common/constants.js +31 -0
  11. package/dist/common/index.d.ts +6 -0
  12. package/dist/common/index.js +28 -0
  13. package/dist/common/strategy-interface.d.ts +59 -0
  14. package/dist/common/strategy-interface.js +42 -0
  15. package/dist/elemental-lend/accounts.d.ts +103 -0
  16. package/dist/elemental-lend/accounts.js +354 -0
  17. package/dist/elemental-lend/constants.d.ts +25 -0
  18. package/dist/elemental-lend/constants.js +48 -0
  19. package/dist/elemental-lend/index.d.ts +8 -0
  20. package/dist/elemental-lend/index.js +24 -0
  21. package/dist/elemental-lend/instructions.d.ts +104 -0
  22. package/dist/elemental-lend/instructions.js +266 -0
  23. package/dist/elemental-lend/jupiter-lend.d.ts +91 -0
  24. package/dist/elemental-lend/jupiter-lend.js +189 -0
  25. package/dist/elemental-lend/kamino-vault.d.ts +173 -0
  26. package/dist/elemental-lend/kamino-vault.js +483 -0
  27. package/dist/elemental-lend/pda.d.ts +12 -0
  28. package/dist/elemental-lend/pda.js +24 -0
  29. package/dist/elemental-lend/protocol-actions.d.ts +56 -0
  30. package/dist/elemental-lend/protocol-actions.js +244 -0
  31. package/dist/elemental-lend/types.d.ts +113 -0
  32. package/dist/elemental-lend/types.js +2 -0
  33. package/dist/elemental-lend-v2/accounts.d.ts +14 -0
  34. package/dist/elemental-lend-v2/accounts.js +136 -0
  35. package/dist/elemental-lend-v2/adapters.d.ts +22 -0
  36. package/dist/elemental-lend-v2/adapters.js +50 -0
  37. package/dist/elemental-lend-v2/constants.d.ts +48 -0
  38. package/dist/elemental-lend-v2/constants.js +104 -0
  39. package/dist/elemental-lend-v2/index.d.ts +8 -0
  40. package/dist/elemental-lend-v2/index.js +24 -0
  41. package/dist/elemental-lend-v2/instructions.d.ts +96 -0
  42. package/dist/elemental-lend-v2/instructions.js +190 -0
  43. package/dist/elemental-lend-v2/lut.d.ts +20 -0
  44. package/dist/elemental-lend-v2/lut.js +65 -0
  45. package/dist/elemental-lend-v2/pda.d.ts +9 -0
  46. package/dist/elemental-lend-v2/pda.js +27 -0
  47. package/dist/elemental-lend-v2/types.d.ts +105 -0
  48. package/dist/elemental-lend-v2/types.js +2 -0
  49. package/dist/elemental-lend-v2/update-aum.d.ts +29 -0
  50. package/dist/elemental-lend-v2/update-aum.js +82 -0
  51. package/dist/index.d.ts +5 -3552
  52. package/dist/index.js +37 -4454
  53. package/dist/jlpd-strategy/accounts.d.ts +83 -0
  54. package/dist/jlpd-strategy/accounts.js +216 -0
  55. package/dist/jlpd-strategy/adapter.d.ts +81 -0
  56. package/dist/jlpd-strategy/adapter.js +118 -0
  57. package/dist/jlpd-strategy/base-to-base-swap.d.ts +74 -0
  58. package/dist/jlpd-strategy/base-to-base-swap.js +205 -0
  59. package/dist/jlpd-strategy/constants.d.ts +127 -0
  60. package/dist/jlpd-strategy/constants.js +174 -0
  61. package/dist/jlpd-strategy/fluid-view.d.ts +199 -0
  62. package/dist/jlpd-strategy/fluid-view.js +799 -0
  63. package/dist/jlpd-strategy/hedge-derived.d.ts +135 -0
  64. package/dist/jlpd-strategy/hedge-derived.js +231 -0
  65. package/dist/jlpd-strategy/hedge-instructions.d.ts +210 -0
  66. package/dist/jlpd-strategy/hedge-instructions.js +300 -0
  67. package/dist/jlpd-strategy/hedge-state.d.ts +88 -0
  68. package/dist/jlpd-strategy/hedge-state.js +110 -0
  69. package/dist/jlpd-strategy/index.d.ts +17 -0
  70. package/dist/jlpd-strategy/index.js +33 -0
  71. package/dist/jlpd-strategy/instructions.d.ts +159 -0
  72. package/dist/jlpd-strategy/instructions.js +234 -0
  73. package/dist/jlpd-strategy/jlp-borrow.d.ts +63 -0
  74. package/dist/jlpd-strategy/jlp-borrow.js +87 -0
  75. package/dist/jlpd-strategy/jlp-data.d.ts +166 -0
  76. package/dist/jlpd-strategy/jlp-data.js +611 -0
  77. package/dist/jlpd-strategy/jupusd-earn.d.ts +90 -0
  78. package/dist/jlpd-strategy/jupusd-earn.js +166 -0
  79. package/dist/jlpd-strategy/live-jlp-price.d.ts +46 -0
  80. package/dist/jlpd-strategy/live-jlp-price.js +267 -0
  81. package/dist/jlpd-strategy/pda.d.ts +13 -0
  82. package/dist/jlpd-strategy/pda.js +28 -0
  83. package/dist/jlpd-strategy/settle-yield.d.ts +45 -0
  84. package/dist/jlpd-strategy/settle-yield.js +113 -0
  85. package/dist/jlpd-strategy/swap-jlp.d.ts +198 -0
  86. package/dist/jlpd-strategy/swap-jlp.js +586 -0
  87. package/dist/jlpd-strategy/types.d.ts +101 -0
  88. package/dist/jlpd-strategy/types.js +29 -0
  89. package/dist/p-stv-core/accounts.d.ts +152 -0
  90. package/dist/p-stv-core/accounts.js +407 -0
  91. package/dist/p-stv-core/constants.d.ts +138 -0
  92. package/dist/p-stv-core/constants.js +181 -0
  93. package/dist/p-stv-core/events.d.ts +7 -0
  94. package/dist/p-stv-core/events.js +246 -0
  95. package/dist/p-stv-core/index.d.ts +11 -0
  96. package/dist/p-stv-core/index.js +27 -0
  97. package/dist/p-stv-core/instructions.d.ts +637 -0
  98. package/dist/p-stv-core/instructions.js +670 -0
  99. package/dist/p-stv-core/lut.d.ts +41 -0
  100. package/dist/p-stv-core/lut.js +81 -0
  101. package/dist/p-stv-core/pda.d.ts +30 -0
  102. package/dist/p-stv-core/pda.js +65 -0
  103. package/dist/p-stv-core/prices.d.ts +20 -0
  104. package/dist/p-stv-core/prices.js +77 -0
  105. package/dist/p-stv-core/remaining-accounts.d.ts +107 -0
  106. package/dist/p-stv-core/remaining-accounts.js +326 -0
  107. package/dist/p-stv-core/send-tx.d.ts +72 -0
  108. package/dist/p-stv-core/send-tx.js +290 -0
  109. package/dist/p-stv-core/sol-wrap.d.ts +34 -0
  110. package/dist/p-stv-core/sol-wrap.js +74 -0
  111. package/dist/p-stv-core/types.d.ts +361 -0
  112. package/dist/p-stv-core/types.js +2 -0
  113. package/package.json +56 -15
  114. package/dist/index.d.mts +0 -3552
  115. package/dist/index.mjs +0 -4363
@@ -0,0 +1,159 @@
1
+ import { PublicKey, TransactionInstruction } from "@solana/web3.js";
2
+ import BN from "bn.js";
3
+ export interface InitOrUpdateConfigArgs {
4
+ /** Must equal params.admin on init; must be existing config.admin on update. Signer + writable. */
5
+ payer: PublicKey;
6
+ /** Config PDA (init_if_needed). */
7
+ config: PublicKey;
8
+ /** JLP token mint — used for ATA derivation on init; must still be passed on update. */
9
+ jlpMint: PublicKey;
10
+ /** Token program that owns the JLP mint's ATA namespace. */
11
+ tokenProgram: PublicKey;
12
+ systemProgram?: PublicKey;
13
+ /** Required on init; ignored on update (pass null on update). */
14
+ jlpMintParam?: PublicKey | null;
15
+ /** Required on init; ignored on update (pass null on update). */
16
+ baseAssetMints?: [PublicKey, PublicKey, PublicKey, PublicKey, PublicKey] | null;
17
+ /** Admin pubkey (sets config.admin; must equal payer on init). */
18
+ admin: PublicKey;
19
+ /** Config flags (FLAG_PAUSED, FLAG_DEPOSITS_DISABLED, etc). */
20
+ flags: number;
21
+ /** Oracle slippage tolerance BPS (max 1000). */
22
+ jlpSlippageBps: number;
23
+ /** Oracle staleness threshold in seconds (1..600). Defaults to 60 on init when null. */
24
+ oracleStalenessSecs?: number | null;
25
+ /**
26
+ * Per-StrategyState cap on banked `swap_arb` (USD, 6-dec). Init: `null`/omitted → 0 (fail-closed,
27
+ * no positive arb banked until an admin sets this); update: `null`/omitted keeps the existing
28
+ * on-chain value, a value updates it.
29
+ */
30
+ maxSwapArbUsdPerAsset?: BN | number | null;
31
+ /**
32
+ * Divergence-breaker SOFT band (bps). Init: `null`/omitted → 0 (resolves to the 1% on-chain
33
+ * default at read time); update: `null`/omitted keeps existing. Validated on-chain (post-update
34
+ * resolved value) `<=` the resolved hard band.
35
+ */
36
+ softBreakerTolBps?: number | null;
37
+ /**
38
+ * Divergence-breaker HARD band (bps). Init: `null`/omitted → 0 (resolves to the 3% on-chain
39
+ * default); update: `null`/omitted keeps existing. Validated on-chain (post-update resolved
40
+ * value) `<=` `MAX_BREAKER_BPS` (10_000) and `>=` the resolved soft band.
41
+ */
42
+ aumHardBreakerBps?: number | null;
43
+ }
44
+ export declare function createInitOrUpdateConfigIx(args: InitOrUpdateConfigArgs, programId?: PublicKey): TransactionInstruction;
45
+ export interface InitOrUpdateStrategyStateArgs {
46
+ /** Admin signer; also the rent payer for the init_if_needed ATAs (writable). */
47
+ admin: PublicKey;
48
+ config: PublicKey;
49
+ strategyState: PublicKey;
50
+ baseMint: PublicKey;
51
+ jlpMint: PublicKey;
52
+ strategyBaseAta: PublicKey;
53
+ strategyJlpAta: PublicKey;
54
+ tokenProgram: PublicKey;
55
+ systemProgram?: PublicKey;
56
+ associatedTokenProgram?: PublicKey;
57
+ rent?: PublicKey;
58
+ /** New admin/authority Pubkey, or null to leave unchanged. */
59
+ authority?: PublicKey | null;
60
+ /** New flags value, or null to leave unchanged. */
61
+ flags?: number | null;
62
+ /**
63
+ * Doves price-feed account to store in strategy_state.price_oracle.
64
+ * Serialized as the THIRD optional field in InitOrUpdateStrategyStateParams.
65
+ * Pass null to leave unchanged.
66
+ */
67
+ priceOracle?: PublicKey | null;
68
+ }
69
+ /**
70
+ * Create an `init_or_update_strategy_state` instruction for the JLPD program.
71
+ *
72
+ * Instruction data: [8-byte disc,
73
+ * Option<Pubkey> authority, (1 tag + 32 bytes if Some)
74
+ * Option<u16> flags, (1 tag + 2 bytes if Some)
75
+ * Option<Pubkey> price_oracle (1 tag + 32 bytes if Some)]
76
+ *
77
+ * Field order matches Rust `InitOrUpdateStrategyStateParams`:
78
+ * authority: Option<Pubkey>, flags: Option<u16>, price_oracle: Option<Pubkey>
79
+ *
80
+ * Accounts (match on-chain InitOrUpdateStrategyState exactly):
81
+ * 0. admin (signer, writable — pays init_if_needed ATA rent)
82
+ * 1. config
83
+ * 2. strategy_state (writable — init_if_needed)
84
+ * 3. base_mint
85
+ * 4. jlp_mint
86
+ * 5. strategy_base_ata (writable — init_if_needed)
87
+ * 6. strategy_jlp_ata (writable — init_if_needed)
88
+ * 7. system_program
89
+ * 8. token_program
90
+ * 9. associated_token_program
91
+ * 10. rent
92
+ */
93
+ export declare function createInitOrUpdateStrategyStateIx(args: InitOrUpdateStrategyStateArgs, programId?: PublicKey): TransactionInstruction;
94
+ export interface AddManagerArgs {
95
+ admin: PublicKey;
96
+ payer: PublicKey;
97
+ config: PublicKey;
98
+ managerRole: PublicKey;
99
+ manager: PublicKey;
100
+ systemProgram?: PublicKey;
101
+ }
102
+ /**
103
+ * Create an `add_manager` instruction for the JLPD Strategy program.
104
+ *
105
+ * Anchor instruction data: [8-byte disc, 32-byte manager pubkey]
106
+ *
107
+ * Accounts:
108
+ * 0. admin (signer)
109
+ * 1. payer (signer, writable)
110
+ * 2. config (writable — Anchor init needs writable config for bump read)
111
+ * 3. manager_role (writable — init)
112
+ * 4. system_program
113
+ */
114
+ export declare function createAddManagerIx(args: AddManagerArgs, programId?: PublicKey): TransactionInstruction;
115
+ export interface RemoveManagerArgs {
116
+ admin: PublicKey;
117
+ payer: PublicKey;
118
+ config: PublicKey;
119
+ managerRole: PublicKey;
120
+ }
121
+ /**
122
+ * Create a `remove_manager` instruction for the JLPD Strategy program.
123
+ *
124
+ * Anchor instruction data: [8-byte disc]
125
+ *
126
+ * Accounts:
127
+ * 0. admin (signer)
128
+ * 1. payer (writable — receives rent)
129
+ * 2. config
130
+ * 3. manager_role (writable — closed)
131
+ */
132
+ export declare function createRemoveManagerIx(args: RemoveManagerArgs, programId?: PublicKey): TransactionInstruction;
133
+ export interface CloseStrategyStateArgs {
134
+ /** Admin signer — must match config.admin. */
135
+ admin: PublicKey;
136
+ /** Receives rent refund from the closed StrategyState account. */
137
+ payer: PublicKey;
138
+ /** JLPD Config PDA. */
139
+ config: PublicKey;
140
+ /** The StrategyState PDA to close. */
141
+ strategyState: PublicKey;
142
+ /** Base asset mint stored in strategy_state.base_mint. */
143
+ baseMint: PublicKey;
144
+ /** JLP mint stored in config.jlp_mint. */
145
+ jlpMint: PublicKey;
146
+ /** Canonical base ATA owned by StrategyState PDA (must have zero balance). */
147
+ strategyBaseAta: PublicKey;
148
+ /** Canonical JLP staging ATA owned by StrategyState PDA (must have zero balance). */
149
+ strategyJlpAta: PublicKey;
150
+ /** Token program that owns the ATA namespace (used for canonical ATA derivation). */
151
+ tokenProgram: PublicKey;
152
+ }
153
+ /**
154
+ * Create a `close_strategy_state` instruction for the JLPD Strategy program.
155
+ *
156
+ * Discriminator verified against IDL:
157
+ * sha256("global:close_strategy_state")[..8] = [126, 163, 50, 191, 191, 74, 84, 53]
158
+ */
159
+ export declare function createCloseStrategyStateIx(args: CloseStrategyStateArgs, programId?: PublicKey): TransactionInstruction;
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInitOrUpdateConfigIx = createInitOrUpdateConfigIx;
4
+ exports.createInitOrUpdateStrategyStateIx = createInitOrUpdateStrategyStateIx;
5
+ exports.createAddManagerIx = createAddManagerIx;
6
+ exports.createRemoveManagerIx = createRemoveManagerIx;
7
+ exports.createCloseStrategyStateIx = createCloseStrategyStateIx;
8
+ const web3_js_1 = require("@solana/web3.js");
9
+ const spl_token_1 = require("@solana/spl-token");
10
+ const buffer_1 = require("../common/buffer");
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
+ (0, buffer_1.writeOptionalPubkey)(parts, args.jlpMintParam ?? null);
20
+ // base_asset_mints: Option<[Pubkey; 5]>
21
+ if (args.baseAssetMints != null) {
22
+ parts.push(0x01);
23
+ for (const m of args.baseAssetMints) {
24
+ parts.push(...m.toBuffer());
25
+ }
26
+ }
27
+ else {
28
+ parts.push(0x00);
29
+ }
30
+ // admin: Pubkey (not optional)
31
+ parts.push(...args.admin.toBuffer());
32
+ // flags: u16 LE
33
+ const flagsBuf = Buffer.alloc(2);
34
+ flagsBuf.writeUInt16LE(args.flags & 0xffff, 0);
35
+ parts.push(...flagsBuf);
36
+ // jlp_slippage_bps: u16 LE
37
+ const slippageBuf = Buffer.alloc(2);
38
+ slippageBuf.writeUInt16LE(args.jlpSlippageBps & 0xffff, 0);
39
+ parts.push(...slippageBuf);
40
+ // oracle_staleness_threshold: Option<u64>
41
+ (0, buffer_1.writeOptionalU64)(parts, args.oracleStalenessSecs ?? null);
42
+ // max_swap_arb_usd_per_asset: Option<u64>
43
+ (0, buffer_1.writeOptionalU64)(parts, args.maxSwapArbUsdPerAsset ?? null);
44
+ // soft_breaker_tol_bps: Option<u16>
45
+ (0, buffer_1.writeOptionalU16)(parts, args.softBreakerTolBps ?? null);
46
+ // aum_hard_breaker_bps: Option<u16>
47
+ (0, buffer_1.writeOptionalU16)(parts, args.aumHardBreakerBps ?? null);
48
+ return parts;
49
+ }
50
+ function createInitOrUpdateConfigIx(args, programId = constants_1.PROGRAM_ID) {
51
+ const { payer, config, jlpMint, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, } = args;
52
+ // FIX E: flags and jlpSlippageBps are encoded as u16 LE; validate range 0..65535
53
+ // before silently wrapping via & 0xffff.
54
+ if (!Number.isInteger(args.flags) || args.flags < 0 || args.flags > 65535) {
55
+ throw new RangeError("createInitOrUpdateConfigIx: flags must be an integer in 0..65535, got " + args.flags);
56
+ }
57
+ // The deployed program caps jlp_slippage_bps at MAX_JLP_SLIPPAGE_BPS = 1000
58
+ // (validate_config_bounds, init_or_update_config.rs); 1001..65535 fit the u16
59
+ // wire width but revert on-chain, so reject them client-side.
60
+ if (!Number.isInteger(args.jlpSlippageBps) || args.jlpSlippageBps < 0 || args.jlpSlippageBps > 1000) {
61
+ throw new RangeError("createInitOrUpdateConfigIx: jlpSlippageBps must be an integer in 0..1000, got " + args.jlpSlippageBps);
62
+ }
63
+ // The deployed program requires oracle_staleness_threshold in 1..=600
64
+ // (MAX_ORACLE_STALENESS_SECS). Validated only when provided — omitting it keeps
65
+ // the existing on-chain value on update.
66
+ if (args.oracleStalenessSecs != null) {
67
+ if (!Number.isInteger(args.oracleStalenessSecs) || args.oracleStalenessSecs < 1 || args.oracleStalenessSecs > 600) {
68
+ throw new RangeError("createInitOrUpdateConfigIx: oracleStalenessSecs must be an integer in 1..600, got " + args.oracleStalenessSecs);
69
+ }
70
+ }
71
+ // The deployed program requires the RESOLVED (0 -> default) soft/hard breaker bands both
72
+ // <= MAX_BREAKER_BPS = 10_000 (validate_breaker_bounds, init_or_update_config.rs); a raw
73
+ // value above that fits the u16 wire width but always reverts on-chain, so reject client-side.
74
+ const MAX_BREAKER_BPS = 10000;
75
+ if (args.softBreakerTolBps != null) {
76
+ if (!Number.isInteger(args.softBreakerTolBps) || args.softBreakerTolBps < 0 || args.softBreakerTolBps > MAX_BREAKER_BPS) {
77
+ throw new RangeError("createInitOrUpdateConfigIx: softBreakerTolBps must be an integer in 0.." + MAX_BREAKER_BPS + ", got " + args.softBreakerTolBps);
78
+ }
79
+ }
80
+ if (args.aumHardBreakerBps != null) {
81
+ if (!Number.isInteger(args.aumHardBreakerBps) || args.aumHardBreakerBps < 0 || args.aumHardBreakerBps > MAX_BREAKER_BPS) {
82
+ throw new RangeError("createInitOrUpdateConfigIx: aumHardBreakerBps must be an integer in 0.." + MAX_BREAKER_BPS + ", got " + args.aumHardBreakerBps);
83
+ }
84
+ }
85
+ const paramBytes = serializeInitOrUpdateConfigParams(args);
86
+ const data = Buffer.concat([constants_1.IX_INIT_OR_UPDATE_CONFIG, Buffer.from(paramBytes)]);
87
+ return new web3_js_1.TransactionInstruction({
88
+ keys: [
89
+ { pubkey: payer, isSigner: true, isWritable: true },
90
+ { pubkey: config, isSigner: false, isWritable: true },
91
+ { pubkey: jlpMint, isSigner: false, isWritable: false },
92
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
93
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
94
+ ],
95
+ programId,
96
+ data,
97
+ });
98
+ }
99
+ /**
100
+ * Create an `init_or_update_strategy_state` instruction for the JLPD program.
101
+ *
102
+ * Instruction data: [8-byte disc,
103
+ * Option<Pubkey> authority, (1 tag + 32 bytes if Some)
104
+ * Option<u16> flags, (1 tag + 2 bytes if Some)
105
+ * Option<Pubkey> price_oracle (1 tag + 32 bytes if Some)]
106
+ *
107
+ * Field order matches Rust `InitOrUpdateStrategyStateParams`:
108
+ * authority: Option<Pubkey>, flags: Option<u16>, price_oracle: Option<Pubkey>
109
+ *
110
+ * Accounts (match on-chain InitOrUpdateStrategyState exactly):
111
+ * 0. admin (signer, writable — pays init_if_needed ATA rent)
112
+ * 1. config
113
+ * 2. strategy_state (writable — init_if_needed)
114
+ * 3. base_mint
115
+ * 4. jlp_mint
116
+ * 5. strategy_base_ata (writable — init_if_needed)
117
+ * 6. strategy_jlp_ata (writable — init_if_needed)
118
+ * 7. system_program
119
+ * 8. token_program
120
+ * 9. associated_token_program
121
+ * 10. rent
122
+ */
123
+ function createInitOrUpdateStrategyStateIx(args, programId = constants_1.PROGRAM_ID) {
124
+ const { admin, config, strategyState, baseMint, jlpMint, strategyBaseAta, strategyJlpAta, tokenProgram, systemProgram = web3_js_1.SystemProgram.programId, associatedTokenProgram = spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, rent = web3_js_1.SYSVAR_RENT_PUBKEY, authority, flags, priceOracle, } = args;
125
+ // Serialize Borsh Option<T> fields in Rust param order:
126
+ // 1. authority: Option<Pubkey>
127
+ // 2. flags: Option<u16>
128
+ // 3. price_oracle: Option<Pubkey>
129
+ const parts = [...constants_1.IX_INIT_OR_UPDATE_STRATEGY_STATE];
130
+ (0, buffer_1.writeOptionalPubkey)(parts, authority ?? null);
131
+ (0, buffer_1.writeOptionalU16)(parts, flags ?? null);
132
+ (0, buffer_1.writeOptionalPubkey)(parts, priceOracle ?? null);
133
+ return new web3_js_1.TransactionInstruction({
134
+ keys: [
135
+ { pubkey: admin, isSigner: true, isWritable: true },
136
+ { pubkey: config, isSigner: false, isWritable: false },
137
+ { pubkey: strategyState, isSigner: false, isWritable: true },
138
+ { pubkey: baseMint, isSigner: false, isWritable: false },
139
+ { pubkey: jlpMint, isSigner: false, isWritable: false },
140
+ { pubkey: strategyBaseAta, isSigner: false, isWritable: true },
141
+ { pubkey: strategyJlpAta, isSigner: false, isWritable: true },
142
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
143
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
144
+ { pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
145
+ { pubkey: rent, isSigner: false, isWritable: false },
146
+ ],
147
+ programId,
148
+ data: Buffer.from(parts),
149
+ });
150
+ }
151
+ /**
152
+ * Create an `add_manager` instruction for the JLPD Strategy program.
153
+ *
154
+ * Anchor instruction data: [8-byte disc, 32-byte manager pubkey]
155
+ *
156
+ * Accounts:
157
+ * 0. admin (signer)
158
+ * 1. payer (signer, writable)
159
+ * 2. config (writable — Anchor init needs writable config for bump read)
160
+ * 3. manager_role (writable — init)
161
+ * 4. system_program
162
+ */
163
+ function createAddManagerIx(args, programId = constants_1.PROGRAM_ID) {
164
+ const { admin, payer, config, managerRole, manager, systemProgram = web3_js_1.SystemProgram.programId, } = args;
165
+ // Anchor discriminator (8 bytes) + manager pubkey (32 bytes)
166
+ const data = Buffer.alloc(8 + 32);
167
+ constants_1.IX_ADD_MANAGER.copy(data, 0);
168
+ manager.toBuffer().copy(data, 8);
169
+ return new web3_js_1.TransactionInstruction({
170
+ keys: [
171
+ { pubkey: admin, isSigner: true, isWritable: false },
172
+ { pubkey: payer, isSigner: true, isWritable: true },
173
+ { pubkey: config, isSigner: false, isWritable: false },
174
+ { pubkey: managerRole, isSigner: false, isWritable: true },
175
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
176
+ ],
177
+ programId,
178
+ data,
179
+ });
180
+ }
181
+ /**
182
+ * Create a `remove_manager` instruction for the JLPD Strategy program.
183
+ *
184
+ * Anchor instruction data: [8-byte disc]
185
+ *
186
+ * Accounts:
187
+ * 0. admin (signer)
188
+ * 1. payer (writable — receives rent)
189
+ * 2. config
190
+ * 3. manager_role (writable — closed)
191
+ */
192
+ function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
193
+ const { admin, payer, config, managerRole } = args;
194
+ // Anchor discriminator only (8 bytes)
195
+ const data = Buffer.alloc(8);
196
+ constants_1.IX_REMOVE_MANAGER.copy(data, 0);
197
+ return new web3_js_1.TransactionInstruction({
198
+ keys: [
199
+ { pubkey: admin, isSigner: true, isWritable: false },
200
+ { pubkey: payer, isSigner: false, isWritable: true },
201
+ { pubkey: config, isSigner: false, isWritable: false },
202
+ { pubkey: managerRole, isSigner: false, isWritable: true },
203
+ ],
204
+ programId,
205
+ data,
206
+ });
207
+ }
208
+ /**
209
+ * Create a `close_strategy_state` instruction for the JLPD Strategy program.
210
+ *
211
+ * Discriminator verified against IDL:
212
+ * sha256("global:close_strategy_state")[..8] = [126, 163, 50, 191, 191, 74, 84, 53]
213
+ */
214
+ function createCloseStrategyStateIx(args, programId = constants_1.PROGRAM_ID) {
215
+ const { admin, payer, config, strategyState, baseMint, jlpMint, strategyBaseAta, strategyJlpAta, tokenProgram, } = args;
216
+ // Discriminator only — no additional instruction data
217
+ const data = Buffer.alloc(8);
218
+ constants_1.IX_CLOSE_STRATEGY_STATE.copy(data, 0);
219
+ return new web3_js_1.TransactionInstruction({
220
+ keys: [
221
+ { pubkey: admin, isSigner: true, isWritable: false },
222
+ { pubkey: payer, isSigner: false, isWritable: true },
223
+ { pubkey: config, isSigner: false, isWritable: false },
224
+ { pubkey: strategyState, isSigner: false, isWritable: true },
225
+ { pubkey: baseMint, isSigner: false, isWritable: false },
226
+ { pubkey: jlpMint, isSigner: false, isWritable: false },
227
+ { pubkey: strategyBaseAta, isSigner: false, isWritable: false },
228
+ { pubkey: strategyJlpAta, isSigner: false, isWritable: false },
229
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
230
+ ],
231
+ programId,
232
+ data,
233
+ });
234
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Jupiter Lend Borrow (Fluid Vaults) — account constants and position reading.
3
+ *
4
+ * The instruction builders for deposit/withdraw are in adapter.ts.
5
+ * This file provides static account addresses and position parsing utilities.
6
+ *
7
+ * @remarks
8
+ * Read-only utilities for displaying JLP Borrow positions. This module exports
9
+ * **no instruction builders** — all on-chain operations against the Jupiter
10
+ * Lend Borrow program are routed through `adapter.ts`. The exports here are:
11
+ *
12
+ * - Static program / account constants (program IDs, vault accounts, oracles)
13
+ * - `parsePosition` — deserializes a position account
14
+ * - `readBorrowExchangePrice` — reads the vault state exchange price
15
+ *
16
+ * Anything new that needs to *send transactions* should live in `adapter.ts`.
17
+ */
18
+ import { PublicKey } from "@solana/web3.js";
19
+ import BN from "bn.js";
20
+ export declare const JUP_LEND_BORROW_PROGRAM: PublicKey;
21
+ export declare const BORROW_VAULT_CONFIG: PublicKey;
22
+ export declare const BORROW_VAULT_STATE: PublicKey;
23
+ export declare const BORROW_ORACLE: PublicKey;
24
+ export declare const SUPPLY_RESERVES_LIQUIDITY: PublicKey;
25
+ export declare const BORROW_RESERVES_LIQUIDITY: PublicKey;
26
+ export declare const VAULT_SUPPLY_POS_ON_LIQ: PublicKey;
27
+ export declare const VAULT_BORROW_POS_ON_LIQ: PublicKey;
28
+ export declare const SUPPLY_RATE_MODEL: PublicKey;
29
+ export declare const BORROW_RATE_MODEL: PublicKey;
30
+ export declare const VAULT_SUPPLY_ATA: PublicKey;
31
+ export declare const VAULT_BORROW_ATA: PublicKey;
32
+ export declare const NEW_BRANCH: PublicKey;
33
+ export declare const LIQUIDITY: PublicKey;
34
+ export declare const LIQUIDITY_PROGRAM: PublicKey;
35
+ export declare const ORACLE_PROGRAM: PublicKey;
36
+ export declare const JLP_JUPUSD_VAULT_ID = 58;
37
+ export declare const POSITION_DISCRIMINATOR: Buffer<ArrayBuffer>;
38
+ export interface BorrowPosition {
39
+ tick: number;
40
+ supplyAmount: BN;
41
+ dustDebtAmount: BN;
42
+ positionMint: PublicKey;
43
+ }
44
+ /**
45
+ * Parse a Jupiter Lend Borrow Position account.
46
+ *
47
+ * Layout (offsets include the 8-byte discriminator):
48
+ * [ 0.. 8] discriminator (sha256("account:Position")[..8] —
49
+ * value documented in `POSITION_DISCRIMINATOR`)
50
+ * [ 8.. 14] _padding [u8; 6]
51
+ * [ 14.. 46] positionMint Pubkey (NFT mint that owns this position)
52
+ * [ 46.. 47] _padding u8
53
+ * [ 47.. 51] tick i32 (signed Fluid Vaults tick)
54
+ * [ 51.. 55] _padding [u8; 4]
55
+ * [ 55.. 63] supplyAmount u64 (collateral)
56
+ * [ 63.. 71] dustDebtAmount u64 (residual borrow)
57
+ */
58
+ export declare function parsePosition(data: Buffer): BorrowPosition;
59
+ /**
60
+ * Read the exchange price (1e12 precision) from a Jupiter Lend Borrow VaultState
61
+ * account. The price is at offset 107 (u64 LE) within the account data.
62
+ */
63
+ export declare function readBorrowExchangePrice(vaultStateData: Buffer): BN;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * Jupiter Lend Borrow (Fluid Vaults) — account constants and position reading.
4
+ *
5
+ * The instruction builders for deposit/withdraw are in adapter.ts.
6
+ * This file provides static account addresses and position parsing utilities.
7
+ *
8
+ * @remarks
9
+ * Read-only utilities for displaying JLP Borrow positions. This module exports
10
+ * **no instruction builders** — all on-chain operations against the Jupiter
11
+ * Lend Borrow program are routed through `adapter.ts`. The exports here are:
12
+ *
13
+ * - Static program / account constants (program IDs, vault accounts, oracles)
14
+ * - `parsePosition` — deserializes a position account
15
+ * - `readBorrowExchangePrice` — reads the vault state exchange price
16
+ *
17
+ * Anything new that needs to *send transactions* should live in `adapter.ts`.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.POSITION_DISCRIMINATOR = exports.JLP_JUPUSD_VAULT_ID = exports.ORACLE_PROGRAM = exports.LIQUIDITY_PROGRAM = exports.LIQUIDITY = exports.NEW_BRANCH = exports.VAULT_BORROW_ATA = exports.VAULT_SUPPLY_ATA = exports.BORROW_RATE_MODEL = exports.SUPPLY_RATE_MODEL = exports.VAULT_BORROW_POS_ON_LIQ = exports.VAULT_SUPPLY_POS_ON_LIQ = exports.BORROW_RESERVES_LIQUIDITY = exports.SUPPLY_RESERVES_LIQUIDITY = exports.BORROW_ORACLE = exports.BORROW_VAULT_STATE = exports.BORROW_VAULT_CONFIG = exports.JUP_LEND_BORROW_PROGRAM = void 0;
21
+ exports.parsePosition = parsePosition;
22
+ exports.readBorrowExchangePrice = readBorrowExchangePrice;
23
+ const web3_js_1 = require("@solana/web3.js");
24
+ const buffer_1 = require("../common/buffer");
25
+ // ============================================================================
26
+ // Jupiter Lend Borrow Program
27
+ // ============================================================================
28
+ exports.JUP_LEND_BORROW_PROGRAM = new web3_js_1.PublicKey("jupr81YtYssSyPt8jbnGuiWon5f6x9TcDEFxYe3Bdzi");
29
+ // ============================================================================
30
+ // JLP → JupUSD Fluid Vault — Static Accounts
31
+ // ============================================================================
32
+ exports.BORROW_VAULT_CONFIG = new web3_js_1.PublicKey("3b5bK5PspMmVmA6ZkqXcKtLTskPJGvkJZqjCezspLBu8");
33
+ exports.BORROW_VAULT_STATE = new web3_js_1.PublicKey("4nzptpV8dMv9D6CnsqmNMQJ5TVnRGQDES75a1FWi23YL");
34
+ exports.BORROW_ORACLE = new web3_js_1.PublicKey("25UZhqEoQeMA2ovbM1PgwZbU3NGUA8eM2y5g1j58YmFV");
35
+ exports.SUPPLY_RESERVES_LIQUIDITY = new web3_js_1.PublicKey("2cYcYwTWHkiszdzDs8aPq1fkcpipJ8zVEzwCXo5RzXpx");
36
+ exports.BORROW_RESERVES_LIQUIDITY = new web3_js_1.PublicKey("2tQE8jVR5ezDw3PDa21BNzfyQ14Ug5cTf6n3swJNjkod");
37
+ exports.VAULT_SUPPLY_POS_ON_LIQ = new web3_js_1.PublicKey("fHbvnrFe9ywN9hc8SZHdxFUcMWrgSMmVXfYdizQALkR");
38
+ exports.VAULT_BORROW_POS_ON_LIQ = new web3_js_1.PublicKey("2fewCticRvPLQbC1EczxF7Fv46J7HK9hdyTHVopy1Wg9");
39
+ exports.SUPPLY_RATE_MODEL = new web3_js_1.PublicKey("9miY226e1qR9YgHfCE6hTKTxMRiyFZSUUTcdeZD6Ntmw");
40
+ exports.BORROW_RATE_MODEL = new web3_js_1.PublicKey("2hT44GA9r5PiqsbbmqN5CuF7ymtquoEdokRncAs9CVej");
41
+ exports.VAULT_SUPPLY_ATA = new web3_js_1.PublicKey("EJ6CLvJPJErjkUnPQicVahzw4Q4NHLfpDV9knoP7iqfK");
42
+ exports.VAULT_BORROW_ATA = new web3_js_1.PublicKey("9kGqd5zsQGaFfFPdUuEgbRM4V7x72Jdt7WTS4uRouAQ7");
43
+ exports.NEW_BRANCH = new web3_js_1.PublicKey("BpdVtFA1FmQkXdcdjPNDb3TL86VdKcHqRU9dNfBrRD1i");
44
+ exports.LIQUIDITY = new web3_js_1.PublicKey("7s1da8DduuBFqGra5bJBjpnvL5E9mGzCuMk1Qkh4or2Z");
45
+ exports.LIQUIDITY_PROGRAM = new web3_js_1.PublicKey("jupeiUmn818Jg1ekPURTpr4mFo29p46vygyykFJ3wZC");
46
+ exports.ORACLE_PROGRAM = new web3_js_1.PublicKey("jupnw4B6Eqs7ft6rxpzYLJZYSnrpRgPcr589n5Kv4oc");
47
+ exports.JLP_JUPUSD_VAULT_ID = 58;
48
+ // ============================================================================
49
+ // Position Account Parsing
50
+ // ============================================================================
51
+ exports.POSITION_DISCRIMINATOR = Buffer.from([0xaa, 0xbc, 0x8f, 0xe4, 0x7a, 0x40, 0xf7, 0xd0]);
52
+ /**
53
+ * Parse a Jupiter Lend Borrow Position account.
54
+ *
55
+ * Layout (offsets include the 8-byte discriminator):
56
+ * [ 0.. 8] discriminator (sha256("account:Position")[..8] —
57
+ * value documented in `POSITION_DISCRIMINATOR`)
58
+ * [ 8.. 14] _padding [u8; 6]
59
+ * [ 14.. 46] positionMint Pubkey (NFT mint that owns this position)
60
+ * [ 46.. 47] _padding u8
61
+ * [ 47.. 51] tick i32 (signed Fluid Vaults tick)
62
+ * [ 51.. 55] _padding [u8; 4]
63
+ * [ 55.. 63] supplyAmount u64 (collateral)
64
+ * [ 63.. 71] dustDebtAmount u64 (residual borrow)
65
+ */
66
+ function parsePosition(data) {
67
+ if (data.length < 71)
68
+ throw new Error(`Position data too short: ${data.length}`);
69
+ const disc = data.subarray(0, 8);
70
+ if (!disc.equals(exports.POSITION_DISCRIMINATOR))
71
+ throw new Error("Invalid Position discriminator");
72
+ return {
73
+ positionMint: new web3_js_1.PublicKey(data.subarray(14, 46)),
74
+ tick: data.readInt32LE(47),
75
+ supplyAmount: (0, buffer_1.readU64)(data, 55),
76
+ dustDebtAmount: (0, buffer_1.readU64)(data, 63),
77
+ };
78
+ }
79
+ /**
80
+ * Read the exchange price (1e12 precision) from a Jupiter Lend Borrow VaultState
81
+ * account. The price is at offset 107 (u64 LE) within the account data.
82
+ */
83
+ function readBorrowExchangePrice(vaultStateData) {
84
+ if (vaultStateData.length < 115)
85
+ throw new Error("VaultState data too short");
86
+ return (0, buffer_1.readU64)(vaultStateData, 107);
87
+ }