@lavarage/sdk 7.5.21 → 8.0.1
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/constants.ts +6 -0
- package/crossbar.ts +53 -0
- package/dist/index.d.mts +5559 -1791
- package/dist/index.d.ts +5559 -1791
- package/dist/index.js +3502 -4975
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3301 -4772
- package/dist/index.mjs.map +1 -1
- package/docs/functions/borrowV1.html +1 -1
- package/docs/functions/borrowV2.html +1 -1
- package/docs/functions/closePositionEvm.html +2 -2
- package/docs/functions/closeTradeV1.html +2 -2
- package/docs/functions/closeTradeV2.html +2 -2
- package/docs/functions/createTpDelegate.html +2 -2
- package/docs/functions/getActiveLoanCountEvm.html +2 -2
- package/docs/functions/getActiveLoansBatchEvm.html +2 -2
- package/docs/functions/getAllPositions.html +2 -2
- package/docs/functions/getAvailableExposureEvm.html +2 -2
- package/docs/functions/getClosedPositions.html +2 -2
- package/docs/functions/getClosedPositionsEvm.html +2 -2
- package/docs/functions/getCollateralExposureEvm.html +2 -2
- package/docs/functions/getCollateralInfoEvm.html +2 -2
- package/docs/functions/getDelegateAccounts.html +2 -2
- package/docs/functions/getLiquidatedPositions.html +2 -2
- package/docs/functions/getLiquidatedPositionsEvm.html +2 -2
- package/docs/functions/getLoanEvm.html +2 -2
- package/docs/functions/getLoansByBorrowerEvm.html +2 -2
- package/docs/functions/getOffers.html +2 -2
- package/docs/functions/getOffersEvm.html +2 -2
- package/docs/functions/getOpenPositions.html +2 -2
- package/docs/functions/getOpeningFeeEvm.html +2 -2
- package/docs/functions/getPda.html +2 -2
- package/docs/functions/getPositionAccountPDA.html +2 -2
- package/docs/functions/getPositionsEvm.html +2 -2
- package/docs/functions/getProfitFeeEvm.html +2 -2
- package/docs/functions/getTokenBalanceEvm.html +2 -2
- package/docs/functions/getUserLoansEvm.html +2 -2
- package/docs/functions/lending.addToWithdrawalAccessList.html +1 -1
- package/docs/functions/lending.createOffer.html +2 -2
- package/docs/functions/lending.depositFunds.html +2 -2
- package/docs/functions/lending.getNodeWalletPDA.html +2 -2
- package/docs/functions/lending.getTradingPoolPDA.html +2 -2
- package/docs/functions/lending.getWithdrawalAccessList.html +1 -1
- package/docs/functions/lending.getWithdrawalAccessListPDA.html +1 -1
- package/docs/functions/lending.removeFromWithdrawalAccessList.html +1 -1
- package/docs/functions/lending.updateInterestRate.html +2 -2
- package/docs/functions/lending.updateMaxBorrow.html +2 -2
- package/docs/functions/lending.updateMaxExposure.html +2 -2
- package/docs/functions/lending.updateOffer.html +2 -2
- package/docs/functions/lending.withdrawFunds.html +2 -2
- package/docs/functions/lending.withdrawFundsV1.html +2 -2
- package/docs/functions/lending.withdrawFundsV2.html +2 -2
- package/docs/functions/liquidatePositionEvm.html +2 -2
- package/docs/functions/mergePositionV2.html +2 -2
- package/docs/functions/modifyTpDelegate.html +2 -2
- package/docs/functions/openPositionEvm.html +2 -2
- package/docs/functions/openTradeV1.html +2 -2
- package/docs/functions/openTradeV2.html +2 -2
- package/docs/functions/partialRepayV1.html +2 -2
- package/docs/functions/partialRepayV2.html +2 -2
- package/docs/functions/removeTpDelegate.html +2 -2
- package/docs/functions/splitPositionV2.html +2 -2
- package/docs/functions/updateMaxLendPerTokenBatchEvm.html +2 -2
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +2 -2
- package/docs/modules/IDLV2.html +2 -2
- package/docs/modules/lending.html +1 -1
- package/docs/modules.html +2 -2
- package/docs/types/IDLV2.Lavarage.html +2 -2
- package/docs/types/Lavarage.html +2 -2
- package/docs/variables/IDL.html +1 -1
- package/docs/variables/IDLV2.IDL.html +1 -1
- package/idl/lavarageSOL.json +1852 -0
- package/idl/lavarageSOL.ts +1858 -0
- package/idl/lavarageUSDC.json +5377 -0
- package/idl/lavarageUSDC.ts +5383 -0
- package/idl/userVault.json +244 -0
- package/idl/userVault.ts +250 -0
- package/index.ts +81 -42
- package/lending.ts +225 -86
- package/package.json +6 -4
- package/switchboard.ts +23 -0
- package/tsconfig.json +2 -1
- package/utils.ts +54 -0
- package/idl/lavarage.ts +0 -3465
- package/idl/lavaragev2.ts +0 -3791
- package/idl/referralVault.ts +0 -276
package/lending.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BN,
|
|
2
|
-
import { Lavarage } from "./idl/
|
|
3
|
-
import { Lavarage as
|
|
1
|
+
import { BN, Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { Lavarage as LavarageSOL } from "./idl/lavarageSOL";
|
|
3
|
+
import { Lavarage as LavarageUSDC } from "./idl/lavarageUSDC";
|
|
4
4
|
import {
|
|
5
5
|
ComputeBudgetProgram,
|
|
6
6
|
Keypair,
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getMint,
|
|
20
20
|
} from "@solana/spl-token";
|
|
21
21
|
import { getPda } from "./index";
|
|
22
|
+
import { isSolProgram } from "./utils";
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Derives a node wallet PDA for lending operations
|
|
@@ -104,7 +105,7 @@ export function getWithdrawalAccessListPDA(
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
async function createNodeWallet(
|
|
107
|
-
lavarageProgram: Program<
|
|
108
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
108
109
|
params: {
|
|
109
110
|
operator: PublicKey;
|
|
110
111
|
mint?: string; // Required for V2, optional for V1
|
|
@@ -129,12 +130,10 @@ async function createNodeWallet(
|
|
|
129
130
|
lavarageProgram.programId
|
|
130
131
|
);
|
|
131
132
|
// V2 version
|
|
132
|
-
instructions.push(await (lavarageProgram as Program<
|
|
133
|
+
instructions.push(await (lavarageProgram as Program<LavarageUSDC>).methods
|
|
133
134
|
.lpOperatorCreateNodeWallet(params.liquidationLtv)
|
|
134
135
|
.accounts({
|
|
135
|
-
nodeWallet: nodeWallet,
|
|
136
136
|
operator: new PublicKey(params.operator),
|
|
137
|
-
systemProgram: SystemProgram.programId,
|
|
138
137
|
mint: new PublicKey(params.mint),
|
|
139
138
|
})
|
|
140
139
|
.instruction());
|
|
@@ -160,7 +159,7 @@ async function createNodeWallet(
|
|
|
160
159
|
}));// Some code
|
|
161
160
|
|
|
162
161
|
// V1 version
|
|
163
|
-
instructions.push(await (lavarageProgram as Program<
|
|
162
|
+
instructions.push(await (lavarageProgram as Program<LavarageSOL>).methods
|
|
164
163
|
.lpOperatorCreateNodeWallet()
|
|
165
164
|
.accounts({
|
|
166
165
|
nodeWallet: auxAccountPubkey,
|
|
@@ -216,7 +215,7 @@ async function createNodeWallet(
|
|
|
216
215
|
* @see {@link withdrawFunds} - Unified withdraw function for both V1 and V2
|
|
217
216
|
*/
|
|
218
217
|
export async function depositFunds(
|
|
219
|
-
lavarageProgram: Program<
|
|
218
|
+
lavarageProgram: Program<LavarageSOL>,
|
|
220
219
|
params: {
|
|
221
220
|
nodeWallet: PublicKey;
|
|
222
221
|
mint?: string; // Required for V2, optional for V1
|
|
@@ -327,7 +326,7 @@ export async function depositFunds(
|
|
|
327
326
|
* @see {@link withdrawFunds} - Unified withdraw function for both V1 and V2
|
|
328
327
|
*/
|
|
329
328
|
export async function withdrawFundsV1(
|
|
330
|
-
lavarageProgram: Program<
|
|
329
|
+
lavarageProgram: Program<LavarageSOL>,
|
|
331
330
|
params: {
|
|
332
331
|
nodeWallet: PublicKey;
|
|
333
332
|
funder: PublicKey;
|
|
@@ -397,7 +396,7 @@ export async function withdrawFundsV1(
|
|
|
397
396
|
* @see {@link withdrawFunds} - Unified withdraw function for both V1 and V2
|
|
398
397
|
*/
|
|
399
398
|
export async function withdrawFundsV2(
|
|
400
|
-
lavarageProgram: Program<
|
|
399
|
+
lavarageProgram: Program<LavarageUSDC>,
|
|
401
400
|
params: {
|
|
402
401
|
nodeWallet: PublicKey;
|
|
403
402
|
funder: PublicKey;
|
|
@@ -489,7 +488,7 @@ export async function withdrawFundsV2(
|
|
|
489
488
|
*/
|
|
490
489
|
// Unified withdraw function that works with both V1 and V2
|
|
491
490
|
export async function withdrawFunds(
|
|
492
|
-
lavarageProgram: Program<
|
|
491
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
493
492
|
params: {
|
|
494
493
|
nodeWallet: PublicKey;
|
|
495
494
|
funder: PublicKey;
|
|
@@ -502,7 +501,7 @@ export async function withdrawFunds(
|
|
|
502
501
|
): Promise<VersionedTransaction> {
|
|
503
502
|
// Check if mint is provided to determine if this is V2
|
|
504
503
|
if (params.mint) {
|
|
505
|
-
return withdrawFundsV2(lavarageProgram as Program<
|
|
504
|
+
return withdrawFundsV2(lavarageProgram as Program<LavarageUSDC>, {
|
|
506
505
|
nodeWallet: params.nodeWallet,
|
|
507
506
|
funder: params.funder,
|
|
508
507
|
mint: params.mint,
|
|
@@ -512,7 +511,7 @@ export async function withdrawFunds(
|
|
|
512
511
|
computeBudgetMicroLamports: params.computeBudgetMicroLamports,
|
|
513
512
|
});
|
|
514
513
|
} else {
|
|
515
|
-
return withdrawFundsV1(lavarageProgram as Program<
|
|
514
|
+
return withdrawFundsV1(lavarageProgram as Program<LavarageSOL>, {
|
|
516
515
|
nodeWallet: params.nodeWallet,
|
|
517
516
|
funder: params.funder,
|
|
518
517
|
amount: params.amount,
|
|
@@ -554,7 +553,7 @@ export async function withdrawFunds(
|
|
|
554
553
|
* ```
|
|
555
554
|
*/
|
|
556
555
|
export async function createOffer(
|
|
557
|
-
lavarageProgram: Program<
|
|
556
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
558
557
|
params: {
|
|
559
558
|
tradingPool: PublicKey;
|
|
560
559
|
poolOwner: PublicKey;
|
|
@@ -566,6 +565,8 @@ export async function createOffer(
|
|
|
566
565
|
maxExposure: number;
|
|
567
566
|
computeBudgetMicroLamports?: number;
|
|
568
567
|
maxBorrow?: number;
|
|
568
|
+
openLtv?: number;
|
|
569
|
+
feedId?: string;
|
|
569
570
|
}
|
|
570
571
|
): Promise<VersionedTransaction> {
|
|
571
572
|
|
|
@@ -614,26 +615,47 @@ export async function createOffer(
|
|
|
614
615
|
await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
615
616
|
|
|
616
617
|
// Both V1 and V2 lpOperatorCreateTradingPool require mint parameter
|
|
617
|
-
const instruction =
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
618
|
+
const instruction = isSolProgram(lavarageProgram)
|
|
619
|
+
? await (lavarageProgram as Program<LavarageSOL>).methods
|
|
620
|
+
.lpOperatorCreateTradingPool(params.interestRate)
|
|
621
|
+
.accounts({
|
|
622
|
+
tradingPool: params.tradingPool,
|
|
623
|
+
operator: params.poolOwner,
|
|
624
|
+
nodeWallet: nodeWalletPubKey,
|
|
625
|
+
mint: new PublicKey(params.mint),
|
|
626
|
+
systemProgram: SystemProgram.programId,
|
|
627
|
+
})
|
|
628
|
+
.instruction()
|
|
629
|
+
: await (lavarageProgram as Program<LavarageUSDC>).methods
|
|
630
|
+
.lpOperatorCreateTradingPool({
|
|
631
|
+
interestRate: params.interestRate,
|
|
632
|
+
feedId: params.feedId,
|
|
633
|
+
openLtv: params.openLtv,
|
|
634
|
+
maxExposure: new BN(params.maxExposure),
|
|
635
|
+
})
|
|
636
|
+
.accounts({
|
|
637
|
+
operator: params.poolOwner,
|
|
638
|
+
nodeWallet: nodeWalletPubKey,
|
|
639
|
+
mint: new PublicKey(params.mint),
|
|
640
|
+
})
|
|
641
|
+
.instruction();
|
|
627
642
|
|
|
628
|
-
const updateMaxExposureInstruction =
|
|
629
|
-
|
|
643
|
+
const updateMaxExposureInstruction = isSolProgram(lavarageProgram)
|
|
644
|
+
? await (lavarageProgram as Program<LavarageSOL>).methods
|
|
645
|
+
.lpOperatorUpdateMaxExposure({
|
|
646
|
+
maxExposure: new BN(params.maxExposure),
|
|
647
|
+
interestRate: null,
|
|
648
|
+
openLtv: null,
|
|
649
|
+
feedId: null,
|
|
650
|
+
})
|
|
630
651
|
.accounts({
|
|
631
652
|
tradingPool: params.tradingPool,
|
|
632
653
|
nodeWallet: nodeWalletPubKey,
|
|
633
654
|
operator: params.poolOwner,
|
|
634
655
|
systemProgram: SystemProgram.programId,
|
|
635
656
|
})
|
|
636
|
-
.instruction()
|
|
657
|
+
.instruction()
|
|
658
|
+
: undefined;
|
|
637
659
|
|
|
638
660
|
const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
|
|
639
661
|
microLamports: params.computeBudgetMicroLamports ?? 150000,
|
|
@@ -645,15 +667,17 @@ export async function createOffer(
|
|
|
645
667
|
lamports: 0.3 * LAMPORTS_PER_SOL
|
|
646
668
|
});
|
|
647
669
|
|
|
648
|
-
const updateMaxBorrowInstruction =
|
|
649
|
-
|
|
670
|
+
const updateMaxBorrowInstruction = isSolProgram(lavarageProgram) && params.maxBorrow && params.maxBorrow > 0
|
|
671
|
+
? await (lavarageProgram as Program<LavarageSOL>).methods
|
|
672
|
+
.lpOperatorUpdateMaxBorrow(new BN(params.maxBorrow))
|
|
650
673
|
.accountsStrict({
|
|
651
674
|
tradingPool: params.tradingPool,
|
|
652
675
|
nodeWallet: nodeWalletPubKey,
|
|
653
676
|
operator: params.poolOwner,
|
|
654
677
|
systemProgram: SystemProgram.programId,
|
|
655
678
|
})
|
|
656
|
-
.instruction()
|
|
679
|
+
.instruction()
|
|
680
|
+
: undefined
|
|
657
681
|
|
|
658
682
|
const messageV0 = new TransactionMessage({
|
|
659
683
|
payerKey: lavarageProgram.provider.publicKey!,
|
|
@@ -662,7 +686,7 @@ export async function createOffer(
|
|
|
662
686
|
...createNodeWalletInstruction,
|
|
663
687
|
instruction,
|
|
664
688
|
updateMaxExposureInstruction,
|
|
665
|
-
|
|
689
|
+
updateMaxBorrowInstruction,
|
|
666
690
|
computeFeeIx,
|
|
667
691
|
].filter(Boolean) as TransactionInstruction[],
|
|
668
692
|
}).compileToV0Message();
|
|
@@ -699,7 +723,7 @@ export async function createOffer(
|
|
|
699
723
|
* ```
|
|
700
724
|
*/
|
|
701
725
|
export async function updateMaxExposure(
|
|
702
|
-
lavarageProgram: Program<
|
|
726
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
703
727
|
params: {
|
|
704
728
|
tradingPool: PublicKey;
|
|
705
729
|
nodeWallet: string;
|
|
@@ -711,15 +735,29 @@ export async function updateMaxExposure(
|
|
|
711
735
|
const { blockhash } =
|
|
712
736
|
await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
713
737
|
|
|
714
|
-
const instruction =
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
738
|
+
const instruction = isSolProgram(lavarageProgram)
|
|
739
|
+
? await (lavarageProgram as Program<LavarageSOL>).methods
|
|
740
|
+
.lpOperatorUpdateMaxExposure(new BN(params.maxExposure))
|
|
741
|
+
.accountsStrict({
|
|
742
|
+
tradingPool: params.tradingPool,
|
|
743
|
+
nodeWallet: new PublicKey(params.nodeWallet),
|
|
744
|
+
operator: params.poolOwner,
|
|
745
|
+
systemProgram: SystemProgram.programId,
|
|
746
|
+
})
|
|
747
|
+
.instruction()
|
|
748
|
+
: await (lavarageProgram as Program<LavarageUSDC>).methods
|
|
749
|
+
.lpOperatorUpdateTradingPool({
|
|
750
|
+
maxExposure: new BN(params.maxExposure),
|
|
751
|
+
interestRate: null,
|
|
752
|
+
openLtv: null,
|
|
753
|
+
feedId: null,
|
|
754
|
+
})
|
|
755
|
+
.accounts({
|
|
756
|
+
tradingPool: params.tradingPool,
|
|
757
|
+
nodeWallet: new PublicKey(params.nodeWallet),
|
|
758
|
+
operator: params.poolOwner,
|
|
759
|
+
})
|
|
760
|
+
.instruction();
|
|
723
761
|
|
|
724
762
|
const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
|
|
725
763
|
microLamports: params.computeBudgetMicroLamports ?? 150000,
|
|
@@ -763,7 +801,7 @@ export async function updateMaxExposure(
|
|
|
763
801
|
* ```
|
|
764
802
|
*/
|
|
765
803
|
export async function updateInterestRate(
|
|
766
|
-
lavarageProgram: Program<
|
|
804
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
767
805
|
params: {
|
|
768
806
|
tradingPool: PublicKey;
|
|
769
807
|
nodeWallet: string;
|
|
@@ -775,15 +813,29 @@ export async function updateInterestRate(
|
|
|
775
813
|
const { blockhash } =
|
|
776
814
|
await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
777
815
|
|
|
778
|
-
const instruction =
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
816
|
+
const instruction = isSolProgram(lavarageProgram)
|
|
817
|
+
? await (lavarageProgram as Program<LavarageSOL>).methods
|
|
818
|
+
.lpOperatorUpdateInterestRate(new BN(params.interestRate))
|
|
819
|
+
.accountsStrict({
|
|
820
|
+
tradingPool: params.tradingPool,
|
|
821
|
+
nodeWallet: new PublicKey(params.nodeWallet),
|
|
822
|
+
operator: params.poolOwner,
|
|
823
|
+
systemProgram: SystemProgram.programId,
|
|
824
|
+
})
|
|
825
|
+
.instruction()
|
|
826
|
+
: await (lavarageProgram as Program<LavarageUSDC>).methods
|
|
827
|
+
.lpOperatorUpdateTradingPool({
|
|
828
|
+
maxExposure: null,
|
|
829
|
+
interestRate: new BN(params.interestRate),
|
|
830
|
+
openLtv: null,
|
|
831
|
+
feedId: null,
|
|
832
|
+
})
|
|
833
|
+
.accounts({
|
|
834
|
+
tradingPool: params.tradingPool,
|
|
835
|
+
nodeWallet: new PublicKey(params.nodeWallet),
|
|
836
|
+
operator: params.poolOwner,
|
|
837
|
+
})
|
|
838
|
+
.instruction();
|
|
787
839
|
|
|
788
840
|
const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
|
|
789
841
|
microLamports: params.computeBudgetMicroLamports ?? 150000,
|
|
@@ -834,7 +886,7 @@ export async function updateInterestRate(
|
|
|
834
886
|
* @see {@link updateMaxExposure} - Update only max exposure
|
|
835
887
|
*/
|
|
836
888
|
export async function updateOffer(
|
|
837
|
-
lavarageProgram: Program<
|
|
889
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
838
890
|
params: {
|
|
839
891
|
tradingPool: PublicKey;
|
|
840
892
|
poolOwner: PublicKey;
|
|
@@ -867,35 +919,50 @@ export async function updateOffer(
|
|
|
867
919
|
// instructions.push(createPoolInstruction);
|
|
868
920
|
// }
|
|
869
921
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
922
|
+
if (isSolProgram(lavarageProgram)) {
|
|
923
|
+
instructions.push(
|
|
924
|
+
await (lavarageProgram as Program<LavarageSOL>).methods
|
|
925
|
+
.lpOperatorUpdateMaxExposure(new BN(params.maxExposure))
|
|
926
|
+
.accountsStrict({
|
|
927
|
+
tradingPool: params.tradingPool,
|
|
928
|
+
nodeWallet: new PublicKey(params.nodeWallet),
|
|
929
|
+
operator: params.poolOwner,
|
|
930
|
+
systemProgram: SystemProgram.programId,
|
|
931
|
+
})
|
|
932
|
+
.instruction(),
|
|
933
|
+
await (lavarageProgram as Program<LavarageSOL>).methods
|
|
934
|
+
.lpOperatorUpdateInterestRate(new BN(params.interestRate))
|
|
935
|
+
.accountsStrict({
|
|
936
|
+
tradingPool: params.tradingPool,
|
|
937
|
+
nodeWallet: new PublicKey(params.nodeWallet),
|
|
938
|
+
operator: params.poolOwner,
|
|
939
|
+
systemProgram: SystemProgram.programId,
|
|
940
|
+
})
|
|
941
|
+
.instruction()
|
|
942
|
+
);
|
|
943
|
+
} else {
|
|
944
|
+
instructions.push(
|
|
945
|
+
await (lavarageProgram as Program<LavarageUSDC>).methods
|
|
946
|
+
.lpOperatorUpdateTradingPool({
|
|
947
|
+
maxExposure: new BN(params.maxExposure),
|
|
948
|
+
interestRate: new BN(params.interestRate),
|
|
949
|
+
openLtv: null,
|
|
950
|
+
feedId: null,
|
|
951
|
+
})
|
|
952
|
+
.accounts({
|
|
953
|
+
tradingPool: params.tradingPool,
|
|
954
|
+
nodeWallet: new PublicKey(params.nodeWallet),
|
|
955
|
+
operator: params.poolOwner,
|
|
956
|
+
})
|
|
957
|
+
.instruction()
|
|
958
|
+
);
|
|
959
|
+
}
|
|
891
960
|
|
|
892
961
|
const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
|
|
893
962
|
microLamports: params.computeBudgetMicroLamports ?? 150000,
|
|
894
963
|
});
|
|
895
964
|
|
|
896
965
|
instructions.push(
|
|
897
|
-
updateMaxExposureInstruction,
|
|
898
|
-
updateInterestRateInstruction,
|
|
899
966
|
computeFeeIx
|
|
900
967
|
);
|
|
901
968
|
|
|
@@ -910,10 +977,10 @@ export async function updateOffer(
|
|
|
910
977
|
|
|
911
978
|
/**
|
|
912
979
|
* Updates the maximum borrow limit for a trading pool
|
|
913
|
-
*
|
|
980
|
+
*
|
|
914
981
|
* @group Lending
|
|
915
982
|
* @category Operations
|
|
916
|
-
*
|
|
983
|
+
*
|
|
917
984
|
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
918
985
|
* @param params - Update parameters
|
|
919
986
|
* @param params.tradingPool - The trading pool PDA
|
|
@@ -921,9 +988,9 @@ export async function updateOffer(
|
|
|
921
988
|
* @param params.oracle - The oracle public key authorized to update
|
|
922
989
|
* @param params.maxBorrow - New maximum borrow limit
|
|
923
990
|
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
924
|
-
*
|
|
991
|
+
*
|
|
925
992
|
* @returns Transaction to update max borrow limit
|
|
926
|
-
*
|
|
993
|
+
*
|
|
927
994
|
* @example
|
|
928
995
|
* ```typescript
|
|
929
996
|
* const tx = await updateMaxBorrow(lavarageProgram, {
|
|
@@ -932,12 +999,12 @@ export async function updateOffer(
|
|
|
932
999
|
* oracle: oraclePublicKey,
|
|
933
1000
|
* maxBorrow: 5000000
|
|
934
1001
|
* });
|
|
935
|
-
*
|
|
1002
|
+
*
|
|
936
1003
|
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
937
1004
|
* ```
|
|
938
1005
|
*/
|
|
939
1006
|
export async function updateMaxBorrow(
|
|
940
|
-
lavarageProgram: Program<
|
|
1007
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
941
1008
|
params: {
|
|
942
1009
|
tradingPool: PublicKey;
|
|
943
1010
|
nodeWallet: string;
|
|
@@ -946,10 +1013,14 @@ export async function updateMaxBorrow(
|
|
|
946
1013
|
computeBudgetMicroLamports?: number;
|
|
947
1014
|
}
|
|
948
1015
|
): Promise<VersionedTransaction> {
|
|
1016
|
+
if (!isSolProgram(lavarageProgram)) {
|
|
1017
|
+
throw new Error("updateMaxBorrow is only supported for the SOL program");
|
|
1018
|
+
}
|
|
1019
|
+
|
|
949
1020
|
const { blockhash } =
|
|
950
1021
|
await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
951
1022
|
|
|
952
|
-
const instruction = await lavarageProgram.methods
|
|
1023
|
+
const instruction = await (lavarageProgram as Program<LavarageSOL>).methods
|
|
953
1024
|
.lpOperatorUpdateMaxBorrow(new BN(params.maxBorrow))
|
|
954
1025
|
.accountsStrict({
|
|
955
1026
|
tradingPool: params.tradingPool,
|
|
@@ -972,8 +1043,76 @@ export async function updateMaxBorrow(
|
|
|
972
1043
|
return new VersionedTransaction(messageV0);
|
|
973
1044
|
}
|
|
974
1045
|
|
|
1046
|
+
/**
|
|
1047
|
+
* Updates the open LTV for a trading pool
|
|
1048
|
+
*
|
|
1049
|
+
* @group Lending
|
|
1050
|
+
* @category Operations
|
|
1051
|
+
*
|
|
1052
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
1053
|
+
* @param params - Update parameters
|
|
1054
|
+
* @param params.tradingPool - The trading pool PDA
|
|
1055
|
+
* @param params.nodeWallet - The node wallet address
|
|
1056
|
+
* @param params.oracle - The oracle public key authorized to update
|
|
1057
|
+
* @param params.openLtv - New open LTV
|
|
1058
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
1059
|
+
*
|
|
1060
|
+
* @returns Transaction to update open LTV
|
|
1061
|
+
*
|
|
1062
|
+
* @example
|
|
1063
|
+
* ```typescript
|
|
1064
|
+
* const tx = await updateOpenLtv(lavarageProgram, {
|
|
1065
|
+
* tradingPool: poolPDA,
|
|
1066
|
+
* nodeWallet: nodeWalletAddress,
|
|
1067
|
+
* oracle: oraclePublicKey,
|
|
1068
|
+
* openLtv: 7500
|
|
1069
|
+
* });
|
|
1070
|
+
*
|
|
1071
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
1072
|
+
* ```
|
|
1073
|
+
*/
|
|
1074
|
+
export async function updateOpenLtv(
|
|
1075
|
+
lavarageProgram: Program<LavarageUSDC>,
|
|
1076
|
+
params: {
|
|
1077
|
+
tradingPool: PublicKey;
|
|
1078
|
+
nodeWallet: string;
|
|
1079
|
+
oracle: PublicKey;
|
|
1080
|
+
openLtv: number;
|
|
1081
|
+
computeBudgetMicroLamports?: number;
|
|
1082
|
+
}
|
|
1083
|
+
): Promise<VersionedTransaction> {
|
|
1084
|
+
const { blockhash } =
|
|
1085
|
+
await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1086
|
+
|
|
1087
|
+
const instruction = await lavarageProgram.methods
|
|
1088
|
+
.lpOperatorUpdateTradingPool({
|
|
1089
|
+
maxExposure: null,
|
|
1090
|
+
interestRate: null,
|
|
1091
|
+
openLtv: new BN(params.openLtv),
|
|
1092
|
+
feedId: null,
|
|
1093
|
+
})
|
|
1094
|
+
.accounts({
|
|
1095
|
+
tradingPool: params.tradingPool,
|
|
1096
|
+
nodeWallet: new PublicKey(params.nodeWallet),
|
|
1097
|
+
operator: params.oracle,
|
|
1098
|
+
})
|
|
1099
|
+
.instruction();
|
|
1100
|
+
|
|
1101
|
+
const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
|
|
1102
|
+
microLamports: params.computeBudgetMicroLamports ?? 150000,
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
const messageV0 = new TransactionMessage({
|
|
1106
|
+
payerKey: lavarageProgram.provider.publicKey!,
|
|
1107
|
+
recentBlockhash: blockhash,
|
|
1108
|
+
instructions: [instruction, computeFeeIx],
|
|
1109
|
+
}).compileToV0Message();
|
|
1110
|
+
|
|
1111
|
+
return new VersionedTransaction(messageV0);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
975
1114
|
export async function addToWithdrawalAccessList(
|
|
976
|
-
lavarageProgram: Program<
|
|
1115
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
977
1116
|
params: {
|
|
978
1117
|
nodeWallet: PublicKey;
|
|
979
1118
|
authority: PublicKey;
|
|
@@ -1009,7 +1148,7 @@ export async function addToWithdrawalAccessList(
|
|
|
1009
1148
|
|
|
1010
1149
|
|
|
1011
1150
|
export async function removeFromWithdrawalAccessList(
|
|
1012
|
-
lavarageProgram: Program<
|
|
1151
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
1013
1152
|
params: {
|
|
1014
1153
|
authority: PublicKey;
|
|
1015
1154
|
nodeWallet: string; // This is a string in the IDL
|
|
@@ -1044,7 +1183,7 @@ export async function removeFromWithdrawalAccessList(
|
|
|
1044
1183
|
|
|
1045
1184
|
|
|
1046
1185
|
export async function getWithdrawalAccessList(
|
|
1047
|
-
lavarageProgram: Program<
|
|
1186
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
1048
1187
|
params: {
|
|
1049
1188
|
nodeWallet: string;
|
|
1050
1189
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lavarage/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "Lavarage SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -18,9 +18,11 @@
|
|
|
18
18
|
"author": "",
|
|
19
19
|
"license": "ISC",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@coral-xyz/anchor": "0.
|
|
22
|
-
"@solana/spl-token": "
|
|
23
|
-
"@solana/web3.js": "1.98.
|
|
21
|
+
"@coral-xyz/anchor": "0.32.1",
|
|
22
|
+
"@solana/spl-token": "^0.4.14",
|
|
23
|
+
"@solana/web3.js": "1.98.4",
|
|
24
|
+
"@switchboard-xyz/common": "^5.7.0",
|
|
25
|
+
"@switchboard-xyz/on-demand": "^3.9.0",
|
|
24
26
|
"bs58": "^6.0.0",
|
|
25
27
|
"ethers": "^6.13.5"
|
|
26
28
|
},
|
package/switchboard.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OracleQuote } from "@switchboard-xyz/on-demand";
|
|
2
|
+
import { queuePubkey } from "./constants";
|
|
3
|
+
import { PublicKey } from "@solana/web3.js";
|
|
4
|
+
import { SURGE_FEEDS } from "./crossbar";
|
|
5
|
+
|
|
6
|
+
export function getOracleQuoteForFeedId(feedId: string) {
|
|
7
|
+
const [oracleQuote] = OracleQuote.getCanonicalPubkey(
|
|
8
|
+
queuePubkey,
|
|
9
|
+
[feedId]
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
return oracleQuote;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getOracleQuoteForCollateralType(collateralType: PublicKey) {
|
|
16
|
+
const feed = SURGE_FEEDS.find(feed => feed.address === collateralType.toBase58());
|
|
17
|
+
|
|
18
|
+
if (!feed) {
|
|
19
|
+
throw new Error(`Quote feed not found for ${collateralType.toBase58()}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return getOracleQuoteForFeedId(feed.feedId);
|
|
23
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
|
|
104
104
|
/* Completeness */
|
|
105
105
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
106
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files.
|
|
106
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
|
|
107
|
+
"resolveJsonModule": true
|
|
107
108
|
}
|
|
108
109
|
}
|
package/utils.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import LavarageSOLIdl from "./idl/lavarageSOL.json";
|
|
3
|
+
|
|
4
|
+
export async function retryWithBackoff<T>(
|
|
5
|
+
fn: () => Promise<T>,
|
|
6
|
+
maxRetries: number = 5,
|
|
7
|
+
initialDelay: number = 1000,
|
|
8
|
+
): Promise<T> {
|
|
9
|
+
let lastError: any;
|
|
10
|
+
|
|
11
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
12
|
+
try {
|
|
13
|
+
return await fn();
|
|
14
|
+
} catch (error) {
|
|
15
|
+
lastError = error;
|
|
16
|
+
|
|
17
|
+
if (attempt < maxRetries - 1) {
|
|
18
|
+
// exponentially increase delay
|
|
19
|
+
const delay = initialDelay * Math.pow(2, attempt);
|
|
20
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
throw lastError;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function stringToU8Array(input: string): number[] {
|
|
29
|
+
const encoder = new TextEncoder();
|
|
30
|
+
const encoded = encoder.encode(input);
|
|
31
|
+
|
|
32
|
+
if (encoded.length > 32) {
|
|
33
|
+
throw new Error(`String too long: ${encoded.length} bytes (max 32)`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Create array of 32 zeros and fill with encoded bytes
|
|
37
|
+
const result = new Array(32).fill(0);
|
|
38
|
+
for (let i = 0; i < encoded.length; i++) {
|
|
39
|
+
result[i] = encoded[i];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
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
|
+
return new TextDecoder().decode(bytes);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function isSolProgram(program: Program<any>): boolean {
|
|
53
|
+
return program.programId.toBase58() === LavarageSOLIdl.address;
|
|
54
|
+
}
|