@metamask-previews/perps-controller 1.2.0-preview-0b8553c95 → 1.3.0-preview-e5ed18206
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 +10 -1
- package/dist/PerpsController.cjs +19 -10
- package/dist/PerpsController.cjs.map +1 -1
- package/dist/PerpsController.d.cts.map +1 -1
- package/dist/PerpsController.d.mts.map +1 -1
- package/dist/PerpsController.mjs +19 -10
- package/dist/PerpsController.mjs.map +1 -1
- package/package.json +4 -2
- package/dist/providers/MYXProvider.cjs +0 -514
- package/dist/providers/MYXProvider.cjs.map +0 -1
- package/dist/providers/MYXProvider.d.cts +0 -105
- package/dist/providers/MYXProvider.d.cts.map +0 -1
- package/dist/providers/MYXProvider.d.mts +0 -105
- package/dist/providers/MYXProvider.d.mts.map +0 -1
- package/dist/providers/MYXProvider.mjs +0 -510
- package/dist/providers/MYXProvider.mjs.map +0 -1
- package/dist/services/MYXClientService.cjs +0 -304
- package/dist/services/MYXClientService.cjs.map +0 -1
- package/dist/services/MYXClientService.d.cts +0 -81
- package/dist/services/MYXClientService.d.cts.map +0 -1
- package/dist/services/MYXClientService.d.mts +0 -81
- package/dist/services/MYXClientService.d.mts.map +0 -1
- package/dist/services/MYXClientService.mjs +0 -300
- package/dist/services/MYXClientService.mjs.map +0 -1
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* MYXClientService
|
|
4
|
-
*
|
|
5
|
-
* Stage 1 service for fetching MYX market data using the @myx-trade/sdk.
|
|
6
|
-
* Handles market listing, ticker fetching, and price polling.
|
|
7
|
-
*
|
|
8
|
-
* Uses MyxClient SDK for API calls.
|
|
9
|
-
* Trading functionality will be added in Stage 3.
|
|
10
|
-
*/
|
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
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");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var _MYXClientService_instances, _MYXClientService_myxClient, _MYXClientService_isTestnet, _MYXClientService_chainId, _MYXClientService_pricePollingTimeout, _MYXClientService_pollingSymbols, _MYXClientService_pollingCallback, _MYXClientService_marketsCache, _MYXClientService_marketsCacheTimestamp, _MYXClientService_marketsCacheTtlMs, _MYXClientService_deps, _MYXClientService_getErrorContext, _MYXClientService_pollPrices, _MYXClientService_scheduleNextPoll;
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.MYXClientService = void 0;
|
|
25
|
-
const sdk_1 = require("@myx-trade/sdk");
|
|
26
|
-
const myxConfig_1 = require("../constants/myxConfig.cjs");
|
|
27
|
-
const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
28
|
-
const errorUtils_1 = require("../utils/errorUtils.cjs");
|
|
29
|
-
// ============================================================================
|
|
30
|
-
// MYXClientService
|
|
31
|
-
// ============================================================================
|
|
32
|
-
/**
|
|
33
|
-
* Service for managing MYX SDK client interactions
|
|
34
|
-
* Stage 1: Read-only operations (markets, prices)
|
|
35
|
-
*/
|
|
36
|
-
class MYXClientService {
|
|
37
|
-
constructor(deps, config) {
|
|
38
|
-
_MYXClientService_instances.add(this);
|
|
39
|
-
// SDK Client
|
|
40
|
-
_MYXClientService_myxClient.set(this, void 0);
|
|
41
|
-
// Configuration
|
|
42
|
-
_MYXClientService_isTestnet.set(this, void 0);
|
|
43
|
-
_MYXClientService_chainId.set(this, void 0);
|
|
44
|
-
// Price polling (sequential using setTimeout to prevent request pileup)
|
|
45
|
-
_MYXClientService_pricePollingTimeout.set(this, void 0);
|
|
46
|
-
_MYXClientService_pollingSymbols.set(this, []);
|
|
47
|
-
_MYXClientService_pollingCallback.set(this, void 0);
|
|
48
|
-
// Caches
|
|
49
|
-
_MYXClientService_marketsCache.set(this, []);
|
|
50
|
-
_MYXClientService_marketsCacheTimestamp.set(this, 0);
|
|
51
|
-
_MYXClientService_marketsCacheTtlMs.set(this, 5 * 60 * 1000); // 5 minutes
|
|
52
|
-
// Platform dependencies
|
|
53
|
-
_MYXClientService_deps.set(this, void 0);
|
|
54
|
-
__classPrivateFieldSet(this, _MYXClientService_deps, deps, "f");
|
|
55
|
-
__classPrivateFieldSet(this, _MYXClientService_isTestnet, config.isTestnet, "f");
|
|
56
|
-
__classPrivateFieldSet(this, _MYXClientService_chainId, (0, myxConfig_1.getMYXChainId)(__classPrivateFieldGet(this, _MYXClientService_isTestnet, "f") ? 'testnet' : 'mainnet'), "f");
|
|
57
|
-
// Initialize MyxClient
|
|
58
|
-
__classPrivateFieldSet(this, _MYXClientService_myxClient, new sdk_1.MyxClient({
|
|
59
|
-
chainId: __classPrivateFieldGet(this, _MYXClientService_chainId, "f"),
|
|
60
|
-
brokerAddress: '0x0000000000000000000000000000000000000000', // Not needed for read-only
|
|
61
|
-
isTestnet: __classPrivateFieldGet(this, _MYXClientService_isTestnet, "f"),
|
|
62
|
-
isBetaMode: __classPrivateFieldGet(this, _MYXClientService_isTestnet, "f"), // Use beta API for testnet
|
|
63
|
-
}), "f");
|
|
64
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Initialized with SDK', {
|
|
65
|
-
isTestnet: __classPrivateFieldGet(this, _MYXClientService_isTestnet, "f"),
|
|
66
|
-
chainId: __classPrivateFieldGet(this, _MYXClientService_chainId, "f"),
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
// ============================================================================
|
|
70
|
-
// Market Operations
|
|
71
|
-
// ============================================================================
|
|
72
|
-
/**
|
|
73
|
-
* Get all available markets/pools
|
|
74
|
-
* Uses SDK markets.getPoolSymbolAll()
|
|
75
|
-
*
|
|
76
|
-
* @returns The array of available MYX pool symbols.
|
|
77
|
-
*/
|
|
78
|
-
async getMarkets() {
|
|
79
|
-
// Return cache if valid
|
|
80
|
-
const now = Date.now();
|
|
81
|
-
if (__classPrivateFieldGet(this, _MYXClientService_marketsCache, "f").length > 0 &&
|
|
82
|
-
now - __classPrivateFieldGet(this, _MYXClientService_marketsCacheTimestamp, "f") < __classPrivateFieldGet(this, _MYXClientService_marketsCacheTtlMs, "f")) {
|
|
83
|
-
return __classPrivateFieldGet(this, _MYXClientService_marketsCache, "f");
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Fetching markets via SDK');
|
|
87
|
-
const pools = await __classPrivateFieldGet(this, _MYXClientService_myxClient, "f").markets.getPoolSymbolAll();
|
|
88
|
-
// Update cache
|
|
89
|
-
__classPrivateFieldSet(this, _MYXClientService_marketsCache, pools || [], "f");
|
|
90
|
-
__classPrivateFieldSet(this, _MYXClientService_marketsCacheTimestamp, Date.now(), "f");
|
|
91
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Markets fetched', {
|
|
92
|
-
count: __classPrivateFieldGet(this, _MYXClientService_marketsCache, "f").length,
|
|
93
|
-
});
|
|
94
|
-
return __classPrivateFieldGet(this, _MYXClientService_marketsCache, "f");
|
|
95
|
-
}
|
|
96
|
-
catch (caughtError) {
|
|
97
|
-
const wrappedError = (0, errorUtils_1.ensureError)(caughtError, 'MYXClientService.getMarkets');
|
|
98
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").logger.error(wrappedError, __classPrivateFieldGet(this, _MYXClientService_instances, "m", _MYXClientService_getErrorContext).call(this, 'getMarkets'));
|
|
99
|
-
// Return stale cache if available
|
|
100
|
-
if (__classPrivateFieldGet(this, _MYXClientService_marketsCache, "f").length > 0) {
|
|
101
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Returning stale cache after error');
|
|
102
|
-
return __classPrivateFieldGet(this, _MYXClientService_marketsCache, "f");
|
|
103
|
-
}
|
|
104
|
-
throw wrappedError;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get tickers for specific symbols/pools
|
|
109
|
-
* Uses SDK markets.getTickerList()
|
|
110
|
-
*
|
|
111
|
-
* @param poolIds - The array of pool identifiers to fetch tickers for.
|
|
112
|
-
* @returns The array of ticker data for the specified pools.
|
|
113
|
-
*/
|
|
114
|
-
async getTickers(poolIds) {
|
|
115
|
-
if (poolIds.length === 0) {
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Fetching tickers via SDK', {
|
|
120
|
-
poolIds: poolIds.length,
|
|
121
|
-
});
|
|
122
|
-
const tickers = await __classPrivateFieldGet(this, _MYXClientService_myxClient, "f").markets.getTickerList({
|
|
123
|
-
chainId: __classPrivateFieldGet(this, _MYXClientService_chainId, "f"),
|
|
124
|
-
poolIds,
|
|
125
|
-
});
|
|
126
|
-
return tickers || [];
|
|
127
|
-
}
|
|
128
|
-
catch (caughtError) {
|
|
129
|
-
const wrappedError = (0, errorUtils_1.ensureError)(caughtError, 'MYXClientService.getTickers');
|
|
130
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").logger.error(wrappedError, __classPrivateFieldGet(this, _MYXClientService_instances, "m", _MYXClientService_getErrorContext).call(this, 'getTickers', { poolIds }));
|
|
131
|
-
throw wrappedError;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Get all tickers (for all available markets)
|
|
136
|
-
*
|
|
137
|
-
* @returns The array of ticker data for all available markets.
|
|
138
|
-
*/
|
|
139
|
-
async getAllTickers() {
|
|
140
|
-
try {
|
|
141
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Fetching all tickers via SDK');
|
|
142
|
-
// Get all pools first, then fetch tickers for them
|
|
143
|
-
const pools = await this.getMarkets();
|
|
144
|
-
const poolIds = pools.map((pool) => pool.poolId);
|
|
145
|
-
if (poolIds.length === 0) {
|
|
146
|
-
return [];
|
|
147
|
-
}
|
|
148
|
-
return this.getTickers(poolIds);
|
|
149
|
-
}
|
|
150
|
-
catch (caughtError) {
|
|
151
|
-
const wrappedError = (0, errorUtils_1.ensureError)(caughtError, 'MYXClientService.getAllTickers');
|
|
152
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").logger.error(wrappedError, __classPrivateFieldGet(this, _MYXClientService_instances, "m", _MYXClientService_getErrorContext).call(this, 'getAllTickers'));
|
|
153
|
-
throw wrappedError;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
// ============================================================================
|
|
157
|
-
// Price Polling
|
|
158
|
-
// ============================================================================
|
|
159
|
-
/**
|
|
160
|
-
* Start polling for price updates.
|
|
161
|
-
* Uses sequential setTimeout to prevent request pileup — the next poll
|
|
162
|
-
* is only scheduled after the current one completes (or fails).
|
|
163
|
-
*
|
|
164
|
-
* @param poolIds - The array of pool identifiers to poll prices for.
|
|
165
|
-
* @param callback - The callback invoked with updated ticker data on each poll.
|
|
166
|
-
*/
|
|
167
|
-
startPricePolling(poolIds, callback) {
|
|
168
|
-
// Stop existing polling
|
|
169
|
-
this.stopPricePolling();
|
|
170
|
-
__classPrivateFieldSet(this, _MYXClientService_pollingSymbols, poolIds, "f");
|
|
171
|
-
__classPrivateFieldSet(this, _MYXClientService_pollingCallback, callback, "f");
|
|
172
|
-
// Fetch immediately, then schedule subsequent polls
|
|
173
|
-
__classPrivateFieldGet(this, _MYXClientService_instances, "m", _MYXClientService_pollPrices).call(this).catch(() => {
|
|
174
|
-
// Error handling is done inside #pollPrices
|
|
175
|
-
});
|
|
176
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Started price polling', {
|
|
177
|
-
symbols: poolIds.length,
|
|
178
|
-
intervalMs: myxConfig_1.MYX_PRICE_POLLING_INTERVAL_MS,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Stop price polling
|
|
183
|
-
*/
|
|
184
|
-
stopPricePolling() {
|
|
185
|
-
if (__classPrivateFieldGet(this, _MYXClientService_pricePollingTimeout, "f")) {
|
|
186
|
-
clearTimeout(__classPrivateFieldGet(this, _MYXClientService_pricePollingTimeout, "f"));
|
|
187
|
-
__classPrivateFieldSet(this, _MYXClientService_pricePollingTimeout, undefined, "f");
|
|
188
|
-
}
|
|
189
|
-
__classPrivateFieldSet(this, _MYXClientService_pollingSymbols, [], "f");
|
|
190
|
-
__classPrivateFieldSet(this, _MYXClientService_pollingCallback, undefined, "f");
|
|
191
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Stopped price polling');
|
|
192
|
-
}
|
|
193
|
-
// ============================================================================
|
|
194
|
-
// Health Check
|
|
195
|
-
// ============================================================================
|
|
196
|
-
/**
|
|
197
|
-
* Health check — attempts a lightweight REST call (getTickerList with empty poolIds)
|
|
198
|
-
* to verify the MYX API is reachable.
|
|
199
|
-
*
|
|
200
|
-
* @param timeoutMs - The timeout in milliseconds for the ping request.
|
|
201
|
-
*/
|
|
202
|
-
async ping(timeoutMs = 5000) {
|
|
203
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Ping - checking REST health');
|
|
204
|
-
let timeoutId;
|
|
205
|
-
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
206
|
-
timeoutId = setTimeout(() => reject(new Error('MYX ping timeout')), timeoutMs);
|
|
207
|
-
});
|
|
208
|
-
try {
|
|
209
|
-
await Promise.race([
|
|
210
|
-
__classPrivateFieldGet(this, _MYXClientService_myxClient, "f").markets.getTickerList({
|
|
211
|
-
chainId: __classPrivateFieldGet(this, _MYXClientService_chainId, "f"),
|
|
212
|
-
poolIds: [],
|
|
213
|
-
}),
|
|
214
|
-
timeoutPromise,
|
|
215
|
-
]);
|
|
216
|
-
}
|
|
217
|
-
catch (caughtError) {
|
|
218
|
-
const wrappedError = (0, errorUtils_1.ensureError)(caughtError, 'MYXClientService.ping');
|
|
219
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Ping failed', {
|
|
220
|
-
error: wrappedError.message,
|
|
221
|
-
});
|
|
222
|
-
throw wrappedError;
|
|
223
|
-
}
|
|
224
|
-
finally {
|
|
225
|
-
clearTimeout(timeoutId);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// ============================================================================
|
|
229
|
-
// Lifecycle
|
|
230
|
-
// ============================================================================
|
|
231
|
-
/**
|
|
232
|
-
* Disconnect and cleanup
|
|
233
|
-
*/
|
|
234
|
-
disconnect() {
|
|
235
|
-
this.stopPricePolling();
|
|
236
|
-
__classPrivateFieldSet(this, _MYXClientService_marketsCache, [], "f");
|
|
237
|
-
__classPrivateFieldSet(this, _MYXClientService_marketsCacheTimestamp, 0, "f");
|
|
238
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Disconnected');
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Get current network mode
|
|
242
|
-
*
|
|
243
|
-
* @returns True if the service is in testnet mode.
|
|
244
|
-
*/
|
|
245
|
-
getIsTestnet() {
|
|
246
|
-
return __classPrivateFieldGet(this, _MYXClientService_isTestnet, "f");
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
exports.MYXClientService = MYXClientService;
|
|
250
|
-
_MYXClientService_myxClient = new WeakMap(), _MYXClientService_isTestnet = new WeakMap(), _MYXClientService_chainId = new WeakMap(), _MYXClientService_pricePollingTimeout = new WeakMap(), _MYXClientService_pollingSymbols = new WeakMap(), _MYXClientService_pollingCallback = new WeakMap(), _MYXClientService_marketsCache = new WeakMap(), _MYXClientService_marketsCacheTimestamp = new WeakMap(), _MYXClientService_marketsCacheTtlMs = new WeakMap(), _MYXClientService_deps = new WeakMap(), _MYXClientService_instances = new WeakSet(), _MYXClientService_getErrorContext = function _MYXClientService_getErrorContext(method, extra) {
|
|
251
|
-
return {
|
|
252
|
-
tags: {
|
|
253
|
-
feature: perpsConfig_1.PERPS_CONSTANTS.FeatureName,
|
|
254
|
-
service: 'MYXClientService',
|
|
255
|
-
network: __classPrivateFieldGet(this, _MYXClientService_isTestnet, "f") ? 'testnet' : 'mainnet',
|
|
256
|
-
},
|
|
257
|
-
context: {
|
|
258
|
-
name: `MYXClientService.${method}`,
|
|
259
|
-
data: {
|
|
260
|
-
chainId: __classPrivateFieldGet(this, _MYXClientService_chainId, "f"),
|
|
261
|
-
...extra,
|
|
262
|
-
},
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
}, _MYXClientService_pollPrices =
|
|
266
|
-
/**
|
|
267
|
-
* Execute a single price poll, then schedule the next one.
|
|
268
|
-
* Sequential pattern ensures no request pileup if polls take longer than the interval.
|
|
269
|
-
*/
|
|
270
|
-
async function _MYXClientService_pollPrices() {
|
|
271
|
-
if (!__classPrivateFieldGet(this, _MYXClientService_pollingCallback, "f") || __classPrivateFieldGet(this, _MYXClientService_pollingSymbols, "f").length === 0) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
try {
|
|
275
|
-
const tickers = await this.getTickers(__classPrivateFieldGet(this, _MYXClientService_pollingSymbols, "f"));
|
|
276
|
-
// Re-check: polling may have been stopped during the await
|
|
277
|
-
// (TS narrows after early return but can't track mutations across await)
|
|
278
|
-
const callback = __classPrivateFieldGet(this, _MYXClientService_pollingCallback, "f");
|
|
279
|
-
if (callback) {
|
|
280
|
-
callback(tickers);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
catch (caughtError) {
|
|
284
|
-
const wrappedError = (0, errorUtils_1.ensureError)(caughtError, 'MYXClientService.pollPrices');
|
|
285
|
-
__classPrivateFieldGet(this, _MYXClientService_deps, "f").debugLogger.log('[MYXClientService] Price poll failed', {
|
|
286
|
-
error: wrappedError.message,
|
|
287
|
-
});
|
|
288
|
-
// Don't propagate error - polling continues
|
|
289
|
-
}
|
|
290
|
-
finally {
|
|
291
|
-
__classPrivateFieldGet(this, _MYXClientService_instances, "m", _MYXClientService_scheduleNextPoll).call(this);
|
|
292
|
-
}
|
|
293
|
-
}, _MYXClientService_scheduleNextPoll = function _MYXClientService_scheduleNextPoll() {
|
|
294
|
-
// Only schedule if polling is still active
|
|
295
|
-
if (!__classPrivateFieldGet(this, _MYXClientService_pollingCallback, "f") || __classPrivateFieldGet(this, _MYXClientService_pollingSymbols, "f").length === 0) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
__classPrivateFieldSet(this, _MYXClientService_pricePollingTimeout, setTimeout(() => {
|
|
299
|
-
__classPrivateFieldGet(this, _MYXClientService_instances, "m", _MYXClientService_pollPrices).call(this).catch(() => {
|
|
300
|
-
// Error handling is done inside #pollPrices
|
|
301
|
-
});
|
|
302
|
-
}, myxConfig_1.MYX_PRICE_POLLING_INTERVAL_MS), "f");
|
|
303
|
-
};
|
|
304
|
-
//# sourceMappingURL=MYXClientService.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MYXClientService.cjs","sourceRoot":"","sources":["../../src/services/MYXClientService.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;AAEH,wCAA2C;AAE3C,0DAGgC;AAChC,8D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AAA,IAAI,uEAAkB,MAAtB,IAAI,CAAoB,CAAC;IAC3B,CAAC;AACH,CAAC;IAMC,2CAA2C;IAC3C,IAAI,CAAC,uBAAA,IAAI,yCAAiB,IAAI,uBAAA,IAAI,wCAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChE,OAAO;IACT,CAAC;IAED,uBAAA,IAAI,yCAAwB,UAAU,CAAC,GAAG,EAAE;QAC1C,uBAAA,IAAI,iEAAY,MAAhB,IAAI,CAAc,CAAC,KAAK,CAAC,GAAG,EAAE;YAC5B,4CAA4C;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,yCAA6B,CAAC,MAAA,CAAC;AACpC,CAAC","sourcesContent":["/**\n * MYXClientService\n *\n * Stage 1 service for fetching MYX market data using the @myx-trade/sdk.\n * Handles market listing, ticker fetching, and price polling.\n *\n * Uses MyxClient SDK for API calls.\n * Trading functionality will be added in Stage 3.\n */\n\nimport { MyxClient } from '@myx-trade/sdk';\n\nimport {\n MYX_PRICE_POLLING_INTERVAL_MS,\n getMYXChainId,\n} from '../constants/myxConfig';\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport type { PerpsPlatformDependencies } from '../types';\nimport type { MYXPoolSymbol, MYXTicker } from '../types/myx-types';\nimport { ensureError } from '../utils/errorUtils';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * MYX Client Configuration\n */\nexport type MYXClientConfig = {\n isTestnet: boolean;\n};\n\n/**\n * Price polling callback type\n */\nexport type PricePollingCallback = (tickers: MYXTicker[]) => void;\n\n// ============================================================================\n// MYXClientService\n// ============================================================================\n\n/**\n * Service for managing MYX SDK client interactions\n * Stage 1: Read-only operations (markets, prices)\n */\nexport class MYXClientService {\n // SDK Client\n readonly #myxClient: MyxClient;\n\n // Configuration\n readonly #isTestnet: boolean;\n\n readonly #chainId: number;\n\n // Price polling (sequential using setTimeout to prevent request pileup)\n #pricePollingTimeout?: ReturnType<typeof setTimeout>;\n\n #pollingSymbols: string[] = [];\n\n #pollingCallback?: PricePollingCallback;\n\n // Caches\n #marketsCache: MYXPoolSymbol[] = [];\n\n #marketsCacheTimestamp = 0;\n\n readonly #marketsCacheTtlMs = 5 * 60 * 1000; // 5 minutes\n\n // Platform dependencies\n readonly #deps: PerpsPlatformDependencies;\n\n constructor(deps: PerpsPlatformDependencies, config: MYXClientConfig) {\n this.#deps = deps;\n\n this.#isTestnet = config.isTestnet;\n this.#chainId = getMYXChainId(this.#isTestnet ? 'testnet' : 'mainnet');\n\n // Initialize MyxClient\n this.#myxClient = new MyxClient({\n chainId: this.#chainId,\n brokerAddress: '0x0000000000000000000000000000000000000000', // Not needed for read-only\n isTestnet: this.#isTestnet,\n isBetaMode: this.#isTestnet, // Use beta API for testnet\n });\n\n this.#deps.debugLogger.log('[MYXClientService] Initialized with SDK', {\n isTestnet: this.#isTestnet,\n chainId: this.#chainId,\n });\n }\n\n // ============================================================================\n // Error Context Helper\n // ============================================================================\n\n #getErrorContext(\n method: string,\n extra?: Record<string, unknown>,\n ): {\n tags?: Record<string, string | number>;\n context?: { name: string; data: Record<string, unknown> };\n } {\n return {\n tags: {\n feature: PERPS_CONSTANTS.FeatureName,\n service: 'MYXClientService',\n network: this.#isTestnet ? 'testnet' : 'mainnet',\n },\n context: {\n name: `MYXClientService.${method}`,\n data: {\n chainId: this.#chainId,\n ...extra,\n },\n },\n };\n }\n\n // ============================================================================\n // Market Operations\n // ============================================================================\n\n /**\n * Get all available markets/pools\n * Uses SDK markets.getPoolSymbolAll()\n *\n * @returns The array of available MYX pool symbols.\n */\n async getMarkets(): Promise<MYXPoolSymbol[]> {\n // Return cache if valid\n const now = Date.now();\n if (\n this.#marketsCache.length > 0 &&\n now - this.#marketsCacheTimestamp < this.#marketsCacheTtlMs\n ) {\n return this.#marketsCache;\n }\n\n try {\n this.#deps.debugLogger.log('[MYXClientService] Fetching markets via SDK');\n\n const pools = await this.#myxClient.markets.getPoolSymbolAll();\n\n // Update cache\n this.#marketsCache = pools || [];\n this.#marketsCacheTimestamp = Date.now();\n\n this.#deps.debugLogger.log('[MYXClientService] Markets fetched', {\n count: this.#marketsCache.length,\n });\n\n return this.#marketsCache;\n } catch (caughtError) {\n const wrappedError = ensureError(\n caughtError,\n 'MYXClientService.getMarkets',\n );\n this.#deps.logger.error(\n wrappedError,\n this.#getErrorContext('getMarkets'),\n );\n\n // Return stale cache if available\n if (this.#marketsCache.length > 0) {\n this.#deps.debugLogger.log(\n '[MYXClientService] Returning stale cache after error',\n );\n return this.#marketsCache;\n }\n\n throw wrappedError;\n }\n }\n\n /**\n * Get tickers for specific symbols/pools\n * Uses SDK markets.getTickerList()\n *\n * @param poolIds - The array of pool identifiers to fetch tickers for.\n * @returns The array of ticker data for the specified pools.\n */\n async getTickers(poolIds: string[]): Promise<MYXTicker[]> {\n if (poolIds.length === 0) {\n return [];\n }\n\n try {\n this.#deps.debugLogger.log(\n '[MYXClientService] Fetching tickers via SDK',\n {\n poolIds: poolIds.length,\n },\n );\n\n const tickers = await this.#myxClient.markets.getTickerList({\n chainId: this.#chainId,\n poolIds,\n });\n\n return tickers || [];\n } catch (caughtError) {\n const wrappedError = ensureError(\n caughtError,\n 'MYXClientService.getTickers',\n );\n this.#deps.logger.error(\n wrappedError,\n this.#getErrorContext('getTickers', { poolIds }),\n );\n throw wrappedError;\n }\n }\n\n /**\n * Get all tickers (for all available markets)\n *\n * @returns The array of ticker data for all available markets.\n */\n async getAllTickers(): Promise<MYXTicker[]> {\n try {\n this.#deps.debugLogger.log(\n '[MYXClientService] Fetching all tickers via SDK',\n );\n\n // Get all pools first, then fetch tickers for them\n const pools = await this.getMarkets();\n const poolIds = pools.map((pool) => pool.poolId);\n\n if (poolIds.length === 0) {\n return [];\n }\n\n return this.getTickers(poolIds);\n } catch (caughtError) {\n const wrappedError = ensureError(\n caughtError,\n 'MYXClientService.getAllTickers',\n );\n this.#deps.logger.error(\n wrappedError,\n this.#getErrorContext('getAllTickers'),\n );\n throw wrappedError;\n }\n }\n\n // ============================================================================\n // Price Polling\n // ============================================================================\n\n /**\n * Start polling for price updates.\n * Uses sequential setTimeout to prevent request pileup — the next poll\n * is only scheduled after the current one completes (or fails).\n *\n * @param poolIds - The array of pool identifiers to poll prices for.\n * @param callback - The callback invoked with updated ticker data on each poll.\n */\n startPricePolling(poolIds: string[], callback: PricePollingCallback): void {\n // Stop existing polling\n this.stopPricePolling();\n\n this.#pollingSymbols = poolIds;\n this.#pollingCallback = callback;\n\n // Fetch immediately, then schedule subsequent polls\n this.#pollPrices().catch(() => {\n // Error handling is done inside #pollPrices\n });\n\n this.#deps.debugLogger.log('[MYXClientService] Started price polling', {\n symbols: poolIds.length,\n intervalMs: MYX_PRICE_POLLING_INTERVAL_MS,\n });\n }\n\n /**\n * Stop price polling\n */\n stopPricePolling(): void {\n if (this.#pricePollingTimeout) {\n clearTimeout(this.#pricePollingTimeout);\n this.#pricePollingTimeout = undefined;\n }\n this.#pollingSymbols = [];\n this.#pollingCallback = undefined;\n\n this.#deps.debugLogger.log('[MYXClientService] Stopped price polling');\n }\n\n /**\n * Execute a single price poll, then schedule the next one.\n * Sequential pattern ensures no request pileup if polls take longer than the interval.\n */\n async #pollPrices(): Promise<void> {\n if (!this.#pollingCallback || this.#pollingSymbols.length === 0) {\n return;\n }\n\n try {\n const tickers = await this.getTickers(this.#pollingSymbols);\n // Re-check: polling may have been stopped during the await\n // (TS narrows after early return but can't track mutations across await)\n const callback = this.#pollingCallback;\n if (callback) {\n callback(tickers);\n }\n } catch (caughtError) {\n const wrappedError = ensureError(\n caughtError,\n 'MYXClientService.pollPrices',\n );\n this.#deps.debugLogger.log('[MYXClientService] Price poll failed', {\n error: wrappedError.message,\n });\n // Don't propagate error - polling continues\n } finally {\n this.#scheduleNextPoll();\n }\n }\n\n /**\n * Schedule the next poll after the configured interval\n */\n #scheduleNextPoll(): void {\n // Only schedule if polling is still active\n if (!this.#pollingCallback || this.#pollingSymbols.length === 0) {\n return;\n }\n\n this.#pricePollingTimeout = setTimeout(() => {\n this.#pollPrices().catch(() => {\n // Error handling is done inside #pollPrices\n });\n }, MYX_PRICE_POLLING_INTERVAL_MS);\n }\n\n // ============================================================================\n // Health Check\n // ============================================================================\n\n /**\n * Health check — attempts a lightweight REST call (getTickerList with empty poolIds)\n * to verify the MYX API is reachable.\n *\n * @param timeoutMs - The timeout in milliseconds for the ping request.\n */\n async ping(timeoutMs = 5000): Promise<void> {\n this.#deps.debugLogger.log(\n '[MYXClientService] Ping - checking REST health',\n );\n\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n const timeoutPromise = new Promise<never>((_resolve, reject) => {\n timeoutId = setTimeout(\n () => reject(new Error('MYX ping timeout')),\n timeoutMs,\n );\n });\n\n try {\n await Promise.race([\n this.#myxClient.markets.getTickerList({\n chainId: this.#chainId,\n poolIds: [],\n }),\n timeoutPromise,\n ]);\n } catch (caughtError) {\n const wrappedError = ensureError(caughtError, 'MYXClientService.ping');\n this.#deps.debugLogger.log('[MYXClientService] Ping failed', {\n error: wrappedError.message,\n });\n throw wrappedError;\n } finally {\n clearTimeout(timeoutId);\n }\n }\n\n // ============================================================================\n // Lifecycle\n // ============================================================================\n\n /**\n * Disconnect and cleanup\n */\n disconnect(): void {\n this.stopPricePolling();\n this.#marketsCache = [];\n this.#marketsCacheTimestamp = 0;\n\n this.#deps.debugLogger.log('[MYXClientService] Disconnected');\n }\n\n /**\n * Get current network mode\n *\n * @returns True if the service is in testnet mode.\n */\n getIsTestnet(): boolean {\n return this.#isTestnet;\n }\n}\n"]}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MYXClientService
|
|
3
|
-
*
|
|
4
|
-
* Stage 1 service for fetching MYX market data using the @myx-trade/sdk.
|
|
5
|
-
* Handles market listing, ticker fetching, and price polling.
|
|
6
|
-
*
|
|
7
|
-
* Uses MyxClient SDK for API calls.
|
|
8
|
-
* Trading functionality will be added in Stage 3.
|
|
9
|
-
*/
|
|
10
|
-
import type { PerpsPlatformDependencies } from "../types/index.cjs";
|
|
11
|
-
import type { MYXPoolSymbol, MYXTicker } from "../types/myx-types.cjs";
|
|
12
|
-
/**
|
|
13
|
-
* MYX Client Configuration
|
|
14
|
-
*/
|
|
15
|
-
export type MYXClientConfig = {
|
|
16
|
-
isTestnet: boolean;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Price polling callback type
|
|
20
|
-
*/
|
|
21
|
-
export type PricePollingCallback = (tickers: MYXTicker[]) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Service for managing MYX SDK client interactions
|
|
24
|
-
* Stage 1: Read-only operations (markets, prices)
|
|
25
|
-
*/
|
|
26
|
-
export declare class MYXClientService {
|
|
27
|
-
#private;
|
|
28
|
-
constructor(deps: PerpsPlatformDependencies, config: MYXClientConfig);
|
|
29
|
-
/**
|
|
30
|
-
* Get all available markets/pools
|
|
31
|
-
* Uses SDK markets.getPoolSymbolAll()
|
|
32
|
-
*
|
|
33
|
-
* @returns The array of available MYX pool symbols.
|
|
34
|
-
*/
|
|
35
|
-
getMarkets(): Promise<MYXPoolSymbol[]>;
|
|
36
|
-
/**
|
|
37
|
-
* Get tickers for specific symbols/pools
|
|
38
|
-
* Uses SDK markets.getTickerList()
|
|
39
|
-
*
|
|
40
|
-
* @param poolIds - The array of pool identifiers to fetch tickers for.
|
|
41
|
-
* @returns The array of ticker data for the specified pools.
|
|
42
|
-
*/
|
|
43
|
-
getTickers(poolIds: string[]): Promise<MYXTicker[]>;
|
|
44
|
-
/**
|
|
45
|
-
* Get all tickers (for all available markets)
|
|
46
|
-
*
|
|
47
|
-
* @returns The array of ticker data for all available markets.
|
|
48
|
-
*/
|
|
49
|
-
getAllTickers(): Promise<MYXTicker[]>;
|
|
50
|
-
/**
|
|
51
|
-
* Start polling for price updates.
|
|
52
|
-
* Uses sequential setTimeout to prevent request pileup — the next poll
|
|
53
|
-
* is only scheduled after the current one completes (or fails).
|
|
54
|
-
*
|
|
55
|
-
* @param poolIds - The array of pool identifiers to poll prices for.
|
|
56
|
-
* @param callback - The callback invoked with updated ticker data on each poll.
|
|
57
|
-
*/
|
|
58
|
-
startPricePolling(poolIds: string[], callback: PricePollingCallback): void;
|
|
59
|
-
/**
|
|
60
|
-
* Stop price polling
|
|
61
|
-
*/
|
|
62
|
-
stopPricePolling(): void;
|
|
63
|
-
/**
|
|
64
|
-
* Health check — attempts a lightweight REST call (getTickerList with empty poolIds)
|
|
65
|
-
* to verify the MYX API is reachable.
|
|
66
|
-
*
|
|
67
|
-
* @param timeoutMs - The timeout in milliseconds for the ping request.
|
|
68
|
-
*/
|
|
69
|
-
ping(timeoutMs?: number): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Disconnect and cleanup
|
|
72
|
-
*/
|
|
73
|
-
disconnect(): void;
|
|
74
|
-
/**
|
|
75
|
-
* Get current network mode
|
|
76
|
-
*
|
|
77
|
-
* @returns True if the service is in testnet mode.
|
|
78
|
-
*/
|
|
79
|
-
getIsTestnet(): boolean;
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=MYXClientService.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MYXClientService.d.cts","sourceRoot":"","sources":["../../src/services/MYXClientService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,KAAK,EAAE,yBAAyB,EAAE,2BAAiB;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,+BAA2B;AAOnE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;AAMlE;;;GAGG;AACH,qBAAa,gBAAgB;;gBA0Bf,IAAI,EAAE,yBAAyB,EAAE,MAAM,EAAE,eAAe;IAmDpE;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IA8C5C;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAgCzD;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAgC3C;;;;;;;OAOG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,oBAAoB,GAAG,IAAI;IAkB1E;;OAEG;IACH,gBAAgB,IAAI,IAAI;IA8DxB;;;;;OAKG;IACG,IAAI,CAAC,SAAS,SAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC3C;;OAEG;IACH,UAAU,IAAI,IAAI;IAQlB;;;;OAIG;IACH,YAAY,IAAI,OAAO;CAGxB"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MYXClientService
|
|
3
|
-
*
|
|
4
|
-
* Stage 1 service for fetching MYX market data using the @myx-trade/sdk.
|
|
5
|
-
* Handles market listing, ticker fetching, and price polling.
|
|
6
|
-
*
|
|
7
|
-
* Uses MyxClient SDK for API calls.
|
|
8
|
-
* Trading functionality will be added in Stage 3.
|
|
9
|
-
*/
|
|
10
|
-
import type { PerpsPlatformDependencies } from "../types/index.mjs";
|
|
11
|
-
import type { MYXPoolSymbol, MYXTicker } from "../types/myx-types.mjs";
|
|
12
|
-
/**
|
|
13
|
-
* MYX Client Configuration
|
|
14
|
-
*/
|
|
15
|
-
export type MYXClientConfig = {
|
|
16
|
-
isTestnet: boolean;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Price polling callback type
|
|
20
|
-
*/
|
|
21
|
-
export type PricePollingCallback = (tickers: MYXTicker[]) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Service for managing MYX SDK client interactions
|
|
24
|
-
* Stage 1: Read-only operations (markets, prices)
|
|
25
|
-
*/
|
|
26
|
-
export declare class MYXClientService {
|
|
27
|
-
#private;
|
|
28
|
-
constructor(deps: PerpsPlatformDependencies, config: MYXClientConfig);
|
|
29
|
-
/**
|
|
30
|
-
* Get all available markets/pools
|
|
31
|
-
* Uses SDK markets.getPoolSymbolAll()
|
|
32
|
-
*
|
|
33
|
-
* @returns The array of available MYX pool symbols.
|
|
34
|
-
*/
|
|
35
|
-
getMarkets(): Promise<MYXPoolSymbol[]>;
|
|
36
|
-
/**
|
|
37
|
-
* Get tickers for specific symbols/pools
|
|
38
|
-
* Uses SDK markets.getTickerList()
|
|
39
|
-
*
|
|
40
|
-
* @param poolIds - The array of pool identifiers to fetch tickers for.
|
|
41
|
-
* @returns The array of ticker data for the specified pools.
|
|
42
|
-
*/
|
|
43
|
-
getTickers(poolIds: string[]): Promise<MYXTicker[]>;
|
|
44
|
-
/**
|
|
45
|
-
* Get all tickers (for all available markets)
|
|
46
|
-
*
|
|
47
|
-
* @returns The array of ticker data for all available markets.
|
|
48
|
-
*/
|
|
49
|
-
getAllTickers(): Promise<MYXTicker[]>;
|
|
50
|
-
/**
|
|
51
|
-
* Start polling for price updates.
|
|
52
|
-
* Uses sequential setTimeout to prevent request pileup — the next poll
|
|
53
|
-
* is only scheduled after the current one completes (or fails).
|
|
54
|
-
*
|
|
55
|
-
* @param poolIds - The array of pool identifiers to poll prices for.
|
|
56
|
-
* @param callback - The callback invoked with updated ticker data on each poll.
|
|
57
|
-
*/
|
|
58
|
-
startPricePolling(poolIds: string[], callback: PricePollingCallback): void;
|
|
59
|
-
/**
|
|
60
|
-
* Stop price polling
|
|
61
|
-
*/
|
|
62
|
-
stopPricePolling(): void;
|
|
63
|
-
/**
|
|
64
|
-
* Health check — attempts a lightweight REST call (getTickerList with empty poolIds)
|
|
65
|
-
* to verify the MYX API is reachable.
|
|
66
|
-
*
|
|
67
|
-
* @param timeoutMs - The timeout in milliseconds for the ping request.
|
|
68
|
-
*/
|
|
69
|
-
ping(timeoutMs?: number): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Disconnect and cleanup
|
|
72
|
-
*/
|
|
73
|
-
disconnect(): void;
|
|
74
|
-
/**
|
|
75
|
-
* Get current network mode
|
|
76
|
-
*
|
|
77
|
-
* @returns True if the service is in testnet mode.
|
|
78
|
-
*/
|
|
79
|
-
getIsTestnet(): boolean;
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=MYXClientService.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MYXClientService.d.mts","sourceRoot":"","sources":["../../src/services/MYXClientService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,KAAK,EAAE,yBAAyB,EAAE,2BAAiB;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,+BAA2B;AAOnE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;AAMlE;;;GAGG;AACH,qBAAa,gBAAgB;;gBA0Bf,IAAI,EAAE,yBAAyB,EAAE,MAAM,EAAE,eAAe;IAmDpE;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IA8C5C;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAgCzD;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAgC3C;;;;;;;OAOG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,oBAAoB,GAAG,IAAI;IAkB1E;;OAEG;IACH,gBAAgB,IAAI,IAAI;IA8DxB;;;;;OAKG;IACG,IAAI,CAAC,SAAS,SAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC3C;;OAEG;IACH,UAAU,IAAI,IAAI;IAQlB;;;;OAIG;IACH,YAAY,IAAI,OAAO;CAGxB"}
|