> For the complete documentation index, see [llms.txt](https://docs.maple.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maple.finance/technical-resources/protocol-overview/smart-contract-architecture.md).

# Smart Contract Architecture

In this section, the architecture of the Maple protocol is outlined, including the rationale behind each decision.

![Protocol Architecture](https://2107472351-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MLg9y0GYo0LxapRXEes%2Fuploads%2Fgit-blob-bea2871804f85fbefc4428b11ecfa0f1cb4e5f5c%2FSystemArchitecture.png?alt=media)

## [Pool](/technical-resources/pools/pools.md)

The pool implements the vault standard ([ERC4626](https://erc4626.info/)) and it is intentionally kept as simple as possible, containing mostly token and deposit/withdrawal functionality. It's the only contract that LPs need to interact with to participate in the protocol. Due to immutability, some of the logic is delegated to the contract called `PoolManager`, which is the only external facing contract that the Pool interacts with.

## [PoolManager](/technical-resources/pools/pool-manager.md)

Pools and PoolManagers currently have a one-to-one relationship (architecturally this is allowed to change), meaning that a single Pool contract is associated with a single PoolManager and vice versa. Its main responsibility is to hold almost all of the administrative functions, as well as serve as the interface between the Pool and the other parts of the protocol architecture.

The main actors that interact with the PoolManager are the Pool Delegate, Governor, Operational Admin and other Maple contracts. No external facing actor is expected to use the Pool Manager directly. The Pool Delegate uses the PoolManager to set Pool parameters, such as liquidity cap, fees and the cap on each strategy. The PoolManager funds two kinds of strategy: the Pool's Open Term Loan Manager and shared Strategy Managers. Other contracts use the PoolManager to route calls to the Pool to perform operations such as withdrawals.

## Open Term Loan Manager

The Open Term Loan Manager is used to keep track of all outstanding Loan accounting for its Pool. It only interacts with and reports to a single PoolManager. The accounting is done on a separate contract and not directly on the Pool because it allows for future flexibility. It is possible to completely change the existing value accrual mechanism, or support multiple value accrual mechanisms in parallel in the future, without needing to migrate pool tokens. The Open Term Loan Manager is attached to the PoolManager as a strategy via `addStrategy` using the Open Term Loan Manager factory.

## Loans

A MapleLoan is the contract that represents the agreement between a Lender and a Borrower, defining all of the rules of the engagement. In it, all of the term details are set and enforced. This includes Loan terms, payment schedules, fee structures, and default conditions. Loans are the mechanism through which the revenue is generated for Pool Delegates and the Maple protocol, as well as yield for Liquidity Providers. All new Loans in the Maple protocol are open-term Loans. See [Open Term Loans](/technical-resources/strategies/open-term-loans.md).

## Strategy Managers

Pools can also allocate capital to shared strategies. A shared strategy is two contracts. The [Strategy Manager](/technical-resources/strategies/strategy-manager.md) tracks each Pool's share of one position, and several Pools can fund it at once. The Underlying Strategy deploys that capital to one underlying protocol: [Aave V3](/technical-resources/strategies/aave-v3-strategy.md), [Sky](/technical-resources/strategies/sky-strategy.md), or Managed Wallets through the [Allocation Strategy](/technical-resources/strategies/allocation-strategy.md). A Strategy Manager only accepts Pool Managers as funders, and it never holds assets itself.

## Liquidity Router

The [Liquidity Router](/technical-resources/strategies/liquidity-router.md) lets Maple's Liquidity Bots batch funding and redemption actions across several Strategy Managers in one transaction. It holds no assets and grants no permission beyond what each Strategy Manager already allows.

## WithdrawalManager

In order to maximize capital efficiency, at any given time, the majority of the assets deposited by Liquidity Providers are directed towards funding loans and therefore, are not available to be withdrawn by LPs. Although Lenders are entitled to the full value of their position, full liquidity might not be available at any given time. To address this in an equitable way, the WithdrawalManager contract is used.

Each Pool has a queue-based WithdrawalManager that processes withdrawal requests in the order they were made. See [Withdrawal Manager](/technical-resources/pools/withdrawal-manager.md).

## [Maple Globals](/technical-resources/singletons/globals.md)

MapleGlobals is a singleton contract responsible for holding protocol-wide parameters. The administrative actor of MapleGlobals is the `Governor` which can configure all the needed parameters in a central place. The `Governor` acts on behalf of the Maple DAO.

The MapleGlobals contract is also used to perform and control [time-locked](/technical-resources/admin-functions/timelocks.md) actions, such as smart contract upgrades, which can directly affect Lenders.

## Factories

Within the Maple protocol there will be multiple instances of each contract described above, so for efficiency of deployment, a factory pattern is employed. Factories are contracts that are responsible to create new instances of specific contracts and to manage and perform upgrades. Factories are managed in an allowlist in MapleGlobals, maintained by the Governor or Operational Admin. This allows protocol contracts to verify on-chain that contracts have been vetted by the Maple DAO. For example, a Loan Manager can check if it is funding a Loan that is part of the Maple protocol, as to avoid funding a Loan with malicious smart contract logic. Further, factories rely on MapleGlobals to determine if their caller is allowed to deploy an instance.

The [Pool Deployer](/technical-resources/pools/pool-creation.md) and the [Strategy Deployer](/technical-resources/strategies/strategy-deployer.md) use these factories to create a new Pool or shared strategy, with all of its contracts, in one transaction.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maple.finance/technical-resources/protocol-overview/smart-contract-architecture.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
