defi學習

1 https://mp.weixin.qq.com/s?__biz=MzIwODA3NDI5MA==&mid=2652528080&idx=1&sn=fbf852b1357c20ef95122213c40b0869&chksm=8ce65e8dbb91d79bb872e091c2c495a4c032dca39ca2db1f4fb470bddfc450491b62470ed321&mpshare=1&scene=1&srcid=#rd

2https://etherscan.io/address/0x724487f080c9d5a808CFB4eF04402C9A4089563E

3 https://www.fengli.com/news/23386498.html dy/dx 借貸

4 https://zhuanlan.zhihu.com/p/63610395 makerdao詳細介紹

5 https://ethfans.org/posts/open-finance-a-simple-guide-to-using-makerdao-and-compound

6 https://medium.com/compound-finance/borrowing-assets-from-compound-quick-start-guide-f5e69af4b8f4 compound

7 https://compound.finance/docs/ctokens ctoken

8 https://www.youtube.com/watch?v=BiseNyNpniE.

https://docs.aave.com/developers/tutorials/performing-a-flash-loan Aave 閃電貸

compound:
ctoken:
https://compound.finance/docs/ctokens

function mint(uint mintAmount) returns (uint)

提供1,000 DAI,當匯率爲0.020070時;你會得到49,825.61 cDAI(1,000 / 0.020070)。

幾個月後,您決定是時候從協議中撤回DAI了;匯率現在是0.021591:

您的49,825.61 cDAI現在等於1,075.78 DAI(49,825.61 * 0.021591)

您可以提取1,075.78 DAI,這將贖回所有49,825.61 cDAI

或者,您可以提取一部分,例如您的原始1,000 DAI,這將贖回46,315.59 cDAI(在您的錢包中保留3,510.01 cDAI)

contract CErc20Interface is CErc20Storage {

    /*** User Interface ***/

    function mint(uint mintAmount) external returns (uint);
    function redeem(uint redeemTokens) external returns (uint);
    function redeemUnderlying(uint redeemAmount) external returns (uint);
    function borrow(uint borrowAmount) external returns (uint);
    function repayBorrow(uint repayAmount) external returns (uint);
    function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint);
    function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) external returns (uint);


    /*** Admin Functions ***/

    function _addReserves(uint addAmount) external returns (uint);
}

Comptroller
it determines how much collateral a user is required to maintain, and whether (and by how much) a user can be liquidated.

Enter Markets
Enter into a list of markets - it is not an error to enter the same market more than once. In order to supply collateral or borrow in a market, it must be entered first.

Comptroller troll = Comptroller(0xABCD...);
CToken[] memory cTokens = new CToken[](2);
cTokens[0] = CErc20(0x3FDA...);
cTokens[1] = CEther(0x3FDB...);
uint[] memory errors = troll.enterMarkets(cTokens);

Get Assets In
Get the list of markets an account is currently entered into. In order to supply collateral or borrow in a market, it must be entered first. Entered markets count towards account liquidity calculations.

function getAssetsIn(address account) view returns (address[] memory)

Comptroller troll = Comptroller(0xABCD...);
address[] memory markets = troll.getAssetsIn(0xMyAccount);

Collateral Factor

Each asset has a unique collateral factor, ranging from 0% to 90%; this represents the percentage of supplied value that can be actively borrowed at any given time.

Comptroller troll = Comptroller(0xABCD...);
(bool isListed, uint collateralFactorMantissa) = troll.markets(0x3FDA...);

collateralFactorMantissa, scaled by 1e18, is multiplied by a supply balance to determine how much value can be borrowed.

Get Account Liquidity

function getAccountLiquidity(address account) view returns (uint, uint, uint)


Comptroller troll = Comptroller(0xABCD...);
(uint error, uint liquidity, uint shortfall) = troll.getAccountLiquidity(msg.caller);
require(error == 0, "join the Discord");
require(shortfall == 0, "account underwater");
require(liquidity > 0, "account has excess collateral");

Close Factor

The percent, ranging from 0% to 100%, of a liquidatable account’s borrow that can be repaid in a single liquidate transaction. If a user has multiple borrowed assets, the closeFactor applies to any single borrowed asset, not the aggregated value of a user’s outstanding borrowing.

Comptroller troll = Comptroller(0xABCD...);
uint closeFactor = troll.closeFactorMantissa();

Liquidation Incentive

The additional collateral given to liquidators as an incentive to perform liquidation of underwater accounts. For example, if the liquidation incentive is 1.1, liquidators receive an extra 10% of the borrowers collateral for every unit they close.

Comptroller troll = Comptroller(0xABCD...);
uint closeFactor = troll.liquidationIncentiveMantissa();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章