@lavarage/sdk 7.5.7 → 7.5.9
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/dist/index.d.mts +148 -2
- package/dist/index.d.ts +148 -2
- package/dist/index.js +355 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +355 -6
- 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/idl/lavarage.ts +126 -0
- package/idl/lavaragev2.ts +166 -0
- package/index.ts +437 -176
- package/package.json +2 -2
package/index.ts
CHANGED
|
@@ -2128,8 +2128,12 @@ export const closeTradeV1 = async (
|
|
|
2128
2128
|
computeBudgetMicroLamports?: number,
|
|
2129
2129
|
platformFeeRecipient?: PublicKey,
|
|
2130
2130
|
splitTransactions?: boolean,
|
|
2131
|
+
discountBps?: number,
|
|
2132
|
+
referralBps?: number,
|
|
2131
2133
|
) => {
|
|
2132
2134
|
let partnerFeeMarkupAsPkey;
|
|
2135
|
+
const referralVaultProgram = new Program<UserVault>(userVaultIDL, REFFERAL_VAULT_PROGRAM_ID, lavarageProgram.provider);
|
|
2136
|
+
|
|
2133
2137
|
if (partnerFeeMarkup) {
|
|
2134
2138
|
const feeBuffer = Buffer.alloc(8);
|
|
2135
2139
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
@@ -2216,6 +2220,31 @@ export const closeTradeV1 = async (
|
|
|
2216
2220
|
const { blockhash } =
|
|
2217
2221
|
await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
2218
2222
|
|
|
2223
|
+
const useReferral = discountBps !== undefined && referralBps !== undefined;
|
|
2224
|
+
|
|
2225
|
+
// Check if partner fee recipient vault needs to be initialized via referralVaultProgram
|
|
2226
|
+
let partnerFeeRecipientCreateIx: TransactionInstruction | undefined;
|
|
2227
|
+
let userVaultPda: PublicKey | undefined;
|
|
2228
|
+
if (partnerFeeRecipient && referralBps !== undefined && referralVaultProgram) {
|
|
2229
|
+
[userVaultPda] = PublicKey.findProgramAddressSync(
|
|
2230
|
+
[Buffer.from("user_vault"), new PublicKey(partnerFeeRecipient).toBuffer()],
|
|
2231
|
+
referralVaultProgram.programId
|
|
2232
|
+
);
|
|
2233
|
+
const vaultAccountInfo = await lavarageProgram.provider.connection.getAccountInfo(userVaultPda);
|
|
2234
|
+
if (!vaultAccountInfo) {
|
|
2235
|
+
// Initialize the vault using referralVaultProgram
|
|
2236
|
+
partnerFeeRecipientCreateIx = await referralVaultProgram.methods
|
|
2237
|
+
.initializeVault()
|
|
2238
|
+
.accountsStrict({
|
|
2239
|
+
userVault: userVaultPda,
|
|
2240
|
+
user: partnerFeeRecipient!,
|
|
2241
|
+
funder: lavarageProgram.provider.publicKey!,
|
|
2242
|
+
systemProgram: SystemProgram.programId,
|
|
2243
|
+
})
|
|
2244
|
+
.instruction();
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2219
2248
|
const closePositionIx = await lavarageProgram.methods
|
|
2220
2249
|
.tradingCloseBorrowCollateral()
|
|
2221
2250
|
.accountsStrict({
|
|
@@ -2236,71 +2265,131 @@ export const closeTradeV1 = async (
|
|
|
2236
2265
|
let repaySolIx: TransactionInstruction | null = null;
|
|
2237
2266
|
let jupiterIxs: TransactionInstruction[] = [];
|
|
2238
2267
|
if (jupInstruction.instructions == undefined) {
|
|
2239
|
-
repaySolIx =
|
|
2240
|
-
.
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2268
|
+
repaySolIx = useReferral
|
|
2269
|
+
? await lavarageProgram.methods
|
|
2270
|
+
.tradingCloseRepaySolWithReferral(
|
|
2271
|
+
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2272
|
+
new BN(9997),
|
|
2273
|
+
new BN(discountBps),
|
|
2274
|
+
new BN(referralBps)
|
|
2275
|
+
)
|
|
2276
|
+
.accountsStrict({
|
|
2277
|
+
nodeWallet: pool.account.nodeWallet,
|
|
2278
|
+
positionAccount: positionAccountPDA,
|
|
2279
|
+
tradingPool: poolPubKey,
|
|
2280
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
2281
|
+
systemProgram: SystemProgram.programId,
|
|
2282
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2283
|
+
randomAccountAsId: position.account.seed,
|
|
2284
|
+
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF",
|
|
2285
|
+
})
|
|
2286
|
+
.remainingAccounts(
|
|
2287
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda
|
|
2288
|
+
? [
|
|
2289
|
+
{
|
|
2290
|
+
pubkey: userVaultPda,
|
|
2291
|
+
isSigner: false,
|
|
2292
|
+
isWritable: true,
|
|
2293
|
+
}
|
|
2294
|
+
]
|
|
2295
|
+
: []
|
|
2296
|
+
)
|
|
2297
|
+
.instruction()
|
|
2298
|
+
: await lavarageProgram.methods
|
|
2299
|
+
.tradingCloseRepaySol(
|
|
2300
|
+
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2301
|
+
new BN(9997)
|
|
2302
|
+
)
|
|
2303
|
+
.accountsStrict({
|
|
2304
|
+
nodeWallet: pool.account.nodeWallet,
|
|
2305
|
+
positionAccount: positionAccountPDA,
|
|
2306
|
+
tradingPool: poolPubKey,
|
|
2307
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
2308
|
+
systemProgram: SystemProgram.programId,
|
|
2309
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2310
|
+
randomAccountAsId: position.account.seed,
|
|
2311
|
+
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF",
|
|
2312
|
+
})
|
|
2313
|
+
.remainingAccounts(
|
|
2314
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey
|
|
2315
|
+
? [
|
|
2316
|
+
{
|
|
2317
|
+
pubkey: partnerFeeRecipient,
|
|
2318
|
+
isSigner: false,
|
|
2319
|
+
isWritable: true,
|
|
2320
|
+
},
|
|
2321
|
+
{
|
|
2322
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
2323
|
+
isSigner: false,
|
|
2324
|
+
isWritable: false,
|
|
2325
|
+
},
|
|
2326
|
+
]
|
|
2327
|
+
: []
|
|
2328
|
+
)
|
|
2329
|
+
.instruction();
|
|
2271
2330
|
} else {
|
|
2272
|
-
repaySolIx =
|
|
2273
|
-
.
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2331
|
+
repaySolIx = useReferral
|
|
2332
|
+
? await lavarageProgram.methods
|
|
2333
|
+
.tradingCloseRepaySolWithReferral(
|
|
2334
|
+
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2335
|
+
new BN(9998),
|
|
2336
|
+
new BN(discountBps),
|
|
2337
|
+
new BN(referralBps)
|
|
2338
|
+
)
|
|
2339
|
+
.accountsStrict({
|
|
2340
|
+
nodeWallet: pool.account.nodeWallet,
|
|
2341
|
+
positionAccount: positionAccountPDA,
|
|
2342
|
+
tradingPool: poolPubKey,
|
|
2343
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
2344
|
+
systemProgram: SystemProgram.programId,
|
|
2345
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2346
|
+
randomAccountAsId: position.account.seed,
|
|
2347
|
+
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF",
|
|
2348
|
+
})
|
|
2349
|
+
.remainingAccounts(
|
|
2350
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda
|
|
2351
|
+
? [
|
|
2352
|
+
{
|
|
2353
|
+
pubkey: userVaultPda,
|
|
2354
|
+
isSigner: false,
|
|
2355
|
+
isWritable: true,
|
|
2356
|
+
}
|
|
2357
|
+
]
|
|
2358
|
+
: []
|
|
2359
|
+
)
|
|
2360
|
+
.instruction()
|
|
2361
|
+
: await lavarageProgram.methods
|
|
2362
|
+
.tradingCloseRepaySol(
|
|
2363
|
+
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2364
|
+
new BN(9998)
|
|
2365
|
+
)
|
|
2366
|
+
.accountsStrict({
|
|
2367
|
+
nodeWallet: pool.account.nodeWallet,
|
|
2368
|
+
positionAccount: positionAccountPDA,
|
|
2369
|
+
tradingPool: poolPubKey,
|
|
2370
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
2371
|
+
systemProgram: SystemProgram.programId,
|
|
2372
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2373
|
+
randomAccountAsId: position.account.seed,
|
|
2374
|
+
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF",
|
|
2375
|
+
})
|
|
2376
|
+
.remainingAccounts(
|
|
2377
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey
|
|
2378
|
+
? [
|
|
2379
|
+
{
|
|
2380
|
+
pubkey: partnerFeeRecipient,
|
|
2381
|
+
isSigner: false,
|
|
2382
|
+
isWritable: true,
|
|
2383
|
+
},
|
|
2384
|
+
{
|
|
2385
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
2386
|
+
isSigner: false,
|
|
2387
|
+
isWritable: false,
|
|
2388
|
+
},
|
|
2389
|
+
]
|
|
2390
|
+
: []
|
|
2391
|
+
)
|
|
2392
|
+
.instruction();
|
|
2304
2393
|
|
|
2305
2394
|
const {
|
|
2306
2395
|
setupInstructions,
|
|
@@ -2339,6 +2428,7 @@ export const closeTradeV1 = async (
|
|
|
2339
2428
|
|
|
2340
2429
|
if (splitTransactions) {
|
|
2341
2430
|
const setUpInstructions = [
|
|
2431
|
+
partnerFeeRecipientCreateIx,
|
|
2342
2432
|
jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
|
|
2343
2433
|
createAssociatedTokenAccountInstruction
|
|
2344
2434
|
].filter((i) => !!i);
|
|
@@ -2375,6 +2465,7 @@ export const closeTradeV1 = async (
|
|
|
2375
2465
|
}
|
|
2376
2466
|
|
|
2377
2467
|
const allInstructions = [
|
|
2468
|
+
partnerFeeRecipientCreateIx,
|
|
2378
2469
|
jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
|
|
2379
2470
|
createAssociatedTokenAccountInstruction,
|
|
2380
2471
|
jupInstruction.instructions?.tokenLedgerInstruction
|
|
@@ -2464,8 +2555,12 @@ export const closeTradeV2 = async (
|
|
|
2464
2555
|
computeBudgetMicroLamports?: number,
|
|
2465
2556
|
platformFeeRecipient?: PublicKey,
|
|
2466
2557
|
splitTransactions?: boolean,
|
|
2558
|
+
discountBps?: number,
|
|
2559
|
+
referralBps?: number,
|
|
2467
2560
|
) => {
|
|
2468
2561
|
let partnerFeeMarkupAsPkey;
|
|
2562
|
+
const referralVaultProgram = new Program<UserVault>(userVaultIDL, REFFERAL_VAULT_PROGRAM_ID, lavarageProgram.provider);
|
|
2563
|
+
|
|
2469
2564
|
if (partnerFeeMarkup) {
|
|
2470
2565
|
const feeBuffer = Buffer.alloc(8);
|
|
2471
2566
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
@@ -2556,6 +2651,60 @@ export const closeTradeV2 = async (
|
|
|
2556
2651
|
const { blockhash } =
|
|
2557
2652
|
await lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
2558
2653
|
|
|
2654
|
+
const useReferral = discountBps !== undefined && referralBps !== undefined;
|
|
2655
|
+
|
|
2656
|
+
// Check if partner fee recipient vault and token account need to be created
|
|
2657
|
+
let partnerFeeRecipientVaultCreateIx: TransactionInstruction | undefined;
|
|
2658
|
+
let partnerFeeRecipientTokenAccountCreateIx: TransactionInstruction | undefined;
|
|
2659
|
+
let userVaultPda: PublicKey | undefined;
|
|
2660
|
+
|
|
2661
|
+
if (partnerFeeRecipient && partnerFeeMarkupAsPkey && referralVaultProgram) {
|
|
2662
|
+
// Derive the userVault PDA
|
|
2663
|
+
[userVaultPda] = PublicKey.findProgramAddressSync(
|
|
2664
|
+
[Buffer.from("user_vault"), new PublicKey(partnerFeeRecipient).toBuffer()],
|
|
2665
|
+
referralVaultProgram.programId
|
|
2666
|
+
);
|
|
2667
|
+
|
|
2668
|
+
// Get the vault's associated token account
|
|
2669
|
+
const vaultTokenAccount = getAssociatedTokenAddressSync(
|
|
2670
|
+
quoteToken,
|
|
2671
|
+
userVaultPda,
|
|
2672
|
+
true, // allowOwnerOffCurve for PDA
|
|
2673
|
+
quoteTokenProgram
|
|
2674
|
+
);
|
|
2675
|
+
|
|
2676
|
+
// Check both accounts at the same time
|
|
2677
|
+
const [vaultAccountInfo, vaultTokenAccountInfo] = await lavarageProgram.provider.connection.getMultipleAccountsInfo([
|
|
2678
|
+
userVaultPda,
|
|
2679
|
+
vaultTokenAccount
|
|
2680
|
+
]);
|
|
2681
|
+
|
|
2682
|
+
// Create vault if it doesn't exist
|
|
2683
|
+
if (!vaultAccountInfo) {
|
|
2684
|
+
partnerFeeRecipientVaultCreateIx = await referralVaultProgram.methods
|
|
2685
|
+
.initializeVault()
|
|
2686
|
+
.accountsStrict({
|
|
2687
|
+
userVault: userVaultPda,
|
|
2688
|
+
user: partnerFeeRecipient!,
|
|
2689
|
+
funder: lavarageProgram.provider.publicKey!,
|
|
2690
|
+
systemProgram: SystemProgram.programId,
|
|
2691
|
+
})
|
|
2692
|
+
.instruction();
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
// Create token account if it doesn't exist
|
|
2696
|
+
if (!vaultTokenAccountInfo) {
|
|
2697
|
+
partnerFeeRecipientTokenAccountCreateIx = createAssociatedTokenAccountIdempotentInstruction(
|
|
2698
|
+
lavarageProgram.provider.publicKey!,
|
|
2699
|
+
vaultTokenAccount,
|
|
2700
|
+
userVaultPda,
|
|
2701
|
+
quoteToken,
|
|
2702
|
+
quoteTokenProgram,
|
|
2703
|
+
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
2704
|
+
);
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2559
2708
|
const closePositionIx = await lavarageProgram.methods
|
|
2560
2709
|
.tradingCloseBorrowCollateral()
|
|
2561
2710
|
.accountsStrict({
|
|
@@ -2576,119 +2725,227 @@ export const closeTradeV2 = async (
|
|
|
2576
2725
|
let repaySolIx: TransactionInstruction | null = null;
|
|
2577
2726
|
let jupiterIxs: TransactionInstruction[] = [];
|
|
2578
2727
|
if (jupInstruction.instructions == undefined) {
|
|
2579
|
-
repaySolIx =
|
|
2580
|
-
.
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2728
|
+
repaySolIx = useReferral
|
|
2729
|
+
? await lavarageProgram.methods
|
|
2730
|
+
.tradingCloseRepaySolWithReferral(
|
|
2731
|
+
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2732
|
+
new BN(9997),
|
|
2733
|
+
new BN(discountBps),
|
|
2734
|
+
new BN(referralBps)
|
|
2735
|
+
)
|
|
2736
|
+
.accountsStrict({
|
|
2737
|
+
nodeWallet: pool.account.nodeWallet,
|
|
2738
|
+
positionAccount: positionAccountPDA,
|
|
2739
|
+
tradingPool: poolPubKey,
|
|
2740
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
2741
|
+
systemProgram: SystemProgram.programId,
|
|
2742
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2743
|
+
randomAccountAsId: position.account.seed,
|
|
2744
|
+
feeTokenAccount: getAssociatedTokenAddressSync(
|
|
2745
|
+
quoteToken,
|
|
2746
|
+
new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
2747
|
+
false,
|
|
2748
|
+
quoteTokenProgram
|
|
2749
|
+
),
|
|
2750
|
+
fromTokenAccount: getAssociatedTokenAddressSync(
|
|
2751
|
+
quoteToken,
|
|
2752
|
+
lavarageProgram.provider.publicKey!,
|
|
2753
|
+
false,
|
|
2754
|
+
quoteTokenProgram
|
|
2755
|
+
),
|
|
2756
|
+
tokenProgram: quoteTokenProgram!,
|
|
2757
|
+
toTokenAccount: getAssociatedTokenAddressSync(
|
|
2758
|
+
quoteToken,
|
|
2759
|
+
pool.account.nodeWallet,
|
|
2760
|
+
true,
|
|
2761
|
+
quoteTokenProgram
|
|
2762
|
+
),
|
|
2763
|
+
mint: quoteToken,
|
|
2764
|
+
})
|
|
2765
|
+
.remainingAccounts(
|
|
2766
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda
|
|
2767
|
+
? [
|
|
2768
|
+
{
|
|
2769
|
+
pubkey: getAssociatedTokenAddressSync(
|
|
2770
|
+
quoteToken,
|
|
2771
|
+
userVaultPda,
|
|
2772
|
+
true, // allowOwnerOffCurve for PDA
|
|
2773
|
+
quoteTokenProgram
|
|
2774
|
+
),
|
|
2775
|
+
isSigner: false,
|
|
2776
|
+
isWritable: true,
|
|
2777
|
+
}
|
|
2778
|
+
]
|
|
2779
|
+
: []
|
|
2780
|
+
)
|
|
2781
|
+
.instruction()
|
|
2782
|
+
: await lavarageProgram.methods
|
|
2783
|
+
.tradingCloseRepaySol(
|
|
2784
|
+
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2785
|
+
new BN(9997)
|
|
2786
|
+
)
|
|
2787
|
+
.accountsStrict({
|
|
2788
|
+
nodeWallet: pool.account.nodeWallet,
|
|
2789
|
+
positionAccount: positionAccountPDA,
|
|
2790
|
+
tradingPool: poolPubKey,
|
|
2791
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
2792
|
+
systemProgram: SystemProgram.programId,
|
|
2793
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2794
|
+
randomAccountAsId: position.account.seed,
|
|
2795
|
+
feeTokenAccount: getAssociatedTokenAddressSync(
|
|
2796
|
+
quoteToken,
|
|
2797
|
+
new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
2798
|
+
false,
|
|
2799
|
+
quoteTokenProgram
|
|
2800
|
+
),
|
|
2801
|
+
fromTokenAccount: getAssociatedTokenAddressSync(
|
|
2802
|
+
quoteToken,
|
|
2803
|
+
lavarageProgram.provider.publicKey!,
|
|
2804
|
+
false,
|
|
2805
|
+
quoteTokenProgram
|
|
2806
|
+
),
|
|
2807
|
+
tokenProgram: quoteTokenProgram!,
|
|
2808
|
+
toTokenAccount: getAssociatedTokenAddressSync(
|
|
2809
|
+
quoteToken,
|
|
2810
|
+
pool.account.nodeWallet,
|
|
2811
|
+
true,
|
|
2812
|
+
quoteTokenProgram
|
|
2813
|
+
),
|
|
2814
|
+
mint: quoteToken,
|
|
2815
|
+
})
|
|
2816
|
+
.remainingAccounts(
|
|
2817
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey
|
|
2818
|
+
? [
|
|
2819
|
+
{
|
|
2820
|
+
pubkey: getAssociatedTokenAddressSync(
|
|
2821
|
+
quoteToken,
|
|
2822
|
+
partnerFeeRecipient,
|
|
2823
|
+
false,
|
|
2824
|
+
quoteTokenProgram
|
|
2825
|
+
),
|
|
2826
|
+
isSigner: false,
|
|
2827
|
+
isWritable: true,
|
|
2828
|
+
},
|
|
2829
|
+
{
|
|
2830
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
2831
|
+
isSigner: false,
|
|
2832
|
+
isWritable: false,
|
|
2833
|
+
},
|
|
2834
|
+
]
|
|
2835
|
+
: []
|
|
2836
|
+
)
|
|
2837
|
+
.instruction();
|
|
2635
2838
|
} else {
|
|
2636
|
-
repaySolIx =
|
|
2637
|
-
.
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2839
|
+
repaySolIx = useReferral
|
|
2840
|
+
? await lavarageProgram.methods
|
|
2841
|
+
.tradingCloseRepaySolWithReferral(
|
|
2842
|
+
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2843
|
+
new BN(9998),
|
|
2844
|
+
new BN(discountBps),
|
|
2845
|
+
new BN(referralBps)
|
|
2846
|
+
)
|
|
2847
|
+
.accountsStrict({
|
|
2848
|
+
nodeWallet: pool.account.nodeWallet,
|
|
2849
|
+
positionAccount: positionAccountPDA,
|
|
2850
|
+
tradingPool: poolPubKey,
|
|
2851
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
2852
|
+
systemProgram: SystemProgram.programId,
|
|
2853
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2854
|
+
randomAccountAsId: position.account.seed,
|
|
2855
|
+
feeTokenAccount: getAssociatedTokenAddressSync(
|
|
2856
|
+
quoteToken,
|
|
2857
|
+
new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
2858
|
+
false,
|
|
2859
|
+
quoteTokenProgram
|
|
2860
|
+
),
|
|
2861
|
+
fromTokenAccount: getAssociatedTokenAddressSync(
|
|
2862
|
+
quoteToken,
|
|
2863
|
+
lavarageProgram.provider.publicKey!,
|
|
2864
|
+
false,
|
|
2865
|
+
quoteTokenProgram
|
|
2866
|
+
),
|
|
2867
|
+
tokenProgram: quoteTokenProgram!,
|
|
2868
|
+
toTokenAccount: getAssociatedTokenAddressSync(
|
|
2869
|
+
quoteToken,
|
|
2870
|
+
pool.account.nodeWallet,
|
|
2871
|
+
true,
|
|
2872
|
+
quoteTokenProgram
|
|
2873
|
+
),
|
|
2874
|
+
mint: quoteToken,
|
|
2875
|
+
})
|
|
2876
|
+
.remainingAccounts(
|
|
2877
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda
|
|
2878
|
+
? [
|
|
2879
|
+
{
|
|
2880
|
+
pubkey: getAssociatedTokenAddressSync(
|
|
2881
|
+
quoteToken,
|
|
2882
|
+
userVaultPda,
|
|
2883
|
+
true, // allowOwnerOffCurve for PDA
|
|
2884
|
+
quoteTokenProgram
|
|
2885
|
+
),
|
|
2886
|
+
isSigner: false,
|
|
2887
|
+
isWritable: true,
|
|
2888
|
+
}
|
|
2889
|
+
]
|
|
2890
|
+
: []
|
|
2891
|
+
)
|
|
2892
|
+
.instruction()
|
|
2893
|
+
: await lavarageProgram.methods
|
|
2894
|
+
.tradingCloseRepaySol(
|
|
2895
|
+
new BN(jupInstruction.quoteResponse.outAmount),
|
|
2896
|
+
new BN(9998)
|
|
2897
|
+
)
|
|
2898
|
+
.accountsStrict({
|
|
2899
|
+
nodeWallet: pool.account.nodeWallet,
|
|
2900
|
+
positionAccount: positionAccountPDA,
|
|
2901
|
+
tradingPool: poolPubKey,
|
|
2902
|
+
trader: lavarageProgram.provider.publicKey!,
|
|
2903
|
+
systemProgram: SystemProgram.programId,
|
|
2904
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2905
|
+
randomAccountAsId: position.account.seed,
|
|
2906
|
+
feeTokenAccount: getAssociatedTokenAddressSync(
|
|
2907
|
+
quoteToken,
|
|
2908
|
+
new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
2909
|
+
false,
|
|
2910
|
+
quoteTokenProgram
|
|
2911
|
+
),
|
|
2912
|
+
fromTokenAccount: getAssociatedTokenAddressSync(
|
|
2913
|
+
quoteToken,
|
|
2914
|
+
lavarageProgram.provider.publicKey!,
|
|
2915
|
+
false,
|
|
2916
|
+
quoteTokenProgram
|
|
2917
|
+
),
|
|
2918
|
+
tokenProgram: quoteTokenProgram!,
|
|
2919
|
+
toTokenAccount: getAssociatedTokenAddressSync(
|
|
2920
|
+
quoteToken,
|
|
2921
|
+
pool.account.nodeWallet,
|
|
2922
|
+
true,
|
|
2923
|
+
quoteTokenProgram
|
|
2924
|
+
),
|
|
2925
|
+
mint: quoteToken,
|
|
2926
|
+
})
|
|
2927
|
+
.remainingAccounts(
|
|
2928
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey
|
|
2929
|
+
? [
|
|
2930
|
+
{
|
|
2931
|
+
pubkey: getAssociatedTokenAddressSync(
|
|
2932
|
+
quoteToken,
|
|
2933
|
+
partnerFeeRecipient,
|
|
2934
|
+
false,
|
|
2935
|
+
quoteTokenProgram
|
|
2936
|
+
),
|
|
2937
|
+
isSigner: false,
|
|
2938
|
+
isWritable: true,
|
|
2939
|
+
},
|
|
2940
|
+
{
|
|
2941
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
2942
|
+
isSigner: false,
|
|
2943
|
+
isWritable: false,
|
|
2944
|
+
},
|
|
2945
|
+
]
|
|
2946
|
+
: []
|
|
2947
|
+
)
|
|
2948
|
+
.instruction();
|
|
2692
2949
|
const {
|
|
2693
2950
|
setupInstructions,
|
|
2694
2951
|
swapInstruction: swapInstructionPayload,
|
|
@@ -2729,6 +2986,8 @@ export const closeTradeV2 = async (
|
|
|
2729
2986
|
|
|
2730
2987
|
if (splitTransactions) {
|
|
2731
2988
|
const setUpInstructions = [
|
|
2989
|
+
partnerFeeRecipientVaultCreateIx,
|
|
2990
|
+
partnerFeeRecipientTokenAccountCreateIx,
|
|
2732
2991
|
jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
|
|
2733
2992
|
createAssociatedTokenAccountInstruction,
|
|
2734
2993
|
].filter((i) => !!i);
|
|
@@ -2765,6 +3024,8 @@ export const closeTradeV2 = async (
|
|
|
2765
3024
|
}
|
|
2766
3025
|
|
|
2767
3026
|
const allInstructions = [
|
|
3027
|
+
partnerFeeRecipientVaultCreateIx,
|
|
3028
|
+
partnerFeeRecipientTokenAccountCreateIx,
|
|
2768
3029
|
jupInstruction.instructions && platformFeeRecipientAccount?.instruction ? platformFeeRecipientAccount.instruction : null,
|
|
2769
3030
|
createAssociatedTokenAccountInstruction,
|
|
2770
3031
|
jupInstruction.instructions?.tokenLedgerInstruction
|