@mimicprotocol/cli 0.0.1-rc.20 → 0.0.1-rc.22

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.
@@ -37,21 +37,24 @@ const core_1 = require("@oclif/core");
37
37
  const child_process_1 = require("child_process");
38
38
  const path = __importStar(require("path"));
39
39
  class Test extends core_1.Command {
40
+ runOrExit(cmd, args, cwd) {
41
+ const result = (0, child_process_1.spawnSync)(cmd, args, { cwd, stdio: 'inherit' });
42
+ if (result.status !== 0)
43
+ this.exit(result.status ?? 1);
44
+ }
40
45
  async run() {
41
46
  const { flags } = await this.parse(Test);
42
47
  const baseDir = path.resolve(flags.directory);
43
48
  const testPath = path.join(baseDir, 'tests');
44
49
  if (!flags.skipCompile) {
45
- const codegen = (0, child_process_1.spawnSync)('yarn', ['mimic', 'codegen'], { cwd: baseDir, stdio: 'inherit' });
46
- if (codegen.status !== 0)
47
- return;
48
- const compile = (0, child_process_1.spawnSync)('yarn', ['mimic', 'compile'], { cwd: baseDir, stdio: 'inherit' });
49
- if (compile.status !== 0)
50
- return;
50
+ this.runOrExit('yarn', ['mimic', 'codegen'], baseDir);
51
+ this.runOrExit('yarn', ['mimic', 'compile'], baseDir);
51
52
  }
52
- (0, child_process_1.spawnSync)('yarn', ['tsx', './node_modules/mocha/bin/mocha.js', `${testPath}/**/*.spec.ts`], {
53
+ const result = (0, child_process_1.spawnSync)('yarn', ['tsx', './node_modules/mocha/bin/mocha.js', `${testPath}/**/*.spec.ts`], {
54
+ cwd: baseDir,
53
55
  stdio: 'inherit',
54
56
  });
57
+ this.exit(result.status ?? 1);
55
58
  }
56
59
  }
57
60
  Test.description = 'Runs task tests';
@@ -57,7 +57,7 @@ class FunctionHandler {
57
57
  }
58
58
  static getReturnType(fn, tupleDefinitions, abiTypeConverter) {
59
59
  if (this.isWriteFunction(fn))
60
- return 'CallBuilder';
60
+ return 'EvmCallBuilder';
61
61
  if (!fn.outputs || fn.outputs.length === 0)
62
62
  return 'void';
63
63
  if (fn.outputs.length === 1)
@@ -93,8 +93,8 @@ class FunctionHandler {
93
93
  lines.push(` ${methodName}(${methodParams}): ${returnType} {`);
94
94
  lines.push(` const encodedData = ${contractName}Utils.encode${capitalizedName}(${inputs.map((p) => p.escapedName).join(', ')})`);
95
95
  importManager.addType(types_1.LibTypes.Bytes);
96
- importManager.addType('CallBuilder');
97
- lines.push(` return CallBuilder.forChain(this._chainId).addCall(this._address, encodedData)`);
96
+ importManager.addType('EvmCallBuilder');
97
+ lines.push(` return EvmCallBuilder.forChain(this._chainId).addCall(this._address, encodedData)`);
98
98
  lines.push(` }`);
99
99
  lines.push('');
100
100
  }
@@ -107,7 +107,7 @@ class FunctionHandler {
107
107
  lines.push(` ${methodName}(${methodParams}): ${returnType} {`);
108
108
  lines.push(` const encodedData = ${contractName}Utils.encode${capitalizedName}(${inputs.map((p) => p.escapedName).join(', ')})`);
109
109
  importManager.addType('environment');
110
- const contractCallLine = `environment.contractCall(this._address, this._chainId, this._timestamp, encodedData.toHexString())`;
110
+ const contractCallLine = `environment.contractCall(this._address, this._chainId, encodedData.toHexString(), this._timestamp)`;
111
111
  if (returnType === 'void') {
112
112
  lines.push(` ${contractCallLine}`);
113
113
  }
@@ -33,15 +33,21 @@ function convertInputs(inputs) {
33
33
  }));
34
34
  }
35
35
  function generateImports(inputs) {
36
- const typesToImport = new Set(Object.values(inputs).filter((e) => e === 'Address' || e === 'Bytes' || e === 'BigInt'));
37
- if (typesToImport.size === 0)
36
+ const IMPORTABLE_TYPES = new Set(['Address', 'Bytes', 'BigInt', 'TokenAmount', 'BlockchainToken']);
37
+ const imports = new Set(Object.values(inputs).filter((type) => IMPORTABLE_TYPES.has(type)));
38
+ if (imports.size === 0)
38
39
  return '';
39
- return `import { ${[...typesToImport].sort().join(', ')} } from '@mimicprotocol/lib-ts'`;
40
+ return `import { ${[...imports].sort().join(', ')} } from '@mimicprotocol/lib-ts'`;
40
41
  }
41
42
  function generateInputsMapping(inputs, originalInputs) {
42
43
  return Object.entries(inputs)
43
44
  .map(([name, type]) => {
44
- const declaration = type === 'string' || type === 'Address' || type === 'Bytes' || type === 'BigInt'
45
+ const declaration = type === 'string' ||
46
+ type === 'Address' ||
47
+ type === 'Bytes' ||
48
+ type === 'BigInt' ||
49
+ type === 'BlockchainToken' ||
50
+ type === 'TokenAmount'
45
51
  ? `var ${name}: string | null`
46
52
  : `const ${name}: ${type}`;
47
53
  const originalInput = originalInputs[name];
@@ -75,6 +81,10 @@ function convertType(type) {
75
81
  return 'Address';
76
82
  if (type.includes('bytes'))
77
83
  return 'Bytes';
84
+ if (type === 'Token')
85
+ return 'BlockchainToken';
86
+ if (type === 'TokenAmount')
87
+ return 'TokenAmount';
78
88
  return type;
79
89
  }
80
90
  function generateGetter(name, type) {
@@ -88,6 +98,10 @@ function generateGetter(name, type) {
88
98
  returnStr = `Bytes.fromHexString(${str}!)`;
89
99
  else if (type === 'BigInt')
90
100
  returnStr = `BigInt.fromString(${str}!)`;
101
+ else if (type === 'BlockchainToken')
102
+ returnStr = `BlockchainToken.fromSerializable(${str}!)`;
103
+ else if (type === 'TokenAmount')
104
+ returnStr = `TokenAmount.fromSerializable(${str}!)`;
91
105
  else
92
106
  returnStr = str;
93
107
  return `static get ${name}(): ${type} {
@@ -3,17 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ManifestValidator = exports.SEM_VER_REGEX = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const SOLIDITY_TYPE_REGEX = /^(u?int(8|16|32|64|128|256)?|bool|address|bytes([1-9]|[1-2][0-9]|3[0-2])?|string)$/;
6
+ const TOKEN_TYPE_REGEX = /^(Token|TokenAmount)$/;
6
7
  // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
7
8
  exports.SEM_VER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
8
9
  const String = zod_1.z.string().min(1);
9
10
  const SolidityType = String.regex(SOLIDITY_TYPE_REGEX, 'Must be a valid solidity type');
10
- const InputValue = zod_1.z.union([
11
- SolidityType,
12
- zod_1.z.object({
13
- type: SolidityType,
14
- description: String.optional(),
15
- }),
16
- ]);
11
+ const TokenType = String.regex(TOKEN_TYPE_REGEX, 'Must be a valid token type');
12
+ const InputType = zod_1.z.union([SolidityType, TokenType]);
13
+ const InputValue = zod_1.z.union([InputType, zod_1.z.object({ type: InputType, description: String.optional() })]);
17
14
  exports.ManifestValidator = zod_1.z.object({
18
15
  version: String.regex(exports.SEM_VER_REGEX, 'Must be a valid semver'),
19
16
  name: String,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimicprotocol/cli",
3
- "version": "0.0.1-rc.20",
3
+ "version": "0.0.1-rc.22",
4
4
  "license": "GPL-3.0",
5
5
  "private": false,
6
6
  "type": "commonjs",