> For the complete documentation index, see [llms.txt](https://docs.elara.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.elara.fi/protocol-reference/reference/api-reference/base/abstract.elarabase.md).

# ElaraBase

[Git Source](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/9301de6eec32ceafb4021f4e7da883b507799ebc/contracts/base/ElaraBase.sol)

**Inherits:** IElaraBase, AccessManagedUpgradeable, UUPSUpgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable

**Title:** Elara Base Contract

Abstract base contract for all Elara upgradeable contracts

* Provides UUPS upgradeability, pausability, reentrancy protection, and access management
* Invariants:
* Only authorized accounts can pause/unpause functionality
* Only authorized accounts can upgrade the implementation
* Upgradeability:
* Uses UUPS upgradeability pattern via {UUPSUpgradeable}
* Initializer must be called exactly once; preserve storage layout for upgrade safety
* All upgradeable contracts should inherit from this base to ensure consistent security controls
* Access Control:
* All critical functions are gated by [AccessManagedUpgradeable-restricted](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/docs/latest/lib/openzeppelin-contracts-upgradeable/contracts/access/manager/AccessManagedUpgradeable.sol/abstract.AccessManagedUpgradeable.md#restricted) modifier
* Access management is handled by a centralized {AccessManager} contract

**Note:** security-contact: <security@elara.finance>

## Functions

### constructor

**Note:** oz-upgrades-unsafe-allow: constructor

```solidity
constructor() ;
```

### \_\_ElaraBase\_init

Internal initializer wiring shared upgrade and access control modules.

Security:

* Only callable during initialization via {initializer} modifier
* Sets up inherited contracts via their respective initialization functions
* Reverts if \_accessManager is zero address
* Critical for establishing access control; must be called exactly once per proxy

```solidity
function __ElaraBase_init(address _accessManager) internal onlyInitializing;
```

**Parameters**

| Name             | Type      | Description                           |
| ---------------- | --------- | ------------------------------------- |
| `_accessManager` | `address` | Address of the AccessManager contract |

### pause

Triggers pause state in {PausableUpgradeable}. May affect other contracts that depend on this contract's functionality.

```solidity
function pause() external override(IElaraBase) restricted;
```

### unpause

Triggers unpause state in {PausableUpgradeable}. May affect other contracts that depend on this contract's functionality.

```solidity
function unpause() external override(IElaraBase) restricted;
```

### upgradeToAndCall

Restricted to proxy calls only via {onlyProxy}; direct calls to the implementation revert. Delegates to [UUPSUpgradeable-upgradeToAndCall](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/docs/latest/lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol/abstract.UUPSUpgradeable.md#upgradetoandcall), which internally calls [\_authorizeUpgrade](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/docs/latest/contracts/base/ElaraBase.sol/abstract.ElaraBase.md#_authorizeupgrade) where access control is enforced via {restricted}.

```solidity
function upgradeToAndCall(
    address newImplementation,
    bytes memory data
)
    public
    payable
    override(IElaraBase, UUPSUpgradeable)
    onlyProxy;
```

### \_authorizeUpgrade

Authorization is enforced via {restricted} modifier on this internal function. Note: While OpenZeppelin generally recommends against using {restricted} on internal functions, UUPS contracts are a special case where this pattern is appropriate and secure. Why this works for UUPS:

* upgradeToAndCall (from UUPSUpgradeable) is the ONLY external entry point for upgrades
* When \_authorizeUpgrade executes, \_msgData() still contains the upgradeToAndCall selector
* AccessManager checks permissions for the upgradeToAndCall selector, which is the intended behavior
* This approach avoids redundant authorization checks while maintaining complete security The security flow is:

1. External call to upgradeToAndCall (inherited from UUPSUpgradeable)
2. UUPSUpgradeable.upgradeToAndCall calls \_authorizeUpgrade internally
3. Our \_authorizeUpgrade uses {restricted} to check AccessManager permissions
4. AccessManager validates that msg.sender can call upgradeToAndCall Reference: <https://forum.openzeppelin.com/t/uupsupgradeable-and-accessmanaged/41142>

```solidity
function _authorizeUpgrade(address) internal override restricted;
```
