@lavarage/sdk 7.5.6 → 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.
- package/.DS_Store +0 -0
- package/.gitignore +18 -1
- package/README.md +33 -0
- package/dist/index.d.mts +1396 -1
- package/dist/index.d.ts +1396 -1
- package/dist/index.js +287 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +287 -3
- package/dist/index.mjs.map +1 -1
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1633 -0
- package/docs/functions/borrowV1.html +1 -0
- package/docs/functions/borrowV2.html +1 -0
- package/docs/functions/closePositionEvm.html +9 -0
- package/docs/functions/closeTradeV1.html +17 -0
- package/docs/functions/closeTradeV2.html +18 -0
- package/docs/functions/createTpDelegate.html +17 -0
- package/docs/functions/getActiveLoanCountEvm.html +8 -0
- package/docs/functions/getActiveLoansBatchEvm.html +10 -0
- package/docs/functions/getAllPositions.html +17 -0
- package/docs/functions/getAvailableExposureEvm.html +9 -0
- package/docs/functions/getClosedPositions.html +7 -0
- package/docs/functions/getClosedPositionsEvm.html +9 -0
- package/docs/functions/getCollateralExposureEvm.html +9 -0
- package/docs/functions/getCollateralInfoEvm.html +9 -0
- package/docs/functions/getDelegateAccounts.html +13 -0
- package/docs/functions/getLiquidatedPositions.html +13 -0
- package/docs/functions/getLiquidatedPositionsEvm.html +9 -0
- package/docs/functions/getLoanEvm.html +9 -0
- package/docs/functions/getLoansByBorrowerEvm.html +9 -0
- package/docs/functions/getOffers.html +7 -0
- package/docs/functions/getOffersEvm.html +9 -0
- package/docs/functions/getOpenPositions.html +11 -0
- package/docs/functions/getOpeningFeeEvm.html +8 -0
- package/docs/functions/getPda.html +8 -0
- package/docs/functions/getPositionAccountPDA.html +9 -0
- package/docs/functions/getPositionsEvm.html +8 -0
- package/docs/functions/getProfitFeeEvm.html +8 -0
- package/docs/functions/getTokenBalanceEvm.html +8 -0
- package/docs/functions/getUserLoansEvm.html +9 -0
- package/docs/functions/lending.addToWithdrawalAccessList.html +1 -0
- package/docs/functions/lending.createOffer.html +15 -0
- package/docs/functions/lending.depositFunds.html +17 -0
- package/docs/functions/lending.getNodeWalletPDA.html +9 -0
- package/docs/functions/lending.getTradingPoolPDA.html +9 -0
- package/docs/functions/lending.getWithdrawalAccessList.html +1 -0
- package/docs/functions/lending.getWithdrawalAccessListPDA.html +1 -0
- package/docs/functions/lending.removeFromWithdrawalAccessList.html +1 -0
- package/docs/functions/lending.updateInterestRate.html +13 -0
- package/docs/functions/lending.updateMaxBorrow.html +13 -0
- package/docs/functions/lending.updateMaxExposure.html +13 -0
- package/docs/functions/lending.updateOffer.html +19 -0
- package/docs/functions/lending.withdrawFunds.html +20 -0
- package/docs/functions/lending.withdrawFundsV1.html +16 -0
- package/docs/functions/lending.withdrawFundsV2.html +19 -0
- package/docs/functions/liquidatePositionEvm.html +6 -0
- package/docs/functions/mergePositionV2.html +13 -0
- package/docs/functions/modifyTpDelegate.html +17 -0
- package/docs/functions/openPositionEvm.html +9 -0
- package/docs/functions/openTradeV1.html +26 -0
- package/docs/functions/openTradeV2.html +29 -0
- package/docs/functions/partialRepayV1.html +10 -0
- package/docs/functions/partialRepayV2.html +10 -0
- package/docs/functions/removeTpDelegate.html +13 -0
- package/docs/functions/splitPositionV2.html +13 -0
- package/docs/functions/updateMaxLendPerTokenBatchEvm.html +9 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +3 -0
- package/docs/modules/IDLV2.html +2 -0
- package/docs/modules/lending.html +1 -0
- package/docs/modules.html +4 -0
- package/docs/types/IDLV2.Lavarage.html +8 -0
- package/docs/types/Lavarage.html +8 -0
- package/docs/variables/IDL.html +1 -0
- package/docs/variables/IDLV2.IDL.html +1 -0
- package/docs-readme.md +5 -0
- package/evm.ts +308 -0
- package/idl/lavarage.ts +126 -0
- package/idl/lavaragev2.ts +166 -0
- package/index.ts +924 -113
- package/lending.ts +330 -1
- package/package.json +8 -5
- package/typedoc.json +23 -0
package/dist/index.d.mts
CHANGED
|
@@ -692,6 +692,69 @@ type Lavarage$1 = {
|
|
|
692
692
|
}
|
|
693
693
|
];
|
|
694
694
|
},
|
|
695
|
+
{
|
|
696
|
+
"name": "tradingCloseRepaySolWithReferral";
|
|
697
|
+
"accounts": [
|
|
698
|
+
{
|
|
699
|
+
"name": "positionAccount";
|
|
700
|
+
"isMut": true;
|
|
701
|
+
"isSigner": false;
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
"name": "trader";
|
|
705
|
+
"isMut": true;
|
|
706
|
+
"isSigner": true;
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
"name": "tradingPool";
|
|
710
|
+
"isMut": true;
|
|
711
|
+
"isSigner": false;
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
"name": "nodeWallet";
|
|
715
|
+
"isMut": true;
|
|
716
|
+
"isSigner": false;
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
"name": "systemProgram";
|
|
720
|
+
"isMut": false;
|
|
721
|
+
"isSigner": false;
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
"name": "clock";
|
|
725
|
+
"isMut": false;
|
|
726
|
+
"isSigner": false;
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
"name": "randomAccountAsId";
|
|
730
|
+
"isMut": false;
|
|
731
|
+
"isSigner": false;
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
"name": "feeReceipient";
|
|
735
|
+
"isMut": true;
|
|
736
|
+
"isSigner": false;
|
|
737
|
+
}
|
|
738
|
+
];
|
|
739
|
+
"args": [
|
|
740
|
+
{
|
|
741
|
+
"name": "closingPositionSize";
|
|
742
|
+
"type": "u64";
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
"name": "closeType";
|
|
746
|
+
"type": "u64";
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
"name": "discountBps";
|
|
750
|
+
"type": "u64";
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
"name": "referralBps";
|
|
754
|
+
"type": "u64";
|
|
755
|
+
}
|
|
756
|
+
];
|
|
757
|
+
},
|
|
695
758
|
{
|
|
696
759
|
"name": "tradingClosePartialRepaySol";
|
|
697
760
|
"accounts": [
|
|
@@ -2371,6 +2434,89 @@ type Lavarage = {
|
|
|
2371
2434
|
}
|
|
2372
2435
|
];
|
|
2373
2436
|
},
|
|
2437
|
+
{
|
|
2438
|
+
"name": "tradingCloseRepaySolWithReferral";
|
|
2439
|
+
"accounts": [
|
|
2440
|
+
{
|
|
2441
|
+
"name": "positionAccount";
|
|
2442
|
+
"isMut": true;
|
|
2443
|
+
"isSigner": false;
|
|
2444
|
+
},
|
|
2445
|
+
{
|
|
2446
|
+
"name": "trader";
|
|
2447
|
+
"isMut": true;
|
|
2448
|
+
"isSigner": true;
|
|
2449
|
+
},
|
|
2450
|
+
{
|
|
2451
|
+
"name": "tradingPool";
|
|
2452
|
+
"isMut": true;
|
|
2453
|
+
"isSigner": false;
|
|
2454
|
+
},
|
|
2455
|
+
{
|
|
2456
|
+
"name": "nodeWallet";
|
|
2457
|
+
"isMut": true;
|
|
2458
|
+
"isSigner": false;
|
|
2459
|
+
},
|
|
2460
|
+
{
|
|
2461
|
+
"name": "systemProgram";
|
|
2462
|
+
"isMut": false;
|
|
2463
|
+
"isSigner": false;
|
|
2464
|
+
},
|
|
2465
|
+
{
|
|
2466
|
+
"name": "clock";
|
|
2467
|
+
"isMut": false;
|
|
2468
|
+
"isSigner": false;
|
|
2469
|
+
},
|
|
2470
|
+
{
|
|
2471
|
+
"name": "randomAccountAsId";
|
|
2472
|
+
"isMut": false;
|
|
2473
|
+
"isSigner": false;
|
|
2474
|
+
},
|
|
2475
|
+
{
|
|
2476
|
+
"name": "mint";
|
|
2477
|
+
"isMut": false;
|
|
2478
|
+
"isSigner": false;
|
|
2479
|
+
},
|
|
2480
|
+
{
|
|
2481
|
+
"name": "fromTokenAccount";
|
|
2482
|
+
"isMut": true;
|
|
2483
|
+
"isSigner": false;
|
|
2484
|
+
},
|
|
2485
|
+
{
|
|
2486
|
+
"name": "toTokenAccount";
|
|
2487
|
+
"isMut": true;
|
|
2488
|
+
"isSigner": false;
|
|
2489
|
+
},
|
|
2490
|
+
{
|
|
2491
|
+
"name": "feeTokenAccount";
|
|
2492
|
+
"isMut": true;
|
|
2493
|
+
"isSigner": false;
|
|
2494
|
+
},
|
|
2495
|
+
{
|
|
2496
|
+
"name": "tokenProgram";
|
|
2497
|
+
"isMut": false;
|
|
2498
|
+
"isSigner": false;
|
|
2499
|
+
}
|
|
2500
|
+
];
|
|
2501
|
+
"args": [
|
|
2502
|
+
{
|
|
2503
|
+
"name": "closingPositionSize";
|
|
2504
|
+
"type": "u64";
|
|
2505
|
+
},
|
|
2506
|
+
{
|
|
2507
|
+
"name": "closeType";
|
|
2508
|
+
"type": "u64";
|
|
2509
|
+
},
|
|
2510
|
+
{
|
|
2511
|
+
"name": "discountBps";
|
|
2512
|
+
"type": "u64";
|
|
2513
|
+
},
|
|
2514
|
+
{
|
|
2515
|
+
"name": "referralBps";
|
|
2516
|
+
"type": "u64";
|
|
2517
|
+
}
|
|
2518
|
+
];
|
|
2519
|
+
},
|
|
2374
2520
|
{
|
|
2375
2521
|
"name": "tradingPartialRepaySol";
|
|
2376
2522
|
"accounts": [
|
|
@@ -3479,10 +3625,30 @@ interface LiquidationEvent {
|
|
|
3479
3625
|
|
|
3480
3626
|
/**
|
|
3481
3627
|
* Creates an unsigned transaction to open a trading position on EVM chain
|
|
3628
|
+
* @group EVM
|
|
3629
|
+
* @category Trading
|
|
3482
3630
|
* @param provider - Ethers provider
|
|
3483
3631
|
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
3484
3632
|
* @param params - Trading parameters
|
|
3485
3633
|
* @returns Unsigned transaction object
|
|
3634
|
+
*
|
|
3635
|
+
* @example
|
|
3636
|
+
* ```typescript
|
|
3637
|
+
* const tx = await openPositionEvm(
|
|
3638
|
+
* provider,
|
|
3639
|
+
* "0x123...", // contract address
|
|
3640
|
+
* {
|
|
3641
|
+
* buyingCode: "0x...", // 1inch swap data
|
|
3642
|
+
* tokenCollateral: "0x456...", // USDC address
|
|
3643
|
+
* borrowAmount: ethers.parseEther("2"),
|
|
3644
|
+
* tokenHolder: "0x789...",
|
|
3645
|
+
* inchRouter: "0xabc...",
|
|
3646
|
+
* buyerContribution: ethers.parseEther("1") // 1 ETH margin
|
|
3647
|
+
* }
|
|
3648
|
+
* );
|
|
3649
|
+
*
|
|
3650
|
+
* const receipt = await signer.sendTransaction(tx);
|
|
3651
|
+
* ```
|
|
3486
3652
|
*/
|
|
3487
3653
|
declare const openPositionEvm: (provider: Provider, borrowerOpsContractAddress: string, { buyingCode, tokenCollateral, borrowAmount, tokenHolder, inchRouter, integratorFeeAddress, buyerContribution, tokenApproval, gasLimit, gasPrice, }: {
|
|
3488
3654
|
buyingCode: string;
|
|
@@ -3498,10 +3664,29 @@ declare const openPositionEvm: (provider: Provider, borrowerOpsContractAddress:
|
|
|
3498
3664
|
}) => Promise<ContractTransaction>;
|
|
3499
3665
|
/**
|
|
3500
3666
|
* Creates an unsigned transaction to close a trading position on EVM chain
|
|
3667
|
+
* @group EVM
|
|
3668
|
+
* @category Trading
|
|
3501
3669
|
* @param provider - Ethers provider
|
|
3502
3670
|
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
3503
3671
|
* @param params - Trading parameters
|
|
3504
3672
|
* @returns Unsigned transaction object
|
|
3673
|
+
*
|
|
3674
|
+
* @example
|
|
3675
|
+
* ```typescript
|
|
3676
|
+
* const tx = await closePositionEvm(
|
|
3677
|
+
* provider,
|
|
3678
|
+
* "0x123...", // contract address
|
|
3679
|
+
* {
|
|
3680
|
+
* loanId: 1,
|
|
3681
|
+
* sellingCode: "0x...", // 1inch swap data for selling
|
|
3682
|
+
* tokenHolder: "0x789...",
|
|
3683
|
+
* inchRouter: "0xabc...",
|
|
3684
|
+
* integratorFeeAddress: "0xdef..." // optional
|
|
3685
|
+
* }
|
|
3686
|
+
* );
|
|
3687
|
+
*
|
|
3688
|
+
* const receipt = await signer.sendTransaction(tx);
|
|
3689
|
+
* ```
|
|
3505
3690
|
*/
|
|
3506
3691
|
declare const closePositionEvm: (provider: Provider, borrowerOpsContractAddress: string, { loanId, sellingCode, tokenHolder, inchRouter, integratorFeeAddress, gasLimit, gasPrice, tokenApproval, }: {
|
|
3507
3692
|
loanId: BigNumberish;
|
|
@@ -3515,57 +3700,173 @@ declare const closePositionEvm: (provider: Provider, borrowerOpsContractAddress:
|
|
|
3515
3700
|
}) => Promise<ContractTransaction>;
|
|
3516
3701
|
/**
|
|
3517
3702
|
* Get all positions from active loans
|
|
3703
|
+
* @group EVM
|
|
3704
|
+
* @category Queries
|
|
3518
3705
|
* @param provider - Ethers provider
|
|
3519
3706
|
* @param tokenHolderContractAddress - TokenHolder contract address
|
|
3520
3707
|
* @returns Array of active positions
|
|
3708
|
+
*
|
|
3709
|
+
* @example
|
|
3710
|
+
* ```typescript
|
|
3711
|
+
* const positions = await getPositionsEvm(
|
|
3712
|
+
* provider,
|
|
3713
|
+
* "0x123..." // TokenHolder address
|
|
3714
|
+
* );
|
|
3715
|
+
*
|
|
3716
|
+
* console.log(`Found ${positions.length} active positions`);
|
|
3717
|
+
*
|
|
3718
|
+
* positions.forEach(pos => {
|
|
3719
|
+
* console.log(`Loan #${pos.loanId}: ${pos.collateralAmount} collateral`);
|
|
3720
|
+
* });
|
|
3721
|
+
* ```
|
|
3521
3722
|
*/
|
|
3522
3723
|
declare function getPositionsEvm(provider: Provider, tokenHolderContractAddress: string): Promise<BuyEvent[]>;
|
|
3523
3724
|
/**
|
|
3524
3725
|
* Get closed positions from events
|
|
3726
|
+
* @group EVM
|
|
3727
|
+
* @category Queries
|
|
3525
3728
|
* @param provider - Ethers provider
|
|
3526
3729
|
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
3527
3730
|
* @param fromBlock - Block to start searching from
|
|
3528
3731
|
* @returns Array of Sell events representing closed positions
|
|
3732
|
+
*
|
|
3733
|
+
* @example
|
|
3734
|
+
* ```typescript
|
|
3735
|
+
* const closedPositions = await getClosedPositionsEvm(
|
|
3736
|
+
* provider,
|
|
3737
|
+
* "0x123...", // BorrowerOps address
|
|
3738
|
+
* 50000000 // optional: custom start block
|
|
3739
|
+
* );
|
|
3740
|
+
*
|
|
3741
|
+
* console.log(`Found ${closedPositions.length} closed positions`);
|
|
3742
|
+
*
|
|
3743
|
+
* // Check profit/loss
|
|
3744
|
+
* closedPositions.forEach(pos => {
|
|
3745
|
+
* console.log(`Loan #${pos.loanId}: ${pos.profit > 0 ? 'Profit' : 'Loss'}`);
|
|
3746
|
+
* });
|
|
3529
3747
|
*/
|
|
3530
3748
|
declare function getClosedPositionsEvm(provider: Provider, borrowerOpsContractAddress: string, fromBlock?: number): Promise<SellEvent[]>;
|
|
3531
3749
|
/**
|
|
3532
3750
|
* Get liquidated positions from events
|
|
3751
|
+
* @group EVM
|
|
3752
|
+
* @category Queries
|
|
3533
3753
|
* @param provider - Ethers provider
|
|
3534
3754
|
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
3535
3755
|
* @param fromBlock - Block to start searching from
|
|
3536
3756
|
* @returns Array of Liquidation events representing liquidated positions
|
|
3757
|
+
* @example
|
|
3758
|
+
* ```typescript
|
|
3759
|
+
* const liquidations = await getLiquidatedPositionsEvm(
|
|
3760
|
+
* provider,
|
|
3761
|
+
* "0x123...", // BorrowerOps address
|
|
3762
|
+
* 50000000 // optional: custom start block
|
|
3763
|
+
* );
|
|
3764
|
+
*
|
|
3765
|
+
* console.log(`Found ${liquidations.length} liquidated positions`);
|
|
3766
|
+
*
|
|
3767
|
+
* // Analyze liquidation data
|
|
3768
|
+
* liquidations.forEach(liq => {
|
|
3769
|
+
* console.log(`Loan #${liq.loanId}: liquidated ${liq.closingPositionSize}`);
|
|
3770
|
+
* console.log(`Liquidator repaid: ${liq.liquidatorRepaidAmount}`);
|
|
3771
|
+
* });
|
|
3772
|
+
* ```
|
|
3537
3773
|
*/
|
|
3538
3774
|
declare function getLiquidatedPositionsEvm(provider: Provider, borrowerOpsContractAddress: string, fromBlock?: number): Promise<LiquidationEvent[]>;
|
|
3539
3775
|
/**
|
|
3540
3776
|
* Get a loan by its ID from TokenHolder contract
|
|
3777
|
+
* @group EVM
|
|
3778
|
+
* @category Queries
|
|
3541
3779
|
* @param provider - Ethers provider
|
|
3542
3780
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3543
3781
|
* @param loanId - ID of the loan to retrieve
|
|
3544
3782
|
* @returns Loan object
|
|
3783
|
+
*
|
|
3784
|
+
* @example
|
|
3785
|
+
* ```typescript
|
|
3786
|
+
* const loan = await getLoanEvm(
|
|
3787
|
+
* provider,
|
|
3788
|
+
* "0x123...", // TokenHolder address
|
|
3789
|
+
* 42 // loan ID
|
|
3790
|
+
* );
|
|
3791
|
+
*
|
|
3792
|
+
* console.log(`Loan #${loan.id}`);
|
|
3793
|
+
* console.log(`Borrower: ${loan.borrower}`);
|
|
3794
|
+
* console.log(`Amount: ${loan.amount}`);
|
|
3795
|
+
* console.log(`Collateral: ${loan.collateralAmount}`);
|
|
3796
|
+
* ```
|
|
3545
3797
|
*/
|
|
3546
3798
|
declare function getLoanEvm(provider: Provider, tokenHolderContractAddress: string, loanId: BigNumberish): Promise<Loan>;
|
|
3547
3799
|
/**
|
|
3548
3800
|
* Get all active loans for a user
|
|
3801
|
+
* @group EVM
|
|
3802
|
+
* @category Queries
|
|
3549
3803
|
* @param provider - Ethers provider
|
|
3550
3804
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3551
3805
|
* @param userAddress - Address of the user to get loans for
|
|
3552
3806
|
* @returns Array of loans belonging to the user
|
|
3807
|
+
*
|
|
3808
|
+
* @example
|
|
3809
|
+
* ```typescript
|
|
3810
|
+
* const userLoans = await getUserLoansEvm(
|
|
3811
|
+
* provider,
|
|
3812
|
+
* "0x123...", // TokenHolder address
|
|
3813
|
+
* "0x456..." // user address
|
|
3814
|
+
* );
|
|
3815
|
+
*
|
|
3816
|
+
* console.log(`User has ${userLoans.length} active loans`);
|
|
3817
|
+
*
|
|
3818
|
+
* userLoans.forEach(loan => {
|
|
3819
|
+
* console.log(`Loan #${loan.id}: ${loan.amount} borrowed`);
|
|
3820
|
+
* });
|
|
3821
|
+
* ```
|
|
3553
3822
|
*/
|
|
3554
3823
|
declare function getUserLoansEvm(provider: Provider, tokenHolderContractAddress: string, userAddress: string): Promise<Loan[]>;
|
|
3555
3824
|
/**
|
|
3556
3825
|
* Get collateral information for a specific token
|
|
3826
|
+
* @group EVM
|
|
3827
|
+
* @category Queries
|
|
3557
3828
|
* @param provider - Ethers provider
|
|
3558
3829
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3559
3830
|
* @param collateralAddress - Address of the collateral token
|
|
3560
3831
|
* @returns Collateral object
|
|
3832
|
+
*
|
|
3833
|
+
* @example
|
|
3834
|
+
* ```typescript
|
|
3835
|
+
* const collateralInfo = await getCollateralInfoEvm(
|
|
3836
|
+
* provider,
|
|
3837
|
+
* "0x123...", // TokenHolder address
|
|
3838
|
+
* "0x456..." // USDC or other collateral token address
|
|
3839
|
+
* );
|
|
3840
|
+
*
|
|
3841
|
+
* console.log(`Collateral: ${collateralInfo.symbol}`);
|
|
3842
|
+
* console.log(`Max LTV: ${collateralInfo.maxLTV}`);
|
|
3843
|
+
* console.log(`Liquidation threshold: ${collateralInfo.liquidationThreshold}`);
|
|
3844
|
+
* ```
|
|
3561
3845
|
*/
|
|
3562
3846
|
declare function getCollateralInfoEvm(provider: Provider, tokenHolderContractAddress: string, collateralAddress: string): Promise<Collateral>;
|
|
3563
3847
|
/**
|
|
3564
3848
|
* Get all available collateral information
|
|
3849
|
+
* @group EVM
|
|
3850
|
+
* @category Queries
|
|
3565
3851
|
* @param provider - Ethers provider
|
|
3566
3852
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3567
3853
|
* @param collateralAddresses - Array of collateral token addresses
|
|
3568
3854
|
* @returns Array of active collaterals
|
|
3855
|
+
*
|
|
3856
|
+
* @example
|
|
3857
|
+
* ```typescript
|
|
3858
|
+
* const collaterals = await getOffersEvm(
|
|
3859
|
+
* provider,
|
|
3860
|
+
* "0x123...", // TokenHolder address
|
|
3861
|
+
* ["0x456...", "0x789...", "0xabc..."] // token addresses to check
|
|
3862
|
+
* );
|
|
3863
|
+
*
|
|
3864
|
+
* console.log(`Found ${collaterals.length} available collaterals`);
|
|
3865
|
+
*
|
|
3866
|
+
* collaterals.forEach(({ address, collateral }) => {
|
|
3867
|
+
* console.log(`Token ${address}: LTV ${collateral.maxLTV}%`);
|
|
3868
|
+
* });
|
|
3869
|
+
* ```
|
|
3569
3870
|
*/
|
|
3570
3871
|
declare function getOffersEvm(provider: Provider, tokenHolderContractAddress: string, collateralAddresses: string[]): Promise<Array<{
|
|
3571
3872
|
address: string;
|
|
@@ -3573,63 +3874,196 @@ declare function getOffersEvm(provider: Provider, tokenHolderContractAddress: st
|
|
|
3573
3874
|
}>>;
|
|
3574
3875
|
/**
|
|
3575
3876
|
* Get the opening fee percentage
|
|
3877
|
+
* @group EVM
|
|
3878
|
+
* @category Queries
|
|
3576
3879
|
* @param provider - Ethers provider
|
|
3577
3880
|
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
3578
3881
|
* @returns Opening fee as a BigNumber
|
|
3882
|
+
*
|
|
3883
|
+
* @example
|
|
3884
|
+
* ```typescript
|
|
3885
|
+
* const openingFee = await getOpeningFeeEvm(
|
|
3886
|
+
* provider,
|
|
3887
|
+
* "0x123..." // BorrowerOps address
|
|
3888
|
+
* );
|
|
3889
|
+
*
|
|
3890
|
+
* // Convert to percentage (assuming 18 decimals)
|
|
3891
|
+
* const feePercent = Number(openingFee) / 1e16; // e.g., 0.5%
|
|
3892
|
+
* console.log(`Opening fee: ${feePercent}%`);
|
|
3893
|
+
* ```
|
|
3579
3894
|
*/
|
|
3580
3895
|
declare function getOpeningFeeEvm(provider: Provider, borrowerOpsContractAddress: string): Promise<bigint>;
|
|
3581
3896
|
/**
|
|
3582
3897
|
* Get the profit fee percentage
|
|
3898
|
+
* @group EVM
|
|
3899
|
+
* @category Queries
|
|
3583
3900
|
* @param provider - Ethers provider
|
|
3584
3901
|
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
3585
3902
|
* @returns Profit fee as a BigNumber
|
|
3903
|
+
*
|
|
3904
|
+
* @example
|
|
3905
|
+
* ```typescript
|
|
3906
|
+
* const profitFee = await getProfitFeeEvm(
|
|
3907
|
+
* provider,
|
|
3908
|
+
* "0x123..." // BorrowerOps address
|
|
3909
|
+
* );
|
|
3910
|
+
*
|
|
3911
|
+
* // Convert to percentage (assuming 18 decimals)
|
|
3912
|
+
* const feePercent = Number(profitFee) / 1e16; // e.g., 1%
|
|
3913
|
+
* console.log(`Profit fee: ${feePercent}%`);
|
|
3914
|
+
* ```
|
|
3586
3915
|
*/
|
|
3587
3916
|
declare function getProfitFeeEvm(provider: Provider, borrowerOpsContractAddress: string): Promise<bigint>;
|
|
3588
3917
|
/**
|
|
3589
3918
|
* Get the token balance of the token holder contract
|
|
3919
|
+
* @group EVM
|
|
3920
|
+
* @category Queries
|
|
3590
3921
|
* @param provider - Ethers provider
|
|
3591
3922
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3592
3923
|
* @returns Token balance as a BigNumber
|
|
3924
|
+
*
|
|
3925
|
+
* @example
|
|
3926
|
+
* ```typescript
|
|
3927
|
+
* const balance = await getTokenBalanceEvm(
|
|
3928
|
+
* provider,
|
|
3929
|
+
* "0x123..." // TokenHolder address
|
|
3930
|
+
* );
|
|
3931
|
+
*
|
|
3932
|
+
* // Format for display (assuming 18 decimals)
|
|
3933
|
+
* const formatted = ethers.formatEther(balance);
|
|
3934
|
+
* console.log(`Contract balance: ${formatted} ETH`);
|
|
3935
|
+
* ```
|
|
3593
3936
|
*/
|
|
3594
3937
|
declare function getTokenBalanceEvm(provider: Provider, tokenHolderContractAddress: string): Promise<bigint>;
|
|
3595
3938
|
/**
|
|
3596
3939
|
* Get the active loan count
|
|
3940
|
+
* @group EVM
|
|
3941
|
+
* @category Queries
|
|
3597
3942
|
* @param provider - Ethers provider
|
|
3598
3943
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3599
3944
|
* @returns Number of active loans
|
|
3945
|
+
*
|
|
3946
|
+
* @example
|
|
3947
|
+
* ```typescript
|
|
3948
|
+
* const loanCount = await getActiveLoanCountEvm(
|
|
3949
|
+
* provider,
|
|
3950
|
+
* "0x123..." // TokenHolder address
|
|
3951
|
+
* );
|
|
3952
|
+
*
|
|
3953
|
+
* console.log(`Total active loans: ${loanCount}`);
|
|
3954
|
+
*
|
|
3955
|
+
* // Use for statistics or monitoring
|
|
3956
|
+
* if (loanCount > 1000n) {
|
|
3957
|
+
* console.log("High activity detected");
|
|
3958
|
+
* }
|
|
3959
|
+
* ```
|
|
3600
3960
|
*/
|
|
3601
3961
|
declare function getActiveLoanCountEvm(provider: Provider, tokenHolderContractAddress: string): Promise<bigint>;
|
|
3602
3962
|
/**
|
|
3603
3963
|
* Get a batch of active loans
|
|
3964
|
+
* @group EVM
|
|
3965
|
+
* @category Queries
|
|
3604
3966
|
* @param provider - Ethers provider
|
|
3605
3967
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3606
3968
|
* @param startIndex - Starting index in the activeLoanIds array
|
|
3607
3969
|
* @param batchSize - Number of loans to retrieve
|
|
3608
3970
|
* @returns Array of active loans
|
|
3971
|
+
*
|
|
3972
|
+
* @example
|
|
3973
|
+
* ```typescript
|
|
3974
|
+
* const loans = await getActiveLoansBatchEvm(
|
|
3975
|
+
* provider,
|
|
3976
|
+
* "0x123...", // TokenHolder address
|
|
3977
|
+
* 0, // start from first loan
|
|
3978
|
+
* 100 // get 100 loans
|
|
3979
|
+
* );
|
|
3980
|
+
*
|
|
3981
|
+
* console.log(`Retrieved ${loans.length} loans`);
|
|
3982
|
+
*
|
|
3983
|
+
* // Process batch
|
|
3984
|
+
* loans.forEach(loan => {
|
|
3985
|
+
* console.log(`Loan #${loan.id}: ${loan.borrower}`);
|
|
3986
|
+
* });
|
|
3987
|
+
* ```
|
|
3609
3988
|
*/
|
|
3610
3989
|
declare function getActiveLoansBatchEvm(provider: Provider, tokenHolderContractAddress: string, startIndex: BigNumberish, batchSize: BigNumberish): Promise<Loan[]>;
|
|
3611
3990
|
/**
|
|
3612
3991
|
* Get all loans for a specific borrower
|
|
3992
|
+
* @group EVM
|
|
3993
|
+
* @category Queries
|
|
3613
3994
|
* @param provider - Ethers provider
|
|
3614
3995
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3615
3996
|
* @param borrowerAddress - Address of the borrower
|
|
3616
3997
|
* @returns Array of loans belonging to the borrower
|
|
3998
|
+
*
|
|
3999
|
+
* @example
|
|
4000
|
+
* ```typescript
|
|
4001
|
+
* const userLoans = await getLoansByBorrowerEvm(
|
|
4002
|
+
* provider,
|
|
4003
|
+
* "0x123...", // TokenHolder address
|
|
4004
|
+
* "0x456..." // borrower address
|
|
4005
|
+
* );
|
|
4006
|
+
*
|
|
4007
|
+
* console.log(`Borrower has ${userLoans.length} loans`);
|
|
4008
|
+
*
|
|
4009
|
+
* userLoans.forEach(loan => {
|
|
4010
|
+
* console.log(`Loan #${loan.id}: ${loan.collateralAmount} collateral`);
|
|
4011
|
+
* });
|
|
4012
|
+
* ```
|
|
3617
4013
|
*/
|
|
3618
4014
|
declare function getLoansByBorrowerEvm(provider: Provider, tokenHolderContractAddress: string, borrowerAddress: string): Promise<Loan[]>;
|
|
3619
4015
|
/**
|
|
3620
4016
|
* Get current exposure for a collateral
|
|
4017
|
+
* @group EVM
|
|
4018
|
+
* @category Queries
|
|
3621
4019
|
* @param provider - Ethers provider
|
|
3622
4020
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3623
4021
|
* @param collateralAddress - Address of the collateral token
|
|
3624
4022
|
* @returns Current exposure as a BigNumber
|
|
4023
|
+
*
|
|
4024
|
+
* @example
|
|
4025
|
+
* ```typescript
|
|
4026
|
+
* const exposure = await getCollateralExposureEvm(
|
|
4027
|
+
* provider,
|
|
4028
|
+
* "0x123...", // TokenHolder address
|
|
4029
|
+
* "0x456..." // collateral token address
|
|
4030
|
+
* );
|
|
4031
|
+
*
|
|
4032
|
+
* console.log(`Current exposure: ${ethers.formatEther(exposure)}`);
|
|
4033
|
+
*
|
|
4034
|
+
* // Check if near limit
|
|
4035
|
+
* const maxExposure = 1000000n;
|
|
4036
|
+
* if (exposure > maxExposure * 90n / 100n) {
|
|
4037
|
+
* console.log("Warning: 90% exposure reached");
|
|
4038
|
+
* }
|
|
4039
|
+
* ```
|
|
3625
4040
|
*/
|
|
3626
4041
|
declare function getCollateralExposureEvm(provider: Provider, tokenHolderContractAddress: string, collateralAddress: string): Promise<bigint>;
|
|
3627
4042
|
/**
|
|
3628
4043
|
* Get available exposure for a collateral
|
|
4044
|
+
* @group EVM
|
|
4045
|
+
* @category Queries
|
|
3629
4046
|
* @param provider - Ethers provider
|
|
3630
4047
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3631
4048
|
* @param collateralAddress - Address of the collateral token
|
|
3632
4049
|
* @returns Available exposure as a BigNumber
|
|
4050
|
+
*
|
|
4051
|
+
* @example
|
|
4052
|
+
* ```typescript
|
|
4053
|
+
* const available = await getAvailableExposureEvm(
|
|
4054
|
+
* provider,
|
|
4055
|
+
* "0x123...", // TokenHolder address
|
|
4056
|
+
* "0x456..." // collateral token address
|
|
4057
|
+
* );
|
|
4058
|
+
*
|
|
4059
|
+
* console.log(`Available exposure: ${ethers.formatEther(available)}`);
|
|
4060
|
+
*
|
|
4061
|
+
* // Check if can open new position
|
|
4062
|
+
* const newPositionSize = ethers.parseEther("10");
|
|
4063
|
+
* if (available >= newPositionSize) {
|
|
4064
|
+
* console.log("Sufficient exposure available");
|
|
4065
|
+
* }
|
|
4066
|
+
* ```
|
|
3633
4067
|
*/
|
|
3634
4068
|
declare function getAvailableExposureEvm(provider: Provider, tokenHolderContractAddress: string, collateralAddress: string): Promise<bigint>;
|
|
3635
4069
|
/**
|
|
@@ -3648,6 +4082,8 @@ declare const liquidatePositionEvm: (provider: Provider, borrowerOpsContractAddr
|
|
|
3648
4082
|
}) => Promise<ContractTransaction>;
|
|
3649
4083
|
/**
|
|
3650
4084
|
* Update max lend per token for multiple collaterals in batch
|
|
4085
|
+
* @group EVM
|
|
4086
|
+
* @category Operations
|
|
3651
4087
|
* @param provider - Ethers provider
|
|
3652
4088
|
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
3653
4089
|
* @param collateralAddresses - Array of collateral token addresses
|
|
@@ -3655,6 +4091,24 @@ declare const liquidatePositionEvm: (provider: Provider, borrowerOpsContractAddr
|
|
|
3655
4091
|
* @param gasLimit - Optional gas limit
|
|
3656
4092
|
* @param gasPrice - Optional gas price
|
|
3657
4093
|
* @returns Unsigned transaction object
|
|
4094
|
+
*
|
|
4095
|
+
* @example
|
|
4096
|
+
* ```typescript
|
|
4097
|
+
* const tx = await updateMaxLendPerTokenBatchEvm(
|
|
4098
|
+
* provider,
|
|
4099
|
+
* "0x123...", // TokenHolder address
|
|
4100
|
+
* {
|
|
4101
|
+
* collateralAddresses: ["0x456...", "0x789..."],
|
|
4102
|
+
* newMaxLendPerTokens: [
|
|
4103
|
+
* ethers.parseEther("1000"),
|
|
4104
|
+
* ethers.parseEther("500")
|
|
4105
|
+
* ]
|
|
4106
|
+
* }
|
|
4107
|
+
* );
|
|
4108
|
+
*
|
|
4109
|
+
* const receipt = await signer.sendTransaction(tx);
|
|
4110
|
+
* console.log("Max lend limits updated");
|
|
4111
|
+
* ```
|
|
3658
4112
|
*/
|
|
3659
4113
|
declare const updateMaxLendPerTokenBatchEvm: (provider: Provider, tokenHolderContractAddress: string, { collateralAddresses, newMaxLendPerTokens, gasLimit, gasPrice, }: {
|
|
3660
4114
|
collateralAddresses: string[];
|
|
@@ -3663,9 +4117,88 @@ declare const updateMaxLendPerTokenBatchEvm: (provider: Provider, tokenHolderCon
|
|
|
3663
4117
|
gasPrice?: string | number;
|
|
3664
4118
|
}) => Promise<ContractTransaction>;
|
|
3665
4119
|
|
|
4120
|
+
/**
|
|
4121
|
+
* Derives a node wallet PDA for lending operations
|
|
4122
|
+
*
|
|
4123
|
+
* @group Lending
|
|
4124
|
+
* @category Utilities
|
|
4125
|
+
*
|
|
4126
|
+
* @param operatorPublicKey - The operator's public key
|
|
4127
|
+
* @param mintPublicKey - The token mint public key
|
|
4128
|
+
* @param programId - The Lavarage program ID
|
|
4129
|
+
*
|
|
4130
|
+
* @returns The derived node wallet PDA
|
|
4131
|
+
*
|
|
4132
|
+
* @example
|
|
4133
|
+
* ```typescript
|
|
4134
|
+
* const nodeWallet = getNodeWalletPDA(
|
|
4135
|
+
* operatorPublicKey,
|
|
4136
|
+
* usdcMint,
|
|
4137
|
+
* programId
|
|
4138
|
+
* );
|
|
4139
|
+
* ```
|
|
4140
|
+
*/
|
|
3666
4141
|
declare function getNodeWalletPDA(operatorPublicKey: PublicKey, mintPublicKey: PublicKey, programId: PublicKey): PublicKey;
|
|
4142
|
+
/**
|
|
4143
|
+
* Derives a trading pool PDA for lending operations
|
|
4144
|
+
*
|
|
4145
|
+
* @group Lending
|
|
4146
|
+
* @category Utilities
|
|
4147
|
+
*
|
|
4148
|
+
* @param poolOwnerPublicKey - The pool owner's public key
|
|
4149
|
+
* @param tokenPublicKey - The token mint public key
|
|
4150
|
+
* @param programId - The Lavarage program ID
|
|
4151
|
+
*
|
|
4152
|
+
* @returns The derived trading pool PDA
|
|
4153
|
+
*
|
|
4154
|
+
* @example
|
|
4155
|
+
* ```typescript
|
|
4156
|
+
* const poolPDA = getTradingPoolPDA(
|
|
4157
|
+
* poolOwnerPublicKey,
|
|
4158
|
+
* usdcMint,
|
|
4159
|
+
* programId
|
|
4160
|
+
* );
|
|
4161
|
+
* ```
|
|
4162
|
+
*/
|
|
3667
4163
|
declare function getTradingPoolPDA(poolOwnerPublicKey: PublicKey, tokenPublicKey: PublicKey, programId: PublicKey): PublicKey;
|
|
3668
4164
|
declare function getWithdrawalAccessListPDA(programId: PublicKey): PublicKey;
|
|
4165
|
+
/**
|
|
4166
|
+
* Deposits funds into a node wallet for lending operations
|
|
4167
|
+
*
|
|
4168
|
+
* @group Lending
|
|
4169
|
+
* @category Operations
|
|
4170
|
+
*
|
|
4171
|
+
* @param lavarageProgram - The Lavarage V1 program instance
|
|
4172
|
+
* @param params - Deposit parameters
|
|
4173
|
+
* @param params.nodeWallet - The node wallet PDA to deposit into
|
|
4174
|
+
* @param params.mint - Token mint address (optional for V1 SOL deposits)
|
|
4175
|
+
* @param params.funder - The account providing the funds
|
|
4176
|
+
* @param params.amount - Amount to deposit (in lamports for SOL or token units)
|
|
4177
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4178
|
+
*
|
|
4179
|
+
* @returns Transaction to deposit funds
|
|
4180
|
+
*
|
|
4181
|
+
* @example
|
|
4182
|
+
* ```typescript
|
|
4183
|
+
* // Deposit SOL
|
|
4184
|
+
* const tx = await depositFunds(lavarageProgram, {
|
|
4185
|
+
* nodeWallet: nodeWalletPDA,
|
|
4186
|
+
* funder: lenderPublicKey,
|
|
4187
|
+
* amount: 1000000000 // 1 SOL
|
|
4188
|
+
* });
|
|
4189
|
+
*
|
|
4190
|
+
* // Deposit USDC
|
|
4191
|
+
* const tx = await depositFunds(lavarageProgram, {
|
|
4192
|
+
* nodeWallet: nodeWalletPDA,
|
|
4193
|
+
* mint: usdcMint.toString(),
|
|
4194
|
+
* funder: lenderPublicKey,
|
|
4195
|
+
* amount: 1000000 // 1 USDC (6 decimals)
|
|
4196
|
+
* });
|
|
4197
|
+
* ```
|
|
4198
|
+
*
|
|
4199
|
+
* @see {@link withdrawFundsV1} - Withdraw funds from a node wallet
|
|
4200
|
+
* @see {@link withdrawFunds} - Unified withdraw function for both V1 and V2
|
|
4201
|
+
*/
|
|
3669
4202
|
declare function depositFunds(lavarageProgram: Program<Lavarage$1>, params: {
|
|
3670
4203
|
nodeWallet: PublicKey;
|
|
3671
4204
|
mint?: string;
|
|
@@ -3673,12 +4206,73 @@ declare function depositFunds(lavarageProgram: Program<Lavarage$1>, params: {
|
|
|
3673
4206
|
amount: number;
|
|
3674
4207
|
computeBudgetMicroLamports?: number;
|
|
3675
4208
|
}): Promise<VersionedTransaction>;
|
|
4209
|
+
/**
|
|
4210
|
+
* Withdraws funds from a node wallet on Lavarage V1
|
|
4211
|
+
*
|
|
4212
|
+
* @group Lending
|
|
4213
|
+
* @category Operations
|
|
4214
|
+
*
|
|
4215
|
+
* @param lavarageProgram - The Lavarage V1 program instance
|
|
4216
|
+
* @param params - Withdrawal parameters
|
|
4217
|
+
* @param params.nodeWallet - The node wallet PDA to withdraw from
|
|
4218
|
+
* @param params.funder - The account receiving the withdrawn funds
|
|
4219
|
+
* @param params.amount - Amount to withdraw in lamports
|
|
4220
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4221
|
+
*
|
|
4222
|
+
* @returns Transaction to withdraw funds
|
|
4223
|
+
*
|
|
4224
|
+
* @example
|
|
4225
|
+
* ```typescript
|
|
4226
|
+
* const tx = await withdrawFundsV1(lavarageProgram, {
|
|
4227
|
+
* nodeWallet: nodeWalletPDA,
|
|
4228
|
+
* funder: lenderPublicKey,
|
|
4229
|
+
* amount: 1000000000 // 1 SOL
|
|
4230
|
+
* });
|
|
4231
|
+
*
|
|
4232
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
4233
|
+
* ```
|
|
4234
|
+
* @see {@link depositFunds} - Deposit funds into a node wallet
|
|
4235
|
+
* @see {@link withdrawFunds} - Unified withdraw function for both V1 and V2
|
|
4236
|
+
*/
|
|
3676
4237
|
declare function withdrawFundsV1(lavarageProgram: Program<Lavarage$1>, params: {
|
|
3677
4238
|
nodeWallet: PublicKey;
|
|
3678
4239
|
funder: PublicKey;
|
|
3679
4240
|
amount: number;
|
|
3680
4241
|
computeBudgetMicroLamports?: number;
|
|
3681
4242
|
}): Promise<VersionedTransaction>;
|
|
4243
|
+
/**
|
|
4244
|
+
* Withdraws funds from a node wallet on Lavarage V2
|
|
4245
|
+
*
|
|
4246
|
+
* @group Lending
|
|
4247
|
+
* @category Operations
|
|
4248
|
+
*
|
|
4249
|
+
* @param lavarageProgram - The Lavarage V2 program instance
|
|
4250
|
+
* @param params - Withdrawal parameters
|
|
4251
|
+
* @param params.nodeWallet - The node wallet PDA to withdraw from
|
|
4252
|
+
* @param params.funder - The account receiving the withdrawn funds
|
|
4253
|
+
* @param params.mint - Token mint address
|
|
4254
|
+
* @param params.amount - Amount to withdraw in token units
|
|
4255
|
+
* @param params.fromTokenAccount - Optional source token account (auto-derived if not provided)
|
|
4256
|
+
* @param params.toTokenAccount - Optional destination token account (auto-derived if not provided)
|
|
4257
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4258
|
+
*
|
|
4259
|
+
* @returns Transaction to withdraw funds
|
|
4260
|
+
*
|
|
4261
|
+
* @example
|
|
4262
|
+
* ```typescript
|
|
4263
|
+
* // Withdraw USDC
|
|
4264
|
+
* const tx = await withdrawFundsV2(lavarageProgram, {
|
|
4265
|
+
* nodeWallet: nodeWalletPDA,
|
|
4266
|
+
* funder: lenderPublicKey,
|
|
4267
|
+
* mint: usdcMint.toString(),
|
|
4268
|
+
* amount: 1000000 // 1 USDC (6 decimals)
|
|
4269
|
+
* });
|
|
4270
|
+
*
|
|
4271
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
4272
|
+
* ```
|
|
4273
|
+
* @see {@link depositFunds} - Deposit funds into a node wallet
|
|
4274
|
+
* @see {@link withdrawFunds} - Unified withdraw function for both V1 and V2
|
|
4275
|
+
*/
|
|
3682
4276
|
declare function withdrawFundsV2(lavarageProgram: Program<Lavarage>, params: {
|
|
3683
4277
|
nodeWallet: PublicKey;
|
|
3684
4278
|
funder: PublicKey;
|
|
@@ -3688,6 +4282,45 @@ declare function withdrawFundsV2(lavarageProgram: Program<Lavarage>, params: {
|
|
|
3688
4282
|
toTokenAccount?: PublicKey;
|
|
3689
4283
|
computeBudgetMicroLamports?: number;
|
|
3690
4284
|
}): Promise<VersionedTransaction>;
|
|
4285
|
+
/**
|
|
4286
|
+
* Withdraws funds from a node wallet (supports both V1 and V2)
|
|
4287
|
+
*
|
|
4288
|
+
* @group Lending
|
|
4289
|
+
* @category Operations
|
|
4290
|
+
*
|
|
4291
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4292
|
+
* @param params - Withdrawal parameters
|
|
4293
|
+
* @param params.nodeWallet - The node wallet PDA to withdraw from
|
|
4294
|
+
* @param params.funder - The account receiving the withdrawn funds
|
|
4295
|
+
* @param params.amount - Amount to withdraw
|
|
4296
|
+
* @param params.mint - Token mint address (required for V2, omit for V1 SOL withdrawal)
|
|
4297
|
+
* @param params.fromTokenAccount - Optional source token account (V2 only)
|
|
4298
|
+
* @param params.toTokenAccount - Optional destination token account (V2 only)
|
|
4299
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4300
|
+
*
|
|
4301
|
+
* @returns Transaction to withdraw funds
|
|
4302
|
+
*
|
|
4303
|
+
* @example
|
|
4304
|
+
* ```typescript
|
|
4305
|
+
* // V1: Withdraw SOL
|
|
4306
|
+
* const tx = await withdrawFunds(lavarageProgram, {
|
|
4307
|
+
* nodeWallet: nodeWalletPDA,
|
|
4308
|
+
* funder: lenderPublicKey,
|
|
4309
|
+
* amount: 1000000000 // 1 SOL
|
|
4310
|
+
* });
|
|
4311
|
+
*
|
|
4312
|
+
* // V2: Withdraw USDC
|
|
4313
|
+
* const tx = await withdrawFunds(lavarageProgram, {
|
|
4314
|
+
* nodeWallet: nodeWalletPDA,
|
|
4315
|
+
* funder: lenderPublicKey,
|
|
4316
|
+
* mint: usdcMint.toString(),
|
|
4317
|
+
* amount: 1000000 // 1 USDC
|
|
4318
|
+
* });
|
|
4319
|
+
* ```
|
|
4320
|
+
* @see {@link depositFunds} - Deposit funds into a node wallet
|
|
4321
|
+
* @see {@link withdrawFundsV1} - V1 specific implementation
|
|
4322
|
+
* @see {@link withdrawFundsV2} - V2 specific implementation
|
|
4323
|
+
*/
|
|
3691
4324
|
declare function withdrawFunds(lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, params: {
|
|
3692
4325
|
nodeWallet: PublicKey;
|
|
3693
4326
|
funder: PublicKey;
|
|
@@ -3697,6 +4330,38 @@ declare function withdrawFunds(lavarageProgram: Program<Lavarage$1> | Program<La
|
|
|
3697
4330
|
toTokenAccount?: PublicKey;
|
|
3698
4331
|
computeBudgetMicroLamports?: number;
|
|
3699
4332
|
}): Promise<VersionedTransaction>;
|
|
4333
|
+
/**
|
|
4334
|
+
* Creates a lending offer/pool on Lavarage
|
|
4335
|
+
*
|
|
4336
|
+
* @group Lending
|
|
4337
|
+
* @category Operations
|
|
4338
|
+
*
|
|
4339
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4340
|
+
* @param params - Offer creation parameters
|
|
4341
|
+
* @param params.tradingPool - The trading pool PDA
|
|
4342
|
+
* @param params.poolOwner - The pool owner's public key
|
|
4343
|
+
* @param params.mint - The collateral token mint address
|
|
4344
|
+
* @param params.quoteMint - The quote token mint address
|
|
4345
|
+
* @param params.interestRate - Interest rate for the pool
|
|
4346
|
+
* @param params.maxExposure - Maximum exposure limit
|
|
4347
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4348
|
+
*
|
|
4349
|
+
* @returns Transaction to create the offer
|
|
4350
|
+
*
|
|
4351
|
+
* @example
|
|
4352
|
+
* ```typescript
|
|
4353
|
+
* const tx = await createOffer(lavarageProgram, {
|
|
4354
|
+
* tradingPool: poolPDA,
|
|
4355
|
+
* poolOwner: lenderPublicKey,
|
|
4356
|
+
* mint: collateralMint.toString(),
|
|
4357
|
+
* quoteMint: usdcMint.toString(),
|
|
4358
|
+
* interestRate: 500, // 5%
|
|
4359
|
+
* maxExposure: 1000000
|
|
4360
|
+
* });
|
|
4361
|
+
*
|
|
4362
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
4363
|
+
* ```
|
|
4364
|
+
*/
|
|
3700
4365
|
declare function createOffer(lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, params: {
|
|
3701
4366
|
tradingPool: PublicKey;
|
|
3702
4367
|
poolOwner: PublicKey;
|
|
@@ -3707,6 +4372,34 @@ declare function createOffer(lavarageProgram: Program<Lavarage$1> | Program<Lava
|
|
|
3707
4372
|
computeBudgetMicroLamports?: number;
|
|
3708
4373
|
maxBorrow?: number;
|
|
3709
4374
|
}): Promise<VersionedTransaction>;
|
|
4375
|
+
/**
|
|
4376
|
+
* Updates the maximum exposure limit for a trading pool
|
|
4377
|
+
*
|
|
4378
|
+
* @group Lending
|
|
4379
|
+
* @category Operations
|
|
4380
|
+
*
|
|
4381
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4382
|
+
* @param params - Update parameters
|
|
4383
|
+
* @param params.tradingPool - The trading pool PDA
|
|
4384
|
+
* @param params.nodeWallet - The node wallet address
|
|
4385
|
+
* @param params.poolOwner - The pool owner's public key
|
|
4386
|
+
* @param params.maxExposure - New maximum exposure limit
|
|
4387
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4388
|
+
*
|
|
4389
|
+
* @returns Transaction to update max exposure
|
|
4390
|
+
*
|
|
4391
|
+
* @example
|
|
4392
|
+
* ```typescript
|
|
4393
|
+
* const tx = await updateMaxExposure(lavarageProgram, {
|
|
4394
|
+
* tradingPool: poolPDA,
|
|
4395
|
+
* nodeWallet: nodeWalletAddress,
|
|
4396
|
+
* poolOwner: lenderPublicKey,
|
|
4397
|
+
* maxExposure: 2000000 // New limit
|
|
4398
|
+
* });
|
|
4399
|
+
*
|
|
4400
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
4401
|
+
* ```
|
|
4402
|
+
*/
|
|
3710
4403
|
declare function updateMaxExposure(lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, params: {
|
|
3711
4404
|
tradingPool: PublicKey;
|
|
3712
4405
|
nodeWallet: string;
|
|
@@ -3714,6 +4407,34 @@ declare function updateMaxExposure(lavarageProgram: Program<Lavarage$1> | Progra
|
|
|
3714
4407
|
maxExposure: number;
|
|
3715
4408
|
computeBudgetMicroLamports?: number;
|
|
3716
4409
|
}): Promise<VersionedTransaction>;
|
|
4410
|
+
/**
|
|
4411
|
+
* Updates the interest rate for a trading pool
|
|
4412
|
+
*
|
|
4413
|
+
* @group Lending
|
|
4414
|
+
* @category Operations
|
|
4415
|
+
*
|
|
4416
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4417
|
+
* @param params - Update parameters
|
|
4418
|
+
* @param params.tradingPool - The trading pool PDA
|
|
4419
|
+
* @param params.nodeWallet - The node wallet address
|
|
4420
|
+
* @param params.poolOwner - The pool owner's public key
|
|
4421
|
+
* @param params.interestRate - New interest rate
|
|
4422
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4423
|
+
*
|
|
4424
|
+
* @returns Transaction to update interest rate
|
|
4425
|
+
*
|
|
4426
|
+
* @example
|
|
4427
|
+
* ```typescript
|
|
4428
|
+
* const tx = await updateInterestRate(lavarageProgram, {
|
|
4429
|
+
* tradingPool: poolPDA,
|
|
4430
|
+
* nodeWallet: nodeWalletAddress,
|
|
4431
|
+
* poolOwner: lenderPublicKey,
|
|
4432
|
+
* interestRate: 750 // 7.5%
|
|
4433
|
+
* });
|
|
4434
|
+
*
|
|
4435
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
4436
|
+
* ```
|
|
4437
|
+
*/
|
|
3717
4438
|
declare function updateInterestRate(lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, params: {
|
|
3718
4439
|
tradingPool: PublicKey;
|
|
3719
4440
|
nodeWallet: string;
|
|
@@ -3721,6 +4442,41 @@ declare function updateInterestRate(lavarageProgram: Program<Lavarage$1> | Progr
|
|
|
3721
4442
|
interestRate: number;
|
|
3722
4443
|
computeBudgetMicroLamports?: number;
|
|
3723
4444
|
}): Promise<VersionedTransaction>;
|
|
4445
|
+
/**
|
|
4446
|
+
* Updates multiple parameters of a trading pool in a single transaction
|
|
4447
|
+
*
|
|
4448
|
+
* @group Lending
|
|
4449
|
+
* @category Operations
|
|
4450
|
+
*
|
|
4451
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4452
|
+
* @param params - Update parameters
|
|
4453
|
+
* @param params.tradingPool - The trading pool PDA
|
|
4454
|
+
* @param params.poolOwner - The pool owner's public key
|
|
4455
|
+
* @param params.nodeWallet - The node wallet address
|
|
4456
|
+
* @param params.mint - The token mint address
|
|
4457
|
+
* @param params.interestRate - New interest rate
|
|
4458
|
+
* @param params.maxExposure - New maximum exposure limit
|
|
4459
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4460
|
+
*
|
|
4461
|
+
* @returns Transaction to update pool parameters
|
|
4462
|
+
*
|
|
4463
|
+
* @example
|
|
4464
|
+
* ```typescript
|
|
4465
|
+
* const tx = await updateOffer(lavarageProgram, {
|
|
4466
|
+
* tradingPool: poolPDA,
|
|
4467
|
+
* poolOwner: lenderPublicKey,
|
|
4468
|
+
* nodeWallet: nodeWalletAddress,
|
|
4469
|
+
* mint: collateralMint.toString(),
|
|
4470
|
+
* interestRate: 600, // 6%
|
|
4471
|
+
* maxExposure: 3000000
|
|
4472
|
+
* });
|
|
4473
|
+
*
|
|
4474
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
4475
|
+
* ```
|
|
4476
|
+
*
|
|
4477
|
+
* @see {@link updateInterestRate} - Update only interest rate
|
|
4478
|
+
* @see {@link updateMaxExposure} - Update only max exposure
|
|
4479
|
+
*/
|
|
3724
4480
|
declare function updateOffer(lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, params: {
|
|
3725
4481
|
tradingPool: PublicKey;
|
|
3726
4482
|
poolOwner: PublicKey;
|
|
@@ -3730,6 +4486,34 @@ declare function updateOffer(lavarageProgram: Program<Lavarage$1> | Program<Lava
|
|
|
3730
4486
|
maxExposure: number;
|
|
3731
4487
|
computeBudgetMicroLamports?: number;
|
|
3732
4488
|
}): Promise<VersionedTransaction>;
|
|
4489
|
+
/**
|
|
4490
|
+
* Updates the maximum borrow limit for a trading pool
|
|
4491
|
+
*
|
|
4492
|
+
* @group Lending
|
|
4493
|
+
* @category Operations
|
|
4494
|
+
*
|
|
4495
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4496
|
+
* @param params - Update parameters
|
|
4497
|
+
* @param params.tradingPool - The trading pool PDA
|
|
4498
|
+
* @param params.nodeWallet - The node wallet address
|
|
4499
|
+
* @param params.oracle - The oracle public key authorized to update
|
|
4500
|
+
* @param params.maxBorrow - New maximum borrow limit
|
|
4501
|
+
* @param params.computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4502
|
+
*
|
|
4503
|
+
* @returns Transaction to update max borrow limit
|
|
4504
|
+
*
|
|
4505
|
+
* @example
|
|
4506
|
+
* ```typescript
|
|
4507
|
+
* const tx = await updateMaxBorrow(lavarageProgram, {
|
|
4508
|
+
* tradingPool: poolPDA,
|
|
4509
|
+
* nodeWallet: nodeWalletAddress,
|
|
4510
|
+
* oracle: oraclePublicKey,
|
|
4511
|
+
* maxBorrow: 5000000
|
|
4512
|
+
* });
|
|
4513
|
+
*
|
|
4514
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
4515
|
+
* ```
|
|
4516
|
+
*/
|
|
3733
4517
|
declare function updateMaxBorrow(lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, params: {
|
|
3734
4518
|
tradingPool: PublicKey;
|
|
3735
4519
|
nodeWallet: string;
|
|
@@ -3771,15 +4555,86 @@ declare namespace lending {
|
|
|
3771
4555
|
export { lending_addToWithdrawalAccessList as addToWithdrawalAccessList, lending_createOffer as createOffer, lending_depositFunds as depositFunds, lending_getNodeWalletPDA as getNodeWalletPDA, lending_getTradingPoolPDA as getTradingPoolPDA, lending_getWithdrawalAccessList as getWithdrawalAccessList, lending_getWithdrawalAccessListPDA as getWithdrawalAccessListPDA, lending_removeFromWithdrawalAccessList as removeFromWithdrawalAccessList, lending_updateInterestRate as updateInterestRate, lending_updateMaxBorrow as updateMaxBorrow, lending_updateMaxExposure as updateMaxExposure, lending_updateOffer as updateOffer, lending_withdrawFunds as withdrawFunds, lending_withdrawFundsV1 as withdrawFundsV1, lending_withdrawFundsV2 as withdrawFundsV2 };
|
|
3772
4556
|
}
|
|
3773
4557
|
|
|
4558
|
+
/**
|
|
4559
|
+
* @packageDocumentation
|
|
4560
|
+
* @module Lavarage SDK
|
|
4561
|
+
*
|
|
4562
|
+
* The main entry point for the Lavarage SDK, providing functionality for interacting
|
|
4563
|
+
* with the Lavarage DeFi protocol on both Solana and EVM chains.
|
|
4564
|
+
*
|
|
4565
|
+
* @example
|
|
4566
|
+
* ```typescript
|
|
4567
|
+
* import { getPda, getPositionAccountPDA } from '@lavarage/sdk';
|
|
4568
|
+
* import * as lending from '@lavarage/sdk/lending';
|
|
4569
|
+
* ```
|
|
4570
|
+
*/
|
|
4571
|
+
|
|
3774
4572
|
type OptionalRPCResults = {
|
|
3775
4573
|
addressLookupTableAccounts?: AccountInfo<Buffer>[];
|
|
3776
4574
|
latestBlockhash?: string;
|
|
3777
4575
|
tokenAccountConfirmCreatedAddresses?: PublicKey[];
|
|
3778
4576
|
quoteMintAccountInfo?: AccountInfo<Buffer>;
|
|
3779
4577
|
};
|
|
4578
|
+
/**
|
|
4579
|
+
* Derives a Program Derived Address (PDA) for the given seed(s) and program ID
|
|
4580
|
+
*
|
|
4581
|
+
* @group Traders
|
|
4582
|
+
* @category Utilities
|
|
4583
|
+
*
|
|
4584
|
+
* @param seed - Single buffer or array of buffers to use as seeds
|
|
4585
|
+
* @param programId - The Solana program ID to derive the PDA from
|
|
4586
|
+
* @returns The derived public key address
|
|
4587
|
+
*
|
|
4588
|
+
* @example
|
|
4589
|
+
* ```typescript
|
|
4590
|
+
* const seed = Buffer.from("position");
|
|
4591
|
+
* const pda = getPda(seed, programId);
|
|
4592
|
+
* ```
|
|
4593
|
+
*/
|
|
3780
4594
|
declare function getPda(seed: Buffer | Buffer[], programId: PublicKey): PublicKey;
|
|
4595
|
+
/**
|
|
4596
|
+
* Generates a Position Account PDA for a specific offer and user
|
|
4597
|
+
*
|
|
4598
|
+
* @group Traders
|
|
4599
|
+
* @category Utilities
|
|
4600
|
+
*
|
|
4601
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4602
|
+
* @param offer - The offer program account
|
|
4603
|
+
* @param seed - Additional seed for uniqueness (typically a public key)
|
|
4604
|
+
* @returns The Position Account PDA public key
|
|
4605
|
+
*
|
|
4606
|
+
* @example
|
|
4607
|
+
* ```typescript
|
|
4608
|
+
* const positionPDA = getPositionAccountPDA(
|
|
4609
|
+
* lavarageProgram,
|
|
4610
|
+
* offerAccount,
|
|
4611
|
+
* userPublicKey
|
|
4612
|
+
* );
|
|
4613
|
+
* ```
|
|
4614
|
+
*/
|
|
3781
4615
|
declare function getPositionAccountPDA(lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, offer: ProgramAccount, seed: PublicKey): PublicKey;
|
|
3782
4616
|
|
|
4617
|
+
/**
|
|
4618
|
+
* Fetches all available lending offers from the Lavarage protocol
|
|
4619
|
+
*
|
|
4620
|
+
* @group Traders
|
|
4621
|
+
* @category Queries
|
|
4622
|
+
*
|
|
4623
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4624
|
+
* @returns Promise resolving to an array of all pool/offer accounts
|
|
4625
|
+
*
|
|
4626
|
+
* @example
|
|
4627
|
+
* ```typescript
|
|
4628
|
+
* // Fetch all offers
|
|
4629
|
+
* const offers = await getOffers(lavarageProgram);
|
|
4630
|
+
*
|
|
4631
|
+
* // Process each offer
|
|
4632
|
+
* offers.forEach(offer => {
|
|
4633
|
+
* console.log('Offer:', offer.publicKey.toString());
|
|
4634
|
+
* console.log('Data:', offer.account);
|
|
4635
|
+
* });
|
|
4636
|
+
* ```
|
|
4637
|
+
*/
|
|
3783
4638
|
declare const getOffers: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>) => Promise<ProgramAccount<{
|
|
3784
4639
|
interestRate: number;
|
|
3785
4640
|
collateralType: PublicKey;
|
|
@@ -3788,6 +4643,35 @@ declare const getOffers: (lavarageProgram: Program<Lavarage$1> | Program<Lavarag
|
|
|
3788
4643
|
maxExposure: BN;
|
|
3789
4644
|
currentExposure: BN;
|
|
3790
4645
|
}>[]>;
|
|
4646
|
+
/**
|
|
4647
|
+
* Fetches all open positions from the Lavarage protocol
|
|
4648
|
+
*
|
|
4649
|
+
* This function filters for positions with a specific data structure size (178 bytes)
|
|
4650
|
+
* and checks for positions that are currently open.
|
|
4651
|
+
*
|
|
4652
|
+
* @group Traders
|
|
4653
|
+
* @category Queries
|
|
4654
|
+
*
|
|
4655
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4656
|
+
* @returns Promise resolving to an array of open position accounts
|
|
4657
|
+
*
|
|
4658
|
+
* @example
|
|
4659
|
+
* ```typescript
|
|
4660
|
+
* // Get all open positions
|
|
4661
|
+
* const openPositions = await getOpenPositions(lavarageProgram);
|
|
4662
|
+
*
|
|
4663
|
+
* console.log(`Found ${openPositions.length} open positions`);
|
|
4664
|
+
*
|
|
4665
|
+
* // Filter positions by user
|
|
4666
|
+
* const userPositions = openPositions.filter(pos =>
|
|
4667
|
+
* pos.account.owner.equals(userPublicKey)
|
|
4668
|
+
* );
|
|
4669
|
+
* ```
|
|
4670
|
+
*
|
|
4671
|
+
* @remarks
|
|
4672
|
+
* The function query only open positions
|
|
4673
|
+
* without fetching closed or liquidated positions.
|
|
4674
|
+
*/
|
|
3791
4675
|
declare const getOpenPositions: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>) => Promise<ProgramAccount<{
|
|
3792
4676
|
pool: PublicKey;
|
|
3793
4677
|
closeStatusRecallTimestamp: BN;
|
|
@@ -3802,6 +4686,30 @@ declare const getOpenPositions: (lavarageProgram: Program<Lavarage$1> | Program<
|
|
|
3802
4686
|
interestRate: number;
|
|
3803
4687
|
lastInterestCollect: BN;
|
|
3804
4688
|
}>[]>;
|
|
4689
|
+
/**
|
|
4690
|
+
* Fetches all closed positions from the Lavarage protocol
|
|
4691
|
+
*
|
|
4692
|
+
*
|
|
4693
|
+
* @group Traders
|
|
4694
|
+
* @category Queries
|
|
4695
|
+
*
|
|
4696
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4697
|
+
* @returns Promise resolving to an array of all closed position accounts from all three states
|
|
4698
|
+
*
|
|
4699
|
+
* @example
|
|
4700
|
+
* ```typescript
|
|
4701
|
+
* // Get all closed positions
|
|
4702
|
+
* const closedPositions = await getClosedPositions(lavarageProgram);
|
|
4703
|
+
*
|
|
4704
|
+
* console.log(`Found ${closedPositions.length} closed positions`);
|
|
4705
|
+
*
|
|
4706
|
+
* // Filter by specific user
|
|
4707
|
+
* const userClosedPositions = closedPositions.filter(pos =>
|
|
4708
|
+
* pos.account.owner.equals(userPublicKey)
|
|
4709
|
+
* );
|
|
4710
|
+
* ```
|
|
4711
|
+
*
|
|
4712
|
+
*/
|
|
3805
4713
|
declare const getClosedPositions: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>) => Promise<ProgramAccount<{
|
|
3806
4714
|
pool: PublicKey;
|
|
3807
4715
|
closeStatusRecallTimestamp: BN;
|
|
@@ -3816,6 +4724,36 @@ declare const getClosedPositions: (lavarageProgram: Program<Lavarage$1> | Progra
|
|
|
3816
4724
|
interestRate: number;
|
|
3817
4725
|
lastInterestCollect: BN;
|
|
3818
4726
|
}>[]>;
|
|
4727
|
+
/**
|
|
4728
|
+
* Fetches all liquidated positions from the Lavarage protocol
|
|
4729
|
+
*
|
|
4730
|
+
* Liquidated positions are positions that were forcefully closed due to
|
|
4731
|
+
* insufficient collateral or health factor falling below the threshold.
|
|
4732
|
+
*
|
|
4733
|
+
* @group Traders
|
|
4734
|
+
* @category Queries
|
|
4735
|
+
*
|
|
4736
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4737
|
+
* @returns Promise resolving to an array of liquidated position accounts
|
|
4738
|
+
*
|
|
4739
|
+
* @example
|
|
4740
|
+
* ```typescript
|
|
4741
|
+
* // Get all liquidated positions
|
|
4742
|
+
* const liquidatedPositions = await getLiquidatedPositions(lavarageProgram);
|
|
4743
|
+
*
|
|
4744
|
+
* console.log(`Found ${liquidatedPositions.length} liquidated positions`);
|
|
4745
|
+
*
|
|
4746
|
+
* // Analyze liquidation data
|
|
4747
|
+
* liquidatedPositions.forEach(pos => {
|
|
4748
|
+
* console.log('Position:', pos.publicKey.toString());
|
|
4749
|
+
* console.log('Liquidated amount:', pos.account.amount);
|
|
4750
|
+
* });
|
|
4751
|
+
* ```
|
|
4752
|
+
*
|
|
4753
|
+
*
|
|
4754
|
+
* @see {@link getClosedPositions} - For other types of closed positions
|
|
4755
|
+
* @see {@link getOpenPositions} - For currently active positions
|
|
4756
|
+
*/
|
|
3819
4757
|
declare const getLiquidatedPositions: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>) => Promise<ProgramAccount<{
|
|
3820
4758
|
pool: PublicKey;
|
|
3821
4759
|
closeStatusRecallTimestamp: BN;
|
|
@@ -3830,6 +4768,40 @@ declare const getLiquidatedPositions: (lavarageProgram: Program<Lavarage$1> | Pr
|
|
|
3830
4768
|
interestRate: number;
|
|
3831
4769
|
lastInterestCollect: BN;
|
|
3832
4770
|
}>[]>;
|
|
4771
|
+
/**
|
|
4772
|
+
* Fetches all positions from the Lavarage protocol
|
|
4773
|
+
*
|
|
4774
|
+
* This function retrieves all position accounts regardless of their state (open, closed, liquidated).
|
|
4775
|
+
*
|
|
4776
|
+
* @group Traders
|
|
4777
|
+
* @category Queries
|
|
4778
|
+
*
|
|
4779
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4780
|
+
* @returns Promise resolving to an array of position accounts
|
|
4781
|
+
*
|
|
4782
|
+
* @example
|
|
4783
|
+
* ```typescript
|
|
4784
|
+
* // Get all positions
|
|
4785
|
+
* const allPositions = await getAllPositions(lavarageProgram);
|
|
4786
|
+
*
|
|
4787
|
+
* console.log(`Found ${allPositions.length} total positions`);
|
|
4788
|
+
*
|
|
4789
|
+
* // Filter positions by user
|
|
4790
|
+
* const userPositions = allPositions.filter(pos =>
|
|
4791
|
+
* pos.account.owner.equals(userPublicKey)
|
|
4792
|
+
* );
|
|
4793
|
+
* ```
|
|
4794
|
+
*
|
|
4795
|
+
* @remarks
|
|
4796
|
+
* Unlike other position query functions, this returns ALL positions without
|
|
4797
|
+
* filtering by status. Use more specific functions like `getOpenPositions`,
|
|
4798
|
+
* `getClosedPositions`, or `getLiquidatedPositions` if you only need positions
|
|
4799
|
+
* with a specific status.
|
|
4800
|
+
*
|
|
4801
|
+
* @see {@link getOpenPositions} - For only open positions
|
|
4802
|
+
* @see {@link getClosedPositions} - For only closed positions
|
|
4803
|
+
* @see {@link getLiquidatedPositions} - For only liquidated positions
|
|
4804
|
+
*/
|
|
3833
4805
|
declare const getAllPositions: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>) => Promise<ProgramAccount<{
|
|
3834
4806
|
pool: PublicKey;
|
|
3835
4807
|
closeStatusRecallTimestamp: BN;
|
|
@@ -3854,6 +4826,56 @@ declare const borrowV2: (lavarageProgram: Program<Lavarage>, offer: ProgramAccou
|
|
|
3854
4826
|
interestRate: number;
|
|
3855
4827
|
collateralType: PublicKey;
|
|
3856
4828
|
}>, marginSOL: BN, leverage: number, randomSeed: Keypair, quoteToken: PublicKey, tokenProgram: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number, computeBudgetMicroLamports?: number, discountBps?: number, referralBps?: number, referralVaultProgram?: Program<UserVault>) => Promise<VersionedTransaction>;
|
|
4829
|
+
/**
|
|
4830
|
+
* Opens a leveraged trading position on Lavarage V1
|
|
4831
|
+
*
|
|
4832
|
+
* This function executes a complete leveraged trade by:
|
|
4833
|
+
* 1. Borrowing funds from the lending pool based on leverage
|
|
4834
|
+
* 2. Swapping tokens through Jupiter DEX
|
|
4835
|
+
* 3. Depositing the swapped tokens as collateral
|
|
4836
|
+
*
|
|
4837
|
+
* @group Traders
|
|
4838
|
+
* @category Trading
|
|
4839
|
+
*
|
|
4840
|
+
* @param lavarageProgram - The Lavarage V1 program instance
|
|
4841
|
+
* @param offer - The lending offer containing terms (interest rate, collateral type, node wallet)
|
|
4842
|
+
* @param jupInstruction - Jupiter swap instructions including setup and swap details
|
|
4843
|
+
* @param marginSOL - The user's margin amount in SOL (as BN)
|
|
4844
|
+
* @param leverage - The leverage multiplier (e.g., 2 for 2x leverage)
|
|
4845
|
+
* @param randomSeed - A keypair used to generate unique position account address
|
|
4846
|
+
* @param tokenProgram - The SPL token program ID
|
|
4847
|
+
* @param partnerFeeRecipient - Optional wallet to receive partner fees
|
|
4848
|
+
* @param partnerFeeMarkup - Optional partner fee amount in basis points
|
|
4849
|
+
* @param computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4850
|
+
*
|
|
4851
|
+
* @returns A versioned transaction ready to be signed and sent
|
|
4852
|
+
*
|
|
4853
|
+
* @example
|
|
4854
|
+
* ```typescript
|
|
4855
|
+
* // Open a 2x leveraged position with 1 SOL margin
|
|
4856
|
+
* const marginSOL = new BN(1_000_000_000); // 1 SOL in lamports
|
|
4857
|
+
* const leverage = 2;
|
|
4858
|
+
* const randomSeed = Keypair.generate();
|
|
4859
|
+
*
|
|
4860
|
+
* const tx = await openTradeV1(
|
|
4861
|
+
* lavarageProgram,
|
|
4862
|
+
* offerAccount,
|
|
4863
|
+
* jupiterInstructions,
|
|
4864
|
+
* marginSOL,
|
|
4865
|
+
* leverage,
|
|
4866
|
+
* randomSeed,
|
|
4867
|
+
* TOKEN_PROGRAM_ID
|
|
4868
|
+
* );
|
|
4869
|
+
*
|
|
4870
|
+
* // Sign and send transaction
|
|
4871
|
+
* const signature = await sendAndConfirmTransaction(connection, tx, [wallet, randomSeed]);
|
|
4872
|
+
* ```
|
|
4873
|
+
*
|
|
4874
|
+
* @remarks
|
|
4875
|
+
* - The function creates token accounts if they don't exist
|
|
4876
|
+
*
|
|
4877
|
+
* @throws Will throw if token accounts cannot be created or if Jupiter instructions are invalid
|
|
4878
|
+
*/
|
|
3857
4879
|
declare const openTradeV1: (lavarageProgram: Program<Lavarage$1>, offer: ProgramAccount<{
|
|
3858
4880
|
nodeWallet: PublicKey;
|
|
3859
4881
|
interestRate: number;
|
|
@@ -3865,6 +4887,61 @@ declare const openTradeV1: (lavarageProgram: Program<Lavarage$1>, offer: Program
|
|
|
3865
4887
|
addressLookupTableAddresses: string[];
|
|
3866
4888
|
};
|
|
3867
4889
|
}, marginSOL: BN, leverage: number, randomSeed: Keypair, tokenProgram: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number, computeBudgetMicroLamports?: number, platformFeeRecipient?: PublicKey, splitTransactions?: boolean, discountBps?: number, referralBps?: number, optionalRPCResults?: OptionalRPCResults) => Promise<VersionedTransaction | VersionedTransaction[]>;
|
|
4890
|
+
/**
|
|
4891
|
+
* Opens a leveraged trading position on Lavarage V2
|
|
4892
|
+
*
|
|
4893
|
+
* This function executes a complete leveraged trade similar to V1, but with
|
|
4894
|
+
* enhanced support for multiple quote tokens (not limited to SOL).
|
|
4895
|
+
* The process includes:
|
|
4896
|
+
* 1. Borrowing funds from the lending pool based on leverage
|
|
4897
|
+
* 2. Swapping tokens through Jupiter DEX
|
|
4898
|
+
* 3. Depositing the swapped tokens as collateral
|
|
4899
|
+
*
|
|
4900
|
+
* @group Traders
|
|
4901
|
+
* @category Trading
|
|
4902
|
+
*
|
|
4903
|
+
* @param lavarageProgram - The Lavarage V2 program instance
|
|
4904
|
+
* @param offer - The lending offer containing terms (interest rate, collateral type, node wallet)
|
|
4905
|
+
* @param jupInstruction - Jupiter swap instructions including setup and swap details
|
|
4906
|
+
* @param marginSOL - The user's margin amount in SOL (as BN)
|
|
4907
|
+
* @param leverage - The leverage multiplier (e.g., 2 for 2x leverage)
|
|
4908
|
+
* @param randomSeed - A keypair used to generate unique position account address
|
|
4909
|
+
* @param quoteToken - The quote token mint address (e.g., USDC, USDT, or SOL)
|
|
4910
|
+
* @param tokenProgram - The SPL token program ID for the collateral token
|
|
4911
|
+
* @param partnerFeeRecipient - Optional wallet to receive partner fees
|
|
4912
|
+
* @param partnerFeeMarkup - Optional partner fee amount in basis points
|
|
4913
|
+
* @param computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
4914
|
+
*
|
|
4915
|
+
* @returns A versioned transaction ready to be signed and sent
|
|
4916
|
+
*
|
|
4917
|
+
* @example
|
|
4918
|
+
* ```typescript
|
|
4919
|
+
* // Open a 3x leveraged position with USDC as quote token
|
|
4920
|
+
* const marginSOL = new BN(1_000_000_000); // 1 SOL equivalent
|
|
4921
|
+
* const leverage = 3;
|
|
4922
|
+
* const randomSeed = Keypair.generate();
|
|
4923
|
+
* const usdcMint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
4924
|
+
*
|
|
4925
|
+
* const tx = await openTradeV2(
|
|
4926
|
+
* lavarageProgram,
|
|
4927
|
+
* offerAccount,
|
|
4928
|
+
* jupiterInstructions,
|
|
4929
|
+
* marginSOL,
|
|
4930
|
+
* leverage,
|
|
4931
|
+
* randomSeed,
|
|
4932
|
+
* usdcMint, // Quote token
|
|
4933
|
+
* TOKEN_PROGRAM_ID
|
|
4934
|
+
* );
|
|
4935
|
+
*
|
|
4936
|
+
* // Sign and send transaction
|
|
4937
|
+
* const signature = await sendAndConfirmTransaction(connection, tx, [wallet, randomSeed]);
|
|
4938
|
+
* ```
|
|
4939
|
+
*
|
|
4940
|
+
* @remarks
|
|
4941
|
+
* - V2 supports multiple quote tokens while V1 only supports SOL
|
|
4942
|
+
*
|
|
4943
|
+
* @see {@link openTradeV1} - The V1 version limited to SOL as quote token
|
|
4944
|
+
*/
|
|
3868
4945
|
declare const openTradeV2: (lavarageProgram: Program<Lavarage>, offer: ProgramAccount<{
|
|
3869
4946
|
nodeWallet: PublicKey;
|
|
3870
4947
|
interestRate: number;
|
|
@@ -3876,36 +4953,222 @@ declare const openTradeV2: (lavarageProgram: Program<Lavarage>, offer: ProgramAc
|
|
|
3876
4953
|
addressLookupTableAddresses: string[];
|
|
3877
4954
|
};
|
|
3878
4955
|
}, marginSOL: BN, leverage: number, randomSeed: Keypair, quoteToken: PublicKey, tokenProgram: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number, computeBudgetMicroLamports?: number, platformFeeRecipient?: PublicKey, splitTransactions?: boolean, discountBps?: number, referralBps?: number, optionalRPCResults?: OptionalRPCResults) => Promise<VersionedTransaction | VersionedTransaction[]>;
|
|
4956
|
+
/**
|
|
4957
|
+
* Creates a take-profit delegate for automated position closing
|
|
4958
|
+
*
|
|
4959
|
+
*
|
|
4960
|
+
* @group Traders
|
|
4961
|
+
* @category Automation
|
|
4962
|
+
*
|
|
4963
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
4964
|
+
* @param position - The position account to set take-profit for
|
|
4965
|
+
* @param tpPrice - The target price at which to take profit (as BN)
|
|
4966
|
+
* @param tpTolerence - Price tolerance/slippage allowed when executing (as BN)
|
|
4967
|
+
* @param prioFee - Priority fee in microlamports for transaction execution
|
|
4968
|
+
* @param quoteToken - The quote token mint address (e.g., USDC, SOL)
|
|
4969
|
+
* @param partnerFeeRecipient - Optional wallet to receive partner fees
|
|
4970
|
+
*
|
|
4971
|
+
* @returns A versioned transaction to create the take-profit delegate
|
|
4972
|
+
*
|
|
4973
|
+
* @example
|
|
4974
|
+
* ```typescript
|
|
4975
|
+
* // Set take-profit at $150 for a position
|
|
4976
|
+
* const position = await getPositionAccount(positionPubkey);
|
|
4977
|
+
* const tpPrice = new BN(150 * 1e6); // $150 with 6 decimals
|
|
4978
|
+
* const tolerance = new BN(1 * 1e6); // $1 tolerance
|
|
4979
|
+
* const prioFee = new BN(100000); // 0.1 SOL priority fee
|
|
4980
|
+
*
|
|
4981
|
+
* const tx = await createTpDelegate(
|
|
4982
|
+
* lavarageProgram,
|
|
4983
|
+
* position,
|
|
4984
|
+
* tpPrice,
|
|
4985
|
+
* tolerance,
|
|
4986
|
+
* prioFee,
|
|
4987
|
+
* usdcMint
|
|
4988
|
+
* );
|
|
4989
|
+
*
|
|
4990
|
+
* // Sign and send
|
|
4991
|
+
* const signature = await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
4992
|
+
* console.log('Take-profit delegate created:', signature);
|
|
4993
|
+
* ```
|
|
4994
|
+
*
|
|
4995
|
+
* @see {@link modifyTpDelegate} - Modify take-profit settings
|
|
4996
|
+
* @see {@link removeTpDelegate} - Remove take-profit without replacement
|
|
4997
|
+
*/
|
|
3879
4998
|
declare const createTpDelegate: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, position: ProgramAccount<{
|
|
3880
4999
|
pool: PublicKey;
|
|
3881
5000
|
seed: PublicKey;
|
|
3882
5001
|
userPaid: BN;
|
|
3883
5002
|
amount: BN;
|
|
3884
5003
|
}>, tpPrice: BN, tpTolerence: BN, prioFee: BN, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey) => Promise<VersionedTransaction>;
|
|
5004
|
+
/**
|
|
5005
|
+
* Modifies take-profit setting for an existing position.
|
|
5006
|
+
*
|
|
5007
|
+
*
|
|
5008
|
+
* @group Traders
|
|
5009
|
+
* @category Automation
|
|
5010
|
+
*
|
|
5011
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
5012
|
+
* @param position - The position account to modify take-profit for
|
|
5013
|
+
* @param tpPrice - The new target price for take-profit (as BN)
|
|
5014
|
+
* @param tpTolerence - The new price tolerance/slippage allowed (as BN)
|
|
5015
|
+
* @param prioFee - Priority fee in microlamports for transaction execution
|
|
5016
|
+
* @param quoteToken - The quote token mint address (e.g., USDC, SOL)
|
|
5017
|
+
* @param partnerFeeRecipient - Optional wallet to receive partner fees
|
|
5018
|
+
*
|
|
5019
|
+
* @returns Transaction to update the take-profit settings.
|
|
5020
|
+
*
|
|
5021
|
+
* @example
|
|
5022
|
+
* ```typescript
|
|
5023
|
+
* const tx = await modifyTpDelegate(
|
|
5024
|
+
* program,
|
|
5025
|
+
* position,
|
|
5026
|
+
* new BN(160 * 1e6), // New target: $160
|
|
5027
|
+
* new BN(2 * 1e6), // Tolerance: $2
|
|
5028
|
+
* new BN(100000), // Priority fee
|
|
5029
|
+
* usdcMint
|
|
5030
|
+
* );
|
|
5031
|
+
* ```
|
|
5032
|
+
*
|
|
5033
|
+
* @see {@link createTpDelegate} - Initial creation of take-profit
|
|
5034
|
+
* @see {@link removeTpDelegate} - Remove take-profit without replacement
|
|
5035
|
+
*/
|
|
3885
5036
|
declare const modifyTpDelegate: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, position: ProgramAccount<{
|
|
3886
5037
|
pool: PublicKey;
|
|
3887
5038
|
seed: PublicKey;
|
|
3888
5039
|
userPaid: BN;
|
|
3889
5040
|
amount: BN;
|
|
3890
5041
|
}>, tpPrice: BN, tpTolerence: BN, prioFee: BN, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey) => Promise<VersionedTransaction>;
|
|
5042
|
+
/**
|
|
5043
|
+
* Removes take-profit settings from a position
|
|
5044
|
+
*
|
|
5045
|
+
* @group Traders
|
|
5046
|
+
* @category Automation
|
|
5047
|
+
*
|
|
5048
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
5049
|
+
* @param position - The position account to remove take-profit from
|
|
5050
|
+
* @param prioFee - Priority fee in microlamports for transaction execution
|
|
5051
|
+
*
|
|
5052
|
+
* @returns Transaction to remove take-profit settings
|
|
5053
|
+
*
|
|
5054
|
+
* @example
|
|
5055
|
+
* ```typescript
|
|
5056
|
+
* const tx = await removeTpDelegate(
|
|
5057
|
+
* lavarageProgram,
|
|
5058
|
+
* position,
|
|
5059
|
+
* new BN(100000) // Priority fee
|
|
5060
|
+
* );
|
|
5061
|
+
*
|
|
5062
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
5063
|
+
* ```
|
|
5064
|
+
*
|
|
5065
|
+
* @see {@link createTpDelegate} - Initial creation of take-profit
|
|
5066
|
+
* @see {@link modifyTpDelegate} - Modify existing take-profit settings
|
|
5067
|
+
*/
|
|
3891
5068
|
declare const removeTpDelegate: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, position: ProgramAccount<{
|
|
3892
5069
|
pool: PublicKey;
|
|
3893
5070
|
seed: PublicKey;
|
|
3894
5071
|
userPaid: BN;
|
|
3895
5072
|
amount: BN;
|
|
3896
5073
|
}>, prioFee: BN) => Promise<VersionedTransaction>;
|
|
5074
|
+
/**
|
|
5075
|
+
* Partially repays a position on Lavarage V1
|
|
5076
|
+
*
|
|
5077
|
+
* @group Traders
|
|
5078
|
+
* @category Trading
|
|
5079
|
+
*
|
|
5080
|
+
* @param lavarageProgram - The Lavarage V1 program instance
|
|
5081
|
+
* @param position - The position account to partially repay
|
|
5082
|
+
* @param repaymentBps - Repayment amount in basis points (10000 = 100%)
|
|
5083
|
+
*
|
|
5084
|
+
* @returns Transaction for partial repayment
|
|
5085
|
+
*
|
|
5086
|
+
* @example
|
|
5087
|
+
* ```typescript
|
|
5088
|
+
* // Repay 50% of the position
|
|
5089
|
+
* const tx = await partialRepayV1(
|
|
5090
|
+
* lavarageProgram,
|
|
5091
|
+
* position,
|
|
5092
|
+
* 5000 // 50% in basis points
|
|
5093
|
+
* );
|
|
5094
|
+
*
|
|
5095
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
5096
|
+
* ```
|
|
5097
|
+
*
|
|
5098
|
+
* @see {@link partialRepayV2} - The V2 version supporting multiple quote tokens
|
|
5099
|
+
*/
|
|
3897
5100
|
declare const partialRepayV1: (lavarageProgram: Program<Lavarage$1>, position: ProgramAccount<{
|
|
3898
5101
|
pool: PublicKey;
|
|
3899
5102
|
seed: PublicKey;
|
|
3900
5103
|
userPaid: BN;
|
|
3901
5104
|
amount: BN;
|
|
3902
5105
|
}>, repaymentBps: number) => Promise<VersionedTransaction>;
|
|
5106
|
+
/**
|
|
5107
|
+
* Partially repays a position on Lavarage V2
|
|
5108
|
+
*
|
|
5109
|
+
* @group Traders
|
|
5110
|
+
* @category Trading
|
|
5111
|
+
*
|
|
5112
|
+
* @param lavarageProgram - The Lavarage V2 program instance
|
|
5113
|
+
* @param position - The position account to partially repay
|
|
5114
|
+
* @param repaymentBps - Repayment amount in basis points (10000 = 100%)
|
|
5115
|
+
*
|
|
5116
|
+
* @returns Transaction for partial repayment
|
|
5117
|
+
*
|
|
5118
|
+
* @example
|
|
5119
|
+
* ```typescript
|
|
5120
|
+
* // Repay 30% of the position
|
|
5121
|
+
* const tx = await partialRepayV2(
|
|
5122
|
+
* lavarageProgram,
|
|
5123
|
+
* position,
|
|
5124
|
+
* 3000 // 30% in basis points
|
|
5125
|
+
* );
|
|
5126
|
+
*
|
|
5127
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
5128
|
+
* ```
|
|
5129
|
+
*
|
|
5130
|
+
* @see {@link partialRepayV1} - The V1 version supporting SOL as quote token
|
|
5131
|
+
*/
|
|
3903
5132
|
declare const partialRepayV2: (lavarageProgram: Program<Lavarage>, position: ProgramAccount<{
|
|
3904
5133
|
pool: PublicKey;
|
|
3905
5134
|
seed: PublicKey;
|
|
3906
5135
|
userPaid: BN;
|
|
3907
5136
|
amount: BN;
|
|
3908
5137
|
}>, repaymentBps: number) => Promise<VersionedTransaction>;
|
|
5138
|
+
/**
|
|
5139
|
+
* Closes a trading position on Lavarage V1
|
|
5140
|
+
*
|
|
5141
|
+
* @group Traders
|
|
5142
|
+
* @category Trading
|
|
5143
|
+
*
|
|
5144
|
+
* @param lavarageProgram - The Lavarage V1 program instance
|
|
5145
|
+
* @param position - The position account to close
|
|
5146
|
+
* @param offer - The offer/pool account associated with the position
|
|
5147
|
+
* @param jupInstruction - Jupiter swap instructions and quote for closing
|
|
5148
|
+
* @param partnerFeeRecipient - Optional wallet to receive partner fees
|
|
5149
|
+
* @param partnerFeeMarkup - Optional partner fee amount in basis points
|
|
5150
|
+
* @param computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
5151
|
+
*
|
|
5152
|
+
* @returns Transaction to close the position
|
|
5153
|
+
*
|
|
5154
|
+
* @example
|
|
5155
|
+
* ```typescript
|
|
5156
|
+
* const jupQuote = await getJupiterQuote(...);
|
|
5157
|
+
* const tx = await closeTradeV1(
|
|
5158
|
+
* lavarageProgram,
|
|
5159
|
+
* position,
|
|
5160
|
+
* offer,
|
|
5161
|
+
* jupQuote,
|
|
5162
|
+
* partnerWallet, // optional
|
|
5163
|
+
* 100, // optional fee in bps
|
|
5164
|
+
* 150000 // optional priority fee
|
|
5165
|
+
* );
|
|
5166
|
+
*
|
|
5167
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
5168
|
+
* ```
|
|
5169
|
+
* @see {@link openTradeV1} - The V1 version for opening positions
|
|
5170
|
+
* @see {@link partialRepayV1} - Partial repayments on V1
|
|
5171
|
+
*/
|
|
3909
5172
|
declare const closeTradeV1: (lavarageProgram: Program<Lavarage$1>, position: ProgramAccount<{
|
|
3910
5173
|
pool: PublicKey;
|
|
3911
5174
|
seed: PublicKey;
|
|
@@ -3925,6 +5188,42 @@ declare const closeTradeV1: (lavarageProgram: Program<Lavarage$1>, position: Pro
|
|
|
3925
5188
|
};
|
|
3926
5189
|
quoteResponse: any;
|
|
3927
5190
|
}, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number, computeBudgetMicroLamports?: number, platformFeeRecipient?: PublicKey, splitTransactions?: boolean) => Promise<VersionedTransaction | VersionedTransaction[]>;
|
|
5191
|
+
/**
|
|
5192
|
+
* Closes a trading position on Lavarage V2
|
|
5193
|
+
*
|
|
5194
|
+
* @group Traders
|
|
5195
|
+
* @category Trading
|
|
5196
|
+
*
|
|
5197
|
+
* @param lavarageProgram - The Lavarage V2 program instance
|
|
5198
|
+
* @param position - The position account to close
|
|
5199
|
+
* @param offer - The offer/pool account associated with the position
|
|
5200
|
+
* @param jupInstruction - Jupiter swap instructions and quote for closing
|
|
5201
|
+
* @param quoteToken - The quote token mint address for this position
|
|
5202
|
+
* @param partnerFeeRecipient - Optional wallet to receive partner fees
|
|
5203
|
+
* @param partnerFeeMarkup - Optional partner fee amount in basis points
|
|
5204
|
+
* @param computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
5205
|
+
*
|
|
5206
|
+
* @returns Transaction to close the position
|
|
5207
|
+
*
|
|
5208
|
+
* @example
|
|
5209
|
+
* ```typescript
|
|
5210
|
+
* const jupQuote = await getJupiterQuote(...);
|
|
5211
|
+
* const tx = await closeTradeV2(
|
|
5212
|
+
* lavarageProgram,
|
|
5213
|
+
* position,
|
|
5214
|
+
* offer,
|
|
5215
|
+
* jupQuote,
|
|
5216
|
+
* usdcMint, // quote token
|
|
5217
|
+
* partnerWallet, // optional
|
|
5218
|
+
* 100, // optional fee in bps
|
|
5219
|
+
* 150000 // optional priority fee
|
|
5220
|
+
* );
|
|
5221
|
+
*
|
|
5222
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
5223
|
+
* ```
|
|
5224
|
+
* @see {@link openTradeV2} - The V2 version for opening positions
|
|
5225
|
+
* @see {@link partialRepayV2} - Partial repay a V2 position
|
|
5226
|
+
*/
|
|
3928
5227
|
declare const closeTradeV2: (lavarageProgram: Program<Lavarage>, position: ProgramAccount<{
|
|
3929
5228
|
pool: PublicKey;
|
|
3930
5229
|
seed: PublicKey;
|
|
@@ -3943,7 +5242,39 @@ declare const closeTradeV2: (lavarageProgram: Program<Lavarage>, position: Progr
|
|
|
3943
5242
|
tokenLedgerInstruction?: Record<string, unknown>;
|
|
3944
5243
|
};
|
|
3945
5244
|
quoteResponse: any;
|
|
3946
|
-
}, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number, computeBudgetMicroLamports?: number, platformFeeRecipient?: PublicKey, splitTransactions?: boolean) => Promise<VersionedTransaction | VersionedTransaction[]>;
|
|
5245
|
+
}, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number, computeBudgetMicroLamports?: number, platformFeeRecipient?: PublicKey, splitTransactions?: boolean, discountBps?: number, referralBps?: number) => Promise<VersionedTransaction | VersionedTransaction[]>;
|
|
5246
|
+
/**
|
|
5247
|
+
* Retrieves delegate accounts for automated position management
|
|
5248
|
+
*
|
|
5249
|
+
* @group Traders
|
|
5250
|
+
* @category Queries
|
|
5251
|
+
*
|
|
5252
|
+
* @param lavarageProgram - The Lavarage program instance (V1 or V2)
|
|
5253
|
+
* @param userPubKey - Optional user public key to filter delegates
|
|
5254
|
+
*
|
|
5255
|
+
* @returns Array of delegate accounts with parsed price data
|
|
5256
|
+
*
|
|
5257
|
+
* @example
|
|
5258
|
+
* ```typescript
|
|
5259
|
+
* // Get all delegates for a specific user
|
|
5260
|
+
* const userDelegates = await getDelegateAccounts(
|
|
5261
|
+
* lavarageProgram,
|
|
5262
|
+
* userPublicKey
|
|
5263
|
+
* );
|
|
5264
|
+
*
|
|
5265
|
+
* // Get all delegates (no filter)
|
|
5266
|
+
* const allDelegates = await getDelegateAccounts(lavarageProgram);
|
|
5267
|
+
*
|
|
5268
|
+
* // Access parsed data
|
|
5269
|
+
* userDelegates.forEach(delegate => {
|
|
5270
|
+
* console.log('TP Price:', delegate.parsed.tpPrice.toString());
|
|
5271
|
+
* console.log('Threshold:', delegate.parsed.tpThreshold.toString());
|
|
5272
|
+
* });
|
|
5273
|
+
* ```
|
|
5274
|
+
* @see {@link createTpDelegate} - Create a new take-profit delegate
|
|
5275
|
+
* @see {@link modifyTpDelegate} - Modify existing take-profit settings
|
|
5276
|
+
* @see {@link removeTpDelegate} - Remove take-profit settings
|
|
5277
|
+
*/
|
|
3947
5278
|
declare const getDelegateAccounts: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, userPubKey?: PublicKey) => Promise<{
|
|
3948
5279
|
parsed: {
|
|
3949
5280
|
tpPrice: any;
|
|
@@ -3962,6 +5293,39 @@ declare const getDelegateAccounts: (lavarageProgram: Program<Lavarage$1> | Progr
|
|
|
3962
5293
|
account: PublicKey;
|
|
3963
5294
|
};
|
|
3964
5295
|
}[]>;
|
|
5296
|
+
/**
|
|
5297
|
+
* Splits a position into two separate positions on Lavarage V2
|
|
5298
|
+
*
|
|
5299
|
+
* @group Traders
|
|
5300
|
+
* @category PositionManagement
|
|
5301
|
+
*
|
|
5302
|
+
* @param lavarageProgram - The Lavarage V2 or V1 program instance
|
|
5303
|
+
* @param position - The original position to split
|
|
5304
|
+
* @param offer - The offer/pool account associated with the position
|
|
5305
|
+
* @param quoteToken - The quote token mint address
|
|
5306
|
+
* @param propotionBps - Split ratio in basis points (5000 = 50/50 split)
|
|
5307
|
+
* @param computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
5308
|
+
*
|
|
5309
|
+
* @returns Object containing transaction and new position addresses
|
|
5310
|
+
*
|
|
5311
|
+
* @example
|
|
5312
|
+
* ```typescript
|
|
5313
|
+
* // Split position 70/30
|
|
5314
|
+
* const result = await splitPositionV2(
|
|
5315
|
+
* lavarageProgram,
|
|
5316
|
+
* position,
|
|
5317
|
+
* offer,
|
|
5318
|
+
* usdcMint,
|
|
5319
|
+
* 7000 // 70% to first position, 30% to second
|
|
5320
|
+
* );
|
|
5321
|
+
*
|
|
5322
|
+
* const tx = result.transaction;
|
|
5323
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
5324
|
+
*
|
|
5325
|
+
* console.log('New positions:', result.newPositionAddresses);
|
|
5326
|
+
* ```
|
|
5327
|
+
* @see {@link mergePositionV2} - Merge two positions into one
|
|
5328
|
+
*/
|
|
3965
5329
|
declare const splitPositionV2: (lavarageProgram: Program<Lavarage> | Program<Lavarage$1>, position: ProgramAccount<{
|
|
3966
5330
|
pool: PublicKey;
|
|
3967
5331
|
seed: PublicKey;
|
|
@@ -3976,6 +5340,37 @@ declare const splitPositionV2: (lavarageProgram: Program<Lavarage> | Program<Lav
|
|
|
3976
5340
|
newPositionAddresses: string[];
|
|
3977
5341
|
newPositionSeeds: string[];
|
|
3978
5342
|
}>;
|
|
5343
|
+
/**
|
|
5344
|
+
* Merges two positions into a single position on Lavarage V2
|
|
5345
|
+
*
|
|
5346
|
+
* @group Traders
|
|
5347
|
+
* @category PositionManagement
|
|
5348
|
+
*
|
|
5349
|
+
* @param lavarageProgram - The Lavarage V2 program instance
|
|
5350
|
+
* @param position1 - The first position to merge
|
|
5351
|
+
* @param position2 - The second position to merge
|
|
5352
|
+
* @param offer - The offer/pool account (must be same for both positions)
|
|
5353
|
+
* @param quoteToken - The quote token mint address
|
|
5354
|
+
* @param computeBudgetMicroLamports - Optional compute budget for priority fees
|
|
5355
|
+
*
|
|
5356
|
+
* @returns Transaction to merge the positions
|
|
5357
|
+
*
|
|
5358
|
+
* @example
|
|
5359
|
+
* ```typescript
|
|
5360
|
+
* // Merge two positions into one
|
|
5361
|
+
* const tx = await mergePositionV2(
|
|
5362
|
+
* lavarageProgram,
|
|
5363
|
+
* position1,
|
|
5364
|
+
* position2,
|
|
5365
|
+
* offer,
|
|
5366
|
+
* usdcMint
|
|
5367
|
+
* );
|
|
5368
|
+
*
|
|
5369
|
+
* await sendAndConfirmTransaction(connection, tx, [wallet]);
|
|
5370
|
+
* ```
|
|
5371
|
+
*
|
|
5372
|
+
* @see {@link splitPositionV2} - Split a position into two
|
|
5373
|
+
*/
|
|
3979
5374
|
declare const mergePositionV2: (lavarageProgram: Program<Lavarage>, position1: ProgramAccount<{
|
|
3980
5375
|
pool: PublicKey;
|
|
3981
5376
|
seed: PublicKey;
|