@metamask-previews/perps-controller 26.0.0-preview-203750488 → 26.1.0-preview-037c8a905
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 +21 -1
- package/dist/PerpsController.d.ts +7 -3
- package/dist/PerpsController.d.ts.map +1 -1
- package/dist/PerpsController.js +23 -5
- package/dist/PerpsController.js.map +1 -1
- package/dist/constants/lighterConfig.d.ts +5 -0
- package/dist/constants/lighterConfig.d.ts.map +1 -1
- package/dist/constants/lighterConfig.js +5 -0
- package/dist/constants/lighterConfig.js.map +1 -1
- package/dist/constants/perpsConfig.d.ts +9 -0
- package/dist/constants/perpsConfig.d.ts.map +1 -1
- package/dist/constants/perpsConfig.js +11 -0
- package/dist/constants/perpsConfig.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.d.ts +7 -0
- package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
- package/dist/providers/AggregatedPerpsProvider.js +13 -0
- package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
- package/dist/providers/LighterProvider.d.ts +7 -0
- package/dist/providers/LighterProvider.d.ts.map +1 -1
- package/dist/providers/LighterProvider.js +25 -5
- package/dist/providers/LighterProvider.js.map +1 -1
- package/dist/services/DataLakeService.d.ts.map +1 -1
- package/dist/services/DataLakeService.js +7 -28
- package/dist/services/DataLakeService.js.map +1 -1
- package/dist/services/LighterNotificationEnrollmentService.d.ts +40 -0
- package/dist/services/LighterNotificationEnrollmentService.d.ts.map +1 -0
- package/dist/services/LighterNotificationEnrollmentService.js +102 -0
- package/dist/services/LighterNotificationEnrollmentService.js.map +1 -0
- package/dist/services/TradingService.d.ts +2 -0
- package/dist/services/TradingService.d.ts.map +1 -1
- package/dist/services/TradingService.js +11 -3
- package/dist/services/TradingService.js.map +1 -1
- package/dist/services/getOptionalBearerToken.d.ts +12 -0
- package/dist/services/getOptionalBearerToken.d.ts.map +1 -0
- package/dist/services/getOptionalBearerToken.js +22 -0
- package/dist/services/getOptionalBearerToken.js.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/lighterClientOrderTag.d.ts +23 -0
- package/dist/utils/lighterClientOrderTag.d.ts.map +1 -0
- package/dist/utils/lighterClientOrderTag.js +43 -0
- package/dist/utils/lighterClientOrderTag.js.map +1 -0
- package/docs/architecture.md +33 -31
- package/package.json +3 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type LighterClientOrderKind = 'stopLoss' | 'takeProfit' | 'other';
|
|
2
|
+
/**
|
|
3
|
+
* Classify a Lighter wire order type for client order index tagging.
|
|
4
|
+
*
|
|
5
|
+
* @param wireOrderType - Lighter wire order type.
|
|
6
|
+
* @returns The tag kind for the order.
|
|
7
|
+
*/
|
|
8
|
+
export declare const getLighterClientOrderKind: (wireOrderType: number) => LighterClientOrderKind;
|
|
9
|
+
/**
|
|
10
|
+
* Map a uniform uint48 draw to a client order index.
|
|
11
|
+
*
|
|
12
|
+
* Stop loss and take profit indexes carry the MetaMask tag: bits 47..32 are
|
|
13
|
+
* {@link LIGHTER_METAMASK_TAG_PREFIX}, bit 31 is 0 for stop loss and 1 for
|
|
14
|
+
* take profit, and bits 30..0 come from the draw. Every other index is the draw
|
|
15
|
+
* itself, unless it carries the prefix, so MetaMask never creates a false tag.
|
|
16
|
+
* Arithmetic, not bitwise operators: JavaScript bitwise operators are 32-bit.
|
|
17
|
+
*
|
|
18
|
+
* @param kind - Tag kind of the order.
|
|
19
|
+
* @param draw - Uniform random integer in [0, 2^48).
|
|
20
|
+
* @returns The client order index, or null when the draw must be redrawn.
|
|
21
|
+
*/
|
|
22
|
+
export declare const toLighterClientOrderIndex: (kind: LighterClientOrderKind, draw: number) => number | null;
|
|
23
|
+
//# sourceMappingURL=lighterClientOrderTag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lighterClientOrderTag.d.ts","sourceRoot":"","sources":["../../src/utils/lighterClientOrderTag.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,sBAAsB,GAAG,UAAU,GAAG,YAAY,GAAG,OAAO,CAAC;AAEzE;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,kBACrB,MAAM,KACpB,sBAWF,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,SAC9B,sBAAsB,QACtB,MAAM,KACX,MAAM,GAAG,IAWX,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LIGHTER_METAMASK_TAG_PREFIX, LIGHTER_ORDER_TYPE_STOP_LOSS, LIGHTER_ORDER_TYPE_STOP_LOSS_LIMIT, LIGHTER_ORDER_TYPE_TAKE_PROFIT, LIGHTER_ORDER_TYPE_TAKE_PROFIT_LIMIT, } from '../constants/lighterConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Classify a Lighter wire order type for client order index tagging.
|
|
4
|
+
*
|
|
5
|
+
* @param wireOrderType - Lighter wire order type.
|
|
6
|
+
* @returns The tag kind for the order.
|
|
7
|
+
*/
|
|
8
|
+
export const getLighterClientOrderKind = (wireOrderType) => {
|
|
9
|
+
switch (wireOrderType) {
|
|
10
|
+
case LIGHTER_ORDER_TYPE_STOP_LOSS:
|
|
11
|
+
case LIGHTER_ORDER_TYPE_STOP_LOSS_LIMIT:
|
|
12
|
+
return 'stopLoss';
|
|
13
|
+
case LIGHTER_ORDER_TYPE_TAKE_PROFIT:
|
|
14
|
+
case LIGHTER_ORDER_TYPE_TAKE_PROFIT_LIMIT:
|
|
15
|
+
return 'takeProfit';
|
|
16
|
+
default:
|
|
17
|
+
return 'other';
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Map a uniform uint48 draw to a client order index.
|
|
22
|
+
*
|
|
23
|
+
* Stop loss and take profit indexes carry the MetaMask tag: bits 47..32 are
|
|
24
|
+
* {@link LIGHTER_METAMASK_TAG_PREFIX}, bit 31 is 0 for stop loss and 1 for
|
|
25
|
+
* take profit, and bits 30..0 come from the draw. Every other index is the draw
|
|
26
|
+
* itself, unless it carries the prefix, so MetaMask never creates a false tag.
|
|
27
|
+
* Arithmetic, not bitwise operators: JavaScript bitwise operators are 32-bit.
|
|
28
|
+
*
|
|
29
|
+
* @param kind - Tag kind of the order.
|
|
30
|
+
* @param draw - Uniform random integer in [0, 2^48).
|
|
31
|
+
* @returns The client order index, or null when the draw must be redrawn.
|
|
32
|
+
*/
|
|
33
|
+
export const toLighterClientOrderIndex = (kind, draw) => {
|
|
34
|
+
if (kind === 'other') {
|
|
35
|
+
return Math.floor(draw / 2 ** 32) === LIGHTER_METAMASK_TAG_PREFIX
|
|
36
|
+
? null
|
|
37
|
+
: draw;
|
|
38
|
+
}
|
|
39
|
+
return (LIGHTER_METAMASK_TAG_PREFIX * 2 ** 32 +
|
|
40
|
+
(kind === 'takeProfit' ? 2 ** 31 : 0) +
|
|
41
|
+
(draw % 2 ** 31));
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=lighterClientOrderTag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lighterClientOrderTag.js","sourceRoot":"","sources":["../../src/utils/lighterClientOrderTag.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,kCAAkC,EAClC,8BAA8B,EAC9B,oCAAoC,GACrC,MAAM,+BAA+B,CAAC;AAIvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,aAAqB,EACG,EAAE;IAC1B,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,4BAA4B,CAAC;QAClC,KAAK,kCAAkC;YACrC,OAAO,UAAU,CAAC;QACpB,KAAK,8BAA8B,CAAC;QACpC,KAAK,oCAAoC;YACvC,OAAO,YAAY,CAAC;QACtB;YACE,OAAO,OAAO,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,IAA4B,EAC5B,IAAY,EACG,EAAE;IACjB,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,2BAA2B;YAC/D,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IACD,OAAO,CACL,2BAA2B,GAAG,CAAC,IAAI,EAAE;QACrC,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,CACjB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n LIGHTER_METAMASK_TAG_PREFIX,\n LIGHTER_ORDER_TYPE_STOP_LOSS,\n LIGHTER_ORDER_TYPE_STOP_LOSS_LIMIT,\n LIGHTER_ORDER_TYPE_TAKE_PROFIT,\n LIGHTER_ORDER_TYPE_TAKE_PROFIT_LIMIT,\n} from '../constants/lighterConfig.js';\n\nexport type LighterClientOrderKind = 'stopLoss' | 'takeProfit' | 'other';\n\n/**\n * Classify a Lighter wire order type for client order index tagging.\n *\n * @param wireOrderType - Lighter wire order type.\n * @returns The tag kind for the order.\n */\nexport const getLighterClientOrderKind = (\n wireOrderType: number,\n): LighterClientOrderKind => {\n switch (wireOrderType) {\n case LIGHTER_ORDER_TYPE_STOP_LOSS:\n case LIGHTER_ORDER_TYPE_STOP_LOSS_LIMIT:\n return 'stopLoss';\n case LIGHTER_ORDER_TYPE_TAKE_PROFIT:\n case LIGHTER_ORDER_TYPE_TAKE_PROFIT_LIMIT:\n return 'takeProfit';\n default:\n return 'other';\n }\n};\n\n/**\n * Map a uniform uint48 draw to a client order index.\n *\n * Stop loss and take profit indexes carry the MetaMask tag: bits 47..32 are\n * {@link LIGHTER_METAMASK_TAG_PREFIX}, bit 31 is 0 for stop loss and 1 for\n * take profit, and bits 30..0 come from the draw. Every other index is the draw\n * itself, unless it carries the prefix, so MetaMask never creates a false tag.\n * Arithmetic, not bitwise operators: JavaScript bitwise operators are 32-bit.\n *\n * @param kind - Tag kind of the order.\n * @param draw - Uniform random integer in [0, 2^48).\n * @returns The client order index, or null when the draw must be redrawn.\n */\nexport const toLighterClientOrderIndex = (\n kind: LighterClientOrderKind,\n draw: number,\n): number | null => {\n if (kind === 'other') {\n return Math.floor(draw / 2 ** 32) === LIGHTER_METAMASK_TAG_PREFIX\n ? null\n : draw;\n }\n return (\n LIGHTER_METAMASK_TAG_PREFIX * 2 ** 32 +\n (kind === 'takeProfit' ? 2 ** 31 : 0) +\n (draw % 2 ** 31)\n );\n};\n"]}
|
package/docs/architecture.md
CHANGED
|
@@ -92,37 +92,38 @@ Code: `src/PerpsController.ts` `#createProviders`, `registerLighterProvider`, `h
|
|
|
92
92
|
|
|
93
93
|
## Services
|
|
94
94
|
|
|
95
|
-
The controller creates `TradingService`, `MarketDataService`, `AccountService`, `EligibilityService`, `DataLakeService`, `DepositService`, `FeatureFlagConfigurationService` and `RewardsIntegrationService` with the platform dependencies (some also get the messenger). Venue services are created by their provider.
|
|
96
|
-
|
|
97
|
-
| File
|
|
98
|
-
|
|
|
99
|
-
| `AccountService`
|
|
100
|
-
| `accountSigner.ts`
|
|
101
|
-
| `agentSigner.ts`
|
|
102
|
-
| `AggregatedOrderBookConnection`
|
|
103
|
-
| `causeChain.ts`
|
|
104
|
-
| `DataLakeService`
|
|
105
|
-
| `DepositService`
|
|
106
|
-
| `DexDiscoveryCacheManager`
|
|
107
|
-
| `EligibilityService`
|
|
108
|
-
| `environmentTypeProperty.ts`
|
|
109
|
-
| `FeatureFlagConfigurationService`
|
|
110
|
-
| `HyperLiquidClientService`
|
|
111
|
-
| `HyperLiquidSubscriptionService`
|
|
112
|
-
| `HyperLiquidWalletService`
|
|
113
|
-
| `LighterChaseService`
|
|
114
|
-
| `LighterClientService`
|
|
115
|
-
| `lighterDispatchIdentity.ts`
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
95
|
+
The controller creates `TradingService`, `MarketDataService`, `AccountService`, `EligibilityService`, `DataLakeService`, `LighterNotificationEnrollmentService`, `DepositService`, `FeatureFlagConfigurationService` and `RewardsIntegrationService` with the platform dependencies (some also get the messenger). Venue services are created by their provider.
|
|
96
|
+
|
|
97
|
+
| File | Job |
|
|
98
|
+
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
99
|
+
| `AccountService` | Withdrawals and withdrawal validation; stateless, delegates to the provider |
|
|
100
|
+
| `accountSigner.ts` | Readiness checks for an injected main-account signer |
|
|
101
|
+
| `agentSigner.ts` | HyperLiquid agent bindings kept across provider instances (`AgentBindings`) |
|
|
102
|
+
| `AggregatedOrderBookConnection` | Dedicated HyperLiquid socket for the order-book panel's aggregated `l2Book` stream; opens on first subscriber, closes after the last |
|
|
103
|
+
| `causeChain.ts` | Matches an error anywhere in its `cause` chain |
|
|
104
|
+
| `DataLakeService` | Reports order events to the Data Lake API with exponential backoff and tracing |
|
|
105
|
+
| `DepositService` | Prepares and validates deposit transaction data; the controller owns the `TransactionController` call and confirmation |
|
|
106
|
+
| `DexDiscoveryCacheManager` | Single HIP-3 DEX discovery cache for every `perpDexs()` derivative |
|
|
107
|
+
| `EligibilityService` | Eligibility from `GeolocationController` geolocation and blocked regions |
|
|
108
|
+
| `environmentTypeProperty.ts` | Adds the optional UI surface to analytics properties |
|
|
109
|
+
| `FeatureFlagConfigurationService` | HIP-3 and geo-blocking config from remote flags; once remote config loads it never drops back to fallback |
|
|
110
|
+
| `HyperLiquidClientService` | HyperLiquid SDK client initialization, HTTP and WebSocket transports, client lifecycle |
|
|
111
|
+
| `HyperLiquidSubscriptionService` | HyperLiquid WebSocket subscriptions with reference counting; per DEX, `clearinghouseState` carries positions and account and `openOrders` carries orders; one `webData3` subscription carries OI caps for all DEXs |
|
|
112
|
+
| `HyperLiquidWalletService` | Wallet adapter and signing for the HyperLiquid SDK |
|
|
113
|
+
| `LighterChaseService` | Bounded Chase order ownership and serial cancel/replace |
|
|
114
|
+
| `LighterClientService` | zkLighter REST client on the platform `fetch`, no SDK; decodes every response |
|
|
115
|
+
| `lighterDispatchIdentity.ts` | Checks the signed Lighter tx hash and expiry; refuses submission without them |
|
|
116
|
+
| `LighterNotificationEnrollmentService` | Enrolls the account index that placed a Lighter order with notify-perps, with exponential backoff; skipped on testnet and without a base URL or token |
|
|
117
|
+
| `LighterTwapService` | Durable native Lighter TWAP schedules |
|
|
118
|
+
| `LighterWalletService` | Routes the L1 signatures Lighter needs; the venue key stays in the client signer bridge |
|
|
119
|
+
| `MarketDataService` | Read-only fetches (markets, positions, orders, account state and more); writes state through `stateManager` when given; tries the Terminal API before the provider |
|
|
120
|
+
| `missingActionHandler.ts` | Detects the `Messenger.call` error for an unregistered or undelegated action |
|
|
121
|
+
| `providerNetwork.ts` | Whether a provider runs on testnet |
|
|
122
|
+
| `RewardsIntegrationService` | Unified fee resolver; lowest of `default`, `rewards`, `grant` and `subscription` |
|
|
123
|
+
| `ServiceContext.ts` | Per-call context type (tracing, error context, state callbacks) |
|
|
124
|
+
| `TerminalMarketService` | Market metadata from the MetaMask Terminal API, cached for `TERMINAL_API_CONFIG.CacheTtlMs`, and one schema-v4 global snapshot per provider, cached until `receivedAt` plus the smaller of its `maxAgeMs` and 30 s |
|
|
125
|
+
| `TradingReadinessCache.ts` | Global signing cache (unified account, builder fee, referral) that survives provider recreation so hardware wallets are not prompted again |
|
|
126
|
+
| `TradingService` | Orders, cancels and positions with fee discounts; signals `cacheInvalidator` after changes |
|
|
126
127
|
|
|
127
128
|
Code: `src/services/`; `src/PerpsController.ts` constructor.
|
|
128
129
|
|
|
@@ -154,6 +155,7 @@ With snapshots configured, a missing or expired slice of a registered venue inva
|
|
|
154
155
|
| `terminalApiUrl` | no | Deprecated; use `terminalApi.marketDataUrl` |
|
|
155
156
|
| `terminalMarketService` | no | Custom Terminal market service; the controller builds `TerminalMarketService` when only URLs are given |
|
|
156
157
|
| `rewards` | yes | `getPerpsDiscountForAccount`, optional `getPerpsTradingFeeGrant` |
|
|
158
|
+
| `notifyPerpsApi` | no | `baseUrl` of notify-perps; Lighter account enrollment is skipped without it |
|
|
157
159
|
| `subscription` | no | `getPerpsBenefits`, optional `registerTradingAddress` |
|
|
158
160
|
| `accountSigner` | no | Main-account signer for clients without a `KeyringController` |
|
|
159
161
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/perps-controller",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.1.0-preview-037c8a905",
|
|
4
4
|
"description": "Controller for perpetual trading functionality in MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -99,8 +99,8 @@
|
|
|
99
99
|
"@metamask/network-controller": "^38.0.1",
|
|
100
100
|
"@metamask/profile-sync-controller": "^36.1.2",
|
|
101
101
|
"@metamask/remote-feature-flag-controller": "^7.0.0",
|
|
102
|
-
"@metamask/subscription-controller": "^15.
|
|
103
|
-
"@metamask/transaction-controller": "^74.
|
|
102
|
+
"@metamask/subscription-controller": "^15.4.0",
|
|
103
|
+
"@metamask/transaction-controller": "^74.4.0",
|
|
104
104
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
105
105
|
"rimraf": "^6.1.4",
|
|
106
106
|
"tsx": "^4.20.5",
|