This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract YieldMath { | |
/** | |
* Calculate the amount of fyToken a user could sell for given amount of Base. | |
* https://www.desmos.com/calculator/0rgnmtckvy | |
* @param baseReserves base reserves amount | |
* @param fyTokenReserves fyToken reserves amount | |
* @param baseAmount Base amount to be traded | |
* @param timeTillMaturity time till maturity in seconds | |
* @param ts time till maturity coefficient, multiplied by 2^64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Pool { | |
/// @dev Returns how much fyToken would be required to buy `tokenOut` base. | |
function _buyBasePreview( | |
uint128 tokenOut, | |
uint112 baseBalance, | |
uint112 fyTokenBalance | |
) | |
private view | |
beforeMaturity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Pool { | |
/// @dev Buy base for fyToken | |
/// The trader needs to have called `fyToken.approve` | |
/// @param to Wallet receiving the base being bought | |
/// @param tokenOut Amount of base being bought that will be deposited in `to` wallet | |
/// @param max Maximum amount of fyToken that will be paid for the trade | |
/// @return Amount of fyToken that will be taken from caller | |
function buyBase(address to, uint128 tokenOut, uint128 max) | |
external override | |
returns(uint128) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract ERC20 { | |
function _burn(address src, uint wad) internal virtual returns (bool) { | |
unchecked { | |
require(_balanceOf[src] >= wad, "ERC20: Insufficient balance"); | |
_balanceOf[src] = _balanceOf[src] - wad; | |
_totalSupply = _totalSupply - wad; | |
emit Transfer(src, address(0), wad); | |
} | |
return true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Pool { | |
/// @dev Burn liquidity tokens in exchange for base and fyToken. | |
/// The liquidity tokens need to be in this contract. | |
/// @param baseTo Wallet receiving the base. | |
/// @param fyTokenTo Wallet receiving the fyToken. | |
/// @param minRatio Minimum ratio of base to fyToken in the pool. | |
/// @param maxRatio Maximum ratio of base to fyToken in the pool. | |
/// @return The amount of tokens burned and returned (tokensBurned, bases, fyTokens). | |
function burn(address baseTo, address fyTokenTo, uint256 minRatio, uint256 maxRatio) | |
external override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Pool { | |
/// @dev Update cache and, on the first call per block, ratio accumulators | |
function _update(uint128 baseBalance, uint128 fyBalance, uint112 _baseCached, uint112 _fyTokenCached) private { | |
uint32 blockTimestamp = uint32(block.timestamp); | |
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired | |
if (timeElapsed > 0 && _baseCached != 0 && _fyTokenCached != 0) { | |
// We multiply by 1e27 here so that r = t * y/x is a fixed point factor with 27 decimals | |
uint256 scaledFYTokenCached = uint256(_fyTokenCached) * 1e27; | |
cumulativeBalancesRatio += scaledFYTokenCached * timeElapsed / _baseCached; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Pool { | |
/// @dev Mint liquidity tokens, with an optional internal trade to buy fyToken beforehand. | |
/// The amount of liquidity tokens is calculated from the amount of fyToken to buy from the pool, plus the amount of unaccounted for fyToken in this contract. | |
/// The base tokens need to be present in this contract, unaccounted for. | |
/// @param fyTokenToBuy Amount of `fyToken` being bought in the Pool, from this we calculate how much base it will be taken in. | |
function _mintInternal(address to, address remainder, uint256 fyTokenToBuy, uint256 minRatio, uint256 maxRatio) | |
internal | |
returns (uint256 baseIn, uint256 fyTokenIn, uint256 tokensMinted) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract pool { | |
/// @param to Wallet receiving the minted liquidity tokens. | |
/// @param remainder Wallet receiving any surplus base. | |
/// @param minRatio Minimum ratio of base to fyToken in the pool. | |
/// @param maxRatio Maximum ratio of base to fyToken in the pool. | |
/// @return The amount of liquidity tokens minted. | |
function mint(address to, address remainder, uint256 minRatio, uint256 maxRatio) | |
external override | |
returns (uint256, uint256, uint256) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract pool { | |
/// @dev Burn liquidity tokens in exchange for base. | |
/// The liquidity provider needs to have called `pool.approve`. | |
/// @return tokensBurned The amount of pool tokens burned. | |
/// @return tokenOut The amount of base tokens returned. | |
/// @return fyTokenOut The amount of fyTokens returned. | |
function _burnInternal(address baseTo, address fyTokenTo, bool tradeToBase, uint256 minRatio, uint256 maxRatio) | |
internal | |
returns (uint256 tokensBurned, uint256 tokenOut, uint256 fyTokenOut) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CErc20.sol | |
contract CErc20 is CToken, CErc20Interface { | |
// 중간 코드는 생략 | |
function liquidateBorrow(address borrower, uint repayAmount, CTokenInterface cTokenCollateral) external returns (uint) { | |
(uint err,) = liquidateBorrowInternal(borrower, repayAmount, cTokenCollateral); | |
return err; | |
} | |
} |