Skip to content

Commit

Permalink
feat: align interface with IL comptroller
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Jan 20, 2025
1 parent 5972bfd commit 3ec715f
Show file tree
Hide file tree
Showing 10 changed files with 477 additions and 158 deletions.
60 changes: 41 additions & 19 deletions contracts/Comptroller/Diamond/facets/MarketFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,33 +226,32 @@ 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 __supportMarket(vToken);
}

return uint256(Error.NO_ERROR);
/**
* @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;
}

/**
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);
}
}
33 changes: 24 additions & 9 deletions contracts/Comptroller/Diamond/facets/PolicyFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -407,22 +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
*/
function getBorrowingPower(
address account
) external view returns (uint256 error, uint256 liquidity, uint256 shortfall) {
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);
}

/**
* @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed
Expand Down Expand Up @@ -473,6 +477,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

0 comments on commit 3ec715f

Please sign in to comment.