@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/index.ts
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { BN, Program, ProgramAccount } from "@coral-xyz/anchor";
|
|
16
|
-
import { Lavarage } from "./idl/
|
|
17
|
-
import { Lavarage as
|
|
18
|
-
import { UserVault
|
|
16
|
+
import { Lavarage as LavarageSOL } from "./idl/lavarageSOL";
|
|
17
|
+
import { Lavarage as LavarageUSDC } from "./idl/lavarageUSDC";
|
|
18
|
+
import { UserVault } from "./idl/userVault";
|
|
19
|
+
import userVaultIDL from "./idl/userVault.json";
|
|
19
20
|
import bs58 from "bs58";
|
|
20
21
|
import {
|
|
21
22
|
AccountInfo,
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
SystemProgram,
|
|
27
28
|
SYSVAR_CLOCK_PUBKEY,
|
|
28
29
|
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
30
|
+
SYSVAR_SLOT_HASHES_PUBKEY,
|
|
29
31
|
Transaction,
|
|
30
32
|
TransactionInstruction,
|
|
31
33
|
TransactionMessage,
|
|
@@ -35,13 +37,14 @@ import {
|
|
|
35
37
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
36
38
|
createAssociatedTokenAccountIdempotentInstruction,
|
|
37
39
|
createAssociatedTokenAccountInstruction,
|
|
38
|
-
createTransferInstruction,
|
|
39
|
-
getAccount,
|
|
40
40
|
getAssociatedTokenAddressSync,
|
|
41
|
+
NATIVE_MINT,
|
|
41
42
|
TOKEN_PROGRAM_ID,
|
|
42
|
-
TokenAccountNotFoundError,
|
|
43
|
-
TokenInvalidAccountOwnerError,
|
|
44
43
|
} from "@solana/spl-token";
|
|
44
|
+
import { queuePubkey, USDC_MINT } from "./constants";
|
|
45
|
+
import { getOracleQuoteForCollateralType, getOracleQuoteForFeedId } from "./switchboard";
|
|
46
|
+
import { u8ArrayToString } from "./utils";
|
|
47
|
+
import { ApiKeys, getUpdateOracleIxs } from "./crossbar";
|
|
45
48
|
|
|
46
49
|
export * from "./evm";
|
|
47
50
|
export * as lending from "./lending";
|
|
@@ -55,8 +58,6 @@ type OptionalRPCResults = {
|
|
|
55
58
|
}
|
|
56
59
|
const REFFERAL_VAULT_PROGRAM_ID = new PublicKey("FFe8xWs9iBdWB6vsxg8yBLirZHsbACFNbXqAM4K3fPPB");
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
60
61
|
/**
|
|
61
62
|
* Derives a Program Derived Address (PDA) for the given seed(s) and program ID
|
|
62
63
|
*
|
|
@@ -100,7 +101,7 @@ export function getPda(seed: Buffer | Buffer[], programId: PublicKey) {
|
|
|
100
101
|
*/
|
|
101
102
|
|
|
102
103
|
export function getPositionAccountPDA(
|
|
103
|
-
lavarageProgram: Program<
|
|
104
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
104
105
|
offer: ProgramAccount,
|
|
105
106
|
seed: PublicKey
|
|
106
107
|
) {
|
|
@@ -130,7 +131,7 @@ export function getPositionAccountPDA(
|
|
|
130
131
|
*/
|
|
131
132
|
|
|
132
133
|
async function getTokenAccountOrCreateIfNotExists(
|
|
133
|
-
lavarageProgram: Program<
|
|
134
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
134
135
|
ownerPublicKey: PublicKey,
|
|
135
136
|
tokenAddress: PublicKey,
|
|
136
137
|
tokenProgram?: PublicKey,
|
|
@@ -173,12 +174,12 @@ async function getTokenAccountOrCreateIfNotExists(
|
|
|
173
174
|
* Re-exports all types and interfaces from the Lavarage V1 IDL
|
|
174
175
|
* @group Solana
|
|
175
176
|
*/
|
|
176
|
-
export * from "./idl/
|
|
177
|
+
export * from "./idl/lavarageSOL";
|
|
177
178
|
/**
|
|
178
179
|
* Namespace containing all types and interfaces from the Lavarage V2 IDL
|
|
179
180
|
* @group Solana
|
|
180
181
|
*/
|
|
181
|
-
export * as IDLV2 from "./idl/
|
|
182
|
+
export * as IDLV2 from "./idl/lavarageUSDC";
|
|
182
183
|
/**
|
|
183
184
|
* Fetches all available lending offers from the Lavarage protocol
|
|
184
185
|
*
|
|
@@ -202,7 +203,7 @@ export * as IDLV2 from "./idl/lavaragev2";
|
|
|
202
203
|
*/
|
|
203
204
|
|
|
204
205
|
export const getOffers = (
|
|
205
|
-
lavarageProgram: Program<
|
|
206
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>
|
|
206
207
|
) => {
|
|
207
208
|
return lavarageProgram.account.pool.all();
|
|
208
209
|
};
|
|
@@ -237,7 +238,7 @@ export const getOffers = (
|
|
|
237
238
|
*/
|
|
238
239
|
|
|
239
240
|
export const getOpenPositions = (
|
|
240
|
-
lavarageProgram: Program<
|
|
241
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>
|
|
241
242
|
) => {
|
|
242
243
|
return lavarageProgram.account.position.all([
|
|
243
244
|
{ dataSize: 178 },
|
|
@@ -275,7 +276,7 @@ export const getOpenPositions = (
|
|
|
275
276
|
*/
|
|
276
277
|
|
|
277
278
|
export const getClosedPositions = async (
|
|
278
|
-
lavarageProgram: Program<
|
|
279
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>
|
|
279
280
|
) => {
|
|
280
281
|
const value = BigInt(9997);
|
|
281
282
|
const valueBuffer = Buffer.alloc(8);
|
|
@@ -352,7 +353,7 @@ export const getClosedPositions = async (
|
|
|
352
353
|
*/
|
|
353
354
|
|
|
354
355
|
export const getLiquidatedPositions = (
|
|
355
|
-
lavarageProgram: Program<
|
|
356
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>
|
|
356
357
|
) => {
|
|
357
358
|
const value = BigInt(9999);
|
|
358
359
|
const valueBuffer = Buffer.alloc(8);
|
|
@@ -403,13 +404,13 @@ export const getLiquidatedPositions = (
|
|
|
403
404
|
*/
|
|
404
405
|
|
|
405
406
|
export const getAllPositions = (
|
|
406
|
-
lavarageProgram: Program<
|
|
407
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>
|
|
407
408
|
) => {
|
|
408
409
|
return lavarageProgram.account.position.all([{ dataSize: 178 }]);
|
|
409
410
|
};
|
|
410
411
|
|
|
411
412
|
export const borrowV1 = async (
|
|
412
|
-
lavarageProgram: Program<
|
|
413
|
+
lavarageProgram: Program<LavarageSOL>,
|
|
413
414
|
offer: ProgramAccount<{
|
|
414
415
|
nodeWallet: PublicKey;
|
|
415
416
|
interestRate: number;
|
|
@@ -598,17 +599,19 @@ export const borrowV1 = async (
|
|
|
598
599
|
};
|
|
599
600
|
|
|
600
601
|
export const borrowV2 = async (
|
|
601
|
-
lavarageProgram: Program<
|
|
602
|
+
lavarageProgram: Program<LavarageUSDC>,
|
|
602
603
|
offer: ProgramAccount<{
|
|
603
604
|
nodeWallet: PublicKey;
|
|
604
605
|
interestRate: number;
|
|
605
606
|
collateralType: PublicKey;
|
|
607
|
+
feedId: number[];
|
|
606
608
|
}>,
|
|
607
609
|
marginSOL: BN,
|
|
608
610
|
leverage: number,
|
|
609
611
|
randomSeed: Keypair,
|
|
610
612
|
quoteToken: PublicKey,
|
|
611
613
|
tokenProgram: PublicKey,
|
|
614
|
+
apiKeys: ApiKeys,
|
|
612
615
|
partnerFeeRecipient?: PublicKey,
|
|
613
616
|
partnerFeeMarkup?: number,
|
|
614
617
|
computeBudgetMicroLamports?: number,
|
|
@@ -706,9 +709,16 @@ export const borrowV2 = async (
|
|
|
706
709
|
}
|
|
707
710
|
}
|
|
708
711
|
|
|
712
|
+
const updateOracleInstructions = await getUpdateOracleIxs(
|
|
713
|
+
// @ts-expect-error IDL mismatch
|
|
714
|
+
lavarageProgram,
|
|
715
|
+
u8ArrayToString(offer.account.feedId), lavarageProgram.provider.publicKey!,
|
|
716
|
+
apiKeys
|
|
717
|
+
);
|
|
718
|
+
|
|
709
719
|
const tradingOpenBorrowInstruction = useReferral
|
|
710
720
|
? await lavarageProgram.methods
|
|
711
|
-
.
|
|
721
|
+
.tradingOpenBorrow(
|
|
712
722
|
new BN((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
713
723
|
marginSOL,
|
|
714
724
|
new BN(discountBps),
|
|
@@ -829,6 +839,10 @@ export const borrowV2 = async (
|
|
|
829
839
|
)
|
|
830
840
|
.instruction();
|
|
831
841
|
|
|
842
|
+
const baseOracleQuote = getOracleQuoteForFeedId(u8ArrayToString(offer.account.feedId));
|
|
843
|
+
|
|
844
|
+
const quoteOracleQuote = getOracleQuoteForCollateralType(USDC_MINT);
|
|
845
|
+
|
|
832
846
|
const openAddCollateralInstruction = await lavarageProgram.methods
|
|
833
847
|
.tradingOpenAddCollateral(offer.account.interestRate < 255 ? offer.account.interestRate + 1 : 255)
|
|
834
848
|
.accountsStrict({
|
|
@@ -840,7 +854,12 @@ export const borrowV2 = async (
|
|
|
840
854
|
positionAccount,
|
|
841
855
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
842
856
|
tokenProgram: tokenProgram,
|
|
843
|
-
|
|
857
|
+
baseOracleQuote,
|
|
858
|
+
quoteOracleQuote,
|
|
859
|
+
clockSysvar: SYSVAR_CLOCK_PUBKEY,
|
|
860
|
+
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
861
|
+
oracleQueue: queuePubkey,
|
|
862
|
+
slotHashesSysvar: SYSVAR_SLOT_HASHES_PUBKEY,
|
|
844
863
|
})
|
|
845
864
|
.instruction();
|
|
846
865
|
|
|
@@ -852,6 +871,7 @@ export const borrowV2 = async (
|
|
|
852
871
|
fromTokenAccount.instruction!,
|
|
853
872
|
partnerFeeRecipientVaultCreateIx,
|
|
854
873
|
partnerFeeRecipientTokenAccountCreateIx,
|
|
874
|
+
...updateOracleInstructions,
|
|
855
875
|
tradingOpenBorrowInstruction!,
|
|
856
876
|
openAddCollateralInstruction!,
|
|
857
877
|
computeBudgetMicroLamports ? computeFeeIx : undefined,
|
|
@@ -925,7 +945,7 @@ export const borrowV2 = async (
|
|
|
925
945
|
*/
|
|
926
946
|
|
|
927
947
|
export const openTradeV1 = async (
|
|
928
|
-
lavarageProgram: Program<
|
|
948
|
+
lavarageProgram: Program<LavarageSOL>,
|
|
929
949
|
offer: ProgramAccount<{
|
|
930
950
|
nodeWallet: PublicKey;
|
|
931
951
|
interestRate: number;
|
|
@@ -952,7 +972,7 @@ export const openTradeV1 = async (
|
|
|
952
972
|
optionalRPCResults?: OptionalRPCResults,
|
|
953
973
|
) => {
|
|
954
974
|
let partnerFeeMarkupAsPkey;
|
|
955
|
-
const referralVaultProgram = new Program<UserVault>(userVaultIDL,
|
|
975
|
+
const referralVaultProgram = new Program<UserVault>(userVaultIDL, lavarageProgram.provider);
|
|
956
976
|
if (partnerFeeMarkup) {
|
|
957
977
|
const feeBuffer = Buffer.alloc(8);
|
|
958
978
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
@@ -1303,11 +1323,12 @@ export const openTradeV1 = async (
|
|
|
1303
1323
|
*/
|
|
1304
1324
|
|
|
1305
1325
|
export const openTradeV2 = async (
|
|
1306
|
-
lavarageProgram: Program<
|
|
1326
|
+
lavarageProgram: Program<LavarageUSDC>,
|
|
1307
1327
|
offer: ProgramAccount<{
|
|
1308
1328
|
nodeWallet: PublicKey;
|
|
1309
1329
|
interestRate: number;
|
|
1310
1330
|
collateralType: PublicKey;
|
|
1331
|
+
feedId: number[];
|
|
1311
1332
|
}>,
|
|
1312
1333
|
jupInstruction: {
|
|
1313
1334
|
instructions: {
|
|
@@ -1321,6 +1342,7 @@ export const openTradeV2 = async (
|
|
|
1321
1342
|
randomSeed: Keypair,
|
|
1322
1343
|
quoteToken: PublicKey,
|
|
1323
1344
|
tokenProgram: PublicKey,
|
|
1345
|
+
apiKeys: ApiKeys,
|
|
1324
1346
|
partnerFeeRecipient?: PublicKey,
|
|
1325
1347
|
partnerFeeMarkup?: number,
|
|
1326
1348
|
computeBudgetMicroLamports?: number,
|
|
@@ -1331,7 +1353,7 @@ export const openTradeV2 = async (
|
|
|
1331
1353
|
optionalRPCResults?: OptionalRPCResults,
|
|
1332
1354
|
) => {
|
|
1333
1355
|
let partnerFeeMarkupAsPkey;
|
|
1334
|
-
const referralVaultProgram = new Program<UserVault>(userVaultIDL,
|
|
1356
|
+
const referralVaultProgram = new Program<UserVault>(userVaultIDL, lavarageProgram.provider);
|
|
1335
1357
|
|
|
1336
1358
|
if (partnerFeeMarkup) {
|
|
1337
1359
|
const feeBuffer = Buffer.alloc(8);
|
|
@@ -1524,9 +1546,16 @@ export const openTradeV2 = async (
|
|
|
1524
1546
|
|
|
1525
1547
|
|
|
1526
1548
|
|
|
1549
|
+
const updateOracleInstructions = await getUpdateOracleIxs(
|
|
1550
|
+
// @ts-expect-error IDL mismatch
|
|
1551
|
+
lavarageProgram,
|
|
1552
|
+
u8ArrayToString(offer.account.feedId), lavarageProgram.provider.publicKey!,
|
|
1553
|
+
apiKeys
|
|
1554
|
+
);
|
|
1555
|
+
|
|
1527
1556
|
const tradingOpenBorrowInstruction = useReferral
|
|
1528
1557
|
? await lavarageProgram.methods
|
|
1529
|
-
.
|
|
1558
|
+
.tradingOpenBorrow(
|
|
1530
1559
|
new BN((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
1531
1560
|
marginSOL,
|
|
1532
1561
|
new BN(discountBps),
|
|
@@ -1642,6 +1671,10 @@ export const openTradeV2 = async (
|
|
|
1642
1671
|
)
|
|
1643
1672
|
.instruction();
|
|
1644
1673
|
|
|
1674
|
+
const baseOracleQuote = getOracleQuoteForFeedId(u8ArrayToString(offer.account.feedId));
|
|
1675
|
+
|
|
1676
|
+
const quoteOracleQuote = getOracleQuoteForCollateralType(USDC_MINT);
|
|
1677
|
+
|
|
1645
1678
|
const openAddCollateralInstruction = await lavarageProgram.methods
|
|
1646
1679
|
.tradingOpenAddCollateral(offer.account.interestRate < 255 ? offer.account.interestRate + 1 : 255)
|
|
1647
1680
|
.accountsStrict({
|
|
@@ -1653,7 +1686,12 @@ export const openTradeV2 = async (
|
|
|
1653
1686
|
positionAccount,
|
|
1654
1687
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
1655
1688
|
tokenProgram: tokenProgram,
|
|
1656
|
-
|
|
1689
|
+
baseOracleQuote,
|
|
1690
|
+
quoteOracleQuote,
|
|
1691
|
+
clockSysvar: SYSVAR_CLOCK_PUBKEY,
|
|
1692
|
+
slotHashesSysvar: SYSVAR_SLOT_HASHES_PUBKEY,
|
|
1693
|
+
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1694
|
+
oracleQueue: queuePubkey,
|
|
1657
1695
|
})
|
|
1658
1696
|
.instruction();
|
|
1659
1697
|
|
|
@@ -1676,6 +1714,7 @@ export const openTradeV2 = async (
|
|
|
1676
1714
|
].filter(Boolean) as TransactionInstruction[];
|
|
1677
1715
|
|
|
1678
1716
|
const allInstructions = [
|
|
1717
|
+
...updateOracleInstructions,
|
|
1679
1718
|
tradingOpenBorrowInstruction!,
|
|
1680
1719
|
deserializeInstruction(swapInstructionPayload), ,
|
|
1681
1720
|
openAddCollateralInstruction!,
|
|
@@ -1767,7 +1806,7 @@ export const openTradeV2 = async (
|
|
|
1767
1806
|
*/
|
|
1768
1807
|
|
|
1769
1808
|
export const createTpDelegate = async (
|
|
1770
|
-
lavarageProgram: Program<
|
|
1809
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
1771
1810
|
position: ProgramAccount<{
|
|
1772
1811
|
pool: PublicKey;
|
|
1773
1812
|
seed: PublicKey;
|
|
@@ -1866,7 +1905,7 @@ export const createTpDelegate = async (
|
|
|
1866
1905
|
*/
|
|
1867
1906
|
|
|
1868
1907
|
export const modifyTpDelegate = async (
|
|
1869
|
-
lavarageProgram: Program<
|
|
1908
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
1870
1909
|
position: ProgramAccount<{
|
|
1871
1910
|
pool: PublicKey;
|
|
1872
1911
|
seed: PublicKey;
|
|
@@ -1969,7 +2008,7 @@ export const modifyTpDelegate = async (
|
|
|
1969
2008
|
*/
|
|
1970
2009
|
|
|
1971
2010
|
export const removeTpDelegate = async (
|
|
1972
|
-
lavarageProgram: Program<
|
|
2011
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
1973
2012
|
position: ProgramAccount<{
|
|
1974
2013
|
pool: PublicKey;
|
|
1975
2014
|
seed: PublicKey;
|
|
@@ -2034,7 +2073,7 @@ export const removeTpDelegate = async (
|
|
|
2034
2073
|
*/
|
|
2035
2074
|
|
|
2036
2075
|
export const partialRepayV1 = async (
|
|
2037
|
-
lavarageProgram: Program<
|
|
2076
|
+
lavarageProgram: Program<LavarageSOL>,
|
|
2038
2077
|
position: ProgramAccount<{
|
|
2039
2078
|
pool: PublicKey;
|
|
2040
2079
|
seed: PublicKey;
|
|
@@ -2095,7 +2134,7 @@ export const partialRepayV1 = async (
|
|
|
2095
2134
|
* @see {@link partialRepayV1} - The V1 version supporting SOL as quote token
|
|
2096
2135
|
*/
|
|
2097
2136
|
export const partialRepayV2 = async (
|
|
2098
|
-
lavarageProgram: Program<
|
|
2137
|
+
lavarageProgram: Program<LavarageUSDC>,
|
|
2099
2138
|
position: ProgramAccount<{
|
|
2100
2139
|
pool: PublicKey;
|
|
2101
2140
|
seed: PublicKey;
|
|
@@ -2184,7 +2223,7 @@ export const partialRepayV2 = async (
|
|
|
2184
2223
|
* @see {@link partialRepayV1} - Partial repayments on V1
|
|
2185
2224
|
*/
|
|
2186
2225
|
export const closeTradeV1 = async (
|
|
2187
|
-
lavarageProgram: Program<
|
|
2226
|
+
lavarageProgram: Program<LavarageSOL>,
|
|
2188
2227
|
position: ProgramAccount<{
|
|
2189
2228
|
pool: PublicKey;
|
|
2190
2229
|
seed: PublicKey;
|
|
@@ -2215,7 +2254,7 @@ export const closeTradeV1 = async (
|
|
|
2215
2254
|
referralBps?: number,
|
|
2216
2255
|
) => {
|
|
2217
2256
|
let partnerFeeMarkupAsPkey;
|
|
2218
|
-
const referralVaultProgram = new Program<UserVault>(userVaultIDL,
|
|
2257
|
+
const referralVaultProgram = new Program<UserVault>(userVaultIDL, lavarageProgram.provider);
|
|
2219
2258
|
|
|
2220
2259
|
if (partnerFeeMarkup) {
|
|
2221
2260
|
const feeBuffer = Buffer.alloc(8);
|
|
@@ -2613,7 +2652,7 @@ export const closeTradeV1 = async (
|
|
|
2613
2652
|
* @see {@link partialRepayV2} - Partial repay a V2 position
|
|
2614
2653
|
*/
|
|
2615
2654
|
export const closeTradeV2 = async (
|
|
2616
|
-
lavarageProgram: Program<
|
|
2655
|
+
lavarageProgram: Program<LavarageUSDC>,
|
|
2617
2656
|
position: ProgramAccount<{
|
|
2618
2657
|
pool: PublicKey;
|
|
2619
2658
|
seed: PublicKey;
|
|
@@ -2645,7 +2684,7 @@ export const closeTradeV2 = async (
|
|
|
2645
2684
|
referralBps?: number,
|
|
2646
2685
|
) => {
|
|
2647
2686
|
let partnerFeeMarkupAsPkey;
|
|
2648
|
-
const referralVaultProgram = new Program<UserVault>(userVaultIDL,
|
|
2687
|
+
const referralVaultProgram = new Program<UserVault>(userVaultIDL, lavarageProgram.provider);
|
|
2649
2688
|
|
|
2650
2689
|
if (partnerFeeMarkup) {
|
|
2651
2690
|
const feeBuffer = Buffer.alloc(8);
|
|
@@ -2814,7 +2853,7 @@ export const closeTradeV2 = async (
|
|
|
2814
2853
|
if (jupInstruction.instructions == undefined) {
|
|
2815
2854
|
repaySolIx = useReferral
|
|
2816
2855
|
? await lavarageProgram.methods
|
|
2817
|
-
.
|
|
2856
|
+
.tradingCloseRepaySol(
|
|
2818
2857
|
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2819
2858
|
new BN(9997),
|
|
2820
2859
|
new BN(discountBps),
|
|
@@ -2925,7 +2964,7 @@ export const closeTradeV2 = async (
|
|
|
2925
2964
|
} else {
|
|
2926
2965
|
repaySolIx = useReferral
|
|
2927
2966
|
? await lavarageProgram.methods
|
|
2928
|
-
.
|
|
2967
|
+
.tradingCloseRepaySol(
|
|
2929
2968
|
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2930
2969
|
new BN(9998),
|
|
2931
2970
|
new BN(discountBps),
|
|
@@ -3170,7 +3209,7 @@ export const closeTradeV2 = async (
|
|
|
3170
3209
|
* @see {@link removeTpDelegate} - Remove take-profit settings
|
|
3171
3210
|
*/
|
|
3172
3211
|
export const getDelegateAccounts = async (
|
|
3173
|
-
lavarageProgram: Program<
|
|
3212
|
+
lavarageProgram: Program<LavarageSOL> | Program<LavarageUSDC>,
|
|
3174
3213
|
userPubKey?: PublicKey
|
|
3175
3214
|
) => {
|
|
3176
3215
|
const delegateAccounts = await lavarageProgram.account.delegate.all(
|
|
@@ -3239,7 +3278,7 @@ const getQuoteCurrencySpecificAddressLookupTable = (quoteCurrency: string) => {
|
|
|
3239
3278
|
* @see {@link mergePositionV2} - Merge two positions into one
|
|
3240
3279
|
*/
|
|
3241
3280
|
export const splitPositionV2 = async (
|
|
3242
|
-
lavarageProgram: Program<
|
|
3281
|
+
lavarageProgram: Program<LavarageUSDC> | Program<LavarageSOL>,
|
|
3243
3282
|
position: ProgramAccount<{
|
|
3244
3283
|
pool: PublicKey;
|
|
3245
3284
|
seed: PublicKey;
|
|
@@ -3399,7 +3438,7 @@ export const splitPositionV2 = async (
|
|
|
3399
3438
|
* @see {@link splitPositionV2} - Split a position into two
|
|
3400
3439
|
*/
|
|
3401
3440
|
export const mergePositionV2 = async (
|
|
3402
|
-
lavarageProgram: Program<
|
|
3441
|
+
lavarageProgram: Program<LavarageUSDC>,
|
|
3403
3442
|
position1: ProgramAccount<{
|
|
3404
3443
|
pool: PublicKey;
|
|
3405
3444
|
seed: PublicKey;
|