Skip to content

Commit

Permalink
add pause spells and rename to execute() to be more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
hexonaut committed Dec 2, 2023
1 parent ec0a517 commit fb9b050
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/spells/EmergencySpell_SparkLend_FreezeAllAssets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract EmergencySpell_SparkLend_FreezeAllAssets {
sparkLendFreezerMom = sparklendFreezerMom_;
}

function freeze() external {
function execute() external {
require(!executed, "FreezeAllAssetsSpell/already-executed");
executed = true;
ISparkLendFreezerMom(sparkLendFreezerMom).freezeAllMarkets(true);
Expand Down
2 changes: 1 addition & 1 deletion src/spells/EmergencySpell_SparkLend_FreezeSingleAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract EmergencySpell_SparkLend_FreezeSingleAsset {
reserve = reserve_;
}

function freeze() external {
function execute() external {
require(!executed, "FreezeSingleAssetSpell/already-executed");
executed = true;
ISparkLendFreezerMom(sparkLendFreezerMom).freezeMarket(reserve, true);
Expand Down
22 changes: 22 additions & 0 deletions src/spells/EmergencySpell_SparkLend_PauseAllAssets.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.13;

import { ISparkLendFreezerMom } from "src/interfaces/ISparkLendFreezerMom.sol";

contract EmergencySpell_SparkLend_PauseAllAssets {

address public immutable sparkLendFreezerMom;

bool public executed;

constructor(address sparklendFreezerMom_) {
sparkLendFreezerMom = sparklendFreezerMom_;
}

function freeze() external {
require(!executed, "PauseAllAssetsSpell/already-executed");
executed = true;
ISparkLendFreezerMom(sparkLendFreezerMom).pauseAllMarkets(true);
}

}
24 changes: 24 additions & 0 deletions src/spells/EmergencySpell_SparkLend_PauseSingleAsset.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.13;

import { ISparkLendFreezerMom } from "src/interfaces/ISparkLendFreezerMom.sol";

contract EmergencySpell_SparkLend_PauseSingleAsset {

address public immutable sparkLendFreezerMom;
address public immutable reserve;

bool public executed;

constructor(address sparklendFreezerMom_, address reserve_) {
sparkLendFreezerMom = sparklendFreezerMom_;
reserve = reserve_;
}

function execute() external {
require(!executed, "PauseSingleAssetSpell/already-executed");
executed = true;
ISparkLendFreezerMom(sparkLendFreezerMom).pauseMarket(reserve, true);
}

}
20 changes: 10 additions & 10 deletions test/IntegrationTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ contract FreezeSingleAssetSpellFailures is IntegrationTestsBase {
);

vm.expectRevert("SparkLendFreezerMom/not-authorized");
freezeAssetSpell.freeze();
freezeAssetSpell.execute();
}

function test_cannotCallWithoutRoleSetup() external {
Expand All @@ -232,7 +232,7 @@ contract FreezeSingleAssetSpellFailures is IntegrationTestsBase {
);

vm.expectRevert(bytes("4")); // CALLER_NOT_RISK_OR_POOL_ADMIN
freezeAssetSpell.freeze();
freezeAssetSpell.execute();
}

function test_cannotCallTwice() external {
Expand All @@ -251,10 +251,10 @@ contract FreezeSingleAssetSpellFailures is IntegrationTestsBase {
);

vm.startPrank(randomUser); // Demonstrate no ACL in spell
freezeAssetSpell.freeze();
freezeAssetSpell.execute();

vm.expectRevert("FreezeSingleAssetSpell/already-executed");
freezeAssetSpell.freeze();
freezeAssetSpell.execute();
}

}
Expand All @@ -279,7 +279,7 @@ contract FreezeAllAssetsSpellFailures is IntegrationTestsBase {
);

vm.expectRevert("SparkLendFreezerMom/not-authorized");
freezeAllAssetsSpell.freeze();
freezeAllAssetsSpell.execute();
}

function test_cannotCallWithoutRoleSetup() external {
Expand All @@ -295,7 +295,7 @@ contract FreezeAllAssetsSpellFailures is IntegrationTestsBase {
);

vm.expectRevert(bytes("4")); // CALLER_NOT_RISK_OR_POOL_ADMIN
freezeAllAssetsSpell.freeze();
freezeAllAssetsSpell.execute();
}

function test_cannotCallTwice() external {
Expand All @@ -314,10 +314,10 @@ contract FreezeAllAssetsSpellFailures is IntegrationTestsBase {
);

vm.startPrank(randomUser); // Demonstrate no ACL in spell
freezeAllAssetsSpell.freeze();
freezeAllAssetsSpell.execute();

vm.expectRevert("FreezeAllAssetsSpell/already-executed");
freezeAllAssetsSpell.freeze();
freezeAllAssetsSpell.execute();
}

}
Expand Down Expand Up @@ -381,7 +381,7 @@ contract FreezeSingleAssetSpellTest is IntegrationTestsBase {
assertEq(FreezeSingleAssetSpell(freezeAssetSpell).executed(), false);

vm.prank(randomUser); // Demonstrate no ACL in spell
FreezeSingleAssetSpell(freezeAssetSpell).freeze();
FreezeSingleAssetSpell(freezeAssetSpell).execute();

assertEq(FreezeSingleAssetSpell(freezeAssetSpell).executed(), true);

Expand Down Expand Up @@ -469,7 +469,7 @@ contract FreezeAllAssetsSpellTest is IntegrationTestsBase {

// Freeze all assets in the protocol
vm.prank(randomUser); // Demonstrate no ACL in spell
FreezeAllAssetsSpell(freezeAllAssetsSpell).freeze();
FreezeAllAssetsSpell(freezeAllAssetsSpell).execute();

assertEq(FreezeAllAssetsSpell(freezeAllAssetsSpell).executed(), true);

Expand Down

0 comments on commit fb9b050

Please sign in to comment.