@meteora-ag/cp-amm-sdk 1.0.1-rc.8 → 1.0.1

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 (32) hide show
  1. package/README.md +45 -200
  2. package/dist/index.d.mts +3303 -3426
  3. package/dist/index.d.ts +3303 -3426
  4. package/dist/index.js +2251 -795
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +2288 -832
  7. package/dist/index.mjs.map +1 -1
  8. package/node_modules/@types/node/README.md +1 -1
  9. package/node_modules/@types/node/fs.d.ts +15 -16
  10. package/node_modules/@types/node/https.d.ts +3 -1
  11. package/node_modules/@types/node/module.d.ts +50 -5
  12. package/node_modules/@types/node/package.json +4 -4
  13. package/node_modules/@types/node/process.d.ts +28 -0
  14. package/node_modules/@types/node/sqlite.d.ts +63 -17
  15. package/node_modules/@types/node/test.d.ts +82 -0
  16. package/node_modules/@types/node/timers/promises.d.ts +24 -13
  17. package/node_modules/@types/node/timers.d.ts +159 -112
  18. package/node_modules/@types/node/util.d.ts +11 -4
  19. package/node_modules/@types/node/worker_threads.d.ts +1 -0
  20. package/node_modules/bigint-buffer/build/Makefile +2 -2
  21. package/node_modules/bigint-buffer/build/Release/bigint_buffer.node +0 -0
  22. package/node_modules/bigint-buffer/build/Release/obj.target/bigint_buffer/src/bigint-buffer.o +0 -0
  23. package/node_modules/bigint-buffer/build/config.gypi +1 -1
  24. package/node_modules/rpc-websockets/node_modules/@types/ws/README.md +1 -1
  25. package/node_modules/rpc-websockets/node_modules/@types/ws/index.d.mts +1 -1
  26. package/node_modules/rpc-websockets/node_modules/@types/ws/index.d.ts +1 -1
  27. package/node_modules/rpc-websockets/node_modules/@types/ws/package.json +3 -3
  28. package/node_modules/undici-types/dispatcher.d.ts +1 -0
  29. package/node_modules/undici-types/package.json +1 -1
  30. package/node_modules/undici-types/readable.d.ts +5 -0
  31. package/node_modules/undici-types/webidl.d.ts +6 -0
  32. package/package.json +42 -41
package/README.md CHANGED
@@ -1,201 +1,46 @@
1
- # CP-AMM SDK
2
-
3
- The main example for SDK
4
-
5
- ## 1. Create a CpAmm instance
6
- ```ts
7
- const cpAmm = new CpAmm(connection, programId)
8
- ```
9
- Note: Flexible setup for mainnet/devnet by connection and programId.
10
- ## 2. Create customize pool
11
- ```ts
12
- // Setup base fee
13
- const baseFee: BaseFee = {
14
- cliffFeeNumerator: new BN(1_000_000), // 1%
15
- numberOfPeriod: 10,
16
- periodFrequency: new BN(10),
17
- reductionFactor: new BN(2),
18
- feeSchedulerMode: 0, // 0: Linear, 1: Exponential
19
- };
20
-
21
- // Setup dynamic fee (Optional)
22
- type DynamicFee = {
23
- binStep: number;
24
- binStepU128: BN;
25
- filterPeriod: number;
26
- decayPeriod: number;
27
- reductionFactor: number;
28
- maxVolatilityAccumulator: number;
29
- variableFeeControl: number;
30
- };
31
-
32
- // Setup pool fees
33
- const poolFees: PoolFeesParams = {
34
- baseFee,
35
- protocolFeePercent: 20,
36
- partnerFeePercent: 0,
37
- referralFeePercent: 20,
38
- dynamicFee: null, // Optional dynamic fee
39
- };
40
-
41
- // Setup params
42
- const params: InitializeCustomizeablePoolParams = {
43
- payer: wallet.publicKey,
44
- creator: wallet.publicKey,
45
- positionNft: positionNft.publicKey, // position nft pubkey, User can choose specific keypair.
46
- tokenX,
47
- tokenY,
48
- tokenXAmount: new BN(1000 * 10 ** 6), // amount token X
49
- tokenYAmount: new BN(1000 * 10 ** 9), // amount token Y
50
- tokenXDecimal: 6,
51
- tokenYDecimal: 9,
52
- poolFees, // poolFees setup above
53
- hasAlphaVault: false,
54
- activationType: 1, // 0: slot, 1: timestamp
55
- collectFeeMode: 0, // 0: BothToken 1: OnlyB
56
- activationPoint: null,
57
- };
58
-
59
- const {tx: transaction, pool} = await cpAmm.createCustomPool(params);
60
- ```
61
- Note: We need two signers for transaction: positionNft & payer.
62
-
63
- ## 3. Create position
64
- ```ts
65
- // Prepare create position params
66
- const createPositionParams: CreatePositionParams = {
67
- owner: wallet.publicKey,
68
- payer: wallet.publicKey,
69
- pool: pool,
70
- positionNft: positionNft.publicKey,
71
- };
72
- // Build transaction
73
- const transaction = await cpAmm.createPosition(createPositionParams);
74
- ```
75
- Note: We need two signers for transaction: positionNft & payer.
76
-
77
- ## 5. Add liquidity
78
- ```ts
79
- // Calculate liquidity delta will add by supply max amount for tokenA & tokenB
80
- const positionState = await cpAmm.fetchPositionState(position);
81
- const poolState = await cpAmm.fetchPoolState(pool);
82
- const {
83
- sqrtPrice,
84
- sqrtMaxPrice,
85
- sqrtMinPrice,
86
- tokenAMint,
87
- tokenBMint,
88
- tokenAVault,
89
- tokenBVault,
90
- tokenAFlag,
91
- tokenBFlag,
92
- } = poolState;
93
-
94
- const liquidityDelta = await cpAmm.getLiquidityDelta({
95
- maxAmountTokenA: new BN(100_000 * 10 ** 6),
96
- maxAmountTokenB: new BN(100_000 * 10 ** 9),
97
- tokenAMint,
98
- tokenBMint,
99
- sqrtMaxPrice,
100
- sqrtMinPrice,
101
- sqrtPrice,
102
- });
103
-
104
- const transaction = await cpAmm.addLiquidity({
105
- owner: wallet.publicKey,
106
- position,
107
- pool,
108
- positionNftMint: positionState.nftMint,
109
- liquidityDeltaQ64: liquidityDelta,
110
- tokenAAmountThreshold: new BN(100000000735553),
111
- tokenBAmountThreshold: new BN(100000000735553),
112
- tokenAMint,
113
- tokenBMint,
114
- tokenAVault,
115
- tokenBVault,
116
- tokenAProgram: getTokenProgram(tokenAFlag),
117
- tokenBProgram: getTokenProgram(tokenBFlag),
118
- });
119
- ```
120
-
121
- ## 6. Swap
122
- ```ts
123
- const poolState = await cpAmm.fetchPoolState(pool);
124
- const {
125
- tokenAMint,
126
- tokenBMint,
127
- tokenAVault,
128
- tokenBVault,
129
- tokenAFlag,
130
- tokenBFlag,
131
- } = poolState;
132
-
133
- const slippage = 5; // 5%
134
- // Get quotes
135
- const quotes = await cpAmm.getQuote({
136
- inAmount: new BN(1000 * 10 ** 6),
137
- inputTokenMint: tokenAMint,
138
- slippage,
139
- poolState,
140
- });
141
-
142
- const transaction = await cpAmm.swap({
143
- payer: wallet.publicKey,
144
- pool,
145
- inputTokenMint: tokenAMint,
146
- outputTokenMint: tokenBMint,
147
- amountIn: new BN(1000 * 10 ** 6),
148
- minimumAmountOut: new BN(10),
149
- tokenAMint,
150
- tokenBMint,
151
- tokenAVault,
152
- tokenBVault,
153
- tokenAProgram: getTokenProgram(tokenAFlag),
154
- tokenBProgram: getTokenProgram(tokenBFlag),
155
- referralTokenAccount: null,
156
- });
157
- ```
158
-
159
- ## 7. Remove liquidity
160
- ```ts
161
- const positionState = await cpAmm.fetchPositionState(position);
162
- const poolState = await cpAmm.fetchPoolState(pool);
163
- const {
164
- sqrtPrice,
165
- sqrtMaxPrice,
166
- sqrtMinPrice,
167
- tokenAMint,
168
- tokenBMint,
169
- tokenAVault,
170
- tokenBVault,
171
- tokenAFlag,
172
- tokenBFlag,
173
- } = poolState;
174
-
175
- const liquidityDelta = await cpAmm.getLiquidityDelta({
176
- maxAmountTokenA: new BN(100_000 * 10 ** 6),
177
- maxAmountTokenB: new BN(100_000 * 10 ** 9),
178
- tokenAMint,
179
- tokenBMint,
180
- sqrtMaxPrice,
181
- sqrtMinPrice,
182
- sqrtPrice,
183
- });
184
-
185
- const transaction = await cpAmm.removeLiquidity({
186
- owner: wallet.publicKey,
187
- position,
188
- pool,
189
- positionNftMint: positionState.nftMint,
190
- liquidityDeltaQ64: liquidityDelta,
191
- tokenAAmountThreshold: new BN(0),
192
- tokenBAmountThreshold: new BN(0),
193
- tokenAMint,
194
- tokenBMint,
195
- tokenAVault,
196
- tokenBVault,
197
- tokenAProgram: getTokenProgram(tokenAFlag),
198
- tokenBProgram: getTokenProgram(tokenBFlag),
199
- });
200
- ```
1
+ # Meteora Constant Product AMM SDK (DAMM V2 SDK)
201
2
 
3
+ A TypeScript SDK for interacting with the Dynamic CP-AMM on Meteora
4
+
5
+ ## Overview
6
+
7
+ This SDK provides a set of tools and methods to interact with the [Meteora Dynamic CP-AMM](https://github.com/MeteoraAg/cp-amm). It simplifies common operations like creating pools, managing positions, adding/removing liquidity, swapping tokens, and claiming rewards.
8
+
9
+ For detailed technical documentation, please refer to the [CP-AMM SDK Documentation](https://github.com/MeteoraAg/cp-amm-sdk/blob/main/docs.md).
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pnpm install @meteora-ag/cp-amm-sdk
15
+ # or
16
+ yarn add @meteora-ag/cp-amm-sdk
17
+ ```
18
+
19
+ ### Initialization
20
+
21
+ ```typescript
22
+ import { Connection } from "@solana/web3.js";
23
+ import { CpAmm } from "@meteora-ag/cp-amm-sdk";
24
+
25
+ // Initialize a connection to the Solana network
26
+ const connection = new Connection("https://api.mainnet-beta.solana.com");
27
+
28
+ // Create a new instance of the CpAmm SDK
29
+ const cpAmm = new CpAmm(connection);
30
+ ```
31
+
32
+ ### Test
33
+
34
+ ```
35
+ pnpm install
36
+ pnpm test
37
+ ```
38
+
39
+ ## Deployments
40
+
41
+ - Mainnet-beta: cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG
42
+ - Devnet: cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG
43
+
44
+ ## Faucets
45
+
46
+ https://faucet.raccoons.dev/