Skip to content

Commit cc822ce

Browse files
committed
prepare systems for deploy
1 parent 07aca1f commit cc822ce

File tree

10 files changed

+490
-386
lines changed

10 files changed

+490
-386
lines changed

packages/cli/src/commands/mirror.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ const options = {
3333
},
3434
fromIndexer: {
3535
type: "string",
36-
desc: "MUD indexer URL of source chain to mirror from.",
36+
desc: "MUD indexer URL of source chain to mirror from. Used to fetch table data.",
37+
},
38+
fromBlockscout: {
39+
type: "string",
40+
desc: "Blockscout URL of source chain to mirror from. Used to fetch contract init code.",
3741
},
3842
toWorld: {
3943
type: "string",
@@ -67,11 +71,21 @@ const commandModule: CommandModule<Options, Options> = {
6771
pollingInterval: 500,
6872
});
6973
const fromChainId = await getChainId(fromClient);
70-
const fromIndexer = opts.fromIndexer ?? defaultChains.find((chain) => chain.id === fromChainId)?.indexerUrl;
74+
const fromChain = defaultChains.find((chain) => chain.id === fromChainId);
75+
const fromIndexer = opts.fromIndexer ?? fromChain?.indexerUrl;
7176
if (!fromIndexer) {
7277
throw new MUDError(`No \`--fromIndexer\` provided or indexer URL configured for chain ${fromChainId}.`);
7378
}
7479

80+
const fromBlockscout = opts.fromBlockscout
81+
? ({ name: "Blockscout", url: opts.fromBlockscout } as const)
82+
: fromChain?.blockExplorers.default;
83+
if (!fromBlockscout || fromBlockscout.name !== "Blockscout") {
84+
throw new MUDError(
85+
`No \`--fromBlockscout\` provided or Blockscout block explorer URL configured for chain ${fromChainId}.`,
86+
);
87+
}
88+
7589
const account = await (async () => {
7690
if (opts.kms) {
7791
const keyId = process.env.AWS_KMS_KEY_ID;
@@ -121,6 +135,7 @@ const commandModule: CommandModule<Options, Options> = {
121135
indexer: fromIndexer,
122136
world: fromWorld,
123137
block: opts.fromBlock != null ? BigInt(opts.fromBlock) : undefined,
138+
blockscout: fromBlockscout.url,
124139
},
125140
to: {
126141
client: toClient,

packages/cli/src/mirror/common.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ import { StoreLog } from "@latticexyz/store";
66
export const mirrorPlansDirectory = `${mudDataDirectory}/mirror-plans`;
77

88
export type PlanStep =
9-
| { step: "mirror"; chainId: number; worldAddress: Address }
109
| { step: "deploySystem"; system: DeployedSystem; bytecode: DeployedBytecode }
11-
| { step: "start:setRecords" }
12-
| { step: "setRecord"; record: Extract<StoreLog, { eventName: "Store_SetRecord" }>["args"] }
13-
| { step: "end:setRecords" };
10+
| { step: "setRecord"; record: Extract<StoreLog, { eventName: "Store_SetRecord" }>["args"] };
1411

1512
export type DeployedBytecode = {
1613
address: Address;
17-
code: Hex;
14+
initCode: Hex;
1815
libraries: {
1916
offset: number;
2017
reference: DeployedBytecode;

packages/cli/src/mirror/createMirrorPlan.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,19 @@ export async function createMirrorPlan({
2626
world: Address;
2727
client: Client;
2828
indexer: string;
29+
blockscout: string;
2930
};
3031
}) {
3132
const fromChainId = await getChainId(from.client);
3233

3334
const planFilename = path.join(rootDir, mirrorPlansDirectory, `${fromChainId}_${from.world.toLowerCase()}.ndjson.gz`);
34-
return planFilename;
3535
await mkdir(path.dirname(planFilename), { recursive: true });
3636

3737
const plan = createPlanWriter(planFilename);
3838

3939
const makePlan = (async () => {
40-
plan.write({ step: "mirror", chainId: fromChainId, worldAddress: from.world });
41-
4240
const worldDeploy = await getWorldDeploy(from.client, from.world, from.block);
41+
4342
console.log("getting systems");
4443
const systems = await getSystems({
4544
client: from.client,
@@ -51,7 +50,13 @@ export async function createMirrorPlan({
5150
console.log("getting bytecode for", systems.length, "systems");
5251
const systemsWithBytecode = await Promise.all(
5352
systems.map(async (system) => {
54-
const bytecode = await getDeployedBytecode({ client: from.client, address: system.address });
53+
const bytecode = await getDeployedBytecode({
54+
client: from.client,
55+
address: system.address,
56+
debugLabel: `${resourceToLabel(system)} system`,
57+
allowedStorage: ["empty", { worldConsumer: worldDeploy.address }],
58+
blockscoutUrl: from.blockscout,
59+
});
5560
return { system, bytecode };
5661
}),
5762
);
@@ -70,7 +75,6 @@ export async function createMirrorPlan({
7075
// TODO: sort tables so that the insert order is correct (e.g. namespaces first)
7176

7277
let count = 0;
73-
plan.write({ step: "start:setRecords" });
7478
for (const table of tables) {
7579
const logs = await pRetry(() =>
7680
getRecordsAsLogs<Table>({
@@ -87,7 +91,6 @@ export async function createMirrorPlan({
8791
}
8892
count += logs.length;
8993
}
90-
plan.write({ step: "end:setRecords" });
9194
console.log("got", count, "total record logs");
9295
})();
9396

0 commit comments

Comments
 (0)