Skip to content

Commit

Permalink
Merge pull request #84 from VenusProtocol/refactor/consolidate-vtokens
Browse files Browse the repository at this point in the history
[VEN-689] Consolidate VToken contracts
  • Loading branch information
kkirka authored Nov 7, 2022
2 parents e287859 + 1fe7334 commit 1d85028
Show file tree
Hide file tree
Showing 34 changed files with 503 additions and 833 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ pragma solidity 0.8.13;

import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import "../VBep20Immutable.sol";
import "../VToken.sol";
import "../Governance/AccessControlManager.sol";
import "../VTokenInterfaces.sol";

contract VBep20ImmutableProxyFactory {
struct VBep20Args {
contract VTokenProxyFactory {
struct VTokenArgs {
address underlying_;
ComptrollerInterface comptroller_;
InterestRateModel interestRateModel_;
Expand All @@ -18,20 +18,20 @@ contract VBep20ImmutableProxyFactory {
uint8 decimals_;
address payable admin_;
AccessControlManager accessControlManager_;
VBep20Interface.RiskManagementInit riskManagement;
VTokenInterface.RiskManagementInit riskManagement;
address vTokenProxyAdmin_;
VBep20Immutable tokenImplementation_;
VToken tokenImplementation_;
}

function deployVBep20Proxy(VBep20Args memory input)
function deployVTokenProxy(VTokenArgs memory input)
external
returns (VBep20Immutable)
returns (VToken)
{
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
address(input.tokenImplementation_),
input.vTokenProxyAdmin_,
abi.encodeWithSelector(
input.tokenImplementation_.initializeVToken.selector,
input.tokenImplementation_.initialize.selector,
input.underlying_,
input.comptroller_,
input.interestRateModel_,
Expand All @@ -44,6 +44,6 @@ contract VBep20ImmutableProxyFactory {
input.riskManagement
)
);
return VBep20Immutable(address(proxy));
return VToken(address(proxy));
}
}
9 changes: 3 additions & 6 deletions contracts/Lens/PoolLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

import "../VBep20.sol";
import "../VToken.sol";
import "../PriceOracle.sol";
import "../ComptrollerInterface.sol";
Expand Down Expand Up @@ -209,9 +208,8 @@ contract PoolLens is ExponentialNoError {
address underlyingAssetAddress;
uint256 underlyingDecimals;

VBep20 vBep20 = VBep20(address(vToken));
underlyingAssetAddress = vBep20.underlying();
underlyingDecimals = IERC20Metadata(vBep20.underlying()).decimals();
underlyingAssetAddress = vToken.underlying();
underlyingDecimals = IERC20Metadata(vToken.underlying()).decimals();

return
VTokenMetadata({
Expand Down Expand Up @@ -276,8 +274,7 @@ contract PoolLens is ExponentialNoError {
uint256 tokenBalance;
uint256 tokenAllowance;

VBep20 vBep20 = VBep20(address(vToken));
IERC20 underlying = IERC20(vBep20.underlying());
IERC20 underlying = IERC20(vToken.underlying());
tokenBalance = underlying.balanceOf(account);
tokenAllowance = underlying.allowance(account, address(vToken));

Expand Down
18 changes: 9 additions & 9 deletions contracts/Pool/PoolRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";

import "../Comptroller.sol";
import "../PriceOracle.sol";
import "../Factories/VBep20ImmutableProxyFactory.sol";
import "../Factories/VTokenProxyFactory.sol";
import "../Factories/JumpRateModelFactory.sol";
import "../Factories/WhitePaperInterestRateModelFactory.sol";
import "../WhitePaperInterestRateModel.sol";
import "../JumpRateModelV2.sol";
import "../VBep20Immutable.sol";
import "../VToken.sol";
import "../InterestRateModel.sol";
import "../Governance/AccessControlManager.sol";
import "../Shortfall/Shortfall.sol";
Expand All @@ -23,7 +23,7 @@ import "../VTokenInterfaces.sol";
* @notice PoolRegistry is a registry for Venus interest rate pools.
*/
contract PoolRegistry is OwnableUpgradeable {
VBep20ImmutableProxyFactory private vTokenFactory;
VTokenProxyFactory private vTokenFactory;
JumpRateModelFactory private jumpRateFactory;
WhitePaperInterestRateModelFactory private whitePaperFactory;
Shortfall private shortfall;
Expand All @@ -39,7 +39,7 @@ contract PoolRegistry is OwnableUpgradeable {
* @param protocolShareReserve_ protocol's shares reserve address.
*/
function initialize(
VBep20ImmutableProxyFactory _vTokenFactory,
VTokenProxyFactory _vTokenFactory,
JumpRateModelFactory _jumpRateFactory,
WhitePaperInterestRateModelFactory _whitePaperFactory,
Shortfall _shortfall,
Expand Down Expand Up @@ -144,7 +144,7 @@ contract PoolRegistry is OwnableUpgradeable {
uint256 liquidationThreshold;
AccessControlManager accessControlManager;
address vTokenProxyAdmin;
VBep20Immutable tokenImplementation_;
VToken tokenImplementation_;
}

/**
Expand Down Expand Up @@ -368,8 +368,8 @@ contract PoolRegistry is OwnableUpgradeable {

Comptroller comptroller = Comptroller(input.comptroller);

VBep20ImmutableProxyFactory.VBep20Args
memory initializeArgs = VBep20ImmutableProxyFactory.VBep20Args(
VTokenProxyFactory.VTokenArgs
memory initializeArgs = VTokenProxyFactory.VTokenArgs(
input.asset,
comptroller,
rate,
Expand All @@ -379,7 +379,7 @@ contract PoolRegistry is OwnableUpgradeable {
input.decimals,
payable(msg.sender),
input.accessControlManager,
VBep20Interface.RiskManagementInit(
VTokenInterface.RiskManagementInit(
address(shortfall),
riskFund,
protocolShareReserve
Expand All @@ -388,7 +388,7 @@ contract PoolRegistry is OwnableUpgradeable {
input.tokenImplementation_
);

VBep20Immutable vToken = vTokenFactory.deployVBep20Proxy(
VToken vToken = vTokenFactory.deployVTokenProxy(
initializeArgs
);

Expand Down
2 changes: 1 addition & 1 deletion contracts/RiskFund/RiskFund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ contract RiskFund is OwnableUpgradeable, ExponentialNoError {
{
uint256 totalAmount;

address underlyingAsset = VBep20Interface(address(vToken)).underlying();
address underlyingAsset = VTokenInterface(address(vToken)).underlying();
uint256 balanceOfUnderlyingAsset = IERC20(underlyingAsset).balanceOf(
address(this)
);
Expand Down
9 changes: 4 additions & 5 deletions contracts/Shortfall/Shortfall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

import "../VToken.sol";
import "../VBep20.sol";
import "../PriceOracle.sol";
import "../ComptrollerInterface.sol";
import "../RiskFund/IRiskFund.sol";
Expand Down Expand Up @@ -262,8 +261,8 @@ contract Shortfall is OwnableUpgradeable, ReentrancyGuardUpgradeable {
);

for (uint256 i = 0; i < auction.markets.length; i++) {
VBep20 vBep20 = VBep20(address(auction.markets[i]));
IERC20 erc20 = IERC20(address(vBep20.underlying()));
VToken vToken = VToken(address(auction.markets[i]));
IERC20 erc20 = IERC20(address(vToken.underlying()));

if (auction.auctionType == AuctionType.LARGE_POOL_DEBT) {
if (auction.highestBidder != address(0)) {
Expand Down Expand Up @@ -322,8 +321,8 @@ contract Shortfall is OwnableUpgradeable, ReentrancyGuardUpgradeable {
auction.status = AuctionStatus.ENDED;

for (uint256 i = 0; i < auction.markets.length; i++) {
VBep20 vBep20 = VBep20(address(auction.markets[i]));
IERC20 erc20 = IERC20(address(vBep20.underlying()));
VToken vToken = VToken(address(auction.markets[i]));
IERC20 erc20 = IERC20(address(vToken.underlying()));

if (auction.auctionType == AuctionType.LARGE_POOL_DEBT) {
uint256 bidAmount = ((auction.marketDebt[auction.markets[i]] *
Expand Down
Loading

0 comments on commit 1d85028

Please sign in to comment.