Skip to content

Commit a6a3717

Browse files
committed
fix(contract-manager) Lazer Deploy Script
1 parent dbd11c5 commit a6a3717

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed

contract_manager/scripts/deploy_evm_lazer_contracts.ts

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
*/
5050

5151
import { execSync } from "node:child_process";
52+
import { existsSync, readFileSync, unlinkSync } from "node:fs";
5253
import path from "node:path";
54+
import { fileURLToPath } from "node:url";
5355

5456
import yargs from "yargs";
5557
import { hideBin } from "yargs/helpers";
@@ -126,6 +128,12 @@ const parser = yargs(hideBin(process.argv))
126128
return true;
127129
});
128130

131+
type DeploymentOutput = {
132+
implementationAddress: string;
133+
proxyAddress: string;
134+
chainId: number;
135+
};
136+
129137
/**
130138
* Deploys the PythLazer contract using forge script
131139
* @param chain - The EVM chain to deploy to
@@ -140,12 +148,26 @@ async function deployPythLazerContract(
140148
verify: boolean,
141149
etherscanApiKey?: string,
142150
): Promise<string> {
143-
const lazerContractsDir = path.resolve("../../lazer/contracts/evm");
151+
// Resolve path relative to this script's location, not CWD
152+
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
153+
const lazerContractsDir = path.resolve(
154+
scriptDir,
155+
"../../lazer/contracts/evm",
156+
);
157+
const deploymentOutputPath = path.join(
158+
lazerContractsDir,
159+
"deployment-output.json",
160+
);
144161
const rpcUrl = chain.rpcUrl;
145162

146163
console.log(`Deploying PythLazer contract to ${chain.getId()}...`);
147164
console.log(`RPC URL: ${rpcUrl}`);
148165

166+
// Clean up any previous deployment output
167+
if (existsSync(deploymentOutputPath)) {
168+
unlinkSync(deploymentOutputPath);
169+
}
170+
149171
// Build forge command
150172
let forgeCommand = `forge script script/PythLazerDeploy.s.sol --rpc-url ${rpcUrl} --private-key ${privateKey} --broadcast`;
151173

@@ -162,19 +184,37 @@ async function deployPythLazerContract(
162184
stdio: "pipe",
163185
});
164186

165-
console.log("Deployment output:");
166187
console.log(output);
167188

168-
// Extract proxy address from output
169-
const proxyMatch = /Deployed proxy to: (0x[a-fA-F0-9]{40})/.exec(output);
170-
if (!proxyMatch) {
171-
throw new Error("Could not extract proxy address from deployment output");
189+
// Read deployment output from JSON file written by the forge script
190+
if (!existsSync(deploymentOutputPath)) {
191+
throw new Error(
192+
"Deployment output file not found. Deployment may have failed.",
193+
);
172194
}
173195

174-
const proxyAddress = proxyMatch[1];
175-
console.log(`\nPythLazer proxy deployed at: ${proxyAddress}`);
196+
const deploymentOutput = JSON.parse(
197+
readFileSync(deploymentOutputPath, "utf8"),
198+
) as DeploymentOutput;
199+
200+
// Verify chain ID matches
201+
if (deploymentOutput.chainId !== chain.networkId) {
202+
throw new Error(
203+
`Chain ID mismatch: expected ${chain.networkId}, got ${deploymentOutput.chainId}`,
204+
);
205+
}
206+
207+
console.log(
208+
`\nPythLazer implementation deployed at: ${deploymentOutput.implementationAddress}`,
209+
);
210+
console.log(
211+
`PythLazer proxy deployed at: ${deploymentOutput.proxyAddress}`,
212+
);
213+
214+
// Clean up the output file
215+
unlinkSync(deploymentOutputPath);
176216

177-
return proxyAddress ?? "";
217+
return deploymentOutput.proxyAddress;
178218
} catch (error) {
179219
console.error("Deployment failed:", error);
180220
throw error;

lazer/contracts/evm/foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
src = "src"
33
out = "out"
44
libs = ["lib"]
5+
fs_permissions = [{ access = "read-write", path = "."}]
56

67
optimizer = true
78
optimizer_runs = 100000

lazer/contracts/evm/script/PythLazerDeploy.s.sol

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,29 @@ contract PythLazerDeployScript is Script {
177177

178178
function run() public {
179179
address impl = deployImplementation("lazer:impl");
180-
deployProxy("lazer:proxy", impl);
180+
address proxy = deployProxy("lazer:proxy", impl);
181+
182+
// Write deployment output to JSON file for programmatic access
183+
_writeDeploymentOutput(impl, proxy);
184+
}
185+
186+
function _writeDeploymentOutput(
187+
address impl,
188+
address proxy
189+
) internal {
190+
string memory jsonKey = "deployment";
191+
192+
vm.serializeAddress(jsonKey, "implementationAddress", impl);
193+
vm.serializeUint(jsonKey, "chainId", block.chainid);
194+
string memory finalJson = vm.serializeAddress(
195+
jsonKey,
196+
"proxyAddress",
197+
proxy
198+
);
199+
200+
vm.writeJson(finalJson, "./deployment-output.json");
201+
202+
console.log("Deployment output written to deployment-output.json");
181203
}
182204

183205
function migrate() public {

0 commit comments

Comments
 (0)