Skip to content

Commit

Permalink
feat: membership
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Sep 5, 2024
1 parent 64df459 commit 8be1af6
Show file tree
Hide file tree
Showing 9 changed files with 2,423 additions and 1,183 deletions.
25 changes: 11 additions & 14 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
WakuRlnV2Test:test__IdCommitmentToMetadata__DoesntExist() (gas: 16726)
WakuRlnV2Test:test__InvalidPaginationQuery__EndIndexGTcommitmentIndex() (gas: 18249)
WakuRlnV2Test:test__InvalidPaginationQuery__StartIndexGTEndIndex() (gas: 16130)
WakuRlnV2Test:test__InvalidRegistration__DuplicateIdCommitment() (gas: 99502)
WakuRlnV2Test:test__InvalidRegistration__FullTree() (gas: 14328)
WakuRlnV2Test:test__InvalidRegistration__InvalidIdCommitment__LargerThanField() (gas: 15229)
WakuRlnV2Test:test__InvalidRegistration__InvalidIdCommitment__Zero() (gas: 14004)
WakuRlnV2Test:test__InvalidRegistration__InvalidUserMessageLimit__LargerThanMax() (gas: 17703)
WakuRlnV2Test:test__InvalidRegistration__InvalidUserMessageLimit__Zero() (gas: 14085)
WakuRlnV2Test:test__Upgrade() (gas: 3791109)
WakuRlnV2Test:test__ValidPaginationQuery(uint32) (runs: 1000, μ: 445155, ~: 159972)
WakuRlnV2Test:test__ValidPaginationQuery__OneElement() (gas: 119773)
WakuRlnV2Test:test__ValidRegistration(uint256,uint32) (runs: 1000, μ: 124408, ~: 124408)
WakuRlnV2Test:test__ValidRegistration__kats() (gas: 96616)
WakuRlnV2Test:test__IdCommitmentToMetadata__DoesntExist() (gas: 27478)
WakuRlnV2Test:test__InsertionNormalOrder(uint32) (runs: 1001, μ: 1123469, ~: 494837)
WakuRlnV2Test:test__InvalidPaginationQuery__EndIndexGTcommitmentIndex() (gas: 18261)
WakuRlnV2Test:test__InvalidPaginationQuery__StartIndexGTEndIndex() (gas: 16108)
WakuRlnV2Test:test__InvalidRegistration__DuplicateIdCommitment() (gas: 249370)
WakuRlnV2Test:test__InvalidRegistration__InvalidIdCommitment__Zero() (gas: 12135)
WakuRlnV2Test:test__Upgrade() (gas: 6728616)
WakuRlnV2Test:test__ValidPaginationQuery(uint32) (runs: 1002, μ: 226428, ~: 52927)
WakuRlnV2Test:test__ValidPaginationQuery__OneElement() (gas: 262351)
WakuRlnV2Test:test__ValidRegistration(uint256,uint32) (runs: 1001, μ: 268741, ~: 268741)
WakuRlnV2Test:test__ValidRegistration__kats() (gas: 238744)
2,459 changes: 1,371 additions & 1,088 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
pragma solidity >=0.8.19 <=0.9.0;

import { WakuRlnV2 } from "../src/WakuRlnV2.sol";
import { LinearPriceCalculator } from "../src/LinearPriceCalculator.sol";
import { PoseidonT3 } from "poseidon-solidity/PoseidonT3.sol";
import { LazyIMT } from "@zk-kit/imt.sol/LazyIMT.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

Check warning on line 9 in script/Deploy.s.sol

View workflow job for this annotation

GitHub Actions / lint

imported name UUPSUpgradeable is not used

import { BaseScript } from "./Base.s.sol";
import { DeploymentConfig } from "./DeploymentConfig.s.sol";

contract Deploy is BaseScript {
function run() public broadcast returns (WakuRlnV2 w, address impl) {
// TODO: Use the correct values when deploying to mainnet
address priceCalcAddr = address(new LinearPriceCalculator(address(0), 0.05 ether));
// TODO: set DAI address 0x6B175474E89094C44Da98b954EedeAC495271d0F
impl = address(new WakuRlnV2());
bytes memory data = abi.encodeCall(WakuRlnV2.initialize, 100);
bytes memory data = abi.encodeCall(WakuRlnV2.initialize, (priceCalcAddr, 160_000, 20, 600, 30 days, 5 days));
// (priceCalcAddr, 160000, 20, 600, 30 days, 5 days)
address proxy = address(new ERC1967Proxy(impl, data));
w = WakuRlnV2(proxy);
}
Expand Down
11 changes: 11 additions & 0 deletions src/IPriceCalculator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface IPriceCalculator {
/// Returns the token and price to pay in `token` for some `_rateLimit`
/// @param _rateLimit the rate limit the user wants to acquire
/// @param _numberOfPeriods the number of periods the user wants to acquire
/// @return address of the erc20 token
/// @return uint price to pay for acquiring the specified `_rateLimit`
function calculate(uint256 _rateLimit, uint32 _numberOfPeriods) external view returns (address, uint256);
}
36 changes: 36 additions & 0 deletions src/LinearPriceCalculator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { Ownable } from "openzeppelin-contracts/contracts/access/Ownable.sol";
import { IPriceCalculator } from "./IPriceCalculator.sol";

/// @title Linear Price Calculator to determine the price to acquire a membership
contract LinearPriceCalculator is IPriceCalculator, Ownable {
/// @notice Address of the ERC20 token accepted by this contract. Address(0) represents ETH
address public token;

/// @notice The price per message per epoch per period
uint256 public pricePerMessagePerPeriod;

constructor(address _token, uint256 _pricePerPeriod) Ownable() {
token = _token;
pricePerMessagePerPeriod = _pricePerPeriod;
}

/// Set accepted token and price per message per epoch per period
/// @param _token The token accepted by the membership management for RLN
/// @param _pricePerPeriod Price per message per epoch
function setTokenAndPrice(address _token, uint256 _pricePerPeriod) external onlyOwner {
token = _token;
pricePerMessagePerPeriod = _pricePerPeriod;
}

/// Returns the token and price to pay in `token` for some `_rateLimit`
/// @param _rateLimit the rate limit the user wants to acquire
/// @param _numberOfPeriods the number of periods the user wants to acquire
/// @return address of the erc20 token
/// @return uint price to pay for acquiring the specified `_rateLimit`
function calculate(uint256 _rateLimit, uint32 _numberOfPeriods) external view returns (address, uint256) {
return (token, uint256(_numberOfPeriods) * uint256(_rateLimit) * pricePerMessagePerPeriod);
}
}
Loading

0 comments on commit 8be1af6

Please sign in to comment.