@metamask-previews/perps-controller 11.0.0-preview-9efd0b754 → 12.0.0-preview-4e64b66e8
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/CHANGELOG.md +30 -1
- package/dist/PerpsController-method-action-types.cjs.map +1 -1
- package/dist/PerpsController-method-action-types.d.cts +36 -1
- package/dist/PerpsController-method-action-types.d.cts.map +1 -1
- package/dist/PerpsController-method-action-types.d.mts +36 -1
- package/dist/PerpsController-method-action-types.d.mts.map +1 -1
- package/dist/PerpsController-method-action-types.mjs.map +1 -1
- package/dist/PerpsController.cjs +600 -119
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts +35 -4
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts +35 -4
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +603 -122
- package/dist/PerpsController.mjs.map +1 -1
- package/dist/constants/eventNames.cjs +3 -0
- package/dist/constants/eventNames.cjs.map +1 -1
- package/dist/constants/eventNames.d.cts +1 -0
- package/dist/constants/eventNames.d.cts.map +1 -1
- package/dist/constants/eventNames.d.mts +1 -0
- package/dist/constants/eventNames.d.mts.map +1 -1
- package/dist/constants/eventNames.mjs +3 -0
- package/dist/constants/eventNames.mjs.map +1 -1
- package/dist/constants/hyperLiquidConfig.cjs +14 -2
- package/dist/constants/hyperLiquidConfig.cjs.map +1 -1
- package/dist/constants/hyperLiquidConfig.d.cts +7 -0
- package/dist/constants/hyperLiquidConfig.d.cts.map +1 -1
- package/dist/constants/hyperLiquidConfig.d.mts +7 -0
- package/dist/constants/hyperLiquidConfig.d.mts.map +1 -1
- package/dist/constants/hyperLiquidConfig.mjs +11 -0
- package/dist/constants/hyperLiquidConfig.mjs.map +1 -1
- package/dist/constants/perpsConfig.cjs +19 -2
- package/dist/constants/perpsConfig.cjs.map +1 -1
- package/dist/constants/perpsConfig.d.cts +39 -7
- package/dist/constants/perpsConfig.d.cts.map +1 -1
- package/dist/constants/perpsConfig.d.mts +39 -7
- package/dist/constants/perpsConfig.d.mts.map +1 -1
- package/dist/constants/perpsConfig.mjs +18 -1
- package/dist/constants/perpsConfig.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.cjs +16 -0
- package/dist/providers/AggregatedPerpsProvider.cjs.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts +3 -1
- package/dist/providers/AggregatedPerpsProvider.d.cts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts +3 -1
- package/dist/providers/AggregatedPerpsProvider.d.mts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.mjs +16 -0
- package/dist/providers/AggregatedPerpsProvider.mjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.cjs +325 -59
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts +27 -1
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts +27 -1
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +326 -60
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/services/HyperLiquidClientService.cjs +74 -25
- package/dist/services/HyperLiquidClientService.cjs.map +1 -1
- package/dist/services/HyperLiquidClientService.d.cts.map +1 -1
- package/dist/services/HyperLiquidClientService.d.mts.map +1 -1
- package/dist/services/HyperLiquidClientService.mjs +74 -25
- package/dist/services/HyperLiquidClientService.mjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.cjs +16 -5
- package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.mjs +16 -5
- package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -1
- package/dist/services/MarketDataService.cjs +49 -5
- package/dist/services/MarketDataService.cjs.map +1 -1
- package/dist/services/MarketDataService.d.cts +2 -2
- package/dist/services/MarketDataService.d.cts.map +1 -1
- package/dist/services/MarketDataService.d.mts +2 -2
- package/dist/services/MarketDataService.d.mts.map +1 -1
- package/dist/services/MarketDataService.mjs +49 -5
- package/dist/services/MarketDataService.mjs.map +1 -1
- package/dist/services/RewardsIntegrationService.cjs +330 -68
- package/dist/services/RewardsIntegrationService.cjs.map +1 -1
- package/dist/services/RewardsIntegrationService.d.cts +61 -5
- package/dist/services/RewardsIntegrationService.d.cts.map +1 -1
- package/dist/services/RewardsIntegrationService.d.mts +61 -5
- package/dist/services/RewardsIntegrationService.d.mts.map +1 -1
- package/dist/services/RewardsIntegrationService.mjs +330 -68
- package/dist/services/RewardsIntegrationService.mjs.map +1 -1
- package/dist/services/ServiceContext.cjs.map +1 -1
- package/dist/services/ServiceContext.d.cts +17 -1
- package/dist/services/ServiceContext.d.cts.map +1 -1
- package/dist/services/ServiceContext.d.mts +17 -1
- package/dist/services/ServiceContext.d.mts.map +1 -1
- package/dist/services/ServiceContext.mjs.map +1 -1
- package/dist/services/TerminalMarketService.cjs +422 -7
- package/dist/services/TerminalMarketService.cjs.map +1 -1
- package/dist/services/TerminalMarketService.d.cts +10 -1
- package/dist/services/TerminalMarketService.d.cts.map +1 -1
- package/dist/services/TerminalMarketService.d.mts +10 -1
- package/dist/services/TerminalMarketService.d.mts.map +1 -1
- package/dist/services/TerminalMarketService.mjs +423 -8
- package/dist/services/TerminalMarketService.mjs.map +1 -1
- package/dist/services/TradingService.cjs +52 -28
- package/dist/services/TradingService.cjs.map +1 -1
- package/dist/services/TradingService.d.cts.map +1 -1
- package/dist/services/TradingService.d.mts.map +1 -1
- package/dist/services/TradingService.mjs +52 -28
- package/dist/services/TradingService.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +156 -7
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +156 -7
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/marketUtils.cjs +16 -1
- package/dist/utils/marketUtils.cjs.map +1 -1
- package/dist/utils/marketUtils.d.cts +1 -0
- package/dist/utils/marketUtils.d.cts.map +1 -1
- package/dist/utils/marketUtils.d.mts +1 -0
- package/dist/utils/marketUtils.d.mts.map +1 -1
- package/dist/utils/marketUtils.mjs +14 -0
- package/dist/utils/marketUtils.mjs.map +1 -1
- package/dist/utils/perpsDiskPersistence.cjs +19 -12
- package/dist/utils/perpsDiskPersistence.cjs.map +1 -1
- package/dist/utils/perpsDiskPersistence.d.cts +5 -1
- package/dist/utils/perpsDiskPersistence.d.cts.map +1 -1
- package/dist/utils/perpsDiskPersistence.d.mts +5 -1
- package/dist/utils/perpsDiskPersistence.d.mts.map +1 -1
- package/dist/utils/perpsDiskPersistence.mjs +19 -12
- package/dist/utils/perpsDiskPersistence.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _TradingService_instances, _TradingService_deps, _TradingService_controllerDeps, _TradingService_getErrorContext, _TradingService_buildAttributionProperties, _TradingService_trackSubmitted, _TradingService_trackOrderResult, _TradingService_handleOrderSuccess, _TradingService_withFeeDiscount, _TradingService_loadPositionData, _TradingService_calculateCloseMetrics, _TradingService_buildCloseEventProperties, _TradingService_trackPositionCloseResult, _TradingService_handleDataLakeReporting, _TradingService_calculateFeeDiscountWithMeasurement;
|
|
13
|
+
var _TradingService_instances, _TradingService_deps, _TradingService_controllerDeps, _TradingService_feeContextTail, _TradingService_getErrorContext, _TradingService_buildAttributionProperties, _TradingService_trackSubmitted, _TradingService_trackOrderResult, _TradingService_handleOrderSuccess, _TradingService_withFeeDiscount, _TradingService_loadPositionData, _TradingService_calculateCloseMetrics, _TradingService_buildCloseEventProperties, _TradingService_trackPositionCloseResult, _TradingService_handleDataLakeReporting, _TradingService_calculateFeeDiscountWithMeasurement;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.TradingService = void 0;
|
|
16
16
|
const bignumber_js_1 = require("bignumber.js");
|
|
@@ -49,6 +49,8 @@ class TradingService {
|
|
|
49
49
|
* Set via setControllerDependencies() after construction.
|
|
50
50
|
*/
|
|
51
51
|
_TradingService_controllerDeps.set(this, null);
|
|
52
|
+
/** Serializes provider fee context so concurrent orders cannot share it. */
|
|
53
|
+
_TradingService_feeContextTail.set(this, Promise.resolve());
|
|
52
54
|
__classPrivateFieldSet(this, _TradingService_deps, deps, "f");
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
@@ -112,10 +114,11 @@ class TradingService {
|
|
|
112
114
|
},
|
|
113
115
|
});
|
|
114
116
|
// Calculate fee discount at execution time (fresh, secure)
|
|
115
|
-
const
|
|
116
|
-
__classPrivateFieldGet(this, _TradingService_deps, "f").debugLogger.log('TradingService: Fee
|
|
117
|
-
feeDiscountBips,
|
|
118
|
-
|
|
117
|
+
const feeResolution = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_calculateFeeDiscountWithMeasurement).call(this);
|
|
118
|
+
__classPrivateFieldGet(this, _TradingService_deps, "f").debugLogger.log('TradingService: Fee resolution calculated', {
|
|
119
|
+
feeDiscountBips: feeResolution?.discountBips,
|
|
120
|
+
feeSource: feeResolution?.source,
|
|
121
|
+
hasDiscount: feeResolution?.discountBips !== undefined,
|
|
119
122
|
});
|
|
120
123
|
__classPrivateFieldGet(this, _TradingService_deps, "f").debugLogger.log('TradingService: Submitting order to provider', {
|
|
121
124
|
symbol: params.symbol,
|
|
@@ -165,7 +168,7 @@ class TradingService {
|
|
|
165
168
|
}, perpsConfig_js_1.PERPS_CONSTANTS.PlaceOrderTimeoutMs);
|
|
166
169
|
const result = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_withFeeDiscount).call(this, {
|
|
167
170
|
provider,
|
|
168
|
-
|
|
171
|
+
feeResolution,
|
|
169
172
|
operation: () => provider.placeOrder(params),
|
|
170
173
|
});
|
|
171
174
|
if (orderSubmissionThresholdTimeoutId !== undefined) {
|
|
@@ -292,11 +295,11 @@ class TradingService {
|
|
|
292
295
|
},
|
|
293
296
|
});
|
|
294
297
|
// Calculate fee discount only if required dependencies are available
|
|
295
|
-
const
|
|
298
|
+
const feeResolution = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_calculateFeeDiscountWithMeasurement).call(this);
|
|
296
299
|
// Execute order edit with fee discount management
|
|
297
300
|
const result = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_withFeeDiscount).call(this, {
|
|
298
301
|
provider,
|
|
299
|
-
|
|
302
|
+
feeResolution,
|
|
300
303
|
operation: () => provider.editOrder(params),
|
|
301
304
|
});
|
|
302
305
|
const completionDuration = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now() - startTime;
|
|
@@ -686,11 +689,11 @@ class TradingService {
|
|
|
686
689
|
}),
|
|
687
690
|
});
|
|
688
691
|
// Calculate fee discount with measurement
|
|
689
|
-
const
|
|
692
|
+
const feeResolution = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_calculateFeeDiscountWithMeasurement).call(this);
|
|
690
693
|
// Execute position close with fee discount management
|
|
691
694
|
result = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_withFeeDiscount).call(this, {
|
|
692
695
|
provider,
|
|
693
|
-
|
|
696
|
+
feeResolution,
|
|
694
697
|
operation: () => provider.closePosition(params),
|
|
695
698
|
});
|
|
696
699
|
const completionDuration = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now() - startTime;
|
|
@@ -807,10 +810,10 @@ class TradingService {
|
|
|
807
810
|
});
|
|
808
811
|
// Use batch close if provider supports it (provider handles filtering)
|
|
809
812
|
if (provider.closePositions) {
|
|
810
|
-
const
|
|
813
|
+
const feeResolution = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_calculateFeeDiscountWithMeasurement).call(this);
|
|
811
814
|
operationResult = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_withFeeDiscount).call(this, {
|
|
812
815
|
provider,
|
|
813
|
-
|
|
816
|
+
feeResolution,
|
|
814
817
|
operation: async () => {
|
|
815
818
|
if (!provider.closePositions) {
|
|
816
819
|
throw new Error('closePositions method not available');
|
|
@@ -970,11 +973,11 @@ class TradingService {
|
|
|
970
973
|
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, params.trackingData),
|
|
971
974
|
});
|
|
972
975
|
// Get fee discount from rewards
|
|
973
|
-
const
|
|
976
|
+
const feeResolution = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_calculateFeeDiscountWithMeasurement).call(this);
|
|
974
977
|
// Execute with fee discount management
|
|
975
978
|
result = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_withFeeDiscount).call(this, {
|
|
976
979
|
provider,
|
|
977
|
-
|
|
980
|
+
feeResolution,
|
|
978
981
|
operation: () => provider.updatePositionTPSL(params),
|
|
979
982
|
});
|
|
980
983
|
if (result.success) {
|
|
@@ -1221,8 +1224,13 @@ class TradingService {
|
|
|
1221
1224
|
[eventNames_js_1.PERPS_EVENT_PROPERTY.ACTION]: flipAction,
|
|
1222
1225
|
...__classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_buildAttributionProperties).call(this, trackingData),
|
|
1223
1226
|
});
|
|
1227
|
+
const feeResolution = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_calculateFeeDiscountWithMeasurement).call(this);
|
|
1224
1228
|
// Place flip order (HyperLiquid handles margin transfer automatically)
|
|
1225
|
-
const result = await
|
|
1229
|
+
const result = await __classPrivateFieldGet(this, _TradingService_instances, "m", _TradingService_withFeeDiscount).call(this, {
|
|
1230
|
+
provider,
|
|
1231
|
+
feeResolution,
|
|
1232
|
+
operation: () => provider.placeOrder(orderParams),
|
|
1233
|
+
});
|
|
1226
1234
|
const completionDuration = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now() - startTime;
|
|
1227
1235
|
const executedPrice = parseFloat(result.averagePrice ?? position.entryPrice);
|
|
1228
1236
|
if (result.success) {
|
|
@@ -1319,7 +1327,7 @@ class TradingService {
|
|
|
1319
1327
|
}
|
|
1320
1328
|
}
|
|
1321
1329
|
exports.TradingService = TradingService;
|
|
1322
|
-
_TradingService_deps = new WeakMap(), _TradingService_controllerDeps = new WeakMap(), _TradingService_instances = new WeakSet(), _TradingService_getErrorContext = function _TradingService_getErrorContext(method, additionalContext) {
|
|
1330
|
+
_TradingService_deps = new WeakMap(), _TradingService_controllerDeps = new WeakMap(), _TradingService_feeContextTail = new WeakMap(), _TradingService_instances = new WeakSet(), _TradingService_getErrorContext = function _TradingService_getErrorContext(method, additionalContext) {
|
|
1323
1331
|
return {
|
|
1324
1332
|
controller: 'TradingService',
|
|
1325
1333
|
method,
|
|
@@ -1554,18 +1562,29 @@ async function _TradingService_handleOrderSuccess(options) {
|
|
|
1554
1562
|
*
|
|
1555
1563
|
* @param options - The configuration options.
|
|
1556
1564
|
* @param options.provider - The perps provider instance.
|
|
1557
|
-
* @param options.
|
|
1565
|
+
* @param options.feeResolution - The resolved fee and attribution source.
|
|
1558
1566
|
* @param options.operation - The operation value.
|
|
1559
1567
|
* @returns The result of the operation.
|
|
1560
1568
|
*/
|
|
1561
1569
|
async function _TradingService_withFeeDiscount(options) {
|
|
1562
|
-
const { provider,
|
|
1570
|
+
const { provider, feeResolution, operation } = options;
|
|
1571
|
+
const previous = __classPrivateFieldGet(this, _TradingService_feeContextTail, "f");
|
|
1572
|
+
let release = () => undefined;
|
|
1573
|
+
__classPrivateFieldSet(this, _TradingService_feeContextTail, new Promise((resolve) => {
|
|
1574
|
+
release = resolve;
|
|
1575
|
+
}), "f");
|
|
1576
|
+
await previous;
|
|
1563
1577
|
try {
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1578
|
+
if (provider.setUserFeeResolution) {
|
|
1579
|
+
provider.setUserFeeResolution(feeResolution);
|
|
1580
|
+
}
|
|
1581
|
+
else if (provider.setUserFeeDiscount) {
|
|
1582
|
+
provider.setUserFeeDiscount(feeResolution?.discountBips);
|
|
1583
|
+
}
|
|
1584
|
+
if (feeResolution) {
|
|
1585
|
+
__classPrivateFieldGet(this, _TradingService_deps, "f").debugLogger.log('TradingService: Fee resolution set in provider', {
|
|
1586
|
+
feeDiscountBips: feeResolution.discountBips,
|
|
1587
|
+
feeSource: feeResolution.source,
|
|
1569
1588
|
});
|
|
1570
1589
|
}
|
|
1571
1590
|
// Execute the operation
|
|
@@ -1573,10 +1592,14 @@ async function _TradingService_withFeeDiscount(options) {
|
|
|
1573
1592
|
}
|
|
1574
1593
|
finally {
|
|
1575
1594
|
// Always clear discount context, even on exception
|
|
1576
|
-
if (provider.
|
|
1595
|
+
if (provider.setUserFeeResolution) {
|
|
1596
|
+
provider.setUserFeeResolution(undefined);
|
|
1597
|
+
}
|
|
1598
|
+
else if (provider.setUserFeeDiscount) {
|
|
1577
1599
|
provider.setUserFeeDiscount(undefined);
|
|
1578
|
-
__classPrivateFieldGet(this, _TradingService_deps, "f").debugLogger.log('TradingService: Fee discount cleared from provider');
|
|
1579
1600
|
}
|
|
1601
|
+
__classPrivateFieldGet(this, _TradingService_deps, "f").debugLogger.log('TradingService: Fee resolution cleared from provider');
|
|
1602
|
+
release();
|
|
1580
1603
|
}
|
|
1581
1604
|
}, _TradingService_loadPositionData =
|
|
1582
1605
|
/**
|
|
@@ -1828,14 +1851,15 @@ async function _TradingService_calculateFeeDiscountWithMeasurement() {
|
|
|
1828
1851
|
const { rewardsIntegrationService } = __classPrivateFieldGet(this, _TradingService_controllerDeps, "f");
|
|
1829
1852
|
const orderExecutionFeeDiscountStartTime = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now();
|
|
1830
1853
|
// Calculate fee discount using messenger pattern (service handles controller access internally)
|
|
1831
|
-
const
|
|
1854
|
+
const resolution = await rewardsIntegrationService.resolveFee();
|
|
1832
1855
|
const orderExecutionFeeDiscountDuration = __classPrivateFieldGet(this, _TradingService_deps, "f").performance.now() - orderExecutionFeeDiscountStartTime;
|
|
1833
1856
|
// Record measurement
|
|
1834
1857
|
__classPrivateFieldGet(this, _TradingService_deps, "f").tracer.setMeasurement(performanceMetrics_js_1.PerpsMeasurementName.PerpsRewardsOrderExecutionFeeDiscountApiCall, orderExecutionFeeDiscountDuration, 'millisecond');
|
|
1835
1858
|
__classPrivateFieldGet(this, _TradingService_deps, "f").debugLogger.log('TradingService: Fee discount API call completed', {
|
|
1836
|
-
discountBips,
|
|
1859
|
+
discountBips: resolution.discountBips,
|
|
1860
|
+
source: resolution.source,
|
|
1837
1861
|
duration: `${orderExecutionFeeDiscountDuration.toFixed(0)}ms`,
|
|
1838
1862
|
});
|
|
1839
|
-
return
|
|
1863
|
+
return resolution;
|
|
1840
1864
|
};
|
|
1841
1865
|
//# sourceMappingURL=TradingService.cjs.map
|