@lavarage/sdk 5.1.1 → 6.0.0

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.js CHANGED
@@ -2441,9 +2441,9 @@ function getPda(seed, programId) {
2441
2441
  function getPositionAccountPDA(lavarageProgram, offer, seed) {
2442
2442
  return getPda([Buffer.from("position"), lavarageProgram.provider.publicKey.toBuffer(), offer.publicKey.toBuffer(), seed.toBuffer()], lavarageProgram.programId);
2443
2443
  }
2444
- function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress) {
2444
+ function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress, tokenProgram) {
2445
2445
  return __async(this, null, function* () {
2446
- const associatedTokenAddress = (0, import_spl_token.getAssociatedTokenAddressSync)(tokenAddress, ownerPublicKey, true, import_spl_token.TOKEN_PROGRAM_ID, import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID);
2446
+ const associatedTokenAddress = (0, import_spl_token.getAssociatedTokenAddressSync)(tokenAddress, ownerPublicKey, true, tokenProgram, import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID);
2447
2447
  try {
2448
2448
  const tokenAccount = yield (0, import_spl_token.getAccount)(lavarageProgram.provider.connection, associatedTokenAddress, "finalized");
2449
2449
  return { account: tokenAccount, instruction: null };
@@ -2454,7 +2454,7 @@ function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tok
2454
2454
  associatedTokenAddress,
2455
2455
  ownerPublicKey,
2456
2456
  tokenAddress,
2457
- import_spl_token.TOKEN_PROGRAM_ID,
2457
+ tokenProgram,
2458
2458
  import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID
2459
2459
  );
2460
2460
  return {
@@ -2541,8 +2541,10 @@ var getAllPositions = (lavarageProgram) => {
2541
2541
  };
2542
2542
  var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient) => __async(void 0, null, function* () {
2543
2543
  const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2544
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType);
2545
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType);
2544
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
2545
+ const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2546
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType, tokenProgram);
2547
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType, tokenProgram);
2546
2548
  const tokenAccountCreationTx = new import_web3.Transaction();
2547
2549
  if (fromTokenAccount.instruction) {
2548
2550
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2625,8 +2627,12 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2625
2627
  });
2626
2628
  var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
2627
2629
  const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2628
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType);
2629
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType);
2630
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
2631
+ const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2632
+ const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
2633
+ const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
2634
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType, tokenProgram);
2635
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType, tokenProgram);
2630
2636
  const tokenAccountCreationTx = new import_web3.Transaction();
2631
2637
  if (fromTokenAccount.instruction) {
2632
2638
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2674,9 +2680,9 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2674
2680
  clock: import_web3.SYSVAR_CLOCK_PUBKEY,
2675
2681
  randomAccountAsId: randomSeed.publicKey.toBase58(),
2676
2682
  feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
2677
- toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey),
2678
- tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
2679
- fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, offer.account.nodeWallet, true)
2683
+ toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey, true, quoteTokenProgram),
2684
+ tokenProgram,
2685
+ fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, offer.account.nodeWallet, true, tokenProgram)
2680
2686
  }).remainingAccounts(partnerFeeRecipient ? [{
2681
2687
  pubkey: partnerFeeRecipient,
2682
2688
  isSigner: false,
@@ -2795,9 +2801,11 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
2795
2801
  const pool = offer;
2796
2802
  const poolPubKey = offer.publicKey;
2797
2803
  const tokenAddressPubKey = new import_web3.PublicKey(offer.account.collateralType);
2804
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
2805
+ const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2798
2806
  const positionAccountPDA = position.publicKey;
2799
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey);
2800
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey);
2807
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
2808
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey, tokenProgram);
2801
2809
  const jupiterSellIx = jupInstruction.instructions;
2802
2810
  const deserializeInstruction = (instruction) => {
2803
2811
  return new import_web3.TransactionInstruction({
@@ -2836,7 +2844,7 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
2836
2844
  clock: import_web3.SYSVAR_CLOCK_PUBKEY,
2837
2845
  systemProgram: import_web3.SystemProgram.programId,
2838
2846
  trader: lavarageProgram.provider.publicKey,
2839
- tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
2847
+ tokenProgram,
2840
2848
  randomAccountAsId: position.account.seed
2841
2849
  }).instruction();
2842
2850
  let repaySolIx = null;
@@ -2906,9 +2914,13 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
2906
2914
  const pool = offer;
2907
2915
  const poolPubKey = offer.publicKey;
2908
2916
  const tokenAddressPubKey = new import_web3.PublicKey(offer.account.collateralType);
2917
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
2918
+ const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2919
+ const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
2920
+ const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
2909
2921
  const positionAccountPDA = position.publicKey;
2910
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey);
2911
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey);
2922
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
2923
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey, tokenProgram);
2912
2924
  const jupiterSellIx = jupInstruction.instructions;
2913
2925
  const deserializeInstruction = (instruction) => {
2914
2926
  return new import_web3.TransactionInstruction({
@@ -2947,7 +2959,7 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
2947
2959
  clock: import_web3.SYSVAR_CLOCK_PUBKEY,
2948
2960
  systemProgram: import_web3.SystemProgram.programId,
2949
2961
  trader: lavarageProgram.provider.publicKey,
2950
- tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
2962
+ tokenProgram,
2951
2963
  randomAccountAsId: position.account.seed
2952
2964
  }).instruction();
2953
2965
  let repaySolIx = null;
@@ -2961,10 +2973,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
2961
2973
  systemProgram: import_web3.SystemProgram.programId,
2962
2974
  clock: import_web3.SYSVAR_CLOCK_PUBKEY,
2963
2975
  randomAccountAsId: position.account.seed,
2964
- feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
2965
- fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey),
2966
- tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
2967
- toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, pool.account.nodeWallet, true),
2976
+ feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
2977
+ fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
2978
+ tokenProgram: quoteTokenProgram,
2979
+ toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
2968
2980
  mint: quoteToken
2969
2981
  }).remainingAccounts(partnerFeeRecipient ? [{
2970
2982
  pubkey: partnerFeeRecipient,
@@ -2980,10 +2992,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
2980
2992
  systemProgram: import_web3.SystemProgram.programId,
2981
2993
  clock: import_web3.SYSVAR_CLOCK_PUBKEY,
2982
2994
  randomAccountAsId: position.account.seed,
2983
- feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
2984
- fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey),
2985
- tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
2986
- toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, pool.account.nodeWallet, true),
2995
+ feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
2996
+ fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
2997
+ tokenProgram: quoteTokenProgram,
2998
+ toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
2987
2999
  mint: quoteToken
2988
3000
  }).remainingAccounts(partnerFeeRecipient ? [{
2989
3001
  pubkey: partnerFeeRecipient,
@@ -3004,12 +3016,13 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3004
3016
  closePositionIx,
3005
3017
  ...jupiterIxs,
3006
3018
  repaySolIx,
3007
- profitFeeMarkup && partnerFeeRecipient ? import_web3.SystemProgram.transfer(
3008
- {
3009
- fromPubkey: lavarageProgram.provider.publicKey,
3010
- toPubkey: partnerFeeRecipient,
3011
- lamports: profit.toNumber() > 0 ? profit.mul(new import_anchor.BN(profitFeeMarkup * 1e3)).div(new import_anchor.BN(1e3)).toNumber() : 0
3012
- }
3019
+ profitFeeMarkup && partnerFeeRecipient ? (0, import_spl_token.createTransferInstruction)(
3020
+ (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
3021
+ partnerFeeRecipient,
3022
+ lavarageProgram.provider.publicKey,
3023
+ profit.toNumber() > 0 ? profit.mul(new import_anchor.BN(profitFeeMarkup * 1e3)).div(new import_anchor.BN(1e3)).toNumber() : 0,
3024
+ [],
3025
+ quoteTokenProgram
3013
3026
  ) : null
3014
3027
  ].filter((i) => !!i);
3015
3028
  const messageV0 = new import_web3.TransactionMessage({