Questions About UUPS Proxy Pattern

Hello, I want to write a contract for our Defi project using the UUPS proxies, but there are a few points that I can't understand. I would be glad if you could help.

1- I will make changes in the contracts according to the decisions taken in the DAO for the Defi protocol. Do you think UUPS proxies are the right choice for this?

2- Should the functions required for the Defi protocol be written in the proxy contract or the implementation contract?

3- Is it possible to revert to the previous version after an incorrect update?

Also, could you suggest any projects using UUPS proxies that we can use as a guide? I run through the Openzeppelin tutorial (Deploying More Efficient Upgradeable Contracts), but if there is a more comprehensive example than that, it would be great.

:1234: Proxy Contract

contract Treasury is Initializable,UUPSUpgradeable, OwnableUpgradeable {
   
 function initialize() public initializer {
        __Ownable_init(); //constructor kullanilmadigi icin ownablein baslamasi lazim
    }

    function _authorizeUpgrade(address newImplementation) internal override onlyOwner{
    }
    uint protocolFee;
    function setProtocolFee(uint _protocolFee) public virtual returns(uint){
        protocolFee = _protocolFee;
        return _protocolFee;
    }

    function getProtocolFee() public view virtual returns(uint){
        return protocolFee;
    }
}

Implementation

contract TreasuryV2 is Treasury {

    function setProtocolFee(uint _protocolFeeV2) public override returns(uint){
        protocolFee = _protocolFeeV2;
        return protocolFee;
    }    

    function getProtocolFee() public override view returns(uint){
        return protocolFee;
    }
   
    function version() public pure override returns (string memory) {
        return "v2!";
    }

}

Yeah, with proxy pattern, you can upgrade your contract later if you need, and UUPS is okay.

It should be in the implementation, so then later, you can change implementation contract to upgrade your contract, and for more details, maybe you can have a look at here: Upgrades - OpenZeppelin Docs

You can upgrade again with the previous implementation to revert the new changes. Actually, whenever you want to update your contracts, you should have a test at first, ensure the new function can work as expect, and the previous variables are right.

I think you can have a look at this tutorial:

1 Like