The FAQ answer and code examples repository for Compound III developers.
This repository contains code examples for frequent Compound III developer tasks.
See contracts/MyContract.sol
for Solidity examples, and also the individual JavaScript files in examples/
for the following cases:
First install all of this repository's dependencies.
npm install
Be sure to set your JSON RPC provider URL at the top of hardhat.config.js
. Also pick the supported Comet instance to run tests against locally.
const providerUrl = 'https://eth-mainnet.alchemyapi.io/v2/__YOUR_API_KEY_HERE__';
const cometInstance = 'usdc-mainnet';
Use the mocha descriptions to run subsets of tests. The Comet instances supported by the tests are listed in hardhat.config.js
.
npm test
. With the environment variable if not set already MAINNET_PROVIDER_URL="__Alchemy_or_Infura_provider_URL_here__" npm test
.npm test -- -g "Find an account's Compound III base asset interest earned"
npm test -- -g 'Finds the interest earned of base asset'
Compound III has several contract files that make up the public Comet interface. The address of the Compound III upgradable proxy contract is used to call methods in Comet.sol, CometExt.sol, and CometCore.sol.
To get the ABI for Comet, run the build process in the Compound III repository. Look for the artifact of CometInterface.sol
in the generated Hardhat artifacts folder.
## First, run the build command in the Compound III project repository
git clone https://github.com/compound-finance/comet.git
cd comet/
yarn run build
// Reference the Hardhat artifact in the Compound III project build files
const abi = require('./artifacts/contracts/CometInterface.sol/CometInterface.json').abi;
const comet = new ethers.Contract(cometAddress, abi, provider);
pragma solidity 0.8.13;
import "./CometInterface.sol";
contract MyContract { //...
Use the spider functionality in the Compound III repository. The addresses can then be found in the deployments/
folder.
git clone https://github.com/compound-finance/comet.git
cd comet/
yarn
npx hardhat spider --deployment mainnet
To deploy to a public blockchain, see the yarn deploy
instructions in the README file of the Comet repository. Be sure to first use the spider
command to pull in the network's existing configuration and latest contract addresses.
Compound III can be deployed to EVM compatible blockchains. Here is an example for deploying to a locally run Ethereum node.
## In one command line window:
git clone https://github.com/compound-finance/comet.git
cd comet/
yarn install
## This runs the ethereum node locally
## The development mnemonic or private keys can be configured in hardhat.config.ts
npx hardhat node
## In another command line window:
cd comet/
## This deploys to the running local ethereum node
## It also writes deployment information to ./deployments/localhost/
yarn deploy --network localhost