@lavarage/sdk 6.8.3 → 6.8.5

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/lending.ts CHANGED
@@ -62,14 +62,15 @@ async function createNodeWallet(
62
62
  ): Promise<{
63
63
  instruction: TransactionInstruction;
64
64
  nodeWallet: Keypair | undefined;
65
+ nodeWalletAccount: PublicKey;
65
66
  }> {
66
67
  const { blockhash } =
67
68
  await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
68
69
 
69
70
  let instruction, nodeWallet;
70
71
 
71
- // Check if this is V2 program (has mint parameter)
72
- if (params.mint !== undefined) {
72
+ // Check if this is V2 program (has mint and liquidationLtv parameters)
73
+ if (params.mint !== undefined && params.liquidationLtv !== undefined) {
73
74
  nodeWallet = getNodeWalletPDA(
74
75
  new PublicKey(params.operator),
75
76
  new PublicKey(params.mint),
@@ -101,6 +102,8 @@ async function createNodeWallet(
101
102
  return {
102
103
  instruction,
103
104
  nodeWallet: nodeWallet instanceof Keypair ? nodeWallet : undefined,
105
+ nodeWalletAccount:
106
+ nodeWallet instanceof Keypair ? nodeWallet.publicKey : nodeWallet,
104
107
  };
105
108
  }
106
109
 
@@ -119,21 +122,38 @@ export async function depositFunds(
119
122
  let instruction;
120
123
  if (params.mint === undefined) {
121
124
  instruction = await lavarageProgram.methods
122
- .lpOperatorFundNodeWallet(new BN(params.amount))
123
- .accounts({
124
- nodeWallet: params.nodeWallet,
125
- funder: params.funder,
126
- systemProgram: SystemProgram.programId,
127
- })
128
- .instruction();
125
+ .lpOperatorFundNodeWallet(new BN(params.amount))
126
+ .accounts({
127
+ nodeWallet: params.nodeWallet,
128
+ funder: params.funder,
129
+ systemProgram: SystemProgram.programId,
130
+ })
131
+ .instruction();
129
132
  } else {
130
133
  const mintPubkey = new PublicKey(params.mint);
131
- const mintOwner = await lavarageProgram.provider.connection.getAccountInfo(mintPubkey);
132
- const mintAccount = await getMint(lavarageProgram.provider.connection, mintPubkey, 'confirmed', mintOwner?.owner);
134
+ const mintOwner = await lavarageProgram.provider.connection.getAccountInfo(
135
+ mintPubkey
136
+ );
137
+ const mintAccount = await getMint(
138
+ lavarageProgram.provider.connection,
139
+ mintPubkey,
140
+ "confirmed",
141
+ mintOwner?.owner
142
+ );
133
143
  instruction = createTransferCheckedInstruction(
134
- getAssociatedTokenAddressSync(mintPubkey, new PublicKey(params.funder), true, mintOwner?.owner),
144
+ getAssociatedTokenAddressSync(
145
+ mintPubkey,
146
+ new PublicKey(params.funder),
147
+ true,
148
+ mintOwner?.owner
149
+ ),
135
150
  new PublicKey(params.mint),
136
- getAssociatedTokenAddressSync(mintPubkey, new PublicKey(params.nodeWallet), true, mintOwner?.owner),
151
+ getAssociatedTokenAddressSync(
152
+ mintPubkey,
153
+ new PublicKey(params.nodeWallet),
154
+ true,
155
+ mintOwner?.owner
156
+ ),
137
157
  lavarageProgram.provider.publicKey!,
138
158
  params.amount,
139
159
  mintAccount.decimals,
@@ -262,45 +282,76 @@ export async function createOffer(
262
282
  params: {
263
283
  tradingPool: PublicKey;
264
284
  poolOwner: PublicKey;
265
- nodeWallet: string;
266
- mint?: string;
285
+ // the collateral mint
286
+ mint: string;
287
+ // the quote mint
288
+ quoteMint: string;
267
289
  interestRate: number;
268
290
  maxExposure: number;
269
291
  }
270
292
  ): Promise<VersionedTransaction> {
293
+
294
+ let nodeWalletAccount, nodeWalletSigner, createNodeWalletInstruction, nodeWalletPubKey;
295
+
296
+ if (params.mint === "So11111111111111111111111111111111111111112") {
297
+ const nodeWallets = await lavarageProgram.account.nodeWallet.all();
298
+ nodeWalletAccount = nodeWallets.find((wallet) =>
299
+ wallet.account.nodeOperator.equals(new PublicKey(params.poolOwner)),
300
+ );
301
+ } else {
302
+ const nodeWalletPda = getNodeWalletPDA(
303
+ new PublicKey(params.poolOwner),
304
+ new PublicKey(params.quoteMint),
305
+ lavarageProgram.programId
306
+ );
307
+ const nodeWalletAccountInfo = await lavarageProgram.provider.connection.getAccountInfo(nodeWalletPda);
308
+ if (nodeWalletAccountInfo) {
309
+ nodeWalletAccount = {
310
+ publicKey: nodeWalletPda,
311
+ };
312
+ }
313
+ }
271
314
 
272
- const nodeWalletAccount = await lavarageProgram.provider.connection.getAccountInfo(new PublicKey(params.nodeWallet));
273
- let nodeWalletSigner, createNodeWalletInstruction;
274
315
  if (!nodeWalletAccount) {
275
- // create node wallet
276
- const { instruction, nodeWallet } = await createNodeWallet(lavarageProgram, {
316
+ // Determine if this is V2 based on mint (SOL = V1, others = V2)
317
+ const isSOL = params.quoteMint === "So11111111111111111111111111111111111111112";
318
+
319
+ const {
320
+ instruction,
321
+ nodeWallet,
322
+ nodeWalletAccount: nodeWalletPublicKey,
323
+ } = await createNodeWallet(lavarageProgram, {
277
324
  operator: new PublicKey(params.poolOwner.toBase58()),
278
- mint: params.mint,
279
- liquidationLtv: 90,
325
+ mint: isSOL ? undefined : params.quoteMint, // Only pass mint for V2 (non-SOL)
326
+ liquidationLtv: isSOL ? undefined : 90, // Only pass liquidationLtv for V2 (non-SOL)
280
327
  });
281
328
  nodeWalletSigner = nodeWallet;
282
329
  createNodeWalletInstruction = instruction;
330
+ nodeWalletPubKey = nodeWalletPublicKey;
331
+ } else {
332
+ nodeWalletPubKey = nodeWalletAccount.publicKey;
283
333
  }
284
334
 
285
335
  const { blockhash } =
286
336
  await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
287
337
 
338
+ // Both V1 and V2 lpOperatorCreateTradingPool require mint parameter
288
339
  const instruction = await lavarageProgram.methods
289
340
  .lpOperatorCreateTradingPool(new BN(params.interestRate))
290
341
  .accounts({
291
342
  tradingPool: params.tradingPool,
292
343
  operator: params.poolOwner,
293
- nodeWallet: new PublicKey(params.nodeWallet),
294
- mint: params.mint ? new PublicKey(params.mint) : undefined,
344
+ nodeWallet: nodeWalletPubKey,
345
+ mint: new PublicKey(params.mint), // Always required for both V1 and V2
295
346
  systemProgram: SystemProgram.programId,
296
347
  })
297
348
  .instruction();
298
-
349
+
299
350
  const updateMaxExposureInstruction = await lavarageProgram.methods
300
351
  .lpOperatorUpdateMaxExposure(new BN(params.maxExposure))
301
352
  .accounts({
302
353
  tradingPool: params.tradingPool,
303
- nodeWallet: new PublicKey(params.nodeWallet),
354
+ nodeWallet: nodeWalletPubKey,
304
355
  operator: params.poolOwner,
305
356
  systemProgram: SystemProgram.programId,
306
357
  })
@@ -309,7 +360,14 @@ export async function createOffer(
309
360
  const messageV0 = new TransactionMessage({
310
361
  payerKey: lavarageProgram.provider.publicKey!,
311
362
  recentBlockhash: blockhash,
312
- instructions: [createNodeWalletInstruction === undefined ? null : createNodeWalletInstruction, instruction, updateMaxExposureInstruction, computeFeeIx].filter(Boolean) as TransactionInstruction[],
363
+ instructions: [
364
+ createNodeWalletInstruction === undefined
365
+ ? null
366
+ : createNodeWalletInstruction,
367
+ instruction,
368
+ updateMaxExposureInstruction,
369
+ computeFeeIx,
370
+ ].filter(Boolean) as TransactionInstruction[],
313
371
  }).compileToV0Message();
314
372
 
315
373
  if (nodeWalletSigner) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavarage/sdk",
3
- "version": "6.8.3",
3
+ "version": "6.8.5",
4
4
  "description": "Lavarage SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",