Skip to content

Commit

Permalink
feat: update to add executed boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-manuel committed Nov 21, 2023
1 parent 7462465 commit 856308c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/spells/EmergencySpell_SparkLend_FreezeAllAssets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ contract EmergencySpell_SparkLend_FreezeAllAssets {

address public immutable sparkLendFreezerMom;

bool public executed;

constructor(address sparklendFreezerMom_) {
sparkLendFreezerMom = sparklendFreezerMom_;
}

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

}
4 changes: 4 additions & 0 deletions src/spells/EmergencySpell_SparkLend_FreezeSingleAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ contract EmergencySpell_SparkLend_FreezeSingleAsset {
address public immutable sparkLendFreezerMom;
address public immutable reserve;

bool public executed;

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

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

}
54 changes: 53 additions & 1 deletion test/IntegrationTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@ contract FreezeSingleAssetSpellFailures is IntegrationTestsBase {
freezeAssetSpell.freeze();
}

function test_cannotCallTwice() external {
vm.prank(SPARK_PROXY);
aclManager.addRiskAdmin(address(freezer));

_vote(address(freezeAssetSpell));

assertTrue(authority.hat() == address(freezeAssetSpell));
assertTrue(
authority.canCall(
address(freezeAssetSpell),
address(freezer),
freezer.freezeMarket.selector
)
);

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

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

}

contract FreezeAllAssetsSpellFailures is IntegrationTestsBase {
Expand Down Expand Up @@ -276,6 +298,28 @@ contract FreezeAllAssetsSpellFailures is IntegrationTestsBase {
freezeAllAssetsSpell.freeze();
}

function test_cannotCallTwice() external {
vm.prank(SPARK_PROXY);
aclManager.addRiskAdmin(address(freezer));

_vote(address(freezeAllAssetsSpell));

assertTrue(authority.hat() == address(freezeAllAssetsSpell));
assertTrue(
authority.canCall(
address(freezeAllAssetsSpell),
address(freezer),
freezer.freezeMarket.selector
)
);

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

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

}

contract FreezeSingleAssetSpellTest is IntegrationTestsBase {
Expand Down Expand Up @@ -334,9 +378,13 @@ contract FreezeSingleAssetSpellTest is IntegrationTestsBase {
repayAmount
);

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

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

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

_checkUserActionsFrozen(
asset,
supplyAmount,
Expand Down Expand Up @@ -417,9 +465,13 @@ contract FreezeAllAssetsSpellTest is IntegrationTestsBase {

assertEq(untestedReserves.length, 0);

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

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

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

// Check that protocol is working as expected after the freeze spell for all assets
for (uint256 i = 0; i < reserves.length; i++) {
Expand Down

0 comments on commit 856308c

Please sign in to comment.