@mimicprotocol/cli 0.0.1-rc.28 → 0.0.1-rc.29

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mimicprotocol/cli
2
2
 
3
+ ## 0.0.1-rc.29
4
+
5
+ ### Patch Changes
6
+
7
+ - 72bb607: Fix relevant tokens query price filter
8
+ - 52b567d: Align oracle types naming convention
9
+ - 73a9cde: Fix npx init
10
+ - 0a6602a: Handle oracle query errors
11
+
3
12
  ## 0.0.1-rc.28
4
13
 
5
14
  ### Patch Changes
@@ -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
- fs.rmSync(fullDirectory, { recursive: true });
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(` ${methodName}(${fullMethodParams}): ${returnType} {`);
96
- lines.push(` const encodedData = ${contractName}Utils.encode${capitalizedName}(${inputs.map((p) => p.escapedName).join(', ')})`);
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(` return EvmCallBuilder.forChain(this._chainId).addCall(this._address, encodedData${isPayable ? ', value' : ''})`);
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
- const contractCallLine = `environment.contractCall(this._address, this._chainId, encodedData.toHexString(), this._timestamp)`;
115
- if (returnType === 'void') {
116
- lines.push(` ${contractCallLine}`);
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(` const response = ${contractCallLine}`);
120
- lines.push(` return ${contractName}Utils.decode${capitalizedName}(response)`);
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
  }
package/dist/types.js CHANGED
@@ -8,6 +8,7 @@ var LibTypes;
8
8
  LibTypes["Bytes"] = "Bytes";
9
9
  LibTypes["ChainId"] = "ChainId";
10
10
  LibTypes["TokenAmount"] = "TokenAmount";
11
+ LibTypes["Void"] = "Void";
11
12
  })(LibTypes || (exports.LibTypes = LibTypes = {}));
12
13
  var AssemblyPrimitiveTypes;
13
14
  (function (AssemblyPrimitiveTypes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimicprotocol/cli",
3
- "version": "0.0.1-rc.28",
3
+ "version": "0.0.1-rc.29",
4
4
  "license": "GPL-3.0",
5
5
  "private": false,
6
6
  "type": "commonjs",