@exponent-labs/generic-sy-sdk 0.1.3 → 0.1.6

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/build/index.js CHANGED
@@ -2,15 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initSy = exports.GenericSySdk = exports.getInterfaceTypeFromString = exports.getInterfaceTypeObj = exports.InterfaceType = void 0;
4
4
  const anchor_1 = require("@coral-xyz/anchor");
5
- const generic_sy_idl_1 = require("@exponent-labs/generic-sy-idl");
6
5
  const spl_token_1 = require("@solana/spl-token");
7
- const generic_sy_pda_1 = require("@exponent-labs/generic-sy-pda");
8
- const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
9
6
  const exponent_admin_pda_1 = require("@exponent-labs/exponent-admin-pda");
10
- const utils_1 = require("./utils");
7
+ const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
11
8
  const fragmetric_pda_1 = require("@exponent-labs/fragmetric-pda");
12
- const generic_sy_idl_2 = require("@exponent-labs/generic-sy-idl");
9
+ const generic_sy_idl_1 = require("@exponent-labs/generic-sy-idl");
10
+ const generic_sy_pda_1 = require("@exponent-labs/generic-sy-pda");
13
11
  const precise_number_1 = require("@exponent-labs/precise-number");
12
+ const utils_1 = require("./utils");
14
13
  async function loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType) {
15
14
  let interfaceIndex;
16
15
  if ("pyth" in interfaceType) {
@@ -28,9 +27,30 @@ async function loadAccountState(cnx, yieldBearingMint, genericStandardProgramId,
28
27
  else if ("meteora" in interfaceType) {
29
28
  interfaceIndex = InterfaceType.Meteora;
30
29
  }
30
+ else if ("sanctum" in interfaceType) {
31
+ interfaceIndex = InterfaceType.Sanctum;
32
+ }
31
33
  else if ("fragmetricSupportedAsset" in interfaceType) {
32
34
  interfaceIndex = InterfaceType.FragmetricSupportedAsset;
33
35
  }
36
+ else if ("jupiterPerps" in interfaceType) {
37
+ interfaceIndex = InterfaceType.JupiterPerps;
38
+ }
39
+ else if ("adrena" in interfaceType) {
40
+ interfaceIndex = InterfaceType.Adrena;
41
+ }
42
+ else if ("hyloLpToken" in interfaceType) {
43
+ interfaceIndex = InterfaceType.HyloLpToken;
44
+ }
45
+ else if ("jupiterLend" in interfaceType) {
46
+ interfaceIndex = InterfaceType.JupiterLend;
47
+ }
48
+ else if ("kaminoVault" in interfaceType) {
49
+ interfaceIndex = InterfaceType.KaminoVault;
50
+ }
51
+ else if ("solstice" in interfaceType) {
52
+ interfaceIndex = InterfaceType.Solstice;
53
+ }
34
54
  else {
35
55
  throw new Error("Unsupported interface type");
36
56
  }
@@ -50,6 +70,13 @@ var InterfaceType;
50
70
  InterfaceType[InterfaceType["Fragmetric"] = 3] = "Fragmetric";
51
71
  InterfaceType[InterfaceType["Meteora"] = 4] = "Meteora";
52
72
  InterfaceType[InterfaceType["FragmetricSupportedAsset"] = 5] = "FragmetricSupportedAsset";
73
+ InterfaceType[InterfaceType["Sanctum"] = 6] = "Sanctum";
74
+ InterfaceType[InterfaceType["JupiterPerps"] = 7] = "JupiterPerps";
75
+ InterfaceType[InterfaceType["Adrena"] = 8] = "Adrena";
76
+ InterfaceType[InterfaceType["HyloLpToken"] = 9] = "HyloLpToken";
77
+ InterfaceType[InterfaceType["JupiterLend"] = 10] = "JupiterLend";
78
+ InterfaceType[InterfaceType["KaminoVault"] = 11] = "KaminoVault";
79
+ InterfaceType[InterfaceType["Solstice"] = 12] = "Solstice";
53
80
  })(InterfaceType || (exports.InterfaceType = InterfaceType = {}));
54
81
  function getInterfaceTypeObj(interfaceType) {
55
82
  switch (interfaceType) {
@@ -65,6 +92,27 @@ function getInterfaceTypeObj(interfaceType) {
65
92
  return { fragmetricSupportedAsset: {} };
66
93
  case InterfaceType.Meteora:
67
94
  return { meteora: {} };
95
+ case InterfaceType.Sanctum:
96
+ return { sanctum: {} };
97
+ case InterfaceType.JupiterPerps:
98
+ return {
99
+ jupiterPerps: {
100
+ lastFeeUsdResetUnixTimestamp: 0,
101
+ lastRealizedFeeUsd: new anchor_1.BN(0),
102
+ lastAumUsd: new anchor_1.BN(0),
103
+ lastRealizedFeeUsdUpdateUnixTimestamp: 0,
104
+ },
105
+ };
106
+ case InterfaceType.Adrena:
107
+ return { adrena: { previousTotalFees: new anchor_1.BN(0) } };
108
+ case InterfaceType.HyloLpToken:
109
+ return { hyloLpToken: {} };
110
+ case InterfaceType.JupiterLend:
111
+ return { jupiterLend: { padding: [] } };
112
+ case InterfaceType.KaminoVault:
113
+ return { kaminoVault: { padding: [] } };
114
+ case InterfaceType.Solstice:
115
+ return { solstice: { padding: [] } };
68
116
  default:
69
117
  throw new Error(`Unsupported interface type: ${interfaceType}`);
70
118
  }
@@ -84,6 +132,27 @@ function getInterfaceTypeFromString(interfaceType) {
84
132
  return { fragmetricSupportedAsset: {} };
85
133
  case "meteora":
86
134
  return { meteora: {} };
135
+ case "sanctum":
136
+ return { sanctum: {} };
137
+ case "jupiter-perps":
138
+ return {
139
+ jupiterPerps: {
140
+ lastFeeUsdResetUnixTimestamp: 0,
141
+ lastRealizedFeeUsd: new anchor_1.BN(0),
142
+ lastAumUsd: new anchor_1.BN(0),
143
+ lastRealizedFeeUsdUpdateUnixTimestamp: 0,
144
+ },
145
+ };
146
+ case "adrena":
147
+ return { adrena: { previousTotalFees: new anchor_1.BN(0) } };
148
+ case "hylo-lp-token":
149
+ return { hyloLpToken: {} };
150
+ case "jupiter-lend":
151
+ return { jupiterLend: { padding: [] } };
152
+ case "kamino-vault":
153
+ return { kaminoVault: { padding: [] } };
154
+ case "solstice":
155
+ return { solstice: { padding: [] } };
87
156
  default:
88
157
  throw new Error(`Unsupported interface type: ${interfaceType}`);
89
158
  }
@@ -95,7 +164,7 @@ class GenericSySdk {
95
164
  program;
96
165
  config;
97
166
  syPda;
98
- constructor(state, programId = new anchor_1.web3.PublicKey(generic_sy_idl_2.PROGRAM_ID), config = {}) {
167
+ constructor(state, programId = new anchor_1.web3.PublicKey(generic_sy_idl_1.PROGRAM_ID), config = {}) {
99
168
  this.state = state;
100
169
  this.config = config;
101
170
  // create a fake AnchorProvider -- which is unused
@@ -120,6 +189,27 @@ class GenericSySdk {
120
189
  else if ("meteora" in this.state.account.interfaceType) {
121
190
  interfaceIndex = InterfaceType.Meteora;
122
191
  }
192
+ else if ("sanctum" in this.state.account.interfaceType) {
193
+ interfaceIndex = InterfaceType.Sanctum;
194
+ }
195
+ else if ("jupiterPerps" in this.state.account.interfaceType) {
196
+ interfaceIndex = InterfaceType.JupiterPerps;
197
+ }
198
+ else if ("adrena" in this.state.account.interfaceType) {
199
+ interfaceIndex = InterfaceType.Adrena;
200
+ }
201
+ else if ("hyloLpToken" in this.state.account.interfaceType) {
202
+ interfaceIndex = InterfaceType.HyloLpToken;
203
+ }
204
+ else if ("jupiterLend" in this.state.account.interfaceType) {
205
+ interfaceIndex = InterfaceType.JupiterLend;
206
+ }
207
+ else if ("kaminoVault" in this.state.account.interfaceType) {
208
+ interfaceIndex = InterfaceType.KaminoVault;
209
+ }
210
+ else if ("solstice" in this.state.account.interfaceType) {
211
+ interfaceIndex = InterfaceType.Solstice;
212
+ }
123
213
  else {
124
214
  throw new Error("Unsupported interface type");
125
215
  }
@@ -140,14 +230,24 @@ class GenericSySdk {
140
230
  fragmetricFund: account.interfaceAccounts[0],
141
231
  index: 0,
142
232
  });
143
- return { syRate: index, fragmetricData: { receiptTokenMint, wrappedTokenMint } };
233
+ return {
234
+ syRate: index,
235
+ additionalData: {
236
+ fragmetricData: { receiptTokenMint, wrappedTokenMint },
237
+ },
238
+ };
144
239
  }
145
240
  else if ("fragmetric" in interfaceType) {
146
241
  const { index, receiptTokenMint, wrappedTokenMint } = await (0, exponent_fetcher_1.fetchFragmetricIndex)({
147
242
  connection: cnx,
148
243
  fragmetricFund: account.interfaceAccounts[0],
149
244
  });
150
- return { syRate: index, fragmetricData: { receiptTokenMint, wrappedTokenMint } };
245
+ return {
246
+ syRate: index,
247
+ additionalData: {
248
+ fragmetricData: { receiptTokenMint, wrappedTokenMint },
249
+ },
250
+ };
151
251
  }
152
252
  else if ("meteora" in interfaceType) {
153
253
  const currentTs = Math.floor(Date.now() / 1000);
@@ -159,6 +259,98 @@ class GenericSySdk {
159
259
  const virtualPrice = await (0, exponent_fetcher_1.fetchMeteoraIndex)({ connection: cnx, accounts, onChainTime: currentTs });
160
260
  return { syRate: virtualPrice.virtualPrice };
161
261
  }
262
+ else if ("sanctum" in interfaceType) {
263
+ const accounts = {
264
+ lpMint: account.interfaceAccounts[0],
265
+ poolState: account.interfaceAccounts[1],
266
+ };
267
+ const exchangeRate = await (0, exponent_fetcher_1.fetchSanctumIndex)({ connection: cnx, accounts });
268
+ return { syRate: exchangeRate };
269
+ }
270
+ else if ("adrena" in interfaceType) {
271
+ // @ts-ignore
272
+ const previousTotalFees = account.interfaceType.adrena.previousTotalFees;
273
+ const currentIndex = account.index;
274
+ let accounts = {
275
+ pool: account.interfaceAccounts[0],
276
+ custody1: account.interfaceAccounts[1],
277
+ custody2: account.interfaceAccounts[2],
278
+ custody3: account.interfaceAccounts[3],
279
+ custody4: account.interfaceAccounts[4],
280
+ };
281
+ const syRate = await (0, exponent_fetcher_1.fetchAdrenaIndex)({ connection: cnx, accounts, currentIndex, previousTotalFees });
282
+ return { syRate: syRate.index };
283
+ }
284
+ else if ("jupiterPerps" in interfaceType) {
285
+ // @ts-ignore
286
+ const j = account.interfaceType.jupiterPerps;
287
+ const { index } = await (0, exponent_fetcher_1.fetchJupiterPerpsIndex)({
288
+ connection: cnx,
289
+ pool: account.interfaceAccounts[0],
290
+ lastFeeUsdResetUnixTimestamp: j.lastFeeUsdResetUnixTimestamp,
291
+ lastRealizedFeeUsd: new anchor_1.BN(j.lastRealizedFeeUsd),
292
+ lastAumUsd: new anchor_1.BN(j.lastAumUsd),
293
+ currentIndex: account.index,
294
+ lastRealizedFeeUsdUpdateUnixTimestamp: j.lastRealizedFeeUsdUpdateUnixTimestamp,
295
+ });
296
+ return { syRate: index };
297
+ }
298
+ else if ("hyloLpToken" in interfaceType) {
299
+ // For HyloLpToken, the exchange rate is calculated by the Rust program using hylo_cpi
300
+ // and will be available in the index field
301
+ const syRate = Number(precise_number_1.PreciseNumber.fromRaw(account.index[0]).valueString);
302
+ return { syRate };
303
+ }
304
+ else if ("jupiterLend" in interfaceType) {
305
+ const { index, baseTokenMint, tokenReservesLiquidity, lendingSupplyPosition, rewardsRateModel, rateModel } = await (0, exponent_fetcher_1.fetchJupiterLendIndex)({
306
+ connection: cnx,
307
+ jupiterLendAccount: account.interfaceAccounts[0],
308
+ });
309
+ return {
310
+ syRate: index,
311
+ additionalData: {
312
+ jupiterLendData: {
313
+ baseTokenMint,
314
+ tokenReservesLiquidity,
315
+ lendingSupplyPosition,
316
+ rewardsRateModel,
317
+ rateModel,
318
+ },
319
+ },
320
+ };
321
+ }
322
+ else if ("kaminoVault" in interfaceType) {
323
+ const { index, tokenVault, tokenMint, baseVaultAuthority, sharesMint, reserves } = await (0, exponent_fetcher_1.fetchKaminoVaultIndex)({
324
+ connection: cnx,
325
+ kaminoVaultAccount: account.interfaceAccounts[0],
326
+ });
327
+ return {
328
+ syRate: index,
329
+ additionalData: {
330
+ kaminoVaultData: {
331
+ vault: account.interfaceAccounts[0],
332
+ reserves: reserves.map((r) => {
333
+ return {
334
+ reserveAddress: r.reserveAddress,
335
+ marketAddress: r.reserve,
336
+ };
337
+ }),
338
+ tokenVault,
339
+ tokenMint,
340
+ baseVaultAuthority,
341
+ sharesMint,
342
+ },
343
+ },
344
+ };
345
+ }
346
+ else if ("solstice" in interfaceType) {
347
+ const { redemptionRate } = await (0, exponent_fetcher_1.fetchSolsticeRedemptionRate)({
348
+ connection: cnx,
349
+ yieldPool: account.interfaceAccounts[0],
350
+ vestingSchedule: account.interfaceAccounts[1],
351
+ });
352
+ return { syRate: redemptionRate };
353
+ }
162
354
  else {
163
355
  return { syRate: 1 };
164
356
  }
@@ -166,7 +358,7 @@ class GenericSySdk {
166
358
  /** Load an instance of SyMeta */
167
359
  static async load({ cnx, yieldBearingMint, interfaceType, genericStandardProgramId, config = {}, }) {
168
360
  const account = await loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType);
169
- const tokenProgramBase = spl_token_1.TOKEN_PROGRAM_ID;
361
+ const tokenProgramBase = (await cnx.getAccountInfo(yieldBearingMint))?.owner;
170
362
  let interfaceIndex;
171
363
  if ("pyth" in interfaceType) {
172
364
  interfaceIndex = InterfaceType.Pyth;
@@ -186,19 +378,40 @@ class GenericSySdk {
186
378
  else if ("meteora" in interfaceType) {
187
379
  interfaceIndex = InterfaceType.Meteora;
188
380
  }
381
+ else if ("sanctum" in interfaceType) {
382
+ interfaceIndex = InterfaceType.Sanctum;
383
+ }
384
+ else if ("jupiterPerps" in interfaceType) {
385
+ interfaceIndex = InterfaceType.JupiterPerps;
386
+ }
387
+ else if ("adrena" in interfaceType) {
388
+ interfaceIndex = InterfaceType.Adrena;
389
+ }
390
+ else if ("hyloLpToken" in interfaceType) {
391
+ interfaceIndex = InterfaceType.HyloLpToken;
392
+ }
393
+ else if ("jupiterLend" in interfaceType) {
394
+ interfaceIndex = InterfaceType.JupiterLend;
395
+ }
396
+ else if ("kaminoVault" in interfaceType) {
397
+ interfaceIndex = InterfaceType.KaminoVault;
398
+ }
399
+ else if ("solstice" in interfaceType) {
400
+ interfaceIndex = InterfaceType.Solstice;
401
+ }
189
402
  else {
190
403
  throw new Error("Unsupported interface type");
191
404
  }
192
405
  const selfAddress = new generic_sy_pda_1.GenericSyPda(genericStandardProgramId, interfaceIndex).syMeta({
193
406
  yieldBearingMint,
194
407
  });
195
- const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, interfaceType, cnx);
408
+ const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, interfaceType, cnx);
196
409
  const state = {
197
410
  selfAddress,
198
411
  account,
199
412
  tokenProgramBase,
200
413
  syRate,
201
- fragmetricData,
414
+ additionalData,
202
415
  };
203
416
  return new GenericSySdk(state, genericStandardProgramId, config);
204
417
  }
@@ -207,13 +420,13 @@ class GenericSySdk {
207
420
  const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId });
208
421
  const account = await fetcher.fetchGenericSyMeta(syMetaAddress);
209
422
  const tokenProgramBase = spl_token_1.TOKEN_PROGRAM_ID;
210
- const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, account.interfaceType, cnx);
423
+ const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, account.interfaceType, cnx);
211
424
  const state = {
212
425
  selfAddress: syMetaAddress,
213
426
  account,
214
427
  tokenProgramBase,
215
428
  syRate,
216
- fragmetricData,
429
+ additionalData,
217
430
  };
218
431
  return new GenericSySdk(state, genericStandardProgramId, config);
219
432
  }
@@ -221,9 +434,9 @@ class GenericSySdk {
221
434
  async reload(cnx) {
222
435
  const account = await loadAccountState(cnx, this.state.account.yieldBearingMint, this.program.programId, this.state.account.interfaceType);
223
436
  this.state.account = account;
224
- const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, account.interfaceType, cnx);
437
+ const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, account.interfaceType, cnx);
225
438
  this.state.syRate = syRate;
226
- this.state.fragmetricData = fragmetricData;
439
+ this.state.additionalData = additionalData;
227
440
  }
228
441
  get account() {
229
442
  return this.state.account;
@@ -256,7 +469,7 @@ class GenericSySdk {
256
469
  return this.state.tokenProgramBase;
257
470
  }
258
471
  get tokenVrtEscrow() {
259
- return (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, this.selfAddress, true, spl_token_1.TOKEN_PROGRAM_ID);
472
+ return (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, this.selfAddress, true, this.tokenProgramBase);
260
473
  }
261
474
  get tokenSyEscrow() {
262
475
  return this.state.account.tokenSyEscrow;
@@ -269,10 +482,28 @@ class GenericSySdk {
269
482
  !("fragmetricSupportedAsset" in this.state.account.interfaceType)) {
270
483
  throw new Error("Not a fragmetric interface");
271
484
  }
272
- if (!this.state.fragmetricData) {
485
+ if (!this.state.additionalData?.fragmetricData) {
273
486
  throw new Error("Fragmetric data not loaded");
274
487
  }
275
- return this.state.fragmetricData;
488
+ return this.state.additionalData.fragmetricData;
489
+ }
490
+ get jupiterLendData() {
491
+ if (!("jupiterLend" in this.state.account.interfaceType)) {
492
+ throw new Error("Not a Jupiter Lend interface");
493
+ }
494
+ if (!this.state.additionalData?.jupiterLendData) {
495
+ throw new Error("Jupiter Lend data not loaded");
496
+ }
497
+ return this.state.additionalData.jupiterLendData;
498
+ }
499
+ get kaminoVaultData() {
500
+ if (!("kaminoVault" in this.state.account.interfaceType)) {
501
+ throw new Error("Not a Kamino Vault interface");
502
+ }
503
+ if (!this.state.additionalData?.kaminoVaultData) {
504
+ throw new Error("Kamino Vault data not loaded");
505
+ }
506
+ return this.state.additionalData.kaminoVaultData;
276
507
  }
277
508
  get remainingAccounts() {
278
509
  const accounts = this.account.interfaceAccounts
@@ -284,7 +515,7 @@ class GenericSySdk {
284
515
  .concat(this.emissions.map((e) => ({ pubkey: e.escrowAccount, isSigner: false, isWritable: false })));
285
516
  return accounts;
286
517
  }
287
- getAccountsWithSigner(signer) {
518
+ getAccountsWithSigner(signer, type = "mint") {
288
519
  const accounts = this.account.interfaceAccounts
289
520
  .map((a) => ({
290
521
  pubkey: a,
@@ -292,14 +523,19 @@ class GenericSySdk {
292
523
  isWritable: true,
293
524
  }))
294
525
  .concat(this.emissions.map((e) => ({ pubkey: e.escrowAccount, isSigner: false, isWritable: false })));
295
- if ("fragmetric" in this.state.account.interfaceType && signer) {
296
- // If skipFragmetricWrap is true, return minimal accounts
297
- if (this.config.skipFragmetricWrap) {
526
+ if (("fragmetric" in this.state.account.interfaceType ||
527
+ "fragmetricSupportedAsset" in this.state.account.interfaceType) &&
528
+ signer) {
529
+ // If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
530
+ if (this.config.skipWrap) {
298
531
  return accounts;
299
532
  }
300
- // Existing fragmetric account logic
301
- const fragmetricReceiptTokenMint = this.state.fragmetricData.receiptTokenMint;
302
- const fragmetricWrappedTokenMint = this.state.fragmetricData.wrappedTokenMint;
533
+ // Fragmetric interface account logic
534
+ if (!this.state.additionalData?.fragmetricData) {
535
+ throw new Error("Fragmetric data not loaded for fragmetric interface");
536
+ }
537
+ const fragmetricReceiptTokenMint = this.state.additionalData.fragmetricData.receiptTokenMint;
538
+ const fragmetricWrappedTokenMint = this.state.additionalData.fragmetricData.wrappedTokenMint;
303
539
  const fragmetricPda = new fragmetric_pda_1.FragmetricPda();
304
540
  const fragmetricFundAccount = fragmetricPda.fundAccount(fragmetricReceiptTokenMint);
305
541
  const fragmetricRewardAccount = fragmetricPda.rewardAccount(fragmetricReceiptTokenMint);
@@ -325,19 +561,170 @@ class GenericSySdk {
325
561
  isWritable: false,
326
562
  });
327
563
  }
564
+ if ("jupiterLend" in this.state.account.interfaceType) {
565
+ // If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
566
+ if (this.config.skipWrap) {
567
+ return accounts;
568
+ }
569
+ const jupiterLendData = this.state.additionalData?.jupiterLendData;
570
+ if (!jupiterLendData) {
571
+ throw new Error("Jupiter lend data not loaded");
572
+ }
573
+ console.log("accounts before push", accounts);
574
+ const vaultAuthority = new anchor_1.web3.PublicKey("7s1da8DduuBFqGra5bJBjpnvL5E9mGzCuMk1Qkh4or2Z");
575
+ const vaultAta = (0, spl_token_1.getAssociatedTokenAddressSync)(jupiterLendData.baseTokenMint, vaultAuthority, true, this.tokenProgramBase);
576
+ if (type === "mint") {
577
+ const depositorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(jupiterLendData.baseTokenMint, signer, true, this.tokenProgramBase);
578
+ const recipientTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, signer, true, this.tokenProgramBase);
579
+ console.log("jupiter lend rate model: ", jupiterLendData.rateModel.toBase58());
580
+ accounts.push({ pubkey: signer, isSigner: true, isWritable: true }, { pubkey: depositorTokenAccount, isSigner: false, isWritable: true }, { pubkey: recipientTokenAccount, isSigner: false, isWritable: true }, { pubkey: jupiterLendData.baseTokenMint, isSigner: false, isWritable: true },
581
+ // lending admin
582
+ {
583
+ pubkey: new anchor_1.web3.PublicKey("5nmGjA4s7ATzpBQXC5RNceRpaJ7pYw2wKsNBWyuSAZV6"),
584
+ isSigner: false,
585
+ isWritable: false,
586
+ }, { pubkey: this.account.interfaceAccounts[0], isSigner: false, isWritable: true }, { pubkey: this.vrtMint, isSigner: false, isWritable: true }, { pubkey: jupiterLendData.tokenReservesLiquidity, isSigner: false, isWritable: true }, { pubkey: jupiterLendData.lendingSupplyPosition, isSigner: false, isWritable: true }, { pubkey: jupiterLendData.rateModel, isSigner: false, isWritable: true },
587
+ // vault
588
+ {
589
+ pubkey: vaultAta,
590
+ isSigner: false,
591
+ isWritable: true,
592
+ },
593
+ // supply vault owner - can be hardcoded
594
+ {
595
+ pubkey: vaultAuthority,
596
+ isSigner: false,
597
+ isWritable: true,
598
+ },
599
+ // liquidity program - can be hardcoded
600
+ {
601
+ pubkey: new anchor_1.web3.PublicKey("jupeiUmn818Jg1ekPURTpr4mFo29p46vygyykFJ3wZC"),
602
+ isSigner: false,
603
+ isWritable: true,
604
+ }, { pubkey: jupiterLendData.rewardsRateModel, isSigner: false, isWritable: true },
605
+ // token program
606
+ { pubkey: this.tokenProgramBase, isSigner: false, isWritable: false },
607
+ // associated token program
608
+ { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: anchor_1.web3.SystemProgram.programId, isSigner: false, isWritable: false }, {
609
+ pubkey: new anchor_1.web3.PublicKey("jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9"),
610
+ isSigner: false,
611
+ isWritable: false,
612
+ });
613
+ }
614
+ else if (type === "redeem") {
615
+ const recipientTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(jupiterLendData.baseTokenMint, signer, true, this.tokenProgramBase);
616
+ const depositorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, signer, true, this.tokenProgramBase);
617
+ accounts.push({ pubkey: signer, isSigner: true, isWritable: true }, { pubkey: depositorTokenAccount, isSigner: false, isWritable: true }, { pubkey: recipientTokenAccount, isSigner: false, isWritable: true }, {
618
+ // lending admin
619
+ pubkey: new anchor_1.web3.PublicKey("5nmGjA4s7ATzpBQXC5RNceRpaJ7pYw2wKsNBWyuSAZV6"),
620
+ isSigner: false,
621
+ isWritable: false,
622
+ },
623
+ // lending
624
+ { pubkey: this.account.interfaceAccounts[0], isSigner: false, isWritable: true }, { pubkey: jupiterLendData.baseTokenMint, isSigner: false, isWritable: true }, { pubkey: this.vrtMint, isSigner: false, isWritable: true }, { pubkey: jupiterLendData.tokenReservesLiquidity, isSigner: false, isWritable: true }, { pubkey: jupiterLendData.lendingSupplyPosition, isSigner: false, isWritable: true }, { pubkey: jupiterLendData.rateModel, isSigner: false, isWritable: true },
625
+ // vault
626
+ {
627
+ pubkey: vaultAta,
628
+ isSigner: false,
629
+ isWritable: true,
630
+ },
631
+ // claim account
632
+ {
633
+ pubkey: new anchor_1.web3.PublicKey("HN1r4VfkDn53xQQfeGDYrNuDKFdemAhZsHYRwBrFhsW"),
634
+ isSigner: false,
635
+ isWritable: true,
636
+ },
637
+ // liquidity
638
+ {
639
+ pubkey: new anchor_1.web3.PublicKey("7s1da8DduuBFqGra5bJBjpnvL5E9mGzCuMk1Qkh4or2Z"),
640
+ isSigner: false,
641
+ isWritable: true,
642
+ },
643
+ // liquidity program
644
+ {
645
+ pubkey: new anchor_1.web3.PublicKey("jupeiUmn818Jg1ekPURTpr4mFo29p46vygyykFJ3wZC"),
646
+ isSigner: false,
647
+ isWritable: true,
648
+ }, { pubkey: jupiterLendData.rewardsRateModel, isSigner: false, isWritable: true },
649
+ // token program
650
+ { pubkey: this.tokenProgramBase, isSigner: false, isWritable: false },
651
+ // associated token program
652
+ { pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: anchor_1.web3.SystemProgram.programId, isSigner: false, isWritable: false }, {
653
+ pubkey: new anchor_1.web3.PublicKey("jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9"),
654
+ isSigner: false,
655
+ isWritable: false,
656
+ });
657
+ }
658
+ }
659
+ if ("kaminoVault" in this.state.account.interfaceType) {
660
+ // If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
661
+ if (this.config.skipWrap) {
662
+ return accounts;
663
+ }
664
+ const kaminoVaultData = this.state.additionalData?.kaminoVaultData;
665
+ if (!kaminoVaultData) {
666
+ throw new Error("Kamino vault data not loaded");
667
+ }
668
+ const userTokenAta = (0, spl_token_1.getAssociatedTokenAddressSync)(kaminoVaultData.tokenMint, signer, true, spl_token_1.TOKEN_PROGRAM_ID);
669
+ const userSharesAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, signer, true, spl_token_1.TOKEN_PROGRAM_ID);
670
+ accounts.push(
671
+ // user
672
+ { pubkey: signer, isSigner: true, isWritable: true },
673
+ // vault_state
674
+ { pubkey: kaminoVaultData.vault, isSigner: false, isWritable: true },
675
+ // token_vault
676
+ { pubkey: kaminoVaultData.tokenVault, isSigner: false, isWritable: true },
677
+ // token_mint
678
+ { pubkey: kaminoVaultData.tokenMint, isSigner: false, isWritable: true },
679
+ // base_vault_authority
680
+ { pubkey: kaminoVaultData.baseVaultAuthority, isSigner: false, isWritable: true },
681
+ // shares_mint
682
+ { pubkey: kaminoVaultData.sharesMint, isSigner: false, isWritable: true },
683
+ // user_token_ata
684
+ { pubkey: userTokenAta, isSigner: false, isWritable: true },
685
+ // user_shares_ata
686
+ { pubkey: userSharesAta, isSigner: false, isWritable: true },
687
+ // klend_program
688
+ {
689
+ pubkey: new anchor_1.web3.PublicKey("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD"),
690
+ isSigner: false,
691
+ isWritable: false,
692
+ },
693
+ // token_program
694
+ { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
695
+ // shares_token_program
696
+ { pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
697
+ // event_authority
698
+ {
699
+ pubkey: new anchor_1.web3.PublicKey("24tHwQyJJ9akVXxnvkekGfAoeUJXXS7mE6kQNioNySsK"),
700
+ isSigner: false,
701
+ isWritable: true,
702
+ },
703
+ // kamino vault program
704
+ {
705
+ pubkey: new anchor_1.web3.PublicKey("KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd"),
706
+ isSigner: false,
707
+ isWritable: false,
708
+ }, ...kaminoVaultData.reserves.map((reserve) => ({
709
+ pubkey: reserve.reserveAddress,
710
+ isSigner: false,
711
+ isWritable: true,
712
+ })), ...kaminoVaultData.reserves.map((reserve) => ({
713
+ pubkey: reserve.marketAddress,
714
+ isSigner: false,
715
+ isWritable: true,
716
+ })));
717
+ }
328
718
  return accounts;
329
719
  }
330
720
  ixMintSy({ depositor, amountBase, baseSrc, syDst, }) {
331
721
  baseSrc = baseSrc || (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, depositor, true, this.state.tokenProgramBase);
332
- console.log("baseSrc", baseSrc.toBase58());
333
- console.log("depositor", depositor.toBase58());
334
722
  syDst = syDst || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
335
- console.log("this.selfAddress", this.selfAddress.toBase58());
336
723
  return this.program.methods
337
724
  .mint(new anchor_1.BN(amountBase))
338
725
  .accountsStrict({
339
726
  meta: this.selfAddress,
340
- baseTokenProgram: this.tokenProgramBase,
727
+ baseTokenProgram: this.state.tokenProgramBase,
341
728
  depositor,
342
729
  mintSy: this.mintSy,
343
730
  tokenBaseDepositor: baseSrc,
@@ -363,9 +750,51 @@ class GenericSySdk {
363
750
  baseTokenProgram: this.tokenProgramBase,
364
751
  tokenYieldBearingEscrow: this.tokenVrtEscrow,
365
752
  })
366
- .remainingAccounts(this.getAccountsWithSigner(redeemer))
753
+ .remainingAccounts(this.getAccountsWithSigner(redeemer, "redeem"))
367
754
  .instruction();
368
755
  }
756
+ preInstructions() {
757
+ let ixs = [];
758
+ if ("jupiterLend" in this.state.account.interfaceType) {
759
+ const jupiterLendData = this.state.additionalData?.jupiterLendData;
760
+ if (!jupiterLendData) {
761
+ throw new Error("Jupiter lend data not loaded");
762
+ }
763
+ const refreshInstruction = new anchor_1.web3.TransactionInstruction({
764
+ keys: [
765
+ {
766
+ pubkey: this.account.interfaceAccounts[0],
767
+ isSigner: false,
768
+ isWritable: true,
769
+ },
770
+ {
771
+ pubkey: jupiterLendData.baseTokenMint,
772
+ isSigner: false,
773
+ isWritable: true,
774
+ },
775
+ {
776
+ pubkey: this.vrtMint,
777
+ isSigner: false,
778
+ isWritable: true,
779
+ },
780
+ {
781
+ pubkey: jupiterLendData.tokenReservesLiquidity,
782
+ isSigner: false,
783
+ isWritable: true,
784
+ },
785
+ {
786
+ pubkey: jupiterLendData.rewardsRateModel,
787
+ isSigner: false,
788
+ isWritable: true,
789
+ },
790
+ ],
791
+ programId: new anchor_1.web3.PublicKey("jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9"),
792
+ data: Buffer.from([24, 225, 53, 189, 72, 212, 225, 178]),
793
+ });
794
+ ixs.push(refreshInstruction);
795
+ }
796
+ return ixs;
797
+ }
369
798
  getSyState() {
370
799
  return this.program.methods
371
800
  .getState()
@@ -398,30 +827,30 @@ class GenericSySdk {
398
827
  preMintHookDiscriminator: Buffer.from(hook.preMintHookDiscriminator),
399
828
  postRedeemHookDiscriminator: Buffer.from(hook.postRedeemHookDiscriminator),
400
829
  };
401
- return this.program.methods.modifyHook(modifiedHook).accountsStrict({
830
+ return this.program.methods
831
+ .modifyHook(modifiedHook)
832
+ .accountsStrict({
402
833
  adminState: this.adminState,
403
834
  signer,
404
835
  feePayer: signer,
405
836
  meta: this.selfAddress,
406
837
  systemProgram: anchor_1.web3.SystemProgram.programId,
407
- });
838
+ })
839
+ .instruction();
408
840
  }
409
841
  }
410
842
  exports.GenericSySdk = GenericSySdk;
411
- function initSy(signer, interfaceAccounts, yieldBearingMint, interfaceIndex, syToken, initConfig) {
843
+ function initSy(signer, interfaceAccounts, yieldBearingMint, interfaceIndex, syToken, initConfig, yieldBearingMintTokenProgram = spl_token_1.TOKEN_PROGRAM_ID) {
412
844
  const program = new anchor_1.Program(generic_sy_idl_1.IDL, new anchor_1.AnchorProvider(new anchor_1.web3.Connection("https://api.devnet.solana.com"), new utils_1.MyWallet(anchor_1.web3.Keypair.generate())));
413
- console.log("interfaceIndex", interfaceIndex);
414
845
  const pda = new generic_sy_pda_1.GenericSyPda(program.programId, interfaceIndex);
415
846
  const syMetaAddress = pda.syMeta({ yieldBearingMint });
416
- console.log("this.selfAddress in sdk", syMetaAddress.toBase58());
417
847
  const mintSy = pda.mintSy({ yieldBearingMint });
418
- console.log("mintSy in sdk", mintSy.toBase58());
419
848
  const exponentAdminPda = new exponent_admin_pda_1.ExponentAdminPda(exponent_admin_pda_1.EXPONENT_ADMIN_PROGRAM_ID);
420
849
  const metaplexMetadataProgram = new anchor_1.web3.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
421
850
  const mintSyMetaplexMetadataPda = anchor_1.web3.PublicKey.findProgramAddressSync([Buffer.from("metadata"), metaplexMetadataProgram.toBuffer(), mintSy.toBuffer()], metaplexMetadataProgram)[0];
422
- const tokenVrtEscrow = (0, spl_token_1.getAssociatedTokenAddressSync)(yieldBearingMint, syMetaAddress, true, spl_token_1.TOKEN_PROGRAM_ID);
851
+ const tokenVrtEscrow = (0, spl_token_1.getAssociatedTokenAddressSync)(yieldBearingMint, syMetaAddress, true, yieldBearingMintTokenProgram);
423
852
  const { minMintSize, minRedeemSize } = initConfig ? initConfig : { minMintSize: new anchor_1.BN(0), minRedeemSize: new anchor_1.BN(0) };
424
- const { name: tokenName, uri: tokenUri, symbol: tokenSymbol, } = syToken ? syToken : { symbol: "ewfragBTC", name: "Exponent Wrapped wfragBTC", uri: "" };
853
+ const { name: tokenName, uri: tokenUri, symbol: tokenSymbol, } = syToken ? syToken : { symbol: "wjlSOL", name: "Exponent Wrapped jlSOL", uri: "" };
425
854
  const interfaceType = getInterfaceTypeObj(interfaceIndex);
426
855
  const ix = program.methods
427
856
  .initSy(minMintSize, minRedeemSize, tokenName, tokenSymbol, tokenUri, interfaceAccounts, interfaceType)
@@ -432,7 +861,7 @@ function initSy(signer, interfaceAccounts, yieldBearingMint, interfaceIndex, syT
432
861
  admin: signer,
433
862
  yieldBearingMint,
434
863
  syTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
435
- yieldBearingTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
864
+ yieldBearingTokenProgram: yieldBearingMintTokenProgram,
436
865
  tokenSyEscrow: pda.syEscrow({ yieldBearingMint }),
437
866
  systemProgram: anchor_1.web3.SystemProgram.programId,
438
867
  metadata: mintSyMetaplexMetadataPda,