From f09b5c3546405c4e93b0405aa741d5d3c75a5ca9 Mon Sep 17 00:00:00 2001 From: Joey Santoro Date: Fri, 14 Jan 2022 15:58:54 -0800 Subject: [PATCH 1/5] scripts cleanup --- package.json | 7 +--- proposals/dao/{ => old}/fip_54.ts | 2 +- proposals/dao/{ => old}/fip_60.ts | 0 proposals/dao/{ => old}/fip_61.ts | 0 proposals/dao/{ => old}/fip_62.ts | 0 proposals/dao/{ => old}/fip_bribe.ts | 0 proposals/description/{ => old}/fip_54.ts | 0 proposals/description/{ => old}/fip_60.ts | 0 proposals/description/{ => old}/fip_60b.ts | 0 proposals/description/{ => old}/fip_61.ts | 0 proposals/description/{ => old}/fip_62.ts | 0 scripts/coverage.js | 26 ------------- .../deploy/{ => old}/optimisticTimelock.ts | 2 +- scripts/sortAddresses.js | 37 ------------------- scripts/{ => utils}/abis.js | 0 test/integration/proposals_config.ts | 22 +---------- test/integration/tests/backstop.ts | 2 +- 17 files changed, 6 insertions(+), 92 deletions(-) rename proposals/dao/{ => old}/fip_54.ts (99%) rename proposals/dao/{ => old}/fip_60.ts (100%) rename proposals/dao/{ => old}/fip_61.ts (100%) rename proposals/dao/{ => old}/fip_62.ts (100%) rename proposals/dao/{ => old}/fip_bribe.ts (100%) rename proposals/description/{ => old}/fip_54.ts (100%) rename proposals/description/{ => old}/fip_60.ts (100%) rename proposals/description/{ => old}/fip_60b.ts (100%) rename proposals/description/{ => old}/fip_61.ts (100%) rename proposals/description/{ => old}/fip_62.ts (100%) delete mode 100755 scripts/coverage.js rename scripts/deploy/{ => old}/optimisticTimelock.ts (92%) delete mode 100644 scripts/sortAddresses.js rename scripts/{ => utils}/abis.js (100%) diff --git a/package.json b/package.json index b3fe2fe04..3f0c45ca4 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,7 @@ "files": [], "scripts": { "compile": "npx hardhat compile", - "coverage": "scripts/coverage.js", - "coverage:hardhat": "npx hardhat coverage", + "coverage": "npx hardhat coverage", "console": "npx hardhat console", "console:rinkeby": "npx hardhat console --network rinkeby", "console:ropsten": "npx hardhat console --network ropsten", @@ -27,9 +26,7 @@ "deploy:fuse": "DEPLOY_FILE=compoundPCVDeposit npx hardhat run --network mainnet scripts/deploy/migrations.ts", "deploy:timelock": "DEPLOY_FILE=optimisticTimelockDeploy npx hardhat run --network mainnet scripts/deploy/migrations.ts", "deploy:stw": "DEPLOY_FILE=deployStakedTokenWrapper npx hardhat run --network mainnet scripts/deploy/migrations.ts", - "deploy:ropsten": "npx hardhat run --network ropsten scripts/deploy/migrations.ts", - "deploy:rinkeby": "npx hardhat run --network rinkeby scripts/deploy/migrations.ts", - "abis": "node scripts/abis.js", + "abis": "node scripts/utils/abis.js", "calldata": "npx hardhat run scripts/utils/getProposalCalldata.ts", "check-proposal": "ENABLE_MAINNET_FORKING=true npx hardhat run scripts/utils/checkProposal.ts", "prettier-format": "prettier --config .prettierrc './**/*.ts' --write", diff --git a/proposals/dao/fip_54.ts b/proposals/dao/old/fip_54.ts similarity index 99% rename from proposals/dao/fip_54.ts rename to proposals/dao/old/fip_54.ts index 8bf2fdaf8..9e750ac89 100644 --- a/proposals/dao/fip_54.ts +++ b/proposals/dao/old/fip_54.ts @@ -7,7 +7,7 @@ import { SetupUpgradeFunc, TeardownUpgradeFunc, ValidateUpgradeFunc -} from '../../types/types'; +} from '../../../types/types'; chai.use(CBN(ethers.BigNumber)); diff --git a/proposals/dao/fip_60.ts b/proposals/dao/old/fip_60.ts similarity index 100% rename from proposals/dao/fip_60.ts rename to proposals/dao/old/fip_60.ts diff --git a/proposals/dao/fip_61.ts b/proposals/dao/old/fip_61.ts similarity index 100% rename from proposals/dao/fip_61.ts rename to proposals/dao/old/fip_61.ts diff --git a/proposals/dao/fip_62.ts b/proposals/dao/old/fip_62.ts similarity index 100% rename from proposals/dao/fip_62.ts rename to proposals/dao/old/fip_62.ts diff --git a/proposals/dao/fip_bribe.ts b/proposals/dao/old/fip_bribe.ts similarity index 100% rename from proposals/dao/fip_bribe.ts rename to proposals/dao/old/fip_bribe.ts diff --git a/proposals/description/fip_54.ts b/proposals/description/old/fip_54.ts similarity index 100% rename from proposals/description/fip_54.ts rename to proposals/description/old/fip_54.ts diff --git a/proposals/description/fip_60.ts b/proposals/description/old/fip_60.ts similarity index 100% rename from proposals/description/fip_60.ts rename to proposals/description/old/fip_60.ts diff --git a/proposals/description/fip_60b.ts b/proposals/description/old/fip_60b.ts similarity index 100% rename from proposals/description/fip_60b.ts rename to proposals/description/old/fip_60b.ts diff --git a/proposals/description/fip_61.ts b/proposals/description/old/fip_61.ts similarity index 100% rename from proposals/description/fip_61.ts rename to proposals/description/old/fip_61.ts diff --git a/proposals/description/fip_62.ts b/proposals/description/old/fip_62.ts similarity index 100% rename from proposals/description/fip_62.ts rename to proposals/description/old/fip_62.ts diff --git a/scripts/coverage.js b/scripts/coverage.js deleted file mode 100755 index c00d3c9d5..000000000 --- a/scripts/coverage.js +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env node - -const { runCoverage } = require('@openzeppelin/test-environment'); - -async function main() { - await runCoverage( - [ - 'mock', - 'external', - 'orchestration', - 'utils/SafeMath128.sol', - 'utils/SafeMath32.sol', - 'dao/Timelock.sol', - 'dao/GovernorAlpha.sol', - 'tribe/Tribe.sol', - 'Migrations.sol' - ], - 'npx oz compile --evm-version "istanbul" --optimizer off', - './node_modules/.bin/mocha --exit --timeout 10000 --recursive'.split(' ') - ); -} - -main().catch((e) => { - console.error(e); - process.exit(1); -}); diff --git a/scripts/deploy/optimisticTimelock.ts b/scripts/deploy/old/optimisticTimelock.ts similarity index 92% rename from scripts/deploy/optimisticTimelock.ts rename to scripts/deploy/old/optimisticTimelock.ts index 7ebf8b16a..e693d0437 100644 --- a/scripts/deploy/optimisticTimelock.ts +++ b/scripts/deploy/old/optimisticTimelock.ts @@ -1,4 +1,4 @@ -import { DeployUpgradeFunc } from '../../types/types'; +import { DeployUpgradeFunc } from '../../../types/types'; import { ethers } from 'hardhat'; const fourDays = 4 * 24 * 60 * 60; diff --git a/scripts/sortAddresses.js b/scripts/sortAddresses.js deleted file mode 100644 index e92b4539a..000000000 --- a/scripts/sortAddresses.js +++ /dev/null @@ -1,37 +0,0 @@ - -import addresses from '../protocol-configuration/mainnetAddresses'; - -const categories = { - Core: 0, - Governance: 1, - Peg: 2, - PCV: 3, - Collateralization: 4, - Oracle: 5, - Keeper: 6, - Rewards: 7, - FeiRari: 8, - External: 9, - Deprecated: 10, - TBD: 11 - } - -const result = - Object.keys(addresses) - .sort((a, b) => - { - let order = categories[addresses[a].category] - categories[addresses[b].category]; - if (order === 0) { - order = a.localeCompare(b); - } - return order; - }) - .reduce( - (_sortedObj, key) => ({ - ..._sortedObj, - [key]: addresses[key] - }), - {} - ); - -console.log(result); \ No newline at end of file diff --git a/scripts/abis.js b/scripts/utils/abis.js similarity index 100% rename from scripts/abis.js rename to scripts/utils/abis.js diff --git a/test/integration/proposals_config.ts b/test/integration/proposals_config.ts index cc849b471..518266525 100644 --- a/test/integration/proposals_config.ts +++ b/test/integration/proposals_config.ts @@ -2,8 +2,7 @@ import { ProposalCategory, ProposalsConfigMap } from '@custom-types/types'; // import fip_xx_proposal from '@proposals/description/fip_xx'; -import fip_54 from '@proposals/description/fip_54'; -import fip_60b from '@proposals/description/fip_60b'; +import fip_60b from '@proposals/description/old/fip_60b'; import fip_63 from '@proposals/description/fip_63'; import fip_64 from '@proposals/description/fip_64'; @@ -16,25 +15,6 @@ const proposals: ProposalsConfigMap = { proposal: fip_xx_proposal // full proposal file, imported from '@proposals/description/fip_xx.ts' } */ - fip_54: { - deploy: false, - proposalId: undefined, - affectedContractSignoff: [ - 'restrictedPermissions', - 'fei', - 'core', - 'ethPSMFeiSkimmer', - 'daiPSMFeiSkimmer', - 'rariInfraTribeTimelock', - 'rariInfraFeiTimelock', - 'votiumBriberD3pool', - 'opsOptimisticTimelock' - ], - deprecatedContractSignoff: [], - category: ProposalCategory.DAO, - totalValue: 0, - proposal: fip_54 - }, fip_60b: { deploy: false, proposalId: undefined, diff --git a/test/integration/tests/backstop.ts b/test/integration/tests/backstop.ts index b24c0163c..437dd634d 100644 --- a/test/integration/tests/backstop.ts +++ b/test/integration/tests/backstop.ts @@ -15,7 +15,7 @@ before(async () => { await resetFork(); }); -describe('e2e-backstop', function () { +describe.only('e2e-backstop', function () { let contracts: NamedContracts; let contractAddresses: NamedAddresses; let deployAddress: string; From e1f6ecabfae35f36f09342a53ef73a955fa2137e Mon Sep 17 00:00:00 2001 From: Joey Santoro Date: Fri, 14 Jan 2022 16:01:06 -0800 Subject: [PATCH 2/5] .only --- test/integration/tests/backstop.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/tests/backstop.ts b/test/integration/tests/backstop.ts index 437dd634d..b24c0163c 100644 --- a/test/integration/tests/backstop.ts +++ b/test/integration/tests/backstop.ts @@ -15,7 +15,7 @@ before(async () => { await resetFork(); }); -describe.only('e2e-backstop', function () { +describe('e2e-backstop', function () { let contracts: NamedContracts; let contractAddresses: NamedAddresses; let deployAddress: string; From 2cba62b0e09a8cd1ae051e0039937b529aac3456 Mon Sep 17 00:00:00 2001 From: Joey Santoro Date: Fri, 14 Jan 2022 16:49:02 -0800 Subject: [PATCH 3/5] reorg tests --- test/unit/dao/{ => governor}/FeiDao.test.ts | 0 test/unit/dao/{ => timelocks}/FeiDAOTimelock.test.ts | 2 +- .../dao/{ => timelocks}/OptimisticTimelock.test.ts | 2 +- test/unit/{token => fei}/Fei.test.ts | 0 .../{token => fei/minter}/FeiTimedMinter.test.ts | 2 +- .../{token => fei/minter}/PCVEquityMinter.test.ts | 2 +- .../{utils => fei/minter}/RateLimitedMinter.test.ts | 2 +- .../feirari => fuse}/AutoRewardsDistributor.test.ts | 12 ++++++------ .../feirari => fuse}/RewardsDistributorAdmin.test.ts | 0 .../CollateralizationOracle.test.ts | 2 +- .../CollateralizationOracleGuardian.test.ts | 2 +- .../CollateralizationOracleWrapper.test.ts | 2 +- test/unit/pcv/{ => aave}/AavePCVDeposit.test.ts | 2 +- .../pcv/{ => angle}/AngleUniswapPCVDeposit.test.ts | 2 +- test/unit/pcv/{ => balancer}/BPTLens.test.ts | 0 .../pcv/{ => balancer}/BalancerLBPSwapper.test.ts | 0 .../BalancerPCVDepositWeightedPool.test.ts | 0 .../{ => compound}/ERC20CompoundPCVDeposit.test.ts | 2 +- .../pcv/{ => compound}/EthCompoundPCVDeposit.test.ts | 2 +- test/unit/pcv/{ => convex}/ConvexPCVDeposit.test.ts | 0 .../pcv/{ => curve}/CurvePCVDepositPlainPool.test.ts | 0 test/unit/pcv/{ => lido}/EthLidoPCVDeposit.test.ts | 4 ++-- .../pcv/{ => tokemak}/ERC20TokemakPCVDeposit.test.ts | 0 .../pcv/{ => tokemak}/EthTokemakPCVDeposit.test.ts | 0 .../unit/pcv/{ => uniswap}/PCVSwapperUniswap.test.ts | 2 +- .../unit/pcv/{ => uniswap}/UniswapPCVDeposit.test.ts | 2 +- test/unit/pcv/{ => utils}/ERC20Dripper.test.ts | 2 +- .../pcv/{ => utils}/ERC20PCVDepositWrapper.test.ts | 2 +- test/unit/pcv/{ => utils}/ERC20Splitter.test.ts | 2 +- test/unit/pcv/{ => utils}/FeiSkimmer.test.ts | 0 .../{ => utils}/NamedStaticPCVDepositWrapper.test.ts | 0 test/unit/pcv/{ => utils}/PCVDepositWrapper.test.ts | 2 +- test/unit/pcv/{ => utils}/PCVDripController.test.ts | 2 +- .../pcv/{ => utils}/RatioPCVControllerV2.test.ts | 2 +- .../MintRedeemPausePSM.test.ts} | 0 test/unit/{stabilizer => peg}/PSMRouter.test.ts | 0 .../{stabilizer => peg}/PegStabilityModule.test.ts | 0 .../PriceBoundPegStabilityModule.test.ts | 0 .../{stabilizer => peg}/ReserveStabilizer.test.ts | 0 .../{dao => timelocks}/QuadraticTimelock.test.ts | 0 .../{dao => timelocks}/TimelockedDelegator.test.ts | 0 test/unit/{dao => tribe}/TribeMinter.test.ts | 6 ------ .../TribeReserveStabilizer.test.ts | 0 43 files changed, 28 insertions(+), 34 deletions(-) rename test/unit/dao/{ => governor}/FeiDao.test.ts (100%) rename test/unit/dao/{ => timelocks}/FeiDAOTimelock.test.ts (98%) rename test/unit/dao/{ => timelocks}/OptimisticTimelock.test.ts (96%) rename test/unit/{token => fei}/Fei.test.ts (100%) rename test/unit/{token => fei/minter}/FeiTimedMinter.test.ts (99%) rename test/unit/{token => fei/minter}/PCVEquityMinter.test.ts (99%) rename test/unit/{utils => fei/minter}/RateLimitedMinter.test.ts (99%) rename test/unit/{staking/feirari => fuse}/AutoRewardsDistributor.test.ts (96%) rename test/unit/{staking/feirari => fuse}/RewardsDistributorAdmin.test.ts (100%) rename test/unit/oracle/{ => collateralization}/CollateralizationOracle.test.ts (99%) rename test/unit/oracle/{ => collateralization}/CollateralizationOracleGuardian.test.ts (99%) rename test/unit/oracle/{ => collateralization}/CollateralizationOracleWrapper.test.ts (99%) rename test/unit/pcv/{ => aave}/AavePCVDeposit.test.ts (98%) rename test/unit/pcv/{ => angle}/AngleUniswapPCVDeposit.test.ts (99%) rename test/unit/pcv/{ => balancer}/BPTLens.test.ts (100%) rename test/unit/pcv/{ => balancer}/BalancerLBPSwapper.test.ts (100%) rename test/unit/pcv/{ => balancer}/BalancerPCVDepositWeightedPool.test.ts (100%) rename test/unit/pcv/{ => compound}/ERC20CompoundPCVDeposit.test.ts (98%) rename test/unit/pcv/{ => compound}/EthCompoundPCVDeposit.test.ts (98%) rename test/unit/pcv/{ => convex}/ConvexPCVDeposit.test.ts (100%) rename test/unit/pcv/{ => curve}/CurvePCVDepositPlainPool.test.ts (100%) rename test/unit/pcv/{ => lido}/EthLidoPCVDeposit.test.ts (98%) rename test/unit/pcv/{ => tokemak}/ERC20TokemakPCVDeposit.test.ts (100%) rename test/unit/pcv/{ => tokemak}/EthTokemakPCVDeposit.test.ts (100%) rename test/unit/pcv/{ => uniswap}/PCVSwapperUniswap.test.ts (99%) rename test/unit/pcv/{ => uniswap}/UniswapPCVDeposit.test.ts (99%) rename test/unit/pcv/{ => utils}/ERC20Dripper.test.ts (99%) rename test/unit/pcv/{ => utils}/ERC20PCVDepositWrapper.test.ts (97%) rename test/unit/pcv/{ => utils}/ERC20Splitter.test.ts (97%) rename test/unit/pcv/{ => utils}/FeiSkimmer.test.ts (100%) rename test/unit/pcv/{ => utils}/NamedStaticPCVDepositWrapper.test.ts (100%) rename test/unit/pcv/{ => utils}/PCVDepositWrapper.test.ts (98%) rename test/unit/pcv/{ => utils}/PCVDripController.test.ts (99%) rename test/unit/pcv/{ => utils}/RatioPCVControllerV2.test.ts (99%) rename test/unit/{stabilizer/EthPegStabilityModule.test.ts => peg/MintRedeemPausePSM.test.ts} (100%) rename test/unit/{stabilizer => peg}/PSMRouter.test.ts (100%) rename test/unit/{stabilizer => peg}/PegStabilityModule.test.ts (100%) rename test/unit/{stabilizer => peg}/PriceBoundPegStabilityModule.test.ts (100%) rename test/unit/{stabilizer => peg}/ReserveStabilizer.test.ts (100%) rename test/unit/{dao => timelocks}/QuadraticTimelock.test.ts (100%) rename test/unit/{dao => timelocks}/TimelockedDelegator.test.ts (100%) rename test/unit/{dao => tribe}/TribeMinter.test.ts (97%) rename test/unit/{stabilizer => tribe}/TribeReserveStabilizer.test.ts (100%) diff --git a/test/unit/dao/FeiDao.test.ts b/test/unit/dao/governor/FeiDao.test.ts similarity index 100% rename from test/unit/dao/FeiDao.test.ts rename to test/unit/dao/governor/FeiDao.test.ts diff --git a/test/unit/dao/FeiDAOTimelock.test.ts b/test/unit/dao/timelocks/FeiDAOTimelock.test.ts similarity index 98% rename from test/unit/dao/FeiDAOTimelock.test.ts rename to test/unit/dao/timelocks/FeiDAOTimelock.test.ts index 333842822..6d37497b9 100644 --- a/test/unit/dao/FeiDAOTimelock.test.ts +++ b/test/unit/dao/timelocks/FeiDAOTimelock.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, getAddresses, getCore, getImpersonatedSigner, latestTime } from '../../helpers'; +import { expectRevert, getAddresses, getCore, getImpersonatedSigner, latestTime } from '@test/helpers'; import { expect } from 'chai'; import { ethers } from 'hardhat'; import { Core, FeiDAOTimelock } from '@custom-types/contracts'; diff --git a/test/unit/dao/OptimisticTimelock.test.ts b/test/unit/dao/timelocks/OptimisticTimelock.test.ts similarity index 96% rename from test/unit/dao/OptimisticTimelock.test.ts rename to test/unit/dao/timelocks/OptimisticTimelock.test.ts index 729b073a9..294a93844 100644 --- a/test/unit/dao/OptimisticTimelock.test.ts +++ b/test/unit/dao/timelocks/OptimisticTimelock.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, getAddresses, getCore } from '../../helpers'; +import { expectRevert, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/token/Fei.test.ts b/test/unit/fei/Fei.test.ts similarity index 100% rename from test/unit/token/Fei.test.ts rename to test/unit/fei/Fei.test.ts diff --git a/test/unit/token/FeiTimedMinter.test.ts b/test/unit/fei/minter/FeiTimedMinter.test.ts similarity index 99% rename from test/unit/token/FeiTimedMinter.test.ts rename to test/unit/fei/minter/FeiTimedMinter.test.ts index cc74cc4b3..dab7b43cc 100644 --- a/test/unit/token/FeiTimedMinter.test.ts +++ b/test/unit/fei/minter/FeiTimedMinter.test.ts @@ -1,4 +1,4 @@ -import { ZERO_ADDRESS, expectRevert, time, getAddresses, getCore, expectApprox } from '../../helpers'; +import { ZERO_ADDRESS, expectRevert, time, getAddresses, getCore, expectApprox } from '@test/helpers'; import chai, { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/token/PCVEquityMinter.test.ts b/test/unit/fei/minter/PCVEquityMinter.test.ts similarity index 99% rename from test/unit/token/PCVEquityMinter.test.ts rename to test/unit/fei/minter/PCVEquityMinter.test.ts index ac854ffa5..72ba2dec1 100644 --- a/test/unit/token/PCVEquityMinter.test.ts +++ b/test/unit/fei/minter/PCVEquityMinter.test.ts @@ -1,4 +1,4 @@ -import { ZERO_ADDRESS, expectRevert, time, getAddresses, getCore, expectApprox } from '../../helpers'; +import { ZERO_ADDRESS, expectRevert, time, getAddresses, getCore, expectApprox } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/utils/RateLimitedMinter.test.ts b/test/unit/fei/minter/RateLimitedMinter.test.ts similarity index 99% rename from test/unit/utils/RateLimitedMinter.test.ts rename to test/unit/fei/minter/RateLimitedMinter.test.ts index 9a47ef6bd..8b5888239 100644 --- a/test/unit/utils/RateLimitedMinter.test.ts +++ b/test/unit/fei/minter/RateLimitedMinter.test.ts @@ -1,4 +1,4 @@ -import { time, expectRevert, expectApprox, getAddresses, getCore } from '../../helpers'; +import { time, expectRevert, expectApprox, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/staking/feirari/AutoRewardsDistributor.test.ts b/test/unit/fuse/AutoRewardsDistributor.test.ts similarity index 96% rename from test/unit/staking/feirari/AutoRewardsDistributor.test.ts rename to test/unit/fuse/AutoRewardsDistributor.test.ts index 342920eaf..cc5e3e0ec 100644 --- a/test/unit/staking/feirari/AutoRewardsDistributor.test.ts +++ b/test/unit/fuse/AutoRewardsDistributor.test.ts @@ -1,12 +1,12 @@ -import { expectRevert, getAddresses, getCore } from '../../../helpers'; +import { expectRevert, getAddresses, getCore } from '../../helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer, BigNumber } from 'ethers'; -import { AutoRewardsDistributor } from '../../../../types/contracts/AutoRewardsDistributor'; -import { MockRewardsDistributor } from '../../../../types/contracts/MockRewardsDistributor'; -import { MockTribalChief } from '../../../../types/contracts/MockTribalChief'; -import { Core } from '../../../../types/contracts/Core'; -import { Tribe } from '../../../../types/contracts/Tribe'; +import { AutoRewardsDistributor } from '../../../types/contracts/AutoRewardsDistributor'; +import { MockRewardsDistributor } from '../../../types/contracts/MockRewardsDistributor'; +import { MockTribalChief } from '../../../types/contracts/MockTribalChief'; +import { Core } from '../../../types/contracts/Core'; +import { Tribe } from '../../../types/contracts/Tribe'; const toBN = ethers.BigNumber.from; diff --git a/test/unit/staking/feirari/RewardsDistributorAdmin.test.ts b/test/unit/fuse/RewardsDistributorAdmin.test.ts similarity index 100% rename from test/unit/staking/feirari/RewardsDistributorAdmin.test.ts rename to test/unit/fuse/RewardsDistributorAdmin.test.ts diff --git a/test/unit/oracle/CollateralizationOracle.test.ts b/test/unit/oracle/collateralization/CollateralizationOracle.test.ts similarity index 99% rename from test/unit/oracle/CollateralizationOracle.test.ts rename to test/unit/oracle/collateralization/CollateralizationOracle.test.ts index fcbe5eaad..1c97ee7dc 100644 --- a/test/unit/oracle/CollateralizationOracle.test.ts +++ b/test/unit/oracle/collateralization/CollateralizationOracle.test.ts @@ -1,4 +1,4 @@ -import { ZERO_ADDRESS, getCore, getAddresses, expectRevert, expectUnspecifiedRevert } from '../../helpers'; +import { ZERO_ADDRESS, getCore, getAddresses, expectRevert, expectUnspecifiedRevert } from '../../../helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/oracle/CollateralizationOracleGuardian.test.ts b/test/unit/oracle/collateralization/CollateralizationOracleGuardian.test.ts similarity index 99% rename from test/unit/oracle/CollateralizationOracleGuardian.test.ts rename to test/unit/oracle/collateralization/CollateralizationOracleGuardian.test.ts index 859016f08..ddc49e56e 100644 --- a/test/unit/oracle/CollateralizationOracleGuardian.test.ts +++ b/test/unit/oracle/collateralization/CollateralizationOracleGuardian.test.ts @@ -1,4 +1,4 @@ -import { getCore, getAddresses, expectRevert, increaseTime, getImpersonatedSigner } from '../../helpers'; +import { getCore, getAddresses, expectRevert, increaseTime, getImpersonatedSigner } from '../../../helpers'; import { expect } from 'chai'; import { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/oracle/CollateralizationOracleWrapper.test.ts b/test/unit/oracle/collateralization/CollateralizationOracleWrapper.test.ts similarity index 99% rename from test/unit/oracle/CollateralizationOracleWrapper.test.ts rename to test/unit/oracle/collateralization/CollateralizationOracleWrapper.test.ts index 95b5cda94..33858f8ee 100644 --- a/test/unit/oracle/CollateralizationOracleWrapper.test.ts +++ b/test/unit/oracle/collateralization/CollateralizationOracleWrapper.test.ts @@ -1,4 +1,4 @@ -import { ZERO_ADDRESS, time, getCore, getAddresses, expectRevert } from '../../helpers'; +import { ZERO_ADDRESS, time, getCore, getAddresses, expectRevert } from '../../../helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/AavePCVDeposit.test.ts b/test/unit/pcv/aave/AavePCVDeposit.test.ts similarity index 98% rename from test/unit/pcv/AavePCVDeposit.test.ts rename to test/unit/pcv/aave/AavePCVDeposit.test.ts index 1fb48a049..afdc9ff2b 100644 --- a/test/unit/pcv/AavePCVDeposit.test.ts +++ b/test/unit/pcv/aave/AavePCVDeposit.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, getAddresses, getCore } from '../../helpers'; +import { expectRevert, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/AngleUniswapPCVDeposit.test.ts b/test/unit/pcv/angle/AngleUniswapPCVDeposit.test.ts similarity index 99% rename from test/unit/pcv/AngleUniswapPCVDeposit.test.ts rename to test/unit/pcv/angle/AngleUniswapPCVDeposit.test.ts index 11478fb77..8fa52c791 100644 --- a/test/unit/pcv/AngleUniswapPCVDeposit.test.ts +++ b/test/unit/pcv/angle/AngleUniswapPCVDeposit.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, expectApprox, getAddresses, getCore, getImpersonatedSigner } from '../../helpers'; +import { expectRevert, expectApprox, getAddresses, getCore, getImpersonatedSigner } from '@test/helpers'; import { expect } from 'chai'; import { ethers } from 'hardhat'; diff --git a/test/unit/pcv/BPTLens.test.ts b/test/unit/pcv/balancer/BPTLens.test.ts similarity index 100% rename from test/unit/pcv/BPTLens.test.ts rename to test/unit/pcv/balancer/BPTLens.test.ts diff --git a/test/unit/pcv/BalancerLBPSwapper.test.ts b/test/unit/pcv/balancer/BalancerLBPSwapper.test.ts similarity index 100% rename from test/unit/pcv/BalancerLBPSwapper.test.ts rename to test/unit/pcv/balancer/BalancerLBPSwapper.test.ts diff --git a/test/unit/pcv/BalancerPCVDepositWeightedPool.test.ts b/test/unit/pcv/balancer/BalancerPCVDepositWeightedPool.test.ts similarity index 100% rename from test/unit/pcv/BalancerPCVDepositWeightedPool.test.ts rename to test/unit/pcv/balancer/BalancerPCVDepositWeightedPool.test.ts diff --git a/test/unit/pcv/ERC20CompoundPCVDeposit.test.ts b/test/unit/pcv/compound/ERC20CompoundPCVDeposit.test.ts similarity index 98% rename from test/unit/pcv/ERC20CompoundPCVDeposit.test.ts rename to test/unit/pcv/compound/ERC20CompoundPCVDeposit.test.ts index 58b67da50..9bf297275 100644 --- a/test/unit/pcv/ERC20CompoundPCVDeposit.test.ts +++ b/test/unit/pcv/compound/ERC20CompoundPCVDeposit.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, getAddresses, getCore } from '../../helpers'; +import { expectRevert, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/EthCompoundPCVDeposit.test.ts b/test/unit/pcv/compound/EthCompoundPCVDeposit.test.ts similarity index 98% rename from test/unit/pcv/EthCompoundPCVDeposit.test.ts rename to test/unit/pcv/compound/EthCompoundPCVDeposit.test.ts index d8924d370..827565d35 100644 --- a/test/unit/pcv/EthCompoundPCVDeposit.test.ts +++ b/test/unit/pcv/compound/EthCompoundPCVDeposit.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, balance, getAddresses, getCore } from '../../helpers'; +import { expectRevert, balance, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/ConvexPCVDeposit.test.ts b/test/unit/pcv/convex/ConvexPCVDeposit.test.ts similarity index 100% rename from test/unit/pcv/ConvexPCVDeposit.test.ts rename to test/unit/pcv/convex/ConvexPCVDeposit.test.ts diff --git a/test/unit/pcv/CurvePCVDepositPlainPool.test.ts b/test/unit/pcv/curve/CurvePCVDepositPlainPool.test.ts similarity index 100% rename from test/unit/pcv/CurvePCVDepositPlainPool.test.ts rename to test/unit/pcv/curve/CurvePCVDepositPlainPool.test.ts diff --git a/test/unit/pcv/EthLidoPCVDeposit.test.ts b/test/unit/pcv/lido/EthLidoPCVDeposit.test.ts similarity index 98% rename from test/unit/pcv/EthLidoPCVDeposit.test.ts rename to test/unit/pcv/lido/EthLidoPCVDeposit.test.ts index 4398f7cc6..d203353ed 100644 --- a/test/unit/pcv/EthLidoPCVDeposit.test.ts +++ b/test/unit/pcv/lido/EthLidoPCVDeposit.test.ts @@ -1,8 +1,8 @@ -import { expectRevert, getAddresses, getCore } from '../../helpers'; +import { expectRevert, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; -import { forceSpecificEth } from '../../integration/setup/utils'; +import { forceSpecificEth } from '@test/integration/setup/utils'; const e18 = '000000000000000000'; diff --git a/test/unit/pcv/ERC20TokemakPCVDeposit.test.ts b/test/unit/pcv/tokemak/ERC20TokemakPCVDeposit.test.ts similarity index 100% rename from test/unit/pcv/ERC20TokemakPCVDeposit.test.ts rename to test/unit/pcv/tokemak/ERC20TokemakPCVDeposit.test.ts diff --git a/test/unit/pcv/EthTokemakPCVDeposit.test.ts b/test/unit/pcv/tokemak/EthTokemakPCVDeposit.test.ts similarity index 100% rename from test/unit/pcv/EthTokemakPCVDeposit.test.ts rename to test/unit/pcv/tokemak/EthTokemakPCVDeposit.test.ts diff --git a/test/unit/pcv/PCVSwapperUniswap.test.ts b/test/unit/pcv/uniswap/PCVSwapperUniswap.test.ts similarity index 99% rename from test/unit/pcv/PCVSwapperUniswap.test.ts rename to test/unit/pcv/uniswap/PCVSwapperUniswap.test.ts index 279a22952..761033d84 100644 --- a/test/unit/pcv/PCVSwapperUniswap.test.ts +++ b/test/unit/pcv/uniswap/PCVSwapperUniswap.test.ts @@ -1,6 +1,6 @@ import hre, { ethers } from 'hardhat'; import { expect } from 'chai'; -import { time, expectRevert, getAddresses, getCore, deployDevelopmentWeth } from '../../helpers'; +import { time, expectRevert, getAddresses, getCore, deployDevelopmentWeth } from '@test/helpers'; import { Signer } from 'ethers'; const e18 = '000000000000000000'; diff --git a/test/unit/pcv/UniswapPCVDeposit.test.ts b/test/unit/pcv/uniswap/UniswapPCVDeposit.test.ts similarity index 99% rename from test/unit/pcv/UniswapPCVDeposit.test.ts rename to test/unit/pcv/uniswap/UniswapPCVDeposit.test.ts index ec9e12845..698b9c1eb 100644 --- a/test/unit/pcv/UniswapPCVDeposit.test.ts +++ b/test/unit/pcv/uniswap/UniswapPCVDeposit.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, expectApprox, getAddresses, getCore } from '../../helpers'; +import { expectRevert, expectApprox, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/ERC20Dripper.test.ts b/test/unit/pcv/utils/ERC20Dripper.test.ts similarity index 99% rename from test/unit/pcv/ERC20Dripper.test.ts rename to test/unit/pcv/utils/ERC20Dripper.test.ts index 5391e08d6..aff7560e0 100644 --- a/test/unit/pcv/ERC20Dripper.test.ts +++ b/test/unit/pcv/utils/ERC20Dripper.test.ts @@ -1,4 +1,4 @@ -import { time, getCore, expectRevert, getAddresses, getImpersonatedSigner } from '../../helpers'; +import { time, getCore, expectRevert, getAddresses, getImpersonatedSigner } from '@test/helpers'; import { expect } from 'chai'; import hre, { artifacts, ethers } from 'hardhat'; diff --git a/test/unit/pcv/ERC20PCVDepositWrapper.test.ts b/test/unit/pcv/utils/ERC20PCVDepositWrapper.test.ts similarity index 97% rename from test/unit/pcv/ERC20PCVDepositWrapper.test.ts rename to test/unit/pcv/utils/ERC20PCVDepositWrapper.test.ts index a4c2894f9..cc83eb310 100644 --- a/test/unit/pcv/ERC20PCVDepositWrapper.test.ts +++ b/test/unit/pcv/utils/ERC20PCVDepositWrapper.test.ts @@ -1,4 +1,4 @@ -import { getAddresses } from '../../helpers'; +import { getAddresses } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/ERC20Splitter.test.ts b/test/unit/pcv/utils/ERC20Splitter.test.ts similarity index 97% rename from test/unit/pcv/ERC20Splitter.test.ts rename to test/unit/pcv/utils/ERC20Splitter.test.ts index 741528950..3948339cb 100644 --- a/test/unit/pcv/ERC20Splitter.test.ts +++ b/test/unit/pcv/utils/ERC20Splitter.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, getAddresses, getCore } from '../../helpers'; +import { expectRevert, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/FeiSkimmer.test.ts b/test/unit/pcv/utils/FeiSkimmer.test.ts similarity index 100% rename from test/unit/pcv/FeiSkimmer.test.ts rename to test/unit/pcv/utils/FeiSkimmer.test.ts diff --git a/test/unit/pcv/NamedStaticPCVDepositWrapper.test.ts b/test/unit/pcv/utils/NamedStaticPCVDepositWrapper.test.ts similarity index 100% rename from test/unit/pcv/NamedStaticPCVDepositWrapper.test.ts rename to test/unit/pcv/utils/NamedStaticPCVDepositWrapper.test.ts diff --git a/test/unit/pcv/PCVDepositWrapper.test.ts b/test/unit/pcv/utils/PCVDepositWrapper.test.ts similarity index 98% rename from test/unit/pcv/PCVDepositWrapper.test.ts rename to test/unit/pcv/utils/PCVDepositWrapper.test.ts index 8f923c29e..29667796c 100644 --- a/test/unit/pcv/PCVDepositWrapper.test.ts +++ b/test/unit/pcv/utils/PCVDepositWrapper.test.ts @@ -1,4 +1,4 @@ -import { getCore, getAddresses } from '../../helpers'; +import { getCore, getAddresses } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/PCVDripController.test.ts b/test/unit/pcv/utils/PCVDripController.test.ts similarity index 99% rename from test/unit/pcv/PCVDripController.test.ts rename to test/unit/pcv/utils/PCVDripController.test.ts index 36d353030..16354cf2f 100644 --- a/test/unit/pcv/PCVDripController.test.ts +++ b/test/unit/pcv/utils/PCVDripController.test.ts @@ -1,4 +1,4 @@ -import { expectRevert, time, balance, getAddresses, getCore } from '../../helpers'; +import { expectRevert, time, balance, getAddresses, getCore } from '@test/helpers'; import { expect } from 'chai'; import hre, { ethers } from 'hardhat'; import { Signer } from 'ethers'; diff --git a/test/unit/pcv/RatioPCVControllerV2.test.ts b/test/unit/pcv/utils/RatioPCVControllerV2.test.ts similarity index 99% rename from test/unit/pcv/RatioPCVControllerV2.test.ts rename to test/unit/pcv/utils/RatioPCVControllerV2.test.ts index 1d723319f..25d4a3160 100644 --- a/test/unit/pcv/RatioPCVControllerV2.test.ts +++ b/test/unit/pcv/utils/RatioPCVControllerV2.test.ts @@ -5,7 +5,7 @@ import { getCore, getImpersonatedSigner, deployDevelopmentWeth -} from '../../helpers'; +} from '@test/helpers'; import { forceEth } from '@test/integration/setup/utils'; import { expect } from 'chai'; import { ethers } from 'hardhat'; diff --git a/test/unit/stabilizer/EthPegStabilityModule.test.ts b/test/unit/peg/MintRedeemPausePSM.test.ts similarity index 100% rename from test/unit/stabilizer/EthPegStabilityModule.test.ts rename to test/unit/peg/MintRedeemPausePSM.test.ts diff --git a/test/unit/stabilizer/PSMRouter.test.ts b/test/unit/peg/PSMRouter.test.ts similarity index 100% rename from test/unit/stabilizer/PSMRouter.test.ts rename to test/unit/peg/PSMRouter.test.ts diff --git a/test/unit/stabilizer/PegStabilityModule.test.ts b/test/unit/peg/PegStabilityModule.test.ts similarity index 100% rename from test/unit/stabilizer/PegStabilityModule.test.ts rename to test/unit/peg/PegStabilityModule.test.ts diff --git a/test/unit/stabilizer/PriceBoundPegStabilityModule.test.ts b/test/unit/peg/PriceBoundPegStabilityModule.test.ts similarity index 100% rename from test/unit/stabilizer/PriceBoundPegStabilityModule.test.ts rename to test/unit/peg/PriceBoundPegStabilityModule.test.ts diff --git a/test/unit/stabilizer/ReserveStabilizer.test.ts b/test/unit/peg/ReserveStabilizer.test.ts similarity index 100% rename from test/unit/stabilizer/ReserveStabilizer.test.ts rename to test/unit/peg/ReserveStabilizer.test.ts diff --git a/test/unit/dao/QuadraticTimelock.test.ts b/test/unit/timelocks/QuadraticTimelock.test.ts similarity index 100% rename from test/unit/dao/QuadraticTimelock.test.ts rename to test/unit/timelocks/QuadraticTimelock.test.ts diff --git a/test/unit/dao/TimelockedDelegator.test.ts b/test/unit/timelocks/TimelockedDelegator.test.ts similarity index 100% rename from test/unit/dao/TimelockedDelegator.test.ts rename to test/unit/timelocks/TimelockedDelegator.test.ts diff --git a/test/unit/dao/TribeMinter.test.ts b/test/unit/tribe/TribeMinter.test.ts similarity index 97% rename from test/unit/dao/TribeMinter.test.ts rename to test/unit/tribe/TribeMinter.test.ts index 99f0494f6..759f34fa2 100644 --- a/test/unit/dao/TribeMinter.test.ts +++ b/test/unit/tribe/TribeMinter.test.ts @@ -107,9 +107,6 @@ describe('TribeMinter', function () { expect(await tribeMinter.isPokeNeeded()).to.be.true; const tx = await tribeMinter.poke(); - // Check the events, particularly that the buffer is used by the increase - expect(tx).to.emit(tribeMinter, 'BufferUsed').withArgs(inflationIncrement, bufferCapBefore); - // To get rate limit per second divide by 365.25 days in seconds expect(tx) .to.emit(tribeMinter, 'RateLimitPerSecondUpdate') @@ -136,9 +133,6 @@ describe('TribeMinter', function () { const tx = await tribeMinter.poke(); - // Check the events, particularly that no buffer is used - expect(tx).to.not.emit(tribeMinter, 'BufferUsed'); - // To get rate limit per second divide by 365.25 days in seconds expect(tx) .to.emit(tribeMinter, 'RateLimitPerSecondUpdate') diff --git a/test/unit/stabilizer/TribeReserveStabilizer.test.ts b/test/unit/tribe/TribeReserveStabilizer.test.ts similarity index 100% rename from test/unit/stabilizer/TribeReserveStabilizer.test.ts rename to test/unit/tribe/TribeReserveStabilizer.test.ts From d35e6e17101f19e8759a70cd048624cc884c2491 Mon Sep 17 00:00:00 2001 From: Joey Santoro Date: Fri, 14 Jan 2022 17:11:06 -0800 Subject: [PATCH 4/5] unskip --- test/integration/tests/buybacks.ts | 68 --------- test/integration/tests/fei.ts | 16 +- test/integration/tests/merger.ts | 54 ------- test/integration/tests/staking.ts | 226 ----------------------------- 4 files changed, 7 insertions(+), 357 deletions(-) diff --git a/test/integration/tests/buybacks.ts b/test/integration/tests/buybacks.ts index f80db7295..2015744d4 100644 --- a/test/integration/tests/buybacks.ts +++ b/test/integration/tests/buybacks.ts @@ -97,74 +97,6 @@ describe('e2e-buybacks', function () { }); }); - // Skipped because the LUSD auction is now over - describe.skip('LUSD LBP', async function () { - it('mints appropriate amount and swaps', async function () { - const feiLusdLBPSwapper: BalancerLBPSwapper = contracts.feiLusdLBPSwapper as BalancerLBPSwapper; - const feiLusdLBP: IWeightedPool = contracts.feiLusdLBP as IWeightedPool; - const balancerVault: IVault = contracts.balancerVault as IVault; - - const LUSD_HOLDING_ADDRESS = '0x66017D22b0f8556afDd19FC67041899Eb65a21bb'; - await forceEth(LUSD_HOLDING_ADDRESS); - const lusdSigner = await getImpersonatedSigner(LUSD_HOLDING_ADDRESS); - - await contracts.lusd.connect(lusdSigner).approve(balancerVault.address, ethers.constants.MaxUint256); - - await balancerVault.connect(lusdSigner).swap( - { - poolId: await feiLusdLBP.getPoolId(), - kind: 0, // given in - assetIn: contracts.lusd.address, - assetOut: contracts.fei.address, - amount: ethers.constants.WeiPerEther.mul(300_000), - userData: '0x' - }, - { - sender: LUSD_HOLDING_ADDRESS, - fromInternalBalance: false, - recipient: LUSD_HOLDING_ADDRESS, - toInternalBalance: false - }, - ethers.constants.WeiPerEther.mul(200_000), - ethers.constants.WeiPerEther // huge deadline - ); - await increaseTime(24 * 3600); - - // get pool info - const poolId = await feiLusdLBP.getPoolId(); - const poolTokens = await contracts.balancerVault.getPoolTokens(poolId); - // there should be 1.01M LUSD in the pool - expect(poolTokens.tokens[0]).to.be.equal(contracts.lusd.address); - expect(poolTokens.balances[0]).to.be.equal('1310101010101010101010101'); - - await balancerVault.connect(lusdSigner).swap( - { - poolId: poolId, - kind: 0, // given in - assetIn: contracts.lusd.address, - assetOut: contracts.fei.address, - amount: ethers.constants.WeiPerEther.mul(300_000), - userData: '0x' - }, - { - sender: LUSD_HOLDING_ADDRESS, - fromInternalBalance: false, - recipient: LUSD_HOLDING_ADDRESS, - toInternalBalance: false - }, - ethers.constants.WeiPerEther.mul(1_000_000), - ethers.constants.WeiPerEther // huge deadline - ); - - await increaseTime(await feiLusdLBPSwapper.remainingTime()); - - await feiLusdLBPSwapper.swap(); - expect( - await contracts.lusd.balanceOf(contracts.liquityFusePoolLusdPCVDeposit.address) - ).to.be.bignumber.greaterThan(ethers.constants.WeiPerEther.mul(600_000)); - }); - }); - describe('Collateralization Oracle', async function () { it('exempting an address removes from PCV stats', async function () { const collateralizationOracle: CollateralizationOracle = diff --git a/test/integration/tests/fei.ts b/test/integration/tests/fei.ts index 0f62d3f60..1beb775b3 100644 --- a/test/integration/tests/fei.ts +++ b/test/integration/tests/fei.ts @@ -3,7 +3,7 @@ import CBN from 'chai-bn'; import { solidity } from 'ethereum-waffle'; import { ethers } from 'hardhat'; import { NamedContracts } from '@custom-types/types'; -import { resetFork, ZERO_ADDRESS } from '@test/helpers'; +import { expectRevert, resetFork, ZERO_ADDRESS } from '@test/helpers'; import proposals from '@test/integration/proposals_config'; import { TestEndtoEndCoordinator } from '@test/integration/setup'; import { Fei } from '@custom-types/contracts'; @@ -49,7 +49,7 @@ describe('e2e-fei', function () { }); describe('Fei Functionality', async function () { - it.skip('setIncentiveContract', async function () { + it('setIncentiveContract', async function () { expect(await contracts.core.isGovernor(deployAddress)).to.be.true; expect(fei.connect(deploySigner).setIncentiveContract(ZERO_ADDRESS, ZERO_ADDRESS)).to.be.revertedWith( 'CoreRef: Caller is not a governor' @@ -58,14 +58,14 @@ describe('e2e-fei', function () { /* Tests disabled until restrictedPermissions is deployed. */ - it.skip('burnFrom', async function () { + it('burnFrom', async function () { expect(await contracts.core.isBurner(deployAddress)).to.be.true; expect(fei.connect(deploySigner).burnFrom(ZERO_ADDRESS, 10)).to.be.revertedWith( 'RestrictedPermissions: Burner deprecated for contract' ); }); - it.skip('burnFrom', async function () { + it('burnFrom', async function () { const balanceBefore = await fei.balanceOf(deployAddress); await fei.connect(deploySigner).burn(10); const balanceAfter = await fei.balanceOf(deployAddress); @@ -73,7 +73,7 @@ describe('e2e-fei', function () { expect(balanceBefore.sub(balanceAfter)).to.be.bignumber.equal(toBN(10)); }); - it.skip('mint', async function () { + it('mint', async function () { expect(await contracts.core.isMinter(deployAddress)).to.be.true; await fei.connect(deploySigner).mint(contracts.core.address, 10); @@ -82,12 +82,10 @@ describe('e2e-fei', function () { }); /* Test disabled until restrictedPermissions is deployed. */ - describe.skip('CoreRef Functionality', async function () { + describe('CoreRef Functionality', async function () { it('setCore', async function () { expect(await contracts.core.isGovernor(deployAddress)).to.be.true; - expect(await fei.connect(deploySigner).setCore(ZERO_ADDRESS)).to.be.revertedWith( - 'CoreRef: Caller is not a governor' - ); + await expectRevert(fei.connect(deploySigner).setCore(ZERO_ADDRESS), 'CoreRef: Caller is not a governor'); }); it('pause/unpause', async function () { diff --git a/test/integration/tests/merger.ts b/test/integration/tests/merger.ts index 25aaa676e..315af0531 100644 --- a/test/integration/tests/merger.ts +++ b/test/integration/tests/merger.ts @@ -48,60 +48,6 @@ describe('e2e-merger', function () { doLogging && console.log(`Environment loaded.`); }); - describe.skip('TribeRagequit', async function () { - const guardianBalance = '18903018000000000000000000'; - - it('ngmi', async function () { - const tribeRagequit: TRIBERagequit = contracts.tribeRagequit as TRIBERagequit; - const { fei, tribe } = contracts; - - // Construct merkle tree and leaf for guardian - const tree = createTree(); - const guardian = contractAddresses.multisig; - const leaf = solidityKeccak256(['address', 'uint256'], [guardian, guardianBalance]); - - // Construct proof for guardian - const proof = tree.getProof(leaf); - const proofArray = []; - proof.map(function (key, index) { - proofArray.push(key.data); - }); - - const signer = await getImpersonatedSigner(guardian); - - const startTime = await tribeRagequit.rageQuitStart(); - - // Advance to vote start - if (toBN(await time.latest()).lt(toBN(startTime))) { - doLogging && console.log(`Advancing To: ${startTime}`); - await time.increaseTo(startTime); - } else { - doLogging && console.log('Ragequit live'); - } - - // Ragequit 1 TRIBE - const feiBalanceBefore = await fei.balanceOf(guardian); - const tribeBalanceBefore = await tribe.balanceOf(guardian); - await tribe.connect(signer).approve(tribeRagequit.address, ethers.constants.MaxUint256); - - await tribeRagequit.connect(signer).ngmi(ethers.constants.WeiPerEther, guardianBalance, proofArray); - const feiBalanceAfter = await fei.balanceOf(guardian); - const tribeBalanceAfter = await tribe.balanceOf(guardian); - - expect(tribeBalanceBefore.sub(tribeBalanceAfter)).to.be.equal(ethers.constants.WeiPerEther); - expect(feiBalanceAfter.sub(feiBalanceBefore)).to.be.bignumber.equal(toBN('1078903938000000000')); - - // Ragequit original TRIBE fails - expect(tribeRagequit.connect(signer).ngmi(guardianBalance, guardianBalance, proofArray)).to.be.revertedWith( - 'exceeds ragequit limit' - ); - - // Ragequit all held TRIBE succeeds - await tribeRagequit.connect(signer).ngmi(await tribe.balanceOf(guardian), guardianBalance, proofArray); - expect(await tribe.balanceOf(guardian)).to.be.bignumber.equal(toBN(0)); - }); - }); - describe('PegExchanger', async () => { const RGT_WHALE = '0x20017a30D3156D4005bDA08C40Acda0A6aE209B1'; diff --git a/test/integration/tests/staking.ts b/test/integration/tests/staking.ts index 27d5722b4..9bb7240fd 100644 --- a/test/integration/tests/staking.ts +++ b/test/integration/tests/staking.ts @@ -170,232 +170,6 @@ describe('e2e-staking', function () { } } } - - /// skip this test as FEI/TRIBE LM rewards have been disabled - describe.skip('FeiTribe LP Token Staking', async () => { - const feiTribeLPTokenOwner = '0x7D809969f6A04777F0A87FF94B57E56078E5fE0F'; - const feiTribeLPTokenOwnerNumberFour = '0xEc0AB4ED27f6dEF15165Fede40EebdcB955B710D'; - const feiTribeLPTokenOwnerNumberFive = '0x2464E8F7809c05FCd77C54292c69187Cb66FE294'; - const totalStaked = '100000000000000000000'; - - let uniFeiTribe: Contract; - let tribalChief: Contract; - let tribePerBlock: BigNumber; - let tribe: Contract; - - before(async function () { - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [feiTribeLPTokenOwner] - }); - - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [feiTribeLPTokenOwnerNumberFour] - }); - - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [feiTribeLPTokenOwnerNumberFive] - }); - - uniFeiTribe = contracts.feiTribePair; - tribalChief = contracts.tribalChief; - tribePerBlock = await tribalChief.tribePerBlock(); - tribe = contracts.tribe; - await forceEth(feiTribeLPTokenOwner); - }); - - it('find uni fei/tribe LP balances', async function () { - expect(await uniFeiTribe.balanceOf(feiTribeLPTokenOwner)).to.be.gt(toBN(0)); - expect(await uniFeiTribe.balanceOf(feiTribeLPTokenOwnerNumberFour)).to.be.gt(toBN(0)); - expect(await uniFeiTribe.balanceOf(feiTribeLPTokenOwnerNumberFive)).to.be.gt(toBN(0)); - }); - - it('stakes uniswap fei/tribe LP tokens', async function () { - const pid = 0; - - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [feiTribeLPTokenOwner] - }); - - const feiTribeLPTokenOwnerSigner = await ethers.getSigner(feiTribeLPTokenOwner); - - await uniFeiTribe.connect(feiTribeLPTokenOwnerSigner).approve(tribalChief.address, totalStaked); - await tribalChief.connect(feiTribeLPTokenOwnerSigner).deposit(pid, totalStaked, 0); - - const advanceBlockAmount = 3; - for (let i = 0; i < advanceBlockAmount; i++) { - await time.advanceBlock(); - } - - const balanceOfPool = await uniFeiTribe.balanceOf(tribalChief.address); - const perBlockReward = tribePerBlock - .div(await tribalChief.numPools()) - .mul(toBN(totalStaked)) - .div(balanceOfPool); - - expectApprox( - await tribalChief.pendingRewards(pid, feiTribeLPTokenOwner), - Number(perBlockReward.toString()) * advanceBlockAmount - ); - - await tribalChief.connect(feiTribeLPTokenOwnerSigner).harvest(pid, feiTribeLPTokenOwner); - - // add on one to the advance block amount as we have - // advanced one more block when calling the harvest function - expectApprox( - await tribe.balanceOf(feiTribeLPTokenOwner), - Number(perBlockReward.toString()) * (advanceBlockAmount + 1) - ); - // now withdraw from deposit to clear the setup for the next test - await unstakeAndHarvestAllPositions([feiTribeLPTokenOwner], pid, tribalChief, uniFeiTribe); - - await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [feiTribeLPTokenOwner] - }); - }); - - it('multiple users stake uniswap fei/tribe LP tokens', async function () { - const userAddresses = [feiTribeLPTokenOwner, feiTribeLPTokenOwnerNumberFour]; - const pid = 0; - - const balanceOfPool: BigNumber = await uniFeiTribe.balanceOf(tribalChief.address); - const staked = ethers.BigNumber.from(totalStaked); - const userPerBlockReward = tribePerBlock - .div(await tribalChief.numPools()) - .mul(staked) - .div(balanceOfPool.add(staked.mul(toBN(userAddresses.length)))); - - await testMultipleUsersPooling( - tribalChief, - uniFeiTribe, - userAddresses, - userPerBlockReward, - 1, - 0, - totalStaked, - pid - ); - - for (let i = 0; i < userAddresses.length; i++) { - const pendingTribe = await tribalChief.pendingRewards(pid, userAddresses[i]); - - // assert that getTotalStakedInPool returns proper amount - const expectedTotalStaked = toBN(totalStaked); - const poolStakedAmount = await tribalChief.getTotalStakedInPool(pid, userAddresses[i]); - expect(expectedTotalStaked).to.be.equal(poolStakedAmount); - const startingUniLPTokenBalance = await uniFeiTribe.balanceOf(userAddresses[i]); - const startingTribeBalance = await tribe.balanceOf(userAddresses[i]); - - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [userAddresses[i]] - }); - - const userSigner = await ethers.getSigner(userAddresses[i]); - - await tribalChief.connect(userSigner).withdrawAllAndHarvest(pid, userAddresses[i]); - - await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [userAddresses[i]] - }); - - expect(await uniFeiTribe.balanceOf(userAddresses[i])).to.be.equal( - toBN(totalStaked).add(startingUniLPTokenBalance) - ); - - expect(await tribe.balanceOf(userAddresses[i])).to.be.gt(pendingTribe.add(startingTribeBalance)); - } - // withdraw from deposit to clear the setup for the next test - await unstakeAndHarvestAllPositions(userAddresses, pid, tribalChief, uniFeiTribe); - }); - - it('multiple users stake uniswap fei/tribe LP tokens, one user calls emergency withdraw and loses all reward debt', async function () { - const userAddresses = [feiTribeLPTokenOwner, feiTribeLPTokenOwnerNumberFour, feiTribeLPTokenOwnerNumberFive]; - const pid = 0; - - const balanceOfPool = await uniFeiTribe.balanceOf(tribalChief.address); - const staked = toBN(totalStaked); - const userPerBlockReward = tribePerBlock - .div(await tribalChief.numPools()) - .mul(staked) - .div(balanceOfPool.add(staked.mul(toBN(userAddresses.length)))); - - await testMultipleUsersPooling( - tribalChief, - uniFeiTribe, - userAddresses, - userPerBlockReward, - 1, - 0, - totalStaked, - pid - ); - - const startingUniLPTokenBalance = await uniFeiTribe.balanceOf(feiTribeLPTokenOwnerNumberFive); - const { virtualAmount } = await tribalChief.userInfo(pid, feiTribeLPTokenOwnerNumberFive); - - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [feiTribeLPTokenOwnerNumberFive] - }); - - const feiTribeLPTokenOwnerNumberFiveSigner = await ethers.getSigner(feiTribeLPTokenOwnerNumberFive); - - await tribalChief - .connect(feiTribeLPTokenOwnerNumberFiveSigner) - .emergencyWithdraw(pid, feiTribeLPTokenOwnerNumberFive); - - await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [feiTribeLPTokenOwnerNumberFive] - }); - - const endingUniLPTokenBalance = await uniFeiTribe.balanceOf(feiTribeLPTokenOwnerNumberFive); - expect(startingUniLPTokenBalance.add(virtualAmount)).to.be.equal(endingUniLPTokenBalance); - const { rewardDebt } = await tribalChief.userInfo(pid, feiTribeLPTokenOwnerNumberFive); - expect(rewardDebt).to.be.equal(toBN(0)); - - // remove user 5 from userAddresses array - userAddresses.pop(); - for (let i = 0; i < userAddresses.length; i++) { - const pendingTribe = await tribalChief.pendingRewards(pid, userAddresses[i]); - - // assert that getTotalStakedInPool returns proper amount - const expectedTotalStaked = toBN(totalStaked); - const poolStakedAmount = await tribalChief.getTotalStakedInPool(pid, userAddresses[i]); - expect(expectedTotalStaked).to.be.equal(poolStakedAmount); - const startingUniLPTokenBalance = await uniFeiTribe.balanceOf(userAddresses[i]); - const startingTribeBalance = await tribe.balanceOf(userAddresses[i]); - - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [userAddresses[i]] - }); - - const userSigner = await ethers.getSigner(userAddresses[i]); - - await tribalChief.connect(userSigner).withdrawAllAndHarvest(pid, userAddresses[i]); - - await hre.network.provider.request({ - method: 'hardhat_stopImpersonatingAccount', - params: [userAddresses[i]] - }); - - expect(await uniFeiTribe.balanceOf(userAddresses[i])).to.be.equal( - toBN(totalStaked).add(startingUniLPTokenBalance) - ); - - expect(await tribe.balanceOf(userAddresses[i])).to.be.gt(pendingTribe.add(startingTribeBalance)); - } - // withdraw from deposit to clear the setup for the next test - await unstakeAndHarvestAllPositions(userAddresses, pid, tribalChief, uniFeiTribe); - }); - }); }); describe('FeiRari Tribe Staking Rewards', async () => { From e10b4a3ef009550e91a42221e0e91bbbaea8d8ae Mon Sep 17 00:00:00 2001 From: Joey Santoro Date: Fri, 14 Jan 2022 17:29:12 -0800 Subject: [PATCH 5/5] delet --- contracts/pcv/uniswap/PCVSwapperUniswap.sol | 248 ----------- .../pcv/uniswap/PCVSwapperUniswap.test.ts | 415 ------------------ 2 files changed, 663 deletions(-) delete mode 100644 contracts/pcv/uniswap/PCVSwapperUniswap.sol delete mode 100644 test/unit/pcv/uniswap/PCVSwapperUniswap.test.ts diff --git a/contracts/pcv/uniswap/PCVSwapperUniswap.sol b/contracts/pcv/uniswap/PCVSwapperUniswap.sol deleted file mode 100644 index c0b1f2480..000000000 --- a/contracts/pcv/uniswap/PCVSwapperUniswap.sol +++ /dev/null @@ -1,248 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -pragma solidity ^0.8.4; - -import "../IPCVSwapper.sol"; -import "../../Constants.sol"; -import "../utils/WethPCVDeposit.sol"; -import "../../utils/Incentivized.sol"; -import "../../fei/minter/RateLimitedMinter.sol"; -import "../../refs/OracleRef.sol"; -import "../../utils/Timed.sol"; -import "../../external/uniswap/UniswapV2Library.sol"; -import "@openzeppelin/contracts/utils/math/Math.sol"; -import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; -import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol"; - -/// @title implementation for PCV Swapper that swaps ERC20 tokens on Uniswap -/// @author eswak -contract PCVSwapperUniswap is IPCVSwapper, WethPCVDeposit, OracleRef, Timed, Incentivized, RateLimitedMinter { - using SafeERC20 for IERC20; - using Decimal for Decimal.D256; - - // ----------- Events ----------- - event UpdateMaximumSlippage(uint256 oldMaxSlippage, uint256 newMaximumSlippage); - event UpdateMaxSpentPerSwap(uint256 oldMaxSpentPerSwap, uint256 newMaxSpentPerSwap); - - /// @notice the token to spend on swap (outbound) - address public immutable override tokenSpent; - /// @notice the token to receive on swap (inbound) - address public immutable override tokenReceived; - /// @notice the address that will receive the inbound tokens - address public override tokenReceivingAddress; - /// @notice the maximum amount of tokens to spend on every swap - uint256 public maxSpentPerSwap; - /// @notice the maximum amount of slippage vs oracle price - uint256 public maximumSlippageBasisPoints; - - /// @notice Uniswap pair to swap on - IUniswapV2Pair public immutable pair; - - struct OracleData { - address _core; - address _oracle; - address _backupOracle; - // invert should be false if the oracle is reported in tokenSpent terms otherwise true - bool _invertOraclePrice; - // The decimalsNormalizer should be calculated as tokenSpent.decimals() - tokenReceived.decimals() if invert is false, otherwise reverse order - int256 _decimalsNormalizer; - } - - struct PCVSwapperData { - address _tokenSpent; - address _tokenReceived; - address _tokenReceivingAddress; - uint256 _maxSpentPerSwap; - uint256 _maximumSlippageBasisPoints; - IUniswapV2Pair _pair; - } - - struct MinterData { - uint256 _swapFrequency; - uint256 _swapIncentiveAmount; - } - constructor( - OracleData memory oracleData, - PCVSwapperData memory pcvSwapperData, - MinterData memory minterData - ) - OracleRef( - oracleData._core, - oracleData._oracle, - oracleData._backupOracle, - oracleData._decimalsNormalizer, - oracleData._invertOraclePrice - ) - Timed(minterData._swapFrequency) - Incentivized(minterData._swapIncentiveAmount) - RateLimitedMinter(minterData._swapIncentiveAmount / minterData._swapFrequency, minterData._swapIncentiveAmount, false) - { - address _tokenSpent = pcvSwapperData._tokenSpent; - address _tokenReceived = pcvSwapperData._tokenReceived; - address _tokenReceivingAddress = pcvSwapperData._tokenReceivingAddress; - uint256 _maxSpentPerSwap = pcvSwapperData._maxSpentPerSwap; - uint256 _maximumSlippageBasisPoints = pcvSwapperData._maximumSlippageBasisPoints; - IUniswapV2Pair _pair = pcvSwapperData._pair; - - require(_pair.token0() == _tokenSpent || _pair.token1() == _tokenSpent, "PCVSwapperUniswap: token spent not in pair"); - require(_pair.token0() == _tokenReceived || _pair.token1() == _tokenReceived, "PCVSwapperUniswap: token received not in pair"); - pair = _pair; - tokenSpent = _tokenSpent; - tokenReceived = _tokenReceived; - - tokenReceivingAddress = _tokenReceivingAddress; - emit UpdateReceivingAddress(address(0), _tokenReceivingAddress); - - maxSpentPerSwap = _maxSpentPerSwap; - emit UpdateMaxSpentPerSwap(0, _maxSpentPerSwap); - - maximumSlippageBasisPoints = _maximumSlippageBasisPoints; - emit UpdateMaximumSlippage(0, _maximumSlippageBasisPoints); - - // start timer - _initTimed(); - } - - // ======================================================================= - // IPCVDeposit interface override - // ======================================================================= - - /// @notice withdraw tokenReceived from the contract - /// @param to address destination of the ERC20 - /// @param amount quantity of tokenReceived to send - function withdraw(address to, uint256 amount) external override onlyPCVController { - withdrawERC20(tokenReceived, to, amount); - } - - /// @notice Reads the balance of tokenReceived held in the contract - /// @return held balance of token of tokenReceived - function balance() public view override returns(uint256) { - return IERC20(tokenReceived).balanceOf(address(this)); - } - - /// @notice display the related token of the balance reported - function balanceReportedIn() public view override returns (address) { - return address(tokenReceived); - } - - // ======================================================================= - // IPCVSwapper interface override - // ======================================================================= - - /// @notice Sets the address receiving swap's inbound tokens - /// @param newTokenReceivingAddress the address that will receive tokens - function setReceivingAddress(address newTokenReceivingAddress) external override onlyGovernor { - require(newTokenReceivingAddress != address(0), "PCVSwapperUniswap: zero address"); - address oldTokenReceivingAddress = tokenReceivingAddress; - tokenReceivingAddress = newTokenReceivingAddress; - emit UpdateReceivingAddress(oldTokenReceivingAddress, newTokenReceivingAddress); - } - - // ======================================================================= - // Setters - // ======================================================================= - - /// @notice Sets the maximum slippage vs Oracle price accepted during swaps - /// @param newMaximumSlippageBasisPoints the maximum slippage expressed in basis points (1/10_000) - function setMaximumSlippage(uint256 newMaximumSlippageBasisPoints) external onlyGovernorOrAdmin { - uint256 oldMaxSlippage = maximumSlippageBasisPoints; - require(newMaximumSlippageBasisPoints <= Constants.BASIS_POINTS_GRANULARITY, "PCVSwapperUniswap: Exceeds bp granularity."); - maximumSlippageBasisPoints = newMaximumSlippageBasisPoints; - emit UpdateMaximumSlippage(oldMaxSlippage, newMaximumSlippageBasisPoints); - } - - /// @notice Sets the maximum tokens spent on each swap - /// @param newMaxSpentPerSwap the maximum number of tokens to be swapped on each call - function setMaxSpentPerSwap(uint256 newMaxSpentPerSwap) external onlyGovernorOrAdmin { - uint256 oldMaxSpentPerSwap = maxSpentPerSwap; - require(newMaxSpentPerSwap != 0, "PCVSwapperUniswap: Cannot swap 0."); - maxSpentPerSwap = newMaxSpentPerSwap; - emit UpdateMaxSpentPerSwap(oldMaxSpentPerSwap, newMaxSpentPerSwap); - } - - /// @notice sets the minimum time between swaps - /// @param _duration minimum time between swaps in seconds - function setSwapFrequency(uint256 _duration) external onlyGovernorOrAdmin { - _setDuration(_duration); - } - - // ======================================================================= - // External functions - // ======================================================================= - - /// @notice Swap tokenSpent for tokenReceived - function swap() external override afterTime whenNotPaused { - // Reset timer - _initTimed(); - - updateOracle(); - - uint256 amountIn = _getExpectedAmountIn(); - uint256 amountOut = _getExpectedAmountOut(amountIn); - uint256 minimumAcceptableAmountOut = _getMinimumAcceptableAmountOut(amountIn); - - // Check spot price vs oracle price discounted by max slippage - // E.g. for a max slippage of 3%, spot price must be >= 97% oraclePrice - require(minimumAcceptableAmountOut <= amountOut, "PCVSwapperUniswap: slippage too high."); - - // Perform swap - IERC20(tokenSpent).safeTransfer(address(pair), amountIn); - (uint256 amount0Out, uint256 amount1Out) = - pair.token0() == address(tokenSpent) - ? (uint256(0), amountOut) - : (amountOut, uint256(0)); - pair.swap(amount0Out, amount1Out, tokenReceivingAddress, new bytes(0)); - - // Emit event - emit Swap( - msg.sender, - tokenSpent, - tokenReceived, - amountIn, - amountOut - ); - - // Incentivize call with FEI rewards - _incentivize(); - } - - // ======================================================================= - // Internal functions - // ======================================================================= - - function _getExpectedAmountIn() internal view returns (uint256) { - uint256 amount = IERC20(tokenSpent).balanceOf(address(this)); - require(amount != 0, "PCVSwapperUniswap: no tokenSpent left."); - return Math.min(maxSpentPerSwap, amount); - } - - function _getExpectedAmountOut(uint256 amountIn) internal view returns (uint256) { - // Get pair reserves - (uint256 _token0, uint256 _token1, ) = pair.getReserves(); - (uint256 tokenSpentReserves, uint256 tokenReceivedReserves) = - pair.token0() == tokenSpent - ? (_token0, _token1) - : (_token1, _token0); - - // Prepare swap - uint256 amountOut = UniswapV2Library.getAmountOut( - amountIn, - tokenSpentReserves, - tokenReceivedReserves - ); - - return amountOut; - } - - function _getMinimumAcceptableAmountOut(uint256 amountIn) internal view returns (uint256) { - Decimal.D256 memory oraclePrice = readOracle(); - Decimal.D256 memory oracleAmountOut = oraclePrice.mul(amountIn); - Decimal.D256 memory maxSlippage = Decimal.ratio(Constants.BASIS_POINTS_GRANULARITY - maximumSlippageBasisPoints, Constants.BASIS_POINTS_GRANULARITY); - Decimal.D256 memory oraclePriceMinusSlippage = maxSlippage.mul(oracleAmountOut); - return oraclePriceMinusSlippage.asUint256(); - } - - function _mintFei(address to, uint256 amountIn) internal override(CoreRef, RateLimitedMinter) { - RateLimitedMinter._mintFei(to, amountIn); - } -} diff --git a/test/unit/pcv/uniswap/PCVSwapperUniswap.test.ts b/test/unit/pcv/uniswap/PCVSwapperUniswap.test.ts deleted file mode 100644 index 761033d84..000000000 --- a/test/unit/pcv/uniswap/PCVSwapperUniswap.test.ts +++ /dev/null @@ -1,415 +0,0 @@ -import hre, { ethers } from 'hardhat'; -import { expect } from 'chai'; -import { time, expectRevert, getAddresses, getCore, deployDevelopmentWeth } from '@test/helpers'; -import { Signer } from 'ethers'; - -const e18 = '000000000000000000'; - -const toBN = ethers.BigNumber.from; - -describe('PCVSwapperUniswap', function () { - let userAddress: string; - let secondUserAddress: string; - let minterAddress: string; - let guardianAddress: string; - let governorAddress: string; - let pcvControllerAddress: string; - - const impersonatedSigners: { [key: string]: Signer } = {}; - - before(async () => { - const addresses = await getAddresses(); - - // add any addresses you want to impersonate here - const impersonatedAddresses = [ - addresses.userAddress, - addresses.pcvControllerAddress, - addresses.governorAddress, - addresses.pcvControllerAddress, - addresses.minterAddress, - addresses.burnerAddress, - addresses.beneficiaryAddress1, - addresses.beneficiaryAddress2, - addresses.guardianAddress, - addresses.secondUserAddress - ]; - - for (const address of impersonatedAddresses) { - await hre.network.provider.request({ - method: 'hardhat_impersonateAccount', - params: [address] - }); - - impersonatedSigners[address] = await ethers.getSigner(address); - } - }); - - beforeEach(async function () { - ({ userAddress, secondUserAddress, minterAddress, guardianAddress, governorAddress, pcvControllerAddress } = - await getAddresses()); - - await deployDevelopmentWeth(); - - this.core = await getCore(); - this.weth = await ethers.getContractAt('MockWeth', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'); - this.fei = await ethers.getContractAt('Fei', await this.core.fei()); - this.pair = await ( - await ethers.getContractFactory('MockUniswapV2PairLiquidity') - ).deploy(this.fei.address, this.weth.address); - await this.pair.setReserves(`62500000${e18}`, `25000${e18}`); - // await web3.eth.sendTransaction({from: userAddress, to: this.pair.address, value: '25000'+e18}); - await this.fei.connect(impersonatedSigners[minterAddress]).mint(this.pair.address, `62500000${e18}`, {}); - this.oracle = await (await ethers.getContractFactory('MockOracle')).deploy(2500); // 2500:1 oracle price - this.mockChainlinkOracle = await (await ethers.getContractFactory('MockChainlinkOracle')).deploy('500', 0); // 0 decimals, val = 500 - this.chainlinkOracleWrapper = await ( - await ethers.getContractFactory('ChainlinkOracleWrapper') - ).deploy(this.core.address, this.mockChainlinkOracle.address); - - this.swapper = await ( - await ethers.getContractFactory('PCVSwapperUniswap') - ).deploy( - { - _core: this.core.address, - _oracle: this.oracle.address, // oracle - _backupOracle: this.oracle.address, // backup oracle - _invertOraclePrice: false, - _decimalsNormalizer: 0 - }, - { - _tokenSpent: this.weth.address, - _tokenReceived: this.fei.address, - _tokenReceivingAddress: userAddress, - _maxSpentPerSwap: `100${e18}`, - _maximumSlippageBasisPoints: '300', - _pair: this.pair.address - }, - { - _swapFrequency: '1000', - _swapIncentiveAmount: `200${e18}` // swap incentive = 200 FEI - } - ); - - await this.core.connect(impersonatedSigners[governorAddress]).grantPCVController(pcvControllerAddress, {}); - }); - - describe('Payable', function () { - it('should accept ETH transfers', async function () { - const beforeBalance = await ethers.provider.getBalance(this.swapper.address); - // send 23 ETH - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`23${e18}`) - }); - const afterBalance = await ethers.provider.getBalance(this.swapper.address); - - expect(afterBalance.sub(beforeBalance)).to.be.equal(`23${e18}`); - }); - }); - - describe('IPCVDeposit interface override', function () { - describe('Getters', function () { - it('balance()', async function () { - await this.fei.connect(impersonatedSigners[minterAddress]).mint(this.swapper.address, '1000', {}); - expect(await this.swapper.balance()).to.be.equal('1000'); - }); - }); - - describe('Withdraw', function () { - describe('As PCVController', function () { - it('withdraw() emit WithdrawERC20', async function () { - expect(await this.fei.balanceOf(this.swapper.address)).to.be.equal('0'); - expect(await this.fei.balanceOf(userAddress)).to.be.equal('0'); - await this.fei.connect(impersonatedSigners[minterAddress]).mint(this.swapper.address, `1${e18}`, {}); - expect(await this.fei.balanceOf(this.swapper.address)).to.be.equal(`1${e18}`); - await expect( - await this.swapper.connect(impersonatedSigners[pcvControllerAddress]).withdraw(userAddress, `1${e18}`) - ).to.emit(this.swapper, 'WithdrawERC20'); //.withArgs(pcvControllerAddress, userAddress, this.fei.address, `1${e18}`); - expect(await this.fei.balanceOf(this.swapper.address)).to.be.equal('0'); - expect(await this.fei.balanceOf(userAddress)).to.be.equal(`1${e18}`); - }); - }); - - describe('As Anyone', function () { - it('revert withdraw() onlyPCVController', async function () { - await expectRevert(this.swapper.withdraw(userAddress, 1), 'CoreRef: Caller is not a PCV controller'); - }); - }); - }); - - describe('Deposit', function () { - it('Wraps ETH', async function () { - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`100${e18}`) - }); - await this.swapper.deposit(); - expect(await ethers.provider.getBalance(this.swapper.address)).to.be.equal('0'); - expect(await this.weth.balanceOf(this.swapper.address)).to.be.equal(`100${e18}`); - }); - }); - }); - - describe('IPCVSwapper interface override', function () { - describe('Getters', function () { - it('tokenSpent()', async function () { - expect(await this.swapper.tokenSpent()).to.equal(this.weth.address); - }); - it('tokenReceived()', async function () { - expect(await this.swapper.tokenReceived()).to.equal(this.fei.address); - }); - it('tokenReceivingAddress()', async function () { - expect(await this.swapper.tokenReceivingAddress()).to.equal(userAddress); - }); - }); - - describe('Setters', function () { - describe('As Governor', function () { - it('setReceivingAddress() emit UpdateReceivingAddress', async function () { - expect(await this.swapper.tokenReceivingAddress()).to.equal(userAddress); - await expect( - await this.swapper.connect(impersonatedSigners[governorAddress]).setReceivingAddress(secondUserAddress) - ).to.emit(this.swapper, 'UpdateReceivingAddress'); //.withArgs(secondUserAddress) - expect(await this.swapper.tokenReceivingAddress()).to.equal(secondUserAddress); - }); - }); - - describe('As Anyone', function () { - it('revert setReceivingAddress() onlyGovernor', async function () { - await expectRevert(this.swapper.setReceivingAddress(userAddress), 'CoreRef: Caller is not a governor'); - }); - }); - }); - - describe('Withdraw', function () { - describe('As PCVController', function () { - it('withdrawETH() emit WithdrawETH', async function () { - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`10${e18}`) - }); - await this.swapper.wrapETH(); - const balanceBefore = toBN(await ethers.provider.getBalance(secondUserAddress)); - await await expect( - await this.swapper - .connect(impersonatedSigners[pcvControllerAddress]) - .withdrawETH(secondUserAddress, `10${e18}`) - ) - .to.emit(this.swapper, 'WithdrawETH') - .withArgs(pcvControllerAddress, secondUserAddress, `10${e18}`); - expect(await ethers.provider.getBalance(secondUserAddress)).to.be.equal(toBN(`10${e18}`).add(balanceBefore)); - }); - it('withdrawETH() revert if not enough WETH to unwrap', async function () { - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`10${e18}`) - }); - await this.swapper.wrapETH(); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`20${e18}`) - }); - // revert because the swapper has 10 WETH and 20 ETH, can't unwrap 15 WETH - // to solve this situation, swapper.wrapETH() should be called before withdraw. - await expectRevert( - this.swapper.connect(impersonatedSigners[pcvControllerAddress]).withdrawETH(userAddress, `15${e18}`, {}), - 'revert' - ); - }); - it('withdrawERC20() emit WithdrawERC20', async function () { - expect(await this.fei.balanceOf(this.swapper.address)).to.be.equal('0'); - expect(await this.fei.balanceOf(userAddress)).to.be.equal('0'); - await this.fei.connect(impersonatedSigners[minterAddress]).mint(this.swapper.address, `1${e18}`, {}); - expect(await this.fei.balanceOf(this.swapper.address)).to.be.equal(`1${e18}`); - await expect( - await this.swapper - .connect(impersonatedSigners[pcvControllerAddress]) - .withdrawERC20(this.fei.address, userAddress, `1${e18}`, {}) - ).to.emit(this.swapper, 'WithdrawERC20'); //.withArgs(pcvControllerAddress, userAddress, this.fei.address, `1${e18}`); - - expect(await this.fei.balanceOf(this.swapper.address)).to.be.equal('0'); - expect(await this.fei.balanceOf(userAddress)).to.be.equal(`1${e18}`); - }); - }); - describe('As Anyone', function () { - it('revert withdrawETH() onlyPCVController', async function () { - await expectRevert(this.swapper.withdrawETH(userAddress, 1), 'CoreRef: Caller is not a PCV controller'); - }); - it('revert withdrawERC20() onlyPCVController', async function () { - await expectRevert( - this.swapper.withdrawERC20(userAddress, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 1), - 'CoreRef: Caller is not a PCV controller' - ); - }); - }); - }); - describe('Swap', function () { - it('swap() emit Swap', async function () { - await time.increase(1000); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`100${e18}`) - }); - await this.swapper.connect(impersonatedSigners[pcvControllerAddress]).wrapETH({}); - await await expect(await this.swapper.connect(impersonatedSigners[userAddress]).swap()) - .to.emit(this.swapper, 'Swap') - .withArgs(userAddress, this.weth.address, this.fei.address, `100${e18}`, '248259939361825041733566'); - }); - }); - }); - - describe('Setters', function () { - it('setMaximumSlippage() revert if not governor', async function () { - await expectRevert(this.swapper.setMaximumSlippage('500'), 'CoreRef: Caller is not a governor'); - }); - it('setMaximumSlippage() revert on invalid value', async function () { - await expectRevert( - this.swapper.connect(impersonatedSigners[governorAddress]).setMaximumSlippage('10001', {}), - 'PCVSwapperUniswap: Exceeds bp granularity.' - ); - }); - it('setMaximumSlippage() emit UpdateMaximumSlippage', async function () { - expect(await this.swapper.maximumSlippageBasisPoints()).to.be.equal('300'); - await await expect( - await this.swapper.connect(impersonatedSigners[governorAddress]).setMaximumSlippage('500') - ).to.emit(this.swapper, 'UpdateMaximumSlippage'); //.withArgs('500') - - expect(await this.swapper.maximumSlippageBasisPoints()).to.be.equal('500'); - }); - it('setMaxSpentPerSwap() revert if not governor', async function () { - await expectRevert(this.swapper.setMaxSpentPerSwap('0'), 'CoreRef: Caller is not a governor'); - }); - it('setMaxSpentPerSwap() revert on invalid value', async function () { - await expectRevert( - this.swapper.connect(impersonatedSigners[governorAddress]).setMaxSpentPerSwap('0', {}), - 'PCVSwapperUniswap: Cannot swap 0.' - ); - }); - it('setMaxSpentPerSwap() emit UpdateMaxSpentPerSwap', async function () { - expect(await this.swapper.maxSpentPerSwap()).to.be.equal(`100${e18}`); - await await expect( - await this.swapper.connect(impersonatedSigners[governorAddress]).setMaxSpentPerSwap(`50${e18}`) - ).to.emit(this.swapper, 'UpdateMaxSpentPerSwap'); //.withArgs(`50${e18}`); - - expect(await this.swapper.maxSpentPerSwap()).to.be.equal(`50${e18}`); - }); - it('setSwapFrequency() revert if not governor', async function () { - await expectRevert(this.swapper.setSwapFrequency('2000'), 'CoreRef: Caller is not a governor'); - }); - it('setSwapFrequency() emit UpdateSwapFrequency', async function () { - expect(await this.swapper.duration()).to.be.equal('1000'); - await await expect(await this.swapper.connect(impersonatedSigners[governorAddress]).setSwapFrequency('2000')) - .to.emit(this.swapper, 'DurationUpdate') - .withArgs('1000', '2000'); - - expect(await this.swapper.duration()).to.be.equal('2000'); - }); - }); - - describe('ETH wrap/unwrap', function () { - it('wrapETH()', async function () { - expect(await this.weth.balanceOf(this.swapper.address)).to.be.equal(`0${e18}`); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`100${e18}`) - }); - expect(await ethers.provider.getBalance(this.swapper.address)).to.be.equal(`100${e18}`); - await this.swapper.wrapETH(); - expect(await this.weth.balanceOf(this.swapper.address)).to.be.equal(`100${e18}`); - expect(await ethers.provider.getBalance(this.swapper.address)).to.be.equal(`0${e18}`); - }); - }); - - describe('Swap', function () { - it('revert if paused by guardian', async function () { - await time.increase(1000); - await this.swapper.connect(impersonatedSigners[guardianAddress]).pause({}); - await expectRevert(this.swapper.swap(), 'Pausable: paused'); - }); - it('revert if paused by governor', async function () { - await time.increase(1000); - await this.swapper.connect(impersonatedSigners[governorAddress]).pause({}); - await expectRevert(this.swapper.swap(), 'Pausable: paused'); - }); - it('revert if time is not elapsed', async function () { - await expectRevert(this.swapper.swap(), 'Timed: time not ended'); - }); - it('revert if oracle is invalid', async function () { - await this.oracle.setValid(false); - await time.increase(1000); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`100${e18}`) - }); - await this.swapper.connect(impersonatedSigners[pcvControllerAddress]).wrapETH({}); - await expectRevert(this.swapper.swap(), 'OracleRef: oracle invalid'); - }); - it('revert if slippage is too high', async function () { - await time.increase(1000); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`1000${e18}`) - }); - await this.swapper.connect(impersonatedSigners[pcvControllerAddress]).wrapETH({}); - await this.swapper.connect(impersonatedSigners[governorAddress]).setMaxSpentPerSwap(`1000${e18}`, {}); - await expectRevert(this.swapper.swap(), 'PCVSwapperUniswap: slippage too high.'); - }); - it('send tokens to tokenReceivingAddress', async function () { - await time.increase(1000); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`100${e18}`) - }); - await this.swapper.connect(impersonatedSigners[pcvControllerAddress]).wrapETH({}); - await this.swapper.connect(impersonatedSigners[userAddress]).swap({}); - expect(await this.fei.balanceOf(userAddress)).to.be.equal('248259939361825041733566'); - }); - it('swap remaining tokens if balance < maxSpentPerSwap', async function () { - await time.increase(1000); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`50${e18}`) - }); - await this.swapper.connect(impersonatedSigners[pcvControllerAddress]).wrapETH({}); - await this.swapper.connect(impersonatedSigners[userAddress]).swap({}); - expect(await this.fei.balanceOf(userAddress)).to.be.equal('124376992277398866659880'); - }); - - it('no FEI incentive to caller if swapper is not a Minter', async function () { - await time.increase(1000); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`50${e18}`) - }); - await this.swapper.connect(impersonatedSigners[pcvControllerAddress]).wrapETH({}); - expect((await this.fei.balanceOf(secondUserAddress)) / 1e18).to.be.equal(0); - await this.swapper.connect(impersonatedSigners[secondUserAddress]).swap({}); - expect((await this.fei.balanceOf(secondUserAddress)) / 1e18).to.be.equal(0); - }); - - it('send FEI incentive to caller if swapper is Minter', async function () { - await time.increase(1000); - await impersonatedSigners[userAddress].sendTransaction({ - from: userAddress, - to: this.swapper.address, - value: toBN(`50${e18}`) - }); - await this.swapper.connect(impersonatedSigners[pcvControllerAddress]).wrapETH({}); - await this.core.connect(impersonatedSigners[governorAddress]).grantMinter(this.swapper.address, {}); - expect((await this.fei.balanceOf(secondUserAddress)) / 1e18).to.be.equal(0); - await this.swapper.connect(impersonatedSigners[secondUserAddress]).swap({}); - expect((await this.fei.balanceOf(secondUserAddress)) / 1e18).to.be.equal(200); - }); - }); -});