@lavarage/sdk 7.5.7 → 7.5.8

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 (84) hide show
  1. package/.DS_Store +0 -0
  2. package/dist/index.d.mts +147 -1
  3. package/dist/index.d.ts +147 -1
  4. package/dist/index.js +287 -3
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +287 -3
  7. package/dist/index.mjs.map +1 -1
  8. package/docs/.nojekyll +1 -0
  9. package/docs/assets/hierarchy.js +1 -0
  10. package/docs/assets/highlight.css +92 -0
  11. package/docs/assets/icons.js +18 -0
  12. package/docs/assets/icons.svg +1 -0
  13. package/docs/assets/main.js +60 -0
  14. package/docs/assets/navigation.js +1 -0
  15. package/docs/assets/search.js +1 -0
  16. package/docs/assets/style.css +1633 -0
  17. package/docs/functions/borrowV1.html +1 -0
  18. package/docs/functions/borrowV2.html +1 -0
  19. package/docs/functions/closePositionEvm.html +9 -0
  20. package/docs/functions/closeTradeV1.html +17 -0
  21. package/docs/functions/closeTradeV2.html +18 -0
  22. package/docs/functions/createTpDelegate.html +17 -0
  23. package/docs/functions/getActiveLoanCountEvm.html +8 -0
  24. package/docs/functions/getActiveLoansBatchEvm.html +10 -0
  25. package/docs/functions/getAllPositions.html +17 -0
  26. package/docs/functions/getAvailableExposureEvm.html +9 -0
  27. package/docs/functions/getClosedPositions.html +7 -0
  28. package/docs/functions/getClosedPositionsEvm.html +9 -0
  29. package/docs/functions/getCollateralExposureEvm.html +9 -0
  30. package/docs/functions/getCollateralInfoEvm.html +9 -0
  31. package/docs/functions/getDelegateAccounts.html +13 -0
  32. package/docs/functions/getLiquidatedPositions.html +13 -0
  33. package/docs/functions/getLiquidatedPositionsEvm.html +9 -0
  34. package/docs/functions/getLoanEvm.html +9 -0
  35. package/docs/functions/getLoansByBorrowerEvm.html +9 -0
  36. package/docs/functions/getOffers.html +7 -0
  37. package/docs/functions/getOffersEvm.html +9 -0
  38. package/docs/functions/getOpenPositions.html +11 -0
  39. package/docs/functions/getOpeningFeeEvm.html +8 -0
  40. package/docs/functions/getPda.html +8 -0
  41. package/docs/functions/getPositionAccountPDA.html +9 -0
  42. package/docs/functions/getPositionsEvm.html +8 -0
  43. package/docs/functions/getProfitFeeEvm.html +8 -0
  44. package/docs/functions/getTokenBalanceEvm.html +8 -0
  45. package/docs/functions/getUserLoansEvm.html +9 -0
  46. package/docs/functions/lending.addToWithdrawalAccessList.html +1 -0
  47. package/docs/functions/lending.createOffer.html +15 -0
  48. package/docs/functions/lending.depositFunds.html +17 -0
  49. package/docs/functions/lending.getNodeWalletPDA.html +9 -0
  50. package/docs/functions/lending.getTradingPoolPDA.html +9 -0
  51. package/docs/functions/lending.getWithdrawalAccessList.html +1 -0
  52. package/docs/functions/lending.getWithdrawalAccessListPDA.html +1 -0
  53. package/docs/functions/lending.removeFromWithdrawalAccessList.html +1 -0
  54. package/docs/functions/lending.updateInterestRate.html +13 -0
  55. package/docs/functions/lending.updateMaxBorrow.html +13 -0
  56. package/docs/functions/lending.updateMaxExposure.html +13 -0
  57. package/docs/functions/lending.updateOffer.html +19 -0
  58. package/docs/functions/lending.withdrawFunds.html +20 -0
  59. package/docs/functions/lending.withdrawFundsV1.html +16 -0
  60. package/docs/functions/lending.withdrawFundsV2.html +19 -0
  61. package/docs/functions/liquidatePositionEvm.html +6 -0
  62. package/docs/functions/mergePositionV2.html +13 -0
  63. package/docs/functions/modifyTpDelegate.html +17 -0
  64. package/docs/functions/openPositionEvm.html +9 -0
  65. package/docs/functions/openTradeV1.html +26 -0
  66. package/docs/functions/openTradeV2.html +29 -0
  67. package/docs/functions/partialRepayV1.html +10 -0
  68. package/docs/functions/partialRepayV2.html +10 -0
  69. package/docs/functions/removeTpDelegate.html +13 -0
  70. package/docs/functions/splitPositionV2.html +13 -0
  71. package/docs/functions/updateMaxLendPerTokenBatchEvm.html +9 -0
  72. package/docs/hierarchy.html +1 -0
  73. package/docs/index.html +3 -0
  74. package/docs/modules/IDLV2.html +2 -0
  75. package/docs/modules/lending.html +1 -0
  76. package/docs/modules.html +4 -0
  77. package/docs/types/IDLV2.Lavarage.html +8 -0
  78. package/docs/types/Lavarage.html +8 -0
  79. package/docs/variables/IDL.html +1 -0
  80. package/docs/variables/IDLV2.IDL.html +1 -0
  81. package/idl/lavarage.ts +126 -0
  82. package/idl/lavaragev2.ts +166 -0
  83. package/index.ts +282 -112
  84. package/package.json +2 -2
package/index.ts CHANGED
@@ -2464,8 +2464,12 @@ export const closeTradeV2 = async (
2464
2464
  computeBudgetMicroLamports?: number,
2465
2465
  platformFeeRecipient?: PublicKey,
2466
2466
  splitTransactions?: boolean,
2467
+ discountBps?: number,
2468
+ referralBps?: number,
2467
2469
  ) => {
2468
2470
  let partnerFeeMarkupAsPkey;
2471
+ const referralVaultProgram = new Program<UserVault>(userVaultIDL, REFFERAL_VAULT_PROGRAM_ID, lavarageProgram.provider);
2472
+
2469
2473
  if (partnerFeeMarkup) {
2470
2474
  const feeBuffer = Buffer.alloc(8);
2471
2475
  feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
@@ -2556,6 +2560,60 @@ export const closeTradeV2 = async (
2556
2560
  const { blockhash } =
2557
2561
  await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2558
2562
 
2563
+ const useReferral = discountBps !== undefined && referralBps !== undefined;
2564
+
2565
+ // Check if partner fee recipient vault and token account need to be created
2566
+ let partnerFeeRecipientVaultCreateIx: TransactionInstruction | undefined;
2567
+ let partnerFeeRecipientTokenAccountCreateIx: TransactionInstruction | undefined;
2568
+ let userVaultPda: PublicKey | undefined;
2569
+
2570
+ if (partnerFeeRecipient && partnerFeeMarkupAsPkey && referralVaultProgram) {
2571
+ // Derive the userVault PDA
2572
+ [userVaultPda] = PublicKey.findProgramAddressSync(
2573
+ [Buffer.from("user_vault"), new PublicKey(partnerFeeRecipient).toBuffer()],
2574
+ referralVaultProgram.programId
2575
+ );
2576
+
2577
+ // Get the vault's associated token account
2578
+ const vaultTokenAccount = getAssociatedTokenAddressSync(
2579
+ quoteToken,
2580
+ userVaultPda,
2581
+ true, // allowOwnerOffCurve for PDA
2582
+ quoteTokenProgram
2583
+ );
2584
+
2585
+ // Check both accounts at the same time
2586
+ const [vaultAccountInfo, vaultTokenAccountInfo] = await lavarageProgram.provider.connection.getMultipleAccountsInfo([
2587
+ userVaultPda,
2588
+ vaultTokenAccount
2589
+ ]);
2590
+
2591
+ // Create vault if it doesn't exist
2592
+ if (!vaultAccountInfo) {
2593
+ partnerFeeRecipientVaultCreateIx = await referralVaultProgram.methods
2594
+ .initializeVault()
2595
+ .accountsStrict({
2596
+ userVault: userVaultPda,
2597
+ user: partnerFeeRecipient!,
2598
+ funder: lavarageProgram.provider.publicKey!,
2599
+ systemProgram: SystemProgram.programId,
2600
+ })
2601
+ .instruction();
2602
+ }
2603
+
2604
+ // Create token account if it doesn't exist
2605
+ if (!vaultTokenAccountInfo) {
2606
+ partnerFeeRecipientTokenAccountCreateIx = createAssociatedTokenAccountIdempotentInstruction(
2607
+ lavarageProgram.provider.publicKey!,
2608
+ vaultTokenAccount,
2609
+ userVaultPda,
2610
+ quoteToken,
2611
+ quoteTokenProgram,
2612
+ ASSOCIATED_TOKEN_PROGRAM_ID
2613
+ );
2614
+ }
2615
+ }
2616
+
2559
2617
  const closePositionIx = await lavarageProgram.methods
2560
2618
  .tradingCloseBorrowCollateral()
2561
2619
  .accountsStrict({
@@ -2576,119 +2634,227 @@ export const closeTradeV2 = async (
2576
2634
  let repaySolIx: TransactionInstruction | null = null;
2577
2635
  let jupiterIxs: TransactionInstruction[] = [];
2578
2636
  if (jupInstruction.instructions == undefined) {
2579
- repaySolIx = await lavarageProgram.methods
2580
- .tradingCloseRepaySol(
2581
- new BN(jupInstruction.quoteResponse.outAmount),
2582
- new BN(9997)
2583
- )
2584
- .accountsStrict({
2585
- nodeWallet: pool.account.nodeWallet,
2586
- positionAccount: positionAccountPDA,
2587
- tradingPool: poolPubKey,
2588
- trader: lavarageProgram.provider.publicKey!,
2589
- systemProgram: SystemProgram.programId,
2590
- clock: SYSVAR_CLOCK_PUBKEY,
2591
- randomAccountAsId: position.account.seed,
2592
- feeTokenAccount: getAssociatedTokenAddressSync(
2593
- quoteToken,
2594
- new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
2595
- false,
2596
- quoteTokenProgram
2597
- ),
2598
- fromTokenAccount: getAssociatedTokenAddressSync(
2599
- quoteToken,
2600
- lavarageProgram.provider.publicKey!,
2601
- false,
2602
- quoteTokenProgram
2603
- ),
2604
- tokenProgram: quoteTokenProgram!,
2605
- toTokenAccount: getAssociatedTokenAddressSync(
2606
- quoteToken,
2607
- pool.account.nodeWallet,
2608
- true,
2609
- quoteTokenProgram
2610
- ),
2611
- mint: quoteToken,
2612
- })
2613
- .remainingAccounts(
2614
- partnerFeeRecipient && partnerFeeMarkupAsPkey
2615
- ? [
2616
- {
2617
- pubkey: getAssociatedTokenAddressSync(
2618
- quoteToken,
2619
- partnerFeeRecipient,
2620
- false,
2621
- quoteTokenProgram
2622
- ),
2623
- isSigner: false,
2624
- isWritable: true,
2625
- },
2626
- {
2627
- pubkey: partnerFeeMarkupAsPkey,
2628
- isSigner: false,
2629
- isWritable: false,
2630
- },
2631
- ]
2632
- : []
2633
- )
2634
- .instruction();
2637
+ repaySolIx = useReferral
2638
+ ? await lavarageProgram.methods
2639
+ .tradingCloseRepaySolWithReferral(
2640
+ new BN(jupInstruction.quoteResponse.outAmount),
2641
+ new BN(9997),
2642
+ new BN(discountBps),
2643
+ new BN(referralBps)
2644
+ )
2645
+ .accountsStrict({
2646
+ nodeWallet: pool.account.nodeWallet,
2647
+ positionAccount: positionAccountPDA,
2648
+ tradingPool: poolPubKey,
2649
+ trader: lavarageProgram.provider.publicKey!,
2650
+ systemProgram: SystemProgram.programId,
2651
+ clock: SYSVAR_CLOCK_PUBKEY,
2652
+ randomAccountAsId: position.account.seed,
2653
+ feeTokenAccount: getAssociatedTokenAddressSync(
2654
+ quoteToken,
2655
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
2656
+ false,
2657
+ quoteTokenProgram
2658
+ ),
2659
+ fromTokenAccount: getAssociatedTokenAddressSync(
2660
+ quoteToken,
2661
+ lavarageProgram.provider.publicKey!,
2662
+ false,
2663
+ quoteTokenProgram
2664
+ ),
2665
+ tokenProgram: quoteTokenProgram!,
2666
+ toTokenAccount: getAssociatedTokenAddressSync(
2667
+ quoteToken,
2668
+ pool.account.nodeWallet,
2669
+ true,
2670
+ quoteTokenProgram
2671
+ ),
2672
+ mint: quoteToken,
2673
+ })
2674
+ .remainingAccounts(
2675
+ partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda
2676
+ ? [
2677
+ {
2678
+ pubkey: getAssociatedTokenAddressSync(
2679
+ quoteToken,
2680
+ userVaultPda,
2681
+ true, // allowOwnerOffCurve for PDA
2682
+ quoteTokenProgram
2683
+ ),
2684
+ isSigner: false,
2685
+ isWritable: true,
2686
+ }
2687
+ ]
2688
+ : []
2689
+ )
2690
+ .instruction()
2691
+ : await lavarageProgram.methods
2692
+ .tradingCloseRepaySol(
2693
+ new BN(jupInstruction.quoteResponse.outAmount),
2694
+ new BN(9997)
2695
+ )
2696
+ .accountsStrict({
2697
+ nodeWallet: pool.account.nodeWallet,
2698
+ positionAccount: positionAccountPDA,
2699
+ tradingPool: poolPubKey,
2700
+ trader: lavarageProgram.provider.publicKey!,
2701
+ systemProgram: SystemProgram.programId,
2702
+ clock: SYSVAR_CLOCK_PUBKEY,
2703
+ randomAccountAsId: position.account.seed,
2704
+ feeTokenAccount: getAssociatedTokenAddressSync(
2705
+ quoteToken,
2706
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
2707
+ false,
2708
+ quoteTokenProgram
2709
+ ),
2710
+ fromTokenAccount: getAssociatedTokenAddressSync(
2711
+ quoteToken,
2712
+ lavarageProgram.provider.publicKey!,
2713
+ false,
2714
+ quoteTokenProgram
2715
+ ),
2716
+ tokenProgram: quoteTokenProgram!,
2717
+ toTokenAccount: getAssociatedTokenAddressSync(
2718
+ quoteToken,
2719
+ pool.account.nodeWallet,
2720
+ true,
2721
+ quoteTokenProgram
2722
+ ),
2723
+ mint: quoteToken,
2724
+ })
2725
+ .remainingAccounts(
2726
+ partnerFeeRecipient && partnerFeeMarkupAsPkey
2727
+ ? [
2728
+ {
2729
+ pubkey: getAssociatedTokenAddressSync(
2730
+ quoteToken,
2731
+ partnerFeeRecipient,
2732
+ false,
2733
+ quoteTokenProgram
2734
+ ),
2735
+ isSigner: false,
2736
+ isWritable: true,
2737
+ },
2738
+ {
2739
+ pubkey: partnerFeeMarkupAsPkey,
2740
+ isSigner: false,
2741
+ isWritable: false,
2742
+ },
2743
+ ]
2744
+ : []
2745
+ )
2746
+ .instruction();
2635
2747
  } else {
2636
- repaySolIx = await lavarageProgram.methods
2637
- .tradingCloseRepaySol(
2638
- new BN(jupInstruction.quoteResponse.outAmount),
2639
- new BN(9998)
2640
- )
2641
- .accountsStrict({
2642
- nodeWallet: pool.account.nodeWallet,
2643
- positionAccount: positionAccountPDA,
2644
- tradingPool: poolPubKey,
2645
- trader: lavarageProgram.provider.publicKey!,
2646
- systemProgram: SystemProgram.programId,
2647
- clock: SYSVAR_CLOCK_PUBKEY,
2648
- randomAccountAsId: position.account.seed,
2649
- feeTokenAccount: getAssociatedTokenAddressSync(
2650
- quoteToken,
2651
- new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
2652
- false,
2653
- quoteTokenProgram
2654
- ),
2655
- fromTokenAccount: getAssociatedTokenAddressSync(
2656
- quoteToken,
2657
- lavarageProgram.provider.publicKey!,
2658
- false,
2659
- quoteTokenProgram
2660
- ),
2661
- tokenProgram: quoteTokenProgram!,
2662
- toTokenAccount: getAssociatedTokenAddressSync(
2663
- quoteToken,
2664
- pool.account.nodeWallet,
2665
- true,
2666
- quoteTokenProgram
2667
- ),
2668
- mint: quoteToken,
2669
- })
2670
- .remainingAccounts(
2671
- partnerFeeRecipient && partnerFeeMarkupAsPkey
2672
- ? [
2673
- {
2674
- pubkey: getAssociatedTokenAddressSync(
2675
- quoteToken,
2676
- partnerFeeRecipient,
2677
- false,
2678
- quoteTokenProgram
2679
- ),
2680
- isSigner: false,
2681
- isWritable: true,
2682
- },
2683
- {
2684
- pubkey: partnerFeeMarkupAsPkey,
2685
- isSigner: false,
2686
- isWritable: false,
2687
- },
2688
- ]
2689
- : []
2690
- )
2691
- .instruction();
2748
+ repaySolIx = useReferral
2749
+ ? await lavarageProgram.methods
2750
+ .tradingCloseRepaySolWithReferral(
2751
+ new BN(jupInstruction.quoteResponse.outAmount),
2752
+ new BN(9998),
2753
+ new BN(discountBps),
2754
+ new BN(referralBps)
2755
+ )
2756
+ .accountsStrict({
2757
+ nodeWallet: pool.account.nodeWallet,
2758
+ positionAccount: positionAccountPDA,
2759
+ tradingPool: poolPubKey,
2760
+ trader: lavarageProgram.provider.publicKey!,
2761
+ systemProgram: SystemProgram.programId,
2762
+ clock: SYSVAR_CLOCK_PUBKEY,
2763
+ randomAccountAsId: position.account.seed,
2764
+ feeTokenAccount: getAssociatedTokenAddressSync(
2765
+ quoteToken,
2766
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
2767
+ false,
2768
+ quoteTokenProgram
2769
+ ),
2770
+ fromTokenAccount: getAssociatedTokenAddressSync(
2771
+ quoteToken,
2772
+ lavarageProgram.provider.publicKey!,
2773
+ false,
2774
+ quoteTokenProgram
2775
+ ),
2776
+ tokenProgram: quoteTokenProgram!,
2777
+ toTokenAccount: getAssociatedTokenAddressSync(
2778
+ quoteToken,
2779
+ pool.account.nodeWallet,
2780
+ true,
2781
+ quoteTokenProgram
2782
+ ),
2783
+ mint: quoteToken,
2784
+ })
2785
+ .remainingAccounts(
2786
+ partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda
2787
+ ? [
2788
+ {
2789
+ pubkey: getAssociatedTokenAddressSync(
2790
+ quoteToken,
2791
+ userVaultPda,
2792
+ true, // allowOwnerOffCurve for PDA
2793
+ quoteTokenProgram
2794
+ ),
2795
+ isSigner: false,
2796
+ isWritable: true,
2797
+ }
2798
+ ]
2799
+ : []
2800
+ )
2801
+ .instruction()
2802
+ : await lavarageProgram.methods
2803
+ .tradingCloseRepaySol(
2804
+ new BN(jupInstruction.quoteResponse.outAmount),
2805
+ new BN(9998)
2806
+ )
2807
+ .accountsStrict({
2808
+ nodeWallet: pool.account.nodeWallet,
2809
+ positionAccount: positionAccountPDA,
2810
+ tradingPool: poolPubKey,
2811
+ trader: lavarageProgram.provider.publicKey!,
2812
+ systemProgram: SystemProgram.programId,
2813
+ clock: SYSVAR_CLOCK_PUBKEY,
2814
+ randomAccountAsId: position.account.seed,
2815
+ feeTokenAccount: getAssociatedTokenAddressSync(
2816
+ quoteToken,
2817
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
2818
+ false,
2819
+ quoteTokenProgram
2820
+ ),
2821
+ fromTokenAccount: getAssociatedTokenAddressSync(
2822
+ quoteToken,
2823
+ lavarageProgram.provider.publicKey!,
2824
+ false,
2825
+ quoteTokenProgram
2826
+ ),
2827
+ tokenProgram: quoteTokenProgram!,
2828
+ toTokenAccount: getAssociatedTokenAddressSync(
2829
+ quoteToken,
2830
+ pool.account.nodeWallet,
2831
+ true,
2832
+ quoteTokenProgram
2833
+ ),
2834
+ mint: quoteToken,
2835
+ })
2836
+ .remainingAccounts(
2837
+ partnerFeeRecipient && partnerFeeMarkupAsPkey
2838
+ ? [
2839
+ {
2840
+ pubkey: getAssociatedTokenAddressSync(
2841
+ quoteToken,
2842
+ partnerFeeRecipient,
2843
+ false,
2844
+ quoteTokenProgram
2845
+ ),
2846
+ isSigner: false,
2847
+ isWritable: true,
2848
+ },
2849
+ {
2850
+ pubkey: partnerFeeMarkupAsPkey,
2851
+ isSigner: false,
2852
+ isWritable: false,
2853
+ },
2854
+ ]
2855
+ : []
2856
+ )
2857
+ .instruction();
2692
2858
  const {
2693
2859
  setupInstructions,
2694
2860
  swapInstruction: swapInstructionPayload,
@@ -2729,6 +2895,8 @@ export const closeTradeV2 = async (
2729
2895
 
2730
2896
  if (splitTransactions) {
2731
2897
  const setUpInstructions = [
2898
+ partnerFeeRecipientVaultCreateIx,
2899
+ partnerFeeRecipientTokenAccountCreateIx,
2732
2900
  jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
2733
2901
  createAssociatedTokenAccountInstruction,
2734
2902
  ].filter((i) => !!i);
@@ -2765,6 +2933,8 @@ export const closeTradeV2 = async (
2765
2933
  }
2766
2934
 
2767
2935
  const allInstructions = [
2936
+ partnerFeeRecipientVaultCreateIx,
2937
+ partnerFeeRecipientTokenAccountCreateIx,
2768
2938
  jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
2769
2939
  createAssociatedTokenAccountInstruction,
2770
2940
  jupInstruction.instructions?.tokenLedgerInstruction
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavarage/sdk",
3
- "version": "7.5.7",
3
+ "version": "7.5.8",
4
4
  "description": "Lavarage SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "tsup": "^8.2.4",
29
- "typedoc": "^0.28.12"
29
+ "typedoc": "^0.28.15"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"