Skip to content

Commit

Permalink
Cosmetic & Added finance/Vesting (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
dovgopoly committed Feb 8, 2024
1 parent 1bdea83 commit 961b927
Show file tree
Hide file tree
Showing 21 changed files with 688 additions and 49 deletions.
4 changes: 2 additions & 2 deletions docs/getting-started/contribution/solidity.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ interface IBadEventParameterNames {

#### 2.6 Constant and immutable variables

Constant and immutable variables are named with SCREAMING\_SNAKE\_CASE. Internal and private constant and immutable variables are named with an underscore before the name, while public ones have no underscore. 
Constant and immutable variables are named with SCREAMING\_SNAKE\_CASE. Internal and private constant and immutable variables are named with an underscore before the name, while public ones have no underscore.

<Tabs>
<TabItem value="good" label="Good" default>
Expand Down Expand Up @@ -464,7 +464,7 @@ contract BadErrorMessages {

While we prioritize gas optimization in our code, readability remains equally important. As such, we don't engage in extreme optimization practices that could obscure code understanding or maintainability. To guide our approach, below are examples illustrating when optimization is necessary and when it's not.

#### 5.1 Unchecked &#x20;
#### 5.1 Unchecked

Use `unchecked` statements only to migrate code from older Solidity versions. Avoid using it for loop iterator variables as it reduces readability.

Expand Down
25 changes: 22 additions & 3 deletions docs/getting-started/contribution/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,28 @@ $ npm run coverage

Expected output.

<table><thead><tr><th>File</th><th>% Stmts</th><th>% Branch</th><th>% Funcs</th><th>% Lines</th></tr></thead><tbody><tr><td>All files</td><td>100</td><td>100</td><td>100</td><td>100</td></tr></tbody></table>

Sometimes, reaching 100% coverage can be challenging. For these situations, we recommend creating a contract within the `contracts/mock` folder. While mock contracts themselves are not included in the coverage metrics, they are highly beneficial. These can either inherit from the contract you're testing or provide specific functions to test a library. In tests, you can use these mock contracts to replace the original contract or library.&#x20;
<table>
<thead>
<tr>
<th>File</th>
<th>% Stmts</th>
<th>% Branch</th>
<th>% Funcs</th>
<th>% Lines</th>
</tr>
</thead>
<tbody>
<tr>
<td>All files</td>
<td>100</td>
<td>100</td>
<td>100</td>
<td>100</td>
</tr>
</tbody>
</table>

Sometimes, reaching 100% coverage can be challenging. For these situations, we recommend creating a contract within the `contracts/mock` folder. While mock contracts themselves are not included in the coverage metrics, they are highly beneficial. These can either inherit from the contract you're testing or provide specific functions to test a library. In tests, you can use these mock contracts to replace the original contract or library.

```solidity
contract PriorityQueueMock {
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/guides/access/merkle-whitelisted.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 🤠 Merkle Whitelisted
# 📗 Merkle Whitelisted

## Introduction

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 😎 Role Based Access Module (RBAC)
# 📚 Role Based Access Module (RBAC)

## Introduction

Expand Down Expand Up @@ -41,7 +41,32 @@ The `RBAC` contract comes with a pre-configured `MASTER` role. By default, the `

Functions for managing `Roles`:

<table><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><code>grantRoles</code></td><td>Grants a set of <code>Roles</code> to the specified user</td></tr><tr><td><code>revokeRoles</code></td><td>Revokes a set of <code>Roles</code> from the specified user</td></tr><tr><td><code>addPermissionsToRole</code></td><td>Assigns a combination of <code>Resource</code> and its <code>Permissions</code> to a <code>Role</code> with an indicator to either allow or deny access</td></tr><tr><td><code>removePermissionsFromRole</code></td><td>Removes a combination of <code>Resource</code> and its <code>Permissions</code> from a <code>Role</code> with an indicator to either allow or deny access</td></tr></tbody></table>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>grantRoles</code></td>
<td>Grants a set of <code>Roles</code> to the specified user</td>
</tr>
<tr>
<td><code>revokeRoles</code></td>
<td>Revokes a set of <code>Roles</code> from the specified user</td>
</tr>
<tr>
<td><code>addPermissionsToRole</code></td>
<td>Assigns a combination of <code>Resource</code> and its <code>Permissions</code> to a <code>Role</code> with an indicator to either allow or deny access</td>
</tr>
<tr>
<td><code>removePermissionsFromRole</code></td>
<td>Removes a combination of <code>Resource</code> and its <code>Permissions</code> from a <code>Role</code> with an indicator to either allow or deny access</td>
</tr>
</tbody>
</table>

#### 4 Group (extension)

Expand All @@ -51,7 +76,36 @@ If the default group is enabled, it will automatically include every user. The i

Functions for managing `Group`:

<table><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><code>addUserToGroups</code></td><td>Adds a user to specified groups</td></tr><tr><td><code>removeUserFromGroups</code></td><td>Removes a user from specific groups</td></tr><tr><td><code>grantGroupRoles</code></td><td>Assigns a list of <code>Roles</code> to the specific group</td></tr><tr><td><code>revokeGroupRoles</code></td><td>Removes a list of <code>Roles</code> from the specified group</td></tr><tr><td><code>toggleDefaultGroup</code></td><td>Toggles the default group state between enabled and disabled</td></tr></tbody></table>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>addUserToGroups</code></td>
<td>Adds a user to specified groups</td>
</tr>
<tr>
<td><code>removeUserFromGroups</code></td>
<td>Removes a user from specific groups</td>
</tr>
<tr>
<td><code>grantGroupRoles</code></td>
<td>Assigns a list of <code>Roles</code> to the specific group</td>
</tr>
<tr>
<td><code>revokeGroupRoles</code></td>
<td>Removes a list of <code>Roles</code> from the specified group</td>
</tr>
<tr>
<td><code>toggleDefaultGroup</code></td>
<td>Toggles the default group state between enabled and disabled</td>
</tr>
</tbody>
</table>

## Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Introduction

The Compound Rate Keeper module is designed to be employed in lending protocols to compute interest and borrow rates, as well as in staking contracts to determine users' rewards accrual with a fixed Annual Percentage Yield (APY).&#x20;
The Compound Rate Keeper module is designed to be employed in lending protocols to compute interest and borrow rates, as well as in staking contracts to determine users' rewards accrual with a fixed Annual Percentage Yield (APY).

## Implementation

Expand All @@ -22,11 +22,69 @@ Note, that the _compoundRate_ is calculated with the **precision** of `10**25`.

The `AbstractCompoundRateKeeper` contract defines the calculation of the compound rate and can serve as a base for implementing diverse lending or staking calculations. This contract includes the following public functions:

<table><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><code>emergencyUpdateCompoundRate</code></td><td>Updates the compound rate. If overflows, sets <code>isMaxRateReached</code> to true</td></tr><tr><td><code>getCompoundRate</code></td><td>Returns current compound rate</td></tr><tr><td><code>getFutureCompoundRate</code></td><td>Returns future compound rate</td></tr><tr><td><code>getCapitalizationRate</code></td><td>Returns current capitalization rate</td></tr><tr><td><code>getCapitalizationPeriod</code></td><td>Returns current capitalization period</td></tr><tr><td><code>getLastUpdate</code></td><td>Returns timestamp of the last update</td></tr><tr><td><code>getIsMaxRateReached</code></td><td>Returns whether the max rate is reached</td></tr><tr><td><code>getCurrentRate</code></td><td>Returns current rate</td></tr></tbody></table>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>emergencyUpdateCompoundRate</code></td>
<td>Updates the compound rate. If overflows, sets <code>isMaxRateReached</code> to true</td>
</tr>
<tr>
<td><code>getCompoundRate</code></td>
<td>Returns current compound rate</td>
</tr>
<tr>
<td><code>getFutureCompoundRate</code></td>
<td>Returns future compound rate</td>
</tr>
<tr>
<td><code>getCapitalizationRate</code></td>
<td>Returns current capitalization rate</td>
</tr>
<tr>
<td><code>getCapitalizationPeriod</code></td>
<td>Returns current capitalization period</td>
</tr>
<tr>
<td><code>getLastUpdate</code></td>
<td>Returns timestamp of the last update</td>
</tr>
<tr>
<td><code>getIsMaxRateReached</code></td>
<td>Returns whether the max rate is reached</td>
</tr>
<tr>
<td><code>getCurrentRate</code></td>
<td>Returns current rate</td>
</tr>
</tbody>
</table>

Additionally, there are a couple of internal functions to update the capitalization rate or capitalization period:

<table><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><code>_setCapitalizationRate</code></td><td>Sets the capitalization rate</td></tr><tr><td><code>_setCapitalizationPeriod</code></td><td>Sets the capitalization period</td></tr></tbody></table>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>_setCapitalizationRate</code></td>
<td>Sets the capitalization rate</td>
</tr>
<tr>
<td><code>_setCapitalizationPeriod</code></td>
<td>Sets the capitalization period</td>
</tr>
</tbody>
</table>

The core function containing the rate calculation logic is `getFutureCompoundRate`, which eventually returns the new rate.

Expand Down
116 changes: 110 additions & 6 deletions docs/getting-started/guides/contracts-registry/contracts-registry.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 🗒 Contracts Registry
# 🗒 Contracts Registry

## Introduction

Expand Down Expand Up @@ -29,7 +29,40 @@ Behind the scenes, the `ContractRegistry` maintains a mapping of string contract

Functions featured by the `ContractsRegisry`:

<table><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><code>injectDependencies</code>, <code>injectDependenciesWithData</code></td><td>Injects the dependencies into the given contract</td></tr><tr><td><code>upgradeContract</code>, <code>upgradeContractAndCall</code></td><td>Upgrades added proxy contract with a new implementation</td></tr><tr><td><code>addContract</code></td><td>Adds contracts that the system does not have direct upgradeability control over, or the contracts that are not upgradeable</td></tr><tr><td><code>addProxyContract</code>, <code>addProxyContractAndCall</code></td><td>Adds the contracts and deploys the proxy above them</td></tr><tr><td><code>justAddProxyContract</code></td><td>Adds the already deployed proxy</td></tr><tr><td><code>removeContact</code></td><td>Removes the contract</td></tr></tbody></table>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>injectDependencies</code>, <code>injectDependenciesWithData</code></td>
<td>Injects the dependencies into the given contract</td>
</tr>
<tr>
<td><code>upgradeContract</code>, <code>upgradeContractAndCall</code></td>
<td>Upgrades added proxy contract with a new implementation</td>
</tr>
<tr>
<td><code>addContract</code></td>
<td>Adds contracts that the system does not have direct upgradeability control over, or the contracts that are not upgradeable</td>
</tr>
<tr>
<td><code>addProxyContract</code>, <code>addProxyContractAndCall</code></td>
<td>Adds the contracts and deploys the proxy above them</td>
</tr>
<tr>
<td><code>justAddProxyContract</code></td>
<td>Adds the already deployed proxy</td>
</tr>
<tr>
<td><code>removeContact</code></td>
<td>Removes the contract</td>
</tr>
</tbody>
</table>

#### 2 Dependency Injection

Expand All @@ -41,17 +74,88 @@ To facilitate the deployment and management of pool contracts, the `PoolRegistry

Functions featured by the `PoolRegistry`:

<table><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><code>setNewImplementations</code></td><td>Sets pools' implementations</td></tr><tr><td><code>injectDependenciesToExistingPools, injectDependenciesToExistingPoolsWithData</code></td><td>Injects dependencies to the pools</td></tr><tr><td><code>addProxyPool</code></td><td>Adds new pools</td></tr></tbody></table>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>setNewImplementations</code></td>
<td>Sets pools' implementations</td>
</tr>
<tr>
<td><code>injectDependenciesToExistingPools, injectDependenciesToExistingPoolsWithData</code></td>
<td>Injects dependencies to the pools</td>
</tr>
<tr>
<td><code>addProxyPool</code></td>
<td>Adds new pools</td>
</tr>
</tbody>
</table>

Functions featured by the `PoolFactory`:

<table><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><code>deploy</code></td><td>Deploys Beacon Proxy pointing to the pool implementation taken from the <code>PoolRegistry</code></td></tr><tr><td><code>deploy2</code></td><td>Deploys Beacon Proxy pointing to the pool implementation taken from the <code>PoolRegistry</code> using the create2 mechanism</td></tr><tr><td><code>register</code></td><td>Registers newly deployed pool in the <code>PoolRegistry</code></td></tr><tr><td><code>injectDependencies</code></td><td>Injects dependencies to the newly deployed pool and sets <code>PoolRegistry</code> as an injector</td></tr></tbody></table>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>deploy</code></td>
<td>Deploys Beacon Proxy pointing to the pool implementation taken from the <code>PoolRegistry</code></td>
</tr>
<tr>
<td><code>deploy2</code></td>
<td>Deploys Beacon Proxy pointing to the pool implementation taken from the <code>PoolRegistry</code> using the create2 mechanism</td>
</tr>
<tr>
<td><code>register</code></td>
<td>Registers the newly deployed pool in the <code>PoolRegistry</code></td>
</tr>
<tr>
<td><code>injectDependencies</code></td>
<td>Injects dependencies into the newly deployed pool and sets <code>PoolRegistry</code> as an injector</td>
</tr>
</tbody>
</table>

#### 4 Presets

The Contracts Registry module includes several preset contracts to help you establish permissions.

<table><thead><tr><th>Function</th><th>Description</th></tr></thead><tbody><tr><td><a href="https://github.com/dl-solarity/solidity-lib/blob/master/contracts/contracts-registry/presets/OwnableContractsRegistry.sol">OwnableContractsRegistry</a></td><td>Only the owner can inject dependencies into, add, remove, and upgrade contracts</td></tr><tr><td><a href="https://github.com/dl-solarity/solidity-lib/blob/master/contracts/contracts-registry/presets/MultiOwnableContractsRegistry.sol">MultiOwnableContractsRegistry</a></td><td>Only multiple owners can inject dependencies into, add, remove, and upgrade contracts</td></tr><tr><td><a href="https://github.com/dl-solarity/solidity-lib/blob/master/contracts/contracts-registry/pools/presets/OwnablePoolContractsRegistry.sol">OwnablePoolContractsRegistry</a></td><td>Only the owner can call set pools' implementations and inject dependencies into existing pools</td></tr><tr><td><a href="https://github.com/dl-solarity/solidity-lib/blob/master/contracts/contracts-registry/pools/presets/MultiOwnablePoolContractsRegistry.sol">MultiOwnablePoolContractsRegistry</a></td><td>Only multiple owners can call set pools' implementations and inject dependencies into existing pools</td></tr></tbody></table>
<table>
<thead>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://github.com/dl-solarity/solidity-lib/blob/master/contracts/contracts-registry/presets/OwnableContractsRegistry.sol">OwnableContractsRegistry</a></td>
<td>Only the owner can inject dependencies into, add, remove, and upgrade contracts</td>
</tr>
<tr>
<td><a href="https://github.com/dl-solarity/solidity-lib/blob/master/contracts/contracts-registry/presets/MultiOwnableContractsRegistry.sol">MultiOwnableContractsRegistry</a></td>
<td>Only multiple owners can inject dependencies into, add, remove, and upgrade contracts</td>
</tr>
<tr>
<td><a href="https://github.com/dl-solarity/solidity-lib/blob/master/contracts/contracts-registry/pools/presets/OwnablePoolContractsRegistry.sol">OwnablePoolContractsRegistry</a></td>
<td>Only the owner can call set pools' implementations and inject dependencies into existing pools</td>
</tr>
<tr>
<td><a href="https://github.com/dl-solarity/solidity-lib/blob/master/contracts/contracts-registry/pools/presets/MultiOwnablePoolContractsRegistry.sol">MultiOwnablePoolContractsRegistry</a></td>
<td>Only multiple owners can call set pools' implementations and inject dependencies into existing pools</td>
</tr>
</tbody>
</table>

## Example

Expand Down Expand Up @@ -97,7 +201,7 @@ contract SystemContract2 {
}
```

To initiate the migration process, begin by deploying and initializing the `ContractsRegistry` contract. Following this, deploy all system contracts and register them. In this example, `SystemContract1` is deployed under the transparent proxy managed by `ContractsRegistry`, while `SystemContract2` is added as is. Conclude by injecting dependencies into the `SystemContract1`.&#x20;
To initiate the migration process, begin by deploying and initializing the `ContractsRegistry` contract. Following this, deploy all system contracts and register them. In this example, `SystemContract1` is deployed under the transparent proxy managed by `ContractsRegistry`, while `SystemContract2` is added as is. Conclude by injecting dependencies into the `SystemContract1`.

```solidity
function migration() external {
Expand Down
Loading

0 comments on commit 961b927

Please sign in to comment.