@raydium-io/raydium-sdk-v2 0.1.32-alpha → 0.1.34-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.1.32-alpha",
3
+ "version": "0.1.34-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",
@@ -307,9 +307,9 @@ export default class CpmmModule extends ModuleBase {
307
307
  owner: this.scope.ownerPubKey,
308
308
  createInfo: mintAUseSOLBalance
309
309
  ? {
310
- payer: payer!,
311
- amount: mintAAmount,
312
- }
310
+ payer: payer!,
311
+ amount: mintAAmount,
312
+ }
313
313
  : undefined,
314
314
  notUseTokenAccount: mintAUseSOLBalance,
315
315
  skipCloseAccount: !mintAUseSOLBalance,
@@ -324,9 +324,9 @@ export default class CpmmModule extends ModuleBase {
324
324
  owner: this.scope.ownerPubKey,
325
325
  createInfo: mintBUseSOLBalance
326
326
  ? {
327
- payer: payer!,
328
- amount: mintBAmount,
329
- }
327
+ payer: payer!,
328
+ amount: mintBAmount,
329
+ }
330
330
  : undefined,
331
331
 
332
332
  notUseTokenAccount: mintBUseSOLBalance,
@@ -416,20 +416,20 @@ export default class CpmmModule extends ModuleBase {
416
416
  inputAmountFee,
417
417
  anotherAmount: _anotherAmount,
418
418
  } = computeResult ||
419
- this.computePairAmount({
420
- poolInfo: {
421
- ...poolInfo,
422
- lpAmount: new Decimal(rpcPoolData!.lpAmount.toString()).div(10 ** poolInfo.lpMint.decimals).toNumber(),
423
- },
424
- baseReserve: rpcPoolData!.baseReserve,
425
- quoteReserve: rpcPoolData!.quoteReserve,
426
- slippage: new Percent(0),
427
- baseIn,
428
- epochInfo: await this.scope.fetchEpochInfo(),
429
- amount: new Decimal(inputAmount.toString()).div(
430
- 10 ** (baseIn ? poolInfo.mintA.decimals : poolInfo.mintB.decimals),
431
- ),
432
- });
419
+ this.computePairAmount({
420
+ poolInfo: {
421
+ ...poolInfo,
422
+ lpAmount: new Decimal(rpcPoolData!.lpAmount.toString()).div(10 ** poolInfo.lpMint.decimals).toNumber(),
423
+ },
424
+ baseReserve: rpcPoolData!.baseReserve,
425
+ quoteReserve: rpcPoolData!.quoteReserve,
426
+ slippage: new Percent(0),
427
+ baseIn,
428
+ epochInfo: await this.scope.fetchEpochInfo(),
429
+ amount: new Decimal(inputAmount.toString()).div(
430
+ 10 ** (baseIn ? poolInfo.mintA.decimals : poolInfo.mintB.decimals),
431
+ ),
432
+ });
433
433
 
434
434
  const anotherAmount = _anotherAmount.amount;
435
435
  const mintAUseSOLBalance = poolInfo.mintA.address === NATIVE_MINT.toString();
@@ -447,9 +447,9 @@ export default class CpmmModule extends ModuleBase {
447
447
  createInfo:
448
448
  mintAUseSOLBalance || (baseIn ? inputAmount : anotherAmount).isZero()
449
449
  ? {
450
- payer: this.scope.ownerPubKey,
451
- amount: baseIn ? inputAmount : anotherAmount,
452
- }
450
+ payer: this.scope.ownerPubKey,
451
+ amount: baseIn ? inputAmount : anotherAmount,
452
+ }
453
453
  : undefined,
454
454
  skipCloseAccount: !mintAUseSOLBalance,
455
455
  notUseTokenAccount: mintAUseSOLBalance,
@@ -468,9 +468,9 @@ export default class CpmmModule extends ModuleBase {
468
468
  createInfo:
469
469
  mintBUseSOLBalance || (baseIn ? anotherAmount : inputAmount).isZero()
470
470
  ? {
471
- payer: this.scope.ownerPubKey,
472
- amount: baseIn ? anotherAmount : inputAmount,
473
- }
471
+ payer: this.scope.ownerPubKey,
472
+ amount: baseIn ? anotherAmount : inputAmount,
473
+ }
474
474
  : undefined,
475
475
  skipCloseAccount: !mintBUseSOLBalance,
476
476
  notUseTokenAccount: mintBUseSOLBalance,
@@ -541,8 +541,8 @@ export default class CpmmModule extends ModuleBase {
541
541
 
542
542
  const epochInfo = await this.scope.fetchEpochInfo();
543
543
  const [mintAAmountFee, mintBAmountFee] = [
544
- getTransferAmountFeeV2(amountMintA, poolInfo.mintA.extensions.feeConfig, epochInfo, true),
545
- getTransferAmountFeeV2(amountMintB, poolInfo.mintB.extensions.feeConfig, epochInfo, true),
544
+ getTransferAmountFeeV2(amountMintA, poolInfo.mintA.extensions.feeConfig, epochInfo, false),
545
+ getTransferAmountFeeV2(amountMintB, poolInfo.mintB.extensions.feeConfig, epochInfo, false),
546
546
  ];
547
547
 
548
548
  const { account } = this.scope;
@@ -662,9 +662,9 @@ export default class CpmmModule extends ModuleBase {
662
662
  createInfo:
663
663
  mintAUseSOLBalance || !baseIn
664
664
  ? {
665
- payer: this.scope.ownerPubKey,
666
- amount: baseIn ? swapResult.sourceAmountSwapped : 0,
667
- }
665
+ payer: this.scope.ownerPubKey,
666
+ amount: baseIn ? swapResult.sourceAmountSwapped : 0,
667
+ }
668
668
  : undefined,
669
669
  notUseTokenAccount: mintAUseSOLBalance,
670
670
  skipCloseAccount: !mintAUseSOLBalance,
@@ -681,9 +681,9 @@ export default class CpmmModule extends ModuleBase {
681
681
  createInfo:
682
682
  mintBUseSOLBalance || baseIn
683
683
  ? {
684
- payer: this.scope.ownerPubKey,
685
- amount: baseIn ? 0 : swapResult.sourceAmountSwapped,
686
- }
684
+ payer: this.scope.ownerPubKey,
685
+ amount: baseIn ? 0 : swapResult.sourceAmountSwapped,
686
+ }
687
687
  : undefined,
688
688
  notUseTokenAccount: mintBUseSOLBalance,
689
689
  skipCloseAccount: !mintBUseSOLBalance,
@@ -709,48 +709,48 @@ export default class CpmmModule extends ModuleBase {
709
709
  instructions: [
710
710
  baseIn
711
711
  ? makeSwapCpmmBaseInInInstruction(
712
- new PublicKey(poolInfo.programId),
713
- this.scope.ownerPubKey,
714
- new PublicKey(poolKeys.authority),
715
- new PublicKey(poolKeys.config.id),
716
- new PublicKey(poolInfo.id),
717
- mintATokenAcc!,
718
- mintBTokenAcc!,
719
- new PublicKey(poolKeys.vault.A),
720
- new PublicKey(poolKeys.vault.B),
721
- new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
722
- new PublicKey(poolInfo.mintB.programId ?? TOKEN_PROGRAM_ID),
723
- mintA,
724
- mintB,
725
- getPdaObservationId(new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)).publicKey,
726
-
727
- swapResult.sourceAmountSwapped,
728
- swapResult.destinationAmountSwapped,
729
- )
712
+ new PublicKey(poolInfo.programId),
713
+ this.scope.ownerPubKey,
714
+ new PublicKey(poolKeys.authority),
715
+ new PublicKey(poolKeys.config.id),
716
+ new PublicKey(poolInfo.id),
717
+ mintATokenAcc!,
718
+ mintBTokenAcc!,
719
+ new PublicKey(poolKeys.vault.A),
720
+ new PublicKey(poolKeys.vault.B),
721
+ new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
722
+ new PublicKey(poolInfo.mintB.programId ?? TOKEN_PROGRAM_ID),
723
+ mintA,
724
+ mintB,
725
+ getPdaObservationId(new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)).publicKey,
726
+
727
+ swapResult.sourceAmountSwapped,
728
+ swapResult.destinationAmountSwapped,
729
+ )
730
730
  : makeSwapCpmmBaseOutInInstruction(
731
- new PublicKey(poolInfo.programId),
732
- this.scope.ownerPubKey,
733
- new PublicKey(poolKeys.authority),
734
- new PublicKey(poolKeys.config.id),
735
- new PublicKey(poolInfo.id),
731
+ new PublicKey(poolInfo.programId),
732
+ this.scope.ownerPubKey,
733
+ new PublicKey(poolKeys.authority),
734
+ new PublicKey(poolKeys.config.id),
735
+ new PublicKey(poolInfo.id),
736
736
 
737
- mintBTokenAcc!,
738
- mintATokenAcc!,
737
+ mintBTokenAcc!,
738
+ mintATokenAcc!,
739
739
 
740
- new PublicKey(poolKeys.vault.B),
741
- new PublicKey(poolKeys.vault.A),
740
+ new PublicKey(poolKeys.vault.B),
741
+ new PublicKey(poolKeys.vault.A),
742
742
 
743
- new PublicKey(poolInfo.mintB.programId ?? TOKEN_PROGRAM_ID),
744
- new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
743
+ new PublicKey(poolInfo.mintB.programId ?? TOKEN_PROGRAM_ID),
744
+ new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
745
745
 
746
- mintB,
747
- mintA,
746
+ mintB,
747
+ mintA,
748
748
 
749
- getPdaObservationId(new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)).publicKey,
749
+ getPdaObservationId(new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)).publicKey,
750
750
 
751
- swapResult.sourceAmountSwapped,
752
- swapResult.destinationAmountSwapped,
753
- ),
751
+ swapResult.sourceAmountSwapped,
752
+ swapResult.destinationAmountSwapped,
753
+ ),
754
754
  ],
755
755
  instructionTypes: [baseIn ? InstructionType.CpmmSwapBaseIn : InstructionType.CpmmSwapBaseOut],
756
756
  });
@@ -590,10 +590,25 @@ export default class Farm extends ModuleBase {
590
590
  version,
591
591
  });
592
592
  const ledgerData = await this.scope.connection.getAccountInfo(ledger);
593
- if (!ledgerData) this.logAndCreateError("no lp data", { farmId: farmInfo.id, version, ledgerData });
594
- const ledgerLayout = getFarmLedgerLayout(version)!;
595
- const ledgerInfo = ledgerLayout.decode(ledgerData!.data);
596
- if (ledgerInfo.deposited.isZero()) this.logAndCreateError("no deposited lp", { farmId: farmInfo.id });
593
+ if (!ledgerData) {
594
+ // user has old not ata farm vault and don't have ata vault
595
+ if (version !== 6 && (userAuxiliaryLedgers || []).length > 0) {
596
+ const { instruction, instructionType } = createAssociatedLedgerAccountInstruction({
597
+ id: new PublicKey(farmKeys.id),
598
+ programId: new PublicKey(farmKeys.programId),
599
+ version,
600
+ ledger,
601
+ owner: this.scope.ownerPubKey,
602
+ });
603
+ txBuilder.addInstruction({ instructions: [instruction], instructionTypes: [instructionType] });
604
+ } else {
605
+ this.logAndCreateError("no lp data", { farmId: farmInfo.id, version, ledgerData });
606
+ }
607
+ } else {
608
+ const ledgerLayout = getFarmLedgerLayout(version)!;
609
+ const ledgerInfo = ledgerLayout.decode(ledgerData!.data);
610
+ if (ledgerInfo.deposited.isZero()) this.logAndCreateError("no deposited lp", { farmId: farmInfo.id });
611
+ }
597
612
  } else {
598
613
  if (deposited.isZero()) this.logAndCreateError("no deposited lp", { farmId: farmInfo.id });
599
614
  }