@dany-armstrong/hardhat-compound
v1.0.6
Published
Compound deployment plugin
Downloads
13
Maintainers
Readme
Compound V2 protocol deployment
Installation
npm install @dany-armstrong/hardhat-compound
yarn add @dany-armstrong/hardhat-compound
The function deployCompoundV2(CTokenDeployArg[], Signer): Promise<CompoundV2>
deploys Comptroller, Interest rate models, SimplePriceOracle, and cTokens. cToken config is passed
in a form of CTokenDeployArg
. Compound contract types are pre-generated by TypeChain.
import { deployCompoundV2 } from '@dany-armstrong/hardhat-compound';
const cTokenDeployArgs = [
{
cToken: 'cUSDC',
underlying: '0x1234...',
underlyingPrice: '1000000000000000000000000000000',
collateralFactor: '750000000000000000',
},
];
const { cTokens, comptroller, interestRateModels, priceOracle } = await deployCompoundV2(
cTokenDeployArgs,
deployer,
// optional overrides
{
gasLmit: 5_000_000
}
);
Full example is available at https://github.com/dany-armstrong/hardhat-compound-example .
Usage in scripts
You can use this plugin in a Hardhat script to deploy.
import { ethers } from "hardhat";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { assert } from "chai";
import { deployErc20Token, Erc20Token } from "@dany-armstrong/hardhat-erc20";
import { CTokenDeployArg, deployCompoundV2, Comptroller,} from "@dany-armstrong/hardhat-compound";
async function main() {
const [deployer] = await ethers.getSigners();
const UNI_PRICE = "25022748000000000000";
const USDC_PRICE = "1000000000000000000000000000000";
// Deploy USDC ERC20
const USDC: Erc20Token = await deployErc20Token(
{
name: "USDC",
symbol: "USDC",
decimals: 6,
}, deployer
);
// Deploy UNI ERC20
const UNI: Erc20Token = await deployErc20Token(
{
name: "UNI",
symbol: "UNI",
decimals: 18,
},deployer
);
const ctokenArgs: CTokenDeployArg[] = [
{
cToken: "cUNI",
underlying: UNI.address,
underlyingPrice: UNI_PRICE,
collateralFactor: "500000000000000000", // 50%
},
{
cToken: "cUSDC",
underlying: USDC.address,
underlyingPrice: USDC_PRICE,
collateralFactor: "500000000000000000", // 50%
},
];
const { comptroller, cTokens, priceOracle, interestRateModels } =
await deployCompoundV2(ctokenArgs, deployer);
await comptroller._setCloseFactor(parseUnits("0.5", 18).toString());
await comptroller._setLiquidationIncentive(parseUnits("1.08", 18));
const { cUNI, cUSDC } = cTokens;
console.log("Comptroller: ", comptroller.address);
console.log("SimplePriceOralce: ", await comptroller.oracle());
console.log("cUNI: ", cUNI.address);
console.log("cUSDC: ", cUSDC.address);
}
...
Usage in tests
You can also use the deployCompoundV2 function from your Hardhat tests Full sample code