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
quickborrow:
https://medium.com/compound-finance/building-on-compound-d6ddcf869178

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();
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值