@steerprotocol/data-connector-loader 0.0.1
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/LICENSE.md +7 -0
- package/README.md +1 -0
- package/lib/dataConnector.d.ts +20 -0
- package/lib/dataConnector.js +86 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +82 -0
- package/lib/types.d.ts +51 -0
- package/lib/types.js +2 -0
- package/package.json +55 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Hebert Cisco
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Steer Protocol App Loader
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WasmModule } from '@steerprotocol/app-loader';
|
|
2
|
+
import { ExecutionContext } from './types';
|
|
3
|
+
export declare class DataConnector {
|
|
4
|
+
private wasmFile;
|
|
5
|
+
module?: WasmModule;
|
|
6
|
+
config: string;
|
|
7
|
+
configObj: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
executionContext?: ExecutionContext & {
|
|
11
|
+
epochTimestamp: number;
|
|
12
|
+
};
|
|
13
|
+
constructor(wasmFile: string | ArrayBuffer, _config: string);
|
|
14
|
+
load(): Promise<WasmModule>;
|
|
15
|
+
setExecutionContext(executionContext: ExecutionContext): void;
|
|
16
|
+
execute(response: string): Promise<string>;
|
|
17
|
+
getResults(): string;
|
|
18
|
+
version(): number;
|
|
19
|
+
private subtractDate;
|
|
20
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DataConnector = void 0;
|
|
13
|
+
const app_loader_1 = require("@steerprotocol/app-loader");
|
|
14
|
+
class DataConnector {
|
|
15
|
+
constructor(wasmFile, _config) {
|
|
16
|
+
this.wasmFile = wasmFile;
|
|
17
|
+
this.config = _config;
|
|
18
|
+
this.configObj = JSON.parse(_config);
|
|
19
|
+
}
|
|
20
|
+
load() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const instance = yield (0, app_loader_1.loadWasm)(this.wasmFile, {});
|
|
23
|
+
this.module = instance;
|
|
24
|
+
this.module.initialize(this.config);
|
|
25
|
+
return this.module;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
setExecutionContext(executionContext) {
|
|
29
|
+
var _a;
|
|
30
|
+
// Determine the timestamp for epoch
|
|
31
|
+
const timestamp = this.subtractDate(executionContext.executionTimestamp, Number(executionContext.epochLength)).getTime();
|
|
32
|
+
// Divide milliseconds data to seconds for transformation bundle
|
|
33
|
+
const timestampInSecs = Math.floor(timestamp / 1000);
|
|
34
|
+
this.executionContext = Object.assign(Object.assign({}, executionContext), { epochTimestamp: timestampInSecs });
|
|
35
|
+
(_a = this.module) === null || _a === void 0 ? void 0 : _a.initialize(JSON.stringify(Object.assign(Object.assign({}, JSON.parse(this.config)), { executionContext: this.executionContext })));
|
|
36
|
+
}
|
|
37
|
+
execute(response) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
if (!this.executionContext) {
|
|
40
|
+
throw new Error('Execution context missing');
|
|
41
|
+
}
|
|
42
|
+
// If the module is not initialized, try to load it
|
|
43
|
+
if (!this.module) {
|
|
44
|
+
try {
|
|
45
|
+
yield this.load();
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
throw new Error('Module not initialized');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// If the module is still not initialized, throw an error
|
|
52
|
+
if (!this.module)
|
|
53
|
+
throw new Error('Module not initialized');
|
|
54
|
+
// Call the main function with the response
|
|
55
|
+
return this.module.execute(response);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Makes contract instance and calls, returns stringified result
|
|
59
|
+
// public async view(config: any): Promise<string> {
|
|
60
|
+
// const contract = new Contract(config.address, config.abi, this.identityManager.wallet);
|
|
61
|
+
// // For formatting the parameters if needed
|
|
62
|
+
// const paramsArray = config.arguments;
|
|
63
|
+
// // Calculate block number for determinism
|
|
64
|
+
// // const syncedBlock = await getBlockFromTimestamp(this.timestamp,this.identityManager) //@note uncomment for deterministic blocks
|
|
65
|
+
// // Call the desired method with the specified arguements at synced block
|
|
66
|
+
// const result = await contract[config.method](...paramsArray); //, {blockTag: syncedBlock}) //@note uncomment for deterministic blocks
|
|
67
|
+
// // This gets stringified before calling main
|
|
68
|
+
// return result;
|
|
69
|
+
// }
|
|
70
|
+
getResults() {
|
|
71
|
+
if (!this.module)
|
|
72
|
+
throw new Error('Module not initialized');
|
|
73
|
+
return this.module.transform();
|
|
74
|
+
}
|
|
75
|
+
version() {
|
|
76
|
+
if (!this.module)
|
|
77
|
+
throw new Error('Module not initialized');
|
|
78
|
+
return this.module.version();
|
|
79
|
+
}
|
|
80
|
+
subtractDate(timestamp, epochLength) {
|
|
81
|
+
const date = new Date(timestamp);
|
|
82
|
+
date.setSeconds(date.getSeconds() - epochLength);
|
|
83
|
+
return date;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.DataConnector = DataConnector;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DataConnector } from './dataConnector';
|
|
2
|
+
export declare class DataConnectorExecution {
|
|
3
|
+
private dataConnector;
|
|
4
|
+
constructor(dataConnector: DataConnector);
|
|
5
|
+
execute<T>(vaultAddress: string, _vaultConfig: string): Promise<Array<T>>;
|
|
6
|
+
private downloadWasmBundle;
|
|
7
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DataConnectorExecution = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
class DataConnectorExecution {
|
|
18
|
+
constructor(dataConnector) {
|
|
19
|
+
this.dataConnector = dataConnector;
|
|
20
|
+
}
|
|
21
|
+
execute(vaultAddress, _vaultConfig) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
// get current timestamp
|
|
24
|
+
const executionTimestamp = new Date().getTime();
|
|
25
|
+
// get vault configuration
|
|
26
|
+
const vaultConfig = JSON.parse(_vaultConfig);
|
|
27
|
+
// get data connector configurations
|
|
28
|
+
const dataConnectorConfigs = vaultConfig.dataConnectorsData;
|
|
29
|
+
// Each data connector results will be pushed into single array
|
|
30
|
+
// they will passed to execution bundle
|
|
31
|
+
const transformationData = [];
|
|
32
|
+
// Iterate over each data connector
|
|
33
|
+
for (const connectorConfig of dataConnectorConfigs) {
|
|
34
|
+
// If bundle hash is not present, skip the data connector
|
|
35
|
+
if (!connectorConfig.bundleHash) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
this.dataConnector.setExecutionContext({
|
|
39
|
+
executionTimestamp,
|
|
40
|
+
epochLength: Number(vaultConfig.strategyConfigData.epochLength)
|
|
41
|
+
});
|
|
42
|
+
// Append vault address to config
|
|
43
|
+
if (vaultAddress) {
|
|
44
|
+
connectorConfig.configData.vaultAddress = vaultAddress;
|
|
45
|
+
}
|
|
46
|
+
// loading data connector
|
|
47
|
+
if (!this.dataConnector.module) {
|
|
48
|
+
yield this.dataConnector.load();
|
|
49
|
+
}
|
|
50
|
+
// get first request
|
|
51
|
+
let request = yield this.dataConnector.execute('');
|
|
52
|
+
let response;
|
|
53
|
+
while (request != 'true') {
|
|
54
|
+
const parsedRequest = JSON.parse(request);
|
|
55
|
+
// On Chain
|
|
56
|
+
// if (this.dataConnector.configObj.isChainRead == true) {
|
|
57
|
+
// response = await this.dataConnector.view(parsedRequest);
|
|
58
|
+
// } else {
|
|
59
|
+
// Axios logic (off-chain)
|
|
60
|
+
const ax_instance = axios_1.default.create();
|
|
61
|
+
response = (yield ax_instance.request(parsedRequest)).data;
|
|
62
|
+
// }
|
|
63
|
+
// break;
|
|
64
|
+
request = yield this.dataConnector.execute(JSON.stringify(response));
|
|
65
|
+
}
|
|
66
|
+
const totData = JSON.parse(this.dataConnector.getResults());
|
|
67
|
+
transformationData.push(totData);
|
|
68
|
+
}
|
|
69
|
+
return transformationData;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
downloadWasmBundle(ipfsHash) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const response = yield axios_1.default.get(`https://steerprotocol.mypinata.cloud/ipfs/${ipfsHash}`, {
|
|
75
|
+
responseType: 'arraybuffer',
|
|
76
|
+
});
|
|
77
|
+
const wasmFile = new Uint8Array(response.data);
|
|
78
|
+
return wasmFile;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.DataConnectorExecution = DataConnectorExecution;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type VaultInput = {
|
|
2
|
+
_id?: string;
|
|
3
|
+
tokenId: string;
|
|
4
|
+
vaultAddress: string;
|
|
5
|
+
state: string;
|
|
6
|
+
token0: string;
|
|
7
|
+
token1: string;
|
|
8
|
+
name: string;
|
|
9
|
+
symbol: string;
|
|
10
|
+
beaconName: string;
|
|
11
|
+
token0Name: string;
|
|
12
|
+
token1Name: string;
|
|
13
|
+
token0Symbol: string;
|
|
14
|
+
token1Symbol: string;
|
|
15
|
+
decimals: string;
|
|
16
|
+
token0Decimals: string;
|
|
17
|
+
token1Decimals: string;
|
|
18
|
+
payloadIpfs: string;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
vaultConfigPayload: VaultConfigPayload;
|
|
21
|
+
};
|
|
22
|
+
export interface VaultConfigPayload {
|
|
23
|
+
strategyConfigData: StrategyConfigData;
|
|
24
|
+
vaultPayload: VaultPayload;
|
|
25
|
+
dataConnectorsData: DataConnectorsDaum[];
|
|
26
|
+
}
|
|
27
|
+
export interface StrategyConfigData {
|
|
28
|
+
[key: string]: string | number;
|
|
29
|
+
epochStart: number;
|
|
30
|
+
epochLength: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ConcentratedLiquidityManagerPayload {
|
|
33
|
+
maxTotalSupply: string;
|
|
34
|
+
ratioErrorTolerance: number;
|
|
35
|
+
maxTickChange: number;
|
|
36
|
+
twapInterval: number;
|
|
37
|
+
fee: number;
|
|
38
|
+
slippage: number;
|
|
39
|
+
}
|
|
40
|
+
export type VaultPayload = ConcentratedLiquidityManagerPayload;
|
|
41
|
+
export interface DataConnectorsDaum {
|
|
42
|
+
bundleHash: string;
|
|
43
|
+
configData: ConfigData;
|
|
44
|
+
}
|
|
45
|
+
export interface ConfigData {
|
|
46
|
+
[key: string]: string | number;
|
|
47
|
+
}
|
|
48
|
+
export interface ExecutionContext {
|
|
49
|
+
executionTimestamp: number;
|
|
50
|
+
epochLength: number;
|
|
51
|
+
}
|
package/lib/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@steerprotocol/data-connector-loader",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "App Loader for Steer Protocol",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"format": "prettier --write \"src/**/*.(js|ts)\"",
|
|
10
|
+
"lint": "eslint src --ext .js,.ts",
|
|
11
|
+
"lint:fix": "eslint src --fix --ext .js,.ts",
|
|
12
|
+
"test": "jest --config jest.config.js",
|
|
13
|
+
"prepare": "npm run build",
|
|
14
|
+
"prepublishOnly": "npm test && npm run lint",
|
|
15
|
+
"preversion": "npm run lint",
|
|
16
|
+
"version": "npm run format && git add -A src",
|
|
17
|
+
"postversion": "git push && git push --tags"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/SteerProtocol/data-connector-loader.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"boilerplate",
|
|
25
|
+
"typescript"
|
|
26
|
+
],
|
|
27
|
+
"author": "Hebert Cisco",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/SteerProtocol/data-connector-loader/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/SteerProtocol/data-connector-loader#readme",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/jest": "29.2.4",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "5.46.0",
|
|
36
|
+
"@typescript-eslint/parser": "5.47.1",
|
|
37
|
+
"date-fns": "^2.29.3",
|
|
38
|
+
"eslint": "8.30.0",
|
|
39
|
+
"eslint-plugin-jest": "27.1.7",
|
|
40
|
+
"jest": "29.3.1",
|
|
41
|
+
"prettier": "2.8.1",
|
|
42
|
+
"ts-jest": "29.0.3",
|
|
43
|
+
"typescript": "4.9.4"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"lib/**/*"
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@steerprotocol/app-loader": "^0.0.9",
|
|
50
|
+
"@steerprotocol/strategy-utils": "^2.1.0",
|
|
51
|
+
"axios": "^1.3.2",
|
|
52
|
+
"ethers": "^6.0.3",
|
|
53
|
+
"pondjs": "1.0.0-alpha.10"
|
|
54
|
+
}
|
|
55
|
+
}
|