From fb9b050ba48f95774eb1a2122bf00cdc927697ec Mon Sep 17 00:00:00 2001 From: Sam MacPherson Date: Sat, 2 Dec 2023 11:14:58 -0500 Subject: [PATCH] add pause spells and rename to execute() to be more generic --- ...ergencySpell_SparkLend_FreezeAllAssets.sol | 2 +- ...gencySpell_SparkLend_FreezeSingleAsset.sol | 2 +- ...mergencySpell_SparkLend_PauseAllAssets.sol | 22 +++++++++++++++++ ...rgencySpell_SparkLend_PauseSingleAsset.sol | 24 +++++++++++++++++++ test/IntegrationTests.t.sol | 20 ++++++++-------- 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 src/spells/EmergencySpell_SparkLend_PauseAllAssets.sol create mode 100644 src/spells/EmergencySpell_SparkLend_PauseSingleAsset.sol diff --git a/src/spells/EmergencySpell_SparkLend_FreezeAllAssets.sol b/src/spells/EmergencySpell_SparkLend_FreezeAllAssets.sol index 6ba98d4..67d9718 100644 --- a/src/spells/EmergencySpell_SparkLend_FreezeAllAssets.sol +++ b/src/spells/EmergencySpell_SparkLend_FreezeAllAssets.sol @@ -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); diff --git a/src/spells/EmergencySpell_SparkLend_FreezeSingleAsset.sol b/src/spells/EmergencySpell_SparkLend_FreezeSingleAsset.sol index c55e674..28f4635 100644 --- a/src/spells/EmergencySpell_SparkLend_FreezeSingleAsset.sol +++ b/src/spells/EmergencySpell_SparkLend_FreezeSingleAsset.sol @@ -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); diff --git a/src/spells/EmergencySpell_SparkLend_PauseAllAssets.sol b/src/spells/EmergencySpell_SparkLend_PauseAllAssets.sol new file mode 100644 index 0000000..f8a016e --- /dev/null +++ b/src/spells/EmergencySpell_SparkLend_PauseAllAssets.sol @@ -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); + } + +} diff --git a/src/spells/EmergencySpell_SparkLend_PauseSingleAsset.sol b/src/spells/EmergencySpell_SparkLend_PauseSingleAsset.sol new file mode 100644 index 0000000..0daf2a4 --- /dev/null +++ b/src/spells/EmergencySpell_SparkLend_PauseSingleAsset.sol @@ -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); + } + +} diff --git a/test/IntegrationTests.t.sol b/test/IntegrationTests.t.sol index 249aea8..810e47d 100644 --- a/test/IntegrationTests.t.sol +++ b/test/IntegrationTests.t.sol @@ -216,7 +216,7 @@ contract FreezeSingleAssetSpellFailures is IntegrationTestsBase { ); vm.expectRevert("SparkLendFreezerMom/not-authorized"); - freezeAssetSpell.freeze(); + freezeAssetSpell.execute(); } function test_cannotCallWithoutRoleSetup() external { @@ -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 { @@ -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(); } } @@ -279,7 +279,7 @@ contract FreezeAllAssetsSpellFailures is IntegrationTestsBase { ); vm.expectRevert("SparkLendFreezerMom/not-authorized"); - freezeAllAssetsSpell.freeze(); + freezeAllAssetsSpell.execute(); } function test_cannotCallWithoutRoleSetup() external { @@ -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 { @@ -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(); } } @@ -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); @@ -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);