From c56cbc2c1493a0725383d0306fef93cc6446df5f Mon Sep 17 00:00:00 2001 From: Harsh Pandey Date: Sat, 30 Nov 2024 19:13:18 +0530 Subject: [PATCH] fix: base test contract and refactor folders --- lib/aave-helpers | 2 +- scripts/RiskStewardsBase.s.sol | 175 --------------- src/contracts/examples/ArbitrumExample.sol | 2 +- src/contracts/examples/AvalancheExample.sol | 2 +- src/contracts/examples/BNBExample.sol | 2 +- src/contracts/examples/BaseExample.sol | 2 +- src/contracts/examples/EthereumExample.sol | 2 +- .../examples/EthereumLidoExample.sol | 2 +- src/contracts/examples/GnosisExample.sol | 2 +- src/contracts/examples/MetisExample.sol | 2 +- src/contracts/examples/OptimismExample.sol | 2 +- src/contracts/examples/PolygonExample.sol | 2 +- src/contracts/examples/ScrollExample.sol | 2 +- .../payload-helpers/RiskStewardsBase.t.sol | 207 ++++++++++++++++++ .../networks/RiskStewardsArbitrum.t.sol | 2 +- .../networks/RiskStewardsAvalanche.t.sol | 2 +- .../networks/RiskStewardsBNB.t.sol | 2 +- .../networks/RiskStewardsBaseChain.t.sol | 2 +- .../networks/RiskStewardsEthereum.t.sol | 2 +- .../RiskStewardsEthereumEtherFi.t.sol | 2 +- .../networks/RiskStewardsEthereumLido.t.sol | 2 +- .../networks/RiskStewardsGnosis.t.sol | 2 +- .../networks/RiskStewardsMetis.t.sol | 2 +- .../networks/RiskStewardsOptimism.t.sol | 2 +- .../networks/RiskStewardsPolygon.t.sol | 2 +- .../networks/RiskStewardsScroll.t.sol | 2 +- 26 files changed, 231 insertions(+), 199 deletions(-) delete mode 100644 scripts/RiskStewardsBase.s.sol create mode 100644 src/contracts/payload-helpers/RiskStewardsBase.t.sol rename scripts/networks/RiskStewardsArbitrum.s.sol => src/contracts/payload-helpers/networks/RiskStewardsArbitrum.t.sol (82%) rename scripts/networks/RiskStewardsAvalanche.s.sol => src/contracts/payload-helpers/networks/RiskStewardsAvalanche.t.sol (83%) rename scripts/networks/RiskStewardsBNB.s.sol => src/contracts/payload-helpers/networks/RiskStewardsBNB.t.sol (81%) rename scripts/networks/RiskStewardsBaseChain.s.sol => src/contracts/payload-helpers/networks/RiskStewardsBaseChain.t.sol (82%) rename scripts/networks/RiskStewardsEthereum.s.sol => src/contracts/payload-helpers/networks/RiskStewardsEthereum.t.sol (82%) rename scripts/networks/RiskStewardsEthereumEtherFi.sol => src/contracts/payload-helpers/networks/RiskStewardsEthereumEtherFi.t.sol (84%) rename scripts/networks/RiskStewardsEthereumLido.s.sol => src/contracts/payload-helpers/networks/RiskStewardsEthereumLido.t.sol (83%) rename scripts/networks/RiskStewardsGnosis.s.sol => src/contracts/payload-helpers/networks/RiskStewardsGnosis.t.sol (82%) rename scripts/networks/RiskStewardsMetis.s.sol => src/contracts/payload-helpers/networks/RiskStewardsMetis.t.sol (82%) rename scripts/networks/RiskStewardsOptimism.s.sol => src/contracts/payload-helpers/networks/RiskStewardsOptimism.t.sol (82%) rename scripts/networks/RiskStewardsPolygon.s.sol => src/contracts/payload-helpers/networks/RiskStewardsPolygon.t.sol (82%) rename scripts/networks/RiskStewardsScroll.s.sol => src/contracts/payload-helpers/networks/RiskStewardsScroll.t.sol (82%) diff --git a/lib/aave-helpers b/lib/aave-helpers index 1bc10cd..12b604d 160000 --- a/lib/aave-helpers +++ b/lib/aave-helpers @@ -1 +1 @@ -Subproject commit 1bc10cd4f291c05af78021d87fea3cb079d1394c +Subproject commit 12b604d8ae104bc6b232ce882590e350d77703d8 diff --git a/scripts/RiskStewardsBase.s.sol b/scripts/RiskStewardsBase.s.sol deleted file mode 100644 index b90bff5..0000000 --- a/scripts/RiskStewardsBase.s.sol +++ /dev/null @@ -1,175 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {IAaveV3ConfigEngine as IEngine, IPool} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; -import {IRiskSteward} from '../src/interfaces/IRiskSteward.sol'; -import {ProtocolV3TestBase} from 'aave-helpers/src/ProtocolV3TestBase.sol'; -import {IOwnable} from 'aave-address-book/common/IOwnable.sol'; -import {IACLManager} from 'aave-address-book/AaveV3.sol'; - -abstract contract RiskStewardsBase is ProtocolV3TestBase { - error FailedUpdate(); - IPool immutable POOL; - IRiskSteward immutable STEWARD; - - uint8 public constant MAX_TX = 5; - - constructor(address pool, address steward) { - POOL = IPool(pool); - STEWARD = IRiskSteward(steward); - } - - function capsUpdates() public pure virtual returns (IEngine.CapsUpdate[] memory) {} - - function collateralsUpdates() public pure virtual returns (IEngine.CollateralUpdate[] memory) {} - - function rateStrategiesUpdates() - public - pure - virtual - returns (IEngine.RateStrategyUpdate[] memory) - {} - - function lstPriceCapsUpdates() public pure virtual returns (IRiskSteward.PriceCapLstUpdate[] memory) {} - - function stablePriceCapsUpdates() public pure virtual returns (IRiskSteward.PriceCapStableUpdate[] memory) {} - - function name() public pure virtual returns (string memory); - - /** - * @notice This script doesn't broadcast as it's intended to be used via safe - */ - function run(bool broadcastToSafe, bool generateDiffReport) external { - vm.startPrank(STEWARD.RISK_COUNCIL()); - bytes[] memory callDatas = _simulateAndGenerateDiff(generateDiffReport); - vm.stopPrank(); - - if (callDatas.length > 1) emit log_string('** multiple calldatas emitted, please execute them all **'); - emit log_string('safe address'); - emit log_address(STEWARD.RISK_COUNCIL()); - emit log_string('steward address:'); - emit log_address(address(STEWARD)); - - for (uint8 i = 0; i < callDatas.length; i++) { - emit log_string('calldata:'); - emit log_bytes(callDatas[i]); - - if (broadcastToSafe) { - _sendToSafe(callDatas[i]); - } - } - } - - function _simulateAndGenerateDiff(bool generateDiffReport) internal returns (bytes[] memory) { - bytes[] memory callDatas = new bytes[](MAX_TX); - uint8 txCount; - - string memory pre = string(abi.encodePacked('pre_', name())); - string memory post = string(abi.encodePacked('post_', name())); - - IEngine.CapsUpdate[] memory capUpdates = capsUpdates(); - IEngine.CollateralUpdate[] memory collateralUpdates = collateralsUpdates(); - IEngine.RateStrategyUpdate[] memory rateUpdates = rateStrategiesUpdates(); - IRiskSteward.PriceCapLstUpdate[] memory lstPriceCapUpdates = lstPriceCapsUpdates(); - IRiskSteward.PriceCapStableUpdate[] memory stablePriceCapUpdates = stablePriceCapsUpdates(); - - bool rateUpdatesPresent = rateUpdates.length != 0; - if (generateDiffReport) createConfigurationSnapshot(pre, POOL, true, rateUpdatesPresent, false, false); - - if (capUpdates.length != 0) { - callDatas[txCount] = abi.encodeWithSelector( - IRiskSteward.updateCaps.selector, - capUpdates - ); - (bool success, bytes memory resultData) = address(STEWARD).call(callDatas[txCount]); - _verifyCallResult(success, resultData); - txCount++; - } - - if (collateralUpdates.length != 0) { - callDatas[txCount] = abi.encodeWithSelector( - IRiskSteward.updateCollateralSide.selector, - collateralUpdates - ); - (bool success, bytes memory resultData) = address(STEWARD).call(callDatas[txCount]); - _verifyCallResult(success, resultData); - txCount++; - } - - if (rateUpdates.length != 0) { - callDatas[txCount] = abi.encodeWithSelector( - IRiskSteward.updateRates.selector, - rateUpdates - ); - (bool success, bytes memory resultData) = address(STEWARD).call(callDatas[txCount]); - _verifyCallResult(success, resultData); - txCount++; - } - - if (lstPriceCapUpdates.length != 0) { - callDatas[txCount] = abi.encodeWithSelector( - IRiskSteward.updateLstPriceCaps.selector, - lstPriceCapUpdates - ); - (bool success, bytes memory resultData) = address(STEWARD).call(callDatas[txCount]); - _verifyCallResult(success, resultData); - txCount++; - } - - if (stablePriceCapUpdates.length != 0) { - callDatas[txCount] = abi.encodeWithSelector( - IRiskSteward.updateStablePriceCaps.selector, - stablePriceCapUpdates - ); - (bool success, bytes memory resultData) = address(STEWARD).call(callDatas[txCount]); - _verifyCallResult(success, resultData); - txCount++; - } - - if (generateDiffReport) { - createConfigurationSnapshot(post, POOL, true, rateUpdatesPresent, false, false); - diffReports(pre, post); - } - - // we defined the callDatas with MAX_TX size, we now squash it to the number of txs - assembly { - mstore(callDatas, txCount) - } - return callDatas; - } - - function _sendToSafe(bytes memory callDatas) internal { - string[] memory inputs = new string[](8); - inputs[0] = 'npx'; - inputs[1] = 'ts-node'; - inputs[2] = 'scripts/safe-helper.ts'; - inputs[3] = vm.toString(STEWARD.RISK_COUNCIL()); - inputs[4] = vm.toString(address(STEWARD)); - inputs[5] = vm.toString(callDatas); - inputs[6] = vm.toString(block.chainid); - inputs[7] = 'Call'; - vm.ffi(inputs); - } - - function _verifyCallResult( - bool success, - bytes memory returnData - ) private pure returns (bytes memory) { - if (success) { - return returnData; - } else { - // Look for revert reason and bubble it up if present - if (returnData.length > 0) { - // The easiest way to bubble the revert reason is using memory via assembly - - // solhint-disable-next-line no-inline-assembly - assembly { - let returndata_size := mload(returnData) - revert(add(32, returnData), returndata_size) - } - } else { - revert FailedUpdate(); - } - } - } -} diff --git a/src/contracts/examples/ArbitrumExample.sol b/src/contracts/examples/ArbitrumExample.sol index 6923c8c..c4ff4f7 100644 --- a/src/contracts/examples/ArbitrumExample.sol +++ b/src/contracts/examples/ArbitrumExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3ArbitrumAssets} from 'aave-address-book/AaveV3Arbitrum.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsArbitrum} from '../../../scripts/networks/RiskStewardsArbitrum.s.sol'; +import {RiskStewardsArbitrum} from '../payload-helpers/networks/RiskStewardsArbitrum.t.sol'; // make run-script network=arbitrum contract=src/contracts/examples/ArbitrumExample.sol:ArbitrumExample broadcast=false generate_diff=true contract ArbitrumExample is RiskStewardsArbitrum { diff --git a/src/contracts/examples/AvalancheExample.sol b/src/contracts/examples/AvalancheExample.sol index 8f9fd6c..0514112 100644 --- a/src/contracts/examples/AvalancheExample.sol +++ b/src/contracts/examples/AvalancheExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3AvalancheAssets} from 'aave-address-book/AaveV3Avalanche.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsAvalanche} from '../../../scripts/networks/RiskStewardsAvalanche.s.sol'; +import {RiskStewardsAvalanche} from '../payload-helpers/networks/RiskStewardsAvalanche.t.sol'; // make run-script network=avalanche contract=src/contracts/examples/AvalancheExample.sol:AvalancheExample broadcast=false generate_diff=true contract AvalancheExample is RiskStewardsAvalanche { diff --git a/src/contracts/examples/BNBExample.sol b/src/contracts/examples/BNBExample.sol index c032b59..8dbcdbe 100644 --- a/src/contracts/examples/BNBExample.sol +++ b/src/contracts/examples/BNBExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3BNBAssets} from 'aave-address-book/AaveV3BNB.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsBNB} from '../../../scripts/networks/RiskStewardsBNB.s.sol'; +import {RiskStewardsBNB} from '../payload-helpers/networks/RiskStewardsBNB.t.sol'; // make run-script network=bnb contract=src/contracts/examples/BNBExample.sol:BNBExample broadcast=false generate_diff=true contract BNBExample is RiskStewardsBNB { diff --git a/src/contracts/examples/BaseExample.sol b/src/contracts/examples/BaseExample.sol index d2cedf4..4baf177 100644 --- a/src/contracts/examples/BaseExample.sol +++ b/src/contracts/examples/BaseExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3BaseAssets} from 'aave-address-book/AaveV3Base.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsBaseChain} from '../../../scripts/networks/RiskStewardsBaseChain.s.sol'; +import {RiskStewardsBaseChain} from '../payload-helpers/networks/RiskStewardsBaseChain.t.sol'; // make run-script network=base contract=src/contracts/examples/BaseExample.sol:BaseExample broadcast=false generate_diff=true contract BaseExample is RiskStewardsBaseChain { diff --git a/src/contracts/examples/EthereumExample.sol b/src/contracts/examples/EthereumExample.sol index 7006b41..b0ebfc1 100644 --- a/src/contracts/examples/EthereumExample.sol +++ b/src/contracts/examples/EthereumExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsEthereum} from '../../../scripts/networks/RiskStewardsEthereum.s.sol'; +import {RiskStewardsEthereum} from '../payload-helpers/networks/RiskStewardsEthereum.t.sol'; import {IRiskSteward, IPriceCapAdapter} from '../../interfaces/IRiskSteward.sol'; // make run-script network=mainnet contract=src/contracts/examples/EthereumExample.sol:EthereumExample broadcast=false generate_diff=true diff --git a/src/contracts/examples/EthereumLidoExample.sol b/src/contracts/examples/EthereumLidoExample.sol index 040f7e7..7b6bf1e 100644 --- a/src/contracts/examples/EthereumLidoExample.sol +++ b/src/contracts/examples/EthereumLidoExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3EthereumLidoAssets} from 'aave-address-book/AaveV3EthereumLido.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsEthereumLido} from '../../../scripts/networks/RiskStewardsEthereumLido.s.sol'; +import {RiskStewardsEthereumLido} from '../payload-helpers/networks/RiskStewardsEthereumLido.t.sol'; // make run-script network=mainnet contract=src/contracts/examples/EthereumLidoExample.sol:EthereumLidoExample broadcast=false generate_diff=true contract EthereumLidoExample is RiskStewardsEthereumLido { diff --git a/src/contracts/examples/GnosisExample.sol b/src/contracts/examples/GnosisExample.sol index 3e78098..d338a75 100644 --- a/src/contracts/examples/GnosisExample.sol +++ b/src/contracts/examples/GnosisExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3GnosisAssets} from 'aave-address-book/AaveV3Gnosis.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsGnosis} from '../../../scripts/networks/RiskStewardsGnosis.s.sol'; +import {RiskStewardsGnosis} from '../payload-helpers/networks/RiskStewardsGnosis.t.sol'; // make run-script network=gnosis contract=src/contracts/examples/GnosisExample.sol:GnosisExample broadcast=false generate_diff=true contract GnosisExample is RiskStewardsGnosis { diff --git a/src/contracts/examples/MetisExample.sol b/src/contracts/examples/MetisExample.sol index 10c68da..6a58fe1 100644 --- a/src/contracts/examples/MetisExample.sol +++ b/src/contracts/examples/MetisExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3MetisAssets} from 'aave-address-book/AaveV3Metis.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsMetis} from '../../../scripts/networks/RiskStewardsMetis.s.sol'; +import {RiskStewardsMetis} from '../payload-helpers/networks/RiskStewardsMetis.t.sol'; // make run-script network=metis contract=src/contracts/examples/MetisExample.sol:MetisExample broadcast=false generate_diff=true contract MetisExample is RiskStewardsMetis { diff --git a/src/contracts/examples/OptimismExample.sol b/src/contracts/examples/OptimismExample.sol index 2a93567..8923447 100644 --- a/src/contracts/examples/OptimismExample.sol +++ b/src/contracts/examples/OptimismExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3OptimismAssets} from 'aave-address-book/AaveV3Optimism.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsOptimism} from '../../../scripts/networks/RiskStewardsOptimism.s.sol'; +import {RiskStewardsOptimism} from '../payload-helpers/networks/RiskStewardsOptimism.t.sol'; // make run-script network=optimism contract=src/contracts/examples/OptimismExample.sol:OptimismExample broadcast=false generate_diff=true contract OptimismExample is RiskStewardsOptimism { diff --git a/src/contracts/examples/PolygonExample.sol b/src/contracts/examples/PolygonExample.sol index 652e3ef..35df534 100644 --- a/src/contracts/examples/PolygonExample.sol +++ b/src/contracts/examples/PolygonExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3PolygonAssets} from 'aave-address-book/AaveV3Polygon.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsPolygon} from '../../../scripts/networks/RiskStewardsPolygon.s.sol'; +import {RiskStewardsPolygon} from '../payload-helpers/networks/RiskStewardsPolygon.t.sol'; // make run-script network=polygon contract=src/contracts/examples/PolygonExample.sol:PolygonExample broadcast=false generate_diff=true contract PolygonExample is RiskStewardsPolygon { diff --git a/src/contracts/examples/ScrollExample.sol b/src/contracts/examples/ScrollExample.sol index 5cb1af3..7723d72 100644 --- a/src/contracts/examples/ScrollExample.sol +++ b/src/contracts/examples/ScrollExample.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import {AaveV3ScrollAssets} from 'aave-address-book/AaveV3Scroll.sol'; import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol'; -import {RiskStewardsScroll} from '../../../scripts/networks/RiskStewardsScroll.s.sol'; +import {RiskStewardsScroll} from '../payload-helpers/networks/RiskStewardsScroll.t.sol'; // make run-script network=scroll contract=src/contracts/examples/ScrollExample.sol:ScrollExample broadcast=false generate_diff=true contract ScrollExample is RiskStewardsScroll { diff --git a/src/contracts/payload-helpers/RiskStewardsBase.t.sol b/src/contracts/payload-helpers/RiskStewardsBase.t.sol new file mode 100644 index 0000000..f77c2fa --- /dev/null +++ b/src/contracts/payload-helpers/RiskStewardsBase.t.sol @@ -0,0 +1,207 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-address-book/governance-v3/IPayloadsControllerCore.sol'; +import {Executor} from '../dependencies/Executor.sol'; +import {TransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/TransparentProxyFactory.sol'; +import {PermissionedPayloadsController} from '../dependencies/PermissionedPayloadsController.sol'; +import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol'; +import {RiskSteward} from '../RiskSteward.sol'; + +import {IAaveV3ConfigEngine as IEngine, IPool} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol'; +import {IRiskSteward} from '../../interfaces/IRiskSteward.sol'; +import {ProtocolV3TestBase} from 'aave-helpers/src/ProtocolV3TestBase.sol'; +import {IOwnable} from 'aave-address-book/common/IOwnable.sol'; +import {IACLManager} from 'aave-address-book/AaveV3.sol'; + +abstract contract RiskStewardsBase is ProtocolV3TestBase { + error FailedUpdate(); + IPool immutable POOL; + IRiskSteward STEWARD; // TODO: make immutable once deployed + IPayloadsControllerCore PAYLOADS_CONTROLLER; // TODO: make immutable once deployed + address public constant PAYLOADS_MANAGER = address(490); // TOOD: remove once contracts are deployed + + uint8 public constant MAX_TX = 5; + + // TODO: remove once deployed + function setUp() public virtual { + _setupPermissionedPayloadsController(); + } + + constructor(address pool, address steward) { + POOL = IPool(pool); + STEWARD = IRiskSteward(steward); + } + + function capsUpdates() public pure virtual returns (IEngine.CapsUpdate[] memory) {} + + function collateralsUpdates() public pure virtual returns (IEngine.CollateralUpdate[] memory) {} + + function rateStrategiesUpdates() + public + pure + virtual + returns (IEngine.RateStrategyUpdate[] memory) + {} + + function lstPriceCapsUpdates() public pure virtual returns (IRiskSteward.PriceCapLstUpdate[] memory) {} + + function stablePriceCapsUpdates() public pure virtual returns (IRiskSteward.PriceCapStableUpdate[] memory) {} + + function name() public pure virtual returns (string memory); + + /** + * @notice This script doesn't broadcast as it's intended to be used via safe + */ + function test_run() external { + bool generateDiffReport = vm.envBool('GENERATE_DIFF'); + + _simulateAndGenerateDiff(generateDiffReport); + } + + function _simulateAndGenerateDiff(bool generateDiffReport) internal { + string memory pre = string(abi.encodePacked('pre_', name())); + string memory post = string(abi.encodePacked('post_', name())); + + vm.prank(PAYLOADS_MANAGER); + uint40 payloadId = PAYLOADS_CONTROLLER.createPayload(buildActions()); + + vm.warp(block.timestamp + 1 days + 1); + + if (generateDiffReport) createConfigurationSnapshot(pre, POOL, true, true, false, false); + + PAYLOADS_CONTROLLER.executePayload(payloadId); + + if (generateDiffReport) { + createConfigurationSnapshot(post, POOL, true, true, false, false); + diffReports(pre, post); + } + } + + function buildActions() public view returns (IPayloadsControllerCore.ExecutionAction[] memory) { + IPayloadsControllerCore.ExecutionAction[] + memory actions = new IPayloadsControllerCore.ExecutionAction[](MAX_TX); + uint256 actionsCount; + + IEngine.CapsUpdate[] memory capUpdates = capsUpdates(); + IEngine.CollateralUpdate[] memory collateralUpdates = collateralsUpdates(); + IEngine.RateStrategyUpdate[] memory rateUpdates = rateStrategiesUpdates(); + IRiskSteward.PriceCapLstUpdate[] memory lstPriceCapUpdates = lstPriceCapsUpdates(); + IRiskSteward.PriceCapStableUpdate[] memory stablePriceCapUpdates = stablePriceCapsUpdates(); + + if (capUpdates.length != 0) { + actions[actionsCount].target = address(STEWARD); + actions[actionsCount].accessLevel = PayloadsControllerUtils.AccessControl.Level_1; + actions[actionsCount].callData = abi.encodeWithSelector( + IRiskSteward.updateCaps.selector, + capUpdates + ); + actionsCount++; + } + + if (collateralUpdates.length != 0) { + actions[actionsCount].target = address(STEWARD); + actions[actionsCount].accessLevel = PayloadsControllerUtils.AccessControl.Level_1; + actions[actionsCount].callData = abi.encodeWithSelector( + IRiskSteward.updateCollateralSide.selector, + collateralUpdates + ); + actionsCount++; + } + + if (rateUpdates.length != 0) { + actions[actionsCount].target = address(STEWARD); + actions[actionsCount].accessLevel = PayloadsControllerUtils.AccessControl.Level_1; + actions[actionsCount].callData = abi.encodeWithSelector( + IRiskSteward.updateRates.selector, + rateUpdates + ); + actionsCount++; + } + + if (lstPriceCapUpdates.length != 0) { + actions[actionsCount].target = address(STEWARD); + actions[actionsCount].accessLevel = PayloadsControllerUtils.AccessControl.Level_1; + actions[actionsCount].callData = abi.encodeWithSelector( + IRiskSteward.updateLstPriceCaps.selector, + lstPriceCapUpdates + ); + actionsCount++; + } + + if (stablePriceCapUpdates.length != 0) { + actions[actionsCount].target = address(STEWARD); + actions[actionsCount].accessLevel = PayloadsControllerUtils.AccessControl.Level_1; + actions[actionsCount].callData = abi.encodeWithSelector( + IRiskSteward.updateStablePriceCaps.selector, + stablePriceCapUpdates + ); + actionsCount++; + } + + // we defined the actions with MAX_TX size, we now squash it to the number of txs + assembly { + mstore(actions, actionsCount) + } + + return actions; + } + + function _verifyCallResult( + bool success, + bytes memory returnData + ) private pure returns (bytes memory) { + if (success) { + return returnData; + } else { + // Look for revert reason and bubble it up if present + if (returnData.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + + // solhint-disable-next-line no-inline-assembly + assembly { + let returndata_size := mload(returnData) + revert(add(32, returnData), returndata_size) + } + } else { + revert FailedUpdate(); + } + } + } + + function _setupPermissionedPayloadsController() internal { + Executor executor = new Executor(); + address payloadsControllerImpl = address(new PermissionedPayloadsController()); + + IPayloadsControllerCore.UpdateExecutorInput[] + memory executorInput = new IPayloadsControllerCore.UpdateExecutorInput[](1); + executorInput[0].accessLevel = PayloadsControllerUtils.AccessControl.Level_1; + executorInput[0].executorConfig.executor = address(executor); + executorInput[0].executorConfig.delay = 1 days; + + TransparentProxyFactory proxyFactory = new TransparentProxyFactory(); + PAYLOADS_CONTROLLER = IPayloadsControllerCore( + proxyFactory.create( + address(payloadsControllerImpl), + ProxyAdmin(address(728)), + abi.encodeWithSelector( + PermissionedPayloadsController.initialize.selector, + address(659), + PAYLOADS_MANAGER, + executorInput + ) + ) + ); + executor.transferOwnership(address(PAYLOADS_CONTROLLER)); + + STEWARD = new RiskSteward( + STEWARD.POOL_DATA_PROVIDER(), + STEWARD.CONFIG_ENGINE(), + address(executor), + STEWARD.getRiskConfig() + ); + address aclManager = STEWARD.POOL_DATA_PROVIDER().ADDRESSES_PROVIDER().getACLManager(); + vm.prank(STEWARD.POOL_DATA_PROVIDER().ADDRESSES_PROVIDER().getACLAdmin()); + IACLManager(aclManager).addRiskAdmin(address(STEWARD)); + } +} diff --git a/scripts/networks/RiskStewardsArbitrum.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsArbitrum.t.sol similarity index 82% rename from scripts/networks/RiskStewardsArbitrum.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsArbitrum.t.sol index 9c72296..aca6858 100644 --- a/scripts/networks/RiskStewardsArbitrum.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsArbitrum.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Arbitrum} from 'aave-address-book/AaveV3Arbitrum.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsArbitrum is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsAvalanche.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsAvalanche.t.sol similarity index 83% rename from scripts/networks/RiskStewardsAvalanche.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsAvalanche.t.sol index c650fdf..82702e9 100644 --- a/scripts/networks/RiskStewardsAvalanche.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsAvalanche.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Avalanche} from 'aave-address-book/AaveV3Avalanche.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsAvalanche is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsBNB.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsBNB.t.sol similarity index 81% rename from scripts/networks/RiskStewardsBNB.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsBNB.t.sol index c48a491..3cd662b 100644 --- a/scripts/networks/RiskStewardsBNB.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsBNB.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3BNB} from 'aave-address-book/AaveV3BNB.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsBNB is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsBaseChain.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsBaseChain.t.sol similarity index 82% rename from scripts/networks/RiskStewardsBaseChain.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsBaseChain.t.sol index 773804d..fe34cd1 100644 --- a/scripts/networks/RiskStewardsBaseChain.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsBaseChain.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Base} from 'aave-address-book/AaveV3Base.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsBaseChain is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsEthereum.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsEthereum.t.sol similarity index 82% rename from scripts/networks/RiskStewardsEthereum.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsEthereum.t.sol index e639b85..63520db 100644 --- a/scripts/networks/RiskStewardsEthereum.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsEthereum.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Ethereum} from 'aave-address-book/AaveV3Ethereum.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsEthereum is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsEthereumEtherFi.sol b/src/contracts/payload-helpers/networks/RiskStewardsEthereumEtherFi.t.sol similarity index 84% rename from scripts/networks/RiskStewardsEthereumEtherFi.sol rename to src/contracts/payload-helpers/networks/RiskStewardsEthereumEtherFi.t.sol index d8e6844..0c3eae1 100644 --- a/scripts/networks/RiskStewardsEthereumEtherFi.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsEthereumEtherFi.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3EthereumEtherFi} from 'aave-address-book/AaveV3EthereumEtherFi.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsEthereumEtherFi is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsEthereumLido.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsEthereumLido.t.sol similarity index 83% rename from scripts/networks/RiskStewardsEthereumLido.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsEthereumLido.t.sol index 84beb59..6b15927 100644 --- a/scripts/networks/RiskStewardsEthereumLido.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsEthereumLido.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3EthereumLido} from 'aave-address-book/AaveV3EthereumLido.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsEthereumLido is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsGnosis.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsGnosis.t.sol similarity index 82% rename from scripts/networks/RiskStewardsGnosis.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsGnosis.t.sol index 2d4391d..e5e151d 100644 --- a/scripts/networks/RiskStewardsGnosis.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsGnosis.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Gnosis} from 'aave-address-book/AaveV3Gnosis.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsGnosis is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsMetis.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsMetis.t.sol similarity index 82% rename from scripts/networks/RiskStewardsMetis.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsMetis.t.sol index 301038a..4fda742 100644 --- a/scripts/networks/RiskStewardsMetis.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsMetis.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Metis} from 'aave-address-book/AaveV3Metis.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsMetis is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsOptimism.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsOptimism.t.sol similarity index 82% rename from scripts/networks/RiskStewardsOptimism.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsOptimism.t.sol index b7bb3e5..4bd92fb 100644 --- a/scripts/networks/RiskStewardsOptimism.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsOptimism.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Optimism} from 'aave-address-book/AaveV3Optimism.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsOptimism is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsPolygon.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsPolygon.t.sol similarity index 82% rename from scripts/networks/RiskStewardsPolygon.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsPolygon.t.sol index 3b3b9ee..dc462b7 100644 --- a/scripts/networks/RiskStewardsPolygon.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsPolygon.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Polygon} from 'aave-address-book/AaveV3Polygon.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsPolygon is RiskStewardsBase { constructor() diff --git a/scripts/networks/RiskStewardsScroll.s.sol b/src/contracts/payload-helpers/networks/RiskStewardsScroll.t.sol similarity index 82% rename from scripts/networks/RiskStewardsScroll.s.sol rename to src/contracts/payload-helpers/networks/RiskStewardsScroll.t.sol index ea779de..7537217 100644 --- a/scripts/networks/RiskStewardsScroll.s.sol +++ b/src/contracts/payload-helpers/networks/RiskStewardsScroll.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {AaveV3Scroll} from 'aave-address-book/AaveV3Scroll.sol'; -import {RiskStewardsBase} from '../RiskStewardsBase.s.sol'; +import {RiskStewardsBase} from '../RiskStewardsBase.t.sol'; abstract contract RiskStewardsScroll is RiskStewardsBase { constructor()