dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
83 lines • 3.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypechainDeployment = void 0;
const ethers_1 = require("ethers");
const provider_1 = require("../../provider");
// Helper function to get signer
async function getSigner() {
const provider = await (0, provider_1.getProvider)();
if (!process.env.PRIVATE_KEY) {
throw new Error('Missing PRIVATE_KEY environment variable');
}
return new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY, provider);
}
class TypechainDeployment {
static async deploySimple(moduleName, factoryManager, signer) {
const factory = await factoryManager.getContractFactory(moduleName, signer);
const contract = await factory.deploy();
await contract.deployed();
return contract;
}
static async deployWithBytecode(moduleName, factoryManager, linkedBytecode, signer) {
const metadata = await factoryManager.getContractMetadata(moduleName);
const signerToUse = signer || await getSigner();
const factory = new ethers_1.ethers.ContractFactory(metadata.abi, linkedBytecode, signerToUse);
const contract = await factory.deploy();
await contract.deployed();
return contract;
}
static async deployWithLibraries(moduleName, factoryManager, libraries, signer) {
const metadata = await factoryManager.getContractMetadata(moduleName);
const signerToUse = signer || await getSigner();
// Format libraries correctly using metadata linkReferences
const formattedLibraries = {};
if (metadata.linkReferences) {
for (const [libName, libAddress] of Object.entries(libraries)) {
// Find the correct path from metadata
for (const [filePath, libs] of Object.entries(metadata.linkReferences)) {
if (libName in libs) {
// Use the actual file path from metadata
formattedLibraries[`${filePath}:${libName}`] = libAddress;
break;
}
}
}
}
console.log(formattedLibraries);
// Create factory with libraries
const contractFactory = await factoryManager.getContractFactoryLib(moduleName, signerToUse, formattedLibraries);
try {
// Deploy the main contract
const contract = await contractFactory.deploy();
await contract.deployed();
console.log("Transfer contract deployed at:", contract.address);
return contract;
}
catch (error) {
console.error('Deployment error:', error);
console.error('Libraries:', libraries);
throw error;
}
}
// >>>>>
static async deployWithLibrariesB(moduleName, factoryManager, libraries, signer) {
const signerToUse = signer || await getSigner();
const contractFactory = await factoryManager.getContractFactoryLib(moduleName, signerToUse, {
"contracts/Modules/transfer/providers/transferFeeUtil.provider.sol:TransferFeeUtils": "0x811091f7B3c47ee763cE150956130627E1E8c7d9",
});
try {
// Deploy the main contract
const contract = await contractFactory.deploy();
await contract.deployed();
console.log("Transfer contract deployed at:", contract.address);
return contract;
}
catch (error) {
console.error('Deployment error:', error);
console.error('Libraries:', libraries);
throw error;
}
}
}
exports.TypechainDeployment = TypechainDeployment;
//# sourceMappingURL=deployment.js.map