@cartesi/cli 2.0.0-alpha.2 → 2.0.0-alpha.21

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.
Files changed (169) hide show
  1. package/dist/base.d.ts +28 -0
  2. package/dist/base.d.ts.map +1 -0
  3. package/dist/base.js +109 -0
  4. package/dist/builder/directory.d.ts +2 -2
  5. package/dist/builder/directory.d.ts.map +1 -1
  6. package/dist/builder/directory.js +5 -3
  7. package/dist/builder/docker.d.ts +2 -2
  8. package/dist/builder/docker.d.ts.map +1 -1
  9. package/dist/builder/docker.js +39 -37
  10. package/dist/builder/empty.d.ts +1 -1
  11. package/dist/builder/empty.d.ts.map +1 -1
  12. package/dist/builder/empty.js +1 -1
  13. package/dist/builder/none.d.ts +1 -1
  14. package/dist/builder/none.d.ts.map +1 -1
  15. package/dist/builder/none.js +1 -1
  16. package/dist/builder/tar.d.ts +1 -1
  17. package/dist/builder/tar.d.ts.map +1 -1
  18. package/dist/builder/tar.js +1 -1
  19. package/dist/commands/address-book.d.ts +5 -8
  20. package/dist/commands/address-book.d.ts.map +1 -1
  21. package/dist/commands/address-book.js +18 -14
  22. package/dist/commands/build.d.ts +7 -11
  23. package/dist/commands/build.d.ts.map +1 -1
  24. package/dist/commands/build.js +82 -58
  25. package/dist/commands/clean.d.ts +2 -7
  26. package/dist/commands/clean.d.ts.map +1 -1
  27. package/dist/commands/clean.js +9 -10
  28. package/dist/commands/create.d.ts +6 -15
  29. package/dist/commands/create.d.ts.map +1 -1
  30. package/dist/commands/create.js +25 -54
  31. package/dist/commands/deploy/build.d.ts +2 -14
  32. package/dist/commands/deploy/build.d.ts.map +1 -1
  33. package/dist/commands/deploy/build.js +8 -61
  34. package/dist/commands/deploy.d.ts +3 -0
  35. package/dist/commands/deploy.d.ts.map +1 -0
  36. package/dist/commands/deploy.js +12 -0
  37. package/dist/commands/deposit/erc1155.d.ts +18 -0
  38. package/dist/commands/deposit/erc1155.d.ts.map +1 -0
  39. package/dist/commands/deposit/erc1155.js +254 -0
  40. package/dist/commands/deposit/erc20.d.ts +10 -0
  41. package/dist/commands/deposit/erc20.d.ts.map +1 -0
  42. package/dist/commands/deposit/erc20.js +125 -0
  43. package/dist/commands/deposit/erc721.d.ts +10 -0
  44. package/dist/commands/deposit/erc721.d.ts.map +1 -0
  45. package/dist/commands/deposit/erc721.js +143 -0
  46. package/dist/commands/deposit/ether.d.ts +10 -0
  47. package/dist/commands/deposit/ether.d.ts.map +1 -0
  48. package/dist/commands/deposit/ether.js +65 -0
  49. package/dist/commands/deposit.d.ts +9 -0
  50. package/dist/commands/deposit.d.ts.map +1 -0
  51. package/dist/commands/deposit.js +37 -0
  52. package/dist/commands/doctor.d.ts +2 -12
  53. package/dist/commands/doctor.d.ts.map +1 -1
  54. package/dist/commands/doctor.js +90 -91
  55. package/dist/commands/hash.d.ts +4 -9
  56. package/dist/commands/hash.d.ts.map +1 -1
  57. package/dist/commands/hash.js +14 -14
  58. package/dist/commands/logs.d.ts +9 -0
  59. package/dist/commands/logs.d.ts.map +1 -0
  60. package/dist/commands/logs.js +34 -0
  61. package/dist/commands/run.d.ts +14 -20
  62. package/dist/commands/run.d.ts.map +1 -1
  63. package/dist/commands/run.js +193 -182
  64. package/dist/commands/send.d.ts +10 -0
  65. package/dist/commands/send.d.ts.map +1 -0
  66. package/dist/commands/send.js +130 -0
  67. package/dist/commands/shell.d.ts +6 -14
  68. package/dist/commands/shell.d.ts.map +1 -1
  69. package/dist/commands/shell.js +34 -51
  70. package/dist/commands/status.d.ts +6 -0
  71. package/dist/commands/status.d.ts.map +1 -0
  72. package/dist/commands/status.js +50 -0
  73. package/dist/compose/default.env +36 -0
  74. package/dist/compose/docker-compose-anvil.yaml +39 -0
  75. package/dist/compose/docker-compose-bundler.yaml +71 -0
  76. package/dist/{node → compose}/docker-compose-database.yaml +4 -2
  77. package/dist/compose/docker-compose-explorer.yaml +96 -0
  78. package/dist/compose/docker-compose-node-cpus.yaml +6 -0
  79. package/dist/compose/docker-compose-node-memory.yaml +6 -0
  80. package/dist/compose/docker-compose-node.yaml +50 -0
  81. package/dist/compose/docker-compose-passkey-server.yaml +37 -0
  82. package/dist/compose/docker-compose-paymaster.yaml +40 -0
  83. package/dist/compose/docker-compose-proxy.yaml +24 -0
  84. package/dist/config.d.ts +30 -9
  85. package/dist/config.d.ts.map +1 -1
  86. package/dist/config.js +93 -53
  87. package/dist/contracts.d.ts +1695 -1636
  88. package/dist/contracts.d.ts.map +1 -1
  89. package/dist/contracts.js +632 -592
  90. package/dist/exec/cartesi-machine.d.ts +2 -2
  91. package/dist/exec/cartesi-machine.d.ts.map +1 -1
  92. package/dist/exec/cartesi-machine.js +3 -5
  93. package/dist/exec/genext2fs.d.ts +6 -3
  94. package/dist/exec/genext2fs.d.ts.map +1 -1
  95. package/dist/exec/genext2fs.js +5 -5
  96. package/dist/exec/index.d.ts +0 -1
  97. package/dist/exec/index.d.ts.map +1 -1
  98. package/dist/exec/index.js +0 -1
  99. package/dist/exec/mksquashfs.d.ts +2 -2
  100. package/dist/exec/mksquashfs.d.ts.map +1 -1
  101. package/dist/exec/mksquashfs.js +4 -2
  102. package/dist/exec/rollups.d.ts +105 -0
  103. package/dist/exec/rollups.d.ts.map +1 -0
  104. package/dist/exec/rollups.js +375 -0
  105. package/dist/exec/util.d.ts +1 -16
  106. package/dist/exec/util.d.ts.map +1 -1
  107. package/dist/exec/util.js +3 -50
  108. package/dist/index.d.ts +2 -1
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +57 -1
  111. package/dist/machine.d.ts +8 -2
  112. package/dist/machine.d.ts.map +1 -1
  113. package/dist/machine.js +26 -16
  114. package/dist/prompts.d.ts +13 -2
  115. package/dist/prompts.d.ts.map +1 -1
  116. package/dist/prompts.js +60 -26
  117. package/dist/template.d.ts +3 -0
  118. package/dist/template.d.ts.map +1 -0
  119. package/dist/template.js +16 -0
  120. package/dist/wallet.d.ts +9222 -21
  121. package/dist/wallet.d.ts.map +1 -1
  122. package/dist/wallet.js +35 -198
  123. package/package.json +39 -57
  124. package/bin/dev.cmd +0 -3
  125. package/bin/dev.js +0 -25
  126. package/bin/run.cmd +0 -3
  127. package/bin/run.js +0 -8
  128. package/dist/baseCommand.d.ts +0 -22
  129. package/dist/baseCommand.d.ts.map +0 -1
  130. package/dist/baseCommand.js +0 -92
  131. package/dist/commands/deploy/index.d.ts +0 -12
  132. package/dist/commands/deploy/index.d.ts.map +0 -1
  133. package/dist/commands/deploy/index.js +0 -78
  134. package/dist/commands/send/erc20.d.ts +0 -14
  135. package/dist/commands/send/erc20.d.ts.map +0 -1
  136. package/dist/commands/send/erc20.js +0 -70
  137. package/dist/commands/send/erc721.d.ts +0 -14
  138. package/dist/commands/send/erc721.d.ts.map +0 -1
  139. package/dist/commands/send/erc721.js +0 -73
  140. package/dist/commands/send/ether.d.ts +0 -13
  141. package/dist/commands/send/ether.d.ts.map +0 -1
  142. package/dist/commands/send/ether.js +0 -32
  143. package/dist/commands/send/generic.d.ts +0 -15
  144. package/dist/commands/send/generic.d.ts.map +0 -1
  145. package/dist/commands/send/generic.js +0 -119
  146. package/dist/commands/send/index.d.ts +0 -28
  147. package/dist/commands/send/index.d.ts.map +0 -1
  148. package/dist/commands/send/index.js +0 -102
  149. package/dist/exec/crane.d.ts +0 -15
  150. package/dist/exec/crane.d.ts.map +0 -1
  151. package/dist/exec/crane.js +0 -17
  152. package/dist/flags.d.ts +0 -17
  153. package/dist/flags.d.ts.map +0 -1
  154. package/dist/flags.js +0 -28
  155. package/dist/node/DockerfileDeploy.txt +0 -4
  156. package/dist/node/default.env +0 -27
  157. package/dist/node/docker-compose-anvil.yaml +0 -50
  158. package/dist/node/docker-compose-bundler.yaml +0 -57
  159. package/dist/node/docker-compose-envfile.yaml +0 -4
  160. package/dist/node/docker-compose-explorer.yaml +0 -88
  161. package/dist/node/docker-compose-host.yaml +0 -30
  162. package/dist/node/docker-compose-paymaster.yaml +0 -33
  163. package/dist/node/docker-compose-prompt.yaml +0 -17
  164. package/dist/node/docker-compose-proxy.yaml +0 -48
  165. package/dist/node/docker-compose-snapshot-volume.yaml +0 -8
  166. package/dist/node/docker-compose-validator-cpus.yaml +0 -6
  167. package/dist/node/docker-compose-validator-memory.yaml +0 -6
  168. package/dist/node/docker-compose-validator.yaml +0 -59
  169. package/oclif.manifest.json +0 -876
@@ -1,8 +1,3 @@
1
- import { BaseCommand } from "../baseCommand.js";
2
- export default class Clean extends BaseCommand<typeof Clean> {
3
- static summary: string;
4
- static description: string;
5
- static examples: string[];
6
- run(): Promise<void>;
7
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createCleanCommand: () => Command<[], {}, {}>;
8
3
  //# sourceMappingURL=clean.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,WAAW,CAAC,OAAO,KAAK,CAAC;IACxD,MAAM,CAAC,OAAO,SAA2C;IAEzD,MAAM,CAAC,WAAW,SAAwD;IAE1E,MAAM,CAAC,QAAQ,WAA2C;IAE7C,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,kBAAkB,2BAM9B,CAAC"}
@@ -1,11 +1,10 @@
1
+ import { Command } from "@commander-js/extra-typings";
1
2
  import fs from "fs-extra";
2
- import { BaseCommand } from "../baseCommand.js";
3
- class Clean extends BaseCommand {
4
- async run() {
5
- await fs.emptyDir(this.getContextPath());
6
- }
7
- }
8
- Clean.summary = "Clean build artifacts of application.";
9
- Clean.description = "Deletes all cached build artifacts of application.";
10
- Clean.examples = ["<%= config.bin %> <%= command.id %>"];
11
- export default Clean;
3
+ import { getContextPath } from "../base.js";
4
+ export const createCleanCommand = () => {
5
+ return new Command("clean")
6
+ .description("Deletes all cached build artifacts of application.")
7
+ .action(async () => {
8
+ await fs.emptyDir(getContextPath());
9
+ });
10
+ };
@@ -1,16 +1,7 @@
1
- import { BaseCommand } from "../baseCommand.js";
2
- export declare const DEFAULT_TEMPLATES_BRANCH = "sdk-0.9";
3
- export default class CreateCommand extends BaseCommand<typeof CreateCommand> {
4
- static description: string;
5
- static examples: string[];
6
- static args: {
7
- name: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
8
- };
9
- static flags: {
10
- template: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
- branch: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
- };
13
- private download;
14
- run(): Promise<void>;
15
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const DEFAULT_TEMPLATES_BRANCH = "prerelease/sdk-12";
3
+ export declare const createCreateCommand: () => Command<[string], {
4
+ template: "cpp" | "cpp-low-level" | "go" | "java" | "javascript" | "lua" | "python" | "ruby" | "rust" | "typescript";
5
+ branch: string;
6
+ }, {}>;
16
7
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,eAAO,MAAM,wBAAwB,YAAY,CAAC;AAElD,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,WAAW,CAAC,OAAO,aAAa,CAAC;IACxE,MAAM,CAAC,WAAW,SAAwB;IAE1C,MAAM,CAAC,QAAQ,WAA2C;IAE1D,MAAM,CAAC,IAAI;;MAKT;IAEF,MAAM,CAAC,KAAK;;;MAoBV;YAEY,QAAQ;IAqBT,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAkBpC"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAK9D,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAe5D,eAAO,MAAM,mBAAmB;;;MA0B/B,CAAC"}
@@ -1,30 +1,31 @@
1
- import { Args, Flags } from "@oclif/core";
1
+ import { Command, Option } from "@commander-js/extra-typings";
2
2
  import chalk from "chalk";
3
- import { downloadTemplate } from "giget";
4
3
  import ora from "ora";
5
- import { BaseCommand } from "../baseCommand.js";
6
- export const DEFAULT_TEMPLATES_BRANCH = "sdk-0.9";
7
- class CreateCommand extends BaseCommand {
8
- async download(template, branch, out) {
9
- const cartesiProvider = async (input) => {
10
- return {
11
- name: "cartesi",
12
- subdir: input,
13
- url: "https://github.com/cartesi/application-templates",
14
- tar: `https://codeload.github.com/cartesi/application-templates/tar.gz/refs/heads/${branch}`,
15
- };
16
- };
17
- const input = `cartesi:${template}`;
18
- return downloadTemplate(input, {
19
- dir: out,
20
- providers: { cartesi: cartesiProvider },
21
- });
22
- }
23
- async run() {
24
- const { args, flags } = await this.parse(CreateCommand);
4
+ import { download } from "../template.js";
5
+ export const DEFAULT_TEMPLATES_BRANCH = "prerelease/sdk-12";
6
+ const TEMPLATES = [
7
+ "cpp",
8
+ "cpp-low-level",
9
+ "go",
10
+ "java",
11
+ "javascript",
12
+ "lua",
13
+ "python",
14
+ "ruby",
15
+ "rust",
16
+ "typescript",
17
+ ];
18
+ export const createCreateCommand = () => {
19
+ return new Command("create")
20
+ .argument("<name>", "application and directory name")
21
+ .addOption(new Option("-t, --template <template>", "template name to use")
22
+ .choices(TEMPLATES)
23
+ .makeOptionMandatory())
24
+ .option("-b, --branch <branch>", "cartesi/application-templates repository branch name to use", DEFAULT_TEMPLATES_BRANCH)
25
+ .action(async (name, { branch, template }) => {
25
26
  const spinner = ora("Creating application...").start();
26
27
  try {
27
- const { dir } = await this.download(flags.template, flags.branch, args.name);
28
+ const { dir } = await download(template, branch, name);
28
29
  spinner.succeed(`Application created at ${chalk.cyan(dir)}`);
29
30
  }
30
31
  catch (e) {
@@ -32,35 +33,5 @@ class CreateCommand extends BaseCommand {
32
33
  ? `Error creating application: ${chalk.red(e.message)}`
33
34
  : String(e));
34
35
  }
35
- }
36
- }
37
- CreateCommand.description = "Create application";
38
- CreateCommand.examples = ["<%= config.bin %> <%= command.id %>"];
39
- CreateCommand.args = {
40
- name: Args.string({
41
- description: "application and directory name",
42
- required: true,
43
- }),
36
+ });
44
37
  };
45
- CreateCommand.flags = {
46
- template: Flags.string({
47
- description: "template name to use",
48
- required: true,
49
- options: [
50
- "cpp",
51
- "cpp-low-level",
52
- "go",
53
- "javascript",
54
- "lua",
55
- "python",
56
- "ruby",
57
- "rust",
58
- "typescript",
59
- ],
60
- }),
61
- branch: Flags.string({
62
- description: `cartesi/application-templates repository branch name to use`,
63
- default: DEFAULT_TEMPLATES_BRANCH,
64
- }),
65
- };
66
- export default CreateCommand;
@@ -1,15 +1,3 @@
1
- import { BaseCommand } from "../../baseCommand.js";
2
- export default class DeployBuild extends BaseCommand<typeof DeployBuild> {
3
- static summary: string;
4
- static description: string;
5
- static examples: string[];
6
- static flags: {
7
- platform: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- };
9
- static enableJsonFlag: boolean;
10
- private buildRollupsImage;
11
- run(): Promise<{
12
- image: string;
13
- }>;
14
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createBuildCommand: () => Command<[], {}, {}>;
15
3
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy/build.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,WAAW,CAAC,OAAO,WAAW,CAAC;IACpE,MAAM,CAAC,OAAO,SAAmD;IAEjE,MAAM,CAAC,WAAW,SACoD;IAEtE,MAAM,CAAC,QAAQ,WAA2C;IAE1D,MAAM,CAAC,KAAK;;MAOV;IAEF,OAAc,cAAc,UAAQ;YAEtB,iBAAiB;IA6BlB,GAAG;;;CAwBnB"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAGtD,eAAO,MAAM,kBAAkB,2BAQ9B,CAAC"}
@@ -1,62 +1,9 @@
1
- import { Flags } from "@oclif/core";
2
- import { execa } from "execa";
3
- import fs from "fs-extra";
4
- import path from "path";
5
- import { tmpNameSync } from "tmp";
6
- import { URL } from "url";
7
- import { BaseCommand } from "../../baseCommand.js";
8
- class DeployBuild extends BaseCommand {
9
- async buildRollupsImage(platform) {
10
- const buildResult = tmpNameSync();
11
- const imagePath = this.getContextPath("image");
12
- const binPath = path.join(path.dirname(new URL(import.meta.url).pathname), "..", "..");
13
- const dockerfile = path.join(binPath, "node", "DockerfileDeploy.txt");
14
- const args = [
15
- "buildx",
16
- "build",
17
- "-f",
18
- dockerfile,
19
- "--load",
20
- "--iidfile",
21
- buildResult,
22
- imagePath,
23
- ];
24
- // optional platform, default to not defining, which will build for the host platform
25
- if (platform) {
26
- args.push("--platform", platform);
27
- }
28
- await execa("docker", args, { stdio: "inherit" });
29
- return fs.readFileSync(buildResult, "utf8");
30
- }
31
- async run() {
32
- const { flags } = await this.parse(DeployBuild);
33
- // print machine hash
34
- const templateHash = this.getMachineHash();
35
- if (!templateHash) {
36
- this.error(`Cartesi machine snapshot not found, run '${this.config.bin} build'`);
37
- }
38
- this.logPrompt({
39
- title: "Cartesi machine templateHash",
40
- value: templateHash,
41
- });
42
- this.log("Building application node Docker image...");
43
- const image = await this.buildRollupsImage(flags.platform);
44
- this.logPrompt({
45
- title: "Application node Docker image",
46
- value: image,
47
- });
48
- return { image };
49
- }
50
- }
51
- DeployBuild.summary = "Build deployment Docker image of application.";
52
- DeployBuild.description = "Package the application in a Docker image ready to be deployed.";
53
- DeployBuild.examples = ["<%= config.bin %> <%= command.id %>"];
54
- DeployBuild.flags = {
55
- platform: Flags.string({
56
- options: ["linux/amd64", "linux/arm64"],
57
- summary: "Docker image target platform",
58
- description: "Select the target platform for the produced Docker image. It depends on the platform where the application node will be deployed.",
59
- }),
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import chalk from "chalk";
3
+ export const createBuildCommand = () => {
4
+ return new Command("build")
5
+ .description("DEPRECATED: Package the application in a Docker image ready to be deployed.")
6
+ .action(async () => {
7
+ console.warn(chalk.yellow("deploy build command is deprecated"));
8
+ });
60
9
  };
61
- DeployBuild.enableJsonFlag = true;
62
- export default DeployBuild;
@@ -0,0 +1,3 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createDeployCommand: () => Command<[], {}, {}>;
3
+ //# sourceMappingURL=deploy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,mBAAmB,2BAc/B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import chalk from "chalk";
3
+ import { createBuildCommand } from "./deploy/build.js";
4
+ export const createDeployCommand = () => {
5
+ const command = new Command("deploy")
6
+ .description("DEPRECATED: Package and deploy the application to a supported live network.")
7
+ .action(async () => {
8
+ console.warn(chalk.yellow("deploy command is deprecated, use 'cartesi-rollups-cli' directly instead"));
9
+ });
10
+ command.addCommand(createBuildCommand(), { hidden: true });
11
+ return command;
12
+ };
@@ -0,0 +1,18 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createErc1155SingleCommand: () => Command<[string | undefined, string | undefined], {
3
+ [x: string]: never;
4
+ }, {
5
+ from?: string | undefined;
6
+ application?: string | undefined;
7
+ projectName?: string | undefined;
8
+ rpcUrl?: string | undefined;
9
+ }>;
10
+ export declare const createErc1155BatchCommand: () => Command<[string | undefined, string | undefined], {
11
+ [x: string]: never;
12
+ }, {
13
+ from?: string | undefined;
14
+ application?: string | undefined;
15
+ projectName?: string | undefined;
16
+ rpcUrl?: string | undefined;
17
+ }>;
18
+ //# sourceMappingURL=erc1155.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erc1155.d.ts","sourceRoot":"","sources":["../../../src/commands/deposit/erc1155.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAyCtD,eAAO,MAAM,0BAA0B;;;;;;;EAmItC,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;;;;;EAwKrC,CAAC"}
@@ -0,0 +1,254 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import input from "@inquirer/input";
3
+ import chalk from "chalk";
4
+ import ora from "ora";
5
+ import { getAddress, isAddress, isHex } from "viem";
6
+ import { getProjectName } from "../../base.js";
7
+ import { erc1155BatchPortalAbi, erc1155BatchPortalAddress, erc1155SinglePortalAbi, erc1155SinglePortalAddress, testMultiTokenAbi, testMultiTokenAddress, } from "../../contracts.js";
8
+ import { addressInput, bigintInput, getInputApplicationAddress, } from "../../prompts.js";
9
+ import { connect } from "../../wallet.js";
10
+ const parseToken = async (options) => {
11
+ const address = options.token && isAddress(options.token)
12
+ ? getAddress(options.token)
13
+ : await addressInput({
14
+ message: "Token address",
15
+ default: testMultiTokenAddress,
16
+ });
17
+ return { address, name: "TestMultiToken" };
18
+ };
19
+ export const createErc1155SingleCommand = () => {
20
+ return new Command("erc1155-single")
21
+ .description("Deposits an ERC1155 token to the application")
22
+ .configureHelp({ showGlobalOptions: true })
23
+ .argument("[token-id]", "token ID")
24
+ .argument("[amount]", "amount to send")
25
+ .option("--token <address>", "ERC1155 token address")
26
+ .option("--base-layer-data <hex>", "base layer data", "0x")
27
+ .option("--exec-layer-data <hex>", "exec layer data", "0x")
28
+ .action(async (tokenIdString, amountString, options, command) => {
29
+ const { from } = command.optsWithGlobals();
30
+ // connect to anvil
31
+ const testClient = await connect(command.optsWithGlobals());
32
+ const token = await parseToken({
33
+ token: options.token,
34
+ });
35
+ const tokenId = tokenIdString
36
+ ? BigInt(tokenIdString)
37
+ : await bigintInput({ decimals: 0, message: "Token ID" });
38
+ const projectName = getProjectName(command.optsWithGlobals());
39
+ // get dapp address from local node, or ask
40
+ const application = await getInputApplicationAddress({
41
+ ...command.optsWithGlobals(),
42
+ projectName,
43
+ });
44
+ // the input sender, impersonated
45
+ const account = from && isAddress(from)
46
+ ? getAddress(from)
47
+ : (await testClient.getAddresses())[0];
48
+ const amount = amountString
49
+ ? BigInt(amountString)
50
+ : await bigintInput({
51
+ message: `Amount of token ID ${tokenId}`,
52
+ decimals: 0,
53
+ });
54
+ // ensure amount is positive
55
+ if (amount <= BigInt(0)) {
56
+ console.error(chalk.red("Amount of tokens to be deposited, must be greater than zero."));
57
+ return;
58
+ }
59
+ const tokenAbi = testMultiTokenAbi;
60
+ const baseLayerData = isHex(options.baseLayerData)
61
+ ? options.baseLayerData
62
+ : "0x";
63
+ const execLayerData = isHex(options.execLayerData)
64
+ ? options.execLayerData
65
+ : "0x";
66
+ // progress spinner
67
+ const progress = ora();
68
+ // check balance
69
+ const balance = await testClient.readContract({
70
+ abi: tokenAbi,
71
+ address: token.address,
72
+ functionName: "balanceOf",
73
+ args: [account, tokenId],
74
+ });
75
+ if (balance < amount) {
76
+ progress.fail("Insufficient balance");
77
+ return;
78
+ }
79
+ // check if sufficiently approved
80
+ const isApproved = await testClient.readContract({
81
+ abi: tokenAbi,
82
+ address: token.address,
83
+ functionName: "isApprovedForAll",
84
+ args: [account, erc1155SinglePortalAddress],
85
+ });
86
+ // approve if needed
87
+ if (isApproved === false) {
88
+ progress.start(`Approving ERC1155Portal...`);
89
+ const { request } = await testClient.simulateContract({
90
+ abi: tokenAbi,
91
+ account,
92
+ address: token.address,
93
+ functionName: "setApprovalForAll",
94
+ args: [erc1155SinglePortalAddress, true],
95
+ });
96
+ const hash = await testClient.writeContract(request);
97
+ await testClient.waitForTransactionReceipt({ hash });
98
+ progress.succeed(`Approved ERC1155Portal`);
99
+ }
100
+ // simulate deposit call
101
+ const { request } = await testClient.simulateContract({
102
+ abi: erc1155SinglePortalAbi,
103
+ account,
104
+ address: erc1155SinglePortalAddress,
105
+ functionName: "depositSingleERC1155Token",
106
+ args: [
107
+ token.address,
108
+ application,
109
+ tokenId,
110
+ amount,
111
+ baseLayerData,
112
+ execLayerData,
113
+ ],
114
+ });
115
+ // for messages
116
+ const amountLabel = `${chalk.cyan(amount)} units of token id ${tokenId}`;
117
+ // send deposit
118
+ progress.start(`Depositing ${amountLabel} to ${chalk.cyan(application)}...`);
119
+ const hash = await testClient.writeContract(request);
120
+ await testClient.waitForTransactionReceipt({ hash });
121
+ progress.succeed(`Deposited ${amountLabel} to ${chalk.cyan(application)}`);
122
+ });
123
+ };
124
+ export const createErc1155BatchCommand = () => {
125
+ return new Command("erc1155-batch")
126
+ .description("Deposits multiple ERC1155 tokens to the application")
127
+ .configureHelp({ showGlobalOptions: true })
128
+ .argument("[token-ids]", "token IDs separated by comma")
129
+ .argument("[amounts]", "amounts separated by comma")
130
+ .option("--token <address>", "ERC1155 token address")
131
+ .option("--base-layer-data <hex>", "base layer data", "0x")
132
+ .option("--exec-layer-data <hex>", "exec layer data", "0x")
133
+ .action(async (tokenIdsString, amountsString, options, command) => {
134
+ const { from } = command.optsWithGlobals();
135
+ // connect to anvil
136
+ const testClient = await connect(command.optsWithGlobals());
137
+ const token = await parseToken({
138
+ token: options.token,
139
+ });
140
+ // Parse token IDs
141
+ let tokenIds;
142
+ if (tokenIdsString) {
143
+ tokenIds = tokenIdsString
144
+ .split(",")
145
+ .map((id) => BigInt(id.trim()));
146
+ }
147
+ else {
148
+ // Prompt for token IDs if not provided
149
+ const user_input = await input({
150
+ message: "Token IDs (comma separated)",
151
+ });
152
+ tokenIds = user_input.split(",").map((id) => BigInt(id.trim()));
153
+ }
154
+ // Parse amounts
155
+ let amounts;
156
+ if (amountsString) {
157
+ amounts = amountsString.split(",").map((a) => BigInt(a.trim()));
158
+ }
159
+ else {
160
+ // Prompt for amounts if not provided
161
+ const user_input = await input({
162
+ message: "Amounts (comma separated)",
163
+ });
164
+ amounts = user_input.split(",").map((a) => BigInt(a.trim()));
165
+ }
166
+ if (tokenIds.length !== amounts.length) {
167
+ console.error(chalk.red("Token IDs and amounts must have the same length."));
168
+ return;
169
+ }
170
+ for (let i = 0; i < amounts.length; i++) {
171
+ if (amounts[i] <= BigInt(0)) {
172
+ console.error(chalk.red(`Amount of token Id: ${tokenIds[i]} to be deposited, must be greater than zero.`));
173
+ return;
174
+ }
175
+ }
176
+ const projectName = getProjectName(command.optsWithGlobals());
177
+ // get dapp address from local node, or ask
178
+ const application = await getInputApplicationAddress({
179
+ ...command.optsWithGlobals(),
180
+ projectName,
181
+ });
182
+ // the input sender, impersonated
183
+ const account = from && isAddress(from)
184
+ ? getAddress(from)
185
+ : (await testClient.getAddresses())[0];
186
+ const tokenAbi = testMultiTokenAbi;
187
+ const baseLayerData = isHex(options.baseLayerData)
188
+ ? options.baseLayerData
189
+ : "0x";
190
+ const execLayerData = isHex(options.execLayerData)
191
+ ? options.execLayerData
192
+ : "0x";
193
+ // progress spinner
194
+ const progress = ora();
195
+ // check balances
196
+ for (let i = 0; i < tokenIds.length; i++) {
197
+ const balance = await testClient.readContract({
198
+ abi: tokenAbi,
199
+ address: token.address,
200
+ functionName: "balanceOf",
201
+ args: [account, tokenIds[i]],
202
+ });
203
+ if (balance < amounts[i]) {
204
+ progress.fail(`Insufficient balance for token ID ${tokenIds[i]}`);
205
+ return;
206
+ }
207
+ }
208
+ // check if sufficiently approved
209
+ const isApproved = await testClient.readContract({
210
+ abi: tokenAbi,
211
+ address: token.address,
212
+ functionName: "isApprovedForAll",
213
+ args: [account, erc1155BatchPortalAddress],
214
+ });
215
+ // approve if needed
216
+ if (isApproved === false) {
217
+ progress.start(`Approving ERC1155Portal...`);
218
+ const { request } = await testClient.simulateContract({
219
+ abi: tokenAbi,
220
+ account,
221
+ address: token.address,
222
+ functionName: "setApprovalForAll",
223
+ args: [erc1155BatchPortalAddress, true],
224
+ });
225
+ const hash = await testClient.writeContract(request);
226
+ await testClient.waitForTransactionReceipt({ hash });
227
+ progress.succeed(`Approved ERC1155Portal`);
228
+ }
229
+ // simulate batch deposit call
230
+ const { request } = await testClient.simulateContract({
231
+ abi: erc1155BatchPortalAbi,
232
+ account,
233
+ address: erc1155BatchPortalAddress,
234
+ functionName: "depositBatchERC1155Token",
235
+ args: [
236
+ token.address,
237
+ application,
238
+ tokenIds,
239
+ amounts,
240
+ baseLayerData,
241
+ execLayerData,
242
+ ],
243
+ });
244
+ // for messages
245
+ const amountLabel = tokenIds
246
+ .map((id, i) => `${chalk.cyan(amounts[i])} units of token id ${id}`)
247
+ .join(", ");
248
+ // send deposit
249
+ progress.start(`Depositing tokens to ${chalk.cyan(application)}...`);
250
+ const hash = await testClient.writeContract(request);
251
+ await testClient.waitForTransactionReceipt({ hash });
252
+ progress.succeed(`Deposited ${amountLabel} to ${chalk.cyan(application)}`);
253
+ });
254
+ };
@@ -0,0 +1,10 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createErc20Command: () => Command<[string | undefined], {
3
+ [x: string]: never;
4
+ }, {
5
+ from?: string | undefined;
6
+ application?: string | undefined;
7
+ projectName?: string | undefined;
8
+ rpcUrl?: string | undefined;
9
+ }>;
10
+ //# sourceMappingURL=erc20.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erc20.d.ts","sourceRoot":"","sources":["../../../src/commands/deposit/erc20.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AA4EtD,eAAO,MAAM,kBAAkB;;;;;;;EAwG9B,CAAC"}