Skip to content

Commit f2419c1

Browse files
Rewrite the Architecture section of the Overview page [skip ci]
1 parent 746991b commit f2419c1

File tree

4 files changed

+100
-77
lines changed

4 files changed

+100
-77
lines changed

docs/_Docs_Overview.md

Lines changed: 100 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -10,80 +10,103 @@ The Colony Network is a large set of contracts that together define how all colo
1010

1111
Colony is designed to be modular, upgradable, and eternally backwards-compatible. This is achieved through a sophisticated contract architecture that requires a bit of exposition. It is recommended that any developer seeking to understand the Colony Network solidity implementation first read the [Colony White Paper](https://colony.io/whitepaper.pdf), or at the very least, the [White Paper TL;DR](/colonynetwork/whitepaper-tldr-colony/).
1212

13-
## Overview of Contracts
14-
Broadly speaking, the Colony Network contracts can be divided into a few categories:
15-
16-
* Core contracts that facilitate upgrades, versioning, and emergency functions
17-
* `EtherRouter.sol`
18-
* `Resolver.sol`
19-
* `ContractRecovery.sol`
20-
* `CommonStorage.sol`
21-
22-
* Interface contracts that collate and register public functions on the network. These provide the integration points for interacting with the Colony Network. See [API documentation](/colonynetwork/interface-ietherrouter).
23-
* `IColony.sol`
24-
* `IMetaColony.sol`
25-
* `IColonyNetwork.sol`
26-
* `IReputationMiningCycle.sol`
27-
* `ITokenLocking.sol`
28-
* `IRecovery.sol`
29-
* `IEtherRouter.sol`
30-
31-
* Authority contracts that define who can call which registered functions.
32-
* `CommonAuthority.sol`
33-
* `ColonyAuthority.sol`
34-
* `ColonyNetworkAuthority.sol`
35-
* `DomainRoles.sol`
36-
37-
* Colony contracts that define the state of an individual colony, such as funding pots, tasks, domains, and skills.
38-
* `Colony.sol`
39-
* `ColonyFunding.sol`
40-
* `ColonyPayment.sol`
41-
* `ColonyTask.sol`
42-
43-
* `ColonyStorage.sol`
44-
* `ColonyDataTypes.sol`
45-
46-
* Network contracts that define a global state shared by all colonies, such as reputation, token auctions and ENS.
47-
* `ColonyNetwork.sol`
48-
* `ColonyNetworkAuction.sol`
49-
* `ColonyNetworkENS.sol`
50-
* `ColonyNetworkMining.sol`
51-
52-
* `ColonyNetworkStorage.sol`
53-
* `ColonyNetworkDataTypes.sol`
54-
55-
* Reputation Mining contracts that define a consensus protocol for validators of the global reputation state.
56-
* `ReputationMiningCycle.sol`
57-
* `ReputationMiningCycleRespond.sol`
58-
59-
* `ReputationMiningCycleStorage.sol`
60-
* `ReputationMiningCycleDataTypes.sol`
61-
62-
* Token locking contracts allowing witholding access to depostied tokens from all colonies in the network.
63-
* `TokenLocking.sol`
64-
65-
* `TokenLockingStorage.sol`
66-
* `TokenLockingDataTypes.sol`
67-
68-
* Extension contracts that allow for custom, legacy, or modified extention contracts to be added to a colony
69-
* `ExtensionFactory.sol`
70-
* `OldRoles.sol`
71-
* `OldRolesFactory.sol`
72-
* `OneTxPayment.sol`
73-
* `OneTxPaymentFactory.sol`
74-
75-
* ENS contracts that define a custom ENS registry for use with colonies and the Colony Network
76-
* `ENS.sol`
77-
* `ENSRegistry.sol`
78-
79-
## Inheritance Architecture
80-
The Colony Network contracts are separated out into functional layers, and named according to their context.
81-
82-
![Interface, Logic, Data](img/colonyNetwork_diagram_r11.png)
83-
Starting from the lowest level, all data types are declared in a DataTypes contract.
84-
85-
All storage variables are declared and stored in a storage contract, which inherits a DataTypes contract.
86-
87-
The actual logic of functions is implemented in separate contracts, which inherit a storage contract. All functions which are implemented in this layer must only modify storage varibles declared in the appropriate storage contract.
88-
89-
Finally, all public functions are composed from all logic contracts into a single interface contract, which is used to register functions with EtherRouter (see the next section).
13+
## Smart Contracts Architecture
14+
The Colony Network contracts are separated out into four functional layers, and four logical entities outined below. This design is to an extent mandated by the [contract upgrade mechanism](/colonynetwork/docs-the-delegate-proxy-pattern/) we use.
15+
16+
![Interface, Logic, Data](img/colonyNetwork_diagram_r12.png)
17+
Starting from the layer closes to the user:
18+
19+
**Interface layer**
20+
21+
* `IColony.sol`
22+
* `IMetaColony.sol`
23+
* `IColonyNetwork.sol`
24+
* `IReputationMiningCycle.sol`
25+
* `ITokenLocking.sol`
26+
* `IRecovery.sol`
27+
* `IEtherRouter.sol`
28+
29+
Finally, all public and external functions from the logic contracts for an entity are composed into a single interface. For example the Colony interface - `IColony.sol` is a superset of the public and external functions from the logic contracts for a Colony entity, i.e. `Colony.sol`, `ColonyFunding.sol`, `ColonyPayment.sol` and `ColonyTask.sol`.
30+
31+
This layer represents the Colony Network API, documented in the [Interface section](https://docs.colony.io/colonynetwork/interface-ietherrouter) of the documentation.
32+
33+
**Logic layer**
34+
35+
All function declarations live here and therefore this layer constitutes the majority of the code we write. There are often more than one contracts representing a single logical entity. For example the logic for a Colony entity is distributed across `Colony.sol`, `ColonyFunding.sol`, `ColonyPayment.sol` and `ColonyTask.sol`. Same thing is valid for the ColonyNetwork and ReputationMiningCycle entities. The TokenLocking logic however is succinct enough to be held entirely in the `TokenLocking.sol` contract.
36+
37+
Note that this logic distribution is possible due to the [contract upgrade mechanism](/colonynetwork/docs-the-delegate-proxy-pattern/) we use where essentially all logic contracts for an entity, work with the same underlying `EtherRouter` delegate proxy instance.
38+
39+
**Access layer**
40+
41+
Access management in the network is handled by a group of contracts that underpin all of the application layers.
42+
43+
* `CommonAuthority.sol`
44+
* `ColonyAuthority.sol`
45+
* `ColonyNetworkAuthority.sol`
46+
* `DomainRoles.sol`
47+
48+
These are based on the `DSRoles` and `DSAuth` implementations from the [dappsys library of contracts](https://github.com/dapphub/dappsys-monolithic).
49+
For a full list of these contracts, see the "Roles and Authority" point below. Also see [modular permissions section](/colonynetwork/docs-modular-permissions) for design details.
50+
51+
**Data Layer**
52+
53+
Data structures, enums, constants and events are declared in a dedicated `*DataTypes.sol` contract, e.g. `ColonyDataTypes.sol`.
54+
55+
For clarity all storage variables are held separately in a `*Storage.sol` contract, e.g. `ColonyStorage.sol`. Storage variable declaration ordering is crucial to be maintained correctly as that ordering cannot change during contract upgrages, due to the [contract upgrade mechanism](/colonynetwork/docs-the-delegate-proxy-pattern/) we use.
56+
57+
Additionally when using recovery mode, we write to storage slots directly so again it is essential to maintain as clear storage layout as possible. We even have code comments with slot numbers in the storage contracts to faciliate that process.
58+
59+
**Integrations**
60+
61+
* Extension contracts that allow for custom, legacy, or modified extention contracts to be added to a colony.
62+
* `ExtensionFactory.sol`
63+
* `OldRoles.sol`
64+
* `OldRolesFactory.sol`
65+
* `OneTxPayment.sol`
66+
* `OneTxPaymentFactory.sol`
67+
68+
* ENS contracts that define a custom ENS registry for use with colonies and the Colony Network.
69+
* `ENS.sol`
70+
* `ENSRegistry.sol`
71+
72+
## Logic Entities
73+
Broadly speaking, the Colony Network can be divided into four logical entities:
74+
75+
**Colony**
76+
77+
Defines the state of an individual colony, such as funding pots, tasks, domains, and skills.
78+
* `Colony.sol`
79+
* `ColonyFunding.sol`
80+
* `ColonyPayment.sol`
81+
* `ColonyTask.sol`
82+
83+
* `ColonyStorage.sol`
84+
* `ColonyDataTypes.sol`
85+
86+
**Colony Network **
87+
88+
Defines a global state shared by all colonies, such as reputation, token auctions and ENS.
89+
* `ColonyNetwork.sol`
90+
* `ColonyNetworkAuction.sol`
91+
* `ColonyNetworkENS.sol`
92+
* `ColonyNetworkMining.sol`
93+
94+
* `ColonyNetworkStorage.sol`
95+
* `ColonyNetworkDataTypes.sol`
96+
97+
**Reputation Mining Cycle**
98+
99+
Define a consensus protocol for validators of the global reputation state.
100+
* `ReputationMiningCycle.sol`
101+
* `ReputationMiningCycleRespond.sol`
102+
103+
* `ReputationMiningCycleStorage.sol`
104+
* `ReputationMiningCycleDataTypes.sol`
105+
106+
**Token locking**
107+
108+
Allowing witholding access to deposited tokens from all colonies in the network.
109+
* `TokenLocking.sol`
110+
111+
* `TokenLockingStorage.sol`
112+
* `TokenLockingDataTypes.sol`
-56 KB
Binary file not shown.
-57.7 KB
Binary file not shown.
23.8 KB
Loading

0 commit comments

Comments
 (0)