datahaven/test/cli/handlers/deploy/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

54 lines
1.7 KiB
TypeScript

import {
buildContracts,
constructDeployCommand,
executeDeployment,
validateDeploymentParams
} from "scripts/deploy-contracts";
import { logger, printDivider, printHeader } from "utils";
import type { ParameterCollection } from "utils/parameters";
interface DeployContractsOptions {
chain?: string;
rpcUrl: string;
privateKey?: string | undefined;
verified?: boolean;
blockscoutBackendUrl?: string;
parameterCollection?: ParameterCollection;
skipContracts: boolean;
}
/**
* Deploys smart contracts to the specified RPC URL
*
* @param options - Configuration options for deployment
* @param options.rpcUrl - The RPC URL to deploy to
* @param options.verified - Whether to verify contracts (requires blockscoutBackendUrl)
* @param options.blockscoutBackendUrl - URL for the Blockscout API (required if verified is true)
* @param options.parameterCollection - Collection of parameters to update in the DataHaven runtime
* @returns Promise resolving to true if contracts were deployed successfully, false if skipped
*/
export const deployContracts = async (options: DeployContractsOptions) => {
printHeader("Deploying Smart Contracts");
if (options.skipContracts) {
logger.info("🏳️ Skipping contract deployment");
printDivider();
return;
}
// Check if required parameters are provided
validateDeploymentParams(options);
// Build contracts
await buildContracts();
// Construct and execute deployment
const deployCommand = constructDeployCommand(options);
const env: Record<string, string> = { TX_EXECUTION: "true" };
if (options.privateKey) {
env.DEPLOYER_PRIVATE_KEY = options.privateKey;
}
await executeDeployment(deployCommand, options.parameterCollection, options.chain, env);
printDivider();
};