@steerprotocol/app-loader 1.0.2 → 1.1.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/lib/index.js +52 -74
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -33,14 +33,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.loadWasm = exports.loadWasmSync = exports.RawTradeData = exports.Candle = void 0;
|
|
36
|
-
|
|
37
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
38
|
-
//import ccxt from "ccxt";
|
|
36
|
+
const ethers_1 = require("ethers");
|
|
39
37
|
const Candle_1 = require("./Candle");
|
|
40
38
|
Object.defineProperty(exports, "Candle", { enumerable: true, get: function () { return Candle_1.Candle; } });
|
|
41
39
|
const RawTradeData_1 = require("./RawTradeData");
|
|
42
40
|
Object.defineProperty(exports, "RawTradeData", { enumerable: true, get: function () { return RawTradeData_1.RawTradeData; } });
|
|
41
|
+
let isNode = process || null;
|
|
43
42
|
let fetchImpl = null;
|
|
43
|
+
let fsImpl = null;
|
|
44
|
+
let ccxt = null;
|
|
44
45
|
if (globalThis["fetch"])
|
|
45
46
|
fetchImpl = fetch;
|
|
46
47
|
var State;
|
|
@@ -69,18 +70,16 @@ function loadWasm(input, imports = {}) {
|
|
|
69
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
71
|
const mod = instantiate(yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
71
72
|
if (typeof input === "string") {
|
|
72
|
-
|
|
73
|
-
if (!
|
|
73
|
+
if (isNode) {
|
|
74
|
+
if (!fetchImpl)
|
|
74
75
|
fetchImpl = (yield Promise.resolve().then(() => __importStar(require("undici")))).fetch;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
catch (_a) {
|
|
82
|
-
return WebAssembly.compile(yield (yield Promise.resolve().then(() => __importStar(require("fs/promises")))).readFile(input));
|
|
76
|
+
if (!fsImpl)
|
|
77
|
+
fsImpl = yield Promise.resolve().then(() => __importStar(require("fs/promises")));
|
|
78
|
+
if (!ccxt)
|
|
79
|
+
ccxt = (yield Promise.resolve().then(() => __importStar(require("ccxt")))).default;
|
|
80
|
+
return WebAssembly.compile(yield fsImpl.readFile(input));
|
|
83
81
|
}
|
|
82
|
+
return yield WebAssembly.compileStreaming(globalThis.fetch(input));
|
|
84
83
|
}
|
|
85
84
|
else {
|
|
86
85
|
return WebAssembly.compile(input);
|
|
@@ -92,11 +91,9 @@ function loadWasm(input, imports = {}) {
|
|
|
92
91
|
exports.loadWasm = loadWasm;
|
|
93
92
|
function instantiate(module, imports = {}) {
|
|
94
93
|
let WASM_MEMORY;
|
|
95
|
-
// eslint-disable-next-line prefer-const
|
|
96
94
|
let WASM_EXPORTS;
|
|
97
95
|
let WASM_DV;
|
|
98
96
|
let ASYNCIFY_PTR = 0;
|
|
99
|
-
// eslint-disable-next-line prefer-const
|
|
100
97
|
let ASYNCIFY_MEM;
|
|
101
98
|
let ASYNCIFY_INITIALIZED = false;
|
|
102
99
|
let fetchFn = null;
|
|
@@ -108,6 +105,18 @@ function instantiate(module, imports = {}) {
|
|
|
108
105
|
console.log(__liftString(text));
|
|
109
106
|
},
|
|
110
107
|
},
|
|
108
|
+
ethers: {
|
|
109
|
+
keccak256_str(str_ptr) {
|
|
110
|
+
const str = __liftString(str_ptr);
|
|
111
|
+
const hash = ethers_1.ethers.keccak256(str);
|
|
112
|
+
return __lowerString(hash);
|
|
113
|
+
},
|
|
114
|
+
keccak256_buf(buf_ptr) {
|
|
115
|
+
const buf = __liftBuffer(buf_ptr);
|
|
116
|
+
const hash = ethers_1.ethers.keccak256(new Uint8Array(buf));
|
|
117
|
+
return __lowerString(hash);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
111
120
|
// @ts-ignore
|
|
112
121
|
env: {
|
|
113
122
|
abort(message, fileName, lineNumber, columnNumber) {
|
|
@@ -248,20 +257,14 @@ function instantiate(module, imports = {}) {
|
|
|
248
257
|
const mod = new WebAssembly.Instance(module, adaptedImports);
|
|
249
258
|
WASM_EXPORTS = mod.exports;
|
|
250
259
|
// @ts-ignore
|
|
251
|
-
// eslint-disable-next-line prefer-const
|
|
252
260
|
WASM_MEMORY = WASM_EXPORTS.memory || adaptedImports.env.memory;
|
|
253
261
|
ASYNCIFY_MEM = new Uint32Array(WASM_MEMORY.buffer);
|
|
254
262
|
const handledExports = Object.setPrototypeOf({
|
|
255
263
|
responseHandler(body, statusCode, redirected, callbackID) {
|
|
256
264
|
if (!WASM_EXPORTS["responseHandler"])
|
|
257
265
|
throw new Error("Unable to call .responseHandler on wasm module. Add the line export { responseHandler } from \"as-fetch/assembly\" to your entry file.");
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
|
|
261
|
-
}
|
|
262
|
-
catch (e) {
|
|
263
|
-
console.error(e);
|
|
264
|
-
}
|
|
266
|
+
// @ts-ignore
|
|
267
|
+
WASM_EXPORTS.responseHandler(__lowerBuffer(body), statusCode, redirected ? 1 : 0, callbackID);
|
|
265
268
|
},
|
|
266
269
|
initialize(config) {
|
|
267
270
|
if (!WASM_EXPORTS["initialize"])
|
|
@@ -280,69 +283,46 @@ function instantiate(module, imports = {}) {
|
|
|
280
283
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281
284
|
if (!WASM_EXPORTS["execute"])
|
|
282
285
|
throw new Error("Unable to call .execute on wasm module. Are you sure this is a data connector?");
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
286
|
+
const loweredArgs = new Array(params.length);
|
|
287
|
+
for (let i = 0; i < params.length; i++) {
|
|
288
|
+
loweredArgs[i] = __lower(params[i]);
|
|
289
|
+
}
|
|
290
|
+
let result = WASM_EXPORTS.execute(...loweredArgs);
|
|
291
|
+
if (ASYNCIFY_INITIALIZED) {
|
|
292
|
+
// @ts-ignore
|
|
293
|
+
while (WASM_EXPORTS.asyncify_get_state() === State.Unwinding) {
|
|
290
294
|
// @ts-ignore
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
300
|
-
result = WASM_EXPORTS.execute();
|
|
301
|
-
}
|
|
295
|
+
WASM_EXPORTS.asyncify_stop_unwind();
|
|
296
|
+
if (fetchFn)
|
|
297
|
+
detachedValue = yield fetchFn();
|
|
298
|
+
if (ccxtFn)
|
|
299
|
+
detachedValue = yield ccxtFn();
|
|
300
|
+
// @ts-ignore
|
|
301
|
+
WASM_EXPORTS.asyncify_start_rewind(ASYNCIFY_PTR);
|
|
302
|
+
result = WASM_EXPORTS.execute();
|
|
302
303
|
}
|
|
303
|
-
if (fetchFn)
|
|
304
|
-
fetchFn = null;
|
|
305
|
-
if (ccxtFn)
|
|
306
|
-
ccxtFn = null;
|
|
307
|
-
// @ts-ignore
|
|
308
|
-
return __liftString(result);
|
|
309
|
-
}
|
|
310
|
-
catch (e) {
|
|
311
|
-
console.error(e);
|
|
312
|
-
return null;
|
|
313
304
|
}
|
|
305
|
+
if (fetchFn)
|
|
306
|
+
fetchFn = null;
|
|
307
|
+
if (ccxtFn)
|
|
308
|
+
ccxtFn = null;
|
|
309
|
+
// @ts-ignore
|
|
310
|
+
return __liftString(result);
|
|
314
311
|
});
|
|
315
312
|
},
|
|
316
313
|
config() {
|
|
317
314
|
if (!WASM_EXPORTS["config"])
|
|
318
315
|
throw new Error("Unable to call .config on wasm module. Are you sure this is a data connector?");
|
|
319
|
-
|
|
320
|
-
return __liftString(WASM_EXPORTS.config());
|
|
321
|
-
}
|
|
322
|
-
catch (e) {
|
|
323
|
-
console.error(e);
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
316
|
+
return __liftString(WASM_EXPORTS.config());
|
|
326
317
|
},
|
|
327
318
|
transform() {
|
|
328
319
|
if (!WASM_EXPORTS["transform"])
|
|
329
320
|
throw new Error("Unable to call .transform on wasm module. Are you sure this is a data connector?");
|
|
330
|
-
|
|
331
|
-
return __liftString(WASM_EXPORTS.transform());
|
|
332
|
-
}
|
|
333
|
-
catch (e) {
|
|
334
|
-
console.error(e);
|
|
335
|
-
return null;
|
|
336
|
-
}
|
|
321
|
+
return __liftString(WASM_EXPORTS.transform());
|
|
337
322
|
},
|
|
338
323
|
reset() {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
WASM_EXPORTS.reset();
|
|
342
|
-
}
|
|
343
|
-
catch (e) {
|
|
344
|
-
console.error(e);
|
|
345
|
-
}
|
|
324
|
+
if (WASM_EXPORTS["reset"])
|
|
325
|
+
WASM_EXPORTS.reset();
|
|
346
326
|
}
|
|
347
327
|
}, WASM_EXPORTS);
|
|
348
328
|
WASM_DV = new DataView(WASM_MEMORY.buffer);
|
|
@@ -393,7 +373,6 @@ function instantiate(module, imports = {}) {
|
|
|
393
373
|
new Uint8Array(WASM_MEMORY.buffer).set(new Uint8Array(value), ptr);
|
|
394
374
|
return ptr;
|
|
395
375
|
}
|
|
396
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
397
376
|
function __liftArray(liftElement, align, ptr) {
|
|
398
377
|
if (!ptr)
|
|
399
378
|
return null;
|
|
@@ -404,7 +383,6 @@ function instantiate(module, imports = {}) {
|
|
|
404
383
|
values[i] = liftElement(dataStart + (i << align >>> 0));
|
|
405
384
|
return values;
|
|
406
385
|
}
|
|
407
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
408
386
|
function __lowerStaticArray(lowerElement, id, align, values, typedConstructor = null) {
|
|
409
387
|
if (values == null)
|
|
410
388
|
return 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerprotocol/app-loader",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "App Loader for Steer Protocol",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"ccxt": "^4.1.19",
|
|
50
|
+
"ethers": "^6.12.1",
|
|
50
51
|
"timestring": "^7.0.0",
|
|
51
52
|
"undici": "^5.26.4"
|
|
52
53
|
}
|