-
Notifications
You must be signed in to change notification settings - Fork 200
Unlist Market from eMode Pools #650
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -217,6 +217,18 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| require(_market.collateralFactorMantissa == 0, "collateral factor is not 0"); | ||
|
|
||
| _market.isListed = false; | ||
|
|
||
| for (uint96 i = lastPoolId; i > corePoolId; i--) { | ||
| address[] memory markets = getPoolVTokens(uint96(i)); | ||
|
|
||
| for (uint256 j = 0; j < markets.length; j++) { | ||
| if (markets[j] == market) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand this is to avoid a revert in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, let's avoid looping here which could waste ton of gas
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
| _removePoolMarket(i, market); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| emit MarketUnlisted(market); | ||
|
|
||
| return uint256(Error.NO_ERROR); | ||
|
|
@@ -409,27 +421,7 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| */ | ||
| function removePoolMarket(uint96 poolId, address vToken) external { | ||
| ensureAllowed("removePoolMarket(uint96,address)"); | ||
|
|
||
| if (poolId == corePoolId) revert InvalidOperationForCorePool(); | ||
| PoolMarketId index = getPoolMarketIndex(poolId, vToken); | ||
| if (!_poolMarkets[index].isListed) { | ||
| revert PoolMarketNotFound(poolId, vToken); | ||
| } | ||
|
|
||
| address[] storage assets = pools[poolId].vTokens; | ||
|
|
||
| uint256 length = assets.length; | ||
| for (uint256 i; i < length; i++) { | ||
| if (assets[i] == vToken) { | ||
| assets[i] = assets[length - 1]; | ||
| assets.pop(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| delete _poolMarkets[index]; | ||
|
|
||
| emit PoolMarketRemoved(poolId, vToken); | ||
| _removePoolMarket(poolId, vToken); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -507,7 +499,7 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| * @custom:error PoolDoesNotExist Reverts if the given pool ID do not exist. | ||
| * @custom:error InvalidOperationForCorePool Reverts if called on the Core Pool. | ||
| */ | ||
| function getPoolVTokens(uint96 poolId) external view returns (address[] memory) { | ||
| function getPoolVTokens(uint96 poolId) public view returns (address[] memory) { | ||
| if (poolId > lastPoolId) revert PoolDoesNotExist(poolId); | ||
| if (poolId == corePoolId) revert InvalidOperationForCorePool(); | ||
| return pools[poolId].vTokens; | ||
|
|
@@ -697,6 +689,29 @@ contract MarketFacet is IMarketFacet, FacetBase { | |
| emit PoolMarketInitialized(poolId, vToken); | ||
| } | ||
|
|
||
| function _removePoolMarket(uint96 poolId, address vToken) internal { | ||
| if (poolId == corePoolId) revert InvalidOperationForCorePool(); | ||
| PoolMarketId index = getPoolMarketIndex(poolId, vToken); | ||
| if (!_poolMarkets[index].isListed) { | ||
| revert PoolMarketNotFound(poolId, vToken); | ||
| } | ||
|
|
||
| address[] storage assets = pools[poolId].vTokens; | ||
|
|
||
| uint256 length = assets.length; | ||
| for (uint256 i; i < length; i++) { | ||
| if (assets[i] == vToken) { | ||
| assets[i] = assets[length - 1]; | ||
| assets.pop(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| delete _poolMarkets[index]; | ||
|
|
||
| emit PoolMarketRemoved(poolId, vToken); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Returns only the core risk parameters (CF, LI, LT) for a vToken in a specific pool. | ||
| * @dev If the pool is inactive, or if the vToken is not configured in the given pool and | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,6 +145,7 @@ describe("Comptroller: assetListTest", () => { | |
|
|
||
| const receipt = await comptroller.connect(customer).unlistMarket(unlistToken.address); | ||
| expect(receipt).to.emit(unitroller, "MarketUnlisted"); | ||
| expect(receipt).to.emit(unitroller, "PoolMarketRemoved"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see we already added an event check in the test. Could we also include a simple test to verify that an unlisted market is no longer present in any eMode pool ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
|
||
| const expectedError_ = expectedError || Error.NO_ERROR; | ||
| expect(reply).to.equal(expectedError_); | ||
|
|
@@ -326,6 +327,10 @@ describe("Comptroller: assetListTest", () => { | |
| true, | ||
| ); | ||
|
|
||
| const newLabel = "test-pool"; | ||
| await comptroller.createPool(newLabel); | ||
| await comptroller.addPoolMarkets([1], [OMG.address]); | ||
|
|
||
| await unlistAndCheckMarket(OMG, [BAT, ZRX], [OMG, BAT, ZRX]); | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We currently don’t allow adding a market to a pool that isn’t listed in the Core Pool. It might be better to set
_market.isListed = falseafter removing it from all pools (delisting from eMode). Functionally it doesn’t change behavior, but it aligns the logic more clearly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed