Skip to content

compound-developers/compound-3-developer-faq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compound III Developer FAQ

This repository contains code examples for frequent Compound III developer tasks.

Pattern Examples for Developers

See contracts/MyContract.sol for Solidity examples, and also the individual JavaScript files in examples/ for the following cases:

Running The Examples

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.

  • To run all tests: npm test. With the environment variable if not set already MAINNET_PROVIDER_URL="__Alchemy_or_Infura_provider_URL_here__" npm test.
  • To run a single file's tests: npm test -- -g "Find an account's Compound III base asset interest earned"
    • Use the description in the top (whole file) level describe block for the test file.
  • To run a single test: npm test -- -g 'Finds the interest earned of base asset'
    • Use the description in the test level describe block.

How do I call Comet methods? From off chain? From Solidity?

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 { //...

How do I get the latest contract addresses?

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

How do I deploy Compound III?

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