@raydium-io/raydium-sdk-v2 0.0.26-alpha → 0.0.27-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raydium-io/raydium-sdk-v2",
3
- "version": "0.0.26-alpha",
3
+ "version": "0.0.27-alpha",
4
4
  "description": "An SDK for building applications on top of Raydium.",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./lib/index.js",
@@ -422,40 +422,50 @@ 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);
425
427
 
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
- });
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,
431
433
 
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
- });
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
+ });
437
445
 
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);
446
+ txBuilder.addInstruction(_mintATokenAccountIns || {});
447
447
 
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);
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,
453
+
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
+ });
465
+
466
+ txBuilder.addInstruction(_mintBTokenAccountIns || {});
457
467
 
458
- if (!_mintATokenAcc && !_mintBTokenAcc)
468
+ if (!mintATokenAccount && !mintBTokenAccount)
459
469
  this.logAndCreateError("cannot found target token accounts", "tokenAccounts", this.scope.account.tokenAccounts);
460
470
 
461
471
  const poolKeys = await this.getCpmmPoolKeys(poolInfo.id);
@@ -467,10 +477,10 @@ export default class CpmmModule extends ModuleBase {
467
477
  new PublicKey(poolInfo.programId),
468
478
  this.scope.ownerPubKey,
469
479
  new PublicKey(poolKeys.authority),
470
- new PublicKey(poolKeys.id), // todo config id
480
+ new PublicKey(poolKeys.config.id),
471
481
  new PublicKey(poolInfo.id),
472
- _mintATokenAcc!,
473
- _mintBTokenAcc!,
482
+ mintATokenAccount!,
483
+ mintBTokenAccount!,
474
484
  new PublicKey(poolKeys.vault.A),
475
485
  new PublicKey(poolKeys.vault.B),
476
486
  new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
@@ -486,11 +496,11 @@ export default class CpmmModule extends ModuleBase {
486
496
  new PublicKey(poolInfo.programId),
487
497
  this.scope.ownerPubKey,
488
498
  new PublicKey(poolKeys.authority),
489
- new PublicKey(poolKeys.id), // todo config id
499
+ new PublicKey(poolKeys.config.id),
490
500
  new PublicKey(poolInfo.id),
491
501
 
492
- _mintBTokenAcc!,
493
- _mintATokenAcc!,
502
+ mintBTokenAccount!,
503
+ mintATokenAccount!,
494
504
 
495
505
  new PublicKey(poolKeys.vault.B),
496
506
  new PublicKey(poolKeys.vault.A),