🛠️System Architecture

"One smart contract to rule them all... introducing the Diamond Proxy standard💎 👀"

The COFI Money protocol has been developed with a highly modular, upgradeable, and scalable architecture in mind. As such, our smart contracts have been designed in accordance with the EIP-2535 Diamond Standard. This standardisation makes integrations with other tools and software possible, and enables highly granular upgradeability without having to redeploy contracts.

The motivations behind opting for the Diamond standard are described as follows:

  • A single address for unlimited contract functionality. Using a single address makes deployment, testing and integration with other smart contracts, software and user interfaces considerably easier.

  • No maximum contract size. Therefore no need to deploy and integrate multiple contracts, which adds unnecessary complexity.

  • Effective organisation of contract code and data. As the Stoa system is complex and contains a lot of functionality, a Diamond pattern provides a systematic way to isolate different functions, connect them together and share data in a gas-efficient way.

COFI Money Diamond Contract

The COFI Money Diamond is a facade smart contract that performs a delegatecall into its facets to execute function calls.

A fallback is a function that is triggered when a smart contract is passed a function signature outside of its immediate vicinity. delegatecall, a low-level assembly operation, is used to “borrow” the function from the contract residing at the designated facet address.

Every user interaction made to COFI Money (not including periphery contracts such as ERC20s) will traverse through this fallback function, and routed according to the function-to-facet mapping.

Facets are smart contracts that live on the blockchain, with their own addresses, that house external function calls for a given application, and can share internal functions, libraries and state variables.

COFI Money Diamond Facets

The Diamond facets specifically relate to operations governing the Diamond Standard itself.

  • DiamondLoupeFacet - A “loupe” is a tool used for inspecting (real-life) diamonds. As the source code of a Diamond does not include what functions it has (as they are held externally); tools like Etherscan cannot retrieve a Diamond’s supported functions. The DiamondLoupeFacet enables us to access the necessary information. For example, calling facets() returns all of the facet addresses and their function selectors.

  • DiamondCutFacet - This houses the diamondCut() function, which updates any number of functions from any number of facets in a single transaction (if carried out in multiple transactions, as is the case with other proxy patterns, this increases the risk of data corruption).

  • OwnershipFacet - This keeps track of the contract owner(s), so only authorised addresses can perform upgrades.

COFI Money App Facets

The App facets specifically relate to operations of the Stoa Protocol. Stoa can add or remove functionality by deploying new facets and/or executing a diamondCut().

  • SupplyFacet - This houses logic relating to interfacing with yield venues and minting, burning and changing the supply of Stoa stablecoins in accordance with the amount of underlying assets held in the venue.

  • RewardsFacet - This houses logic relating to rewards such as distributing yield earnings and spending Points.

  • PartnerFacet - This houses custom logic required for integrating with certain partners. For example, obtaining the required USDC-LP tokens prior to depositing.

  • AccessFacet - This houses administrator functions such as whitelisting users.

Last updated