@lavarage/sdk 7.5.8 → 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/dist/index.mjs CHANGED
@@ -6250,9 +6250,10 @@ var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0
6250
6250
  }).compileToV0Message();
6251
6251
  return new VersionedTransaction2(messageV0);
6252
6252
  });
6253
- 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* () {
6254
6254
  var _a, _b;
6255
6255
  let partnerFeeMarkupAsPkey;
6256
+ const referralVaultProgram = new Program2(IDL, REFFERAL_VAULT_PROGRAM_ID, lavarageProgram.provider);
6256
6257
  if (partnerFeeMarkup) {
6257
6258
  const feeBuffer = Buffer.alloc(8);
6258
6259
  feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
@@ -6320,6 +6321,24 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
6320
6321
  });
6321
6322
  const addressLookupTableAccounts = [];
6322
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
+ }
6323
6342
  const closePositionIx = yield lavarageProgram.methods.tradingCloseBorrowCollateral().accountsStrict({
6324
6343
  tradingPool: poolPubKey,
6325
6344
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
@@ -6336,7 +6355,29 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
6336
6355
  let repaySolIx = null;
6337
6356
  let jupiterIxs = [];
6338
6357
  if (jupInstruction.instructions == void 0) {
6339
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
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(
6340
6381
  new BN2(jupInstruction.quoteResponse.outAmount),
6341
6382
  new BN2(9997)
6342
6383
  ).accountsStrict({
@@ -6363,7 +6404,29 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
6363
6404
  ] : []
6364
6405
  ).instruction();
6365
6406
  } else {
6366
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
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(
6367
6430
  new BN2(jupInstruction.quoteResponse.outAmount),
6368
6431
  new BN2(9998)
6369
6432
  ).accountsStrict({
@@ -6420,6 +6483,7 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
6420
6483
  });
6421
6484
  if (splitTransactions) {
6422
6485
  const setUpInstructions = [
6486
+ partnerFeeRecipientCreateIx,
6423
6487
  jupInstruction.instructions && (platformFeeRecipientAccount == null ? void 0 : platformFeeRecipientAccount.instruction) ? platformFeeRecipientAccount.instruction : null,
6424
6488
  createAssociatedTokenAccountInstruction2
6425
6489
  ].filter((i) => !!i);
@@ -6447,6 +6511,7 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
6447
6511
  return [tx2, tx22];
6448
6512
  }
6449
6513
  const allInstructions = [
6514
+ partnerFeeRecipientCreateIx,
6450
6515
  jupInstruction.instructions && (platformFeeRecipientAccount == null ? void 0 : platformFeeRecipientAccount.instruction) ? platformFeeRecipientAccount.instruction : null,
6451
6516
  createAssociatedTokenAccountInstruction2,
6452
6517
  ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(