Separating accounting logic & business logic


Shell Protocol adopts a distinctive approach by fully separating accounting from business logic, thus creating a modular DeFi system.

The Ocean 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 primitive address (DAI+USDC AMM). 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.

While this gives a general overview, we won't delve much deeper into the intricacies of Ocean here, as it isn't pivotal for understanding the separation of accounting and business logic. For a detailed examination of Ocean, refer to its dedicated page.

Why separate accounting from business logic in the first place?

Opting for this distinction offers numerous advantages, with the most salient being:

  • Generalized Accounting Logic: By decoupling, you can design an accounting logic that supports any primitive, not just AMMs, paving the way for versatility.

  • 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