@elmntl/jlpd-sdk 0.2.0 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 -4199
  52. package/dist/index.js +37 -5187
  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 -4199
  115. package/dist/index.mjs +0 -5090
@@ -0,0 +1,26 @@
1
+ import { PublicKey, TransactionInstruction } from "@solana/web3.js";
2
+ /**
3
+ * Derive an Associated Token Account (ATA) address.
4
+ *
5
+ * Equivalent to `@solana/spl-token`'s `getAssociatedTokenAddressSync` but
6
+ * inlined to avoid pulling the runtime helpers into hot paths and to give a
7
+ * single source of truth across all SDK sub-packages (p-stv-core,
8
+ * elemental-lend, jlpd-strategy).
9
+ *
10
+ * @param mint - Token mint
11
+ * @param owner - Owner of the ATA (typically a PDA or wallet)
12
+ * @param tokenProgram - Token program ID (SPL Token or Token-2022)
13
+ */
14
+ export declare function findAta(mint: PublicKey, owner: PublicKey, tokenProgram: PublicKey): PublicKey;
15
+ /**
16
+ * Build an Associated Token Account `CreateIdempotent` instruction.
17
+ *
18
+ * Idempotent — safe to include on every tx; the ATA program no-ops if the
19
+ * account already exists. Works for both SPL Token and Token-2022.
20
+ *
21
+ * @param payer - Wallet paying rent + signing the tx
22
+ * @param mint - Token mint the ATA will hold
23
+ * @param owner - ATA owner (wallet or PDA)
24
+ * @param tokenProgram - SPL Token or Token-2022 program id
25
+ */
26
+ export declare function createIdempotentAtaIx(payer: PublicKey, mint: PublicKey, owner: PublicKey, tokenProgram: PublicKey): TransactionInstruction;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findAta = findAta;
4
+ exports.createIdempotentAtaIx = createIdempotentAtaIx;
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const spl_token_1 = require("@solana/spl-token");
7
+ /**
8
+ * Derive an Associated Token Account (ATA) address.
9
+ *
10
+ * Equivalent to `@solana/spl-token`'s `getAssociatedTokenAddressSync` but
11
+ * inlined to avoid pulling the runtime helpers into hot paths and to give a
12
+ * single source of truth across all SDK sub-packages (p-stv-core,
13
+ * elemental-lend, jlpd-strategy).
14
+ *
15
+ * @param mint - Token mint
16
+ * @param owner - Owner of the ATA (typically a PDA or wallet)
17
+ * @param tokenProgram - Token program ID (SPL Token or Token-2022)
18
+ */
19
+ function findAta(mint, owner, tokenProgram) {
20
+ const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
21
+ return ata;
22
+ }
23
+ /**
24
+ * Build an Associated Token Account `CreateIdempotent` instruction.
25
+ *
26
+ * Idempotent — safe to include on every tx; the ATA program no-ops if the
27
+ * account already exists. Works for both SPL Token and Token-2022.
28
+ *
29
+ * @param payer - Wallet paying rent + signing the tx
30
+ * @param mint - Token mint the ATA will hold
31
+ * @param owner - ATA owner (wallet or PDA)
32
+ * @param tokenProgram - SPL Token or Token-2022 program id
33
+ */
34
+ function createIdempotentAtaIx(payer, mint, owner, tokenProgram) {
35
+ const ata = findAta(mint, owner, tokenProgram);
36
+ return new web3_js_1.TransactionInstruction({
37
+ keys: [
38
+ { pubkey: payer, isSigner: true, isWritable: true },
39
+ { pubkey: ata, isSigner: false, isWritable: true },
40
+ { pubkey: owner, isSigner: false, isWritable: false },
41
+ { pubkey: mint, isSigner: false, isWritable: false },
42
+ { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
43
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
44
+ ],
45
+ programId: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
46
+ data: Buffer.from([1]), // CreateIdempotent
47
+ });
48
+ }
@@ -0,0 +1,15 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import BN from "bn.js";
3
+ export declare function readPubkey(data: Buffer, offset: number): PublicKey;
4
+ export declare function readU64(data: Buffer, offset: number): BN;
5
+ /** Read a signed little-endian i64 as a BN (two's-complement aware). */
6
+ export declare function readI64(data: Buffer, offset: number): BN;
7
+ export declare function readU32(data: Buffer, offset: number): number;
8
+ export declare function readU16(data: Buffer, offset: number): number;
9
+ export declare function readU8(data: Buffer, offset: number): number;
10
+ export declare function writeU64(parts: number[], value: BN | number): void;
11
+ export declare function writeOptionalPubkey(parts: number[], value: PublicKey | undefined | null): void;
12
+ export declare function writeOptionalU64(parts: number[], value: BN | number | undefined | null): void;
13
+ export declare function writeOptionalU32(parts: number[], value: number | undefined | null): void;
14
+ export declare function writeOptionalU16(parts: number[], value: number | undefined | null): void;
15
+ export declare function writeOptionalU8(parts: number[], value: number | undefined | null): void;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readPubkey = readPubkey;
7
+ exports.readU64 = readU64;
8
+ exports.readI64 = readI64;
9
+ exports.readU32 = readU32;
10
+ exports.readU16 = readU16;
11
+ exports.readU8 = readU8;
12
+ exports.writeU64 = writeU64;
13
+ exports.writeOptionalPubkey = writeOptionalPubkey;
14
+ exports.writeOptionalU64 = writeOptionalU64;
15
+ exports.writeOptionalU32 = writeOptionalU32;
16
+ exports.writeOptionalU16 = writeOptionalU16;
17
+ exports.writeOptionalU8 = writeOptionalU8;
18
+ const web3_js_1 = require("@solana/web3.js");
19
+ const bn_js_1 = __importDefault(require("bn.js"));
20
+ // ---------------------------------------------------------------------------
21
+ // Read Helpers (account deserialization)
22
+ //
23
+ // Each helper validates that `offset + width <= data.length` and throws a
24
+ // descriptive error if the slice would run past the buffer end. Catching
25
+ // these at the call site (a malformed account, a layout drift, an incorrect
26
+ // offset constant) is much cheaper than chasing the resulting garbage data
27
+ // through downstream parsing.
28
+ // ---------------------------------------------------------------------------
29
+ function checkBounds(data, offset, width, label) {
30
+ if (offset < 0 || offset + width > data.length) {
31
+ throw new RangeError(`${label}: cannot read ${width} bytes at offset ${offset} (buffer length=${data.length})`);
32
+ }
33
+ }
34
+ function readPubkey(data, offset) {
35
+ checkBounds(data, offset, 32, "readPubkey");
36
+ return new web3_js_1.PublicKey(data.subarray(offset, offset + 32));
37
+ }
38
+ function readU64(data, offset) {
39
+ checkBounds(data, offset, 8, "readU64");
40
+ return new bn_js_1.default(data.subarray(offset, offset + 8), "le");
41
+ }
42
+ /** Read a signed little-endian i64 as a BN (two's-complement aware). */
43
+ function readI64(data, offset) {
44
+ checkBounds(data, offset, 8, "readI64");
45
+ return new bn_js_1.default(data.readBigInt64LE(offset).toString());
46
+ }
47
+ function readU32(data, offset) {
48
+ checkBounds(data, offset, 4, "readU32");
49
+ return data.readUInt32LE(offset);
50
+ }
51
+ function readU16(data, offset) {
52
+ checkBounds(data, offset, 2, "readU16");
53
+ return data.readUInt16LE(offset);
54
+ }
55
+ function readU8(data, offset) {
56
+ checkBounds(data, offset, 1, "readU8");
57
+ return data[offset];
58
+ }
59
+ // ---------------------------------------------------------------------------
60
+ // Write Helpers (instruction serialization)
61
+ // ---------------------------------------------------------------------------
62
+ function writeU64(parts, value) {
63
+ const bn = new bn_js_1.default(value);
64
+ parts.push(...bn.toArrayLike(Buffer, "le", 8));
65
+ }
66
+ function writeOptionalPubkey(parts, value) {
67
+ if (value != null) {
68
+ parts.push(0x01);
69
+ parts.push(...value.toBuffer());
70
+ }
71
+ else {
72
+ parts.push(0x00);
73
+ }
74
+ }
75
+ function writeOptionalU64(parts, value) {
76
+ if (value != null) {
77
+ parts.push(0x01);
78
+ const bn = new bn_js_1.default(value);
79
+ parts.push(...bn.toArrayLike(Buffer, "le", 8));
80
+ }
81
+ else {
82
+ parts.push(0x00);
83
+ }
84
+ }
85
+ function writeOptionalU32(parts, value) {
86
+ if (value != null) {
87
+ parts.push(0x01);
88
+ const buf = Buffer.alloc(4);
89
+ buf.writeUInt32LE(value, 0);
90
+ parts.push(...buf);
91
+ }
92
+ else {
93
+ parts.push(0x00);
94
+ }
95
+ }
96
+ function writeOptionalU16(parts, value) {
97
+ if (value != null) {
98
+ parts.push(0x01);
99
+ const buf = Buffer.alloc(2);
100
+ buf.writeUInt16LE(value, 0);
101
+ parts.push(...buf);
102
+ }
103
+ else {
104
+ parts.push(0x00);
105
+ }
106
+ }
107
+ function writeOptionalU8(parts, value) {
108
+ if (value != null) {
109
+ if (!Number.isInteger(value) || value < 0 || value > 0xff) {
110
+ throw new Error(`writeOptionalU8: value out of range (0..255): ${value}`);
111
+ }
112
+ parts.push(0x01);
113
+ parts.push(value);
114
+ }
115
+ else {
116
+ parts.push(0x00);
117
+ }
118
+ }
@@ -0,0 +1,13 @@
1
+ import { Connection } from "@solana/web3.js";
2
+ /**
3
+ * Canonical structural connection type used by every Elemental SDK module
4
+ * that needs to read on-chain state.
5
+ *
6
+ * Using a `Pick<Connection, ...>` here lets callers pass any version of
7
+ * `@solana/web3.js` without nominal type mismatches across module versions.
8
+ *
9
+ * If a builder needs only a subset of these methods, prefer aliasing further
10
+ * (`type ProtocolActionConnection = Pick<SolanaConnection, "getAccountInfo" | "getMultipleAccountsInfo">`)
11
+ * rather than defining a competing top-level type.
12
+ */
13
+ export type SolanaConnection = Pick<Connection, "getAccountInfo" | "getMultipleAccountsInfo" | "getProgramAccounts" | "getTokenAccountsByOwner" | "getSlot" | "getBlockTime">;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ /** Price per share scale factor (10^9) */
2
+ export declare const PPS_DECIMALS = 1000000000;
3
+ /** Basis points denominator */
4
+ export declare const BPS_DENOMINATOR = 10000;
5
+ /** Seconds in a year (365 days) */
6
+ export declare const SECONDS_PER_YEAR = 31536000;
7
+ /** Default staleness threshold in seconds */
8
+ export declare const STALENESS_THRESHOLD = 120;
9
+ /** sha256("account:StrategyState")[..8] — used by elemental-lend, jlpd-strategy */
10
+ export declare const DISC_STRATEGY_STATE: Buffer<ArrayBuffer>;
11
+ /** sha256("account:StvPosition")[..8] — used by elemental-lend, jlpd-strategy */
12
+ export declare const DISC_STV_POSITION: Buffer<ArrayBuffer>;
13
+ /** sha256("account:ManagerRole")[..8] — used by p-stv-core, elemental-lend, jlpd-strategy */
14
+ export declare const DISC_MANAGER_ROLE: Buffer<ArrayBuffer>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.STALENESS_THRESHOLD = exports.SECONDS_PER_YEAR = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = void 0;
4
+ /** Price per share scale factor (10^9) */
5
+ exports.PPS_DECIMALS = 1000000000;
6
+ /** Basis points denominator */
7
+ exports.BPS_DENOMINATOR = 10000;
8
+ /** Seconds in a year (365 days) */
9
+ exports.SECONDS_PER_YEAR = 31536000;
10
+ /** Default staleness threshold in seconds */
11
+ exports.STALENESS_THRESHOLD = 120;
12
+ // ---------------------------------------------------------------------------
13
+ // Shared Anchor account discriminators
14
+ //
15
+ // All three Elemental programs use Anchor's `sha256("account:<Type>")[..8]`
16
+ // discriminator format. The following types share the same on-chain layout
17
+ // across programs and therefore the same discriminator bytes — defining them
18
+ // once in `common` keeps them in lock-step.
19
+ // ---------------------------------------------------------------------------
20
+ /** sha256("account:StrategyState")[..8] — used by elemental-lend, jlpd-strategy */
21
+ exports.DISC_STRATEGY_STATE = Buffer.from([
22
+ 0x53, 0x12, 0xe0, 0x6d, 0xae, 0x64, 0x27, 0x8b,
23
+ ]);
24
+ /** sha256("account:StvPosition")[..8] — used by elemental-lend, jlpd-strategy */
25
+ exports.DISC_STV_POSITION = Buffer.from([
26
+ 0x2f, 0xd4, 0xfb, 0xb0, 0x8a, 0xa0, 0x1e, 0x57,
27
+ ]);
28
+ /** sha256("account:ManagerRole")[..8] — used by p-stv-core, elemental-lend, jlpd-strategy */
29
+ exports.DISC_MANAGER_ROLE = Buffer.from([
30
+ 0x25, 0xe8, 0x64, 0xe9, 0xaa, 0xe9, 0xdb, 0xb9,
31
+ ]);
@@ -0,0 +1,6 @@
1
+ export { readPubkey, readU64, readU32, readU16, readU8, writeU64, writeOptionalPubkey, writeOptionalU64, writeOptionalU32, writeOptionalU16, } from "./buffer";
2
+ export { PPS_DECIMALS, BPS_DENOMINATOR, SECONDS_PER_YEAR, STALENESS_THRESHOLD, DISC_STRATEGY_STATE, DISC_STV_POSITION, DISC_MANAGER_ROLE, } from "./constants";
3
+ export type { SolanaConnection } from "./connection";
4
+ export type { StrategyStateHeader, StvPosition, } from "./strategy-interface";
5
+ export { deserializeStrategyStateHeader, deserializeStvPosition, } from "./strategy-interface";
6
+ export { findAta, createIdempotentAtaIx } from "./ata";
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIdempotentAtaIx = exports.findAta = exports.deserializeStvPosition = exports.deserializeStrategyStateHeader = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.STALENESS_THRESHOLD = exports.SECONDS_PER_YEAR = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.writeOptionalU16 = exports.writeOptionalU32 = exports.writeOptionalU64 = exports.writeOptionalPubkey = exports.writeU64 = exports.readU8 = exports.readU16 = exports.readU32 = exports.readU64 = exports.readPubkey = void 0;
4
+ var buffer_1 = require("./buffer");
5
+ Object.defineProperty(exports, "readPubkey", { enumerable: true, get: function () { return buffer_1.readPubkey; } });
6
+ Object.defineProperty(exports, "readU64", { enumerable: true, get: function () { return buffer_1.readU64; } });
7
+ Object.defineProperty(exports, "readU32", { enumerable: true, get: function () { return buffer_1.readU32; } });
8
+ Object.defineProperty(exports, "readU16", { enumerable: true, get: function () { return buffer_1.readU16; } });
9
+ Object.defineProperty(exports, "readU8", { enumerable: true, get: function () { return buffer_1.readU8; } });
10
+ Object.defineProperty(exports, "writeU64", { enumerable: true, get: function () { return buffer_1.writeU64; } });
11
+ Object.defineProperty(exports, "writeOptionalPubkey", { enumerable: true, get: function () { return buffer_1.writeOptionalPubkey; } });
12
+ Object.defineProperty(exports, "writeOptionalU64", { enumerable: true, get: function () { return buffer_1.writeOptionalU64; } });
13
+ Object.defineProperty(exports, "writeOptionalU32", { enumerable: true, get: function () { return buffer_1.writeOptionalU32; } });
14
+ Object.defineProperty(exports, "writeOptionalU16", { enumerable: true, get: function () { return buffer_1.writeOptionalU16; } });
15
+ var constants_1 = require("./constants");
16
+ Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_1.PPS_DECIMALS; } });
17
+ Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_1.BPS_DENOMINATOR; } });
18
+ Object.defineProperty(exports, "SECONDS_PER_YEAR", { enumerable: true, get: function () { return constants_1.SECONDS_PER_YEAR; } });
19
+ Object.defineProperty(exports, "STALENESS_THRESHOLD", { enumerable: true, get: function () { return constants_1.STALENESS_THRESHOLD; } });
20
+ Object.defineProperty(exports, "DISC_STRATEGY_STATE", { enumerable: true, get: function () { return constants_1.DISC_STRATEGY_STATE; } });
21
+ Object.defineProperty(exports, "DISC_STV_POSITION", { enumerable: true, get: function () { return constants_1.DISC_STV_POSITION; } });
22
+ Object.defineProperty(exports, "DISC_MANAGER_ROLE", { enumerable: true, get: function () { return constants_1.DISC_MANAGER_ROLE; } });
23
+ var strategy_interface_1 = require("./strategy-interface");
24
+ Object.defineProperty(exports, "deserializeStrategyStateHeader", { enumerable: true, get: function () { return strategy_interface_1.deserializeStrategyStateHeader; } });
25
+ Object.defineProperty(exports, "deserializeStvPosition", { enumerable: true, get: function () { return strategy_interface_1.deserializeStvPosition; } });
26
+ var ata_1 = require("./ata");
27
+ Object.defineProperty(exports, "findAta", { enumerable: true, get: function () { return ata_1.findAta; } });
28
+ Object.defineProperty(exports, "createIdempotentAtaIx", { enumerable: true, get: function () { return ata_1.createIdempotentAtaIx; } });
@@ -0,0 +1,59 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import BN from "bn.js";
3
+ /**
4
+ * StrategyStateHeader — 104-byte prefix shared by every strategy program.
5
+ *
6
+ * Layout (offsets include the 8-byte discriminator):
7
+ * [ 0.. 8] discriminator (set by the wrapping account)
8
+ * [ 8.. 40] baseMint Pubkey
9
+ * [ 40.. 72] authority Pubkey (p-stv-core program)
10
+ * [ 72.. 80] pps u64 (scaled by PPS_DECIMALS = 10^9)
11
+ * [ 80.. 88] totalAum u64
12
+ * [ 88.. 96] totalShares u64
13
+ * [ 96..104] lastUpdated u64 (unix seconds)
14
+ * [104..106] flags u16
15
+ * [106..107] version u8
16
+ * [107..108] bump u8
17
+ * [108..112] _headerPadding [u8; 4]
18
+ */
19
+ export interface StrategyStateHeader {
20
+ baseMint: PublicKey;
21
+ authority: PublicKey;
22
+ pps: BN;
23
+ totalAum: BN;
24
+ totalShares: BN;
25
+ lastUpdated: BN;
26
+ flags: number;
27
+ version: number;
28
+ bump: number;
29
+ }
30
+ /**
31
+ * Deserialize the standard 104-byte StrategyState header from any strategy
32
+ * account. `data` must include the 8-byte discriminator prefix; the caller
33
+ * is responsible for validating that the discriminator matches the expected
34
+ * type before invoking this helper.
35
+ */
36
+ export declare function deserializeStrategyStateHeader(data: Buffer): StrategyStateHeader;
37
+ /**
38
+ * StvPosition — per-STV virtual share record. 48 bytes of meaningful data
39
+ * (full account is 120 bytes including the 8-byte discriminator and trailing
40
+ * reserved padding).
41
+ *
42
+ * Layout (offsets include the 8-byte discriminator):
43
+ * [ 0.. 8] discriminator (set by the wrapping account)
44
+ * [ 8.. 40] stv Pubkey
45
+ * [ 40.. 48] shares u64
46
+ * [ 48.. 49] bump u8
47
+ * [ 49..120] _reserved [u8; 71]
48
+ */
49
+ export interface StvPosition {
50
+ stv: PublicKey;
51
+ shares: BN;
52
+ bump: number;
53
+ }
54
+ /**
55
+ * Deserialize the standard StvPosition from any strategy account. `data`
56
+ * must include the 8-byte discriminator prefix; the caller validates the
57
+ * discriminator before invoking this helper.
58
+ */
59
+ export declare function deserializeStvPosition(data: Buffer): StvPosition;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deserializeStrategyStateHeader = deserializeStrategyStateHeader;
4
+ exports.deserializeStvPosition = deserializeStvPosition;
5
+ const buffer_1 = require("./buffer");
6
+ /**
7
+ * Deserialize the standard 104-byte StrategyState header from any strategy
8
+ * account. `data` must include the 8-byte discriminator prefix; the caller
9
+ * is responsible for validating that the discriminator matches the expected
10
+ * type before invoking this helper.
11
+ */
12
+ function deserializeStrategyStateHeader(data) {
13
+ if (data.length < 112) {
14
+ throw new Error(`StrategyState header data too short: ${data.length} < 112`);
15
+ }
16
+ return {
17
+ baseMint: (0, buffer_1.readPubkey)(data, 8),
18
+ authority: (0, buffer_1.readPubkey)(data, 40),
19
+ pps: (0, buffer_1.readU64)(data, 72),
20
+ totalAum: (0, buffer_1.readU64)(data, 80),
21
+ totalShares: (0, buffer_1.readU64)(data, 88),
22
+ lastUpdated: (0, buffer_1.readU64)(data, 96),
23
+ flags: (0, buffer_1.readU16)(data, 104),
24
+ version: (0, buffer_1.readU8)(data, 106),
25
+ bump: (0, buffer_1.readU8)(data, 107),
26
+ };
27
+ }
28
+ /**
29
+ * Deserialize the standard StvPosition from any strategy account. `data`
30
+ * must include the 8-byte discriminator prefix; the caller validates the
31
+ * discriminator before invoking this helper.
32
+ */
33
+ function deserializeStvPosition(data) {
34
+ if (data.length < 56) {
35
+ throw new Error(`StvPosition data too short: ${data.length} < 56`);
36
+ }
37
+ return {
38
+ stv: (0, buffer_1.readPubkey)(data, 8),
39
+ shares: (0, buffer_1.readU64)(data, 40),
40
+ bump: (0, buffer_1.readU8)(data, 48),
41
+ };
42
+ }
@@ -0,0 +1,103 @@
1
+ import { AccountMeta, PublicKey } from "@solana/web3.js";
2
+ import type { StvPosition } from "../common/strategy-interface";
3
+ import type { SolanaConnection } from "../common/connection";
4
+ import { LendStrategyState, ManagerRole } from "./types";
5
+ /**
6
+ * LendStrategyState — Elemental Lend's per-base-mint strategy account. Total 536 bytes.
7
+ *
8
+ * Layout (offsets include the 8-byte discriminator):
9
+ * [ 0.. 8] discriminator (sha256("account:StrategyState")[..8] —
10
+ * shared with jlpd-strategy)
11
+ * --- StrategyStateHeader (104 bytes, identical across all strategy programs) ---
12
+ * [ 8.. 40] baseMint Pubkey
13
+ * [ 40.. 72] authority Pubkey (p-stv-core program)
14
+ * [ 72.. 80] pps u64 (scaled by PPS_DECIMALS = 10^9)
15
+ * [ 80.. 88] totalAum u64
16
+ * [ 88.. 96] totalShares u64
17
+ * [ 96..104] lastUpdated u64 (unix seconds)
18
+ * [104..106] flags u16 (FLAG_PAUSED, …)
19
+ * [106..107] version u8
20
+ * [107..108] bump u8
21
+ * [108..112] _headerPadding [u8; 4]
22
+ * --- Custom Elemental Lend fields (424 bytes) ---
23
+ * [112..144] admin Pubkey
24
+ * [144..464] protocols[10] [Pubkey; 10] (registered protocol accounts)
25
+ * [464..465] protocolCount u8
26
+ * [465..466] managerCount u8
27
+ * [466..472] _padding [u8; 6]
28
+ * [472..536] _reserved [u8; 64]
29
+ */
30
+ export declare function deserializeLendStrategyState(data: Buffer): LendStrategyState;
31
+ /**
32
+ * StvPosition — per-STV virtual share record. Total 120 bytes.
33
+ *
34
+ * The on-disk layout is identical across elemental-lend and jlpd-strategy
35
+ * (`StvPosition` from `common/strategy-interface.ts`). The 8-byte
36
+ * discriminator validation here distinguishes the two so a `JlpdStvPosition`
37
+ * can't be parsed as a lend position by mistake. See
38
+ * `common/strategy-interface.ts` for the field-by-field layout.
39
+ */
40
+ export declare function deserializeLendStvPosition(data: Buffer): StvPosition;
41
+ /**
42
+ * ManagerRole — per-(strategy_state, manager) authorization. Total 80 bytes.
43
+ *
44
+ * Layout (offsets include the 8-byte discriminator):
45
+ * [ 0.. 8] discriminator (sha256("account:ManagerRole")[..8] —
46
+ * shared with p-stv-core + jlpd-strategy)
47
+ * [ 8.. 40] strategyState Pubkey
48
+ * [ 40.. 72] manager Pubkey
49
+ * [ 72.. 73] bump u8
50
+ * [ 73.. 80] _padding [u8; 7]
51
+ */
52
+ export declare function deserializeManagerRole(data: Buffer): ManagerRole;
53
+ export declare function fetchLendStrategyState(connection: SolanaConnection, baseMint: PublicKey, programId?: PublicKey): Promise<LendStrategyState>;
54
+ export declare function fetchLendStrategyStateByAddress(connection: SolanaConnection, address: PublicKey): Promise<LendStrategyState>;
55
+ export declare function fetchLendStvPosition(connection: SolanaConnection, stv: PublicKey, programId?: PublicKey): Promise<StvPosition>;
56
+ export declare function fetchManagerRole(connection: SolanaConnection, strategyState: PublicKey, manager: PublicKey, programId?: PublicKey): Promise<ManagerRole | null>;
57
+ export declare function fetchAllLendStrategyStates(connection: SolanaConnection, programId?: PublicKey): Promise<[PublicKey, LendStrategyState][]>;
58
+ export declare function fetchManagersForStrategy(connection: SolanaConnection, strategyState: PublicKey, programId?: PublicKey): Promise<[PublicKey, ManagerRole][]>;
59
+ /**
60
+ * Build remaining_accounts for the update_aum CPI on elemental-lend.
61
+ *
62
+ * COMPLETENESS REQUIREMENT: Every registered protocol MUST be present in the
63
+ * returned array. The on-chain update_aum.rs validates a completeness bitmap
64
+ * (seen == expected) and rejects with `IncompleteProtocolAccounts` if any
65
+ * registered protocol is missing (update_aum.rs:265). An uninitialized share
66
+ * ATA is NOT an error — the on-chain `read_protocol_share_ata` checks the
67
+ * canonical ATA key and returns 0 for uninitialised accounts (update_aum.rs:314).
68
+ *
69
+ * Canonical ATA addresses are DERIVED (not fetched from token account lists) so
70
+ * that uninitialized ATAs are included. The on-chain `is_canonical_ata`
71
+ * (update_aum.rs:30-37) pins the SINGLE SPL-Token ATA derivation — all Elemental
72
+ * Lend receipt mints (Kamino kvTokens, Jupiter fTokens) are SPL-Token mints. Share
73
+ * ATAs are ALWAYS derived under the SPL Token program id regardless of the caller's
74
+ * `tokenProgramId`; passing a Token-2022 id would yield a different ATA address that
75
+ * the on-chain handler rejects.
76
+ *
77
+ * - kVault (KvauG...): [kvtoken_ata, vault_state] (2 accounts)
78
+ * - Jupiter Lend (jup3Y...): [ftoken_ata, lending_account, rewards_rate_model] (3 accounts)
79
+ *
80
+ * @param connection - Solana connection (needed to fetch protocol account data)
81
+ * @param strategy - Deserialized LendStrategyState (with protocols list)
82
+ * @param strategyStatePda - The strategy state PDA (owns the share-token ATAs)
83
+ * @param tokenProgramId - Token program for the BASE mint ATA derivation. Share-mint ATAs
84
+ * (kvToken, fToken) are always derived under SPL Token regardless of this value.
85
+ * @param protocolCache - Optional pre-resolved cache of protocol specs keyed by protocol
86
+ * pubkey base-58. On a cache hit the `getMultipleAccountsInfo` fetch is skipped for
87
+ * that protocol. On a miss the protocol is fetched and the result is stored in the
88
+ * cache for future calls. Pass a shared `Map` across repeated calls (e.g. in a keeper
89
+ * loop) to avoid refetching mostly-static protocol metadata every iteration.
90
+ *
91
+ * **Cache contract (FIX 4 — staleness):** The cache is caller-owned and intentionally
92
+ * short-lived / slot-scoped. Callers are responsible for invalidation. For Jupiter Lend
93
+ * protocols the cached `data` includes the `fTokenMint` and `rewardsRateModel` fields;
94
+ * if a Jupiter Lend pool's `rewardsRateModel` account changes (rare, governance-gated)
95
+ * the cache entry becomes stale. Always construct a fresh `Map` (or clear the existing
96
+ * one) at the start of each slot/epoch boundary or after any on-chain governance change
97
+ * to the protocol accounts. Do NOT hold the same cache instance across multiple slots in
98
+ * latency-sensitive paths — create a new `Map()` per transaction-building pass instead.
99
+ */
100
+ export declare function buildProtocolAccountsForAum(connection: SolanaConnection, strategy: LendStrategyState, strategyStatePda: PublicKey, _tokenProgramId: PublicKey, protocolCache?: Map<string, {
101
+ owner: PublicKey;
102
+ data: Buffer;
103
+ }>): Promise<AccountMeta[]>;