@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.
Files changed (149) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +250 -0
  3. package/dist/common/ata.d.ts +14 -0
  4. package/dist/common/ata.js +21 -0
  5. package/dist/common/buffer.d.ts +0 -1
  6. package/dist/common/buffer.js +16 -1
  7. package/dist/common/connection.d.ts +13 -0
  8. package/dist/common/connection.js +2 -0
  9. package/dist/common/constants.d.ts +6 -1
  10. package/dist/common/constants.js +21 -2
  11. package/dist/common/index.d.ts +3 -2
  12. package/dist/common/index.js +6 -2
  13. package/dist/common/strategy-interface.d.ts +35 -5
  14. package/dist/common/strategy-interface.js +7 -5
  15. package/dist/elemental-lend/accounts.d.ts +53 -9
  16. package/dist/elemental-lend/accounts.js +66 -8
  17. package/dist/elemental-lend/constants.d.ts +6 -7
  18. package/dist/elemental-lend/constants.js +13 -12
  19. package/dist/elemental-lend/index.d.ts +0 -1
  20. package/dist/elemental-lend/index.js +0 -1
  21. package/dist/elemental-lend/instructions.d.ts +0 -1
  22. package/dist/elemental-lend/instructions.js +0 -1
  23. package/dist/elemental-lend/jupiter-lend.d.ts +0 -1
  24. package/dist/elemental-lend/jupiter-lend.js +2 -3
  25. package/dist/elemental-lend/kamino-vault.d.ts +6 -6
  26. package/dist/elemental-lend/kamino-vault.js +49 -26
  27. package/dist/elemental-lend/pda.d.ts +9 -2
  28. package/dist/elemental-lend/pda.js +10 -3
  29. package/dist/elemental-lend/protocol-actions.d.ts +6 -5
  30. package/dist/elemental-lend/protocol-actions.js +22 -17
  31. package/dist/elemental-lend/types.d.ts +0 -1
  32. package/dist/elemental-lend/types.js +0 -1
  33. package/dist/index.d.ts +0 -1
  34. package/dist/index.js +0 -1
  35. package/dist/jlpd-strategy/accounts.d.ts +64 -11
  36. package/dist/jlpd-strategy/accounts.js +66 -7
  37. package/dist/jlpd-strategy/adapter.d.ts +60 -0
  38. package/dist/jlpd-strategy/adapter.js +90 -0
  39. package/dist/jlpd-strategy/constants.d.ts +27 -16
  40. package/dist/jlpd-strategy/constants.js +40 -29
  41. package/dist/jlpd-strategy/index.d.ts +3 -1
  42. package/dist/jlpd-strategy/index.js +3 -1
  43. package/dist/jlpd-strategy/instructions.d.ts +0 -1
  44. package/dist/jlpd-strategy/instructions.js +0 -1
  45. package/dist/jlpd-strategy/jlp-borrow.d.ts +63 -0
  46. package/dist/jlpd-strategy/jlp-borrow.js +87 -0
  47. package/dist/jlpd-strategy/jlp-data.d.ts +4 -4
  48. package/dist/jlpd-strategy/jlp-data.js +0 -1
  49. package/dist/jlpd-strategy/jupusd-earn.d.ts +90 -0
  50. package/dist/jlpd-strategy/jupusd-earn.js +166 -0
  51. package/dist/jlpd-strategy/pda.d.ts +9 -4
  52. package/dist/jlpd-strategy/pda.js +10 -6
  53. package/dist/jlpd-strategy/settle-yield.d.ts +12 -45
  54. package/dist/jlpd-strategy/settle-yield.js +14 -19
  55. package/dist/jlpd-strategy/swap-jlp.d.ts +4 -4
  56. package/dist/jlpd-strategy/swap-jlp.js +35 -27
  57. package/dist/jlpd-strategy/types.d.ts +5 -4
  58. package/dist/jlpd-strategy/types.js +0 -1
  59. package/dist/p-stv-core/accounts.d.ts +84 -11
  60. package/dist/p-stv-core/accounts.js +83 -5
  61. package/dist/p-stv-core/constants.d.ts +13 -3
  62. package/dist/p-stv-core/constants.js +23 -11
  63. package/dist/p-stv-core/events.d.ts +0 -1
  64. package/dist/p-stv-core/events.js +50 -1
  65. package/dist/p-stv-core/index.d.ts +0 -1
  66. package/dist/p-stv-core/index.js +0 -1
  67. package/dist/p-stv-core/instructions.d.ts +49 -4
  68. package/dist/p-stv-core/instructions.js +46 -14
  69. package/dist/p-stv-core/pda.d.ts +9 -2
  70. package/dist/p-stv-core/pda.js +10 -3
  71. package/dist/p-stv-core/prices.d.ts +0 -1
  72. package/dist/p-stv-core/prices.js +0 -1
  73. package/dist/p-stv-core/remaining-accounts.d.ts +13 -14
  74. package/dist/p-stv-core/remaining-accounts.js +53 -46
  75. package/dist/p-stv-core/send-tx.d.ts +23 -7
  76. package/dist/p-stv-core/send-tx.js +17 -26
  77. package/dist/p-stv-core/sol-wrap.d.ts +0 -1
  78. package/dist/p-stv-core/sol-wrap.js +5 -6
  79. package/dist/p-stv-core/types.d.ts +9 -2
  80. package/dist/p-stv-core/types.js +0 -1
  81. package/package.json +17 -1
  82. package/dist/common/buffer.d.ts.map +0 -1
  83. package/dist/common/buffer.js.map +0 -1
  84. package/dist/common/constants.d.ts.map +0 -1
  85. package/dist/common/constants.js.map +0 -1
  86. package/dist/common/index.d.ts.map +0 -1
  87. package/dist/common/index.js.map +0 -1
  88. package/dist/common/strategy-interface.d.ts.map +0 -1
  89. package/dist/common/strategy-interface.js.map +0 -1
  90. package/dist/elemental-lend/accounts.d.ts.map +0 -1
  91. package/dist/elemental-lend/accounts.js.map +0 -1
  92. package/dist/elemental-lend/constants.d.ts.map +0 -1
  93. package/dist/elemental-lend/constants.js.map +0 -1
  94. package/dist/elemental-lend/index.d.ts.map +0 -1
  95. package/dist/elemental-lend/index.js.map +0 -1
  96. package/dist/elemental-lend/instructions.d.ts.map +0 -1
  97. package/dist/elemental-lend/instructions.js.map +0 -1
  98. package/dist/elemental-lend/jupiter-lend.d.ts.map +0 -1
  99. package/dist/elemental-lend/jupiter-lend.js.map +0 -1
  100. package/dist/elemental-lend/kamino-vault.d.ts.map +0 -1
  101. package/dist/elemental-lend/kamino-vault.js.map +0 -1
  102. package/dist/elemental-lend/pda.d.ts.map +0 -1
  103. package/dist/elemental-lend/pda.js.map +0 -1
  104. package/dist/elemental-lend/protocol-actions.d.ts.map +0 -1
  105. package/dist/elemental-lend/protocol-actions.js.map +0 -1
  106. package/dist/elemental-lend/types.d.ts.map +0 -1
  107. package/dist/elemental-lend/types.js.map +0 -1
  108. package/dist/index.d.ts.map +0 -1
  109. package/dist/index.js.map +0 -1
  110. package/dist/jlpd-strategy/accounts.d.ts.map +0 -1
  111. package/dist/jlpd-strategy/accounts.js.map +0 -1
  112. package/dist/jlpd-strategy/constants.d.ts.map +0 -1
  113. package/dist/jlpd-strategy/constants.js.map +0 -1
  114. package/dist/jlpd-strategy/index.d.ts.map +0 -1
  115. package/dist/jlpd-strategy/index.js.map +0 -1
  116. package/dist/jlpd-strategy/instructions.d.ts.map +0 -1
  117. package/dist/jlpd-strategy/instructions.js.map +0 -1
  118. package/dist/jlpd-strategy/jlp-data.d.ts.map +0 -1
  119. package/dist/jlpd-strategy/jlp-data.js.map +0 -1
  120. package/dist/jlpd-strategy/pda.d.ts.map +0 -1
  121. package/dist/jlpd-strategy/pda.js.map +0 -1
  122. package/dist/jlpd-strategy/settle-yield.d.ts.map +0 -1
  123. package/dist/jlpd-strategy/settle-yield.js.map +0 -1
  124. package/dist/jlpd-strategy/swap-jlp.d.ts.map +0 -1
  125. package/dist/jlpd-strategy/swap-jlp.js.map +0 -1
  126. package/dist/jlpd-strategy/types.d.ts.map +0 -1
  127. package/dist/jlpd-strategy/types.js.map +0 -1
  128. package/dist/p-stv-core/accounts.d.ts.map +0 -1
  129. package/dist/p-stv-core/accounts.js.map +0 -1
  130. package/dist/p-stv-core/constants.d.ts.map +0 -1
  131. package/dist/p-stv-core/constants.js.map +0 -1
  132. package/dist/p-stv-core/events.d.ts.map +0 -1
  133. package/dist/p-stv-core/events.js.map +0 -1
  134. package/dist/p-stv-core/index.d.ts.map +0 -1
  135. package/dist/p-stv-core/index.js.map +0 -1
  136. package/dist/p-stv-core/instructions.d.ts.map +0 -1
  137. package/dist/p-stv-core/instructions.js.map +0 -1
  138. package/dist/p-stv-core/pda.d.ts.map +0 -1
  139. package/dist/p-stv-core/pda.js.map +0 -1
  140. package/dist/p-stv-core/prices.d.ts.map +0 -1
  141. package/dist/p-stv-core/prices.js.map +0 -1
  142. package/dist/p-stv-core/remaining-accounts.d.ts.map +0 -1
  143. package/dist/p-stv-core/remaining-accounts.js.map +0 -1
  144. package/dist/p-stv-core/send-tx.d.ts.map +0 -1
  145. package/dist/p-stv-core/send-tx.js.map +0 -1
  146. package/dist/p-stv-core/sol-wrap.d.ts.map +0 -1
  147. package/dist/p-stv-core/sol-wrap.js.map +0 -1
  148. package/dist/p-stv-core/types.d.ts.map +0 -1
  149. package/dist/p-stv-core/types.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JLPD_VAULT_IDS = 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.JLP_VAULT_SIZE = exports.STV_POSITION_SIZE = exports.STRATEGY_STATE_SIZE = exports.MANAGER_ROLE_SIZE = exports.JLPD_CONFIG_SIZE = exports.IX_INIT_OR_UPDATE_JLP_VAULT = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_SETTLE_YIELD = 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_JLP_VAULT = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.DISC_MANAGER_ROLE = exports.DISC_JLPD_CONFIG = exports.JLP_VAULT_SEED = 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;
3
+ exports.JLPD_VAULT_IDS_BY_POOL = 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_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 = void 0;
4
5
  const web3_js_1 = require("@solana/web3.js");
5
6
  exports.PROGRAM_ID = new web3_js_1.PublicKey("GXqt4ZH2UUBsLWwMNJiZMXza3q7xEGChfW8XjVRjLxr5");
6
7
  exports.PROGRAM_ID_MAINNET = exports.PROGRAM_ID;
@@ -27,17 +28,14 @@ exports.CONFIG_SEED = Buffer.from("config");
27
28
  exports.MANAGER_SEED = Buffer.from("manager");
28
29
  exports.STRATEGY_STATE_SEED = Buffer.from("strategy_state");
29
30
  exports.POSITION_SEED = Buffer.from("position");
30
- /** @deprecated Use CONFIG_SEED instead */
31
- exports.JLP_VAULT_SEED = exports.CONFIG_SEED;
32
31
  // Account discriminators (Anchor 8-byte)
33
- // sha256("account:JlpdConfig")[..8]
32
+ // sha256("account:JlpdConfig")[..8] — JLPD-specific
34
33
  exports.DISC_JLPD_CONFIG = Buffer.from([185, 146, 185, 28, 172, 71, 122, 38]);
35
- // sha256("account:ManagerRole")[..8]
36
- exports.DISC_MANAGER_ROLE = Buffer.from([37, 232, 100, 233, 170, 233, 219, 185]);
37
- exports.DISC_STRATEGY_STATE = Buffer.from([83, 18, 224, 109, 174, 100, 39, 139]);
38
- exports.DISC_STV_POSITION = Buffer.from([47, 212, 251, 176, 138, 160, 30, 87]);
39
- /** @deprecated Use DISC_JLPD_CONFIG instead */
40
- exports.DISC_JLP_VAULT = exports.DISC_JLPD_CONFIG;
34
+ // Shared types — defined once in common/, re-exported here
35
+ var constants_1 = require("../common/constants");
36
+ Object.defineProperty(exports, "DISC_STRATEGY_STATE", { enumerable: true, get: function () { return constants_1.DISC_STRATEGY_STATE; } });
37
+ Object.defineProperty(exports, "DISC_STV_POSITION", { enumerable: true, get: function () { return constants_1.DISC_STV_POSITION; } });
38
+ Object.defineProperty(exports, "DISC_MANAGER_ROLE", { enumerable: true, get: function () { return constants_1.DISC_MANAGER_ROLE; } });
41
39
  // Instruction discriminators (Anchor 8-byte)
42
40
  exports.IX_INIT_OR_UPDATE_CONFIG = Buffer.from([234, 24, 218, 120, 213, 149, 245, 213]);
43
41
  exports.IX_INIT_OR_UPDATE_STRATEGY_STATE = Buffer.from([223, 7, 93, 99, 12, 44, 180, 255]);
@@ -48,19 +46,21 @@ exports.IX_WITHDRAW = Buffer.from([183, 18, 70, 156, 148, 109, 161, 34]);
48
46
  exports.IX_UPDATE_AUM = Buffer.from([162, 40, 227, 16, 84, 169, 182, 185]);
49
47
  exports.IX_SWAP_JLP = Buffer.from([190, 44, 224, 191, 169, 243, 146, 127]);
50
48
  exports.IX_SETTLE_YIELD = Buffer.from([64, 28, 44, 24, 43, 204, 58, 215]);
49
+ // sha256("global:deposit_to_adapter")[..8]
50
+ exports.IX_DEPOSIT_TO_ADAPTER = Buffer.from([123, 167, 9, 180, 75, 80, 195, 219]);
51
+ // sha256("global:withdraw_from_adapter")[..8]
52
+ exports.IX_WITHDRAW_FROM_ADAPTER = Buffer.from([87, 57, 243, 113, 157, 131, 135, 83]);
53
+ // sha256("global:adapter_manage")[..8]
54
+ exports.IX_ADAPTER_MANAGE = Buffer.from([210, 30, 127, 237, 109, 210, 2, 212]);
51
55
  // sha256("global:add_manager")[..8]
52
56
  exports.IX_ADD_MANAGER = Buffer.from([125, 38, 192, 212, 101, 91, 179, 16]);
53
57
  // sha256("global:remove_manager")[..8]
54
58
  exports.IX_REMOVE_MANAGER = Buffer.from([150, 55, 157, 77, 128, 148, 7, 15]);
55
- /** @deprecated Use IX_INIT_OR_UPDATE_CONFIG instead */
56
- exports.IX_INIT_OR_UPDATE_JLP_VAULT = exports.IX_INIT_OR_UPDATE_CONFIG;
57
59
  // Account sizes
58
- exports.JLPD_CONFIG_SIZE = 272;
60
+ exports.JLPD_CONFIG_SIZE = 392;
59
61
  exports.MANAGER_ROLE_SIZE = 80;
60
- exports.STRATEGY_STATE_SIZE = 160;
61
- exports.STV_POSITION_SIZE = 56;
62
- /** @deprecated Use JLPD_CONFIG_SIZE instead */
63
- exports.JLP_VAULT_SIZE = exports.JLPD_CONFIG_SIZE;
62
+ exports.STRATEGY_STATE_SIZE = 224;
63
+ exports.STV_POSITION_SIZE = 120;
64
64
  // Flags
65
65
  exports.FLAG_PAUSED = 0x0001;
66
66
  exports.FLAG_DEPOSITS_DISABLED = 0x0002;
@@ -72,15 +72,26 @@ exports.FLAG_TEST_MODE = 0x0020;
72
72
  exports.NUM_ASSETS = 5;
73
73
  exports.MAX_MGMT_FEE_BPS = 500;
74
74
  exports.MAX_PERF_FEE_BPS = 3000;
75
- var constants_1 = require("../common/constants");
76
- Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_1.PPS_DECIMALS; } });
77
- Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_1.BPS_DENOMINATOR; } });
78
- /** Maps base_mint address → p-STV Core vault_id for JLPD strategy STVs */
79
- exports.JLPD_VAULT_IDS = {
80
- "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh": 11, // BTC
81
- "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs": 12, // ETH
82
- "So11111111111111111111111111111111111111112": 13, // SOL
83
- "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v": 14, // USDC
84
- "JuprjznTrTSp2UFa3ZBUFgwdAmtZCq4MQCwysN55USD": 15, // JupUSD
85
- };
86
- //# sourceMappingURL=constants.js.map
75
+ var constants_2 = require("../common/constants");
76
+ Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_2.PPS_DECIMALS; } });
77
+ Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_2.BPS_DENOMINATOR; } });
78
+ /** Stable per-pool registry for JLPD strategy STVs.
79
+ *
80
+ * Each entry is the canonical record for a pool: short symbol, base mint
81
+ * address (base58), p-STV Core vault id, and base mint decimals. The
82
+ * `JLPD_VAULT_IDS` and `JLPD_POOL_NAMES_BY_VAULT_ID` lookups below are
83
+ * derived from this single table so consumers cannot get out of sync.
84
+ */
85
+ exports.JLPD_POOLS = [
86
+ { name: "BTC", mint: "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", vaultId: 11, decimals: 8 },
87
+ { name: "ETH", mint: "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", vaultId: 12, decimals: 8 },
88
+ { name: "SOL", mint: "So11111111111111111111111111111111111111112", vaultId: 13, decimals: 9 },
89
+ { name: "USDC", mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", vaultId: 14, decimals: 6 },
90
+ { name: "JupUSD", mint: "JuprjznTrTSp2UFa3ZBUFgwdAmtZCq4MQCwysN55USD", vaultId: 15, decimals: 6 },
91
+ ];
92
+ /** Lookup: base_mint (base58) → vault_id. Derived from `JLPD_POOLS`. */
93
+ exports.JLPD_VAULT_IDS = Object.fromEntries(exports.JLPD_POOLS.map((p) => [p.mint, p.vaultId]));
94
+ /** Lookup: pool symbol → vault_id. Derived from `JLPD_POOLS`. */
95
+ exports.JLPD_VAULT_IDS_BY_POOL = Object.fromEntries(exports.JLPD_POOLS.map((p) => [p.name, p.vaultId]));
96
+ /** Lookup: pool symbol → base mint decimals. Derived from `JLPD_POOLS`. */
97
+ exports.JLPD_POOL_DECIMALS = Object.fromEntries(exports.JLPD_POOLS.map((p) => [p.name, p.decimals]));
@@ -6,4 +6,6 @@ export * from "./instructions";
6
6
  export * from "./swap-jlp";
7
7
  export * from "./settle-yield";
8
8
  export * from "./jlp-data";
9
- //# sourceMappingURL=index.d.ts.map
9
+ export * from "./jlp-borrow";
10
+ export * from "./jupusd-earn";
11
+ export * from "./adapter";
@@ -22,4 +22,6 @@ __exportStar(require("./instructions"), exports);
22
22
  __exportStar(require("./swap-jlp"), exports);
23
23
  __exportStar(require("./settle-yield"), exports);
24
24
  __exportStar(require("./jlp-data"), exports);
25
- //# sourceMappingURL=index.js.map
25
+ __exportStar(require("./jlp-borrow"), exports);
26
+ __exportStar(require("./jupusd-earn"), exports);
27
+ __exportStar(require("./adapter"), exports);
@@ -38,4 +38,3 @@ export interface RemoveManagerArgs {
38
38
  * 3. manager_role (writable — closed)
39
39
  */
40
40
  export declare function createRemoveManagerIx(args: RemoveManagerArgs, programId?: PublicKey): TransactionInstruction;
41
- //# sourceMappingURL=instructions.d.ts.map
@@ -61,4 +61,3 @@ function createRemoveManagerIx(args, programId = constants_1.PROGRAM_ID) {
61
61
  data,
62
62
  });
63
63
  }
64
- //# sourceMappingURL=instructions.js.map
@@ -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
+ }
@@ -1,4 +1,5 @@
1
- import { Connection, PublicKey } from "@solana/web3.js";
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import type { SolanaConnection } from "../common/connection";
2
3
  export type CustodyName = "SOL" | "ETH" | "WBTC" | "USDC" | "USDT";
3
4
  export interface JlpCustody {
4
5
  name: CustodyName;
@@ -43,7 +44,7 @@ export interface JlpPoolDetails {
43
44
  * Reads the Pool account for fees and aumUsd, Custody accounts for per-asset
44
45
  * data including target weights, and the JLP mint for total supply.
45
46
  */
46
- export declare function fetchJlpPoolDetails(connection: Connection): Promise<JlpPoolDetails>;
47
+ export declare function fetchJlpPoolDetails(connection: SolanaConnection): Promise<JlpPoolDetails>;
47
48
  /**
48
49
  * Estimate the addLiquidity fee for depositing into a specific JLP custody.
49
50
  *
@@ -69,5 +70,4 @@ export declare function computeAddLiquidityFee(args: {
69
70
  feeBps: number;
70
71
  isDiscount: boolean;
71
72
  };
72
- export declare function fetchJlpCustodyData(connection: Connection): Promise<JlpData>;
73
- //# sourceMappingURL=jlp-data.d.ts.map
73
+ export declare function fetchJlpCustodyData(connection: SolanaConnection): Promise<JlpData>;
@@ -403,4 +403,3 @@ async function fetchJlpCustodyData(connection) {
403
403
  custodies: results,
404
404
  };
405
405
  }
406
- //# sourceMappingURL=jlp-data.js.map
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Jupiter Lend Earn SDK helpers for JLPD Strategy.
3
+ *
4
+ * Provides position reading and APR computation for the JupUSD Earn
5
+ * pool used by the JLP Borrow / JupUSD Earn route.
6
+ *
7
+ * Reuses the JupUSD pool config from elemental-lend/jupiter-lend.ts
8
+ * since it's the same Jupiter Lend Earn program and pool.
9
+ *
10
+ * @remarks
11
+ * Read-only utilities for displaying JupUSD Earn positions. This module exports
12
+ * **no instruction builders** — all on-chain operations against the Jupiter
13
+ * Lend Earn program are routed through `adapter.ts`. The exports here are:
14
+ *
15
+ * - Static program / account constants for the JupUSD Earn pool
16
+ * - `computeExchangeRate`, `computeFTokenValue`, `computeEarnApr` — math
17
+ * - `fetchEarnPosition` — read-only position fetcher
18
+ *
19
+ * Anything new that needs to *send transactions* should live in `adapter.ts`.
20
+ */
21
+ import { PublicKey } from "@solana/web3.js";
22
+ import BN from "bn.js";
23
+ import type { SolanaConnection } from "../common/connection";
24
+ import { JUP_LEND_EARN_PROGRAM } from "../elemental-lend/constants";
25
+ /**
26
+ * Jupiter Lend Earn program ID. Re-exported from `elemental-lend/constants`
27
+ * so callers of `jlpd-strategy/jupusd-earn` can reach it without an extra
28
+ * import path.
29
+ */
30
+ export { JUP_LEND_EARN_PROGRAM };
31
+ export declare const JUPUSD_LENDING: PublicKey;
32
+ export declare const JUPUSD_FTOKEN_MINT: PublicKey;
33
+ export declare const JUPUSD_RESERVES_LIQUIDITY: PublicKey;
34
+ export declare const JUPUSD_SUPPLY_POS_ON_LIQ: PublicKey;
35
+ export declare const JUPUSD_RATE_MODEL: PublicKey;
36
+ export declare const JUPUSD_VAULT: PublicKey;
37
+ export declare const JUPUSD_REWARDS_RATE_MODEL: PublicKey;
38
+ export declare const JUPUSD_LENDING_ADMIN: PublicKey;
39
+ /**
40
+ * Read the earn exchange rate from lending account + rewards model.
41
+ * Returns the rate scaled to 1e12.
42
+ *
43
+ * Jupiter Lend Earn lending account layout (relevant fields):
44
+ * [115..123] baseExchangePrice u64 (1e12 precision)
45
+ * [123..131] lastUpdate u64 (unix seconds)
46
+ *
47
+ * Jupiter Lend rewards rate model layout (relevant fields):
48
+ * [ 56.. 64] startTime u64 (unix seconds)
49
+ * [ 64.. 72] yearlyReward u64 (rewards distributed per year)
50
+ */
51
+ export declare function computeExchangeRate(lendingData: Buffer, rewardsModelData: Buffer, fTokenTotalSupply: BN, currentTimestamp: number): bigint;
52
+ /**
53
+ * Compute the value of fTokens in JupUSD (native 6-decimal).
54
+ */
55
+ export declare function computeFTokenValue(fTokenBalance: BN, exchangeRate: bigint): BN;
56
+ export interface EarnAprBreakdown {
57
+ lendingApr: number;
58
+ rewardsApr: number;
59
+ totalApr: number;
60
+ }
61
+ /**
62
+ * Compute earn APR breakdown: base lending + rewards.
63
+ *
64
+ * Total APR is derived by projecting the exchange rate 1 year forward
65
+ * (captures both lending yield and rewards). Rewards APR is isolated
66
+ * from yearly_reward / total_assets. Base = total - rewards.
67
+ */
68
+ /**
69
+ * Compute earn APR breakdown: base lending + rewards.
70
+ *
71
+ * Reads the liquidity pool's supply rate from the liquidity account,
72
+ * and the rewards rate from the rewards model. Requires the liquidity
73
+ * account data as an additional parameter.
74
+ *
75
+ * @param rewardsModelData - Rewards rate model account data
76
+ * @param fTokenTotalSupply - fToken total supply (from mint)
77
+ * @param tokenExchangePrice - From lending account offset 115
78
+ * @param liquiditySupplyRate - Supply rate from liquidity pool (pass 0 if unknown)
79
+ */
80
+ export declare function computeEarnApr(rewardsModelData: Buffer, fTokenTotalSupply: BN, tokenExchangePrice: bigint, liquiditySupplyRate?: number): EarnAprBreakdown;
81
+ export interface EarnPositionInfo {
82
+ fTokenBalance: BN;
83
+ jupusdValue: BN;
84
+ apr: EarnAprBreakdown;
85
+ }
86
+ /**
87
+ * Fetch the earn position for a jlpd_config PDA.
88
+ * Returns null if no fToken ATA exists.
89
+ */
90
+ export declare function fetchEarnPosition(connection: SolanaConnection, fTokenAta: PublicKey): Promise<EarnPositionInfo | null>;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ /**
3
+ * Jupiter Lend Earn SDK helpers for JLPD Strategy.
4
+ *
5
+ * Provides position reading and APR computation for the JupUSD Earn
6
+ * pool used by the JLP Borrow / JupUSD Earn route.
7
+ *
8
+ * Reuses the JupUSD pool config from elemental-lend/jupiter-lend.ts
9
+ * since it's the same Jupiter Lend Earn program and pool.
10
+ *
11
+ * @remarks
12
+ * Read-only utilities for displaying JupUSD Earn positions. This module exports
13
+ * **no instruction builders** — all on-chain operations against the Jupiter
14
+ * Lend Earn program are routed through `adapter.ts`. The exports here are:
15
+ *
16
+ * - Static program / account constants for the JupUSD Earn pool
17
+ * - `computeExchangeRate`, `computeFTokenValue`, `computeEarnApr` — math
18
+ * - `fetchEarnPosition` — read-only position fetcher
19
+ *
20
+ * Anything new that needs to *send transactions* should live in `adapter.ts`.
21
+ */
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.JUPUSD_LENDING_ADMIN = exports.JUPUSD_REWARDS_RATE_MODEL = exports.JUPUSD_VAULT = exports.JUPUSD_RATE_MODEL = exports.JUPUSD_SUPPLY_POS_ON_LIQ = exports.JUPUSD_RESERVES_LIQUIDITY = exports.JUPUSD_FTOKEN_MINT = exports.JUPUSD_LENDING = exports.JUP_LEND_EARN_PROGRAM = void 0;
27
+ exports.computeExchangeRate = computeExchangeRate;
28
+ exports.computeFTokenValue = computeFTokenValue;
29
+ exports.computeEarnApr = computeEarnApr;
30
+ exports.fetchEarnPosition = fetchEarnPosition;
31
+ const bn_js_1 = __importDefault(require("bn.js"));
32
+ const buffer_1 = require("../common/buffer");
33
+ const jupiter_lend_1 = require("../elemental-lend/jupiter-lend");
34
+ const constants_1 = require("../elemental-lend/constants");
35
+ Object.defineProperty(exports, "JUP_LEND_EARN_PROGRAM", { enumerable: true, get: function () { return constants_1.JUP_LEND_EARN_PROGRAM; } });
36
+ // ============================================================================
37
+ // JupUSD Earn Pool — Static Accounts
38
+ // ----------------------------------------------------------------------------
39
+ // All pool addresses are imported from `elemental-lend/jupiter-lend.ts` so
40
+ // there is exactly one canonical definition. The named re-exports below are
41
+ // preserved for backwards compatibility with any external consumers.
42
+ // ============================================================================
43
+ exports.JUPUSD_LENDING = jupiter_lend_1.JUPUSD_POOL.lending;
44
+ exports.JUPUSD_FTOKEN_MINT = jupiter_lend_1.JUPUSD_POOL.fTokenMint;
45
+ exports.JUPUSD_RESERVES_LIQUIDITY = jupiter_lend_1.JUPUSD_POOL.tokenReservesLiquidity;
46
+ exports.JUPUSD_SUPPLY_POS_ON_LIQ = jupiter_lend_1.JUPUSD_POOL.supplyPositionOnLiquidity;
47
+ exports.JUPUSD_RATE_MODEL = jupiter_lend_1.JUPUSD_POOL.rateModel;
48
+ exports.JUPUSD_VAULT = jupiter_lend_1.JUPUSD_POOL.vault;
49
+ exports.JUPUSD_REWARDS_RATE_MODEL = jupiter_lend_1.JUPUSD_POOL.rewardsRateModel;
50
+ exports.JUPUSD_LENDING_ADMIN = jupiter_lend_1.LENDING_ADMIN;
51
+ // ============================================================================
52
+ // Exchange Rate / APR Computation
53
+ // ============================================================================
54
+ const EXCHANGE_PRICES_PRECISION = 1000000000000n; // 1e12
55
+ const SECONDS_PER_YEAR = 31536000;
56
+ /**
57
+ * Read the earn exchange rate from lending account + rewards model.
58
+ * Returns the rate scaled to 1e12.
59
+ *
60
+ * Jupiter Lend Earn lending account layout (relevant fields):
61
+ * [115..123] baseExchangePrice u64 (1e12 precision)
62
+ * [123..131] lastUpdate u64 (unix seconds)
63
+ *
64
+ * Jupiter Lend rewards rate model layout (relevant fields):
65
+ * [ 56.. 64] startTime u64 (unix seconds)
66
+ * [ 64.. 72] yearlyReward u64 (rewards distributed per year)
67
+ */
68
+ function computeExchangeRate(lendingData, rewardsModelData, fTokenTotalSupply, currentTimestamp) {
69
+ if (lendingData.length < 131)
70
+ throw new Error("Lending data too short");
71
+ const baseRate = (0, buffer_1.readU64)(lendingData, 115).toNumber();
72
+ const lastUpdate = (0, buffer_1.readU64)(lendingData, 123).toNumber();
73
+ if (rewardsModelData.length < 72)
74
+ return BigInt(baseRate);
75
+ const startTime = (0, buffer_1.readU64)(rewardsModelData, 56).toNumber();
76
+ const yearlyReward = (0, buffer_1.readU64)(rewardsModelData, 64).toNumber();
77
+ if (yearlyReward === 0 || fTokenTotalSupply.isZero())
78
+ return BigInt(baseRate);
79
+ // Compute time-accrued rewards since last update
80
+ const elapsed = Math.max(0, currentTimestamp - Math.max(lastUpdate, startTime));
81
+ const totalAssets = Number((BigInt(fTokenTotalSupply.toString()) * BigInt(baseRate)) / EXCHANGE_PRICES_PRECISION);
82
+ if (totalAssets === 0)
83
+ return BigInt(baseRate);
84
+ // rewards_return = yearly_reward * elapsed / SECONDS_PER_YEAR / total_assets
85
+ // new_rate = base_rate + base_rate * rewards_return / 1e14
86
+ const rewardAmount = (yearlyReward * elapsed) / SECONDS_PER_YEAR;
87
+ const rewardsReturn = Math.floor((rewardAmount * 1e14) / totalAssets);
88
+ const newRate = BigInt(baseRate) + (BigInt(baseRate) * BigInt(rewardsReturn)) / 100000000000000n;
89
+ return newRate;
90
+ }
91
+ /**
92
+ * Compute the value of fTokens in JupUSD (native 6-decimal).
93
+ */
94
+ function computeFTokenValue(fTokenBalance, exchangeRate) {
95
+ const value = (BigInt(fTokenBalance.toString()) * exchangeRate) / EXCHANGE_PRICES_PRECISION;
96
+ return new bn_js_1.default(value.toString());
97
+ }
98
+ /**
99
+ * Compute earn APR breakdown: base lending + rewards.
100
+ *
101
+ * Total APR is derived by projecting the exchange rate 1 year forward
102
+ * (captures both lending yield and rewards). Rewards APR is isolated
103
+ * from yearly_reward / total_assets. Base = total - rewards.
104
+ */
105
+ /**
106
+ * Compute earn APR breakdown: base lending + rewards.
107
+ *
108
+ * Reads the liquidity pool's supply rate from the liquidity account,
109
+ * and the rewards rate from the rewards model. Requires the liquidity
110
+ * account data as an additional parameter.
111
+ *
112
+ * @param rewardsModelData - Rewards rate model account data
113
+ * @param fTokenTotalSupply - fToken total supply (from mint)
114
+ * @param tokenExchangePrice - From lending account offset 115
115
+ * @param liquiditySupplyRate - Supply rate from liquidity pool (pass 0 if unknown)
116
+ */
117
+ function computeEarnApr(rewardsModelData, fTokenTotalSupply, tokenExchangePrice, liquiditySupplyRate) {
118
+ const zero = { lendingApr: 0, rewardsApr: 0, totalApr: 0 };
119
+ if (rewardsModelData.length < 72)
120
+ return zero;
121
+ if (fTokenTotalSupply.isZero() || tokenExchangePrice === 0n)
122
+ return zero;
123
+ // Rewards APR: yearly_reward / total_assets * 100
124
+ const yearlyReward = Number((0, buffer_1.readU64)(rewardsModelData, 64).toString());
125
+ const totalAssets = Number(BigInt(fTokenTotalSupply.toString()) * tokenExchangePrice / EXCHANGE_PRICES_PRECISION);
126
+ const rewardsApr = totalAssets > 0 ? (yearlyReward / totalAssets) * 100 : 0;
127
+ // Lending APR: from liquidity pool supply rate if provided
128
+ // The lend-read SDK returns supplyRate as an integer where /100 = %
129
+ const lendingApr = liquiditySupplyRate != null ? liquiditySupplyRate / 100 : 0;
130
+ return {
131
+ lendingApr,
132
+ rewardsApr,
133
+ totalApr: lendingApr + rewardsApr,
134
+ };
135
+ }
136
+ /**
137
+ * Fetch the earn position for a jlpd_config PDA.
138
+ * Returns null if no fToken ATA exists.
139
+ */
140
+ async function fetchEarnPosition(connection, fTokenAta) {
141
+ const [ataInfo, lendingInfo, rewardsInfo, mintInfo] = await connection.getMultipleAccountsInfo([
142
+ fTokenAta,
143
+ exports.JUPUSD_LENDING,
144
+ exports.JUPUSD_REWARDS_RATE_MODEL,
145
+ exports.JUPUSD_FTOKEN_MINT,
146
+ ]);
147
+ if (!ataInfo || !lendingInfo || !rewardsInfo || !mintInfo)
148
+ return null;
149
+ // SPL Token Account layout: [mint(0..32)][owner(32..64)][amount(64..72)]…
150
+ const ataData = ataInfo.data;
151
+ if (ataData.length < 72)
152
+ return null;
153
+ const fTokenBalance = (0, buffer_1.readU64)(ataData, 64);
154
+ // SPL Token Mint layout: [mintAuthority(0..36)][supply(36..44)][decimals(44..45)]…
155
+ const mintData = mintInfo.data;
156
+ const fTokenSupply = (0, buffer_1.readU64)(mintData, 36);
157
+ // baseExchangePrice from Jupiter Lend Earn lending account (offset 115)
158
+ const lendingData = lendingInfo.data;
159
+ const rewardsData = rewardsInfo.data;
160
+ const tokenExchangePrice = BigInt((0, buffer_1.readU64)(lendingData, 115).toString());
161
+ const now = Math.floor(Date.now() / 1000);
162
+ const exchangeRate = computeExchangeRate(lendingData, rewardsData, fTokenSupply, now);
163
+ const jupusdValue = computeFTokenValue(fTokenBalance, exchangeRate);
164
+ const apr = computeEarnApr(rewardsData, fTokenSupply, tokenExchangePrice);
165
+ return { fTokenBalance, jupusdValue, apr };
166
+ }
@@ -1,8 +1,13 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  export declare function findJlpdConfigPda(programId?: PublicKey): [PublicKey, number];
3
- /** @deprecated Use findJlpdConfigPda instead */
4
- export declare const findJlpVaultPda: typeof findJlpdConfigPda;
5
- export declare function findManagerRolePda(config: PublicKey, manager: PublicKey, programId?: PublicKey): [PublicKey, number];
3
+ /**
4
+ * Derive the per-JlpdConfig `ManagerRole` PDA for JLPD Strategy.
5
+ * Seeds: `["manager", config, manager]`.
6
+ *
7
+ * Note the per-program prefix on the name: each Elemental program has its
8
+ * own `ManagerRole` PDA scoped to a different anchor account (`p-stv-core`
9
+ * → STV, `elemental-lend` → strategy_state).
10
+ */
11
+ export declare function findJlpdManagerRolePda(config: PublicKey, manager: PublicKey, programId?: PublicKey): [PublicKey, number];
6
12
  export declare function findStrategyStatePda(baseMint: PublicKey, programId?: PublicKey): [PublicKey, number];
7
13
  export declare function findStvPositionPda(stv: PublicKey, programId?: PublicKey): [PublicKey, number];
8
- //# sourceMappingURL=pda.d.ts.map
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findJlpVaultPda = void 0;
4
3
  exports.findJlpdConfigPda = findJlpdConfigPda;
5
- exports.findManagerRolePda = findManagerRolePda;
4
+ exports.findJlpdManagerRolePda = findJlpdManagerRolePda;
6
5
  exports.findStrategyStatePda = findStrategyStatePda;
7
6
  exports.findStvPositionPda = findStvPositionPda;
8
7
  const web3_js_1 = require("@solana/web3.js");
@@ -10,9 +9,15 @@ const constants_1 = require("./constants");
10
9
  function findJlpdConfigPda(programId = constants_1.PROGRAM_ID) {
11
10
  return web3_js_1.PublicKey.findProgramAddressSync([constants_1.CONFIG_SEED], programId);
12
11
  }
13
- /** @deprecated Use findJlpdConfigPda instead */
14
- exports.findJlpVaultPda = findJlpdConfigPda;
15
- function findManagerRolePda(config, manager, programId = constants_1.PROGRAM_ID) {
12
+ /**
13
+ * Derive the per-JlpdConfig `ManagerRole` PDA for JLPD Strategy.
14
+ * Seeds: `["manager", config, manager]`.
15
+ *
16
+ * Note the per-program prefix on the name: each Elemental program has its
17
+ * own `ManagerRole` PDA scoped to a different anchor account (`p-stv-core`
18
+ * → STV, `elemental-lend` → strategy_state).
19
+ */
20
+ function findJlpdManagerRolePda(config, manager, programId = constants_1.PROGRAM_ID) {
16
21
  return web3_js_1.PublicKey.findProgramAddressSync([constants_1.MANAGER_SEED, config.toBuffer(), manager.toBuffer()], programId);
17
22
  }
18
23
  function findStrategyStatePda(baseMint, programId = constants_1.PROGRAM_ID) {
@@ -21,4 +26,3 @@ function findStrategyStatePda(baseMint, programId = constants_1.PROGRAM_ID) {
21
26
  function findStvPositionPda(stv, programId = constants_1.PROGRAM_ID) {
22
27
  return web3_js_1.PublicKey.findProgramAddressSync([constants_1.POSITION_SEED, stv.toBuffer()], programId);
23
28
  }
24
- //# sourceMappingURL=pda.js.map