@raydium-io/raydium-sdk-v2 0.0.27-alpha → 0.0.29-alpha

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.
@@ -422,50 +422,40 @@ export default class CpmmModule extends ModuleBase {
422
422
  const txBuilder = this.createTxBuilder();
423
423
 
424
424
  const [mintA, mintB] = [new PublicKey(poolInfo.mintA.address), new PublicKey(poolInfo.mintB.address)];
425
- const mintAUseSOLBalance = mintA.equals(NATIVE_MINT);
426
- const mintBUseSOLBalance = mintB.equals(NATIVE_MINT);
427
425
 
428
- const { account: mintATokenAccount, instructionParams: _mintATokenAccountIns } =
429
- await this.scope.account.getOrCreateTokenAccount({
430
- tokenProgram: poolInfo.mintA.programId,
431
- mint: new PublicKey(poolInfo.mintA.address),
432
- owner: this.scope.ownerPubKey,
433
-
434
- createInfo: mintAUseSOLBalance
435
- ? {
436
- payer: this.scope.ownerPubKey,
437
- amount: baseIn ? swapResult.sourceAmountSwapped : 0,
438
- }
439
- : undefined,
440
- skipCloseAccount: !mintAUseSOLBalance,
441
- notUseTokenAccount: mintAUseSOLBalance,
442
- associatedOnly: false,
443
- checkCreateATAOwner,
444
- });
445
-
446
- txBuilder.addInstruction(_mintATokenAccountIns || {});
426
+ const mintATokenAcc = await this.scope.account.getCreatedTokenAccount({
427
+ programId: new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
428
+ mint: mintA,
429
+ associatedOnly: false,
430
+ });
447
431
 
448
- const { account: mintBTokenAccount, instructionParams: _mintBTokenAccountIns } =
449
- await this.scope.account.getOrCreateTokenAccount({
450
- tokenProgram: poolInfo.mintA.programId,
451
- mint: new PublicKey(poolInfo.mintA.address),
452
- owner: this.scope.ownerPubKey,
432
+ const mintBTokenAcc = await this.scope.account.getCreatedTokenAccount({
433
+ programId: new PublicKey(poolInfo.mintB.programId ?? TOKEN_PROGRAM_ID),
434
+ mint: mintB,
435
+ associatedOnly: false,
436
+ });
453
437
 
454
- createInfo: mintBUseSOLBalance
455
- ? {
456
- payer: this.scope.ownerPubKey,
457
- amount: baseIn ? 0 : swapResult.sourceAmountSwapped,
458
- }
459
- : undefined,
460
- skipCloseAccount: !mintAUseSOLBalance,
461
- notUseTokenAccount: mintAUseSOLBalance,
462
- associatedOnly: false,
463
- checkCreateATAOwner,
464
- });
438
+ const { tokenAccount: _mintATokenAcc, ...mintATokenAccInstruction } = await this.scope.account.handleTokenAccount({
439
+ side: baseIn ? "in" : "out",
440
+ amount: baseIn ? swapResult.sourceAmountSwapped : swapResult.destinationAmountSwapped,
441
+ mint: mintA,
442
+ tokenAccount: mintATokenAcc,
443
+ bypassAssociatedCheck,
444
+ checkCreateATAOwner,
445
+ });
446
+ txBuilder.addInstruction(mintATokenAccInstruction);
465
447
 
466
- txBuilder.addInstruction(_mintBTokenAccountIns || {});
448
+ const { tokenAccount: _mintBTokenAcc, ...mintBTokenAccInstruction } = await this.scope.account.handleTokenAccount({
449
+ side: baseIn ? "out" : "in",
450
+ amount: baseIn ? swapResult.destinationAmountSwapped : swapResult.sourceAmountSwapped,
451
+ mint: mintB,
452
+ tokenAccount: mintBTokenAcc,
453
+ bypassAssociatedCheck,
454
+ checkCreateATAOwner,
455
+ });
456
+ txBuilder.addInstruction(mintBTokenAccInstruction);
467
457
 
468
- if (!mintATokenAccount && !mintBTokenAccount)
458
+ if (!_mintATokenAcc && !_mintBTokenAcc)
469
459
  this.logAndCreateError("cannot found target token accounts", "tokenAccounts", this.scope.account.tokenAccounts);
470
460
 
471
461
  const poolKeys = await this.getCpmmPoolKeys(poolInfo.id);
@@ -479,8 +469,8 @@ export default class CpmmModule extends ModuleBase {
479
469
  new PublicKey(poolKeys.authority),
480
470
  new PublicKey(poolKeys.config.id),
481
471
  new PublicKey(poolInfo.id),
482
- mintATokenAccount!,
483
- mintBTokenAccount!,
472
+ _mintATokenAcc!,
473
+ _mintBTokenAcc!,
484
474
  new PublicKey(poolKeys.vault.A),
485
475
  new PublicKey(poolKeys.vault.B),
486
476
  new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
@@ -499,8 +489,8 @@ export default class CpmmModule extends ModuleBase {
499
489
  new PublicKey(poolKeys.config.id),
500
490
  new PublicKey(poolInfo.id),
501
491
 
502
- mintBTokenAccount!,
503
- mintATokenAccount!,
492
+ _mintBTokenAcc!,
493
+ _mintATokenAcc!,
504
494
 
505
495
  new PublicKey(poolKeys.vault.B),
506
496
  new PublicKey(poolKeys.vault.A),