From 53dc34abd7ce2f564ae63c2e163a4c6b8062dd8c Mon Sep 17 00:00:00 2001 From: David Racero Date: Wed, 16 Jun 2021 12:52:00 +0200 Subject: [PATCH] feat: added deploy scripts --- ...> CurveLpReserveInterestRateStratregy.sol} | 14 ++++--- .../curve/CurveGaugeRewardsAwareAToken.sol | 8 ++++ helpers/constants.ts | 16 ++++++++ helpers/contracts-deployments.ts | 31 ++++++++++++-- helpers/types.ts | 1 + tasks/deployments/deploy-CurveTreasury.ts | 40 +++++++++++++++++++ 6 files changed, 101 insertions(+), 9 deletions(-) rename contracts/adapters/interests-strategies/{CurveLpReserveInterestRateStratregy.sol.keep => CurveLpReserveInterestRateStratregy.sol} (93%) create mode 100644 tasks/deployments/deploy-CurveTreasury.ts diff --git a/contracts/adapters/interests-strategies/CurveLpReserveInterestRateStratregy.sol.keep b/contracts/adapters/interests-strategies/CurveLpReserveInterestRateStratregy.sol similarity index 93% rename from contracts/adapters/interests-strategies/CurveLpReserveInterestRateStratregy.sol.keep rename to contracts/adapters/interests-strategies/CurveLpReserveInterestRateStratregy.sol index ac154c12..df6aebb3 100644 --- a/contracts/adapters/interests-strategies/CurveLpReserveInterestRateStratregy.sol.keep +++ b/contracts/adapters/interests-strategies/CurveLpReserveInterestRateStratregy.sol @@ -7,11 +7,12 @@ import {PercentageMath} from '../../protocol/libraries/math/PercentageMath.sol'; import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol'; import {ILendingRateOracle} from '../../interfaces/ILendingRateOracle.sol'; import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol'; -import {ISushiRewardsAwareAToken} from '../interfaces/sushi/ISushiRewardsAwareAToken.sol'; -import {IMasterChef} from '../../adapters/interfaces/sushi/IMasterChef.sol'; import { DefaultReserveInterestRateStrategy } from '../../protocol/lendingpool/DefaultReserveInterestRateStrategy.sol'; +import { + CurveGaugeRewardsAwareAToken +} from '../../adapters/rewards/curve/CurveGaugeRewardsAwareAToken.sol'; /** * @title DefaultReserveInterestRateStrategy contract @@ -22,7 +23,7 @@ import { * of the LendingPoolAddressesProvider * @author Aave **/ -contract CurveLPReserveInterestRateStrategy is DefaultReserveInterestRateStrategy { +contract CurveGaugeReserveInterestRateStrategy is DefaultReserveInterestRateStrategy { using WadRayMath for uint256; using SafeMath for uint256; using PercentageMath for uint256; @@ -78,9 +79,10 @@ contract CurveLPReserveInterestRateStrategy is DefaultReserveInterestRateStrateg uint256 ) { - uint256 poolId = ISushiRewardsAwareAToken(aToken).getMasterChefPoolId(); - (uint256 stakedBalance, ) = - IMasterChef(ISushiRewardsAwareAToken(aToken).getMasterChef()).userInfo(poolId, aToken); + uint256 stakedBalance = + IERC20(CurveGaugeRewardsAwareAToken(aToken).getGaugeController()).balanceOf( + CurveGaugeRewardsAwareAToken(aToken).getCurveTreasury() + ); //avoid stack too deep uint256 availableLiquidity = stakedBalance.add(liquidityAdded).sub(liquidityTaken); diff --git a/contracts/adapters/rewards/curve/CurveGaugeRewardsAwareAToken.sol b/contracts/adapters/rewards/curve/CurveGaugeRewardsAwareAToken.sol index c13ecba1..8c785189 100644 --- a/contracts/adapters/rewards/curve/CurveGaugeRewardsAwareAToken.sol +++ b/contracts/adapters/rewards/curve/CurveGaugeRewardsAwareAToken.sol @@ -251,5 +251,13 @@ contract CurveGaugeRewardsAwareAToken is RewardsAwareAToken { function getCrvToken() external view returns (address) { return CRV_TOKEN; } + + function getCurveTreasury() external view returns (address) { + return CURVE_TREASURY; + } + + function getGaugeController() external view returns (address) { + return _gaugeController; + } /** End of External getters */ } diff --git a/helpers/constants.ts b/helpers/constants.ts index 55e2b704..516b7689 100644 --- a/helpers/constants.ts +++ b/helpers/constants.ts @@ -77,3 +77,19 @@ export const MOCK_CHAINLINK_AGGREGATORS_PRICES = { export const CRV_TOKEN = { [eEthereumNetwork.main]: '0xD533a949740bb3306d119CC777fa900bA034cd52', }; + +export const CURVE_TREASURY = { + [eEthereumNetwork.main]: ZERO_ADDRESS, +}; + +export const CURVE_CONFIG = { + votingEscrow: { + [eEthereumNetwork.main]: ZERO_ADDRESS, + }, + curveFeeDistributor: { + [eEthereumNetwork.main]: ZERO_ADDRESS, + }, + gaugeController: { + [eEthereumNetwork.main]: ZERO_ADDRESS, + }, +}; diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index 37519a38..8dac278f 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -52,6 +52,7 @@ import { RewardsTokenFactory, RewardsATokenMockFactory, CurveGaugeRewardsAwareATokenFactory, + CurveTreasuryFactory, } from '../types'; import { withSaveAndVerify, @@ -69,7 +70,7 @@ import { readArtifact as buidlerReadArtifact } from '@nomiclabs/buidler/plugins' import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { LendingPoolLibraryAddresses } from '../types/LendingPoolFactory'; import { UiPoolDataProvider } from '../types'; -import { CRV_TOKEN } from './constants'; +import { CRV_TOKEN, CURVE_TREASURY } from './constants'; export const deployUiPoolDataProvider = async ( [incentivesController, aaveOracle]: [tEthereumAddress, tEthereumAddress], @@ -721,9 +722,10 @@ export const deployATokenImplementations = async ( export const deployCurveGaugeRewardsAwareAToken = async ( crvToken: tEthereumAddress, + curveTreasury: tEthereumAddress, verify?: boolean ) => { - const args: [tEthereumAddress] = [crvToken]; + const args: [tEthereumAddress, tEthereumAddress] = [crvToken, curveTreasury]; return withSaveAndVerify( await new CurveGaugeRewardsAwareATokenFactory(await getFirstSigner()).deploy(...args), eContractid.CurveGaugeRewardsAwareAToken, @@ -734,5 +736,28 @@ export const deployCurveGaugeRewardsAwareAToken = async ( export const deployCurveGaugeRewardsAwareATokenByNetwork = async (verify?: boolean) => { const network = DRE.network.name as eEthereumNetwork; - return deployCurveGaugeRewardsAwareAToken(CRV_TOKEN[network], verify); + return deployCurveGaugeRewardsAwareAToken(CRV_TOKEN[network], CURVE_TREASURY[network], verify); +}; + +export const deployCurveTreasury = async ( + votingEscrow: tEthereumAddress, + crvToken: tEthereumAddress, + curveFeeDistributor: tEthereumAddress, + gaugeController: tEthereumAddress, + aaveCollector: tEthereumAddress, + verify?: boolean +) => { + const args: [ + tEthereumAddress, + tEthereumAddress, + tEthereumAddress, + tEthereumAddress, + tEthereumAddress + ] = [votingEscrow, crvToken, curveFeeDistributor, gaugeController, aaveCollector]; + return withSaveAndVerify( + await new CurveTreasuryFactory(await getFirstSigner()).deploy(...args), + eContractid.CurveTreasury, + args, + verify + ); }; diff --git a/helpers/types.ts b/helpers/types.ts index db888f9b..dd1b06f9 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -90,6 +90,7 @@ export enum eContractid { RewardsATokenMock = 'RewardsATokenMock', RewardsToken = 'RewardsToken', CurveGaugeRewardsAwareAToken = 'CurveGaugeRewardsAwareAToken', + CurveTreasury = 'CurveTreasury', } /* diff --git a/tasks/deployments/deploy-CurveTreasury.ts b/tasks/deployments/deploy-CurveTreasury.ts new file mode 100644 index 00000000..a2fa878f --- /dev/null +++ b/tasks/deployments/deploy-CurveTreasury.ts @@ -0,0 +1,40 @@ +import { task } from 'hardhat/config'; +import { CRV_TOKEN, CURVE_CONFIG, ZERO_ADDRESS } from '../../helpers/constants'; +import { + deployCurveTreasury, + deployInitializableAdminUpgradeabilityProxy, +} from '../../helpers/contracts-deployments'; +import { waitForTx } from '../../helpers/misc-utils'; + +task(`deploy-curve-treasury`, `Deploys the CurveTreasury contract`) + .addParam('proxyAdmin') + .addParam('treasuryAdmin') + .addFlag('verify', `Verify contract via Etherscan API.`) + .setAction(async ({ verify, proxyAdmin, treasuryAdmin }, localBRE) => { + await localBRE.run('set-DRE'); + + const net = localBRE.network.name; + console.log(`\n- Curve Treasury deployment`); + + const implementation = await deployCurveTreasury( + CURVE_CONFIG.votingEscrow[net], + CRV_TOKEN[net], + CURVE_CONFIG.curveFeeDistributor[net], + CURVE_CONFIG.gaugeController[net], + ZERO_ADDRESS, + verify + ); + + const proxy = await deployInitializableAdminUpgradeabilityProxy(verify); + const encoded = implementation.interface.encodeFunctionData('initialize', [ + treasuryAdmin, + [], + [], + [], + ]); + await waitForTx(await proxy.initialize(implementation.address, proxyAdmin, encoded)); + + console.log(`\tFinished CurveTreasury deployment`); + console.log(`\tProxy:`, proxy.address); + console.log(`\tImpl:`, implementation.address); + });