Skip to content

Commit cfa4488

Browse files
committed
fargate done! now replacing docker calls with viem WITHOUT a testnet...
1 parent 0d12841 commit cfa4488

File tree

10 files changed

+2997
-656
lines changed

10 files changed

+2997
-656
lines changed

tooling/sparta/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM oven/bun:latest
2+
3+
ENV PATH="/root/.foundry/bin:${PATH}"
4+
5+
RUN apt update && apt install -y curl apt-utils
6+
RUN curl -fsSL https://get.docker.com | bash
7+
RUN curl -L https://foundry.paradigm.xyz | bash
8+
9+
RUN foundryup
10+
RUN cast --version
11+
12+
WORKDIR /app
13+
COPY src ./
14+
15+
RUN bun install
16+
CMD ["bun", "run", "start"]

tooling/sparta/src/commands/getChainInfo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
});
1717

1818
try {
19+
console.log("Getting chain info");
1920
const {
2021
pendingBlockNum,
2122
provenBlockNum,

tooling/sparta/src/env.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import dotenv from "dotenv";
44
const loadSecrets = async () => {
55
try {
66
console.log("Loading secrets from AWS Secrets Manager");
7-
const secretsManager = new SecretsManager({
8-
region: process.env.AWS_REGION || "us-west-2",
9-
});
7+
const secretsManager = new SecretsManager();
108

119
const secretKeys = [
1210
"TOKEN",

tooling/sparta/src/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "1.0.0",
44
"type": "module",
55
"scripts": {
6-
"build": "tsc",
7-
"start": "node dist/index.js",
6+
"build": "bun build index.ts --target bun --minify --outdir=dist",
7+
"dev": "bun run --watch index.ts",
88
"watch": "tsc -w",
99
"test": "jest",
1010
"lint": "eslint . --ext .ts",
@@ -13,7 +13,8 @@
1313
"dependencies": {
1414
"@aws-sdk/client-secrets-manager": "^3.529.1",
1515
"discord.js": "^14.14.1",
16-
"dotenv": "^16.3.1"
16+
"dotenv": "^16.3.1",
17+
"viem": "^2.22.15"
1718
},
1819
"devDependencies": {
1920
"@types/node": "^20.10.5",

tooling/sparta/src/services/chaininfo-service.ts

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { exec } from "child_process";
2-
import { promisify } from "util";
1+
import { Ethereum } from "../utils/ethereum.js";
32

43
type ChainInfo = {
54
pendingBlockNum: string;
@@ -12,39 +11,47 @@ type ChainInfo = {
1211
proposerNow: string;
1312
};
1413

15-
const execAsync = promisify(exec);
16-
1714
export class ChainInfoService {
1815
static async getInfo(): Promise<ChainInfo> {
1916
try {
20-
// Add validator to the set
21-
const command = `docker run --rm aztecprotocol/aztec:unhinged-unicorn debug-rollup -u ${process.env.ETHEREUM_HOST} --rollup ${process.env.ETHEREUM_ROLLUP_ADDRESS} --l1-chain-id ${process.env.ETHEREUM_CHAIN_ID} `;
22-
const { stdout, stderr } = await execAsync(command);
17+
const ethereum = new Ethereum();
18+
const rollup = ethereum.getRollupContract();
19+
const [
20+
pendingNum,
21+
provenNum,
22+
validators,
23+
committee,
24+
archive,
25+
epochNum,
26+
slot,
27+
nextBlockTS,
28+
] = await Promise.all([
29+
rollup.read.getPendingBlockNumber(),
30+
rollup.read.getProvenBlockNumber(),
31+
rollup.read.getAttesters(),
32+
rollup.read.getCurrentEpochCommittee(),
33+
rollup.read.archive(),
34+
rollup.read.getCurrentEpoch(),
35+
rollup.read.getCurrentSlot(),
36+
rollup.read.getCurrentProposer(),
37+
(async () => {
38+
const block = await ethereum.getPublicClient().getBlock();
39+
return BigInt(block.timestamp + BigInt(12));
40+
})(),
41+
]);
2342

24-
if (stderr) {
25-
throw new Error(stderr);
26-
}
43+
const proposer = await rollup.read.getProposerAt([nextBlockTS]);
2744

28-
// looks like hell, but it just parses the output of the command
29-
// into a key-value object
30-
const info = stdout
31-
.split("\n")
32-
.map((line) => line.trim())
33-
.filter(Boolean)
34-
.reduce((acc, s) => {
35-
let [key, value] = s.split(": ");
36-
const sanitizedKey = key
37-
.toLowerCase()
38-
.replace(/\s+(.)/g, (_, c) => c.toUpperCase());
39-
return { ...acc, [sanitizedKey]: value };
40-
}, {}) as ChainInfo;
41-
if (typeof info.validators === "string") {
42-
info.validators = info.validators.split(", ").map(String);
43-
}
44-
if (typeof info.committee === "string") {
45-
info.committee = info.committee.split(", ").map(String);
46-
}
47-
return info as ChainInfo;
45+
return {
46+
pendingBlockNum: pendingNum as string,
47+
provenBlockNum: provenNum as string,
48+
validators: validators as string[],
49+
committee: committee as string[],
50+
archive: archive as string[],
51+
currentEpoch: epochNum as string,
52+
currentSlot: slot as string,
53+
proposerNow: proposer as string,
54+
};
4855
} catch (error) {
4956
console.error("Error getting chain info:", error);
5057
throw error;

tooling/sparta/src/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"strict": true,
99
"esModuleInterop": true,
1010
"skipLibCheck": true,
11-
"forceConsistentCasingInFileNames": true
11+
"forceConsistentCasingInFileNames": true,
12+
"resolveJsonModule": true
1213
},
1314
"include": ["**/*.ts"],
1415
"exclude": ["node_modules", "dist"]

tooling/sparta/src/utils/ethereum.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
AbiConstructorNotFoundError,
3+
createPublicClient,
4+
createWalletClient,
5+
getContract,
6+
http,
7+
PublicClient,
8+
} from "viem";
9+
10+
import RollupAbi from "./rollupAbi.json";
11+
12+
import {
13+
generatePrivateKey,
14+
mnemonicToAccount,
15+
privateKeyToAccount,
16+
} from "viem/accounts";
17+
18+
export class Ethereum {
19+
public publicClient: PublicClient;
20+
21+
constructor() {
22+
this.publicClient = createPublicClient({
23+
chain: {
24+
id: process.env.ETHEREUM_CHAIN_ID as unknown as number,
25+
name: "Ethereum",
26+
rpcUrls: {
27+
default: {
28+
http: [process.env.ETHEREUM_HOST as unknown as string],
29+
},
30+
},
31+
nativeCurrency: {
32+
decimals: 18,
33+
name: "Ether",
34+
symbol: "ETH",
35+
},
36+
},
37+
transport: http(process.env.ETHEREUM_HOST as unknown as string),
38+
});
39+
}
40+
41+
getPublicClient = () => {
42+
return this.publicClient;
43+
};
44+
45+
getRollupContract = () => {
46+
const rollup = getContract({
47+
address: process.env
48+
.ETHEREUM_ROLLUP_ADDRESS as unknown as `0x${string}`,
49+
abi: RollupAbi.abi,
50+
client: this.publicClient,
51+
});
52+
return rollup;
53+
};
54+
}

0 commit comments

Comments
 (0)