Skip to content

Commit

Permalink
Split whitelists in 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nezouse committed Apr 24, 2024
1 parent d1ad4c0 commit 4b2c00d
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 38 deletions.
27 changes: 21 additions & 6 deletions contracts/AdminContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ contract AdminContract is IAdminContract, UUPSUpgradeable, OwnableUpgradeable, A
*/
mapping(address => CollateralParams) internal collateralParams;

mapping(address => bool) internal whitelistedRedeemers;
mapping(address => bool) internal whitelistedLiquidators;

mapping(address => mapping(address => bool)) internal collateralWhitelistedAddresses;

// list of all collateral types in collateralParams (active and deprecated)
// Addresses for easy access
Expand Down Expand Up @@ -248,9 +250,18 @@ contract AdminContract is IAdminContract, UUPSUpgradeable, OwnableUpgradeable, A
emit RedemptionBlockTimestampChanged(_collateral, _blockTimestamp);
}

function setWhitelistedRedeemer(address _redeemer, bool _whitelisted) external onlyTimelock {
whitelistedRedeemers[_redeemer] = _whitelisted;
emit RedeemerWhitelisted(_redeemer, _whitelisted);
function setWhitelistedLiquidator(address _liquidator, bool _whitelisted) external onlyTimelock {
whitelistedLiquidators[_liquidator] = _whitelisted;
emit LiquidatorWhitelisted(_liquidator, _whitelisted);
}

function setAddressCollateralWhitelisted(
address _collateral,
address _address,
bool _whitelisted
) external onlyTimelock {
collateralWhitelistedAddresses[_collateral][_address] = _whitelisted;
emit CollateralAddressWhitelisted(_collateral, _address, _whitelisted);
}

function setRedemptionBaseFeeEnabled(address _collateral, bool _enabled) external onlyTimelock {
Expand Down Expand Up @@ -329,8 +340,12 @@ contract AdminContract is IAdminContract, UUPSUpgradeable, OwnableUpgradeable, A
return IActivePool(activePool).getDebtTokenBalance(_asset) + IDefaultPool(defaultPool).getDebtTokenBalance(_asset);
}

function getRedeemerIsWhitelisted(address _redeemer) external view returns (bool) {
return whitelistedRedeemers[_redeemer];
function getLiquidatorIsWhitelisted(address _liquidator) external view returns (bool) {
return whitelistedLiquidators[_liquidator];
}

function getCollateralAddressIsWhitelisted(address _collateral, address _address) external view returns (bool) {
return collateralWhitelistedAddresses[_collateral][_address];
}

function getRedemptionBaseFeeEnabled(address _collateral) external view override returns (bool) {
Expand Down
9 changes: 6 additions & 3 deletions contracts/Interfaces/IAdminContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ interface IAdminContract {
event RedemptionFeeFloorChanged(uint256 oldRedemptionFeeFloor, uint256 newRedemptionFeeFloor);
event MintCapChanged(uint256 oldMintCap, uint256 newMintCap);
event RedemptionBlockTimestampChanged(address _collateral, uint256 _blockTimestamp);
event RedeemerWhitelisted(address _redeemer, bool _whitelisted);
event LiquidatorWhitelisted(address _redeemer, bool _whitelisted);
event CollateralAddressWhitelisted(address _collateral, address _address, bool _whitelisted);
event BaseFeeEnabledChanged(address _collateral, bool _enabled);

// Functions --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -81,7 +82,7 @@ interface IAdminContract {

function setRedemptionBlockTimestamp(address _collateral, uint256 _blockTimestamp) external;

function setWhitelistedRedeemer(address _redeemer, bool _whitelisted) external;
function setWhitelistedLiquidator(address _redeemer, bool _whitelisted) external;

function setRedemptionBaseFeeEnabled(address _collateral, bool _enabled) external;

Expand Down Expand Up @@ -111,7 +112,9 @@ interface IAdminContract {

function getTotalAssetDebt(address _asset) external view returns (uint256);

function getRedeemerIsWhitelisted(address _redeemer) external view returns (bool);
function getLiquidatorIsWhitelisted(address _liquidator) external view returns (bool);

function getCollateralAddressIsWhitelisted(address _collateral, address _address) external view returns (bool);

function getRedemptionBaseFeeEnabled(address _collateral) external view returns (bool);
}
6 changes: 2 additions & 4 deletions contracts/Interfaces/IVesselManagerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ interface IVesselManagerOperations is ITrinityBase {
IVesselManager.VesselManagerOperation _operation
);

event RedemptionSoftenParamChanged(
uint256 _redemptionSofteningParam
);
event RedemptionSoftenParamChanged(uint256 _redemptionSofteningParam);

// Custom Errors ----------------------------------------------------------------------------------------------------

Expand All @@ -51,7 +49,7 @@ interface IVesselManagerOperations is ITrinityBase {
error VesselManagerOperations__InvalidParam();
error VesselManagerOperations__NotTimelock();
error VesselManagerOperations__LiquidatorNotWhitelisted();
error VesselManagerOperations__RedemptorNotWhitelisted();
error VesselManagerOperations__CollateralAddressNotWhitelisted();

// Structs ----------------------------------------------------------------------------------------------------------

Expand Down
8 changes: 4 additions & 4 deletions contracts/VesselManagerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
* starting from the one with the lowest collateral ratio in the system, and moving upwards.
*/
function liquidateVessels(address _asset, uint256 _n) external override nonReentrant {
if (!IAdminContract(adminContract).getRedeemerIsWhitelisted(msg.sender)) {
if (!IAdminContract(adminContract).getLiquidatorIsWhitelisted(msg.sender)) {
revert VesselManagerOperations__LiquidatorNotWhitelisted();
}

Expand Down Expand Up @@ -114,7 +114,7 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
* Attempt to liquidate a custom list of vessels provided by the caller.
*/
function batchLiquidateVessels(address _asset, address[] memory _vesselArray) public override nonReentrant {
if (!IAdminContract(adminContract).getRedeemerIsWhitelisted(msg.sender)) {
if (!IAdminContract(adminContract).getLiquidatorIsWhitelisted(msg.sender)) {
revert VesselManagerOperations__LiquidatorNotWhitelisted();
}
if (_vesselArray.length == 0 || _vesselArray.length > BATCH_SIZE_LIMIT) {
Expand Down Expand Up @@ -877,8 +877,8 @@ contract VesselManagerOperations is IVesselManagerOperations, UUPSUpgradeable, R
uint256 _price
) internal view {
address redeemer = msg.sender;
if (!IAdminContract(adminContract).getRedeemerIsWhitelisted(redeemer)) {
revert VesselManagerOperations__RedemptorNotWhitelisted();
if (!IAdminContract(adminContract).getCollateralAddressIsWhitelisted(_asset, redeemer)) {
revert VesselManagerOperations__CollateralAddressNotWhitelisted();
}

uint256 redemptionBlockTimestamp = IAdminContract(adminContract).getRedemptionBlockTimestamp(_asset);
Expand Down
28 changes: 20 additions & 8 deletions test/trinity/AdminContractTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,28 @@ contract("AdminContract", async accounts => {
assert.isTrue(_USDVFee_Asset.eq(expectedFee_Asset))
})

it('setRedeemerWhitelisted: Owner change parameter - Valid Owner', async () => {
await adminContract.setWhitelistedRedeemer(ZERO_ADDRESS, true)
assert.isTrue(await adminContract.getRedeemerIsWhitelisted(ZERO_ADDRESS))
await adminContract.setWhitelistedRedeemer(ZERO_ADDRESS, false)
assert.isFalse(await adminContract.getRedeemerIsWhitelisted(ZERO_ADDRESS))
it('setLiquidatorWhitelisted: Owner change parameter - Valid Owner', async () => {
await adminContract.setWhitelistedLiquidator(ZERO_ADDRESS, true)
assert.isTrue(await adminContract.getLiquidatorIsWhitelisted(ZERO_ADDRESS))
await adminContract.setWhitelistedLiquidator(ZERO_ADDRESS, false)
assert.isFalse(await adminContract.getLiquidatorIsWhitelisted(ZERO_ADDRESS))
})

it('setRedeemerWhitelisted: Owner change parameter - Invalid Owner', async () => {
await assertRevert(adminContract.setWhitelistedRedeemer(ZERO_ADDRESS, true, {from: user}))
await assertRevert(adminContract.setWhitelistedRedeemer(ZERO_ADDRESS, false, {from: user}))
it('setLiquidatorWhitelisted: Owner change parameter - Invalid Owner', async () => {
await assertRevert(adminContract.setWhitelistedLiquidator(ZERO_ADDRESS, true, {from: user}))
await assertRevert(adminContract.setWhitelistedLiquidator(ZERO_ADDRESS, false, {from: user}))
})

it('setAddressCollateralWhitelisted: Owner change parameter - Valid Owner', async () => {
await adminContract.setAddressCollateralWhitelisted(erc20.address, ZERO_ADDRESS, true)
assert.isTrue(await adminContract.getCollateralAddressIsWhitelisted(erc20.address, ZERO_ADDRESS))
await adminContract.setAddressCollateralWhitelisted(erc20.address, ZERO_ADDRESS, false)
assert.isFalse(await adminContract.getCollateralAddressIsWhitelisted(erc20.address, ZERO_ADDRESS))
})

it('setAddressCollateralWhitelisted: Owner change parameter - Invalid Owner', async () => {
await assertRevert(adminContract.setAddressCollateralWhitelisted(erc20.address, ZERO_ADDRESS, true, {from: user}))
await assertRevert(adminContract.setAddressCollateralWhitelisted(erc20.address, ZERO_ADDRESS, false, {from: user}))
})

it('setRedemptionBaseFeeEnabled: Owner change parameter - Valid Owner', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/trinity/BorrowerOperationsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const deploy = async (treasury, mintingAccounts) => {
longTimelock = contracts.core.longTimelock

for(const account of mintingAccounts) {
await adminContract.setWhitelistedRedeemer(account, true)
await adminContract.setWhitelistedLiquidator(account, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/trinity/CollSurplusPoolTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract("CollSurplusPool", async accounts => {
await th.fastForwardTime(timeValues.SECONDS_IN_ONE_WEEK * 2, web3.currentProvider)

// At ETH:USD = 100, this redemption should leave 1 ether of coll surplus
await adminContract.setWhitelistedRedeemer(A, true)
await adminContract.setAddressCollateralWhitelisted(erc20.address, A, true)
await th.redeemCollateralAndGetTxObject(A, contracts.core, B_netDebt, erc20.address)

const ETH_2 = await collSurplusPool.getAssetBalance(erc20.address)
Expand Down
2 changes: 1 addition & 1 deletion test/trinity/GasCompensationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const deploy = async (treasury, mintingAccounts) => {
validCollateral = await adminContract.getValidCollateral()

for(const account of mintingAccounts) {
await adminContract.setWhitelistedRedeemer(account, true)
await adminContract.setWhitelistedLiquidator(account, true)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/trinity/StabilityPoolTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const deploy = async (treasury, mintingAccounts) => {
validCollateral = validCollateral.slice(0).sort((a, b) => toBN(a.toLowerCase()).sub(toBN(b.toLowerCase())))

for(const account of mintingAccounts) {
await adminContract.setWhitelistedRedeemer(account, true)
await adminContract.setWhitelistedLiquidator(account, true)
}
}

Expand Down
13 changes: 7 additions & 6 deletions test/trinity/VesselManagerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const deploy = async (treasury, mintingAccounts) => {
validCollateral = validCollateral.slice(0).sort((a, b) => toBN(a.toLowerCase()).sub(toBN(b.toLowerCase())))

for(const account of mintingAccounts) {
await adminContract.setWhitelistedRedeemer(account, true)
await adminContract.setWhitelistedLiquidator(account, true)
await adminContract.setAddressCollateralWhitelisted(erc20.address, account, true)
}
}

Expand Down Expand Up @@ -137,7 +138,7 @@ contract("VesselManager", async accounts => {
extraParams: { from: alice },
})

await adminContract.setWhitelistedRedeemer(alice, false)
await adminContract.setWhitelistedLiquidator(alice, false)

try {
const tx = await vesselManagerOperations.liquidate(erc20.address, alice, {from: alice})
Expand Down Expand Up @@ -1435,7 +1436,7 @@ contract("VesselManager", async accounts => {
// --- liquidateVessels() ---

it("liquidateVessels(): reverts when not whitelisted", async () => {
await adminContract.setWhitelistedRedeemer(alice, false)
await adminContract.setWhitelistedLiquidator(alice, false)

try {
const tx = await vesselManagerOperations.liquidateVessels(erc20.address, 2, {from: alice})
Expand Down Expand Up @@ -2477,7 +2478,7 @@ contract("VesselManager", async accounts => {

describe("Batch Liquidations", async () => {
it("batchLiquidateVessels(): reverts when not whitelisted", async () => {
await adminContract.setWhitelistedRedeemer(alice, false)
await adminContract.setWhitelistedLiquidator(alice, false)

try {
const tx = await vesselManagerOperations.batchLiquidateVessels(erc20.address, [], {from: alice})
Expand Down Expand Up @@ -4296,14 +4297,14 @@ contract("VesselManager", async accounts => {
// skip bootstrapping phase
await th.fastForwardTime(timeValues.SECONDS_IN_ONE_WEEK * 2, web3.currentProvider)

await adminContract.setWhitelistedRedeemer(alice, false)
await adminContract.setAddressCollateralWhitelisted(erc20.address, alice, false)

try {
const tx = await th.redeemCollateralAndGetTxObject(alice, contracts.core, dec(10, 18), erc20.address)
assert.isFalse(tx.receipt.status)
} catch (err) {
assert.include(err.message, "revert")
assert.include(err.message, "VesselManagerOperations__RedemptorNotWhitelisted()")
assert.include(err.message, "VesselManagerOperations__CollateralAddressNotWhitelisted()")
}
})

Expand Down
2 changes: 1 addition & 1 deletion test/trinity/VesselManager_LiquidationRewardsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const deploy = async (treasury, mintingAccounts) => {
longTimelock = contracts.core.longTimelock

for(const account of mintingAccounts) {
await adminContract.setWhitelistedRedeemer(account, true)
await adminContract.setWhitelistedLiquidator(account, true)
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/trinity/VesselManager_RecoveryModeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const deploy = async (treasury, mintingAccounts) => {
validCollateral = validCollateral.slice(0).sort((a, b) => toBN(a.toLowerCase()).sub(toBN(b.toLowerCase())))

for(const account of mintingAccounts) {
await adminContract.setWhitelistedRedeemer(account, true)
await adminContract.setWhitelistedLiquidator(account, true)
await adminContract.setAddressCollateralWhitelisted(erc20.address, account, true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const deploy = async (treasury, mintingAccounts) => {
validCollateral = validCollateral.slice(0).sort((a, b) => toBN(a.toLowerCase()).sub(toBN(b.toLowerCase())))

for(const account of mintingAccounts) {
await adminContract.setWhitelistedRedeemer(account, true)
await adminContract.setWhitelistedLiquidator(account, true)
}
}

Expand Down

0 comments on commit 4b2c00d

Please sign in to comment.