-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
saving Aave USDC and DAI genericAave (#38)
- Loading branch information
1 parent
81be38c
commit 3dbeded
Showing
15 changed files
with
544 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.