Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Caps update timelock error skip flag #22

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ git-diff :
deploy-ledger :; FOUNDRY_PROFILE=${chain} forge script $(if $(filter zksync,${chain}),--zksync) ${contract} --rpc-url ${chain} $(if ${dry},--sender 0x25F2226B597E8F9514B3F68F00f494cF4f286491 -vvvv, --ledger --mnemonic-indexes ${MNEMONIC_INDEX} --sender ${LEDGER_SENDER} --verify -vvvv --slow --broadcast)
deploy-pk :; FOUNDRY_PROFILE=${chain} forge script $(if $(filter zksync,${chain}),--zksync) ${contract} --rpc-url ${chain} $(if ${dry},--sender 0x25F2226B597E8F9514B3F68F00f494cF4f286491 -vvvv, --private-key ${PRIVATE_KEY} --verify -vvvv --slow --broadcast)

run-script:; FOUNDRY_PROFILE=${network} forge script ${contract} --rpc-url ${network} --sig "run(bool, bool)" ${broadcast} ${generate_diff} -vv
run-script:; FOUNDRY_PROFILE=${network} forge script ${contract} --rpc-url ${network} --sig "run(bool, bool, bool)" ${broadcast} ${generate_diff} ${skip_timelock} -vv
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ $ tsx generator/cli

The generator generates the scripts for doing the updates in `src/contracts/updates` directory.

The script can be executed by running: `make run-script network=mainnet contract_path=src/contracts/examples/EthereumExample.sol:EthereumExample broadcast=false generate_diff=true` where the bool inside the `broadcast=` determines if the calldata should be sent to safe and `generate_diff=` determines if diff report should be generated. The script also emits the calldata for doing the update in the console which can be used on the safe manually as well.
The script can be executed by running: `make run-script network=mainnet contract_path=src/contracts/examples/EthereumExample.sol:EthereumExample broadcast=false generate_diff=true skip_timelock=false` where:

- `broadcast=` determines if the calldata should be sent to safe
- `generate_diff=` determines if diff report should be generated
- `skip_timelock=` determines if timelock errors should revert the script, helpful in generating diff report / calldata when the current timelock has not ended.

The script also emits the calldata for doing the update in the console which can be used on the safe manually as well.

### Before I will submit anything to sign, how do I test out the update, or get visibility from what will happen?

Expand Down
2 changes: 1 addition & 1 deletion generator/templates/proposal.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const proposalTemplate = (
* - discussion: ${discussion || 'TODO'}
* - deploy-command: make run-script contract=src/contracts/updates/${folderName}/${contractName}.sol:${contractName} network=${getChainAlias(
chain
)} broadcast=false generate_diff=true
)} broadcast=false generate_diff=true skip_timelock=false
*/
contract ${contractName} is ${`RiskStewards${chain === 'Base' ? 'BaseChain' : chain}`} {
function name() public pure override returns (string memory) {
Expand Down
78 changes: 63 additions & 15 deletions scripts/RiskStewardsBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,32 @@ abstract contract RiskStewardsBase is ProtocolV3TestBase {
returns (IEngine.RateStrategyUpdate[] memory)
{}

function lstPriceCapsUpdates() public pure virtual returns (IRiskSteward.PriceCapLstUpdate[] memory) {}
function lstPriceCapsUpdates()
public
pure
virtual
returns (IRiskSteward.PriceCapLstUpdate[] memory)
{}

function stablePriceCapsUpdates() public pure virtual returns (IRiskSteward.PriceCapStableUpdate[] 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 {
function run(bool broadcastToSafe, bool generateDiffReport, bool skipTimelock) external {
vm.startPrank(STEWARD.RISK_COUNCIL());
bytes[] memory callDatas = _simulateAndGenerateDiff(generateDiffReport);
bytes[] memory callDatas = _simulateAndGenerateDiff(generateDiffReport, skipTimelock);
vm.stopPrank();

if (callDatas.length > 1) emit log_string('** multiple calldatas emitted, please execute them all **');
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:');
Expand All @@ -60,7 +71,10 @@ abstract contract RiskStewardsBase is ProtocolV3TestBase {
}
}

function _simulateAndGenerateDiff(bool generateDiffReport) internal returns (bytes[] memory) {
function _simulateAndGenerateDiff(
bool generateDiffReport,
bool skipTimelock
) internal returns (bytes[] memory) {
bytes[] memory callDatas = new bytes[](MAX_TX);
uint8 txCount;

Expand All @@ -73,16 +87,53 @@ abstract contract RiskStewardsBase is ProtocolV3TestBase {
IRiskSteward.PriceCapLstUpdate[] memory lstPriceCapUpdates = lstPriceCapsUpdates();
IRiskSteward.PriceCapStableUpdate[] memory stablePriceCapUpdates = stablePriceCapsUpdates();

if (skipTimelock) {
// warp to the max timelock

uint40[] memory timelocks = new uint40[](12);
uint256 index = 0; // Track the current index for adding elements

IRiskSteward.Config memory riskConfig = STEWARD.getRiskConfig();
if (capUpdates.length != 0) {
timelocks[index++] = riskConfig.supplyCap.minDelay;
timelocks[index++] = riskConfig.borrowCap.minDelay;
}
if (collateralUpdates.length != 0) {
timelocks[index++] = riskConfig.ltv.minDelay;
timelocks[index++] = riskConfig.liquidationThreshold.minDelay;
timelocks[index++] = riskConfig.liquidationBonus.minDelay;
timelocks[index++] = riskConfig.debtCeiling.minDelay;
}
if (rateUpdates.length != 0) {
timelocks[index++] = riskConfig.baseVariableBorrowRate.minDelay;
timelocks[index++] = riskConfig.optimalUsageRatio.minDelay;
timelocks[index++] = riskConfig.variableRateSlope1.minDelay;
timelocks[index++] = riskConfig.variableRateSlope2.minDelay;
}
if (lstPriceCapUpdates.length != 0) {
timelocks[index++] = riskConfig.priceCapLst.minDelay;
}
if (stablePriceCapUpdates.length != 0) {
timelocks[index++] = riskConfig.priceCapStable.minDelay;
}
uint40 maxTimelock = 0;
for (uint256 i = 0; i < timelocks.length; i++) {
if (timelocks[i] > maxTimelock) {
maxTimelock = timelocks[i];
}
}
vm.warp(block.timestamp + uint256(maxTimelock) + 1);
}

bool rateUpdatesPresent = rateUpdates.length != 0;
if (generateDiffReport) createConfigurationSnapshot(pre, POOL, true, rateUpdatesPresent, false, false);
if (generateDiffReport)
createConfigurationSnapshot(pre, POOL, true, rateUpdatesPresent, false, false);

if (capUpdates.length != 0) {
callDatas[txCount] = abi.encodeWithSelector(
IRiskSteward.updateCaps.selector,
capUpdates
);
callDatas[txCount] = abi.encodeWithSelector(IRiskSteward.updateCaps.selector, capUpdates);
(bool success, bytes memory resultData) = address(STEWARD).call(callDatas[txCount]);
_verifyCallResult(success, resultData);

txCount++;
}

Expand All @@ -97,10 +148,7 @@ abstract contract RiskStewardsBase is ProtocolV3TestBase {
}

if (rateUpdates.length != 0) {
callDatas[txCount] = abi.encodeWithSelector(
IRiskSteward.updateRates.selector,
rateUpdates
);
callDatas[txCount] = abi.encodeWithSelector(IRiskSteward.updateRates.selector, rateUpdates);
(bool success, bytes memory resultData) = address(STEWARD).call(callDatas[txCount]);
_verifyCallResult(success, resultData);
txCount++;
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/ArbitrumExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsArbitrum} from '../../../scripts/networks/RiskStewardsArbitrum.s.sol';

// make run-script network=arbitrum contract=src/contracts/examples/ArbitrumExample.sol:ArbitrumExample broadcast=false generate_diff=true
// make run-script network=arbitrum contract=src/contracts/examples/ArbitrumExample.sol:ArbitrumExample broadcast=false generate_diff=true skip_timelock=false
contract ArbitrumExample is RiskStewardsArbitrum {
/**
* @return string name identifier used for the diff
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/AvalancheExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsAvalanche} from '../../../scripts/networks/RiskStewardsAvalanche.s.sol';

// make run-script network=avalanche contract=src/contracts/examples/AvalancheExample.sol:AvalancheExample broadcast=false generate_diff=true
// make run-script network=avalanche contract=src/contracts/examples/AvalancheExample.sol:AvalancheExample broadcast=false generate_diff=true skip_timelock=false
contract AvalancheExample is RiskStewardsAvalanche {
/**
* @return string name identifier used for the diff
Expand Down
9 changes: 7 additions & 2 deletions src/contracts/examples/BNBExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsBNB} from '../../../scripts/networks/RiskStewardsBNB.s.sol';

// make run-script network=bnb contract=src/contracts/examples/BNBExample.sol:BNBExample broadcast=false generate_diff=true
// make run-script network=bnb contract=src/contracts/examples/BNBExample.sol:BNBExample broadcast=false generate_diff=true skip_timelock=false
contract BNBExample is RiskStewardsBNB {
/**
* @return string name identifier used for the diff
Expand All @@ -15,7 +15,12 @@ contract BNBExample is RiskStewardsBNB {
return 'bnb_example';
}

function rateStrategiesUpdates() public pure override returns (IEngine.RateStrategyUpdate[] memory) {
function rateStrategiesUpdates()
public
pure
override
returns (IEngine.RateStrategyUpdate[] memory)
{
IEngine.RateStrategyUpdate[] memory rateUpdates = new IEngine.RateStrategyUpdate[](1);
rateUpdates[0] = IEngine.RateStrategyUpdate({
asset: AaveV3BNBAssets.ETH_UNDERLYING,
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/BaseExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsBaseChain} from '../../../scripts/networks/RiskStewardsBaseChain.s.sol';

// make run-script network=base contract=src/contracts/examples/BaseExample.sol:BaseExample broadcast=false generate_diff=true
// make run-script network=base contract=src/contracts/examples/BaseExample.sol:BaseExample broadcast=false generate_diff=true skip_timelock=false
contract BaseExample is RiskStewardsBaseChain {
/**
* @return string name identifier used for the diff
Expand Down
13 changes: 10 additions & 3 deletions src/contracts/examples/EthereumExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-eng
import {RiskStewardsEthereum} from '../../../scripts/networks/RiskStewardsEthereum.s.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
// make run-script network=mainnet contract=src/contracts/examples/EthereumExample.sol:EthereumExample broadcast=false generate_diff=true skip_timelock=false
contract EthereumExample is RiskStewardsEthereum {
/**
* @return string name identifier used for the diff
Expand All @@ -16,8 +16,15 @@ contract EthereumExample is RiskStewardsEthereum {
return 'ethereum_example';
}

function lstPriceCapsUpdates() public pure override returns (IRiskSteward.PriceCapLstUpdate[] memory) {
IRiskSteward.PriceCapLstUpdate[] memory priceCapUpdates = new IRiskSteward.PriceCapLstUpdate[](1);
function lstPriceCapsUpdates()
public
pure
override
returns (IRiskSteward.PriceCapLstUpdate[] memory)
{
IRiskSteward.PriceCapLstUpdate[] memory priceCapUpdates = new IRiskSteward.PriceCapLstUpdate[](
1
);

priceCapUpdates[0] = IRiskSteward.PriceCapLstUpdate({
oracle: AaveV3EthereumAssets.wstETH_ORACLE,
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/EthereumLidoExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsEthereumLido} from '../../../scripts/networks/RiskStewardsEthereumLido.s.sol';

// make run-script network=mainnet contract=src/contracts/examples/EthereumLidoExample.sol:EthereumLidoExample broadcast=false generate_diff=true
// make run-script network=mainnet contract=src/contracts/examples/EthereumLidoExample.sol:EthereumLidoExample broadcast=false generate_diff=true skip_timelock=false
contract EthereumLidoExample is RiskStewardsEthereumLido {
/**
* @return string name identifier used for the diff
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/GnosisExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsGnosis} from '../../../scripts/networks/RiskStewardsGnosis.s.sol';

// make run-script network=gnosis contract=src/contracts/examples/GnosisExample.sol:GnosisExample broadcast=false generate_diff=true
// make run-script network=gnosis contract=src/contracts/examples/GnosisExample.sol:GnosisExample broadcast=false generate_diff=true skip_timelock=false
contract GnosisExample is RiskStewardsGnosis {
/**
* @return string name identifier used for the diff
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/MetisExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsMetis} from '../../../scripts/networks/RiskStewardsMetis.s.sol';

// make run-script network=metis contract=src/contracts/examples/MetisExample.sol:MetisExample broadcast=false generate_diff=true
// make run-script network=metis contract=src/contracts/examples/MetisExample.sol:MetisExample broadcast=false generate_diff=true skip_timelock=false
contract MetisExample is RiskStewardsMetis {
/**
* @return string name identifier used for the diff
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/OptimismExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsOptimism} from '../../../scripts/networks/RiskStewardsOptimism.s.sol';

// make run-script network=optimism contract=src/contracts/examples/OptimismExample.sol:OptimismExample broadcast=false generate_diff=true
// make run-script network=optimism contract=src/contracts/examples/OptimismExample.sol:OptimismExample broadcast=false generate_diff=true skip_timelock=false
contract OptimismExample is RiskStewardsOptimism {
/**
* @return string name identifier used for the diff
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/PolygonExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsPolygon} from '../../../scripts/networks/RiskStewardsPolygon.s.sol';

// make run-script network=polygon contract=src/contracts/examples/PolygonExample.sol:PolygonExample broadcast=false generate_diff=true
// make run-script network=polygon contract=src/contracts/examples/PolygonExample.sol:PolygonExample broadcast=false generate_diff=true skip_timelock=false
contract PolygonExample is RiskStewardsPolygon {
/**
* @return string name identifier used for the diff
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/examples/ScrollExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/exten
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsScroll} from '../../../scripts/networks/RiskStewardsScroll.s.sol';

// make run-script network=scroll contract=src/contracts/examples/ScrollExample.sol:ScrollExample broadcast=false generate_diff=true
// make run-script network=scroll contract=src/contracts/examples/ScrollExample.sol:ScrollExample broadcast=false generate_diff=true skip_timelock=false
contract ScrollExample is RiskStewardsScroll {
/**
* @return string name identifier used for the diff
Expand Down
Loading