@meteora-ag/dlmm 1.3.15 → 1.3.17-rc.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/dist/index.d.ts CHANGED
@@ -5716,6 +5716,7 @@ declare enum BitmapType {
5716
5716
  U512 = 1
5717
5717
  }
5718
5718
  interface SeedLiquidityResponse {
5719
+ sendPositionOwnerTokenProveIxs: TransactionInstruction[];
5719
5720
  initializeBinArraysAndPositionIxs: TransactionInstruction[][];
5720
5721
  addLiquidityIxs: TransactionInstruction[][];
5721
5722
  }
@@ -6209,9 +6210,14 @@ declare class DLMM {
6209
6210
  * - `minPrice`: Start price in UI format
6210
6211
  * - `maxPrice`: End price in UI format
6211
6212
  * - `base`: Base key
6213
+ * - `txPayer`: Account rental fee payer
6214
+ * - `feeOwner`: Fee owner key. Default to position owner
6215
+ * - `operator`: Operator key
6216
+ * - `lockReleasePoint`: Timelock. Point (slot/timestamp) the position can withdraw the liquidity,
6217
+ * - `shouldSeedPositionOwner` (optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
6212
6218
  * @returns {Promise<SeedLiquidityResponse>}
6213
6219
  */
6214
- seedLiquidity(owner: PublicKey, seedAmount: BN, curvature: number, minPrice: number, maxPrice: number, base: PublicKey): Promise<SeedLiquidityResponse>;
6220
+ seedLiquidity(owner: PublicKey, seedAmount: BN, curvature: number, minPrice: number, maxPrice: number, base: PublicKey, payer: PublicKey, feeOwner: PublicKey, operator: PublicKey, lockReleasePoint: BN, shouldSeedPositionOwner?: boolean): Promise<SeedLiquidityResponse>;
6215
6221
  /**
6216
6222
  * The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be either [initialize bin array + initialize position instructions] or [deposit instruction] combination.
6217
6223
  * @param
package/dist/index.js CHANGED
@@ -9,6 +9,8 @@ var _bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
9
9
 
10
10
 
11
11
 
12
+
13
+
12
14
  var _spltoken = require('@solana/spl-token');
13
15
 
14
16
 
@@ -5477,6 +5479,7 @@ var CONSTANTS = Object.entries(IDL.constants);
5477
5479
  var MAX_BIN_ARRAY_SIZE = new (0, _anchor.BN)(
5478
5480
  _nullishCoalesce(_optionalChain([CONSTANTS, 'access', _2 => _2.find, 'call', _3 => _3(([k, v]) => v.name == "MAX_BIN_PER_ARRAY"), 'optionalAccess', _4 => _4[1], 'access', _5 => _5.value]), () => ( 0))
5479
5481
  );
5482
+ console.log("CONSTANTS", CONSTANTS);
5480
5483
  var MAX_BIN_PER_POSITION = new (0, _anchor.BN)(
5481
5484
  _nullishCoalesce(_optionalChain([CONSTANTS, 'access', _6 => _6.find, 'call', _7 => _7(([k, v]) => v.name == "MAX_BIN_PER_POSITION"), 'optionalAccess', _8 => _8[1], 'access', _9 => _9.value]), () => ( 0))
5482
5485
  );
@@ -6641,7 +6644,7 @@ function derivePosition(lbPair, base, lowerBinId, width, programId) {
6641
6644
  lbPair.toBuffer(),
6642
6645
  base.toBuffer(),
6643
6646
  lowerBinIdBytes,
6644
- new Uint8Array(width.toBuffer("le", 4))
6647
+ new Uint8Array(width.toArrayLike(Buffer, "le", 4))
6645
6648
  ],
6646
6649
  programId
6647
6650
  );
@@ -11042,9 +11045,14 @@ var DLMM = class {
11042
11045
  * - `minPrice`: Start price in UI format
11043
11046
  * - `maxPrice`: End price in UI format
11044
11047
  * - `base`: Base key
11048
+ * - `txPayer`: Account rental fee payer
11049
+ * - `feeOwner`: Fee owner key. Default to position owner
11050
+ * - `operator`: Operator key
11051
+ * - `lockReleasePoint`: Timelock. Point (slot/timestamp) the position can withdraw the liquidity,
11052
+ * - `shouldSeedPositionOwner` (optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
11045
11053
  * @returns {Promise<SeedLiquidityResponse>}
11046
11054
  */
11047
- async seedLiquidity(owner, seedAmount, curvature, minPrice, maxPrice, base) {
11055
+ async seedLiquidity(owner, seedAmount, curvature, minPrice, maxPrice, base, payer, feeOwner, operator, lockReleasePoint, shouldSeedPositionOwner = false) {
11048
11056
  const toLamportMultiplier = new (0, _decimaljs2.default)(
11049
11057
  10 ** (this.tokenY.decimal - this.tokenX.decimal)
11050
11058
  );
@@ -11089,13 +11097,56 @@ var DLMM = class {
11089
11097
  );
11090
11098
  const positionCount = getPositionCount(minBinId, maxBinId.sub(new (0, _anchor.BN)(1)));
11091
11099
  const seederTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
11100
+ this.lbPair.tokenXMint,
11101
+ operator,
11102
+ false
11103
+ );
11104
+ const seederTokenY = _spltoken.getAssociatedTokenAddressSync.call(void 0,
11105
+ this.lbPair.tokenYMint,
11106
+ operator,
11107
+ false
11108
+ );
11109
+ const ownerTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
11092
11110
  this.lbPair.tokenXMint,
11093
11111
  owner,
11094
11112
  false
11095
11113
  );
11114
+ const sendPositionOwnerTokenProveIxs = [];
11096
11115
  const initializeBinArraysAndPositionIxs = [];
11097
11116
  const addLiquidityIxs = [];
11098
11117
  const appendedInitBinArrayIx = /* @__PURE__ */ new Set();
11118
+ if (shouldSeedPositionOwner) {
11119
+ const positionOwnerTokenX = await this.program.provider.connection.getAccountInfo(ownerTokenX);
11120
+ let requireTokenProve = false;
11121
+ if (positionOwnerTokenX) {
11122
+ const ownerTokenXState = _spltoken.unpackAccount.call(void 0,
11123
+ ownerTokenX,
11124
+ positionOwnerTokenX,
11125
+ _spltoken.TOKEN_PROGRAM_ID
11126
+ );
11127
+ requireTokenProve = ownerTokenXState.amount == 0n;
11128
+ } else {
11129
+ requireTokenProve = true;
11130
+ }
11131
+ if (requireTokenProve) {
11132
+ const initPositionOwnerTokenX = _spltoken.createAssociatedTokenAccountIdempotentInstruction.call(void 0,
11133
+ payer,
11134
+ ownerTokenX,
11135
+ owner,
11136
+ this.lbPair.tokenXMint,
11137
+ _spltoken.TOKEN_PROGRAM_ID
11138
+ );
11139
+ sendPositionOwnerTokenProveIxs.push(initPositionOwnerTokenX);
11140
+ sendPositionOwnerTokenProveIxs.push(
11141
+ _spltoken.createTransferInstruction.call(void 0,
11142
+ seederTokenX,
11143
+ ownerTokenX,
11144
+ operator,
11145
+ 1n
11146
+ )
11147
+ );
11148
+ }
11149
+ }
11099
11150
  for (let i = 0; i < positionCount.toNumber(); i++) {
11100
11151
  const lowerBinId = minBinId.add(MAX_BIN_PER_POSITION.mul(new (0, _anchor.BN)(i)));
11101
11152
  const upperBinId = lowerBinId.add(MAX_BIN_PER_POSITION).sub(new (0, _anchor.BN)(1));
@@ -11130,7 +11181,7 @@ var DLMM = class {
11130
11181
  await this.program.methods.initializeBinArray(lowerBinArrayIndex).accounts({
11131
11182
  lbPair: this.pubkey,
11132
11183
  binArray: lowerBinArray,
11133
- funder: owner
11184
+ funder: payer
11134
11185
  }).instruction()
11135
11186
  );
11136
11187
  appendedInitBinArrayIx.add(lowerBinArray.toBase58());
@@ -11141,7 +11192,7 @@ var DLMM = class {
11141
11192
  await this.program.methods.initializeBinArray(upperBinArrayIndex).accounts({
11142
11193
  lbPair: this.pubkey,
11143
11194
  binArray: upperBinArray,
11144
- funder: owner
11195
+ funder: payer
11145
11196
  }).instruction()
11146
11197
  );
11147
11198
  appendedInitBinArrayIx.add(upperBinArray.toBase58());
@@ -11149,26 +11200,25 @@ var DLMM = class {
11149
11200
  const positionAccount = accounts[2];
11150
11201
  if (!positionAccount) {
11151
11202
  instructions.push(
11152
- await this.program.methods.initializePositionPda(
11203
+ await this.program.methods.initializePositionByOperator(
11153
11204
  lowerBinId.toNumber(),
11154
- MAX_BIN_PER_POSITION.toNumber()
11205
+ MAX_BIN_PER_POSITION.toNumber(),
11206
+ feeOwner,
11207
+ lockReleasePoint
11155
11208
  ).accounts({
11156
11209
  lbPair: this.pubkey,
11157
11210
  position: positionPda,
11158
11211
  base,
11159
11212
  owner,
11160
- payer: owner
11213
+ payer,
11214
+ operator,
11215
+ operatorTokenX: seederTokenX,
11216
+ ownerTokenX,
11217
+ systemProgram: _web3js.SystemProgram.programId
11161
11218
  }).instruction()
11162
11219
  );
11163
11220
  }
11164
11221
  if (instructions.length > 1) {
11165
- instructions.push(
11166
- await getEstimatedComputeUnitIxWithBuffer(
11167
- this.program.provider.connection,
11168
- instructions,
11169
- owner
11170
- )
11171
- );
11172
11222
  initializeBinArraysAndPositionIxs.push(instructions);
11173
11223
  instructions = [];
11174
11224
  }
@@ -11198,7 +11248,7 @@ var DLMM = class {
11198
11248
  tokenMint: this.lbPair.tokenXMint,
11199
11249
  binArrayLower: lowerBinArray,
11200
11250
  binArrayUpper: upperBinArray,
11201
- sender: owner
11251
+ sender: operator
11202
11252
  }).instruction()
11203
11253
  );
11204
11254
  if (i + 1 >= positionCount.toNumber() && !finalLoss.isZero()) {
@@ -11222,7 +11272,7 @@ var DLMM = class {
11222
11272
  tokenMint: this.lbPair.tokenXMint,
11223
11273
  binArrayLower: lowerBinArray,
11224
11274
  binArrayUpper: upperBinArray,
11225
- sender: owner
11275
+ sender: operator
11226
11276
  }).instruction()
11227
11277
  );
11228
11278
  }
@@ -11234,7 +11284,9 @@ var DLMM = class {
11234
11284
  ]);
11235
11285
  }
11236
11286
  }
11287
+ console.log("let return");
11237
11288
  return {
11289
+ sendPositionOwnerTokenProveIxs,
11238
11290
  initializeBinArraysAndPositionIxs,
11239
11291
  addLiquidityIxs
11240
11292
  };