# 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](/deep-dive/the-ocean.md) 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](/deep-dive/the-ocean.md).

## 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*](https://wiki.shellprotocol.io/how-shell-works/the-ocean-accounting-hub#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*](https://wiki.shellprotocol.io/how-shell-works/the-ocean-accounting-hub#insight-3-transitory-updates-need-not-be-saved-to-the-blockchain) section of our wiki.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shellprotocol.io/deep-dive/important-concepts/separating-accounting-logic-and-business-logic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
