@pear-protocol/utils 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from './asset/index';
2
2
  export * from './basket/index';
3
3
  export * from './contract-size';
4
4
  export * from './fills/index';
5
- export { countDecimals, exponentiate } from './math/index';
5
+ export * from './math/index';
6
6
  export * from './position/index';
7
7
  export * from './precise-price';
8
8
  export * from './precise-quantity';
package/dist/index.js CHANGED
@@ -7,10 +7,17 @@ function exponentiate(value) {
7
7
  const result = Math.exp(value);
8
8
  return new BigNumber7(result);
9
9
  }
10
+ function sign(value) {
11
+ if (value.isZero()) return 0;
12
+ return value.isPositive() ? 1 : -1;
13
+ }
10
14
  function countDecimals(value) {
11
15
  const parts = value.split(".");
12
16
  return parts[1]?.length ?? 0;
13
17
  }
18
+ function compareValue(track, value, threshold) {
19
+ return track === "PEAK" ? value.isGreaterThanOrEqualTo(threshold) : value.isLessThan(threshold);
20
+ }
14
21
 
15
22
  // src/fills/compute.ts
16
23
  function computeEntryPriceForAsset(fills) {
@@ -129,8 +136,8 @@ function computeBasketWeightedRatioV1(basket, priceMap) {
129
136
  if (!price) return null;
130
137
  const priceNum = Number(price);
131
138
  if (priceNum <= 0) return null;
132
- const sign = leg.side === "BUY" ? 1 : -1;
133
- logSum += sign * leg.weight * Math.log(priceNum);
139
+ const sign2 = leg.side === "BUY" ? 1 : -1;
140
+ logSum += sign2 * leg.weight * Math.log(priceNum);
134
141
  }
135
142
  return exponentiate(logSum);
136
143
  }
@@ -471,8 +478,8 @@ function _walkBackwardsToFindLastZeroCrossing(group) {
471
478
  throw new Error("Corrupted state: fill symbol mismatch in grouped creatables");
472
479
  }
473
480
  const quantity = new BigNumber(fill.quantity);
474
- const sign = fill.side === "BUY" ? 1 : -1;
475
- const signedQuantity = quantity.multipliedBy(sign);
481
+ const sign2 = fill.side === "BUY" ? 1 : -1;
482
+ const signedQuantity = quantity.multipliedBy(sign2);
476
483
  netDelta = netDelta.plus(signedQuantity);
477
484
  }
478
485
  if (netDelta.isZero()) {
@@ -489,8 +496,8 @@ function _walkBackwardsToFindLastZeroCrossing(group) {
489
496
  if (previousExposure.plus(walkDelta).isZero() && cutoff === void 0) {
490
497
  cutoff = index;
491
498
  }
492
- const sign = fill.side === "BUY" ? 1 : -1;
493
- const quantity = new BigNumber(fill.quantity).multipliedBy(sign);
499
+ const sign2 = fill.side === "BUY" ? 1 : -1;
500
+ const quantity = new BigNumber(fill.quantity).multipliedBy(sign2);
494
501
  walkDelta = walkDelta.minus(quantity);
495
502
  }
496
503
  const allowed = new Set(
@@ -603,4 +610,4 @@ function validateQuantity(quantity, price, precision) {
603
610
  return true;
604
611
  }
605
612
 
606
- export { baseToContracts, computeAssetEntryNotional, computeAssetGrossRealizedPnL, computeAssetRealizedPnLs, computeAssetUnrealizedPnL, computeAssetUnrealizedPnLs, computeBasketWeightedRatioV1, computeEntryPriceForAsset, computeRealizedPositionState, computeSyncPayload, computeUnrealizedPositionState, contractsToBase, countDecimals, exponentiate, precisePrice, preciseQuantity, validateLeverage, validateQuantity };
613
+ export { BIPS, ZERO, baseToContracts, compareValue, computeAssetEntryNotional, computeAssetGrossRealizedPnL, computeAssetRealizedPnLs, computeAssetUnrealizedPnL, computeAssetUnrealizedPnLs, computeBasketWeightedRatioV1, computeEntryPriceForAsset, computeRealizedPositionState, computeSyncPayload, computeUnrealizedPositionState, contractsToBase, countDecimals, exponentiate, precisePrice, preciseQuantity, sign, validateLeverage, validateQuantity };
@@ -21,3 +21,4 @@ export declare function sign(value: BigNumber): 1 | -1 | 0;
21
21
  * Count decimal places in a numeric string (e.g. "0.001" → 3, "1" → 0).
22
22
  */
23
23
  export declare function countDecimals(value: string): number;
24
+ export declare function compareValue(track: 'PEAK' | 'TROUGH', value: BigNumber, threshold: number): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/utils",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "Pear Protocol Utility functions",
5
5
  "private": false,
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "typecheck": "tsc --noEmit"
27
27
  },
28
28
  "dependencies": {
29
- "@pear-protocol/types": "^0.0.21",
29
+ "@pear-protocol/types": "^1.0.0",
30
30
  "bignumber.js": "9.3.1"
31
31
  },
32
32
  "devDependencies": {