@metamask-previews/perps-controller 20.0.0-preview-44b7ded21 → 20.0.0-preview-2750df1dc
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 +8 -0
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +82 -52
- package/dist/PerpsController.js.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.ts +3 -2
- package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
- package/dist/providers/HyperLiquidProvider.js +89 -29
- package/dist/providers/HyperLiquidProvider.js.map +1 -1
- package/dist/providers/LighterProvider.d.ts +1 -1
- package/dist/providers/LighterProvider.d.ts.map +1 -1
- package/dist/providers/LighterProvider.js +113 -24
- package/dist/providers/LighterProvider.js.map +1 -1
- package/dist/services/AccountService.d.ts.map +1 -1
- package/dist/services/AccountService.js +26 -19
- package/dist/services/AccountService.js.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -1
- package/dist/services/HyperLiquidSubscriptionService.js +13 -14
- package/dist/services/HyperLiquidSubscriptionService.js.map +1 -1
- package/dist/services/TradingService.d.ts.map +1 -1
- package/dist/services/TradingService.js +143 -92
- package/dist/services/TradingService.js.map +1 -1
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/errorContext.d.ts +78 -0
- package/dist/utils/errorContext.d.ts.map +1 -0
- package/dist/utils/errorContext.js +92 -0
- package/dist/utils/errorContext.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { PerpsLogger } from '../types/index.js';
|
|
2
|
+
export declare const PERPS_ERROR_OPERATION: {
|
|
3
|
+
readonly ConnectionManagement: 'connection_management';
|
|
4
|
+
readonly OrderManagement: 'order_management';
|
|
5
|
+
readonly PositionManagement: 'position_management';
|
|
6
|
+
readonly FinancialOperations: 'financial_operations';
|
|
7
|
+
};
|
|
8
|
+
export type PerpsErrorOperation = (typeof PERPS_ERROR_OPERATION)[keyof typeof PERPS_ERROR_OPERATION];
|
|
9
|
+
export declare const PERPS_ERROR_ACTION: {
|
|
10
|
+
readonly ConnectionConnection: 'connection_connection';
|
|
11
|
+
readonly FinancialDeposit: 'financial_deposit';
|
|
12
|
+
readonly FinancialWithdrawal: 'financial_withdrawal';
|
|
13
|
+
readonly PlaceOrder: 'place_order';
|
|
14
|
+
readonly EditOrder: 'edit_order';
|
|
15
|
+
readonly CancelOrder: 'cancel_order';
|
|
16
|
+
readonly ClosePosition: 'close_position';
|
|
17
|
+
readonly PositionTpslUpdate: 'position_tpsl_update';
|
|
18
|
+
readonly UpdateMargin: 'update_margin';
|
|
19
|
+
readonly FlipPosition: 'flip_position';
|
|
20
|
+
};
|
|
21
|
+
export type PerpsErrorAction = (typeof PERPS_ERROR_ACTION)[keyof typeof PERPS_ERROR_ACTION];
|
|
22
|
+
export declare const PERPS_ERROR_COMPONENT: {
|
|
23
|
+
readonly ConnectionManager: 'PerpsConnectionManager';
|
|
24
|
+
};
|
|
25
|
+
export type PerpsErrorComponent = (typeof PERPS_ERROR_COMPONENT)[keyof typeof PERPS_ERROR_COMPONENT];
|
|
26
|
+
export type PerpsErrorTags = {
|
|
27
|
+
operation: PerpsErrorOperation;
|
|
28
|
+
action?: PerpsErrorAction;
|
|
29
|
+
component?: PerpsErrorComponent;
|
|
30
|
+
};
|
|
31
|
+
export type PerpsLoggerOptions = NonNullable<Parameters<PerpsLogger['error']>[1]>;
|
|
32
|
+
declare const PROVIDER_ERROR_REPORTED: unique symbol;
|
|
33
|
+
type ProviderErrorReported = {
|
|
34
|
+
[PROVIDER_ERROR_REPORTED]?: true;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Mark a failed provider result whose underlying error was already reported.
|
|
38
|
+
*
|
|
39
|
+
* The symbol remains internal to Core and survives object spreads used by the
|
|
40
|
+
* aggregated provider without adding a consumer-facing result field.
|
|
41
|
+
*
|
|
42
|
+
* @param result - Provider result to mark.
|
|
43
|
+
* @returns The same result with internal reporting metadata.
|
|
44
|
+
*/
|
|
45
|
+
export declare function markProviderErrorReported<Result extends object>(result: Result): Result & ProviderErrorReported;
|
|
46
|
+
/**
|
|
47
|
+
* Check whether a provider already reported the error represented by a result.
|
|
48
|
+
*
|
|
49
|
+
* @param result - Provider result returned to a service.
|
|
50
|
+
* @returns Whether the provider owns reporting for the failure.
|
|
51
|
+
*/
|
|
52
|
+
export declare function wasProviderErrorReported(result: object): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Build a Perps logger payload with bounded, searchable Sentry tags.
|
|
55
|
+
*
|
|
56
|
+
* Diagnostic data is deliberately kept separate from tags so identifiers,
|
|
57
|
+
* symbols, messages, and method names cannot accidentally create unbounded
|
|
58
|
+
* tag cardinality.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Error context options.
|
|
61
|
+
* @param options.contextName - Stable name for the diagnostic context.
|
|
62
|
+
* @param options.method - Method or boundary where the error occurred.
|
|
63
|
+
* @param options.provider - Optional provider identifier.
|
|
64
|
+
* @param options.network - Optional network environment.
|
|
65
|
+
* @param options.errorTags - Optional bounded dashboard tags.
|
|
66
|
+
* @param options.data - Optional diagnostic data retained in context.
|
|
67
|
+
* @returns Logger options accepted by the platform-provided Perps logger.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createPerpsErrorContext(options: {
|
|
70
|
+
contextName: string;
|
|
71
|
+
method: string;
|
|
72
|
+
provider?: string;
|
|
73
|
+
network?: 'mainnet' | 'testnet';
|
|
74
|
+
errorTags?: PerpsErrorTags;
|
|
75
|
+
data?: Record<string, unknown>;
|
|
76
|
+
}): PerpsLoggerOptions;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=errorContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorContext.d.ts","sourceRoot":"","sources":["../../src/utils/errorContext.ts"],"names":[],"mappings":"AACA,OAAO,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,CAAC,CAAC,EAAE,IAAI,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,SAAS,MAAM,EAC7D,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,qBAAqB,CAEhC;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,GAAG,kBAAkB,CAgCrB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { PERPS_CONSTANTS } from '../constants/perpsConfig.js';
|
|
2
|
+
export const PERPS_ERROR_OPERATION = {
|
|
3
|
+
ConnectionManagement: 'connection_management',
|
|
4
|
+
OrderManagement: 'order_management',
|
|
5
|
+
PositionManagement: 'position_management',
|
|
6
|
+
FinancialOperations: 'financial_operations',
|
|
7
|
+
};
|
|
8
|
+
export const PERPS_ERROR_ACTION = {
|
|
9
|
+
ConnectionConnection: 'connection_connection',
|
|
10
|
+
FinancialDeposit: 'financial_deposit',
|
|
11
|
+
FinancialWithdrawal: 'financial_withdrawal',
|
|
12
|
+
PlaceOrder: 'place_order',
|
|
13
|
+
EditOrder: 'edit_order',
|
|
14
|
+
CancelOrder: 'cancel_order',
|
|
15
|
+
ClosePosition: 'close_position',
|
|
16
|
+
PositionTpslUpdate: 'position_tpsl_update',
|
|
17
|
+
UpdateMargin: 'update_margin',
|
|
18
|
+
FlipPosition: 'flip_position',
|
|
19
|
+
};
|
|
20
|
+
export const PERPS_ERROR_COMPONENT = {
|
|
21
|
+
ConnectionManager: 'PerpsConnectionManager',
|
|
22
|
+
};
|
|
23
|
+
const PROVIDER_ERROR_REPORTED = Symbol('providerErrorReported');
|
|
24
|
+
/**
|
|
25
|
+
* Mark a failed provider result whose underlying error was already reported.
|
|
26
|
+
*
|
|
27
|
+
* The symbol remains internal to Core and survives object spreads used by the
|
|
28
|
+
* aggregated provider without adding a consumer-facing result field.
|
|
29
|
+
*
|
|
30
|
+
* @param result - Provider result to mark.
|
|
31
|
+
* @returns The same result with internal reporting metadata.
|
|
32
|
+
*/
|
|
33
|
+
export function markProviderErrorReported(result) {
|
|
34
|
+
return Object.assign(result, { [PROVIDER_ERROR_REPORTED]: true });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check whether a provider already reported the error represented by a result.
|
|
38
|
+
*
|
|
39
|
+
* @param result - Provider result returned to a service.
|
|
40
|
+
* @returns Whether the provider owns reporting for the failure.
|
|
41
|
+
*/
|
|
42
|
+
export function wasProviderErrorReported(result) {
|
|
43
|
+
return result[PROVIDER_ERROR_REPORTED] === true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build a Perps logger payload with bounded, searchable Sentry tags.
|
|
47
|
+
*
|
|
48
|
+
* Diagnostic data is deliberately kept separate from tags so identifiers,
|
|
49
|
+
* symbols, messages, and method names cannot accidentally create unbounded
|
|
50
|
+
* tag cardinality.
|
|
51
|
+
*
|
|
52
|
+
* @param options - Error context options.
|
|
53
|
+
* @param options.contextName - Stable name for the diagnostic context.
|
|
54
|
+
* @param options.method - Method or boundary where the error occurred.
|
|
55
|
+
* @param options.provider - Optional provider identifier.
|
|
56
|
+
* @param options.network - Optional network environment.
|
|
57
|
+
* @param options.errorTags - Optional bounded dashboard tags.
|
|
58
|
+
* @param options.data - Optional diagnostic data retained in context.
|
|
59
|
+
* @returns Logger options accepted by the platform-provided Perps logger.
|
|
60
|
+
*/
|
|
61
|
+
export function createPerpsErrorContext(options) {
|
|
62
|
+
const { contextName, method, provider, network, errorTags, data } = options;
|
|
63
|
+
const tags = {
|
|
64
|
+
feature: PERPS_CONSTANTS.FeatureName,
|
|
65
|
+
};
|
|
66
|
+
if (provider !== undefined) {
|
|
67
|
+
tags.provider = provider;
|
|
68
|
+
}
|
|
69
|
+
if (network !== undefined) {
|
|
70
|
+
tags.network = network;
|
|
71
|
+
}
|
|
72
|
+
if (errorTags !== undefined) {
|
|
73
|
+
tags.operation = errorTags.operation;
|
|
74
|
+
if (errorTags.action !== undefined) {
|
|
75
|
+
tags.action = errorTags.action;
|
|
76
|
+
}
|
|
77
|
+
if (errorTags.component !== undefined) {
|
|
78
|
+
tags.component = errorTags.component;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
tags,
|
|
83
|
+
context: {
|
|
84
|
+
name: contextName,
|
|
85
|
+
data: {
|
|
86
|
+
method,
|
|
87
|
+
...data,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=errorContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorContext.js","sourceRoot":"","sources":["../../src/utils/errorContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,oBAAoB,EAAE,uBAAuB;IAC7C,eAAe,EAAE,kBAAkB;IACnC,kBAAkB,EAAE,qBAAqB;IACzC,mBAAmB,EAAE,sBAAsB;CACnC,CAAC;AAKX,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,oBAAoB,EAAE,uBAAuB;IAC7C,gBAAgB,EAAE,mBAAmB;IACrC,mBAAmB,EAAE,sBAAsB;IAC3C,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,YAAY;IACvB,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,gBAAgB;I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SAAS,EAAE,CAAC;YACtC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;QACvC,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI;QACJ,OAAO,EAAE;YACP,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE;gBACJ,MAAM;gBACN,GAAG,IAAI;aACR;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { PERPS_CONSTANTS } from '../constants/perpsConfig.js';\nimport type { PerpsLogger } from '../types/index.js';\n\nexport const PERPS_ERROR_OPERATION = {\n ConnectionManagement: 'connection_management',\n OrderManagement: 'order_management',\n PositionManagement: 'position_management',\n FinancialOperations: 'financial_operations',\n} as const;\n\nexport type PerpsErrorOperation =\n (typeof PERPS_ERROR_OPERATION)[keyof typeof PERPS_ERROR_OPERATION];\n\nexport const PERPS_ERROR_ACTION = {\n ConnectionConnection: 'connection_connection',\n FinancialDeposit: 'financial_deposit',\n FinancialWithdrawal: 'financial_withdrawal',\n PlaceOrder: 'place_order',\n EditOrder: 'edit_order',\n CancelOrder: 'cancel_order',\n ClosePosition: 'close_position',\n PositionTpslUpdate: 'position_tpsl_update',\n UpdateMargin: 'update_margin',\n FlipPosition: 'flip_position',\n} as const;\n\nexport type PerpsErrorAction =\n (typeof PERPS_ERROR_ACTION)[keyof typeof PERPS_ERROR_ACTION];\n\nexport const PERPS_ERROR_COMPONENT = {\n ConnectionManager: 'PerpsConnectionManager',\n} as const;\n\nexport type PerpsErrorComponent =\n (typeof PERPS_ERROR_COMPONENT)[keyof typeof PERPS_ERROR_COMPONENT];\n\nexport type PerpsErrorTags = {\n operation: PerpsErrorOperation;\n action?: PerpsErrorAction;\n component?: PerpsErrorComponent;\n};\n\nexport type PerpsLoggerOptions = NonNullable<\n Parameters<PerpsLogger['error']>[1]\n>;\n\nconst PROVIDER_ERROR_REPORTED = Symbol('providerErrorReported');\n\ntype ProviderErrorReported = {\n [PROVIDER_ERROR_REPORTED]?: true;\n};\n\n/**\n * Mark a failed provider result whose underlying error was already reported.\n *\n * The symbol remains internal to Core and survives object spreads used by the\n * aggregated provider without adding a consumer-facing result field.\n *\n * @param result - Provider result to mark.\n * @returns The same result with internal reporting metadata.\n */\nexport function markProviderErrorReported<Result extends object>(\n result: Result,\n): Result & ProviderErrorReported {\n return Object.assign(result, { [PROVIDER_ERROR_REPORTED]: true as const });\n}\n\n/**\n * Check whether a provider already reported the error represented by a result.\n *\n * @param result - Provider result returned to a service.\n * @returns Whether the provider owns reporting for the failure.\n */\nexport function wasProviderErrorReported(result: object): boolean {\n return (result as ProviderErrorReported)[PROVIDER_ERROR_REPORTED] === true;\n}\n\n/**\n * Build a Perps logger payload with bounded, searchable Sentry tags.\n *\n * Diagnostic data is deliberately kept separate from tags so identifiers,\n * symbols, messages, and method names cannot accidentally create unbounded\n * tag cardinality.\n *\n * @param options - Error context options.\n * @param options.contextName - Stable name for the diagnostic context.\n * @param options.method - Method or boundary where the error occurred.\n * @param options.provider - Optional provider identifier.\n * @param options.network - Optional network environment.\n * @param options.errorTags - Optional bounded dashboard tags.\n * @param options.data - Optional diagnostic data retained in context.\n * @returns Logger options accepted by the platform-provided Perps logger.\n */\nexport function createPerpsErrorContext(options: {\n contextName: string;\n method: string;\n provider?: string;\n network?: 'mainnet' | 'testnet';\n errorTags?: PerpsErrorTags;\n data?: Record<string, unknown>;\n}): PerpsLoggerOptions {\n const { contextName, method, provider, network, errorTags, data } = options;\n const tags: Record<string, string | number> = {\n feature: PERPS_CONSTANTS.FeatureName,\n };\n\n if (provider !== undefined) {\n tags.provider = provider;\n }\n if (network !== undefined) {\n tags.network = network;\n }\n if (errorTags !== undefined) {\n tags.operation = errorTags.operation;\n if (errorTags.action !== undefined) {\n tags.action = errorTags.action;\n }\n if (errorTags.component !== undefined) {\n tags.component = errorTags.component;\n }\n }\n\n return {\n tags,\n context: {\n name: contextName,\n data: {\n method,\n ...data,\n },\n },\n };\n}\n"]}
|
package/package.json
CHANGED