@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
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
return new Command("erc20")
|
|
42
|
+
.description("Deposit ERC-20 to the application")
|
|
43
|
+
.configureHelp({ showGlobalOptions: true })
|
|
44
|
+
.argument("[amount]", "amount to send")
|
|
45
|
+
.option("--token <address>", "token address")
|
|
46
|
+
.option("--exec-layer-data <hex>", "exec layer data", "0x")
|
|
47
|
+
.action(async (amountStr, options, command) => {
|
|
48
|
+
const { from } = command.optsWithGlobals();
|
|
49
|
+
const projectName = getProjectName(command.optsWithGlobals());
|
|
50
|
+
// connect to anvil
|
|
51
|
+
const testClient = await connect(command.optsWithGlobals());
|
|
52
|
+
// the input sender, impersonated
|
|
53
|
+
const account = from && isAddress(from)
|
|
54
|
+
? getAddress(from)
|
|
55
|
+
: (await testClient.getAddresses())[0];
|
|
56
|
+
const token = await parseToken({
|
|
57
|
+
testClient,
|
|
58
|
+
token: options.token,
|
|
59
|
+
});
|
|
60
|
+
// get dapp address from local node, or ask
|
|
61
|
+
const application = await getInputApplicationAddress({
|
|
62
|
+
...command.optsWithGlobals(),
|
|
63
|
+
projectName,
|
|
64
|
+
});
|
|
65
|
+
const { decimals, symbol } = token;
|
|
66
|
+
const amount = amountStr
|
|
67
|
+
? parseUnits(amountStr, decimals)
|
|
68
|
+
: await bigintInput({
|
|
69
|
+
message: `Amount (${symbol})`,
|
|
70
|
+
decimals,
|
|
71
|
+
});
|
|
72
|
+
const execLayerData = isHex(options.execLayerData)
|
|
73
|
+
? options.execLayerData
|
|
74
|
+
: "0x";
|
|
75
|
+
// progress spinner
|
|
76
|
+
const progress = ora();
|
|
77
|
+
// check balance
|
|
78
|
+
const balance = await testClient.readContract({
|
|
79
|
+
abi: erc20Abi,
|
|
80
|
+
address: token.address,
|
|
81
|
+
functionName: "balanceOf",
|
|
82
|
+
args: [account],
|
|
83
|
+
});
|
|
84
|
+
if (balance < amount) {
|
|
85
|
+
progress.fail("Insufficient balance");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// check allowance
|
|
89
|
+
const allowance = await testClient.readContract({
|
|
90
|
+
abi: erc20Abi,
|
|
91
|
+
address: token.address,
|
|
92
|
+
functionName: "allowance",
|
|
93
|
+
args: [account, erc20PortalAddress],
|
|
94
|
+
});
|
|
95
|
+
// for messages
|
|
96
|
+
const amountLabel = `${chalk.cyan(formatUnits(amount, decimals))} ${symbol}`;
|
|
97
|
+
// approve if needed
|
|
98
|
+
if (allowance < amount) {
|
|
99
|
+
progress.start(`Approving ${amountLabel}...`);
|
|
100
|
+
const { request } = await testClient.simulateContract({
|
|
101
|
+
abi: erc20Abi,
|
|
102
|
+
account,
|
|
103
|
+
address: token.address,
|
|
104
|
+
functionName: "approve",
|
|
105
|
+
args: [erc20PortalAddress, amount],
|
|
106
|
+
});
|
|
107
|
+
const hash = await testClient.writeContract(request);
|
|
108
|
+
await testClient.waitForTransactionReceipt({ hash });
|
|
109
|
+
progress.succeed(`Approved ${amountLabel}`);
|
|
110
|
+
}
|
|
111
|
+
// simulate deposit call
|
|
112
|
+
const { request } = await testClient.simulateContract({
|
|
113
|
+
abi: erc20PortalAbi,
|
|
114
|
+
account,
|
|
115
|
+
address: erc20PortalAddress,
|
|
116
|
+
functionName: "depositERC20Tokens",
|
|
117
|
+
args: [token.address, application, amount, execLayerData],
|
|
118
|
+
});
|
|
119
|
+
// send deposit
|
|
120
|
+
progress.start(`Depositing ${amountLabel} to ${chalk.cyan(application)}...`);
|
|
121
|
+
const hash = await testClient.writeContract(request);
|
|
122
|
+
await testClient.waitForTransactionReceipt({ hash });
|
|
123
|
+
progress.succeed(`Deposited ${amountLabel} to ${chalk.cyan(application)}`);
|
|
124
|
+
});
|
|
125
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createErc721Command: () => 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=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;;;;;;;EAmI/B,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { BaseError, ContractFunctionRevertedError, erc721Abi, getAddress, isAddress, isHex, } from "viem";
|
|
5
|
+
import { getProjectName } from "../../base.js";
|
|
6
|
+
import { erc721PortalAbi, erc721PortalAddress, testNftAbi, testNftAddress, } 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: erc721Abi, 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
|
+
return {
|
|
20
|
+
address,
|
|
21
|
+
name,
|
|
22
|
+
symbol,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const parseToken = async (options) => {
|
|
26
|
+
const { testClient } = options;
|
|
27
|
+
const address = options.token && isAddress(options.token)
|
|
28
|
+
? getAddress(options.token)
|
|
29
|
+
: await addressInput({
|
|
30
|
+
message: "Token address",
|
|
31
|
+
default: testNftAddress,
|
|
32
|
+
});
|
|
33
|
+
return readToken(testClient, address);
|
|
34
|
+
};
|
|
35
|
+
export const createErc721Command = () => {
|
|
36
|
+
return new Command("erc721")
|
|
37
|
+
.description("Deposit ERC-721 to the application")
|
|
38
|
+
.configureHelp({ showGlobalOptions: true })
|
|
39
|
+
.argument("[token-id]", "token ID")
|
|
40
|
+
.option("--token <address>", "token address")
|
|
41
|
+
.option("--base-layer-data <hex>", "base layer data", "0x")
|
|
42
|
+
.option("--exec-layer-data <hex>", "exec layer data", "0x")
|
|
43
|
+
.action(async (tokenIdStr, options, command) => {
|
|
44
|
+
const { from } = command.optsWithGlobals();
|
|
45
|
+
const tokenId = tokenIdStr
|
|
46
|
+
? BigInt(tokenIdStr)
|
|
47
|
+
: await bigintInput({ decimals: 0, message: "Token ID" });
|
|
48
|
+
const projectName = getProjectName(command.optsWithGlobals());
|
|
49
|
+
// connect to anvil
|
|
50
|
+
const testClient = await connect(command.optsWithGlobals());
|
|
51
|
+
// the input sender, impersonated
|
|
52
|
+
const account = from && isAddress(from)
|
|
53
|
+
? getAddress(from)
|
|
54
|
+
: (await testClient.getAddresses())[0];
|
|
55
|
+
const token = await parseToken({
|
|
56
|
+
testClient,
|
|
57
|
+
token: options.token,
|
|
58
|
+
});
|
|
59
|
+
const tokenAbi = token.address === testNftAddress ? testNftAbi : erc721Abi;
|
|
60
|
+
// get dapp address from local node, or ask
|
|
61
|
+
const application = await getInputApplicationAddress({
|
|
62
|
+
...command.optsWithGlobals(),
|
|
63
|
+
projectName,
|
|
64
|
+
});
|
|
65
|
+
const { symbol } = token;
|
|
66
|
+
const baseLayerData = isHex(options.baseLayerData)
|
|
67
|
+
? options.baseLayerData
|
|
68
|
+
: "0x";
|
|
69
|
+
const execLayerData = isHex(options.execLayerData)
|
|
70
|
+
? options.execLayerData
|
|
71
|
+
: "0x";
|
|
72
|
+
// progress spinner
|
|
73
|
+
const progress = ora();
|
|
74
|
+
// check balance
|
|
75
|
+
try {
|
|
76
|
+
const currentOwner = await testClient.readContract({
|
|
77
|
+
abi: tokenAbi,
|
|
78
|
+
address: token.address,
|
|
79
|
+
args: [tokenId],
|
|
80
|
+
functionName: "ownerOf",
|
|
81
|
+
});
|
|
82
|
+
if (currentOwner !== account) {
|
|
83
|
+
progress.fail("Insufficient balance");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
if (e instanceof BaseError) {
|
|
89
|
+
const revertError = e.walk((err) => err instanceof ContractFunctionRevertedError);
|
|
90
|
+
if (revertError instanceof ContractFunctionRevertedError) {
|
|
91
|
+
const errorName = revertError.data?.errorName ?? "";
|
|
92
|
+
if (errorName === "ERC721NonexistentToken") {
|
|
93
|
+
progress.fail(`Token ${tokenIdStr} does not exist`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
progress.fail("Failed to check ownership");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// check allowance
|
|
101
|
+
const operator = await testClient.readContract({
|
|
102
|
+
abi: tokenAbi,
|
|
103
|
+
address: token.address,
|
|
104
|
+
args: [tokenId],
|
|
105
|
+
functionName: "getApproved",
|
|
106
|
+
});
|
|
107
|
+
// for messages
|
|
108
|
+
const amountStr = `${chalk.cyan(tokenIdStr)} ${symbol}`;
|
|
109
|
+
// approve if needed
|
|
110
|
+
if (operator !== erc721PortalAddress) {
|
|
111
|
+
progress.start(`Approving ${amountStr}...`);
|
|
112
|
+
const { request } = await testClient.simulateContract({
|
|
113
|
+
abi: tokenAbi,
|
|
114
|
+
account,
|
|
115
|
+
address: token.address,
|
|
116
|
+
functionName: "approve",
|
|
117
|
+
args: [erc721PortalAddress, tokenId],
|
|
118
|
+
});
|
|
119
|
+
const hash = await testClient.writeContract(request);
|
|
120
|
+
await testClient.waitForTransactionReceipt({ hash });
|
|
121
|
+
progress.succeed(`Approved ${amountStr}`);
|
|
122
|
+
}
|
|
123
|
+
// simulate deposit call
|
|
124
|
+
const { request } = await testClient.simulateContract({
|
|
125
|
+
abi: erc721PortalAbi,
|
|
126
|
+
account,
|
|
127
|
+
address: erc721PortalAddress,
|
|
128
|
+
functionName: "depositERC721Token",
|
|
129
|
+
args: [
|
|
130
|
+
token.address,
|
|
131
|
+
application,
|
|
132
|
+
tokenId,
|
|
133
|
+
baseLayerData,
|
|
134
|
+
execLayerData,
|
|
135
|
+
],
|
|
136
|
+
});
|
|
137
|
+
// send deposit
|
|
138
|
+
progress.start(`Depositing ${amountStr} to ${chalk.cyan(application)}...`);
|
|
139
|
+
const hash = await testClient.writeContract(request);
|
|
140
|
+
await testClient.waitForTransactionReceipt({ hash });
|
|
141
|
+
progress.succeed(`Deposited ${amountStr} to ${chalk.cyan(application)}`);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createEtherCommand: () => 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=ether.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ether.d.ts","sourceRoot":"","sources":["../../../src/commands/deposit/ether.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAUtD,eAAO,MAAM,kBAAkB;;;;;;;EAwE9B,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { formatUnits, getAddress, isAddress, isHex, parseUnits } from "viem";
|
|
5
|
+
import { getProjectName } from "../../base.js";
|
|
6
|
+
import { etherPortalAbi, etherPortalAddress } from "../../contracts.js";
|
|
7
|
+
import { bigintInput, getInputApplicationAddress } from "../../prompts.js";
|
|
8
|
+
import { connect } from "../../wallet.js";
|
|
9
|
+
export const createEtherCommand = () => {
|
|
10
|
+
return new Command("ether")
|
|
11
|
+
.description("Deposit ether to the application")
|
|
12
|
+
.configureHelp({ showGlobalOptions: true })
|
|
13
|
+
.argument("[amount]", "amount, in ETH units")
|
|
14
|
+
.option("--exec-layer-data <hex>", "exec layer data", "0x")
|
|
15
|
+
.action(async (amountStr, options, command) => {
|
|
16
|
+
const { from } = command.optsWithGlobals();
|
|
17
|
+
const projectName = getProjectName(command.optsWithGlobals());
|
|
18
|
+
// connect to anvil
|
|
19
|
+
const testClient = await connect(command.optsWithGlobals());
|
|
20
|
+
// the input sender, impersonated
|
|
21
|
+
const account = from && isAddress(from)
|
|
22
|
+
? getAddress(from)
|
|
23
|
+
: (await testClient.getAddresses())[0];
|
|
24
|
+
// get dapp address from local node, or ask
|
|
25
|
+
const application = await getInputApplicationAddress({
|
|
26
|
+
...command.optsWithGlobals(),
|
|
27
|
+
projectName,
|
|
28
|
+
});
|
|
29
|
+
const { decimals, symbol } = testClient.chain.nativeCurrency;
|
|
30
|
+
const amount = amountStr
|
|
31
|
+
? parseUnits(amountStr, decimals)
|
|
32
|
+
: await bigintInput({
|
|
33
|
+
message: `Amount (${symbol})`,
|
|
34
|
+
decimals,
|
|
35
|
+
});
|
|
36
|
+
const execLayerData = isHex(options.execLayerData)
|
|
37
|
+
? options.execLayerData
|
|
38
|
+
: "0x";
|
|
39
|
+
// progress spinner
|
|
40
|
+
const progress = ora();
|
|
41
|
+
// for messages
|
|
42
|
+
const amountLabel = `${chalk.cyan(formatUnits(amount, decimals))} ${symbol}`;
|
|
43
|
+
// check balance
|
|
44
|
+
const balance = await testClient.getBalance({
|
|
45
|
+
address: account,
|
|
46
|
+
});
|
|
47
|
+
if (balance < amount) {
|
|
48
|
+
progress.fail("Insufficient balance");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const { request } = await testClient.simulateContract({
|
|
52
|
+
abi: etherPortalAbi,
|
|
53
|
+
account,
|
|
54
|
+
address: etherPortalAddress,
|
|
55
|
+
args: [application, execLayerData],
|
|
56
|
+
functionName: "depositEther",
|
|
57
|
+
value: amount,
|
|
58
|
+
});
|
|
59
|
+
// send deposit
|
|
60
|
+
progress.start(`Depositing ${amountLabel} to ${chalk.cyan(application)}...`);
|
|
61
|
+
const hash = await testClient.writeContract(request);
|
|
62
|
+
await testClient.waitForTransactionReceipt({ hash });
|
|
63
|
+
progress.succeed(`Deposited ${amountLabel} to ${chalk.cyan(application)}`);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createDepositCommand: () => Command<[], {
|
|
3
|
+
from?: string | undefined;
|
|
4
|
+
application?: string | undefined;
|
|
5
|
+
projectName?: string | undefined;
|
|
6
|
+
rpcUrl?: string | undefined;
|
|
7
|
+
}, {}>;
|
|
8
|
+
export type DepositCommandOpts = ReturnType<ReturnType<typeof createDepositCommand>["opts"]>;
|
|
9
|
+
//# sourceMappingURL=deposit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../../src/commands/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAUtD,eAAO,MAAM,oBAAoB;;;;;MAsChC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,UAAU,CACvC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAClD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import select from "@inquirer/select";
|
|
3
|
+
import { createErc1155BatchCommand, createErc1155SingleCommand, } from "./deposit/erc1155.js";
|
|
4
|
+
import { createErc20Command } from "./deposit/erc20.js";
|
|
5
|
+
import { createErc721Command } from "./deposit/erc721.js";
|
|
6
|
+
import { createEtherCommand } from "./deposit/ether.js";
|
|
7
|
+
export const createDepositCommand = () => {
|
|
8
|
+
const command = new Command("deposit")
|
|
9
|
+
.description("Deposits an asset to the application")
|
|
10
|
+
.configureHelp({ showGlobalOptions: true })
|
|
11
|
+
.option("--from <address>", "input sender address")
|
|
12
|
+
.option("--application <address>", "application address")
|
|
13
|
+
.option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
|
|
14
|
+
.option("--rpc-url <url>", "RPC URL of the Cartesi Devnet")
|
|
15
|
+
.action(async (_options, command) => {
|
|
16
|
+
// get registered subcommands
|
|
17
|
+
const commands = command.commands;
|
|
18
|
+
// create choices for the selected prompt based on registered subcommands
|
|
19
|
+
const choices = commands.map((cmd) => ({
|
|
20
|
+
name: cmd.name(),
|
|
21
|
+
value: cmd,
|
|
22
|
+
description: cmd.description(),
|
|
23
|
+
}));
|
|
24
|
+
const subcommand = await select({
|
|
25
|
+
choices,
|
|
26
|
+
message: "Select type of asset to deposit",
|
|
27
|
+
});
|
|
28
|
+
// execute selected subcommand
|
|
29
|
+
subcommand.parseAsync(command.args);
|
|
30
|
+
});
|
|
31
|
+
command.addCommand(createEtherCommand());
|
|
32
|
+
command.addCommand(createErc20Command());
|
|
33
|
+
command.addCommand(createErc721Command());
|
|
34
|
+
command.addCommand(createErc1155SingleCommand());
|
|
35
|
+
command.addCommand(createErc1155BatchCommand());
|
|
36
|
+
return command;
|
|
37
|
+
};
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
private static MINIMUM_DOCKER_VERSION;
|
|
6
|
-
private static MINIMUM_DOCKER_COMPOSE_VERSION;
|
|
7
|
-
private static MINIMUM_BUILDX_VERSION;
|
|
8
|
-
private checkDocker;
|
|
9
|
-
private checkCompose;
|
|
10
|
-
private checkBuildx;
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
}
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createDoctorCommand: () => Command<[], {}, {}>;
|
|
13
3
|
//# sourceMappingURL=doctor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAyHtD,eAAO,MAAM,mBAAmB,2BAa/B,CAAC"}
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,106 +1,105 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import chalk from "chalk";
|
|
1
3
|
import { execa } from "execa";
|
|
4
|
+
import ora from "ora";
|
|
2
5
|
import semver from "semver";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
6
|
+
const MINIMUM_DOCKER_VERSION = "23.0.0"; // Replace with our minimum required Docker version
|
|
7
|
+
const MINIMUM_DOCKER_COMPOSE_VERSION = "2.21.0"; // Replace with our minimum required Docker Compose version
|
|
8
|
+
const MINIMUM_BUILDX_VERSION = "0.13.0"; // Replace with our minimum required Buildx version
|
|
9
|
+
const checkDocker = async (progress) => {
|
|
10
|
+
try {
|
|
11
|
+
progress.start("Checking Docker Engine version...");
|
|
12
|
+
const { stdout: dockerVersion } = await execa("docker", [
|
|
13
|
+
"version",
|
|
14
|
+
"--format",
|
|
15
|
+
"{{json .Client.Version}}",
|
|
16
|
+
]);
|
|
17
|
+
const v = semver.coerce(dockerVersion);
|
|
18
|
+
if (v !== null && !semver.gte(v, MINIMUM_DOCKER_VERSION)) {
|
|
19
|
+
throw new Error(`Unsupported Docker version. Minimum required version is ${MINIMUM_DOCKER_VERSION}. Installed version is ${v}.`);
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw e;
|
|
25
|
-
}
|
|
21
|
+
progress.succeed(`Docker Engine ${chalk.cyan(v)}`);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (e instanceof Error &&
|
|
25
|
+
e.code === "ENOENT") {
|
|
26
|
+
throw new Error("Docker not found");
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
throw e;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
32
|
+
const checkCompose = async (progress) => {
|
|
33
|
+
try {
|
|
34
|
+
progress.start("Checking Docker Compose version...");
|
|
35
|
+
const { stdout: dockerComposeVersion } = await execa("docker", [
|
|
36
|
+
"compose",
|
|
37
|
+
"version",
|
|
38
|
+
"--short",
|
|
39
|
+
]);
|
|
40
|
+
const v = semver.coerce(dockerComposeVersion);
|
|
41
|
+
if (v !== null && !semver.gte(v, MINIMUM_DOCKER_COMPOSE_VERSION)) {
|
|
42
|
+
throw new Error(`Unsupported Docker Compose version. Minimum required version is ${MINIMUM_DOCKER_COMPOSE_VERSION}. Installed version is ${v}.`);
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
throw e;
|
|
49
|
-
}
|
|
44
|
+
progress.succeed(`Docker Compose ${chalk.cyan(dockerComposeVersion)}`);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (e instanceof Error &&
|
|
48
|
+
e.exitCode === 125) {
|
|
49
|
+
throw new Error("Docker Compose is required but not installed or the command execution failed. Please refer to the Docker Compose documentation for installation instructions: https://docs.docker.com/compose/install/");
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
throw e;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"buildx",
|
|
66
|
-
"ls",
|
|
67
|
-
"--format",
|
|
68
|
-
"{{.Platforms}}",
|
|
69
|
-
]);
|
|
70
|
-
const buildxPlatforms = platformsOutput
|
|
71
|
-
.split(",")
|
|
72
|
-
.map((platform) => platform.trim());
|
|
73
|
-
if (!buildxPlatforms.includes("linux/riscv64")) {
|
|
74
|
-
throw new Error("Your system does not support riscv64 architecture. Run `docker run --privileged --rm tonistiigi/binfmt:riscv` to enable riscv64 support.");
|
|
75
|
-
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
const checkBuildx = async (progress) => {
|
|
56
|
+
try {
|
|
57
|
+
progress.start("Checking Docker Buildx version...");
|
|
58
|
+
const { stdout: buildxOutput } = await execa("docker", [
|
|
59
|
+
"buildx",
|
|
60
|
+
"version",
|
|
61
|
+
]);
|
|
62
|
+
const v = semver.coerce(buildxOutput);
|
|
63
|
+
if (v !== null && !semver.gte(v, MINIMUM_BUILDX_VERSION)) {
|
|
64
|
+
throw new Error(`Unsupported Docker Buildx version. Minimum required version is ${MINIMUM_BUILDX_VERSION}. Installed version is ${v}.`);
|
|
76
65
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
progress.succeed(`Docker Buildx ${chalk.cyan(v)}`);
|
|
67
|
+
progress.start("Checking Docker RISC-V support...");
|
|
68
|
+
const { stdout: platformsOutput } = await execa("docker", [
|
|
69
|
+
"buildx",
|
|
70
|
+
"ls",
|
|
71
|
+
"--format",
|
|
72
|
+
"{{.Platforms}}",
|
|
73
|
+
]);
|
|
74
|
+
const buildxPlatforms = platformsOutput
|
|
75
|
+
.split(",")
|
|
76
|
+
.map((platform) => platform.trim());
|
|
77
|
+
if (!buildxPlatforms.includes("linux/riscv64")) {
|
|
78
|
+
throw new Error("Your system does not support riscv64 architecture. Run `docker run --privileged --rm tonistiigi/binfmt:riscv` to enable riscv64 support.");
|
|
85
79
|
}
|
|
86
|
-
|
|
80
|
+
progress.succeed(`Docker RISC-V support ${chalk.cyan("linux/riscv64")}`);
|
|
87
81
|
}
|
|
88
|
-
|
|
82
|
+
catch (e) {
|
|
83
|
+
if (e instanceof Error &&
|
|
84
|
+
e.exitCode === 125) {
|
|
85
|
+
throw new Error("Docker Buildx is required but not installed. Please refer to the Docker Desktop documentation for installation instructions: https://docs.docker.com/desktop/");
|
|
86
|
+
}
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
};
|
|
91
|
+
export const createDoctorCommand = () => {
|
|
92
|
+
return new Command("doctor").action(async () => {
|
|
93
|
+
const progress = ora();
|
|
89
94
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
await checkDocker(progress);
|
|
96
|
+
await checkCompose(progress);
|
|
97
|
+
await checkBuildx(progress);
|
|
98
|
+
progress.succeed("Your system is ready.");
|
|
94
99
|
}
|
|
95
100
|
catch (e) {
|
|
96
|
-
|
|
101
|
+
progress.fail(e.message);
|
|
102
|
+
process.exit(1);
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
DoctorCommand.description = "Verify the minimal sytem requirements";
|
|
102
|
-
DoctorCommand.examples = ["<%= config.bin %> <%= command.id %>"];
|
|
103
|
-
DoctorCommand.MINIMUM_DOCKER_VERSION = "23.0.0"; // Replace with our minimum required Docker version
|
|
104
|
-
DoctorCommand.MINIMUM_DOCKER_COMPOSE_VERSION = "2.21.0"; // Replace with our minimum required Docker Compose version
|
|
105
|
-
DoctorCommand.MINIMUM_BUILDX_VERSION = "0.13.0"; // Replace with our minimum required Buildx version
|
|
106
|
-
export default DoctorCommand;
|
|
104
|
+
});
|
|
105
|
+
};
|
package/dist/commands/hash.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
static enableJsonFlag: boolean;
|
|
6
|
-
run(): Promise<{
|
|
7
|
-
hash: `0x${string}`;
|
|
8
|
-
} | undefined>;
|
|
9
|
-
}
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createHashCommand: () => Command<[], {
|
|
3
|
+
json?: true | undefined;
|
|
4
|
+
}, {}>;
|
|
10
5
|
//# sourceMappingURL=hash.d.ts.map
|