Introduction
This Gitbook provides a line-by-line walkthrough of the Cooler Loan codebase, including the Clearing House designed for use by Olympus. It is broken into two sections: the Borrower Flow, and the Lender/ClearingHouse Flow. Every line of every function in the code base is laid out here, with brief explanations of functionality and some comments on design choices. This is meant to be used as a resource for code auditors and reviewers. On this page we will review some general information.
A suggestion to the reader: go through this walkthrough with the codebase open next to it. Each code block will tell you where it is found, but many functions are broken into chunks for readability. Viewing them side-by-side will give you the best picture of the whole thing!
Cooler Contract Immutables
The owner of a Cooler, the debt token to borrow, and the collateral token used, are all immutable and set when the factory creates the contract.
These are all set in the constructor.
The Factory passes these in when it creates a new Cooler.
Events
The Cooler Factory has a function, newEvent(), that emits events when a created Cooler: creates a loan request, rescinds a loan request, or clears a loan request.
Consolidating this information onto the Factory makes it easy for subgraphs to pick up and aggregate. Calls to this function occur on the request(), rescind(), and clear() functions in Cooler.sol. For example, the call on request() looks like this:
mininterfaces.sol
This file, found in the /lib/ folder, contains two small interfaces. The first is the delegation function for delegatable ERC20's, which extends the standard ERC20 interface. The other is the manage function from the Olympus treasury, which allows the ClearingHouse to interact with and pull tokens (given it has been permissioned to do so).
The four other interfaces in /lib/ are easily verified as standard OpenZeppelin contracts. They are: context.sol, ERC20.sol, IERC20.sol, and IERC20Metadata.sol.
Cooler Lender Transfers
The Cooler allows a lender to transfer their ownership rights over a loan to a different address. This is accomplished with a approve/transfer scheme, akin to a push/pull model. First, the lender will approve an address to transfer the loan rights by calling approve() and passing in the new address and ID of the loan. This can only be called by the lender.
After an approval has been executed, the approved address can now transfer the lending rights. They do this by calling the transfer() function and passing in the ID of the loan.
ClearingHouse Role Transfers
The Clearing House has two roles: Operator and Overseer. Each can transfer their role to a new address (for, i.e., security purposes). This process is handled with a standard push/pull model to ensure safety.
Either role can call the push() function, passing in the intended new address for their role. That address will be assigned a pending role (but not yet set to the actual role!).
Once an address is set as pending, it can call the pull() function to be set as the actual role.
Note that, because both roles share the same functions, small issues (though easily surmountable) may arise if the same address is set as both Overseer and Operator. However, this should not be done in the first place. Thus, because it is unlikely to occur, and it is recoverable even should it occur, this is not an area of concern.
Last updated