Skip to content

Commit

Permalink
feat: update createGauge logic;
Browse files Browse the repository at this point in the history
scripts: add calculate_boost
  • Loading branch information
ludete committed Jul 25, 2024
1 parent 85927f1 commit 154f4cf
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 15 deletions.
4 changes: 2 additions & 2 deletions contracts/Voter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ contract Voter is IVoter, ERC2771Context, ReentrancyGuard {
}

/// @inheritdoc IVoter
function createGauge(address _poolFactory, address _pool) external nonReentrant returns (address) {
function createGauge(address _poolFactory, address _pool, uint8 _gaugeType) external nonReentrant returns (address) {
if (gauges[_pool] != address(0)) revert GaugeExists();
(address incentiveFactory, address gaugeFactory) = IFactoryRegistry(factoryRegistry).factoriesToPoolFactory(
_poolFactory
Expand All @@ -277,7 +277,7 @@ contract Voter is IVoter, ERC2771Context, ReentrancyGuard {
}

address _incentiveReward = IIncentivesFactory(incentiveFactory).createRewards(forwarder, _pool);
address _gauge = IGaugeFactory(gaugeFactory).createERC20Gauge(forwarder, _pool, _incentiveReward);
address _gauge = IGaugeFactory(gaugeFactory).createGauge(forwarder, _pool, _incentiveReward, _gaugeType);
IIncentive(_incentiveReward).setGauge(_gauge);

gauges[_pool] = _gauge;
Expand Down
29 changes: 26 additions & 3 deletions contracts/factories/GaugeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,42 @@ import {ERC20Gauge} from "../gauges/ERC20Gauge.sol";
import {DeviceGauge} from "../gauges/DeviceGauge.sol";

contract GaugeFactory is IGaugeFactory {
function createERC20Gauge(address _forwarder, address _pool, address _incentives) external returns (address gauge) {
uint8 constant Erc20Gauge = 0;
uint8 constant DeviceNFTGauge = 1;
uint8 constant WithdrawGauge = 2;

function createGauge(
address _forwarder,
address _poolOrDeviceNFTOrGauge,
address _incentives,
uint8 _gaugeType
) external returns (address gauge) {
address _gauge;
if (_gaugeType == Erc20Gauge) {
_gauge = createERC20Gauge(_forwarder, _poolOrDeviceNFTOrGauge, _incentives);
} else if (_gaugeType == DeviceNFTGauge) {
_gauge = createDeviceGauge(_forwarder, _poolOrDeviceNFTOrGauge, _incentives);
} else if (_gaugeType == WithdrawGauge) {
_gauge = createWithdrawalGauge(_poolOrDeviceNFTOrGauge);
} else {
revert IncorrectnessGaugeType();
}
return _gauge;
}

function createERC20Gauge(address _forwarder, address _pool, address _incentives) internal returns (address gauge) {
gauge = address(new ERC20Gauge(_forwarder, _pool, msg.sender, _incentives));
}

function createDeviceGauge(
address _forwarder,
address _deviceNFT,
address _incentives
) external override returns (address gauge) {
) internal returns (address gauge) {
gauge = address(new DeviceGauge(_forwarder, _deviceNFT, msg.sender, _incentives));
}

function createWithdrawalGauge(address _guage) external pure override returns (address gauge) {
function createWithdrawalGauge(address _guage) internal returns (address gauge) {
gauge = _guage;
}
}
3 changes: 2 additions & 1 deletion contracts/interfaces/IVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ interface IVoter {
/// @dev V1 gauges can only be created by governor.
/// @param _poolFactory .
/// @param _pool .
function createGauge(address _poolFactory, address _pool) external returns (address);
/// @param _gaugeType
function createGauge(address _poolFactory, address _pool, uint8 _gaugeType) external returns (address);

/// @notice Kills a gauge. The gauge will not receive any new emissions and cannot be deposited into.
/// Can still withdraw from gauge.
Expand Down
11 changes: 8 additions & 3 deletions contracts/interfaces/factories/IGaugeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
pragma solidity ^0.8.0;

interface IGaugeFactory {
function createERC20Gauge(address _forwarder, address _pool, address _incentives) external returns (address);
function createDeviceGauge(address _forwarder, address _deviceNFT, address _incentives) external returns (address);
function createWithdrawalGauge(address _guage) external returns (address);
error IncorrectnessGaugeType();

function createGauge(
address _forwarder,
address _poolOrDeviceNFTOrGauge,
address _incentives,
uint8 _gaugeType
) external returns (address gauge);
}
29 changes: 29 additions & 0 deletions script/07_calculate_boost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { ethers } = require("hardhat")

// npx hardhat run script/07_calculate_boost.ts --network testnet
async function main() {
if (!process.env.LST_GAUGE) {
console.log(`Please provide LST_GAUGE address`);
return;
}

const [deployer] = await ethers.getSigners();
console.log('Deployer address:', deployer.address);

const gauge = await ethers.getContractAt('IRewardGauge', process.env.LST_GAUGE, deployer);
const totalSupply = await gauge.totalSupply();
const totalShare = await gauge.totalShare();

const userWillDepositLp = BigInt(10000);
const userWillVoteShare = BigInt(100) ;
var boost = Number(1.5) * Number((totalSupply+userWillDepositLp) *userWillVoteShare)/Number(totalShare+userWillVoteShare)/Number(userWillDepositLp) + Number(1)
if (boost > Number(2.5)){
boost = Number(2.5)
}
console.log("boost for user: ", boost);
}

main().catch(err => {
console.error(err);
process.exitCode = 1;
});
12 changes: 6 additions & 6 deletions test/TestVoter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ contract TestVoter is Test {

function test_gauge_actions() external {
//1. createGauge success
voter.createGauge(poolFactory, address(pool));
voter.createGauge(poolFactory, address(pool), 0);
assertEq(1, voter.length());
assertNotEq(address(0), voter.gauges(address(pool)));

//1.1 repeat add same pool so failed
vm.expectRevert(IVoter.GaugeExists.selector);
voter.createGauge(poolFactory, address(pool));
voter.createGauge(poolFactory, address(pool), 0);
assertEq(1, voter.length());

//1.2 caller not governor & pool is not whitelistedToken
address pool2 = address(22);
vm.prank(address(2));
vm.expectRevert(IVoter.NotWhitelistedToken.selector);
voter.createGauge(poolFactory, pool2);
voter.createGauge(poolFactory, pool2, 0);
assertEq(1, voter.length());

//1.3 set whitelistedToken
voter.whitelistToken(pool2, true);
voter.createGauge(poolFactory, pool2);
voter.createGauge(poolFactory, pool2, 0);
assertEq(2, voter.length());

//2. kill gauge
Expand All @@ -76,7 +76,7 @@ contract TestVoter is Test {

function test_vote_actions() external {
skip(10 days);
voter.createGauge(poolFactory, address(pool));
voter.createGauge(poolFactory, address(pool), 0);
strategyManager.setShare(address(this), 500);

//1. vote failed due to UnequalLengths
Expand Down Expand Up @@ -121,7 +121,7 @@ contract TestVoter is Test {

function test_notifyReward_updateFor_distribute_claimRewards() external {
// 0. setup to create gauge and vote for the gauge
voter.createGauge(poolFactory, address(pool));
voter.createGauge(poolFactory, address(pool), 0);
address gauge = voter.gauges(address(pool));
strategyManager.setShare(address(this), 1000);
address[] memory poolvote = new address[](1);
Expand Down

0 comments on commit 154f4cf

Please sign in to comment.