@pear-protocol/utils 0.5.2 → 0.5.3

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.js CHANGED
@@ -1108,13 +1108,9 @@ function resolveLeftoverTarget(args) {
1108
1108
  const leftoverShorts = new Set(leftover.filter((entry) => entry.side === "SELL").map((entry) => entry.leg.symbol));
1109
1109
  const target = book.open().find((position) => {
1110
1110
  const { longs, shorts } = position.exposure.activeLegs();
1111
- const longOk = [
1112
- ...leftoverLongs
1113
- ].every((a) => longs.has(a));
1114
- const shortOk = [
1115
- ...leftoverShorts
1116
- ].every((a) => shorts.has(a));
1117
- return longOk && shortOk;
1111
+ const sameActiveShape = setEq(leftoverLongs, longs) && setEq(leftoverShorts, shorts);
1112
+ const noDormantLegs = position.exposure.symbols().length === longs.size + shorts.size;
1113
+ return sameActiveShape && noDormantLegs;
1118
1114
  });
1119
1115
  if (target) {
1120
1116
  return target;
@@ -6,8 +6,8 @@ import type { MatchedPosition } from './types';
6
6
  * - findExactCloseTarget picks the open position whose ACTIVE legs mirror the
7
7
  * basket (dead legs ignored) — the basket closes that position first,
8
8
  * - applyCloses reduces holders (the mirrored target first, then any other),
9
- * - resolveLeftoverTarget subset-merges into a compatible position, else opens
10
- * new (same-shape ADDs consolidate here).
9
+ * - resolveLeftoverTarget merges into a position whose FULL leg set (active and
10
+ * dormant) is exactly the leftover's, else opens new (same-shape ADDs consolidate here).
11
11
  * The asset SET of a position never grows, so positionKey == key(opening symbols).
12
12
  */
13
13
  export declare function matchPositions(args: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/utils",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Pear Protocol Utility functions",
5
5
  "private": false,
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@noble/hashes": "^1.3.2",
30
- "@pear-protocol/types": "^1.24.1",
30
+ "@pear-protocol/types": "^1.28.0",
31
31
  "@scure/base": "^2.3.0",
32
32
  "bignumber.js": "9.3.1"
33
33
  },