Skip to content

Commit

Permalink
feat: BotListV3 config functions are now one-way
Browse files Browse the repository at this point in the history
  • Loading branch information
lekhovitsky committed Aug 15, 2024
1 parent 53c99c6 commit d8486fb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
20 changes: 10 additions & 10 deletions contracts/core/BotListV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ contract BotListV3 is IBotListV3, SanityCheckTrait, Ownable {
return _botInfo[bot].forbidden;
}

/// @notice Sets `bot`'s status to `forbidden`
function setBotForbiddenStatus(address bot, bool forbidden) external override onlyOwner {
/// @notice Forbid's `bot`
function forbidBot(address bot) external override onlyOwner {
BotInfo storage info = _botInfo[bot];
if (info.forbidden != forbidden) {
info.forbidden = forbidden;
emit SetBotForbiddenStatus(bot, forbidden);
if (!info.forbidden) {
info.forbidden = true;
emit ForbidBot(bot);
}
}

/// @notice Sets `creditManager`'s status to `approved`
function setCreditManagerApprovedStatus(address creditManager, bool approved) external override onlyOwner {
if (approvedCreditManager[creditManager] != approved) {
approvedCreditManager[creditManager] = approved;
emit SetCreditManagerApprovedStatus(creditManager, approved);
/// @notice Approves `creditManager`
function approveCreditManager(address creditManager) external override onlyOwner {
if (!approvedCreditManager[creditManager]) {
approvedCreditManager[creditManager] = true;
emit ApproveCreditManager(creditManager);
}
}

Expand Down
12 changes: 6 additions & 6 deletions contracts/interfaces/IBotListV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ interface IBotListV3Events {
// CONFIGURATION //
// ------------- //

/// @notice Emitted when `bot`'s forbidden status is set
event SetBotForbiddenStatus(address indexed bot, bool forbidden);
/// @notice Emitted when `bot` is forbidden
event ForbidBot(address indexed bot);

/// @notice Emitted when `creditManager`'s approved status is set
event SetCreditManagerApprovedStatus(address indexed creditManager, bool approved);
/// @notice Emitted when `creditManager` is approved
event ApproveCreditManager(address indexed creditManager);
}

/// @title Bot list V3 interface
Expand Down Expand Up @@ -63,7 +63,7 @@ interface IBotListV3 is IBotListV3Events, IVersion {

function approvedCreditManager(address creditManager) external view returns (bool);

function setBotForbiddenStatus(address bot, bool forbidden) external;
function forbidBot(address bot) external;

function setCreditManagerApprovedStatus(address creditManager, bool approved) external;
function approveCreditManager(address creditManager) external;
}
2 changes: 1 addition & 1 deletion contracts/test/helpers/IntegrationTestHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager {
pool.setCreditManagerDebtLimit(address(creditManager), cmParams.poolLimit);

vm.prank(CONFIGURATOR);
botList.setCreditManagerApprovedStatus(address(creditManager), true);
botList.approveCreditManager(address(creditManager));

vm.label(address(creditFacade), "CreditFacadeV3");
vm.label(address(creditManager), "CreditManagerV3");
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/integration/credit/Bots.int.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ contract BotsIntegrationTest is IntegrationTestHelper, ICreditFacadeV3Events {
creditFacade.botMulticall(creditAccount, calls);

vm.prank(CONFIGURATOR);
botList.setBotForbiddenStatus(bot, true);
botList.forbidBot(bot);

vm.expectRevert(abi.encodeWithSelector(NotApprovedBotException.selector, (bot)));
vm.prank(bot);
Expand Down
12 changes: 5 additions & 7 deletions contracts/test/unit/core/BotListV3.unit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract BotListV3UnitTest is Test, IBotListV3Events {

botList = new BotListV3(CONFIGURATOR);
vm.prank(CONFIGURATOR);
botList.setCreditManagerApprovedStatus(creditManager, true);
botList.approveCreditManager(creditManager);
}

/// @notice U:[BL-1]: `setBotPermissions` works correctly
Expand All @@ -52,20 +52,18 @@ contract BotListV3UnitTest is Test, IBotListV3Events {
botList.setBotPermissions({bot: bot, creditAccount: creditAccount, permissions: type(uint192).max});

BotMock(bot).setRequiredPermissions(1);
BotMock(otherBot).setRequiredPermissions(1);

vm.expectRevert(IncorrectBotPermissionsException.selector);
vm.prank(creditFacade);
botList.setBotPermissions({bot: bot, creditAccount: creditAccount, permissions: 2});

vm.prank(CONFIGURATOR);
botList.setBotForbiddenStatus(bot, true);
botList.forbidBot(otherBot);

vm.expectRevert(InvalidBotException.selector);
vm.prank(creditFacade);
botList.setBotPermissions({bot: bot, creditAccount: creditAccount, permissions: 1});

vm.prank(CONFIGURATOR);
botList.setBotForbiddenStatus(bot, false);
botList.setBotPermissions({bot: otherBot, creditAccount: creditAccount, permissions: 1});

vm.expectEmit(true, true, true, true);
emit SetBotPermissions(bot, creditManager, creditAccount, 1);
Expand Down Expand Up @@ -94,7 +92,7 @@ contract BotListV3UnitTest is Test, IBotListV3Events {
assertEq(bots[0], bot, "Incorrect address added to active bots list");

vm.prank(CONFIGURATOR);
botList.setBotForbiddenStatus(bot, true);
botList.forbidBot(bot);

vm.expectEmit(true, true, true, true);
emit SetBotPermissions(bot, creditManager, creditAccount, 0);
Expand Down

0 comments on commit d8486fb

Please sign in to comment.