Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.62 KB

readme.md

File metadata and controls

48 lines (33 loc) · 1.62 KB

Compound Math Questions

Code answers to commonly asked math calculations when developing with the Compound Protocol.

What is Compound?

Compound is an open-source, autonomous protocol built for developers, to unlock a universe of new financial applications. Interest and borrowing, for the open financial system. Learn more on the website:

Compound Finance

Setup

If you haven't already, install Node.js LTS. Clone this repository, cd to the root directory of the project, and run:

git clone git@github.com:compound-developers/protocol-math-examples.git
cd protocol-math-examples
npm install

To access the blockchain, each of the scripts use Infura. Add your Infura project key (it's free) as an environment variable. Or run each script on the command line like this: infuraApiKey="_key_here_" node someScript.js

Each of the hard coded main net contract addresses and ABIs can be found here: https://compound.finance/docs#networks

Questions and Answers

How many decimals are in a cToken contract?

node decimals.js

How Do I Calculate the Exchange Rate of a cToken to its Underlying?

node exchangeRate-cTokenToUnderlying.js

How Do I Calculate the Exchange Rate of an Underlying to its cToken?

node exchangeRate-underlyingToCToken.js

How Do I Calculate APY from the Rate Per Block?

node apy.js