mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 09:50:01 +00:00
68 lines
2.4 KiB
TypeScript
68 lines
2.4 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;
|
|
injectContracts?: 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.deployContracts - Flag to control deployment (if undefined, will prompt)
|
|
* @param options.parameterCollection - Collection of parameters to update in the DataHaven runtime
|
|
* @param options.injectContracts - If true, skips contract deployment entirely
|
|
* @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, injectContracts } = options;
|
|
|
|
// Skip deployment if injectContracts is set
|
|
if (injectContracts) {
|
|
logger.info("💉 Inject contracts is enabled. Skipping contract deployment.");
|
|
printDivider();
|
|
return false;
|
|
}
|
|
|
|
// 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
|
|
});
|
|
|
|
printDivider();
|
|
return true;
|
|
};
|