@steerprotocol/app-loader 2.1.1 → 3.0.0
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/README.md +137 -1
- package/lib/{WasmModule.d.ts → WasmModule-MhaHnYBX.d.mts} +21 -2
- package/lib/{esm/WasmModule.d.ts → WasmModule-MhaHnYBX.d.ts} +21 -2
- package/lib/browser.mjs +559 -0
- package/lib/browser.mjs.map +1 -0
- package/lib/index.cjs +623 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.mts +20 -0
- package/lib/index.d.ts +10 -8
- package/lib/index.mjs +600 -0
- package/lib/index.mjs.map +1 -0
- package/lib/node.cjs +607 -0
- package/lib/node.cjs.map +1 -0
- package/lib/node.d.mts +19 -0
- package/lib/node.d.ts +19 -0
- package/lib/node.mjs +567 -0
- package/lib/node.mjs.map +1 -0
- package/package.json +27 -13
- package/lib/Candle.d.ts +0 -14
- package/lib/Candle.js +0 -79
- package/lib/RawTradeData.d.ts +0 -6
- package/lib/RawTradeData.js +0 -11
- package/lib/WasmModule.js +0 -2
- package/lib/esm/Candle.d.ts +0 -14
- package/lib/esm/Candle.js +0 -75
- package/lib/esm/RawTradeData.d.ts +0 -6
- package/lib/esm/RawTradeData.js +0 -10
- package/lib/esm/WasmModule.js +0 -1
- package/lib/esm/index.d.ts +0 -18
- package/lib/esm/index.js +0 -397
- package/lib/esm/package.json +0 -1
- package/lib/esm/timestring.d.ts +0 -9
- package/lib/esm/timestring.js +0 -83
- package/lib/index.js +0 -439
- package/lib/timestring.d.ts +0 -9
- package/lib/timestring.js +0 -86
package/lib/browser.mjs
ADDED
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
// src/internal/instantiate.ts
|
|
2
|
+
import { ethers } from "ethers";
|
|
3
|
+
|
|
4
|
+
// src/timestring.ts
|
|
5
|
+
var DEFAULT_OPTS = {
|
|
6
|
+
hoursPerDay: 24,
|
|
7
|
+
daysPerWeek: 7,
|
|
8
|
+
weeksPerMonth: 4,
|
|
9
|
+
monthsPerYear: 12,
|
|
10
|
+
daysPerYear: 365.25
|
|
11
|
+
};
|
|
12
|
+
var UNIT_MAP = {
|
|
13
|
+
ms: ["ms", "milli", "millisecond", "milliseconds"],
|
|
14
|
+
s: ["s", "sec", "secs", "second", "seconds"],
|
|
15
|
+
m: ["m", "min", "mins", "minute", "minutes"],
|
|
16
|
+
h: ["h", "hr", "hrs", "hour", "hours"],
|
|
17
|
+
d: ["d", "day", "days"],
|
|
18
|
+
w: ["w", "week", "weeks"],
|
|
19
|
+
mth: ["mon", "mth", "mths", "month", "months"],
|
|
20
|
+
y: ["y", "yr", "yrs", "year", "years"]
|
|
21
|
+
};
|
|
22
|
+
function parseTimestring(value, returnUnit, opts) {
|
|
23
|
+
const options = Object.assign({}, DEFAULT_OPTS, opts || {});
|
|
24
|
+
let strValue;
|
|
25
|
+
if (typeof value === "number") {
|
|
26
|
+
strValue = parseInt(value.toString()) + "ms";
|
|
27
|
+
} else if (value.match(/^[-+]?[0-9.]+$/g)) {
|
|
28
|
+
strValue = parseInt(value) + "ms";
|
|
29
|
+
} else {
|
|
30
|
+
strValue = value;
|
|
31
|
+
}
|
|
32
|
+
let totalSeconds = 0;
|
|
33
|
+
const unitValues = getUnitValues(options);
|
|
34
|
+
const groups = strValue.toLowerCase().replace(/[^.\w+-]+/g, "").match(/[-+]?[0-9.]+[a-z]+/g);
|
|
35
|
+
if (groups === null) {
|
|
36
|
+
throw new Error(`The value [${strValue}] could not be parsed by timestring`);
|
|
37
|
+
}
|
|
38
|
+
groups.forEach((group) => {
|
|
39
|
+
const valMatch = group.match(/[0-9.]+/g);
|
|
40
|
+
const unitMatch = group.match(/[a-z]+/g);
|
|
41
|
+
if (valMatch && unitMatch) {
|
|
42
|
+
const val = parseFloat(valMatch[0]);
|
|
43
|
+
const unit = unitMatch[0];
|
|
44
|
+
totalSeconds += getSeconds(val, unit, unitValues);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (returnUnit) {
|
|
48
|
+
return convert(totalSeconds, returnUnit, unitValues);
|
|
49
|
+
}
|
|
50
|
+
return totalSeconds;
|
|
51
|
+
}
|
|
52
|
+
function getUnitValues(opts) {
|
|
53
|
+
const unitValues = {
|
|
54
|
+
ms: 1e-3,
|
|
55
|
+
s: 1,
|
|
56
|
+
m: 60,
|
|
57
|
+
h: 3600,
|
|
58
|
+
d: 0,
|
|
59
|
+
w: 0,
|
|
60
|
+
mth: 0,
|
|
61
|
+
y: 0
|
|
62
|
+
};
|
|
63
|
+
unitValues.d = opts.hoursPerDay * unitValues.h;
|
|
64
|
+
unitValues.w = opts.daysPerWeek * unitValues.d;
|
|
65
|
+
unitValues.mth = opts.daysPerYear / opts.monthsPerYear * unitValues.d;
|
|
66
|
+
unitValues.y = opts.daysPerYear * unitValues.d;
|
|
67
|
+
return unitValues;
|
|
68
|
+
}
|
|
69
|
+
function getUnitKey(unit) {
|
|
70
|
+
for (const key of Object.keys(UNIT_MAP)) {
|
|
71
|
+
if (UNIT_MAP[key].indexOf(unit) > -1) {
|
|
72
|
+
return key;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`The unit [${unit}] is not supported by timestring`);
|
|
76
|
+
}
|
|
77
|
+
function getSeconds(value, unit, unitValues) {
|
|
78
|
+
return value * unitValues[getUnitKey(unit)];
|
|
79
|
+
}
|
|
80
|
+
function convert(value, unit, unitValues) {
|
|
81
|
+
return value / unitValues[getUnitKey(unit)];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/Candle.ts
|
|
85
|
+
var Candle = class {
|
|
86
|
+
constructor(timestamp, high, low, open, close, volume) {
|
|
87
|
+
this.timestamp = timestamp;
|
|
88
|
+
this.high = high;
|
|
89
|
+
this.low = low;
|
|
90
|
+
this.open = open;
|
|
91
|
+
this.close = close;
|
|
92
|
+
this.volume = volume;
|
|
93
|
+
}
|
|
94
|
+
toString() {
|
|
95
|
+
return JSON.stringify(this);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
function generateCandles(data, candleSize) {
|
|
99
|
+
const candleWidth = parseTimestring(candleSize, "ms", {});
|
|
100
|
+
if (data.length === 0) {
|
|
101
|
+
throw new Error("Input data is empty");
|
|
102
|
+
}
|
|
103
|
+
const _data = data.map((point) => {
|
|
104
|
+
return Object.assign(Object.assign({}, point), {
|
|
105
|
+
// This will convert the timestamp to milliseconds if it's in seconds
|
|
106
|
+
timestamp: point.timestamp && String(point.timestamp).length == 10 ? point.timestamp * 1e3 : point.timestamp
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
if (_data[0] === void 0 || Object.keys(_data[0]).length === 0) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
const ohlcvData = [];
|
|
113
|
+
let i = 0;
|
|
114
|
+
let currentTimestamp = Math.floor(_data[0].timestamp / candleWidth) * candleWidth;
|
|
115
|
+
let open = _data[0].price;
|
|
116
|
+
let high = _data[0].price;
|
|
117
|
+
let low = _data[0].price;
|
|
118
|
+
let close = _data[0].price;
|
|
119
|
+
let volume = 0;
|
|
120
|
+
while (i < _data.length) {
|
|
121
|
+
open = close;
|
|
122
|
+
high = close;
|
|
123
|
+
low = close;
|
|
124
|
+
volume = 0;
|
|
125
|
+
let innerI = i;
|
|
126
|
+
while (innerI < _data.length && _data[innerI].timestamp < currentTimestamp + candleWidth) {
|
|
127
|
+
open = innerI === 0 ? _data[innerI].price : open;
|
|
128
|
+
high = Math.max(high, _data[innerI].price);
|
|
129
|
+
low = Math.min(low, _data[innerI].price);
|
|
130
|
+
close = _data[innerI].price;
|
|
131
|
+
volume += _data[innerI].volume;
|
|
132
|
+
innerI++;
|
|
133
|
+
}
|
|
134
|
+
ohlcvData.push({
|
|
135
|
+
timestamp: currentTimestamp,
|
|
136
|
+
high,
|
|
137
|
+
low,
|
|
138
|
+
open,
|
|
139
|
+
close,
|
|
140
|
+
volume
|
|
141
|
+
});
|
|
142
|
+
currentTimestamp += candleWidth;
|
|
143
|
+
i = innerI;
|
|
144
|
+
}
|
|
145
|
+
return ohlcvData;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/RawTradeData.ts
|
|
149
|
+
var RawTradeData = class {
|
|
150
|
+
constructor(timestamp, price, volume) {
|
|
151
|
+
this.timestamp = timestamp;
|
|
152
|
+
this.price = price;
|
|
153
|
+
this.volume = volume;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/internal/instantiate.ts
|
|
158
|
+
function instantiate(module, imports = {}, runtime = {}) {
|
|
159
|
+
let WASM_MEMORY;
|
|
160
|
+
let WASM_EXPORTS;
|
|
161
|
+
let WASM_DV;
|
|
162
|
+
let ASYNCIFY_PTR = 0;
|
|
163
|
+
let ASYNCIFY_MEM;
|
|
164
|
+
let ASYNCIFY_INITIALIZED = false;
|
|
165
|
+
let fetchFn = null;
|
|
166
|
+
let ccxtFn = null;
|
|
167
|
+
let detachedValue = null;
|
|
168
|
+
const adaptedImports = Object.assign(
|
|
169
|
+
{
|
|
170
|
+
console: {
|
|
171
|
+
log(text) {
|
|
172
|
+
console.log(__liftString(text));
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
ethers: {
|
|
176
|
+
keccak256_str(str_ptr) {
|
|
177
|
+
const str = __liftString(str_ptr);
|
|
178
|
+
const hash = ethers.keccak256(str);
|
|
179
|
+
return __lowerString(hash);
|
|
180
|
+
},
|
|
181
|
+
keccak256_buf(buf_ptr) {
|
|
182
|
+
const buf = __liftBuffer(buf_ptr);
|
|
183
|
+
const hash = ethers.keccak256(new Uint8Array(buf));
|
|
184
|
+
return __lowerString(hash);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
env: {
|
|
189
|
+
abort(message, fileName, lineNumber, columnNumber) {
|
|
190
|
+
(() => {
|
|
191
|
+
throw Error(`${__liftString(message)} in ${__liftString(fileName)}:${lineNumber}:${columnNumber}`);
|
|
192
|
+
})();
|
|
193
|
+
},
|
|
194
|
+
_initAsyncify(frame_ptr, stack_ptr) {
|
|
195
|
+
if (!WASM_EXPORTS["asyncify_get_state"])
|
|
196
|
+
throw new Error(
|
|
197
|
+
"Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!"
|
|
198
|
+
);
|
|
199
|
+
if (ASYNCIFY_INITIALIZED) return;
|
|
200
|
+
ASYNCIFY_PTR = frame_ptr;
|
|
201
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
202
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR + 4 >> 2] = stack_ptr;
|
|
203
|
+
ASYNCIFY_INITIALIZED = true;
|
|
204
|
+
},
|
|
205
|
+
generateCandles(data, candleSize) {
|
|
206
|
+
const _data = __liftString(data) || "[]";
|
|
207
|
+
const _candleSize = __liftString(candleSize) || "69m";
|
|
208
|
+
const candles = generateCandles(JSON.parse(_data), _candleSize);
|
|
209
|
+
return __lowerString(JSON.stringify(candles));
|
|
210
|
+
},
|
|
211
|
+
"console.log": (text) => {
|
|
212
|
+
console.log(__liftString(text));
|
|
213
|
+
},
|
|
214
|
+
ccxt_fetchOHLCV: (exchangeId, symbol, timeframe, limit, since) => {
|
|
215
|
+
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
216
|
+
if (currentState === 2 /* Rewinding */) {
|
|
217
|
+
WASM_EXPORTS.asyncify_stop_rewind();
|
|
218
|
+
const ptr = __lowerStaticArray(
|
|
219
|
+
(pointer, value) => {
|
|
220
|
+
__setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array));
|
|
221
|
+
},
|
|
222
|
+
8,
|
|
223
|
+
2,
|
|
224
|
+
detachedValue
|
|
225
|
+
);
|
|
226
|
+
return ptr;
|
|
227
|
+
}
|
|
228
|
+
const _exchange = __liftString(exchangeId);
|
|
229
|
+
const _symbol = __liftString(symbol);
|
|
230
|
+
const _timeframe = __liftString(timeframe);
|
|
231
|
+
ccxtFn = async () => {
|
|
232
|
+
if (!_exchange || !_symbol || !_timeframe)
|
|
233
|
+
throw new Error("Exchange, Symbol, or Timeframe not provided when fetching OHCLV data.");
|
|
234
|
+
const ccxt = await getCcxtOrThrow(runtime);
|
|
235
|
+
const data = await new ccxt[_exchange]({
|
|
236
|
+
apiKey: "",
|
|
237
|
+
secret: ""
|
|
238
|
+
}).fetchOHLCV(_symbol, _timeframe, since, limit);
|
|
239
|
+
return data;
|
|
240
|
+
};
|
|
241
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
"as-fetch": {
|
|
245
|
+
_initAsyncify(frame_ptr, stack_ptr) {
|
|
246
|
+
if (!WASM_EXPORTS["asyncify_get_state"])
|
|
247
|
+
throw new Error(
|
|
248
|
+
"Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!"
|
|
249
|
+
);
|
|
250
|
+
if (ASYNCIFY_INITIALIZED) return;
|
|
251
|
+
ASYNCIFY_PTR = frame_ptr;
|
|
252
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;
|
|
253
|
+
ASYNCIFY_MEM[ASYNCIFY_PTR + 4 >> 2] = stack_ptr;
|
|
254
|
+
ASYNCIFY_INITIALIZED = true;
|
|
255
|
+
},
|
|
256
|
+
_fetchPOSTSync(url, mode, headers, body) {
|
|
257
|
+
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
258
|
+
if (currentState === 2 /* Rewinding */) {
|
|
259
|
+
WASM_EXPORTS.asyncify_stop_rewind();
|
|
260
|
+
const ptr = __lowerBuffer(detachedValue);
|
|
261
|
+
detachedValue = null;
|
|
262
|
+
return ptr;
|
|
263
|
+
}
|
|
264
|
+
fetchFn = async () => {
|
|
265
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
266
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
267
|
+
method: "POST",
|
|
268
|
+
mode: modeToString(mode) || "cors",
|
|
269
|
+
headers: __liftArray(
|
|
270
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
271
|
+
2,
|
|
272
|
+
headers
|
|
273
|
+
) || [],
|
|
274
|
+
body: __liftBuffer(body)
|
|
275
|
+
});
|
|
276
|
+
const value = await res.arrayBuffer();
|
|
277
|
+
return value;
|
|
278
|
+
};
|
|
279
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
280
|
+
},
|
|
281
|
+
_fetchGETSync(url, mode, headers) {
|
|
282
|
+
const currentState = WASM_EXPORTS.asyncify_get_state();
|
|
283
|
+
if (currentState === 2 /* Rewinding */) {
|
|
284
|
+
WASM_EXPORTS.asyncify_stop_rewind();
|
|
285
|
+
const ptr = __lowerBuffer(detachedValue);
|
|
286
|
+
detachedValue = null;
|
|
287
|
+
return ptr;
|
|
288
|
+
}
|
|
289
|
+
fetchFn = async () => {
|
|
290
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
291
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
292
|
+
method: "GET",
|
|
293
|
+
mode: modeToString(mode) || "cors",
|
|
294
|
+
headers: __liftArray(
|
|
295
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
296
|
+
2,
|
|
297
|
+
headers
|
|
298
|
+
) || []
|
|
299
|
+
});
|
|
300
|
+
const value = await res.arrayBuffer();
|
|
301
|
+
return value;
|
|
302
|
+
};
|
|
303
|
+
WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);
|
|
304
|
+
},
|
|
305
|
+
_fetchGET(url, mode, headers, callbackID) {
|
|
306
|
+
void (async () => {
|
|
307
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
308
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
309
|
+
method: "GET",
|
|
310
|
+
mode: modeToString(mode) || "cors",
|
|
311
|
+
headers: __liftArray(
|
|
312
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
313
|
+
2,
|
|
314
|
+
headers
|
|
315
|
+
) || []
|
|
316
|
+
});
|
|
317
|
+
const body = await res.arrayBuffer();
|
|
318
|
+
WASM_EXPORTS.responseHandler(body, res.status, res.redirected ? 1 : 0, callbackID);
|
|
319
|
+
})();
|
|
320
|
+
},
|
|
321
|
+
_fetchPOST(url, mode, headers, body, callbackID) {
|
|
322
|
+
void (async () => {
|
|
323
|
+
const fetchImpl = await getFetchOrThrow(runtime);
|
|
324
|
+
const res = await fetchImpl(__liftString(url) || "", {
|
|
325
|
+
method: "POST",
|
|
326
|
+
mode: modeToString(mode) || "cors",
|
|
327
|
+
body,
|
|
328
|
+
headers: __liftArray(
|
|
329
|
+
(pointer) => __liftArray((pointer2) => __liftString(__getU32(pointer2)), 2, __getU32(pointer)),
|
|
330
|
+
2,
|
|
331
|
+
headers
|
|
332
|
+
) || []
|
|
333
|
+
});
|
|
334
|
+
const responseBody = await res.arrayBuffer();
|
|
335
|
+
WASM_EXPORTS.responseHandler(responseBody, res.status, res.redirected ? 1 : 0, callbackID);
|
|
336
|
+
})();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
imports
|
|
341
|
+
);
|
|
342
|
+
const mod = new WebAssembly.Instance(module, adaptedImports);
|
|
343
|
+
WASM_EXPORTS = mod.exports;
|
|
344
|
+
WASM_MEMORY = WASM_EXPORTS.memory || adaptedImports.env.memory;
|
|
345
|
+
ASYNCIFY_MEM = new Uint32Array(WASM_MEMORY.buffer);
|
|
346
|
+
const handledExports = Object.setPrototypeOf(
|
|
347
|
+
{
|
|
348
|
+
responseHandler(body, statusCode, redirected, callbackID) {
|
|
349
|
+
if (!WASM_EXPORTS["responseHandler"])
|
|
350
|
+
throw new Error(
|
|
351
|
+
'Unable to call .responseHandler on wasm module. Add the line export { responseHandler } from "as-fetch/assembly" to your entry file.'
|
|
352
|
+
);
|
|
353
|
+
WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
|
|
354
|
+
},
|
|
355
|
+
initialize(config) {
|
|
356
|
+
if (!WASM_EXPORTS["initialize"])
|
|
357
|
+
throw new Error("Unable to call .initialize on wasm module. Are you sure this is a data connector?");
|
|
358
|
+
try {
|
|
359
|
+
WASM_EXPORTS.initialize(__lowerString(config));
|
|
360
|
+
return true;
|
|
361
|
+
} catch (e) {
|
|
362
|
+
console.error(e);
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
async execute(...params) {
|
|
367
|
+
if (!WASM_EXPORTS["execute"])
|
|
368
|
+
throw new Error("Unable to call .execute on wasm module. Are you sure this is a data connector?");
|
|
369
|
+
const loweredArgs = new Array(params.length);
|
|
370
|
+
for (let i = 0; i < params.length; i++) {
|
|
371
|
+
loweredArgs[i] = __lower(params[i]);
|
|
372
|
+
}
|
|
373
|
+
let result;
|
|
374
|
+
try {
|
|
375
|
+
result = WASM_EXPORTS.execute(...loweredArgs);
|
|
376
|
+
} catch (error) {
|
|
377
|
+
if (params.length !== 0) {
|
|
378
|
+
throw error;
|
|
379
|
+
}
|
|
380
|
+
result = WASM_EXPORTS.execute(__lowerString(""));
|
|
381
|
+
}
|
|
382
|
+
if (ASYNCIFY_INITIALIZED) {
|
|
383
|
+
while (WASM_EXPORTS.asyncify_get_state() === 1 /* Unwinding */) {
|
|
384
|
+
WASM_EXPORTS.asyncify_stop_unwind();
|
|
385
|
+
if (fetchFn) detachedValue = await fetchFn();
|
|
386
|
+
if (ccxtFn) detachedValue = await ccxtFn();
|
|
387
|
+
WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
388
|
+
result = WASM_EXPORTS.execute();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (fetchFn) fetchFn = null;
|
|
392
|
+
if (ccxtFn) ccxtFn = null;
|
|
393
|
+
return __liftString(result);
|
|
394
|
+
},
|
|
395
|
+
config() {
|
|
396
|
+
if (!WASM_EXPORTS["config"])
|
|
397
|
+
throw new Error("Unable to call .config on wasm module. Are you sure this is a data connector?");
|
|
398
|
+
return __liftString(WASM_EXPORTS.config());
|
|
399
|
+
},
|
|
400
|
+
transform() {
|
|
401
|
+
if (!WASM_EXPORTS["transform"])
|
|
402
|
+
throw new Error("Unable to call .transform on wasm module. Are you sure this is a data connector?");
|
|
403
|
+
return __liftString(WASM_EXPORTS.transform());
|
|
404
|
+
},
|
|
405
|
+
reset() {
|
|
406
|
+
if (WASM_EXPORTS["reset"]) WASM_EXPORTS.reset();
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
WASM_EXPORTS
|
|
410
|
+
);
|
|
411
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
412
|
+
function __lower(val) {
|
|
413
|
+
if (typeof val === "number") {
|
|
414
|
+
return val;
|
|
415
|
+
} else if (typeof val === "string") {
|
|
416
|
+
return __lowerString(val);
|
|
417
|
+
} else if (val instanceof ArrayBuffer) {
|
|
418
|
+
return __lowerBuffer(val);
|
|
419
|
+
} else {
|
|
420
|
+
return 0;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function __liftString(ptr) {
|
|
424
|
+
if (!ptr) return null;
|
|
425
|
+
const end = ptr + new Uint32Array(WASM_MEMORY.buffer)[ptr - 4 >>> 2] >>> 1;
|
|
426
|
+
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
427
|
+
let start = ptr >>> 1;
|
|
428
|
+
let string = "";
|
|
429
|
+
while (end - start > 1024) string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
|
|
430
|
+
return string + String.fromCharCode(...memoryU16.subarray(start, end));
|
|
431
|
+
}
|
|
432
|
+
function __lowerString(value) {
|
|
433
|
+
if (value == null) return 0;
|
|
434
|
+
const length = value.length;
|
|
435
|
+
const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << 1, 2) >>> 0);
|
|
436
|
+
const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);
|
|
437
|
+
for (let i = 0; i < length; ++i) memoryU16[(ptr >>> 1) + i] = value.charCodeAt(i);
|
|
438
|
+
return ptr;
|
|
439
|
+
}
|
|
440
|
+
function __liftBuffer(ptr) {
|
|
441
|
+
if (!ptr) return null;
|
|
442
|
+
return WASM_MEMORY.buffer.slice(ptr, ptr + new Uint32Array(WASM_MEMORY.buffer)[ptr - 4 >>> 2]);
|
|
443
|
+
}
|
|
444
|
+
function __lowerBuffer(value) {
|
|
445
|
+
if (value == null) return 0;
|
|
446
|
+
const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(value.byteLength, 1) >>> 0);
|
|
447
|
+
new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(value), ptr);
|
|
448
|
+
return ptr;
|
|
449
|
+
}
|
|
450
|
+
function __liftArray(liftElement, align, ptr) {
|
|
451
|
+
if (!ptr) return null;
|
|
452
|
+
const dataStart = __getU32(ptr + 4);
|
|
453
|
+
const length = WASM_DV.getUint32(ptr + 12, true);
|
|
454
|
+
const values = new Array(length);
|
|
455
|
+
for (let i = 0; i < length; ++i) values[i] = liftElement(dataStart + (i << align >>> 0));
|
|
456
|
+
return values;
|
|
457
|
+
}
|
|
458
|
+
function __lowerStaticArray(lowerElement, id, align, values, typedConstructor = null) {
|
|
459
|
+
if (values == null) return 0;
|
|
460
|
+
const length = values.length;
|
|
461
|
+
const buffer = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << align, id)) >>> 0;
|
|
462
|
+
if (typedConstructor) {
|
|
463
|
+
new typedConstructor(WASM_MEMORY.buffer, buffer, length).set(values);
|
|
464
|
+
} else {
|
|
465
|
+
for (let i = 0; i < length; i++) lowerElement(buffer + (i << align >>> 0), values[i]);
|
|
466
|
+
}
|
|
467
|
+
return buffer;
|
|
468
|
+
}
|
|
469
|
+
function __setU32(ptr, value) {
|
|
470
|
+
try {
|
|
471
|
+
WASM_DV.setUint32(ptr, value, true);
|
|
472
|
+
} catch {
|
|
473
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
474
|
+
WASM_DV.setUint32(ptr, value, true);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function __setF64(ptr, value) {
|
|
478
|
+
try {
|
|
479
|
+
WASM_DV.setFloat64(ptr, value, true);
|
|
480
|
+
} catch {
|
|
481
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
482
|
+
WASM_DV.setFloat64(ptr, value, true);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function __getU32(ptr) {
|
|
486
|
+
try {
|
|
487
|
+
return WASM_DV.getUint32(ptr, true);
|
|
488
|
+
} catch {
|
|
489
|
+
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
490
|
+
return WASM_DV.getUint32(ptr, true);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return handledExports;
|
|
494
|
+
}
|
|
495
|
+
async function getFetchOrThrow(runtime) {
|
|
496
|
+
if (!runtime.getFetch) {
|
|
497
|
+
throw new Error("Fetch is not available in this runtime.");
|
|
498
|
+
}
|
|
499
|
+
return runtime.getFetch();
|
|
500
|
+
}
|
|
501
|
+
async function getCcxtOrThrow(runtime) {
|
|
502
|
+
if (!runtime.getCcxt) {
|
|
503
|
+
throw new Error("ccxt is not available in this runtime.");
|
|
504
|
+
}
|
|
505
|
+
return runtime.getCcxt();
|
|
506
|
+
}
|
|
507
|
+
function modeToString(mode) {
|
|
508
|
+
if (mode == 1) return "cors";
|
|
509
|
+
if (mode == 2) return "no-cors";
|
|
510
|
+
if (mode == 3) return "same-origin";
|
|
511
|
+
if (mode == 4) return "navigate";
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/browser.ts
|
|
516
|
+
function loadWasmSync(input, imports = {}) {
|
|
517
|
+
return instantiate(new WebAssembly.Module(input), imports, {
|
|
518
|
+
getFetch: getBrowserFetch,
|
|
519
|
+
getCcxt: getBrowserCcxt
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
async function loadWasm(input, imports = {}) {
|
|
523
|
+
const module = typeof input === "string" ? await compileFromUrl(input) : await WebAssembly.compile(input);
|
|
524
|
+
return instantiate(module, imports, {
|
|
525
|
+
getFetch: getBrowserFetch,
|
|
526
|
+
getCcxt: getBrowserCcxt
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
async function compileFromUrl(url) {
|
|
530
|
+
const fetchImpl = await getBrowserFetch();
|
|
531
|
+
const response = await fetchImpl(url);
|
|
532
|
+
if (typeof WebAssembly.compileStreaming === "function") {
|
|
533
|
+
try {
|
|
534
|
+
return await WebAssembly.compileStreaming(Promise.resolve(response.clone()));
|
|
535
|
+
} catch {
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return WebAssembly.compile(await response.arrayBuffer());
|
|
539
|
+
}
|
|
540
|
+
async function getBrowserFetch() {
|
|
541
|
+
if (typeof globalThis.fetch !== "function") {
|
|
542
|
+
throw new Error("Fetch is not available in this browser runtime.");
|
|
543
|
+
}
|
|
544
|
+
return globalThis.fetch.bind(globalThis);
|
|
545
|
+
}
|
|
546
|
+
async function getBrowserCcxt() {
|
|
547
|
+
const ccxt = globalThis.ccxt;
|
|
548
|
+
if (!ccxt) {
|
|
549
|
+
throw new Error("ccxt is not available in this browser runtime.");
|
|
550
|
+
}
|
|
551
|
+
return ccxt;
|
|
552
|
+
}
|
|
553
|
+
export {
|
|
554
|
+
Candle,
|
|
555
|
+
RawTradeData,
|
|
556
|
+
loadWasm,
|
|
557
|
+
loadWasmSync
|
|
558
|
+
};
|
|
559
|
+
//# sourceMappingURL=browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/instantiate.ts","../src/timestring.ts","../src/Candle.ts","../src/RawTradeData.ts","../src/browser.ts"],"sourcesContent":["import { ethers } from 'ethers';\nimport { Candle, generateCandles } from '../Candle';\nimport { RawTradeData } from '../RawTradeData';\nimport type { WasmModule } from '../WasmModule';\n\nenum State {\n None = 0,\n Unwinding = 1,\n Rewinding = 2,\n}\n\ntype RuntimeAdapters = {\n getFetch?: () => Promise<typeof fetch>;\n getCcxt?: () => Promise<any>;\n};\n\nexport { Candle, RawTradeData };\nexport type { WasmModule };\n\nexport function instantiate(module: WebAssembly.Module, imports = {}, runtime: RuntimeAdapters = {}): WasmModule {\n let WASM_MEMORY: WebAssembly.Memory;\n let WASM_EXPORTS: WasmModule;\n let WASM_DV: DataView;\n\n let ASYNCIFY_PTR = 0;\n let ASYNCIFY_MEM!: Uint32Array;\n let ASYNCIFY_INITIALIZED = false;\n\n let fetchFn: (() => Promise<ArrayBuffer>) | null = null;\n let ccxtFn: (() => Promise<number[][]>) | null = null;\n\n let detachedValue: number[][] | ArrayBuffer | null = null;\n\n const adaptedImports = Object.assign(\n {\n console: {\n log(text: number) {\n console.log(__liftString(text));\n },\n },\n ethers: {\n keccak256_str(str_ptr: number) {\n const str = __liftString(str_ptr);\n const hash = ethers.keccak256(str!);\n return __lowerString(hash);\n },\n keccak256_buf(buf_ptr: number) {\n const buf = __liftBuffer(buf_ptr);\n const hash = ethers.keccak256(new Uint8Array(buf!));\n return __lowerString(hash);\n },\n },\n // @ts-ignore\n env: {\n abort(message: number, fileName: number, lineNumber: number, columnNumber: number) {\n (() => {\n throw Error(`${__liftString(message)} in ${__liftString(fileName)}:${lineNumber}:${columnNumber}`);\n })();\n },\n _initAsyncify(frame_ptr: number, stack_ptr: number) {\n // @ts-ignore\n if (!WASM_EXPORTS['asyncify_get_state'])\n throw new Error(\n 'Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!',\n );\n if (ASYNCIFY_INITIALIZED) return;\n ASYNCIFY_PTR = frame_ptr;\n ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;\n ASYNCIFY_MEM[(ASYNCIFY_PTR + 4) >> 2] = stack_ptr;\n ASYNCIFY_INITIALIZED = true;\n },\n generateCandles(data: number, candleSize: number) {\n const _data = __liftString(data) || '[]';\n const _candleSize = __liftString(candleSize) || '69m';\n const candles = generateCandles(JSON.parse(_data), _candleSize);\n return __lowerString(JSON.stringify(candles));\n },\n 'console.log': (text: number) => {\n console.log(__liftString(text));\n },\n ccxt_fetchOHLCV: (exchangeId: number, symbol: number, timeframe: number, limit: number, since: number) => {\n // @ts-ignore\n const currentState = WASM_EXPORTS.asyncify_get_state();\n if (currentState === State.Rewinding) {\n // @ts-ignore\n WASM_EXPORTS.asyncify_stop_rewind();\n // @ts-ignore\n const ptr = __lowerStaticArray(\n (pointer: number, value: any) => {\n __setU32(pointer, __lowerStaticArray(__setF64, 7, 3, value, Float64Array));\n },\n 8,\n 2,\n detachedValue as number[][],\n );\n return ptr;\n }\n\n const _exchange = __liftString(exchangeId);\n const _symbol = __liftString(symbol);\n const _timeframe = __liftString(timeframe);\n ccxtFn = async () => {\n if (!_exchange || !_symbol || !_timeframe)\n throw new Error('Exchange, Symbol, or Timeframe not provided when fetching OHCLV data.');\n\n const ccxt = await getCcxtOrThrow(runtime);\n // @ts-ignore\n const data = await new ccxt[_exchange]({\n apiKey: '',\n secret: '',\n }).fetchOHLCV(_symbol, _timeframe, since, limit);\n return data;\n };\n\n // @ts-ignore\n WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);\n },\n },\n 'as-fetch': {\n _initAsyncify(frame_ptr: number, stack_ptr: number) {\n // @ts-ignore\n if (!WASM_EXPORTS['asyncify_get_state'])\n throw new Error(\n 'Asyncify initialized, but not enabled when run! Compile with the --runPasses asyncify flag or asyncify-shim transform!',\n );\n if (ASYNCIFY_INITIALIZED) return;\n ASYNCIFY_PTR = frame_ptr;\n ASYNCIFY_MEM[ASYNCIFY_PTR >> 2] = ASYNCIFY_PTR + 8;\n ASYNCIFY_MEM[(ASYNCIFY_PTR + 4) >> 2] = stack_ptr;\n ASYNCIFY_INITIALIZED = true;\n },\n _fetchPOSTSync(url: number, mode: number, headers: number, body: number) {\n // @ts-ignore\n const currentState = WASM_EXPORTS.asyncify_get_state();\n if (currentState === State.Rewinding) {\n // @ts-ignore\n WASM_EXPORTS.asyncify_stop_rewind();\n const ptr = __lowerBuffer(detachedValue as ArrayBuffer);\n detachedValue = null;\n return ptr;\n }\n\n fetchFn = async () => {\n const fetchImpl = await getFetchOrThrow(runtime);\n const res = await fetchImpl(__liftString(url) || '', {\n method: 'POST',\n mode: modeToString(mode) || 'cors',\n headers:\n __liftArray(\n (pointer: number) =>\n __liftArray((pointer: number) => __liftString(__getU32(pointer)), 2, __getU32(pointer)),\n 2,\n headers,\n ) || [],\n body: __liftBuffer(body),\n });\n const value = await res.arrayBuffer();\n return value;\n };\n\n // @ts-ignore\n WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);\n },\n _fetchGETSync(url: number, mode: number, headers: number) {\n // @ts-ignore\n const currentState = WASM_EXPORTS.asyncify_get_state();\n if (currentState === State.Rewinding) {\n // @ts-ignore\n WASM_EXPORTS.asyncify_stop_rewind();\n const ptr = __lowerBuffer(detachedValue as ArrayBuffer);\n detachedValue = null;\n return ptr;\n }\n\n fetchFn = async () => {\n const fetchImpl = await getFetchOrThrow(runtime);\n const res = await fetchImpl(__liftString(url) || '', {\n method: 'GET',\n mode: modeToString(mode) || 'cors',\n headers:\n __liftArray(\n (pointer: number) =>\n __liftArray((pointer: number) => __liftString(__getU32(pointer)), 2, __getU32(pointer)),\n 2,\n headers,\n ) || [],\n });\n const value = await res.arrayBuffer();\n return value;\n };\n\n // @ts-ignore\n WASM_EXPORTS.asyncify_start_unwind(ASYNCIFY_PTR);\n },\n _fetchGET(url: number, mode: number, headers: number, callbackID: number) {\n void (async () => {\n const fetchImpl = await getFetchOrThrow(runtime);\n const res = await fetchImpl(__liftString(url) || '', {\n method: 'GET',\n mode: modeToString(mode) || 'cors',\n headers:\n __liftArray(\n (pointer: number) =>\n __liftArray((pointer: number) => __liftString(__getU32(pointer)), 2, __getU32(pointer)),\n 2,\n headers,\n ) || [],\n });\n const body = await res.arrayBuffer();\n WASM_EXPORTS.responseHandler(body, res.status, res.redirected ? 1 : 0, callbackID);\n })();\n },\n _fetchPOST(url: number, mode: number, headers: number, body: ArrayBuffer, callbackID: number) {\n void (async () => {\n const fetchImpl = await getFetchOrThrow(runtime);\n const res = await fetchImpl(__liftString(url) || '', {\n method: 'POST',\n mode: modeToString(mode) || 'cors',\n body: body,\n headers:\n __liftArray(\n (pointer: number) =>\n __liftArray((pointer: number) => __liftString(__getU32(pointer)), 2, __getU32(pointer)),\n 2,\n headers,\n ) || [],\n });\n const responseBody = await res.arrayBuffer();\n WASM_EXPORTS.responseHandler(responseBody, res.status, res.redirected ? 1 : 0, callbackID);\n })();\n },\n },\n },\n imports,\n );\n\n const mod = new WebAssembly.Instance(module, adaptedImports) as unknown as { exports: WasmModule };\n WASM_EXPORTS = mod.exports;\n // @ts-ignore\n WASM_MEMORY = WASM_EXPORTS.memory || adaptedImports.env.memory;\n\n ASYNCIFY_MEM = new Uint32Array(WASM_MEMORY.buffer);\n\n const handledExports = Object.setPrototypeOf(\n {\n responseHandler(body: ArrayBuffer, statusCode: number, redirected: boolean, callbackID: number) {\n if (!WASM_EXPORTS['responseHandler'])\n throw new Error(\n 'Unable to call .responseHandler on wasm module. Add the line export { responseHandler } from \"as-fetch/assembly\" to your entry file.',\n );\n // @ts-ignore\n WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);\n },\n initialize(config: string): boolean {\n if (!WASM_EXPORTS['initialize'])\n throw new Error('Unable to call .initialize on wasm module. Are you sure this is a data connector?');\n try {\n // @ts-ignore\n WASM_EXPORTS.initialize(__lowerString(config));\n return true;\n } catch (e) {\n console.error(e);\n return false;\n }\n },\n async execute(...params: number[] | string[] | ArrayBuffer[] | null[]): Promise<string | null> {\n if (!WASM_EXPORTS['execute'])\n throw new Error('Unable to call .execute on wasm module. Are you sure this is a data connector?');\n const loweredArgs = new Array<number>(params.length);\n for (let i = 0; i < params.length; i++) {\n loweredArgs[i] = __lower(params[i]);\n }\n\n let result: unknown;\n\n try {\n result = WASM_EXPORTS.execute(...loweredArgs);\n } catch (error) {\n if (params.length !== 0) {\n throw error;\n }\n\n // Legacy v1 bundles can expect execute(\"\") for their first host-driven request.\n result = WASM_EXPORTS.execute(__lowerString(''));\n }\n\n if (ASYNCIFY_INITIALIZED) {\n // @ts-ignore\n while (WASM_EXPORTS.asyncify_get_state() === State.Unwinding) {\n // @ts-ignore\n WASM_EXPORTS.asyncify_stop_unwind();\n if (fetchFn) detachedValue = await fetchFn();\n if (ccxtFn) detachedValue = await ccxtFn();\n // @ts-ignore\n WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);\n\n result = WASM_EXPORTS.execute();\n }\n }\n if (fetchFn) fetchFn = null;\n if (ccxtFn) ccxtFn = null;\n // @ts-ignore\n return __liftString(result);\n },\n config() {\n if (!WASM_EXPORTS['config'])\n throw new Error('Unable to call .config on wasm module. Are you sure this is a data connector?');\n return __liftString(WASM_EXPORTS.config() as unknown as number);\n },\n transform() {\n if (!WASM_EXPORTS['transform'])\n throw new Error('Unable to call .transform on wasm module. Are you sure this is a data connector?');\n return __liftString(WASM_EXPORTS.transform() as unknown as number);\n },\n reset() {\n if (WASM_EXPORTS['reset']) WASM_EXPORTS.reset();\n },\n },\n WASM_EXPORTS,\n );\n\n WASM_DV = new DataView(WASM_MEMORY.buffer);\n\n function __lower(val: number | string | ArrayBuffer | null): number {\n if (typeof val === 'number') {\n return val;\n } else if (typeof val === 'string') {\n return __lowerString(val);\n } else if (val instanceof ArrayBuffer) {\n return __lowerBuffer(val);\n } else {\n return 0;\n }\n }\n\n function __liftString(ptr: number): string | null {\n if (!ptr) return null;\n const end = (ptr + new Uint32Array(WASM_MEMORY.buffer)[(ptr - 4) >>> 2]) >>> 1;\n const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);\n let start = ptr >>> 1;\n let string = '';\n while (end - start > 1024) string += String.fromCharCode(...memoryU16.subarray(start, (start += 1024)));\n return string + String.fromCharCode(...memoryU16.subarray(start, end));\n }\n\n function __lowerString(value: string): number {\n if (value == null) return 0;\n const length = value.length;\n const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << 1, 2) >>> 0);\n const memoryU16 = new Uint16Array(WASM_MEMORY.buffer);\n for (let i = 0; i < length; ++i) memoryU16[(ptr >>> 1) + i] = value.charCodeAt(i);\n return ptr;\n }\n\n function __liftBuffer(ptr: number): ArrayBuffer | null {\n if (!ptr) return null;\n return WASM_MEMORY.buffer.slice(ptr, ptr + new Uint32Array(WASM_MEMORY.buffer)[(ptr - 4) >>> 2]);\n }\n\n function __lowerBuffer(value: ArrayBuffer): number {\n if (value == null) return 0;\n const ptr = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(value.byteLength, 1) >>> 0);\n new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(value), ptr);\n return ptr;\n }\n\n function __liftArray(liftElement: Function, align: number, ptr: number): any[] | null {\n if (!ptr) return null;\n const dataStart = __getU32(ptr + 4);\n const length = WASM_DV.getUint32(ptr + 12, true);\n const values = new Array(length);\n for (let i = 0; i < length; ++i) values[i] = liftElement(dataStart + ((i << align) >>> 0));\n return values;\n }\n\n function __lowerStaticArray(\n lowerElement: Function,\n id: number,\n align: number,\n values: any[],\n typedConstructor: any | null = null,\n ) {\n if (values == null) return 0;\n const length = values.length;\n const buffer = WASM_EXPORTS.__pin(WASM_EXPORTS.__new(length << align, id)) >>> 0;\n if (typedConstructor) {\n new typedConstructor(WASM_MEMORY.buffer, buffer, length).set(values);\n } else {\n for (let i = 0; i < length; i++) lowerElement(buffer + ((i << align) >>> 0), values[i]);\n }\n return buffer;\n }\n\n function __setU32(ptr: number, value: number) {\n try {\n WASM_DV.setUint32(ptr, value, true);\n } catch {\n WASM_DV = new DataView(WASM_MEMORY.buffer);\n WASM_DV.setUint32(ptr, value, true);\n }\n }\n\n function __setF64(ptr: number, value: number) {\n try {\n WASM_DV.setFloat64(ptr, value, true);\n } catch {\n WASM_DV = new DataView(WASM_MEMORY.buffer);\n WASM_DV.setFloat64(ptr, value, true);\n }\n }\n\n function __getU32(ptr: number): number {\n try {\n return WASM_DV.getUint32(ptr, true);\n } catch {\n WASM_DV = new DataView(WASM_MEMORY.buffer);\n return WASM_DV.getUint32(ptr, true);\n }\n }\n\n return handledExports;\n}\n\nasync function getFetchOrThrow(runtime: RuntimeAdapters): Promise<typeof fetch> {\n if (!runtime.getFetch) {\n throw new Error('Fetch is not available in this runtime.');\n }\n\n return runtime.getFetch();\n}\n\nasync function getCcxtOrThrow(runtime: RuntimeAdapters): Promise<any> {\n if (!runtime.getCcxt) {\n throw new Error('ccxt is not available in this runtime.');\n }\n\n return runtime.getCcxt();\n}\n\nfunction modeToString(mode: number): RequestMode | null {\n if (mode == 1) return 'cors';\n if (mode == 2) return 'no-cors';\n if (mode == 3) return 'same-origin';\n if (mode == 4) return 'navigate';\n return null;\n}\n","interface TimestringOptions {\n hoursPerDay?: number;\n daysPerWeek?: number;\n weeksPerMonth?: number;\n monthsPerYear?: number;\n daysPerYear?: number;\n}\n\nconst DEFAULT_OPTS: Required<TimestringOptions> = {\n hoursPerDay: 24,\n daysPerWeek: 7,\n weeksPerMonth: 4,\n monthsPerYear: 12,\n daysPerYear: 365.25,\n};\n\nconst UNIT_MAP: Record<string, string[]> = {\n ms: ['ms', 'milli', 'millisecond', 'milliseconds'],\n s: ['s', 'sec', 'secs', 'second', 'seconds'],\n m: ['m', 'min', 'mins', 'minute', 'minutes'],\n h: ['h', 'hr', 'hrs', 'hour', 'hours'],\n d: ['d', 'day', 'days'],\n w: ['w', 'week', 'weeks'],\n mth: ['mon', 'mth', 'mths', 'month', 'months'],\n y: ['y', 'yr', 'yrs', 'year', 'years'],\n};\n\nexport default function parseTimestring(value: string | number, returnUnit?: string, opts?: TimestringOptions): number {\n const options = Object.assign({}, DEFAULT_OPTS, opts || {});\n\n let strValue: string;\n if (typeof value === 'number') {\n strValue = parseInt(value.toString()) + 'ms';\n } else if (value.match(/^[-+]?[0-9.]+$/g)) {\n strValue = parseInt(value) + 'ms';\n } else {\n strValue = value;\n }\n\n let totalSeconds = 0;\n const unitValues = getUnitValues(options);\n const groups = strValue\n .toLowerCase()\n .replace(/[^.\\w+-]+/g, '')\n .match(/[-+]?[0-9.]+[a-z]+/g);\n\n if (groups === null) {\n throw new Error(`The value [${strValue}] could not be parsed by timestring`);\n }\n\n groups.forEach((group) => {\n const valMatch = group.match(/[0-9.]+/g);\n const unitMatch = group.match(/[a-z]+/g);\n\n if (valMatch && unitMatch) {\n const val = parseFloat(valMatch[0]);\n const unit = unitMatch[0];\n totalSeconds += getSeconds(val, unit, unitValues);\n }\n });\n\n if (returnUnit) {\n return convert(totalSeconds, returnUnit, unitValues);\n }\n\n return totalSeconds;\n}\n\nfunction getUnitValues(opts: Required<TimestringOptions>): Record<string, number> {\n const unitValues: Record<string, number> = {\n ms: 0.001,\n s: 1,\n m: 60,\n h: 3600,\n d: 0,\n w: 0,\n mth: 0,\n y: 0,\n };\n\n unitValues.d = opts.hoursPerDay * unitValues.h;\n unitValues.w = opts.daysPerWeek * unitValues.d;\n unitValues.mth = (opts.daysPerYear / opts.monthsPerYear) * unitValues.d;\n unitValues.y = opts.daysPerYear * unitValues.d;\n\n return unitValues;\n}\n\nfunction getUnitKey(unit: string): string {\n for (const key of Object.keys(UNIT_MAP)) {\n if (UNIT_MAP[key].indexOf(unit) > -1) {\n return key;\n }\n }\n\n throw new Error(`The unit [${unit}] is not supported by timestring`);\n}\n\nfunction getSeconds(value: number, unit: string, unitValues: Record<string, number>): number {\n return value * unitValues[getUnitKey(unit)];\n}\n\nfunction convert(value: number, unit: string, unitValues: Record<string, number>): number {\n return value / unitValues[getUnitKey(unit)];\n}\n","import timestring from './timestring';\nimport { RawTradeData } from './RawTradeData';\n\nexport class Candle {\n timestamp: number;\n high: number;\n low: number;\n open: number;\n close: number;\n volume: number;\n\n constructor(timestamp: number, high: number, low: number, open: number, close: number, volume: number) {\n this.timestamp = timestamp;\n this.high = high;\n this.low = low;\n this.open = open;\n this.close = close;\n this.volume = volume;\n }\n\n toString(): string {\n return JSON.stringify(this);\n }\n}\n\nexport function encodeCandle(candle: Candle): Uint32Array {\n return new Uint32Array([candle.timestamp, candle.high, candle.low, candle.open, candle.close, candle.volume]);\n}\n\nexport function decodeCandle(buffer: Uint32Array): Candle {\n return new Candle(buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);\n}\n\nexport function generateCandles(data: RawTradeData[], candleSize: string): Candle[] {\n const candleWidth = timestring(candleSize, 'ms', {});\n if (data.length === 0) {\n throw new Error('Input data is empty');\n }\n const _data = data.map((point) => {\n return Object.assign(Object.assign({}, point), {\n // This will convert the timestamp to milliseconds if it's in seconds\n timestamp: point.timestamp && String(point.timestamp).length == 10 ? point.timestamp * 1000 : point.timestamp,\n });\n });\n if (_data[0] === undefined || Object.keys(_data[0]).length === 0) {\n return [];\n }\n const ohlcvData = [];\n let i = 0;\n let currentTimestamp = Math.floor(_data[0].timestamp / candleWidth) * candleWidth;\n let open = _data[0].price;\n let high = _data[0].price;\n let low = _data[0].price;\n let close = _data[0].price;\n let volume = 0.0;\n while (i < _data.length) {\n open = close;\n high = close;\n low = close;\n volume = 0.0;\n\n let innerI = i;\n\n while (innerI < _data.length && _data[innerI].timestamp < currentTimestamp + candleWidth) {\n open = innerI === 0 ? _data[innerI].price : open;\n high = Math.max(high, _data[innerI].price);\n low = Math.min(low, _data[innerI].price);\n close = _data[innerI].price;\n volume += _data[innerI].volume;\n innerI++;\n }\n\n ohlcvData.push({\n timestamp: currentTimestamp,\n high,\n low,\n open,\n close,\n volume,\n });\n\n currentTimestamp += candleWidth;\n i = innerI;\n }\n return ohlcvData;\n}\n","export class RawTradeData {\n timestamp: number;\n price: number;\n volume: number;\n\n constructor(timestamp: number, price: number, volume: number) {\n this.timestamp = timestamp;\n this.price = price;\n this.volume = volume;\n }\n}\n","import { instantiate, Candle, RawTradeData } from './internal/instantiate';\nimport type { WasmModule } from './internal/instantiate';\n\nexport { Candle, RawTradeData };\nexport type { WasmModule };\n\n/**\n * Load a wasm bundle synchronously. Only accepts the actual binary data.\n * @param input - Wasm bundle data\n * @param imports - Imports\n * @returns\n */\nexport function loadWasmSync(input: ArrayBuffer, imports = {}): WasmModule {\n return instantiate(new WebAssembly.Module(input), imports, {\n getFetch: getBrowserFetch,\n getCcxt: getBrowserCcxt,\n });\n}\n\n/**\n * Load a wasm bundle asynchronously. Accepts the actual binary data or URL.\n * @param input - Wasm bundle data or URL\n * @param imports - Imports\n * @returns\n */\nexport async function loadWasm(input: string | ArrayBuffer, imports = {}): Promise<WasmModule> {\n const module = typeof input === 'string' ? await compileFromUrl(input) : await WebAssembly.compile(input);\n return instantiate(module, imports, {\n getFetch: getBrowserFetch,\n getCcxt: getBrowserCcxt,\n });\n}\n\nasync function compileFromUrl(url: string): Promise<WebAssembly.Module> {\n const fetchImpl = await getBrowserFetch();\n const response = await fetchImpl(url);\n\n if (typeof WebAssembly.compileStreaming === 'function') {\n try {\n return await WebAssembly.compileStreaming(Promise.resolve(response.clone()));\n } catch {\n // Some deployments still serve wasm with the wrong content type.\n }\n }\n\n return WebAssembly.compile(await response.arrayBuffer());\n}\n\nasync function getBrowserFetch(): Promise<typeof fetch> {\n if (typeof globalThis.fetch !== 'function') {\n throw new Error('Fetch is not available in this browser runtime.');\n }\n\n return globalThis.fetch.bind(globalThis);\n}\n\nasync function getBrowserCcxt(): Promise<any> {\n const ccxt = (globalThis as typeof globalThis & { ccxt?: any }).ccxt;\n\n if (!ccxt) {\n throw new Error('ccxt is not available in this browser runtime.');\n }\n\n return ccxt;\n}\n"],"mappings":";AAAA,SAAS,cAAc;;;ACQvB,IAAM,eAA4C;AAAA,EAChD,aAAa;AAAA,EACb,aAAa;AAAA,EACb,eAAe;AAAA,EACf,eAAe;AAAA,EACf,aAAa;AACf;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