Skip to content

Commit

Permalink
feat(cli): manually fetch gas price from rpc before PostDeploy runs (#…
Browse files Browse the repository at this point in the history
…2638)

Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
Kooshaba and holic committed Apr 25, 2024
1 parent 4198ef4 commit 189050b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-rocks-rescue.md
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Deploy will now fetch and set the gas price during execution of PostDeploy script. This should greatly reduce the fees paid for L2s.
40 changes: 30 additions & 10 deletions packages/cli/src/utils/postDeploy.ts
Expand Up @@ -2,24 +2,44 @@ import { existsSync } from "fs";
import path from "path";
import chalk from "chalk";
import { getScriptDirectory, forge } from "@latticexyz/common/foundry";
import { execSync } from "child_process";
import { formatGwei } from "viem";

export async function postDeploy(
postDeployScript: string,
worldAddress: string,
rpc: string,
profile: string | undefined,
): Promise<void> {
// Execute postDeploy forge script
const postDeployPath = path.join(await getScriptDirectory(), postDeployScript + ".s.sol");
if (existsSync(postDeployPath)) {
console.log(chalk.blue(`Executing post deploy script at ${postDeployPath}`));
await forge(
["script", postDeployScript, "--sig", "run(address)", worldAddress, "--broadcast", "--rpc-url", rpc, "-vvv"],
{
profile: profile,
},
);
} else {
if (!existsSync(postDeployPath)) {
console.log(`No script at ${postDeployPath}, skipping post deploy hook`);
return;
}

// TODO: replace this with a viem call
const gasPrice = BigInt(execSync(`cast gas-price --rpc-url ${rpc}`, { encoding: "utf-8" }).trim());

console.log(chalk.blue(`Executing post deploy script at ${postDeployPath}`));
console.log(chalk.blue(` using gas price of ${formatGwei(gasPrice)} gwei`));

await forge(
[
"script",
postDeployScript,
"--broadcast",
"--sig",
"run(address)",
worldAddress,
// TODO: also set priority fee?
"--with-gas-price",
gasPrice.toString(),
"--rpc-url",
rpc,
"-vvv",
],
{
profile: profile,
},
);
}

0 comments on commit 189050b

Please sign in to comment.