@openzeppelin/hardhat-upgrades
Version:
[](https://docs.openzeppelin.com/upgrades-plugins/hardhat-upgrades) [](https://www.npmjs.org/package/@openzeppelin/h
24 lines • 1.54 kB
JavaScript
import { forceImport as engineForceImport } from '../engine/force-import.js';
import { getUpgradeableBeaconContract } from './upgradeable-beacon.js';
import { attachViemContract, getContractAddress, getContractInfo, makeReadBinding, } from './utils.js';
export function makeForceImport(hre, connection) {
return async function forceImport(addressOrInstance, contractName, opts = {}) {
const address = getContractAddress(addressOrInstance);
const binding = await makeReadBinding(hre, connection, opts);
const implInfo = await getContractInfo(hre, contractName, opts.libraries);
const classification = await engineForceImport(binding, address, implInfo, opts);
// For an imported beacon, return the beacon contract like the ethers-based API does.
if (classification === 'beacon') {
const beacon = await getUpgradeableBeaconContract(connection, address, opts.client);
// The beacon's ABI is unrelated to the named contract's, as documented on ForceImportFunction.
return beacon;
}
else {
// Attach from the implementation ABI rather than re-reading the artifact, and without
// requiring an account: the import (above) does not need one, so neither should building the
// returned instance — it is read-capable, and write-capable when an account is available.
return attachViemContract(connection, implInfo.abi, address, opts.client);
}
};
}
//# sourceMappingURL=force-import.js.map