@mimicprotocol/cli 0.0.1-rc.37 → 0.0.1-rc.39
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 +14 -0
- package/dist/commands/compile.js +57 -1
- package/dist/lib/ManifestHandler.js +2 -17
- package/dist/validators.js +1 -1
- package/package.json +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mimicprotocol/cli
|
|
2
2
|
|
|
3
|
+
## 0.0.1-rc.39
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 48352fe: Add runner target on compilation
|
|
8
|
+
- Updated dependencies [48352fe]
|
|
9
|
+
- @mimicprotocol/lib-ts@0.0.1-rc.39
|
|
10
|
+
|
|
11
|
+
## 0.0.1-rc.38
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 73e9713: Add getCode function to get the code of an address (Only EVM)
|
|
16
|
+
|
|
3
17
|
## 0.0.1-rc.37
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/commands/compile.js
CHANGED
|
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const constants_1 = require("@mimicprotocol/lib-ts/constants");
|
|
39
40
|
const core_1 = require("@oclif/core");
|
|
40
41
|
const fs = __importStar(require("fs"));
|
|
41
42
|
const path = __importStar(require("path"));
|
|
@@ -56,12 +57,13 @@ class Compile extends core_1.Command {
|
|
|
56
57
|
log_1.default.startAction('Verifying Manifest');
|
|
57
58
|
const manifest = ManifestHandler_1.default.load(cmd, manifestDir);
|
|
58
59
|
log_1.default.startAction('Compiling');
|
|
60
|
+
const wasmPath = path.join(absBuildDir, 'function.wasm');
|
|
59
61
|
const ascArgs = [
|
|
60
62
|
absFunctionFile,
|
|
61
63
|
'--target',
|
|
62
64
|
'release',
|
|
63
65
|
'--outFile',
|
|
64
|
-
|
|
66
|
+
wasmPath,
|
|
65
67
|
'--optimize',
|
|
66
68
|
'--exportRuntime',
|
|
67
69
|
'--transform',
|
|
@@ -74,6 +76,13 @@ class Compile extends core_1.Command {
|
|
|
74
76
|
suggestions: ['Check the AssemblyScript file'],
|
|
75
77
|
});
|
|
76
78
|
}
|
|
79
|
+
log_1.default.startAction('Injecting metadata');
|
|
80
|
+
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
81
|
+
const metadata = {
|
|
82
|
+
runnerTarget: constants_1.RUNNER_TARGET_VERSION,
|
|
83
|
+
};
|
|
84
|
+
const wasmWithMetadata = addCustomSection(wasmBuffer, 'mimic-metadata', JSON.stringify(metadata));
|
|
85
|
+
fs.writeFileSync(wasmPath, wasmWithMetadata);
|
|
77
86
|
log_1.default.startAction('Saving files');
|
|
78
87
|
fs.writeFileSync(path.join(absBuildDir, 'manifest.json'), JSON.stringify(manifest, null, 2));
|
|
79
88
|
log_1.default.stopAction();
|
|
@@ -95,3 +104,50 @@ Compile.flags = {
|
|
|
95
104
|
}),
|
|
96
105
|
};
|
|
97
106
|
exports.default = Compile;
|
|
107
|
+
/**
|
|
108
|
+
* Add a custom section to a WASM binary
|
|
109
|
+
* @param wasmBuffer - The original WASM binary
|
|
110
|
+
* @param sectionName - Name of the custom section
|
|
111
|
+
* @param data - String data to store in the section
|
|
112
|
+
* @returns Modified WASM binary with the custom section
|
|
113
|
+
*/
|
|
114
|
+
function addCustomSection(wasmBuffer, sectionName, data) {
|
|
115
|
+
const dataBuffer = Buffer.from(data, 'utf-8');
|
|
116
|
+
const nameBuffer = Buffer.from(sectionName, 'utf-8');
|
|
117
|
+
// WASM custom section format:
|
|
118
|
+
// - Section ID: 0 (custom section)
|
|
119
|
+
// - Section size (LEB128) - size of name length + name + data
|
|
120
|
+
// - Name length (LEB128)
|
|
121
|
+
// - Name bytes
|
|
122
|
+
// - Data bytes
|
|
123
|
+
const nameLengthBuffer = encodeLEB128(nameBuffer.length);
|
|
124
|
+
const sectionContentSize = nameLengthBuffer.length + nameBuffer.length + dataBuffer.length;
|
|
125
|
+
const sectionSizeBuffer = encodeLEB128(sectionContentSize);
|
|
126
|
+
const customSection = Buffer.concat([
|
|
127
|
+
Buffer.from([0]), // Custom section ID
|
|
128
|
+
sectionSizeBuffer,
|
|
129
|
+
nameLengthBuffer,
|
|
130
|
+
nameBuffer,
|
|
131
|
+
dataBuffer,
|
|
132
|
+
]);
|
|
133
|
+
// Insert after the WASM header (8 bytes: magic + version)
|
|
134
|
+
const headerSize = 8;
|
|
135
|
+
return Buffer.concat([wasmBuffer.slice(0, headerSize), customSection, wasmBuffer.slice(headerSize)]);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Encode an unsigned integer as LEB128 (Little Endian Base 128)
|
|
139
|
+
*/
|
|
140
|
+
function encodeLEB128(value) {
|
|
141
|
+
const bytes = [];
|
|
142
|
+
while (true) {
|
|
143
|
+
let byte = value & 0x7f;
|
|
144
|
+
value >>>= 7;
|
|
145
|
+
if (value !== 0) {
|
|
146
|
+
byte |= 0x80;
|
|
147
|
+
}
|
|
148
|
+
bytes.push(byte);
|
|
149
|
+
if (value === 0)
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
return Buffer.from(bytes);
|
|
153
|
+
}
|
|
@@ -33,9 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const constants_1 = require("@mimicprotocol/lib-ts/constants");
|
|
36
37
|
const fs = __importStar(require("fs"));
|
|
37
38
|
const js_yaml_1 = require("js-yaml");
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
39
|
const zod_1 = require("zod");
|
|
40
40
|
const errors_1 = require("../errors");
|
|
41
41
|
const validators_1 = require("../validators");
|
|
@@ -48,7 +48,7 @@ exports.default = {
|
|
|
48
48
|
...manifest,
|
|
49
49
|
inputs: mergeIfUnique(manifest.inputs),
|
|
50
50
|
abis: mergeIfUnique(manifest.abis),
|
|
51
|
-
metadata: {
|
|
51
|
+
metadata: { runnerTarget: constants_1.RUNNER_TARGET_VERSION },
|
|
52
52
|
};
|
|
53
53
|
return validators_1.ManifestValidator.parse(mergedManifest);
|
|
54
54
|
},
|
|
@@ -117,18 +117,3 @@ function handleValidationError(command, err) {
|
|
|
117
117
|
}
|
|
118
118
|
command.error(message, { code, suggestions });
|
|
119
119
|
}
|
|
120
|
-
function getLibVersion() {
|
|
121
|
-
try {
|
|
122
|
-
let currentDir = process.cwd();
|
|
123
|
-
while (currentDir !== path.dirname(currentDir)) {
|
|
124
|
-
const libPackagePath = path.join(currentDir, 'node_modules', '@mimicprotocol', 'lib-ts', 'package.json');
|
|
125
|
-
if (fs.existsSync(libPackagePath))
|
|
126
|
-
return JSON.parse(fs.readFileSync(libPackagePath, 'utf-8')).version;
|
|
127
|
-
currentDir = path.dirname(currentDir);
|
|
128
|
-
}
|
|
129
|
-
throw new Error('Could not find @mimicprotocol/lib-ts package');
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
throw new Error(`Failed to read @mimicprotocol/lib-ts version: ${error}`);
|
|
133
|
-
}
|
|
134
|
-
}
|
package/dist/validators.js
CHANGED
|
@@ -18,6 +18,6 @@ exports.ManifestValidator = zod_1.z.object({
|
|
|
18
18
|
inputs: zod_1.z.record(String, InputValue),
|
|
19
19
|
abis: zod_1.z.record(String, String),
|
|
20
20
|
metadata: zod_1.z.object({
|
|
21
|
-
|
|
21
|
+
runnerTarget: String.regex(exports.SEM_VER_REGEX, 'Must be a valid semver'),
|
|
22
22
|
}),
|
|
23
23
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimicprotocol/cli",
|
|
3
|
-
"version": "0.0.1-rc.
|
|
3
|
+
"version": "0.0.1-rc.39",
|
|
4
4
|
"license": "GPL-3.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "commonjs",
|
|
@@ -49,6 +49,14 @@
|
|
|
49
49
|
"ts-node": "^10.9.2",
|
|
50
50
|
"typescript": "^5.8.3"
|
|
51
51
|
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@mimicprotocol/lib-ts": ">=0.0.1-rc.39"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"@mimicprotocol/lib-ts": {
|
|
57
|
+
"optional": false
|
|
58
|
+
}
|
|
59
|
+
},
|
|
52
60
|
"oclif": {
|
|
53
61
|
"bin": "mimic",
|
|
54
62
|
"commands": "./dist/commands",
|