Im trying to deploy a contract that uses AccessControlUpgradeable.sol as base. I have defined an interface for this new contract so that I can make cheap external calls from external contracts into an instance of this newly designed People.sol. Here are both contracts:
Code to reproduce
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "./PeopleLibrary.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165StorageUpgradeable.sol";
import "./IPeople.sol";
contract People
is
Initializable,
AccessControlUpgradeable, ERC165StorageUpgradeable, IPeople
{
function people_init() public initializer {
__AccessControl_init();
_grantRole(AccessControlUpgradeable.DEFAULT_ADMIN_ROLE, tx.origin);
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(
ERC165StorageUpgradeable,
AccessControlUpgradeable
)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
And its interface:
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
interface IPeople {
function People_init() external;
}
Now this is the contract making the external call:
import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";
import "./IPeople.sol";
contract MyInsideCaller {
...
function initialize(address PeopleContract ) public payable initializer {
try IPeople(PeopleContract).People_init() {
} catch Error(string memory reason) {
revert(reason);
}
...
But the contract that actually triggers the call initially is this one:
contract TheTrigger {
address PeopleTemplate;
function initialize(address _template) {
PeopleTemplate = _template;
}
...
function createManyStuff()
public
payable
{
...
address peopleContract = ClonesUpgradeable.clone(PeopleTemplate);
ERC1967Proxy myInsideCallerProxy = new ERC1967Proxy(
MyInsideCallerTemplate,
abi.encodeWithSelector(
MyInsideCaller(address(0)).initialize.selector,
...args,
peopleContract
)
);
So basically a main contract has a function which creates and initializes a proxy, this step creates a clone of a People contract and initializes it internally, but for some reason the external call fails. Any ideas?
Environment
The funny thing is that this works well on Remix but not on my local environment and I have literally the same code but on remix I go through the initializers manually while on local I have a script that does it all in one way.