@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,105 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import BN from "bn.js";
3
+ import type { StrategyStateHeader } from "../common/strategy-interface";
4
+ /** LendStrategyState v2 (280 bytes). */
5
+ export interface LendStrategyState extends StrategyStateHeader {
6
+ admin: PublicKey;
7
+ protocolCount: number;
8
+ }
9
+ /**
10
+ * ProtocolVault (224 bytes). Per-protocol adapter registration.
11
+ * Core pins only `protocolState`; everything else is validated adapter-side.
12
+ */
13
+ export interface ProtocolVault {
14
+ strategyState: PublicKey;
15
+ adapterProgram: PublicKey;
16
+ protocolState: PublicKey;
17
+ index: number;
18
+ bump: number;
19
+ readAumAccountCount: number;
20
+ }
21
+ export interface ManagerRole {
22
+ strategyState: PublicKey;
23
+ manager: PublicKey;
24
+ bump: number;
25
+ }
26
+ export type { StvPosition } from "../common/strategy-interface";
27
+ export interface StrategyInitializedEvent {
28
+ name: "StrategyInitialized";
29
+ baseMint: PublicKey;
30
+ authority: PublicKey;
31
+ admin: PublicKey;
32
+ }
33
+ export interface StrategyUpdatedEvent {
34
+ name: "StrategyUpdated";
35
+ baseMint: PublicKey;
36
+ newAdmin: PublicKey | null;
37
+ newFlags: number | null;
38
+ }
39
+ export interface AdapterRegisteredEvent {
40
+ name: "AdapterRegistered";
41
+ baseMint: PublicKey;
42
+ index: number;
43
+ adapterProgram: PublicKey;
44
+ protocolState: PublicKey;
45
+ }
46
+ export interface AdapterDeregisteredEvent {
47
+ name: "AdapterDeregistered";
48
+ baseMint: PublicKey;
49
+ index: number;
50
+ adapterProgram: PublicKey;
51
+ }
52
+ export interface RouteDepositedEvent {
53
+ name: "RouteDeposited";
54
+ baseMint: PublicKey;
55
+ protocolIndex: number;
56
+ amount: BN;
57
+ actualDeposited: BN;
58
+ }
59
+ export interface RouteWithdrawnEvent {
60
+ name: "RouteWithdrawn";
61
+ baseMint: PublicKey;
62
+ protocolIndex: number;
63
+ amount: BN;
64
+ actualWithdrawn: BN;
65
+ }
66
+ export interface AumUpdatedEvent {
67
+ name: "AumUpdated";
68
+ baseMint: PublicKey;
69
+ totalAum: BN;
70
+ pps: BN;
71
+ baseBalance: BN;
72
+ /** Sum of protocol AUM values computed this CPI (not a cached value). */
73
+ protocolAumSum: BN;
74
+ }
75
+ export interface DepositedEvent {
76
+ name: "Deposited";
77
+ stv: PublicKey;
78
+ amount: BN;
79
+ sharesMinted: BN;
80
+ }
81
+ export interface WithdrawnEvent {
82
+ name: "Withdrawn";
83
+ stv: PublicKey;
84
+ shares: BN;
85
+ baseAmount: BN;
86
+ }
87
+ export interface PositionInitializedEvent {
88
+ name: "PositionInitialized";
89
+ stv: PublicKey;
90
+ }
91
+ export interface PositionClosedEvent {
92
+ name: "PositionClosed";
93
+ stv: PublicKey;
94
+ }
95
+ export interface ManagerAddedEvent {
96
+ name: "ManagerAdded";
97
+ strategyState: PublicKey;
98
+ manager: PublicKey;
99
+ }
100
+ export interface ManagerRemovedEvent {
101
+ name: "ManagerRemoved";
102
+ strategyState: PublicKey;
103
+ manager: PublicKey;
104
+ }
105
+ export type LendV2Event = StrategyInitializedEvent | StrategyUpdatedEvent | AdapterRegisteredEvent | AdapterDeregisteredEvent | RouteDepositedEvent | RouteWithdrawnEvent | AumUpdatedEvent | DepositedEvent | WithdrawnEvent | PositionInitializedEvent | PositionClosedEvent | ManagerAddedEvent | ManagerRemovedEvent;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,29 @@
1
+ import { PublicKey, TransactionInstruction, AccountMeta } from "@solana/web3.js";
2
+ import type { SolanaConnection } from "../common/connection";
3
+ import type { LendStrategyState, ProtocolVault } from "./types";
4
+ /**
5
+ * Per-protocol map of adapter-specific accounts appended after
6
+ * `[protocol_vault, adapter_program]` in update_aum's remaining_accounts.
7
+ *
8
+ * Keyed by protocol index. First account MUST equal the registered
9
+ * protocol_state (enforced by core). Subsequent accounts adapter-validated.
10
+ * Length must equal `ProtocolVault.readAumAccountCount`.
11
+ */
12
+ export type PerProtocolReadAumAccounts = Record<number, PublicKey[]>;
13
+ /**
14
+ * Build the update_aum remaining_accounts tail.
15
+ *
16
+ * Layout per protocol i in 0..protocol_count:
17
+ * [protocol_vault_i, adapter_program_i, ...perProtocolReadAumAccounts[i]]
18
+ */
19
+ export declare function buildUpdateAumRemainingAccounts(connection: SolanaConnection, strategy: LendStrategyState, strategyStatePda: PublicKey, perProtocolReadAumAccounts: PerProtocolReadAumAccounts, programId?: PublicKey): Promise<AccountMeta[]>;
20
+ /** Sync variant when the caller already has ProtocolVault data cached. */
21
+ export declare function buildUpdateAumRemainingAccountsSync(strategy: LendStrategyState, strategyStatePda: PublicKey, protocolVaults: ProtocolVault[], perProtocolReadAumAccounts: PerProtocolReadAumAccounts, programId?: PublicKey): AccountMeta[];
22
+ export interface UpdateAumArgs {
23
+ strategyState: PublicKey;
24
+ stv: PublicKey;
25
+ strategyBaseAta: PublicKey;
26
+ baseMint: PublicKey;
27
+ remainingAccounts: AccountMeta[];
28
+ }
29
+ export declare function createUpdateAumIx(args: UpdateAumArgs, programId?: PublicKey): TransactionInstruction;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildUpdateAumRemainingAccounts = buildUpdateAumRemainingAccounts;
4
+ exports.buildUpdateAumRemainingAccountsSync = buildUpdateAumRemainingAccountsSync;
5
+ exports.createUpdateAumIx = createUpdateAumIx;
6
+ const web3_js_1 = require("@solana/web3.js");
7
+ const constants_1 = require("./constants");
8
+ const accounts_1 = require("./accounts");
9
+ const pda_1 = require("./pda");
10
+ /**
11
+ * Build the update_aum remaining_accounts tail.
12
+ *
13
+ * Layout per protocol i in 0..protocol_count:
14
+ * [protocol_vault_i, adapter_program_i, ...perProtocolReadAumAccounts[i]]
15
+ */
16
+ async function buildUpdateAumRemainingAccounts(connection, strategy, strategyStatePda, perProtocolReadAumAccounts, programId = constants_1.PROGRAM_ID) {
17
+ const out = [];
18
+ if (strategy.protocolCount === 0)
19
+ return out;
20
+ const pvs = await (0, accounts_1.fetchAllProtocolVaults)(connection, strategyStatePda, strategy.protocolCount, programId);
21
+ for (let i = 0; i < pvs.length; i++) {
22
+ const [pvPda, pv] = pvs[i];
23
+ const reads = perProtocolReadAumAccounts[i];
24
+ if (!reads) {
25
+ throw new Error(`buildUpdateAumRemainingAccounts: missing read_aum accounts for protocol ${i}`);
26
+ }
27
+ if (reads.length !== pv.readAumAccountCount) {
28
+ throw new Error(`buildUpdateAumRemainingAccounts: protocol ${i} expects ` +
29
+ `${pv.readAumAccountCount} read_aum accounts, got ${reads.length}`);
30
+ }
31
+ if (!reads[0].equals(pv.protocolState)) {
32
+ throw new Error(`buildUpdateAumRemainingAccounts: protocol ${i} first read_aum account must equal ` +
33
+ `protocol_state ${pv.protocolState.toBase58()}, got ${reads[0].toBase58()}`);
34
+ }
35
+ out.push({ pubkey: pvPda, isSigner: false, isWritable: false });
36
+ out.push({ pubkey: pv.adapterProgram, isSigner: false, isWritable: false });
37
+ for (const k of reads) {
38
+ out.push({ pubkey: k, isSigner: false, isWritable: false });
39
+ }
40
+ }
41
+ return out;
42
+ }
43
+ /** Sync variant when the caller already has ProtocolVault data cached. */
44
+ function buildUpdateAumRemainingAccountsSync(strategy, strategyStatePda, protocolVaults, perProtocolReadAumAccounts, programId = constants_1.PROGRAM_ID) {
45
+ if (protocolVaults.length !== strategy.protocolCount) {
46
+ throw new Error(`protocolVaults length ${protocolVaults.length} does not match strategy.protocolCount ${strategy.protocolCount}`);
47
+ }
48
+ const out = [];
49
+ for (let i = 0; i < protocolVaults.length; i++) {
50
+ const pv = protocolVaults[i];
51
+ const [pvPda] = (0, pda_1.deriveProtocolVault)(strategyStatePda, i, programId);
52
+ const reads = perProtocolReadAumAccounts[i];
53
+ if (!reads) {
54
+ throw new Error(`missing read_aum accounts for protocol ${i}`);
55
+ }
56
+ if (reads.length !== pv.readAumAccountCount) {
57
+ throw new Error(`protocol ${i} expects ${pv.readAumAccountCount} read_aum accounts, got ${reads.length}`);
58
+ }
59
+ if (!reads[0].equals(pv.protocolState)) {
60
+ throw new Error(`protocol ${i} first read_aum account must equal protocol_state`);
61
+ }
62
+ out.push({ pubkey: pvPda, isSigner: false, isWritable: false });
63
+ out.push({ pubkey: pv.adapterProgram, isSigner: false, isWritable: false });
64
+ for (const k of reads) {
65
+ out.push({ pubkey: k, isSigner: false, isWritable: false });
66
+ }
67
+ }
68
+ return out;
69
+ }
70
+ function createUpdateAumIx(args, programId = constants_1.PROGRAM_ID) {
71
+ return new web3_js_1.TransactionInstruction({
72
+ keys: [
73
+ { pubkey: args.strategyState, isSigner: false, isWritable: true },
74
+ { pubkey: args.stv, isSigner: true, isWritable: false },
75
+ { pubkey: args.strategyBaseAta, isSigner: false, isWritable: false },
76
+ { pubkey: args.baseMint, isSigner: false, isWritable: false },
77
+ ...args.remainingAccounts,
78
+ ],
79
+ programId,
80
+ data: constants_1.IX_UPDATE_AUM,
81
+ });
82
+ }