ytLending supports USDC as the base token
This commit is contained in:
@@ -200,5 +200,11 @@ contract Configurator is
|
||||
function getConfiguration(address lendingProxy) external view returns (Configuration memory) {
|
||||
return configuratorParams[lendingProxy];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 预留存储空间,用于未来升级时添加新的状态变量
|
||||
* 50个slot = 50 * 32 bytes = 1600 bytes
|
||||
*/
|
||||
uint256[50] private __gap;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ contract Lending is
|
||||
function supply(uint256 amount) external override nonReentrant whenNotPaused {
|
||||
accrueInterest();
|
||||
|
||||
IERC20(baseToken).safeTransferFrom(msg.sender, address(this), amount);
|
||||
IERC20(baseToken).transferFrom(msg.sender, address(this), amount);
|
||||
|
||||
// 获取用户当前本金
|
||||
UserBasic memory user = userBasic[msg.sender];
|
||||
@@ -240,7 +240,7 @@ contract Lending is
|
||||
uint256 newTotal = userCollateral[msg.sender][asset] + amount;
|
||||
if (newTotal > config.supplyCap) revert SupplyCapExceeded();
|
||||
|
||||
IERC20(asset).safeTransferFrom(msg.sender, address(this), amount);
|
||||
IERC20(asset).transferFrom(msg.sender, address(this), amount);
|
||||
|
||||
userCollateral[msg.sender][asset] += amount;
|
||||
|
||||
@@ -440,7 +440,7 @@ contract Lending is
|
||||
if (collateralAmount > collateralReserves[asset]) revert InsufficientBalance();
|
||||
|
||||
// 收取清算人支付的资金
|
||||
IERC20(baseToken).safeTransferFrom(msg.sender, address(this), baseAmount);
|
||||
IERC20(baseToken).transferFrom(msg.sender, address(this), baseAmount);
|
||||
|
||||
// 抵押品出库
|
||||
collateralReserves[asset] -= collateralAmount;
|
||||
@@ -673,5 +673,11 @@ contract Lending is
|
||||
|
||||
emit WithdrawReserves(to, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev 预留存储空间,用于未来升级时添加新的状态变量
|
||||
* 50个slot = 50 * 32 bytes = 1600 bytes
|
||||
*/
|
||||
uint256[50] private __gap;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,39 +1,59 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "../interfaces/IYTVault.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "../interfaces/IYTAssetVault.sol";
|
||||
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
||||
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
||||
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
|
||||
|
||||
contract LendingPriceFeed is Ownable {
|
||||
address public ytVault;
|
||||
address public wusdAddress;
|
||||
contract LendingPriceFeed is OwnableUpgradeable, UUPSUpgradeable {
|
||||
address public usdcAddress;
|
||||
AggregatorV3Interface internal usdcPriceFeed;
|
||||
|
||||
error InvalidYTVaultAddress();
|
||||
error InvalidWUSDAddress();
|
||||
|
||||
constructor(address _ytVault, address _wusdAddress) Ownable(msg.sender) {
|
||||
if (_ytVault == address(0)) revert InvalidYTVaultAddress();
|
||||
if (_wusdAddress == address(0)) revert InvalidWUSDAddress();
|
||||
ytVault = _ytVault;
|
||||
wusdAddress = _wusdAddress;
|
||||
error InvalidUsdcAddress();
|
||||
error InvalidUsdcPriceFeedAddress();
|
||||
error InvalidChainlinkPrice();
|
||||
|
||||
/// @custom:oz-upgrades-unsafe-allow constructor
|
||||
constructor() {
|
||||
_disableInitializers();
|
||||
}
|
||||
|
||||
function setYTVault(address _ytVault) external onlyOwner {
|
||||
if (_ytVault == address(0)) revert InvalidYTVaultAddress();
|
||||
ytVault = _ytVault;
|
||||
function initialize(address _usdcAddress, address _usdcPriceFeed) external initializer {
|
||||
__UUPSUpgradeable_init();
|
||||
__Ownable_init(msg.sender);
|
||||
if (_usdcAddress == address(0)) revert InvalidUsdcAddress();
|
||||
if (_usdcPriceFeed == address(0)) revert InvalidUsdcPriceFeedAddress();
|
||||
usdcAddress = _usdcAddress;
|
||||
usdcPriceFeed = AggregatorV3Interface(_usdcPriceFeed);
|
||||
}
|
||||
|
||||
function setWUSDAddress(address _wusdAddress) external onlyOwner {
|
||||
if (_wusdAddress == address(0)) revert InvalidWUSDAddress();
|
||||
wusdAddress = _wusdAddress;
|
||||
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
|
||||
|
||||
function setUsdcAddress(address _usdcAddress) external onlyOwner {
|
||||
if (_usdcAddress == address(0)) revert InvalidUsdcAddress();
|
||||
usdcAddress = _usdcAddress;
|
||||
}
|
||||
|
||||
function getPrice(address _token) external view returns (uint256) {
|
||||
if (_token == wusdAddress) {
|
||||
return IYTVault(ytVault).wusdPrice();
|
||||
} else {
|
||||
return IYTVault(_token).ytPrice();
|
||||
if (_token == usdcAddress) {
|
||||
return _getUSDCPrice();
|
||||
}
|
||||
return IYTAssetVault(_token).ytPrice();
|
||||
}
|
||||
|
||||
function _getUSDCPrice() internal view returns (uint256) {
|
||||
(
|
||||
/* uint80 roundId */,
|
||||
int256 price,
|
||||
/* uint256 startedAt */,
|
||||
/* uint256 updatedAt */,
|
||||
/* uint80 answeredInRound */
|
||||
) = usdcPriceFeed.latestRoundData();
|
||||
|
||||
if (price <= 0) revert InvalidChainlinkPrice();
|
||||
|
||||
return uint256(price) * 1e22; // 1e22 = 10^(30-8)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ contract YTPoolManager is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrade
|
||||
uint256 aumInUsdy = getAumInUsdy(true);
|
||||
uint256 ytLPSupply = IERC20(ytLP).totalSupply();
|
||||
|
||||
IERC20(_token).safeTransferFrom(_fundingAccount, ytVault, _amount);
|
||||
IERC20(_token).transferFrom(_fundingAccount, ytVault, _amount);
|
||||
uint256 usdyAmount = IYTVault(ytVault).buyUSDY(_token, address(this));
|
||||
if (usdyAmount < _minUsdy) revert InsufficientOutput();
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ contract YTRewardRouter is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrad
|
||||
|
||||
address account = msg.sender;
|
||||
|
||||
IERC20(_token).safeTransferFrom(account, address(this), _amount);
|
||||
IERC20(_token).transferFrom(account, address(this), _amount);
|
||||
IERC20(_token).approve(ytPoolManager, _amount);
|
||||
|
||||
uint256 ytLPAmount = IYTPoolManager(ytPoolManager).addLiquidityForAccount(
|
||||
@@ -181,7 +181,7 @@ contract YTRewardRouter is Initializable, UUPSUpgradeable, ReentrancyGuardUpgrad
|
||||
|
||||
address account = msg.sender;
|
||||
|
||||
IERC20(_tokenIn).safeTransferFrom(account, ytVault, _amountIn);
|
||||
IERC20(_tokenIn).transferFrom(account, ytVault, _amountIn);
|
||||
|
||||
uint256 amountOut = IYTVault(ytVault).swap(_tokenIn, _tokenOut, _receiver);
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ contract YTAssetVault is
|
||||
}
|
||||
|
||||
// 转入USDC
|
||||
IERC20(usdcAddress).safeTransferFrom(msg.sender, address(this), _usdcAmount);
|
||||
IERC20(usdcAddress).transferFrom(msg.sender, address(this), _usdcAmount);
|
||||
|
||||
// 铸造YT
|
||||
_mint(msg.sender, ytAmount);
|
||||
@@ -551,7 +551,7 @@ contract YTAssetVault is
|
||||
}
|
||||
|
||||
// 从manager转入USDC到合约
|
||||
IERC20(usdcAddress).safeTransferFrom(msg.sender, address(this), _amount);
|
||||
IERC20(usdcAddress).transferFrom(msg.sender, address(this), _amount);
|
||||
|
||||
emit AssetsDeposited(_amount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user