Skip to content

Commit

Permalink
feat: stewards injector robot (#13)
Browse files Browse the repository at this point in the history
* fix: no same updates or all keep current

* fix: no same update for capo

* feat: add edge risk steward

* chore: fix lint

* chore: add risk oracle contract

* feat: add stewards injector and fix remappings

* test: stewards injector

* test: isUpdatedIdExecuted

* test: expiredUpdate

* test: some more injector tests

* test: edge risk steward

* refactor: rename method

* feat: add writeup

* test: add missing tests

* fix: script for coverage

* chore: deploy scripts

* fix: deploy script

* feat: simplify injector

* fix: update contracts to v3.2 and adjust imports and remappings

* chore: update readme

* fix: certora remapping

* chore: update readme from suggestion

Co-authored-by: Ernesto Boado <[email protected]>

* chore: update readme from suggestion

Co-authored-by: Ernesto Boado <[email protected]>

* chore: update readme from suggestion

Co-authored-by: Ernesto Boado <[email protected]>

* fix: remove revert on sameUpdate and all keepCurrent

* chore: fix lint

* chore: fix typo in writeup

* fix: generator imports and update address book

* fix: stewards base

* chore: add risk oracle to deploy script

---------

Co-authored-by: Ernesto Boado <[email protected]>
  • Loading branch information
brotherlymite and eboadom authored Nov 9, 2024
1 parent 3fd7b75 commit 650d51e
Show file tree
Hide file tree
Showing 42 changed files with 1,544 additions and 132 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ update:; forge update
coverage :; forge coverage --report lcov && \
lcov --remove ./lcov.info -o ./lcov.info.p \
'tests/*' \
'src/contracts/dependencies/*' \
'src/contracts/examples/*' \
'src/contracts/updates/*' \
'scripts/*' \
&& genhtml ./lcov.info.p -o report --branch-coverage \
&& coverage=$$(awk -F '[<>]' '/headerCovTableEntryHi/{print $3}' ./report/index.html | sed 's/[^0-9.]//g' | head -n 1); \
wget -O ./report/coverage.svg "https://img.shields.io/badge/coverage-$${coverage}%25-brightgreen"
Expand All @@ -27,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_path} --rpc-url ${network} --sig "run(bool)" ${broadcast} -vv
run-script:; FOUNDRY_PROFILE=${network} forge script ${contract} --rpc-url ${network} --sig "run(bool)" ${broadcast} -vv
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Expanding from the scope of CapsPlusRiskSteward, we now introduce the new RiskSt

## Specification

The new RiskSteward we propose follows the same design as the CapsPlusRiskSteward: a smart contract to which the Aave Governance gives `POOL_ADMIN` the role over all v3 instances, controlled by a 2-of-2 multi-sig of the risk providers, and heavily constrained on what can do and how by its own logic.
The new RiskSteward we propose follows the same design as the CapsPlusRiskSteward: a smart contract to which the Aave Governance gives `POOL_ADMIN` the role over all v3 instances. It is controlled by a 2-of-2 multi-sig and is heavily constrained on what can do and how by its own logic.

_Note: The Risk Stewards will only be available for Aave V3.1 instances and not Aave V2 (or previous Aave v3) due to missing admin roles on Aave V2 instances and other incompatibilities._

Expand Down Expand Up @@ -39,10 +39,10 @@ For each risk param, `minDelay` can be configured, which is the minimum amount o

#### Max Percent Change:

For each risk param, `maxPercentChange` which is the maximum percent change allowed (both upwards and downwards) for the risk param using the RiskStewards.
For each risk param, `maxPercentChange` is the maximum percent change allowed (both upwards and downwards) for the risk param using the RiskStewards.

- Supply cap, Borrow cap and Debt ceiling: The `maxPercentChange` is relative and is denominated in BPS. (Ex. `50_00` for +-50% relative change).
For example, for a current supply cap of an asset at 1_000_000 and `maxPercentChange` configured for supply cap at `50_00`, the max supply cap that can be configured is 1_500_000 and the minimum 500_000 via the steward.
- Supply cap, Borrow cap, and Debt ceiling: The `maxPercentChange` is relative and is denominated in BPS. (Ex. `50_00` for +-50% relative change).
For example, with an asset's current supply cap at 1_000_000 and `maxPercentChange` configured for supply cap at `50_00`, the max supply cap that can be configured is 1_500_000, and the minimum is 500_000 via the steward.

- LTV, LT, LB: The `maxPercentChange` is in absolute values and is also denominated in BPS. (Ex. `5_00` for +-5% change in LTV).
For example, for a current LTV of an asset configured at 70_00 (70%) and `maxPercentChange` configured for ltv at `10_00`, the max ltv that can be configured is 77_00 (77%) and the minimum 63_00 (63%) via the steward.
Expand All @@ -66,6 +66,30 @@ Some assets/oracles can also be restricted on the RiskStewards by calling the `s

<br>

## AGRS + Edge Infrastructure (Risk Oracles)

With the introduction of Edge Risk Oracles by Chaos Labs, which leverages advanced off-chain infrastructure to deliver real-time risk updates to the Aave protocol via the Risk Oracle, the risk updates for the Aave protocol can be automated in a constrained manner. This can be done by combining the Edge Risk Oracle with the Aave Risk Steward, using a middleware contract `AaveStewardsInjector`.

The Aave Risk Steward contract used for automated updates (called now [EdgeRiskSteward](./src/contracts/EdgeRiskSteward.sol)), has been slightly modified to only allow Interest Rates Updates on the protocol initially as a matter of extra security considerations.

The following is a simple diagram of how the system works as a whole:

<img src="./docs/agrs-edge.png" alt="AGRS and Risk Oracle Diagram Flow" width="100%" height="100%">

### AaveStewardsInjector

The [AaveStewardsInjector](./src/contracts//AaveStewardInjector.sol) is a Chainlink automation compatible contract which checks if the latest update from the Edge Risk Oracle could be pushed to the Risk Steward, and if so, injects it to the Aave Risk Stewards. The `AaveStewardsInjector` should be set as the `riskCouncil` on the Aave Risk Steward contract so it can inject updates.

The `AaveStewardsInjector` has the following major functions:

- `checkUpkeep()`: This method is called off-chain by Chainlink nodes every block to check if the latest update could be injected, and if so, calls `performUpKeep()`. It fetches the latest interest rate update for the whitelisted asset (initially WETH) using the `getLatestUpdateByParameterAndMarket()` method on the Risk Oracle, and checks if the update can be injected into the Risk Steward if not already executed before. If the latest update is not executed or disabled the method returns true.

- `performUpkeep()`: The `performUpkeep()` method is called by the Chainlink automation nodes when the `checkUpkeep()` method returns true. The `performUpkeep()` call injects the latest update on the Risk Steward, unless that update has been disabled by the steward injector guardian or previously executed. After an update has been injected on the Risk Steward using the params from the Risk Oracle, we mark the updateId as executed on storage mapping `_isUpdateIdExecuted[id]`. The `performUpkeep()` method is permissionless on purpose, so as to allow injections from the Risk Oracle to the Risk Steward even in case of some downtime on the automation infra via a manual trigger.

The Stewards Injector Guardian is an entity, which is the owner of the `AaveStewardsInjector` contract and has access to disable updates for the specific `updateId` using the `disableUpdateById()` method in case of any emergencies. The guardian can also change / add update types using the `addUpdateType()` method, to whitelist the type of updates that can be injected via the Stewards Injector.

The `AaveStewardsInjector` contract also introduces an `EXPIRATION_PERIOD` to disallow outdated risk param updates to be injected. The `EXPIRATION_PERIOD` is set to 6 hours, which means after an update is pushed on the Edge Risk Oracle, the `AaveStewardsInjector` has a maximum of 6 hours to inject the update onto the Risk Steward otherwise the update expires.

## Security

- Certora security review: [2024-07-10](./audits/10-07-2024_Certora_AaveV3-Risk-Steward.pdf)
Expand Down
9 changes: 4 additions & 5 deletions certora/confs/rules.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": [
"certora/munged/src/contracts/RiskSteward.sol",
"lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/periphery/contracts/v3-config-engine/AaveV3ConfigEngine.sol"
"lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/contracts/extensions/v3-config-engine/AaveV3ConfigEngine.sol"
],
"link": [
"RiskSteward:CONFIG_ENGINE=AaveV3ConfigEngine",
Expand All @@ -10,10 +10,9 @@
"aave-helpers=lib/aave-helpers",
"forge-std=lib/aave-helpers/lib/forge-std/src",
"aave-address-book=lib/aave-helpers/lib/aave-address-book/src",
"solidity-utils=lib/aave-helpers/lib/solidity-utils/src",
"aave-v3-origin=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src",
"aave-v3-core=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/core",
"aave-v3-periphery=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/periphery",
"solidity-utils=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/lib/solidity-utils/src",
"lib/aave-helpers:aave-v3-origin=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src",
"aave-v3-origin=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin",
"aave-capo=lib/aave-capo/src",
"lib/aave-capo:cl-synchronicity-price-adapter=lib/aave-capo/lib/cl-synchronicity-price-adapter/src"
],
Expand Down
7 changes: 3 additions & 4 deletions certora/confs/sanity.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"aave-helpers=lib/aave-helpers",
"forge-std=lib/aave-helpers/lib/forge-std/src",
"aave-address-book=lib/aave-helpers/lib/aave-address-book/src",
"solidity-utils=lib/aave-helpers/lib/solidity-utils/src",
"aave-v3-origin=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src",
"aave-v3-core=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/core",
"aave-v3-periphery=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/periphery",
"solidity-utils=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/lib/solidity-utils/src",
"lib/aave-helpers:aave-v3-origin=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src",
"aave-v3-origin=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin",
"aave-capo=lib/aave-capo/src",
"lib/aave-capo:cl-synchronicity-price-adapter=lib/aave-capo/lib/cl-synchronicity-price-adapter/src"
],
Expand Down
Binary file added docs/agrs-edge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ src = 'src'
test = 'tests'
script = 'scripts'
out = 'out'
solc = '0.8.19'
solc = '0.8.20'
libs = ['lib']
remappings = [
]
Expand All @@ -16,10 +16,10 @@ src = 'zksync'
test = 'zksync'
script = 'scripts'
libs = ['lib']
solc = '0.8.19'
solc = '0.8.20'
fs_permissions = [{ access = "write", path = "./reports" }]
ffi = true
evm_version = 'paris'
evm_version = 'shanghai'

[profile.zksync.zksync]
compile = true
Expand Down
2 changes: 1 addition & 1 deletion generator/features/__snapshots__/capUpdates.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pragma solidity ^0.8.0;
import {AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {RiskStewardsEthereum} from '../../../../scripts/networks/RiskStewardsEthereum.s.sol';
import {IAaveV3ConfigEngine} from 'aave-v3-periphery/contracts/v3-config-engine/IAaveV3ConfigEngine.sol';
import {IAaveV3ConfigEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol';
/**
* @title test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pragma solidity ^0.8.0;
import {AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {RiskStewardsEthereum} from '../../../../scripts/networks/RiskStewardsEthereum.s.sol';
import {EngineFlags} from 'aave-v3-periphery/contracts/v3-config-engine/EngineFlags.sol';
import {IAaveV3ConfigEngine} from 'aave-v3-periphery/contracts/v3-config-engine/IAaveV3ConfigEngine.sol';
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {IAaveV3ConfigEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol';
/**
* @title test
Expand Down
4 changes: 2 additions & 2 deletions generator/features/__snapshots__/rateUpdates.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ pragma solidity ^0.8.0;
import {AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {RiskStewardsEthereum} from '../../../../scripts/networks/RiskStewardsEthereum.s.sol';
import {EngineFlags} from 'aave-v3-periphery/contracts/v3-config-engine/EngineFlags.sol';
import {IAaveV3ConfigEngine} from 'aave-v3-periphery/contracts/v3-config-engine/IAaveV3ConfigEngine.sol';
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {IAaveV3ConfigEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol';
/**
* @title test
Expand Down
4 changes: 2 additions & 2 deletions generator/utils/importsResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ describe('prefixWithImports', () => {

it('should detect v3 Engine imports', () => {
expect(prefixWithImports(`EngineFlags.KEEP_CURRENT`)).toContain(
`import {EngineFlags} from 'aave-v3-periphery/contracts/v3-config-engine/EngineFlags.sol';`,
`import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';`,
);

expect(prefixWithImports('IAaveV3ConfigEngine.CapsUpdate')).toContain(
`import {IAaveV3ConfigEngine} from 'aave-v3-periphery/contracts/v3-config-engine/IAaveV3ConfigEngine.sol';`,
`import {IAaveV3ConfigEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol';`,
);
});

Expand Down
4 changes: 2 additions & 2 deletions generator/utils/importsResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ export function prefixWithImports(code: string) {
}
// shared config engine imports
if (findMatch(code, 'EngineFlags')) {
imports += `import {EngineFlags} from 'aave-v3-periphery/contracts/v3-config-engine/EngineFlags.sol';\n`;
imports += `import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';\n`;
}
// v3 config engine imports
if (findMatch(code, 'IAaveV3ConfigEngine')) {
imports += `import {IAaveV3ConfigEngine} from 'aave-v3-periphery/contracts/v3-config-engine/IAaveV3ConfigEngine.sol';\n`;
imports += `import {IAaveV3ConfigEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol';\n`;
}
// v2 config engine imports
if (findMatch(code, 'IAaveV2ConfigEngine')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/aave-helpers
Submodule aave-helpers updated 77 files
+1 −0 .assets/17f6b65b666e033f6d757eab80af272608f3179e.svg
+1 −0 .assets/229e4f50d5cb7a04464c2bd175ef23d256e2d25d.svg
+1 −0 .assets/23e67c7d46dd80f36d580b243c5716c84080a34f.svg
+1 −0 .assets/3f4ff4e3916b8e502cabc40483a392da51ad678a.svg
+1 −0 .assets/4023527fa4852947cff1f02ae9ff00ea9bc77719.svg
+1 −0 .assets/47b0af3d54a5c5cfec9387787b9ad4e8de5bce63.svg
+1 −0 .assets/5f6eef0835ac19ee0c898e4b760d8970954291bf.svg
+1 −0 .assets/64fd6acec636adec0e975e8031f8e3f7fb87bb7d.svg
+1 −0 .assets/772fdedb24491c4dde9a73af5e1fd183523d5024.svg
+1 −0 .assets/838ead98a9ae093ded1390e58ff2a328cd8e29a4.svg
+1 −0 .assets/8a8a0e067285eb92c25c539be301949997ccd175.svg
+1 −0 .assets/8f48c9478437c54125028a1d71100121cc58dcd0.svg
+1 −0 .assets/952932c7b15c44b006f762abc15f3c37d87b04d9.svg
+1 −0 .assets/9b3ea57ff4b19f392d36203fa741c94e83a96393.svg
+1 −0 .assets/bf52f4b65079681aa65fd69327e3061d269fe51d.svg
+1 −0 .assets/c6f6294fedb5e5b5fc418d2c7861ece2c2bdef75.svg
+1 −0 .assets/ea9358e636f19fd911c6b5fcbe0f3b0c33f010bb.svg
+1 −0 .assets/ee98e9626d6dd42942fdaf5d08078961de8bf38f.svg
+1 −0 .assets/fefe2c9708de2db1319f2fac935bcc21796a28c0.svg
+0 −3 .gitmodules
+2 −2,086 diffs/default_before_default_after.md
+8 −8 diffs/preTestV2RatesUpdates_postTestV2RatesUpdates.md
+1 −1 lib/aave-address-book
+1 −1 lib/forge-std
+0 −1 lib/solidity-utils
+2 −2 package.json
+2 −3 remappings.txt
+1 −1 scripts/RiskStewards.s.sol
+0 −6 src/AaveHelpers.sol
+1 −1 src/CollectorUtils.sol
+0 −267 src/GovHelpers.sol
+17 −5 src/GovV3Helpers.sol
+1 −1 src/ProtocolV2TestBase.sol
+55 −34 src/ProtocolV3TestBase.sol
+0 −30 src/ProxyHelpers.sol
+19 −2 src/asset-manager/AaveWstethWithdrawer.sol
+1 −2 src/asset-manager/interfaces/IAaveWstethWithdrawer.sol
+8 −0 src/bridges/arbitrum/AaveArbEthERC20Bridge.sol
+8 −0 src/bridges/optimism/AaveOpEthERC20Bridge.sol
+8 −0 src/bridges/polygon/AavePolEthERC20Bridge.sol
+8 −0 src/bridges/polygon/AavePolEthPlasmaBridge.sol
+8 −8 src/dependencies/DefaultReserveInterestRateStrategy.sol
+4 −4 src/dependencies/IReserveInterestRateStrategy.sol
+2 −2 src/riskstewards/CapsPlusRiskSteward.sol
+2 −2 src/riskstewards/ICapsPlusRiskSteward.sol
+8 −0 src/swaps/AaveSwapper.sol
+1 −1 src/v2-config-engine/AaveV2ConfigEngine.sol
+2 −2 src/v2-config-engine/AaveV2Payload.sol
+1 −1 src/v3-config-engine/AaveV3PayloadArbitrum.sol
+1 −1 src/v3-config-engine/AaveV3PayloadAvalanche.sol
+1 −1 src/v3-config-engine/AaveV3PayloadBNB.sol
+1 −1 src/v3-config-engine/AaveV3PayloadBase.sol
+1 −1 src/v3-config-engine/AaveV3PayloadEthereum.sol
+6 −3 src/v3-config-engine/AaveV3PayloadEthereumEtherFi.sol
+4 −2 src/v3-config-engine/AaveV3PayloadEthereumLido.sol
+1 −1 src/v3-config-engine/AaveV3PayloadGnosis.sol
+1 −1 src/v3-config-engine/AaveV3PayloadMetis.sol
+1 −1 src/v3-config-engine/AaveV3PayloadOptimism.sol
+1 −1 src/v3-config-engine/AaveV3PayloadPolygon.sol
+1 −1 src/v3-config-engine/AaveV3PayloadPolygonZkEvm.sol
+1 −1 src/v3-config-engine/AaveV3PayloadScroll.sol
+13 −13 src/v3-config-engine/AaveV3PayloadZkSync.sol
+31 −0 tests/CollectorUtils.t.sol
+0 −1 tests/GovV3Test.t.sol
+1 −1 tests/ProtocolV3TestBase.t.sol
+1 −1 tests/ProxyHelpersTest.t.sol
+0 −1 tests/mocks/AaveV3AvalancheEModeCategoryUpdateNoChange.sol
+3 −1 tests/mocks/AaveV3EthereumAssetEModeUpdate.sol
+1 −2 tests/mocks/AaveV3PolygonBorrowUpdate.sol
+1 −2 tests/mocks/AaveV3PolygonBorrowUpdateNoChange.sol
+1 −3 tests/mocks/AaveV3PolygonEModeCategoryUpdate.sol
+1 −1 tests/mocks/AaveV3PolygonPriceFeedUpdate.sol
+4 −4 tests/riskstewards/CapsPlusRiskSteward.t.sol
+3 −3 tests/v2-config-engine/AaveV2ConfigEngineTest.t.sol
+119 −690 yarn.lock
+6 −10 zksync/src/ProtocolV3TestBase.sol
+69 −59 zksync/src/SnapshotHelpersV3.sol
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"prettier": "2.8.7",
"prettier-plugin-solidity": "1.1.3",
"vitest": "^2.0.4",
"@bgd-labs/aave-address-book": "^3.2.1",
"@bgd-labs/aave-address-book": "^4.3.1",
"@bgd-labs/aave-cli": "^0.16.2",
"@bgd-labs/js-utils": "^1.4.2",
"@inquirer/prompts": "^3.3.0",
Expand Down
7 changes: 3 additions & 4 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
aave-helpers/=lib/aave-helpers/
forge-std/=lib/aave-helpers/lib/forge-std/src/
aave-address-book/=lib/aave-helpers/lib/aave-address-book/src/
solidity-utils/=lib/aave-helpers/lib/solidity-utils/src/
aave-v3-origin/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/
aave-v3-core/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/core
aave-v3-periphery/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src/periphery
solidity-utils/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/lib/solidity-utils/src/
lib/aave-helpers:aave-v3-origin/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/src
aave-v3-origin/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-origin/
aave-capo/=lib/aave-capo/src
lib/aave-capo:cl-synchronicity-price-adapter/=lib/aave-capo/lib/cl-synchronicity-price-adapter/src/
8 changes: 1 addition & 7 deletions scripts/RiskStewardsBase.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IAaveV3ConfigEngine as IEngine, IPool} from 'aave-v3-periphery/contracts/v3-config-engine/IAaveV3ConfigEngine.sol';
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';
Expand Down Expand Up @@ -40,12 +40,6 @@ abstract contract RiskStewardsBase is ProtocolV3TestBase {
* @notice This script doesn't broadcast as it's intended to be used via safe
*/
function run(bool broadcastToSafe) external {
// TODO: remove once risk stewards are activated via governance
vm.startPrank(IOwnable(address(STEWARD)).owner());
address aclManager = STEWARD.POOL_DATA_PROVIDER().ADDRESSES_PROVIDER().getACLManager();
IACLManager(aclManager).grantRole(IACLManager(aclManager).RISK_ADMIN_ROLE(), address(STEWARD));
vm.stopPrank();

vm.startPrank(STEWARD.RISK_COUNCIL());
bytes[] memory callDatas = _simulateAndGenerateDiff();
vm.stopPrank();
Expand Down
90 changes: 90 additions & 0 deletions scripts/deploy/DeployInjector.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import 'solidity-utils/contracts/utils/ScriptUtils.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';
import {AaveV3EthereumLido, AaveV3EthereumLidoAssets} from 'aave-address-book/AaveV3EthereumLido.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {ICreate3Factory} from 'solidity-utils/contracts/create3/interfaces/ICreate3Factory.sol';
import {IOwnable} from 'aave-address-book/common/IOwnable.sol';
import {EdgeRiskSteward, IRiskSteward, IPoolDataProvider, IEngine} from '../../src/contracts/EdgeRiskSteward.sol';
import {AaveStewardInjector, IAaveStewardInjector} from '../../src/contracts/AaveStewardInjector.sol';

library DeployStewardContracts {
address constant EDGE_RISK_ORACLE = 0x7ABB46C690C52E919687D19ebF89C81A6136C1F2;

function _deployRiskStewards(
address poolDataProvider,
address configEngine,
address riskCouncil,
address governance
) internal returns (address) {
address riskSteward = address(new EdgeRiskSteward(
IPoolDataProvider(poolDataProvider),
IEngine(configEngine),
riskCouncil,
_getRiskConfig()
));
IOwnable(riskSteward).transferOwnership(governance);
return riskSteward;
}

function _deployStewardsInjector(
bytes32 salt,
address riskSteward,
address guardian,
address whitelistedAsset
) internal returns (address) {
address stewardInjector = ICreate3Factory(MiscEthereum.CREATE_3_FACTORY).create(
salt,
abi.encodePacked(
type(AaveStewardInjector).creationCode,
abi.encode(
EDGE_RISK_ORACLE,
riskSteward,
guardian,
whitelistedAsset
)
)
);
return stewardInjector;
}

function _getRiskConfig() internal pure returns (IRiskSteward.Config memory) {
return IRiskSteward.Config({
ltv: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 25}),
liquidationThreshold: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 25}),
liquidationBonus: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 50}),
supplyCap: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 100_00}),
borrowCap: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 100_00}),
debtCeiling: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 20_00}),
baseVariableBorrowRate: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 50}),
variableRateSlope1: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 50}),
variableRateSlope2: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 5_00}),
optimalUsageRatio: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 3_00}),
priceCapLst: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 5_00}),
priceCapStable: IRiskSteward.RiskParamConfig({minDelay: 1 days, maxPercentChange: 50})
});
}
}

// make deploy-ledger contract=scripts/deploy/DeployInjector.s.sol:DeployEthereumLido chain=mainnet
contract DeployEthereumLido is EthereumScript {
address constant GUARDIAN = 0xff37939808EcF199A2D599ef91D699Fb13dab7F7;

function run() external {
vm.startBroadcast();
bytes32 salt = 'StewardInjector';
address predictedStewardsInjector = ICreate3Factory(MiscEthereum.CREATE_3_FACTORY).predictAddress(msg.sender, salt);

address riskSteward = DeployStewardContracts._deployRiskStewards(
address(AaveV3EthereumLido.AAVE_PROTOCOL_DATA_PROVIDER),
AaveV3EthereumLido.CONFIG_ENGINE,
predictedStewardsInjector,
GovernanceV3Ethereum.EXECUTOR_LVL_1
);

DeployStewardContracts._deployStewardsInjector(salt, riskSteward, GUARDIAN, AaveV3EthereumLidoAssets.WETH_UNDERLYING);
vm.stopBroadcast();
}
}
Loading

0 comments on commit 650d51e

Please sign in to comment.