generated from bgd-labs/bgd-forge-template
-
Notifications
You must be signed in to change notification settings - Fork 9
/
CapsPlusRiskStewardBase.s.sol
102 lines (90 loc) · 3.41 KB
/
CapsPlusRiskStewardBase.s.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import 'forge-std/Test.sol';
import {Script} from 'forge-std/Script.sol';
import {AaveGovernanceV2} from 'aave-address-book/AaveGovernanceV2.sol';
import {IPool} from 'aave-address-book/AaveV3.sol';
import {CapsPlusRiskSteward} from 'aave-helpers/riskstewards/CapsPlusRiskSteward.sol';
import {IAaveV3ConfigEngine} from 'aave-helpers/v3-config-engine/IAaveV3ConfigEngine.sol';
import {EngineFlags} from 'aave-helpers/v3-config-engine/EngineFlags.sol';
import {ProtocolV3TestBase, ReserveConfig} from 'aave-helpers/ProtocolV3TestBase.sol';
abstract contract CapsPlusRiskStewardBase is ProtocolV3TestBase {
error FailedUpdate();
IPool immutable POOL;
CapsPlusRiskSteward immutable STEWARD;
constructor(IPool pool, address steward) {
POOL = pool;
STEWARD = CapsPlusRiskSteward(steward);
}
function capsUpdates() internal pure virtual returns (IAaveV3ConfigEngine.CapsUpdate[] memory);
function name() internal pure virtual returns (string memory);
/**
* @notice This script doesn't broadcast as it's intended to be used via safe
*/
function run(bool broadcastToSafe) external {
// only needed as long as things are mocked
IAaveV3ConfigEngine.CapsUpdate[] memory updates = capsUpdates();
vm.startPrank(STEWARD.RISK_COUNCIL());
bytes memory callDatas = _simulateAndGenerateDiff(updates);
vm.stopPrank();
emit log_string('safe address');
emit log_address(STEWARD.RISK_COUNCIL());
emit log_string('steward address:');
emit log_address(address(STEWARD));
emit log_string('calldata:');
emit log_bytes(callDatas);
if (broadcastToSafe) {
_sendToSafe(callDatas);
}
}
function _simulateAndGenerateDiff(
IAaveV3ConfigEngine.CapsUpdate[] memory capUpdates
) internal returns (bytes memory) {
string memory pre = string(abi.encodePacked('pre_', name()));
string memory post = string(abi.encodePacked('post_', name()));
createConfigurationSnapshot(pre, POOL, true, false, false, false);
bytes memory callDatas = abi.encodeWithSelector(
CapsPlusRiskSteward.updateCaps.selector,
capUpdates
);
bool success;
bytes memory resultData;
(success, resultData) = address(STEWARD).call(callDatas);
_verifyCallResult(success, resultData);
createConfigurationSnapshot(post, POOL, true, false, false, false);
diffReports(pre, post);
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();
}
}
}
}