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

ContractRegistry module + LoanConsolidator #19

Merged
merged 169 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
0b142d4
Add tests for third-party clearinghouse/cooler and active status
0xJem Sep 26, 2024
51b25b4
Compile fix due to new constructor argument
0xJem Sep 26, 2024
e97af50
Add checks for Clearinghouse, Cooler and active status. Renames some …
0xJem Sep 26, 2024
d7eaf09
chore: linting
0xJem Sep 26, 2024
f06fef5
Test stubs. Define additional admin address.
0xJem Sep 26, 2024
6ff1b59
setAdmin: allow for zero address (to disable), prevent duplicating th…
0xJem Sep 26, 2024
d4c8282
Minor test fix
0xJem Sep 26, 2024
786cdbf
Update docs
0xJem Sep 26, 2024
5073418
Set fee collector to TRSRY v1
0xJem Sep 27, 2024
5f3f6a4
Remove admin address, perform lookup of "emergency_shutdown" role.
0xJem Oct 3, 2024
8678136
Add initial version of EXREG module
0xJem Oct 8, 2024
29a6416
NatSpec
0xJem Oct 8, 2024
a061cd6
Test stubs
0xJem Oct 8, 2024
593e005
Implementation fixes. Complete tests.
0xJem Oct 8, 2024
089c233
Rename CoolerUtils -> LoanConsolidator. Move into policies directory.
0xJem Oct 8, 2024
b04be60
Rename env key
0xJem Oct 8, 2024
a0a7990
Convert LoanConsolidator to a policy
0xJem Oct 8, 2024
802e9b4
Update deployment and tests for LoanConsolidator
0xJem Oct 8, 2024
b7f2e75
Refresh dependent policies when registering/deregistering contracts i…
0xJem Oct 8, 2024
03c10e9
LoanConsolidator: Rename active state variable to be distinct from Po…
0xJem Oct 9, 2024
79e12cf
Fix formatter used by VSCode
0xJem Oct 9, 2024
f491d0e
Add policy to interface with EXREG
0xJem Oct 9, 2024
43c8571
EXREG: force contract names to be lowercase or have a numeral
0xJem Oct 9, 2024
4eb7110
Avoid stalling due to formatting on save
0xJem Oct 9, 2024
cb71371
Document roles used
0xJem Oct 9, 2024
40efb96
LoanConsolidator: disable functions if the policy is not active
0xJem Oct 9, 2024
776933e
LoanConsolidator: update tests to support conversion to policy
0xJem Oct 9, 2024
58cebc2
Fix regex for fork tests script
0xJem Oct 9, 2024
dc5ff35
Add NatSpec on initialisation of state variables
0xJem Oct 10, 2024
a1b099c
Rename _EXREG state variable to EXREG for consistency
0xJem Oct 10, 2024
0b56b41
Remove view functions from ExternalRegistryAdmin
0xJem Oct 10, 2024
e149966
Update EXREG to have distinct registerContract and updateContract fun…
0xJem Oct 10, 2024
d4d498b
Extra logs in deploy script
0xJem Oct 10, 2024
fc841dd
Add EXREG and ExternalRegistryAdmin to deploy script
0xJem Oct 10, 2024
6cadd53
Cross-port extensions and solidity metrics from PR #203
0xJem Oct 14, 2024
3d4d394
Cross-port metrics script from PR #203
0xJem Oct 14, 2024
833ef74
Add solidity-code-metrics dependency from PR #203
0xJem Oct 14, 2024
c16a1b6
Add audit README and code metrics
0xJem Oct 14, 2024
617e688
Bump pnpm version in CI
0xJem Oct 14, 2024
9c83ffd
Rename EXREG to RGSTY
0xJem Oct 16, 2024
734bbab
Rename LoanConsolidator test file
0xJem Oct 16, 2024
af0cf03
Pin fork block in BLV tests
0xJem Oct 16, 2024
46ff472
Fix deployment sequences
0xJem Oct 16, 2024
688fe51
Update solidity metrics
0xJem Oct 16, 2024
755ccf3
Integrate migration logic into consolidator
chefomi Oct 22, 2024
2317598
Add test for consolidation on a disabled Clearinghouse
0xJem Oct 23, 2024
6307d9b
Merge branch 'develop' into coolerutils-improvements
0xJem Oct 23, 2024
0c8d055
Add distinct immutable addresses to RGSTY
0xJem Oct 23, 2024
1219560
Shift LoanConsolidator to use immutable contract addresses for tokens
0xJem Oct 23, 2024
c1f6286
Merge branch 'coolerutils-improvements' into coolerutils-migrator
0xJem Oct 23, 2024
e83f06d
Add DaiUsdsMigrator interface
0xJem Oct 23, 2024
afa91bb
Populate DAI migrator state variable
0xJem Oct 23, 2024
87d9e57
Fix compilation errors
0xJem Oct 23, 2024
4290c69
Add support for bi-directional migration of loans
0xJem Oct 23, 2024
03a8a06
Fix compilation errors due to function signature changes
0xJem Oct 23, 2024
4f399f8
chore: linting
0xJem Oct 23, 2024
632cb4d
Resolve stack too deep errors
0xJem Oct 24, 2024
b1c3164
Additional tests for CHREG
0xJem Oct 24, 2024
e3ee76f
Update docs, add missing USDS variable
0xJem Oct 24, 2024
4e5fa6a
WIP tests for DAI<->USDS migration
0xJem Oct 24, 2024
bb859ed
WIP improvements to requiredApprovals, with tests
0xJem Oct 24, 2024
20b00cc
TODO
0xJem Oct 24, 2024
2c2bd29
Simplify approach: remove useFunds_ parameter, better documentation. …
0xJem Oct 25, 2024
98ca36e
Another CHREG test
0xJem Oct 25, 2024
5615216
Workaround for CHREG.registryCount() not updating
0xJem Oct 25, 2024
b7512da
Cross-port Clearinghouse changes (DAI -> reserve) from #427
0xJem Oct 25, 2024
1bd7c5f
Test fixes
0xJem Oct 25, 2024
2356f5a
Fix fork block
0xJem Oct 25, 2024
f43a8d0
Fix failing tests, due to incorrect setup
0xJem Oct 26, 2024
8677f07
Remove obsolete error
0xJem Oct 28, 2024
762f2e0
Update docs
0xJem Oct 28, 2024
d60e9b6
Update audit README
0xJem Oct 28, 2024
c85528b
Update metrics
0xJem Oct 28, 2024
ea1de1d
chore: linting
0xJem Oct 28, 2024
c52ca86
Add test for non-zero lender fee, fix issues
0xJem Oct 28, 2024
9f1ff4b
chore: linting
0xJem Oct 28, 2024
dcae82c
Fix DAI-USDS migration logic
0xJem Oct 28, 2024
8d79972
chore: linting
0xJem Oct 28, 2024
379000b
chore: linting
0xJem Oct 28, 2024
b6bb507
Merge pull request #430 from OlympusDAO/coolerutils-migrator
0xJem Oct 28, 2024
774d277
add func for transfer
chefomi Oct 29, 2024
12ace53
Cleanup
0xJem Oct 30, 2024
ca620a7
Fix issue with third-party cooler tests
0xJem Oct 30, 2024
3b552f6
Enable 1 loan to be consolidated across different Coolers. More thoro…
0xJem Oct 30, 2024
b832c1a
Rename consolidateWithFlashLoan -> consolidate
0xJem Oct 30, 2024
52aec52
Cross-port Clearinghouse cosmetic changes from PR #424
0xJem Oct 30, 2024
6d82233
Cleanup test TODOs
0xJem Oct 30, 2024
0915c16
Add tests for consolidateWithNewOwner(). Add additional checks to the…
0xJem Oct 30, 2024
95479d5
Disable the contract functionality by default
0xJem Oct 30, 2024
1937b86
WIP OCG proposal
0xJem Oct 30, 2024
9692a92
Fix compilation error
0xJem Oct 31, 2024
f368b39
Rename proposal file. Linting.
0xJem Oct 31, 2024
4767ceb
Split into two OCG proposals: ContractRegistry and LoanConsolidator. …
0xJem Oct 31, 2024
c7788d4
More robust detection of OCG proposals when running "pnpm run test:pr…
0xJem Oct 31, 2024
51b961b
Split proposal simulation tests into own github workflow
0xJem Oct 31, 2024
80eda97
Add link to audit report
0xJem Oct 31, 2024
153795c
Fix fork test script
0xJem Oct 31, 2024
8a34c4c
Unpin foundry version
0xJem Oct 31, 2024
09a9ecd
Exclude cross-chain bridge fork
0xJem Oct 31, 2024
599b91b
Merge pull request #432 from OlympusDAO/coolerutils-with-transfer
0xJem Oct 31, 2024
1ffea94
Fixes two issues. Add tests for consolidation between clearinghouses …
0xJem Oct 31, 2024
f70896c
Fix: lenderFee should be exclusive of totalInterest
0xJem Oct 31, 2024
31732c7
Fix: Contract names can be visually identical but
0xJem Nov 1, 2024
4aa38c5
Fix: Comment / minor code improvements
0xJem Nov 1, 2024
a641c10
Fix: Redundant sDAI token variable
0xJem Nov 1, 2024
75bd452
Minor fix to build script
0xJem Nov 1, 2024
6fff1fc
Fix: New cooler owner verification can be optimised
0xJem Nov 1, 2024
57ab1f3
Fix: Iterating through contractNames is redundant
0xJem Nov 1, 2024
8748966
Add ROLES document based on PR #424 with additions
0xJem Nov 1, 2024
49a2655
Remove redundant import
0xJem Nov 4, 2024
fc92f01
Remove redundant code in valid character check
0xJem Nov 4, 2024
b4951b8
Remove redundant condition
0xJem Nov 4, 2024
d2d5b63
Merge pull request #433 from OlympusDAO/loanconsolidator-audit-remedi…
0xJem Nov 5, 2024
c51e354
Fixes for MS batch script and OCG proposal
0xJem Nov 6, 2024
37a23ad
Scripts for OCG proposal submission
0xJem Nov 6, 2024
54efe63
Note on batch scripts on forks
0xJem Nov 6, 2024
a1bf723
WIP script to execute OCG proposals on a testnet
0xJem Nov 7, 2024
d7f2849
Working proposal execution on Tenderly fork
0xJem Nov 7, 2024
f93a185
Fix for linting
0xJem Nov 7, 2024
81f452d
Extract proposal submission and execution code into ProposalScript ab…
0xJem Nov 7, 2024
093c8b4
Documentation
0xJem Nov 7, 2024
f9b9d5d
Zero out address
0xJem Nov 7, 2024
ead5ca9
Merge branch 'coolerutils-improvements' into coolerutils-testnet
0xJem Nov 7, 2024
6074d41
Add named parameters, validation and a custom env file to the deploym…
0xJem Nov 7, 2024
2409a43
Correct HTTP status code
0xJem Nov 7, 2024
ef4c0ee
Correct comment
0xJem Nov 7, 2024
30d6360
Modify scripts to support MS batch execution on testnets
0xJem Nov 7, 2024
731cba8
Fix issues with soldeer
0xJem Nov 7, 2024
99e8c7b
Correct build script
0xJem Nov 7, 2024
3e0d1e5
Use https for soldeer dependencies
0xJem Nov 7, 2024
99338eb
Update logs
0xJem Nov 8, 2024
925a06f
Update LoanConsolidatorProposal to use ProposalScript
0xJem Nov 8, 2024
7599f27
Fix issues with remappings
0xJem Nov 12, 2024
524577a
Merge pull request #437 from OlympusDAO/coolerutils-testnet
0xJem Nov 12, 2024
c937be2
Merge remote-tracking branch 'origin/bophades/loan-consolidator' into…
0xJem Nov 12, 2024
ad0efdd
Add links to pull request
0xJem Nov 12, 2024
510095f
Merge branch 'develop' into loan-consolidator
0xJem Nov 12, 2024
8d5f32a
Proposal: update formatting
0xJem Nov 13, 2024
186b422
Merge branch 'develop' into loan-consolidator
0xJem Nov 13, 2024
289d143
chore: linting
0xJem Nov 13, 2024
4aca6a0
Merge branch 'develop' into loan-consolidator
0xJem Nov 13, 2024
c46133e
Merge branch 'develop' into loan-consolidator
0xJem Dec 9, 2024
b76f1ea
Restore github workflow for OCG proposals
0xJem Dec 10, 2024
f96c9fe
Merge branch 'develop' into loan-consolidator
0xJem Dec 10, 2024
bbcd90f
Shift contract registry and loan consolidator proposal tests to use P…
0xJem Dec 10, 2024
cfb921f
LoanConsolidator: upgrade CHREG to the latest version if v1.0 is dete…
0xJem Dec 10, 2024
c1c1ffa
Add additional tests for contract/policy active state
0xJem Dec 10, 2024
f35eb2d
Use the contract address for the old CHREG version
0xJem Dec 10, 2024
8965a1f
Update CHREG to latest version
0xJem Dec 10, 2024
8cac9bc
Bump proposal ids
0xJem Dec 10, 2024
f3f7276
Deployment of RGSTY and ContractRegistryAdmin contracts
0xJem Dec 10, 2024
be077d3
Deployment for LoanConsolidator
0xJem Dec 10, 2024
d25b3d8
Assume installation batch script has been run during RGTSY proposal s…
0xJem Dec 10, 2024
20f991b
Assume installation batch script has been run during LoanConsolidator…
0xJem Dec 10, 2024
217051a
Update block for LoanConsolidator proposal
0xJem Dec 10, 2024
334f1ae
Update docs on proposal submission
0xJem Dec 11, 2024
d181a3e
Add support for Ledger when running OlyBatch scripts
0xJem Dec 13, 2024
791d315
Add missing environment variables for batch scripts
0xJem Dec 13, 2024
5d119cf
Logging in batches
0xJem Dec 13, 2024
7b69dd0
Working batch script with Ledger
0xJem Dec 13, 2024
bc3dbfc
Set sender address for proposal submission script
0xJem Dec 16, 2024
c296ff4
Mark ContractRegistryAdmin proposal as submitted (LoanConsolidator pr…
0xJem Dec 16, 2024
3130992
chore: linting
0xJem Dec 30, 2024
eb79b15
Update fork block for LoanConsolidator proposal test
0xJem Dec 30, 2024
ef01267
Minor update to comment
0xJem Dec 30, 2024
64c825c
Correct argument to forge for setting the sender
0xJem Jan 2, 2025
9546ab5
Mark proposal submission as true
0xJem Jan 2, 2025
ee90017
Disable activation of LoanConsolidator policy during simulation
0xJem Jan 2, 2025
235af27
Move the fork block so that tests pass
0xJem Jan 14, 2025
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: 2 additions & 0 deletions ROLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This document describes the roles that are used in the Olympus protocol.
| bridge_admin | CrossChainBridge | Allows configuring the CrossChainBridge |
| callback_admin | BondCallback | Administers the policy |
| callback_whitelist | BondCallback | Whitelists/blacklists tellers for callback |
| contract_registry_admin | ContractRegistryAdmin | Allows registering/deregistering contracts |
| cooler_overseer | Clearinghouse | Allows activating the Clearinghouse |
| custodian | TreasuryCustodian | Deposit/withdraw reserves and grant/revoke approvals |
| distributor_admin | Distributor | Set reward rate, bounty, and other parameters |
Expand All @@ -24,6 +25,7 @@ This document describes the roles that are used in the Olympus protocol.
| heart | ReserveMigrator | Allows migrating reserves from one reserve token to another |
| heart | YieldRepurchaseFacility | Creates a new YRF market |
| heart_admin | Heart | Allows configuring heart parameters and activation/deactivation |
| loan_consolidator_admin | LoanConsolidator | Allows configuring the LoanConsolidator |
| loop_daddy | YieldRepurchaseFacility | Activate/deactivate the functionality |
| operator_admin | Operator | Activate/deactivate the functionality |
| operator_policy | Operator | Set spreads, threshold factor, and cushion factor |
Expand Down
149 changes: 149 additions & 0 deletions audit/2024-10_loan-consolidator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Olympus Loan Consolidator Audit

## Purpose

The purpose of this audit is to review the Cooler Loans LoanConsolidator contract and associated contracts.

These contracts will be installed in the Olympus V3 "Bophades" system, based on the [Default Framework](https://palm-cause-2bd.notion.site/Default-A-Design-Pattern-for-Better-Protocol-Development-7f8ace6d263c4303b108dc5f8c3055b1).

## Scope

### In-Scope Contracts

The contracts in scope for this audit are:

- [src/](../../src)
- [interfaces/](../../src/interfaces)
- [maker-dao/](../../src/interfaces/maker-dao)
- [IERC3156FlashBorrower.sol](../../src/interfaces/maker-dao/IERC3156FlashBorrower.sol)
- [IERC3156FlashLender.sol](../../src/interfaces/maker-dao/IERC3156FlashLender.sol)
- [modules/](../../src/modules)
- [CHREG/](../../src/modules/CHREG)
- [CHREG.v1.sol](../../src/modules/CHREG/CHREG.v1.sol)
- [OlympusClearinghouseRegistry.sol](../../src/modules/CHREG/OlympusClearinghouseRegistry.sol)
- [RGSTY/](../../src/modules/RGSTY)
- [RGSTY.v1.sol](../../src/modules/RGSTY/RGSTY.v1.sol)
- [OlympusContractRegistry.sol](../../src/modules/RGSTY/OlympusContractRegistry.sol)
- [policies/](../../src/policies)
- [ContractRegistryAdmin.sol](../../src/policies/ContractRegistryAdmin.sol)
- [LoanConsolidator.sol](../../src/policies/LoanConsolidator.sol)

The following pull requests can be referred to for the in-scope contracts:

- [Clearinghouse Registry](https://github.com/OlympusDAO/bophades/pull/191)
- [LoanConsolidator v1](https://github.com/OlympusDAO/bophades/pull/397)
- [LoanConsolidator v2](https://github.com/OlympusDAO/bophades/pull/412)

See the [solidity-metrics.html](./solidity-metrics.html) report for a summary of the code metrics for these contracts.

### Previous Audits

You can review previous audits here:

- Spearbit (07/2022)
- [Report](https://storage.googleapis.com/olympusdao-landing-page-reports/audits/2022-08%20Code4rena.pdf)
- Code4rena Olympus V3 Audit (08/2022)
- [Repo](https://github.com/code-423n4/2022-08-olympus)
- [Findings](https://github.com/code-423n4/2022-08-olympus-findings)
- Kebabsec Olympus V3 Remediation and Follow-up Audits (10/2022 - 11/2022)
- [Remediation Audit Phase 1 Report](https://hackmd.io/tJdujc0gSICv06p_9GgeFQ)
- [Remediation Audit Phase 2 Report](https://hackmd.io/@12og4u7y8i/rk5PeIiEs)
- [Follow-on Audit Report](https://hackmd.io/@12og4u7y8i/Sk56otcBs)
- Cross-Chain Bridge by OtterSec (04/2023)🙏🏼
- [Report](https://storage.googleapis.com/olympusdao-landing-page-reports/audits/Olympus-CrossChain-Audit.pdf)
- PRICEv2 by HickupHH3 (06/2023)
- [Report](https://storage.googleapis.com/olympusdao-landing-page-reports/audits/2023_7_OlympusDAO-final.pdf)
- [Pre-Audit Commit](https://github.com/OlympusDAO/bophades/tree/17fe660525b2f0d706ca318b53111fbf103949ba)
- [Post-Remediations Commit](https://github.com/OlympusDAO/bophades/tree/9c10dc188210632b6ce46c7a836484e8e063151f)
- Cooler Loans by Sherlock (09/2023)
- [Report](https://docs.olympusdao.finance/assets/files/Cooler_Update_Audit_Report-f3f983a8ee8632637790bcc136275aa0.pdf)
- RBS 1.3 & 1.4 by HickupHH3 (11/2023)
- [Report](https://storage.googleapis.com/olympusdao-landing-page-reports/audits/OlympusDAO%20Nov%202023.pdf)
- [Pre-Audit Commit](https://github.com/OlympusDAO/bophades/tree/7a0902cf3ced19d41aafa83e96cf235fb3f15921)
- [Post-Remediations Commit](https://github.com/OlympusDAO/bophades/tree/e61d954cc620254effb014f2d2733e59d828b5b1)

## Architecture

### Overview

The diagram illustrates the architecture of the components:

```mermaid
flowchart TD
cooler_overseer((cooler_overseer)) -- activate --> Clearinghouse
Clearinghouse -- activates clearinghouse --> CHREG
cooler_overseer((cooler_overseer)) -- deactivate --> Clearinghouse
Clearinghouse -- deactivates clearinghouse --> CHREG

subgraph Policies
ContractRegistryAdmin
LoanConsolidator
Clearinghouse
end

subgraph Modules
CHREG
RGSTY
end

contract_registry_admin((contract_registry_admin)) -- registers contract --> ContractRegistryAdmin
ContractRegistryAdmin -- registers contract --> RGSTY
contract_registry_admin((contract_registry_admin)) -- updates contract --> ContractRegistryAdmin
ContractRegistryAdmin -- updates contract --> RGSTY
contract_registry_admin((contract_registry_admin)) -- deregisters contract --> ContractRegistryAdmin
ContractRegistryAdmin -- deregisters contract --> RGSTY

Caller((Caller)) -- determine required approvals --> LoanConsolidator
Caller -- consolidate loans --> LoanConsolidator
LoanConsolidator -- validates Clearinghouse is Olympus-owned --> CHREG
LoanConsolidator -- obtains contract addresses --> RGSTY
LoanConsolidator -- takes flashloan --> IERC3156FlashLender
LoanConsolidator -- consolidates loans --> Clearinghouse
```

### CHREG (Module)

Features:

- Activate and deactivate Clearinghouses
- Access a list of active Clearinghouses
- Access a list of all Clearinghouses (regardless of state)

The Clearinghouse Registry is a module that requires permissioned access in order to activate/deactivate a Clearinghouse.

In the current implementation, when a Clearinghouse policy is activated (via `activate()`) by a permissioned user (`cooler_overseer` role), the policy marks the Clearinghouse as active in the Clearinghouse Registry.

### RGSTY (Module)

Features:

- Tracks contract addresses against an alpha-numeric name
- Access a list of registered names
- Access the current address for a given name
- Update the address for a given name
- Deregister a name
- Contract addresses can be registered as mutable or immutable

The Contract Registry is a module that requires permissioned access in order to add/update/remove an address for a given name.

### Contract Registry Admin (Policy)

Features:

- Register a name for a contract address
- Update the address for a given name
- Deregister a name

The Contract Registry Admin is a policy that enables modification of the RGSTY module. It is gated to the `contract_registry_admin` role.

### Loan Consolidator (Policy)

Features:

- Enables the owner of Cooler Loans to consolidate multiple loans (within the same Cooler) into a single loan, using an ERC3156 flash loan provider.
- Enables the owner of Cooler Loans to migrate loans between Clearinghouses and debt tokens (DAI and USDS).
- Has a helper function to advise the owner on the approvals of gOHM/DAI/sDAI required in order to complete the consolidation.
- The policy can optionally take a protocol fee (sent to the TRSRY) that is set to 0 by default.
- Utilises the CHREG module to obtain the list of Clearinghouse policies.
- Utilises the RGSTY module to obtain the addresses of contracts.
- The loan consolidation functionality can be activated/deactivated by the `loan_consolidator_admin` role.
Loading
Loading