-
Notifications
You must be signed in to change notification settings - Fork 1
CToken
Each supported asset is integrated through a cToken contract, which is a TZIP-7 compliant representation of balances supplied to the protocol. By minting cTokens, users (1) earn interest through the cToken's exchange rate, which increases in value relative to the underlying asset, and (2) gain the ability to use cTokens as collateral.
cTokens are the primary means of interacting with the Tezfin; when a user mints, redeems, borrows, repays a borrow, or transfers cTokens, she will do so using the cToken contract.
There are currently three types of cTokens: CXTZ, CFA12, and CFA2. Though these types expose the TZIP-7 interface, CFA12 wraps an underlying FA1.2 asset, CFA2 wraps an underlying FA2 asset, and CXTZ simply wraps XTZ itself. As such, the core functions which involve transferring an asset into the protocol have slightly different interfaces depending on the type.
Applies accrued interest to total borrows and reserves.
This function should be executed within 5 blocks prior to other operations of the market.
accrueInterest()
The mint function transfers an asset into the protocol, which begins accumulating interest based on the current Supply Rate for the asset. The user receives a quantity of cTokens equal to the underlying tokens supplied, divided by the current Exchange Rate.
Requires accrueInterest() to be executed prior to this operation.
mint(amount: TNat)
- For CXTZ, users should provide the amount of Mutez equal to mint() parameter
- For CFA12, users should approve the cToken to access their token balance
- For CFA2, users should add cToken as operator
The redeem function converts a specified quantity of cTokens into the underlying asset, and returns them to the user. The amount of underlying tokens received is equal to the quantity of cTokens redeemed, multiplied by the current Exchange Rate. The amount redeemed must be less than the user's Account Liquidity and the market's available liquidity.
Requires accrueInterest() to be executed prior to this operation.
Requires Comptroller method - updateAssetPrice() and updateAccountLiquidity() to be executed prior to this operation.
redeem(redeemTokens: TNat)
The redeem underlying function converts cTokens into a specified quantity of the underlying asset, and returns them to the user. The amount of cTokens redeemed is equal to the quantity of underlying tokens received, divided by the current Exchange Rate. The amount redeemed must be less than the user's Account Liquidity and the market's available liquidity.
Requires accrueInterest() to be executed prior to this operation.
Requires Comptroller method - updateAssetPrice() and updateAccountLiquidity() to be executed prior to this operation.
redeemUnderlying(redeemAmount: TNat)
The borrow function transfers an asset from the protocol to the user, and creates a borrow balance which begins accumulating interest based on the Borrow Rate for the asset. The amount borrowed must be less than the user's Account Liquidity and the market's available liquidity.
Requires accrueInterest() to be executed prior to this operation.
Requires Comptroller method - updateAssetPrice() and updateAccountLiquidity() to be executed prior to this operation.
borrow(borrowAmount: TNat)
The repay function transfers an asset into the protocol, reducing the user's borrow balance.
Requires accrueInterest() to be executed prior to this operation.
repayBorrow(amount: TNat)
- For CXTZ, users should provide the amount of Mutez equal to repayBorrow() parameter
- For CFA12, users should approve the cToken to access their token balance
- For CFA2, users should add cToken as operator
The repay function transfers an asset into the protocol, reducing the target user's borrow balance.
Requires accrueInterest() to be executed prior to this operation.
repayBorrowBehalf(TRecord(borrower: TAddress, repayAmount: TNat))
- For CXTZ, users should provide the amount of Mutez equal to repayBorrow() parameter
- For CFA12, users should approve the cToken to access their token balance
- For CFA2, users should add cToken as operator
Transfer is an TZIP-7 method that allows accounts to send tokens to other Tezos addresses. A cToken transfer will fail if the account has entered that cToken market and the transfer would have put the account into a state of negative liquidity.
Requires Comptroller method - updateAssetPrice() and updateAccountLiquidity() to be executed prior to this operation.
transfer(TRecord(from_: TAddress, to_: TAddress, value: TNat))
General information
Code description