Compound 收益计算
tags: Blockchain, DeFi, ETH, AAVE 收益计算 有了前面的 AAVE 收益计算,我们采用相同的思路来查看如何计算 Compound 的收益1,首先来查看 balanceOf2 /** * @notice Query the current positive base balance of an account or zero * @dev Note: uses updated interest indices to calculate * @param account The account whose balance to query * @return The present day base balance magnitude of the account, if positive */ function balanceOf(address account) override public view returns (uint256) { (uint64 baseSupplyIndex_, ) = accruedInterestIndices(getNowInternal() - lastAccrualTime); int104 principal = userBasic[account].principal; return principal > 0 ? presentValueSupply(baseSupplyIndex_, unsigned104(principal)) : 0; } 这里用到两个变量:principal 和 baseSupplyIndex,principal 可以通过 userBasic(address) 读取3,但是 baseSupplyIndex 只能通过合约读取,无法在链下获取, 仔细研究presentValueSupply4: ...