@meteora-ag/dlmm 1.3.17-rc.2 → 1.4.0

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # DLMM SDK
2
2
 
3
3
  <p align="center">
4
- <img align="center" src="https://vaults.mercurial.finance/icons/logo.svg" width="180" height="180" />
4
+ <img align="center" src="https://app.meteora.ag/icons/logo.svg" width="180" height="180" />
5
5
  </p>
6
6
  <br>
7
7
 
@@ -48,32 +48,39 @@ const activeBinPricePerToken = dlmmPool.fromPricePerLamport(
48
48
  );
49
49
  ```
50
50
 
51
- - Create Position
51
+ - Create Balance Position
52
52
 
53
53
  ```ts
54
54
  const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin
55
- const minBinId = activeBin.bin_id - TOTAL_RANGE_INTERVAL;
56
- const maxBinId = activeBin.bin_id + TOTAL_RANGE_INTERVAL;
55
+ const minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL;
56
+ const maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL;
57
57
 
58
- const activeBinPricePerToken = dlmmPool.fromPricePerLamport(
59
- Number(activeBin.price)
60
- );
61
- const totalXAmount = new BN(100);
62
- const totalYAmount = totalXAmount.mul(new BN(Number(activeBinPricePerToken)));
63
-
64
- // Create Position (Spot Balance deposit, Please refer ``example.ts` for more example)
65
- const createPositionTx =
66
- await dlmmPool.initializePositionAndAddLiquidityByStrategy({
67
- positionPubKey: newBalancePosition.publicKey,
68
- user: user.publicKey,
58
+ const totalXAmount = new BN(100 * 10 ** baseMint.decimals);
59
+ const totalYAmount = autoFillYByStrategy(
60
+ activeBin.binId,
61
+ dlmmPool.lbPair.binStep,
69
62
  totalXAmount,
70
- totalYAmount,
71
- strategy: {
72
- maxBinId,
73
- minBinId,
74
- strategyType: StrategyType.SpotBalanced,
75
- },
76
- });
63
+ activeBin.xAmount,
64
+ activeBin.yAmount,
65
+ minBinId,
66
+ maxBinId,
67
+ StrategyType.Spot // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
68
+ );
69
+ const newBalancePosition = new Keypair();
70
+
71
+ // Create Position
72
+ const createPositionTx =
73
+ await dlmmPool.initializePositionAndAddLiquidityByStrategy({
74
+ positionPubKey: newBalancePosition.publicKey,
75
+ user: user.publicKey,
76
+ totalXAmount,
77
+ totalYAmount,
78
+ strategy: {
79
+ maxBinId,
80
+ minBinId,
81
+ strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
82
+ },
83
+ });
77
84
 
78
85
  try {
79
86
  const createBalancePositionTxHash = await sendAndConfirmTransaction(
@@ -84,6 +91,73 @@ try {
84
91
  } catch (error) {}
85
92
  ```
86
93
 
94
+ - Create Imbalance Position
95
+ ```ts
96
+ const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin
97
+ const minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL;
98
+ const maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL;
99
+
100
+ const totalXAmount = new BN(100 * 10 ** baseMint.decimals);
101
+ const totalYAmount = new BN(0.5 * 10 ** 9); // SOL
102
+ const newImbalancePosition = new Keypair();
103
+
104
+ // Create Position
105
+ const createPositionTx =
106
+ await dlmmPool.initializePositionAndAddLiquidityByStrategy({
107
+ positionPubKey: newImbalancePosition.publicKey,
108
+ user: user.publicKey,
109
+ totalXAmount,
110
+ totalYAmount,
111
+ strategy: {
112
+ maxBinId,
113
+ minBinId,
114
+ strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
115
+ },
116
+ });
117
+
118
+ try {
119
+ const createBalancePositionTxHash = await sendAndConfirmTransaction(
120
+ connection,
121
+ createPositionTx,
122
+ [user, newImbalancePosition]
123
+ );
124
+ } catch (error) {}
125
+ ```
126
+
127
+ - Create One Side Position
128
+
129
+ ```ts
130
+ const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin
131
+ const minBinId = activeBin.binId;
132
+ const maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL * 2;
133
+
134
+ const totalXAmount = new BN(100 * 10 ** baseMint.decimals);
135
+ const totalYAmount = new BN(0);
136
+ const newOneSidePosition = new Keypair();
137
+
138
+ // Create Position
139
+ const createPositionTx =
140
+ await dlmmPool.initializePositionAndAddLiquidityByStrategy({
141
+ positionPubKey: newOneSidePosition.publicKey,
142
+ user: user.publicKey,
143
+ totalXAmount,
144
+ totalYAmount,
145
+ strategy: {
146
+ maxBinId,
147
+ minBinId,
148
+ strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
149
+ },
150
+ });
151
+
152
+ try {
153
+ const createOneSidePositionTxHash = await sendAndConfirmTransaction(
154
+ connection,
155
+ createPositionTx,
156
+ [user, newOneSidePosition]
157
+ );
158
+ } catch (error) {}
159
+ ```
160
+
87
161
  - Get list of positions
88
162
 
89
163
  ```ts
@@ -97,27 +171,33 @@ const binData = userPositions[0].positionData.positionBinData;
97
171
 
98
172
  ```ts
99
173
  const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin
100
- const minBinId = activeBin.bin_id - TOTAL_RANGE_INTERVAL;
101
- const maxBinId = activeBin.bin_id + TOTAL_RANGE_INTERVAL;
102
-
103
- const activeBinPricePerToken = dlmmPool.fromPricePerLamport(
104
- Number(activeBin.price)
105
- );
106
- const totalXAmount = new BN(100);
107
- const totalYAmount = totalXAmount.mul(new BN(Number(activeBinPricePerToken)));
174
+ const minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL;
175
+ const maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL;
108
176
 
109
- // Add Liquidity to existing position
110
- const addLiquidityTx = await dlmmPool.addLiquidityByStrategy({
111
- positionPubKey: newBalancePosition.publicKey,
112
- user: user.publicKey,
113
- totalXAmount,
114
- totalYAmount,
115
- strategy: {
116
- maxBinId,
177
+ const totalXAmount = new BN(100 * 10 ** baseMint.decimals);
178
+ const totalYAmount = autoFillYByStrategy(
179
+ activeBin.binId,
180
+ dlmmPool.lbPair.binStep,
181
+ totalXAmount,
182
+ activeBin.xAmount,
183
+ activeBin.yAmount,
117
184
  minBinId,
118
- strategyType: StrategyType.SpotBalanced,
119
- },
120
- });
185
+ maxBinId,
186
+ StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
187
+ );
188
+
189
+ // Add Liquidity to existing position
190
+ const addLiquidityTx = await dlmmPool.addLiquidityByStrategy({
191
+ positionPubKey: newBalancePosition.publicKey,
192
+ user: user.publicKey,
193
+ totalXAmount,
194
+ totalYAmount,
195
+ strategy: {
196
+ maxBinId,
197
+ minBinId,
198
+ strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve
199
+ },
200
+ });
121
201
 
122
202
  try {
123
203
  const addLiquidityTxHash = await sendAndConfirmTransaction(
@@ -162,30 +242,44 @@ try {
162
242
  } catch (error) {}
163
243
  ```
164
244
 
245
+ - Close Position
246
+
247
+ ```ts
248
+ const closePositionTx = await dlmmPool.closePosition({
249
+ owner: user.publicKey,
250
+ position: newBalancePosition.publicKey,
251
+ });
252
+
253
+ try {
254
+ const closePositionTxHash = await sendAndConfirmTransaction(
255
+ connection,
256
+ closePositionTx,
257
+ [user],
258
+ { skipPreflight: false, preflightCommitment: "singleGossip" }
259
+ );
260
+ } catch (error) {}
261
+ ```
262
+
165
263
  - Swap
166
264
 
167
265
  ```ts
168
- const swapAmount = new BN(100);
169
- // Swap quote
170
- const swapYtoX = true;
171
- const binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX);
172
- const swapQuote = await dlmmPool.swapQuote(
173
- swapAmount,
174
- swapYtoX,
175
- new BN(10),
176
- binArrays
177
- );
266
+ const swapAmount = new BN(0.1 * 10 ** 9);
267
+ // Swap quote
268
+ const swapYtoX = true;
269
+ const binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX);
270
+
271
+ const swapQuote = await dlmmPool.swapQuote(swapAmount, swapYtoX, new BN(1), binArrays);
178
272
 
179
273
  // Swap
180
274
  const swapTx = await dlmmPool.swap({
181
- inToken: dlmmPool.tokenX.publicKey,
182
- binArraysPubkey: swapQuote.binArraysPubkey,
183
- inAmount: swapAmount,
184
- lbPair: dlmmPool.pubkey,
185
- user: user.publicKey,
186
- minOutAmount: swapQuote.minOutAmount,
187
- outToken: dlmmPool.tokenY.publicKey,
188
- });
275
+ inToken: dlmmPool.tokenX.publicKey,
276
+ binArraysPubkey: swapQuote.binArraysPubkey,
277
+ inAmount: swapAmount,
278
+ lbPair: dlmmPool.pubkey,
279
+ user: user.publicKey,
280
+ minOutAmount: swapQuote.minOutAmount,
281
+ outToken: dlmmPool.tokenY.publicKey,
282
+ });
189
283
 
190
284
  try {
191
285
  const swapTxHash = await sendAndConfirmTransaction(connection, swapTx, [
@@ -200,7 +294,11 @@ try {
200
294
  | ----------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------ |
201
295
  | `create` | Given the DLMM address, create an instance to access the state and functions | `Promise<DLMM>` |
202
296
  | `createMultiple` | Given a list of DLMM addresses, create instances to access the state and functions | `Promise<Array<DLMM>>` |
203
- | `getAllLbPairPositionsByUser` | Given a list of DLMM addresses, create instances to access the state and functions | `Promise<Map<string, PositionInfo>>` |
297
+ | `getAllPresetParameters` | Get all the preset params (use to create DLMM pool) | `Promise<PresetParams>` |
298
+ | `createPermissionLbPair` | Create DLMM Pool | `Promise<Transcation>` |
299
+ | `getClaimableLMReward` | Get Claimable LM reward for a position | `Promise<LMRewards>` |
300
+ | `getClaimableSwapFee` | Get Claimable Swap Fee for a position | `Promise<SwapFee>` |
301
+ | `getAllLbPairPositionsByUser` | Get user's all positions for all DLMM pools | `Promise<Map<string, PositionInfo>>` |
204
302
 
205
303
  ## DLMM instance functions
206
304