@coinbase/onchaintestkit
Version:
End-to-end testing toolkit for blockchain applications, powered by Playwright
68 lines (67 loc) • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProxyDeployer = void 0;
const viem_1 = require("viem");
const chains_1 = require("viem/chains");
/**
* The deterministic deployment proxy bytecode and deployment transaction
* Source: https://github.com/Arachnid/deterministic-deployment-proxy
*/
const PROXY_DEPLOYMENT_TX = "0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222";
const PROXY_ADDRESS = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
/**
* Utility class to deploy and manage the deterministic deployment proxy
*/
class ProxyDeployer {
constructor(node) {
this.rpcUrl = node.rpcUrl;
this.publicClient = (0, viem_1.createPublicClient)({
chain: chains_1.localhost,
transport: (0, viem_1.http)(this.rpcUrl),
});
}
/**
* Check if the deterministic deployment proxy is already deployed
*/
async isProxyDeployed() {
try {
const code = await this.publicClient.getBytecode({
address: PROXY_ADDRESS,
});
return code !== undefined && code !== "0x";
}
catch {
return false;
}
}
/**
* Deploy the deterministic deployment proxy if it's not already deployed
*/
async ensureProxyDeployed() {
if (await this.isProxyDeployed()) {
console.log("Deterministic deployment proxy already deployed at:", PROXY_ADDRESS);
return;
}
try {
// Send the raw deployment transaction
const hash = await this.publicClient.request({
method: "eth_sendRawTransaction",
params: [PROXY_DEPLOYMENT_TX],
});
console.log("Deploying deterministic deployment proxy, tx hash:", hash);
// Wait for the transaction to be mined
await this.publicClient.waitForTransactionReceipt({ hash });
console.log("Deterministic deployment proxy deployed at:", PROXY_ADDRESS);
}
catch (error) {
throw new Error(`Failed to deploy deterministic deployment proxy: ${error}`);
}
}
/**
* Get the proxy address
*/
getProxyAddress() {
return PROXY_ADDRESS;
}
}
exports.ProxyDeployer = ProxyDeployer;