@elmntl/jlpd-sdk 0.1.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.
- package/README.md +363 -0
- package/dist/index.d.mts +743 -0
- package/dist/index.d.ts +743 -0
- package/dist/index.js +1843 -0
- package/dist/index.mjs +1753 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# JLP.D SDK
|
|
2
|
+
|
|
3
|
+
SDK for interacting with the JLP.D (JLP Deconstructed) protocol on Solana.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Using npm
|
|
9
|
+
npm install git+https://github.com/elementalfund/jlpd-sdk.git
|
|
10
|
+
|
|
11
|
+
# Using yarn
|
|
12
|
+
yarn add git+https://github.com/elementalfund/jlpd-sdk.git
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or add directly to `package.json`:
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"jlpd-sdk": "git+https://github.com/elementalfund/jlpd-sdk.git"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { Connection } from "@solana/web3.js";
|
|
28
|
+
import { JlpdClient } from "jlpd-sdk";
|
|
29
|
+
|
|
30
|
+
// Connect to Solana mainnet
|
|
31
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
32
|
+
const client = JlpdClient.mainnet(connection);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Available Pools
|
|
36
|
+
|
|
37
|
+
| Pool | Description |
|
|
38
|
+
| ---------- | ----------- |
|
|
39
|
+
| `"SOL"` | Solana |
|
|
40
|
+
| `"USDC"` | USD Coin |
|
|
41
|
+
| `"JupUSD"` | Jupiter USD |
|
|
42
|
+
| `"BTC"` | Bitcoin |
|
|
43
|
+
| `"ETH"` | Ethereum |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## User Operations
|
|
48
|
+
|
|
49
|
+
### Deposit
|
|
50
|
+
|
|
51
|
+
Deposit tokens and receive vault shares (jvX tokens).
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { BN } from "@coral-xyz/anchor";
|
|
55
|
+
|
|
56
|
+
const pool = client.pool("SOL");
|
|
57
|
+
|
|
58
|
+
const tx = await pool.deposit({
|
|
59
|
+
user: walletPublicKey,
|
|
60
|
+
amount: new BN(1_000_000_000), // 1 SOL (9 decimals)
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Sign and send transaction with your wallet
|
|
64
|
+
const signature = await wallet.sendTransaction(tx, connection);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Withdraw
|
|
68
|
+
|
|
69
|
+
Burn vault shares and receive tokens back.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
const tx = await pool.withdraw({
|
|
73
|
+
user: walletPublicKey,
|
|
74
|
+
shares: new BN(500_000_000), // Amount of jvX shares to burn
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const signature = await wallet.sendTransaction(tx, connection);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Reading Data
|
|
83
|
+
|
|
84
|
+
### Get Vault Info
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const vault = await client.fetchVault();
|
|
88
|
+
|
|
89
|
+
console.log("Admin:", vault.admin.toBase58());
|
|
90
|
+
console.log("Manager:", vault.manager.toBase58());
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Get Pool (STV) Info
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const stv = await client.fetchStv(MINTS.SOL);
|
|
97
|
+
|
|
98
|
+
console.log("Price per share:", stv.pps.toString());
|
|
99
|
+
console.log("Total fees accrued:", stv.accruedFeesJlx.toString());
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Get Exchange Rate
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const rate = await client.fetchExchangeRate("SOL");
|
|
106
|
+
|
|
107
|
+
console.log("Exchange rate:", rate.rate); // e.g., 1.05 means 5% yield
|
|
108
|
+
console.log("Is fresh:", rate.isFresh);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Manager Operations
|
|
114
|
+
|
|
115
|
+
These operations require manager permissions.
|
|
116
|
+
|
|
117
|
+
### Jupiter Earn (Deposit/Withdraw to Jupiter Lend)
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const pool = client.pool("SOL");
|
|
121
|
+
|
|
122
|
+
// Deposit base tokens to Jupiter Lend
|
|
123
|
+
const depositTx = await pool.jupEarn({
|
|
124
|
+
manager: managerPublicKey,
|
|
125
|
+
direction: "Deposit",
|
|
126
|
+
amount: new BN(1_000_000_000),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Withdraw from Jupiter Lend
|
|
130
|
+
const withdrawTx = await pool.jupEarn({
|
|
131
|
+
manager: managerPublicKey,
|
|
132
|
+
direction: "Withdraw",
|
|
133
|
+
amount: new BN(1_000_000_000),
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Move Tokens Between STV and Vault
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const pool = client.pool("SOL");
|
|
141
|
+
|
|
142
|
+
// Move jlX tokens to vault (for JLP conversion)
|
|
143
|
+
const toVaultTx = await pool.moveJlx({
|
|
144
|
+
manager: managerPublicKey,
|
|
145
|
+
direction: "ToVault",
|
|
146
|
+
jlxAmount: new BN(1_000_000_000),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Move jlX tokens back from vault to STV
|
|
150
|
+
const fromVaultTx = await pool.moveJlx({
|
|
151
|
+
manager: managerPublicKey,
|
|
152
|
+
direction: "FromVault",
|
|
153
|
+
jlxAmount: new BN(1_000_000_000),
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Claim Fees
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const pool = client.pool("SOL");
|
|
161
|
+
|
|
162
|
+
const tx = await pool.claimFees({
|
|
163
|
+
manager: managerPublicKey,
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Settle Yield
|
|
168
|
+
|
|
169
|
+
Distributes JLP yield across all pools. Requires fetching the current JLP price.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { fetchJlpRate, MINTS } from "jlpd-sdk";
|
|
173
|
+
|
|
174
|
+
// Fetch current JLP price from Jupiter
|
|
175
|
+
const jlpRate = await fetchJlpRate(MINTS.JLP.toBase58());
|
|
176
|
+
|
|
177
|
+
// Settle yield
|
|
178
|
+
const admin = client.admin();
|
|
179
|
+
const tx = await admin.settleYield({
|
|
180
|
+
manager: managerPublicKey,
|
|
181
|
+
jlpRate,
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Swap Operations
|
|
188
|
+
|
|
189
|
+
### Swap jlX to/from JLP
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
const swap = client.swap();
|
|
193
|
+
|
|
194
|
+
// Get a quote first
|
|
195
|
+
const quote = await swap.quoteJlxJlp({
|
|
196
|
+
pool: "SOL",
|
|
197
|
+
direction: "JlxToJlp", // or "JlpToJlx"
|
|
198
|
+
amountIn: new BN(1_000_000_000),
|
|
199
|
+
slippageBps: 30, // 0.3% slippage
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
console.log("Expected output:", quote.outAmount.toString());
|
|
203
|
+
console.log("Price impact:", quote.priceImpactPct, "%");
|
|
204
|
+
|
|
205
|
+
// Execute the swap
|
|
206
|
+
const tx = await swap.swapJlxJlp({
|
|
207
|
+
manager: managerPublicKey,
|
|
208
|
+
pool: "SOL",
|
|
209
|
+
direction: "JlxToJlp",
|
|
210
|
+
amountIn: new BN(1_000_000_000),
|
|
211
|
+
expectedOut: quote.outAmount,
|
|
212
|
+
quote,
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Swap Between jlX Types
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const swap = client.swap();
|
|
220
|
+
|
|
221
|
+
// Get a quote
|
|
222
|
+
const quote = await swap.quoteJlxJlx({
|
|
223
|
+
fromPool: "SOL",
|
|
224
|
+
toPool: "USDC",
|
|
225
|
+
amountIn: new BN(1_000_000_000),
|
|
226
|
+
slippageBps: 30,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Execute the swap
|
|
230
|
+
const tx = await swap.swapJlxJlx({
|
|
231
|
+
manager: managerPublicKey,
|
|
232
|
+
fromPool: "SOL",
|
|
233
|
+
toPool: "USDC",
|
|
234
|
+
amountIn: new BN(1_000_000_000),
|
|
235
|
+
minOut: quote.minOutAmount,
|
|
236
|
+
quote,
|
|
237
|
+
});
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Token Decimals Reference
|
|
243
|
+
|
|
244
|
+
| Token | Decimals | Example |
|
|
245
|
+
| ------ | -------- | ----------------------- |
|
|
246
|
+
| SOL | 9 | `1 SOL = 1_000_000_000` |
|
|
247
|
+
| USDC | 6 | `1 USDC = 1_000_000` |
|
|
248
|
+
| JupUSD | 6 | `1 JupUSD = 1_000_000` |
|
|
249
|
+
| BTC | 8 | `1 BTC = 100_000_000` |
|
|
250
|
+
| ETH | 8 | `1 ETH = 100_000_000` |
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Working with BN (Big Numbers)
|
|
255
|
+
|
|
256
|
+
Solana uses big integers for token amounts. Use the `BN` class:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { BN } from "@coral-xyz/anchor";
|
|
260
|
+
|
|
261
|
+
// Create from number (small amounts only)
|
|
262
|
+
const small = new BN(1000);
|
|
263
|
+
|
|
264
|
+
// Create from string (recommended for large amounts)
|
|
265
|
+
const large = new BN("1000000000000");
|
|
266
|
+
|
|
267
|
+
// Arithmetic
|
|
268
|
+
const sum = a.add(b);
|
|
269
|
+
const diff = a.sub(b);
|
|
270
|
+
const product = a.mul(b);
|
|
271
|
+
const quotient = a.div(b);
|
|
272
|
+
|
|
273
|
+
// Comparison
|
|
274
|
+
a.gt(b); // greater than
|
|
275
|
+
a.lt(b); // less than
|
|
276
|
+
a.eq(b); // equal
|
|
277
|
+
a.isZero();
|
|
278
|
+
|
|
279
|
+
// Convert to display string
|
|
280
|
+
const displayAmount = amount.toString();
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Error Handling
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import { JlpdClientError } from "jlpd-sdk";
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
const tx = await pool.deposit({
|
|
292
|
+
user: walletPublicKey,
|
|
293
|
+
amount: new BN(0), // Invalid amount
|
|
294
|
+
});
|
|
295
|
+
} catch (error) {
|
|
296
|
+
if (error instanceof JlpdClientError) {
|
|
297
|
+
console.error("SDK Error:", error.message);
|
|
298
|
+
} else {
|
|
299
|
+
console.error("Unexpected error:", error);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Constants
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
import { MINTS, JLPD_PROGRAM_ID } from "jlpd-sdk";
|
|
310
|
+
|
|
311
|
+
// Token mints
|
|
312
|
+
MINTS.SOL; // Native SOL mint
|
|
313
|
+
MINTS.USDC; // USDC mint
|
|
314
|
+
MINTS.JLP; // JLP token mint
|
|
315
|
+
MINTS.WBTC; // Wrapped BTC mint
|
|
316
|
+
MINTS.WETH; // Wrapped ETH mint
|
|
317
|
+
|
|
318
|
+
// Program ID
|
|
319
|
+
JLPD_PROGRAM_ID; // Main program address
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## Full Example: Deposit Flow
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
328
|
+
import { BN } from "@coral-xyz/anchor";
|
|
329
|
+
import { JlpdClient } from "jlpd-sdk";
|
|
330
|
+
|
|
331
|
+
async function deposit(walletPublicKey: PublicKey, wallet: any) {
|
|
332
|
+
// 1. Create client
|
|
333
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
334
|
+
const client = JlpdClient.mainnet(connection);
|
|
335
|
+
|
|
336
|
+
// 2. Get pool context
|
|
337
|
+
const pool = client.pool("SOL");
|
|
338
|
+
|
|
339
|
+
// 3. Check current exchange rate (optional)
|
|
340
|
+
const rate = await client.fetchExchangeRate("SOL");
|
|
341
|
+
console.log(`Current yield: ${((rate.rate - 1) * 100).toFixed(2)}%`);
|
|
342
|
+
|
|
343
|
+
// 4. Build deposit transaction
|
|
344
|
+
const tx = await pool.deposit({
|
|
345
|
+
user: walletPublicKey,
|
|
346
|
+
amount: new BN(1_000_000_000), // 1 SOL
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// 5. Send transaction
|
|
350
|
+
const signature = await wallet.sendTransaction(tx, connection);
|
|
351
|
+
console.log("Transaction sent:", signature);
|
|
352
|
+
|
|
353
|
+
// 6. Confirm transaction
|
|
354
|
+
await connection.confirmTransaction(signature, "confirmed");
|
|
355
|
+
console.log("Deposit confirmed!");
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Support
|
|
362
|
+
|
|
363
|
+
For issues or questions, contact the Elemental team.
|