Skip to content

Commit

Permalink
Merge pull request #21 from ionicprotocol/fix/gauge-factory-access
Browse files Browse the repository at this point in the history
gauge factory access fix
  • Loading branch information
vminkov authored Sep 15, 2023
2 parents 77748ce + e00e60c commit d62bf08
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contracts/VoteEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Rec
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { IVotesUpgradeable } from "@openzeppelin/contracts-upgradeable/governance/utils/IVotesUpgradeable.sol";

import { IERC20 } from "./interfaces/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IVoteEscrow } from "./interfaces/IVoteEscrow.sol";
import { XERC721Upgradeable } from "./XERC721Upgradeable.sol";

Expand Down
1 change: 0 additions & 1 deletion contracts/Voter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.19;

import "./interfaces/IGauge.sol";
import "./interfaces/IGaugeFactory.sol";
import "./interfaces/IERC20.sol";
import "./interfaces/IMinter.sol";
import "./interfaces/IMarket.sol";
import "./interfaces/IVoter.sol";
Expand Down
19 changes: 19 additions & 0 deletions contracts/VoterRolesAuthority.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "./factories/GaugeFactory.sol";

import { RolesAuthority, Authority } from "solmate/auth/authorities/RolesAuthority.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

Expand All @@ -9,8 +11,25 @@ contract VoterRolesAuthority is RolesAuthority, Initializable {
_disableInitializers();
}

uint8 public VOTER_ROLE = 1;

modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");

_;
}

function initialize(address _owner) public initializer {
owner = _owner;
authority = this;
}

function configureRoles(address _gaugesFactory) external onlyOwner {
setRoleCapability(VOTER_ROLE, _gaugesFactory, GaugeFactory.createMarketGauge.selector, true);
setRoleCapability(VOTER_ROLE, _gaugesFactory, GaugeFactory.createPairGauge.selector, true);
}

function configureVoterPermissions(address _voter) external onlyOwner {
setUserRole(_voter, VOTER_ROLE, true);
}
}
4 changes: 2 additions & 2 deletions contracts/factories/GaugeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract GaugeFactory is IGaugeFactory, OwnableUpgradeable {
address _ve,
address _token,
address _distribution
) external returns (address) {
) external onlyAllowed returns (address) {
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(gaugeLogic), _getProxyAdmin(), "");
PairGauge(address(proxy)).initialize(_rewardToken, _ve, _token, _distribution);
last_gauge = address(proxy);
Expand All @@ -76,7 +76,7 @@ contract GaugeFactory is IGaugeFactory, OwnableUpgradeable {
address _ve,
address _token,
address _distribution
) external returns (address) {
) external onlyAllowed returns (address) {
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(gaugeLogic), _getProxyAdmin(), "");
MarketGauge(address(proxy)).initialize(_flywheel, _rewardToken, _ve, _token, _distribution);
last_gauge = address(proxy);
Expand Down
3 changes: 3 additions & 0 deletions contracts/test/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ contract BaseTest is Test {
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(impl), proxyAdmin, "");
gaugeFactory = GaugeFactory(address(proxy));
gaugeFactory.initialize(voterRolesAuth);

voterRolesAuth.configureRoles(address(gaugeFactory));
}

{
Expand Down Expand Up @@ -86,6 +88,7 @@ contract BaseTest is Test {
voter.initialize(address(ve), address(gaugeFactory), address(timer), voterRolesAuth);

ve.setVoter(address(voter));
voterRolesAuth.configureVoterPermissions(address(voter));

vm.prank(ve.owner());
ve.addBridge(bridge1);
Expand Down
11 changes: 10 additions & 1 deletion deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DeployFunction } from "hardhat-deploy/types";

import { IonicToken } from "../typechain/IonicToken";
import { VoteEscrow } from "../typechain/VoteEscrow";
import { VoterRolesAuthority } from "../typechain/VoterRolesAuthority";

const func: DeployFunction = async ({ ethers, getNamedAccounts, deployments, getChainId }): Promise<void> => {
console.log("RPC URL: ", ethers.provider.connection.url);

Check warning on line 8 in deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
Expand Down Expand Up @@ -78,6 +79,11 @@ const func: DeployFunction = async ({ ethers, getNamedAccounts, deployments, get
}
});
console.log(`GaugeFactory deployed at ${gaugeFactory.address}`);

Check warning on line 81 in deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
const voterRolesAuthority = (await ethers.getContract("VoterRolesAuthority")) as VoterRolesAuthority;
let tx = await voterRolesAuthority.configureRoles(gaugeFactory.address);
console.log(`setting the gauge factory in the voter roles auth`, tx.hash);

Check warning on line 84 in deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
await tx.wait();
console.log(`tx mined`);

Check warning on line 86 in deploy/deploy.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

const voteEscrow = await deployments.deploy("VoteEscrow", {
contract: "VoteEscrow",
Expand Down Expand Up @@ -141,9 +147,12 @@ const func: DeployFunction = async ({ ethers, getNamedAccounts, deployments, get
}
});
console.log(`Voter deployed at ${voter.address}`);
tx = await voterRolesAuthority.configureVoterPermissions(voter.address);
console.log(`configuring the voter permissions`, tx.hash);
await tx.wait();
console.log(`tx mined`);

const voteEscrowContract = (await ethers.getContractOrNull("VoteEscrow")) as VoteEscrow;

const currentVoter = await voteEscrowContract.callStatic.voter();
if (currentVoter != voter.address) {
const tx = await voteEscrowContract.setVoter(voter.address);
Expand Down

0 comments on commit d62bf08

Please sign in to comment.