@meteora-ag/dlmm 1.9.13 → 1.9.14-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +32 -6
- package/dist/index.js +163 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +304 -176
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
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 Decimal13 from "decimal.js";
|
|
23
23
|
|
|
24
24
|
// src/dlmm/constants/index.ts
|
|
25
25
|
import { LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
|
|
@@ -10323,13 +10323,17 @@ var LIMIT_ORDER_MIN_SIZE = 112;
|
|
|
10323
10323
|
var LIMIT_ORDER_BIN_DATA_SIZE = 32;
|
|
10324
10324
|
var BinLiquidity;
|
|
10325
10325
|
((BinLiquidity2) => {
|
|
10326
|
-
function fromBin(bin, binId, binStep, baseTokenDecimal, quoteTokenDecimal, version, lbPair) {
|
|
10326
|
+
function fromBin(bin, binId, binStep, baseTokenDecimal, quoteTokenDecimal, version, lbPair, baseMultiplier = new Decimal2(1), quoteMultiplier = new Decimal2(1)) {
|
|
10327
10327
|
const pricePerLamport = getPriceOfBinByBinId(binId, binStep).toString();
|
|
10328
10328
|
const supportLimitOrder = isSupportLimitOrder(lbPair);
|
|
10329
|
-
const xAmount = bin.amountX;
|
|
10330
|
-
const yAmount = bin.amountY;
|
|
10329
|
+
const xAmount = scaleAmountByMultiplier(bin.amountX, baseMultiplier);
|
|
10330
|
+
const yAmount = scaleAmountByMultiplier(bin.amountY, quoteMultiplier);
|
|
10331
10331
|
const supply = bin.liquiditySupply;
|
|
10332
|
-
const pricePerToken =
|
|
10332
|
+
const pricePerToken = scalePricePerToken(
|
|
10333
|
+
new Decimal2(pricePerLamport).mul(new Decimal2(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString(),
|
|
10334
|
+
baseMultiplier,
|
|
10335
|
+
quoteMultiplier
|
|
10336
|
+
);
|
|
10333
10337
|
const feeAmountXPerTokenStored = bin.feeAmountXPerTokenStored;
|
|
10334
10338
|
const feeAmountYPerTokenStored = bin.feeAmountYPerTokenStored;
|
|
10335
10339
|
if (supportLimitOrder) {
|
|
@@ -10379,7 +10383,7 @@ var BinLiquidity;
|
|
|
10379
10383
|
}
|
|
10380
10384
|
}
|
|
10381
10385
|
BinLiquidity2.fromBin = fromBin;
|
|
10382
|
-
function empty(binId, binStep, baseTokenDecimal, quoteTokenDecimal, version) {
|
|
10386
|
+
function empty(binId, binStep, baseTokenDecimal, quoteTokenDecimal, version, baseMultiplier = new Decimal2(1), quoteMultiplier = new Decimal2(1)) {
|
|
10383
10387
|
const pricePerLamport = getPriceOfBinByBinId(binId, binStep).toString();
|
|
10384
10388
|
return {
|
|
10385
10389
|
binId,
|
|
@@ -10388,7 +10392,11 @@ var BinLiquidity;
|
|
|
10388
10392
|
supply: new BN2(0),
|
|
10389
10393
|
price: pricePerLamport,
|
|
10390
10394
|
version,
|
|
10391
|
-
pricePerToken:
|
|
10395
|
+
pricePerToken: scalePricePerToken(
|
|
10396
|
+
new Decimal2(pricePerLamport).mul(new Decimal2(10 ** (baseTokenDecimal - quoteTokenDecimal))).toString(),
|
|
10397
|
+
baseMultiplier,
|
|
10398
|
+
quoteMultiplier
|
|
10399
|
+
),
|
|
10392
10400
|
feeAmountXPerTokenStored: new BN2(0),
|
|
10393
10401
|
feeAmountYPerTokenStored: new BN2(0),
|
|
10394
10402
|
rewardPerTokenStored: [new BN2(0), new BN2(0)],
|
|
@@ -10450,6 +10458,7 @@ var LimitOrderStatus = /* @__PURE__ */ ((LimitOrderStatus2) => {
|
|
|
10450
10458
|
// src/dlmm/helpers/binArray.ts
|
|
10451
10459
|
import { BN as BN8 } from "@coral-xyz/anchor";
|
|
10452
10460
|
import { PublicKey as PublicKey5 } from "@solana/web3.js";
|
|
10461
|
+
import Decimal7 from "decimal.js";
|
|
10453
10462
|
|
|
10454
10463
|
// src/dlmm/helpers/derive.ts
|
|
10455
10464
|
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
@@ -10614,7 +10623,7 @@ function deriveOperator(whitelistedSigner, programId) {
|
|
|
10614
10623
|
|
|
10615
10624
|
// src/dlmm/helpers/math.ts
|
|
10616
10625
|
import { BN as BN7 } from "@coral-xyz/anchor";
|
|
10617
|
-
import
|
|
10626
|
+
import Decimal6 from "decimal.js";
|
|
10618
10627
|
|
|
10619
10628
|
// src/dlmm/helpers/u64xu64_math.ts
|
|
10620
10629
|
import BN3 from "bn.js";
|
|
@@ -10723,11 +10732,11 @@ function pow(base, exp) {
|
|
|
10723
10732
|
// src/dlmm/helpers/weight.ts
|
|
10724
10733
|
import { BN as BN6 } from "@coral-xyz/anchor";
|
|
10725
10734
|
import gaussian from "gaussian";
|
|
10726
|
-
import
|
|
10735
|
+
import Decimal5 from "decimal.js";
|
|
10727
10736
|
|
|
10728
10737
|
// src/dlmm/helpers/weightToAmounts.ts
|
|
10729
10738
|
import { BN as BN5 } from "@coral-xyz/anchor";
|
|
10730
|
-
import
|
|
10739
|
+
import Decimal4 from "decimal.js";
|
|
10731
10740
|
|
|
10732
10741
|
// src/dlmm/helpers/token_2022.ts
|
|
10733
10742
|
import {
|
|
@@ -10746,6 +10755,7 @@ import {
|
|
|
10746
10755
|
PublicKey as PublicKey4
|
|
10747
10756
|
} from "@solana/web3.js";
|
|
10748
10757
|
import BN4 from "bn.js";
|
|
10758
|
+
import Decimal3 from "decimal.js";
|
|
10749
10759
|
async function getMultipleMintsExtraAccountMetasForTransferHook(connection, mintAddressesWithAccountInfo) {
|
|
10750
10760
|
const extraAccountMetas = await Promise.all(
|
|
10751
10761
|
mintAddressesWithAccountInfo.map(
|
|
@@ -10886,6 +10896,45 @@ function calculateTransferFeeExcludedAmount(transferFeeIncludedAmount, mint, cur
|
|
|
10886
10896
|
transferFee: new BN4(transferFee.toString())
|
|
10887
10897
|
};
|
|
10888
10898
|
}
|
|
10899
|
+
var SCALED_UI_AMOUNT_CONFIG_EXTENSION_TYPE = 25;
|
|
10900
|
+
var SCALED_UI_AMOUNT_CONFIG_SIZE = 56;
|
|
10901
|
+
function getScaledUiAmountMultiplier(mint, unixTimestamp) {
|
|
10902
|
+
const tlvData = mint.tlvData;
|
|
10903
|
+
if (!tlvData || tlvData.length === 0) {
|
|
10904
|
+
return new Decimal3(1);
|
|
10905
|
+
}
|
|
10906
|
+
let offset = 0;
|
|
10907
|
+
while (offset + 4 <= tlvData.length) {
|
|
10908
|
+
const extensionType = tlvData.readUInt16LE(offset);
|
|
10909
|
+
const length = tlvData.readUInt16LE(offset + 2);
|
|
10910
|
+
const dataStart = offset + 4;
|
|
10911
|
+
if (extensionType === SCALED_UI_AMOUNT_CONFIG_EXTENSION_TYPE && dataStart + SCALED_UI_AMOUNT_CONFIG_SIZE <= tlvData.length) {
|
|
10912
|
+
const multiplier = tlvData.readDoubleLE(dataStart + 32);
|
|
10913
|
+
const newMultiplierEffectiveTimestamp = tlvData.readBigUInt64LE(
|
|
10914
|
+
dataStart + 40
|
|
10915
|
+
);
|
|
10916
|
+
const newMultiplier = tlvData.readDoubleLE(dataStart + 48);
|
|
10917
|
+
const effectiveMultiplier = BigInt(unixTimestamp) >= newMultiplierEffectiveTimestamp ? newMultiplier : multiplier;
|
|
10918
|
+
return new Decimal3(effectiveMultiplier);
|
|
10919
|
+
}
|
|
10920
|
+
offset = dataStart + length;
|
|
10921
|
+
}
|
|
10922
|
+
return new Decimal3(1);
|
|
10923
|
+
}
|
|
10924
|
+
function scaleAmountByMultiplier(amount, multiplier) {
|
|
10925
|
+
if (multiplier.eq(1)) {
|
|
10926
|
+
return amount;
|
|
10927
|
+
}
|
|
10928
|
+
return new BN4(
|
|
10929
|
+
new Decimal3(amount.toString()).mul(multiplier).floor().toString()
|
|
10930
|
+
);
|
|
10931
|
+
}
|
|
10932
|
+
function scalePricePerToken(pricePerToken, baseMultiplier, quoteMultiplier) {
|
|
10933
|
+
if (baseMultiplier.isZero()) {
|
|
10934
|
+
return pricePerToken;
|
|
10935
|
+
}
|
|
10936
|
+
return new Decimal3(pricePerToken).mul(quoteMultiplier).div(baseMultiplier).toString();
|
|
10937
|
+
}
|
|
10889
10938
|
|
|
10890
10939
|
// src/dlmm/helpers/weightToAmounts.ts
|
|
10891
10940
|
function toAmountBidSide(activeId, totalAmount, distributions, mintY, clock) {
|
|
@@ -10896,8 +10945,8 @@ function toAmountBidSide(activeId, totalAmount, distributions, mintY, clock) {
|
|
|
10896
10945
|
).amount;
|
|
10897
10946
|
const totalWeight = distributions.reduce(function(sum, el) {
|
|
10898
10947
|
return el.binId > activeId ? sum : sum.add(el.weight);
|
|
10899
|
-
}, new
|
|
10900
|
-
if (totalWeight.cmp(new
|
|
10948
|
+
}, new Decimal4(0));
|
|
10949
|
+
if (totalWeight.cmp(new Decimal4(0)) != 1) {
|
|
10901
10950
|
throw Error("Invalid parameteres");
|
|
10902
10951
|
}
|
|
10903
10952
|
return distributions.map((bin) => {
|
|
@@ -10910,7 +10959,7 @@ function toAmountBidSide(activeId, totalAmount, distributions, mintY, clock) {
|
|
|
10910
10959
|
return {
|
|
10911
10960
|
binId: bin.binId,
|
|
10912
10961
|
amount: new BN5(
|
|
10913
|
-
new
|
|
10962
|
+
new Decimal4(totalAmount.toString()).mul(new Decimal4(bin.weight).div(totalWeight)).floor().toString()
|
|
10914
10963
|
)
|
|
10915
10964
|
};
|
|
10916
10965
|
}
|
|
@@ -10927,11 +10976,11 @@ function toAmountAskSide(activeId, binStep, totalAmount, distributions, mintX, c
|
|
|
10927
10976
|
return sum;
|
|
10928
10977
|
} else {
|
|
10929
10978
|
const price = getPriceOfBinByBinId(el.binId, binStep);
|
|
10930
|
-
const weightPerPrice = new
|
|
10979
|
+
const weightPerPrice = new Decimal4(el.weight).div(price);
|
|
10931
10980
|
return sum.add(weightPerPrice);
|
|
10932
10981
|
}
|
|
10933
|
-
}, new
|
|
10934
|
-
if (totalWeight.cmp(new
|
|
10982
|
+
}, new Decimal4(0));
|
|
10983
|
+
if (totalWeight.cmp(new Decimal4(0)) != 1) {
|
|
10935
10984
|
throw Error("Invalid parameteres");
|
|
10936
10985
|
}
|
|
10937
10986
|
return distributions.map((bin) => {
|
|
@@ -10942,11 +10991,11 @@ function toAmountAskSide(activeId, binStep, totalAmount, distributions, mintX, c
|
|
|
10942
10991
|
};
|
|
10943
10992
|
} else {
|
|
10944
10993
|
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
10945
|
-
const weightPerPrice = new
|
|
10994
|
+
const weightPerPrice = new Decimal4(bin.weight).div(price);
|
|
10946
10995
|
return {
|
|
10947
10996
|
binId: bin.binId,
|
|
10948
10997
|
amount: new BN5(
|
|
10949
|
-
new
|
|
10998
|
+
new Decimal4(totalAmount.toString()).mul(weightPerPrice).div(totalWeight).floor().toString()
|
|
10950
10999
|
)
|
|
10951
11000
|
};
|
|
10952
11001
|
}
|
|
@@ -11001,23 +11050,23 @@ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBi
|
|
|
11001
11050
|
});
|
|
11002
11051
|
if (activeBins.length === 1) {
|
|
11003
11052
|
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
11004
|
-
let wx0 = new
|
|
11005
|
-
let wy0 = new
|
|
11053
|
+
let wx0 = new Decimal4(0);
|
|
11054
|
+
let wy0 = new Decimal4(0);
|
|
11006
11055
|
const activeBin = activeBins[0];
|
|
11007
11056
|
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
11008
|
-
wx0 = new
|
|
11009
|
-
wy0 = new
|
|
11057
|
+
wx0 = new Decimal4(activeBin.weight).div(p0.mul(new Decimal4(2)));
|
|
11058
|
+
wy0 = new Decimal4(activeBin.weight).div(new Decimal4(2));
|
|
11010
11059
|
} else {
|
|
11011
|
-
let amountXInActiveBinDec = new
|
|
11012
|
-
let amountYInActiveBinDec = new
|
|
11060
|
+
let amountXInActiveBinDec = new Decimal4(amountXInActiveBin.toString());
|
|
11061
|
+
let amountYInActiveBinDec = new Decimal4(amountYInActiveBin.toString());
|
|
11013
11062
|
if (!amountXInActiveBin.isZero()) {
|
|
11014
|
-
wx0 = new
|
|
11063
|
+
wx0 = new Decimal4(activeBin.weight).div(
|
|
11015
11064
|
p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec))
|
|
11016
11065
|
);
|
|
11017
11066
|
}
|
|
11018
11067
|
if (!amountYInActiveBin.isZero()) {
|
|
11019
|
-
wy0 = new
|
|
11020
|
-
new
|
|
11068
|
+
wy0 = new Decimal4(activeBin.weight).div(
|
|
11069
|
+
new Decimal4(1).add(
|
|
11021
11070
|
p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)
|
|
11022
11071
|
)
|
|
11023
11072
|
);
|
|
@@ -11027,20 +11076,20 @@ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBi
|
|
|
11027
11076
|
let totalWeightY = wy0;
|
|
11028
11077
|
distributions.forEach((element) => {
|
|
11029
11078
|
if (element.binId < activeId) {
|
|
11030
|
-
totalWeightY = totalWeightY.add(new
|
|
11079
|
+
totalWeightY = totalWeightY.add(new Decimal4(element.weight));
|
|
11031
11080
|
}
|
|
11032
11081
|
if (element.binId > activeId) {
|
|
11033
11082
|
let price = getPriceOfBinByBinId(element.binId, binStep);
|
|
11034
|
-
let weighPerPrice = new
|
|
11083
|
+
let weighPerPrice = new Decimal4(element.weight).div(price);
|
|
11035
11084
|
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
11036
11085
|
}
|
|
11037
11086
|
});
|
|
11038
|
-
const kx = new
|
|
11039
|
-
const ky = new
|
|
11087
|
+
const kx = new Decimal4(amountX.toString()).div(totalWeightX);
|
|
11088
|
+
const ky = new Decimal4(amountY.toString()).div(totalWeightY);
|
|
11040
11089
|
let k = kx.lessThan(ky) ? kx : ky;
|
|
11041
11090
|
return distributions.map((bin) => {
|
|
11042
11091
|
if (bin.binId < activeId) {
|
|
11043
|
-
const amount = k.mul(new
|
|
11092
|
+
const amount = k.mul(new Decimal4(bin.weight));
|
|
11044
11093
|
return {
|
|
11045
11094
|
binId: bin.binId,
|
|
11046
11095
|
amountX: new BN5(0),
|
|
@@ -11049,7 +11098,7 @@ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBi
|
|
|
11049
11098
|
}
|
|
11050
11099
|
if (bin.binId > activeId) {
|
|
11051
11100
|
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
11052
|
-
const weighPerPrice = new
|
|
11101
|
+
const weighPerPrice = new Decimal4(bin.weight).div(price);
|
|
11053
11102
|
const amount = k.mul(weighPerPrice);
|
|
11054
11103
|
return {
|
|
11055
11104
|
binId: bin.binId,
|
|
@@ -11066,23 +11115,23 @@ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBi
|
|
|
11066
11115
|
};
|
|
11067
11116
|
});
|
|
11068
11117
|
} else {
|
|
11069
|
-
let totalWeightX = new
|
|
11070
|
-
let totalWeightY = new
|
|
11118
|
+
let totalWeightX = new Decimal4(0);
|
|
11119
|
+
let totalWeightY = new Decimal4(0);
|
|
11071
11120
|
distributions.forEach((element) => {
|
|
11072
11121
|
if (element.binId < activeId) {
|
|
11073
|
-
totalWeightY = totalWeightY.add(new
|
|
11122
|
+
totalWeightY = totalWeightY.add(new Decimal4(element.weight));
|
|
11074
11123
|
} else {
|
|
11075
11124
|
let price = getPriceOfBinByBinId(element.binId, binStep);
|
|
11076
|
-
let weighPerPrice = new
|
|
11125
|
+
let weighPerPrice = new Decimal4(element.weight).div(price);
|
|
11077
11126
|
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
11078
11127
|
}
|
|
11079
11128
|
});
|
|
11080
|
-
let kx = new
|
|
11081
|
-
let ky = new
|
|
11129
|
+
let kx = new Decimal4(amountX.toString()).div(totalWeightX);
|
|
11130
|
+
let ky = new Decimal4(amountY.toString()).div(totalWeightY);
|
|
11082
11131
|
let k = kx.lessThan(ky) ? kx : ky;
|
|
11083
11132
|
return distributions.map((bin) => {
|
|
11084
11133
|
if (bin.binId < activeId) {
|
|
11085
|
-
const amount = k.mul(new
|
|
11134
|
+
const amount = k.mul(new Decimal4(bin.weight));
|
|
11086
11135
|
return {
|
|
11087
11136
|
binId: bin.binId,
|
|
11088
11137
|
amountX: new BN5(0),
|
|
@@ -11090,7 +11139,7 @@ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBi
|
|
|
11090
11139
|
};
|
|
11091
11140
|
} else {
|
|
11092
11141
|
let price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
11093
|
-
let weighPerPrice = new
|
|
11142
|
+
let weighPerPrice = new Decimal4(bin.weight).div(price);
|
|
11094
11143
|
const amount = k.mul(weighPerPrice);
|
|
11095
11144
|
return {
|
|
11096
11145
|
binId: bin.binId,
|
|
@@ -11107,23 +11156,23 @@ function autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amoun
|
|
|
11107
11156
|
});
|
|
11108
11157
|
if (activeBins.length === 1) {
|
|
11109
11158
|
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
11110
|
-
let wx0 = new
|
|
11111
|
-
let wy0 = new
|
|
11159
|
+
let wx0 = new Decimal4(0);
|
|
11160
|
+
let wy0 = new Decimal4(0);
|
|
11112
11161
|
const activeBin = activeBins[0];
|
|
11113
11162
|
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
11114
|
-
wx0 = new
|
|
11115
|
-
wy0 = new
|
|
11163
|
+
wx0 = new Decimal4(activeBin.weight).div(p0.mul(new Decimal4(2)));
|
|
11164
|
+
wy0 = new Decimal4(activeBin.weight).div(new Decimal4(2));
|
|
11116
11165
|
} else {
|
|
11117
|
-
let amountXInActiveBinDec = new
|
|
11118
|
-
let amountYInActiveBinDec = new
|
|
11166
|
+
let amountXInActiveBinDec = new Decimal4(amountXInActiveBin.toString());
|
|
11167
|
+
let amountYInActiveBinDec = new Decimal4(amountYInActiveBin.toString());
|
|
11119
11168
|
if (!amountXInActiveBin.isZero()) {
|
|
11120
|
-
wx0 = new
|
|
11169
|
+
wx0 = new Decimal4(activeBin.weight).div(
|
|
11121
11170
|
p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec))
|
|
11122
11171
|
);
|
|
11123
11172
|
}
|
|
11124
11173
|
if (!amountYInActiveBin.isZero()) {
|
|
11125
|
-
wy0 = new
|
|
11126
|
-
new
|
|
11174
|
+
wy0 = new Decimal4(activeBin.weight).div(
|
|
11175
|
+
new Decimal4(1).add(
|
|
11127
11176
|
p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)
|
|
11128
11177
|
)
|
|
11129
11178
|
);
|
|
@@ -11133,30 +11182,30 @@ function autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amoun
|
|
|
11133
11182
|
let totalWeightY = wy0;
|
|
11134
11183
|
distributions.forEach((element) => {
|
|
11135
11184
|
if (element.binId < activeId) {
|
|
11136
|
-
totalWeightY = totalWeightY.add(new
|
|
11185
|
+
totalWeightY = totalWeightY.add(new Decimal4(element.weight));
|
|
11137
11186
|
}
|
|
11138
11187
|
if (element.binId > activeId) {
|
|
11139
11188
|
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
11140
|
-
const weighPerPrice = new
|
|
11189
|
+
const weighPerPrice = new Decimal4(element.weight).div(price);
|
|
11141
11190
|
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
11142
11191
|
}
|
|
11143
11192
|
});
|
|
11144
|
-
const kx = totalWeightX.isZero() ? new
|
|
11193
|
+
const kx = totalWeightX.isZero() ? new Decimal4(1) : new Decimal4(amountX.toString()).div(totalWeightX);
|
|
11145
11194
|
const amountY = kx.mul(totalWeightY);
|
|
11146
11195
|
return new BN5(amountY.floor().toString());
|
|
11147
11196
|
} else {
|
|
11148
|
-
let totalWeightX = new
|
|
11149
|
-
let totalWeightY = new
|
|
11197
|
+
let totalWeightX = new Decimal4(0);
|
|
11198
|
+
let totalWeightY = new Decimal4(0);
|
|
11150
11199
|
distributions.forEach((element) => {
|
|
11151
11200
|
if (element.binId < activeId) {
|
|
11152
|
-
totalWeightY = totalWeightY.add(new
|
|
11201
|
+
totalWeightY = totalWeightY.add(new Decimal4(element.weight));
|
|
11153
11202
|
} else {
|
|
11154
11203
|
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
11155
|
-
const weighPerPrice = new
|
|
11204
|
+
const weighPerPrice = new Decimal4(element.weight).div(price);
|
|
11156
11205
|
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
11157
11206
|
}
|
|
11158
11207
|
});
|
|
11159
|
-
const kx = totalWeightX.isZero() ? new
|
|
11208
|
+
const kx = totalWeightX.isZero() ? new Decimal4(1) : new Decimal4(amountX.toString()).div(totalWeightX);
|
|
11160
11209
|
const amountY = kx.mul(totalWeightY);
|
|
11161
11210
|
return new BN5(amountY.floor().toString());
|
|
11162
11211
|
}
|
|
@@ -11167,23 +11216,23 @@ function autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amoun
|
|
|
11167
11216
|
});
|
|
11168
11217
|
if (activeBins.length === 1) {
|
|
11169
11218
|
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
11170
|
-
let wx0 = new
|
|
11171
|
-
let wy0 = new
|
|
11219
|
+
let wx0 = new Decimal4(0);
|
|
11220
|
+
let wy0 = new Decimal4(0);
|
|
11172
11221
|
const activeBin = activeBins[0];
|
|
11173
11222
|
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
11174
|
-
wx0 = new
|
|
11175
|
-
wy0 = new
|
|
11223
|
+
wx0 = new Decimal4(activeBin.weight).div(p0.mul(new Decimal4(2)));
|
|
11224
|
+
wy0 = new Decimal4(activeBin.weight).div(new Decimal4(2));
|
|
11176
11225
|
} else {
|
|
11177
|
-
let amountXInActiveBinDec = new
|
|
11178
|
-
let amountYInActiveBinDec = new
|
|
11226
|
+
let amountXInActiveBinDec = new Decimal4(amountXInActiveBin.toString());
|
|
11227
|
+
let amountYInActiveBinDec = new Decimal4(amountYInActiveBin.toString());
|
|
11179
11228
|
if (!amountXInActiveBin.isZero()) {
|
|
11180
|
-
wx0 = new
|
|
11229
|
+
wx0 = new Decimal4(activeBin.weight).div(
|
|
11181
11230
|
p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec))
|
|
11182
11231
|
);
|
|
11183
11232
|
}
|
|
11184
11233
|
if (!amountYInActiveBin.isZero()) {
|
|
11185
|
-
wy0 = new
|
|
11186
|
-
new
|
|
11234
|
+
wy0 = new Decimal4(activeBin.weight).div(
|
|
11235
|
+
new Decimal4(1).add(
|
|
11187
11236
|
p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)
|
|
11188
11237
|
)
|
|
11189
11238
|
);
|
|
@@ -11193,30 +11242,30 @@ function autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amoun
|
|
|
11193
11242
|
let totalWeightY = wy0;
|
|
11194
11243
|
distributions.forEach((element) => {
|
|
11195
11244
|
if (element.binId < activeId) {
|
|
11196
|
-
totalWeightY = totalWeightY.add(new
|
|
11245
|
+
totalWeightY = totalWeightY.add(new Decimal4(element.weight));
|
|
11197
11246
|
}
|
|
11198
11247
|
if (element.binId > activeId) {
|
|
11199
11248
|
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
11200
|
-
const weighPerPrice = new
|
|
11249
|
+
const weighPerPrice = new Decimal4(element.weight).div(price);
|
|
11201
11250
|
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
11202
11251
|
}
|
|
11203
11252
|
});
|
|
11204
|
-
const ky = totalWeightY.isZero() ? new
|
|
11253
|
+
const ky = totalWeightY.isZero() ? new Decimal4(1) : new Decimal4(amountY.toString()).div(totalWeightY);
|
|
11205
11254
|
const amountX = ky.mul(totalWeightX);
|
|
11206
11255
|
return new BN5(amountX.floor().toString());
|
|
11207
11256
|
} else {
|
|
11208
|
-
let totalWeightX = new
|
|
11209
|
-
let totalWeightY = new
|
|
11257
|
+
let totalWeightX = new Decimal4(0);
|
|
11258
|
+
let totalWeightY = new Decimal4(0);
|
|
11210
11259
|
distributions.forEach((element) => {
|
|
11211
11260
|
if (element.binId < activeId) {
|
|
11212
|
-
totalWeightY = totalWeightY.add(new
|
|
11261
|
+
totalWeightY = totalWeightY.add(new Decimal4(element.weight));
|
|
11213
11262
|
} else {
|
|
11214
11263
|
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
11215
|
-
const weighPerPrice = new
|
|
11264
|
+
const weighPerPrice = new Decimal4(element.weight).div(price);
|
|
11216
11265
|
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
11217
11266
|
}
|
|
11218
11267
|
});
|
|
11219
|
-
const ky = totalWeightY.isZero() ? new
|
|
11268
|
+
const ky = totalWeightY.isZero() ? new Decimal4(1) : new Decimal4(amountY.toString()).div(totalWeightY);
|
|
11220
11269
|
const amountX = ky.mul(totalWeightX);
|
|
11221
11270
|
return new BN5(amountX.floor().toString());
|
|
11222
11271
|
}
|
|
@@ -11224,8 +11273,8 @@ function autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amoun
|
|
|
11224
11273
|
|
|
11225
11274
|
// src/dlmm/helpers/weight.ts
|
|
11226
11275
|
function getPriceOfBinByBinId(binId, binStep) {
|
|
11227
|
-
const binStepNum = new
|
|
11228
|
-
return new
|
|
11276
|
+
const binStepNum = new Decimal5(binStep).div(new Decimal5(BASIS_POINT_MAX));
|
|
11277
|
+
return new Decimal5(1).add(new Decimal5(binStepNum)).pow(new Decimal5(binId));
|
|
11229
11278
|
}
|
|
11230
11279
|
function buildGaussianFromBins(activeBin, binIds) {
|
|
11231
11280
|
const smallestBin = Math.min(...binIds);
|
|
@@ -11678,17 +11727,17 @@ function getQPriceBaseFactor(binStep) {
|
|
|
11678
11727
|
return base;
|
|
11679
11728
|
}
|
|
11680
11729
|
function getC(amount, binStep, binId, baseTokenDecimal, quoteTokenDecimal, minPrice, maxPrice, k) {
|
|
11681
|
-
const currentPricePerLamport = new
|
|
11730
|
+
const currentPricePerLamport = new Decimal6(1 + binStep / 1e4).pow(
|
|
11682
11731
|
binId.toNumber()
|
|
11683
11732
|
);
|
|
11684
11733
|
const currentPricePerToken = currentPricePerLamport.mul(
|
|
11685
|
-
new
|
|
11734
|
+
new Decimal6(10 ** (baseTokenDecimal - quoteTokenDecimal))
|
|
11686
11735
|
);
|
|
11687
11736
|
const priceRange = maxPrice.sub(minPrice);
|
|
11688
11737
|
const currentPriceDeltaFromMin = currentPricePerToken.sub(
|
|
11689
|
-
new
|
|
11738
|
+
new Decimal6(minPrice)
|
|
11690
11739
|
);
|
|
11691
|
-
const c = new
|
|
11740
|
+
const c = new Decimal6(amount.toString()).mul(
|
|
11692
11741
|
currentPriceDeltaFromMin.div(priceRange).pow(k)
|
|
11693
11742
|
);
|
|
11694
11743
|
return c.floor();
|
|
@@ -11761,7 +11810,7 @@ function compressBinAmount(binAmount, multiplier) {
|
|
|
11761
11810
|
};
|
|
11762
11811
|
}
|
|
11763
11812
|
function generateAmountForBinRange(amount, binStep, tokenXDecimal, tokenYDecimal, minBinId, maxBinId, k) {
|
|
11764
|
-
const toTokenMultiplier = new
|
|
11813
|
+
const toTokenMultiplier = new Decimal6(10 ** (tokenXDecimal - tokenYDecimal));
|
|
11765
11814
|
const minPrice = getPriceOfBinByBinId(minBinId.toNumber(), binStep).mul(
|
|
11766
11815
|
toTokenMultiplier
|
|
11767
11816
|
);
|
|
@@ -12059,7 +12108,7 @@ function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId
|
|
|
12059
12108
|
index
|
|
12060
12109
|
}));
|
|
12061
12110
|
}
|
|
12062
|
-
function* enumerateBins(binsById, lowerBinId, upperBinId, binStep, baseTokenDecimal, quoteTokenDecimal, version, lbPair) {
|
|
12111
|
+
function* enumerateBins(binsById, lowerBinId, upperBinId, binStep, baseTokenDecimal, quoteTokenDecimal, version, lbPair, baseMultiplier = new Decimal7(1), quoteMultiplier = new Decimal7(1)) {
|
|
12063
12112
|
for (let currentBinId = lowerBinId; currentBinId <= upperBinId; currentBinId++) {
|
|
12064
12113
|
const bin = binsById.get(currentBinId);
|
|
12065
12114
|
if (bin != null) {
|
|
@@ -12070,7 +12119,9 @@ function* enumerateBins(binsById, lowerBinId, upperBinId, binStep, baseTokenDeci
|
|
|
12070
12119
|
baseTokenDecimal,
|
|
12071
12120
|
quoteTokenDecimal,
|
|
12072
12121
|
version,
|
|
12073
|
-
lbPair
|
|
12122
|
+
lbPair,
|
|
12123
|
+
baseMultiplier,
|
|
12124
|
+
quoteMultiplier
|
|
12074
12125
|
);
|
|
12075
12126
|
} else {
|
|
12076
12127
|
yield BinLiquidity.empty(
|
|
@@ -12078,7 +12129,9 @@ function* enumerateBins(binsById, lowerBinId, upperBinId, binStep, baseTokenDeci
|
|
|
12078
12129
|
binStep,
|
|
12079
12130
|
baseTokenDecimal,
|
|
12080
12131
|
quoteTokenDecimal,
|
|
12081
|
-
version
|
|
12132
|
+
version,
|
|
12133
|
+
baseMultiplier,
|
|
12134
|
+
quoteMultiplier
|
|
12082
12135
|
);
|
|
12083
12136
|
}
|
|
12084
12137
|
}
|
|
@@ -12501,7 +12554,7 @@ function decodeExtendedPosition(base, program, bytes) {
|
|
|
12501
12554
|
// src/dlmm/helpers/rebalance/rebalancePosition.ts
|
|
12502
12555
|
import { SYSVAR_CLOCK_PUBKEY } from "@solana/web3.js";
|
|
12503
12556
|
import BN12 from "bn.js";
|
|
12504
|
-
import
|
|
12557
|
+
import Decimal8 from "decimal.js";
|
|
12505
12558
|
|
|
12506
12559
|
// src/dlmm/helpers/fee.ts
|
|
12507
12560
|
import { BN as BN11 } from "@coral-xyz/anchor";
|
|
@@ -13005,8 +13058,8 @@ var RebalancePosition = class {
|
|
|
13005
13058
|
};
|
|
13006
13059
|
}
|
|
13007
13060
|
_simulateResize(depositMinBinId, depositMaxBinId, binStep, tokenXDecimal, tokenYDecimal) {
|
|
13008
|
-
const tokenXMultiplier = new
|
|
13009
|
-
const tokenYMultiplier = new
|
|
13061
|
+
const tokenXMultiplier = new Decimal8(10 ** tokenXDecimal.toNumber());
|
|
13062
|
+
const tokenYMultiplier = new Decimal8(10 ** tokenYDecimal.toNumber());
|
|
13010
13063
|
const [minBinId, maxBinId] = findMinMaxBinIdWithLiquidity(
|
|
13011
13064
|
this.rebalancePositionBinData
|
|
13012
13065
|
);
|
|
@@ -13759,7 +13812,7 @@ var SpotStrategyParameterBuilder = class {
|
|
|
13759
13812
|
};
|
|
13760
13813
|
|
|
13761
13814
|
// src/dlmm/helpers/rebalance/liquidity_strategy/index.ts
|
|
13762
|
-
import
|
|
13815
|
+
import Decimal9 from "decimal.js";
|
|
13763
13816
|
function getLiquidityStrategyParameterBuilder(strategyType) {
|
|
13764
13817
|
switch (strategyType) {
|
|
13765
13818
|
case 0 /* Spot */:
|
|
@@ -13819,7 +13872,7 @@ function getAutoFillAmountByRebalancedPosition(rebalancePosition, strategyType)
|
|
|
13819
13872
|
binData
|
|
13820
13873
|
] of rebalancePosition.rebalancePositionBinData.entries()) {
|
|
13821
13874
|
const liquidityBid = binData.amountY;
|
|
13822
|
-
const liquidityAsk = new
|
|
13875
|
+
const liquidityAsk = new Decimal9(binData.price).mul(new Decimal9(binData.amountX.toString())).floor().toString();
|
|
13823
13876
|
liquidityInBidSide = liquidityInBidSide.add(liquidityBid);
|
|
13824
13877
|
liquidityInAskSide = liquidityInAskSide.add(new BN16(liquidityAsk));
|
|
13825
13878
|
if (binData.binId == lbPair.activeId) {
|
|
@@ -13907,8 +13960,8 @@ function suggestBalancedYParametersFromX(x0, deltaX, minDeltaId, maxDeltaId, act
|
|
|
13907
13960
|
bin.binId.toNumber(),
|
|
13908
13961
|
binStep.toNumber()
|
|
13909
13962
|
);
|
|
13910
|
-
return acc.add(price.mul(new
|
|
13911
|
-
}, new
|
|
13963
|
+
return acc.add(price.mul(new Decimal9(bin.amountX.toString())));
|
|
13964
|
+
}, new Decimal9(0));
|
|
13912
13965
|
const totalAmountXInQuoteBN = new BN16(totalAmountXInQuote.floor().toString());
|
|
13913
13966
|
const minYDeltaId = minDeltaId;
|
|
13914
13967
|
const maxYDeltaId = startDeltaIdAskSide.subn(1);
|
|
@@ -13985,7 +14038,7 @@ function buildLiquidityStrategyParameters(amountX, amountY, minDeltaId, maxDelta
|
|
|
13985
14038
|
}
|
|
13986
14039
|
|
|
13987
14040
|
// src/dlmm/helpers/index.ts
|
|
13988
|
-
import
|
|
14041
|
+
import Decimal11 from "decimal.js";
|
|
13989
14042
|
|
|
13990
14043
|
// src/dlmm/helpers/lbPair.ts
|
|
13991
14044
|
import { PublicKey as PublicKey8 } from "@solana/web3.js";
|
|
@@ -14839,7 +14892,7 @@ function getBinMaxAmountOut(bin, swapForY, supportLimitOrder) {
|
|
|
14839
14892
|
|
|
14840
14893
|
// src/dlmm/helpers/oracle/wrapper.ts
|
|
14841
14894
|
import BN19 from "bn.js";
|
|
14842
|
-
import
|
|
14895
|
+
import Decimal10 from "decimal.js";
|
|
14843
14896
|
var ORACLE_METADATA_SIZE = 8 + 24;
|
|
14844
14897
|
var OBSERVATION_SIZE = 32;
|
|
14845
14898
|
var Observation = class {
|
|
@@ -14852,7 +14905,7 @@ var Observation = class {
|
|
|
14852
14905
|
return !this.createdAt.isZero() && !this.lastUpdatedAt.isZero();
|
|
14853
14906
|
}
|
|
14854
14907
|
};
|
|
14855
|
-
function wrapOracle(oracleAddress, data, binStep, currentActiveBinId, baseTokenDecimals, quoteTokenDecimals, program) {
|
|
14908
|
+
function wrapOracle(oracleAddress, data, binStep, currentActiveBinId, baseTokenDecimals, quoteTokenDecimals, program, baseMultiplier = new Decimal10(1), quoteMultiplier = new Decimal10(1)) {
|
|
14856
14909
|
const oracleBaseData = data.subarray(0, ORACLE_METADATA_SIZE);
|
|
14857
14910
|
const oracleState = decodeAccount(program, "oracle", oracleBaseData);
|
|
14858
14911
|
const observationSlice = data.subarray(ORACLE_METADATA_SIZE);
|
|
@@ -14884,11 +14937,13 @@ function wrapOracle(oracleAddress, data, binStep, currentActiveBinId, baseTokenD
|
|
|
14884
14937
|
binStep,
|
|
14885
14938
|
currentActiveBinId,
|
|
14886
14939
|
baseTokenDecimals,
|
|
14887
|
-
quoteTokenDecimals
|
|
14940
|
+
quoteTokenDecimals,
|
|
14941
|
+
baseMultiplier,
|
|
14942
|
+
quoteMultiplier
|
|
14888
14943
|
);
|
|
14889
14944
|
}
|
|
14890
14945
|
var DynamicOracle = class {
|
|
14891
|
-
constructor(oracleAddress, metadata, observations, binStep, currentActiveBinId, baseTokenDecimals, quoteTokenDecimals) {
|
|
14946
|
+
constructor(oracleAddress, metadata, observations, binStep, currentActiveBinId, baseTokenDecimals, quoteTokenDecimals, baseMultiplier = new Decimal10(1), quoteMultiplier = new Decimal10(1)) {
|
|
14892
14947
|
this.oracleAddress = oracleAddress;
|
|
14893
14948
|
this.metadata = metadata;
|
|
14894
14949
|
this.observations = observations;
|
|
@@ -14896,6 +14951,8 @@ var DynamicOracle = class {
|
|
|
14896
14951
|
this.currentActiveBinId = currentActiveBinId;
|
|
14897
14952
|
this.baseTokenDecimals = baseTokenDecimals;
|
|
14898
14953
|
this.quoteTokenDecimals = quoteTokenDecimals;
|
|
14954
|
+
this.baseMultiplier = baseMultiplier;
|
|
14955
|
+
this.quoteMultiplier = quoteMultiplier;
|
|
14899
14956
|
}
|
|
14900
14957
|
nextIndex() {
|
|
14901
14958
|
const currentIndex = this.metadata.idx.toNumber();
|
|
@@ -14998,12 +15055,13 @@ var DynamicOracle = class {
|
|
|
14998
15055
|
if (result === null) {
|
|
14999
15056
|
return null;
|
|
15000
15057
|
}
|
|
15001
|
-
const uiMultiplier = new
|
|
15058
|
+
const uiMultiplier = new Decimal10(10).pow(
|
|
15002
15059
|
this.baseTokenDecimals - this.quoteTokenDecimals
|
|
15003
15060
|
);
|
|
15004
|
-
const quoteAdjustment = new
|
|
15061
|
+
const quoteAdjustment = new Decimal10(10).pow(this.quoteTokenDecimals);
|
|
15062
|
+
const priceScaleFactor = this.baseMultiplier.isZero() ? new Decimal10(1) : this.quoteMultiplier.div(this.baseMultiplier);
|
|
15005
15063
|
return {
|
|
15006
|
-
value: result.value.mul(uiMultiplier).mul(quoteAdjustment).floor().div(quoteAdjustment),
|
|
15064
|
+
value: result.value.mul(uiMultiplier).mul(quoteAdjustment).floor().div(quoteAdjustment).mul(priceScaleFactor),
|
|
15007
15065
|
duration: result.duration
|
|
15008
15066
|
};
|
|
15009
15067
|
}
|
|
@@ -15278,16 +15336,16 @@ function getSlippageMaxAmount(amount, slippage) {
|
|
|
15278
15336
|
if (slippage == 100) {
|
|
15279
15337
|
return U64_MAX;
|
|
15280
15338
|
}
|
|
15281
|
-
const amountDecimal = new
|
|
15339
|
+
const amountDecimal = new Decimal11(amount.toString());
|
|
15282
15340
|
const slippageAppliedAmount = new BN20(
|
|
15283
|
-
amountDecimal.mul(new
|
|
15341
|
+
amountDecimal.mul(new Decimal11(100 + slippage)).div(new Decimal11(100)).floor().toString()
|
|
15284
15342
|
);
|
|
15285
15343
|
return slippageAppliedAmount;
|
|
15286
15344
|
}
|
|
15287
15345
|
function getSlippageMinAmount(amount, slippage) {
|
|
15288
|
-
const amountDecimal = new
|
|
15346
|
+
const amountDecimal = new Decimal11(amount.toString());
|
|
15289
15347
|
return new BN20(
|
|
15290
|
-
amountDecimal.mul(new
|
|
15348
|
+
amountDecimal.mul(new Decimal11(100 - slippage)).div(new Decimal11(100)).ceil().toString()
|
|
15291
15349
|
);
|
|
15292
15350
|
}
|
|
15293
15351
|
function getPositionCountByBinCount(binCount) {
|
|
@@ -15743,7 +15801,7 @@ var BalancedStrategyBuilder = class {
|
|
|
15743
15801
|
|
|
15744
15802
|
// src/dlmm/helpers/limitOrders/wrapper.ts
|
|
15745
15803
|
import BN23 from "bn.js";
|
|
15746
|
-
import
|
|
15804
|
+
import Decimal12 from "decimal.js";
|
|
15747
15805
|
var LimitOrderBinDataWrapper = class {
|
|
15748
15806
|
constructor(inner) {
|
|
15749
15807
|
this.inner = inner;
|
|
@@ -15811,11 +15869,11 @@ var LimitOrderV1Wrapper = class {
|
|
|
15811
15869
|
let totalFeeAmountY = new BN23(0);
|
|
15812
15870
|
const collectFeeMode = lbPair.parameters.collectFeeMode;
|
|
15813
15871
|
const parsedLimitOrderBinData = [];
|
|
15814
|
-
const tokenXUiMultiplier = new
|
|
15815
|
-
new
|
|
15872
|
+
const tokenXUiMultiplier = new Decimal12(10).pow(
|
|
15873
|
+
new Decimal12(baseMint.decimals)
|
|
15816
15874
|
);
|
|
15817
|
-
const tokenYUiMultiplier = new
|
|
15818
|
-
new
|
|
15875
|
+
const tokenYUiMultiplier = new Decimal12(10).pow(
|
|
15876
|
+
new Decimal12(quoteMint.decimals)
|
|
15819
15877
|
);
|
|
15820
15878
|
for (const loBin of this.limitOrderBinData) {
|
|
15821
15879
|
const binArrayIndex = binIdToBinArrayIndex(new BN23(loBin.binId()));
|
|
@@ -15875,17 +15933,17 @@ var LimitOrderV1Wrapper = class {
|
|
|
15875
15933
|
parsedLimitOrderBinData.push({
|
|
15876
15934
|
binId: loBin.binId(),
|
|
15877
15935
|
empty: loBin.isEmpty(),
|
|
15878
|
-
depositAmountX: new
|
|
15879
|
-
depositAmountY: new
|
|
15880
|
-
unfilledAmountX: new
|
|
15881
|
-
unfilledAmountY: new
|
|
15882
|
-
swappedAmountX: new
|
|
15883
|
-
swappedAmountY: new
|
|
15936
|
+
depositAmountX: new Decimal12(depositAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15937
|
+
depositAmountY: new Decimal12(depositAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15938
|
+
unfilledAmountX: new Decimal12(unFilledAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15939
|
+
unfilledAmountY: new Decimal12(unFilledAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15940
|
+
swappedAmountX: new Decimal12(swappedAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15941
|
+
swappedAmountY: new Decimal12(swappedAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15884
15942
|
isAskSide: loBin.isAsk(),
|
|
15885
|
-
filledAmountX: new
|
|
15886
|
-
filledAmountY: new
|
|
15887
|
-
feeAmountX: new
|
|
15888
|
-
feeAmountY: new
|
|
15943
|
+
filledAmountX: new Decimal12(filledAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15944
|
+
filledAmountY: new Decimal12(filledAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15945
|
+
feeAmountX: new Decimal12(feeAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15946
|
+
feeAmountY: new Decimal12(feeAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15889
15947
|
status: limitOrderStatus
|
|
15890
15948
|
});
|
|
15891
15949
|
}
|
|
@@ -15902,21 +15960,21 @@ var LimitOrderV1Wrapper = class {
|
|
|
15902
15960
|
clock.epoch.toNumber()
|
|
15903
15961
|
).amount;
|
|
15904
15962
|
return {
|
|
15905
|
-
totalDepositAmountX: new
|
|
15906
|
-
totalDepositAmountY: new
|
|
15963
|
+
totalDepositAmountX: new Decimal12(totalAmountXDeposited.toString()).div(tokenXUiMultiplier).toString(),
|
|
15964
|
+
totalDepositAmountY: new Decimal12(totalAmountYDeposited.toString()).div(tokenYUiMultiplier).toString(),
|
|
15907
15965
|
limitOrderBinData: parsedLimitOrderBinData,
|
|
15908
|
-
totalUnfilledAmountX: new
|
|
15909
|
-
totalUnfilledAmountY: new
|
|
15910
|
-
totalFilledAmountX: new
|
|
15911
|
-
totalFilledAmountY: new
|
|
15912
|
-
totalSwappedAmountX: new
|
|
15913
|
-
totalSwappedAmountY: new
|
|
15914
|
-
totalFeeAmountX: new
|
|
15915
|
-
totalFeeAmountY: new
|
|
15916
|
-
transferFeeExcludedWithdrawableAmountX: new
|
|
15966
|
+
totalUnfilledAmountX: new Decimal12(totalUnfilledAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15967
|
+
totalUnfilledAmountY: new Decimal12(totalUnfilledAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15968
|
+
totalFilledAmountX: new Decimal12(totalFilledAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15969
|
+
totalFilledAmountY: new Decimal12(totalFilledAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15970
|
+
totalSwappedAmountX: new Decimal12(totalSwappedAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15971
|
+
totalSwappedAmountY: new Decimal12(totalSwappedAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15972
|
+
totalFeeAmountX: new Decimal12(totalFeeAmountX.toString()).div(tokenXUiMultiplier).toString(),
|
|
15973
|
+
totalFeeAmountY: new Decimal12(totalFeeAmountY.toString()).div(tokenYUiMultiplier).toString(),
|
|
15974
|
+
transferFeeExcludedWithdrawableAmountX: new Decimal12(
|
|
15917
15975
|
transferFeeExcludedWithdrawableAmountX.toString()
|
|
15918
15976
|
).div(tokenXUiMultiplier).toString(),
|
|
15919
|
-
transferFeeExcludedWithdrawableAmountY: new
|
|
15977
|
+
transferFeeExcludedWithdrawableAmountY: new Decimal12(
|
|
15920
15978
|
transferFeeExcludedWithdrawableAmountY.toString()
|
|
15921
15979
|
).div(tokenYUiMultiplier).toString()
|
|
15922
15980
|
};
|
|
@@ -16985,11 +17043,11 @@ var DLMM = class {
|
|
|
16985
17043
|
return limitOrdersMap;
|
|
16986
17044
|
}
|
|
16987
17045
|
static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
|
|
16988
|
-
return new
|
|
17046
|
+
return new Decimal13(price).mul(new Decimal13(10 ** (tokenYDecimal - tokenXDecimal))).toString();
|
|
16989
17047
|
}
|
|
16990
17048
|
static getBinIdFromPrice(price, binStep, min) {
|
|
16991
|
-
const binStepNum = new
|
|
16992
|
-
const binId = new
|
|
17049
|
+
const binStepNum = new Decimal13(binStep).div(new Decimal13(BASIS_POINT_MAX));
|
|
17050
|
+
const binId = new Decimal13(price).log().dividedBy(new Decimal13(1).add(binStepNum).log());
|
|
16993
17051
|
return (min ? binId.floor() : binId.ceil()).toNumber();
|
|
16994
17052
|
}
|
|
16995
17053
|
/**
|
|
@@ -17711,8 +17769,8 @@ var DLMM = class {
|
|
|
17711
17769
|
*/
|
|
17712
17770
|
static calculateFeeInfo(baseFactor, binStep, baseFeePowerFactor) {
|
|
17713
17771
|
const baseFeeRate = new BN24(baseFactor).mul(new BN24(binStep)).mul(new BN24(10)).mul(new BN24(10).pow(new BN24(baseFeePowerFactor ?? 0)));
|
|
17714
|
-
const baseFeeRatePercentage = new
|
|
17715
|
-
const maxFeeRatePercentage = new
|
|
17772
|
+
const baseFeeRatePercentage = new Decimal13(baseFeeRate.toString()).mul(new Decimal13(100)).div(new Decimal13(FEE_PRECISION.toString()));
|
|
17773
|
+
const maxFeeRatePercentage = new Decimal13(MAX_FEE_RATE.toString()).mul(new Decimal13(100)).div(new Decimal13(FEE_PRECISION.toString()));
|
|
17716
17774
|
return {
|
|
17717
17775
|
baseFeeRatePercentage,
|
|
17718
17776
|
maxFeeRatePercentage
|
|
@@ -17730,7 +17788,7 @@ var DLMM = class {
|
|
|
17730
17788
|
this.lbPair.binStep,
|
|
17731
17789
|
this.lbPair.parameters.baseFeePowerFactor
|
|
17732
17790
|
);
|
|
17733
|
-
const protocolFeePercentage = new
|
|
17791
|
+
const protocolFeePercentage = new Decimal13(protocolShare.toString()).mul(new Decimal13(100)).div(new Decimal13(BASIS_POINT_MAX));
|
|
17734
17792
|
return {
|
|
17735
17793
|
baseFeeRatePercentage,
|
|
17736
17794
|
maxFeeRatePercentage,
|
|
@@ -17762,7 +17820,7 @@ var DLMM = class {
|
|
|
17762
17820
|
sParameters3,
|
|
17763
17821
|
vParameterClone
|
|
17764
17822
|
);
|
|
17765
|
-
return new
|
|
17823
|
+
return new Decimal13(totalFee.toString()).div(new Decimal13(FEE_PRECISION.toString())).mul(100);
|
|
17766
17824
|
}
|
|
17767
17825
|
/**
|
|
17768
17826
|
* The function `getEmissionRate` returns the emission rates for two rewards.
|
|
@@ -17775,8 +17833,8 @@ var DLMM = class {
|
|
|
17775
17833
|
({ rewardRate, rewardDurationEnd }) => now > rewardDurationEnd.toNumber() ? void 0 : rewardRate
|
|
17776
17834
|
);
|
|
17777
17835
|
return {
|
|
17778
|
-
rewardOne: rewardOneEmissionRate ? new
|
|
17779
|
-
rewardTwo: rewardTwoEmissionRate ? new
|
|
17836
|
+
rewardOne: rewardOneEmissionRate ? new Decimal13(rewardOneEmissionRate.toString()).div(PRECISION) : void 0,
|
|
17837
|
+
rewardTwo: rewardTwoEmissionRate ? new Decimal13(rewardTwoEmissionRate.toString()).div(PRECISION) : void 0
|
|
17780
17838
|
};
|
|
17781
17839
|
}
|
|
17782
17840
|
/**
|
|
@@ -17869,11 +17927,15 @@ var DLMM = class {
|
|
|
17869
17927
|
* @returns {string} real price of bin
|
|
17870
17928
|
*/
|
|
17871
17929
|
fromPricePerLamport(pricePerLamport) {
|
|
17872
|
-
|
|
17873
|
-
|
|
17930
|
+
const nowTs = this.clock.unixTimestamp.toNumber();
|
|
17931
|
+
const baseMultiplier = getScaledUiAmountMultiplier(this.tokenX.mint, nowTs);
|
|
17932
|
+
const quoteMultiplier = getScaledUiAmountMultiplier(this.tokenY.mint, nowTs);
|
|
17933
|
+
const priceScaleFactor = baseMultiplier.isZero() ? new Decimal13(1) : quoteMultiplier.div(baseMultiplier);
|
|
17934
|
+
return new Decimal13(pricePerLamport).div(
|
|
17935
|
+
new Decimal13(
|
|
17874
17936
|
10 ** (this.tokenY.mint.decimals - this.tokenX.mint.decimals)
|
|
17875
17937
|
)
|
|
17876
|
-
).toString();
|
|
17938
|
+
).mul(priceScaleFactor).toString();
|
|
17877
17939
|
}
|
|
17878
17940
|
/**
|
|
17879
17941
|
* The function retrieves the active bin ID and its corresponding price.
|
|
@@ -18157,12 +18219,12 @@ var DLMM = class {
|
|
|
18157
18219
|
const lowerBinArrayIndex = binIdToBinArrayIndex(currentMinBinId);
|
|
18158
18220
|
const upperBinArrayIndex = binIdToBinArrayIndex(currentMaxBinId);
|
|
18159
18221
|
const binArraysCount = (await this.binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex)).length;
|
|
18160
|
-
const binArrayCost = new
|
|
18161
|
-
new
|
|
18222
|
+
const binArrayCost = new Decimal13(binArraysCount).mul(
|
|
18223
|
+
new Decimal13(BIN_ARRAY_FEE)
|
|
18162
18224
|
);
|
|
18163
18225
|
return {
|
|
18164
|
-
positionExtendCost: new
|
|
18165
|
-
new
|
|
18226
|
+
positionExtendCost: new Decimal13(positionExtendCost).div(
|
|
18227
|
+
new Decimal13(LAMPORTS_PER_SOL2)
|
|
18166
18228
|
),
|
|
18167
18229
|
binArrayCost
|
|
18168
18230
|
};
|
|
@@ -19960,7 +20022,7 @@ var DLMM = class {
|
|
|
19960
20022
|
activeId.toNumber(),
|
|
19961
20023
|
this.lbPair.binStep
|
|
19962
20024
|
);
|
|
19963
|
-
const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new
|
|
20025
|
+
const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal13(100));
|
|
19964
20026
|
actualInAmount = calculateTransferFeeIncludedAmount(
|
|
19965
20027
|
actualInAmount,
|
|
19966
20028
|
inMint,
|
|
@@ -20158,7 +20220,7 @@ var DLMM = class {
|
|
|
20158
20220
|
),
|
|
20159
20221
|
swapForY
|
|
20160
20222
|
);
|
|
20161
|
-
const priceImpact = new
|
|
20223
|
+
const priceImpact = new Decimal13(totalOutAmount.toString()).sub(new Decimal13(outAmountWithoutSlippage.toString())).div(new Decimal13(outAmountWithoutSlippage.toString())).mul(new Decimal13(100)).abs();
|
|
20162
20224
|
const endPrice = getPriceOfBinByBinId(
|
|
20163
20225
|
lastFilledActiveBinId.toNumber(),
|
|
20164
20226
|
this.lbPair.binStep
|
|
@@ -20208,6 +20270,16 @@ var DLMM = class {
|
|
|
20208
20270
|
this.clock.epoch.toNumber()
|
|
20209
20271
|
).amount;
|
|
20210
20272
|
const minOutAmount = transferFeeExcludedAmountOut.mul(new BN24(BASIS_POINT_MAX).sub(allowedSlippage)).div(new BN24(BASIS_POINT_MAX));
|
|
20273
|
+
const nowTs = this.clock.unixTimestamp.toNumber();
|
|
20274
|
+
const endPriceBaseMultiplier = getScaledUiAmountMultiplier(
|
|
20275
|
+
this.tokenX.mint,
|
|
20276
|
+
nowTs
|
|
20277
|
+
);
|
|
20278
|
+
const endPriceQuoteMultiplier = getScaledUiAmountMultiplier(
|
|
20279
|
+
this.tokenY.mint,
|
|
20280
|
+
nowTs
|
|
20281
|
+
);
|
|
20282
|
+
const scaledEndPrice = endPriceBaseMultiplier.isZero() ? endPrice : endPrice.mul(endPriceQuoteMultiplier).div(endPriceBaseMultiplier);
|
|
20211
20283
|
return {
|
|
20212
20284
|
consumedInAmount: transferFeeIncludedInAmount,
|
|
20213
20285
|
outAmount: transferFeeExcludedAmountOut,
|
|
@@ -20216,7 +20288,7 @@ var DLMM = class {
|
|
|
20216
20288
|
minOutAmount,
|
|
20217
20289
|
priceImpact,
|
|
20218
20290
|
binArraysPubkey,
|
|
20219
|
-
endPrice,
|
|
20291
|
+
endPrice: scaledEndPrice,
|
|
20220
20292
|
feeOnInput
|
|
20221
20293
|
};
|
|
20222
20294
|
}
|
|
@@ -20771,11 +20843,11 @@ var DLMM = class {
|
|
|
20771
20843
|
let totalBinArraysCount = new BN24(0);
|
|
20772
20844
|
let totalBinArraysLamports = new BN24(0);
|
|
20773
20845
|
let binArrayBitmapLamports = new BN24(0);
|
|
20774
|
-
const toLamportMultiplier = new
|
|
20846
|
+
const toLamportMultiplier = new Decimal13(
|
|
20775
20847
|
10 ** (this.tokenY.mint.decimals - this.tokenX.mint.decimals)
|
|
20776
20848
|
);
|
|
20777
|
-
const minPricePerLamport = new
|
|
20778
|
-
const maxPricePerLamport = new
|
|
20849
|
+
const minPricePerLamport = new Decimal13(minPrice).mul(toLamportMultiplier);
|
|
20850
|
+
const maxPricePerLamport = new Decimal13(maxPrice).mul(toLamportMultiplier);
|
|
20779
20851
|
const minBinId = new BN24(
|
|
20780
20852
|
DLMM.getBinIdFromPrice(minPricePerLamport, this.lbPair.binStep, false)
|
|
20781
20853
|
);
|
|
@@ -22542,6 +22614,11 @@ var DLMM = class {
|
|
|
22542
22614
|
const totalClaimedFeeYAmount = position.totalClaimedFeeYAmount();
|
|
22543
22615
|
const positionRewardInfos = position.rewardInfos();
|
|
22544
22616
|
const feeOwner = position.feeOwner();
|
|
22617
|
+
const nowTs = clock.unixTimestamp.toNumber();
|
|
22618
|
+
const baseMultiplier = getScaledUiAmountMultiplier(baseMint, nowTs);
|
|
22619
|
+
const quoteMultiplier = getScaledUiAmountMultiplier(quoteMint, nowTs);
|
|
22620
|
+
const rewardOneMultiplier = rewardMint0 ? getScaledUiAmountMultiplier(rewardMint0, nowTs) : new Decimal13(1);
|
|
22621
|
+
const rewardTwoMultiplier = rewardMint1 ? getScaledUiAmountMultiplier(rewardMint1, nowTs) : new Decimal13(1);
|
|
22545
22622
|
const bins = this.getBinsBetweenLowerAndUpperBound(
|
|
22546
22623
|
lbPairKey,
|
|
22547
22624
|
lbPair,
|
|
@@ -22550,13 +22627,15 @@ var DLMM = class {
|
|
|
22550
22627
|
baseMint.decimals,
|
|
22551
22628
|
quoteMint.decimals,
|
|
22552
22629
|
binArrayMap,
|
|
22553
|
-
program.programId
|
|
22630
|
+
program.programId,
|
|
22631
|
+
baseMultiplier,
|
|
22632
|
+
quoteMultiplier
|
|
22554
22633
|
);
|
|
22555
22634
|
if (!bins.length)
|
|
22556
22635
|
return null;
|
|
22557
22636
|
const positionData = [];
|
|
22558
|
-
let totalXAmount = new
|
|
22559
|
-
let totalYAmount = new
|
|
22637
|
+
let totalXAmount = new Decimal13(0);
|
|
22638
|
+
let totalYAmount = new Decimal13(0);
|
|
22560
22639
|
const ZERO = new BN24(0);
|
|
22561
22640
|
let feeX = ZERO;
|
|
22562
22641
|
let feeY = ZERO;
|
|
@@ -22567,8 +22646,8 @@ var DLMM = class {
|
|
|
22567
22646
|
const posBinRewardInfo = positionRewardInfos[idx];
|
|
22568
22647
|
const positionXAmount = binSupply.eq(ZERO) ? ZERO : posShare.mul(bin.xAmount).div(binSupply);
|
|
22569
22648
|
const positionYAmount = binSupply.eq(ZERO) ? ZERO : posShare.mul(bin.yAmount).div(binSupply);
|
|
22570
|
-
totalXAmount = totalXAmount.add(new
|
|
22571
|
-
totalYAmount = totalYAmount.add(new
|
|
22649
|
+
totalXAmount = totalXAmount.add(new Decimal13(positionXAmount.toString()));
|
|
22650
|
+
totalYAmount = totalYAmount.add(new Decimal13(positionYAmount.toString()));
|
|
22572
22651
|
const feeInfo = feeInfos[idx];
|
|
22573
22652
|
const newFeeX = posShare.isZero() ? new BN24(0) : mulShr(
|
|
22574
22653
|
posShares[idx].shrn(SCALE_OFFSET),
|
|
@@ -22633,10 +22712,19 @@ var DLMM = class {
|
|
|
22633
22712
|
positionLiquidity: posShare.toString(),
|
|
22634
22713
|
positionXAmount: positionXAmount.toString(),
|
|
22635
22714
|
positionYAmount: positionYAmount.toString(),
|
|
22636
|
-
positionFeeXAmount:
|
|
22637
|
-
|
|
22715
|
+
positionFeeXAmount: scaleAmountByMultiplier(
|
|
22716
|
+
claimableFeeX,
|
|
22717
|
+
baseMultiplier
|
|
22718
|
+
).toString(),
|
|
22719
|
+
positionFeeYAmount: scaleAmountByMultiplier(
|
|
22720
|
+
claimableFeeY,
|
|
22721
|
+
quoteMultiplier
|
|
22722
|
+
).toString(),
|
|
22638
22723
|
positionRewardAmount: claimableRewardsInBin.map(
|
|
22639
|
-
(amount) =>
|
|
22724
|
+
(amount, j) => scaleAmountByMultiplier(
|
|
22725
|
+
amount,
|
|
22726
|
+
j === 0 ? rewardOneMultiplier : rewardTwoMultiplier
|
|
22727
|
+
).toString()
|
|
22640
22728
|
)
|
|
22641
22729
|
});
|
|
22642
22730
|
});
|
|
@@ -22680,29 +22768,48 @@ var DLMM = class {
|
|
|
22680
22768
|
currentEpoch
|
|
22681
22769
|
).amount;
|
|
22682
22770
|
return {
|
|
22771
|
+
// totals inherit the scale from the already-scaled bin amounts
|
|
22683
22772
|
totalXAmount: totalXAmount.toString(),
|
|
22684
22773
|
totalYAmount: totalYAmount.toString(),
|
|
22685
22774
|
positionBinData: positionData,
|
|
22686
22775
|
lastUpdatedAt,
|
|
22687
22776
|
lowerBinId: lowerBinId.toNumber(),
|
|
22688
22777
|
upperBinId: upperBinId.toNumber(),
|
|
22689
|
-
feeX,
|
|
22690
|
-
feeY,
|
|
22691
|
-
rewardOne,
|
|
22692
|
-
rewardTwo,
|
|
22778
|
+
feeX: scaleAmountByMultiplier(feeX, baseMultiplier),
|
|
22779
|
+
feeY: scaleAmountByMultiplier(feeY, quoteMultiplier),
|
|
22780
|
+
rewardOne: scaleAmountByMultiplier(rewardOne, rewardOneMultiplier),
|
|
22781
|
+
rewardTwo: scaleAmountByMultiplier(rewardTwo, rewardTwoMultiplier),
|
|
22693
22782
|
feeOwner,
|
|
22694
|
-
totalClaimedFeeXAmount
|
|
22695
|
-
|
|
22783
|
+
totalClaimedFeeXAmount: scaleAmountByMultiplier(
|
|
22784
|
+
totalClaimedFeeXAmount,
|
|
22785
|
+
baseMultiplier
|
|
22786
|
+
),
|
|
22787
|
+
totalClaimedFeeYAmount: scaleAmountByMultiplier(
|
|
22788
|
+
totalClaimedFeeYAmount,
|
|
22789
|
+
quoteMultiplier
|
|
22790
|
+
),
|
|
22696
22791
|
totalXAmountExcludeTransferFee,
|
|
22697
22792
|
totalYAmountExcludeTransferFee,
|
|
22698
|
-
rewardOneExcludeTransferFee
|
|
22699
|
-
|
|
22700
|
-
|
|
22701
|
-
|
|
22793
|
+
rewardOneExcludeTransferFee: scaleAmountByMultiplier(
|
|
22794
|
+
rewardOneExcludeTransferFee,
|
|
22795
|
+
rewardOneMultiplier
|
|
22796
|
+
),
|
|
22797
|
+
rewardTwoExcludeTransferFee: scaleAmountByMultiplier(
|
|
22798
|
+
rewardTwoExcludeTransferFee,
|
|
22799
|
+
rewardTwoMultiplier
|
|
22800
|
+
),
|
|
22801
|
+
feeXExcludeTransferFee: scaleAmountByMultiplier(
|
|
22802
|
+
feeXExcludeTransferFee,
|
|
22803
|
+
baseMultiplier
|
|
22804
|
+
),
|
|
22805
|
+
feeYExcludeTransferFee: scaleAmountByMultiplier(
|
|
22806
|
+
feeYExcludeTransferFee,
|
|
22807
|
+
quoteMultiplier
|
|
22808
|
+
),
|
|
22702
22809
|
owner: position.owner()
|
|
22703
22810
|
};
|
|
22704
22811
|
}
|
|
22705
|
-
static getBinsBetweenLowerAndUpperBound(lbPairKey, lbPair, lowerBinId, upperBinId, baseTokenDecimal, quoteTokenDecimal, binArrayMap, programId) {
|
|
22812
|
+
static getBinsBetweenLowerAndUpperBound(lbPairKey, lbPair, lowerBinId, upperBinId, baseTokenDecimal, quoteTokenDecimal, binArrayMap, programId, baseMultiplier = new Decimal13(1), quoteMultiplier = new Decimal13(1)) {
|
|
22706
22813
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN24(lowerBinId));
|
|
22707
22814
|
const upperBinArrayIndex = binIdToBinArrayIndex(new BN24(upperBinId));
|
|
22708
22815
|
let bins = [];
|
|
@@ -22725,7 +22832,9 @@ var DLMM = class {
|
|
|
22725
22832
|
lbPair.binStep,
|
|
22726
22833
|
baseTokenDecimal,
|
|
22727
22834
|
quoteTokenDecimal,
|
|
22728
|
-
BIN_ARRAY_DEFAULT_VERSION
|
|
22835
|
+
BIN_ARRAY_DEFAULT_VERSION,
|
|
22836
|
+
baseMultiplier,
|
|
22837
|
+
quoteMultiplier
|
|
22729
22838
|
)
|
|
22730
22839
|
);
|
|
22731
22840
|
} else {
|
|
@@ -22738,7 +22847,9 @@ var DLMM = class {
|
|
|
22738
22847
|
baseTokenDecimal,
|
|
22739
22848
|
quoteTokenDecimal,
|
|
22740
22849
|
binArray.version,
|
|
22741
|
-
lbPair
|
|
22850
|
+
lbPair,
|
|
22851
|
+
baseMultiplier,
|
|
22852
|
+
quoteMultiplier
|
|
22742
22853
|
)
|
|
22743
22854
|
);
|
|
22744
22855
|
}
|
|
@@ -22799,6 +22910,15 @@ var DLMM = class {
|
|
|
22799
22910
|
})
|
|
22800
22911
|
);
|
|
22801
22912
|
const version = binArrays.find((binArray) => binArray != null)?.version ?? 1;
|
|
22913
|
+
const nowTs = this.clock.unixTimestamp.toNumber();
|
|
22914
|
+
const baseMultiplier = getScaledUiAmountMultiplier(
|
|
22915
|
+
this.tokenX.mint,
|
|
22916
|
+
nowTs
|
|
22917
|
+
);
|
|
22918
|
+
const quoteMultiplier = getScaledUiAmountMultiplier(
|
|
22919
|
+
this.tokenY.mint,
|
|
22920
|
+
nowTs
|
|
22921
|
+
);
|
|
22802
22922
|
return Array.from(
|
|
22803
22923
|
enumerateBins(
|
|
22804
22924
|
binsById,
|
|
@@ -22808,7 +22928,9 @@ var DLMM = class {
|
|
|
22808
22928
|
baseTokenDecimal,
|
|
22809
22929
|
quoteTokenDecimal,
|
|
22810
22930
|
version,
|
|
22811
|
-
this.lbPair
|
|
22931
|
+
this.lbPair,
|
|
22932
|
+
baseMultiplier,
|
|
22933
|
+
quoteMultiplier
|
|
22812
22934
|
)
|
|
22813
22935
|
);
|
|
22814
22936
|
}
|
|
@@ -23071,6 +23193,7 @@ var DLMM = class {
|
|
|
23071
23193
|
"lbPair",
|
|
23072
23194
|
lbPairAccountInfo.data
|
|
23073
23195
|
);
|
|
23196
|
+
const nowTs = this.clock.unixTimestamp.toNumber();
|
|
23074
23197
|
return wrapOracle(
|
|
23075
23198
|
oracleAddress,
|
|
23076
23199
|
oracleAccountInfo.data,
|
|
@@ -23078,7 +23201,9 @@ var DLMM = class {
|
|
|
23078
23201
|
new BN24(lbPairState.activeId),
|
|
23079
23202
|
this.tokenX.mint.decimals,
|
|
23080
23203
|
this.tokenY.mint.decimals,
|
|
23081
|
-
this.program
|
|
23204
|
+
this.program,
|
|
23205
|
+
getScaledUiAmountMultiplier(this.tokenX.mint, nowTs),
|
|
23206
|
+
getScaledUiAmountMultiplier(this.tokenY.mint, nowTs)
|
|
23082
23207
|
);
|
|
23083
23208
|
}
|
|
23084
23209
|
/**
|
|
@@ -23279,6 +23404,7 @@ export {
|
|
|
23279
23404
|
getQPriceBaseFactor,
|
|
23280
23405
|
getQPriceFromId,
|
|
23281
23406
|
getRebalanceBinArrayIndexesAndBitmapCoverage,
|
|
23407
|
+
getScaledUiAmountMultiplier,
|
|
23282
23408
|
getSlippageMaxAmount,
|
|
23283
23409
|
getSlippageMinAmount,
|
|
23284
23410
|
getTokenBalance,
|
|
@@ -23306,6 +23432,8 @@ export {
|
|
|
23306
23432
|
presetParameter2BinStepFilter,
|
|
23307
23433
|
range,
|
|
23308
23434
|
resetUninvolvedLiquidityParams,
|
|
23435
|
+
scaleAmountByMultiplier,
|
|
23436
|
+
scalePricePerToken,
|
|
23309
23437
|
shlDiv,
|
|
23310
23438
|
splitFee,
|
|
23311
23439
|
suggestBalancedXParametersFromY,
|