Skip to content

Commit

Permalink
fix adhoc bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Aug 20, 2024
1 parent a204e4f commit d633f04
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
8 changes: 7 additions & 1 deletion contracts/AdhocVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IAdhocVoter} from "./interfaces/IAdhocVoter.sol";
import {IIncentive} from "./interfaces/IIncentive.sol";
import {IGauge} from "./interfaces/IGauge.sol";
import {IStrategyManager} from "./interfaces/IStrategyManager.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
Expand Down Expand Up @@ -34,6 +35,10 @@ contract AdhocVoter is IAdhocVoter, Initializable {
weekly = 100_000 * 1e18;
}

function isAlive(address) external override pure returns (bool) {
return true;
}

function setGovernor(address _governor) public {
require(msg.sender == governor, "Not Governor");
require (_governor != address(0), "ZeroAddress");
Expand Down Expand Up @@ -72,13 +77,14 @@ contract AdhocVoter is IAdhocVoter, Initializable {
emit WeeklyChanged(_weekly);
}

function addGauge(address _gauge, uint256 _weight) external {
function addGauge(address _gauge, address _incentive, uint256 _weight) external {
require(_weight >= 10 && _weight <= 100, "invalid weight");
require(msg.sender == governor, "Not Governor");
require(!gauges.contains(_gauge), "gauge already exist");

weights[_gauge] = _weight;
totalWeight += _weight;
IIncentive(_incentive).setGauge(_gauge);
emit WeightChanged(_gauge, _weight);
}

Expand Down
6 changes: 5 additions & 1 deletion contracts/interfaces/IAdhocVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ interface IAdhocVoter {
/// @notice Number of epochs in which updatePeriod was called
function epochCount() external view returns (uint256);

/// @dev Gauge => Liveness status
function isAlive(address gauge) external view returns (bool);

/// @notice Processes emissions and rebases. Callable once per epoch (1 week).
/// @return _period Start of current epoch.
function emitReward() external returns (uint256 _period);
Expand All @@ -47,8 +50,9 @@ interface IAdhocVoter {

/// @notice Add new gauge;
/// @param _gauge .
/// @param _incentive .
/// @param _weight for _gauge
function addGauge(address _gauge, uint256 _weight) external;
function addGauge(address _gauge, address _incentive, uint256 _weight) external;

/// @notice change weight of the gauge
/// @param _gauge .
Expand Down
34 changes: 21 additions & 13 deletions script/08_deploy_taxgauge_voter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {ethers, upgrades} from 'hardhat';
import fs from "fs";
import { ethers, upgrades } from 'hardhat';
import fs from 'fs';
require('dotenv').config();

// npx hardhat run script/08_deploy_taxgauge_voter.ts --network testnet
async function main() {
if (!process.env.FORWARDER) {
console.log(`Please provide VOTER address`);
return;
}
if (!process.env.DeviceNFT) {
console.log(`Please provide EMPTY_FACTORY address`);
console.log(`Please provide FORWARDER address`);
return;
}

Expand All @@ -20,19 +16,31 @@ async function main() {
await adhocVoter.waitForDeployment();
console.log(`AdhocVoter deployed to ${adhocVoter.target}`);

const incentive = await ethers.deployContract('Incentives', [
process.env.FORWARDER, adhocVoter.target, []]);
const incentive = await ethers.deployContract('Incentives', [process.env.FORWARDER, adhocVoter.target, []]);
await incentive.waitForDeployment();
console.log(`Incentive deployed to ${incentive.target}`);

const deviceNFTToken = await ethers.deployContract('TestDeviceNFT', ["DeviceNFT", "TestNFT"])
await deviceNFTToken.waitForDeployment();
console.log(`TestToken deployed to ${deviceNFTToken.target}`);
let deviceNFT = process.env.DEVICE_NFT;

if (!deviceNFT) {
const deviceNFTToken = await ethers.deployContract('TestDeviceNFT', ['DeviceNFT', 'TestNFT']);
await deviceNFTToken.waitForDeployment();
// @ts-ignore
deviceNFT = deviceNFTToken.target;
console.log(`TestToken deployed to ${deviceNFTToken.target}`);
}

const taxDeviceGauge = await ethers.deployContract('TaxDeviceGauge', [
process.env.FORWARDER, deviceNFTToken.target, adhocVoter.target, incentive.target]);
process.env.FORWARDER,
deviceNFT,
adhocVoter.target,
incentive.target,
]);
await taxDeviceGauge.waitForDeployment();
console.log(`taxDeviceGauge deployed to ${taxDeviceGauge.target}`);

const tx = await adhocVoter.addGauge(taxDeviceGauge.target, incentive.target, 100);
await tx.wait();
}

main().catch(err => {
Expand Down

0 comments on commit d633f04

Please sign in to comment.