1

I am working on a KYC smart contract and I want to provide the upgradable feature so I can add more functions or add more fields to the struct in the future. I have learned about proxies and the way I separate the storage and the code and I saw the transparent proxy, UUPs, and diamond proxy in my case, I think I have to use diamond especially when I have used UUPs the smart contract exceeds the limit of 24KB so I have to divide the smart contract to many contracts using the diamond mechanism. i saw many resources talking about diamond mechanism implementation but I don't get how to use it with my smart contract and i saw someone who uses louper he just deployed the main diamond and then deployed the smart contracts he wished to add to diamond and used louper to write or read from each contract but i don't see where is the benefits from this because i want one smart contract that users connect to it by a dapp and when they call a function they get it from the updated place also the storage keeps saving the data so we always connect to one place to fetch the data from and if i would add another fields i could add to somewhere as extended fields. also, i saw another way to use diamond but i didn't get it why we did such way, and if i tried to use i can't add my array/mapping of struct that store the data of persons to TestState.

bytes32 constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.test.storage");
  
  struct TestState {
      address myAddress;
      uint256 myNum;
  }

  function diamondStorage() internal pure returns (TestState storage ds) {
      bytes32 position = DIAMOND_STORAGE_POSITION;
      assembly {
          ds.slot := position
      }
  }

the UUPs method i tried to use:


    import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
    import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
    import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
    import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
    import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
    
    contract KYC is Initializable, ERC20Upgradeable, ERC20PermitUpgradeable, OwnableUpgradeable, UUPSUpgradeable {
        /// @custom:oz-upgrades-unsafe-allow constructor
        constructor() {
            _disableInitializers();
    //some other required functionality
        }
    
        function initialize(address initialOwner) initializer public {
            __ERC20_init("MyToken", "MTK");
            __ERC20Permit_init("MyToken");
            __Ownable_init(initialOwner);
            __UUPSUpgradeable_init();
        }
    
        function _authorizeUpgrade(address newImplementation)
            internal
            onlyOwner
            override
        {}
    // remaining functions
    }

Currently, i am working on remix because it is easier and i will move to hardhat later.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.