@metamask-previews/perps-controller 24.0.0-preview-e92ccc12d → 24.0.0-preview-d94a14f45
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 +28 -0
- package/dist/PerpsController-method-action-types.d.ts +27 -1
- package/dist/PerpsController-method-action-types.d.ts.map +1 -1
- package/dist/PerpsController-method-action-types.js.map +1 -1
- package/dist/PerpsController.d.ts +22 -1
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +34 -0
- package/dist/PerpsController.js.map +1 -1
- package/dist/constants/lighterConfig.d.ts +27 -0
- package/dist/constants/lighterConfig.d.ts.map +1 -1
- package/dist/constants/lighterConfig.js +30 -0
- package/dist/constants/lighterConfig.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/LighterProvider.d.ts +20 -1
- package/dist/providers/LighterProvider.d.ts.map +1 -1
- package/dist/providers/LighterProvider.js +537 -56
- package/dist/providers/LighterProvider.js.map +1 -1
- package/dist/services/LighterClientService.d.ts +33 -0
- package/dist/services/LighterClientService.d.ts.map +1 -1
- package/dist/services/LighterClientService.js +175 -13
- package/dist/services/LighterClientService.js.map +1 -1
- package/dist/types/index.d.ts +41 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/providerHealth.d.ts +38 -0
- package/dist/utils/providerHealth.d.ts.map +1 -0
- package/dist/utils/providerHealth.js +91 -0
- package/dist/utils/providerHealth.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { WebSocketConnectionState } from '../types/index.js';
|
|
2
|
+
import type { PerpsProvider, PerpsProviderHealth, PerpsProviderType } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Health for a provider without its own health API, from its socket state:
|
|
5
|
+
* degraded while it is reconnecting after a drop, or disconnected after
|
|
6
|
+
* reconnect attempts. Disconnected at attempt 0 reads `unavailable`: the
|
|
7
|
+
* provider has not started or was disconnected on purpose. A failed first
|
|
8
|
+
* connect also ends there, as the state cannot tell it apart.
|
|
9
|
+
*
|
|
10
|
+
* @param providerId - Provider the state belongs to.
|
|
11
|
+
* @param connectionState - The provider's socket state.
|
|
12
|
+
* @param reconnectionAttempt - Reconnect attempts since its last open.
|
|
13
|
+
* @returns The derived health.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getHealthFromConnectionState: (providerId: PerpsProviderType, connectionState: WebSocketConnectionState, reconnectionAttempt: number) => PerpsProviderHealth;
|
|
16
|
+
/**
|
|
17
|
+
* The provider methods health is read from; all are optional.
|
|
18
|
+
*/
|
|
19
|
+
export type ProviderHealthSource = Pick<PerpsProvider, 'getProviderHealth' | 'subscribeToProviderHealth' | 'getWebSocketConnectionState' | 'subscribeToConnectionState'>;
|
|
20
|
+
/**
|
|
21
|
+
* Read one provider's health.
|
|
22
|
+
*
|
|
23
|
+
* @param providerId - Provider to report on.
|
|
24
|
+
* @param provider - The registered provider, if any.
|
|
25
|
+
* @returns Its own health, health derived from its socket state, or
|
|
26
|
+
* `unavailable` when it is not registered.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getProviderHealthOf: (providerId: PerpsProviderType, provider: ProviderHealthSource | undefined) => PerpsProviderHealth;
|
|
29
|
+
/**
|
|
30
|
+
* Watch one provider's health: the current value at once, then each change.
|
|
31
|
+
*
|
|
32
|
+
* @param providerId - Provider to watch.
|
|
33
|
+
* @param provider - The registered provider, if any.
|
|
34
|
+
* @param callback - Receives each health snapshot.
|
|
35
|
+
* @returns Cleanup function.
|
|
36
|
+
*/
|
|
37
|
+
export declare const subscribeToProviderHealthOf: (providerId: PerpsProviderType, provider: ProviderHealthSource | undefined, callback: (health: PerpsProviderHealth) => void) => (() => void);
|
|
38
|
+
//# sourceMappingURL=providerHealth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providerHealth.d.ts","sourceRoot":"","sources":["../../src/utils/providerHealth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,4BAA4B,eAC3B,iBAAiB,mBACZ,wBAAwB,uBACpB,MAAM,KAC1B,mBAqBF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,aAAa,EACX,mBAAmB,GACnB,2BAA2B,GAC3B,6BAA6B,GAC7B,4BAA4B,CAC/B,CAAC;AAaF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,eAClB,iBAAiB,YACnB,oBAAoB,GAAG,SAAS,KACzC,mBA2BF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,eAC1B,iBAAiB,YACnB,oBAAoB,GAAG,SAAS,YAChC,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,KAC9C,CAAC,MAAM,IAAI,CAWb,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { WebSocketConnectionState } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Health for a provider without its own health API, from its socket state:
|
|
4
|
+
* degraded while it is reconnecting after a drop, or disconnected after
|
|
5
|
+
* reconnect attempts. Disconnected at attempt 0 reads `unavailable`: the
|
|
6
|
+
* provider has not started or was disconnected on purpose. A failed first
|
|
7
|
+
* connect also ends there, as the state cannot tell it apart.
|
|
8
|
+
*
|
|
9
|
+
* @param providerId - Provider the state belongs to.
|
|
10
|
+
* @param connectionState - The provider's socket state.
|
|
11
|
+
* @param reconnectionAttempt - Reconnect attempts since its last open.
|
|
12
|
+
* @returns The derived health.
|
|
13
|
+
*/
|
|
14
|
+
export const getHealthFromConnectionState = (providerId, connectionState, reconnectionAttempt) => {
|
|
15
|
+
const isDown = connectionState !== WebSocketConnectionState.Connected &&
|
|
16
|
+
reconnectionAttempt > 0;
|
|
17
|
+
const isIdle = connectionState === WebSocketConnectionState.Disconnected &&
|
|
18
|
+
reconnectionAttempt === 0;
|
|
19
|
+
let status = 'healthy';
|
|
20
|
+
if (isDown) {
|
|
21
|
+
status = 'degraded';
|
|
22
|
+
}
|
|
23
|
+
else if (isIdle) {
|
|
24
|
+
status = 'unavailable';
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
providerId,
|
|
28
|
+
status,
|
|
29
|
+
reasons: isDown ? ['socket_down'] : [],
|
|
30
|
+
connectionState,
|
|
31
|
+
reconnectionAttempt,
|
|
32
|
+
updatedAt: Date.now(),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const getUnavailableHealth = (providerId) => ({
|
|
36
|
+
providerId,
|
|
37
|
+
status: 'unavailable',
|
|
38
|
+
reasons: [],
|
|
39
|
+
connectionState: WebSocketConnectionState.Disconnected,
|
|
40
|
+
reconnectionAttempt: 0,
|
|
41
|
+
updatedAt: Date.now(),
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Read one provider's health.
|
|
45
|
+
*
|
|
46
|
+
* @param providerId - Provider to report on.
|
|
47
|
+
* @param provider - The registered provider, if any.
|
|
48
|
+
* @returns Its own health, health derived from its socket state, or
|
|
49
|
+
* `unavailable` when it is not registered.
|
|
50
|
+
*/
|
|
51
|
+
export const getProviderHealthOf = (providerId, provider) => {
|
|
52
|
+
if (!provider) {
|
|
53
|
+
return getUnavailableHealth(providerId);
|
|
54
|
+
}
|
|
55
|
+
if (provider.getProviderHealth) {
|
|
56
|
+
return provider.getProviderHealth();
|
|
57
|
+
}
|
|
58
|
+
if (provider.subscribeToConnectionState) {
|
|
59
|
+
// Providers report their current state and reconnect attempt
|
|
60
|
+
// synchronously on subscribe; read that once.
|
|
61
|
+
let health;
|
|
62
|
+
const unsubscribe = provider.subscribeToConnectionState((state, attempt) => {
|
|
63
|
+
health ??= getHealthFromConnectionState(providerId, state, attempt);
|
|
64
|
+
});
|
|
65
|
+
unsubscribe();
|
|
66
|
+
if (health) {
|
|
67
|
+
return health;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return getHealthFromConnectionState(providerId, provider.getWebSocketConnectionState?.() ??
|
|
71
|
+
WebSocketConnectionState.Disconnected, 0);
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Watch one provider's health: the current value at once, then each change.
|
|
75
|
+
*
|
|
76
|
+
* @param providerId - Provider to watch.
|
|
77
|
+
* @param provider - The registered provider, if any.
|
|
78
|
+
* @param callback - Receives each health snapshot.
|
|
79
|
+
* @returns Cleanup function.
|
|
80
|
+
*/
|
|
81
|
+
export const subscribeToProviderHealthOf = (providerId, provider, callback) => {
|
|
82
|
+
if (provider?.subscribeToProviderHealth) {
|
|
83
|
+
return provider.subscribeToProviderHealth(callback);
|
|
84
|
+
}
|
|
85
|
+
if (provider?.subscribeToConnectionState) {
|
|
86
|
+
return provider.subscribeToConnectionState((state, attempt) => callback(getHealthFromConnectionState(providerId, state, attempt)));
|
|
87
|
+
}
|
|
88
|
+
callback(getProviderHealthOf(providerId, provider));
|
|
89
|
+
return () => undefined;
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=providerHealth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providerHealth.js","sourceRoot":"","sources":["../../src/utils/providerHealth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAO7D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,UAA6B,EAC7B,eAAyC,EACzC,mBAA2B,EACN,EAAE;IACvB,MAAM,MAAM,GACV,eAAe,KAAK,wBAAwB,CAAC,SAAS;QACtD,mBAAmB,GAAG,CAAC,CAAC;IAC1B,MAAM,MAAM,GACV,eAAe,KAAK,wBAAwB,C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AAC,CAAC;QACtE,CAAC,CACF,CAAC;QACF,WAAW,EAAE,CAAC;QACd,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,4BAA4B,CACjC,UAAU,EACV,QAAQ,CAAC,2BAA2B,EAAE,EAAE;QACtC,wBAAwB,CAAC,YAAY,EACvC,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,UAA6B,EAC7B,QAA0C,EAC1C,QAA+C,EACjC,EAAE;IAChB,IAAI,QAAQ,EAAE,yBAAyB,EAAE,CAAC;QACxC,OAAO,QAAQ,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,QAAQ,EAAE,0BAA0B,EAAE,CAAC;QACzC,OAAO,QAAQ,CAAC,0BAA0B,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAC5D,QAAQ,CAAC,4BAA4B,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CACnE,CAAC;IACJ,CAAC;IACD,QAAQ,CAAC,mBAAmB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IACpD,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC;AACzB,CAAC,CAAC","sourcesContent":["import { WebSocketConnectionState } from '../types/index.js';\nimport type {\n PerpsProvider,\n PerpsProviderHealth,\n PerpsProviderType,\n} from '../types/index.js';\n\n/**\n * Health for a provider without its own health API, from its socket state:\n * degraded while it is reconnecting after a drop, or disconnected after\n * reconnect attempts. Disconnected at attempt 0 reads `unavailable`: the\n * provider has not started or was disconnected on purpose. A failed first\n * connect also ends there, as the state cannot tell it apart.\n *\n * @param providerId - Provider the state belongs to.\n * @param connectionState - The provider's socket state.\n * @param reconnectionAttempt - Reconnect attempts since its last open.\n * @returns The derived health.\n */\nexport const getHealthFromConnectionState = (\n providerId: PerpsProviderType,\n connectionState: WebSocketConnectionState,\n reconnectionAttempt: number,\n): PerpsProviderHealth => {\n const isDown =\n connectionState !== WebSocketConnectionState.Connected &&\n reconnectionAttempt > 0;\n const isIdle =\n connectionState === WebSocketConnectionState.Disconnected &&\n reconnectionAttempt === 0;\n let status: PerpsProviderHealth['status'] = 'healthy';\n if (isDown) {\n status = 'degraded';\n } else if (isIdle) {\n status = 'unavailable';\n }\n return {\n providerId,\n status,\n reasons: isDown ? ['socket_down'] : [],\n connectionState,\n reconnectionAttempt,\n updatedAt: Date.now(),\n };\n};\n\n/**\n * The provider methods health is read from; all are optional.\n */\nexport type ProviderHealthSource = Pick<\n PerpsProvider,\n | 'getProviderHealth'\n | 'subscribeToProviderHealth'\n | 'getWebSocketConnectionState'\n | 'subscribeToConnectionState'\n>;\n\nconst getUnavailableHealth = (\n providerId: PerpsProviderType,\n): PerpsProviderHealth => ({\n providerId,\n status: 'unavailable',\n reasons: [],\n connectionState: WebSocketConnectionState.Disconnected,\n reconnectionAttempt: 0,\n updatedAt: Date.now(),\n});\n\n/**\n * Read one provider's health.\n *\n * @param providerId - Provider to report on.\n * @param provider - The registered provider, if any.\n * @returns Its own health, health derived from its socket state, or\n * `unavailable` when it is not registered.\n */\nexport const getProviderHealthOf = (\n providerId: PerpsProviderType,\n provider: ProviderHealthSource | undefined,\n): PerpsProviderHealth => {\n if (!provider) {\n return getUnavailableHealth(providerId);\n }\n if (provider.getProviderHealth) {\n return provider.getProviderHealth();\n }\n if (provider.subscribeToConnectionState) {\n // Providers report their current state and reconnect attempt\n // synchronously on subscribe; read that once.\n let health: PerpsProviderHealth | undefined;\n const unsubscribe = provider.subscribeToConnectionState(\n (state, attempt) => {\n health ??= getHealthFromConnectionState(providerId, state, attempt);\n },\n );\n unsubscribe();\n if (health) {\n return health;\n }\n }\n return getHealthFromConnectionState(\n providerId,\n provider.getWebSocketConnectionState?.() ??\n WebSocketConnectionState.Disconnected,\n 0,\n );\n};\n\n/**\n * Watch one provider's health: the current value at once, then each change.\n *\n * @param providerId - Provider to watch.\n * @param provider - The registered provider, if any.\n * @param callback - Receives each health snapshot.\n * @returns Cleanup function.\n */\nexport const subscribeToProviderHealthOf = (\n providerId: PerpsProviderType,\n provider: ProviderHealthSource | undefined,\n callback: (health: PerpsProviderHealth) => void,\n): (() => void) => {\n if (provider?.subscribeToProviderHealth) {\n return provider.subscribeToProviderHealth(callback);\n }\n if (provider?.subscribeToConnectionState) {\n return provider.subscribeToConnectionState((state, attempt) =>\n callback(getHealthFromConnectionState(providerId, state, attempt)),\n );\n }\n callback(getProviderHealthOf(providerId, provider));\n return () => undefined;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/perps-controller",
|
|
3
|
-
"version": "24.0.0-preview-
|
|
3
|
+
"version": "24.0.0-preview-d94a14f45",
|
|
4
4
|
"description": "Controller for perpetual trading functionality in MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@metamask/auto-changelog": "^7.1.0",
|
|
94
94
|
"@metamask/geolocation-controller": "^2.0.0",
|
|
95
95
|
"@metamask/keyring-api": "^24.3.0",
|
|
96
|
-
"@metamask/keyring-controller": "^28.2.
|
|
96
|
+
"@metamask/keyring-controller": "^28.2.2",
|
|
97
97
|
"@metamask/keyring-internal-api": "^12.1.2",
|
|
98
98
|
"@metamask/network-controller": "^38.0.1",
|
|
99
99
|
"@metamask/profile-sync-controller": "^36.1.2",
|