dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
56 lines • 2.45 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LibraryDeploymentManager = void 0;
const libraryDetector_1 = require("./libraryDetector");
const libraryTimelineAdapter_1 = require("../logsAndMetrics/adapters/libraryTimelineAdapter");
class LibraryDeploymentManager {
constructor(factoryManager, signer) {
this.deployedLibraries = new Map();
this.factoryManager = factoryManager;
this.detector = new libraryDetector_1.LibraryDetector(factoryManager);
this.timeline = new libraryTimelineAdapter_1.LibraryTimelineAdapter();
this.signer = signer;
}
async deployLibrariesForModule(moduleName) {
const libraries = await this.detector.detectLibraries(moduleName);
const deployedAddresses = {};
if (libraries.length === 0) {
return deployedAddresses;
}
this.timeline.startLibraryResolution(libraries.map(lib => lib.name));
for (const lib of libraries) {
try {
// Check if already deployed
if (this.deployedLibraries.has(lib.name)) {
const address = this.deployedLibraries.get(lib.name);
deployedAddresses[lib.name] = address;
this.timeline.logLibraryResolved(lib.name, address);
continue;
}
// Deploy the library
const deployedLib = await this.deployLibrary(lib);
this.deployedLibraries.set(lib.name, deployedLib.address);
deployedAddresses[lib.name] = deployedLib.address;
this.timeline.logLibraryDeployment(lib.name, 'success', deployedLib.address);
}
catch (error) {
this.timeline.logLibraryError(lib.name, error);
throw error;
}
}
return deployedAddresses;
}
async deployLibrary(lib) {
const factory = await this.factoryManager.getFactory(lib.name, this.signer);
this.timeline.logLibraryDeployment(lib.name, 'starting');
const contract = await factory.deploy();
await contract.deployed();
return {
name: lib.name,
address: contract.address,
deploymentHash: contract.deployTransaction.hash
};
}
}
exports.LibraryDeploymentManager = LibraryDeploymentManager;
//# sourceMappingURL=libraryDeploymentManager.js.map