Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Aug 30, 2024
1 parent 65b2ec2 commit d17dc45
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 76 deletions.
7 changes: 6 additions & 1 deletion contracts/Voter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contracts/gauges/DeviceGauge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/gauges/ERC20Gauge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/gauges/RewardGauge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ 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);
}

/// @inheritdoc IRewardGauge
function deposit(uint256 _amountOrNFTID, address _recipient) external {
if (balanceOf[_recipient] == 0){
if (balanceOf[_recipient] == 0) {
depositUserNum++;
}
_depositFor(_amountOrNFTID, _recipient);
Expand Down
7 changes: 6 additions & 1 deletion contracts/interfaces/IVoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion script/02_deploy_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
6 changes: 3 additions & 3 deletions script/04_deploy_test.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
6 changes: 3 additions & 3 deletions script/05_deploy_gauge.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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`);
Expand All @@ -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`);
Expand Down
43 changes: 21 additions & 22 deletions script/06_deploy_deposit.ts
Original file line number Diff line number Diff line change
@@ -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;
});
42 changes: 23 additions & 19 deletions script/07_calculate_boost.ts
Original file line number Diff line number Diff line change
@@ -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;
});
2 changes: 1 addition & 1 deletion script/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ async function main() {
main().catch(err => {
console.error(err);
process.exitCode = 1;
});
});
39 changes: 22 additions & 17 deletions test/TestClaimVault.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,64 @@
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');

const lastClaimedBlock = await vault.lastClaimedBlock(projectId);
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');
})
})
});
});
8 changes: 6 additions & 2 deletions test/TestGauge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/TestVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d17dc45

Please sign in to comment.