We've decided to use the UUPS proxy module offered by OpenZeppelin for our contracts to enable future updates.
However, our contract implementation requires users to deposit crypto for some functionality to work.
We'd like the crypto our users send to ideally stay in the same place and not require movement for every implementation upgrade.
Is this possible? If so, should our users send crypto to the proxy or the implementation contract for this to work?
Thanks!
Referencing https://docs.openzeppelin.com/contracts/4.x/api/proxy and https://docs.openzeppelin.com/upgrades-plugins/1.x/
Another Question :
If we were to deploy a v2 implementation and update the proxy, then our user deposits would be split between the v1 and v2 implementation contracts. Is there any way to avoid this? Or would we need to instruct our users to manually migrate their funds to the v2 implementation?
Answer :
contract MigrationContract
// The address of the v1 implementation contract.
address public v1ImplementationContract;
// The address of the v2 implementation contract.
address public v2ImplementationContract;
constructor(address _v1ImplementationContract,
address_v2ImplementationContract) {
v1ImplementationContract = _v1ImplementationContract;
v2ImplementationContract = _v2ImplementationContract;
}
// Migrates the user's deposit from the v1 implementation contract to
the v2 implementation contract.
function migrate() public {
// Get the user's deposit from the v1 implementation contract.
uint256 deposit = v1ImplementationContract.balanceOf(msg.sender);
// Transfer the user's deposit to the v2 implementation contract.
v2ImplementationContract.transfer(msg.sender, deposit);
}
Upgrade Proxy to v2:
After a sufficient migration period or when most users have moved their funds, you can proceed with upgrading the proxy contract to point to the v2 implementation.
// Upgrade the proxy to v2 implementation
function upgradeToV2() external onlyAdmin {
// Update the proxy to point to v2 implementation
_upgradeTo(v2Implementation);
}