@lavarage/sdk 6.4.5 → 6.4.7

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
@@ -2737,30 +2737,20 @@ function getPositionAccountPDA(lavarageProgram, offer, seed) {
2737
2737
  function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress, tokenProgram) {
2738
2738
  return __async(this, null, function* () {
2739
2739
  const associatedTokenAddress = (0, import_spl_token.getAssociatedTokenAddressSync)(tokenAddress, ownerPublicKey, true, tokenProgram, import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID);
2740
- try {
2741
- const tokenAccount = yield (0, import_spl_token.getAccount)(lavarageProgram.provider.connection, associatedTokenAddress, "finalized", tokenProgram);
2742
- return { account: tokenAccount, instruction: null };
2743
- } catch (error) {
2744
- if (error instanceof import_spl_token.TokenAccountNotFoundError || error instanceof import_spl_token.TokenInvalidAccountOwnerError) {
2745
- const instruction = (0, import_spl_token.createAssociatedTokenAccountInstruction)(
2746
- lavarageProgram.provider.publicKey,
2747
- associatedTokenAddress,
2748
- ownerPublicKey,
2749
- tokenAddress,
2750
- tokenProgram,
2751
- import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID
2752
- );
2753
- return {
2754
- account: {
2755
- address: associatedTokenAddress
2756
- },
2757
- instruction
2758
- };
2759
- } else {
2760
- console.error("Error in getTokenAccountOrCreateIfNotExists: ", error);
2761
- return { account: null, instruction: null };
2762
- }
2763
- }
2740
+ const instruction = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
2741
+ lavarageProgram.provider.publicKey,
2742
+ associatedTokenAddress,
2743
+ ownerPublicKey,
2744
+ tokenAddress,
2745
+ tokenProgram,
2746
+ import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID
2747
+ );
2748
+ return {
2749
+ account: {
2750
+ address: associatedTokenAddress
2751
+ },
2752
+ instruction
2753
+ };
2764
2754
  });
2765
2755
  }
2766
2756
  var getOffers = (lavarageProgram) => {
@@ -3160,7 +3150,7 @@ var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0
3160
3150
  return new import_web3.VersionedTransaction(messageV0);
3161
3151
  });
3162
3152
  var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
3163
- var _a;
3153
+ var _a, _b;
3164
3154
  let partnerFeeMarkupAsPkey;
3165
3155
  if (partnerFeeMarkup) {
3166
3156
  const feeBuffer = Buffer.alloc(8);
@@ -3268,8 +3258,16 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3268
3258
  addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(["5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi", ...addressLookupTableAddresses]));
3269
3259
  }
3270
3260
  const profit = new import_anchor.BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3261
+ let createAssociatedTokenAccountInstruction2 = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
3262
+ lavarageProgram.provider.publicKey,
3263
+ toTokenAccount.account.address,
3264
+ lavarageProgram.provider.publicKey,
3265
+ offer.account.collateralType,
3266
+ tokenProgram
3267
+ );
3271
3268
  const allInstructions = [
3272
- ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? deserializeInstruction(jupInstruction.instructions.tokenLedgerInstruction) : null,
3269
+ ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
3270
+ ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(jupInstruction.instructions.tokenLedgerInstruction) : null,
3273
3271
  toTokenAccount.instruction,
3274
3272
  closePositionIx,
3275
3273
  ...jupiterIxs,
@@ -3284,7 +3282,7 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3284
3282
  return tx;
3285
3283
  });
3286
3284
  var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
3287
- var _a;
3285
+ var _a, _b;
3288
3286
  let partnerFeeMarkupAsPkey;
3289
3287
  if (partnerFeeMarkup) {
3290
3288
  const feeBuffer = Buffer.alloc(8);
@@ -3402,8 +3400,16 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3402
3400
  addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts([...addressLookupTableAddresses, getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()), "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"]));
3403
3401
  }
3404
3402
  const profit = new import_anchor.BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3403
+ let createAssociatedTokenAccountInstruction2 = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
3404
+ lavarageProgram.provider.publicKey,
3405
+ toTokenAccount.account.address,
3406
+ lavarageProgram.provider.publicKey,
3407
+ offer.account.collateralType,
3408
+ tokenProgram
3409
+ );
3405
3410
  const allInstructions = [
3406
- ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? deserializeInstruction(jupInstruction.instructions.tokenLedgerInstruction) : null,
3411
+ ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
3412
+ ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(jupInstruction.instructions.tokenLedgerInstruction) : null,
3407
3413
  toTokenAccount.instruction,
3408
3414
  closePositionIx,
3409
3415
  ...jupiterIxs,