Hello. Im trying to call a function from my factory to my deployed proxy with this snippet:
// Starts a Pre-Sale
function _startPresale(uint32 activeFrom, uint32 activeUntil, uint _id)
external
{
ERC1967Proxy eventProxyToStart = getEventProxyById(_id);
(bool success,) = address(eventProxyToStart).delegatecall(abi.encodeWithSignature("startPreSale(uint32,uint32)", activeFrom, activeUntil));
require(success, "FAILED");
emit PreSaleCreated(
address(eventProxyToStart)
);
}
The following is the code in the implementation contract I am delegatecalling:
// Set a presale
function startPreSale(uint32 _activeFrom, uint32 _activeUntil)
external
onlyRole(MANAGER_ROLE)
{
(
uint256[] memory eventIndexes,
EventLibrary.Event[] memory events
) = getUpdatedEvents();
for (uint256 i = 0; i < eventIndexes.length; i++) {
if (
idToEvent[eventIndexes[i]].eventState !=
EventLibrary.EventState.deactivated
) {
revert("All events must be deactivated to start a pre-sale");
}
if (_activeFrom | _activeUntil >= idToEvent[eventIndexes[i]].startDate) {
revert(
"Pre-sale must start and end before the start date"
);
}
idToEvent[eventIndexes[i]].eventState ==
EventLibrary.EventState.onPreSale;
contractToSaleTrack[address(this)].eventContract = address(this);
contractToSaleTrack[address(this)].organizer = msg.sender;
contractToSaleTrack[address(this)].saleState = MarketPlaceLibrary
.SaleState
.onPreSale;
contractToSaleTrack[address(this)].activeFrom = _activeFrom;
contractToSaleTrack[address(this)].activeUntil = _activeUntil;
}
emit MarketPlaceLibrary.EventSeriesStateChange(
address(this),
contractToSaleTrack[address(this)].saleState,
events
);
}
I understand this factory needs to use delegateCall due to the fact that it is a proxy. Am I right?
In order to interact with the proxy, I deploy a contract of type Implementation to the address I get from the proxy creation and it gets initialized well from the factory.
The startPreSale call from the factory executes without exceptions but when I check the state variables in the proxy contract instance they are being partially stored so the return value are not right. I notice that some of the variables in the proxy deployed were not saved because the initialize function was called outside of the contract so there are variables that didn't get written. I assume data is not being recorded due to delegatecall. How do I deal with this parallelism in the writing of variables?
All in all, I want to be able to call functions directly in the proxy contract and also call others from the factory but having consistency in the state variables each contract has defined in its own.
Environment
Remix