Skip to content

Commit

Permalink
feat(WakuRlnRegistry): uups proxy (#9)
Browse files Browse the repository at this point in the history
* feat(WakuRlnRegistry): uups proxy

* feat: deployments
  • Loading branch information
rymnc authored Sep 11, 2023
1 parent e5eefe4 commit 19fded8
Show file tree
Hide file tree
Showing 20 changed files with 1,188 additions and 542 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/Openzeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
13 changes: 9 additions & 4 deletions contracts/WakuRlnRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ pragma solidity 0.8.15;

import {WakuRln} from "./WakuRln.sol";
import {IPoseidonHasher} from "rln-contract/PoseidonHasher.sol";
import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
import {UUPSUpgradeable} from "openzeppelin-contracts/contracts/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol";
import {ERC1967Proxy} from "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";

error StorageAlreadyExists(address storageAddress);
error NoStorageContractAvailable();
error IncompatibleStorage();
error IncompatibleStorageIndex();

contract WakuRlnRegistry is Ownable {
contract WakuRlnRegistry is OwnableUpgradeable, UUPSUpgradeable {
uint16 public nextStorageIndex;
mapping(uint16 => address) public storages;

uint16 public usingStorageIndex = 0;

IPoseidonHasher public immutable poseidonHasher;
IPoseidonHasher public poseidonHasher;

event NewStorageContract(uint16 index, address storageAddress);

Expand All @@ -25,10 +27,13 @@ contract WakuRlnRegistry is Ownable {
_;
}

constructor(address _poseidonHasher) Ownable() {
function initialize(address _poseidonHasher) external initializer {
poseidonHasher = IPoseidonHasher(_poseidonHasher);
__Ownable_init();
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

function _insertIntoStorageMap(address storageAddress) internal {
storages[nextStorageIndex] = storageAddress;
emit NewStorageContract(nextStorageIndex, storageAddress);
Expand Down
17 changes: 14 additions & 3 deletions deploy/002_deploy_rln_registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { DeployFunction, DeploymentSubmission } from "hardhat-deploy/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getUnnamedAccounts } = hre;
Expand All @@ -10,10 +10,21 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const poseidonHasherAddress = (await deployments.get("PoseidonHasher"))
.address;

await deploy("WakuRlnRegistry", {
const implRes = await deploy("WakuRlnRegistry_Implementation", {
contract: "WakuRlnRegistry",
from: deployer,
log: true,
args: [poseidonHasherAddress],
});

let initializeAbi = ["function initialize(address _poseidonHasher)"];
let iface = new hre.ethers.utils.Interface(initializeAbi);
const data = iface.encodeFunctionData("initialize", [poseidonHasherAddress]);

await deploy("WakuRlnRegistry_Proxy", {
contract: "ERC1967Proxy",
from: deployer,
log: true,
args: [implRes.address, data],
});
};

Expand Down
15 changes: 13 additions & 2 deletions deploy/003_deploy_rln.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const [deployer] = await getUnnamedAccounts();

const wakuRlnRegistry = await deployments.get("WakuRlnRegistry");
const proxyDeployment = await deployments.get("WakuRlnRegistry_Proxy");
const wakuRlnRegistry = await deployments.get(
"WakuRlnRegistry_Implementation"
);
const registryContract = new hre.ethers.Contract(
wakuRlnRegistry.address,
proxyDeployment.address,
wakuRlnRegistry.abi,
hre.ethers.provider.getSigner(deployer)
);
Expand Down Expand Up @@ -43,3 +46,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
export default func;
func.dependencies = ["WakuRlnRegistry"];
func.tags = ["WakuRlnStorage"];
func.skip = async (hre: HardhatRuntimeEnvironment) => {
// skip if already deployed
const wakuRlnStorage = await hre.deployments.getOrNull("WakuRlnStorage_0");
if (wakuRlnStorage) {
return true;
}
return false;
};
208 changes: 193 additions & 15 deletions deployments/allDeployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"chainId": "11155111",
"contracts": {
"PoseidonHasher": {
"address": "0x9c1c939aCB5c356c91fF2f27E9FD29C5C95E671b",
"address": "0x6b81Eaf30b0C16A9842458A3131fBa78745907A8",
"abi": [
{
"inputs": [],
Expand Down Expand Up @@ -41,20 +41,9 @@
}
]
},
"WakuRlnRegistry": {
"address": "0x0A988fd9CA5BAebDf098b8A73621b2AaDa6492E8",
"WakuRlnRegistry_Implementation": {
"address": "0xF1935b338321013f11068abCafC548A7B0db732C",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_poseidonHasher",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "IncompatibleStorage",
Expand All @@ -81,6 +70,51 @@
"name": "StorageAlreadyExists",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "previousAdmin",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "newAdmin",
"type": "address"
}
],
"name": "AdminChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "beacon",
"type": "address"
}
],
"name": "BeaconUpgraded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint8",
"name": "version",
"type": "uint8"
}
],
"name": "Initialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -119,13 +153,39 @@
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "implementation",
"type": "address"
}
],
"name": "Upgraded",
"type": "event"
},
{
"inputs": [],
"name": "forceProgress",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_poseidonHasher",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "newStorage",
Expand Down Expand Up @@ -172,6 +232,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "proxiableUUID",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -273,6 +346,37 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newImplementation",
"type": "address"
}
],
"name": "upgradeTo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newImplementation",
"type": "address"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "upgradeToAndCall",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "usingStorageIndex",
Expand All @@ -288,8 +392,82 @@
}
]
},
"WakuRlnRegistry_Proxy": {
"address": "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_logic",
"type": "address"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"stateMutability": "payable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "previousAdmin",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "newAdmin",
"type": "address"
}
],
"name": "AdminChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "beacon",
"type": "address"
}
],
"name": "BeaconUpgraded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "implementation",
"type": "address"
}
],
"name": "Upgraded",
"type": "event"
},
{
"stateMutability": "payable",
"type": "fallback"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
},
"WakuRlnStorage_0": {
"address": "0x02A29114ECDE0Da4D6DB61eAE73a86486cB88c10",
"address": "0x58322513A35a8f747AF5A385bA14C2AbE602AA59",
"abi": [
{
"inputs": [
Expand Down
Loading

0 comments on commit 19fded8

Please sign in to comment.