---
# System prepended metadata

title: AragonOS Fundamentals

---

---
slideOptions:
  transition: slide
  
---

# AragonOS Fundamentals

<!-- Put the link to this slide here so people can follow -->
slide: https://hackmd.io/@AbuUsama/AragonOSFundamentals

---

## HouseKeeping


- [Notion Page](https://www.notion.so/daobox/Teamspace-Home-2a8cf08616414f9cb96daee4b22d73f7)

- [Read the Docs!](https://devs.aragon.org/docs/core/)

Note: 
    - scribe
    - Although we have time for Q&A at the end 

---

## What we will be covering

- Main Contracts
- Infrastructure Contracts
- Development cycle
- Q&A
    
Note: 
    - Although we have time for Q&A at the end, jump in anywhere something doesn't make sense or you feel I have skipped over something
    - This will be very high level, look at some code but no coding 

---

## Core Contracts

![](https://i.imgur.com/i9nfVf8.png)



- `DAO`
- `PermissionManager`
- `Plugin`

Note: 
    Thankfully there are only three core contracts that makeup your DAO
    & you won't have to interact with the permission manager directly 
    which leaves just the DAO contract and your plugin

---

## DAO Contract

- Identity
- Managing Assets
- interacting with other contracts

----

lets look at a minimal `IDAO` interface for the DAO contract

---

### `IDAO.sol`

```solidity= [9|2-6|11]
interface IDAO {
    struct Action {
        address to; // Address to call
        uint256 value; // Value to be sent with the call (for example ETH if on mainnet)
        bytes data; // Function selector + arguments
    }

    
    function execute(bytes32 callId, Action[] memory _actions, uint256 _allowFailureMap);
    
    function setMetadata(bytes calldata _metadata);
    
}
```

Note:
    callId: it's up to the calling contract how to use, eg nonce
    almost always you are going to call execute()

---

## PermissionManager

- governs the interactions between the DAO, Plugins and other addresses
- Functionally equivelent to ACL
- `DAO.sol` inherits `PermissionManager`
- The secret sauce that makes a DAO a DAO

Note:
    DAOs are essentially permission management systems

----

### `DAO.sol`

```solidity
contract DAO is PermissionManager {

    bytes32 EXECUTE_PERMISSION_ID = keccak256("EXECUTE_PERMISSION");
    bytes32 UPGRADE_DAO_PERMISSION_ID = keccak256("UPGRADE_DAO_PERMISSION");
    bytes32 SET_METADATA_PERMISSION_ID = keccak256("SET_METADATA_PERMISSION");
    
    // ...

}
```

Note:
    permission identifiers
    

----

### `DAO.sol`

```solidity
contract DAO is PermissionManager {
    // ...
    
    function hasPermission(
        address _where,
        address _who,
        bytes32 _permissionId,
        bytes memory _data
    ) external view returns (bool) {
        // ...
    }
    

}
```

Note:
    view function to see if an address has a permission on another address
    data is optional. it's used to encode permission conditions

----

### `DAO.sol`

```solidity
contract DAO is PermissionManager {
    function execute(
        bytes32 callId,
        Action[] calldata _actions,
        uint256 allowFailureMap
    )
        external
        override
        auth(address(this), EXECUTE_PERMISSION_ID)
        returns (bytes[] memory execResults, uint256 failureMap)
    {
        // ...
    }

}
```

Note:
    auth1: address where the permission is required
    auth2: the permission identifier its self

---

## Plugin Contract

- used to add functionality to the dao

    - Governance
    - Finance

Note:
    fine-grained control
    if you give an address execute, they can execute anything 

---

Lets walk through a pseudocode example of a Swapper Plugin

Note:
    code should let anyone with the swap permission perform a swap

----

```solidity= [2-3|6-11|13-22]
contract SwapPlugin is Plugin {
    bytes32 SWAP_PERMISSION_ID = keccak256("SWAP_PERMISSION");
    bytes32 ADMIN_PERMISSION_ID = keccak256("ADMIN_PERMISSION");
    

    function addAdmin(address newAdmin) 
        external 
        auth(address(this), ADMIN_PERMISSION_ID)
    {
        dao.grant(address(this), newAdmin, ADMIN_PERMISSION_ID);
    }
    
    function swap(address tokenIn, address tokenOut, uint amount)
        external 
        auth(address(this), SWAP_PERMISSION_ID)
    {
        dao.execute(
            nonce++, // use the current nonce then add 1
            [encodedTokenApproval, encodedSwapAction], // actions for the dao
            0, // 0 means none if any action fails, revert 
        )
    }

}
```

---

## Plugin Upgradeability


- Minimal Proxy
- Transparent Proxy
- UUPS proxy
    
Note: 
    minimal Proxy is non upgradable

---

## Infrastructure Contracts

- Plugin setup contract
- plugin repo contract

---

## Plugin Setup Contract

- its a script to install the plugin in a DAO
- it sets up initial permissions

---

## Plugin Repo Contract

- functionally equivilent to APM 
- contains the current (and all previous) versions of your plugin
- contains the setup contract
- contains a URI to the apps UI

--- 

## UP Next 

- Setting up the development environment

---

:end: 
