@metamask-previews/perps-controller 11.0.0-preview-9c0f91815 → 11.0.0-preview-e57e5c3dc

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +0 -49
  2. package/dist/PerpsController.cjs.map +1 -1
  3. package/dist/PerpsController.d.cts +1 -1
  4. package/dist/PerpsController.d.cts.map +1 -1
  5. package/dist/PerpsController.d.mts +1 -1
  6. package/dist/PerpsController.d.mts.map +1 -1
  7. package/dist/PerpsController.mjs.map +1 -1
  8. package/dist/constants/eventNames.cjs +0 -4
  9. package/dist/constants/eventNames.cjs.map +1 -1
  10. package/dist/constants/eventNames.d.cts +0 -3
  11. package/dist/constants/eventNames.d.cts.map +1 -1
  12. package/dist/constants/eventNames.d.mts +0 -3
  13. package/dist/constants/eventNames.d.mts.map +1 -1
  14. package/dist/constants/eventNames.mjs +0 -4
  15. package/dist/constants/eventNames.mjs.map +1 -1
  16. package/dist/constants/perpsConfig.cjs +1 -54
  17. package/dist/constants/perpsConfig.cjs.map +1 -1
  18. package/dist/constants/perpsConfig.d.cts +2 -71
  19. package/dist/constants/perpsConfig.d.cts.map +1 -1
  20. package/dist/constants/perpsConfig.d.mts +2 -71
  21. package/dist/constants/perpsConfig.d.mts.map +1 -1
  22. package/dist/constants/perpsConfig.mjs +0 -53
  23. package/dist/constants/perpsConfig.mjs.map +1 -1
  24. package/dist/index.cjs +3 -12
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +4 -4
  27. package/dist/index.d.cts.map +1 -1
  28. package/dist/index.d.mts +4 -4
  29. package/dist/index.d.mts.map +1 -1
  30. package/dist/index.mjs +2 -2
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/perpsErrorCodes.cjs +0 -20
  33. package/dist/perpsErrorCodes.cjs.map +1 -1
  34. package/dist/perpsErrorCodes.d.cts +0 -19
  35. package/dist/perpsErrorCodes.d.cts.map +1 -1
  36. package/dist/perpsErrorCodes.d.mts +0 -19
  37. package/dist/perpsErrorCodes.d.mts.map +1 -1
  38. package/dist/perpsErrorCodes.mjs +0 -20
  39. package/dist/perpsErrorCodes.mjs.map +1 -1
  40. package/dist/providers/HyperLiquidProvider.cjs +14 -1276
  41. package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
  42. package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
  43. package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
  44. package/dist/providers/HyperLiquidProvider.mjs +17 -1279
  45. package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
  46. package/dist/types/index.cjs.map +1 -1
  47. package/dist/types/index.d.cts +2 -40
  48. package/dist/types/index.d.cts.map +1 -1
  49. package/dist/types/index.d.mts +2 -40
  50. package/dist/types/index.d.mts.map +1 -1
  51. package/dist/types/index.mjs.map +1 -1
  52. package/dist/types/perps-types.cjs.map +1 -1
  53. package/dist/types/perps-types.d.cts +2 -33
  54. package/dist/types/perps-types.d.cts.map +1 -1
  55. package/dist/types/perps-types.d.mts +2 -33
  56. package/dist/types/perps-types.d.mts.map +1 -1
  57. package/dist/types/perps-types.mjs.map +1 -1
  58. package/dist/utils/hyperLiquidValidation.cjs +3 -192
  59. package/dist/utils/hyperLiquidValidation.cjs.map +1 -1
  60. package/dist/utils/hyperLiquidValidation.d.cts +3 -30
  61. package/dist/utils/hyperLiquidValidation.d.cts.map +1 -1
  62. package/dist/utils/hyperLiquidValidation.d.mts +3 -30
  63. package/dist/utils/hyperLiquidValidation.d.mts.map +1 -1
  64. package/dist/utils/hyperLiquidValidation.mjs +5 -194
  65. package/dist/utils/hyperLiquidValidation.mjs.map +1 -1
  66. package/dist/utils/orderCalculations.cjs +1 -131
  67. package/dist/utils/orderCalculations.cjs.map +1 -1
  68. package/dist/utils/orderCalculations.d.cts +3 -88
  69. package/dist/utils/orderCalculations.d.cts.map +1 -1
  70. package/dist/utils/orderCalculations.d.mts +3 -88
  71. package/dist/utils/orderCalculations.d.mts.map +1 -1
  72. package/dist/utils/orderCalculations.mjs +2 -128
  73. package/dist/utils/orderCalculations.mjs.map +1 -1
  74. package/dist/utils/orderTypes.cjs +4 -56
  75. package/dist/utils/orderTypes.cjs.map +1 -1
  76. package/dist/utils/orderTypes.d.cts +3 -32
  77. package/dist/utils/orderTypes.d.cts.map +1 -1
  78. package/dist/utils/orderTypes.d.mts +3 -32
  79. package/dist/utils/orderTypes.d.mts.map +1 -1
  80. package/dist/utils/orderTypes.mjs +3 -54
  81. package/dist/utils/orderTypes.mjs.map +1 -1
  82. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"orderTypes.d.cts","sourceRoot":"","sources":["../../src/utils/orderTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,oBAAoB,EAAE,2BAA0B;AACrE,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EACjB,iCAAgC;AAEjC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,mFAKgB,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,qCAIgB,CAAC;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;;CAA+B,CAAC;AA8B9D;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GACnB,SAAS,IAAI,gBAAgB,CAE/B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,GACnB,SAAS,IAAI,iBAAiB,CAEhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAIvE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,SAAS,GAAG,cAAc,CAIxE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,gBAAgB,GAC1B,gBAAgB,CAIlB;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AE,SAAS,GAAG,OAAO,CAIvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,SAAS,GAAG,cAAc,CAExE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,gBAAgB,GAC1B,gBAAgB,CAIlB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,gBAAgB,GAAG,SAAS,CAuB/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kCAAkC,CAAC,MAAM,EAAE;IACzD,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,oBAAoB,GAAG,SAAS,CAqDnC;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAC5C,SAAS,EAAE,gBAAgB,CAAC;IAC5B,SAAS,EAAE,cAAc,CAAC;CAC3B,GAAG,gBAAgB,CAQnB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAClC,KAAK,GAAG,KAAK,GAAG,KAAK,CASvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAUzE"}
@@ -1,27 +1,10 @@
1
1
  import type { Order, PositionTriggerOrder } from "../types/index.mjs";
2
- import type { OrderExecution, OrderType, StrategyOrderType, TriggerDirection, TriggerOrderType } from "../types/perps-types.mjs";
2
+ import type { OrderExecution, OrderType, TriggerDirection, TriggerOrderType } from "../types/perps-types.mjs";
3
3
  /**
4
4
  * All trigger placement types, in a stable order suitable for iteration
5
5
  * (validation tables, e2e matrices).
6
6
  */
7
7
  export declare const TRIGGER_ORDER_TYPES: readonly ["stop_market", "stop_limit", "take_profit_market", "take_profit_limit"];
8
- /**
9
- * All strategy placement types, in a stable order suitable for iteration
10
- * (validation tables, e2e matrices).
11
- */
12
- export declare const STRATEGY_ORDER_TYPES: readonly ["twap", "scale", "chase"];
13
- /**
14
- * Bounds on how many limit orders a scale placement may fan out into.
15
- *
16
- * A ladder needs at least two rungs to span a range at all; the upper bound
17
- * keeps a single placement from consuming a venue's per-account open-order
18
- * budget. Protocol-agnostic: a provider whose venue is stricter narrows this
19
- * further in its own validation.
20
- */
21
- export declare const SCALE_ORDER_COUNT: {
22
- readonly min: 2;
23
- readonly max: 20;
24
- };
25
8
  /**
26
9
  * Check whether an order type is a trigger placement (stop / take profit).
27
10
  *
@@ -29,14 +12,6 @@ export declare const SCALE_ORDER_COUNT: {
29
12
  * @returns True when the type requires `OrderParams.triggerPrice`.
30
13
  */
31
14
  export declare function isTriggerOrderType(orderType: OrderType): orderType is TriggerOrderType;
32
- /**
33
- * Check whether an order type is a strategy placement (TWAP / scale / chase).
34
- *
35
- * @param orderType - Order type to check.
36
- * @returns True when the placement expands into an execution schedule rather
37
- * than a single order.
38
- */
39
- export declare function isStrategyOrderType(orderType: OrderType): orderType is StrategyOrderType;
40
15
  /**
41
16
  * Check whether an order type executes as a limit order.
42
17
  *
@@ -51,14 +26,10 @@ export declare function isLimitExecutionOrderType(orderType: OrderType): boolean
51
26
  * Get how an order executes, ignoring whether it is trigger-gated.
52
27
  *
53
28
  * This is also the coarse execution type that consumers predating trigger orders
54
- * understand (fee tiers, max order value, analytics). It answers "does this rest
55
- * on the book or cross it", which is not the same question as
56
- * `isLimitExecutionOrderType` — a scale ladder and a chase rest limit orders
57
- * without carrying an `OrderParams.price`.
29
+ * understand (fee tiers, max order value, analytics).
58
30
  *
59
31
  * @param orderType - Order type to inspect.
60
- * @returns `'limit'` for limit, `*_limit`, `scale` and `chase`; `'market'`
61
- * otherwise, including `twap`, whose suborders cross the book.
32
+ * @returns `'limit'` for limit and `*_limit` types, `'market'` otherwise.
62
33
  */
63
34
  export declare function getTriggerExecution(orderType: OrderType): OrderExecution;
64
35
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"orderTypes.d.mts","sourceRoot":"","sources":["../../src/utils/orderTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,oBAAoB,EAAE,2BAA0B;AACrE,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EACjB,iCAAgC;AAEjC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,mFAKgB,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,qCAIgB,CAAC;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;;CAA+B,CAAC;AA8B9D;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,GACnB,SAAS,IAAI,gBAAgB,CAE/B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,GACnB,SAAS,IAAI,iBAAiB,CAEhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAIvE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,SAAS,GAAG,cAAc,CAIxE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,gBAAgB,GAC1B,gBAAgB,CAIlB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,gBAAgB,GAAG,SAAS,CAuB/B;AAED;;;;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GAYG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,gBAAgB,GAAG,SAAS,CAuB/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kCAAkC,CAAC,MAAM,EAAE;IACzD,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,oBAAoB,GAAG,SAAS,CAqDnC;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAC5C,SAAS,EAAE,gBAAgB,CAAC;IAC5B,SAAS,EAAE,cAAc,CAAC;CAC3B,GAAG,gBAAgB,CAQnB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAClC,KAAK,GAAG,KAAK,GAAG,KAAK,CASvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAUzE"}
@@ -8,24 +8,6 @@ export const TRIGGER_ORDER_TYPES = [
8
8
  'take_profit_market',
9
9
  'take_profit_limit',
10
10
  ];
11
- /**
12
- * All strategy placement types, in a stable order suitable for iteration
13
- * (validation tables, e2e matrices).
14
- */
15
- export const STRATEGY_ORDER_TYPES = [
16
- 'twap',
17
- 'scale',
18
- 'chase',
19
- ];
20
- /**
21
- * Bounds on how many limit orders a scale placement may fan out into.
22
- *
23
- * A ladder needs at least two rungs to span a range at all; the upper bound
24
- * keeps a single placement from consuming a venue's per-account open-order
25
- * budget. Protocol-agnostic: a provider whose venue is stricter narrows this
26
- * further in its own validation.
27
- */
28
- export const SCALE_ORDER_COUNT = { min: 2, max: 20 };
29
11
  /**
30
12
  * Order types whose price field (`OrderParams.price`) is a real limit price the
31
13
  * exchange must honour, as opposed to a slippage cap derived from the market.
@@ -35,23 +17,6 @@ const LIMIT_EXECUTION_ORDER_TYPES = [
35
17
  'stop_limit',
36
18
  'take_profit_limit',
37
19
  ];
38
- /**
39
- * Order types that rest limit orders on the book, whatever decides their price.
40
- *
41
- * A superset of `LIMIT_EXECUTION_ORDER_TYPES`: a scale ladder and a chase both
42
- * rest limit orders, but they derive their own prices rather than taking one
43
- * from `OrderParams.price`, so they are limit *execution* without being
44
- * limit-*priced*. A TWAP is absent because its suborders cross the book.
45
- *
46
- * The distinction matters wherever execution is what is being charged or
47
- * bounded — fee tier, max order value — as opposed to where the caller's price
48
- * field is being read.
49
- */
50
- const LIMIT_RESTING_ORDER_TYPES = [
51
- ...LIMIT_EXECUTION_ORDER_TYPES,
52
- 'scale',
53
- 'chase',
54
- ];
55
20
  /**
56
21
  * Check whether an order type is a trigger placement (stop / take profit).
57
22
  *
@@ -61,16 +26,6 @@ const LIMIT_RESTING_ORDER_TYPES = [
61
26
  export function isTriggerOrderType(orderType) {
62
27
  return TRIGGER_ORDER_TYPES.includes(orderType);
63
28
  }
64
- /**
65
- * Check whether an order type is a strategy placement (TWAP / scale / chase).
66
- *
67
- * @param orderType - Order type to check.
68
- * @returns True when the placement expands into an execution schedule rather
69
- * than a single order.
70
- */
71
- export function isStrategyOrderType(orderType) {
72
- return STRATEGY_ORDER_TYPES.includes(orderType);
73
- }
74
29
  /**
75
30
  * Check whether an order type executes as a limit order.
76
31
  *
@@ -87,19 +42,13 @@ export function isLimitExecutionOrderType(orderType) {
87
42
  * Get how an order executes, ignoring whether it is trigger-gated.
88
43
  *
89
44
  * This is also the coarse execution type that consumers predating trigger orders
90
- * understand (fee tiers, max order value, analytics). It answers "does this rest
91
- * on the book or cross it", which is not the same question as
92
- * `isLimitExecutionOrderType` — a scale ladder and a chase rest limit orders
93
- * without carrying an `OrderParams.price`.
45
+ * understand (fee tiers, max order value, analytics).
94
46
  *
95
47
  * @param orderType - Order type to inspect.
96
- * @returns `'limit'` for limit, `*_limit`, `scale` and `chase`; `'market'`
97
- * otherwise, including `twap`, whose suborders cross the book.
48
+ * @returns `'limit'` for limit and `*_limit` types, `'market'` otherwise.
98
49
  */
99
50
  export function getTriggerExecution(orderType) {
100
- return LIMIT_RESTING_ORDER_TYPES.includes(orderType)
101
- ? 'limit'
102
- : 'market';
51
+ return isLimitExecutionOrderType(orderType) ? 'limit' : 'market';
103
52
  }
104
53
  /**
105
54
  * Get the direction a trigger order fires in.
@@ -1 +1 @@
1
- {"version":3,"file":"orderTypes.mjs","sourceRoot":"","sources":["../../src/utils/orderTypes.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,aAAa;IACb,YAAY;IACZ,oBAAoB;IACpB,mBAAmB;CAC2B,CAAC;AAEjD;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,MAAM;IACN,OAAO;IACP,OAAO;CACwC,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAW,CAAC;AAE9D;;;GAGG;AACH,MAAM,2BAA2B,GAAG;IAClC,OAAO;IACP,YAAY;IACZ,mBAAmB;CACoB,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,MAAM,yBAAyB,GAAG;IAChC,GAAG,2BAA2B;IAC9B,OAAO;IACP,OAAO;CACgC,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAoB;IAEpB,OAAQ,mBAA4C,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAAoB;IAEpB,OAAQ,oBAA6C,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;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AAS,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACnI;SACA,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["import type { Order, PositionTriggerOrder } from '../types/index.js';\nimport type {\n OrderExecution,\n OrderType,\n StrategyOrderType,\n TriggerDirection,\n TriggerOrderType,\n} from '../types/perps-types.js';\n\n/**\n * All trigger placement types, in a stable order suitable for iteration\n * (validation tables, e2e matrices).\n */\nexport const TRIGGER_ORDER_TYPES = [\n 'stop_market',\n 'stop_limit',\n 'take_profit_market',\n 'take_profit_limit',\n] as const satisfies readonly TriggerOrderType[];\n\n/**\n * All strategy placement types, in a stable order suitable for iteration\n * (validation tables, e2e matrices).\n */\nexport const STRATEGY_ORDER_TYPES = [\n 'twap',\n 'scale',\n 'chase',\n] as const satisfies readonly StrategyOrderType[];\n\n/**\n * Bounds on how many limit orders a scale placement may fan out into.\n *\n * A ladder needs at least two rungs to span a range at all; the upper bound\n * keeps a single placement from consuming a venue's per-account open-order\n * budget. Protocol-agnostic: a provider whose venue is stricter narrows this\n * further in its own validation.\n */\nexport const SCALE_ORDER_COUNT = { min: 2, max: 20 } as const;\n\n/**\n * Order types whose price field (`OrderParams.price`) is a real limit price the\n * exchange must honour, as opposed to a slippage cap derived from the market.\n */\nconst LIMIT_EXECUTION_ORDER_TYPES = [\n 'limit',\n 'stop_limit',\n 'take_profit_limit',\n] as const satisfies readonly OrderType[];\n\n/**\n * Order types that rest limit orders on the book, whatever decides their price.\n *\n * A superset of `LIMIT_EXECUTION_ORDER_TYPES`: a scale ladder and a chase both\n * rest limit orders, but they derive their own prices rather than taking one\n * from `OrderParams.price`, so they are limit *execution* without being\n * limit-*priced*. A TWAP is absent because its suborders cross the book.\n *\n * The distinction matters wherever execution is what is being charged or\n * bounded — fee tier, max order value — as opposed to where the caller's price\n * field is being read.\n */\nconst LIMIT_RESTING_ORDER_TYPES = [\n ...LIMIT_EXECUTION_ORDER_TYPES,\n 'scale',\n 'chase',\n] as const satisfies readonly OrderType[];\n\n/**\n * Check whether an order type is a trigger placement (stop / take profit).\n *\n * @param orderType - Order type to check.\n * @returns True when the type requires `OrderParams.triggerPrice`.\n */\nexport function isTriggerOrderType(\n orderType: OrderType,\n): orderType is TriggerOrderType {\n return (TRIGGER_ORDER_TYPES as readonly OrderType[]).includes(orderType);\n}\n\n/**\n * Check whether an order type is a strategy placement (TWAP / scale / chase).\n *\n * @param orderType - Order type to check.\n * @returns True when the placement expands into an execution schedule rather\n * than a single order.\n */\nexport function isStrategyOrderType(\n orderType: OrderType,\n): orderType is StrategyOrderType {\n return (STRATEGY_ORDER_TYPES as readonly OrderType[]).includes(orderType);\n}\n\n/**\n * Check whether an order type executes as a limit order.\n *\n * Covers plain limit orders and the `*_limit` trigger types, both of which\n * require `OrderParams.price`.\n *\n * @param orderType - Order type to check.\n * @returns True when the order executes as a limit order.\n */\nexport function isLimitExecutionOrderType(orderType: OrderType): boolean {\n return (LIMIT_EXECUTION_ORDER_TYPES as readonly OrderType[]).includes(\n orderType,\n );\n}\n\n/**\n * Get how an order executes, ignoring whether it is trigger-gated.\n *\n * This is also the coarse execution type that consumers predating trigger orders\n * understand (fee tiers, max order value, analytics). It answers \"does this rest\n * on the book or cross it\", which is not the same question as\n * `isLimitExecutionOrderType` — a scale ladder and a chase rest limit orders\n * without carrying an `OrderParams.price`.\n *\n * @param orderType - Order type to inspect.\n * @returns `'limit'` for limit, `*_limit`, `scale` and `chase`; `'market'`\n * otherwise, including `twap`, whose suborders cross the book.\n */\nexport function getTriggerExecution(orderType: OrderType): OrderExecution {\n return (LIMIT_RESTING_ORDER_TYPES as readonly OrderType[]).includes(orderType)\n ? 'limit'\n : 'market';\n}\n\n/**\n * Get the direction a trigger order fires in.\n *\n * @param orderType - Trigger order type.\n * @returns `'stop'` for `stop_*`, `'take_profit'` for `take_profit_*`.\n */\nexport function getTriggerDirection(\n orderType: TriggerOrderType,\n): TriggerDirection {\n return orderType === 'stop_market' || orderType === 'stop_limit'\n ? 'stop'\n : 'take_profit';\n}\n\n/**\n * Recover which way a trigger fires from its price relative to the entry.\n *\n * Used when the exchange reports a trigger without naming its placement type:\n * a long takes profit above its entry and stops out below, a short the other\n * way round. Shared by both transports so they classify identically.\n *\n * @param params - Classification parameters\n * @param params.triggerPrice - Price at which the order activates\n * @param params.entryPrice - Entry price of the position it is attached to\n * @param params.positionSize - Signed position size; its sign gives the side\n * @returns The direction, or undefined when there is nothing to compare against\n */\nexport function classifyTriggerDirection(params: {\n triggerPrice?: string;\n entryPrice?: string;\n positionSize: string;\n}): TriggerDirection | undefined {\n const { triggerPrice, entryPrice, positionSize } = params;\n\n const trigger = parseFloat(triggerPrice ?? '');\n const entry = parseFloat(entryPrice ?? '');\n const signedSize = parseFloat(positionSize || '0');\n\n if (!Number.isFinite(trigger) || !Number.isFinite(entry) || entry <= 0) {\n return undefined;\n }\n\n // A long takes profit above its entry and stops out below; a short is the\n // mirror image. A trigger sitting exactly at entry is neither, so both sides\n // fall to 'stop' — matching the legacy price fallback the scalar\n // takeProfitPrice/stopLossPrice fields still use. Splitting that tie the\n // other way would file the order under takeProfitOrders while the scalar\n // still reported it as a stop.\n const isLong = signedSize > 0;\n\n if (isLong) {\n return trigger > entry ? 'take_profit' : 'stop';\n }\n return trigger < entry ? 'take_profit' : 'stop';\n}\n\n/**\n * Project a normalized open order onto the position-state view of a trigger order.\n *\n * Returns undefined when the order is not a trigger, or when its direction can\n * be established neither from a named placement type nor from its price.\n *\n * @param params - Mapping parameters\n * @param params.order - Normalized open order\n * @param params.positionSize - Size of the position the trigger is attached to\n * @param params.entryPrice - Entry price, used to classify an unnamed trigger\n * @returns The position trigger order, or undefined\n */\nexport function buildPositionTriggerOrderFromOrder(params: {\n order: Order;\n positionSize: string;\n entryPrice?: string;\n}): PositionTriggerOrder | undefined {\n const { order, positionSize, entryPrice } = params;\n\n if (!order.isTrigger) {\n return undefined;\n }\n\n // HyperLiquid sometimes reports a bare 'Trigger', naming neither direction\n // nor execution. The direction is still recoverable from the trigger price\n // against the entry, and it is what decides which array the order belongs\n // to — so an unnamed trigger is kept rather than dropped, with its execution\n // mode left unstated. Without a position to compare against there is nothing\n // to recover, and it is dropped.\n const direction =\n order.triggerOrderType === undefined\n ? classifyTriggerDirection({\n triggerPrice: order.triggerPrice ?? order.price,\n entryPrice,\n positionSize,\n })\n : getTriggerDirection(order.triggerOrderType);\n\n if (!direction) {\n return undefined;\n }\n\n const absolutePositionSize = Math.abs(parseFloat(positionSize || '0'));\n const rawSize = Math.abs(parseFloat(order.size || '0'));\n\n // A position-bound TP/SL covers whatever the position currently is. The\n // exchange encodes that as size 0, but `adaptOrderFromSDK` has already\n // resolved it against the position as it stood when the order was adapted,\n // so the size carried here goes stale as soon as the position is resized.\n // The flag is the durable statement of what the trigger covers; the number\n // is not. Reading the number instead would report the old size, and would\n // call the order partial whenever the position had since grown.\n const isPositionBound = order.isPositionTpsl === true;\n const size =\n isPositionBound || rawSize === 0 ? absolutePositionSize : rawSize;\n\n return {\n orderId: order.orderId,\n direction,\n orderType: order.triggerOrderType,\n triggerPrice: order.triggerPrice ?? order.price,\n size: size.toString(),\n isPartial:\n !isPositionBound &&\n rawSize > 0 &&\n absolutePositionSize > 0 &&\n rawSize < absolutePositionSize,\n reduceOnly: Boolean(order.reduceOnly),\n };\n}\n\n/**\n * Build a trigger order type from its two independent dimensions.\n *\n * @param params - Trigger dimensions.\n * @param params.direction - Whether the trigger is a stop or a take profit.\n * @param params.execution - How the order executes once triggered.\n * @returns The matching trigger order type.\n */\nexport function buildTriggerOrderType(params: {\n direction: TriggerDirection;\n execution: OrderExecution;\n}): TriggerOrderType {\n const { direction, execution } = params;\n\n if (direction === 'stop') {\n return execution === 'limit' ? 'stop_limit' : 'stop_market';\n }\n\n return execution === 'limit' ? 'take_profit_limit' : 'take_profit_market';\n}\n\n/**\n * Map the controller's time in force onto the exchange's spelling.\n *\n * Shared by the two order-building paths so they cannot drift apart.\n *\n * @param timeInForce - Requested time in force; defaults to GTC.\n * @returns The SDK time-in-force value.\n */\nexport function toSDKTimeInForce(\n timeInForce?: 'GTC' | 'IOC' | 'ALO',\n): 'Gtc' | 'Ioc' | 'Alo' {\n switch (timeInForce) {\n case 'IOC':\n return 'Ioc';\n case 'ALO':\n return 'Alo';\n default:\n return 'Gtc';\n }\n}\n\n/**\n * Hash the identity of a position's trigger orders for change detection.\n *\n * Streamed positions only re-emit when their hash changes, so this has to move\n * when a trigger is added, removed, repriced, resized, or retyped — otherwise\n * subscribers never receive the updated arrays.\n *\n * The placement type is part of the identity because a trigger can be modified\n * in place: switching a stop from market to limit execution keeps its order ID,\n * trigger price, and size, so nothing else here would move even though the\n * execution semantics subscribers rely on have changed.\n *\n * @param orders - Trigger orders attached to a position, if any.\n * @returns A stable string; `'0'` for both empty and absent.\n */\nexport function hashTriggerOrders(orders?: PositionTriggerOrder[]): string {\n if (!orders || orders.length === 0) {\n return '0';\n }\n return orders\n .map(\n (order) =>\n `${order.orderId}:${order.direction}:${order.orderType ?? '?'}@${order.triggerPrice}x${order.size}${order.isPartial ? 'p' : ''}`,\n )\n .join(',');\n}\n"]}
1
+ {"version":3,"file":"orderTypes.mjs","sourceRoot":"","sources":["../../src/utils/orderTypes.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,aAAa;IACb,YAAY;IACZ,oBAAoB;IACpB,mBAAmB;CAC2B,CAAC;AAEjD;;;GAGG;AACH,MAAM,2BAA2B,GAAG;IAClC,OAAO;IACP,YAAY;IACZ,mBAAmB;CACoB,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAoB;IAEpB,OAAQ,mBAA4C,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;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,CAAC,SAAS,IAAI,GAAG,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACnI;SACA,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["import type { Order, PositionTriggerOrder } from '../types/index.js';\nimport type {\n OrderExecution,\n OrderType,\n TriggerDirection,\n TriggerOrderType,\n} from '../types/perps-types.js';\n\n/**\n * All trigger placement types, in a stable order suitable for iteration\n * (validation tables, e2e matrices).\n */\nexport const TRIGGER_ORDER_TYPES = [\n 'stop_market',\n 'stop_limit',\n 'take_profit_market',\n 'take_profit_limit',\n] as const satisfies readonly TriggerOrderType[];\n\n/**\n * Order types whose price field (`OrderParams.price`) is a real limit price the\n * exchange must honour, as opposed to a slippage cap derived from the market.\n */\nconst LIMIT_EXECUTION_ORDER_TYPES = [\n 'limit',\n 'stop_limit',\n 'take_profit_limit',\n] as const satisfies readonly OrderType[];\n\n/**\n * Check whether an order type is a trigger placement (stop / take profit).\n *\n * @param orderType - Order type to check.\n * @returns True when the type requires `OrderParams.triggerPrice`.\n */\nexport function isTriggerOrderType(\n orderType: OrderType,\n): orderType is TriggerOrderType {\n return (TRIGGER_ORDER_TYPES as readonly OrderType[]).includes(orderType);\n}\n\n/**\n * Check whether an order type executes as a limit order.\n *\n * Covers plain limit orders and the `*_limit` trigger types, both of which\n * require `OrderParams.price`.\n *\n * @param orderType - Order type to check.\n * @returns True when the order executes as a limit order.\n */\nexport function isLimitExecutionOrderType(orderType: OrderType): boolean {\n return (LIMIT_EXECUTION_ORDER_TYPES as readonly OrderType[]).includes(\n orderType,\n );\n}\n\n/**\n * Get how an order executes, ignoring whether it is trigger-gated.\n *\n * This is also the coarse execution type that consumers predating trigger orders\n * understand (fee tiers, max order value, analytics).\n *\n * @param orderType - Order type to inspect.\n * @returns `'limit'` for limit and `*_limit` types, `'market'` otherwise.\n */\nexport function getTriggerExecution(orderType: OrderType): OrderExecution {\n return isLimitExecutionOrderType(orderType) ? 'limit' : 'market';\n}\n\n/**\n * Get the direction a trigger order fires in.\n *\n * @param orderType - Trigger order type.\n * @returns `'stop'` for `stop_*`, `'take_profit'` for `take_profit_*`.\n */\nexport function getTriggerDirection(\n orderType: TriggerOrderType,\n): TriggerDirection {\n return orderType === 'stop_market' || orderType === 'stop_limit'\n ? 'stop'\n : 'take_profit';\n}\n\n/**\n * Recover which way a trigger fires from its price relative to the entry.\n *\n * Used when the exchange reports a trigger without naming its placement type:\n * a long takes profit above its entry and stops out below, a short the other\n * way round. Shared by both transports so they classify identically.\n *\n * @param params - Classification parameters\n * @param params.triggerPrice - Price at which the order activates\n * @param params.entryPrice - Entry price of the position it is attached to\n * @param params.positionSize - Signed position size; its sign gives the side\n * @returns The direction, or undefined when there is nothing to compare against\n */\nexport function classifyTriggerDirection(params: {\n triggerPrice?: string;\n entryPrice?: string;\n positionSize: string;\n}): TriggerDirection | undefined {\n const { triggerPrice, entryPrice, positionSize } = params;\n\n const trigger = parseFloat(triggerPrice ?? '');\n const entry = parseFloat(entryPrice ?? '');\n const signedSize = parseFloat(positionSize || '0');\n\n if (!Number.isFinite(trigger) || !Number.isFinite(entry) || entry <= 0) {\n return undefined;\n }\n\n // A long takes profit above its entry and stops out below; a short is the\n // mirror image. A trigger sitting exactly at entry is neither, so both sides\n // fall to 'stop' — matching the legacy price fallback the scalar\n // takeProfitPrice/stopLossPrice fields still use. Splitting that tie the\n // other way would file the order under takeProfitOrders while the scalar\n // still reported it as a stop.\n const isLong = signedSize > 0;\n\n if (isLong) {\n return trigger > entry ? 'take_profit' : 'stop';\n }\n return trigger < entry ? 'take_profit' : 'stop';\n}\n\n/**\n * Project a normalized open order onto the position-state view of a trigger order.\n *\n * Returns undefined when the order is not a trigger, or when its direction can\n * be established neither from a named placement type nor from its price.\n *\n * @param params - Mapping parameters\n * @param params.order - Normalized open order\n * @param params.positionSize - Size of the position the trigger is attached to\n * @param params.entryPrice - Entry price, used to classify an unnamed trigger\n * @returns The position trigger order, or undefined\n */\nexport function buildPositionTriggerOrderFromOrder(params: {\n order: Order;\n positionSize: string;\n entryPrice?: string;\n}): PositionTriggerOrder | undefined {\n const { order, positionSize, entryPrice } = params;\n\n if (!order.isTrigger) {\n return undefined;\n }\n\n // HyperLiquid sometimes reports a bare 'Trigger', naming neither direction\n // nor execution. The direction is still recoverable from the trigger price\n // against the entry, and it is what decides which array the order belongs\n // to — so an unnamed trigger is kept rather than dropped, with its execution\n // mode left unstated. Without a position to compare against there is nothing\n // to recover, and it is dropped.\n const direction =\n order.triggerOrderType === undefined\n ? classifyTriggerDirection({\n triggerPrice: order.triggerPrice ?? order.price,\n entryPrice,\n positionSize,\n })\n : getTriggerDirection(order.triggerOrderType);\n\n if (!direction) {\n return undefined;\n }\n\n const absolutePositionSize = Math.abs(parseFloat(positionSize || '0'));\n const rawSize = Math.abs(parseFloat(order.size || '0'));\n\n // A position-bound TP/SL covers whatever the position currently is. The\n // exchange encodes that as size 0, but `adaptOrderFromSDK` has already\n // resolved it against the position as it stood when the order was adapted,\n // so the size carried here goes stale as soon as the position is resized.\n // The flag is the durable statement of what the trigger covers; the number\n // is not. Reading the number instead would report the old size, and would\n // call the order partial whenever the position had since grown.\n const isPositionBound = order.isPositionTpsl === true;\n const size =\n isPositionBound || rawSize === 0 ? absolutePositionSize : rawSize;\n\n return {\n orderId: order.orderId,\n direction,\n orderType: order.triggerOrderType,\n triggerPrice: order.triggerPrice ?? order.price,\n size: size.toString(),\n isPartial:\n !isPositionBound &&\n rawSize > 0 &&\n absolutePositionSize > 0 &&\n rawSize < absolutePositionSize,\n reduceOnly: Boolean(order.reduceOnly),\n };\n}\n\n/**\n * Build a trigger order type from its two independent dimensions.\n *\n * @param params - Trigger dimensions.\n * @param params.direction - Whether the trigger is a stop or a take profit.\n * @param params.execution - How the order executes once triggered.\n * @returns The matching trigger order type.\n */\nexport function buildTriggerOrderType(params: {\n direction: TriggerDirection;\n execution: OrderExecution;\n}): TriggerOrderType {\n const { direction, execution } = params;\n\n if (direction === 'stop') {\n return execution === 'limit' ? 'stop_limit' : 'stop_market';\n }\n\n return execution === 'limit' ? 'take_profit_limit' : 'take_profit_market';\n}\n\n/**\n * Map the controller's time in force onto the exchange's spelling.\n *\n * Shared by the two order-building paths so they cannot drift apart.\n *\n * @param timeInForce - Requested time in force; defaults to GTC.\n * @returns The SDK time-in-force value.\n */\nexport function toSDKTimeInForce(\n timeInForce?: 'GTC' | 'IOC' | 'ALO',\n): 'Gtc' | 'Ioc' | 'Alo' {\n switch (timeInForce) {\n case 'IOC':\n return 'Ioc';\n case 'ALO':\n return 'Alo';\n default:\n return 'Gtc';\n }\n}\n\n/**\n * Hash the identity of a position's trigger orders for change detection.\n *\n * Streamed positions only re-emit when their hash changes, so this has to move\n * when a trigger is added, removed, repriced, resized, or retyped — otherwise\n * subscribers never receive the updated arrays.\n *\n * The placement type is part of the identity because a trigger can be modified\n * in place: switching a stop from market to limit execution keeps its order ID,\n * trigger price, and size, so nothing else here would move even though the\n * execution semantics subscribers rely on have changed.\n *\n * @param orders - Trigger orders attached to a position, if any.\n * @returns A stable string; `'0'` for both empty and absent.\n */\nexport function hashTriggerOrders(orders?: PositionTriggerOrder[]): string {\n if (!orders || orders.length === 0) {\n return '0';\n }\n return orders\n .map(\n (order) =>\n `${order.orderId}:${order.direction}:${order.orderType ?? '?'}@${order.triggerPrice}x${order.size}${order.isPartial ? 'p' : ''}`,\n )\n .join(',');\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/perps-controller",
3
- "version": "11.0.0-preview-9c0f91815",
3
+ "version": "11.0.0-preview-e57e5c3dc",
4
4
  "description": "Controller for perpetual trading functionality in MetaMask",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -119,7 +119,7 @@
119
119
  "@metamask/network-controller": "^35.0.1",
120
120
  "@metamask/profile-sync-controller": "^29.0.0",
121
121
  "@metamask/remote-feature-flag-controller": "^5.0.0",
122
- "@metamask/transaction-controller": "^69.5.2",
122
+ "@metamask/transaction-controller": "^69.5.0",
123
123
  "@ts-bridge/cli": "^0.6.4",
124
124
  "@types/jest": "^30.0.0",
125
125
  "@types/uuid": "^8.3.0",