Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account Abstraction in CLI #59

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-cougars-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": minor
---

flags to disable optional services (explorer, bundler, paymaster)
5 changes: 5 additions & 0 deletions .changeset/neat-frogs-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": minor
---

account abstraction contracts information
5 changes: 5 additions & 0 deletions .changeset/sixty-pants-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

remove workaround of anvil bug
5 changes: 5 additions & 0 deletions .changeset/tasty-hornets-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": minor
---

account abstraction services (bundler and paymaster)
5 changes: 5 additions & 0 deletions .changeset/tidy-trees-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

enable json output of cartesi deploy build
5 changes: 5 additions & 0 deletions .changeset/witty-lemons-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/mock-verifying-paymaster": patch
---

printing contract address on startup
10 changes: 10 additions & 0 deletions apps/cli/src/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,26 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
AuthorityHistoryPairFactory: authorityHistoryPairFactoryAddress,
CartesiDAppFactory: cartesiDAppFactoryAddress,
DAppAddressRelay: dAppAddressRelayAddress,
EntryPointV06: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
EntryPointV07: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
ERC1155BatchPortal: erc1155BatchPortalAddress,
ERC1155SinglePortal: erc1155SinglePortalAddress,
ERC20Portal: erc20PortalAddress,
ERC721Portal: erc721PortalAddress,
EtherPortal: etherPortalAddress,
InputBox: inputBoxAddress,
LightAccountFactory: "0x00004EC70002a32400f8ae005A26081065620D20",
SelfHostedApplicationFactory: selfHostedApplicationFactoryAddress,
SimpleAccountFactory: "0x9406Cc6185a346906296840746125a0E44976454",
SmartAccountFactory: "0x000000a56Aaca3e9a4C479ea6b6CD0DbcB6634F5",
KernelFactoryV2: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3",
KernelFactoryV3: "0x6723b44Abeec4E71eBE3232BD5B455805baDD22f",
KernelFactoryV3_1: "0xaac5D4240AF87249B3f71BC8E4A2cae074A3E419",
TestToken: testTokenAddress,
TestNFT: testNftAddress,
TestMultiToken: testMultiTokenAddress,
VerifyingPaymasterV06: "0x28ec0633192d0cBd9E1156CE05D5FdACAcB93947",
VerifyingPaymasterV07: "0xc5c97885C67F7361aBAfD2B95067a5bBdA603608",
};

// get dapp address
Expand Down
6 changes: 4 additions & 2 deletions apps/cli/src/commands/deploy/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class DeployBuild extends BaseCommand<typeof DeployBuild> {
}),
};

public static enableJsonFlag = true;

private async buildRollupsImage(platform?: string) {
const buildResult = tmpNameSync();
const imagePath = this.getContextPath("image");
Expand Down Expand Up @@ -53,7 +55,7 @@ export default class DeployBuild extends BaseCommand<typeof DeployBuild> {
return fs.readFileSync(buildResult, "utf8");
}

public async run(): Promise<string> {
public async run() {
const { flags } = await this.parse(DeployBuild);

// print machine hash
Expand All @@ -75,6 +77,6 @@ export default class DeployBuild extends BaseCommand<typeof DeployBuild> {
value: image,
});

return image;
return { image };
}
}
31 changes: 30 additions & 1 deletion apps/cli/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
description: "interval between blocks (in seconds)",
default: 5,
}),
"disable-explorer": Flags.boolean({
default: false,
description:
"disable local explorer service to save machine resources",
summary: "disable explorer service",
}),
"disable-bundler": Flags.boolean({
default: false,
description:
"disable local bundler service to save machine resources",
summary: "disable bundler service",
}),
"disable-paymaster": Flags.boolean({
default: false,
description:
"disable local paymaster service to save machine resources",
summary: "disable paymaster service",
}),
"epoch-length": Flags.integer({
description: "length of an epoch (in blocks)",
default: 720,
Expand Down Expand Up @@ -99,7 +117,18 @@
composeFiles.push("docker-compose-anvil.yaml");

// explorer
composeFiles.push("docker-compose-explorer.yaml");
if (!flags["disable-explorer"]) {
composeFiles.push("docker-compose-explorer.yaml");
}

// account abstraction
if (!flags["disable-bundler"]) {
composeFiles.push("docker-compose-bundler.yaml");
}
if (!flags["disable-paymaster"] && !flags["disable-bundler"]) {
// only add paymaster if bundler is enabled
composeFiles.push("docker-compose-paymaster.yaml");
}

// load the no-backend compose file
if (flags["no-backend"]) {
Expand Down Expand Up @@ -147,7 +176,7 @@
});
} catch (e: unknown) {
// 130 is a graceful shutdown, so we can swallow it
if ((e as any).exitCode !== 130) {

Check warning on line 179 in apps/cli/src/commands/run.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
throw e;
}
} finally {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class Shell extends BaseCommand<typeof Shell> {
const ext2 = path.join(containerDir, path.basename(ext2Path));
const ramSize = "128Mi";
const driveLabel = "root";
const sdkImage = "cartesi/sdk:0.9.0"; // XXX: how to resolve sdk version?
const sdkImage = "cartesi/sdk:0.10.0"; // XXX: how to resolve sdk version?
const args = [
"run",
"--interactive",
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/node/docker-compose-anvil.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
anvil:
image: cartesi/sdk:0.9.0
image: cartesi/sdk:0.10.0
command:
[
"devnet",
Expand All @@ -19,7 +19,7 @@ services:
- 8545:8545

dapp_deployer:
image: cartesi/sdk:0.9.0
image: cartesi/sdk:0.10.0
restart: on-failure
depends_on:
anvil:
Expand Down
57 changes: 57 additions & 0 deletions apps/cli/src/node/docker-compose-bundler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
services:
alto:
image: cartesi/sdk:0.10.0
command:
- "alto"
- "--entrypoints"
- "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789,0x0000000071727De22E5E9d8BAf0edAc6f37da032"
- "--log-level"
- "info"
- "--entrypoint-simulation-contract"
- "0x74Cb5e4eE81b86e70f9045036a1C5477de69eE87"
- "--rpc-url"
- "http://anvil:8545"
- "--min-executor-balance"
- "0"
- "--utility-private-key"
- "0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97"
- "--executor-private-keys"
- "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6,0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356,0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e,0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba,0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a"
- "--max-block-range"
- "10000"
- "--safe-mode"
- "false"
- "--port"
- "4337"
- "--public-client-log-level"
- "error"
- "--wallet-client-log-level"
- "error"
- "--polling-interval"
- "100"
- "--enable-debug-endpoints"
prompt:
image: debian:bookworm-slim
environment:
PROMPT_TXT_06_BUNDLER: "Bundler running at http://localhost:${CARTESI_LISTEN_PORT}/bundler/rpc"

traefik-config-generator:
environment:
TRAEFIK_CONFIG_BUNDLER: |
http:
routers:
bundler:
rule: "PathPrefix(`/bundler`)"
middlewares:
- "remove-bundler-prefix"
service: bundler
middlewares:
remove-bundler-prefix:
replacePathRegex:
regex: "^/bundler/(.*)"
replacement: "/$1"
services:
bundler:
loadBalancer:
servers:
- url: "http://alto:4337"
5 changes: 0 additions & 5 deletions apps/cli/src/node/docker-compose-database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@ services:
retries: 5
environment:
- POSTGRES_PASSWORD=password

database_creator:
depends_on:
database:
condition: service_healthy
4 changes: 3 additions & 1 deletion apps/cli/src/node/docker-compose-explorer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ services:
database_creator:
image: postgres:15-alpine
command: ["createdb", "squid"]
depends_on:
database:
condition: service_healthy
environment:
PGHOST: ${PGHOST:-database}
PGPORT: ${PGPORT:-5432}
Expand Down Expand Up @@ -30,7 +33,6 @@ services:
CHAIN_ID: ${CHAIN_ID:-31337}
RPC_URL_31337: ${RPC_URL:-http://anvil:8545}
BLOCK_CONFIRMATIONS_31337: 0
GENESIS_BLOCK_31337: 22
DB_NAME: ${PGDATABASE:-squid}
DB_PORT: ${PGPORT:-5432}
DB_HOST: ${PGHOST:-database}
Expand Down
33 changes: 33 additions & 0 deletions apps/cli/src/node/docker-compose-paymaster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
mock-verifying-paymaster:
image: cartesi/sdk:0.10.0
command: "mock-verifying-paymaster"
environment:
- ALTO_RPC=http://alto:4337
- ANVIL_RPC=http://anvil:8545

prompt:
image: debian:bookworm-slim
environment:
PROMPT_TXT_07_PAYMASTER: "Paymaster running at http://localhost:${CARTESI_LISTEN_PORT}/paymaster/"

traefik-config-generator:
environment:
TRAEFIK_CONFIG_PAYMASTER: |
http:
routers:
paymaster:
rule: "PathPrefix(`/paymaster`)"
middlewares:
- "remove-paymaster-prefix"
service: paymaster
middlewares:
remove-paymaster-prefix:
replacePathRegex:
regex: "^/paymaster/(.*)"
replacement: "/$1"
services:
paymaster:
loadBalancer:
servers:
- url: "http://mock-verifying-paymaster:3000"
4 changes: 2 additions & 2 deletions packages/mock-verifying-paymaster/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
anvil:
image: cartesi/sdk:0.9.0
image: cartesi/sdk:0.10.0
command: ["devnet", "--block-time", "${BLOCK_TIME:-5}"]
healthcheck:
test: ["CMD", "eth_isready"]
Expand All @@ -13,7 +13,7 @@ services:
- 8545:8545

alto:
image: cartesi/sdk:0.9.0
image: cartesi/sdk:0.10.0
command:
[
"alto",
Expand Down
4 changes: 3 additions & 1 deletion packages/mock-verifying-paymaster/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ const main = async () => {
return reply.code(200).send({ message: "pong" });
});

const service = await app.listen({ host: "0.0.0.0", port: 3000 });
const service = await app.listen({ host: "0.0.0.0", port: 3001 });
console.log(`VerifyingPaymasterV06: ${verifyingPaymasterV06.address}`);
console.log(`VerifyingPaymasterV07: ${verifyingPaymasterV07.address}`);
console.log(`Service ready: ${service}`);
};

Expand Down
Loading