Skip to content

Commit

Permalink
saving Aave USDC and DAI genericAave (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeNervoXS authored May 27, 2022
1 parent 81be38c commit 3dbeded
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ contract GenericCompoundUpgradeable is GenericLenderBaseUpgradeable {
string memory _name,
address _cToken,
address[] memory governorList,
address[] memory keeperList,
address guardian
address guardian,
address[] memory keeperList
) external {
_initialize(_strategy, _name, governorList, guardian, keeperList);

Expand Down
78 changes: 0 additions & 78 deletions deploy/GenericCompoundV3.ts

This file was deleted.

27 changes: 12 additions & 15 deletions deploy/StrategyAaveFlashLoanImplementation.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { CONTRACTS_ADDRESSES, Interfaces } from '@angleprotocol/sdk';
import { BigNumber, Contract } from 'ethers';
import { AaveFlashloanStrategy__factory, PoolManager } from '../typechain';

const func: DeployFunction = async ({ deployments, ethers }) => {
const { deploy } = deployments;
const [deployer] = await ethers.getSigners();

const governor = CONTRACTS_ADDRESSES[1].GovernanceMultiSig as string;
const guardian = CONTRACTS_ADDRESSES[1].Guardian as string;
const proxyAdmin = '0x1D941EF0D3Bba4ad67DBfBCeE5262F4CEE53A32b';
// const governor = CONTRACTS_ADDRESSES[1].GovernanceMultiSig as string;
// const guardian = CONTRACTS_ADDRESSES[1].Guardian as string;
// const proxyAdmin = '0x1D941EF0D3Bba4ad67DBfBCeE5262F4CEE53A32b';
const flashMintLib = '0x169487a55dE79476125A56B07C36cA8dbF37a373'; // (await deployments.getOrNull('FlashMintLib')).address

const collats: { [key: string]: { interestRateStrategyAddress: string } } = {
DAI: {
interestRateStrategyAddress: '0xfffE32106A68aA3eD39CcCE673B646423EEaB62a',
},
// USDC: {
// interestRateStrategyAddress: '0x8Cae0596bC1eD42dc3F04c4506cfe442b3E74e27',
// },
};
// const collats: { [key: string]: { interestRateStrategyAddress: string } } = {
// DAI: {
// interestRateStrategyAddress: '0xfffE32106A68aA3eD39CcCE673B646423EEaB62a',
// },
// // USDC: {
// // interestRateStrategyAddress: '0x8Cae0596bC1eD42dc3F04c4506cfe442b3E74e27',
// // },
// };

const keeper = '0xcC617C6f9725eACC993ac626C7efC6B96476916E';
// const keeper = '0xcC617C6f9725eACC993ac626C7efC6B96476916E';

let strategyImplementation = await deployments.getOrNull('AaveFlashloanStrategy_NewImplementation');

Expand Down
88 changes: 88 additions & 0 deletions deploy/lenders/GenericAave.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { network } from 'hardhat';
import { DeployFunction } from 'hardhat-deploy/types';
import { CONTRACTS_ADDRESSES, ChainId } from '@angleprotocol/sdk';
import { BigNumber } from 'ethers';
import { GenericAaveNoStaker__factory, OptimizerAPRStrategy, OptimizerAPRStrategy__factory } from '../../typechain';
import { impersonate } from '../../test/test-utils';

const func: DeployFunction = async ({ deployments, ethers }) => {
const { deploy } = deployments;
const { deployer, keeper: fakeKeeper } = await ethers.getNamedSigners();
const collats = ['USDC', 'DAI'];

let guardian: string;
let governor: string;
let strategyAddress, proxyAdminAddress: string;
let keeper: string;

// if fork we suppose that we are in mainnet
// eslint-disable-next-line
let json = (await import('../networks/mainnet.json')) as any;
if (!network.live) {
guardian = CONTRACTS_ADDRESSES[ChainId.MAINNET].Guardian as string;
governor = CONTRACTS_ADDRESSES[ChainId.MAINNET].GovernanceMultiSig as string;
proxyAdminAddress = CONTRACTS_ADDRESSES[ChainId.MAINNET].ProxyAdmin as string;
keeper = '0xcC617C6f9725eACC993ac626C7efC6B96476916E';
} else {
guardian = CONTRACTS_ADDRESSES[network.config.chainId as ChainId].Guardian!;
governor = CONTRACTS_ADDRESSES[network.config.chainId as ChainId].GovernanceMultiSig as string;
proxyAdminAddress = CONTRACTS_ADDRESSES[network.config.chainId as ChainId].ProxyAdmin as string;
keeper = fakeKeeper.address;
}

const lenderImplementationAddress = (await ethers.getContract(`GenericAaveNoStaker_Implementation`)).address;
console.log('deployed lender Aave implementation', lenderImplementationAddress);
console.log('');

for (const collat in collats) {
const collateralName = collats[collat];
console.log('');
console.log('Handling collat: ', collateralName);
if (!network.live) {
strategyAddress = CONTRACTS_ADDRESSES[ChainId.MAINNET].agEUR?.collaterals?.[collateralName]?.Strategies
?.GenericOptimisedLender as string;
} else {
strategyAddress = CONTRACTS_ADDRESSES[network.config.chainId as ChainId].agEUR?.collaterals?.[collateralName]
?.Strategies?.GenericOptimisedLender as string;
}

const initializeData = GenericAaveNoStaker__factory.createInterface().encodeFunctionData('initialize', [
strategyAddress,
`Aave Lender ${collateralName}`,
true,
[governor],
guardian,
[keeper],
]);

const proxyLender = await deploy(`GenericAaveNoStaker_${collateralName}`, {
contract: 'TransparentUpgradeableProxy',
from: deployer.address,
args: [lenderImplementationAddress, proxyAdminAddress, initializeData],
});

console.log(
`Lender GenericAaveNoStaker_${collateralName} (proxy) successfully deployed at address: `,
proxyLender.address,
);
console.log(`Deploy cost: ${(proxyLender.receipt?.gasUsed as BigNumber)?.toString()} (proxy)`);

if (!network.live) {
const strategy = new ethers.Contract(
strategyAddress,
OptimizerAPRStrategy__factory.createInterface(),
deployer,
) as OptimizerAPRStrategy;

await impersonate(guardian, async acc => {
await network.provider.send('hardhat_setBalance', [guardian, '0x10000000000000000000000000000']);
await await strategy.connect(acc).addLender(proxyLender.address);
console.log('Add lender: success');
});
}
}
};

func.tags = ['genericAave'];
func.dependencies = ['genericAaveImplementation'];
export default func;
19 changes: 19 additions & 0 deletions deploy/lenders/GenericAaveImplementation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { BigNumber } from 'ethers';

const func: DeployFunction = async ({ deployments, ethers }) => {
const { deploy } = deployments;
const { deployer } = await ethers.getNamedSigners();

const lenderImplementation = await deploy(`GenericAaveNoStaker_Implementation`, {
contract: 'GenericAaveNoStaker',
from: deployer.address,
args: [],
});
console.log('success: deployed lender implementation', lenderImplementation.address);
console.log(`Deploy cost: ${(lenderImplementation?.receipt?.gasUsed as BigNumber)?.toString()} (implem)`);
console.log('');
};

func.tags = ['genericAaveImplementation'];
export default func;
118 changes: 118 additions & 0 deletions deploy/lenders/GenericCompoundV3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { network } from 'hardhat';
import { DeployFunction } from 'hardhat-deploy/types';
import { CONTRACTS_ADDRESSES, ChainId } from '@angleprotocol/sdk';
import { BigNumber } from 'ethers';
import {
ERC20,
ERC20__factory,
GenericCompoundUpgradeable,
GenericCompoundUpgradeable__factory,
OptimizerAPRStrategy,
OptimizerAPRStrategy__factory,
} from '../../typechain';
import { parseUnits } from 'ethers/lib/utils';
import { impersonate } from '../../test/test-utils';

const func: DeployFunction = async ({ deployments, ethers }) => {
const { deploy } = deployments;
const { deployer, keeper: fakeKeeper } = await ethers.getNamedSigners();
const collats = ['USDC', 'DAI'];

let guardian: string;
let governor: string;
let strategyAddress, proxyAdminAddress: string;
let keeper: string;

// if fork we suppose that we are in mainnet
// eslint-disable-next-line
let json = (await import('../networks/mainnet.json')) as any;
if (!network.live) {
guardian = CONTRACTS_ADDRESSES[ChainId.MAINNET].Guardian as string;
governor = CONTRACTS_ADDRESSES[ChainId.MAINNET].GovernanceMultiSig as string;
proxyAdminAddress = CONTRACTS_ADDRESSES[ChainId.MAINNET].ProxyAdmin as string;
keeper = '0xcC617C6f9725eACC993ac626C7efC6B96476916E';
} else {
guardian = CONTRACTS_ADDRESSES[network.config.chainId as ChainId].Guardian!;
governor = CONTRACTS_ADDRESSES[network.config.chainId as ChainId].GovernanceMultiSig as string;
proxyAdminAddress = CONTRACTS_ADDRESSES[network.config.chainId as ChainId].ProxyAdmin as string;
keeper = fakeKeeper.address;
}

const lenderImplementationAddress = (await ethers.getContract(`GenericCompoundV3_Implementation`)).address;
console.log('deployed lender Compound implementation', lenderImplementationAddress);
console.log('');

for (const collat in collats) {
const collateralName = collats[collat];
console.log('');
console.log('Handling collat: ', collateralName);
if (!network.live) {
strategyAddress = CONTRACTS_ADDRESSES[ChainId.MAINNET].agEUR?.collaterals?.[collateralName]?.Strategies
?.GenericOptimisedLender as string;
} else {
strategyAddress = CONTRACTS_ADDRESSES[network.config.chainId as ChainId].agEUR?.collaterals?.[collateralName]
?.Strategies?.GenericOptimisedLender as string;
}

const token = (await ethers.getContractAt(ERC20__factory.abi, json[collateralName])) as ERC20;
const tokenDecimal = await token.decimals();
const cToken = json.Compound[collateralName];

console.log('token ', token.address);
console.log('cToken ', cToken);

const initializeData = GenericCompoundUpgradeable__factory.createInterface().encodeFunctionData('initialize', [
strategyAddress,
`Compound Lender ${collateralName}`,
cToken,
[governor],
guardian,
[keeper],
]);

const proxyLender = await deploy(`GenericCompoundV3_${collateralName}`, {
contract: 'TransparentUpgradeableProxy',
from: deployer.address,
args: [lenderImplementationAddress, proxyAdminAddress, initializeData],
});

console.log(
`Lender GenericCompoundV3_${collateralName} (proxy) successfully deployed at address: `,
proxyLender.address,
);
console.log(`Deploy cost: ${(proxyLender.receipt?.gasUsed as BigNumber)?.toString()} (proxy)`);

if (!network.live) {
await network.provider.request({
method: 'hardhat_impersonateAccount',
params: [governor],
});
const governorSigner = await ethers.getSigner(governor);
await network.provider.send('hardhat_setBalance', [governor, '0x10000000000000000000000000000']);

const lenderCompound = new ethers.Contract(
proxyLender.address,
GenericCompoundUpgradeable__factory.createInterface(),
deployer,
) as GenericCompoundUpgradeable;

const strategy = new ethers.Contract(
strategyAddress,
OptimizerAPRStrategy__factory.createInterface(),
deployer,
) as OptimizerAPRStrategy;

await impersonate(guardian, async acc => {
await network.provider.send('hardhat_setBalance', [guardian, '0x10000000000000000000000000000']);
await await lenderCompound.connect(acc).setDust(parseUnits('1', tokenDecimal + 2));
console.log('Set dust: success');
await await strategy.connect(acc).addLender(proxyLender.address);
console.log('Add lender: success');
});
}
}
};

func.tags = ['genericCompoundV3'];
func.dependencies = ['genericCompoundV3Implementation'];
export default func;
19 changes: 19 additions & 0 deletions deploy/lenders/GenericCompoundV3Implementation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { BigNumber } from 'ethers';

const func: DeployFunction = async ({ deployments, ethers }) => {
const { deploy } = deployments;
const { deployer } = await ethers.getNamedSigners();

const lenderImplementation = await deploy(`GenericCompoundV3_Implementation`, {
contract: 'GenericCompoundUpgradeable',
from: deployer.address,
args: [],
});
console.log('success: deployed lender implementation', lenderImplementation.address);
console.log(`Deploy cost: ${(lenderImplementation?.receipt?.gasUsed as BigNumber)?.toString()} (implem)`);
console.log('');
};

func.tags = ['genericCompoundV3Implementation'];
export default func;
Loading

0 comments on commit 3dbeded

Please sign in to comment.