Intro to Diamond Contracts
Before we hop into the repository's contents, we need to explain Diamond contracts since the Teller protocol makes extensive use of it. In February 2020, the user **mudgen** proposed **EIP-2535** with an extensive overview of what a Diamond contract is. The way a diamond works is simple: a main diamond contract delegates calls to multiple facets, which borrows functionalities and storage from libraries. Because the Diamond contract delegates the calls, it acts as one giant contract as calling the facet just means calling the diamond.
In terms of storage, the Diamond solves the 24KB contract storage problem using the Diamond storage technique. The way it works is we hash a position string, like
teller-notion-test, then store a storage struct into the position's slot.
The protocol is designed around the pattern of Diamond Contracts. Several of these contracts and peripheral contracts make the protocol.
Diamond contracts are like standard contracts, but they contain very little external logic except for delegation and configuration of that delegation. Instead, external logic is aggregated into this contract in the form of "facets". Facets are also contracts, equivalent to logic contracts in our current structure. By default, diamonds come with the following facets:
- DiamondCut (upgradeable)
- DiamondLoupe (introspection)
External functions can be added/removed from a diamond contract by calling the standard "diamondCut" function on it. This is an external function which resides in the initial DiamondCut facet logic contract. Important to note that any of the exposed calls from the starting facets of a diamond contract can be completely replaced by using this function, including itself. This means that we can permanently remove the upgradeability feature of the diamond contract when it shouldn't change anymore (e.g. DAO handoff).
The standard facets, delegation management and even deterministic deployments (static addresses across networks and blocks) are all managed out-of-the-box by the latest version of hardhat-deploy.