diff --git a/contracts/Voter.sol b/contracts/Voter.sol index ce95cb4..6dfc8f0 100644 --- a/contracts/Voter.sol +++ b/contracts/Voter.sol @@ -276,7 +276,12 @@ contract Voter is IVoter, ERC2771Context, ReentrancyGuard { } /// @inheritdoc IVoter - function createGauge(address _poolFactory, address _pool, uint8 _gaugeType, uint256 threshold) external nonReentrant returns (address) { + function createGauge( + address _poolFactory, + address _pool, + uint8 _gaugeType, + uint256 threshold + ) external nonReentrant returns (address) { if (gauges[_pool] != address(0)) revert GaugeExists(); (address incentiveFactory, address gaugeFactory) = IFactoryRegistry(factoryRegistry).factoriesToPoolFactory( _poolFactory diff --git a/contracts/gauges/DeviceGauge.sol b/contracts/gauges/DeviceGauge.sol index 2f16793..d44919a 100644 --- a/contracts/gauges/DeviceGauge.sol +++ b/contracts/gauges/DeviceGauge.sol @@ -60,7 +60,7 @@ contract DeviceGauge is RewardGauge, ERC721Holder { delete tokenWeight[_tokenId]; updateWeightBalance(sender); IIncentive(incentive).withdraw(_amount, sender); - if (balanceOf[sender] == 0){ + if (balanceOf[sender] == 0) { depositUserNum--; } diff --git a/contracts/gauges/ERC20Gauge.sol b/contracts/gauges/ERC20Gauge.sol index 8c99709..7147748 100644 --- a/contracts/gauges/ERC20Gauge.sol +++ b/contracts/gauges/ERC20Gauge.sol @@ -47,7 +47,7 @@ contract ERC20Gauge is RewardGauge { IERC20(stakingToken).safeTransfer(sender, _amount); updateWeightBalance(sender); IIncentive(incentive).withdraw(_amount, sender); - if (balanceOf[sender] == 0){ + if (balanceOf[sender] == 0) { depositUserNum--; } diff --git a/contracts/gauges/RewardGauge.sol b/contracts/gauges/RewardGauge.sol index 6bf3704..ee5808c 100644 --- a/contracts/gauges/RewardGauge.sol +++ b/contracts/gauges/RewardGauge.sol @@ -132,7 +132,7 @@ abstract contract RewardGauge is IRewardGauge, ERC2771Context, ReentrancyGuard { /// @inheritdoc IRewardGauge function deposit(uint256 _amountOrNFTID) external { address sender = _msgSender(); - if (balanceOf[sender] == 0){ + if (balanceOf[sender] == 0) { depositUserNum++; } _depositFor(_amountOrNFTID, sender); @@ -140,7 +140,7 @@ abstract contract RewardGauge is IRewardGauge, ERC2771Context, ReentrancyGuard { /// @inheritdoc IRewardGauge function deposit(uint256 _amountOrNFTID, address _recipient) external { - if (balanceOf[_recipient] == 0){ + if (balanceOf[_recipient] == 0) { depositUserNum++; } _depositFor(_amountOrNFTID, _recipient); diff --git a/contracts/interfaces/IVoter.sol b/contracts/interfaces/IVoter.sol index eb82a64..168216e 100644 --- a/contracts/interfaces/IVoter.sol +++ b/contracts/interfaces/IVoter.sol @@ -184,7 +184,12 @@ interface IVoter { /// @param _pool . /// @param _gaugeType 0: ERC20Gauge, 1: DeviceNFTGauge, 2: WithdrawGauge /// @param threshold only >0 for deviceNFTGauge - function createGauge(address _poolFactory, address _pool, uint8 _gaugeType, uint256 threshold) external returns (address); + function createGauge( + address _poolFactory, + address _pool, + uint8 _gaugeType, + uint256 threshold + ) 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. diff --git a/script/02_deploy_factory.ts b/script/02_deploy_factory.ts index e691ff3..dda3011 100644 --- a/script/02_deploy_factory.ts +++ b/script/02_deploy_factory.ts @@ -15,7 +15,11 @@ async function main() { await incentiveFactory.waitForDeployment(); console.log(`VotingRewardsFactory deployed to ${incentiveFactory.target}`); - const factoryRegistry = await ethers.deployContract('FactoryRegistry', [poolFactory.target, incentiveFactory.target,gaugeFactory.target]); + const factoryRegistry = await ethers.deployContract('FactoryRegistry', [ + poolFactory.target, + incentiveFactory.target, + gaugeFactory.target, + ]); await factoryRegistry.waitForDeployment(); console.log(`FactoryRegistry deployed to ${factoryRegistry.target}`); diff --git a/script/04_deploy_test.ts b/script/04_deploy_test.ts index 1186b59..af13ba6 100644 --- a/script/04_deploy_test.ts +++ b/script/04_deploy_test.ts @@ -1,16 +1,16 @@ import { ethers } from 'hardhat'; -import fs from "fs"; +import fs from 'fs'; // npx hardhat run script/04_deploy_test.ts --network testnet async function main() { const lpToken = await ethers.deployContract('TestToken', ['Marshall Token', 'MT']); console.log(`TestToken deployed to ${lpToken.target}`); - const deviceNFTToken = await ethers.deployContract('TestDeviceNFT', ["DeviceNFT", "TestNFT"]) + const deviceNFTToken = await ethers.deployContract('TestDeviceNFT', ['DeviceNFT', 'TestNFT']); console.log(`TestToken deployed to ${deviceNFTToken.target}`); fs.appendFileSync('.env', `DeviceNFT=${deviceNFTToken.target}\n`); - fs.appendFileSync('.env', `LST_POOL1=${lpToken.target}\n`) + fs.appendFileSync('.env', `LST_POOL1=${lpToken.target}\n`); } main().catch(err => { diff --git a/script/05_deploy_gauge.ts b/script/05_deploy_gauge.ts index 489c583..9a09ff5 100644 --- a/script/05_deploy_gauge.ts +++ b/script/05_deploy_gauge.ts @@ -1,5 +1,5 @@ import { ethers } from 'hardhat'; -import fs from "fs"; +import fs from 'fs'; require('dotenv').config(); // npx hardhat run script/05_deploy_gauge.ts --network testnet @@ -35,7 +35,7 @@ async function main() { const deploy_gauge = await voter.gauges(process.env.LST_POOL1); console.log('deploy gauge: ', deploy_gauge); - fs.appendFileSync('.env', `LST_GAUGE=${deploy_gauge}\n`) + fs.appendFileSync('.env', `LST_GAUGE=${deploy_gauge}\n`); const lst_gauge = await ethers.getContractAt('IRewardGauge', deploy_gauge, deployer); const incentive = await lst_gauge.incentive(); fs.appendFileSync('.env', `LST_Incentive=${incentive}\n`); @@ -52,7 +52,7 @@ async function main() { const deploy_gauge = await voter.gauges(process.env.DeviceNFT); console.log('deploy DeviceNFTGauge: ', deploy_gauge); - fs.appendFileSync('.env', `DeviceNFT_GAUGE=${deploy_gauge}\n`) + fs.appendFileSync('.env', `DeviceNFT_GAUGE=${deploy_gauge}\n`); const device_gauge = await ethers.getContractAt('IRewardGauge', deploy_gauge, deployer); const incentive = await device_gauge.incentive(); fs.appendFileSync('.env', `DeviceNFT_Incentive=${incentive}\n`); diff --git a/script/06_deploy_deposit.ts b/script/06_deploy_deposit.ts index 6eaaa4a..d217a99 100644 --- a/script/06_deploy_deposit.ts +++ b/script/06_deploy_deposit.ts @@ -1,34 +1,33 @@ // import { ethers } from 'hardhat'; -const { ethers } = require("hardhat") +const { ethers } = require('hardhat'); import fs from 'fs'; // npx hardhat run script/06_deploy_deposit.ts --network testnet async function main() { - if (!process.env.LST_GAUGE) { - console.log(`Please provide LST_GAUGE address`); - return; - } - if (!process.env.LST_POOL1) { - console.log(`Please provide LST_Token address`); - return; - } + if (!process.env.LST_GAUGE) { + console.log(`Please provide LST_GAUGE address`); + return; + } + if (!process.env.LST_POOL1) { + console.log(`Please provide LST_Token address`); + return; + } - const [deployer] = await ethers.getSigners(); - console.log('Deployer address:', deployer.address); + const [deployer] = await ethers.getSigners(); + console.log('Deployer address:', deployer.address); - const lst_token = await ethers.getContractAt('TestToken', process.env.LST_POOL1) - const tx = await lst_token.approve(process.env.LST_GAUGE, ethers.parseEther('1000')); - await tx.wait(); - const gauge = await ethers.getContractAt('IRewardGauge', process.env.LST_GAUGE, deployer); - const tx2 = await gauge.deposit(ethers.parseEther('1')); - await tx2.wait(); - - const balance = await gauge.balanceOf(deployer); - console.log("balance of deposit: ", balance); + const lst_token = await ethers.getContractAt('TestToken', process.env.LST_POOL1); + const tx = await lst_token.approve(process.env.LST_GAUGE, ethers.parseEther('1000')); + await tx.wait(); + const gauge = await ethers.getContractAt('IRewardGauge', process.env.LST_GAUGE, deployer); + const tx2 = await gauge.deposit(ethers.parseEther('1')); + await tx2.wait(); + const balance = await gauge.balanceOf(deployer); + console.log('balance of deposit: ', balance); } main().catch(err => { - console.error(err); - process.exitCode = 1; + console.error(err); + process.exitCode = 1; }); diff --git a/script/07_calculate_boost.ts b/script/07_calculate_boost.ts index c9a03a8..422af82 100644 --- a/script/07_calculate_boost.ts +++ b/script/07_calculate_boost.ts @@ -1,29 +1,33 @@ -const { ethers } = require("hardhat") +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; - } + 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 [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 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); + 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; + console.error(err); + process.exitCode = 1; }); diff --git a/script/upgrade.ts b/script/upgrade.ts index 8d1ec23..677b1f5 100644 --- a/script/upgrade.ts +++ b/script/upgrade.ts @@ -15,4 +15,4 @@ async function main() { main().catch(err => { console.error(err); process.exitCode = 1; -}); \ No newline at end of file +}); diff --git a/test/TestClaimVault.ts b/test/TestClaimVault.ts index 43ca22b..d177d9e 100644 --- a/test/TestClaimVault.ts +++ b/test/TestClaimVault.ts @@ -1,41 +1,44 @@ import { expect } from 'chai'; import { ethers } from 'hardhat'; -import { time, mine, mineUpTo } from "@nomicfoundation/hardhat-toolbox/network-helpers"; +import { time, mine, mineUpTo } from '@nomicfoundation/hardhat-toolbox/network-helpers'; describe('BatchClaimVault tests', function () { it('claim', async function () { const [owner, projectRecipient, fakeRecipient] = await ethers.getSigners(); - + const vault = await ethers.deployContract('BatchClaimVault'); await vault.connect(owner).initialize(ethers.parseEther('0.1')); - + expect(await vault.batchSize()).to.equal(17280); - await expect(vault.connect(fakeRecipient).changeBatchSize(10)) - .to.revertedWith('Ownable: caller is not the owner'); - await expect(vault.connect(fakeRecipient).changeRewardPerBlock(10)) - .to.revertedWith('Ownable: caller is not the owner'); - await expect(vault.connect(fakeRecipient).changeRecipient(1, fakeRecipient.address)) - .to.revertedWith('invalid admin'); + await expect(vault.connect(fakeRecipient).changeBatchSize(10)).to.revertedWith('Ownable: caller is not the owner'); + await expect(vault.connect(fakeRecipient).changeRewardPerBlock(10)).to.revertedWith( + 'Ownable: caller is not the owner', + ); + await expect(vault.connect(fakeRecipient).changeRecipient(1, fakeRecipient.address)).to.revertedWith( + 'invalid admin', + ); await vault.connect(owner).changeBatchSize(10); const projectId = 1; await expect(vault.connect(projectRecipient).claim(projectId)).to.rejectedWith('invalid project'); - const startBlock = (await time.latestBlock() + 2); + const startBlock = (await time.latestBlock()) + 2; await vault.connect(owner).addProject(projectId, projectRecipient.address, startBlock); await expect(vault.connect(owner).claim(projectId)).to.rejectedWith('claim too short'); await expect(vault.connect(projectRecipient).claim(projectId)).to.rejectedWith('claim too short'); - + await mine(10); await expect(vault.connect(projectRecipient).claim(projectId)).to.rejectedWith('insufficient fund'); - await vault.donate({value: ethers.parseEther("1")}); + await vault.donate({ value: ethers.parseEther('1') }); let claimBeforeBalance = await ethers.provider.getBalance(projectRecipient.address); let tx = await vault.connect(projectRecipient).claim(projectId); let claimAfterBalance = await ethers.provider.getBalance(projectRecipient.address); let receipt = await ethers.provider.getTransactionReceipt(tx.hash); - expect(claimBeforeBalance).to.equals(claimAfterBalance - ethers.parseEther("1") + receipt!.gasUsed * receipt!.gasPrice); + expect(claimBeforeBalance).to.equals( + claimAfterBalance - ethers.parseEther('1') + receipt!.gasUsed * receipt!.gasPrice, + ); await expect(vault.connect(projectRecipient).claim(projectId)).to.rejectedWith('claim too short'); @@ -43,17 +46,19 @@ describe('BatchClaimVault tests', function () { await mineUpTo(lastClaimedBlock + BigInt(10)); await expect(vault.connect(projectRecipient).claim(projectId)).to.rejectedWith('insufficient fund'); - await vault.donate({value: ethers.parseEther("1")}); + await vault.donate({ value: ethers.parseEther('1') }); claimBeforeBalance = await ethers.provider.getBalance(projectRecipient.address); tx = await vault.connect(projectRecipient).claim(projectId); claimAfterBalance = await ethers.provider.getBalance(projectRecipient.address); receipt = await ethers.provider.getTransactionReceipt(tx.hash); - expect(claimBeforeBalance).to.equals(claimAfterBalance - ethers.parseEther("1") + receipt!.gasUsed * receipt!.gasPrice); + expect(claimBeforeBalance).to.equals( + claimAfterBalance - ethers.parseEther('1') + receipt!.gasUsed * receipt!.gasPrice, + ); await vault.removeProject(projectId); await expect(vault.connect(projectRecipient).claim(projectId)).to.rejectedWith('invalid project'); expect(await vault.lastClaimedBlock(projectId)).to.equals(0); expect(await vault.projectRecipient(projectId)).to.equals('0x0000000000000000000000000000000000000000'); - }) -}) + }); +}); diff --git a/test/TestGauge.t.sol b/test/TestGauge.t.sol index 622a6b6..14c5892 100644 --- a/test/TestGauge.t.sol +++ b/test/TestGauge.t.sol @@ -28,11 +28,15 @@ contract TestERC20Gauge is Test { forwarder = new DAOForwarder(); // manager & _factoryRegistry not used in gauge strategyManager = new TestStrategyManager(); - strategyManager.setShare(address (this), 100); + strategyManager.setShare(address(this), 100); GaugeFactory gaugeFactory = new GaugeFactory(); IncentivesFactory incentiveFactory = new IncentivesFactory(); address poolFactory = address(1); - FactoryRegistry factoryRegistry = new FactoryRegistry(poolFactory, address(incentiveFactory), address(gaugeFactory)); + FactoryRegistry factoryRegistry = new FactoryRegistry( + poolFactory, + address(incentiveFactory), + address(gaugeFactory) + ); voter = new Voter(address(forwarder), address(strategyManager), address(factoryRegistry)); address _gauge = voter.createGauge(poolFactory, address(pool), 0, 0); gauge = ERC20Gauge(_gauge); diff --git a/test/TestVault.t.sol b/test/TestVault.t.sol index 89eb685..b061061 100644 --- a/test/TestVault.t.sol +++ b/test/TestVault.t.sol @@ -28,7 +28,7 @@ contract TestVault is Test { gaugeFactory = new GaugeFactory(); incentiveFactory = new IncentivesFactory(); strategyManager = new TestStrategyManager(); - strategyManager.setShare(address (this), 100); + strategyManager.setShare(address(this), 100); poolFactory = address(1); factoryRegistry = new FactoryRegistry(poolFactory, address(incentiveFactory), address(gaugeFactory)); voter = new Voter(address(forwarder), address(strategyManager), address(factoryRegistry)); @@ -71,7 +71,7 @@ contract TestVault is Test { skip(2 hours); payable(address(vault)).transfer(vault.weekly() - 1 ether); voter.initialize(new address[](0), address(vault)); - address pool = address (111); + address pool = address(111); voter.createGauge(poolFactory, address(pool), 0, 0); address[] memory poolvote = new address[](1); uint256[] memory weights = new uint256[](1);