@lavarage/sdk 8.0.14 → 8.0.16

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "address": "F7L3T5fjHbD13SH8UhNuYxCdabHX9CRg2zxbPjmiwU7R",
2
+ "address": "FFe8xWs9iBdWB6vsxg8yBLirZHsbACFNbXqAM4K3fPPB",
3
3
  "metadata": {
4
4
  "name": "user_vault",
5
5
  "version": "0.1.0",
package/idl/userVault.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * IDL can be found at `target/idl/user_vault.json`.
6
6
  */
7
7
  export type UserVault = {
8
- "address": "F7L3T5fjHbD13SH8UhNuYxCdabHX9CRg2zxbPjmiwU7R",
8
+ "address": "FFe8xWs9iBdWB6vsxg8yBLirZHsbACFNbXqAM4K3fPPB",
9
9
  "metadata": {
10
10
  "name": "userVault",
11
11
  "version": "0.1.0",
package/index.ts CHANGED
@@ -57,7 +57,6 @@ type OptionalRPCResults = {
57
57
  tokenAccountConfirmCreatedAddresses?: PublicKey[];
58
58
  quoteMintAccountInfo?: AccountInfo<Buffer>;
59
59
  }
60
- const REFFERAL_VAULT_PROGRAM_ID = new PublicKey("FFe8xWs9iBdWB6vsxg8yBLirZHsbACFNbXqAM4K3fPPB");
61
60
 
62
61
  const LAVARAGE_LOOKUP_TABLE = "CDPmKb5VggsHABwDCTaxiw5XXLjcgkqSJMNKRTzHWXwK";
63
62
 
@@ -908,7 +907,7 @@ export const borrowV2 = async (
908
907
  * @param computeBudgetMicroLamports - Optional compute budget for priority fees
909
908
  * @param platformFeeRecipient - Optional wallet to receive platform fees (jup, okx)
910
909
  * @param splitTransactions - Optional boolean to split the transaction into multiple transactions (jito bundle)
911
- * @param discountBps - Optional discount basis points for the referral program
910
+ * @param discountBps - Optional discount basis points for the referral program and discount program
912
911
  * @param referralBps - Optional referral basis points for the referral program
913
912
  * @param optionalRPCResults - Optional RPC results to use for the transaction (speeds up the transaction building)
914
913
  *
@@ -1079,7 +1078,7 @@ export const openTradeV1 = async (
1079
1078
  const blockhash =
1080
1079
  optionalRPCResults?.latestBlockhash ?? (await lavarageProgram.provider.connection.getLatestBlockhash("finalized")).blockhash;
1081
1080
 
1082
- const useReferral = discountBps !== undefined && referralBps !== undefined;
1081
+ const shouldUseDiscountProgram = (discountBps !== undefined && discountBps > 0) || referralBps !== undefined;
1083
1082
 
1084
1083
  // Check if partner fee recipient vault needs to be initialized via referralVaultProgram
1085
1084
  let partnerFeeRecipientCreateIx: TransactionInstruction | undefined;
@@ -1104,13 +1103,13 @@ export const openTradeV1 = async (
1104
1103
  }
1105
1104
  }
1106
1105
 
1107
- const tradingOpenBorrowInstruction = useReferral
1106
+ const tradingOpenBorrowInstruction = shouldUseDiscountProgram
1108
1107
  ? await lavarageProgram.methods
1109
1108
  .tradingOpenBorrowWithReferral(
1110
1109
  new BN((marginSOL.toNumber() * leverage).toFixed(0)),
1111
1110
  marginSOL,
1112
- new BN(discountBps),
1113
- new BN(referralBps)
1111
+ new BN(discountBps || 0),
1112
+ new BN(referralBps || 0)
1114
1113
  )
1115
1114
  .accountsStrict({
1116
1115
  nodeWallet: offer.account.nodeWallet,
@@ -1284,7 +1283,7 @@ export const openTradeV1 = async (
1284
1283
  * @param computeBudgetMicroLamports - Optional compute budget for priority fees
1285
1284
  * @param platformFeeRecipient - Optional wallet to receive platform fees (jup, okx)
1286
1285
  * @param splitTransactions - Optional boolean to split the transaction into multiple transactions (jito bundle)
1287
- * @param discountBps - Optional discount basis points for the referral program
1286
+ * @param discountBps - Optional discount basis points for the referral program and discount program
1288
1287
  * @param referralBps - Optional referral basis points for the referral program
1289
1288
  * @param optionalRPCResults - Optional RPC results to use for the transaction (speeds up the transaction building)
1290
1289
  *
@@ -1472,7 +1471,7 @@ export const openTradeV2 = async (
1472
1471
  const { blockhash } =
1473
1472
  await program.provider.connection.getLatestBlockhash("finalized");
1474
1473
 
1475
- const useReferral = discountBps !== undefined && referralBps !== undefined;
1474
+ const shouldUseDiscountProgram = (discountBps !== undefined && discountBps > 0) || referralBps !== undefined;
1476
1475
 
1477
1476
  // Check if partner fee recipient vault and token account need to be created
1478
1477
  let partnerFeeRecipientVaultCreateIx: TransactionInstruction | undefined;
@@ -1547,13 +1546,14 @@ export const openTradeV2 = async (
1547
1546
  }
1548
1547
  }
1549
1548
 
1550
- const tradingOpenBorrowInstruction = useReferral
1549
+
1550
+ const tradingOpenBorrowInstruction = shouldUseDiscountProgram
1551
1551
  ? await program.methods
1552
1552
  .tradingOpenBorrow(
1553
1553
  new BN((marginSOL.toNumber() * leverage).toFixed(0)),
1554
1554
  marginSOL,
1555
- new BN(discountBps),
1556
- new BN(referralBps)
1555
+ new BN(discountBps || 0),
1556
+ new BN(referralBps || 0)
1557
1557
  )
1558
1558
  .accountsStrict({
1559
1559
  nodeWallet: offer.account.nodeWallet,
@@ -2194,7 +2194,7 @@ export const partialRepayV2 = async (
2194
2194
  * @param computeBudgetMicroLamports - Optional compute budget for priority fees
2195
2195
  * @param platformFeeRecipient - Optional wallet to receive platform fees (jup, okx)
2196
2196
  * @param splitTransactions - Optional boolean to split the transaction into multiple transactions (jito bundle)
2197
- * @param discountBps - Optional discount basis points for the referral program
2197
+ * @param discountBps - Optional discount basis points for the referral program and discount program
2198
2198
  * @param referralBps - Optional referral basis points for the referral program
2199
2199
  *
2200
2200
  * @returns Transaction to close the position
@@ -2337,7 +2337,7 @@ export const closeTradeV1 = async (
2337
2337
  const { blockhash } =
2338
2338
  await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2339
2339
 
2340
- const useReferral = discountBps !== undefined && referralBps !== undefined;
2340
+ const shouldUseDiscountProgram = (discountBps !== undefined && discountBps > 0) || referralBps !== undefined;
2341
2341
 
2342
2342
  // Check if partner fee recipient vault needs to be initialized via referralVaultProgram
2343
2343
  let partnerFeeRecipientCreateIx: TransactionInstruction | undefined;
@@ -2383,13 +2383,13 @@ export const closeTradeV1 = async (
2383
2383
  let repaySolIx: TransactionInstruction | null = null;
2384
2384
  let jupiterIxs: TransactionInstruction[] = [];
2385
2385
  if (jupInstruction.instructions == undefined) {
2386
- repaySolIx = useReferral
2386
+ repaySolIx = shouldUseDiscountProgram
2387
2387
  ? await lavarageProgram.methods
2388
2388
  .tradingCloseRepaySolWithReferral(
2389
2389
  new BN(jupInstruction.quoteResponse.outAmount),
2390
2390
  new BN(9997),
2391
- new BN(discountBps),
2392
- new BN(referralBps)
2391
+ new BN(discountBps || 0),
2392
+ new BN(referralBps || 0)
2393
2393
  )
2394
2394
  .accountsStrict({
2395
2395
  nodeWallet: pool.account.nodeWallet,
@@ -2446,13 +2446,13 @@ export const closeTradeV1 = async (
2446
2446
  )
2447
2447
  .instruction();
2448
2448
  } else {
2449
- repaySolIx = useReferral
2449
+ repaySolIx = shouldUseDiscountProgram
2450
2450
  ? await lavarageProgram.methods
2451
2451
  .tradingCloseRepaySolWithReferral(
2452
2452
  new BN(jupInstruction.quoteResponse.outAmount),
2453
2453
  new BN(9998),
2454
- new BN(discountBps),
2455
- new BN(referralBps)
2454
+ new BN(discountBps || 0),
2455
+ new BN(referralBps || 0)
2456
2456
  )
2457
2457
  .accountsStrict({
2458
2458
  nodeWallet: pool.account.nodeWallet,
@@ -2622,7 +2622,7 @@ export const closeTradeV1 = async (
2622
2622
  * @param computeBudgetMicroLamports - Optional compute budget for priority fees
2623
2623
  * @param platformFeeRecipient - Optional wallet to receive platform fees (jup, okx)
2624
2624
  * @param splitTransactions - Optional boolean to split the transaction into multiple transactions (jito bundle)
2625
- * @param discountBps - Optional discount basis points for the referral program
2625
+ * @param discountBps - Optional discount basis points for the referral program and discount program
2626
2626
  * @param referralBps - Optional referral basis points for the referral program
2627
2627
  *
2628
2628
  * @returns Transaction to close the position
@@ -2771,7 +2771,7 @@ export const closeTradeV2 = async (
2771
2771
  const { blockhash } =
2772
2772
  await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2773
2773
 
2774
- const useReferral = discountBps !== undefined && referralBps !== undefined;
2774
+ const shouldUseDiscountProgram = (discountBps !== undefined && discountBps > 0) || referralBps !== undefined;
2775
2775
 
2776
2776
  // Check if partner fee recipient vault and token account need to be created
2777
2777
  let partnerFeeRecipientVaultCreateIx: TransactionInstruction | undefined;
@@ -2846,13 +2846,13 @@ export const closeTradeV2 = async (
2846
2846
  let repaySolIx: TransactionInstruction | null = null;
2847
2847
  let jupiterIxs: TransactionInstruction[] = [];
2848
2848
  if (jupInstruction.instructions == undefined) {
2849
- repaySolIx = useReferral
2849
+ repaySolIx = shouldUseDiscountProgram
2850
2850
  ? await lavarageProgram.methods
2851
2851
  .tradingCloseRepaySol(
2852
2852
  new BN(jupInstruction.quoteResponse.outAmount),
2853
2853
  new BN(9997),
2854
- new BN(discountBps),
2855
- new BN(referralBps)
2854
+ new BN(discountBps || 0),
2855
+ new BN(referralBps || 0)
2856
2856
  )
2857
2857
  .accountsStrict({
2858
2858
  nodeWallet: pool.account.nodeWallet,
@@ -2959,13 +2959,13 @@ export const closeTradeV2 = async (
2959
2959
  )
2960
2960
  .instruction();
2961
2961
  } else {
2962
- repaySolIx = useReferral
2962
+ repaySolIx = shouldUseDiscountProgram
2963
2963
  ? await lavarageProgram.methods
2964
2964
  .tradingCloseRepaySol(
2965
2965
  new BN(jupInstruction.quoteResponse.outAmount),
2966
2966
  new BN(9998),
2967
- new BN(discountBps),
2968
- new BN(referralBps)
2967
+ new BN(discountBps || 0),
2968
+ new BN(referralBps || 0)
2969
2969
  )
2970
2970
  .accountsStrict({
2971
2971
  nodeWallet: pool.account.nodeWallet,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavarage/sdk",
3
- "version": "8.0.14",
3
+ "version": "8.0.16",
4
4
  "description": "Lavarage SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/utils.ts CHANGED
@@ -43,18 +43,12 @@ export function stringToU8Array(input: string): number[] {
43
43
  }
44
44
 
45
45
  export function u8ArrayToString(input: number[]): string {
46
- // Strip trailing zero-padding and decode
47
- const end = input.indexOf(0);
48
- const bytes = new Uint8Array(end === -1 ? input : input.slice(0, end));
49
- const decoder = new TextDecoder("utf-8", { fatal: true });
50
- try {
51
- return decoder.decode(bytes);
52
- } catch {
53
- // Not valid UTF-8 (e.g. raw binary/hash); return hex
54
- return '0x' + Array.from(bytes)
55
- .map((b) => b.toString(16).padStart(2, "0"))
56
- .join("");
46
+ // validate that input has no more than 32 bytes
47
+ if (input.length > 32) {
48
+ throw new Error('Input has more than 32 bytes');
57
49
  }
50
+
51
+ return '0x' + Buffer.from(input).toString('hex');
58
52
  }
59
53
 
60
54
  export function isSolProgram(program: Program<any>): boolean {