Getting Started

During alpha testing, contracts are upgraded and redeployed frequently. Compound is currently running on the Rinkeby testnet, and will be available on Ethereum soon.

Deployed Smart Contracts

Name ABI Address
MoneyMarket JSON
0x0dd26d23cf5e4ad2fbdfaf7bc2fefd49f7f4cfb5
PriceOracle JSON
0xfee2ad990b4c562367289c92d8b74cb080c41f7d
FaucetToken BAT JSON
0xbf7bbeef6c56e53f79de37ee9ef5b111335bd2ab
FaucetToken REP JSON
0x930b647320f738d92f5647b2e5c4458497ce3c95
FaucetToken TUSD JSON
0x6f7454cba97fffe10e053187f23925a86f5c20c4
FaucetToken WETH JSON
0xc778417e063141139fce010982780140aa0cd5ab
FaucetToken ZRX JSON
0x8de2f821bc97979b7171e7a6fe065b9e17f73b87

MoneyMarket Contract

The MoneyMarket is the primary Smart Contract that is used to interact with the the Compound Protocol. The primary functions of the protocol are as follows:

Supply

function supply(address asset, uint amount) public returns (uint)
  • Asset - The address of the ERC-20 token to be supplied.
  • Amount - The amount of the asset to be supplied specified in the smallest unit available for the asset. For example, amount should be specified in Wei for a user desiring to supply Wrapped Ether.
  • RETURNS - 0 on Success, otherwise a failure.

User’s who wish to supply assets into the protocol must use the supply function and specify the desired asset to supply as well as the amount of the asset in which to supply. User’s who supply supported assets will begin accumulating interest on their supplied asset based on the current Supply Rate for that particular asset.

Withdraw

function withdraw(address asset, uint requestedAmount) public returns (uint)
  • Asset - The address of the ERC-20 token to be withdrawn.
  • Amount - The amount of the asset to be withdrawn specified in the smallest unit available for the asset. For example, amount should be specified in Wei for a user desiring to withdraw Wrapped Ether. A value of -1 can be used to withdraw the maximum amount allowed.
  • RETURNS - 0 on Success, otherwise a failure.

Users who wish to withdraw assets from the protocol must use the withdraw function and specify the desired asset to withdraw as well as the amount of the asset in which to withdraw. Additionally, Users must have sufficient Account Liquidity available to allow for the desired withdrawal amount. Users who supply supported assets are free to withdraw their original supplied amount as well as any accumulated supply interest so long as they have sufficient liquidity. Finally, users may specify an amount of -1 in order to withdraw the maximum amount they are allowed to withdraw.

Borrow

function borrow(address asset, uint amount) public returns (uint)
  • Asset - The address of the ERC-20 token to be borrowed.
  • Amount - The amount of the asset to be borrowed specified in the smallest unit available for the asset. For example, amount should be specified in Wei for a user desiring to supply Wrapped Ether.
  • RETURNS - 0 on Success, otherwise a failure.

Users who wish to borrow a supported asset from the protocol must use the borrow function and specify the desired asset to borrow as well as the amount of the asset in which to borrow. Users who borrow supported assets will begin accumulating interest on their borrowed asset based on the current Borrow Rate for that particular asset. Additionally, users who wish to borrow assets must have sufficient Account Liquidity to collateralize their desired borrow amount and maintain positive Account Liquidity in order to avoid possible liquidation.

Repay Borrow

function repayBorrow(address asset, uint amount) public returns (uint)
  • Asset - The address of the ERC-20 token to be repaid.
  • Amount - The amount of the asset to be repaid specified in the smallest unit available for the asset. For example, amount should be specified in Wei for a user desiring to repay Wrapped Ether. A value of -1 can be used to repay the maximum amount allowed.
  • RETURNS - 0 on Success, otherwise a failure.

Users who wish to repay a borrowed assets back to the protocol must use the repayBorrow function and specify the desired asset to repay as well as the amount of the asset in which to repay. Also, users may specify an amount of -1 in order to replay the maximum amount they are allowed to.

Get Account Liquidity

function getAccountLiquidity(address account) view public returns (int)
  • Account - The address of the user’s Compound Protocol account.
  • RETURNS - Signed integer where positive indicates user’s Account Liquidity. Negative indicates the user’s Shortfall Amount which may be liquidated to bring the user back to 0 or positive Account Liquidity. Throws a failed assertion on failure.

Within the Compound Protocol, Account Liquidity is defined as the total value of a user’s supply balances subtracted by the total value of a user’s borrow balances multiplied by the protocol Collateral Ratio. Users who do not have positive account liquidity do not have the ability to withdraw or borrow any assets until they bring their account liquidity back positive by supplying more assets or paying back outstanding borrows. A negative value for Account Liquidity also means the user is subject to possible Liquidation in order to bring their Account Liquidity back to 0.

The Compound Protocol exposes a public function in order to get the current Account Liquidity value for a given user. The result is a signed integer denominated in Eth-Wei scaled by 1e18. For example, a user who has only supplied 0.1 Eth into the protocol and has no outstanding borrows would have an Account Liquidity of 0.1 * 1e18 = 100000000000000000.

Get Supply Balance

function getSupplyBalance(address account, address asset) view public returns (uint)
  • Account - The address of the user’s Compound Protocol account where they originally supplied assets from
  • Asset - The address of the ERC-20 token originally supplied by the user for which to obtain the current balance for
  • RETURNS - The user’s current supply balance for the specified asset given in the smallest unit available for the asset on Success, throws a failed assertion otherwise

Users who supply assets from the protocol are subject to accumulate interest based on the current Supply Rate. Interest is accumulated every few blocks and integrations must use the following functions in order to obtain the most up to date value of a user’s supply or borrow balance which may be updated very frequently.

Get Borrow Balance

function getBorrowBalance(address account, address asset) view public returns (uint)
  • Account - The address of the user’s Compound Protocol account where they originally borrowed assets from
  • Asset - The address of the ERC-20 token originally borrowed by the user for which to obtain the current balance for
  • RETURNS - The user’s current borrow balance for the specified asset given in the smallest unit available for the asset on Success, throws a failed assertion otherwise

Users who borrow assets from the protocol are subject to accumulate interest based on the current Borrow Rate. Interest is accumulated every few blocks and integrations must use the following functions in order to obtain the most up to date value of a user’s supply or borrow balance which may be updated very frequently.

Liquidate

function liquidateBorrow(address targetAccount, address assetBorrow, address assetCollateral, uint requestedAmountClose) public returns (uint)
  • targetAccount - The address of the Liquidatee’s Compound Protocol account that currently has negative Account Liquidity
  • assetBorrow - The address of an ERC-20 token originally borrowed by the Liquidatee which currently has an outstanding balance
  • assetCollateral - The address of an ERC-20 token currently held as collateral by a Liquidatee that the Liquidator wishes to seize
  • requestedAmountClose - The amount of the borrowed asset to be repaid specified in the smallest unit available for the asset. For example, amount should be specified in Wei for a Liquidator desiring to liquidate a Wrapped Ether borrow. A value of -1 can be used to liquidate the maximum amount allowed of the Liquidatee’s outstanding borrow balance given the Liquidee’s current collateral balance and negative Account Liquidity remaining

Users who have negative Account Liquidity are subject to possible Liquidation by other users of the protocol in order to return their Account Liquidity back to 0 (exactly “at” the Collateral Ratio), reducing their risk. When Liquidation occurs, a Liquidator may repay some or all of an outstanding borrow on behalf of a Liquidatee and in return receive a discounted amount of collateral held by the Liquidatee; this discount is defined as the Liquidation Discount, and at launch will be 5.0%.