Separating accounting logic & business logic
Overview
Shell Protocol's unique architecture fully separates the accounting from business logic, thus creating a modular DeFi system.
The Ocean contract acts as Shell Protocol's accounting layer. It manages tasks such as transferring tokens between users and primitives (e.g., liquidity pools), wrapping and unwrapping tokens, and executing interactions. In contrast, the role of a primitive is to compute the numerical results of interactions and relay the results to the Ocean.
To illustrate this concept more clearly, consider a simplified example:
Alice wants to swap DAI for USDC. She provides the Ocean with the details of an interaction, which specifies the input token (DAI
), the input amount, output token (USDC
), and the primitive's address (DAI+USDC
pool).
The Ocean queries the primitive to determine how much USDC
Alice should receive for the given amount of DAI
. Subsequently, the Ocean deducts the specified amount of DAI
from Alice's balance, adds it to the pool balance, and deducts the calculated amount of USDC
from the pool to credit the Alice's balance.
We won't delve deeper into the intricacies of Ocean here, as it isn't pivotal for understanding the separation of accounting and business logic. For a complete examination of Ocean, refer to its wiki page.
Why separate accounting from business logic in the first place?
This architecture has many advantages, with the most salient being:
Generalized Accounting Logic: By decoupling from business logic, the Ocean's accounting logic can support any DeFi primitive (not just AMMs).
Infinite Composability: This generalization enables limitless composability, unlocking a breadth of potential applications and combinations.
Reduced Complexity and Contract Size: Eliminating repetitive logic, such as the transfer function in primitives, streamlines the system. For a deeper dive, refer to the Insight #1: EVM Token Standards Are Broken section in our wiki.
Gas Efficiency: When chaining different primitives, it's possible to track intermediate balances (like multiple swaps transitioning from token A to token B) in memory rather than on-chain storage. This approach conserves gas. More on this can be found in the Insight #3: Transitory Updates Need Not be Saved to the Blockchain section of our wiki.
Last updated