How to properly setup OpenZeppelin Proxy structure?

I’ve read through Proxy documentation and contracts, and have a general understanding of how they work and what are the security risks, but struggle to put all the pieces of the puzzle together. I have this simple structure, and the TestLogic contract needs to be upgraded:

contract TestData {
    
    uint256 testId;
    
    struct Test {
        uint256 testId;
    }
    
    mapping (address => Test) testerToTest;
    
    function _addTest() internal {
        testerToTest[msg.sender] = Test({
            testId: testId += 1
        });
    }
}

contract TestLogic is TestData {
    function addTest() public {
        _addTest();
    }
}

contract TestContract is TestLogic {
    constructor() {
        testId = 0;
    }
}

Which contracts from here I should include if I move with UUPS approach? Would be great to be able to upgrade the proxy as well.

So far, I have included the following contracts:

Proxy.sol, ERC1967Upgrade.sol, ERC1967Proxy.sol, and then set TestLogic is ERC1967Proxy.sol, but not sure if this is the correct way.

Documentation is really confusing, since it explains the differences of approaches, but doesn’t provide an example on how to put all those together for a specific approach.

Hey @ruham88! @frangio has recently put together a tutorial on UUPS, check it out:

2 Likes

Thanks for the link to the source, very helpful! Am I right to assume, that in my case TokenLogic needs to be UUPSUpgradeable and OwnableUpgradeable ?

Yep, you're correct!

3 Likes