Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VEN-3019]: align interface with IL comptroller #548

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
62 changes: 42 additions & 20 deletions contracts/Comptroller/Diamond/facets/MarketFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ contract MarketFacet is IMarketFacet, FacetBase {
return markets[address(vToken)].accountMembership[account];
}

/**
* @notice Check if a market is marked as listed (active)
* @param vToken vToken Address for the market to check
* @return listed True if listed otherwise false
*/
function isMarketListed(VToken vToken) external view returns (bool) {
return markets[address(vToken)].isListed;
}

/**
* @notice Add assets to be included in account liquidity calculation
* @param vTokens The list of addresses of the vToken markets to be enabled
Expand Down Expand Up @@ -226,33 +235,23 @@ contract MarketFacet is IMarketFacet, FacetBase {
return uint256(Error.NO_ERROR);
}

/**
* @notice Alias to _supportMarket to support the Isolated Lending Comptroller Interface
* @param vToken The address of the market (token) to list
* @return uint256 0=success, otherwise a failure. (See enum Error for details)
*/
function supportMarket(VToken vToken) external returns (uint256) {
return __supportMarket(vToken);
}

/**
* @notice Add the market to the markets mapping and set it as listed
* @dev Allows a privileged role to add and list markets to the Comptroller
* @param vToken The address of the market (token) to list
* @return uint256 0=success, otherwise a failure. (See enum Error for details)
*/
function _supportMarket(VToken vToken) external returns (uint256) {
ensureAllowed("_supportMarket(address)");

if (markets[address(vToken)].isListed) {
return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS);
}

vToken.isVToken(); // Sanity check to make sure its really a VToken

// Note that isVenus is not in active use anymore
Market storage newMarket = markets[address(vToken)];
newMarket.isListed = true;
newMarket.isVenus = false;
newMarket.collateralFactorMantissa = 0;

_addMarketInternal(vToken);
_initializeMarket(address(vToken));

emit MarketListed(vToken);

return uint256(Error.NO_ERROR);
return __supportMarket(vToken);
}

/**
Expand Down Expand Up @@ -309,4 +308,27 @@ contract MarketFacet is IMarketFacet, FacetBase {
*/
supplyState.block = borrowState.block = blockNumber;
}

function __supportMarket(VToken vToken) internal returns (uint256) {
ensureAllowed("_supportMarket(address)");

if (markets[address(vToken)].isListed) {
return fail(Error.MARKET_ALREADY_LISTED, FailureInfo.SUPPORT_MARKET_EXISTS);
}

vToken.isVToken(); // Sanity check to make sure its really a VToken

// Note that isVenus is not in active use anymore
Market storage newMarket = markets[address(vToken)];
newMarket.isListed = true;
newMarket.isVenus = false;
newMarket.collateralFactorMantissa = 0;

_addMarketInternal(vToken);
_initializeMarket(address(vToken));

emit MarketListed(vToken);

return uint256(Error.NO_ERROR);
}
}
32 changes: 24 additions & 8 deletions contracts/Comptroller/Diamond/facets/PolicyFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -407,21 +407,26 @@ contract PolicyFacet is IPolicyFacet, XVSRewardsHelper {
}
}

/**
* @notice Alias to getAccountLiquidity to support the Isolated Lending Comptroller Interface
* @param account The account get liquidity for
* @return (possible error code (semi-opaque),
account liquidity in excess of collateral requirements,
* account shortfall below collateral requirements)
*/
function getBorrowingPower(address account) external view returns (uint256, uint256, uint256) {
return _getAccountLiquidity(account);
}

/**
* @notice Determine the current account liquidity wrt collateral requirements
* @param account The account get liquidity for
* @return (possible error code (semi-opaque),
account liquidity in excess of collateral requirements,
* account shortfall below collateral requirements)
*/
function getAccountLiquidity(address account) external view returns (uint256, uint256, uint256) {
(Error err, uint256 liquidity, uint256 shortfall) = getHypotheticalAccountLiquidityInternal(
account,
VToken(address(0)),
0,
0
);

return (uint256(err), liquidity, shortfall);
return _getAccountLiquidity(account);
}

/**
Expand Down Expand Up @@ -473,6 +478,17 @@ contract PolicyFacet is IPolicyFacet, XVSRewardsHelper {
}
}

function _getAccountLiquidity(address account) internal view returns (uint256, uint256, uint256) {
(Error err, uint256 liquidity, uint256 shortfall) = getHypotheticalAccountLiquidityInternal(
account,
VToken(address(0)),
0,
0
);

return (uint256(err), liquidity, shortfall);
}

function setVenusSpeedInternal(VToken vToken, uint256 supplySpeed, uint256 borrowSpeed) internal {
ensureListed(markets[address(vToken)]);

Expand Down
Loading
Loading