uint256value of zero (0) for a successful call, or return an error code on a unsuccessful call. The main exceptions to this general rule are the methods that are part of the standard ERC-20 specification, such as the
mintfunction to transfer assets from your wallet to any Cozy market. You can use the
mintfunction when you want to do the following:
amountis the number of tokens to supply, denominated in units of the underlying token. For ETH, instead of specifying an amount, you send ETH along with the transaction and
msg.valueis used in place of
approvethe Cozy market. A successful
mintcall returns a value of zero and transfers Cozy tokens to the caller's wallet. The number of Cozy tokens the user receives is equal to the supplied amount divided by the exchange rate.
redeemmethod to redeem Cozy tokens for the underlying supplying funds. The amount of underlying received is equal to the number of Cozy tokens redeemed multiplied by the exchange rate. There are two methods you can use to redeem tokens:
mintmethod, you can use the
borrowmethod to borrow funds from the Cozy protocol. Borrowed funds accrue interest at the current borrow rate. If a borrower has insufficient account liquidity, however, the borrowed funds can be liquidated.
borrowAmountis specified in units of the token to borrow.
repayBorrowBehalffunction to repay borrowed funds as follows:
MAX_UINT256 = 2^256 - 1.
Maximillionand call the following method:
borroweris the address of the user to pay back debt for, and
cEther_is the address of the market to pay back debt in (for example, the Cozy Ether money market, or a protection market with ETH as the underlying). When calling this method, send along more ETH than the debt amount, and after paying off the full debt, the excess ETH will be refunded.
liquidateBorrowfunction to liquidate a user's assets when their account liquidity is negative. This action brings the user back to a solvent state. During a liquidation, the liquidator repays some or all of the user's borrow and, in return, receives a portion of their collateral, as Cozy tokens, at a discount.
approvethe Cozy token contract before liquidating.
borroweris the account with a shortfall to liquidate and
cTokenCollateralis the token being used by the borrower as collateral that the liquidator will receive. For token-based markets,
repayAmountspecifies how much of the borrowed asset to repay, and for ETH-based markets that amount is specified by
18 + underlyingDecimals - cozyTokenDecimals. For example, all Cozy tokens have 8 decimals. If the underlying token has 6 decimals, the initial exchange rate for that market would have 18 + 6 - 8 = 16 decimals. Querying the exchange rate of this market immediately after deployment would return
0.02e16 = 200000000000000.
underlyingToken.balanceOf(address(this));. For markets with ETH as the underlying, the function returns
address(this).balance - msg.value.
totalSupplymethod to return the number of Cozy tokens in a market as follows:
balanceOfmethod as follows:
balanceOfUnderlyingfunction, which returns the user's Cozy token balance multiplied by the exchange rate.
1000 / 0.02 = 50,000Cozy tokens. Calling
balanceOfwill return 50,000e8, and calling
balanceOfUnderlyingwill return 1000e6, since Cozy tokens have 8 decimals and USDC has 6 decimals).
borrowRatePerBlockfunction to read the current interest rate accrued by borrowers every block.
borrows / (cash + borrows - reserves). The supply rate is then calculated as
utilizationRate * (borrowRatePerBlock * (1 - reserveFactor)). You can query this value as follows:
reserveFactorMantissamethod to return the reserve factor. See the Interest Rates section for more information on how the reserve factor is used.
MAX_UINT256is passed as the
Failurelogs when calling methods on a Cozy token contract. These codes are descriptive so no additional description is provided.