@meteora-ag/dlmm 1.3.1 → 1.3.4
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 +31 -5
- package/dist/index.js +517 -306
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +738 -527
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/dlmm/index.ts
|
|
2
|
+
var _anchor = require('@coral-xyz/anchor');
|
|
3
|
+
var _bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _spltoken = require('@solana/spl-token');
|
|
13
|
+
|
|
2
14
|
|
|
3
15
|
|
|
4
16
|
|
|
@@ -6,6 +18,10 @@
|
|
|
6
18
|
|
|
7
19
|
|
|
8
20
|
var _web3js = require('@solana/web3.js');
|
|
21
|
+
var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault(_decimaljs);
|
|
22
|
+
|
|
23
|
+
// src/dlmm/constants/index.ts
|
|
24
|
+
|
|
9
25
|
|
|
10
26
|
// src/dlmm/idl.ts
|
|
11
27
|
var IDL = {
|
|
@@ -5260,7 +5276,6 @@ var IDL = {
|
|
|
5260
5276
|
|
|
5261
5277
|
// src/dlmm/constants/index.ts
|
|
5262
5278
|
|
|
5263
|
-
var _anchor = require('@coral-xyz/anchor');
|
|
5264
5279
|
var LBCLMM_PROGRAM_IDS = {
|
|
5265
5280
|
devnet: "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo",
|
|
5266
5281
|
localhost: "LbVRzDTvBDEcrthxfZ4RL6yiq3uZw8bS6MwtdY6UhFQ",
|
|
@@ -5309,66 +5324,48 @@ var ILM_BASE = new (0, _web3js.PublicKey)(
|
|
|
5309
5324
|
"MFGQxwAmB91SwuYX36okv2Qmdc9aMuHTwWGUrp4AtB1"
|
|
5310
5325
|
);
|
|
5311
5326
|
|
|
5312
|
-
// src/dlmm/
|
|
5313
|
-
var _borsh = require('@coral-xyz/borsh');
|
|
5314
|
-
var PositionVersion = /* @__PURE__ */ ((PositionVersion2) => {
|
|
5315
|
-
PositionVersion2[PositionVersion2["V1"] = 0] = "V1";
|
|
5316
|
-
PositionVersion2[PositionVersion2["V2"] = 1] = "V2";
|
|
5317
|
-
return PositionVersion2;
|
|
5318
|
-
})(PositionVersion || {});
|
|
5319
|
-
var PairType = /* @__PURE__ */ ((PairType2) => {
|
|
5320
|
-
PairType2[PairType2["Permissionless"] = 0] = "Permissionless";
|
|
5321
|
-
PairType2[PairType2["Permissioned"] = 1] = "Permissioned";
|
|
5322
|
-
return PairType2;
|
|
5323
|
-
})(PairType || {});
|
|
5324
|
-
var Strategy = {
|
|
5325
|
-
SpotOneSide: { spotOneSide: {} },
|
|
5326
|
-
CurveOneSide: { curveOneSide: {} },
|
|
5327
|
-
BidAskOneSide: { bidAskOneSide: {} },
|
|
5328
|
-
SpotBalanced: { spotBalanced: {} },
|
|
5329
|
-
CurveBalanced: { curveBalanced: {} },
|
|
5330
|
-
BidAskBalanced: { bidAskBalanced: {} },
|
|
5331
|
-
SpotImBalanced: { spotImBalanced: {} },
|
|
5332
|
-
CurveImBalanced: { curveImBalanced: {} },
|
|
5333
|
-
BidAskImBalanced: { bidAskImBalanced: {} }
|
|
5334
|
-
};
|
|
5335
|
-
var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
5336
|
-
StrategyType2[StrategyType2["SpotOneSide"] = 0] = "SpotOneSide";
|
|
5337
|
-
StrategyType2[StrategyType2["CurveOneSide"] = 1] = "CurveOneSide";
|
|
5338
|
-
StrategyType2[StrategyType2["BidAskOneSide"] = 2] = "BidAskOneSide";
|
|
5339
|
-
StrategyType2[StrategyType2["SpotImBalanced"] = 3] = "SpotImBalanced";
|
|
5340
|
-
StrategyType2[StrategyType2["CurveImBalanced"] = 4] = "CurveImBalanced";
|
|
5341
|
-
StrategyType2[StrategyType2["BidAskImBalanced"] = 5] = "BidAskImBalanced";
|
|
5342
|
-
StrategyType2[StrategyType2["SpotBalanced"] = 6] = "SpotBalanced";
|
|
5343
|
-
StrategyType2[StrategyType2["CurveBalanced"] = 7] = "CurveBalanced";
|
|
5344
|
-
StrategyType2[StrategyType2["BidAskBalanced"] = 8] = "BidAskBalanced";
|
|
5345
|
-
return StrategyType2;
|
|
5346
|
-
})(StrategyType || {});
|
|
5347
|
-
var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
|
|
5348
|
-
ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
|
|
5349
|
-
ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
|
|
5350
|
-
return ActivationType2;
|
|
5351
|
-
})(ActivationType || {});
|
|
5352
|
-
var BitmapType = /* @__PURE__ */ ((BitmapType2) => {
|
|
5353
|
-
BitmapType2[BitmapType2["U1024"] = 0] = "U1024";
|
|
5354
|
-
BitmapType2[BitmapType2["U512"] = 1] = "U512";
|
|
5355
|
-
return BitmapType2;
|
|
5356
|
-
})(BitmapType || {});
|
|
5357
|
-
var ClockLayout = _borsh.struct.call(void 0, [
|
|
5358
|
-
_borsh.u64.call(void 0, "slot"),
|
|
5359
|
-
_borsh.i64.call(void 0, "epochStartTimestamp"),
|
|
5360
|
-
_borsh.u64.call(void 0, "epoch"),
|
|
5361
|
-
_borsh.u64.call(void 0, "leaderScheduleEpoch"),
|
|
5362
|
-
_borsh.i64.call(void 0, "unixTimestamp")
|
|
5363
|
-
]);
|
|
5364
|
-
var PairStatus = /* @__PURE__ */ ((PairStatus2) => {
|
|
5365
|
-
PairStatus2[PairStatus2["Enabled"] = 0] = "Enabled";
|
|
5366
|
-
PairStatus2[PairStatus2["Disabled"] = 1] = "Disabled";
|
|
5367
|
-
return PairStatus2;
|
|
5368
|
-
})(PairStatus || {});
|
|
5369
|
-
|
|
5370
|
-
// src/dlmm/index.ts
|
|
5327
|
+
// src/dlmm/error.ts
|
|
5371
5328
|
|
|
5329
|
+
var DLMMError = class extends Error {
|
|
5330
|
+
|
|
5331
|
+
|
|
5332
|
+
|
|
5333
|
+
constructor(error) {
|
|
5334
|
+
let _errorCode = 0;
|
|
5335
|
+
let _errorName = "Something went wrong";
|
|
5336
|
+
let _errorMessage = "Something went wrong";
|
|
5337
|
+
if (error instanceof Error) {
|
|
5338
|
+
const anchorError = _anchor.AnchorError.parse(
|
|
5339
|
+
JSON.parse(JSON.stringify(error)).logs
|
|
5340
|
+
);
|
|
5341
|
+
if (_optionalChain([anchorError, 'optionalAccess', _18 => _18.program, 'access', _19 => _19.toBase58, 'call', _20 => _20()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
|
|
5342
|
+
_errorCode = anchorError.error.errorCode.number;
|
|
5343
|
+
_errorName = anchorError.error.errorCode.code;
|
|
5344
|
+
_errorMessage = anchorError.error.errorMessage;
|
|
5345
|
+
}
|
|
5346
|
+
} else {
|
|
5347
|
+
const idlError = IDL.errors.find((err) => err.code === error);
|
|
5348
|
+
if (idlError) {
|
|
5349
|
+
_errorCode = idlError.code;
|
|
5350
|
+
_errorName = idlError.name;
|
|
5351
|
+
_errorMessage = idlError.msg;
|
|
5352
|
+
}
|
|
5353
|
+
}
|
|
5354
|
+
super(_errorMessage);
|
|
5355
|
+
this.errorCode = _errorCode;
|
|
5356
|
+
this.errorName = _errorName;
|
|
5357
|
+
this.errorMessage = _errorMessage;
|
|
5358
|
+
}
|
|
5359
|
+
};
|
|
5360
|
+
var DlmmSdkError = class extends Error {
|
|
5361
|
+
|
|
5362
|
+
|
|
5363
|
+
constructor(name, message) {
|
|
5364
|
+
super();
|
|
5365
|
+
this.name = name;
|
|
5366
|
+
this.message = message;
|
|
5367
|
+
}
|
|
5368
|
+
};
|
|
5372
5369
|
|
|
5373
5370
|
// src/dlmm/helpers/index.ts
|
|
5374
5371
|
|
|
@@ -5381,7 +5378,7 @@ var PairStatus = /* @__PURE__ */ ((PairStatus2) => {
|
|
|
5381
5378
|
|
|
5382
5379
|
|
|
5383
5380
|
|
|
5384
|
-
|
|
5381
|
+
|
|
5385
5382
|
|
|
5386
5383
|
|
|
5387
5384
|
|
|
@@ -5390,7 +5387,7 @@ var _spltoken = require('@solana/spl-token');
|
|
|
5390
5387
|
|
|
5391
5388
|
// src/dlmm/helpers/math.ts
|
|
5392
5389
|
|
|
5393
|
-
|
|
5390
|
+
|
|
5394
5391
|
|
|
5395
5392
|
// src/dlmm/helpers/u64xu64_math.ts
|
|
5396
5393
|
var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
|
|
@@ -6344,6 +6341,14 @@ function generateBinAmount(amount, binStep, binId, tokenXDecimal, tokenYDecimal,
|
|
|
6344
6341
|
return new (0, _anchor.BN)(c1.sub(c0).floor().toString());
|
|
6345
6342
|
}
|
|
6346
6343
|
|
|
6344
|
+
// src/dlmm/helpers/index.ts
|
|
6345
|
+
var _helpers = require('@solana-developers/helpers');
|
|
6346
|
+
|
|
6347
|
+
// src/dlmm/helpers/computeUnit.ts
|
|
6348
|
+
var DEFAULT_ADD_LIQUIDITY_CU = 8e5;
|
|
6349
|
+
var MIN_CU_BUFFER = 5e4;
|
|
6350
|
+
var MAX_CU_BUFFER = 2e5;
|
|
6351
|
+
|
|
6347
6352
|
// src/dlmm/helpers/derive.ts
|
|
6348
6353
|
|
|
6349
6354
|
function sortTokenMints(tokenX, tokenY) {
|
|
@@ -6461,6 +6466,105 @@ function deriveReserve(token, lbPair, programId) {
|
|
|
6461
6466
|
// src/dlmm/helpers/binArray.ts
|
|
6462
6467
|
|
|
6463
6468
|
|
|
6469
|
+
|
|
6470
|
+
// src/dlmm/types/index.ts
|
|
6471
|
+
|
|
6472
|
+
|
|
6473
|
+
|
|
6474
|
+
|
|
6475
|
+
var _borsh = require('@coral-xyz/borsh');
|
|
6476
|
+
var PositionVersion = /* @__PURE__ */ ((PositionVersion2) => {
|
|
6477
|
+
PositionVersion2[PositionVersion2["V1"] = 0] = "V1";
|
|
6478
|
+
PositionVersion2[PositionVersion2["V2"] = 1] = "V2";
|
|
6479
|
+
return PositionVersion2;
|
|
6480
|
+
})(PositionVersion || {});
|
|
6481
|
+
var PairType = /* @__PURE__ */ ((PairType2) => {
|
|
6482
|
+
PairType2[PairType2["Permissionless"] = 0] = "Permissionless";
|
|
6483
|
+
PairType2[PairType2["Permissioned"] = 1] = "Permissioned";
|
|
6484
|
+
return PairType2;
|
|
6485
|
+
})(PairType || {});
|
|
6486
|
+
var Strategy = {
|
|
6487
|
+
SpotOneSide: { spotOneSide: {} },
|
|
6488
|
+
CurveOneSide: { curveOneSide: {} },
|
|
6489
|
+
BidAskOneSide: { bidAskOneSide: {} },
|
|
6490
|
+
SpotBalanced: { spotBalanced: {} },
|
|
6491
|
+
CurveBalanced: { curveBalanced: {} },
|
|
6492
|
+
BidAskBalanced: { bidAskBalanced: {} },
|
|
6493
|
+
SpotImBalanced: { spotImBalanced: {} },
|
|
6494
|
+
CurveImBalanced: { curveImBalanced: {} },
|
|
6495
|
+
BidAskImBalanced: { bidAskImBalanced: {} }
|
|
6496
|
+
};
|
|
6497
|
+
var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
6498
|
+
StrategyType2[StrategyType2["SpotOneSide"] = 0] = "SpotOneSide";
|
|
6499
|
+
StrategyType2[StrategyType2["CurveOneSide"] = 1] = "CurveOneSide";
|
|
6500
|
+
StrategyType2[StrategyType2["BidAskOneSide"] = 2] = "BidAskOneSide";
|
|
6501
|
+
StrategyType2[StrategyType2["SpotImBalanced"] = 3] = "SpotImBalanced";
|
|
6502
|
+
StrategyType2[StrategyType2["CurveImBalanced"] = 4] = "CurveImBalanced";
|
|
6503
|
+
StrategyType2[StrategyType2["BidAskImBalanced"] = 5] = "BidAskImBalanced";
|
|
6504
|
+
StrategyType2[StrategyType2["SpotBalanced"] = 6] = "SpotBalanced";
|
|
6505
|
+
StrategyType2[StrategyType2["CurveBalanced"] = 7] = "CurveBalanced";
|
|
6506
|
+
StrategyType2[StrategyType2["BidAskBalanced"] = 8] = "BidAskBalanced";
|
|
6507
|
+
return StrategyType2;
|
|
6508
|
+
})(StrategyType || {});
|
|
6509
|
+
var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
|
|
6510
|
+
ActivationType2[ActivationType2["Slot"] = 0] = "Slot";
|
|
6511
|
+
ActivationType2[ActivationType2["Timestamp"] = 1] = "Timestamp";
|
|
6512
|
+
return ActivationType2;
|
|
6513
|
+
})(ActivationType || {});
|
|
6514
|
+
var BinLiquidity;
|
|
6515
|
+
((BinLiquidity3) => {
|
|
6516
|
+
function fromBin(bin, binId, binStep, baseTokenDecimal, quoteTokenDecimal, version) {
|
|
6517
|
+
const pricePerLamport = getPriceOfBinByBinId(
|
|
6518
|
+
binId,
|
|
6519
|
+
binStep
|
|
6520
|
+
).toString();
|
|
6521
|
+
return {
|
|
6522
|
+
binId,
|
|
6523
|
+
xAmount: bin.amountX,
|
|
6524
|
+
yAmount: bin.amountY,
|
|
6525
|
+
supply: bin.liquiditySupply,
|
|
6526
|
+
price: pricePerLamport,
|
|
6527
|
+
version,
|
|
6528
|
+
pricePerToken: new (0, _decimaljs2.default)(pricePerLamport).mul(new (0, _decimaljs2.default)(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
|
|
6529
|
+
};
|
|
6530
|
+
}
|
|
6531
|
+
BinLiquidity3.fromBin = fromBin;
|
|
6532
|
+
function empty(binId, binStep, baseTokenDecimal, quoteTokenDecimal, version) {
|
|
6533
|
+
const pricePerLamport = getPriceOfBinByBinId(
|
|
6534
|
+
binId,
|
|
6535
|
+
binStep
|
|
6536
|
+
).toString();
|
|
6537
|
+
return {
|
|
6538
|
+
binId,
|
|
6539
|
+
xAmount: new (0, _anchor.BN)(0),
|
|
6540
|
+
yAmount: new (0, _anchor.BN)(0),
|
|
6541
|
+
supply: new (0, _anchor.BN)(0),
|
|
6542
|
+
price: pricePerLamport,
|
|
6543
|
+
version,
|
|
6544
|
+
pricePerToken: new (0, _decimaljs2.default)(pricePerLamport).mul(new (0, _decimaljs2.default)(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
|
|
6545
|
+
};
|
|
6546
|
+
}
|
|
6547
|
+
BinLiquidity3.empty = empty;
|
|
6548
|
+
})(BinLiquidity || (BinLiquidity = exports.BinLiquidity = {}));
|
|
6549
|
+
var BitmapType = /* @__PURE__ */ ((BitmapType2) => {
|
|
6550
|
+
BitmapType2[BitmapType2["U1024"] = 0] = "U1024";
|
|
6551
|
+
BitmapType2[BitmapType2["U512"] = 1] = "U512";
|
|
6552
|
+
return BitmapType2;
|
|
6553
|
+
})(BitmapType || {});
|
|
6554
|
+
var ClockLayout = _borsh.struct.call(void 0, [
|
|
6555
|
+
_borsh.u64.call(void 0, "slot"),
|
|
6556
|
+
_borsh.i64.call(void 0, "epochStartTimestamp"),
|
|
6557
|
+
_borsh.u64.call(void 0, "epoch"),
|
|
6558
|
+
_borsh.u64.call(void 0, "leaderScheduleEpoch"),
|
|
6559
|
+
_borsh.i64.call(void 0, "unixTimestamp")
|
|
6560
|
+
]);
|
|
6561
|
+
var PairStatus = /* @__PURE__ */ ((PairStatus2) => {
|
|
6562
|
+
PairStatus2[PairStatus2["Enabled"] = 0] = "Enabled";
|
|
6563
|
+
PairStatus2[PairStatus2["Disabled"] = 1] = "Disabled";
|
|
6564
|
+
return PairStatus2;
|
|
6565
|
+
})(PairStatus || {});
|
|
6566
|
+
|
|
6567
|
+
// src/dlmm/helpers/binArray.ts
|
|
6464
6568
|
function internalBitmapRange() {
|
|
6465
6569
|
const lowerBinArrayIndex = BIN_ARRAY_BITMAP_SIZE.neg();
|
|
6466
6570
|
const upperBinArrayIndex = BIN_ARRAY_BITMAP_SIZE.sub(new (0, _anchor.BN)(1));
|
|
@@ -6708,6 +6812,16 @@ function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId
|
|
|
6708
6812
|
index
|
|
6709
6813
|
}));
|
|
6710
6814
|
}
|
|
6815
|
+
function* enumerateBins(binsById, lowerBinId, upperBinId, binStep, baseTokenDecimal, quoteTokenDecimal, version) {
|
|
6816
|
+
for (let currentBinId = lowerBinId; currentBinId <= upperBinId; currentBinId++) {
|
|
6817
|
+
const bin = binsById.get(currentBinId);
|
|
6818
|
+
if (bin != null) {
|
|
6819
|
+
yield BinLiquidity.fromBin(bin, currentBinId, binStep, baseTokenDecimal, quoteTokenDecimal, version);
|
|
6820
|
+
} else {
|
|
6821
|
+
yield BinLiquidity.empty(currentBinId, binStep, baseTokenDecimal, quoteTokenDecimal, version);
|
|
6822
|
+
}
|
|
6823
|
+
}
|
|
6824
|
+
}
|
|
6711
6825
|
|
|
6712
6826
|
// src/dlmm/helpers/fee.ts
|
|
6713
6827
|
|
|
@@ -7449,7 +7563,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
|
|
|
7449
7563
|
);
|
|
7450
7564
|
const program = new (0, _anchor.Program)(
|
|
7451
7565
|
IDL,
|
|
7452
|
-
LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
7566
|
+
LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _21 => _21.cluster]), () => ( "mainnet-beta"))],
|
|
7453
7567
|
provider
|
|
7454
7568
|
);
|
|
7455
7569
|
const poolAccount = await program.account.lbPair.fetchNullable(
|
|
@@ -7469,6 +7583,10 @@ function chunks(array, size) {
|
|
|
7469
7583
|
(_, index) => array.slice(index * size, (index + 1) * size)
|
|
7470
7584
|
);
|
|
7471
7585
|
}
|
|
7586
|
+
function range(min, max, mapfn) {
|
|
7587
|
+
const length = max - min + 1;
|
|
7588
|
+
return Array.from({ length }, (_, i) => mapfn(min + i));
|
|
7589
|
+
}
|
|
7472
7590
|
async function chunkedFetchMultiplePoolAccount(program, pks, chunkSize = 100) {
|
|
7473
7591
|
const accounts = (await Promise.all(
|
|
7474
7592
|
chunks(pks, chunkSize).map(
|
|
@@ -7523,7 +7641,7 @@ async function getTokenBalance(conn, tokenAccount) {
|
|
|
7523
7641
|
var parseLogs = (eventParser, logs) => {
|
|
7524
7642
|
if (!logs.length)
|
|
7525
7643
|
throw new Error("No logs found");
|
|
7526
|
-
for (const event of _optionalChain([eventParser, 'optionalAccess',
|
|
7644
|
+
for (const event of _optionalChain([eventParser, 'optionalAccess', _22 => _22.parseLogs, 'call', _23 => _23(logs)])) {
|
|
7527
7645
|
return event.data;
|
|
7528
7646
|
}
|
|
7529
7647
|
throw new Error("No events found");
|
|
@@ -7574,64 +7692,37 @@ async function chunkedGetMultipleAccountInfos(connection, pks, chunkSize = 100)
|
|
|
7574
7692
|
)).flat();
|
|
7575
7693
|
return accountInfos;
|
|
7576
7694
|
}
|
|
7577
|
-
var
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
});
|
|
7581
|
-
};
|
|
7582
|
-
|
|
7583
|
-
// src/dlmm/index.ts
|
|
7584
|
-
var _bytes = require('@coral-xyz/anchor/dist/cjs/utils/bytes');
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
// src/dlmm/error.ts
|
|
7595
|
-
|
|
7596
|
-
var DLMMError = class extends Error {
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
constructor(error) {
|
|
7601
|
-
let _errorCode = 0;
|
|
7602
|
-
let _errorName = "Something went wrong";
|
|
7603
|
-
let _errorMessage = "Something went wrong";
|
|
7604
|
-
if (error instanceof Error) {
|
|
7605
|
-
const anchorError = _anchor.AnchorError.parse(
|
|
7606
|
-
JSON.parse(JSON.stringify(error)).logs
|
|
7607
|
-
);
|
|
7608
|
-
if (_optionalChain([anchorError, 'optionalAccess', _21 => _21.program, 'access', _22 => _22.toBase58, 'call', _23 => _23()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
|
|
7609
|
-
_errorCode = anchorError.error.errorCode.number;
|
|
7610
|
-
_errorName = anchorError.error.errorCode.code;
|
|
7611
|
-
_errorMessage = anchorError.error.errorMessage;
|
|
7612
|
-
}
|
|
7613
|
-
} else {
|
|
7614
|
-
const idlError = IDL.errors.find((err) => err.code === error);
|
|
7615
|
-
if (idlError) {
|
|
7616
|
-
_errorCode = idlError.code;
|
|
7617
|
-
_errorName = idlError.name;
|
|
7618
|
-
_errorMessage = idlError.msg;
|
|
7619
|
-
}
|
|
7620
|
-
}
|
|
7621
|
-
super(_errorMessage);
|
|
7622
|
-
this.errorCode = _errorCode;
|
|
7623
|
-
this.errorName = _errorName;
|
|
7624
|
-
this.errorMessage = _errorMessage;
|
|
7695
|
+
var getEstimatedComputeUnitUsageWithBuffer = async (connection, instructions, feePayer, buffer) => {
|
|
7696
|
+
if (!buffer) {
|
|
7697
|
+
buffer = 0.1;
|
|
7625
7698
|
}
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
|
|
7699
|
+
buffer = Math.max(0, buffer);
|
|
7700
|
+
buffer = Math.min(1, buffer);
|
|
7701
|
+
const estimatedComputeUnitUsage = await _helpers.getSimulationComputeUnits.call(void 0,
|
|
7702
|
+
connection,
|
|
7703
|
+
instructions,
|
|
7704
|
+
feePayer,
|
|
7705
|
+
[]
|
|
7706
|
+
);
|
|
7707
|
+
let extraComputeUnitBuffer = estimatedComputeUnitUsage * buffer;
|
|
7708
|
+
if (extraComputeUnitBuffer > MAX_CU_BUFFER) {
|
|
7709
|
+
extraComputeUnitBuffer = MAX_CU_BUFFER;
|
|
7710
|
+
} else if (extraComputeUnitBuffer < MIN_CU_BUFFER) {
|
|
7711
|
+
extraComputeUnitBuffer = MIN_CU_BUFFER;
|
|
7634
7712
|
}
|
|
7713
|
+
return estimatedComputeUnitUsage + extraComputeUnitBuffer;
|
|
7714
|
+
};
|
|
7715
|
+
var getEstimatedComputeUnitIxWithBuffer = async (connection, instructions, feePayer, buffer) => {
|
|
7716
|
+
const units = await getEstimatedComputeUnitUsageWithBuffer(
|
|
7717
|
+
connection,
|
|
7718
|
+
instructions,
|
|
7719
|
+
feePayer,
|
|
7720
|
+
buffer
|
|
7721
|
+
).catch((error) => {
|
|
7722
|
+
console.error("Error::getEstimatedComputeUnitUsageWithBuffer", error);
|
|
7723
|
+
return 14e5;
|
|
7724
|
+
});
|
|
7725
|
+
return _web3js.ComputeBudgetProgram.setComputeUnitLimit({ units });
|
|
7635
7726
|
};
|
|
7636
7727
|
|
|
7637
7728
|
// src/dlmm/index.ts
|
|
@@ -8783,15 +8874,15 @@ var DLMM = class {
|
|
|
8783
8874
|
* @returns an object with two properties: "activeBin" and "bins". The value of "activeBin" is the
|
|
8784
8875
|
* active bin ID of the lbPair, and the value of "bins" is an array of BinLiquidity objects.
|
|
8785
8876
|
*/
|
|
8786
|
-
async getBinsBetweenLowerAndUpperBound(lowerBinId, upperBinId,
|
|
8877
|
+
async getBinsBetweenLowerAndUpperBound(lowerBinId, upperBinId, lowerBinArray, upperBinArray) {
|
|
8787
8878
|
const bins = await this.getBins(
|
|
8788
8879
|
this.pubkey,
|
|
8789
8880
|
lowerBinId,
|
|
8790
8881
|
upperBinId,
|
|
8791
8882
|
this.tokenX.decimal,
|
|
8792
8883
|
this.tokenY.decimal,
|
|
8793
|
-
|
|
8794
|
-
|
|
8884
|
+
lowerBinArray,
|
|
8885
|
+
upperBinArray
|
|
8795
8886
|
);
|
|
8796
8887
|
return { activeBin: this.lbPair.activeId, bins };
|
|
8797
8888
|
}
|
|
@@ -9097,7 +9188,6 @@ var DLMM = class {
|
|
|
9097
9188
|
maxBinId,
|
|
9098
9189
|
user
|
|
9099
9190
|
}) {
|
|
9100
|
-
const setComputeUnitLimitIx = computeBudgetIx();
|
|
9101
9191
|
const createPositionIx = await this.program.methods.initializePosition(minBinId, maxBinId - minBinId + 1).accounts({
|
|
9102
9192
|
payer: user,
|
|
9103
9193
|
position: positionPubKey,
|
|
@@ -9114,12 +9204,18 @@ var DLMM = class {
|
|
|
9114
9204
|
lowerBinArrayIndex,
|
|
9115
9205
|
user
|
|
9116
9206
|
);
|
|
9207
|
+
const instructions = [createPositionIx, ...createBinArrayIxs];
|
|
9208
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
9209
|
+
this.program.provider.connection,
|
|
9210
|
+
instructions,
|
|
9211
|
+
user
|
|
9212
|
+
);
|
|
9117
9213
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9118
9214
|
return new (0, _web3js.Transaction)({
|
|
9119
9215
|
blockhash,
|
|
9120
9216
|
lastValidBlockHeight,
|
|
9121
9217
|
feePayer: user
|
|
9122
|
-
}).add(
|
|
9218
|
+
}).add(setCUIx, ...instructions);
|
|
9123
9219
|
}
|
|
9124
9220
|
/**
|
|
9125
9221
|
* The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
|
|
@@ -9143,8 +9239,7 @@ var DLMM = class {
|
|
|
9143
9239
|
}) {
|
|
9144
9240
|
const { maxBinId, minBinId } = strategy;
|
|
9145
9241
|
const maxActiveBinSlippage = slippage ? Math.ceil(slippage / (this.lbPair.binStep / 100)) : MAX_ACTIVE_BIN_SLIPPAGE;
|
|
9146
|
-
const
|
|
9147
|
-
const preInstructions = [setComputeUnitLimitIx];
|
|
9242
|
+
const preInstructions = [];
|
|
9148
9243
|
const initializePositionIx = await this.program.methods.initializePosition(minBinId, maxBinId - minBinId + 1).accounts({
|
|
9149
9244
|
payer: user,
|
|
9150
9245
|
position: positionPubKey,
|
|
@@ -9244,13 +9339,24 @@ var DLMM = class {
|
|
|
9244
9339
|
tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
|
|
9245
9340
|
};
|
|
9246
9341
|
const programMethod = this.program.methods.addLiquidityByStrategy(liquidityParams);
|
|
9247
|
-
const
|
|
9342
|
+
const addLiquidityIx = await programMethod.accounts(addLiquidityAccounts).instruction();
|
|
9343
|
+
const instructions = [
|
|
9344
|
+
...preInstructions,
|
|
9345
|
+
addLiquidityIx,
|
|
9346
|
+
...postInstructions
|
|
9347
|
+
];
|
|
9348
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
9349
|
+
this.program.provider.connection,
|
|
9350
|
+
instructions,
|
|
9351
|
+
user
|
|
9352
|
+
);
|
|
9353
|
+
instructions.unshift(setCUIx);
|
|
9248
9354
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9249
9355
|
return new (0, _web3js.Transaction)({
|
|
9250
9356
|
blockhash,
|
|
9251
9357
|
lastValidBlockHeight,
|
|
9252
9358
|
feePayer: user
|
|
9253
|
-
}).add(
|
|
9359
|
+
}).add(...instructions);
|
|
9254
9360
|
}
|
|
9255
9361
|
/**
|
|
9256
9362
|
* The function `initializePositionAndAddLiquidityByWeight` function is used to initializes a position and adds liquidity
|
|
@@ -9349,7 +9455,6 @@ var DLMM = class {
|
|
|
9349
9455
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
9350
9456
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
9351
9457
|
}
|
|
9352
|
-
const setComputeUnitLimitIx = computeBudgetIx();
|
|
9353
9458
|
const minBinId = Math.min(...binIds);
|
|
9354
9459
|
const maxBinId = Math.max(...binIds);
|
|
9355
9460
|
const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(minBinId));
|
|
@@ -9414,19 +9519,34 @@ var DLMM = class {
|
|
|
9414
9519
|
const isOneSideDeposit = totalXAmount.isZero() || totalYAmount.isZero();
|
|
9415
9520
|
const programMethod = isOneSideDeposit ? this.program.methods.addLiquidityOneSide(oneSideLiquidityParams) : this.program.methods.addLiquidityByWeight(liquidityParams);
|
|
9416
9521
|
if (xYAmountDistribution.length < MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX) {
|
|
9417
|
-
const
|
|
9522
|
+
const addLiqIx2 = await programMethod.accounts(
|
|
9418
9523
|
isOneSideDeposit ? oneSideAddLiquidityAccounts : addLiquidityAccounts
|
|
9419
|
-
).
|
|
9524
|
+
).instruction();
|
|
9525
|
+
const instructions = [...preInstructions, addLiqIx2, ...postInstructions];
|
|
9526
|
+
const setCUIx2 = await getEstimatedComputeUnitIxWithBuffer(
|
|
9527
|
+
this.program.provider.connection,
|
|
9528
|
+
instructions,
|
|
9529
|
+
user
|
|
9530
|
+
);
|
|
9531
|
+
instructions.unshift(setCUIx2);
|
|
9420
9532
|
const { blockhash: blockhash2, lastValidBlockHeight: lastValidBlockHeight2 } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9421
9533
|
return new (0, _web3js.Transaction)({
|
|
9422
9534
|
blockhash: blockhash2,
|
|
9423
9535
|
lastValidBlockHeight: lastValidBlockHeight2,
|
|
9424
9536
|
feePayer: user
|
|
9425
|
-
}).add(
|
|
9537
|
+
}).add(...instructions);
|
|
9426
9538
|
}
|
|
9427
|
-
const
|
|
9539
|
+
const addLiqIx = await programMethod.accounts(
|
|
9428
9540
|
isOneSideDeposit ? oneSideAddLiquidityAccounts : addLiquidityAccounts
|
|
9429
|
-
).
|
|
9541
|
+
).instruction();
|
|
9542
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
9543
|
+
this.program.provider.connection,
|
|
9544
|
+
[addLiqIx],
|
|
9545
|
+
user,
|
|
9546
|
+
DEFAULT_ADD_LIQUIDITY_CU
|
|
9547
|
+
// The function return multiple transactions that dependent on each other, simulation will fail
|
|
9548
|
+
);
|
|
9549
|
+
const mainInstructions = [setCUIx, addLiqIx];
|
|
9430
9550
|
const transactions = [];
|
|
9431
9551
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9432
9552
|
if (preInstructions.length) {
|
|
@@ -9441,7 +9561,7 @@ var DLMM = class {
|
|
|
9441
9561
|
blockhash,
|
|
9442
9562
|
lastValidBlockHeight,
|
|
9443
9563
|
feePayer: user
|
|
9444
|
-
}).add(
|
|
9564
|
+
}).add(...mainInstructions);
|
|
9445
9565
|
transactions.push(mainTx);
|
|
9446
9566
|
if (postInstructions.length) {
|
|
9447
9567
|
const postInstructionsTx = new (0, _web3js.Transaction)({
|
|
@@ -9476,8 +9596,6 @@ var DLMM = class {
|
|
|
9476
9596
|
const { maxBinId, minBinId } = strategy;
|
|
9477
9597
|
const maxActiveBinSlippage = slippage ? Math.ceil(slippage / (this.lbPair.binStep / 100)) : MAX_ACTIVE_BIN_SLIPPAGE;
|
|
9478
9598
|
const preInstructions = [];
|
|
9479
|
-
const setComputeUnitLimitIx = computeBudgetIx();
|
|
9480
|
-
preInstructions.push(setComputeUnitLimitIx);
|
|
9481
9599
|
const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(minBinId));
|
|
9482
9600
|
const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId));
|
|
9483
9601
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
@@ -9571,13 +9689,24 @@ var DLMM = class {
|
|
|
9571
9689
|
tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
|
|
9572
9690
|
};
|
|
9573
9691
|
const programMethod = this.program.methods.addLiquidityByStrategy(liquidityParams);
|
|
9574
|
-
const
|
|
9692
|
+
const addLiquidityIx = await programMethod.accounts(addLiquidityAccounts).instruction();
|
|
9693
|
+
const instructions = [
|
|
9694
|
+
...preInstructions,
|
|
9695
|
+
addLiquidityIx,
|
|
9696
|
+
...postInstructions
|
|
9697
|
+
];
|
|
9698
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
9699
|
+
this.program.provider.connection,
|
|
9700
|
+
instructions,
|
|
9701
|
+
user
|
|
9702
|
+
);
|
|
9703
|
+
instructions.unshift(setCUIx);
|
|
9575
9704
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9576
9705
|
return new (0, _web3js.Transaction)({
|
|
9577
9706
|
blockhash,
|
|
9578
9707
|
lastValidBlockHeight,
|
|
9579
9708
|
feePayer: user
|
|
9580
|
-
}).add(
|
|
9709
|
+
}).add(...instructions);
|
|
9581
9710
|
}
|
|
9582
9711
|
/**
|
|
9583
9712
|
* The `addLiquidityByWeight` function is used to add liquidity to existing position
|
|
@@ -9697,7 +9826,6 @@ var DLMM = class {
|
|
|
9697
9826
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
9698
9827
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
9699
9828
|
}
|
|
9700
|
-
const setComputeUnitLimitIx = computeBudgetIx();
|
|
9701
9829
|
const liquidityParams = {
|
|
9702
9830
|
amountX: totalXAmount,
|
|
9703
9831
|
amountY: totalYAmount,
|
|
@@ -9742,19 +9870,32 @@ var DLMM = class {
|
|
|
9742
9870
|
const isOneSideDeposit = totalXAmount.isZero() || totalYAmount.isZero();
|
|
9743
9871
|
const programMethod = isOneSideDeposit ? this.program.methods.addLiquidityOneSide(oneSideLiquidityParams) : this.program.methods.addLiquidityByWeight(liquidityParams);
|
|
9744
9872
|
if (xYAmountDistribution.length < MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX) {
|
|
9745
|
-
const
|
|
9873
|
+
const addLiqIx2 = await programMethod.accounts(
|
|
9746
9874
|
isOneSideDeposit ? oneSideAddLiquidityAccounts : addLiquidityAccounts
|
|
9747
|
-
).
|
|
9875
|
+
).instruction();
|
|
9876
|
+
const instructions = [...preInstructions, addLiqIx2, ...postInstructions];
|
|
9877
|
+
const setCUIx2 = await getEstimatedComputeUnitIxWithBuffer(
|
|
9878
|
+
this.program.provider.connection,
|
|
9879
|
+
instructions,
|
|
9880
|
+
user
|
|
9881
|
+
);
|
|
9882
|
+
instructions.unshift(setCUIx2);
|
|
9748
9883
|
const { blockhash: blockhash2, lastValidBlockHeight: lastValidBlockHeight2 } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9749
9884
|
return new (0, _web3js.Transaction)({
|
|
9750
9885
|
blockhash: blockhash2,
|
|
9751
9886
|
lastValidBlockHeight: lastValidBlockHeight2,
|
|
9752
9887
|
feePayer: user
|
|
9753
|
-
}).add(
|
|
9888
|
+
}).add(...instructions);
|
|
9754
9889
|
}
|
|
9755
|
-
const
|
|
9890
|
+
const addLiqIx = await programMethod.accounts(
|
|
9756
9891
|
isOneSideDeposit ? oneSideAddLiquidityAccounts : addLiquidityAccounts
|
|
9757
|
-
).
|
|
9892
|
+
).instruction();
|
|
9893
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
9894
|
+
this.program.provider.connection,
|
|
9895
|
+
[addLiqIx],
|
|
9896
|
+
user
|
|
9897
|
+
);
|
|
9898
|
+
const mainInstructions = [setCUIx, addLiqIx];
|
|
9758
9899
|
const transactions = [];
|
|
9759
9900
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9760
9901
|
if (preInstructions.length) {
|
|
@@ -9769,7 +9910,7 @@ var DLMM = class {
|
|
|
9769
9910
|
blockhash,
|
|
9770
9911
|
lastValidBlockHeight,
|
|
9771
9912
|
feePayer: user
|
|
9772
|
-
}).add(
|
|
9913
|
+
}).add(...mainInstructions);
|
|
9773
9914
|
transactions.push(mainTx);
|
|
9774
9915
|
if (postInstructions.length) {
|
|
9775
9916
|
const postInstructionsTx = new (0, _web3js.Transaction)({
|
|
@@ -9814,8 +9955,6 @@ var DLMM = class {
|
|
|
9814
9955
|
this.program.programId
|
|
9815
9956
|
);
|
|
9816
9957
|
const preInstructions = [];
|
|
9817
|
-
const setComputeUnitLimitIx = computeBudgetIx();
|
|
9818
|
-
preInstructions.push(setComputeUnitLimitIx);
|
|
9819
9958
|
const walletToReceiveFee = feeOwner.equals(_web3js.PublicKey.default) ? user : feeOwner;
|
|
9820
9959
|
const [
|
|
9821
9960
|
{ ataPubKey: userTokenX, ix: createPayerTokenXIx },
|
|
@@ -9923,7 +10062,7 @@ var DLMM = class {
|
|
|
9923
10062
|
const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId));
|
|
9924
10063
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
9925
10064
|
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
9926
|
-
const
|
|
10065
|
+
const removeLiquidityIx = await this.program.methods.removeLiquidityByRange(minBinId, maxBinId, bps.toNumber()).accounts({
|
|
9927
10066
|
position,
|
|
9928
10067
|
lbPair,
|
|
9929
10068
|
userTokenX,
|
|
@@ -9938,26 +10077,43 @@ var DLMM = class {
|
|
|
9938
10077
|
tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
|
|
9939
10078
|
tokenYProgram: _spltoken.TOKEN_PROGRAM_ID,
|
|
9940
10079
|
sender: user
|
|
9941
|
-
}).
|
|
9942
|
-
const
|
|
10080
|
+
}).instruction();
|
|
10081
|
+
const instructions = [
|
|
10082
|
+
...preInstructions,
|
|
10083
|
+
removeLiquidityIx,
|
|
10084
|
+
...postInstructions
|
|
10085
|
+
];
|
|
10086
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
10087
|
+
this.program.provider.connection,
|
|
10088
|
+
instructions,
|
|
10089
|
+
user
|
|
10090
|
+
);
|
|
10091
|
+
instructions.unshift(setCUIx);
|
|
9943
10092
|
if (secondTransactionsIx.length) {
|
|
10093
|
+
const setCUIx2 = await getEstimatedComputeUnitIxWithBuffer(
|
|
10094
|
+
this.program.provider.connection,
|
|
10095
|
+
secondTransactionsIx,
|
|
10096
|
+
user
|
|
10097
|
+
);
|
|
10098
|
+
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9944
10099
|
const claimRewardsTx = new (0, _web3js.Transaction)({
|
|
9945
10100
|
blockhash,
|
|
9946
10101
|
lastValidBlockHeight,
|
|
9947
10102
|
feePayer: user
|
|
9948
|
-
}).add(...secondTransactionsIx);
|
|
10103
|
+
}).add(setCUIx2, ...secondTransactionsIx);
|
|
9949
10104
|
const mainTx = new (0, _web3js.Transaction)({
|
|
9950
10105
|
blockhash,
|
|
9951
10106
|
lastValidBlockHeight,
|
|
9952
10107
|
feePayer: user
|
|
9953
|
-
}).add(
|
|
10108
|
+
}).add(...instructions);
|
|
9954
10109
|
return [mainTx, claimRewardsTx];
|
|
9955
10110
|
} else {
|
|
10111
|
+
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9956
10112
|
return new (0, _web3js.Transaction)({
|
|
9957
10113
|
blockhash,
|
|
9958
10114
|
lastValidBlockHeight,
|
|
9959
10115
|
feePayer: user
|
|
9960
|
-
}).add(
|
|
10116
|
+
}).add(...instructions);
|
|
9961
10117
|
}
|
|
9962
10118
|
}
|
|
9963
10119
|
/**
|
|
@@ -10235,7 +10391,8 @@ var DLMM = class {
|
|
|
10235
10391
|
binArraysPubkey
|
|
10236
10392
|
}) {
|
|
10237
10393
|
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
|
|
10238
|
-
const preInstructions = [
|
|
10394
|
+
const preInstructions = [];
|
|
10395
|
+
const postInstructions = [];
|
|
10239
10396
|
const [
|
|
10240
10397
|
{ ataPubKey: userTokenIn, ix: createInTokenAccountIx },
|
|
10241
10398
|
{ ataPubKey: userTokenOut, ix: createOutTokenAccountIx }
|
|
@@ -10260,8 +10417,9 @@ var DLMM = class {
|
|
|
10260
10417
|
BigInt(maxInAmount.toString())
|
|
10261
10418
|
);
|
|
10262
10419
|
preInstructions.push(...wrapSOLIx);
|
|
10420
|
+
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10421
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10263
10422
|
}
|
|
10264
|
-
const postInstructions = [];
|
|
10265
10423
|
if (outToken.equals(_spltoken.NATIVE_MINT)) {
|
|
10266
10424
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10267
10425
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
@@ -10276,7 +10434,7 @@ var DLMM = class {
|
|
|
10276
10434
|
pubkey
|
|
10277
10435
|
};
|
|
10278
10436
|
});
|
|
10279
|
-
const
|
|
10437
|
+
const swapIx = await this.program.methods.swapExactOut(maxInAmount, outAmount).accounts({
|
|
10280
10438
|
lbPair,
|
|
10281
10439
|
reserveX,
|
|
10282
10440
|
reserveY,
|
|
@@ -10290,13 +10448,20 @@ var DLMM = class {
|
|
|
10290
10448
|
binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
|
|
10291
10449
|
oracle,
|
|
10292
10450
|
hostFeeIn: null
|
|
10293
|
-
}).remainingAccounts(binArrays).
|
|
10451
|
+
}).remainingAccounts(binArrays).instruction();
|
|
10452
|
+
const instructions = [...preInstructions, swapIx, ...postInstructions];
|
|
10453
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
10454
|
+
this.program.provider.connection,
|
|
10455
|
+
instructions,
|
|
10456
|
+
user
|
|
10457
|
+
);
|
|
10458
|
+
instructions.unshift(setCUIx);
|
|
10294
10459
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10295
10460
|
return new (0, _web3js.Transaction)({
|
|
10296
10461
|
blockhash,
|
|
10297
10462
|
lastValidBlockHeight,
|
|
10298
10463
|
feePayer: user
|
|
10299
|
-
}).add(
|
|
10464
|
+
}).add(...instructions);
|
|
10300
10465
|
}
|
|
10301
10466
|
/**
|
|
10302
10467
|
* Returns a transaction to be signed and sent by user performing swap.
|
|
@@ -10320,7 +10485,8 @@ var DLMM = class {
|
|
|
10320
10485
|
binArraysPubkey
|
|
10321
10486
|
}) {
|
|
10322
10487
|
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
|
|
10323
|
-
const preInstructions = [
|
|
10488
|
+
const preInstructions = [];
|
|
10489
|
+
const postInstructions = [];
|
|
10324
10490
|
const [
|
|
10325
10491
|
{ ataPubKey: userTokenIn, ix: createInTokenAccountIx },
|
|
10326
10492
|
{ ataPubKey: userTokenOut, ix: createOutTokenAccountIx }
|
|
@@ -10345,8 +10511,9 @@ var DLMM = class {
|
|
|
10345
10511
|
BigInt(inAmount.toString())
|
|
10346
10512
|
);
|
|
10347
10513
|
preInstructions.push(...wrapSOLIx);
|
|
10514
|
+
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10515
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10348
10516
|
}
|
|
10349
|
-
const postInstructions = [];
|
|
10350
10517
|
if (outToken.equals(_spltoken.NATIVE_MINT)) {
|
|
10351
10518
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10352
10519
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
@@ -10361,7 +10528,7 @@ var DLMM = class {
|
|
|
10361
10528
|
pubkey
|
|
10362
10529
|
};
|
|
10363
10530
|
});
|
|
10364
|
-
const
|
|
10531
|
+
const swapIx = await this.program.methods.swapWithPriceImpact(
|
|
10365
10532
|
inAmount,
|
|
10366
10533
|
this.lbPair.activeId,
|
|
10367
10534
|
priceImpact.toNumber()
|
|
@@ -10379,13 +10546,20 @@ var DLMM = class {
|
|
|
10379
10546
|
binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
|
|
10380
10547
|
oracle,
|
|
10381
10548
|
hostFeeIn: null
|
|
10382
|
-
}).remainingAccounts(binArrays).
|
|
10549
|
+
}).remainingAccounts(binArrays).instruction();
|
|
10550
|
+
const instructions = [...preInstructions, swapIx, ...postInstructions];
|
|
10551
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
10552
|
+
this.program.provider.connection,
|
|
10553
|
+
instructions,
|
|
10554
|
+
user
|
|
10555
|
+
);
|
|
10556
|
+
instructions.unshift(setCUIx);
|
|
10383
10557
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10384
10558
|
return new (0, _web3js.Transaction)({
|
|
10385
10559
|
blockhash,
|
|
10386
10560
|
lastValidBlockHeight,
|
|
10387
10561
|
feePayer: user
|
|
10388
|
-
}).add(
|
|
10562
|
+
}).add(...instructions);
|
|
10389
10563
|
}
|
|
10390
10564
|
/**
|
|
10391
10565
|
* Returns a transaction to be signed and sent by user performing swap.
|
|
@@ -10409,7 +10583,8 @@ var DLMM = class {
|
|
|
10409
10583
|
binArraysPubkey
|
|
10410
10584
|
}) {
|
|
10411
10585
|
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
|
|
10412
|
-
const preInstructions = [
|
|
10586
|
+
const preInstructions = [];
|
|
10587
|
+
const postInstructions = [];
|
|
10413
10588
|
const [
|
|
10414
10589
|
{ ataPubKey: userTokenIn, ix: createInTokenAccountIx },
|
|
10415
10590
|
{ ataPubKey: userTokenOut, ix: createOutTokenAccountIx }
|
|
@@ -10434,8 +10609,9 @@ var DLMM = class {
|
|
|
10434
10609
|
BigInt(inAmount.toString())
|
|
10435
10610
|
);
|
|
10436
10611
|
preInstructions.push(...wrapSOLIx);
|
|
10612
|
+
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10613
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10437
10614
|
}
|
|
10438
|
-
const postInstructions = [];
|
|
10439
10615
|
if (outToken.equals(_spltoken.NATIVE_MINT)) {
|
|
10440
10616
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10441
10617
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
@@ -10450,7 +10626,7 @@ var DLMM = class {
|
|
|
10450
10626
|
pubkey
|
|
10451
10627
|
};
|
|
10452
10628
|
});
|
|
10453
|
-
const
|
|
10629
|
+
const swapIx = await this.program.methods.swap(inAmount, minOutAmount).accounts({
|
|
10454
10630
|
lbPair,
|
|
10455
10631
|
reserveX,
|
|
10456
10632
|
reserveY,
|
|
@@ -10466,13 +10642,20 @@ var DLMM = class {
|
|
|
10466
10642
|
binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
|
|
10467
10643
|
oracle,
|
|
10468
10644
|
hostFeeIn: null
|
|
10469
|
-
}).remainingAccounts(binArrays).
|
|
10645
|
+
}).remainingAccounts(binArrays).instruction();
|
|
10646
|
+
const instructions = [...preInstructions, swapIx, ...postInstructions];
|
|
10647
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
10648
|
+
this.program.provider.connection,
|
|
10649
|
+
instructions,
|
|
10650
|
+
user
|
|
10651
|
+
);
|
|
10652
|
+
instructions.unshift(setCUIx);
|
|
10470
10653
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10471
10654
|
return new (0, _web3js.Transaction)({
|
|
10472
10655
|
blockhash,
|
|
10473
10656
|
lastValidBlockHeight,
|
|
10474
10657
|
feePayer: user
|
|
10475
|
-
}).add(
|
|
10658
|
+
}).add(...instructions);
|
|
10476
10659
|
}
|
|
10477
10660
|
/**
|
|
10478
10661
|
* The claimLMReward function is used to claim rewards for a specific position owned by a specific owner.
|
|
@@ -10491,12 +10674,18 @@ var DLMM = class {
|
|
|
10491
10674
|
});
|
|
10492
10675
|
if (!claimTransactions.length)
|
|
10493
10676
|
return;
|
|
10677
|
+
const instructions = claimTransactions.map((t) => t.instructions).flat();
|
|
10678
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
10679
|
+
this.program.provider.connection,
|
|
10680
|
+
instructions,
|
|
10681
|
+
owner
|
|
10682
|
+
);
|
|
10494
10683
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10495
10684
|
return new (0, _web3js.Transaction)({
|
|
10496
10685
|
blockhash,
|
|
10497
10686
|
lastValidBlockHeight,
|
|
10498
10687
|
feePayer: owner
|
|
10499
|
-
}).add(...claimTransactions);
|
|
10688
|
+
}).add(setCUIx, ...claimTransactions);
|
|
10500
10689
|
}
|
|
10501
10690
|
/**
|
|
10502
10691
|
* The `claimAllLMRewards` function is used to claim all liquidity mining rewards for a given owner
|
|
@@ -10522,6 +10711,14 @@ var DLMM = class {
|
|
|
10522
10711
|
})
|
|
10523
10712
|
)).flat();
|
|
10524
10713
|
const chunkedClaimAllTx = chunks(claimAllTxs, MAX_CLAIM_ALL_ALLOWED);
|
|
10714
|
+
if (chunkedClaimAllTx.length === 0)
|
|
10715
|
+
return [];
|
|
10716
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
10717
|
+
this.program.provider.connection,
|
|
10718
|
+
// First tx simulation will success because it will create all the ATA. Then, we use the simulated CU as references for the rest
|
|
10719
|
+
chunkedClaimAllTx[0].map((t) => t.instructions).flat(),
|
|
10720
|
+
owner
|
|
10721
|
+
);
|
|
10525
10722
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10526
10723
|
return Promise.all(
|
|
10527
10724
|
chunkedClaimAllTx.map(async (claimAllTx) => {
|
|
@@ -10529,7 +10726,7 @@ var DLMM = class {
|
|
|
10529
10726
|
feePayer: owner,
|
|
10530
10727
|
blockhash,
|
|
10531
10728
|
lastValidBlockHeight
|
|
10532
|
-
}).add(
|
|
10729
|
+
}).add(setCUIx).add(...claimAllTx);
|
|
10533
10730
|
})
|
|
10534
10731
|
);
|
|
10535
10732
|
}
|
|
@@ -10588,14 +10785,22 @@ var DLMM = class {
|
|
|
10588
10785
|
})
|
|
10589
10786
|
)).flat();
|
|
10590
10787
|
const chunkedClaimAllTx = chunks(claimAllTxs, MAX_CLAIM_ALL_ALLOWED);
|
|
10788
|
+
if (chunkedClaimAllTx.length === 0)
|
|
10789
|
+
return [];
|
|
10790
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
10791
|
+
this.program.provider.connection,
|
|
10792
|
+
// First tx simulation will success because it will create all the ATA. Then, we use the simulated CU as references for the rest
|
|
10793
|
+
chunkedClaimAllTx[0].map((t) => t.instructions).flat(),
|
|
10794
|
+
owner
|
|
10795
|
+
);
|
|
10796
|
+
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10591
10797
|
return Promise.all(
|
|
10592
10798
|
chunkedClaimAllTx.map(async (claimAllTx) => {
|
|
10593
|
-
const { recentBlockhash, lastValidBlockHeight } = claimAllTx[0];
|
|
10594
10799
|
return new (0, _web3js.Transaction)({
|
|
10595
10800
|
feePayer: owner,
|
|
10596
|
-
blockhash
|
|
10801
|
+
blockhash,
|
|
10597
10802
|
lastValidBlockHeight
|
|
10598
|
-
}).add(
|
|
10803
|
+
}).add(setCUIx).add(...claimAllTx);
|
|
10599
10804
|
})
|
|
10600
10805
|
);
|
|
10601
10806
|
}
|
|
@@ -10662,11 +10867,22 @@ var DLMM = class {
|
|
|
10662
10867
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10663
10868
|
return Promise.all(
|
|
10664
10869
|
claimAllTxs.map(async (claimAllTx) => {
|
|
10870
|
+
const mainInstructions = claimAllTx.map((t) => t.instructions).flat();
|
|
10871
|
+
const instructions = [
|
|
10872
|
+
...preInstructions,
|
|
10873
|
+
...mainInstructions,
|
|
10874
|
+
...postInstructions
|
|
10875
|
+
];
|
|
10876
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
10877
|
+
this.program.provider.connection,
|
|
10878
|
+
instructions,
|
|
10879
|
+
owner
|
|
10880
|
+
);
|
|
10665
10881
|
const tx = new (0, _web3js.Transaction)({
|
|
10666
10882
|
feePayer: owner,
|
|
10667
10883
|
blockhash,
|
|
10668
10884
|
lastValidBlockHeight
|
|
10669
|
-
}).add(
|
|
10885
|
+
}).add(setCUIx);
|
|
10670
10886
|
if (preInstructions.length)
|
|
10671
10887
|
tx.add(...preInstructions);
|
|
10672
10888
|
tx.add(...claimAllTx);
|
|
@@ -10765,7 +10981,7 @@ var DLMM = class {
|
|
|
10765
10981
|
upperBinArray,
|
|
10766
10982
|
positionPda
|
|
10767
10983
|
]);
|
|
10768
|
-
let instructions = [
|
|
10984
|
+
let instructions = [];
|
|
10769
10985
|
const lowerBinArrayAccount = accounts[0];
|
|
10770
10986
|
if (!lowerBinArrayAccount && !appendedInitBinArrayIx.has(lowerBinArray.toBase58())) {
|
|
10771
10987
|
instructions.push(
|
|
@@ -10804,8 +11020,15 @@ var DLMM = class {
|
|
|
10804
11020
|
);
|
|
10805
11021
|
}
|
|
10806
11022
|
if (instructions.length > 1) {
|
|
11023
|
+
instructions.push(
|
|
11024
|
+
await getEstimatedComputeUnitIxWithBuffer(
|
|
11025
|
+
this.program.provider.connection,
|
|
11026
|
+
instructions,
|
|
11027
|
+
owner
|
|
11028
|
+
)
|
|
11029
|
+
);
|
|
10807
11030
|
initializeBinArraysAndPositionIxs.push(instructions);
|
|
10808
|
-
instructions = [
|
|
11031
|
+
instructions = [];
|
|
10809
11032
|
}
|
|
10810
11033
|
const positionDeposited = positionAccount && this.program.coder.accounts.decode("positionV2", positionAccount.data).liquidityShares.reduce((total, cur) => total.add(cur), new (0, _anchor.BN)(0)).gt(new (0, _anchor.BN)(0));
|
|
10811
11034
|
if (!positionDeposited) {
|
|
@@ -10861,7 +11084,12 @@ var DLMM = class {
|
|
|
10861
11084
|
}).instruction()
|
|
10862
11085
|
);
|
|
10863
11086
|
}
|
|
10864
|
-
addLiquidityIxs.push(
|
|
11087
|
+
addLiquidityIxs.push([
|
|
11088
|
+
_web3js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
11089
|
+
units: DEFAULT_ADD_LIQUIDITY_CU
|
|
11090
|
+
}),
|
|
11091
|
+
...instructions
|
|
11092
|
+
]);
|
|
10865
11093
|
}
|
|
10866
11094
|
}
|
|
10867
11095
|
return {
|
|
@@ -10872,37 +11100,37 @@ var DLMM = class {
|
|
|
10872
11100
|
/**
|
|
10873
11101
|
* The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be either [initialize bin array + initialize position instructions] or [deposit instruction] combination.
|
|
10874
11102
|
* @param
|
|
10875
|
-
* - `
|
|
11103
|
+
* - `payer`: The public key of the tx payer.
|
|
10876
11104
|
* - `base`: Base key
|
|
10877
11105
|
* - `seedAmount`: Token X lamport amount to be seeded to the pool.
|
|
10878
11106
|
* - `price`: TokenX/TokenY Price in UI format
|
|
10879
11107
|
* - `roundingUp`: Whether to round up the price
|
|
11108
|
+
* - `positionOwner`: The owner of the position
|
|
10880
11109
|
* - `feeOwner`: Position fee owner
|
|
10881
11110
|
* - `operator`: Operator of the position. Operator able to manage the position on behalf of the position owner. However, liquidity withdrawal issue by the operator can only send to the position owner.
|
|
10882
11111
|
* - `lockReleasePoint`: The lock release point of the position.
|
|
11112
|
+
* - `shouldSeedPositionOwner` (optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
|
|
10883
11113
|
*
|
|
10884
11114
|
* The returned instructions need to be executed sequentially if it was separated into multiple transactions.
|
|
10885
11115
|
* @returns {Promise<TransactionInstruction[]>}
|
|
10886
11116
|
*/
|
|
10887
|
-
async seedLiquiditySingleBin(
|
|
10888
|
-
const pricePerLamport = DLMM.getPricePerLamport(
|
|
10889
|
-
|
|
11117
|
+
async seedLiquiditySingleBin(payer, base, seedAmount, price, roundingUp, positionOwner, feeOwner, operator, lockReleasePoint, shouldSeedPositionOwner = false) {
|
|
11118
|
+
const pricePerLamport = DLMM.getPricePerLamport(
|
|
11119
|
+
this.tokenX.decimal,
|
|
11120
|
+
this.tokenY.decimal,
|
|
11121
|
+
price
|
|
11122
|
+
);
|
|
11123
|
+
const binIdNumber = DLMM.getBinIdFromPrice(
|
|
11124
|
+
pricePerLamport,
|
|
11125
|
+
this.lbPair.binStep,
|
|
11126
|
+
!roundingUp
|
|
11127
|
+
);
|
|
10890
11128
|
const binId = new (0, _anchor.BN)(binIdNumber);
|
|
10891
11129
|
const lowerBinArrayIndex = binIdToBinArrayIndex(binId);
|
|
10892
11130
|
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
10893
11131
|
const [lowerBinArray] = deriveBinArray(this.pubkey, lowerBinArrayIndex, this.program.programId);
|
|
10894
11132
|
const [upperBinArray] = deriveBinArray(this.pubkey, upperBinArrayIndex, this.program.programId);
|
|
10895
11133
|
const [positionPda] = derivePosition(this.pubkey, base, binId, new (0, _anchor.BN)(1), this.program.programId);
|
|
10896
|
-
const operatorTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
10897
|
-
this.lbPair.tokenXMint,
|
|
10898
|
-
operator,
|
|
10899
|
-
true
|
|
10900
|
-
);
|
|
10901
|
-
const ownerTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
10902
|
-
this.lbPair.tokenXMint,
|
|
10903
|
-
owner,
|
|
10904
|
-
true
|
|
10905
|
-
);
|
|
10906
11134
|
const preInstructions = [];
|
|
10907
11135
|
const [
|
|
10908
11136
|
{ ataPubKey: userTokenX, ix: createPayerTokenXIx },
|
|
@@ -10911,17 +11139,22 @@ var DLMM = class {
|
|
|
10911
11139
|
getOrCreateATAInstruction(
|
|
10912
11140
|
this.program.provider.connection,
|
|
10913
11141
|
this.tokenX.publicKey,
|
|
10914
|
-
|
|
11142
|
+
operator,
|
|
11143
|
+
payer
|
|
10915
11144
|
),
|
|
10916
11145
|
getOrCreateATAInstruction(
|
|
10917
11146
|
this.program.provider.connection,
|
|
10918
11147
|
this.tokenY.publicKey,
|
|
10919
|
-
|
|
11148
|
+
operator,
|
|
11149
|
+
payer
|
|
10920
11150
|
)
|
|
10921
11151
|
]);
|
|
10922
11152
|
createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
|
|
10923
11153
|
createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
|
|
10924
|
-
let [binArrayBitmapExtension] = deriveBinArrayBitmapExtension(
|
|
11154
|
+
let [binArrayBitmapExtension] = deriveBinArrayBitmapExtension(
|
|
11155
|
+
this.pubkey,
|
|
11156
|
+
this.program.programId
|
|
11157
|
+
);
|
|
10925
11158
|
const accounts = await this.program.provider.connection.getMultipleAccountsInfo([
|
|
10926
11159
|
lowerBinArray,
|
|
10927
11160
|
upperBinArray,
|
|
@@ -10933,13 +11166,38 @@ var DLMM = class {
|
|
|
10933
11166
|
if (!bitmapExtensionAccount) {
|
|
10934
11167
|
preInstructions.push(await this.program.methods.initializeBinArrayBitmapExtension().accounts({
|
|
10935
11168
|
binArrayBitmapExtension,
|
|
10936
|
-
funder:
|
|
11169
|
+
funder: payer,
|
|
10937
11170
|
lbPair: this.pubkey
|
|
10938
11171
|
}).instruction());
|
|
10939
11172
|
}
|
|
10940
11173
|
} else {
|
|
10941
11174
|
binArrayBitmapExtension = this.program.programId;
|
|
10942
11175
|
}
|
|
11176
|
+
const operatorTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
11177
|
+
this.lbPair.tokenXMint,
|
|
11178
|
+
operator,
|
|
11179
|
+
true
|
|
11180
|
+
);
|
|
11181
|
+
const positionOwnerTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0,
|
|
11182
|
+
this.lbPair.tokenXMint,
|
|
11183
|
+
positionOwner,
|
|
11184
|
+
true
|
|
11185
|
+
);
|
|
11186
|
+
if (shouldSeedPositionOwner) {
|
|
11187
|
+
const positionOwnerTokenXAccount = await this.program.provider.connection.getAccountInfo(positionOwnerTokenX);
|
|
11188
|
+
if (positionOwnerTokenXAccount) {
|
|
11189
|
+
const account = _spltoken.AccountLayout.decode(positionOwnerTokenXAccount.data);
|
|
11190
|
+
if (account.amount == BigInt(0)) {
|
|
11191
|
+
const transferIx = _spltoken.createTransferInstruction.call(void 0, operatorTokenX, positionOwnerTokenX, payer, 1);
|
|
11192
|
+
preInstructions.push(transferIx);
|
|
11193
|
+
}
|
|
11194
|
+
} else {
|
|
11195
|
+
const createPositionOwnerTokenXIx = _spltoken.createAssociatedTokenAccountInstruction.call(void 0, payer, positionOwnerTokenX, positionOwner, this.lbPair.tokenXMint);
|
|
11196
|
+
preInstructions.push(createPositionOwnerTokenXIx);
|
|
11197
|
+
const transferIx = _spltoken.createTransferInstruction.call(void 0, operatorTokenX, positionOwnerTokenX, payer, 1);
|
|
11198
|
+
preInstructions.push(transferIx);
|
|
11199
|
+
}
|
|
11200
|
+
}
|
|
10943
11201
|
const lowerBinArrayAccount = accounts[0];
|
|
10944
11202
|
const upperBinArrayAccount = accounts[1];
|
|
10945
11203
|
const positionAccount = accounts[2];
|
|
@@ -10947,7 +11205,7 @@ var DLMM = class {
|
|
|
10947
11205
|
preInstructions.push(
|
|
10948
11206
|
await this.program.methods.initializeBinArray(lowerBinArrayIndex).accounts({
|
|
10949
11207
|
binArray: lowerBinArray,
|
|
10950
|
-
funder:
|
|
11208
|
+
funder: payer,
|
|
10951
11209
|
lbPair: this.pubkey
|
|
10952
11210
|
}).instruction()
|
|
10953
11211
|
);
|
|
@@ -10956,22 +11214,27 @@ var DLMM = class {
|
|
|
10956
11214
|
preInstructions.push(
|
|
10957
11215
|
await this.program.methods.initializeBinArray(upperBinArrayIndex).accounts({
|
|
10958
11216
|
binArray: upperBinArray,
|
|
10959
|
-
funder:
|
|
11217
|
+
funder: payer,
|
|
10960
11218
|
lbPair: this.pubkey
|
|
10961
11219
|
}).instruction()
|
|
10962
11220
|
);
|
|
10963
11221
|
}
|
|
10964
11222
|
if (!positionAccount) {
|
|
10965
11223
|
preInstructions.push(
|
|
10966
|
-
await this.program.methods.initializePositionByOperator(
|
|
10967
|
-
|
|
11224
|
+
await this.program.methods.initializePositionByOperator(
|
|
11225
|
+
binId.toNumber(),
|
|
11226
|
+
1,
|
|
11227
|
+
feeOwner,
|
|
11228
|
+
lockReleasePoint
|
|
11229
|
+
).accounts({
|
|
11230
|
+
payer,
|
|
10968
11231
|
base,
|
|
10969
11232
|
position: positionPda,
|
|
10970
11233
|
lbPair: this.pubkey,
|
|
10971
|
-
owner,
|
|
11234
|
+
owner: positionOwner,
|
|
10972
11235
|
operator,
|
|
10973
11236
|
operatorTokenX,
|
|
10974
|
-
ownerTokenX
|
|
11237
|
+
ownerTokenX: positionOwnerTokenX
|
|
10975
11238
|
}).instruction()
|
|
10976
11239
|
);
|
|
10977
11240
|
}
|
|
@@ -10997,7 +11260,7 @@ var DLMM = class {
|
|
|
10997
11260
|
tokenYMint: this.lbPair.tokenYMint,
|
|
10998
11261
|
binArrayLower: lowerBinArray,
|
|
10999
11262
|
binArrayUpper: upperBinArray,
|
|
11000
|
-
sender:
|
|
11263
|
+
sender: operator,
|
|
11001
11264
|
tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
|
|
11002
11265
|
tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
|
|
11003
11266
|
}).instruction();
|
|
@@ -11071,7 +11334,7 @@ var DLMM = class {
|
|
|
11071
11334
|
owner,
|
|
11072
11335
|
true
|
|
11073
11336
|
);
|
|
11074
|
-
|
|
11337
|
+
const initializePositionByOperatorTx = await this.program.methods.initializePositionByOperator(
|
|
11075
11338
|
lowerBinId.toNumber(),
|
|
11076
11339
|
MAX_BIN_PER_POSITION.toNumber(),
|
|
11077
11340
|
feeOwner,
|
|
@@ -11179,11 +11442,22 @@ var DLMM = class {
|
|
|
11179
11442
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
11180
11443
|
return Promise.all(
|
|
11181
11444
|
chunkedClaimAllTx.map(async (claimAllTx) => {
|
|
11445
|
+
const mainIxs = claimAllTx.map((t) => t.instructions).flat();
|
|
11446
|
+
const instructions = [
|
|
11447
|
+
...preInstructions,
|
|
11448
|
+
...mainIxs,
|
|
11449
|
+
...postInstructions
|
|
11450
|
+
];
|
|
11451
|
+
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
11452
|
+
this.program.provider.connection,
|
|
11453
|
+
instructions,
|
|
11454
|
+
owner
|
|
11455
|
+
);
|
|
11182
11456
|
const tx = new (0, _web3js.Transaction)({
|
|
11183
11457
|
feePayer: owner,
|
|
11184
11458
|
blockhash,
|
|
11185
11459
|
lastValidBlockHeight
|
|
11186
|
-
}).add(
|
|
11460
|
+
}).add(setCUIx);
|
|
11187
11461
|
if (preInstructions.length)
|
|
11188
11462
|
tx.add(...preInstructions);
|
|
11189
11463
|
tx.add(...claimAllTx);
|
|
@@ -11744,106 +12018,39 @@ var DLMM = class {
|
|
|
11744
12018
|
binIds
|
|
11745
12019
|
};
|
|
11746
12020
|
}
|
|
11747
|
-
async getBins(lbPairPubKey, lowerBinId, upperBinId, baseTokenDecimal, quoteTokenDecimal,
|
|
12021
|
+
async getBins(lbPairPubKey, lowerBinId, upperBinId, baseTokenDecimal, quoteTokenDecimal, lowerBinArray, upperBinArray) {
|
|
11748
12022
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
11749
12023
|
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
11750
|
-
|
|
11751
|
-
|
|
11752
|
-
|
|
11753
|
-
|
|
11754
|
-
|
|
11755
|
-
|
|
11756
|
-
)
|
|
11757
|
-
|
|
11758
|
-
|
|
11759
|
-
|
|
11760
|
-
|
|
11761
|
-
|
|
11762
|
-
|
|
11763
|
-
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
binArray.index
|
|
11781
|
-
);
|
|
11782
|
-
binArray.bins.forEach((bin, idx) => {
|
|
11783
|
-
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11784
|
-
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11785
|
-
const pricePerLamport = getPriceOfBinByBinId(
|
|
11786
|
-
binId,
|
|
11787
|
-
this.lbPair.binStep
|
|
11788
|
-
).toString();
|
|
11789
|
-
bins.push({
|
|
11790
|
-
binId,
|
|
11791
|
-
xAmount: bin.amountX,
|
|
11792
|
-
yAmount: bin.amountY,
|
|
11793
|
-
supply: bin.liquiditySupply,
|
|
11794
|
-
price: pricePerLamport,
|
|
11795
|
-
version: binArray.version,
|
|
11796
|
-
pricePerToken: new (0, _decimaljs2.default)(pricePerLamport).mul(new (0, _decimaljs2.default)(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
|
|
11797
|
-
});
|
|
11798
|
-
}
|
|
11799
|
-
});
|
|
11800
|
-
} else {
|
|
11801
|
-
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
11802
|
-
lbPairPubKey,
|
|
11803
|
-
lowerBinArrayIndex,
|
|
11804
|
-
this.program.programId
|
|
11805
|
-
);
|
|
11806
|
-
const [upperBinArrayPubKey] = deriveBinArray(
|
|
11807
|
-
lbPairPubKey,
|
|
11808
|
-
upperBinArrayIndex,
|
|
11809
|
-
this.program.programId
|
|
11810
|
-
);
|
|
11811
|
-
const binArrays = await (async () => {
|
|
11812
|
-
if (!lowerBinArrays || !upperBinArrays) {
|
|
11813
|
-
return (await this.program.account.binArray.fetchMultiple([
|
|
11814
|
-
lowerBinArrayPubKey,
|
|
11815
|
-
upperBinArrayPubKey
|
|
11816
|
-
])).filter((binArray) => binArray !== null);
|
|
11817
|
-
}
|
|
11818
|
-
return [lowerBinArrays, upperBinArrays];
|
|
11819
|
-
})();
|
|
11820
|
-
binArrays.forEach((binArray) => {
|
|
11821
|
-
if (!binArray)
|
|
11822
|
-
return;
|
|
11823
|
-
const [lowerBinIdForBinArray] = getBinArrayLowerUpperBinId(
|
|
11824
|
-
binArray.index
|
|
11825
|
-
);
|
|
11826
|
-
binArray.bins.forEach((bin, idx) => {
|
|
11827
|
-
const binId = lowerBinIdForBinArray.toNumber() + idx;
|
|
11828
|
-
if (binId >= lowerBinId && binId <= upperBinId) {
|
|
11829
|
-
const pricePerLamport = getPriceOfBinByBinId(
|
|
11830
|
-
binId,
|
|
11831
|
-
this.lbPair.binStep
|
|
11832
|
-
).toString();
|
|
11833
|
-
bins.push({
|
|
11834
|
-
binId,
|
|
11835
|
-
xAmount: bin.amountX,
|
|
11836
|
-
yAmount: bin.amountY,
|
|
11837
|
-
supply: bin.liquiditySupply,
|
|
11838
|
-
price: pricePerLamport,
|
|
11839
|
-
version: binArray.version,
|
|
11840
|
-
pricePerToken: new (0, _decimaljs2.default)(pricePerLamport).mul(new (0, _decimaljs2.default)(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
|
|
11841
|
-
});
|
|
11842
|
-
}
|
|
11843
|
-
});
|
|
11844
|
-
});
|
|
11845
|
-
}
|
|
11846
|
-
return bins;
|
|
12024
|
+
const hasCachedLowerBinArray = lowerBinArray != null;
|
|
12025
|
+
const hasCachedUpperBinArray = upperBinArray != null;
|
|
12026
|
+
const isSingleBinArray = lowerBinArrayIndex.eq(upperBinArrayIndex);
|
|
12027
|
+
const lowerBinArrayIndexOffset = hasCachedLowerBinArray ? 1 : 0;
|
|
12028
|
+
const upperBinArrayIndexOffset = hasCachedUpperBinArray ? -1 : 0;
|
|
12029
|
+
const binArrayPubkeys = range(
|
|
12030
|
+
lowerBinArrayIndex.toNumber() + lowerBinArrayIndexOffset,
|
|
12031
|
+
upperBinArrayIndex.toNumber() + upperBinArrayIndexOffset,
|
|
12032
|
+
(i) => deriveBinArray(lbPairPubKey, new (0, _anchor.BN)(i), this.program.programId)[0]
|
|
12033
|
+
);
|
|
12034
|
+
const fetchedBinArrays = binArrayPubkeys.length !== 0 ? await this.program.account.binArray.fetchMultiple(binArrayPubkeys) : [];
|
|
12035
|
+
const binArrays = [
|
|
12036
|
+
...hasCachedLowerBinArray ? [lowerBinArray] : [],
|
|
12037
|
+
...fetchedBinArrays,
|
|
12038
|
+
...hasCachedUpperBinArray && !isSingleBinArray ? [upperBinArray] : []
|
|
12039
|
+
];
|
|
12040
|
+
const binsById = new Map(binArrays.filter((x) => x != null).flatMap(({ bins, index }) => {
|
|
12041
|
+
const [lowerBinId2] = getBinArrayLowerUpperBinId(index);
|
|
12042
|
+
return bins.map((b, i) => [lowerBinId2.toNumber() + i, b]);
|
|
12043
|
+
}));
|
|
12044
|
+
const version = binArrays.length !== 0 ? binArrays[0].version : 1;
|
|
12045
|
+
return Array.from(enumerateBins(
|
|
12046
|
+
binsById,
|
|
12047
|
+
lowerBinId,
|
|
12048
|
+
upperBinId,
|
|
12049
|
+
this.lbPair.binStep,
|
|
12050
|
+
baseTokenDecimal,
|
|
12051
|
+
quoteTokenDecimal,
|
|
12052
|
+
version
|
|
12053
|
+
));
|
|
11847
12054
|
}
|
|
11848
12055
|
async binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex) {
|
|
11849
12056
|
const binArrayIndexes = Array.from(
|
|
@@ -12124,5 +12331,9 @@ var src_default = DLMM;
|
|
|
12124
12331
|
|
|
12125
12332
|
|
|
12126
12333
|
|
|
12127
|
-
|
|
12334
|
+
|
|
12335
|
+
|
|
12336
|
+
|
|
12337
|
+
|
|
12338
|
+
exports.ADMIN = ADMIN; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BinLiquidity = BinLiquidity; exports.BitmapType = BitmapType; exports.ClockLayout = ClockLayout; exports.DLMMError = DLMMError; exports.DlmmSdkError = DlmmSdkError; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.IDL = IDL; exports.ILM_BASE = ILM_BASE; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_POSITION = MAX_BIN_PER_POSITION; exports.MAX_BIN_PER_TX = MAX_BIN_PER_TX; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.Network = Network; exports.POSITION_FEE = POSITION_FEE; exports.PRECISION = PRECISION; exports.PairStatus = PairStatus; exports.PairType = PairType; exports.PositionVersion = PositionVersion; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculateSpotDistribution = calculateSpotDistribution; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunks = chunks; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveCustomizablePermissionlessLbPair = deriveCustomizablePermissionlessLbPair; exports.deriveLbPair = deriveLbPair; exports.deriveLbPair2 = deriveLbPair2; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.derivePresetParameter2 = derivePresetParameter2; exports.deriveReserve = deriveReserve; exports.enumerateBins = enumerateBins; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.getBaseFee = getBaseFee; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinArraysRequiredByPositionRange = getBinArraysRequiredByPositionRange; exports.getBinFromBinArray = getBinFromBinArray; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getOutAmount = getOutAmount; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTokensMintFromPoolAddress = getTokensMintFromPoolAddress; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.parseLogs = parseLogs; exports.range = range; exports.swapExactInQuoteAtBin = swapExactInQuoteAtBin; exports.swapExactOutQuoteAtBin = swapExactOutQuoteAtBin; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toAmountsOneSideByStrategy = toAmountsOneSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
12128
12339
|
//# sourceMappingURL=index.js.map
|