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-2323] Unlist Market #349

Merged
merged 41 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9999eda
fix: added unlist function
web3rover Jan 22, 2024
99e8dd8
fix: updates getAssetsIn
web3rover Jan 22, 2024
bba744b
fix: fixed compile error
web3rover Jan 22, 2024
8ad5761
fix: tests for unlist
web3rover Jan 22, 2024
ac789d2
fix: deployed comptroller in bsctestnet
web3rover Jan 25, 2024
5959aed
feat: updating deployment files
Narayanprusty Jan 25, 2024
e36b799
fix: deployed on sepolia and opbnb testnet
web3rover Jan 25, 2024
f4d2f23
Merge branch 'feat/unlist-market' of github.com:VenusProtocol/isolate…
web3rover Jan 25, 2024
6ee64eb
feat: updating deployment files
Narayanprusty Jan 25, 2024
622cb17
fix: added indexed to event
web3rover Jan 29, 2024
dddcd83
fix: fix CI
web3rover Jan 30, 2024
1b21f05
fix: resolved conflict
web3rover Jan 30, 2024
7e1902a
fix: optimised getAssetsIn
web3rover Feb 19, 2024
6dacce2
fix: rebased
web3rover Mar 4, 2024
b03cb62
fix: fixed yarn.lock
web3rover Mar 4, 2024
0b3a26b
fix: only unlist without updating state
web3rover Mar 4, 2024
f038e3e
fix: VPB-05
web3rover Mar 14, 2024
9fd7543
fix: CVP-01
web3rover Mar 14, 2024
144cb97
fix: VPB-01
web3rover Mar 18, 2024
9584519
fix: change storage to memory
web3rover Mar 21, 2024
f85f96e
fix: resolved conflict
web3rover Mar 29, 2024
97871b8
fix: test description
web3rover Mar 29, 2024
cb1826e
fix: removed unwanted deployment file
web3rover Mar 29, 2024
3e957f1
fix: fixed lint
web3rover Mar 29, 2024
d2a0403
fix: updated yarn lock
web3rover Mar 29, 2024
a4d470c
feat: updating deployment files
Narayanprusty Mar 29, 2024
5fd036c
fix: removed deployments
web3rover Mar 29, 2024
26070c2
fix: resolved conflict
web3rover Jun 6, 2024
ebed4aa
fix: deployment on testnets - wip
web3rover Jun 6, 2024
43cda83
feat: updating deployment files
Narayanprusty Jun 6, 2024
e25fc16
fix: deployed on arb sepolia
web3rover Jun 6, 2024
ae3c021
Merge branch 'feat/unlist-market' of github.com:VenusProtocol/isolate…
web3rover Jun 6, 2024
2e64131
feat: updating deployment files
Narayanprusty Jun 6, 2024
0d4f2e3
fix: added missing solcinputs
web3rover Jun 10, 2024
e2d1bf8
Merge branch 'feat/unlist-market' of github.com:VenusProtocol/isolate…
web3rover Jun 10, 2024
89dc5f4
fix: resolved conflict
web3rover Aug 28, 2024
54ad9ee
fix: resolved conflict
web3rover Aug 28, 2024
03519d6
fix: redeployed contracts
web3rover Aug 30, 2024
7d25caf
feat: updating deployment files
Narayanprusty Aug 30, 2024
c5d4db7
fix: deployed on ethereum and arbitrumone
web3rover Sep 2, 2024
581c592
feat: updating deployment files
Narayanprusty Sep 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 74 additions & 15 deletions contracts/Comptroller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{
// PoolRegistry, immutable to save on gas
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable poolRegistry;

Check warning on line 50 in contracts/Comptroller.sol

View workflow job for this annotation

GitHub Actions / Lint

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice Emitted when an account enters a market
event MarketEntered(VToken indexed vToken, address indexed account);
Expand Down Expand Up @@ -98,6 +98,9 @@
/// @notice Emitted when forced liquidation is enabled or disabled for a market
event IsForcedLiquidationEnabledUpdated(address indexed vToken, bool enable);

/// @notice Emitted when a market is unlisted
event MarketUnlisted(VToken vToken);
web3rover marked this conversation as resolved.
Show resolved Hide resolved

/// @notice Thrown when collateral factor exceeds the upper bound
error InvalidCollateralFactor();

Expand Down Expand Up @@ -199,6 +202,46 @@
return results;
}

/**
* @notice Unlist an market by setting isListed to false
* @dev Pauses all actions, sets borrow/supply caps to 0 and sets collateral factor to 0.
* @param market The address of the market (token) to unlist
* @return uint256 Always NO_ERROR for compatibility with Venus core tooling
*/
function unlistMarket(address market) external returns (uint256) {
_checkAccessAllowed("unlistMarket(address)");

Market storage _market = markets[market];

if (!_market.isListed) {
revert MarketNotListed(market);
}

_setActionPaused(market, Action.BORROW, true);
chechu marked this conversation as resolved.
Show resolved Hide resolved
_setActionPaused(market, Action.MINT, true);
_setActionPaused(market, Action.REDEEM, true);
_setActionPaused(market, Action.REPAY, true);
_setActionPaused(market, Action.ENTER_MARKET, true);
_setActionPaused(market, Action.LIQUIDATE, true);

borrowCaps[market] = 0;
supplyCaps[market] = 0;

VToken vToken = VToken(market);

emit NewSupplyCap(vToken, 0);
emit NewBorrowCap(vToken, 0);

emit NewCollateralFactor(vToken, _market.collateralFactorMantissa, 0);
_market.collateralFactorMantissa = 0;

_market.isListed = false;

emit MarketUnlisted(vToken);

return NO_ERROR;
}

/**
* @notice Removes asset from sender's account liquidity calculation; disabling them as collateral
* @dev Sender must not have an outstanding borrow balance in the asset,
Expand Down Expand Up @@ -352,7 +395,7 @@
* @param redeemAmount The amount of the underlying asset being redeemed
* @param redeemTokens The number of tokens being redeemed
*/
function redeemVerify(address vToken, address redeemer, uint256 redeemAmount, uint256 redeemTokens) external {

Check warning on line 398 in contracts/Comptroller.sol

View workflow job for this annotation

GitHub Actions / Lint

Variable "redeemAmount" is unused

Check warning on line 398 in contracts/Comptroller.sol

View workflow job for this annotation

GitHub Actions / Lint

Variable "redeemTokens" is unused
if (address(prime) != address(0)) {
prime.accrueInterestAndUpdateScore(redeemer, vToken);
}
Expand Down Expand Up @@ -719,7 +762,7 @@
* @custom:access Not restricted
*/
function healAccount(address user) external {
VToken[] memory userAssets = accountAssets[user];
VToken[] memory userAssets = getAssetsIn(user);
uint256 userAssetsCount = userAssets.length;

address liquidator = msg.sender;
Expand Down Expand Up @@ -830,12 +873,12 @@
);
}

VToken[] memory borrowMarkets = accountAssets[borrower];
VToken[] memory borrowMarkets = getAssetsIn(borrower);
uint256 marketsCount = borrowMarkets.length;

for (uint256 i; i < marketsCount; ++i) {
(, uint256 borrowBalance, ) = _safeGetAccountSnapshot(borrowMarkets[i], borrower);
require(borrowBalance == 0, "Nonzero borrow balance after liquidation");

Check warning on line 881 in contracts/Comptroller.sol

View workflow job for this annotation

GitHub Actions / Lint

Use Custom Errors instead of require statements
}
}

Expand All @@ -847,8 +890,8 @@
*/
function setCloseFactor(uint256 newCloseFactorMantissa) external {
_checkAccessAllowed("setCloseFactor(uint256)");
require(MAX_CLOSE_FACTOR_MANTISSA >= newCloseFactorMantissa, "Close factor greater than maximum close factor");

Check warning on line 893 in contracts/Comptroller.sol

View workflow job for this annotation

GitHub Actions / Lint

Use Custom Errors instead of require statements
require(MIN_CLOSE_FACTOR_MANTISSA <= newCloseFactorMantissa, "Close factor smaller than minimum close factor");

Check warning on line 894 in contracts/Comptroller.sol

View workflow job for this annotation

GitHub Actions / Lint

Use Custom Errors instead of require statements

uint256 oldCloseFactorMantissa = closeFactorMantissa;
closeFactorMantissa = newCloseFactorMantissa;
Expand Down Expand Up @@ -923,7 +966,7 @@
* @custom:access Controlled by AccessControlManager
*/
function setLiquidationIncentive(uint256 newLiquidationIncentiveMantissa) external {
require(newLiquidationIncentiveMantissa >= MANTISSA_ONE, "liquidation incentive should be greater than 1e18");

Check warning on line 969 in contracts/Comptroller.sol

View workflow job for this annotation

GitHub Actions / Lint

Use Custom Errors instead of require statements

_checkAccessAllowed("setLiquidationIncentive(uint256)");

Expand Down Expand Up @@ -1214,17 +1257,6 @@

/*** Assets You Are In ***/

/**
* @notice Returns the assets an account has entered
* @param account The address of the account to pull assets for
* @return A list with the assets the account has entered
*/
function getAssetsIn(address account) external view returns (VToken[] memory) {
VToken[] memory assetsIn = accountAssets[account];

return assetsIn;
}

/**
* @notice Returns whether the given account is entered in a given market
* @param account The address of the account to check
Expand Down Expand Up @@ -1316,7 +1348,7 @@
* @param account Address of the account to get associated tokens with
*/
function updatePrices(address account) public {
VToken[] memory vTokens = accountAssets[account];
VToken[] memory vTokens = getAssetsIn(account);
uint256 vTokensCount = vTokens.length;

ResilientOracleInterface oracle_ = oracle;
Expand All @@ -1336,6 +1368,33 @@
return _actionPaused[market][action];
}

/**
* @notice Returns the assets an account has entered
* @param account The address of the account to pull assets for
* @return A list with the assets the account has entered
*/
function getAssetsIn(address account) public view returns (VToken[] memory) {
uint256 len = 0;
for (uint256 i = 0; i < accountAssets[account].length; i++) {
Market storage market = markets[address(accountAssets[account][i])];
if (market.isListed) {
len++;
}
}

VToken[] memory assetsIn = new VToken[](len);
uint256 index = 0;
for (uint256 i = 0; i < accountAssets[account].length; i++) {
Market storage market = markets[address(accountAssets[account][i])];
if (market.isListed) {
assetsIn[index] = accountAssets[account][i];
index++;
}
}

web3rover marked this conversation as resolved.
Show resolved Hide resolved
return assetsIn;
}

/**
* @notice Add the market to the borrower's "assets in" for liquidity calculations
* @param vToken The market to enter
Expand Down Expand Up @@ -1465,7 +1524,7 @@
function(VToken) internal view returns (Exp memory) weight
) internal view returns (AccountLiquiditySnapshot memory snapshot) {
// For each asset the account is in
VToken[] memory assets = accountAssets[account];
VToken[] memory assets = getAssetsIn(account);
uint256 assetsCount = assets.length;

for (uint256 i; i < assetsCount; ++i) {
Expand Down
24 changes: 24 additions & 0 deletions deploy/017-deploy-comptroller.ts
Debugger022 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const poolRegistry = await ethers.getContract("PoolRegistry");

console.log(deployer);

await deploy("ComptrollerImpl", {
contract: "Comptroller",
from: deployer,
args: [poolRegistry.address],
log: true,
autoMine: true,
});
};

func.tags = ["ComptrollerUpgrade"];

export default func;
34 changes: 33 additions & 1 deletion deployments/bsctestnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
]
},
"ComptrollerImpl": {
"address": "0x329Bc34E6A46243d21955A4369cD66bdD52E6C22",
"address": "0x3cE617FCeb5e9Ed622F73b483aC7c94053795197",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -485,6 +485,19 @@
"name": "MarketSupported",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "contract VToken",
"name": "vToken",
"type": "address"
}
],
"name": "MarketUnlisted",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -2054,6 +2067,25 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "market",
"type": "address"
}
],
"name": "unlistMarket",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
199 changes: 123 additions & 76 deletions deployments/bsctestnet/ComptrollerImpl.json

Large diffs are not rendered by default.

Loading
Loading