test deployment strat

This commit is contained in:
rymnc 2023-08-03 17:20:25 +05:30
parent 7827e719c7
commit 196e67e923
No known key found for this signature in database
GPG Key ID: AAA088D5C68ECD34
9 changed files with 2015 additions and 11 deletions

View File

@ -10,7 +10,7 @@ error NoStorageContractAvailable();
error FailedToRegister(string reason); error FailedToRegister(string reason);
contract WakuRlnRegistry is Ownable { contract WakuRlnRegistry is Ownable {
uint16 public currentStorageIndex; uint16 public nextStorageIndex;
mapping(uint16 => address) public storages; mapping(uint16 => address) public storages;
uint16 public usingStorageIndex = 0; uint16 public usingStorageIndex = 0;
@ -24,23 +24,23 @@ contract WakuRlnRegistry is Ownable {
} }
function _insertIntoStorageMap(address storageAddress) internal { function _insertIntoStorageMap(address storageAddress) internal {
storages[currentStorageIndex] = storageAddress; storages[nextStorageIndex] = storageAddress;
emit NewStorageContract(currentStorageIndex, storageAddress); emit NewStorageContract(nextStorageIndex, storageAddress);
currentStorageIndex += 1; nextStorageIndex += 1;
} }
function registerStorage(address storageAddress) external onlyOwner { function registerStorage(address storageAddress) external onlyOwner {
if (storages[currentStorageIndex] != address(0)) revert StorageAlreadyExists(storageAddress); if (storages[nextStorageIndex] != address(0)) revert StorageAlreadyExists(storageAddress);
_insertIntoStorageMap(storageAddress); _insertIntoStorageMap(storageAddress);
} }
function newStorage() external onlyOwner { function newStorage() external onlyOwner {
WakuRln newStorageContract = new WakuRln(address(poseidonHasher), currentStorageIndex); WakuRln newStorageContract = new WakuRln(address(poseidonHasher), nextStorageIndex);
_insertIntoStorageMap(address(newStorageContract)); _insertIntoStorageMap(address(newStorageContract));
} }
function register(uint256 commitment) external payable { function register(uint256 commitment) external payable {
if (usingStorageIndex >= currentStorageIndex) revert NoStorageContractAvailable(); if (usingStorageIndex >= nextStorageIndex) revert NoStorageContractAvailable();
// iteratively check if the storage contract is full, and increment the usingStorageIndex if it is // iteratively check if the storage contract is full, and increment the usingStorageIndex if it is
while (true) { while (true) {

View File

@ -10,7 +10,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const poseidonHasherAddress = (await deployments.get("PoseidonHasher")) const poseidonHasherAddress = (await deployments.get("PoseidonHasher"))
.address; .address;
await deploy("WakuRln", { await deploy("WakuRlnRegistry", {
from: deployer, from: deployer,
log: true, log: true,
args: [poseidonHasherAddress], args: [poseidonHasherAddress],
@ -18,5 +18,5 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}; };
export default func; export default func;
func.tags = ["WakuRln"]; func.tags = ["WakuRlnRegistry"];
func.dependencies = ["PoseidonHasher"]; func.dependencies = ["PoseidonHasher"];

45
deploy/003_deploy_rln.ts Normal file
View File

@ -0,0 +1,45 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction, DeploymentSubmission } from "hardhat-deploy/types";
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getUnnamedAccounts } = hre;
const [deployer] = await getUnnamedAccounts();
const wakuRlnRegistry = await deployments.get("WakuRlnRegistry");
const registryContract = new hre.ethers.Contract(
wakuRlnRegistry.address,
wakuRlnRegistry.abi,
hre.ethers.provider.getSigner(deployer)
);
const indexOfStorageToBeDeployed = await registryContract.nextStorageIndex();
const tx = await registryContract.newStorage();
await tx.wait();
const poseidonHasherAddress = (await deployments.get("PoseidonHasher"))
.address;
const storageAddress = await registryContract.storages(
indexOfStorageToBeDeployed
);
const extendedArtifact = await deployments.getExtendedArtifact("WakuRln");
console.log("Storage address: ", storageAddress);
const d: DeploymentSubmission = {
abi: extendedArtifact.abi,
address: storageAddress,
args: [poseidonHasherAddress, indexOfStorageToBeDeployed],
bytecode: extendedArtifact.bytecode,
deployedBytecode: extendedArtifact.deployedBytecode,
receipt: tx,
transactionHash: tx.hash,
metadata: extendedArtifact.metadata,
solcInput: extendedArtifact.solcInput,
devdoc: extendedArtifact.devdoc,
};
console.log(d);
deployments.save(`WakuRlnStorage_${indexOfStorageToBeDeployed}`, d);
};
export default func;
func.dependencies = ["WakuRlnRegistry"];

View File

@ -334,6 +334,861 @@
"type": "function" "type": "function"
} }
] ]
},
"WakuRlnRegistry": {
"address": "0x50D658a2ab7f66f4B73E27e8731B8b13Cd06Df8A",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_poseidonHasher",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "string",
"name": "reason",
"type": "string"
}
],
"name": "FailedToRegister",
"type": "error"
},
{
"inputs": [],
"name": "NoStorageContractAvailable",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "storageAddress",
"type": "address"
}
],
"name": "StorageAlreadyExists",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint16",
"name": "index",
"type": "uint16"
},
{
"indexed": false,
"internalType": "address",
"name": "storageAddress",
"type": "address"
}
],
"name": "NewStorageContract",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "newStorage",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "nextStorageIndex",
"outputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "poseidonHasher",
"outputs": [
{
"internalType": "contract IPoseidonHasher",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "commitment",
"type": "uint256"
}
],
"name": "register",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "storageAddress",
"type": "address"
}
],
"name": "registerStorage",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"name": "storages",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "usingStorageIndex",
"outputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"stateMutability": "view",
"type": "function"
}
]
},
"WakuRlnStorage_0": {
"address": "0x02c233d3899c3A435631AC857DAD5555F4f9656C",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_poseidonHasher",
"type": "address"
},
{
"internalType": "uint16",
"name": "_contractIndex",
"type": "uint16"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "DuplicateIdCommitment",
"type": "error"
},
{
"inputs": [],
"name": "NotImplemented",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "idCommitment",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "index",
"type": "uint256"
}
],
"name": "MemberRegistered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "idCommitment",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "index",
"type": "uint256"
}
],
"name": "MemberWithdrawn",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "DEPTH",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MEMBERSHIP_DEPOSIT",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "SET_SIZE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "contractIndex",
"outputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "idCommitmentIndex",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "members",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "poseidonHasher",
"outputs": [
{
"internalType": "contract IPoseidonHasher",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256[]",
"name": "idCommitments",
"type": "uint256[]"
}
],
"name": "register",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "idCommitment",
"type": "uint256"
}
],
"name": "register",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "idCommitment",
"type": "uint256"
},
{
"internalType": "address payable",
"name": "receiver",
"type": "address"
},
{
"internalType": "uint256[8]",
"name": "proof",
"type": "uint256[8]"
}
],
"name": "slash",
"outputs": [],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "stakedAmounts",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "verifier",
"outputs": [
{
"internalType": "contract IVerifier",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "withdraw",
"outputs": [],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "withdrawalBalance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
]
},
"WakuRlnStorage_1": {
"address": "0x662Be55E75c829A03c52CDba4Ab7dAde4e1be8a9",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_poseidonHasher",
"type": "address"
},
{
"internalType": "uint16",
"name": "_contractIndex",
"type": "uint16"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "DuplicateIdCommitment",
"type": "error"
},
{
"inputs": [],
"name": "NotImplemented",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "idCommitment",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "index",
"type": "uint256"
}
],
"name": "MemberRegistered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "idCommitment",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "index",
"type": "uint256"
}
],
"name": "MemberWithdrawn",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "DEPTH",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MEMBERSHIP_DEPOSIT",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "SET_SIZE",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "contractIndex",
"outputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "idCommitmentIndex",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "members",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "poseidonHasher",
"outputs": [
{
"internalType": "contract IPoseidonHasher",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256[]",
"name": "idCommitments",
"type": "uint256[]"
}
],
"name": "register",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "idCommitment",
"type": "uint256"
}
],
"name": "register",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "idCommitment",
"type": "uint256"
},
{
"internalType": "address payable",
"name": "receiver",
"type": "address"
},
{
"internalType": "uint256[8]",
"name": "proof",
"type": "uint256[8]"
}
],
"name": "slash",
"outputs": [],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "stakedAmounts",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "verifier",
"outputs": [
{
"internalType": "contract IVerifier",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "withdraw",
"outputs": [],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "withdrawalBalance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
]
} }
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -112,10 +112,10 @@ error FailedToRegister(string reason)
## WakuRlnRegistry ## WakuRlnRegistry
### currentStorageIndex ### nextStorageIndex
```solidity ```solidity
uint16 currentStorageIndex uint16 nextStorageIndex
``` ```
### storages ### storages