编译器
0.8.16+commit.07a7930e
文件 1 的 19:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 19:AggregatorV3Interface.sol
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
文件 3 的 19:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 4 的 19:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
}
_balances[to] += amount;
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
文件 5 的 19:FraxlendPair.sol
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./FraxlendPairConstants.sol";
import "./FraxlendPairCore.sol";
import "./libraries/VaultAccount.sol";
import "./libraries/SafeERC20.sol";
import "./interfaces/IERC4626.sol";
import "./interfaces/IFraxlendWhitelist.sol";
import "./interfaces/IRateCalculator.sol";
import "./interfaces/ISwapper.sol";
contract FraxlendPair is IERC20Metadata, FraxlendPairCore {
using VaultAccountingLibrary for VaultAccount;
using SafeERC20 for IERC20;
constructor(
bytes memory _configData,
bytes memory _immutables,
uint256 _maxLTV,
uint256 _liquidationFee,
uint256 _maturityDate,
uint256 _penaltyRate,
bool _isBorrowerWhitelistActive,
bool _isLenderWhitelistActive
)
FraxlendPairCore(
_configData,
_immutables,
_maxLTV,
_liquidationFee,
_maturityDate,
_penaltyRate,
_isBorrowerWhitelistActive,
_isLenderWhitelistActive
)
ERC20("", "")
Ownable()
Pausable()
{}
function name() public view override(ERC20, IERC20Metadata) returns (string memory) {
return nameOfContract;
}
function symbol() public view override(ERC20, IERC20Metadata) returns (string memory) {
return string(abi.encodePacked("FraxlendV1 - ", collateralContract.safeSymbol(), "/", assetContract.safeSymbol()));
}
function decimals() public pure override(ERC20, IERC20Metadata) returns (uint8) {
return 18;
}
function totalSupply() public view override(ERC20, IERC20) returns (uint256) {
return totalAsset.shares;
}
function asset() external view returns (address) {
return address(assetContract);
}
function getConstants()
external
pure
returns (
uint256 _LTV_PRECISION,
uint256 _LIQ_PRECISION,
uint256 _UTIL_PREC,
uint256 _FEE_PRECISION,
uint256 _EXCHANGE_PRECISION,
uint64 _DEFAULT_INT,
uint16 _DEFAULT_PROTOCOL_FEE,
uint256 _MAX_PROTOCOL_FEE
)
{
_LTV_PRECISION = LTV_PRECISION;
_LIQ_PRECISION = LIQ_PRECISION;
_UTIL_PREC = UTIL_PREC;
_FEE_PRECISION = FEE_PRECISION;
_EXCHANGE_PRECISION = EXCHANGE_PRECISION;
_DEFAULT_INT = DEFAULT_INT;
_DEFAULT_PROTOCOL_FEE = DEFAULT_PROTOCOL_FEE;
_MAX_PROTOCOL_FEE = MAX_PROTOCOL_FEE;
}
function getImmutableAddressBool()
external
view
returns (
address _assetContract,
address _collateralContract,
address _oracleMultiply,
address _oracleDivide,
address _rateContract,
address _DEPLOYER_CONTRACT,
address _COMPTROLLER_ADDRESS,
address _FRAXLEND_WHITELIST,
bool _borrowerWhitelistActive,
bool _lenderWhitelistActive
)
{
_assetContract = address(assetContract);
_collateralContract = address(collateralContract);
_oracleMultiply = oracleMultiply;
_oracleDivide = oracleDivide;
_rateContract = address(rateContract);
_DEPLOYER_CONTRACT = DEPLOYER_ADDRESS;
_COMPTROLLER_ADDRESS = COMPTROLLER_ADDRESS;
_FRAXLEND_WHITELIST = FRAXLEND_WHITELIST_ADDRESS;
_borrowerWhitelistActive = borrowerWhitelistActive;
_lenderWhitelistActive = lenderWhitelistActive;
}
function getImmutableUint256()
external
view
returns (
uint256 _oracleNormalization,
uint256 _maxLTV,
uint256 _cleanLiquidationFee,
uint256 _maturityDate,
uint256 _penaltyRate
)
{
_oracleNormalization = oracleNormalization;
_maxLTV = maxLTV;
_cleanLiquidationFee = cleanLiquidationFee;
_maturityDate = maturityDate;
_penaltyRate = penaltyRate;
}
function getUserSnapshot(address _address)
external
view
returns (
uint256 _userAssetShares,
uint256 _userBorrowShares,
uint256 _userCollateralBalance
)
{
_userAssetShares = balanceOf(_address);
_userBorrowShares = userBorrowShares[_address];
_userCollateralBalance = userCollateralBalance[_address];
}
function getPairAccounting()
external
view
returns (
uint128 _totalAssetAmount,
uint128 _totalAssetShares,
uint128 _totalBorrowAmount,
uint128 _totalBorrowShares,
uint256 _totalCollateral
)
{
VaultAccount memory _totalAsset = totalAsset;
_totalAssetAmount = _totalAsset.amount;
_totalAssetShares = _totalAsset.shares;
VaultAccount memory _totalBorrow = totalBorrow;
_totalBorrowAmount = _totalBorrow.amount;
_totalBorrowShares = _totalBorrow.shares;
_totalCollateral = totalCollateral;
}
function toBorrowShares(uint256 _amount, bool _roundUp) external view returns (uint256) {
return totalBorrow.toShares(_amount, _roundUp);
}
function toBorrowAmount(uint256 _shares, bool _roundUp) external view returns (uint256) {
return totalBorrow.toAmount(_shares, _roundUp);
}
function toAssetAmount(uint256 _shares, bool _roundUp) external view returns (uint256) {
return totalAsset.toAmount(_shares, _roundUp);
}
function toAssetShares(uint256 _amount, bool _roundUp) external view returns (uint256) {
return totalAsset.toShares(_amount, _roundUp);
}
event SetTimeLock(address _oldAddress, address _newAddress);
function setTimeLock(address _newAddress) external {
if (msg.sender != TIME_LOCK_ADDRESS) revert OnlyTimeLock();
emit SetTimeLock(TIME_LOCK_ADDRESS, _newAddress);
TIME_LOCK_ADDRESS = _newAddress;
}
event ChangeFee(uint32 _newFee);
function changeFee(uint32 _newFee) external whenNotPaused {
if (msg.sender != TIME_LOCK_ADDRESS) revert OnlyTimeLock();
if (_newFee > MAX_PROTOCOL_FEE) {
revert BadProtocolFee();
}
_addInterest();
currentRateInfo.feeToProtocolRate = _newFee;
emit ChangeFee(_newFee);
}
event WithdrawFees(uint128 _shares, address _recipient, uint256 _amountToTransfer);
function withdrawFees(uint128 _shares, address _recipient) external onlyOwner returns (uint256 _amountToTransfer) {
VaultAccount memory _totalAsset = totalAsset;
VaultAccount memory _totalBorrow = totalBorrow;
if (_shares == 0) _shares = uint128(balanceOf(address(this)));
_amountToTransfer = _totalAsset.toAmount(_shares, true);
uint256 _assetsAvailable = _totalAssetAvailable(_totalAsset, _totalBorrow);
if (_assetsAvailable < _amountToTransfer) {
revert InsufficientAssetsInContract(_assetsAvailable, _amountToTransfer);
}
_totalAsset.amount -= uint128(_amountToTransfer);
_totalAsset.shares -= _shares;
_burn(address(this), _shares);
totalAsset = _totalAsset;
assetContract.safeTransfer(_recipient, _amountToTransfer);
emit WithdrawFees(_shares, _recipient, _amountToTransfer);
}
event SetSwapper(address _swapper, bool _approval);
function setSwapper(address _swapper, bool _approval) external onlyOwner {
swappers[_swapper] = _approval;
emit SetSwapper(_swapper, _approval);
}
event SetApprovedLender(address indexed _address, bool _approval);
function setApprovedLenders(address[] calldata _lenders, bool _approval) external approvedLender(msg.sender) {
for (uint256 i = 0; i < _lenders.length; i++) {
if (_approval || _lenders[i] != msg.sender) {
approvedLenders[_lenders[i]] = _approval;
emit SetApprovedLender(_lenders[i], _approval);
}
}
}
event SetApprovedBorrower(address indexed _address, bool _approval);
function setApprovedBorrowers(address[] calldata _borrowers, bool _approval) external approvedBorrower {
for (uint256 i = 0; i < _borrowers.length; i++) {
if (_approval || _borrowers[i] != msg.sender) {
approvedBorrowers[_borrowers[i]] = _approval;
emit SetApprovedBorrower(_borrowers[i], _approval);
}
}
}
function pause() external {
if (
msg.sender != CIRCUIT_BREAKER_ADDRESS &&
msg.sender != COMPTROLLER_ADDRESS &&
msg.sender != owner() &&
msg.sender != DEPLOYER_ADDRESS
) {
revert ProtocolOrOwnerOnly();
}
_addInterest();
_pause();
}
function unpause() external {
if (msg.sender != COMPTROLLER_ADDRESS && msg.sender != owner()) {
revert ProtocolOrOwnerOnly();
}
_addInterest();
_unpause();
}
}
文件 6 的 19:FraxlendPairConstants.sol
pragma solidity ^0.8.16;
abstract contract FraxlendPairConstants {
uint256 internal constant LTV_PRECISION = 1e5;
uint256 internal constant LIQ_PRECISION = 1e5;
uint256 internal constant UTIL_PREC = 1e5;
uint256 internal constant FEE_PRECISION = 1e5;
uint256 internal constant EXCHANGE_PRECISION = 1e18;
uint64 internal constant DEFAULT_INT = 158049988;
uint16 internal constant DEFAULT_PROTOCOL_FEE = 0;
uint256 internal constant MAX_PROTOCOL_FEE = 5e4;
error Insolvent(uint256 _borrow, uint256 _collateral, uint256 _exchangeRate);
error BorrowerSolvent();
error OnlyApprovedBorrowers();
error OnlyApprovedLenders();
error PastMaturity();
error ProtocolOrOwnerOnly();
error OracleLTEZero(address _oracle);
error InsufficientAssetsInContract(uint256 _assets, uint256 _request);
error NotOnWhitelist(address _address);
error NotDeployer();
error NameEmpty();
error AlreadyInitialized();
error SlippageTooHigh(uint256 _minOut, uint256 _actual);
error BadSwapper();
error InvalidPath(address _expected, address _actual);
error BadProtocolFee();
error BorrowerWhitelistRequired();
error OnlyTimeLock();
error PriceTooLarge();
error PastDeadline(uint256 _blockTimestamp, uint256 _deadline);
}
文件 7 的 19:FraxlendPairCore.sol
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./FraxlendPairConstants.sol";
import "./libraries/VaultAccount.sol";
import "./libraries/SafeERC20.sol";
import "./interfaces/IERC4626.sol";
import "./interfaces/IFraxlendWhitelist.sol";
import "./interfaces/IRateCalculator.sol";
import "./interfaces/ISwapper.sol";
abstract contract FraxlendPairCore is FraxlendPairConstants, ERC20, Ownable, Pausable, ReentrancyGuard {
using VaultAccountingLibrary for VaultAccount;
using SafeERC20 for IERC20;
using SafeCast for uint256;
string public version = "1.0.0";
IERC20 internal immutable assetContract;
IERC20 public immutable collateralContract;
address public immutable oracleMultiply;
address public immutable oracleDivide;
uint256 public immutable oracleNormalization;
uint256 public immutable maxLTV;
uint256 public immutable cleanLiquidationFee;
uint256 public immutable dirtyLiquidationFee;
IRateCalculator public immutable rateContract;
bytes public rateInitCallData;
mapping(address => bool) public swappers;
address public immutable DEPLOYER_ADDRESS;
address public immutable CIRCUIT_BREAKER_ADDRESS;
address public immutable COMPTROLLER_ADDRESS;
address public TIME_LOCK_ADDRESS;
address public immutable FRAXLEND_WHITELIST_ADDRESS;
string internal nameOfContract;
uint256 public immutable maturityDate;
uint256 public immutable penaltyRate;
CurrentRateInfo public currentRateInfo;
struct CurrentRateInfo {
uint64 lastBlock;
uint64 feeToProtocolRate;
uint64 lastTimestamp;
uint64 ratePerSec;
}
ExchangeRateInfo public exchangeRateInfo;
struct ExchangeRateInfo {
uint32 lastTimestamp;
uint224 exchangeRate;
}
VaultAccount public totalAsset;
VaultAccount public totalBorrow;
uint256 public totalCollateral;
mapping(address => uint256) public userCollateralBalance;
mapping(address => uint256) public userBorrowShares;
bool public immutable borrowerWhitelistActive;
mapping(address => bool) public approvedBorrowers;
bool public immutable lenderWhitelistActive;
mapping(address => bool) public approvedLenders;
constructor(
bytes memory _configData,
bytes memory _immutables,
uint256 _maxLTV,
uint256 _liquidationFee,
uint256 _maturityDate,
uint256 _penaltyRate,
bool _isBorrowerWhitelistActive,
bool _isLenderWhitelistActive
) {
{
(
address _circuitBreaker,
address _comptrollerAddress,
address _timeLockAddress,
address _fraxlendWhitelistAddress
) = abi.decode(_immutables, (address, address, address, address));
DEPLOYER_ADDRESS = msg.sender;
CIRCUIT_BREAKER_ADDRESS = _circuitBreaker;
COMPTROLLER_ADDRESS = _comptrollerAddress;
TIME_LOCK_ADDRESS = _timeLockAddress;
FRAXLEND_WHITELIST_ADDRESS = _fraxlendWhitelistAddress;
}
{
(
address _asset,
address _collateral,
address _oracleMultiply,
address _oracleDivide,
uint256 _oracleNormalization,
address _rateContract,
) = abi.decode(_configData, (address, address, address, address, uint256, address, bytes));
assetContract = IERC20(_asset);
collateralContract = IERC20(_collateral);
currentRateInfo.feeToProtocolRate = DEFAULT_PROTOCOL_FEE;
cleanLiquidationFee = _liquidationFee;
dirtyLiquidationFee = (_liquidationFee * 90000) / LIQ_PRECISION;
if (_maxLTV >= LTV_PRECISION && !_isBorrowerWhitelistActive) revert BorrowerWhitelistRequired();
maxLTV = _maxLTV;
{
IFraxlendWhitelist _fraxlendWhitelist = IFraxlendWhitelist(FRAXLEND_WHITELIST_ADDRESS);
if (_oracleMultiply != address(0) && !_fraxlendWhitelist.oracleContractWhitelist(_oracleMultiply)) {
revert NotOnWhitelist(_oracleMultiply);
}
if (_oracleDivide != address(0) && !_fraxlendWhitelist.oracleContractWhitelist(_oracleDivide)) {
revert NotOnWhitelist(_oracleDivide);
}
oracleMultiply = _oracleMultiply;
oracleDivide = _oracleDivide;
oracleNormalization = _oracleNormalization;
if (!_fraxlendWhitelist.rateContractWhitelist(_rateContract)) {
revert NotOnWhitelist(_rateContract);
}
}
rateContract = IRateCalculator(_rateContract);
}
borrowerWhitelistActive = _isBorrowerWhitelistActive;
lenderWhitelistActive = _isLenderWhitelistActive;
maturityDate = _maturityDate;
penaltyRate = _penaltyRate;
}
function initialize(
string calldata _name,
address[] calldata _approvedBorrowers,
address[] calldata _approvedLenders,
bytes calldata _rateInitCallData
) external {
if (msg.sender != DEPLOYER_ADDRESS) {
revert NotDeployer();
}
if (bytes(_name).length == 0) {
revert NameEmpty();
}
if (bytes(nameOfContract).length != 0) {
revert AlreadyInitialized();
}
nameOfContract = _name;
for (uint256 i = 0; i < _approvedBorrowers.length; ++i) {
approvedBorrowers[_approvedBorrowers[i]] = true;
}
for (uint256 i = 0; i < _approvedLenders.length; ++i) {
approvedLenders[_approvedLenders[i]] = true;
}
IRateCalculator(rateContract).requireValidInitData(_rateInitCallData);
rateInitCallData = _rateInitCallData;
_addInterest();
_updateExchangeRate();
}
function _totalAssetAvailable(VaultAccount memory _totalAsset, VaultAccount memory _totalBorrow)
internal
pure
returns (uint256)
{
return _totalAsset.amount - _totalBorrow.amount;
}
function _isSolvent(address _borrower, uint256 _exchangeRate) internal view returns (bool) {
if (maxLTV == 0) return true;
uint256 _borrowerAmount = totalBorrow.toAmount(userBorrowShares[_borrower], true);
if (_borrowerAmount == 0) return true;
uint256 _collateralAmount = userCollateralBalance[_borrower];
if (_collateralAmount == 0) return false;
uint256 _ltv = (((_borrowerAmount * _exchangeRate) / EXCHANGE_PRECISION) * LTV_PRECISION) / _collateralAmount;
return _ltv <= maxLTV;
}
function _isPastMaturity() internal view returns (bool) {
return maturityDate != 0 && block.timestamp > maturityDate;
}
modifier isSolvent(address _borrower) {
_;
if (!_isSolvent(_borrower, exchangeRateInfo.exchangeRate)) {
revert Insolvent(
totalBorrow.toAmount(userBorrowShares[_borrower], true),
userCollateralBalance[_borrower],
exchangeRateInfo.exchangeRate
);
}
}
modifier approvedBorrower() {
if (borrowerWhitelistActive && !approvedBorrowers[msg.sender]) {
revert OnlyApprovedBorrowers();
}
_;
}
modifier approvedLender(address _receiver) {
if (lenderWhitelistActive && (!approvedLenders[msg.sender] || !approvedLenders[_receiver])) {
revert OnlyApprovedLenders();
}
_;
}
modifier isNotPastMaturity() {
if (_isPastMaturity()) {
revert PastMaturity();
}
_;
}
event AddInterest(
uint256 _interestEarned,
uint256 _rate,
uint256 _deltaTime,
uint256 _feesAmount,
uint256 _feesShare
);
event UpdateRate(uint256 _ratePerSec, uint256 _deltaTime, uint256 _utilizationRate, uint256 _newRatePerSec);
function addInterest()
external
nonReentrant
returns (
uint256 _interestEarned,
uint256 _feesAmount,
uint256 _feesShare,
uint64 _newRate
)
{
return _addInterest();
}
function _addInterest()
internal
returns (
uint256 _interestEarned,
uint256 _feesAmount,
uint256 _feesShare,
uint64 _newRate
)
{
CurrentRateInfo memory _currentRateInfo = currentRateInfo;
if (_currentRateInfo.lastTimestamp == block.timestamp) {
_newRate = _currentRateInfo.ratePerSec;
return (_interestEarned, _feesAmount, _feesShare, _newRate);
}
VaultAccount memory _totalAsset = totalAsset;
VaultAccount memory _totalBorrow = totalBorrow;
if (_totalBorrow.shares == 0 || paused()) {
if (!paused()) {
_currentRateInfo.ratePerSec = DEFAULT_INT;
}
_currentRateInfo.lastTimestamp = uint64(block.timestamp);
_currentRateInfo.lastBlock = uint64(block.number);
currentRateInfo = _currentRateInfo;
} else {
uint256 _deltaTime = block.timestamp - _currentRateInfo.lastTimestamp;
uint256 _utilizationRate = (UTIL_PREC * _totalBorrow.amount) / _totalAsset.amount;
if (_isPastMaturity()) {
_newRate = uint64(penaltyRate);
} else {
bytes memory _rateData = abi.encode(
_currentRateInfo.ratePerSec,
_deltaTime,
_utilizationRate,
block.number - _currentRateInfo.lastBlock
);
_newRate = IRateCalculator(rateContract).getNewRate(_rateData, rateInitCallData);
}
emit UpdateRate(_currentRateInfo.ratePerSec, _deltaTime, _utilizationRate, _newRate);
_currentRateInfo.ratePerSec = _newRate;
_currentRateInfo.lastTimestamp = uint64(block.timestamp);
_currentRateInfo.lastBlock = uint64(block.number);
_interestEarned = (_deltaTime * _totalBorrow.amount * _currentRateInfo.ratePerSec) / 1e18;
if (
_interestEarned + _totalBorrow.amount <= type(uint128).max &&
_interestEarned + _totalAsset.amount <= type(uint128).max
) {
_totalBorrow.amount += uint128(_interestEarned);
_totalAsset.amount += uint128(_interestEarned);
if (_currentRateInfo.feeToProtocolRate > 0) {
_feesAmount = (_interestEarned * _currentRateInfo.feeToProtocolRate) / FEE_PRECISION;
_feesShare = (_feesAmount * _totalAsset.shares) / (_totalAsset.amount - _feesAmount);
_totalAsset.shares += uint128(_feesShare);
_mint(address(this), _feesShare);
}
emit AddInterest(_interestEarned, _currentRateInfo.ratePerSec, _deltaTime, _feesAmount, _feesShare);
}
totalAsset = _totalAsset;
currentRateInfo = _currentRateInfo;
totalBorrow = _totalBorrow;
}
}
event UpdateExchangeRate(uint256 _rate);
function updateExchangeRate() external nonReentrant returns (uint256 _exchangeRate) {
_exchangeRate = _updateExchangeRate();
}
function _updateExchangeRate() internal returns (uint256 _exchangeRate) {
ExchangeRateInfo memory _exchangeRateInfo = exchangeRateInfo;
if (_exchangeRateInfo.lastTimestamp == block.timestamp) {
return _exchangeRate = _exchangeRateInfo.exchangeRate;
}
uint256 _price = uint256(1e36);
if (oracleMultiply != address(0)) {
(, int256 _answer, , , ) = AggregatorV3Interface(oracleMultiply).latestRoundData();
if (_answer <= 0) {
revert OracleLTEZero(oracleMultiply);
}
_price = _price * uint256(_answer);
}
if (oracleDivide != address(0)) {
(, int256 _answer, , , ) = AggregatorV3Interface(oracleDivide).latestRoundData();
if (_answer <= 0) {
revert OracleLTEZero(oracleDivide);
}
_price = _price / uint256(_answer);
}
_exchangeRate = _price / oracleNormalization;
if (_exchangeRate > type(uint224).max) revert PriceTooLarge();
_exchangeRateInfo.exchangeRate = uint224(_exchangeRate);
_exchangeRateInfo.lastTimestamp = uint32(block.timestamp);
exchangeRateInfo = _exchangeRateInfo;
emit UpdateExchangeRate(_exchangeRate);
}
event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);
function _deposit(
VaultAccount memory _totalAsset,
uint128 _amount,
uint128 _shares,
address _receiver
) internal {
_totalAsset.amount += _amount;
_totalAsset.shares += _shares;
_mint(_receiver, _shares);
totalAsset = _totalAsset;
assetContract.safeTransferFrom(msg.sender, address(this), _amount);
emit Deposit(msg.sender, _receiver, _amount, _shares);
}
function deposit(uint256 _amount, address _receiver)
external
nonReentrant
isNotPastMaturity
whenNotPaused
approvedLender(_receiver)
returns (uint256 _sharesReceived)
{
_addInterest();
VaultAccount memory _totalAsset = totalAsset;
_sharesReceived = _totalAsset.toShares(_amount, false);
_deposit(_totalAsset, _amount.toUint128(), _sharesReceived.toUint128(), _receiver);
}
event Withdraw(
address indexed caller,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
function _redeem(
VaultAccount memory _totalAsset,
uint128 _amountToReturn,
uint128 _shares,
address _receiver,
address _owner
) internal {
if (msg.sender != _owner) {
uint256 allowed = allowance(_owner, msg.sender);
if (allowed != type(uint256).max) _approve(_owner, msg.sender, allowed - _shares);
}
uint256 _assetsAvailable = _totalAssetAvailable(_totalAsset, totalBorrow);
if (_assetsAvailable < _amountToReturn) {
revert InsufficientAssetsInContract(_assetsAvailable, _amountToReturn);
}
_totalAsset.amount -= _amountToReturn;
_totalAsset.shares -= _shares;
totalAsset = _totalAsset;
_burn(_owner, _shares);
assetContract.safeTransfer(_receiver, _amountToReturn);
emit Withdraw(msg.sender, _receiver, _owner, _amountToReturn, _shares);
}
function redeem(
uint256 _shares,
address _receiver,
address _owner
) external nonReentrant returns (uint256 _amountToReturn) {
_addInterest();
VaultAccount memory _totalAsset = totalAsset;
_amountToReturn = _totalAsset.toAmount(_shares, false);
_redeem(_totalAsset, _amountToReturn.toUint128(), _shares.toUint128(), _receiver, _owner);
}
event BorrowAsset(
address indexed _borrower,
address indexed _receiver,
uint256 _borrowAmount,
uint256 _sharesAdded
);
function _borrowAsset(uint128 _borrowAmount, address _receiver) internal returns (uint256 _sharesAdded) {
VaultAccount memory _totalBorrow = totalBorrow;
uint256 _assetsAvailable = _totalAssetAvailable(totalAsset, _totalBorrow);
if (_assetsAvailable < _borrowAmount) {
revert InsufficientAssetsInContract(_assetsAvailable, _borrowAmount);
}
_sharesAdded = _totalBorrow.toShares(_borrowAmount, true);
_totalBorrow.amount += _borrowAmount;
_totalBorrow.shares += uint128(_sharesAdded);
totalBorrow = _totalBorrow;
userBorrowShares[msg.sender] += _sharesAdded;
if (_receiver != address(this)) {
assetContract.safeTransfer(_receiver, _borrowAmount);
}
emit BorrowAsset(msg.sender, _receiver, _borrowAmount, _sharesAdded);
}
function borrowAsset(
uint256 _borrowAmount,
uint256 _collateralAmount,
address _receiver
)
external
isNotPastMaturity
whenNotPaused
nonReentrant
isSolvent(msg.sender)
approvedBorrower
returns (uint256 _shares)
{
_addInterest();
_updateExchangeRate();
if (_collateralAmount > 0) {
_addCollateral(msg.sender, _collateralAmount, msg.sender);
}
_shares = _borrowAsset(_borrowAmount.toUint128(), _receiver);
}
event AddCollateral(address indexed _sender, address indexed _borrower, uint256 _collateralAmount);
function _addCollateral(
address _sender,
uint256 _collateralAmount,
address _borrower
) internal {
userCollateralBalance[_borrower] += _collateralAmount;
totalCollateral += _collateralAmount;
if (_sender != address(this)) {
collateralContract.safeTransferFrom(_sender, address(this), _collateralAmount);
}
emit AddCollateral(_sender, _borrower, _collateralAmount);
}
function addCollateral(uint256 _collateralAmount, address _borrower) external nonReentrant isNotPastMaturity {
_addInterest();
_addCollateral(msg.sender, _collateralAmount, _borrower);
}
event RemoveCollateral(
address indexed _sender,
uint256 _collateralAmount,
address indexed _receiver,
address indexed _borrower
);
function _removeCollateral(
uint256 _collateralAmount,
address _receiver,
address _borrower
) internal {
userCollateralBalance[_borrower] -= _collateralAmount;
totalCollateral -= _collateralAmount;
if (_receiver != address(this)) {
collateralContract.safeTransfer(_receiver, _collateralAmount);
}
emit RemoveCollateral(msg.sender, _collateralAmount, _receiver, _borrower);
}
function removeCollateral(uint256 _collateralAmount, address _receiver)
external
nonReentrant
isSolvent(msg.sender)
{
_addInterest();
if (userBorrowShares[msg.sender] > 0) {
_updateExchangeRate();
}
_removeCollateral(_collateralAmount, _receiver, msg.sender);
}
event RepayAsset(address indexed _payer, address indexed _borrower, uint256 _amountToRepay, uint256 _shares);
function _repayAsset(
VaultAccount memory _totalBorrow,
uint128 _amountToRepay,
uint128 _shares,
address _payer,
address _borrower
) internal {
_totalBorrow.amount -= _amountToRepay;
_totalBorrow.shares -= _shares;
userBorrowShares[_borrower] -= _shares;
totalBorrow = _totalBorrow;
if (_payer != address(this)) {
assetContract.safeTransferFrom(_payer, address(this), _amountToRepay);
}
emit RepayAsset(_payer, _borrower, _amountToRepay, _shares);
}
function repayAsset(uint256 _shares, address _borrower) external nonReentrant returns (uint256 _amountToRepay) {
_addInterest();
VaultAccount memory _totalBorrow = totalBorrow;
_amountToRepay = _totalBorrow.toAmount(_shares, true);
_repayAsset(_totalBorrow, _amountToRepay.toUint128(), _shares.toUint128(), msg.sender, _borrower);
}
event Liquidate(
address indexed _borrower,
uint256 _collateralForLiquidator,
uint256 _sharesToLiquidate,
uint256 _amountLiquidatorToRepay,
uint256 _sharesToAdjust,
uint256 _amountToAdjust
);
function liquidate(
uint128 _sharesToLiquidate,
uint256 _deadline,
address _borrower
) external whenNotPaused nonReentrant approvedLender(msg.sender) returns (uint256 _collateralForLiquidator) {
if (block.timestamp > _deadline) revert PastDeadline(block.timestamp, _deadline);
_addInterest();
uint256 _exchangeRate = _updateExchangeRate();
if (_isSolvent(_borrower, _exchangeRate)) {
revert BorrowerSolvent();
}
VaultAccount memory _totalBorrow = totalBorrow;
uint256 _userCollateralBalance = userCollateralBalance[_borrower];
uint128 _borrowerShares = userBorrowShares[_borrower].toUint128();
int256 _leftoverCollateral;
{
uint256 _liquidationAmountInCollateralUnits = ((_totalBorrow.toAmount(_sharesToLiquidate, false) *
_exchangeRate) / EXCHANGE_PRECISION);
uint256 _optimisticCollateralForLiquidator = (_liquidationAmountInCollateralUnits *
(LIQ_PRECISION + cleanLiquidationFee)) / LIQ_PRECISION;
_leftoverCollateral = (_userCollateralBalance.toInt256() - _optimisticCollateralForLiquidator.toInt256());
_collateralForLiquidator = _leftoverCollateral <= 0
? _userCollateralBalance
: (_liquidationAmountInCollateralUnits * (LIQ_PRECISION + dirtyLiquidationFee)) / LIQ_PRECISION;
}
uint128 _amountLiquidatorToRepay = (_totalBorrow.toAmount(_sharesToLiquidate, true)).toUint128();
uint128 _sharesToAdjust;
{
uint128 _amountToAdjust;
if (_leftoverCollateral <= 0) {
_sharesToAdjust = _borrowerShares - _sharesToLiquidate;
if (_sharesToAdjust > 0) {
_amountToAdjust = (_totalBorrow.toAmount(_sharesToAdjust, false)).toUint128();
_totalBorrow.amount -= _amountToAdjust;
totalAsset.amount -= _amountToAdjust;
}
}
emit Liquidate(
_borrower,
_collateralForLiquidator,
_sharesToLiquidate,
_amountLiquidatorToRepay,
_sharesToAdjust,
_amountToAdjust
);
}
_repayAsset(
_totalBorrow,
_amountLiquidatorToRepay,
_sharesToLiquidate + _sharesToAdjust,
msg.sender,
_borrower
);
_removeCollateral(_collateralForLiquidator, msg.sender, _borrower);
}
event LeveragedPosition(
address indexed _borrower,
address _swapperAddress,
uint256 _borrowAmount,
uint256 _borrowShares,
uint256 _initialCollateralAmount,
uint256 _amountCollateralOut
);
function leveragedPosition(
address _swapperAddress,
uint256 _borrowAmount,
uint256 _initialCollateralAmount,
uint256 _amountCollateralOutMin,
address[] memory _path
)
external
isNotPastMaturity
nonReentrant
whenNotPaused
approvedBorrower
isSolvent(msg.sender)
returns (uint256 _totalCollateralBalance)
{
_addInterest();
_updateExchangeRate();
IERC20 _assetContract = assetContract;
IERC20 _collateralContract = collateralContract;
if (!swappers[_swapperAddress]) {
revert BadSwapper();
}
if (_path[0] != address(_assetContract)) {
revert InvalidPath(address(_assetContract), _path[0]);
}
if (_path[_path.length - 1] != address(_collateralContract)) {
revert InvalidPath(address(_collateralContract), _path[_path.length - 1]);
}
if (_initialCollateralAmount > 0) {
_addCollateral(msg.sender, _initialCollateralAmount, msg.sender);
}
uint256 _borrowShares = _borrowAsset(_borrowAmount.toUint128(), address(this));
_assetContract.approve(_swapperAddress, _borrowAmount);
uint256 _initialCollateralBalance = _collateralContract.balanceOf(address(this));
ISwapper(_swapperAddress).swapExactTokensForTokens(
_borrowAmount,
_amountCollateralOutMin,
_path,
address(this),
block.timestamp
);
uint256 _finalCollateralBalance = _collateralContract.balanceOf(address(this));
uint256 _amountCollateralOut = _finalCollateralBalance - _initialCollateralBalance;
if (_amountCollateralOut < _amountCollateralOutMin) {
revert SlippageTooHigh(_amountCollateralOutMin, _amountCollateralOut);
}
_addCollateral(address(this), _amountCollateralOut, msg.sender);
_totalCollateralBalance = _initialCollateralAmount + _amountCollateralOut;
emit LeveragedPosition(
msg.sender,
_swapperAddress,
_borrowAmount,
_borrowShares,
_initialCollateralAmount,
_amountCollateralOut
);
}
event RepayAssetWithCollateral(
address indexed _borrower,
address _swapperAddress,
uint256 _collateralToSwap,
uint256 _amountAssetOut,
uint256 _sharesRepaid
);
function repayAssetWithCollateral(
address _swapperAddress,
uint256 _collateralToSwap,
uint256 _amountAssetOutMin,
address[] calldata _path
) external nonReentrant isSolvent(msg.sender) returns (uint256 _amountAssetOut) {
_addInterest();
_updateExchangeRate();
IERC20 _assetContract = assetContract;
IERC20 _collateralContract = collateralContract;
if (!swappers[_swapperAddress]) {
revert BadSwapper();
}
if (_path[0] != address(_collateralContract)) {
revert InvalidPath(address(_collateralContract), _path[0]);
}
if (_path[_path.length - 1] != address(_assetContract)) {
revert InvalidPath(address(_assetContract), _path[_path.length - 1]);
}
_removeCollateral(_collateralToSwap, address(this), msg.sender);
_collateralContract.approve(_swapperAddress, _collateralToSwap);
uint256 _initialAssetBalance = _assetContract.balanceOf(address(this));
ISwapper(_swapperAddress).swapExactTokensForTokens(
_collateralToSwap,
_amountAssetOutMin,
_path,
address(this),
block.timestamp
);
uint256 _finalAssetBalance = _assetContract.balanceOf(address(this));
_amountAssetOut = _finalAssetBalance - _initialAssetBalance;
if (_amountAssetOut < _amountAssetOutMin) {
revert SlippageTooHigh(_amountAssetOutMin, _amountAssetOut);
}
VaultAccount memory _totalBorrow = totalBorrow;
uint256 _sharesToRepay = _totalBorrow.toShares(_amountAssetOut, false);
_repayAsset(_totalBorrow, _amountAssetOut.toUint128(), _sharesToRepay.toUint128(), address(this), msg.sender);
emit RepayAssetWithCollateral(msg.sender, _swapperAddress, _collateralToSwap, _amountAssetOut, _sharesToRepay);
}
}
文件 8 的 19:IERC20.sol
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol";
文件 9 的 19:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 10 的 19:IERC4626.sol
pragma solidity >=0.8.16;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed caller,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
function asset() external view returns (address);
function convertToAssets(uint256 shares) external view returns (uint256);
function convertToShares(uint256 assets) external view returns (uint256);
function maxDeposit(address) external view returns (uint256);
function maxMint(address) external view returns (uint256);
function maxRedeem(address owner) external view returns (uint256);
function maxWithdraw(address owner) external view returns (uint256);
function previewDeposit(uint256 assets) external view returns (uint256);
function previewMint(uint256 shares) external view returns (uint256);
function previewRedeem(uint256 shares) external view returns (uint256);
function previewWithdraw(uint256 assets) external view returns (uint256);
function totalAssets() external view returns (uint256);
function mint(uint256 shares, address receiver) external returns (uint256 assets);
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
function redeem(
uint256 shares,
address receiver,
address owner
) external returns (uint256 assets);
function withdraw(
uint256 assets,
address receiver,
address owner
) external returns (uint256 shares);
}
文件 11 的 19:IFraxlendWhitelist.sol
pragma solidity >=0.8.16;
interface IFraxlendWhitelist {
function fraxlendDeployerWhitelist(address) external view returns (bool);
function oracleContractWhitelist(address) external view returns (bool);
function owner() external view returns (address);
function rateContractWhitelist(address) external view returns (bool);
function renounceOwnership() external;
function setFraxlendDeployerWhitelist(address[] calldata _addresses, bool _bool) external;
function setOracleContractWhitelist(address[] calldata _addresses, bool _bool) external;
function setRateContractWhitelist(address[] calldata _addresses, bool _bool) external;
function transferOwnership(address newOwner) external;
}
文件 12 的 19:IRateCalculator.sol
pragma solidity >=0.8.16;
interface IRateCalculator {
function name() external pure returns (string memory);
function requireValidInitData(bytes calldata _initData) external pure;
function getConstants() external pure returns (bytes memory _calldata);
function getNewRate(bytes calldata _data, bytes calldata _initData) external pure returns (uint64 _newRatePerSec);
}
文件 13 的 19:ISwapper.sol
pragma solidity >=0.8.16;
interface ISwapper {
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}
文件 14 的 19:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 15 的 19:Pausable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Pausable is Context {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor() {
_paused = false;
}
function paused() public view virtual returns (bool) {
return _paused;
}
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
文件 16 的 19:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 17 的 19:SafeCast.sol
pragma solidity ^0.8.0;
library SafeCast {
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
function toInt256(uint256 value) internal pure returns (int256) {
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}
文件 18 的 19:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 19 的 19:VaultAccount.sol
pragma solidity ^0.8.16;
struct VaultAccount {
uint128 amount;
uint128 shares;
}
library VaultAccountingLibrary {
function toShares(
VaultAccount memory total,
uint256 amount,
bool roundUp
) internal pure returns (uint256 shares) {
if (total.amount == 0) {
shares = amount;
} else {
shares = (amount * total.shares) / total.amount;
if (roundUp && (shares * total.amount) / total.shares < amount) {
shares = shares + 1;
}
}
}
function toAmount(
VaultAccount memory total,
uint256 shares,
bool roundUp
) internal pure returns (uint256 amount) {
if (total.shares == 0) {
amount = shares;
} else {
amount = (shares * total.amount) / total.shares;
if (roundUp && (amount * total.shares) / total.amount < shares) {
amount = amount + 1;
}
}
}
}
{
"compilationTarget": {
"src/contracts/FraxlendPair.sol": "FraxlendPair"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "none"
},
"optimizer": {
"enabled": true,
"runs": 725
},
"remappings": [],
"viaIR": true
}
[{"inputs":[{"internalType":"bytes","name":"_configData","type":"bytes"},{"internalType":"bytes","name":"_immutables","type":"bytes"},{"internalType":"uint256","name":"_maxLTV","type":"uint256"},{"internalType":"uint256","name":"_liquidationFee","type":"uint256"},{"internalType":"uint256","name":"_maturityDate","type":"uint256"},{"internalType":"uint256","name":"_penaltyRate","type":"uint256"},{"internalType":"bool","name":"_isBorrowerWhitelistActive","type":"bool"},{"internalType":"bool","name":"_isLenderWhitelistActive","type":"bool"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"BadProtocolFee","type":"error"},{"inputs":[],"name":"BadSwapper","type":"error"},{"inputs":[],"name":"BorrowerSolvent","type":"error"},{"inputs":[],"name":"BorrowerWhitelistRequired","type":"error"},{"inputs":[{"internalType":"uint256","name":"_borrow","type":"uint256"},{"internalType":"uint256","name":"_collateral","type":"uint256"},{"internalType":"uint256","name":"_exchangeRate","type":"uint256"}],"name":"Insolvent","type":"error"},{"inputs":[{"internalType":"uint256","name":"_assets","type":"uint256"},{"internalType":"uint256","name":"_request","type":"uint256"}],"name":"InsufficientAssetsInContract","type":"error"},{"inputs":[{"internalType":"address","name":"_expected","type":"address"},{"internalType":"address","name":"_actual","type":"address"}],"name":"InvalidPath","type":"error"},{"inputs":[],"name":"NameEmpty","type":"error"},{"inputs":[],"name":"NotDeployer","type":"error"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"NotOnWhitelist","type":"error"},{"inputs":[],"name":"OnlyApprovedBorrowers","type":"error"},{"inputs":[],"name":"OnlyApprovedLenders","type":"error"},{"inputs":[],"name":"OnlyTimeLock","type":"error"},{"inputs":[{"internalType":"address","name":"_oracle","type":"address"}],"name":"OracleLTEZero","type":"error"},{"inputs":[{"internalType":"uint256","name":"_blockTimestamp","type":"uint256"},{"internalType":"uint256","name":"_deadline","type":"uint256"}],"name":"PastDeadline","type":"error"},{"inputs":[],"name":"PastMaturity","type":"error"},{"inputs":[],"name":"PriceTooLarge","type":"error"},{"inputs":[],"name":"ProtocolOrOwnerOnly","type":"error"},{"inputs":[{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"uint256","name":"_actual","type":"uint256"}],"name":"SlippageTooHigh","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"_collateralAmount","type":"uint256"}],"name":"AddCollateral","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_interestEarned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_rate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_deltaTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_feesAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_feesShare","type":"uint256"}],"name":"AddInterest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":true,"internalType":"address","name":"_receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"_borrowAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_sharesAdded","type":"uint256"}],"name":"BorrowAsset","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"_newFee","type":"uint32"}],"name":"ChangeFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"address","name":"_swapperAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"_borrowAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_borrowShares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_initialCollateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amountCollateralOut","type":"uint256"}],"name":"LeveragedPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"_collateralForLiquidator","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_sharesToLiquidate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amountLiquidatorToRepay","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_sharesToAdjust","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amountToAdjust","type":"uint256"}],"name":"Liquidate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_collateralAmount","type":"uint256"},{"indexed":true,"internalType":"address","name":"_receiver","type":"address"},{"indexed":true,"internalType":"address","name":"_borrower","type":"address"}],"name":"RemoveCollateral","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_payer","type":"address"},{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amountToRepay","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_shares","type":"uint256"}],"name":"RepayAsset","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_borrower","type":"address"},{"indexed":false,"internalType":"address","name":"_swapperAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"_collateralToSwap","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amountAssetOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_sharesRepaid","type":"uint256"}],"name":"RepayAssetWithCollateral","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_address","type":"address"},{"indexed":false,"internalType":"bool","name":"_approval","type":"bool"}],"name":"SetApprovedBorrower","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_address","type":"address"},{"indexed":false,"internalType":"bool","name":"_approval","type":"bool"}],"name":"SetApprovedLender","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_swapper","type":"address"},{"indexed":false,"internalType":"bool","name":"_approval","type":"bool"}],"name":"SetSwapper","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"_newAddress","type":"address"}],"name":"SetTimeLock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_rate","type":"uint256"}],"name":"UpdateExchangeRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_ratePerSec","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_deltaTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_utilizationRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newRatePerSec","type":"uint256"}],"name":"UpdateRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"_shares","type":"uint128"},{"indexed":false,"internalType":"address","name":"_recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amountToTransfer","type":"uint256"}],"name":"WithdrawFees","type":"event"},{"inputs":[],"name":"CIRCUIT_BREAKER_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"COMPTROLLER_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEPLOYER_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FRAXLEND_WHITELIST_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TIME_LOCK_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_collateralAmount","type":"uint256"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"addCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addInterest","outputs":[{"internalType":"uint256","name":"_interestEarned","type":"uint256"},{"internalType":"uint256","name":"_feesAmount","type":"uint256"},{"internalType":"uint256","name":"_feesShare","type":"uint256"},{"internalType":"uint64","name":"_newRate","type":"uint64"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvedBorrowers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvedLenders","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_borrowAmount","type":"uint256"},{"internalType":"uint256","name":"_collateralAmount","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"borrowAsset","outputs":[{"internalType":"uint256","name":"_shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"borrowerWhitelistActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_newFee","type":"uint32"}],"name":"changeFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cleanLiquidationFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateralContract","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRateInfo","outputs":[{"internalType":"uint64","name":"lastBlock","type":"uint64"},{"internalType":"uint64","name":"feeToProtocolRate","type":"uint64"},{"internalType":"uint64","name":"lastTimestamp","type":"uint64"},{"internalType":"uint64","name":"ratePerSec","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"_sharesReceived","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"dirtyLiquidationFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exchangeRateInfo","outputs":[{"internalType":"uint32","name":"lastTimestamp","type":"uint32"},{"internalType":"uint224","name":"exchangeRate","type":"uint224"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getConstants","outputs":[{"internalType":"uint256","name":"_LTV_PRECISION","type":"uint256"},{"internalType":"uint256","name":"_LIQ_PRECISION","type":"uint256"},{"internalType":"uint256","name":"_UTIL_PREC","type":"uint256"},{"internalType":"uint256","name":"_FEE_PRECISION","type":"uint256"},{"internalType":"uint256","name":"_EXCHANGE_PRECISION","type":"uint256"},{"internalType":"uint64","name":"_DEFAULT_INT","type":"uint64"},{"internalType":"uint16","name":"_DEFAULT_PROTOCOL_FEE","type":"uint16"},{"internalType":"uint256","name":"_MAX_PROTOCOL_FEE","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getImmutableAddressBool","outputs":[{"internalType":"address","name":"_assetContract","type":"address"},{"internalType":"address","name":"_collateralContract","type":"address"},{"internalType":"address","name":"_oracleMultiply","type":"address"},{"internalType":"address","name":"_oracleDivide","type":"address"},{"internalType":"address","name":"_rateContract","type":"address"},{"internalType":"address","name":"_DEPLOYER_CONTRACT","type":"address"},{"internalType":"address","name":"_COMPTROLLER_ADDRESS","type":"address"},{"internalType":"address","name":"_FRAXLEND_WHITELIST","type":"address"},{"internalType":"bool","name":"_borrowerWhitelistActive","type":"bool"},{"internalType":"bool","name":"_lenderWhitelistActive","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getImmutableUint256","outputs":[{"internalType":"uint256","name":"_oracleNormalization","type":"uint256"},{"internalType":"uint256","name":"_maxLTV","type":"uint256"},{"internalType":"uint256","name":"_cleanLiquidationFee","type":"uint256"},{"internalType":"uint256","name":"_maturityDate","type":"uint256"},{"internalType":"uint256","name":"_penaltyRate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPairAccounting","outputs":[{"internalType":"uint128","name":"_totalAssetAmount","type":"uint128"},{"internalType":"uint128","name":"_totalAssetShares","type":"uint128"},{"internalType":"uint128","name":"_totalBorrowAmount","type":"uint128"},{"internalType":"uint128","name":"_totalBorrowShares","type":"uint128"},{"internalType":"uint256","name":"_totalCollateral","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getUserSnapshot","outputs":[{"internalType":"uint256","name":"_userAssetShares","type":"uint256"},{"internalType":"uint256","name":"_userBorrowShares","type":"uint256"},{"internalType":"uint256","name":"_userCollateralBalance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"address[]","name":"_approvedBorrowers","type":"address[]"},{"internalType":"address[]","name":"_approvedLenders","type":"address[]"},{"internalType":"bytes","name":"_rateInitCallData","type":"bytes"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lenderWhitelistActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_swapperAddress","type":"address"},{"internalType":"uint256","name":"_borrowAmount","type":"uint256"},{"internalType":"uint256","name":"_initialCollateralAmount","type":"uint256"},{"internalType":"uint256","name":"_amountCollateralOutMin","type":"uint256"},{"internalType":"address[]","name":"_path","type":"address[]"}],"name":"leveragedPosition","outputs":[{"internalType":"uint256","name":"_totalCollateralBalance","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"_sharesToLiquidate","type":"uint128"},{"internalType":"uint256","name":"_deadline","type":"uint256"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"liquidate","outputs":[{"internalType":"uint256","name":"_collateralForLiquidator","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maturityDate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLTV","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleDivide","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleMultiply","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleNormalization","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"penaltyRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rateContract","outputs":[{"internalType":"contract IRateCalculator","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rateInitCallData","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"_amountToReturn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_collateralAmount","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"removeCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"address","name":"_borrower","type":"address"}],"name":"repayAsset","outputs":[{"internalType":"uint256","name":"_amountToRepay","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_swapperAddress","type":"address"},{"internalType":"uint256","name":"_collateralToSwap","type":"uint256"},{"internalType":"uint256","name":"_amountAssetOutMin","type":"uint256"},{"internalType":"address[]","name":"_path","type":"address[]"}],"name":"repayAssetWithCollateral","outputs":[{"internalType":"uint256","name":"_amountAssetOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_borrowers","type":"address[]"},{"internalType":"bool","name":"_approval","type":"bool"}],"name":"setApprovedBorrowers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_lenders","type":"address[]"},{"internalType":"bool","name":"_approval","type":"bool"}],"name":"setApprovedLenders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_swapper","type":"address"},{"internalType":"bool","name":"_approval","type":"bool"}],"name":"setSwapper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newAddress","type":"address"}],"name":"setTimeLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"swappers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"bool","name":"_roundUp","type":"bool"}],"name":"toAssetAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"bool","name":"_roundUp","type":"bool"}],"name":"toAssetShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"bool","name":"_roundUp","type":"bool"}],"name":"toBorrowAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"bool","name":"_roundUp","type":"bool"}],"name":"toBorrowShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAsset","outputs":[{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"shares","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBorrow","outputs":[{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint128","name":"shares","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateExchangeRate","outputs":[{"internalType":"uint256","name":"_exchangeRate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userBorrowShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userCollateralBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"_shares","type":"uint128"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"withdrawFees","outputs":[{"internalType":"uint256","name":"_amountToTransfer","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]