@cartesi/cli 2.0.0-alpha.2 → 2.0.0-alpha.20
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/dist/base.d.ts +28 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +109 -0
- package/dist/builder/directory.d.ts +2 -2
- package/dist/builder/directory.d.ts.map +1 -1
- package/dist/builder/directory.js +5 -3
- package/dist/builder/docker.d.ts +2 -2
- package/dist/builder/docker.d.ts.map +1 -1
- package/dist/builder/docker.js +39 -37
- package/dist/builder/empty.d.ts +1 -1
- package/dist/builder/empty.d.ts.map +1 -1
- package/dist/builder/empty.js +1 -1
- package/dist/builder/none.d.ts +1 -1
- package/dist/builder/none.d.ts.map +1 -1
- package/dist/builder/none.js +1 -1
- package/dist/builder/tar.d.ts +1 -1
- package/dist/builder/tar.d.ts.map +1 -1
- package/dist/builder/tar.js +1 -1
- package/dist/commands/address-book.d.ts +5 -8
- package/dist/commands/address-book.d.ts.map +1 -1
- package/dist/commands/address-book.js +18 -14
- package/dist/commands/build.d.ts +7 -11
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +82 -58
- package/dist/commands/clean.d.ts +2 -7
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +9 -10
- package/dist/commands/create.d.ts +6 -15
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +25 -54
- package/dist/commands/deploy/build.d.ts +2 -14
- package/dist/commands/deploy/build.d.ts.map +1 -1
- package/dist/commands/deploy/build.js +8 -61
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +12 -0
- package/dist/commands/deposit/erc1155.d.ts +18 -0
- package/dist/commands/deposit/erc1155.d.ts.map +1 -0
- package/dist/commands/deposit/erc1155.js +254 -0
- package/dist/commands/deposit/erc20.d.ts +10 -0
- package/dist/commands/deposit/erc20.d.ts.map +1 -0
- package/dist/commands/deposit/erc20.js +125 -0
- package/dist/commands/deposit/erc721.d.ts +10 -0
- package/dist/commands/deposit/erc721.d.ts.map +1 -0
- package/dist/commands/deposit/erc721.js +143 -0
- package/dist/commands/deposit/ether.d.ts +10 -0
- package/dist/commands/deposit/ether.d.ts.map +1 -0
- package/dist/commands/deposit/ether.js +65 -0
- package/dist/commands/deposit.d.ts +9 -0
- package/dist/commands/deposit.d.ts.map +1 -0
- package/dist/commands/deposit.js +37 -0
- package/dist/commands/doctor.d.ts +2 -12
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +90 -91
- package/dist/commands/hash.d.ts +4 -9
- package/dist/commands/hash.d.ts.map +1 -1
- package/dist/commands/hash.js +14 -14
- package/dist/commands/logs.d.ts +9 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +34 -0
- package/dist/commands/run.d.ts +14 -20
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +193 -182
- package/dist/commands/send.d.ts +10 -0
- package/dist/commands/send.d.ts.map +1 -0
- package/dist/commands/send.js +130 -0
- package/dist/commands/shell.d.ts +6 -14
- package/dist/commands/shell.d.ts.map +1 -1
- package/dist/commands/shell.js +34 -51
- package/dist/commands/status.d.ts +6 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +50 -0
- package/dist/compose/default.env +36 -0
- package/dist/compose/docker-compose-anvil.yaml +39 -0
- package/dist/compose/docker-compose-bundler.yaml +71 -0
- package/dist/{node → compose}/docker-compose-database.yaml +4 -2
- package/dist/compose/docker-compose-explorer.yaml +96 -0
- package/dist/compose/docker-compose-graphql.yaml +38 -0
- package/dist/compose/docker-compose-node-cpus.yaml +6 -0
- package/dist/compose/docker-compose-node-memory.yaml +6 -0
- package/dist/compose/docker-compose-node.yaml +50 -0
- package/dist/compose/docker-compose-passkey-server.yaml +37 -0
- package/dist/compose/docker-compose-paymaster.yaml +40 -0
- package/dist/compose/docker-compose-proxy.yaml +24 -0
- package/dist/config.d.ts +30 -9
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +93 -53
- package/dist/contracts.d.ts +1695 -1636
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +632 -592
- package/dist/exec/cartesi-machine.d.ts +2 -2
- package/dist/exec/cartesi-machine.d.ts.map +1 -1
- package/dist/exec/cartesi-machine.js +3 -5
- package/dist/exec/genext2fs.d.ts +6 -3
- package/dist/exec/genext2fs.d.ts.map +1 -1
- package/dist/exec/genext2fs.js +5 -5
- package/dist/exec/index.d.ts +0 -1
- package/dist/exec/index.d.ts.map +1 -1
- package/dist/exec/index.js +0 -1
- package/dist/exec/mksquashfs.d.ts +2 -2
- package/dist/exec/mksquashfs.d.ts.map +1 -1
- package/dist/exec/mksquashfs.js +4 -2
- package/dist/exec/rollups.d.ts +105 -0
- package/dist/exec/rollups.d.ts.map +1 -0
- package/dist/exec/rollups.js +383 -0
- package/dist/exec/util.d.ts +1 -16
- package/dist/exec/util.d.ts.map +1 -1
- package/dist/exec/util.js +3 -50
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -1
- package/dist/machine.d.ts +8 -2
- package/dist/machine.d.ts.map +1 -1
- package/dist/machine.js +26 -16
- package/dist/prompts.d.ts +13 -2
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +60 -26
- package/dist/template.d.ts +3 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +16 -0
- package/dist/wallet.d.ts +9222 -21
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +35 -198
- package/package.json +39 -57
- package/bin/dev.cmd +0 -3
- package/bin/dev.js +0 -25
- package/bin/run.cmd +0 -3
- package/bin/run.js +0 -8
- package/dist/baseCommand.d.ts +0 -22
- package/dist/baseCommand.d.ts.map +0 -1
- package/dist/baseCommand.js +0 -92
- package/dist/commands/deploy/index.d.ts +0 -12
- package/dist/commands/deploy/index.d.ts.map +0 -1
- package/dist/commands/deploy/index.js +0 -78
- package/dist/commands/send/erc20.d.ts +0 -14
- package/dist/commands/send/erc20.d.ts.map +0 -1
- package/dist/commands/send/erc20.js +0 -70
- package/dist/commands/send/erc721.d.ts +0 -14
- package/dist/commands/send/erc721.d.ts.map +0 -1
- package/dist/commands/send/erc721.js +0 -73
- package/dist/commands/send/ether.d.ts +0 -13
- package/dist/commands/send/ether.d.ts.map +0 -1
- package/dist/commands/send/ether.js +0 -32
- package/dist/commands/send/generic.d.ts +0 -15
- package/dist/commands/send/generic.d.ts.map +0 -1
- package/dist/commands/send/generic.js +0 -119
- package/dist/commands/send/index.d.ts +0 -28
- package/dist/commands/send/index.d.ts.map +0 -1
- package/dist/commands/send/index.js +0 -102
- package/dist/exec/crane.d.ts +0 -15
- package/dist/exec/crane.d.ts.map +0 -1
- package/dist/exec/crane.js +0 -17
- package/dist/flags.d.ts +0 -17
- package/dist/flags.d.ts.map +0 -1
- package/dist/flags.js +0 -28
- package/dist/node/DockerfileDeploy.txt +0 -4
- package/dist/node/default.env +0 -27
- package/dist/node/docker-compose-anvil.yaml +0 -50
- package/dist/node/docker-compose-bundler.yaml +0 -57
- package/dist/node/docker-compose-envfile.yaml +0 -4
- package/dist/node/docker-compose-explorer.yaml +0 -88
- package/dist/node/docker-compose-host.yaml +0 -30
- package/dist/node/docker-compose-paymaster.yaml +0 -33
- package/dist/node/docker-compose-prompt.yaml +0 -17
- package/dist/node/docker-compose-proxy.yaml +0 -48
- package/dist/node/docker-compose-snapshot-volume.yaml +0 -8
- package/dist/node/docker-compose-validator-cpus.yaml +0 -6
- package/dist/node/docker-compose-validator-memory.yaml +0 -6
- package/dist/node/docker-compose-validator.yaml +0 -59
- package/oclif.manifest.json +0 -876
package/dist/commands/clean.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
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":"
|
|
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"}
|
package/dist/commands/clean.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
1
2
|
import fs from "fs-extra";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 {
|
|
2
|
-
export declare const DEFAULT_TEMPLATES_BRANCH = "sdk-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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":"
|
|
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"}
|
package/dist/commands/create.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
6
|
-
export const DEFAULT_TEMPLATES_BRANCH = "sdk-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
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 {
|
|
2
|
-
export
|
|
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":"
|
|
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 {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 @@
|
|
|
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"}
|