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

60 lines
2.1 KiB
TypeScript

import { confirmWithTimeout, logger, printDivider, printHeader } from "utils";
import type { ParameterCollection } from "utils/parameters";
import { deployContracts as deployContractsCore } from "../../../launcher/contracts";
interface DeployContractsOptions {
rpcUrl: string;
privateKey?: string | undefined;
verified?: boolean;
blockscoutBackendUrl?: string;
deployContracts?: boolean;
parameterCollection?: ParameterCollection;
}
/**
* 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.deployContracts - Flag to control deployment (if undefined, will prompt)
* @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): Promise<boolean> => {
printHeader("Deploying Smart Contracts");
const { deployContracts } = options;
// Check if deployContracts option was set via flags, or prompt if not
let shouldDeployContracts = deployContracts;
if (shouldDeployContracts === undefined) {
shouldDeployContracts = await confirmWithTimeout(
"Do you want to deploy the smart contracts?",
true,
10
);
} else {
logger.info(
`🏳️ Using flag option: ${shouldDeployContracts ? "will deploy" : "will not deploy"} smart contracts`
);
}
if (!shouldDeployContracts) {
logger.info("👍 Skipping contract deployment. Done!");
printDivider();
return false;
}
await deployContractsCore({
rpcUrl: options.rpcUrl,
verified: options.verified,
blockscoutBackendUrl: options.blockscoutBackendUrl,
parameterCollection: options.parameterCollection,
txExecution: true
});
printDivider();
return true;
};