From 4f949e6a8a1f536f57c1339ad5eaccbd3e42e1cd Mon Sep 17 00:00:00 2001 From: defi-dev Date: Sun, 8 May 2022 03:48:24 +0800 Subject: [PATCH] lint fixes --- contracts/PowerIndexVaultRouter.sol | 2 +- .../AbstractStakeRedeemConnector.sol | 7 +-- .../connectors/BalPowerIndexConnector.sol | 44 ++++++----------- contracts/interfaces/ILiquidityGauge.sol | 26 ++++++---- contracts/interfaces/IRouterConnector.sol | 4 +- .../interfaces/balancerV3/IBalancerMinter.sol | 6 ++- contracts/test/crv/BalancerMinterMock.sol | 5 +- contracts/test/crv/LiquidityGaugeMock.sol | 16 ++++-- tasks/deployLUSDAssetManager.js | 49 +++++++++---------- test/helpers/index.js | 26 +++++----- test/implementations/BalAssetManager.unit.js | 34 ++++++------- 11 files changed, 107 insertions(+), 112 deletions(-) diff --git a/contracts/PowerIndexVaultRouter.sol b/contracts/PowerIndexVaultRouter.sol index 5bdaaca..3e2cddd 100644 --- a/contracts/PowerIndexVaultRouter.sol +++ b/contracts/PowerIndexVaultRouter.sol @@ -77,7 +77,7 @@ contract PowerIndexVaultRouter is AbstractPowerIndexRouter, PowerIndexVaultRoute WrappedPiErc20Interface(_piToken).enableRouterCallback(_enable); } - function piTokenCallback(address, uint256 _withdrawAmount) external override payable virtual { + function piTokenCallback(address, uint256 _withdrawAmount) external payable virtual override { PokeFromState memory state = PokeFromState(0, 0, 0, _withdrawAmount, false, true); _rebalance(state, false, false); } diff --git a/contracts/connectors/AbstractStakeRedeemConnector.sol b/contracts/connectors/AbstractStakeRedeemConnector.sol index 93f5ca2..ae6af3a 100644 --- a/contracts/connectors/AbstractStakeRedeemConnector.sol +++ b/contracts/connectors/AbstractStakeRedeemConnector.sol @@ -45,12 +45,7 @@ abstract contract AbstractStakeRedeemConnector is AbstractProfitDistributionConn PowerIndexRouterInterface.StakeStatus _status, DistributeData memory _distributeData, bytes memory - ) - external - virtual - override - returns (bytes memory stakeData) - { + ) external virtual override returns (bytes memory stakeData) { if (_status == PowerIndexRouterInterface.StakeStatus.EQUILIBRIUM) { uint256 tokenBefore = UNDERLYING.balanceOf(address(PI_TOKEN)); _claimImpl(); diff --git a/contracts/connectors/BalPowerIndexConnector.sol b/contracts/connectors/BalPowerIndexConnector.sol index 93e3212..fa76a25 100644 --- a/contracts/connectors/BalPowerIndexConnector.sol +++ b/contracts/connectors/BalPowerIndexConnector.sol @@ -119,24 +119,20 @@ contract BalPowerIndexConnector is AbstractBalancerVaultConnector { } IVault.FundManagement memory fundManagment = IVault.FundManagement(ASSET_MANAGER, false, ASSET_MANAGER, false); - IVault(VAULT).batchSwap(IVault.SwapKind.GIVEN_IN, swaps, assets, fundManagment, limits, uint(-1)); + IVault(VAULT).batchSwap(IVault.SwapKind.GIVEN_IN, swaps, assets, fundManagment, limits, uint256(-1)); } - function stake(uint256 _amount, DistributeData memory _distributeData) - public - override - returns (bytes memory result, bool claimed) - { + function stake(uint256 _amount, DistributeData memory) public override returns (bytes memory result, bool claimed) { uint256 underlyingStaked = getUnderlyingStaked(); _capitalOut(underlyingStaked, _amount); _stakeImpl(_amount); emit Stake(msg.sender, STAKING, address(UNDERLYING), _amount); } - function redeem(uint256 _amount, DistributeData memory _distributeData) - external - override - returns (bytes memory result, bool claimed) + function redeem(uint256 _amount, DistributeData memory) + external + override + returns (bytes memory result, bool claimed) { uint256 underlyingStaked = getUnderlyingStaked(); // redeem amount will be converted to shares @@ -144,7 +140,6 @@ contract BalPowerIndexConnector is AbstractBalancerVaultConnector { // capital in amount without fee _capitalIn(underlyingStaked, _amount); emit Redeem(msg.sender, STAKING, address(UNDERLYING), _amount); - claimed = true; } function initRouter(bytes calldata) external override { @@ -173,9 +168,9 @@ contract BalPowerIndexConnector is AbstractBalancerVaultConnector { } function unpackStakeData(bytes memory _stakeData) - public - pure - returns (uint256 lastAssetsPerShare, uint256 underlyingEarned) + public + pure + returns (uint256 lastAssetsPerShare, uint256 underlyingEarned) { if (_stakeData.length == 0 || keccak256(_stakeData) == keccak256("")) { return (0, 0); @@ -211,9 +206,9 @@ contract BalPowerIndexConnector is AbstractBalancerVaultConnector { * @notice Unpack claim params from bytes to variables. */ function unpackStakeParams(bytes memory _stakeParams) - public - pure - returns (uint256 maxETHOnStaking, uint256 minLUSDToDistribute) + public + pure + returns (uint256 maxETHOnStaking, uint256 minLUSDToDistribute) { if (_stakeParams.length == 0 || keccak256(_stakeParams) == keccak256("")) { return (0, 0); @@ -248,20 +243,9 @@ contract BalPowerIndexConnector is AbstractBalancerVaultConnector { } /** - * @dev This function should be manually changed to "view" in the ABI - */ + * @dev This function should be manually changed to "view" in the ABI + */ function getPendingRewards() public returns (uint256) { return REWARDS_MINTER.mintFor(STAKING, ASSET_MANAGER); } } - - - - - - - - - - - diff --git a/contracts/interfaces/ILiquidityGauge.sol b/contracts/interfaces/ILiquidityGauge.sol index 35aa592..73776f4 100644 --- a/contracts/interfaces/ILiquidityGauge.sol +++ b/contracts/interfaces/ILiquidityGauge.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.7.0; + //pragma experimental ABIEncoderV2; interface ILiquidityGauge { @@ -13,7 +14,11 @@ interface ILiquidityGauge { uint256 integral; } - function deposit(uint256 _value, address _addr, bool _claim_rewards) external; + function deposit( + uint256 _value, + address _addr, + bool _claim_rewards + ) external; function withdraw(uint256 _value, bool _claim_rewards) external; @@ -23,12 +28,15 @@ interface ILiquidityGauge { function user_checkpoint(address user) external returns (bool); - function reward_data(address user) external view returns ( - address token, - address distributor, - uint256 period_finish, - uint256 rate, - uint256 last_update, - uint256 integral - ); + function reward_data(address user) + external + view + returns ( + address token, + address distributor, + uint256 period_finish, + uint256 rate, + uint256 last_update, + uint256 integral + ); } diff --git a/contracts/interfaces/IRouterConnector.sol b/contracts/interfaces/IRouterConnector.sol index 9aba7b8..d13bfbe 100644 --- a/contracts/interfaces/IRouterConnector.sol +++ b/contracts/interfaces/IRouterConnector.sol @@ -52,7 +52,5 @@ interface IRouterConnector { PowerIndexRouterInterface.StakeStatus _status, DistributeData calldata _distributeData, bytes calldata _claimParams - ) - external - returns (bytes calldata); + ) external returns (bytes calldata); } diff --git a/contracts/interfaces/balancerV3/IBalancerMinter.sol b/contracts/interfaces/balancerV3/IBalancerMinter.sol index 1db2aed..07b3a02 100644 --- a/contracts/interfaces/balancerV3/IBalancerMinter.sol +++ b/contracts/interfaces/balancerV3/IBalancerMinter.sol @@ -1,3 +1,5 @@ +pragma solidity ^0.7.0; + interface IBalancerMinter { event MinterApprovalSet(address indexed user, address indexed minter, bool approval); @@ -16,7 +18,7 @@ interface IBalancerMinter { function mintFor(address gauge, address user) external returns (uint256); /** - * @notice Set whether `minter` is approved to mint tokens on your behalf - */ + * @notice Set whether `minter` is approved to mint tokens on your behalf + */ function setMinterApproval(address minter, bool approval) external; } diff --git a/contracts/test/crv/BalancerMinterMock.sol b/contracts/test/crv/BalancerMinterMock.sol index 3ed970f..d5982f3 100644 --- a/contracts/test/crv/BalancerMinterMock.sol +++ b/contracts/test/crv/BalancerMinterMock.sol @@ -35,9 +35,8 @@ contract BalancerMinterMock is ReentrancyGuard, EIP712 { mapping(address => uint256) internal _nextNonce; // solhint-disable-next-line var-name-mixedcase - bytes32 private immutable _SET_MINTER_APPROVAL_TYPEHASH = keccak256( - "SetMinterApproval(address minter,bool approval,uint256 nonce,uint256 deadline)" - ); + bytes32 private immutable _SET_MINTER_APPROVAL_TYPEHASH = + keccak256("SetMinterApproval(address minter,bool approval,uint256 nonce,uint256 deadline)"); event MinterApprovalSet(address indexed user, address indexed minter, bool approval); diff --git a/contracts/test/crv/LiquidityGaugeMock.sol b/contracts/test/crv/LiquidityGaugeMock.sol index 4a13224..661138d 100644 --- a/contracts/test/crv/LiquidityGaugeMock.sol +++ b/contracts/test/crv/LiquidityGaugeMock.sol @@ -19,13 +19,21 @@ contract LiquidityGaugeMock is ILiquidityGauge { IERC20 public rewardsTokens; uint256 public rewardsPerSecond; - constructor(IERC20 _stakeToken, IERC20 _rewardsTokens, uint256 _rewardsPerSecond) public { + constructor( + IERC20 _stakeToken, + IERC20 _rewardsTokens, + uint256 _rewardsPerSecond + ) public { stakeToken = _stakeToken; rewardsTokens = _rewardsTokens; rewardsPerSecond = _rewardsPerSecond; } - function deposit(uint256 _amount, address _depositFor, bool _claim) external override { + function deposit( + uint256 _amount, + address _depositFor, + bool _claim + ) external override { console.log("stakeToken.balanceOf", stakeToken.balanceOf(msg.sender)); stakeToken.transferFrom(msg.sender, address(this), _amount); balanceOf[_depositFor] = balanceOf[_depositFor].add(_amount); @@ -43,7 +51,9 @@ contract LiquidityGaugeMock is ILiquidityGauge { function _updateAccumulated(address _user) internal { accumulated = accumulated.add(rewardsPerSecond.mul(block.timestamp.sub(lastAccumulatedAt))); if (reward_data[_user].rate != 0) { - totalRewards[_user] = totalRewards[_user].add(accumulated.sub(reward_data[_user].rate).mul(balanceOf[_user]).div(totalSupply)); + totalRewards[_user] = totalRewards[_user].add( + accumulated.sub(reward_data[_user].rate).mul(balanceOf[_user]).div(totalSupply) + ); } reward_data[_user].rate = accumulated; lastAccumulatedAt = block.timestamp; diff --git a/tasks/deployLUSDAssetManager.js b/tasks/deployLUSDAssetManager.js index 2833cb8..d3d3aa5 100644 --- a/tasks/deployLUSDAssetManager.js +++ b/tasks/deployLUSDAssetManager.js @@ -2,7 +2,7 @@ require('@nomiclabs/hardhat-truffle5'); require('@nomiclabs/hardhat-ethers'); task('deploy-lusd-asset-manager', 'Deploy LUSD Asset Manager').setAction(async (__, { ethers, network }) => { - const { ether, zeroAddress, impersonateAccount, gwei, increaseTime, maxUint256 } = require('../test/helpers'); + const { ether, impersonateAccount, gwei, increaseTime, maxUint256 } = require('../test/helpers'); const IERC20 = await artifacts.require('@openzeppelin/contracts/token/ERC20/IERC20.sol:IERC20'); const IVault = await artifacts.require('contracts/interfaces/balancerV3/IVault.sol:IVault'); const ILiquidityGauge = await artifacts.require('ILiquidityGauge'); @@ -10,8 +10,7 @@ task('deploy-lusd-asset-manager', 'Deploy LUSD Asset Manager').setAction(async ( const PowerPoke = await artifacts.require('IPowerPoke'); const IBalancerMinter = await artifacts.require('IBalancerMinter'); const IBasePool = await artifacts.require('contracts/interfaces/balancerV3/IBasePool.sol:IBasePool'); - const BAMM = await artifacts.require('BAMM'); - const StabilityPool = await artifacts.require('StabilityPool'); + // const BAMM = await artifacts.require('BAMM'); const BProtocolPowerIndexConnector = await artifacts.require('BProtocolPowerIndexConnector'); const BalPowerIndexConnector = await artifacts.require('BalPowerIndexConnector'); const StablePoolFactory = await artifacts.require('@powerpool/balancer-v2-pool-stable/contracts/StablePoolFactory'); @@ -181,7 +180,7 @@ task('deploy-lusd-asset-manager', 'Deploy LUSD Asset Manager').setAction(async ( { to: pokerReporter, compensateInETH: true }, ); - const bamm = await BAMM.at(bammAddress); + // const bamm = await BAMM.at(bammAddress); const gauge = await ILiquidityGauge.at(liquidityGaugeAddress); const balancerMinter = await IBalancerMinter.at(balancerMinterAddress); @@ -247,27 +246,27 @@ task('deploy-lusd-asset-manager', 'Deploy LUSD Asset Manager').setAction(async ( console.log(prefix, printsNumber + ' assetManagerRewards ', await lqty.balanceOf(lusdAssetManager.address).then(r => r.toString())); } - async function showBammInitInfo() { - console.log('stability pool', await bamm.SP()); - const stabilityPool = await StabilityPool.at(await bamm.SP()); - console.log( - 'getCompoundedLUSDDeposit', - await stabilityPool.getCompoundedLUSDDeposit(bammAddress).then(r => r.toString()), - ); - console.log('getDepositorETHGain', await stabilityPool.getDepositorETHGain(bammAddress).then(r => r.toString())); - console.log('fetchPrice', await bamm.fetchPrice().then(r => r.toString())); - } - - async function showBammStakeInfo(number) { - const c = await lusdAssetManager.connectors('0'); - console.log('stake ' + number, await bamm.stake(lusdAssetManager.address).then(a => a.toString())); - console.log('isClaimAvailable', await lusdConnector.isClaimAvailable(c.claimParams)); - console.log('claimRewardsIntervalReached', await lusdAssetManager.claimRewardsIntervalReached(c.lastClaimRewardsAt)); - console.log( - 'getStakeAndClaimStatusByConnectorIndex', - await lusdAssetManager.getStakeAndClaimStatusByConnectorIndex('0', true), - ); - } + // async function showBammInitInfo() { + // console.log('stability pool', await bamm.SP()); + // const stabilityPool = await StabilityPool.at(await bamm.SP()); + // console.log( + // 'getCompoundedLUSDDeposit', + // await stabilityPool.getCompoundedLUSDDeposit(bammAddress).then(r => r.toString()), + // ); + // console.log('getDepositorETHGain', await stabilityPool.getDepositorETHGain(bammAddress).then(r => r.toString())); + // console.log('fetchPrice', await bamm.fetchPrice().then(r => r.toString())); + // } + // + // async function showBammStakeInfo(number) { + // const c = await lusdAssetManager.connectors('0'); + // console.log('stake ' + number, await bamm.stake(lusdAssetManager.address).then(a => a.toString())); + // console.log('isClaimAvailable', await lusdConnector.isClaimAvailable(c.claimParams)); + // console.log('claimRewardsIntervalReached', await lusdAssetManager.claimRewardsIntervalReached(c.lastClaimRewardsAt)); + // console.log( + // 'getStakeAndClaimStatusByConnectorIndex', + // await lusdAssetManager.getStakeAndClaimStatusByConnectorIndex('0', true), + // ); + // } async function addPokeClient(assetManagerAddress) { const BONUS_NUMERATOR = '7610350076'; diff --git a/test/helpers/index.js b/test/helpers/index.js index 6f3d3f2..691a427 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -215,19 +215,19 @@ async function impersonateAccount(ethers, adminAddress) { await ethers.provider.send('hardhat_impersonateAccount', [adminAddress]); } -async function forkPrepareBalancerAutorizer(ethers, network, deployer) { - const IAuthorizer = await artifacts.require('contracts/interfaces/balancerV3/IAuthorizer.sol:IAuthorizer'); - - await network.provider.request({ - method: 'hardhat_reset', - params: [{ forking: { jsonRpcUrl: process.env.RPC } }], - }); - const daoMultisigAddress = '0x10a19e7ee7d7f8a52822f6817de8ea18204f2e4f'; - const roles = ['0x38850d48acdf7da1f77e6b4a1991447eb2c439554ba14cdfec945500fdc714a1']; - const authorizer = await IAuthorizer.at('0xa331d84ec860bf466b4cdccfb4ac09a1b43f3ae6'); - await impersonateAccount(ethers, daoMultisigAddress); - await authorizer.grantRoles(roles, deployer, { from: daoMultisigAddress }); -} +// async function forkPrepareBalancerAutorizer(ethers, network, deployer) { +// const IAuthorizer = await artifacts.require('contracts/interfaces/balancerV3/IAuthorizer.sol:IAuthorizer'); +// +// await network.provider.request({ +// method: 'hardhat_reset', +// params: [{ forking: { jsonRpcUrl: process.env.RPC } }], +// }); +// const daoMultisigAddress = '0x10a19e7ee7d7f8a52822f6817de8ea18204f2e4f'; +// const roles = ['0x38850d48acdf7da1f77e6b4a1991447eb2c439554ba14cdfec945500fdc714a1']; +// const authorizer = await IAuthorizer.at('0xa331d84ec860bf466b4cdccfb4ac09a1b43f3ae6'); +// await impersonateAccount(ethers, daoMultisigAddress); +// await authorizer.grantRoles(roles, deployer, { from: daoMultisigAddress }); +// } async function forkContractUpgrade(ethers, adminAddress, proxyAdminAddress, proxyAddress, implAddress) { const iface = new ethers.utils.Interface(['function upgrade(address proxy, address impl)']); diff --git a/test/implementations/BalAssetManager.unit.js b/test/implementations/BalAssetManager.unit.js index 81689e0..9efa267 100644 --- a/test/implementations/BalAssetManager.unit.js +++ b/test/implementations/BalAssetManager.unit.js @@ -1,4 +1,4 @@ -const { time, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers'); +const { time, constants, expectRevert } = require('@openzeppelin/test-helpers'); const { ether, zeroAddress, maxUint256, deployContractWithBytecode } = require('./../helpers'); const { buildBasicRouterConfig } = require('./../helpers/builders'); const assert = require('chai').assert; @@ -26,10 +26,10 @@ const { toBN } = web3.utils; describe('BalAssetManager Tests', () => { - let deployer, alice, eve, piGov, stub, pvp; + let deployer, alice, piGov, pvp; before(async function () { - [deployer, alice, eve, piGov, stub, pvp] = await web3.eth.getAccounts(); + [deployer, alice, piGov, pvp] = await web3.eth.getAccounts(); }); let lusd, @@ -221,8 +221,8 @@ describe('BalAssetManager Tests', () => { await time.increase(time.duration.minutes(60)); - const expectedReward = ether(71.81557632398753894); - const expectedFee = ether(71.81557632398753894 * 0.15); + const expectedReward = ether('71.81557632398753894'); + const expectedFee = toBN(ether('71.81557632398753894')).mul(toBN(ether('0.15'))).div(toBN(ether('1'))); approximatelyEqual(await connector.contract.methods.getPendingRewards().call({}).then(r => r.toString()), expectedReward); @@ -255,12 +255,12 @@ describe('BalAssetManager Tests', () => { )[1]; assert.equal(transfer.args.from, assetManager.address); assert.equal(transfer.args.to, staking.address); - approximatelyEqual(transfer.args.value, ether(30.525856697819314641)); + approximatelyEqual(transfer.args.value, ether('30.525856697819314641')); - approximatelyEqual(await assetManager.getUnderlyingStaked(), ether(1600030.530093457943925234)); - assert.equal(await assetManager.getAssetsHolderUnderlyingBalance(), ether(400000)); - approximatelyEqual(await assetManager.getUnderlyingTotal(), ether(2000030.530093457943925234)); - approximatelyEqual(await staking.balanceOf(assetManager.address), ether(1600030.530093457943925234)); + approximatelyEqual(await assetManager.getUnderlyingStaked(), ether('1600030.530093457943925234')); + assert.equal(await assetManager.getAssetsHolderUnderlyingBalance(), ether('400000')); + approximatelyEqual(await assetManager.getUnderlyingTotal(), ether('2000030.530093457943925234')); + approximatelyEqual(await staking.balanceOf(assetManager.address), ether('1600030.530093457943925234')); }); it('should claim rewards twice and reinvest', async () => { @@ -274,7 +274,7 @@ describe('BalAssetManager Tests', () => { await time.increase(time.duration.minutes(60)); - const firstReward = ether(71.81557632398753894); + const firstReward = ether('71.81557632398753894'); approximatelyEqual(await connector.contract.methods.getPendingRewards().call({}).then(r => r.toString()), firstReward); let res = await connector.getPendingRewards(); @@ -289,7 +289,7 @@ describe('BalAssetManager Tests', () => { await time.increase(time.duration.minutes(60)); - const secondReward = ether(35.907788161993769470); + const secondReward = ether('35.907788161993769470'); await expectRevert(assetManager.pokeFromReporter(0, false, '0x'), 'NOTHING_TO_DO'); res = await assetManager.pokeFromReporter('1', true, '0x'); @@ -302,7 +302,7 @@ describe('BalAssetManager Tests', () => { approximatelyEqual(transfer.args.value, secondReward); const totalReward = toBN(firstReward).add(toBN(secondReward)); - const fee = totalReward.mul(toBN(ether(0.15))).div(toBN(ether(1))); + const fee = totalReward.mul(toBN(ether('0.15'))).div(toBN(ether(1))); transfer = MockERC20.decodeLogs(res.receipt.rawLogs).filter( l => l.args.to === swapper.address && l.event === 'Transfer', )[0]; @@ -321,10 +321,10 @@ describe('BalAssetManager Tests', () => { assert.equal(transfer.args.from, assetManager.address); approximatelyEqual(transfer.args.value, totalReward.sub(fee).div(toBN('2'))); - approximatelyEqual(await assetManager.getUnderlyingStaked(), ether(1600045.778193146417445482)); - assert.equal(await assetManager.getAssetsHolderUnderlyingBalance(), ether(400000)); - approximatelyEqual(await assetManager.getUnderlyingTotal(), ether(2000045.778193146417445482)); - approximatelyEqual(await staking.balanceOf(assetManager.address), ether(1600045.778193146417445482)); + approximatelyEqual(await assetManager.getUnderlyingStaked(), ether('1600045.778193146417445482')); + assert.equal(await assetManager.getAssetsHolderUnderlyingBalance(), ether('400000')); + approximatelyEqual(await assetManager.getUnderlyingTotal(), ether('2000045.778193146417445482')); + approximatelyEqual(await staking.balanceOf(assetManager.address), ether('1600045.778193146417445482')); }); }); });