@cartesi/cli 2.0.0-alpha.21 → 2.0.0-alpha.23
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/index.js +685 -50
- package/dist/index.js.map +785 -0
- package/package.json +80 -84
- package/LICENSE +0 -202
- package/dist/base.d.ts +0 -28
- package/dist/base.d.ts.map +0 -1
- package/dist/base.js +0 -109
- package/dist/builder/directory.d.ts +0 -3
- package/dist/builder/directory.d.ts.map +0 -1
- package/dist/builder/directory.js +0 -39
- package/dist/builder/docker.d.ts +0 -10
- package/dist/builder/docker.d.ts.map +0 -1
- package/dist/builder/docker.js +0 -114
- package/dist/builder/empty.d.ts +0 -3
- package/dist/builder/empty.d.ts.map +0 -1
- package/dist/builder/empty.js +0 -21
- package/dist/builder/index.d.ts +0 -6
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/builder/index.js +0 -5
- package/dist/builder/none.d.ts +0 -3
- package/dist/builder/none.d.ts.map +0 -1
- package/dist/builder/none.js +0 -11
- package/dist/builder/tar.d.ts +0 -3
- package/dist/builder/tar.d.ts.map +0 -1
- package/dist/builder/tar.js +0 -30
- package/dist/commands/address-book.d.ts +0 -6
- package/dist/commands/address-book.d.ts.map +0 -1
- package/dist/commands/address-book.js +0 -44
- package/dist/commands/build.d.ts +0 -8
- package/dist/commands/build.d.ts.map +0 -1
- package/dist/commands/build.js +0 -97
- package/dist/commands/clean.d.ts +0 -3
- package/dist/commands/clean.d.ts.map +0 -1
- package/dist/commands/clean.js +0 -10
- package/dist/commands/create.d.ts +0 -7
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js +0 -37
- package/dist/commands/deploy/build.d.ts +0 -3
- package/dist/commands/deploy/build.d.ts.map +0 -1
- package/dist/commands/deploy/build.js +0 -9
- package/dist/commands/deploy.d.ts +0 -3
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js +0 -12
- package/dist/commands/deposit/erc1155.d.ts +0 -18
- package/dist/commands/deposit/erc1155.d.ts.map +0 -1
- package/dist/commands/deposit/erc1155.js +0 -254
- package/dist/commands/deposit/erc20.d.ts +0 -10
- package/dist/commands/deposit/erc20.d.ts.map +0 -1
- package/dist/commands/deposit/erc20.js +0 -125
- package/dist/commands/deposit/erc721.d.ts +0 -10
- package/dist/commands/deposit/erc721.d.ts.map +0 -1
- package/dist/commands/deposit/erc721.js +0 -143
- package/dist/commands/deposit/ether.d.ts +0 -10
- package/dist/commands/deposit/ether.d.ts.map +0 -1
- package/dist/commands/deposit/ether.js +0 -65
- package/dist/commands/deposit.d.ts +0 -9
- package/dist/commands/deposit.d.ts.map +0 -1
- package/dist/commands/deposit.js +0 -37
- package/dist/commands/doctor.d.ts +0 -3
- package/dist/commands/doctor.d.ts.map +0 -1
- package/dist/commands/doctor.js +0 -105
- package/dist/commands/hash.d.ts +0 -5
- package/dist/commands/hash.d.ts.map +0 -1
- package/dist/commands/hash.js +0 -22
- package/dist/commands/logs.d.ts +0 -9
- package/dist/commands/logs.d.ts.map +0 -1
- package/dist/commands/logs.js +0 -34
- package/dist/commands/run.d.ts +0 -15
- package/dist/commands/run.d.ts.map +0 -1
- package/dist/commands/run.js +0 -202
- package/dist/commands/send.d.ts +0 -10
- package/dist/commands/send.d.ts.map +0 -1
- package/dist/commands/send.js +0 -130
- package/dist/commands/shell.d.ts +0 -7
- package/dist/commands/shell.d.ts.map +0 -1
- package/dist/commands/shell.js +0 -48
- package/dist/commands/status.d.ts +0 -6
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js +0 -50
- package/dist/compose/default.env +0 -36
- package/dist/compose/docker-compose-anvil.yaml +0 -39
- package/dist/compose/docker-compose-bundler.yaml +0 -71
- package/dist/compose/docker-compose-database.yaml +0 -12
- package/dist/compose/docker-compose-explorer.yaml +0 -96
- package/dist/compose/docker-compose-node-cpus.yaml +0 -6
- package/dist/compose/docker-compose-node-memory.yaml +0 -6
- package/dist/compose/docker-compose-node.yaml +0 -50
- package/dist/compose/docker-compose-passkey-server.yaml +0 -37
- package/dist/compose/docker-compose-paymaster.yaml +0 -40
- package/dist/compose/docker-compose-proxy.yaml +0 -24
- package/dist/config.d.ts +0 -124
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -418
- package/dist/contracts.d.ts +0 -4376
- package/dist/contracts.d.ts.map +0 -1
- package/dist/contracts.js +0 -1839
- package/dist/exec/cartesi-machine.d.ts +0 -9
- package/dist/exec/cartesi-machine.d.ts.map +0 -1
- package/dist/exec/cartesi-machine.js +0 -18
- package/dist/exec/genext2fs.d.ts +0 -31
- package/dist/exec/genext2fs.d.ts.map +0 -1
- package/dist/exec/genext2fs.js +0 -44
- package/dist/exec/index.d.ts +0 -4
- package/dist/exec/index.d.ts.map +0 -1
- package/dist/exec/index.js +0 -3
- package/dist/exec/mksquashfs.d.ts +0 -21
- package/dist/exec/mksquashfs.d.ts.map +0 -1
- package/dist/exec/mksquashfs.js +0 -47
- package/dist/exec/rollups.d.ts +0 -105
- package/dist/exec/rollups.d.ts.map +0 -1
- package/dist/exec/rollups.js +0 -375
- package/dist/exec/util.d.ts +0 -21
- package/dist/exec/util.d.ts.map +0 -1
- package/dist/exec/util.js +0 -31
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/machine.d.ts +0 -12
- package/dist/machine.d.ts.map +0 -1
- package/dist/machine.js +0 -90
- package/dist/prompts.d.ts +0 -73
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -192
- package/dist/template.d.ts +0 -3
- package/dist/template.d.ts.map +0 -1
- package/dist/template.js +0 -16
- package/dist/types/docker.d.ts +0 -22
- package/dist/types/docker.d.ts.map +0 -1
- package/dist/types/docker.js +0 -1
- package/dist/wallet.d.ts +0 -9225
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -41
|
@@ -1,254 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,125 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,143 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|