@cartesi/cli 2.0.0-alpha.13 → 2.0.0-alpha.15

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 (77) hide show
  1. package/dist/base.d.ts +8 -3
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +7 -4
  4. package/dist/commands/address-book.d.ts +1 -0
  5. package/dist/commands/address-book.d.ts.map +1 -1
  6. package/dist/commands/address-book.js +6 -3
  7. package/dist/commands/create.d.ts +1 -1
  8. package/dist/commands/create.d.ts.map +1 -1
  9. package/dist/commands/create.js +1 -0
  10. package/dist/commands/deploy.d.ts +1 -16
  11. package/dist/commands/deploy.d.ts.map +1 -1
  12. package/dist/commands/deploy.js +8 -267
  13. package/dist/commands/deposit/erc20.d.ts +11 -0
  14. package/dist/commands/deposit/erc20.d.ts.map +1 -0
  15. package/dist/commands/deposit/erc20.js +126 -0
  16. package/dist/commands/deposit/erc721.d.ts +12 -0
  17. package/dist/commands/deposit/erc721.d.ts.map +1 -0
  18. package/dist/commands/deposit/erc721.js +144 -0
  19. package/dist/commands/deposit/ether.d.ts +10 -0
  20. package/dist/commands/deposit/ether.d.ts.map +1 -0
  21. package/dist/commands/deposit/ether.js +66 -0
  22. package/dist/commands/deposit.d.ts +9 -0
  23. package/dist/commands/deposit.d.ts.map +1 -0
  24. package/dist/commands/deposit.js +36 -0
  25. package/dist/commands/logs.d.ts +1 -1
  26. package/dist/commands/logs.d.ts.map +1 -1
  27. package/dist/commands/logs.js +6 -4
  28. package/dist/commands/run.d.ts +13 -1
  29. package/dist/commands/run.d.ts.map +1 -1
  30. package/dist/commands/run.js +196 -4
  31. package/dist/commands/send.d.ts +6 -17
  32. package/dist/commands/send.d.ts.map +1 -1
  33. package/dist/commands/send.js +122 -59
  34. package/dist/commands/status.d.ts +1 -1
  35. package/dist/commands/status.d.ts.map +1 -1
  36. package/dist/commands/status.js +10 -7
  37. package/dist/compose/default.env +1 -1
  38. package/dist/compose/docker-compose-anvil.yaml +1 -1
  39. package/dist/compose/docker-compose-explorer.yaml +6 -5
  40. package/dist/compose/docker-compose-node.yaml +1 -4
  41. package/dist/config.d.ts +2 -2
  42. package/dist/config.d.ts.map +1 -1
  43. package/dist/config.js +2 -2
  44. package/dist/exec/cartesi-machine.js +1 -1
  45. package/dist/exec/rollups.d.ts +94 -5
  46. package/dist/exec/rollups.d.ts.map +1 -1
  47. package/dist/exec/rollups.js +356 -12
  48. package/dist/index.js +5 -7
  49. package/dist/prompts.d.ts +12 -1
  50. package/dist/prompts.d.ts.map +1 -1
  51. package/dist/prompts.js +58 -23
  52. package/dist/wallet.d.ts +15948 -21
  53. package/dist/wallet.d.ts.map +1 -1
  54. package/dist/wallet.js +33 -221
  55. package/package.json +24 -23
  56. package/dist/commands/send/eip712.d.ts +0 -34
  57. package/dist/commands/send/eip712.d.ts.map +0 -1
  58. package/dist/commands/send/eip712.js +0 -81
  59. package/dist/commands/send/erc20.d.ts +0 -12
  60. package/dist/commands/send/erc20.d.ts.map +0 -1
  61. package/dist/commands/send/erc20.js +0 -75
  62. package/dist/commands/send/erc721.d.ts +0 -12
  63. package/dist/commands/send/erc721.d.ts.map +0 -1
  64. package/dist/commands/send/erc721.js +0 -78
  65. package/dist/commands/send/ether.d.ts +0 -12
  66. package/dist/commands/send/ether.d.ts.map +0 -1
  67. package/dist/commands/send/ether.js +0 -36
  68. package/dist/commands/send/generic.d.ts +0 -15
  69. package/dist/commands/send/generic.d.ts.map +0 -1
  70. package/dist/commands/send/generic.js +0 -122
  71. package/dist/commands/start.d.ts +0 -14
  72. package/dist/commands/start.d.ts.map +0 -1
  73. package/dist/commands/start.js +0 -220
  74. package/dist/commands/stop.d.ts +0 -5
  75. package/dist/commands/stop.d.ts.map +0 -1
  76. package/dist/commands/stop.js +0 -27
  77. package/dist/compose/docker-compose-espresso.yaml +0 -81
package/dist/base.d.ts CHANGED
@@ -3,14 +3,19 @@ import { type Config } from "./config.js";
3
3
  export declare const getContextPath: (...paths: string[]) => string;
4
4
  export declare const getMachineHash: () => Hash | undefined;
5
5
  export declare const getApplicationConfig: (configPath: string) => Config;
6
+ export declare const getProjectName: (options: {
7
+ projectName?: string;
8
+ }) => string;
6
9
  export type AddressBook = Record<string, Address>;
7
- export declare const getAddressBook: () => Promise<AddressBook>;
10
+ export declare const getAddressBook: (options: {
11
+ projectName?: string;
12
+ }) => Promise<AddressBook>;
8
13
  export declare const getServiceState: (options: {
9
- environmentName: string;
14
+ projectName: string;
10
15
  service: string;
11
16
  }) => Promise<string | undefined>;
12
17
  export declare const getServiceHealth: (options: {
13
- environmentName: string;
18
+ projectName: string;
14
19
  service: string;
15
20
  }) => Promise<string | undefined>;
16
21
  export declare const parseAddress: (value: string) => Address | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,IAAI,EAKZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,KAAK,MAAM,EAAS,MAAM,aAAa,CAAC;AAkBjD,eAAO,MAAM,cAAc,GAAI,GAAG,OAAO,MAAM,EAAE,KAAG,MAEnD,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,IAAI,GAAG,SAUxC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,YAAY,MAAM,KAAG,MAIzD,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,WAAW,CAkC1D,CAAC;AAqBF,eAAO,MAAM,eAAe,GAAU,SAAS;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAG7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,SAAS;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAG7B,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAAO,GAAG,SAQtD,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,IAQzC,CAAC"}
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,IAAI,EAKZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,KAAK,MAAM,EAAS,MAAM,aAAa,CAAC;AAkBjD,eAAO,MAAM,cAAc,GAAI,GAAG,OAAO,MAAM,EAAE,KAAG,MAEnD,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,IAAI,GAAG,SAUxC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,YAAY,MAAM,KAAG,MAIzD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,SAAS;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,WAE/D,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,eAAO,MAAM,cAAc,GAAU,SAAS;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,KAAG,OAAO,CAAC,WAAW,CAkCtB,CAAC;AAqBF,eAAO,MAAM,eAAe,GAAU,SAAS;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAG7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,SAAS;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAG7B,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAAO,GAAG,SAQtD,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,IAQzC,CAAC"}
package/dist/base.js CHANGED
@@ -25,8 +25,11 @@ export const getApplicationConfig = (configPath) => {
25
25
  ? parse(fs.readFileSync(configPath).toString())
26
26
  : parse("");
27
27
  };
28
- export const getAddressBook = async () => {
29
- const applicationAddress = await getApplicationAddress();
28
+ export const getProjectName = (options) => {
29
+ return options.projectName ?? path.basename(process.cwd());
30
+ };
31
+ export const getAddressBook = async (options) => {
32
+ const applicationAddress = await getApplicationAddress(options);
30
33
  // build rollups contracts address book
31
34
  const contracts = {
32
35
  ApplicationFactory: applicationFactoryAddress,
@@ -58,12 +61,12 @@ export const getAddressBook = async () => {
58
61
  return contracts;
59
62
  };
60
63
  const getServiceInfo = async (options) => {
61
- const { environmentName, service } = options;
64
+ const { projectName, service } = options;
62
65
  // get service information
63
66
  const { stdout } = await execa("docker", [
64
67
  "compose",
65
68
  "--project-name",
66
- environmentName,
69
+ projectName,
67
70
  "ps",
68
71
  service,
69
72
  "--format",
@@ -1,5 +1,6 @@
1
1
  import { Command } from "@commander-js/extra-typings";
2
2
  export declare const createAddressBookCommand: () => Command<[], {
3
3
  json?: true | undefined;
4
+ projectName?: string | undefined;
4
5
  }, {}>;
5
6
  //# sourceMappingURL=address-book.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"address-book.d.ts","sourceRoot":"","sources":["../../src/commands/address-book.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,wBAAwB;;MAsCpC,CAAC"}
1
+ {"version":3,"file":"address-book.d.ts","sourceRoot":"","sources":["../../src/commands/address-book.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,wBAAwB;;;MA4CpC,CAAC"}
@@ -1,12 +1,15 @@
1
1
  import { Command } from "@commander-js/extra-typings";
2
2
  import Table from "cli-table3";
3
- import { getAddressBook } from "../base.js";
3
+ import { getAddressBook, getProjectName } from "../base.js";
4
4
  export const createAddressBookCommand = () => {
5
5
  return new Command("address-book")
6
6
  .description("Prints the addresses of all smart contracts deployed to the runtime environment of the application.")
7
7
  .option("--json", "Format output as json.")
8
- .action(async ({ json }) => {
9
- const addressBook = await getAddressBook();
8
+ .option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
9
+ .action(async (options) => {
10
+ const { json } = options;
11
+ const projectName = getProjectName(options);
12
+ const addressBook = await getAddressBook({ projectName });
10
13
  if (!json) {
11
14
  // print as a table
12
15
  const table = new Table({
@@ -1,7 +1,7 @@
1
1
  import { Command } from "@commander-js/extra-typings";
2
2
  export declare const DEFAULT_TEMPLATES_BRANCH = "prerelease/sdk-12";
3
3
  export declare const createCreateCommand: () => Command<[string], {
4
- template: "cpp" | "cpp-low-level" | "go" | "javascript" | "lua" | "python" | "ruby" | "rust" | "typescript";
4
+ template: "cpp" | "cpp-low-level" | "go" | "java" | "javascript" | "lua" | "python" | "ruby" | "rust" | "typescript";
5
5
  branch: string;
6
6
  }, {}>;
7
7
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
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;AAc5D,eAAO,MAAM,mBAAmB;;;MA0B/B,CAAC"}
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"}
@@ -7,6 +7,7 @@ const TEMPLATES = [
7
7
  "cpp",
8
8
  "cpp-low-level",
9
9
  "go",
10
+ "java",
10
11
  "javascript",
11
12
  "lua",
12
13
  "python",
@@ -1,18 +1,3 @@
1
1
  import { Command } from "@commander-js/extra-typings";
2
- export declare const createDeployCommand: () => Command<[], {
3
- environmentName: string;
4
- chainId: number;
5
- rpcUrl?: string | undefined;
6
- mnemonic?: string | undefined;
7
- mnemonicIndex: number;
8
- name?: string | undefined;
9
- authorityOwner?: `0x${string}` | undefined;
10
- applicationOwner?: `0x${string}` | undefined;
11
- epochLength: number;
12
- salt: `0x${string}`;
13
- json?: true | undefined;
14
- dataAvailability: "input-box" | "espresso";
15
- espressoBlock: number;
16
- espressoNamespace: number;
17
- }, {}>;
2
+ export declare const createDeployCommand: () => Command<[], {}, {}>;
18
3
  //# sourceMappingURL=deploy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAyQ9D,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;MAuJ/B,CAAC"}
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"}
@@ -1,271 +1,12 @@
1
- import { Command, Option } from "@commander-js/extra-typings";
2
- import input from "@inquirer/input";
1
+ import { Command } from "@commander-js/extra-typings";
3
2
  import chalk from "chalk";
4
- import { execa } from "execa";
5
- import ora from "ora";
6
- import { encodeFunctionData, zeroHash } from "viem";
7
- import { cannon } from "viem/chains";
8
- import { getContextPath, getMachineHash, parseAddress, parseHash, } from "../base.js";
9
- import { DEFAULT_COMPOSE_ENVIRONMENT_NAME } from "../config.js";
10
- import { applicationFactoryAbi, applicationFactoryAddress, authorityFactoryAbi, authorityFactoryAddress, dataAvailabilityAbi, inputBoxAddress, } from "../contracts.js";
11
- import { addressInput } from "../prompts.js";
12
- import { connect } from "./send.js";
13
- /**
14
- * Deploy authority contract (if not already deployed)
15
- * @param options
16
- * @returns address of the authority
17
- */
18
- const deployAuthority = async (publicClient, walletClient, options) => {
19
- const { epochLength, progress, salt } = options;
20
- // deploy authority contract (if not already deployed)
21
- const authorityOwner = options.authorityOwner ||
22
- (await addressInput({
23
- message: "Authority Owner",
24
- default: walletClient.account?.address,
25
- }));
26
- const authorityAddress = await publicClient.readContract({
27
- abi: authorityFactoryAbi,
28
- address: authorityFactoryAddress,
29
- functionName: "calculateAuthorityAddress",
30
- args: [authorityOwner, BigInt(epochLength), salt],
31
- });
32
- // check if authority is already deployed
33
- const authorityCode = await publicClient.getCode({
34
- address: authorityAddress,
35
- });
36
- if (authorityCode === undefined) {
37
- // deploy authority
38
- const { request } = await publicClient.simulateContract({
39
- abi: authorityFactoryAbi,
40
- address: authorityFactoryAddress,
41
- account: walletClient.account,
42
- functionName: "newAuthority",
43
- args: [authorityOwner, BigInt(epochLength), salt],
44
- });
45
- progress.start("Deploying authority...");
46
- const hash = await walletClient.writeContract(request);
47
- await publicClient.waitForTransactionReceipt({ hash });
48
- progress.succeed(`Authority ${chalk.cyan(authorityAddress)}`);
49
- }
50
- return authorityAddress;
51
- };
52
- /**
53
- * Deploy application contract
54
- * @param options
55
- * @returns address of the application
56
- */
57
- const deployApplication = async (publicClient, walletClient, options) => {
58
- const { authorityAddress, progress, salt, templateHash, dataAvailability } = options;
59
- const applicationOwner = options.applicationOwner ||
60
- (await addressInput({
61
- message: "Application Owner",
62
- default: walletClient.account?.address,
63
- }));
64
- const applicationAddress = await publicClient.readContract({
65
- abi: applicationFactoryAbi,
66
- address: applicationFactoryAddress,
67
- functionName: "calculateApplicationAddress",
68
- args: [
69
- authorityAddress,
70
- applicationOwner,
71
- templateHash,
72
- dataAvailability,
73
- salt,
74
- ],
75
- });
76
- // check if application is already deployed
77
- const applicationCode = await publicClient.getCode({
78
- address: applicationAddress,
79
- });
80
- if (applicationCode === undefined) {
81
- // deploy application
82
- const { request } = await publicClient.simulateContract({
83
- abi: applicationFactoryAbi,
84
- address: applicationFactoryAddress,
85
- account: walletClient.account,
86
- functionName: "newApplication",
87
- args: [
88
- authorityAddress,
89
- applicationOwner,
90
- templateHash,
91
- dataAvailability,
92
- salt,
93
- ],
94
- });
95
- progress.start("Deploying application...");
96
- const hash = await walletClient.writeContract(request);
97
- await publicClient.waitForTransactionReceipt({ hash });
98
- progress.succeed(`Application ${chalk.cyan(applicationAddress)}`);
99
- }
100
- else {
101
- // abort, because application is already deployed
102
- throw new Error(`Application ${chalk.cyan(templateHash)} already deployed to ${chalk.cyan(applicationAddress)}`);
103
- }
104
- return applicationAddress;
105
- };
106
- /**
107
- * Publish machine snapshot to rollups node by copying it to the rollups node container
108
- * @param options
109
- * @returns path to the snapshot in the rollups node
110
- */
111
- const publishMachine = async (options) => {
112
- const { progress, environmentName, templateHash } = options;
113
- const snapshotPath = getContextPath("image");
114
- const containerSnapshotPath = `/var/lib/cartesi-rollups-node/snapshots/${templateHash}/`;
115
- progress.start("Publishing machine snapshot...");
116
- await execa("docker", [
117
- "compose",
118
- "--project-name",
119
- environmentName,
120
- "cp",
121
- snapshotPath,
122
- `rollups-node:${containerSnapshotPath}`,
123
- ]);
124
- progress.succeed(`Machine snapshot ${chalk.cyan(containerSnapshotPath)}`);
125
- return containerSnapshotPath;
126
- };
127
- /**
128
- * Register application in rollups node
129
- * @param options
130
- * @returns name of the application
131
- */
132
- const registerApplication = async (options) => {
133
- const { applicationAddress, progress, environmentName, snapshotPath, dataAvailability, } = options;
134
- // use application address as the name of the deployment
135
- const name = options.name ??
136
- (await input({
137
- message: "Application Name",
138
- default: applicationAddress.toLowerCase(),
139
- }));
140
- // common app register args
141
- const registerArgs = [
142
- "--name",
143
- name,
144
- "--address",
145
- applicationAddress,
146
- "--template-path",
147
- snapshotPath,
148
- "--data-availability",
149
- dataAvailability,
150
- "--print-json",
151
- ];
152
- // deploy application
153
- progress.start("Registering application...");
154
- const { stdout } = await execa("docker", [
155
- "compose",
156
- "--project-name",
157
- environmentName,
158
- "exec",
159
- "rollups-node",
160
- "cartesi-rollups-cli",
161
- "app",
162
- "register",
163
- ...registerArgs,
164
- ]);
165
- const registration = stdout ? JSON.parse(stdout) : undefined;
166
- if (registration) {
167
- if (registration.state !== "ENABLED") {
168
- throw new Error(registration.reason);
169
- }
170
- progress.succeed(`Registration ${chalk.cyan(name)}`);
171
- }
172
- else {
173
- throw new Error("Failed to deploy application");
174
- }
175
- return name;
176
- };
177
- const parseDataAvailability = (type, espressoBlock, espressoNamespace) => {
178
- if (type === "espresso") {
179
- return encodeFunctionData({
180
- abi: dataAvailabilityAbi,
181
- functionName: "InputBoxAndEspresso",
182
- args: [inputBoxAddress, BigInt(espressoBlock), espressoNamespace],
183
- });
184
- }
185
- return encodeFunctionData({
186
- abi: dataAvailabilityAbi,
187
- functionName: "InputBox",
188
- args: [inputBoxAddress],
189
- });
190
- };
3
+ import { createBuildCommand } from "./deploy/build.js";
191
4
  export const createDeployCommand = () => {
192
- return new Command("deploy")
193
- .description("Deploy a rollups application to a rollups node.")
194
- .configureHelp({ showGlobalOptions: true })
195
- .option("--environment-name <string>", "name of environment", DEFAULT_COMPOSE_ENVIRONMENT_NAME)
196
- .option("--chain-id <id>", "Chain ID", Number.parseInt, 13370)
197
- .option("--rpc-url <url>", "RPC URL")
198
- .option("--mnemonic <phrase>", "Mnemonic passphrase")
199
- .option("--mnemonic-index <index>", "Mnemonic account index", Number.parseInt, 0)
200
- .option("--name <string>", "application name")
201
- .option("--authority-owner <address>", "authority owner", parseAddress, undefined)
202
- .option("--application-owner <address>", "application owner", parseAddress, undefined)
203
- .addOption(new Option("--epoch-length <number>", "length of an epoch (in blocks)")
204
- .argParser(Number)
205
- .default(720))
206
- .option("--salt <hash>", "salt for deployment", parseHash, zeroHash)
207
- .option("--json", "output in JSON format")
208
- .addOption(new Option("--data-availability <type>", "Data availability layer to use (input-box or espresso)")
209
- .choices(["input-box", "espresso"])
210
- .default("input-box"))
211
- .addOption(new Option("--espresso-block <number>", "espresso starting block")
212
- .argParser(Number)
213
- .default(1))
214
- .addOption(new Option("--espresso-namespace <number>", "espresso namespace Id")
215
- .argParser(Number)
216
- .default(1))
217
- .action(async (options, command) => {
218
- const { json, dataAvailability: daType, environmentName, espressoBlock, espressoNamespace, } = options;
219
- // If inputbox is chosen, warn if espresso args are provided
220
- if (daType === "input-box" &&
221
- (espressoBlock !== undefined || espressoNamespace !== undefined)) {
222
- console.warn(chalk.yellow("WARNING: --espresso-block and --espresso-namespace-id are ignored when --data-availability is input-box"));
223
- }
224
- const progress = ora();
225
- // get cartesi machine snapshot hash, produced by 'build'
226
- const templateHash = getMachineHash();
227
- if (!templateHash) {
228
- progress.fail(`Cartesi machine snapshot not found, run 'build'`);
229
- return;
230
- }
231
- progress.succeed(`Cartesi machine template hash ${chalk.cyan(templateHash)}`);
232
- // connect to some chain
233
- const { publicClient, walletClient } = await connect(options);
234
- try {
235
- // parse dataAvailability
236
- const dataAvailability = parseDataAvailability(daType, espressoBlock, espressoNamespace);
237
- // deploy authority contract (if not already deployed)
238
- const authorityAddress = await deployAuthority(publicClient, walletClient, { progress, ...options });
239
- // deploy application contract
240
- const applicationAddress = await deployApplication(publicClient, walletClient, {
241
- authorityAddress,
242
- progress,
243
- templateHash,
244
- ...options,
245
- dataAvailability,
246
- });
247
- if (publicClient.chain?.id === cannon.id) {
248
- // copy machine snapshot to rollups node container
249
- const containerSnapshotPath = await publishMachine({
250
- progress,
251
- templateHash,
252
- environmentName,
253
- });
254
- const name = await registerApplication({
255
- applicationAddress,
256
- progress,
257
- snapshotPath: containerSnapshotPath,
258
- ...options,
259
- dataAvailability,
260
- });
261
- }
262
- else {
263
- const snapshotPath = getContextPath("image");
264
- progress.succeed(`Done. Manually copy machine to rollups node ${chalk.cyan(snapshotPath)}`);
265
- }
266
- }
267
- catch (e) {
268
- progress.fail(e instanceof Error ? e.message : "Unknown error");
269
- }
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"));
270
9
  });
10
+ command.addCommand(createBuildCommand(), { hidden: true });
11
+ return command;
271
12
  };
@@ -0,0 +1,11 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createErc20Command: () => Command<[string | undefined], {
3
+ token?: string | undefined;
4
+ execLayerData: string;
5
+ }, {
6
+ from?: string | undefined;
7
+ application?: string | undefined;
8
+ projectName?: string | undefined;
9
+ rpcUrl?: string | undefined;
10
+ }>;
11
+ //# 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;;;;;;;;EAyG9B,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import chalk from "chalk";
3
+ import ora from "ora";
4
+ import { erc20Abi, formatUnits, getAddress, isAddress, isHex, parseUnits, } from "viem";
5
+ import { getProjectName } from "../../base.js";
6
+ import { erc20PortalAbi, erc20PortalAddress, testTokenAddress, } from "../../contracts.js";
7
+ import { addressInput, bigintInput, getInputApplicationAddress, } from "../../prompts.js";
8
+ import { connect } from "../../wallet.js";
9
+ const readToken = async (publicClient, address) => {
10
+ const args = { abi: erc20Abi, address };
11
+ const symbol = await publicClient.readContract({
12
+ ...args,
13
+ functionName: "symbol",
14
+ });
15
+ const name = await publicClient.readContract({
16
+ ...args,
17
+ functionName: "name",
18
+ });
19
+ const decimals = await publicClient.readContract({
20
+ ...args,
21
+ functionName: "decimals",
22
+ });
23
+ return {
24
+ address,
25
+ name,
26
+ symbol,
27
+ decimals,
28
+ };
29
+ };
30
+ const parseToken = async (options) => {
31
+ const { testClient } = options;
32
+ const address = options.token && isAddress(options.token)
33
+ ? getAddress(options.token)
34
+ : await addressInput({
35
+ message: "Token address",
36
+ default: testTokenAddress,
37
+ });
38
+ return readToken(testClient, address);
39
+ };
40
+ export const createErc20Command = () => {
41
+ // biome-ignore lint/complexity/noBannedTypes: commander pattern
42
+ return new Command("erc20")
43
+ .description("Deposit ERC-20 to the application")
44
+ .configureHelp({ showGlobalOptions: true })
45
+ .argument("[amount]", "amount to send")
46
+ .option("--token <address>", "token address")
47
+ .option("--exec-layer-data <hex>", "exec layer data", "0x")
48
+ .action(async (amountStr, options, command) => {
49
+ const { from } = command.optsWithGlobals();
50
+ const projectName = getProjectName(command.optsWithGlobals());
51
+ // connect to anvil
52
+ const testClient = await connect(command.optsWithGlobals());
53
+ // the input sender, impersonated
54
+ const account = from && isAddress(from)
55
+ ? getAddress(from)
56
+ : (await testClient.getAddresses())[0];
57
+ const token = await parseToken({
58
+ testClient,
59
+ token: options.token,
60
+ });
61
+ // get dapp address from local node, or ask
62
+ const application = await getInputApplicationAddress({
63
+ ...command.optsWithGlobals(),
64
+ projectName,
65
+ });
66
+ const { decimals, symbol } = token;
67
+ const amount = amountStr
68
+ ? parseUnits(amountStr, decimals)
69
+ : await bigintInput({
70
+ message: `Amount (${symbol})`,
71
+ decimals,
72
+ });
73
+ const execLayerData = isHex(options.execLayerData)
74
+ ? options.execLayerData
75
+ : "0x";
76
+ // progress spinner
77
+ const progress = ora();
78
+ // check balance
79
+ const balance = await testClient.readContract({
80
+ abi: erc20Abi,
81
+ address: token.address,
82
+ functionName: "balanceOf",
83
+ args: [account],
84
+ });
85
+ if (balance < amount) {
86
+ progress.fail("Insufficient balance");
87
+ return;
88
+ }
89
+ // check allowance
90
+ const allowance = await testClient.readContract({
91
+ abi: erc20Abi,
92
+ address: token.address,
93
+ functionName: "allowance",
94
+ args: [account, erc20PortalAddress],
95
+ });
96
+ // for messages
97
+ const amountLabel = `${chalk.cyan(formatUnits(amount, decimals))} ${symbol}`;
98
+ // approve if needed
99
+ if (allowance < amount) {
100
+ progress.start(`Approving ${amountStr}...`);
101
+ const { request } = await testClient.simulateContract({
102
+ abi: erc20Abi,
103
+ account,
104
+ address: token.address,
105
+ functionName: "approve",
106
+ args: [erc20PortalAddress, amount],
107
+ });
108
+ const hash = await testClient.writeContract(request);
109
+ await testClient.waitForTransactionReceipt({ hash });
110
+ progress.succeed(`Approved ${amountStr}`);
111
+ }
112
+ // simulate deposit call
113
+ const { request } = await testClient.simulateContract({
114
+ abi: erc20PortalAbi,
115
+ account,
116
+ address: erc20PortalAddress,
117
+ functionName: "depositERC20Tokens",
118
+ args: [token.address, application, amount, execLayerData],
119
+ });
120
+ // send deposit
121
+ progress.start(`Depositing ${amountLabel} to ${chalk.cyan(application)}...`);
122
+ const hash = await testClient.writeContract(request);
123
+ await testClient.waitForTransactionReceipt({ hash });
124
+ progress.succeed(`Deposited ${amountLabel} to ${chalk.cyan(application)}`);
125
+ });
126
+ };
@@ -0,0 +1,12 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createErc721Command: () => Command<[string | undefined], {
3
+ token?: string | undefined;
4
+ baseLayerData: string;
5
+ execLayerData: string;
6
+ }, {
7
+ from?: string | undefined;
8
+ application?: string | undefined;
9
+ projectName?: string | undefined;
10
+ rpcUrl?: string | undefined;
11
+ }>;
12
+ //# sourceMappingURL=erc721.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erc721.d.ts","sourceRoot":"","sources":["../../../src/commands/deposit/erc721.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAuEtD,eAAO,MAAM,mBAAmB;;;;;;;;;EAoI/B,CAAC"}