@raydium-io/raydium-sdk-v2 0.0.25-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.
Files changed (37) hide show
  1. package/lib/index.d.ts +1 -1
  2. package/lib/index.js +1 -1
  3. package/lib/index.js.map +1 -1
  4. package/lib/index.mjs +1 -1
  5. package/lib/index.mjs.map +1 -1
  6. package/lib/raydium/account/account.d.ts +1 -1
  7. package/lib/raydium/clmm/clmm.d.ts +1 -1
  8. package/lib/raydium/clmm/index.d.ts +1 -1
  9. package/lib/raydium/cpmm/cpmm.d.ts +1 -1
  10. package/lib/raydium/cpmm/cpmm.js +1 -1
  11. package/lib/raydium/cpmm/cpmm.js.map +1 -1
  12. package/lib/raydium/cpmm/cpmm.mjs +1 -1
  13. package/lib/raydium/cpmm/cpmm.mjs.map +1 -1
  14. package/lib/raydium/farm/farm.d.ts +1 -1
  15. package/lib/raydium/ido/ido.d.ts +1 -1
  16. package/lib/raydium/ido/index.d.ts +1 -1
  17. package/lib/raydium/index.d.ts +1 -1
  18. package/lib/raydium/index.js +1 -1
  19. package/lib/raydium/index.js.map +1 -1
  20. package/lib/raydium/index.mjs +1 -1
  21. package/lib/raydium/index.mjs.map +1 -1
  22. package/lib/raydium/liquidity/liquidity.d.ts +1 -1
  23. package/lib/raydium/marketV2/createMarket.d.ts +1 -1
  24. package/lib/raydium/marketV2/index.d.ts +1 -1
  25. package/lib/raydium/moduleBase.d.ts +1 -1
  26. package/lib/raydium/raydium.d.ts +1 -1
  27. package/lib/raydium/raydium.js +1 -1
  28. package/lib/raydium/raydium.js.map +1 -1
  29. package/lib/raydium/raydium.mjs +1 -1
  30. package/lib/raydium/raydium.mjs.map +1 -1
  31. package/lib/raydium/token/token.d.ts +1 -1
  32. package/lib/raydium/tradeV2/trade.d.ts +1 -1
  33. package/lib/raydium/utils1216/index.d.ts +1 -1
  34. package/lib/raydium/utils1216/utils1216.d.ts +1 -1
  35. package/lib/{raydium-1fe6ab0b.d.ts → raydium-d75706f4.d.ts} +3 -2
  36. package/package.json +1 -1
  37. package/src/raydium/cpmm/cpmm.ts +59 -37
@@ -1,6 +1,6 @@
1
1
  import '@solana/web3.js';
2
2
  import '../../type-83523f5f.js';
3
- export { j as default } from '../../raydium-1fe6ab0b.js';
3
+ export { j as default } from '../../raydium-d75706f4.js';
4
4
  import 'bn.js';
5
5
  import '@solana/spl-token';
6
6
  import '../../common/txTool/txType.js';
@@ -1,5 +1,5 @@
1
1
  import '@solana/web3.js';
2
- export { i as default } from '../../raydium-1fe6ab0b.js';
2
+ export { i as default } from '../../raydium-d75706f4.js';
3
3
  import './type.js';
4
4
  import '../../type-83523f5f.js';
5
5
  import '../../api/api.js';
@@ -1,4 +1,4 @@
1
- export { S as SHOW_INFO, d as canClaimErrorType, U as default } from '../../raydium-1fe6ab0b.js';
1
+ export { S as SHOW_INFO, d as canClaimErrorType, U as default } from '../../raydium-d75706f4.js';
2
2
  import '@solana/web3.js';
3
3
  import '../../api/api.js';
4
4
  import 'axios';
@@ -1,7 +1,7 @@
1
1
  import '../../marshmallow/index.js';
2
2
  import '@solana/web3.js';
3
3
  import 'bn.js';
4
- export { S as SHOW_INFO, d as canClaimErrorType, U as default } from '../../raydium-1fe6ab0b.js';
4
+ export { S as SHOW_INFO, d as canClaimErrorType, U as default } from '../../raydium-d75706f4.js';
5
5
  import '../../marshmallow/buffer-layout.js';
6
6
  import '../../api/api.js';
7
7
  import 'axios';
@@ -12,7 +12,7 @@ import Decimal from 'decimal.js';
12
12
  import { AddLiquidityParams, RemoveParams, CreatePoolParam, CreatePoolAddress, ComputeAmountOutParam, SwapParam } from './raydium/liquidity/type.js';
13
13
  import { m as CreateConcentratedPool, O as OpenPositionFromBase, p as OpenPositionFromBaseExtInfo, q as OpenPositionFromLiquidity, r as OpenPositionFromLiquidityExtInfo, I as IncreasePositionFromLiquidity, M as ManipulateLiquidityExtInfo, n as IncreasePositionFromBase, D as DecreaseLiquidity, B as ClosePositionExtInfo, s as InitRewardParams, E as InitRewardExtInfo, t as InitRewardsParams, u as SetRewardParams, v as SetRewardsParams, w as CollectRewardParams, x as CollectRewardsParams, H as HarvestAllRewardsParams } from './type-6fd96950.js';
14
14
  import { ClmmPositionLayout } from './raydium/clmm/layout.js';
15
- import { CreateCpmmPoolParam, CreateCpmmPoolAddress, AddCpmmLiquidityParams, WithdrawCpmmLiquidityParams, CpmmSwapParams, ComputePairAmountParams } from './raydium/cpmm/type.js';
15
+ import { CpmmConfigInfoInterface, CreateCpmmPoolParam, CreateCpmmPoolAddress, AddCpmmLiquidityParams, WithdrawCpmmLiquidityParams, CpmmSwapParams, ComputePairAmountParams } from './raydium/cpmm/type.js';
16
16
  import { CpmmPoolInfoLayout } from './raydium/cpmm/layout.js';
17
17
  import { PoolAccountInfoV4, ReturnTypeGetAddLiquidityDefaultPool } from './raydium/tradeV2/type.js';
18
18
  import { Structure } from './marshmallow/index.js';
@@ -224,9 +224,10 @@ declare class CpmmModule extends ModuleBase {
224
224
  constructor(params: ModuleBaseProps);
225
225
  load(): Promise<void>;
226
226
  getCpmmPoolKeys(poolId: string): Promise<CpmmKeys>;
227
- getRpcPoolInfo(poolId: string): Promise<ReturnType<typeof CpmmPoolInfoLayout.decode> & {
227
+ getRpcPoolInfo(poolId: string, fetchConfigInfo?: boolean): Promise<ReturnType<typeof CpmmPoolInfoLayout.decode> & {
228
228
  baseReserve: BN__default;
229
229
  quoteReserve: BN__default;
230
+ configInfo?: CpmmConfigInfoInterface;
230
231
  }>;
231
232
  createPool<T extends TxVersion>({ programId, poolFeeAccount, startTime, ownerInfo, associatedOnly, checkCreateATAOwner, txVersion, computeBudgetConfig, ...params }: CreateCpmmPoolParam<T>): Promise<MakeTxData<T, {
232
233
  address: CreateCpmmPoolAddress;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raydium-io/raydium-sdk-v2",
3
- "version": "0.0.25-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",
@@ -17,6 +17,7 @@ import {
17
17
  WithdrawCpmmLiquidityParams,
18
18
  CpmmSwapParams,
19
19
  ComputePairAmountParams,
20
+ CpmmConfigInfoInterface,
20
21
  } from "./type";
21
22
  import { getCreatePoolKeys, getPdaObservationId } from "./pda";
22
23
  import {
@@ -27,7 +28,7 @@ import {
27
28
  makeSwapCpmmBaseOutInInstruction,
28
29
  } from "./instruction";
29
30
  import BN from "bn.js";
30
- import { CpmmPoolInfoLayout } from "./layout";
31
+ import { CpmmPoolInfoLayout, CpmmConfigInfoLayout } from "./layout";
31
32
  import Decimal from "decimal.js";
32
33
 
33
34
  export default class CpmmModule extends ModuleBase {
@@ -43,10 +44,14 @@ export default class CpmmModule extends ModuleBase {
43
44
  return ((await this.scope.api.fetchPoolKeysById({ idList: [poolId] })) as CpmmKeys[])[0];
44
45
  }
45
46
 
46
- public async getRpcPoolInfo(poolId: string): Promise<
47
+ public async getRpcPoolInfo(
48
+ poolId: string,
49
+ fetchConfigInfo?: boolean,
50
+ ): Promise<
47
51
  ReturnType<typeof CpmmPoolInfoLayout.decode> & {
48
52
  baseReserve: BN;
49
53
  quoteReserve: BN;
54
+ configInfo?: CpmmConfigInfoInterface;
50
55
  }
51
56
  > {
52
57
  const accountData = await this.scope.connection.getAccountInfo(new PublicKey(poolId));
@@ -60,6 +65,12 @@ export default class CpmmModule extends ModuleBase {
60
65
  if (!poolVaultAState) throw new Error(`pool vaultA info not found: ${poolInfo.vaultA.toBase58()}`);
61
66
  if (!poolVaultBState) throw new Error(`pool vaultB info not found: ${poolInfo.vaultB.toBase58()}`);
62
67
 
68
+ let configInfo: CpmmConfigInfoInterface | undefined;
69
+ if (fetchConfigInfo) {
70
+ const configState = await this.scope.connection.getAccountInfo(poolInfo.configId);
71
+ if (configState) configInfo = CpmmConfigInfoLayout.decode(configState.data);
72
+ }
73
+
63
74
  return {
64
75
  ...poolInfo,
65
76
  baseReserve: new BN(AccountLayout.decode(poolVaultAState.data).amount.toString())
@@ -68,6 +79,7 @@ export default class CpmmModule extends ModuleBase {
68
79
  quoteReserve: new BN(AccountLayout.decode(poolVaultBState.data).amount.toString())
69
80
  .sub(poolInfo.protocolFeesMintB)
70
81
  .sub(poolInfo.fundFeesMintB),
82
+ configInfo,
71
83
  };
72
84
  }
73
85
 
@@ -410,40 +422,50 @@ export default class CpmmModule extends ModuleBase {
410
422
  const txBuilder = this.createTxBuilder();
411
423
 
412
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);
413
427
 
414
- const mintATokenAcc = await this.scope.account.getCreatedTokenAccount({
415
- programId: new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
416
- mint: mintA,
417
- associatedOnly: false,
418
- });
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,
419
433
 
420
- const mintBTokenAcc = await this.scope.account.getCreatedTokenAccount({
421
- programId: new PublicKey(poolInfo.mintB.programId ?? TOKEN_PROGRAM_ID),
422
- mint: mintB,
423
- associatedOnly: false,
424
- });
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
+ });
425
445
 
426
- const { tokenAccount: _mintATokenAcc, ...mintATokenAccInstruction } = await this.scope.account.handleTokenAccount({
427
- side: baseIn ? "in" : "out",
428
- amount: baseIn ? swapResult.sourceAmountSwapped : swapResult.destinationAmountSwapped,
429
- mint: mintA,
430
- tokenAccount: mintATokenAcc,
431
- bypassAssociatedCheck,
432
- checkCreateATAOwner,
433
- });
434
- txBuilder.addInstruction(mintATokenAccInstruction);
446
+ txBuilder.addInstruction(_mintATokenAccountIns || {});
435
447
 
436
- const { tokenAccount: _mintBTokenAcc, ...mintBTokenAccInstruction } = await this.scope.account.handleTokenAccount({
437
- side: baseIn ? "out" : "in",
438
- amount: baseIn ? swapResult.destinationAmountSwapped : swapResult.sourceAmountSwapped,
439
- mint: mintB,
440
- tokenAccount: mintBTokenAcc,
441
- bypassAssociatedCheck,
442
- checkCreateATAOwner,
443
- });
444
- 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 || {});
445
467
 
446
- if (!_mintATokenAcc && !_mintBTokenAcc)
468
+ if (!mintATokenAccount && !mintBTokenAccount)
447
469
  this.logAndCreateError("cannot found target token accounts", "tokenAccounts", this.scope.account.tokenAccounts);
448
470
 
449
471
  const poolKeys = await this.getCpmmPoolKeys(poolInfo.id);
@@ -455,10 +477,10 @@ export default class CpmmModule extends ModuleBase {
455
477
  new PublicKey(poolInfo.programId),
456
478
  this.scope.ownerPubKey,
457
479
  new PublicKey(poolKeys.authority),
458
- new PublicKey(poolKeys.id), // todo config id
480
+ new PublicKey(poolKeys.config.id),
459
481
  new PublicKey(poolInfo.id),
460
- _mintATokenAcc!,
461
- _mintBTokenAcc!,
482
+ mintATokenAccount!,
483
+ mintBTokenAccount!,
462
484
  new PublicKey(poolKeys.vault.A),
463
485
  new PublicKey(poolKeys.vault.B),
464
486
  new PublicKey(poolInfo.mintA.programId ?? TOKEN_PROGRAM_ID),
@@ -474,11 +496,11 @@ export default class CpmmModule extends ModuleBase {
474
496
  new PublicKey(poolInfo.programId),
475
497
  this.scope.ownerPubKey,
476
498
  new PublicKey(poolKeys.authority),
477
- new PublicKey(poolKeys.id), // todo config id
499
+ new PublicKey(poolKeys.config.id),
478
500
  new PublicKey(poolInfo.id),
479
501
 
480
- _mintBTokenAcc!,
481
- _mintATokenAcc!,
502
+ mintBTokenAccount!,
503
+ mintATokenAccount!,
482
504
 
483
505
  new PublicKey(poolKeys.vault.B),
484
506
  new PublicKey(poolKeys.vault.A),