datahaven/test/launcher/contracts.ts
Gonza Montiel cb81164f22
feat: enable AVS owner workflow (#332)
# Enable AVS owner workflow

Until now, the deployer of the contracts and the owner of the deployed
contracts where the same account. Even if we allowed a different owner
to be specified, we were using the same. For this reason, a private key
was required, so after the deployment we could execute owned
transactions needed for the CLI.

In this PR we:
- Add a mechanism to the CLI to specify a different owner account other
than the deployer via `--avs-owner-address`
- Add CLI flags `--avs-owner-key` and`--execute-owner-transactions` so
account ownership vs. immediate execution is explicit and deferred. If
both previous parameters are provided, the CLI will execute the
transactions using the private key provided.
- Allow DataHaven AVS deploy scripts to toggle owner-call execution via
an env flag `TX_EXECUTION`
- Add documentation on how the new parameters work in `test/README.md`
and `test/docs/deployment.md`.

---------

Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com>
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
2025-12-10 17:38:21 +01:00

78 lines
2.7 KiB
TypeScript

import {
buildContracts,
constructDeployCommand,
deployContracts as deployContractsCore,
executeDeployment,
validateDeploymentParams
} from "scripts/deploy-contracts";
import { logger } from "utils";
import type { ParameterCollection } from "utils/parameters";
/**
* Configuration options for contract deployment.
*/
export interface ContractsOptions {
chain?: string;
rpcUrl?: string;
privateKey?: string | undefined;
verified?: boolean;
blockscoutBackendUrl?: string;
parameterCollection?: ParameterCollection;
txExecution?: boolean;
}
/**
* Deploys smart contracts to the specified network.
*
* This function handles the complete contract deployment process including:
* - Validating deployment parameters
* - Building contracts from source
* - Constructing deployment commands
* - Executing the deployment
* - Optionally verifying contracts on Blockscout
* - Automatically adding deployed contract addresses to parameter collection if provided
*
* @param options - Configuration options for deployment
* @param options.chain - The network to deploy to (optional, defaults to local deployment)
* @param options.rpcUrl - The RPC URL of the target network
* @param options.verified - Whether to verify contracts on Blockscout (requires blockscoutBackendUrl)
* @param options.blockscoutBackendUrl - URL for the Blockscout API (required if verified is true)
* @param options.parameterCollection - Collection of parameters to update with deployed contract addresses
*
* @throws {Error} If deployment parameters are invalid
* @throws {Error} If contract building fails
* @throws {Error} If deployment execution fails
*/
export const deployContracts = async (options: ContractsOptions): Promise<void> => {
logger.info("🚀 Deploying smart contracts...");
if (options.parameterCollection) {
// Validate required parameters
validateDeploymentParams(options);
// Build contracts
await buildContracts();
// Construct and execute deployment with parameter collection
const deployCommand = constructDeployCommand(options);
const env: Record<string, string> = {};
if (options.privateKey) {
env.DEPLOYER_PRIVATE_KEY = options.privateKey;
}
if (typeof options.txExecution === "boolean") {
env.TX_EXECUTION = options.txExecution ? "true" : "false";
}
await executeDeployment(deployCommand, options.parameterCollection, options.chain, env);
} else {
await deployContractsCore({
chain: options.chain || "anvil",
rpcUrl: options.rpcUrl,
privateKey: options.privateKey,
verified: options.verified,
blockscoutBackendUrl: options.blockscoutBackendUrl,
txExecution: options.txExecution
});
}
logger.success("Smart contracts deployed successfully");
};