@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/dist/index.mjs
CHANGED
|
@@ -2394,6 +2394,69 @@ var IDL2 = {
|
|
|
2394
2394
|
}
|
|
2395
2395
|
]
|
|
2396
2396
|
},
|
|
2397
|
+
{
|
|
2398
|
+
"name": "tradingCloseRepaySolWithReferral",
|
|
2399
|
+
"accounts": [
|
|
2400
|
+
{
|
|
2401
|
+
"name": "positionAccount",
|
|
2402
|
+
"isMut": true,
|
|
2403
|
+
"isSigner": false
|
|
2404
|
+
},
|
|
2405
|
+
{
|
|
2406
|
+
"name": "trader",
|
|
2407
|
+
"isMut": true,
|
|
2408
|
+
"isSigner": true
|
|
2409
|
+
},
|
|
2410
|
+
{
|
|
2411
|
+
"name": "tradingPool",
|
|
2412
|
+
"isMut": true,
|
|
2413
|
+
"isSigner": false
|
|
2414
|
+
},
|
|
2415
|
+
{
|
|
2416
|
+
"name": "nodeWallet",
|
|
2417
|
+
"isMut": true,
|
|
2418
|
+
"isSigner": false
|
|
2419
|
+
},
|
|
2420
|
+
{
|
|
2421
|
+
"name": "systemProgram",
|
|
2422
|
+
"isMut": false,
|
|
2423
|
+
"isSigner": false
|
|
2424
|
+
},
|
|
2425
|
+
{
|
|
2426
|
+
"name": "clock",
|
|
2427
|
+
"isMut": false,
|
|
2428
|
+
"isSigner": false
|
|
2429
|
+
},
|
|
2430
|
+
{
|
|
2431
|
+
"name": "randomAccountAsId",
|
|
2432
|
+
"isMut": false,
|
|
2433
|
+
"isSigner": false
|
|
2434
|
+
},
|
|
2435
|
+
{
|
|
2436
|
+
"name": "feeReceipient",
|
|
2437
|
+
"isMut": true,
|
|
2438
|
+
"isSigner": false
|
|
2439
|
+
}
|
|
2440
|
+
],
|
|
2441
|
+
"args": [
|
|
2442
|
+
{
|
|
2443
|
+
"name": "closingPositionSize",
|
|
2444
|
+
"type": "u64"
|
|
2445
|
+
},
|
|
2446
|
+
{
|
|
2447
|
+
"name": "closeType",
|
|
2448
|
+
"type": "u64"
|
|
2449
|
+
},
|
|
2450
|
+
{
|
|
2451
|
+
"name": "discountBps",
|
|
2452
|
+
"type": "u64"
|
|
2453
|
+
},
|
|
2454
|
+
{
|
|
2455
|
+
"name": "referralBps",
|
|
2456
|
+
"type": "u64"
|
|
2457
|
+
}
|
|
2458
|
+
]
|
|
2459
|
+
},
|
|
2397
2460
|
{
|
|
2398
2461
|
"name": "tradingClosePartialRepaySol",
|
|
2399
2462
|
"accounts": [
|
|
@@ -4077,6 +4140,89 @@ var IDL3 = {
|
|
|
4077
4140
|
}
|
|
4078
4141
|
]
|
|
4079
4142
|
},
|
|
4143
|
+
{
|
|
4144
|
+
"name": "tradingCloseRepaySolWithReferral",
|
|
4145
|
+
"accounts": [
|
|
4146
|
+
{
|
|
4147
|
+
"name": "positionAccount",
|
|
4148
|
+
"isMut": true,
|
|
4149
|
+
"isSigner": false
|
|
4150
|
+
},
|
|
4151
|
+
{
|
|
4152
|
+
"name": "trader",
|
|
4153
|
+
"isMut": true,
|
|
4154
|
+
"isSigner": true
|
|
4155
|
+
},
|
|
4156
|
+
{
|
|
4157
|
+
"name": "tradingPool",
|
|
4158
|
+
"isMut": true,
|
|
4159
|
+
"isSigner": false
|
|
4160
|
+
},
|
|
4161
|
+
{
|
|
4162
|
+
"name": "nodeWallet",
|
|
4163
|
+
"isMut": true,
|
|
4164
|
+
"isSigner": false
|
|
4165
|
+
},
|
|
4166
|
+
{
|
|
4167
|
+
"name": "systemProgram",
|
|
4168
|
+
"isMut": false,
|
|
4169
|
+
"isSigner": false
|
|
4170
|
+
},
|
|
4171
|
+
{
|
|
4172
|
+
"name": "clock",
|
|
4173
|
+
"isMut": false,
|
|
4174
|
+
"isSigner": false
|
|
4175
|
+
},
|
|
4176
|
+
{
|
|
4177
|
+
"name": "randomAccountAsId",
|
|
4178
|
+
"isMut": false,
|
|
4179
|
+
"isSigner": false
|
|
4180
|
+
},
|
|
4181
|
+
{
|
|
4182
|
+
"name": "mint",
|
|
4183
|
+
"isMut": false,
|
|
4184
|
+
"isSigner": false
|
|
4185
|
+
},
|
|
4186
|
+
{
|
|
4187
|
+
"name": "fromTokenAccount",
|
|
4188
|
+
"isMut": true,
|
|
4189
|
+
"isSigner": false
|
|
4190
|
+
},
|
|
4191
|
+
{
|
|
4192
|
+
"name": "toTokenAccount",
|
|
4193
|
+
"isMut": true,
|
|
4194
|
+
"isSigner": false
|
|
4195
|
+
},
|
|
4196
|
+
{
|
|
4197
|
+
"name": "feeTokenAccount",
|
|
4198
|
+
"isMut": true,
|
|
4199
|
+
"isSigner": false
|
|
4200
|
+
},
|
|
4201
|
+
{
|
|
4202
|
+
"name": "tokenProgram",
|
|
4203
|
+
"isMut": false,
|
|
4204
|
+
"isSigner": false
|
|
4205
|
+
}
|
|
4206
|
+
],
|
|
4207
|
+
"args": [
|
|
4208
|
+
{
|
|
4209
|
+
"name": "closingPositionSize",
|
|
4210
|
+
"type": "u64"
|
|
4211
|
+
},
|
|
4212
|
+
{
|
|
4213
|
+
"name": "closeType",
|
|
4214
|
+
"type": "u64"
|
|
4215
|
+
},
|
|
4216
|
+
{
|
|
4217
|
+
"name": "discountBps",
|
|
4218
|
+
"type": "u64"
|
|
4219
|
+
},
|
|
4220
|
+
{
|
|
4221
|
+
"name": "referralBps",
|
|
4222
|
+
"type": "u64"
|
|
4223
|
+
}
|
|
4224
|
+
]
|
|
4225
|
+
},
|
|
4080
4226
|
{
|
|
4081
4227
|
"name": "tradingPartialRepaySol",
|
|
4082
4228
|
"accounts": [
|
|
@@ -6104,9 +6250,10 @@ var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0
|
|
|
6104
6250
|
}).compileToV0Message();
|
|
6105
6251
|
return new VersionedTransaction2(messageV0);
|
|
6106
6252
|
});
|
|
6107
|
-
var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFeeRecipient, partnerFeeMarkup, computeBudgetMicroLamports, platformFeeRecipient, splitTransactions) => __async(void 0, null, function* () {
|
|
6253
|
+
var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFeeRecipient, partnerFeeMarkup, computeBudgetMicroLamports, platformFeeRecipient, splitTransactions, discountBps, referralBps) => __async(void 0, null, function* () {
|
|
6108
6254
|
var _a, _b;
|
|
6109
6255
|
let partnerFeeMarkupAsPkey;
|
|
6256
|
+
const referralVaultProgram = new Program2(IDL, REFFERAL_VAULT_PROGRAM_ID, lavarageProgram.provider);
|
|
6110
6257
|
if (partnerFeeMarkup) {
|
|
6111
6258
|
const feeBuffer = Buffer.alloc(8);
|
|
6112
6259
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
@@ -6174,6 +6321,24 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
6174
6321
|
});
|
|
6175
6322
|
const addressLookupTableAccounts = [];
|
|
6176
6323
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
6324
|
+
const useReferral = discountBps !== void 0 && referralBps !== void 0;
|
|
6325
|
+
let partnerFeeRecipientCreateIx;
|
|
6326
|
+
let userVaultPda;
|
|
6327
|
+
if (partnerFeeRecipient && referralBps !== void 0 && referralVaultProgram) {
|
|
6328
|
+
[userVaultPda] = PublicKey2.findProgramAddressSync(
|
|
6329
|
+
[Buffer.from("user_vault"), new PublicKey2(partnerFeeRecipient).toBuffer()],
|
|
6330
|
+
referralVaultProgram.programId
|
|
6331
|
+
);
|
|
6332
|
+
const vaultAccountInfo = yield lavarageProgram.provider.connection.getAccountInfo(userVaultPda);
|
|
6333
|
+
if (!vaultAccountInfo) {
|
|
6334
|
+
partnerFeeRecipientCreateIx = yield referralVaultProgram.methods.initializeVault().accountsStrict({
|
|
6335
|
+
userVault: userVaultPda,
|
|
6336
|
+
user: partnerFeeRecipient,
|
|
6337
|
+
funder: lavarageProgram.provider.publicKey,
|
|
6338
|
+
systemProgram: SystemProgram2.programId
|
|
6339
|
+
}).instruction();
|
|
6340
|
+
}
|
|
6341
|
+
}
|
|
6177
6342
|
const closePositionIx = yield lavarageProgram.methods.tradingCloseBorrowCollateral().accountsStrict({
|
|
6178
6343
|
tradingPool: poolPubKey,
|
|
6179
6344
|
instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -6190,7 +6355,29 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
6190
6355
|
let repaySolIx = null;
|
|
6191
6356
|
let jupiterIxs = [];
|
|
6192
6357
|
if (jupInstruction.instructions == void 0) {
|
|
6193
|
-
repaySolIx = yield lavarageProgram.methods.
|
|
6358
|
+
repaySolIx = useReferral ? yield lavarageProgram.methods.tradingCloseRepaySolWithReferral(
|
|
6359
|
+
new BN2(jupInstruction.quoteResponse.outAmount),
|
|
6360
|
+
new BN2(9997),
|
|
6361
|
+
new BN2(discountBps),
|
|
6362
|
+
new BN2(referralBps)
|
|
6363
|
+
).accountsStrict({
|
|
6364
|
+
nodeWallet: pool.account.nodeWallet,
|
|
6365
|
+
positionAccount: positionAccountPDA,
|
|
6366
|
+
tradingPool: poolPubKey,
|
|
6367
|
+
trader: lavarageProgram.provider.publicKey,
|
|
6368
|
+
systemProgram: SystemProgram2.programId,
|
|
6369
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
6370
|
+
randomAccountAsId: position.account.seed,
|
|
6371
|
+
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
6372
|
+
}).remainingAccounts(
|
|
6373
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
6374
|
+
{
|
|
6375
|
+
pubkey: userVaultPda,
|
|
6376
|
+
isSigner: false,
|
|
6377
|
+
isWritable: true
|
|
6378
|
+
}
|
|
6379
|
+
] : []
|
|
6380
|
+
).instruction() : yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
6194
6381
|
new BN2(jupInstruction.quoteResponse.outAmount),
|
|
6195
6382
|
new BN2(9997)
|
|
6196
6383
|
).accountsStrict({
|
|
@@ -6217,7 +6404,29 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
6217
6404
|
] : []
|
|
6218
6405
|
).instruction();
|
|
6219
6406
|
} else {
|
|
6220
|
-
repaySolIx = yield lavarageProgram.methods.
|
|
6407
|
+
repaySolIx = useReferral ? yield lavarageProgram.methods.tradingCloseRepaySolWithReferral(
|
|
6408
|
+
new BN2(jupInstruction.quoteResponse.outAmount),
|
|
6409
|
+
new BN2(9998),
|
|
6410
|
+
new BN2(discountBps),
|
|
6411
|
+
new BN2(referralBps)
|
|
6412
|
+
).accountsStrict({
|
|
6413
|
+
nodeWallet: pool.account.nodeWallet,
|
|
6414
|
+
positionAccount: positionAccountPDA,
|
|
6415
|
+
tradingPool: poolPubKey,
|
|
6416
|
+
trader: lavarageProgram.provider.publicKey,
|
|
6417
|
+
systemProgram: SystemProgram2.programId,
|
|
6418
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
6419
|
+
randomAccountAsId: position.account.seed,
|
|
6420
|
+
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
6421
|
+
}).remainingAccounts(
|
|
6422
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
6423
|
+
{
|
|
6424
|
+
pubkey: userVaultPda,
|
|
6425
|
+
isSigner: false,
|
|
6426
|
+
isWritable: true
|
|
6427
|
+
}
|
|
6428
|
+
] : []
|
|
6429
|
+
).instruction() : yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
6221
6430
|
new BN2(jupInstruction.quoteResponse.outAmount),
|
|
6222
6431
|
new BN2(9998)
|
|
6223
6432
|
).accountsStrict({
|
|
@@ -6274,6 +6483,7 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
6274
6483
|
});
|
|
6275
6484
|
if (splitTransactions) {
|
|
6276
6485
|
const setUpInstructions = [
|
|
6486
|
+
partnerFeeRecipientCreateIx,
|
|
6277
6487
|
jupInstruction.instructions && (platformFeeRecipientAccount == null ? void 0 : platformFeeRecipientAccount.instruction) ? platformFeeRecipientAccount.instruction : null,
|
|
6278
6488
|
createAssociatedTokenAccountInstruction2
|
|
6279
6489
|
].filter((i) => !!i);
|
|
@@ -6301,6 +6511,7 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
6301
6511
|
return [tx2, tx22];
|
|
6302
6512
|
}
|
|
6303
6513
|
const allInstructions = [
|
|
6514
|
+
partnerFeeRecipientCreateIx,
|
|
6304
6515
|
jupInstruction.instructions && (platformFeeRecipientAccount == null ? void 0 : platformFeeRecipientAccount.instruction) ? platformFeeRecipientAccount.instruction : null,
|
|
6305
6516
|
createAssociatedTokenAccountInstruction2,
|
|
6306
6517
|
((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
|
|
@@ -6319,9 +6530,10 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
6319
6530
|
const tx = new VersionedTransaction2(messageV0);
|
|
6320
6531
|
return tx;
|
|
6321
6532
|
});
|
|
6322
|
-
var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken, partnerFeeRecipient, partnerFeeMarkup, computeBudgetMicroLamports, platformFeeRecipient, splitTransactions) => __async(void 0, null, function* () {
|
|
6533
|
+
var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken, partnerFeeRecipient, partnerFeeMarkup, computeBudgetMicroLamports, platformFeeRecipient, splitTransactions, discountBps, referralBps) => __async(void 0, null, function* () {
|
|
6323
6534
|
var _a, _b;
|
|
6324
6535
|
let partnerFeeMarkupAsPkey;
|
|
6536
|
+
const referralVaultProgram = new Program2(IDL, REFFERAL_VAULT_PROGRAM_ID, lavarageProgram.provider);
|
|
6325
6537
|
if (partnerFeeMarkup) {
|
|
6326
6538
|
const feeBuffer = Buffer.alloc(8);
|
|
6327
6539
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
@@ -6391,6 +6603,45 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
6391
6603
|
});
|
|
6392
6604
|
const addressLookupTableAccounts = [];
|
|
6393
6605
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
6606
|
+
const useReferral = discountBps !== void 0 && referralBps !== void 0;
|
|
6607
|
+
let partnerFeeRecipientVaultCreateIx;
|
|
6608
|
+
let partnerFeeRecipientTokenAccountCreateIx;
|
|
6609
|
+
let userVaultPda;
|
|
6610
|
+
if (partnerFeeRecipient && partnerFeeMarkupAsPkey && referralVaultProgram) {
|
|
6611
|
+
[userVaultPda] = PublicKey2.findProgramAddressSync(
|
|
6612
|
+
[Buffer.from("user_vault"), new PublicKey2(partnerFeeRecipient).toBuffer()],
|
|
6613
|
+
referralVaultProgram.programId
|
|
6614
|
+
);
|
|
6615
|
+
const vaultTokenAccount = getAssociatedTokenAddressSync2(
|
|
6616
|
+
quoteToken,
|
|
6617
|
+
userVaultPda,
|
|
6618
|
+
true,
|
|
6619
|
+
// allowOwnerOffCurve for PDA
|
|
6620
|
+
quoteTokenProgram
|
|
6621
|
+
);
|
|
6622
|
+
const [vaultAccountInfo, vaultTokenAccountInfo] = yield lavarageProgram.provider.connection.getMultipleAccountsInfo([
|
|
6623
|
+
userVaultPda,
|
|
6624
|
+
vaultTokenAccount
|
|
6625
|
+
]);
|
|
6626
|
+
if (!vaultAccountInfo) {
|
|
6627
|
+
partnerFeeRecipientVaultCreateIx = yield referralVaultProgram.methods.initializeVault().accountsStrict({
|
|
6628
|
+
userVault: userVaultPda,
|
|
6629
|
+
user: partnerFeeRecipient,
|
|
6630
|
+
funder: lavarageProgram.provider.publicKey,
|
|
6631
|
+
systemProgram: SystemProgram2.programId
|
|
6632
|
+
}).instruction();
|
|
6633
|
+
}
|
|
6634
|
+
if (!vaultTokenAccountInfo) {
|
|
6635
|
+
partnerFeeRecipientTokenAccountCreateIx = createAssociatedTokenAccountIdempotentInstruction2(
|
|
6636
|
+
lavarageProgram.provider.publicKey,
|
|
6637
|
+
vaultTokenAccount,
|
|
6638
|
+
userVaultPda,
|
|
6639
|
+
quoteToken,
|
|
6640
|
+
quoteTokenProgram,
|
|
6641
|
+
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
6642
|
+
);
|
|
6643
|
+
}
|
|
6644
|
+
}
|
|
6394
6645
|
const closePositionIx = yield lavarageProgram.methods.tradingCloseBorrowCollateral().accountsStrict({
|
|
6395
6646
|
tradingPool: poolPubKey,
|
|
6396
6647
|
instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -6407,7 +6658,54 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
6407
6658
|
let repaySolIx = null;
|
|
6408
6659
|
let jupiterIxs = [];
|
|
6409
6660
|
if (jupInstruction.instructions == void 0) {
|
|
6410
|
-
repaySolIx = yield lavarageProgram.methods.
|
|
6661
|
+
repaySolIx = useReferral ? yield lavarageProgram.methods.tradingCloseRepaySolWithReferral(
|
|
6662
|
+
new BN2(jupInstruction.quoteResponse.outAmount),
|
|
6663
|
+
new BN2(9997),
|
|
6664
|
+
new BN2(discountBps),
|
|
6665
|
+
new BN2(referralBps)
|
|
6666
|
+
).accountsStrict({
|
|
6667
|
+
nodeWallet: pool.account.nodeWallet,
|
|
6668
|
+
positionAccount: positionAccountPDA,
|
|
6669
|
+
tradingPool: poolPubKey,
|
|
6670
|
+
trader: lavarageProgram.provider.publicKey,
|
|
6671
|
+
systemProgram: SystemProgram2.programId,
|
|
6672
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
6673
|
+
randomAccountAsId: position.account.seed,
|
|
6674
|
+
feeTokenAccount: getAssociatedTokenAddressSync2(
|
|
6675
|
+
quoteToken,
|
|
6676
|
+
new PublicKey2("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
6677
|
+
false,
|
|
6678
|
+
quoteTokenProgram
|
|
6679
|
+
),
|
|
6680
|
+
fromTokenAccount: getAssociatedTokenAddressSync2(
|
|
6681
|
+
quoteToken,
|
|
6682
|
+
lavarageProgram.provider.publicKey,
|
|
6683
|
+
false,
|
|
6684
|
+
quoteTokenProgram
|
|
6685
|
+
),
|
|
6686
|
+
tokenProgram: quoteTokenProgram,
|
|
6687
|
+
toTokenAccount: getAssociatedTokenAddressSync2(
|
|
6688
|
+
quoteToken,
|
|
6689
|
+
pool.account.nodeWallet,
|
|
6690
|
+
true,
|
|
6691
|
+
quoteTokenProgram
|
|
6692
|
+
),
|
|
6693
|
+
mint: quoteToken
|
|
6694
|
+
}).remainingAccounts(
|
|
6695
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
6696
|
+
{
|
|
6697
|
+
pubkey: getAssociatedTokenAddressSync2(
|
|
6698
|
+
quoteToken,
|
|
6699
|
+
userVaultPda,
|
|
6700
|
+
true,
|
|
6701
|
+
// allowOwnerOffCurve for PDA
|
|
6702
|
+
quoteTokenProgram
|
|
6703
|
+
),
|
|
6704
|
+
isSigner: false,
|
|
6705
|
+
isWritable: true
|
|
6706
|
+
}
|
|
6707
|
+
] : []
|
|
6708
|
+
).instruction() : yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
6411
6709
|
new BN2(jupInstruction.quoteResponse.outAmount),
|
|
6412
6710
|
new BN2(9997)
|
|
6413
6711
|
).accountsStrict({
|
|
@@ -6458,7 +6756,54 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
6458
6756
|
] : []
|
|
6459
6757
|
).instruction();
|
|
6460
6758
|
} else {
|
|
6461
|
-
repaySolIx = yield lavarageProgram.methods.
|
|
6759
|
+
repaySolIx = useReferral ? yield lavarageProgram.methods.tradingCloseRepaySolWithReferral(
|
|
6760
|
+
new BN2(jupInstruction.quoteResponse.outAmount),
|
|
6761
|
+
new BN2(9998),
|
|
6762
|
+
new BN2(discountBps),
|
|
6763
|
+
new BN2(referralBps)
|
|
6764
|
+
).accountsStrict({
|
|
6765
|
+
nodeWallet: pool.account.nodeWallet,
|
|
6766
|
+
positionAccount: positionAccountPDA,
|
|
6767
|
+
tradingPool: poolPubKey,
|
|
6768
|
+
trader: lavarageProgram.provider.publicKey,
|
|
6769
|
+
systemProgram: SystemProgram2.programId,
|
|
6770
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
6771
|
+
randomAccountAsId: position.account.seed,
|
|
6772
|
+
feeTokenAccount: getAssociatedTokenAddressSync2(
|
|
6773
|
+
quoteToken,
|
|
6774
|
+
new PublicKey2("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
6775
|
+
false,
|
|
6776
|
+
quoteTokenProgram
|
|
6777
|
+
),
|
|
6778
|
+
fromTokenAccount: getAssociatedTokenAddressSync2(
|
|
6779
|
+
quoteToken,
|
|
6780
|
+
lavarageProgram.provider.publicKey,
|
|
6781
|
+
false,
|
|
6782
|
+
quoteTokenProgram
|
|
6783
|
+
),
|
|
6784
|
+
tokenProgram: quoteTokenProgram,
|
|
6785
|
+
toTokenAccount: getAssociatedTokenAddressSync2(
|
|
6786
|
+
quoteToken,
|
|
6787
|
+
pool.account.nodeWallet,
|
|
6788
|
+
true,
|
|
6789
|
+
quoteTokenProgram
|
|
6790
|
+
),
|
|
6791
|
+
mint: quoteToken
|
|
6792
|
+
}).remainingAccounts(
|
|
6793
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
6794
|
+
{
|
|
6795
|
+
pubkey: getAssociatedTokenAddressSync2(
|
|
6796
|
+
quoteToken,
|
|
6797
|
+
userVaultPda,
|
|
6798
|
+
true,
|
|
6799
|
+
// allowOwnerOffCurve for PDA
|
|
6800
|
+
quoteTokenProgram
|
|
6801
|
+
),
|
|
6802
|
+
isSigner: false,
|
|
6803
|
+
isWritable: true
|
|
6804
|
+
}
|
|
6805
|
+
] : []
|
|
6806
|
+
).instruction() : yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
6462
6807
|
new BN2(jupInstruction.quoteResponse.outAmount),
|
|
6463
6808
|
new BN2(9998)
|
|
6464
6809
|
).accountsStrict({
|
|
@@ -6540,6 +6885,8 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
6540
6885
|
});
|
|
6541
6886
|
if (splitTransactions) {
|
|
6542
6887
|
const setUpInstructions = [
|
|
6888
|
+
partnerFeeRecipientVaultCreateIx,
|
|
6889
|
+
partnerFeeRecipientTokenAccountCreateIx,
|
|
6543
6890
|
jupInstruction.instructions && (platformFeeRecipientAccount == null ? void 0 : platformFeeRecipientAccount.instruction) ? platformFeeRecipientAccount.instruction : null,
|
|
6544
6891
|
createAssociatedTokenAccountInstruction2
|
|
6545
6892
|
].filter((i) => !!i);
|
|
@@ -6567,6 +6914,8 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
6567
6914
|
return [tx2, tx22];
|
|
6568
6915
|
}
|
|
6569
6916
|
const allInstructions = [
|
|
6917
|
+
partnerFeeRecipientVaultCreateIx,
|
|
6918
|
+
partnerFeeRecipientTokenAccountCreateIx,
|
|
6570
6919
|
jupInstruction.instructions && (platformFeeRecipientAccount == null ? void 0 : platformFeeRecipientAccount.instruction) ? platformFeeRecipientAccount.instruction : null,
|
|
6571
6920
|
createAssociatedTokenAccountInstruction2,
|
|
6572
6921
|
((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
|