@mimicprotocol/cli 0.0.1-rc.28 → 0.0.1-rc.30
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 +15 -0
- package/dist/commands/init.js +9 -14
- package/dist/lib/AbisInterfaceGenerator/FunctionHandler.js +19 -12
- package/dist/lib/AbisInterfaceGenerator/NameManager.js +5 -0
- package/dist/lib/AbisInterfaceGenerator/TupleHandler.js +1 -0
- package/dist/types.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mimicprotocol/cli
|
|
2
2
|
|
|
3
|
+
## 0.0.1-rc.30
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 213f37f: Fix class names overlapping
|
|
8
|
+
|
|
9
|
+
## 0.0.1-rc.29
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 72bb607: Fix relevant tokens query price filter
|
|
14
|
+
- 52b567d: Align oracle types naming convention
|
|
15
|
+
- 73a9cde: Fix npx init
|
|
16
|
+
- 0a6602a: Handle oracle query errors
|
|
17
|
+
|
|
3
18
|
## 0.0.1-rc.28
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/commands/init.js
CHANGED
|
@@ -48,12 +48,6 @@ class Init extends core_1.Command {
|
|
|
48
48
|
const { flags } = await this.parse(Init);
|
|
49
49
|
const { directory, force } = flags;
|
|
50
50
|
const fullDirectory = path.resolve(directory);
|
|
51
|
-
const originalCwd = process.cwd();
|
|
52
|
-
const needsCwdChange = originalCwd === fullDirectory || originalCwd.startsWith(fullDirectory + path.sep);
|
|
53
|
-
if (needsCwdChange) {
|
|
54
|
-
const parentDir = path.dirname(fullDirectory);
|
|
55
|
-
process.chdir(parentDir);
|
|
56
|
-
}
|
|
57
51
|
if (force && fs.existsSync(fullDirectory) && fs.readdirSync(fullDirectory).length > 0) {
|
|
58
52
|
const shouldDelete = process.env.NODE_ENV === 'test'
|
|
59
53
|
? true
|
|
@@ -67,7 +61,12 @@ class Init extends core_1.Command {
|
|
|
67
61
|
this.exit(0);
|
|
68
62
|
}
|
|
69
63
|
log_1.default.startAction(`Deleting contents of ${fullDirectory}`);
|
|
70
|
-
|
|
64
|
+
// Delete files individually instead of removing the entire directory to preserve
|
|
65
|
+
// the directory reference. This prevents issues when the directory is the current
|
|
66
|
+
// working directory, as removing it would cause the reference to be lost.
|
|
67
|
+
for (const file of fs.readdirSync(fullDirectory)) {
|
|
68
|
+
fs.rmSync(path.join(fullDirectory, file), { recursive: true, force: true });
|
|
69
|
+
}
|
|
71
70
|
}
|
|
72
71
|
log_1.default.startAction('Creating files');
|
|
73
72
|
if (fs.existsSync(fullDirectory) && fs.readdirSync(fullDirectory).length > 0) {
|
|
@@ -79,22 +78,18 @@ class Init extends core_1.Command {
|
|
|
79
78
|
],
|
|
80
79
|
});
|
|
81
80
|
}
|
|
82
|
-
if (fs.existsSync(fullDirectory) && fs.readdirSync(fullDirectory).length === 0) {
|
|
83
|
-
fs.rmSync(fullDirectory, { recursive: true });
|
|
84
|
-
}
|
|
85
81
|
if (!fs.existsSync(fullDirectory)) {
|
|
86
82
|
fs.mkdirSync(fullDirectory, { recursive: true });
|
|
87
83
|
}
|
|
88
84
|
try {
|
|
89
85
|
await (0, simple_git_1.default)().clone('https://github.com/mimic-protocol/init-template.git', fullDirectory);
|
|
86
|
+
const gitDir = path.join(fullDirectory, '.git');
|
|
87
|
+
if (fs.existsSync(gitDir))
|
|
88
|
+
fs.rmSync(gitDir, { recursive: true, force: true });
|
|
90
89
|
}
|
|
91
90
|
catch (error) {
|
|
92
91
|
this.error(`Failed to clone template repository. Details: ${error}`);
|
|
93
92
|
}
|
|
94
|
-
// Remove .git to make it a fresh project repo
|
|
95
|
-
const gitDir = path.join(fullDirectory, '.git');
|
|
96
|
-
if (fs.existsSync(gitDir))
|
|
97
|
-
fs.rmSync(gitDir, { recursive: true, force: true });
|
|
98
93
|
this.installDependencies(fullDirectory);
|
|
99
94
|
this.runCodegen(fullDirectory);
|
|
100
95
|
log_1.default.stopAction();
|
|
@@ -92,14 +92,14 @@ class FunctionHandler {
|
|
|
92
92
|
const capitalizedName = this.getCapitalizedName(fn);
|
|
93
93
|
const isPayable = fn.stateMutability === 'payable';
|
|
94
94
|
const fullMethodParams = methodParams.concat(isPayable ? `${methodParams.length > 0 ? ', ' : ''}value: ${types_1.LibTypes.BigInt}` : '');
|
|
95
|
-
lines.push(
|
|
96
|
-
lines.push(`
|
|
95
|
+
lines.push(`${methodName}(${fullMethodParams}): ${returnType} {`);
|
|
96
|
+
lines.push(`const encodedData = ${contractName}Utils.encode${capitalizedName}(${inputs.map((p) => p.escapedName).join(', ')})`);
|
|
97
97
|
importManager.addType(types_1.LibTypes.Bytes);
|
|
98
98
|
importManager.addType('EvmCallBuilder');
|
|
99
99
|
if (isPayable)
|
|
100
100
|
importManager.addType(types_1.LibTypes.BigInt);
|
|
101
|
-
lines.push(`
|
|
102
|
-
lines.push(`
|
|
101
|
+
lines.push(`return EvmCallBuilder.forChain(this._chainId).addCall(this._address, encodedData${isPayable ? ', value' : ''})`);
|
|
102
|
+
lines.push(`}`);
|
|
103
103
|
lines.push('');
|
|
104
104
|
}
|
|
105
105
|
static appendReadMethod(lines, fn, importManager, tupleDefinitions, abiTypeConverter, contractName) {
|
|
@@ -108,18 +108,25 @@ class FunctionHandler {
|
|
|
108
108
|
const returnType = this.getReturnType(fn, tupleDefinitions, abiTypeConverter);
|
|
109
109
|
const methodName = fn.escapedName || fn.name;
|
|
110
110
|
const capitalizedName = this.getCapitalizedName(fn);
|
|
111
|
-
lines.push(` ${methodName}(${methodParams}): ${returnType} {`);
|
|
112
|
-
lines.push(` const encodedData = ${contractName}Utils.encode${capitalizedName}(${inputs.map((p) => p.escapedName).join(', ')})`);
|
|
113
111
|
importManager.addType('environment');
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
importManager.addType('Result');
|
|
113
|
+
const isVoid = returnType === 'void';
|
|
114
|
+
if (isVoid)
|
|
115
|
+
importManager.addType(types_1.LibTypes.Void);
|
|
116
|
+
const resultReturnType = isVoid ? `Result<${types_1.LibTypes.Void}, string>` : `Result<${returnType}, string>`;
|
|
117
|
+
lines.push(`${methodName}(${methodParams}): ${resultReturnType} {`);
|
|
118
|
+
lines.push(`const encodedData = ${contractName}Utils.encode${capitalizedName}(${inputs.map((p) => p.escapedName).join(', ')})`);
|
|
119
|
+
const contractCallLine = `environment.evmCallQuery(this._address, this._chainId, encodedData.toHexString(), this._timestamp)`;
|
|
120
|
+
lines.push(`const response = ${contractCallLine}`);
|
|
121
|
+
lines.push(`if (response.isError) return Result.err<${isVoid ? types_1.LibTypes.Void : returnType}, string>(response.error)`);
|
|
122
|
+
if (isVoid) {
|
|
123
|
+
lines.push(`return Result.ok<${types_1.LibTypes.Void}, string>(new ${types_1.LibTypes.Void}())`);
|
|
117
124
|
}
|
|
118
125
|
else {
|
|
119
|
-
lines.push(`
|
|
120
|
-
lines.push(`
|
|
126
|
+
lines.push(`const decoded = ${contractName}Utils.decode${capitalizedName}(response.value)`);
|
|
127
|
+
lines.push(`return Result.ok<${returnType}, string>(decoded)`);
|
|
121
128
|
}
|
|
122
|
-
lines.push(`
|
|
129
|
+
lines.push(`}`);
|
|
123
130
|
lines.push('');
|
|
124
131
|
}
|
|
125
132
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NameContext = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
var NameContext;
|
|
5
6
|
(function (NameContext) {
|
|
6
7
|
NameContext["FUNCTION_PARAMETER"] = "function_parameter";
|
|
7
8
|
NameContext["LOCAL_VARIABLE"] = "local_variable";
|
|
8
9
|
NameContext["CLASS_PROPERTY"] = "class_property";
|
|
9
10
|
NameContext["METHOD_NAME"] = "method_name";
|
|
11
|
+
NameContext["TUPLE_CLASS_NAME"] = "tuple_class_name";
|
|
10
12
|
})(NameContext || (exports.NameContext = NameContext = {}));
|
|
11
13
|
class NameManager {
|
|
12
14
|
static resolveNameConflicts(names, context) {
|
|
@@ -66,6 +68,8 @@ class NameManager {
|
|
|
66
68
|
return '_prop';
|
|
67
69
|
case NameContext.METHOD_NAME:
|
|
68
70
|
return '_';
|
|
71
|
+
case NameContext.TUPLE_CLASS_NAME:
|
|
72
|
+
return '_class';
|
|
69
73
|
default:
|
|
70
74
|
return '_safe';
|
|
71
75
|
}
|
|
@@ -93,6 +97,7 @@ NameManager.RESERVED_BY_CONTEXT = {
|
|
|
93
97
|
'timestamp',
|
|
94
98
|
]),
|
|
95
99
|
[NameContext.METHOD_NAME]: new Set(['constructor']),
|
|
100
|
+
[NameContext.TUPLE_CLASS_NAME]: new Set([...Object.values(types_1.LibTypes), 'JSON']),
|
|
96
101
|
};
|
|
97
102
|
NameManager.INTERNAL_NAME_PATTERNS = [/^item\d+$/, /^s\d+$/];
|
|
98
103
|
exports.default = NameManager;
|
|
@@ -103,6 +103,7 @@ class TupleHandler {
|
|
|
103
103
|
if (structMatch && structMatch[1])
|
|
104
104
|
className = structMatch[1];
|
|
105
105
|
}
|
|
106
|
+
className = NameManager_1.default.escapeName(className, NameManager_1.NameContext.TUPLE_CLASS_NAME);
|
|
106
107
|
const key = baseInternalType || className;
|
|
107
108
|
const components = this.resolveComponentNames(tupleToDefine.components, NameManager_1.NameContext.CLASS_PROPERTY);
|
|
108
109
|
tupleDefinitions.set(key, {
|
package/dist/types.js
CHANGED
|
@@ -8,6 +8,8 @@ var LibTypes;
|
|
|
8
8
|
LibTypes["Bytes"] = "Bytes";
|
|
9
9
|
LibTypes["ChainId"] = "ChainId";
|
|
10
10
|
LibTypes["TokenAmount"] = "TokenAmount";
|
|
11
|
+
LibTypes["Void"] = "Void";
|
|
12
|
+
LibTypes["Result"] = "Result";
|
|
11
13
|
})(LibTypes || (exports.LibTypes = LibTypes = {}));
|
|
12
14
|
var AssemblyPrimitiveTypes;
|
|
13
15
|
(function (AssemblyPrimitiveTypes) {
|