@meteora-ag/dlmm 1.6.0-rc.17 → 1.6.0-rc.18
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 +10 -3
- package/dist/index.js +219 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +246 -68
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
SystemProgram as SystemProgram2,
|
|
20
20
|
Transaction
|
|
21
21
|
} from "@solana/web3.js";
|
|
22
|
-
import
|
|
22
|
+
import Decimal8 from "decimal.js";
|
|
23
23
|
|
|
24
24
|
// src/dlmm/constants/index.ts
|
|
25
25
|
import { LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
|
|
@@ -12992,26 +12992,20 @@ import BN18 from "bn.js";
|
|
|
12992
12992
|
|
|
12993
12993
|
// src/dlmm/helpers/rebalance/liquidity_strategy/bidAsk.ts
|
|
12994
12994
|
import BN15 from "bn.js";
|
|
12995
|
-
function
|
|
12996
|
-
const binCount = maxDeltaId.sub(minDeltaId).addn(1);
|
|
12997
|
-
const totalWeight = binCount.mul(binCount.addn(1)).divn(2);
|
|
12998
|
-
return amountY.div(totalWeight);
|
|
12999
|
-
}
|
|
13000
|
-
function findBaseDeltaY(amountY, minDeltaId, maxDeltaId, minY0) {
|
|
12995
|
+
function findBaseDeltaY(amountY, minDeltaId, maxDeltaId) {
|
|
13001
12996
|
if (minDeltaId.gt(maxDeltaId) || amountY.lte(new BN15(0))) {
|
|
13002
12997
|
return new BN15(0);
|
|
13003
12998
|
}
|
|
13004
12999
|
if (minDeltaId.eq(maxDeltaId)) {
|
|
13005
13000
|
return amountY;
|
|
13006
13001
|
}
|
|
13007
|
-
const m1 = minDeltaId.neg();
|
|
13002
|
+
const m1 = minDeltaId.neg().subn(1);
|
|
13008
13003
|
const m2 = maxDeltaId.neg();
|
|
13009
13004
|
const b = m2.neg().mul(m1.sub(m2).addn(1));
|
|
13010
13005
|
const c = m1.mul(m1.addn(1)).divn(2);
|
|
13011
13006
|
const d = m2.mul(m2.subn(1)).divn(2);
|
|
13012
13007
|
const a = b.add(c.sub(d));
|
|
13013
|
-
|
|
13014
|
-
return amountY.sub(e).div(a);
|
|
13008
|
+
return amountY.div(a);
|
|
13015
13009
|
}
|
|
13016
13010
|
function findY0AndDeltaY(amountY, minDeltaId, maxDeltaId, activeId) {
|
|
13017
13011
|
if (minDeltaId.gt(maxDeltaId) || amountY.isZero()) {
|
|
@@ -13020,9 +13014,8 @@ function findY0AndDeltaY(amountY, minDeltaId, maxDeltaId, activeId) {
|
|
|
13020
13014
|
delta: new BN15(0)
|
|
13021
13015
|
};
|
|
13022
13016
|
}
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
const y0 = baseDeltaY.neg().mul(maxDeltaId).add(minY0);
|
|
13017
|
+
let baseDeltaY = findBaseDeltaY(amountY, minDeltaId, maxDeltaId);
|
|
13018
|
+
const y0 = baseDeltaY.neg().mul(maxDeltaId).add(baseDeltaY);
|
|
13026
13019
|
while (true) {
|
|
13027
13020
|
const amountInBins = getAmountInBinsBidSide(
|
|
13028
13021
|
activeId,
|
|
@@ -13044,27 +13037,14 @@ function findY0AndDeltaY(amountY, minDeltaId, maxDeltaId, activeId) {
|
|
|
13044
13037
|
}
|
|
13045
13038
|
}
|
|
13046
13039
|
}
|
|
13047
|
-
function
|
|
13048
|
-
const minBinId = activeId.add(minDeltaId);
|
|
13049
|
-
const maxBinId = activeId.add(maxDeltaId);
|
|
13050
|
-
let totalWeight = new BN15(0);
|
|
13051
|
-
for (let binId = minBinId.toNumber(); binId <= maxBinId.toNumber(); binId++) {
|
|
13052
|
-
const binDelta = binId - minBinId.toNumber() + 1;
|
|
13053
|
-
const binPrice = getQPriceFromId(new BN15(binId), binStep);
|
|
13054
|
-
const weight = new BN15(binDelta).mul(binPrice);
|
|
13055
|
-
totalWeight = totalWeight.add(weight);
|
|
13056
|
-
}
|
|
13057
|
-
return amountX.shln(SCALE_OFFSET).div(totalWeight);
|
|
13058
|
-
}
|
|
13059
|
-
function findBaseDeltaX(amountX, minDeltaId, maxDeltaId, binStep, activeId, minX0) {
|
|
13040
|
+
function findBaseDeltaX(amountX, minDeltaId, maxDeltaId, binStep, activeId) {
|
|
13060
13041
|
if (minDeltaId.gt(maxDeltaId) || amountX.lte(new BN15(0))) {
|
|
13061
13042
|
return new BN15(0);
|
|
13062
13043
|
}
|
|
13063
13044
|
let b = new BN15(0);
|
|
13064
13045
|
let c = new BN15(0);
|
|
13065
13046
|
let m1 = minDeltaId;
|
|
13066
|
-
let m2 = maxDeltaId;
|
|
13067
|
-
console.log(m1.toNumber(), m2.toNumber());
|
|
13047
|
+
let m2 = maxDeltaId.addn(1);
|
|
13068
13048
|
for (let m = m1.toNumber(); m <= m2.toNumber(); m++) {
|
|
13069
13049
|
const binId = activeId.addn(m);
|
|
13070
13050
|
const pm = getQPriceFromId(binId.neg(), binStep);
|
|
@@ -13073,8 +13053,7 @@ function findBaseDeltaX(amountX, minDeltaId, maxDeltaId, binStep, activeId, minX
|
|
|
13073
13053
|
const cDelta = new BN15(m).mul(pm);
|
|
13074
13054
|
c = c.add(cDelta);
|
|
13075
13055
|
}
|
|
13076
|
-
|
|
13077
|
-
return amountX.sub(minX0).shln(SCALE_OFFSET).div(c.sub(b));
|
|
13056
|
+
return amountX.shln(SCALE_OFFSET).div(c.sub(b));
|
|
13078
13057
|
}
|
|
13079
13058
|
function findX0AndDeltaX(amountX, minDeltaId, maxDeltaId, binStep, activeId) {
|
|
13080
13059
|
if (minDeltaId.gt(maxDeltaId) || amountX.lte(new BN15(0)) || amountX.isZero()) {
|
|
@@ -13083,18 +13062,14 @@ function findX0AndDeltaX(amountX, minDeltaId, maxDeltaId, binStep, activeId) {
|
|
|
13083
13062
|
delta: new BN15(0)
|
|
13084
13063
|
};
|
|
13085
13064
|
}
|
|
13086
|
-
const minX0 = findMinX0(amountX, minDeltaId, maxDeltaId, activeId, binStep);
|
|
13087
13065
|
let baseDeltaX = findBaseDeltaX(
|
|
13088
13066
|
amountX,
|
|
13089
13067
|
minDeltaId,
|
|
13090
13068
|
maxDeltaId,
|
|
13091
13069
|
binStep,
|
|
13092
|
-
activeId
|
|
13093
|
-
minX0
|
|
13070
|
+
activeId
|
|
13094
13071
|
);
|
|
13095
|
-
|
|
13096
|
-
const x0 = minDeltaId.neg().mul(baseDeltaX).add(minX0);
|
|
13097
|
-
console.log("\u{1F680} ~ x0:", x0.toString());
|
|
13072
|
+
const x0 = minDeltaId.neg().mul(baseDeltaX).add(baseDeltaX);
|
|
13098
13073
|
while (true) {
|
|
13099
13074
|
const amountInBins = getAmountInBinsAskSide(
|
|
13100
13075
|
activeId,
|
|
@@ -13124,6 +13099,58 @@ var BidAskStrategyParameterBuilder = class {
|
|
|
13124
13099
|
findYParameters(amountY, minDeltaId, maxDeltaId, activeId) {
|
|
13125
13100
|
return findY0AndDeltaY(amountY, minDeltaId, maxDeltaId, activeId);
|
|
13126
13101
|
}
|
|
13102
|
+
suggestBalancedXParametersFromY(activeId, binStep, favorXInActiveBin, minDeltaId, maxDeltaId, amountY) {
|
|
13103
|
+
const deltaX = amountY.div(
|
|
13104
|
+
maxDeltaId.addn(1).mul(maxDeltaId.addn(2)).divn(2)
|
|
13105
|
+
);
|
|
13106
|
+
const x0 = minDeltaId.neg().mul(deltaX).add(deltaX);
|
|
13107
|
+
const totalAmountX = toAmountIntoBins(
|
|
13108
|
+
activeId,
|
|
13109
|
+
minDeltaId,
|
|
13110
|
+
maxDeltaId,
|
|
13111
|
+
deltaX,
|
|
13112
|
+
new BN15(0),
|
|
13113
|
+
x0,
|
|
13114
|
+
new BN15(0),
|
|
13115
|
+
binStep,
|
|
13116
|
+
favorXInActiveBin
|
|
13117
|
+
).reduce((acc, bin) => {
|
|
13118
|
+
return acc.add(bin.amountX);
|
|
13119
|
+
}, new BN15(0));
|
|
13120
|
+
return {
|
|
13121
|
+
base: x0,
|
|
13122
|
+
delta: deltaX,
|
|
13123
|
+
amountX: totalAmountX
|
|
13124
|
+
};
|
|
13125
|
+
}
|
|
13126
|
+
suggestBalancedYParametersFromX(activeId, binStep, favorXInActiveBin, minDeltaId, maxDeltaId, amountXInQuoteValue) {
|
|
13127
|
+
const m1 = minDeltaId.neg().subn(1);
|
|
13128
|
+
const m2 = maxDeltaId.neg();
|
|
13129
|
+
const a1 = m2.neg().mul(m1.sub(m2).addn(1));
|
|
13130
|
+
const a2 = m1.mul(m1.addn(1)).divn(2);
|
|
13131
|
+
const a3 = m2.mul(m2.subn(1)).divn(2);
|
|
13132
|
+
const a = a1.add(a2.sub(a3));
|
|
13133
|
+
const deltaY = amountXInQuoteValue.div(a);
|
|
13134
|
+
const y0 = deltaY.neg().mul(m2).add(deltaY);
|
|
13135
|
+
const amountY = toAmountIntoBins(
|
|
13136
|
+
activeId,
|
|
13137
|
+
minDeltaId,
|
|
13138
|
+
maxDeltaId,
|
|
13139
|
+
new BN15(0),
|
|
13140
|
+
deltaY,
|
|
13141
|
+
new BN15(0),
|
|
13142
|
+
y0,
|
|
13143
|
+
binStep,
|
|
13144
|
+
favorXInActiveBin
|
|
13145
|
+
).reduce((acc, bin) => {
|
|
13146
|
+
return acc.add(bin.amountY);
|
|
13147
|
+
}, new BN15(0));
|
|
13148
|
+
return {
|
|
13149
|
+
base: y0,
|
|
13150
|
+
delta: deltaY,
|
|
13151
|
+
amountY
|
|
13152
|
+
};
|
|
13153
|
+
}
|
|
13127
13154
|
};
|
|
13128
13155
|
|
|
13129
13156
|
// src/dlmm/helpers/rebalance/liquidity_strategy/curve.ts
|
|
@@ -13228,6 +13255,56 @@ var CurveStrategyParameterBuilder = class {
|
|
|
13228
13255
|
findYParameters(amountY, minDeltaId, maxDeltaId, activeId) {
|
|
13229
13256
|
return findY0AndDeltaY2(amountY, minDeltaId, maxDeltaId, activeId);
|
|
13230
13257
|
}
|
|
13258
|
+
suggestBalancedXParametersFromY(activeId, binStep, favorXInActiveBin, minDeltaId, maxDeltaId, amountY) {
|
|
13259
|
+
const x0 = amountY.muln(2).div(maxDeltaId.addn(1));
|
|
13260
|
+
const deltaX = x0.neg().div(maxDeltaId);
|
|
13261
|
+
const totalAmountX = toAmountIntoBins(
|
|
13262
|
+
activeId,
|
|
13263
|
+
minDeltaId,
|
|
13264
|
+
maxDeltaId,
|
|
13265
|
+
deltaX,
|
|
13266
|
+
new BN16(0),
|
|
13267
|
+
x0,
|
|
13268
|
+
new BN16(0),
|
|
13269
|
+
binStep,
|
|
13270
|
+
favorXInActiveBin
|
|
13271
|
+
).reduce((acc, bin) => {
|
|
13272
|
+
return acc.add(bin.amountX);
|
|
13273
|
+
}, new BN16(0));
|
|
13274
|
+
return {
|
|
13275
|
+
base: x0,
|
|
13276
|
+
delta: deltaX,
|
|
13277
|
+
amountX: totalAmountX
|
|
13278
|
+
};
|
|
13279
|
+
}
|
|
13280
|
+
suggestBalancedYParametersFromX(activeId, binStep, favorXInActiveBin, minDeltaId, maxDeltaId, amountXInQuoteValue) {
|
|
13281
|
+
const m1 = minDeltaId.neg();
|
|
13282
|
+
const m2 = maxDeltaId.neg();
|
|
13283
|
+
const a1 = m1.sub(m2).addn(1);
|
|
13284
|
+
const a2 = m1.mul(m1.addn(1)).divn(2);
|
|
13285
|
+
const a3 = m2.mul(m2.subn(1)).divn(2);
|
|
13286
|
+
const a = m1.sub(a3.sub(a2)).div(m1);
|
|
13287
|
+
const y0 = amountXInQuoteValue.div(a);
|
|
13288
|
+
const deltaY = y0.neg().div(m1);
|
|
13289
|
+
const amountY = toAmountIntoBins(
|
|
13290
|
+
activeId,
|
|
13291
|
+
minDeltaId,
|
|
13292
|
+
maxDeltaId,
|
|
13293
|
+
new BN16(0),
|
|
13294
|
+
deltaY,
|
|
13295
|
+
new BN16(0),
|
|
13296
|
+
y0,
|
|
13297
|
+
binStep,
|
|
13298
|
+
favorXInActiveBin
|
|
13299
|
+
).reduce((acc, bin) => {
|
|
13300
|
+
return acc.add(bin.amountY);
|
|
13301
|
+
}, new BN16(0));
|
|
13302
|
+
return {
|
|
13303
|
+
base: y0,
|
|
13304
|
+
delta: deltaY,
|
|
13305
|
+
amountY
|
|
13306
|
+
};
|
|
13307
|
+
}
|
|
13231
13308
|
};
|
|
13232
13309
|
|
|
13233
13310
|
// src/dlmm/helpers/rebalance/liquidity_strategy/spot.ts
|
|
@@ -13291,9 +13368,52 @@ var SpotStrategyParameterBuilder = class {
|
|
|
13291
13368
|
delta: new BN17(0)
|
|
13292
13369
|
};
|
|
13293
13370
|
}
|
|
13371
|
+
suggestBalancedXParametersFromY(activeId, binStep, favorXInActiveBin, minDeltaId, maxDeltaId, amountY) {
|
|
13372
|
+
const x0 = amountY.div(maxDeltaId.addn(1));
|
|
13373
|
+
const totalAmountX = toAmountIntoBins(
|
|
13374
|
+
activeId,
|
|
13375
|
+
minDeltaId,
|
|
13376
|
+
maxDeltaId,
|
|
13377
|
+
new BN17(0),
|
|
13378
|
+
new BN17(0),
|
|
13379
|
+
x0,
|
|
13380
|
+
new BN17(0),
|
|
13381
|
+
binStep,
|
|
13382
|
+
favorXInActiveBin
|
|
13383
|
+
).reduce((acc, bin) => {
|
|
13384
|
+
return acc.add(bin.amountX);
|
|
13385
|
+
}, new BN17(0));
|
|
13386
|
+
return {
|
|
13387
|
+
base: new BN17(x0.toString()),
|
|
13388
|
+
delta: new BN17(0),
|
|
13389
|
+
amountX: totalAmountX
|
|
13390
|
+
};
|
|
13391
|
+
}
|
|
13392
|
+
suggestBalancedYParametersFromX(activeId, binStep, favorXInActiveBin, minDeltaId, maxDeltaId, amountXInQuoteValue) {
|
|
13393
|
+
const y0 = amountXInQuoteValue.div(maxDeltaId.sub(minDeltaId).addn(1));
|
|
13394
|
+
const amountY = toAmountIntoBins(
|
|
13395
|
+
activeId,
|
|
13396
|
+
minDeltaId,
|
|
13397
|
+
maxDeltaId,
|
|
13398
|
+
new BN17(0),
|
|
13399
|
+
new BN17(0),
|
|
13400
|
+
new BN17(0),
|
|
13401
|
+
y0,
|
|
13402
|
+
binStep,
|
|
13403
|
+
favorXInActiveBin
|
|
13404
|
+
).reduce((acc, bin) => {
|
|
13405
|
+
return acc.add(bin.amountY);
|
|
13406
|
+
}, new BN17(0));
|
|
13407
|
+
return {
|
|
13408
|
+
base: y0,
|
|
13409
|
+
delta: new BN17(0),
|
|
13410
|
+
amountY
|
|
13411
|
+
};
|
|
13412
|
+
}
|
|
13294
13413
|
};
|
|
13295
13414
|
|
|
13296
13415
|
// src/dlmm/helpers/rebalance/liquidity_strategy/index.ts
|
|
13416
|
+
import Decimal7 from "decimal.js";
|
|
13297
13417
|
function getLiquidityStrategyParameterBuilder(strategyType) {
|
|
13298
13418
|
switch (strategyType) {
|
|
13299
13419
|
case 0 /* Spot */:
|
|
@@ -14160,11 +14280,11 @@ var DLMM = class {
|
|
|
14160
14280
|
return positionsMap;
|
|
14161
14281
|
}
|
|
14162
14282
|
static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
|
|
14163
|
-
return new
|
|
14283
|
+
return new Decimal8(price).mul(new Decimal8(10 ** (tokenYDecimal - tokenXDecimal))).toString();
|
|
14164
14284
|
}
|
|
14165
14285
|
static getBinIdFromPrice(price, binStep, min) {
|
|
14166
|
-
const binStepNum = new
|
|
14167
|
-
const binId = new
|
|
14286
|
+
const binStepNum = new Decimal8(binStep).div(new Decimal8(BASIS_POINT_MAX));
|
|
14287
|
+
const binId = new Decimal8(price).log().dividedBy(new Decimal8(1).add(binStepNum).log());
|
|
14168
14288
|
return (min ? binId.floor() : binId.ceil()).toNumber();
|
|
14169
14289
|
}
|
|
14170
14290
|
/**
|
|
@@ -14776,8 +14896,8 @@ var DLMM = class {
|
|
|
14776
14896
|
*/
|
|
14777
14897
|
static calculateFeeInfo(baseFactor, binStep, baseFeePowerFactor) {
|
|
14778
14898
|
const baseFeeRate = new BN21(baseFactor).mul(new BN21(binStep)).mul(new BN21(10)).mul(new BN21(10).pow(new BN21(baseFeePowerFactor ?? 0)));
|
|
14779
|
-
const baseFeeRatePercentage = new
|
|
14780
|
-
const maxFeeRatePercentage = new
|
|
14899
|
+
const baseFeeRatePercentage = new Decimal8(baseFeeRate.toString()).mul(new Decimal8(100)).div(new Decimal8(FEE_PRECISION.toString()));
|
|
14900
|
+
const maxFeeRatePercentage = new Decimal8(MAX_FEE_RATE.toString()).mul(new Decimal8(100)).div(new Decimal8(FEE_PRECISION.toString()));
|
|
14781
14901
|
return {
|
|
14782
14902
|
baseFeeRatePercentage,
|
|
14783
14903
|
maxFeeRatePercentage
|
|
@@ -14795,7 +14915,7 @@ var DLMM = class {
|
|
|
14795
14915
|
this.lbPair.binStep,
|
|
14796
14916
|
this.lbPair.parameters.baseFeePowerFactor
|
|
14797
14917
|
);
|
|
14798
|
-
const protocolFeePercentage = new
|
|
14918
|
+
const protocolFeePercentage = new Decimal8(protocolShare.toString()).mul(new Decimal8(100)).div(new Decimal8(BASIS_POINT_MAX));
|
|
14799
14919
|
return {
|
|
14800
14920
|
baseFeeRatePercentage,
|
|
14801
14921
|
maxFeeRatePercentage,
|
|
@@ -14827,7 +14947,7 @@ var DLMM = class {
|
|
|
14827
14947
|
sParameters3,
|
|
14828
14948
|
vParameterClone
|
|
14829
14949
|
);
|
|
14830
|
-
return new
|
|
14950
|
+
return new Decimal8(totalFee.toString()).div(new Decimal8(FEE_PRECISION.toString())).mul(100);
|
|
14831
14951
|
}
|
|
14832
14952
|
/**
|
|
14833
14953
|
* The function `getEmissionRate` returns the emission rates for two rewards.
|
|
@@ -14840,8 +14960,8 @@ var DLMM = class {
|
|
|
14840
14960
|
({ rewardRate, rewardDurationEnd }) => now > rewardDurationEnd.toNumber() ? void 0 : rewardRate
|
|
14841
14961
|
);
|
|
14842
14962
|
return {
|
|
14843
|
-
rewardOne: rewardOneEmissionRate ? new
|
|
14844
|
-
rewardTwo: rewardTwoEmissionRate ? new
|
|
14963
|
+
rewardOne: rewardOneEmissionRate ? new Decimal8(rewardOneEmissionRate.toString()).div(PRECISION) : void 0,
|
|
14964
|
+
rewardTwo: rewardTwoEmissionRate ? new Decimal8(rewardTwoEmissionRate.toString()).div(PRECISION) : void 0
|
|
14845
14965
|
};
|
|
14846
14966
|
}
|
|
14847
14967
|
/**
|
|
@@ -14934,8 +15054,8 @@ var DLMM = class {
|
|
|
14934
15054
|
* @returns {string} real price of bin
|
|
14935
15055
|
*/
|
|
14936
15056
|
fromPricePerLamport(pricePerLamport) {
|
|
14937
|
-
return new
|
|
14938
|
-
new
|
|
15057
|
+
return new Decimal8(pricePerLamport).div(
|
|
15058
|
+
new Decimal8(
|
|
14939
15059
|
10 ** (this.tokenY.mint.decimals - this.tokenX.mint.decimals)
|
|
14940
15060
|
)
|
|
14941
15061
|
).toString();
|
|
@@ -15093,12 +15213,12 @@ var DLMM = class {
|
|
|
15093
15213
|
const lowerBinArrayIndex = binIdToBinArrayIndex(currentMinBinId);
|
|
15094
15214
|
const upperBinArrayIndex = binIdToBinArrayIndex(currentMaxBinId);
|
|
15095
15215
|
const binArraysCount = (await this.binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex)).length;
|
|
15096
|
-
const binArrayCost = new
|
|
15097
|
-
new
|
|
15216
|
+
const binArrayCost = new Decimal8(binArraysCount).mul(
|
|
15217
|
+
new Decimal8(BIN_ARRAY_FEE)
|
|
15098
15218
|
);
|
|
15099
15219
|
return {
|
|
15100
|
-
positionExtendCost: new
|
|
15101
|
-
new
|
|
15220
|
+
positionExtendCost: new Decimal8(positionExtendCost).div(
|
|
15221
|
+
new Decimal8(LAMPORTS_PER_SOL2)
|
|
15102
15222
|
),
|
|
15103
15223
|
binArrayCost
|
|
15104
15224
|
};
|
|
@@ -16367,7 +16487,7 @@ var DLMM = class {
|
|
|
16367
16487
|
activeId.toNumber(),
|
|
16368
16488
|
this.lbPair.binStep
|
|
16369
16489
|
);
|
|
16370
|
-
const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new
|
|
16490
|
+
const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal8(100));
|
|
16371
16491
|
actualInAmount = calculateTransferFeeIncludedAmount(
|
|
16372
16492
|
actualInAmount.add(feeAmount),
|
|
16373
16493
|
inMint,
|
|
@@ -16554,7 +16674,7 @@ var DLMM = class {
|
|
|
16554
16674
|
),
|
|
16555
16675
|
swapForY
|
|
16556
16676
|
);
|
|
16557
|
-
const priceImpact = new
|
|
16677
|
+
const priceImpact = new Decimal8(totalOutAmount.toString()).sub(new Decimal8(outAmountWithoutSlippage.toString())).div(new Decimal8(outAmountWithoutSlippage.toString())).mul(new Decimal8(100)).abs();
|
|
16558
16678
|
const endPrice = getPriceOfBinByBinId(
|
|
16559
16679
|
lastFilledActiveBinId.toNumber(),
|
|
16560
16680
|
this.lbPair.binStep
|
|
@@ -17163,11 +17283,11 @@ var DLMM = class {
|
|
|
17163
17283
|
let totalBinArraysCount = new BN21(0);
|
|
17164
17284
|
let totalBinArraysLamports = new BN21(0);
|
|
17165
17285
|
let binArrayBitmapLamports = new BN21(0);
|
|
17166
|
-
const toLamportMultiplier = new
|
|
17286
|
+
const toLamportMultiplier = new Decimal8(
|
|
17167
17287
|
10 ** (this.tokenY.mint.decimals - this.tokenX.mint.decimals)
|
|
17168
17288
|
);
|
|
17169
|
-
const minPricePerLamport = new
|
|
17170
|
-
const maxPricePerLamport = new
|
|
17289
|
+
const minPricePerLamport = new Decimal8(minPrice).mul(toLamportMultiplier);
|
|
17290
|
+
const maxPricePerLamport = new Decimal8(maxPrice).mul(toLamportMultiplier);
|
|
17171
17291
|
const minBinId = new BN21(
|
|
17172
17292
|
DLMM.getBinIdFromPrice(minPricePerLamport, this.lbPair.binStep, false)
|
|
17173
17293
|
);
|
|
@@ -18158,7 +18278,6 @@ var DLMM = class {
|
|
|
18158
18278
|
shouldClaimReward: true,
|
|
18159
18279
|
pairAddress: this.pubkey
|
|
18160
18280
|
});
|
|
18161
|
-
console.log("\u{1F680} ~ DLMM ~ rebalancePosition:", rebalancePosition);
|
|
18162
18281
|
const rebalanceStrategyBuilder = new BalancedStrategyBuilder(
|
|
18163
18282
|
new BN21(rebalancePosition.lbPair.activeId),
|
|
18164
18283
|
new BN21(rebalancePosition.lbPair.binStep),
|
|
@@ -18184,10 +18303,65 @@ var DLMM = class {
|
|
|
18184
18303
|
withdraws,
|
|
18185
18304
|
deposits
|
|
18186
18305
|
);
|
|
18187
|
-
|
|
18306
|
+
const binArrayQuoteResult = await this.quoteBinArrayAccountsRentalCost(
|
|
18307
|
+
simulationResult.depositParams,
|
|
18308
|
+
simulationResult.withdrawParams,
|
|
18309
|
+
new BN21(rebalancePosition.lbPair.activeId)
|
|
18310
|
+
);
|
|
18188
18311
|
return {
|
|
18189
18312
|
rebalancePosition,
|
|
18190
|
-
simulationResult
|
|
18313
|
+
simulationResult,
|
|
18314
|
+
...binArrayQuoteResult
|
|
18315
|
+
};
|
|
18316
|
+
}
|
|
18317
|
+
async quoteBinArrayAccountsRentalCost(deposits, withdraws, activeId) {
|
|
18318
|
+
const { binArrayBitmap, binArrayIndexes } = getRebalanceBinArrayIndexesAndBitmapCoverage(
|
|
18319
|
+
deposits,
|
|
18320
|
+
withdraws,
|
|
18321
|
+
activeId.toNumber(),
|
|
18322
|
+
this.pubkey,
|
|
18323
|
+
this.program.programId
|
|
18324
|
+
);
|
|
18325
|
+
const binArrayPublicKeys = binArrayIndexes.map((index) => {
|
|
18326
|
+
const [binArrayPubkey] = deriveBinArray(
|
|
18327
|
+
this.pubkey,
|
|
18328
|
+
index,
|
|
18329
|
+
this.program.programId
|
|
18330
|
+
);
|
|
18331
|
+
return binArrayPubkey;
|
|
18332
|
+
});
|
|
18333
|
+
const accountPublicKeys = [...binArrayPublicKeys];
|
|
18334
|
+
if (!binArrayBitmap.equals(PublicKey10.default)) {
|
|
18335
|
+
accountPublicKeys.push(binArrayBitmap);
|
|
18336
|
+
}
|
|
18337
|
+
const accounts = await chunkedGetMultipleAccountInfos(
|
|
18338
|
+
this.program.provider.connection,
|
|
18339
|
+
binArrayPublicKeys
|
|
18340
|
+
);
|
|
18341
|
+
const binArrayAccounts = accounts.splice(0, binArrayPublicKeys.length);
|
|
18342
|
+
let binArrayCount = 0;
|
|
18343
|
+
let bitmapExtensionCost = 0;
|
|
18344
|
+
const binArraySet = /* @__PURE__ */ new Set();
|
|
18345
|
+
for (let i = 0; i < binArrayAccounts.length; i++) {
|
|
18346
|
+
const binArrayAccount = binArrayAccounts[i];
|
|
18347
|
+
const binArrayPubkey = binArrayPublicKeys[i];
|
|
18348
|
+
if (!binArrayAccount) {
|
|
18349
|
+
binArrayCount++;
|
|
18350
|
+
} else {
|
|
18351
|
+
binArraySet.add(binArrayPubkey.toBase58());
|
|
18352
|
+
}
|
|
18353
|
+
}
|
|
18354
|
+
if (!binArrayBitmap.equals(PublicKey10.default)) {
|
|
18355
|
+
const bitmapAccount = accounts.pop();
|
|
18356
|
+
if (!bitmapAccount) {
|
|
18357
|
+
bitmapExtensionCost = BIN_ARRAY_BITMAP_FEE;
|
|
18358
|
+
}
|
|
18359
|
+
}
|
|
18360
|
+
return {
|
|
18361
|
+
binArrayCost: binArrayCount * BIN_ARRAY_FEE,
|
|
18362
|
+
binArrayCount,
|
|
18363
|
+
binArrayExistence: binArraySet,
|
|
18364
|
+
bitmapExtensionCost
|
|
18191
18365
|
};
|
|
18192
18366
|
}
|
|
18193
18367
|
/**
|
|
@@ -18217,9 +18391,15 @@ var DLMM = class {
|
|
|
18217
18391
|
withdraws,
|
|
18218
18392
|
deposits
|
|
18219
18393
|
);
|
|
18394
|
+
const binArrayQuoteResult = await this.quoteBinArrayAccountsRentalCost(
|
|
18395
|
+
simulationResult.depositParams,
|
|
18396
|
+
simulationResult.withdrawParams,
|
|
18397
|
+
new BN21(rebalancePosition.lbPair.activeId)
|
|
18398
|
+
);
|
|
18220
18399
|
return {
|
|
18221
18400
|
rebalancePosition,
|
|
18222
|
-
simulationResult
|
|
18401
|
+
simulationResult,
|
|
18402
|
+
...binArrayQuoteResult
|
|
18223
18403
|
};
|
|
18224
18404
|
}
|
|
18225
18405
|
/**
|
|
@@ -18297,12 +18477,10 @@ var DLMM = class {
|
|
|
18297
18477
|
chunk,
|
|
18298
18478
|
activeId
|
|
18299
18479
|
);
|
|
18300
|
-
console.log("\u{1F680} ~ DLMM ~ chunkedDepositParams:", chunkedDepositParams);
|
|
18301
18480
|
const chunkedWithdrawParams = splitWithdrawParamsForChunk(
|
|
18302
18481
|
withdrawParams,
|
|
18303
18482
|
chunk
|
|
18304
18483
|
);
|
|
18305
|
-
console.log("\u{1F680} ~ DLMM ~ chunkedWithdrawParams:", chunkedWithdrawParams);
|
|
18306
18484
|
if (chunkedDepositParams.length === 0 && chunkedWithdrawParams.length === 0)
|
|
18307
18485
|
continue;
|
|
18308
18486
|
const { slices, accounts: transferHookAccounts } = this.getPotentialToken2022IxDataAndAccounts(0 /* Liquidity */);
|
|
@@ -18668,8 +18846,8 @@ var DLMM = class {
|
|
|
18668
18846
|
if (!bins.length)
|
|
18669
18847
|
return null;
|
|
18670
18848
|
const positionData = [];
|
|
18671
|
-
let totalXAmount = new
|
|
18672
|
-
let totalYAmount = new
|
|
18849
|
+
let totalXAmount = new Decimal8(0);
|
|
18850
|
+
let totalYAmount = new Decimal8(0);
|
|
18673
18851
|
const ZERO = new BN21(0);
|
|
18674
18852
|
let feeX = ZERO;
|
|
18675
18853
|
let feeY = ZERO;
|
|
@@ -18680,8 +18858,8 @@ var DLMM = class {
|
|
|
18680
18858
|
const posBinRewardInfo = positionRewardInfos[idx];
|
|
18681
18859
|
const positionXAmount = binSupply.eq(ZERO) ? ZERO : posShare.mul(bin.xAmount).div(binSupply);
|
|
18682
18860
|
const positionYAmount = binSupply.eq(ZERO) ? ZERO : posShare.mul(bin.yAmount).div(binSupply);
|
|
18683
|
-
totalXAmount = totalXAmount.add(new
|
|
18684
|
-
totalYAmount = totalYAmount.add(new
|
|
18861
|
+
totalXAmount = totalXAmount.add(new Decimal8(positionXAmount.toString()));
|
|
18862
|
+
totalYAmount = totalYAmount.add(new Decimal8(positionYAmount.toString()));
|
|
18685
18863
|
const feeInfo = feeInfos[idx];
|
|
18686
18864
|
const newFeeX = mulShr(
|
|
18687
18865
|
posShares[idx].shrn(SCALE_OFFSET),
|
|
@@ -18845,7 +19023,7 @@ var DLMM = class {
|
|
|
18845
19023
|
rewardPerTokenStored: [ZERO, ZERO],
|
|
18846
19024
|
price: pricePerLamport,
|
|
18847
19025
|
version: 2,
|
|
18848
|
-
pricePerToken: new
|
|
19026
|
+
pricePerToken: new Decimal8(pricePerLamport).mul(new Decimal8(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
|
|
18849
19027
|
});
|
|
18850
19028
|
} else {
|
|
18851
19029
|
const bin = binArray.bins[i];
|
|
@@ -18859,7 +19037,7 @@ var DLMM = class {
|
|
|
18859
19037
|
rewardPerTokenStored: bin.rewardPerTokenStored,
|
|
18860
19038
|
price: pricePerLamport,
|
|
18861
19039
|
version: binArray.version,
|
|
18862
|
-
pricePerToken: new
|
|
19040
|
+
pricePerToken: new Decimal8(pricePerLamport).mul(new Decimal8(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString()
|
|
18863
19041
|
});
|
|
18864
19042
|
}
|
|
18865
19043
|
}
|