feat: added deploy scripts

This commit is contained in:
David Racero 2021-06-16 12:52:00 +02:00
parent 8d52a520b0
commit 53dc34abd7
6 changed files with 101 additions and 9 deletions

View File

@ -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);

View File

@ -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 */
}

View File

@ -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,
},
};

View File

@ -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
);
};

View File

@ -90,6 +90,7 @@ export enum eContractid {
RewardsATokenMock = 'RewardsATokenMock',
RewardsToken = 'RewardsToken',
CurveGaugeRewardsAwareAToken = 'CurveGaugeRewardsAwareAToken',
CurveTreasury = 'CurveTreasury',
}
/*

View File

@ -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);
});