@metamask-previews/perps-controller 24.0.0-preview-8bb08c709 → 24.1.0-preview-8647f16
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 +38 -1
- package/dist/constants/perpsConfig.d.ts +9 -4
- package/dist/constants/perpsConfig.d.ts.map +1 -1
- package/dist/constants/perpsConfig.js +17 -4
- package/dist/constants/perpsConfig.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
- package/dist/providers/HyperLiquidProvider.js +9 -2
- package/dist/providers/HyperLiquidProvider.js.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.js +21 -9
- package/dist/services/HyperLiquidSubscriptionService.js.map +1 -1
- package/dist/types/index.d.ts +16 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/accountUtils.d.ts +36 -5
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +99 -15
- package/dist/utils/accountUtils.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/lighterAdapter.d.ts.map +1 -1
- package/dist/utils/lighterAdapter.js +8 -0
- package/dist/utils/lighterAdapter.js.map +1 -1
- package/dist/utils/marginAdjustment.d.ts +68 -0
- package/dist/utils/marginAdjustment.d.ts.map +1 -0
- package/dist/utils/marginAdjustment.js +83 -0
- package/dist/utils/marginAdjustment.js.map +1 -0
- package/dist/utils/perpsFormatters.d.ts +101 -4
- package/dist/utils/perpsFormatters.d.ts.map +1 -1
- package/dist/utils/perpsFormatters.js +216 -3
- package/dist/utils/perpsFormatters.js.map +1 -1
- package/dist/utils/tpslCalculations.d.ts +25 -0
- package/dist/utils/tpslCalculations.d.ts.map +1 -1
- package/dist/utils/tpslCalculations.js +15 -0
- package/dist/utils/tpslCalculations.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidSubscriptionService.d.ts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAMV,mBAAmB,EAEnB,sBAAsB,EAItB,gBAAgB,EAMjB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EAEV,0BAA0B,EAC3B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,SAAS,EACT,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,EAG1B,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"HyperLiquidSubscriptionService.d.ts","sourceRoot":"","sources":["../../src/services/HyperLiquidSubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAMV,mBAAmB,EAEnB,sBAAsB,EAItB,gBAAgB,EAMjB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,KAAK,EAEV,0BAA0B,EAC3B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,KAAK,EAEL,SAAS,EACT,qBAAqB,EACrB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EAGxB,yBAAyB,EAG1B,MAAM,mBAAmB,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G,QAAQ,EAAE,GAAG,IAAI,CAKlE;IAwBD;;;;OAIG;IACI,kBAAkB,IAAI,QAAQ,EAAE,GAAG,IAAI,CAE7C;IAED;;;;OAIG;IACI,eAAe,IAAI,KAAK,EAAE,GAAG,IAAI,CAEvC;IAED;;;;;OAKG;IACI,2BAA2B,IAAI,KAAK,EAAE,GAAG,IAAI,CAKnD;IAED;;;;;;OAMG;IACI,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAExD;IAEM,sBAAsB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAOzE;IAED;;;;;OAKG;IACI,cAAc,IAAI,SAAS,EAAE,GAAG,IAAI,CAE1C;IAED;;;;;;;;OAQG;IACI,0BAA0B,IAAI,SAAS,EAAE,GAAG,IAAI,CAKtD;IAilCD;;;;;;;OAOG;IACI,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG,MAAM,IAAI,CAiGxE;IAED;;;;;;;;;;;;;;;OAeG;IACI,0BAA0B,CAAC,MAAM,EAAE;QACxC,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,aAAa,CAAC;QAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;QACjD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;KAClC,GAAG,MAAM,IAAI,CAsJb;IAsJD;;;;;;OAMG;IACU,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAuQjD;IAED;;OAEG;IACI,QAAQ,IAAI,IAAI,CAsPtB;CACF"}
|
|
@@ -4,7 +4,7 @@ import { HYPERLIQUID_CONFIG } from '../constants/hyperLiquidConfig.js';
|
|
|
4
4
|
import { TP_SL_CONFIG, ABSTRACTION_MODE_REFRESH_THROTTLE_MS, } from '../constants/perpsConfig.js';
|
|
5
5
|
import { hyperLiquidModeFoldsSpot } from '../types/hyperliquid-types.js';
|
|
6
6
|
import { WebSocketConnectionState } from '../types/index.js';
|
|
7
|
-
import { addSpotBalanceToAccountState, aggregateAccountStates, calculateWeightedReturnOnEquity, } from '../utils/accountUtils.js';
|
|
7
|
+
import { addSpotBalanceToAccountState, aggregateAccountStates, calculateWeightedReturnOnEquity, getCrossMarginSpotCollateral, } from '../utils/accountUtils.js';
|
|
8
8
|
import { PERPS_ERROR_ACTION, PERPS_ERROR_COMPONENT, PERPS_ERROR_OPERATION, createPerpsErrorContext, } from '../utils/errorContext.js';
|
|
9
9
|
import { ensureError } from '../utils/errorUtils.js';
|
|
10
10
|
import { adaptPositionFromSDK, adaptOrderFromSDK, adaptAccountStateFromSDK, buildHyperLiquidFillId, parseAssetName, } from '../utils/hyperLiquidAdapter.js';
|
|
@@ -617,7 +617,11 @@ export class HyperLiquidSubscriptionService {
|
|
|
617
617
|
const summaryHash = summary
|
|
618
618
|
? `${summary.accountValue}:${summary.maintenanceMargin}:${summary.marginUsed}:${summary.notional}`
|
|
619
619
|
: 'none';
|
|
620
|
-
|
|
620
|
+
// spotCollateral is part of the published account. Unknown and Standard
|
|
621
|
+
// share the same balances, so leaving it out of the hash drops the
|
|
622
|
+
// notification that turns an unset value into '0'.
|
|
623
|
+
const spotCollateral = account.spotCollateral ?? '';
|
|
624
|
+
return `${account.spendableBalance}:${account.withdrawableBalance}:${account.totalBalance}:${account.marginUsed}:${account.unrealizedPnl}:${spotCollateral}:${summaryHash}`;
|
|
621
625
|
}
|
|
622
626
|
// Cache hashes to avoid recomputation
|
|
623
627
|
#cachedPositionsHash = '';
|
|
@@ -938,8 +942,10 @@ export class HyperLiquidSubscriptionService {
|
|
|
938
942
|
return this.#abstractionModeByUser.get(userAddress.toLowerCase()) ?? null;
|
|
939
943
|
}
|
|
940
944
|
#getSpotBalanceOptions() {
|
|
945
|
+
const abstractionMode = this.#getAbstractionModeForUser(this.#cachedSpotStateUserAddress);
|
|
941
946
|
return {
|
|
942
|
-
foldIntoCollateral: hyperLiquidModeFoldsSpot(
|
|
947
|
+
foldIntoCollateral: hyperLiquidModeFoldsSpot(abstractionMode),
|
|
948
|
+
abstractionMode,
|
|
943
949
|
};
|
|
944
950
|
}
|
|
945
951
|
/**
|
|
@@ -1002,14 +1008,20 @@ export class HyperLiquidSubscriptionService {
|
|
|
1002
1008
|
// ratchet the throttle window forward (which would silence every
|
|
1003
1009
|
// subsequent spot WS tick for the full throttle duration).
|
|
1004
1010
|
this.#abstractionModeLastWsRefreshAtByUser.set(normalizedUser, Date.now());
|
|
1005
|
-
//
|
|
1006
|
-
//
|
|
1007
|
-
//
|
|
1008
|
-
//
|
|
1009
|
-
//
|
|
1011
|
+
// Re-aggregate when the published account changes. The fold covers
|
|
1012
|
+
// spendable and withdrawable. Spot collateral also changes when an
|
|
1013
|
+
// unknown mode resolves to Standard: both fail closed to no-fold, so
|
|
1014
|
+
// a fold comparison never fires, and subscribers would keep an unset
|
|
1015
|
+
// spotCollateral until the next balance tick.
|
|
1016
|
+
const spotIsForUser = this.#cachedSpotState !== null &&
|
|
1017
|
+
this.#cachedSpotStateUserAddress === normalizedUser;
|
|
1018
|
+
const collateralChanged = spotIsForUser &&
|
|
1019
|
+
getCrossMarginSpotCollateral(this.#cachedSpotState, previousMode) !==
|
|
1020
|
+
getCrossMarginSpotCollateral(this.#cachedSpotState, mode);
|
|
1010
1021
|
const foldChanged = hyperLiquidModeFoldsSpot(previousMode) !==
|
|
1011
1022
|
hyperLiquidModeFoldsSpot(mode);
|
|
1012
|
-
if (foldChanged
|
|
1023
|
+
if ((foldChanged || collateralChanged) &&
|
|
1024
|
+
this.#dexAccountCache.size > 0) {
|
|
1013
1025
|
this.#aggregateAndNotifySubscribers();
|
|
1014
1026
|
}
|
|
1015
1027
|
}
|